Besa HL7 Component Getting Started

BesaHL7 is Delphi components for handling HL7 (Health Level Seven) messages. BesaHL7 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, 2.7, 2.7.1, 2.8, 2.8.1, 2.8.2 versions.

  • You can use with Delphi 7, 2005, 2006, 2007, 2009, 2010, XE-XE10, 10.1, 10.2, 10.3, 10.4, 11

  • Free Pascal 2.6.4 and 3.0.0 (Windows, Linux, Wince,RaspBerry...)

  • %100 Native pascal code. No DLL No OCX.

  • Application development for Cross Platforms.

  • 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 AsHL7/AsString property.

  • You can get XML document AsXML property.

  • Licensed royalty-free per developer, per team, or per site.

Contents:

  1. Installation
  2. Load Library
  3. Create a HL7 Message
  4. Parse a HL7 Message

Installation

This topic contains the environment changes made by the BesaHL7 installer. If you are having problems with using BesaHL7 or compiling BesaHL7-based products, check this list to make sure that your system is properly configured.

  1. Install BSCoreX.dpk package. This package contains base common classes. (where X is your delphi version number.)

  2. Install BSHL7CoreX.dpk package. This package contains base common HL7 classes. (where X is your delphi version number.)

  3. Install your need BSHL7XXDZ.dpk package. (where XX is hl7 version, Z is delphi version : bsHL722D15.dpk )

if installation is succesfull you can see “Besa HL7” tab in your component palette.

Load Library

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;

Create a HL7 Message

To create a new message you need only create a message and set fields.

For creating ADT_A01 message for version HL7 2.2.

//Load library...
procedure TForm1.FormCreate(Sender: TObject);
begin
  BSHL7Library.LoadFromFile('BSHL722.BSL');
end;

// Create ADT_A01 messsage and set fields.						
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;

For creating ORU_R01 message for version HL7 2.4.

//Load library...
procedure TForm1.FormCreate(Sender: TObject);
begin
  BSHL7Library.LoadFromFile('BSHL724.BSL');
end;

// Create ORU_R01 messsage and set fields.						
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';

  
  Memo1.Lines.Text:=msg.AsHL7;

  FreeAndNil(msg);
end;
{
// Output:
MSH|ˆ˜\&|GHH LAB|ELAB-3|GHH OE|BLDG4|200202150930||ORUˆR01|CNTRL-3456|P|2.4<cr>
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<cr>
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<cr>
OBX|1|SN|1554-5ˆGLUCOSE POST 12H CFSTˆLN||ˆ182|mg/dl|70-105|H|||F<cr>
OBX|2|ED|||ˆTEXTˆPDFˆBase64ˆPDF_BASE64_STR<cr> 
}

Parse a HL7 Message

For parse a HL7 string, you need only create a equvalent message and set HL7 string.

If you do not know about message type, you can use GetMessageInfo function.

var
  mi: TBSHL7MessageInfo
  msg : String;
begin
  msg:='MSH|ˆ˜\&||Sending|||20170609200200||ADTˆA01||P|2.2|123'+#$D+
       'EVN|'+#$D+
       'PID|||123456||DoeˆJohn'+#$D+
       'PV1|'+#$D#$A;

  mi:=GetMessageInfo(msg);

  //mi.FieldSeparator:='|';
  //mi.ComponentSeparator:='ˆ';
  //mi.RepetitionSeparator:='˜';
  //mi.SubcomponentSeparator:='&';
  //mi.EscapeCharacter:='\';
  //mi.EncodingCharacters:='ˆ˜\&';
  //mi.ProcessingID:='P';
  //mi.MessageControlID:='';
  //mi.MessageType:='ADTˆA01';
  //mi.Version:='2.2';
end;

For this message you must create an instance from TbsADT_A01_22 class.

//Load library...
procedure TForm1.FormCreate(Sender: TObject);
begin
  BSHL7Library.LoadFromFile('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;

Parse lab results:

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;


Generated by PasDoc 0.14.0.