2

I am new to Nhapi and using it to parse the HL7 message .

The issue i am facing is i am parsing the ADT^A03 message but always i get the PV1 segment as null.

I am attaching the Sample Message and my Code .

Sample Message :

MSH|^~\&|MMM|MMM|||201412081017||ADT^A03|2014342370374441||2.3
EVN|A03|201412081017|201412080001||73540
PID|1||000000004449^^^PHS^MR|491662^^^MMM|||19500225|F||1||||||D|CAT|78599180^^M10^MMM^PN|
PD1||1|||||NNN|||||
NK1|0001|NONE AS PER PT^NONE AS PER PT^^^^^L|19||||JUCON||||||||||||||||||||||||||||||
NK1|0002|NONE^^^^^^L|||||PTEMP|||UNEMPLOYED|||||||||||||||||||||||||||
PV1|1|O||R|||001211^RAM SHYAM|001211^RAM SHYAM||SDO||||OU|||001211^RAM SHYAM|U||H^20141208||||||||||||||||AHR|||PNKN|||||201412080625|201412081015
PV2||||||||201412080001|||||||N|||||1||||OD|||||||||||||
GT1|0001||SHYAM^RAM|||||19500225|F|P|01|00000000||||NONE|||||||||||||||||||||||||||||||||||NONE||||
IN1||00000000|^NONE^^^^^^^^L||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||(000)2584-33695|||||||NONE^L||

Code :

PipeParser parser = new PipeParser();
 IMessage messageParsed = parser.Parse(message);
ADT_A03 a03 = messageParsed as ADT_A03;

PV1Segment pv1Segment = new PV1Segment();
pv1Segment.Set_Id_PV1_1_1 = a03.PV1.SetIDPatientVisit.Value;
pv1Segment.Patient_Class_2_1 = a03.PV1.PatientClass.Value;
pv1Segment.Assigned_Patient_Location_3_1 = a03.PV1.AssignedPatientLocation.PointOfCare.Value;
pv1Segment.Admission_Type_4_1 = a03.PV1.AdmissionType.Value;
pv1Segment.Pre_Admit_Number_5_1 = a03.PV1.PreadmitNumber.ID.Value;
pv1Segment.Prior_Patient_Location_6_1 = a03.PV1.PriorPatientLocation.PointOfCare.Value;
pv1Segment.Attending_Doctor_Id_7_1 = a03.PV1.AttendingDoctor.IDNumber.Value;
pv1Segment.Attending_Doctor_Name_7_2 = a03.PV1.AttendingDoctor.FamilyName.Value;
pv1Segment.Referring_Doctor_Id_8_1 = a03.PV1.ReferringDoctor.IDNumber.Value;
pv1Segment.Referring_Doctor_Name_8_2 = a03.PV1.ReferringDoctor.FamilyName.Value;
Himanshu
  • 67
  • 1
  • 2
  • 12

2 Answers2

3

Your basic problem here is that you are trying to parse a HL7 2.3 message that doesn't conform to the HL7 2.3 specification for ADT A03 events.

Namely, NK1, GT1 and IN1 segments are not defined in the standard for the ADT A03 event in HL7 version 2.3.

If you remove the problem segments, the message will parse against the 2.3 specification using your code like so:

  var parser = new PipeParser();
  var messageParsed = parser.Parse(message);
  var a03 = messageParsed as ADT_A03;

  var setId = a03.PV1.SetIDPatientVisit.Value;
  var patientClass = a03.PV1.PatientClass.Value;
  var AssignedPatientLocation = a03.PV1.AssignedPatientLocation.PointOfCare.Value;
  var Admission_Type = a03.PV1.AdmissionType.Value;
  var Pre_Admit_Number = a03.PV1.PreadmitNumber.ID.Value;
  var Prior_Patient_Location = a03.PV1.PriorPatientLocation.PointOfCare.Value;
  var Attending_Doctor_Id = a03.PV1.AttendingDoctor.IDNumber.Value;
  var Attending_Doctor_Name = a03.PV1.AttendingDoctor.FamilyName.Value;
  var Referring_Doctor_Id = a03.PV1.ReferringDoctor.IDNumber.Value;
  var Referring_Doctor_Name = a03.PV1.ReferringDoctor.FamilyName.Value;

NHapi's model parsing is modelled tightly against the HL7 standards, so you if give it non-standard data like the message you have shown above, it won't handle it gracefully. (aborting parsing of subsequent segments like in this case).

  • Thanks Duane Edwards, Just a addition , Is there any way to handle this specific structure of HL7 message. – Himanshu Mar 04 '15 at 08:11
  • 1
    messageParsed1.GetStructure("PV1"); Can this method solve the problem? – Himanshu Mar 04 '15 at 09:23
  • Sure, but you'd need to extend the parser to recognise this new message type. The parser needs to know what order of segments, what field types etc to parse first, because as soon as it encounters something it doesn't recognise it will just abort as the original issue showed. Refer to this test class on how you would parse a custom type: https://github.com/duaneedwards/nHapi/blob/master/NHapi20/NHapi.NUnit/CustomZSegmentTest.cs And this project contains the updated Message / Segment definitions required: https://github.com/duaneedwards/nHapi/tree/master/NHapi20/NHapi.Model.V22_ZSegments – Duane Edwards Mar 05 '15 at 22:07
  • And just to confirm as davidlg has mentioned in his answer, modifying the standards database is an option but will be ALOT more messy work than you'd want to do. So proceed with option 2 (extend / replace the ADT_A03 class) as he suggested if you need to do this. I'd suggest extending, using the above links in my previous comment as reference to see what's required. – Duane Edwards Mar 05 '15 at 22:14
  • Can you share the example for the 2nd option. – Himanshu Mar 09 '15 at 18:41
  • I did, read: http://stackoverflow.com/questions/28848007/nhapi-parsing-issue/28848656?noredirect=1#comment46038476_28848656 Look at that test method and the supporting classes to see how you can extend the parser to handle a custom segment. – Duane Edwards Mar 09 '15 at 22:28
  • Hey @DuaneEdwards. I was trying to get the basic patient details, but everytime `a03` in `var a03 = messageParsed as ADT_A03;` is `null` for me. Tried casting to others like `ADT_A01` or `ORU_R01` as well but with same results. The HL7 message is fine. But I'm not sure where the issue lies. Any lead would be appreciated. – Praveen Oct 17 '20 at 10:43
2

You have a couple of options if you want to parse a HL7 message that doesn't quite conform to the standards.

  1. Modify the HL7 standards database and regenerate the code
  2. Extending/replacing the current ADT_A03 class

I can tell you from experience that modifying the HL7 standards database (and regenerating) is hard and messy.

I would simply extend the ADT_A03 class in your application and add the definitions of the non-standard segments - that way you will be able to access all of the data.

davidlg
  • 86
  • 3
  • davidlg, Can you share the example for the 2nd Option. – Himanshu Mar 09 '15 at 06:22
  • 1
    Hi @Himanshu, have a look at Duane's git repo - specifically https://github.com/duaneedwards/nHapi/blob/master/NHapi20/NHapi.Model.V22_ZSegments/Message/ADT_A08.cs – davidlg Apr 20 '15 at 01:54