Go to the first, previous, next, last section, table of contents.

Send and receive messages with iostreams

Any HL7 application will at some point receive a HL7 message from somewhere, at an other point a message is sent to somewhere. Sending or receiving of messages with ProtoGen/HL7 means reading and writing them to and from a stream. The stream may be linked to a file or a socket, ProtoGen/HL7 does not care about this. Since C++ iostream stream abstraction is used, you can send and receive HL7 messages like you would read or write any other I/O in C++ using iostreams. For example:

istream is;
ostream os;
ACKmsg ack;

is >> ack;

os << ack;

This reads an acknowledgement (ACK) message from the stream is and outputs it on an other stream os.

One would expect a HL7 stream to come as three classes: class hl7istream derived from class istream, class hl7ostream derived from class ostream, and class hl7iostream derived from class hl7istream and class hl7ostream. ProtoGen/HL7 will provide this in future releases, however until then you have to take a slight inconvenience: Any iostream that is dedicated to transport HL7 messages must be prepared to do so. This is done according to the following example:

iostream hl7ios;
xios hl7xios(hl7ios);

An object named hl7xios is declared to be of class xios and initialized with an ordinary iostream object. The xios object is not used after it is constructed. Any HL7 communication is sent via the iostream object after it is thus prepared. This is certainly a little confusing but will be cleaned up in a future release of ProtoGen/HL7.

An iostream that is prepared to transport HL7 messages can be in one of two modes that decides how HL7 messages are to be encoded: hl7er or debug. If a HL7 message shall be sent or received, the stream must be in the "hl7er" mode, which means that the HL7 objects are encoded using the HL7 encoding rules. The "debug" mode is used for a structured output that can be used in log files. The debug output can be configured in xios.h during compile time of the HL7 class library. It is not possible to read back a message that has been written using the debug mode.

The modes are set using the manipulators hl7er and debug. A freshly prepared HL7 stream is always in "hl7er" mode.

Go to the first, previous, next, last section, table of contents.