Before you create a message, you need to load the message library. This library contains HL7 2.x definitions.
A library was created for each HL7 version. Library names formatted as BSHL7XX.BSL, XX is HL7 version -without dot '.'- number.
For HL7 2.2 version library name BSHL722.BSL
.
For HL7 2.3.1 version library name BSHL7231.BSL
.
//Load library...
procedure TForm1.FormCreate(Sender: TObject);
begin
BSHL7Library.LoadFromFile('BSHL722.BSL');
end;
Demo project contains :
Creating Message:
//Load library...
procedure TForm1.FormCreate(Sender: TObject);
begin
BSHL7Library.LoadFromFile('..\data\BSHL722.BSL');
end;
procedure TForm1.bMessageCreateClick(Sender: TObject);
var
msg : TbsADT_A01_22;
begin
try
msg := TbsADT_A01_22.Create;
// Populate the MSH Segment
msg.MSH.Sendingfacility.Value:='Sending';
msg.MSH.Sequencenumber.Value:='123';
// Populate the PID Segment
msg.PID.PatientName.FamilyName.AsString:='Doe';
msg.PID.PatientName.GivenName.AsString:='John';
msg.PID.PatientIDInternalID[0].IDNumber.AsString:='123456';
Memo1.Lines.Append(msg.AsHL7);
// MSH|^~\&|||Sending|||||||||123
// PID|||123456||Doe^John
finally
msg.Free;
end;
end;
Message Parse:
//Load library...
procedure TForm1.FormCreate(Sender: TObject);
begin
BSHL7Library.LoadFromFile('..\data\BSHL722.BSL');
end;
procedure TForm1.bParseMessageClick(Sender: TObject);
var
msg : TbsADT_A01_22;
ASending : string;
ASeq : string;
AFName : string;
AGName : string;
AIDNumber : string;
begin
try
msg := TbsADT_A01_22.Create;
msg.AsHL7:='MSH|^~\&|||Sending|||||||||123'+#13+
'EVN|'+#13+
'PID|||123456||Doe^John'+#13+
'PV1|'+#13+#10;
// Get the Sendingfacility value
ASending := msg.MSH.Sendingfacility.Value; //Sending
ASeq := msg.MSH.Sequencenumber.Value; //123;
// Access the PID Segment
AFName := msg.PID.PatientName.FamilyName.AsString; //Doe
AGName := msg.PID.PatientName.GivenName.AsString; //John
AIDnumber:=msg.PID.PatientIDInternalID[0].IDNumber.AsString; //123456
finally
msg.Free;
end;
end;
Parsing Message :
const
MsgORU_R01_22 =
'MSH|^~\&|ABL735^ABL735 Operating Theatres|ABL735^ABL735 Operating Theatres|||'+
'20010516135518||ORU^R01|20010516135518|P^not present|2.2' + #13 +
'PID|1|||F87248654|Doe^John|||U' + #13 +
'OBR|1||6^Sample #||||||||O||||Arterial^' + #13 +
'NTE|1|L|443' + #13 +
'OBX|1|ST|^pH^M||7.600|||N|||F|||20010503151400||' + #13 +
'OBX|2|ST|^pO2^M||127|mmHg||N|||F|||||' + #13 +
'OBX|3|ST|^pCO2^M||20.4|mmHg||N|||F|||||' + #13 +
'OBX|4|ST|^Cl-^M||73|mmol/L||N|||F|||||' + #13 +
'OBX|5|ST|^K+^M||5.5|mmol/L||N|||F|||||' + #13 +
'OBX|6|ST|^Na+^M||125|mmol/L||N|||F|||||' + #13 +
'OBX|7|ST|^Glu^M||11.3|mmol/L||N|||F|||||' + #13 +
'OBX|8|ST|^Lac^M||10.0|mmol/L||N|||F|||||' + #13 +
'OBX|9|ST|^Ca++^M||0.36|mmol/L||N|||F|||||' + #13 +
'OBX|10|ST|^tHb^M||17.3|g/dL||N|||F|||||' + #13 +
'NTE|1|L|314' + #13 +
'OBX|11|ST|^sO2^M||.....|%||N|||F|||||' + #13 +
'NTE|1|L|314' + #13 +
'OBX|12|ST|^O2Hb^M||-58.4|%||<|||F|||||' + #13 +
'NTE|1|L|314^94' + #13 +
'OBX|13|ST|^COHb^M||110.4|%||>|||F|||||' + #13 +
'NTE|1|L|314^93' + #13 +
'OBX|14|ST|^MetHb^M||-6.5|%||<|||F|||||' + #13 +
'NTE|1|L|314^94' + #13 +
'OBX|15|ST|^tBil^M||.....|micromol/L||<|||F|||||' + #13 +
'NTE|1|L|314^94' + #13 +
'OBX|16|ST|^T^I||37.0|Cel|||||F|||||' + #13 +
'OBX|17|ST|^FIO2^D||21.0|%|||||F|||||' + #13 +
'OBX|18|ST|^pH(T)^M||7.600|||N|||F|||||' + #13 +
'OBX|19|ST|^pCO2(T)^M||20.4|mmHg||N|||F|||||' + #13 +
'OBX|20|ST|^SBE^C||-1.5|mmol/L|||||F|||||' + #13 +
'OBX|21|ST|^pO2(T)^M||127|mmHg||N|||F|||||'+ #13#10;
//Load library...
procedure TForm1.FormCreate(Sender: TObject);
begin
BSHL7Library.LoadFromFile('..\data\BSHL722.BSL');
end;
procedure TForm1.bParseMessageAdvClick(Sender: TObject);
var
msg : TbsORU_R01_22;
Patient : TbsPN_22;
observation : TbsORU_R01_PATIENT_RESULT_ORDER_OBSERVATION_OBSERVATION_22;
i : integer;
begin
Memo1.Lines.Append('Message Parse (Advanced)');
msg := TbsORU_R01_22.Create;
//Parse message
msg.AsString := MsgORU_R01_22;
Patient:=msg.PATIENT_RESULT[0].PATIENT.PID.PatientName;
// Shows John
Memo1.Lines.Append('Patient Name : '+Patient.GivenName.AsString);
Memo1.Lines.Add( 'OBSERVATIONRepCount : ' + IntToStr(
msg.PATIENT_RESULT[0].ORDER_OBSERVATION[0].OBSERVATIONRepCount)
);
for i:=0 to msg.PATIENT_RESULT[0].ORDER_OBSERVATION[0].OBSERVATIONRepCount-1
do begin
observation := msg.PATIENT_RESULT[0].ORDER_OBSERVATION[0].OBSERVATION[i];
Memo1.Lines.Append(
observation.OBX.ObservationIdentifier.Text.AsString+#9#9+
observation.OBX.ObservationValue.AsString);
end;
{
OBSERVATIONRepCount : 21
pH 7.600
pO2 127
pCO2 20.4
Cl- 73
K+ 5.5
Na+ 125
Glu 11.3
Lac 10.0
Ca++ 0.36
tHb 17.3
sO2 .....
O2Hb -58.4
COHb 110.4
MetHb -6.5
tBil .....
T 37.0
FIO2 21.0
pH(T) 7.600
pCO2(T) 20.4
SBE -1.5
pO2(T) 127
}
FreeAndNil(msg);
end;
Setting / Getting Value :
There are more than one property to assign a value. These are listed below :
AsString Used to assign a value to the area. If the value is encoded in the special separator characters.
msg.PID.PatientName.FamilyName.AsString:='Doe';
RawValue Used to assign a value to the area. If the value is not encoded in the special separator characters.
adt_a01.MSH.FieldSeparator.RawValue:='|';
Generate XML message
//Load library...
procedure TForm1.FormCreate(Sender: TObject);
begin
BSHL7Library.LoadFromFile('..\data\BSHL724.BSL');
end;
procedure TForm1.bMessageCreateAdvClick(Sender: TObject);
var
msg : TbsORU_R01_24;
msh : TbsMSH_24;
pid: TbsPID_24;
obr: TbsOBR_24;
obx: TbsOBX_24;
sn : TbsSN_24;
begin
msg:=TbsORU_R01_24.Create;
//MSH
msh:= msg.MSH;
msh.SendingApplication.NamespaceID.AsString:='GHH LAB';
msh.SendingFacility.NamespaceID.AsString:='ELAB-3';
msh.ReceivingApplication.NamespaceID.AsString:='GHH OE';
msh.ReceivingFacility.NamespaceID.AsString:='BLDG4';
msh.DateTimeOfMessage.TimeOfAnEvent.AsString:='200202150930';
msh.MessageControlID.AsString:='CNTRL-3456';
//PID
pid:=msg.PATIENT_RESULT[0].PATIENT.PID;
pid.PatientIdentifierList[0].ID.AsString:='555-44-4444';
pid.PatientName[0].Familyname.Surname.AsString:='EVERYWOMAN';
pid.PatientName[0].Givenname.AsString:='EVE';
pid.PatientName[0].Secondandfurthergivennamesorinitialsthereof.AsString:='E';
pid.PatientName[0].Nametypecode.AsString:='L';
pid.MothersMaidenName[0].Familyname.Surname.AsString:='JONES';
pid.DateTimeOfBirth.TimeOfAnEvent.AsString:='196203520';
pid.AdministrativeSex.AsString:='F';
pid.PatientAddress[0].Streetaddress.Streetormailingaddress.AsString:='153 FERNWOOD DR.';
pid.PatientAddress[0].City.AsString:='STATESVILLE';
pid.PatientAddress[0].Stateorprovince.AsString:='OH';
pid.PatientAddress[0].Ziporpostalcode.AsString:='35292';
pid.PhoneNumberHome[0].Telephonenumber.AsString:='(206)3345232';
pid.PhoneNumberBusiness[0].Telephonenumber.AsString:='(206)752-121';
pid.PatientAccountNumber.ID.AsString:='AC555444444';
pid.DriversLicenseNumberPatient.Driverslicensenumber.AsString:='67-A4335';
pid.DriversLicenseNumberPatient.Issuingstate_province_country.AsString:='OH';
pid.DriversLicenseNumberPatient.Expirationdate.AsString:='20030520';
// OBR
obr:=msg.PATIENT_RESULT[0].ORDER_OBSERVATION[0].OBR;
obr.SetIDOBR.AsString:='1';
obr.PlacerOrderNumber.Entityidentifier.AsString:='845439';
obr.PlacerOrderNumber.NamespaceID.AsString:='GHH OE';
obr.FillerOrderNumber.Entityidentifier.AsString:='1045813';
obr.FillerOrderNumber.NamespaceID.AsString:='GHH LAB';
obr.UniversalServiceIdentifier.Identifier.AsString:='1554-5';
obr.UniversalServiceIdentifier.Text.AsString:='GLUCOSE';
obr.UniversalServiceIdentifier.Nameofcodingsystem.AsString:='LN';
obr.ObservationDateTime.TimeOfAnEvent.AsString:='200202150730';
obr.OrderingProvider[0].IDnumber.AsString:='555-55-5555';
obr.OrderingProvider[0].Familyname.Surname.AsString:='PRIMARY';
obr.OrderingProvider[0].Givenname.AsString:='PATRICIA P';
obr.OrderingProvider[0].Degree.AsString:='MD';
obr.OrderingProvider[0].Assigningauthority.NamespaceID.AsString:='LEVEL SEVEN HEALTHCARE, INC.';
obr.ResultStatus.AsString:='F';
obr.PrincipalResultInterpreter.OPName.IDNumber.AsString:='444-44-4444';
obr.PrincipalResultInterpreter.OPName.FamilyName.AsString:='HIPPOCRATES';
obr.PrincipalResultInterpreter.OPName.GivenName.AsString:='HOWARD H';
obr.PrincipalResultInterpreter.OPName.Degree.AsString:='MD';
// OBX
obx:=msg.PATIENT_RESULT[0].ORDER_OBSERVATION[0].OBSERVATION[0].OBX;
obx.SetIDOBX.AsString:='1';
obx.ValueType.AsString:='SN';
obx.ObservationIdentifier.Identifier.AsString:='1554-5';
obx.ObservationIdentifier.Text.AsString:='GLUCOSE POST 12H CFST';
obx.ObservationIdentifier.Nameofcodingsystem.AsString:='LN';
sn:=TbsSN_24.Create;
sn.Num1.AsString:='182';
obx.ObservationValue[0]:= sn;
obx.Units.Identifier.AsString:= 'mg/dl';
obx.ReferencesRange.AsString:='70-105';
obx.AbnormalFlags.AsString:='H';
obx.ObservationResultStatus.AsString:='F';
// XML format
Memo1.Lines.Append('Message Create (Advanced)');
Memo1.Lines.Text:=msg.AsXML;
FreeAndNil(msg);
end;
XML Output
<ORU_R01 xmlns="urn:hl7-org:v2xml">
<MSH>
<MSH.1>|</MSH.1>
<MSH.2>^~\&</MSH.2>
<MSH.3>
<HD.1>GHH LAB</HD.1>
</MSH.3>
<MSH.4>
<HD.1>ELAB-3</HD.1>
</MSH.4>
<MSH.5>
<HD.1>GHH OE</HD.1>
</MSH.5>
<MSH.6>
<HD.1>BLDG4</HD.1>
</MSH.6>
<MSH.7>
<TS.1>200202150930</TS.1>
</MSH.7>
<MSH.9>
<MSG.1>ORU</MSG.1>
<MSG.2>R01</MSG.2>
</MSH.9>
<MSH.10>CNTRL-3456</MSH.10>
<MSH.11>
<PT.1>P</PT.1>
</MSH.11>
<MSH.12>
<VID.1>2.4</VID.1>
</MSH.12>
</MSH>
<ORU_R01.PATIENT_RESULT>
<ORU_R01.PATIENT>
<PID>
<PID.3>
<CX.1>555-44-4444</CX.1>
</PID.3>
<PID.5>
<XPN.1>
<FN.1>EVERYWOMAN</FN.1>
</XPN.1>
<XPN.2>EVE</XPN.2>
<XPN.3>E</XPN.3>
<XPN.7>L</XPN.7>
</PID.5>
<PID.6>
<XPN.1>
<FN.1>JONES</FN.1>
</XPN.1>
</PID.6>
<PID.7>
<TS.1>196203520</TS.1>
</PID.7>
<PID.8>F</PID.8>
<PID.11>
<XAD.1>
<SAD.1>153 FERNWOOD DR.</SAD.1>
</XAD.1>
<XAD.3>STATESVILLE</XAD.3>
<XAD.4>OH</XAD.4>
<XAD.5>35292</XAD.5>
</PID.11>
<PID.13>
<XTN.1>(206)3345232</XTN.1>
</PID.13>
<PID.14>
<XTN.1>(206)752-121</XTN.1>
</PID.14>
<PID.18>
<CX.1>AC555444444</CX.1>
</PID.18>
<PID.20>
<DLN.1>67-A4335</DLN.1>
<DLN.2>OH</DLN.2>
<DLN.3>20030520</DLN.3>
</PID.20>
</PID>
</ORU_R01.PATIENT>
<ORU_R01.ORDER_OBSERVATION>
<OBR>
<OBR.1>1</OBR.1>
<OBR.2>
<EI.1>845439</EI.1>
<EI.2>GHH OE</EI.2>
</OBR.2>
<OBR.3>
<EI.1>1045813</EI.1>
<EI.2>GHH LAB</EI.2>
</OBR.3>
<OBR.4>
<CE.1>1554-5</CE.1>
<CE.2>GLUCOSE</CE.2>
<CE.3>LN</CE.3>
</OBR.4>
<OBR.7>
<TS.1>200202150730</TS.1>
</OBR.7>
<OBR.16>
<XCN.1>555-55-5555</XCN.1>
<XCN.2>
<FN.1>PRIMARY</FN.1>
</XCN.2>
<XCN.3>PATRICIA P</XCN.3>
<XCN.7>MD</XCN.7>
<XCN.9>
<HD.1>LEVEL SEVEN HEALTHCARE, INC.</HD.1>
</XCN.9>
</OBR.16>
<OBR.25>F</OBR.25>
<OBR.32>
<NDL.1>
<CNN.1>444-44-4444</CNN.1>
<CNN.2>HIPPOCRATES</CNN.2>
<CNN.3>HOWARD H</CNN.3>
<CNN.7>MD</CNN.7>
</NDL.1>
</OBR.32>
</OBR>
<ORU_R01.OBSERVATION>
<OBX>
<OBX.1>1</OBX.1>
<OBX.2>SN</OBX.2>
<OBX.3>
<CE.1>1554-5</CE.1>
<CE.2>GLUCOSE POST 12H CFST</CE.2>
<CE.3>LN</CE.3>
</OBX.3>
<OBX.5>
<SN.2>182</SN.2>
</OBX.5>
<OBX.6>
<CE.1>mg/dl</CE.1>
</OBX.6>
<OBX.7>70-105</OBX.7>
<OBX.8>H</OBX.8>
<OBX.11>F</OBX.11>
</OBX>
</ORU_R01.OBSERVATION>
</ORU_R01.ORDER_OBSERVATION>
</ORU_R01.PATIENT_RESULT>
</ORU_R01>
Send Message with Indy (v.10)
const
START_BLOCK = #$0B;
END_BLOCK = #$1C#$0D;
//Load library...
procedure TForm1.FormCreate(Sender: TObject);
begin
BSHL7Library.LoadFromFile('..\data\BSHL722.BSL');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
MsgOut : AnsiString;
MsgIn : AnsiString;
begin
MsgOut:='MSH|^~\&|TestSendingSystem||||200701011539||ADT^A01||P|2.2|123'+#13+
'PID|||123456||Doe^John'+#13;
IdTcpClient1.Port := 100;
IdTcpClient1.Host := '192.168.1.1';
IdTcpClient1.Connect;
// Send Message
IdTCPClient1.IOHandler.Write(START_BLOCK+MsgOut+END_BLOCK);
// Wait ACK Message
MsgIn := IdTCPClient1.IOHandler.ReadLn(END_BLOCK);
// Parse message...
end;
For more socket information see indy's idHL7.pas
Download Indy Project
Documentation
Download the document to get more information about this product.
This document contains :
- Installation
- Sample code for parse generate hl7 message
- Class properties and methods.
Download document Last Update : 2018-05-1
Class documentation in HTML