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

Source for file Segment.php

Documentation is available at Segment.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: Segment.php,v 1.6 2004/07/05 08:57:28 wyldebeast Exp $
  20.  
  21. class Net_HL7_Segment {
  22.  
  23.     var $_fields;
  24.  
  25.     /**
  26.      * Create an instance of this segment. A segment may be created with just
  27.      * a name or a name and a reference to an array of field values. If the
  28.      * name is not given, no segment is created. The segment name should be
  29.      * three characters long, and upper case. If it isn't, no segment is
  30.      * created, and undef is returned.  If a reference to an array is given,
  31.      * all fields will be filled from that array. Note that for composed
  32.      * fields and subcomponents, the array may hold subarrays and
  33.      * subsubarrays. Repeated fields can not be supported the same way, since
  34.      * we can't distinguish between composed fields and repeated fields.
  35.      *
  36.      * Example: <code>
  37.      *
  38.      * $seg =& new Net_HL7_Segment("PID");
  39.      *
  40.      * $seg->setField(3, "12345678");
  41.      * echo $seg->getField(1);
  42.      * </code>
  43.      *
  44.      * @version    0.10
  45.      * @author     D.A.Dokter <dokter@w20e.com>
  46.      * @access     public
  47.      * @category   Networking
  48.      * @package    Net_HL7
  49.      * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  50.      * @param mixed Name of the segment
  51.      * @param array Fields for segment
  52.      */
  53.     function Net_HL7_Segment($name$fields = array()) 
  54.     {  
  55.         // Is the name 3 upper case characters?
  56.         //
  57.         if ((!$name|| (strlen($name!= 3|| (strtoupper($name!= $name)) {
  58.             trigger_error("Name should be 3 characters, uppercase"E_USER_ERROR);
  59.         }
  60.  
  61.         $this->_fields = array();
  62.  
  63.         $this->_fields[0$name;
  64.  
  65.         if (is_array($fields)) {
  66.  
  67.             for ($i = 0; $i count($fields)$i++{
  68.     
  69.                 $this->setField($i + 1$fields[$i]);
  70.             }
  71.         }
  72.     }
  73.  
  74.  
  75.     /**
  76.      * Set the field specified by index to value, and return some true value
  77.      * if the operation succeeded. Indices start at 1, to stay with the HL7
  78.      * standard. Trying to set the value at index 0 has no effect.  The value
  79.      * may also be a reference to an array (that may itself contain arrays)
  80.      * to support composed fields (and subcomponents).
  81.      * 
  82.      * To set a field to the HL7 null value, instead of omitting a field, can
  83.      * be achieved with the _Net_HL7_NULL type, like:
  84.      * <code>
  85.      *   $segment->setField(8, $_Net_HL7_NULL);
  86.      * </code>
  87.      * This will render the field as the double quote ("").
  88.      * If values are not provided at all, the method will just return.
  89.      *
  90.      * @param int Index to set
  91.      * @param mixed Value for field
  92.      * @return boolean 
  93.      * @access public
  94.      */
  95.     function setField($index$value""
  96.     {
  97.         if (!($index && $value)) {
  98.             return false;
  99.         }
  100.     
  101.         // Fill in the blanks...
  102.         for ($i count($this->_fields)$i $index$i++{
  103.             $this->_fields[$i"";
  104.         }
  105.  
  106.         $this->_fields[$index$value;
  107.     
  108.         return true;
  109.     }
  110.  
  111.  
  112.     /**
  113.      * Get the field at index. If the field is a composed field, you might
  114.      * ask for the result to be an array like so:
  115.      * <code>
  116.      * $subfields = $seg->getField(9)
  117.      * </code>
  118.      * otherwise the thing returned will be a reference to an array.
  119.      *
  120.      * @param int Index of field
  121.      * @return mixed The value of the field
  122.      * @access public
  123.      */
  124.     function getField($index
  125.     {
  126.         return $this->_fields[$index];
  127.     }
  128.  
  129.  
  130.     /**
  131.      * Get the number of fields for this segment, not including the name
  132.      *
  133.      * @return int number of fields
  134.      * @access public
  135.      */
  136.     function size(
  137.     {
  138.         return count($this->_fields- 1;
  139.     }
  140.  
  141.  
  142.     /**
  143.      * Get the fields in the specified range, or all if nothing specified. If
  144.      * only the 'from' value is provided, all fields from this index till the
  145.      * end of the segment will be returned.
  146.      *
  147.      * @param int Start range at this index
  148.      * @param int Stop range at this index
  149.      * @return array List of fields
  150.      * @access public
  151.      */
  152.     function getFields($from = 0$to = 0
  153.     {
  154.         if (!$to{
  155.             $to count($this->_fields);
  156.         }
  157.  
  158.         return array_slice($this->_fields$from$to $from + 1);
  159.     }    
  160.  
  161.  
  162.     /**
  163.      * Get the name of the segment. This is basically the value at index 0
  164.      * 
  165.      * @return mixed Name of segment
  166.      * @access public
  167.      */
  168.     function getName(
  169.     {
  170.         return $this->_fields[0];
  171.     }
  172. }
  173. ?>

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