How to parse multiple segments? #92
-
MSH|^~&|MESA_RPT_MGR|EAST_RADIOLOGY|iFW|XYZ|||ORU^R01|MESA3b|P|2.4||||||||
Given the hl7 message above how can i get the OBX2 using message.get('OBX[2]').toString();; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@joemark0008 See below..
In this case, you want to: const message = require('node-hl7-client').Message
const hl7 = `MSH|^~&|MESA_RPT_MGR|EAST_RADIOLOGY|iFW|XYZ|||ORU^R01|MESA3b|P|2.4||||||||
PID|||CR3^^^ADT1||CRTHREE^PAUL|||||||||||||PatientAcct||||||||||||
PV1||1|CE||||12345^SMITH^BARON^H|||||||||||
OBR|||||||20010501141500.0000||||||||||||||||||F||||||||||||||||||
OBX|1|HD|SR Instance UID||1.113654.1.2001.30.2.1||||||F||||||
OBX|2|TX|SR Text||Radiology Report History Cough Findings PA evaluation of the chest demonstrates the lungs to be expanded and clear. Conclusions Normal PA chest x-ray.||||||F||||||
CTI|study1|^1|^10_EP1`
const parsedMessage = new message({ text: hl7 })
parsedMessage.get('OBX').forEach((segment) => {
const seg = segment // HL7Node Property. Has lots of things.
if (seg.get('1').toString() === '2' ) {
console.log(seg.get('5').toString()) // get the path here of OBX 2
}
}) Do a forLoop on each OBX Segmenets. Then, inside the loop, you must compare path "1". If you want the 2nd one, you can also do an "index" match in case path "1" is not always 2, but this comes down to the HL7 message designer. Once you get to the right index or if statement I wrote above, you can extract the information from that segment. In this case, I did 5 getting "Radiology Report History Cough Findings PA evaluation of the chest demonstrates the lungs to be expanded and clear. Conclusions Normal PA chest x-ray." This always works, messy, but it works; console.log(parsedMessage.get('OBX')['_segments'][1].get('5').toString()) A new method might be needed to get to a segment index so you wouldn't have to loop. I hope this helps! |
Beta Was this translation helpful? Give feedback.
@joemark0008 See below..