Blood Type Records

Your company is required to adhere to regulatory compliance in healthcare, and you are tasked to search for blood type records across your organization.

Data Type Requirements

  1. Search case-insensitively for blood type records.
  2. Two possible formats for the blood type records:
    • <blood group A B O AB><Rhesus factor + ->
    • <blood group A B O AB><0-1 whitespaces>Rh<0-1 whitespaces><Rhesus factor + - (+) (-)>
  3. Matches of blood type records should be bounded by non-alphanumeric characters.

Blood Type Records example requirements

Blood Type Record Samples

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 (-)
Go through the detailed steps to build out the custom GLASS data type (recommended), or jump straight to the recommended GLASS solution.

Part 1 - Blood Group

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

Part 2 - Rhesus Factor

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.

Part 3 - Blood Group Followed by Rhesus Factor

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.

Part 4 - Blood Group Followed by Rh Then Rhesus Factor

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.

Part 5 - Combining the Expressions for Both Blood Type Record Formats

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'

Part 6 - Adding Boundary Rules

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.

Match Samples

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.