Your company is required to adhere to regulatory compliance in healthcare, and you are tasked to search for blood type records across your organization.
<blood group A B O AB><Rhesus factor + ->
<blood group A B O AB><0-1 whitespaces>Rh<0-1 whitespaces><Rhesus factor + - (+)
(-)>
Some samples of (comma-separated) blood type records:
1 | a+, a- |
2 | arh+, arh-, arh(+), arh(-), a rh+, a rh-, a rh(+), a rh(-), arh +, arh -, arh (+), arh (-), a rh +, a rh -, a rh (+), a rh (-) |
In Part 1, we use the MAP operator to declare a namespace for the four blood groups.
MAP NOCASE 'BLOOD_GROUP' 'a', 'b', 'o', 'ab'
See MAP Namespace for more information
In Part 2, we define the namespace for the Rhesus factor notation that is common
to both blood type record formats (+
, -
), and use the
COPY operator to append the additional notations
(+
, -
) to a second namespace.
MAP NOCASE 'BLOOD_GROUP' 'a', 'b', 'o', 'ab'
MAP 'RH_FACTOR_1' '+', '-'
MAP 'RH_FACTOR_2' '(+)', '(-)', COPY 'RH_FACTOR_1'
See Copying Keys to a MAP Namespace for more information.
In Part 3, we define the expression that searches for the possible blood groups followed by the Rhesus factor.
MAP NOCASE 'BLOOD_GROUP' 'a', 'b', 'o', 'ab'
MAP 'RH_FACTOR_1' '+', '-'
MAP 'RH_FACTOR_2' '(+)', '(-)', COPY 'RH_FACTOR_1'
GROUP 'BLOOD_GROUP' THEN GROUP 'RH_FACTOR_1'
The expression in Part 3 will match blood type records that are of similar format as Line 1 of the Blood Type Record Samples:
1 | a+ |
2 | O- |
3 | aB- |
To improve the readability of the GLASS code, we can rewrite the expression using the ALIAS and REFER operators.
MAP NOCASE 'BLOOD_GROUP' 'a', 'b', 'o', 'ab'
MAP 'RH_FACTOR_1' '+', '-'
MAP 'RH_FACTOR_2' '(+)', '(-)', COPY 'RH_FACTOR_1'
ALIAS 'BLOOD_TYPE_SEQ_1' \
GROUP 'BLOOD_GROUP' THEN \
GROUP 'RH_FACTOR_1'
REFER 'BLOOD_TYPE_SEQ_1'
See THEN and OR and ALIAS and REFER for more information.
In Part 4, we define the expression that will (only) match the second blood type record format.
MAP NOCASE 'BLOOD_GROUP' 'a', 'b', 'o', 'ab'
MAP 'RH_FACTOR_1' '+', '-'
MAP 'RH_FACTOR_2' '(+)', '(-)', COPY 'RH_FACTOR_1'
GROUP 'BLOOD_GROUP' THEN \
# 0 or 1 whitespace after the BLOOD_GROUP
WORD ' ' TIMES 0-1 THEN \
# Case-insensitive term, 'rh'
WORD NOCASE 'rh' THEN \
# 0 or 1 whitespace after the term, 'rh'
WORD ' ' TIMES 0-1 THEN \
# Second blood type record format supports all Rh factor notations
GROUP 'RH_FACTOR_2'
The expression in Part 4 will match blood type records that are of similar format as Line 2 of the Blood Type Record Samples:
1 | a+ |
2 | O- |
3 | aB- |
Similar to Part 3, we can rewrite the expression using the ALIAS and REFER operators.
MAP NOCASE 'BLOOD_GROUP' 'a', 'b', 'o', 'ab'
MAP 'RH_FACTOR_1' '+', '-'
MAP 'RH_FACTOR_2' '(+)', '(-)', COPY 'RH_FACTOR_1'
ALIAS 'BLOOD_TYPE_SEQ_2' \
GROUP 'BLOOD_GROUP' THEN \
# 0 or 1 whitespace after the BLOOD_GROUP
WORD ' ' TIMES 0-1 THEN \
# Case-insensitive term, 'rh'
WORD NOCASE 'rh' THEN \
# 0 or 1 whitespace after the term, 'rh'
WORD ' ' TIMES 0-1 THEN \
# Second blood type record format supports all Rh factor notations
GROUP 'RH_FACTOR_2'
REFER 'BLOOD_TYPE_SEQ_2'
See WORD for more information.
In Part 5, we join the expressions in Part 3 and Part 4 using the OR operator.
MAP NOCASE 'BLOOD_GROUP' 'a', 'b', 'o', 'ab'
MAP 'RH_FACTOR_1' '+', '-'
MAP 'RH_FACTOR_2' '(+)', '(-)', COPY 'RH_FACTOR_1'
ALIAS 'BLOOD_TYPE_SEQ_1' \
GROUP 'BLOOD_GROUP' THEN \
GROUP 'RH_FACTOR_1'
ALIAS 'BLOOD_TYPE_SEQ_2' \
GROUP 'BLOOD_GROUP' THEN \
# 0 or 1 whitespace after the BLOOD_GROUP
WORD ' ' TIMES 0-1 THEN \
# Case-insensitive term, 'rh'
WORD NOCASE 'rh' THEN \
# 0 or 1 whitespace after the term, 'rh'
WORD ' ' TIMES 0-1 THEN \
# Second blood type record format supports all Rh factor notations
GROUP 'RH_FACTOR_2'
REFER 'BLOOD_TYPE_SEQ_1' OR REFER 'BLOOD_TYPE_SEQ_2'
In Part 6, we define the pattern boundaries for custom GLASS data type.
MAP NOCASE 'BLOOD_GROUP' 'a', 'b', 'o', 'ab'
MAP 'RH_FACTOR_1' '+', '-'
MAP 'RH_FACTOR_2' '(+)', '(-)', COPY 'RH_FACTOR_1'
ALIAS 'BLOOD_TYPE_SEQ_1' \
GROUP 'BLOOD_GROUP' THEN \
GROUP 'RH_FACTOR_1'
ALIAS 'BLOOD_TYPE_SEQ_2' \
GROUP 'BLOOD_GROUP' THEN \
# 0 or 1 whitespace after the BLOOD_GROUP
WORD ' ' TIMES 0-1 THEN \
# Case-insensitive term, 'rh'
WORD NOCASE 'rh' THEN \
# 0 or 1 whitespace after the term, 'rh'
WORD ' ' TIMES 0-1 THEN \
# Second blood type record format supports all Rh factor notations
GROUP 'RH_FACTOR_2'
(REFER 'BLOOD_TYPE_SEQ_1' OR REFER 'BLOOD_TYPE_SEQ_2') BOUND NONALNUM
See BOUND and Preset Keywords for more information.
1 2 3 4 |
Blood Type: a+, B-, Ab+, o- a rh (-) ORh(-) ab Rh(+) |
Based on the GLASS expression in Part 6, the blood type records from line 1 to line 4 will all be returned as match locations by the GLASS pattern matching engine.