NAME
Net::HL7::Message
SYNOPSIS
my $request = new Net::HL7::Request(); my $conn = new Net::HL7::Connection('localhost', 8089);
my $seg1 = new Net::HL7::Segment("PID");
$seg1->setField(1, "foo");
$request->addSegment($seg1);
my $response = $conn->send($request);
DESCRIPTION
In general one needn't create an instance of the Net::HL7::Message class directly, but use the Net::HL7::Request class. The Message will be created with a MSH segment as it's first segment.
METHODS
$m = new Net::HL7::Message()
The constructor takes an optional string argument that is a string representation of a HL7 message. This makes it easy for the Net::HL7::Connection object to return new HL7 messages from a server.
Set the segment at index to segment. The segment should be an instance of Net::HL7::Segment. If the idnex is not given, the segment is added to the end of the message.
getSegmentByIndex($index)
Return the segment specified by $index.
toString($pretty)
Return a string representation of this message. This can be used to send over a Net::HL7::Connection. To print to other output, use provide the $pretty argument as some true value. This will skip the HL7 control characters, and use '\n' instead.
DESCRIPTION
The HL7::Message represents both the request and the answer to and from the HL7 broker. The message can be constructed in two ways: based on a message template, and based on setting individual segment values. The first method goes like this:
my $msg = new HL7::Message();
my $tpl = " MSH|^~\&|ME|SYSTEM|YOU|TDM|${sysdate;%14s}||DFT^P03|${id;%16s}|P|2.4|||AL|NE| EVN||${sysdate;%14s}| ";
$msg->useTemplate($tpl);
my $now = strftime "%Y%m%d%H%M%S", localtime; my $ext = rand(1); $ext =~ s/^0\.([0-9]{5}).*$/\.$1/;
$msg->setTemplateField("sysdate", $now $msg->setTemplateField("id", "$now$ext"); ...
The template contains slots in the following format:
${<name>;<format>}
Setting a value to a name with the setTemplateField
method will replace the slot with the value formatted in the format specified, so for instance ${pipo;%06s}
set with setTemplateField("pipo", "foo")
would render '000foo'. See sprintf for details.
The other way is to just create a new message (either with or without an initial header) like so:
my $msg = new HL7::Message();
$msg->setField("MSH", 4, strftime("%Y%m%m%H%M%S", localtime));
Use the toString
method to see what the message looks like.
METHODS
setField($segment, $index, $value)
Set the indexed value of segment specified by the argument. If the segment doesn't exist, it is created.
getField($segment, $index)
Get the value at the specified index from segment.
toString()
Return the message as a string. The special HL7 segment terminators are translated into end of line characters.
useTemplate($template)
Use a template for the message. The template is a string containing field definitions like:
${name;format}
The format is just like formatting strings used in printf
.
A message template could look something like this:
MSH|^~\&|ME|SYSTEM|YOU|TDM|${sysdate;%14s}||DFT^P03|${id;%16s}|P|2.4|||AL|NE| EVN||${sysdate;%14s}| ";
setTemplateField($field, $value)
Set the field specified by $field to $value. This only makes sense when a template is used.
setTemplateFields(\%fields)
Set the fields specified by the keys of the hashref to the values.
AUTHOR
D.A.Dokter <dokter@wyldebeast-wunderliebe.com>
LICENSE
Copyright (c) 2002 D.A.Dokter. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 116:
Unknown directive: =head