Skip to content
IT related

HL7APY - HL7 formatting

Updated 1 min read

HL7APY data model

HL7 Message Hierarchy

Logical Structure:

  • MSH - Message metadata
  • PID - Patient info
  • PV1 - Visit info
  • ORC - Order Common (metadata about the order)
    • OBR - Observation Request (specific test/procedure ordered)
    • OBX - Observation Results (individual findings/values)
      • OBX - Another result
      • OBX - Another result

In hl7apy's Nested Structure:
Message

  • MSH (segment)
  • ORU_R01_PATIENT_RESULT (group)
    • ORU_R01_PATIENT (group)
      • PID (segment)
        • ORU_R01_VISIT (group)
          • PV1 (segment)
        • ORU_R01_ORDER_OBSERVATION (group) ← This is the container!
          • ORC (segment)
          • OBR (segment)
            • ORU_R01_OBSERVATION (group)
              • OBX (segment)
            • ORU_R01_OBSERVATION (group)
              • OBX (segment)
            • ORU_R01_OBSERVATION (group)
              • OBX (segment)

Accessing the fields in python

Get a string read into the HL7APY class with the grouping above.

from hl7apy.parser import parse_message
from hl7apy.consts import VALIDATION_LEVEL

parsed_message = parse_message(hl7_message_text, validation_level=VALIDATION_LEVEL.TOLERANT, find_groups=True)

Now to access each step we do this:

original_pid = hl7_message.ORU_R01_PATIENT_RESULT[0].ORU_R01_PATIENT.PID
original_pv1 = hl7_message.ORU_R01_PATIENT_RESULT[0].ORU_R01_PATIENT.ORU_R01_VISIT.PV1
original_orc = hl7_message.ORU_R01_PATIENT_RESULT[0].ORU_R01_ORDER_OBSERVATION[0].ORC
original_br = hl7_message.ORU_R01_PATIENT_RESULT[0].ORU_R01_ORDER_OBSERVATION[0].OBR

And on, keeping in mind that you may need to iterate through the groups. you can have multiple patients (although rare)

IT related RSS feed Published with Oblish

Keyboard shortcuts

/
Search
[
Previous page
]
Next page
?
Show this list
Esc
Close