rimiti / hl7-object-parser

:wrench: Convert hl7 messages to javascript object.
29 stars 6 forks source link

Supporting many definitions of one kind #7

Closed rmngrc closed 5 years ago

rmngrc commented 5 years ago

Hello!

First of all, thank you for this library. Found very nice the fact that we can customise the output object by creating the mapping!

One of the bad things though come when trying to parse an HL7 message with many segments of one kind, like test results which may contain many observations and notes. See this message as example extracted from https://hl7messageparser.azurewebsites.net/Parse/Samples:

MSH|^~\&|LAB|MYFAC|LAB||201411130917||ORU^R01|3216598|D|2.3|||AL|NE|
PID|1|ABC123DF|AND234DA_PID3|PID_4_ALTID|Patlast^Patfirst^Mid||19670202|F|||4505 21 st^^LAKE COUNTRY^BC^V4V 2S7||222-555-8484|||||MF0050356/15|
PV1|1|O|MYFACSOMPL||||^Xavarie^Sonna^^^^^XAVS|||||||||||REF||SELF|||||||||||||||||||MYFAC||REG|||201411071440||||||||23390^PV1_52Surname^PV1_52Given^H^^Dr^^PV1_52Mnemonic|
ORC|RE|PT103933301.0100|||CM|N|||201411130917|^Kyle^Andra^J.^^^^KYLA||^Xavarie^Sonna^^^^^XAVS|MYFAC|
OBR|1|PT1311:H00001R301.0100|PT1311:H00001R|301.0100^Complete Blood Count (CBC)^00065227^57021-8^CBC \T\ Auto Differential^pCLOCD|R||201411130914|||KYLA||||201411130914||^Xavarie^Sonna^^^^^XAVS||00065227||||201411130915||LAB|F||^^^^^R|^Xavarie^Sonna^^^^^XAVS|
OBX|1|NM|301.0500^White Blood Count (WBC)^00065227^6690-2^Leukocytes^pCLOCD|1|10.1|10\S\9/L|3.1-9.7|H||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|2|NM|301.0600^Red Blood Count (RBC)^00065227^789-8^Erythrocytes^pCLOCD|1|3.2|10\S\12/L|3.7-5.0|L||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|3|NM|301.0700^Hemoglobin (HGB)^00065227^718-7^Hemoglobin^pCLOCD|1|140|g/L|118-151|N||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|4|NM|301.0900^Hematocrit (HCT)^00065227^4544-3^Hematocrit^pCLOCD|1|0.34|L/L|0.33-0.45|N||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|5|NM|301.1100^MCV^00065227^787-2^Mean Corpuscular Volume^pCLOCD|1|98.0|fL|84.0-98.0|N||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|6|NM|301.1300^MCH^00065227^785-6^Mean Corpuscular Hemoglobin^pCLOCD|1|27.0|pg|28.3-33.5|L||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|7|NM|301.1500^MCHC^00065227^786-4^Mean Corpuscular Hemoglobin Concentration^pCLOCD|1|330|g/L|329-352|N||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|8|NM|301.1700^RDW^00065227^788-0^Erythrocyte Distribution Width^pCLOCD|1|12.0|%|12.0-15.0|N||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|9|NM|301.1900^Platelets^00065227^777-3^Platelets^pCLOCD|1|125|10\S\9/L|147-375|L||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|10|NM|301.2100^Neutrophils^00065227^751-8^Neutrophils^pCLOCD|1|8.0|10\S\9/L|1.2-6.0|H||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|11|NM|301.2300^Lymphocytes^00065227^731-0^Lymphocytes^pCLOCD|1|1.0|10\S\9/L|0.6-3.1|N||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|12|NM|301.2500^Monocytes^00065227^742-7^Monocytes^pCLOCD|1|1.0|10\S\9/L|0.1-0.9|H||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|13|NM|301.2700^Eosinophils^00065227^711-2^Eosinophils^pCLOCD|1|0.0|10\S\9/L|0.0-0.5|N||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|14|NM|301.2900^Basophils^00065227^704-7^Basophils^pCLOCD|1|0.0|10\S\9/L|0.0-0.2|N||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
ZDR||^Xavarie^Sonna^^^^^XAVS^^^^^XX^^ATP|
ZPR||

I made some changes to the lib to loop through the different segments first and not just by the keys set up in the mapping object.

With the following object in the mapping:

"obx": {
  "values": [
    { "field": "obx.id", "component": [3,1] },
  ]
}

This would be parsed as:

{ msh:
   { message_datetime: '201411130917',
     message_type: 'ORU',
     message_type_ref: 'R01',
     message_control_id: '3216598',
     principal_language_of_message: '',
     character_set: '' },
  pid:
   { first_name: 'Patfirst',
     last_name: 'Patlast',
     birthdate: '19670202',
     gender: 'F' },
  obx:
   [ { id: '301.0500' },
     { id: '301.0600' },
     { id: '301.0700' },
     { id: '301.0900' },
     { id: '301.1100' },
     { id: '301.1300' },
     { id: '301.1500' },
     { id: '301.1700' },
     { id: '301.1900' },
     { id: '301.2100' },
     { id: '301.2300' },
     { id: '301.2500' },
     { id: '301.2700' },
     { id: '301.2900' } ] }

Hope you find it useful and we can merge it soon.

PS: I am working in the meantime on extending the unit tests for this case.

coveralls commented 5 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 570b9a1422d117a251ae2d634525c003af650e45 on rmngrc:accepting-multiple-definitions-of-one-kind into 44b0b610be9e8e5c6dd0495f0350106d33077555 on rimiti:master.

rimiti commented 5 years ago

Hello @rmngrc,

Thank you for this awesome pull request, you rock! 🚀 Could you please add some tests to increase the code coverage? 🏅

Regards,

rmngrc commented 5 years ago

@rimiti Sure thing! I'm already on it. Will amend the changes soon.

Thank you!

rmngrc commented 5 years ago

Thank you @rimiti :)

rmngrc commented 5 years ago

Can you please ping me when a new version is published on npm?

rimiti commented 5 years ago

It's released (with https://github.com/rimiti/hl7-object-parser/pull/8) 🚀

Thank you @rmngrc for you awesome work and @nelfurion for your review.

rmngrc commented 5 years ago

Great stuff! Thank you for your responsiveness @rimiti

Let me know if you would need any help improving/maintaining anything related to this library.

rimiti commented 5 years ago

Yeah, it was a great team working. 🤓

For the moment, I don't need help to maintaining this package, but if one day I'll need you'll be notified with pleasure. 👍