I am trying to parse hl7 files using hl7apy i am having below hl7 sample
sample :
MSH|^~\&|XXXX|C|PRIORITYHEALTH|PRIORITYHEALTH|20080511103530||ORU^R01|Q335939501T337311002|P|2.3|||
PID|1||94000000000^^^Priority Health||LASTNAME^FIRSTNAME^INIT||19460101|M|||||
PD1|1|||1234567890^PCPLAST^PCPFIRST^M^^^^^NPI|
OBR|1||185L29839X64489JLPF~X64489^ACC_NUM|JLPF^Lipid Panel - C||||||||||||1694^DOCLAST^DOCFIRST^^MD||||||20080511103529|||
OBX|1|NM|JHDL^HDL Cholesterol (CAD)|1|62|CD:289^mg/dL|>40^>40|""||""|F|||20080511103500|||^^^""|
OBX|2|NM|JTRIG^Triglyceride (CAD)|1|72|CD:289^mg/dL|35-150^35^150|""||""|F|||20080511103500|||^^^""|
OBX|3|NM|JVLDL^VLDL-C (calc - CAD)|1|14|CD:289^mg/dL||""||""|F|||20080511103500|||^^^""|
OBX|4|NM|JLDL^LDL-C (calc - CAD)|1|134|CD:289^mg/dL|0-100^0^100|H||""|F|||20080511103500|||^^^""|
OBX|5|NM|JCHO^Cholesterol (CAD)|1|210|CD:289^mg/dL|90-200^90^200|H||""|F|||20080511103500|||^^^""|
Code:
from hl7apy import parser
from hl7apy.exceptions import UnsupportedVersion
hl7 = open('sample.hl7', 'r').read()
try:
m = parser.parse_message(hl7)
except UnsupportedVersion:
m = parser.parse_message(hl7.replace("n", "r"))
print(m.obx.obx_1.value)
but when i am trying to read OBX (Repeating segments) i am not getting any data, it is displaying nothing. What is am i doing wrong ?
You have an error in your code. It should be
hl7.replace("\n", "\r")
You have to write all groups, if you want to access a field in (a) group(s)
try m.ORU_R01_RESPONSE.ORU_R01_ORDER_OBSERVATION.ORU_R01_OBSERVATION.OBX[0].obx_1.value
for the first value of the first obx segment and so on.
I recommend to read Improve hl7apy documentation