How do I find the repeating fields value of a HL7 string in C#?

917 views Asked by At
string input = 
@"MSH|^~\&|||||20171218104936.3464||ADT^A01^ADT_A01|56ca00f2-a99a-4593-b6cb-1c141c0ae0cb||2.3.1
EVN||20171218104936.3464
PID|||15197||Test^Dummy^HK||19770628000000.0000|O
PV1||0";

In the string above, the name field (Test^Dummy^HK) is a repeating field. How can I get that in C# using the nHapi DLL?

1

There are 1 answers

0
Oliamster On

It is quite simple, but before any attempt to retrieve a field, the message needs to be parsed:

string input = 
@"MSH|^~\&|||||20171218104936.3464||ADT^A01^ADT_A01|56ca00f2-a99a-4593-b6cb-1c141c0ae0cb||2.3.1
EVN||20171218104936.3464
PID|||15197||Test^Dummy^HK||19770628000000.0000|O
PV1||0";

ADT_A01 adt = (ADT_A01)(new PipeParser()).Parse(input);

next, the field you are looking for is an XPN datatype, namely an Extended Patient Name. The following table lists the first 3 components of the Patient Name.

SEQ     LENGTH  DT  OPT TBL#    NAME
XPN.1   194     FN  O           Family Name
XPN.2   30      ST  O           FirstName   Given Name
XPN.3   30      ST  O           Second And Further Given Names Or Initials Thereof

These components can be accessed through thier properties so:

string surname = adt.PID.GetPatientName(0).FamilyName.Surname.Value; //Test
string givenName = adt.PID.GetPatientName(0).GivenName.Value; //Dummy
string secondAndFurtherGivenNamesOrInitialsThereof = adt.PID.GetPatientName(0).SecondAndFurtherGivenNamesOrInitialsThereof.Value; //HK

Since there is no tilde character, the parser assumes that the value provided in the PID-5 corresponds to the first repetition, this is why I have GetPatientName(0) to specify the first repetition. Any attempt to retrieve other repetitions will fail, or yield to null value.

Notice that the Family Name is a composite datatype of type FN, here is the FN's component table:

FN.1    50  ST  R       Surname
FN.2    20  ST  O       Own Surname Prefix
FN.3    50  ST  O       Own Surname
FN.4    20  ST  O       Surname Prefix From Partner/Spouse
FN.5    50  ST  O       Surname From Partner/Spouse

An alternative is:

Terser adtTerser = new Terser(adt);
string surname = adtTerser.Get("PID-5.1") = adtTerser.Get("PID-5-1-1")
string givenName = adtTerser.Get("PID-5.2") = adtTerser.Get("PID-5-2-1")
string secondAndFurtherGivenNamesOrInitialsThereof = adtTerser.Get("PID-5-3") = adtTerser.Get("PID-5-3-1")

I have found this useful documentation check it out. hope that it could help you.