DelphiHL7 Guide
DelphiHL7 Guide
http://www.delphihl7.com
Version 1.6.X
2015-07-12
Delphi HL7 Guide
Contents
Introduction ............................................................................................................................................ 2
Installation .............................................................................................................................................. 2
Delphi versions .................................................................................................................................... 2
C++ Builder versions ........................................................................................................................... 2
Quick Start............................................................................................................................................... 2
Creating Message................................................................................................................................ 2
Parsing Message : ............................................................................................................................... 3
Find message's version: ...................................................................................................................... 5
Generate XML message ...................................................................................................................... 5
Outputs ........................................................................................................................................... 7
Creating custom segments,messages ..................................................................................................... 9
Create custom message types .......................................................................................................... 11
Using Terser function ........................................................................................................................ 13
Send Message with Indy (v.10) ......................................................................................................... 13
Files ....................................................................................................................................................... 14
Components .......................................................................................................................................... 14
Classes ................................................................................................................................................... 14
TdiList Class ....................................................................................................................................... 15
Properties...................................................................................................................................... 15
Methods ........................................................................................................................................ 15
TdiMessage Class .............................................................................................................................. 16
Types ............................................................................................................................................. 16
Methods ........................................................................................................................................ 16
Properties...................................................................................................................................... 16
1-18
Delphi HL7 Guide
Introduction
Delphi components for handling HL7 (Health Level Seven) messages. DelphiHL7 can
generate and parse HL7 messages. You can develop easy your applications for
communicate lab. devices or other healthcare systems.
■ Supports HL7 2.2, 2.3, 2.3.1, 2.4, 2.5, 2.5.1, 2.6 versions.
■ You can use with Delphi 5, 6, 7, 2005, 2006, 2007, 2009, 2010, XE, XE2,
XE3, XE4, XE5, XE6, XE7, XE8.
■ and C++ Builder 2009, 2010, XE, XE2, XE3, XE4, XE5, XE6.
■ %100 Native delphi code. No DLL No OCX.
■ It's support message groups and nested groups.
■ Support for all HL7 data types.
■ Support custom message types .
■ Support custom segment (Z Segment) types.
■ Access to fields using a terse location specification syntax.
■ You can get/set values AsString property
■ You can get XML document AsXML property
■ Licensed royalty-free per developer, per team, or per site
Installation
Delphi versions
1. First install dhbasedX.dpk package. This package contains base common classes.
(where X is your delphi version number).
2. Install your need dhXXdZ.dpk package.
(where XX is hl7 version, Z is delphi version : dh22d15.dpk )
if installation is succesfull you can see this images in “Delphi HL7” tab.
Quick Start
Creating Message
2-18
Delphi HL7 Guide
Easy to create a new class. You need to know which message type and HL7 version you
want to create. For creating new message ADT^A01 for HL7 version 2.2. Your class is :
TdiADT_A01_22.
uses diHL722, diHL7DT22, diHL7Grp22;
Memo1.Lines.Text:= msg.AsString;
{
MSH|^~\&|TestSendingSystem||||200701011539||ADT^A01||P|2.2|123
PID|||123456||Doe^John
}
FreeAndNil(msg);
end;
Parsing Message :
uses diHL722, diHL7DT22, diHL7Grp22;
3-18
Delphi HL7 Guide
begin
MsgStr :=
'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|||||';
msg := TdiORU_R01_22.Create;
msg.AsString := MsgStr; //Parse message
Patient:=msg.PATIENT_RESULT[0].PATIENT.PID.PatientName;
// Shows John
ShowMessage( Patient.GivenName.AsString );
for i := 0 to 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+
TdiST_22(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
4-18
Delphi HL7 Guide
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;
//MSH
msh:= msg.MSH;
msh.SendingApplication.NamespaceID.AsString:='GHH LAB';
msh.SendingFacility.NamespaceID.AsString:='ELAB-3';
msh.ReceivingApplication.NamespaceID.AsString:='GHH OE';
5-18
Delphi HL7 Guide
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:=TdiSN_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';
// Standart format
6-18
Delphi HL7 Guide
Memo1.Lines.Text:=msg.AsString;
// XML format
Memo1.Lines.Text:=msg.AsXML;
FreeAndNil(msg);
end;
Outputs
Standart format
MSH|^~\&|GHH LAB|ELAB-3|GHH OE|BLDG4|200202150930||ORU^R01|CNTRL-3456|P|2.4
PID|||555-44-4444||EVERYWOMAN^EVE^E^^^^L|JONES|196203520|F|||153 FERNWOOD
DR.^^STATESVILLE^OH^35292||(206)3345232|(206)752-121||||AC555444444||67-
A4335^OH^20030520
OBR|1|845439^GHH OE|1045813^GHH LAB|1554-5^GLUCOSE^LN|||200202150730|||||||||555-
55-5555^PRIMARY^PATRICIA P^^^^MD^^LEVEL SEVEN HEALTHCARE, INC.|||||||||F|||||||444-
44-4444&HIPPOCRATES&HOWARD H&&&&MD
OBX|1|SN|1554-5^GLUCOSE POST 12H CFST^LN||^182|mg/dl|70-105|H|||F
XML Format
<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>
7-18
Delphi HL7 Guide
<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>
8-18
Delphi HL7 Guide
All segments must be inherited from TdiSegment. Your segment must have getter and setter
methods.
For example : ifcondition field is ST (String) type.
protected
function Getifcondition: TdiST_24; // Getter method
procedure Setifcondition(const Value: TdiST_24); // Setter method
9-18
Delphi HL7 Guide
public
property ifcondition : TdiST_24 read Getifcondition write Setifcondition
end;
Definitions.Add(
'ifcondition', // Field name must be unique
TdiST_24, // Field Type
0, // Minimum number of repetitions. if 0 is optional
1 // Maximum number of repetitions. if 0 is optional.
// if -1 is unbounded
);
Methods implementation
unit uZINsegment;
interface
uses
diHL7Base,diHL724,diHL7DT24,diHL7Grp24;
type
TdiZIN_24 = class(TdiSegment)
protected
function Getifcondition: TdiST_24;
function Getcondition: TdiST_24;
procedure Setifcondition(const Value: TdiST_24);
procedure Setcondition(const Value: TdiST_24);
public
property ifcondition : TdiST_24 read Getifcondition write
Setifcondition;
property condition : TdiST_24 read Getcondition write Setcondition;
procedure Init;override;
end;
implementation
{ TdiZIN_24 }
procedure TdiZIN_24.Init;
begin
inherited;
Name :='ZIN';
10-18
Delphi HL7 Guide
Definitions.Add('condition',TdiST_24,0,1);
Definitions.Add('ifcondition',TdiST_24,0,1);
end;
initialization
diRegisterClass(TdiZIN_24,'ZIN','2.4');
finalization
diUnRegisterClass(TdiZAU_24);
end.
Example :
We want to need custom ZQI_Z01 message type for hl7 v2.4. It‟s contains MSH, PRD, PID
segments.
interface
uses Classes,SysUtils,diHL7Base,diHL724,diHL7DT24;
TdiZQI_Z01_24= class(TdiMessage)
protected
function GetMSH : TdiMSH_24;
procedure SetMSH(Value : TdiMSH_24);
function GetPRD : TdiPRD_24;
procedure SetPRD(Value : TdiPRD_24);
function GetPID : TdiPID_24;
11-18
Delphi HL7 Guide
implementation
{ TdiZQI_Z01_24 }
procedure TdiZQI_Z01_24.Init;
begin
inherited;
Name :='ZQI_Z01';
MessageType :='ZQI';
TriggerEvent :='Z01';
HL7Version :='2.4';
// Segment’s Name,DataType, Minumum also Maximum rep. count and parent node.
Definitions.Add('MSH',TdiMSH_24,1,1);
Definitions.Add('MSA',TdiMSA_24,1,1);
Definitions.Add('ZAU',TdiZAU_24,1,1);
Definitions.Add('PRD',TdiPRD_24,1,1);
Definitions.Add('PID',TdiPID_24,0,1);
Definitions.Add('IN1',TdiIN1_24,0,1);
Definitions.Add('ZIN',TdiZIN_24,0,1);
Parse(InitMsg);
end;
12-18
Delphi HL7 Guide
SetStructure('PID',0,Value);
end;
initialization
diRegisterClass(TdiZQI_Z01_24,'ZQI_Z01', '2.4');
finalization
diUnRegisterClass(TdiZQI_Z01_24);
end.
Memo1.Lines.Text:= msg.AsString;
{
MSH|^~\&|TestSendingSystem||||201112011539||ADT^A01||P|2.2|123
PID|||123456~7890||Doe^John
}
FreeAndNil(msg);
end;
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;
13-18
Delphi HL7 Guide
// Send Message
IdTCPClient1.IOHandler.Write(START_BLOCK+MsgOut+END_BLOCK);
end;
Files
diHL7Base Base class for all data types, groups and messages.
Components
Classes
TPersistent
|
TdiNode
14-18
Delphi HL7 Guide
|
TdiSegment
|
TdiSegmentList
|
TdiSegmentGroup
|
TdiMessage
TdiNode Class
Properties
Name WideString Define HL7 name, HL7 v2.2 MSH segment „MSH‟, for PN data type
„PN‟
Methods
function GetStructure(Name : WideString; RepCount : Integer =0 ):TdiNode;
Wraps a message to provide access to fields using a terse location specification syntax. For
example:
message.Terser(’MSH-13-1’).AsString:= ‘123’;
message.MSH.Sequencenumber.AsString:=’123’;
15-18
Delphi HL7 Guide
location_spec: segment_path_spec "-" field ["(" rep ")"] ["-" component ["-"
subcomponent]]
... where rep, field, component, and subcomponent are integers (representing, respectively,
the field repetition (starting at 1), and the field number, component number, and
subcomponent numbers (starting at 1). Omitting the rep is equivalent to specifying 1.
TdiMessage Class
Types
TdiFileType = (ftAuto,ftER7,ftXML);
ftAuto : When using LoadFromFile, LoadFromSteam methods, checks file content. For
SaveToFile, SaveToStream methods behaves like ftER7.
ftER7: File Type ER7.
ftXML: File Type XML.
Methods
procedure LoadFromFile(const FileName: WideString;FileType : TdiFileType=ftAuto);
Properties
AsString WideString Gets/Sets HL7 Message with ER7 format
16-18
Delphi HL7 Guide
ParseNonStandartMessages Boolean Used for parse non standart messages. For set,
get operations used Terser method.
17-18