Hl7_dict Documentation

This documentation forms an overview. The classes
are mostly fully documented in the source

Getting Started
===============

In order to use the hl7_dict library, HL7 
metadata is required. 

Somewhere in your start up code, you must
create the Global Hl7 dictionary

uses 
  Hl7_dict, Hl7_dict_bde;

procedure startup;
begin
  ...
  GHL7Dict := THL7DictionaryList.create(THL7BDEDictionary.create('hl7dict'), nil);
end;

The Hl7dict BDE alias must point to the standard Microsoft Access Database
available from http://www.hl7.org. The second parameter provides XML
encoding services, and you do not need to provide it unless you are using XML

Once you have created the global HL7 Dictionary, you can use any 
HL7 version defined in that database. (potentially 2.1 -> 2.4)


Working with messages
=====================

To read a message, you need to do the following things:

1. create a THL7Message object
2. Decode the message

var
  LMsg : THL7Message;
begin
  LMsg := THL7Message.create;
  try
    LMsg.Decode();

Once the message is decoded, they are kept in a tree structure.
There is many ways to read the tree. The most common way is simply
to refer to an element by it's HL7 name.

FOr instance, the Version of the message is stored in the 
1st component of the 12th field of the MSH segment (v2.3.1+).
So
  LMsg['MSH-3.1']
is a handle to the data element for this component. You then use 
one of the typed properties to access the data itself.
i.e.
  Assert(LMsg['MSH-3.1'].AsString = '2.3.1');

Some of the MSH header is exposed directly as properties.

There is 2 different modes for writing messages. The first mode
is where an acknowledgement message is being written. In this case,
You can ask the message to be built like this.

var
  LMsgIn : THL7Message;
  LMsgOut : THL7Message;
begin
  LMsgIn := THL7Message.create;
  try
    LMsgIn.Decode();
    LMsgOut := THL7Message.create;
    try
      LMsgOut.BuildAsReply(LMsgIn);

This will build the appropriate segments for an ACK message and
populate as possible. You must set MSA-1 manually. (See also 
SetException). You access the data elements and components in
the same as when reading a message

In the second mode, and new message is being written. In this case,
you must 
* create a message
* Set the version
* Set the event, message type, msg id, and other MSH Fields as 
  required

The version must be set first, to allow the message to bind to an 
HL7 dictionary

Once the message is fully populated, you encode it to a string:

  LSource := LMsg.Encode;


Other functionality
===================
* You can transfer the database out of the microsoft access database
  into a text format for distribution with your application
* you can obtain various views of the HL7 dictionary and messages
* you can read and write HL7 batches


XML Support
===========
XML encoding and decoding is partially supported in this release. 
The encoding is reasonably compliant with the 2nd membership ballot 
for XML encoding of V2 message (v2.xml). 

In order to use this you will need a copy of the HL7 v2.xml 
schemas. These have not been released yet. This documentation will
be updated once the release policy for the schemas has been 
formulated.


