Giter VIP home page Giter VIP logo

net_hl7's Introduction

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();
?>

net_hl7's People

Contributors

clockwerx avatar kenguest avatar till avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

net_hl7's Issues

$conn->close();

PHP Fatal error: Uncaught Error: Call to undefined method Net_HL7_Connection::close()

Message parsing does not preserve empty components

Using Net_HL7_Message($string), if a segment contains a field that has empty components, those empty components are removed when the string is parsed. For example:

$msgstr = 'MSH|^~\&|SOME_SOURCE||||20180723115125||DFT^P03|2018072311512590201|P|2.2||||NE|' . "\n" .
'PV1|1|POFFV|723327^^^SLM^^^^^^^DEPID|3|||16367^LAST^FIRST^^^^^^EPROV^^^^PROVID|||||||2|||||300023352295|SELF||||||||||||||||||||||||20180123152601||||||100000000375|';

$msg = new Net_HL7_Message($msgstr);
error_log ($msg->toString(true));

results in:

MSH|^~\&|SOME_SOURCE||||20180723115125||DFT^P03|2018072311512590201|P|2.2||||NE|
PV1|1|POFFV|723327^SLM^DEPID|3|||16367^LAST^FIRST^EPROV^PROVID|||||||2|||||300023352295|SELF||||||||||||||||||||||||20180123152601||||||100000000375|

The problem seems to stem from line 165 in Message.php:

$comps = preg_split("/\\" . $this->_componentSeparator ."/", $fields[$j], -1, PREG_SPLIT_NO_EMPTY);

The PREG_SPLIT_NO_EMPTY flag should not be present, I believe.

Response takes too long

When sending a message, the response takes about half a minute.

I tracked down the cause:
In the Net_HL7_Connection class, the send function iteratively reads 256 byte from the socket file pointer at once, until the message suffix is detected. But the last read operation takes very long.
I think it is, because the last buffer may not be filled completely up to 256 bytes.

Error while receiving ACK

PHP Fatal error: Uncaught InvalidArgumentException: Name should be 3 characters, uppercase in Net/HL7/Segment.php:58

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.