9

How to parse the Multiple OBR Segment in HL7 using HAPI using terser

I have sample hl7 message like this

MSH|^~\&|SENDERAPP|SENDERFAC|COVCDR|COVCDR|20130212221503||ORU^R01|1676326503009050|P|2.5
PID|1||MRN101||DOE^JOHN^A||20000101|M||W|1 Campus Martius^^Detroit^MI^48226||(313)227-7300||EN|S|||111-11-1111|||H
PV1|1|U| 12E^1211^01||||1689885733^ORANGE TEAM, OMNI|||Med||||Tra|||99999999^SMITH^KEVIN^^^^MD|I|000000000000|YY|P||||||||||||||||||||Ac|||20130224080500
ORC|RE|F78520223|000000000^LA||CM||||20130226020200||||  PICU|||^RESULT PERFORMED|||RES
OBR|1|F78520223|1305611705^LA|0101301^COMPLETE BLOOD COUNT^COMPLETE BLOOD COUNT|||20130226010600|20130226020200||2632||||20130226014200||333333^GEORGE, BOB|||||0001305611705|20130226020200|||F||^^^20130226043000^^EA~^^^^^EA
OBX|1|NM|0106550^WHITE BLOOD CELL COUNT^WHITE BLOOD CELL COUNT||7.9|10e9/L|4.3-11.0||||F|||20130226020200|34333^Kelly, Bacon^^00010033^MOLIS XE2|RES
OBX|2|NM|0104650^RBCx10e12^RBCx10e12||4.09|10e12/L|4.53-5.73|L|||F|||20130226020200|34333^Kelly, Bacon^^00010033^MOLIS XE2|RES
OBX|3|NM|0102150^HEMOGLOBIN^HEMOGLOBIN||12.9|g/dL|13.6-17.4|L|||F|||20130226020200|34333^Kelly, Bacon^^00010033^MOLIS XE2|RES
OBX|4|NM|0102100^HEMATOCRIT^HEMATOCRIT||37.5|%|40.7-50.8|L|||F|||20130226020200|34333^Kelly, Bacon^^00010033^MOLIS XE2|RES
OBX|5|NM|0103500^MEAN CORPUSCULAR VOLUME^MEAN CORPUSCULAR VOLUME||91.7|fL|81.6-96.8||||F|||20130226020200|34333^Kelly, Bacon^^00010033^MOLIS XE2|RES
NTE|1||Test performed at Tulsa

I am using terser.get("/.OBX-3-1")); to access OBX parent segment. How to get to child OBX segments using terser

iberbeu
  • 15,295
  • 5
  • 27
  • 48
dreambigcoder
  • 1,859
  • 4
  • 22
  • 32

2 Answers2

11

OBX is nested inside an OBSERVATION group (which in return is nested in other groups). Actually, not the OBX segment is repeatable but the OBSERVATION group is. So your terser expression would be something like terser.get("/.OBSERVATION(i)/OBX-3-1");, where in your case i runs from 0 to 3.

cheers christian

user1658722
  • 216
  • 2
  • 2
  • 3
    Note, I was attempting to do this in NHAPI, and NHAPI uses a regex to attempt to find a match. I had to change the check terser get to be: `terser.get("/.^OBSERVATION$(i)/OBX-3-1");` to do an exact match on OBSERVATION. The message was an HL7 v2.3 message. – Steve Wranovsky Jul 17 '14 at 16:30
  • 1
    @SteveWranovsky also tried your solution on 2.3.1 and confirm that is working. – José González Jan 03 '23 at 19:34
3

I think you should use terser.get(/OBX(repetition)-3-1). For instance, terser.get(/OBX(2)-3-1) should be equal to 0102150. Remember that the repetition starts at 0, so OBX(2) refers to OBX|3|NM|0102150^HEMOGLOBIN^...

You can find some hapi terser example about repetitions here:

I have written a couple of post about this issue. You can find them:

http://ignaciosuay.com/how-to-use-hapi-terser-with-hl7/

http://ignaciosuay.com/how-to-set-repetitions-in-hl7-messages-using-hapi-terser/

Cheers Ignacio

ignacio.suay
  • 737
  • 6
  • 7
  • 6
    How are you able to know how many OBX elements there are for each OBR? – CatsLoveJazz May 14 '15 at 16:32
  • What can we do to set multiple OBX if there are no OBX yet constructed for this OBR? – Peggy Apr 07 '20 at 16:45
  • @CatsLoveJazz I think Terser cannot be used to find the number of OBX segments for each OBR. Instead you need to use `HL7Message.getPATIENT_RESULT(0).getORDER_OBSERVATIONAll()` to get all OBR groups. Then for each OBR group, use `getOBSERVATIONReps()` to get the number of OBX segments. – Lonely Solitary Feb 04 '21 at 07:51