0% found this document useful (0 votes)
278 views

DelphiHL7 Guide

This document provides an overview and quick start guide for using the Delphi HL7 Guide component library for handling HL7 messages in Delphi. The library allows developers to generate and parse HL7 messages, create custom message types and segments, and includes classes, components, and files to work with HL7 version 2.2 through 2.6 messages. The guide provides instructions on installation, creating and populating message objects, parsing messages, and includes examples of creating and sending HL7 messages.

Uploaded by

أبو شفاء
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
278 views

DelphiHL7 Guide

This document provides an overview and quick start guide for using the Delphi HL7 Guide component library for handling HL7 messages in Delphi. The library allows developers to generate and parse HL7 messages, create custom message types and segments, and includes classes, components, and files to work with HL7 version 2.2 through 2.6 messages. The guide provides instructions on installation, creating and populating message objects, parsing messages, and includes examples of creating and sending HL7 messages.

Uploaded by

أبو شفاء
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Delphi HL7 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 )

C++ Builder versions


1. First install dhbasecX.cbproj package. This package contains base common
classes. (where X is your C++ Builder version number)
2. Install your need dhXXcZ.cbproj package.
(XX is hl7 version, Z is C++ Builder version : dh22c15.cbproj )

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;

procedure TForm1.diMessageCreateClick(Sender: TObject);


var
msg : TdiADT_A01_22;
begin
msg := TdiADT_A01_22.Create;
// Populate the MSH Segment
//adt_a01.MSH.FieldSeparator.Value:='|'; Default Value
//adt_a01.MSH.Encodingcharacters.Value:='^~\&'; Default Value
msg.MSH.Sendingapplication.AsString:='TestSendingSystem';
//adt_a01.MSH.DateTimeofmessage.TimeOfAnEvent.AsString:='200701011539';
// Default Value is System Date Time
//adt_a01.MSH.Messagetype.MessageType.AsString:='ADT'; Default Value
//adt_a01.MSH.Messagetype.TriggerEvent.AsString:='A01'; Default Value
//adt_a01.MSH.ProcessingID.AsString:='P'; Default Value
//adt_a01.MSH.VersionID.AsString:='2.2'; Default Value
msg.MSH.Sequencenumber.AsString:='123';
// Populate the PID Segment
msg.PID.PatientName.FamilyName.AsString:='Doe';
msg.PID.PatientName.GivenName.AsString:='John';
msg.PID.PatientID1[0].IDNumber.AsString:='123456';

Memo1.Lines.Text:= msg.AsString;

{
MSH|^~\&|TestSendingSystem||||200701011539||ADT^A01||P|2.2|123
PID|||123456||Doe^John
}
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';
Value Used to assign a value to the area. If the value is not encoded in the
special separator characters.
adt_a01.MSH.FieldSeparator.Value:='|';
AsBase64 Reads Base64 value and return decoded string. When setting field
encoded raw string to Base64.

Parsing Message :
uses diHL722, diHL7DT22, diHL7Grp22;

procedure TForm1.diMessageParseClick(Sender: TObject);


var
msg : TdiORU_R01_22;
Patient : TdiPN_22;
observation : TdiORU_R01_PATIENT_RESULT_ORDER_OBSERVATION_OBSERVATION_22;
MsgStr : WideString;
i : integer;

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 );

Memo1.Lines.Add( 'OBSERVATIONRepCount : ' + IntToStr(


msg.PATIENT_RESULT[0].ORDER_OBSERVATION[0].OBSERVATIONRepCount)
);

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;

Find message's version:


uses diHL7Base;
{
TdiMessageInfo = record
FieldSeparator: WideString;
EncodingCharacters: WideString;
ProcessingID: WideString;
MessageControlID: WideString;
MessageType: WideString;
Version: WideString;
end;
}
procedure TForm1.Button1Click(Sender: TObject);
var
mi: TdiMessageInfo;
msg: WideString;
begin
msg:='MSH|^~\&|TestSendingSystem||||200701011539||ADT^A01||P|2.2|123'+#13+
'PID|||123456||Doe^John';

//function GetMessageInfo(Message: WideString): TdiMessageInfo;


mi := GetMessageInfo(msg);
ShowMessage(mi.Version);
// Shows : 2.2
end;

Generate XML message


procedure TForm1.bGenerateXMLMsg(Sender: TObject);
var
msg : TdiORU_R01_24;
msh : TdiMSH_24;
pid: TdiPID_24;
obr: TdiOBR_24;
obx: TdiOBX_24;
sn : TdiSN_24;
begin
msg:=TdiORU_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';

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>^~\&amp;</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

<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>

Creating custom segments,messages


You can create custom segments, groups and messages. Following is a simple walkthrough
that will demonstrate how to define z-segments class.

In the example below we will be adding a ZIN segment to an HL7 2.4.

ZIN attributes are provided below:


SEQ DATA TYPE ELEMENT NAME
1 ST Ifcondition
2 ST Condition

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;

Segments Init method create and set field properties

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

function TdiZIN_24.Getifcondition: TdiST_24;


begin
// Gets ifcondition and first rep. field value
Result:= TdiST_24(GetStructure('ifcondition',0));
end;

procedure TdiZIN_24.Setifcondition(const Value: TdiST_24);


begin
// Sets ifcondition and first rep. value
SetStructure('ifcondition',0,Value);
end;

Sample Unit file:

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;

function TdiZIN_24.Getcondition: TdiST_24;


begin
Result:= TdiST_24(GetStructure('condition',0));
end;

function TdiZIN_24.Getifcondition: TdiST_24;


begin
Result:= TdiST_24(GetStructure('ifcondition',0));
end;

procedure TdiZIN_24.Setcondition(const Value: TdiST_24);


begin
SetStructure('condition',0,Value);
end;

procedure TdiZIN_24.Setifcondition(const Value: TdiST_24);


begin
SetStructure('ifcondition',0,Value);
end;

initialization
diRegisterClass(TdiZIN_24,'ZIN','2.4');

finalization
diUnRegisterClass(TdiZAU_24);

end.

Create custom message types


When creating a new custom message type, you must derive from the TdiMessage class.

Example :
We want to need custom ZQI_Z01 message type for hl7 v2.4. It‟s contains MSH, PRD, PID
segments.

// Custom message unit.


unit MyUnit;

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

procedure SetPID(Value : TdiPID_24);


public
property MSH : TdiMSH_24 read GetMSH write SetMSH;
property PRD : TdiPRD_24 read GetPRD write SetPRD;
property PID : TdiPID_24 read GetPID write SetPID;
procedure Init;override;
end;

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;

function TdiZQI_Z01_24.GetMSH: TdiMSH_24;


begin
Result:=TdiMSH_24(GetStructure('MSH',0));
end;

function TdiZQI_Z01_24.GetPRD: TdiPRD_24;


begin
Result:=TdiPRD_24(GetStructure('PRD',0));
end;

function TdiZQI_Z01_24.GetPID: TdiPID_24;


begin
Result:=TdiPID_24(GetStructure('PID',0));
end;

procedure TdiZQI_Z01_24.SetMSH(Value: TdiMSH_24);


begin
SetStructure('MSH',0,Value);
end;

procedure TdiZQI_Z01_24.SetPRD(Value: TdiPRD_24);


begin
SetStructure('PRD',0,Value);
end;

procedure TdiZQI_Z01_24.SetPID(Value: TdiPID_24);


begin

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.

Using Terser function


uses diHL722, diHL7DT22, diHL7Grp22;

procedure TForm1.diTerserTestClick(Sender: TObject);


var
msg : TdiADT_A01_22;
begin
msg := TdiADT_A01_22.Create;

// Populate the MSH Segment


msg.Terser('/MSH-3-1').AsString:='TestSendingSystem';
msg.Terser('/MSH-13-1').AsString:='123';

// Populate the PID Segment


msg.Terser('/PID-5-1').AsString:='Doe';
msg.Terser('/PID-5-2').AsString:='John';
msg.Terser('/PID-3-1').AsString:='123456';
msg.Terser('/PID-3(2)-1').AsString:='7890';

Memo1.Lines.Text:= msg.AsString;

{
MSH|^~\&|TestSendingSystem||||201112011539||ADT^A01||P|2.2|123
PID|||123456~7890||Doe^John
}
FreeAndNil(msg);
end;

Send Message with Indy (v.10)


const
START_BLOCK = #$0B;
END_BLOCK = #$1C#$0D;

procedure TForm1.Button1Click(Sender: TObject);


var
MsgOut : WideString;
MsgIn : WideString;
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;

13-18
Delphi HL7 Guide

// 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

Files
diHL7Base Base class for all data types, groups and messages.

diHL7XX Defines HL7 XX messages (ADT_A01 : TdiADT_A01_22)

diHL7DTXX Defines Data Types for HL7 XX (Segments:MSH,Fields:ST...)

diHL7GrpXX Defines Message Groups for HL7 XX (TdiADT_A01_INSURANCE_22)

Where XX HL7 version.

Components

Contains HL7 v 2.2 definition.

Contains HL7 v 2.3 definition.

Contains HL7 v 2.3.1 definition.

Contains HL7 v 2.4 definition.

Contains HL7 v 2.5 definition.

Contains HL7 v 2.5.1 definition.

Contains HL7 v 2.6 definition.

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;

Gets specified name and Rep. object.

procedure SetStructure(Name : WideString; RepCount : Integer; Value : TPersistent);

Sets specified name and Rep. Object..

function Definition.Add(Name:String; ClassType : TClass; Minimum : Integer=0;


Maximum : Integer=-1; TypeDefIndex: Integer = -1 ): TdiDefinition;

Define class‟s Name,DataType, Minumum,Maximum,TypeDefIndex field.

function Terser(Path: WideString): TdiString;

Wraps a message to provide access to fields using a terse location specification syntax. For
example:

message.Terser(’MSH-13-1’).AsString:= ‘123’;

can be used instead of

message.MSH.Sequencenumber.AsString:=’123’;

The syntax of a location spec is as follows:

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);

Read message from file.


If the FileType parameter is not given, then the message loaded using the ftAuto type.

procedure SaveToFile(const FileName: WideString;FileType : TdiFileType=ftAuto);

Save message to file.


If the FileType parameter is not given, then the message loaded using the ftAuto type.

procedure LoadFromStream(const Stream: TStream;FileType : TdiFileType=ftAuto);

Read message from stream.


If the FileType parameter is not given, then the message loaded using the ftAuto type.

procedure SaveToStream(const Stream: TStream;FileType : TdiFileType=ftAuto);

Save message to stream.


If the FileType parameter is not given, then the message loaded using the ftAuto type.

Properties
AsString WideString Gets/Sets HL7 Message with ER7 format

16-18
Delphi HL7 Guide

AsXML WideString Gets HL7 Message with XML format

SegmentSeparator WideString Define segment separator. Default : #13

FieldSeparator WideString Define field separator. Default : |

ComponentSeparator WideString Define component separator. Default : &

RepetitionSeparator WideString Define repetition separator. Default : ~

SubcomponentSeparator WideString Define subcomponent separator. Default : ^

EscapeCharacter WideChar Define escape character. Default : \

TrimBlankSeparators Boolean Trims blank field,component,subcomponent


separators. Default : True

EnableEscapedValues Boolean Use unicode values, do not use escape


characters for encoding. Default :True, used
escaped characters.

ParseNonStandartMessages Boolean Used for parse non standart messages. For set,
get operations used Terser method.

17-18

You might also like