Net_HL7
[ class tree: Net_HL7 ] [ index: Net_HL7 ] [ all elements ]

Source for file MSH.php

Documentation is available at MSH.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 2004 D.A.Dokter                                        |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 3.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at the following url:           |
  11. // | http://www.php.net/license/3_0.txt.                                  |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: D.A.Dokter <dokter@w20e.com>                                |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: MSH.php,v 1.8 2004/07/05 15:41:29 wyldebeast Exp $
  20.  
  21. require_once 'Net/HL7/Segment.php';
  22. require_once 'Net/HL7.php';
  23.  
  24. /**
  25.  * MSH (message header) segment class
  26.  *
  27.  * Usage:
  28.  * <code>
  29.  * $seg =& new Net_HL7_Segments_MSH();
  30.  *
  31.  * $seg->setField(9, "ADT^A24");
  32.  * echo $seg->getField(1);
  33.  * </code>
  34.  *
  35.  * The Net_HL7_Segments_MSH is an implementation of the
  36.  * Net_HL7_Segment class. The MSH segment is a bit different from
  37.  * other segments, in that the first field is the field separator
  38.  * after the segment name. Other fields thus start counting from 2!
  39.  * The setting for the field separator for a whole message can be
  40.  * changed by the setField method on index 1 of the MSH for that
  41.  * message.  The MSH segment also contains the default settings for
  42.  * field 2, COMPONENT_SEPARATOR, REPETITION_SEPARATOR,
  43.  * ESCAPE_CHARACTER and SUBCOMPONENT_SEPARATOR. These fields default
  44.  * to ^, ~, \ and & respectively.
  45.  *
  46.  * @version    $Revision: 1.8 $
  47.  * @author     D.A.Dokter <dokter@w20e.com>
  48.  * @access     public
  49.  * @category   Networking
  50.  * @package    Net_HL7
  51.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  52.  */
  53.  
  54.     /**
  55.      * Create an instance of the MSH segment.
  56.      *
  57.      * If an array argument is provided, all fields will be filled
  58.      * from that array. Note that for composed fields and
  59.      * subcomponents, the array may hold subarrays and
  60.      * subsubarrays. If the reference is not given, the MSH segment
  61.      * will be created with the MSH 1,2,7,10 and 12 fields filled in
  62.      * for convenience.
  63.      */
  64.     function Net_HL7_Segments_MSH($fields = NULL$hl7Globals = NULL
  65.     {
  66.         parent::Net_HL7_Segment("MSH"$fields);
  67.     
  68.         // Only fill default fields if no fields array is given 
  69.         //
  70.         if (!isset($fields)) {
  71.       
  72.             if (!is_array($hl7Globals)) {
  73.                 $this->setField(1'|');
  74.                 $this->setField(2'^~\\&');
  75.                 $this->setField(7strftime("%Y%m%d%H%M%S"));
  76.                 
  77.                 // Set ID field
  78.                 //
  79.                 $this->setField(10$this->getField(7rand(1000099999));
  80.                 $this->setField(12'2.2');
  81.             }
  82.             else {
  83.                 $this->setField(1$hl7Globals['FIELD_SEPARATOR']);
  84.                 $this->setField(2
  85.                                 $hl7Globals['COMPONENT_SEPARATOR'.
  86.                                 $hl7Globals['REPETITION_SEPARATOR'.
  87.                                 $hl7Globals['ESCAPE_CHARACTER'.
  88.                                 $hl7Globals['SUBCOMPONENT_SEPARATOR']
  89.                                 );
  90.                 $this->setField(7strftime("%Y%m%d%H%M%S"));
  91.                 
  92.                 // Set ID field
  93.                 //
  94.                 $this->setField(10$this->getField(7rand(1000099999));
  95.                 $this->setField(12$hl7Globals['HL7_VERSION']);
  96.             }
  97.         }
  98.     }
  99.  
  100.  
  101.     /**
  102.      * Set the field specified by index to value.
  103.      *
  104.      * Indices start at 1, to stay with the HL7 standard. Trying to
  105.      * set the value at index 0 has no effect. Setting the value on
  106.      * index 1, will effectively change the value of FIELD_SEPARATOR
  107.      * for the message containing this segment, if the value has
  108.      * length 1; setting the field on index 2 will change the values
  109.      * of COMPONENT_SEPARATOR, REPETITION_SEPARATOR, ESCAPE_CHARACTER
  110.      * and SUBCOMPONENT_SEPARATOR for the message, if the string is of
  111.      * length 4.
  112.      * 
  113.      * @param int Index of field
  114.      * @param mixed Value
  115.      * @return boolean 
  116.      * @access public
  117.      */
  118.     function setField($index$value
  119.     {  
  120.         if ($index == 1{
  121.             if (strlen($value!= 1{
  122.                 return false;
  123.             }
  124.         }
  125.     
  126.         if ($index == 2{
  127.             if (strlen($value!= 4{
  128.                 return false;
  129.             }
  130.         }
  131.     
  132.         return parent::setField($index$value);
  133.     }
  134.  
  135. }
  136.  
  137. ?>

Documentation generated on Mon, 11 Mar 2019 15:32:35 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.