Exemplo n.º 1
0
 /**
  * Usage:
  * <code>
  * $ack = new Net_HL7_Messages_ACK($request);
  * </code>
  *
  * Convenience module implementing an acknowledgement (ACK) message. This
  * can be used in HL7 servers to create an acknowledgement for an
  * incoming message.
  *
  * @version    0.10
  * @author     D.A.Dokter <*****@*****.**>
  * @access     public
  * @category   Networking
  * @package    Net_HL7
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  */
 public function __construct($req = "", $reqMsh = null)
 {
     parent::__construct();
     if ($req) {
         $msh = $req->getSegmentByIndex(0);
         if ($msh) {
             $msh = new Net_HL7_Segments_MSH($msh->getFields(1));
         } else {
             $msh = new Net_HL7_Segments_MSH();
         }
     } else {
         $msh = new Net_HL7_Segments_MSH();
     }
     $msa = new Net_HL7_Segment("MSA");
     // Determine acknowledge mode: normal or enhanced
     //
     if ($req && ($msh->getField(15) || $msh->getField(16))) {
         $this->_ACK_TYPE = "E";
         $msa->setField(1, "CA");
     } else {
         $this->_ACK_TYPE = "N";
         $msa->setField(1, "AA");
     }
     $this->addSegment($msh);
     $this->addSegment($msa);
     $msh->setField(9, "ACK");
     // Construct an ACK based on the request
     if ($req && $reqMsh) {
         $msh->setField(3, $reqMsh->getField(5));
         $msh->setField(4, $reqMsh->getField(6));
         $msh->setField(5, $reqMsh->getField(3));
         $msh->setField(6, $reqMsh->getField(4));
         $msa->setField(2, $reqMsh->getField(10));
     }
 }
Exemplo n.º 2
0
 public function test()
 {
     $msg = new Net_HL7_Message();
     $msg->addSegment(new Net_HL7_Segments_MSH());
     $msh = $msg->getSegmentByIndex(0);
     $msh->setField(15, "AL");
     $msh->setField(16, "NE");
     $ack = new Net_HL7_Messages_ACK($msg);
     $seg1 = $ack->getSegmentByIndex(1);
     $this->assertTrue($seg1->getField(1) == "CA", "Error code is CA");
     $msg = new Net_HL7_Message();
     $msh = new Net_HL7_Segments_MSH();
     $msh->setField(15, "");
     $msh->setField(16, "NE");
     $msg->addSegment($msh);
     $ack = new Net_HL7_Messages_ACK($msg);
     $seg1 = $ack->getSegmentByIndex(1);
     $this->assertTrue($seg1->getField(1) == "CA", "Error code is CA");
     $msg = new Net_HL7_Message();
     $msh = new Net_HL7_Segments_MSH();
     $msh->setField(16, "");
     $msh->setField(15, "");
     $msg->addSegment($msh);
     $ack = new Net_HL7_Messages_ACK($msg);
     $seg1 = $ack->getSegmentByIndex(1);
     $this->assertTrue($seg1->getField(1) == "AA", "Error code is AA");
     $ack->setAckCode("E");
     $this->assertTrue($seg1->getField(1) == "AE", "Error code is AE");
     $ack->setAckCode("CR");
     $this->assertTrue($seg1->getField(1) == "CR", "Error code is CR");
     $ack->setAckCode("CR", "XX");
     $this->assertTrue($seg1->getField(3) == "XX", "Set message and code");
     $msg = new Net_HL7_Message();
     $msg->addSegment(new Net_HL7_Segments_MSH());
     $msh = $msg->getSegmentByIndex(0);
     $msh->setField(16, "NE");
     $msh->setField(11, "P");
     $msh->setField(12, "2.4");
     $msh->setField(15, "NE");
     $ack = new Net_HL7_Messages_ACK($msg);
     $seg0 = $ack->getSegmentByIndex(0);
     $this->assertTrue($seg0->getField(11) == "P", "Field 11 is P");
     $this->assertTrue($seg0->getField(12) == "2.4", "Field 12 is 2.4");
     $this->assertTrue($seg0->getField(15) == "NE", "Field 15 is NE");
     $this->assertTrue($seg0->getField(16) == "NE", "Field 16 is NE");
     $ack = new Net_HL7_Messages_ACK($msg);
     $ack->setErrorMessage("Some error");
     $seg1 = $ack->getSegmentByIndex(1);
     $this->assertTrue($seg1->getField(3) == "Some error", "Setting error message");
     $this->assertTrue($seg1->getField(1) == "CE", "Code CE after setting message");
 }
Exemplo n.º 3
0
 public function test()
 {
     $msh = new Net_HL7_Segments_MSH();
     $msh->setField(1, "*");
     $this->assertTrue($msh->getField(1) == "*", "MSH Field sep field (MSH(1))");
     $msh->setField(1, "xx");
     $this->assertTrue($msh->getField(1) == "*", "MSH Field sep field (MSH(1))");
     $msh->setField(2, "xxxxx");
     # Should have had no effect
     $this->assertTrue($msh->getField(2) == "^~\\&", "Special fields not changed");
     # Should have had the effect of changing some separator fields
     $msh->setField(2, "abcd");
     $this->assertTrue($msh->getField(2) == "abcd", "Encoding characters field set (MSH(2))");
 }
Exemplo n.º 4
0
<?php

require_once "Net/HL7/Segment.php";
require_once "Net/HL7/Segments/MSH.php";
require_once "test_base.php";
$msh = new Net_HL7_Segments_MSH();
$msh->setField(1, "*");
ok($msh->getField(1) == "*", "MSH Field sep field (MSH(1))<br>");
$msh->setField(1, "xx");
ok($msh->getField(1) == "*", "MSH Field sep field (MSH(1))<br>");
$msh->setField(2, "xxxxx");
# Should have had no effect
ok($msh->getField(2) == "^~\\&", "Special fields not changed<br>");
# Should have had the effect of changing some separator fields
$msh->setField(2, "abcd");
ok($msh->getField(2) == "abcd", "Encoding characters field set (MSH(2))<br>");
Exemplo n.º 5
0
 public function test()
 {
     # Simple constructor
     #
     $msg = new Net_HL7_Message();
     $seg1 = new Net_HL7_Segment("PID");
     $seg1->setField(2, "Foo");
     $msg->addSegment(new Net_HL7_Segments_MSH());
     $msg->addSegment($seg1);
     $seg0 = $msg->getSegmentByIndex(0);
     $seg1 = $msg->getSegmentByIndex(1);
     $seg0->setField(3, "XXX");
     $this->assertTrue($seg0->getName() == "MSH", "Segment 0 name MSH");
     $this->assertTrue($seg1->getName() == "PID", "Segment 1 name PID");
     $this->assertTrue($seg0->getField(3) == "XXX", "3d field of MSH");
     $this->assertTrue($seg1->getField(2) == "Foo", "2nd field of PID");
     // Check references
     $segX = $msg->getSegmentByIndex(0);
     $this->assertTrue($segX->getField(3) == "XXX", "3d field of MSH");
     $msg = new Net_HL7_Message("MSH|^~\\&|1|\rPID|||xxx|\r");
     $seg0 = $msg->getSegmentByIndex(0);
     $this->assertTrue($msg->toString() == "MSH|^~\\&|1|\rPID|||xxx|\r", "String representation of message");
     $this->assertTrue($msg->toString(1) == "MSH|^~\\&|1|\nPID|||xxx|\n", "Pretty print representation of message");
     $this->assertTrue($seg0->getField(2) == "^~\\&", "Encoding characters (MSH(2))");
     # Constructor with components and subcomponents
     #
     $msg = new Net_HL7_Message("MSH|^~\\&|1|\rPID|||xx^x&y&z^yy^zz|\r");
     $seg1 = $msg->getSegmentByIndex(1);
     $comps = $seg1->getField(3);
     $this->assertTrue($comps[0] == "xx", "Composed field");
     $this->assertTrue($comps[1][1] == "y", "Subcomposed field");
     # Trying different field separator
     #
     $msg = new Net_HL7_Message("MSH*^~\\&*1\rPID***xxx\r");
     $this->assertTrue($msg->toString() == "MSH*^~\\&*1*\rPID***xxx*\r", "String representation of message with * as field separator");
     $seg0 = $msg->getSegmentByIndex(0);
     $this->assertTrue($seg0->getField(3) == "1", "3d field of MSH");
     # Trying different field sep and control chars
     #
     $msg = new Net_HL7_Message("MSH*.%#@*1\rPID***x.x@y@z.z\r");
     $seg1 = $msg->getSegmentByIndex(1);
     $comps = $seg1->getField(3);
     $this->assertTrue($comps[0] == "x", "Composed field with . as separator");
     $this->assertTrue($comps[1][1] == "y", "Subcomposed field with @ as separator");
     # Faulty constuctor
     #
     //$this->assertTrue(! defined(new Net::HL7::Message("MSH|^~\\&*1\rPID|||xxx\r")), "Field separator not repeated");
     $seg2 = new Net_HL7_Segment("XXX");
     $msg->addSegment($seg2);
     $msg->removeSegmentByIndex(1);
     $seg1 = $msg->getSegmentByIndex(1);
     $this->assertTrue($seg1->getName() == $seg2->getName(), "Add/remove segment");
     $seg3 = new Net_HL7_Segment("YYY");
     $seg4 = new Net_HL7_Segment("ZZZ");
     $msg->insertSegment($seg3, 1);
     $msg->insertSegment($seg4, 1);
     $seg3 = $msg->getSegmentByIndex(3);
     $seg4 = $msg->getSegmentByIndex(4);
     $this->assertTrue($seg3->getName() == $seg2->getName(), "Insert segment");
     $msg->removeSegmentByIndex(1);
     $msg->removeSegmentByIndex(1);
     $msg->removeSegmentByIndex(6);
     $seg5 = new Net_HL7_Segment("ZZ1");
     # This shouldn't be possible
     @$msg->insertSegment($seg5, 3);
     $this->assertTrue(!$msg->getSegmentByIndex(3), "Erroneous insert");
     $msg->insertSegment($seg5, 2);
     $seg2 = $msg->getSegmentByIndex(2);
     $this->assertTrue($seg2->getName() == $seg5->getName(), "Insert segment");
     $msg->setSegment($seg3, 2);
     $seg2 = $msg->getSegmentByIndex(2);
     $this->assertTrue($seg2->getName() == $seg3->getName(), "Set segment");
     $this->assertTrue(count($msg->getSegmentsByName("MSH")) == 1, "Number of MSH segments");
     $msh2 = new Net_HL7_Segments_MSH();
     $msg->addSegment($msh2);
     $this->assertTrue(count($msg->getSegmentsByName("MSH")) == 2, "Added MSH segment, now two in message");
     # Fumble 'round with ctrl chars
     #
     $msg = new Net_HL7_Message();
     $msh = new Net_HL7_Segments_MSH(array());
     $msh->setField(1, "*");
     $msh->setField(2, "abcd");
     $msg->addSegment($msh);
     $this->assertTrue($msg->toString() == "MSH*abcd*\r", "Creating separate MSH");
     $msh->setField(1, "|");
     $msh->setField(2, "^~\\&");
     $this->assertTrue($msg->toString() == "MSH|^~\\&|\r", "Change MSH after add");
     $msh = new Net_HL7_Segments_MSH(array());
     $msh->setField(1, "*");
     $msh->setField(2, "abcd");
     $msg->setSegment($msh, 0);
     $this->assertTrue($msg->toString() == "MSH*abcd*\r", "New MSH with setSegment");
     $str = 'MSH|^~\\&|CodeRyte HL7|CodeRyte HQ|VISION|MISYS|200404061744||DFT^P03|TC-2743|P^T|2.3|||AL|NE||ASCII||| |';
     $msg = new Net_HL7_Message($str);
     $this->assertTrue($msg->toString(1) == "{$str}\n", "Message from string and to string with subcomponents");
     // Segment as string
     $msg = new Net_HL7_Message("MSH*^~\\&*1\rPID*a^b^c*a^b1&b2^c*xxx\r");
     $xxx = new Net_HL7_Segment("XXX");
     $xxx->setField(2, array("a", array("b1", "b2"), "c"));
     $msg->addSegment($xxx);
     $this->assertTrue($msg->getSegmentAsString(0) == "MSH*^~\\&*1*", "MSH segment as string");
     $this->assertTrue($msg->getSegmentAsString(1) == "PID*a^b^c*a^b1&b2^c*xxx*", "PID segment as string");
     $this->assertTrue($msg->getSegmentAsString(2) == "XXX**a^b1&b2^c*", "XXX segment as string");
     // Get segment field as string
     $this->assertTrue($msg->getSegmentFieldAsString(0, 3) == "1", "MSH(3) as string");
     $this->assertTrue($msg->getSegmentFieldAsString(1, 2) == "a^b1&b2^c", "PID(2) as string");
 }
Exemplo n.º 6
0
ok(count($msg->getSegmentsByName("MSH")) == 1, "Number of MSH segments<br>");
$msh2 = new Net_HL7_Segments_MSH();
$msg->addSegment($msh2);
ok(count($msg->getSegmentsByName("MSH")) == 2, "Added MSH segment, now two in message<br>");
# Fumble 'round with ctrl chars
#
$msg = new Net_HL7_Message();
$msh = new Net_HL7_Segments_MSH(array());
$msh->setField(1, "*");
$msh->setField(2, "abcd");
$msg->addSegment($msh);
ok($msg->toString() == "MSH*abcd*\r", "Creating separate MSH<br>");
$msh->setField(1, "|");
$msh->setField(2, "^~\\&");
ok($msg->toString() == "MSH|^~\\&|\r", "Change MSH after add<br>");
$msh = new Net_HL7_Segments_MSH(array());
$msh->setField(1, "*");
$msh->setField(2, "abcd");
$msg->setSegment($msh, 0);
ok($msg->toString() == "MSH*abcd*\r", "New MSH with setSegment<br>");
$str = 'MSH|^~\\&|CodeRyte HL7|CodeRyte HQ|VISION|MISYS|200404061744||DFT^P03|TC-2743|P^T|2.3|||AL|NE||ASCII||| |';
$msg = new Net_HL7_Message($str);
ok($msg->toString(1) == "{$str}\n", "Message from string and to string with subcomponents<br>");
// Segment as string
$msg = new Net_HL7_Message("MSH*^~\\&*1\rPID*a^b^c*a^b1&b2^c*xxx\r");
$xxx = new Net_HL7_Segment("XXX");
$xxx->setField(2, array("a", array("b1", "b2"), "c"));
$msg->addSegment($xxx);
ok($msg->getSegmentAsString(0) == "MSH*^~\\&*1*", "MSH segment as string<br>");
ok($msg->getSegmentAsString(1) == "PID*a^b^c*a^b1&b2^c*xxx*", "PID segment as string<br>");
ok($msg->getSegmentAsString(2) == "XXX**a^b1&b2^c*", "XXX segment as string<br>");
Exemplo n.º 7
0
$msh = $msg->getSegmentByIndex(0);
$msh->setField(15, "AL");
$msh->setField(16, "NE");
$ack = new Net_HL7_Messages_ACK($msg);
$seg1 = $ack->getSegmentByIndex(1);
ok($seg1->getField(1) == "CA", "Error code is CA<br>");
$msg = new Net_HL7_Message();
$msh = new Net_HL7_Segments_MSH();
$msh->setField(15, "");
$msh->setField(16, "NE");
$msg->addSegment($msh);
$ack = new Net_HL7_Messages_ACK($msg);
$seg1 = $ack->getSegmentByIndex(1);
ok($seg1->getField(1) == "CA", "Error code is CA<br>");
$msg = new Net_HL7_Message();
$msh = new Net_HL7_Segments_MSH();
$msh->setField(16, "");
$msh->setField(15, "");
$msg->addSegment($msh);
$ack = new Net_HL7_Messages_ACK($msg);
$seg1 = $ack->getSegmentByIndex(1);
ok($seg1->getField(1) == "AA", "Error code is AA<br>");
$ack->setAckCode("E");
ok($seg1->getField(1) == "AE", "Error code is AE<br>");
$ack->setAckCode("CR");
ok($seg1->getField(1) == "CR", "Error code is CR<br>");
$ack->setAckCode("CR", "XX");
ok($seg1->getField(3) == "XX", "Set message and code<br>");
$msg = new Net_HL7_Message();
$msg->addSegment(new Net_HL7_Segments_MSH());
$msh = $msg->getSegmentByIndex(0);