Skip to content

pear/Net_HL7

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HL7 API: README

Contents

1.0 Introduction
2.0 Usage
2.1 Creating messages
2.2 Sending/receiving

1.0 Introduction

This is the PHP HL7 API. It is a very simple, but rather flexible API for use in PHP applications. The API is a word for word translation of the Perl Net-HL7 package, based on version 0.72.

The focus of this API is on providing functionality for the composition, manipulation and decomposition of HL7 messages, not providing hundreds of prefab HL7 messages. In HL7 terms: this API focuses on the HL7 syntax, not the semantics. This makes the API support all versions that use the classic HL7 syntax, that is, versions untill 3.x. This API does not do XML!

2.0 Usage

2.1 Creating messages

To create an HL7 message, simply do this:

$msg = new Net_HL7_Message();

this gives you an empty message, that doesn't containt ANY segments (not even the header segment). You might also have a string representation of your message at hand, in which case you can do this:

$msg = new Net_HL7_Message(<your string>);

Make sure to escape any characters that have special meaning in PHP!

2.2 Sending/receiving

A full example of sending and receiving a message is listed here, assuming you have an HL7 server on your localhost, listening to port 12002 (you might want to use the hl7d from the Perl HL7 Toolkit package as a simple test server; http://hl7toolkit.sourceforge.net/):

<?php
require_once "Net/HL7/Segments/MSH.php";
require_once "Net/HL7/Message.php";
require_once "Net/HL7/Connection.php";

$msg  = new Net_HL7_Message();
$msg->addSegment(new Net_HL7_Segments_MSH());

$seg1 = new Net_HL7_Segment("PID");

$seg1->setField(3, "XXX");

$msg->addSegment($seg1);

echo "Trying to connect";
$socket = new Net_Socket();
$success = $socket->connect("localhost", 12002);

if ($success instanceof PEAR_Error) {
    echo "Error: {$success->getMessage()}";
    exit(-1);
}

$conn = new Net_HL7_Connection($socket);

echo "Sending message\n" . $msg->toString(true);

$resp = $conn->send($msg);

$resp || exit(-1);

echo "Received answer\n" . $resp->toString(true);

$conn->close();
?>