function parse($data)
 {
     parent::parse($data);
     if ($this->data === "" || $this->data === null) {
         // === $message->nullValue) { // nullValue ("") or null ??
         if ($this->required) {
             $this->error(CHL7v2Exception::FIELD_EMPTY, $this->getPathString(), $this);
         }
     } else {
         if ($this->forbidden) {
             $this->error(CHL7v2Exception::FIELD_FORBIDDEN, $this->data, $this);
         }
     }
     $message = $this->getMessage();
     $items = CHL7v2::split($message->repetitionSeparator, $this->data, $this->keep());
     /* // Ce test ne semble pas etre valide, car meme si maxOccurs n'est pas unbounded, 
        // on en trouve souvent plusieurs occurences 
        if (!$this->unbounded && count($items) > 1) {
          mbTrace($this);
          $this->error(CHL7v2Exception::TOO_MANY_FIELD_ITEMS, $this->name, $this);
        }*/
     $this->items = array();
     foreach ($items as $i => $components) {
         $_field_item = new CHL7v2FieldItem($this, $this->meta_spec, $i);
         $_field_item->parse($components);
         $this->items[] = $_field_item;
     }
     $this->validate();
 }
Exemplo n.º 2
0
 function __construct(CHL7v2SegmentGroup $parent, CHL7v2DOMElement $self_specs)
 {
     parent::__construct($parent);
     $this->parent = $parent;
     $this->specs = $self_specs;
     $name = $self_specs->getAttribute("name");
     $segments = $self_specs->query(".//segment");
     $values = array();
     foreach ($segments as $_segment) {
         $values[] = $_segment->nodeValue;
     }
     $this->name = $name ? $name : implode(" ", $values);
     $parent->appendChild($this);
 }
 /**
  * @see parent::parse
  */
 function parse($data)
 {
     parent::parse($data);
     $message = $this->getMessage();
     $fields = CHL7v2::split($message->fieldSeparator, $data);
     $this->name = array_shift($fields);
     $specs = $this->getSpecs();
     $this->description = $specs->queryTextNode("description");
     if ($this->name === $message->getHeaderSegmentName()) {
         array_unshift($fields, $message->fieldSeparator);
     }
     // Don't count empty fields on the right
     $count_fields = count($fields);
     for ($i = $count_fields - 1; $i >= 0; $i--) {
         if ($fields[$i] === "") {
             $count_fields--;
         } else {
             break;
         }
     }
     $_segment_specs = $specs->getItems();
     // Check the number of fields
     if ($count_fields > count($_segment_specs)) {
         $this->error(CHL7v2Exception::TOO_MANY_FIELDS, $data, $this, CHL7v2Error::E_WARNING);
     }
     foreach ($_segment_specs as $i => $_spec) {
         if (array_key_exists($i, $fields)) {
             $field = new CHL7v2Field($this, $_spec);
             $field->parse($fields[$i]);
             $this->fields[] = $field;
         } elseif ($_spec->isRequired()) {
             $field = new CHL7v2Field($this, $_spec);
             $this->error(CHL7v2Exception::FIELD_EMPTY, $field->getPathString(), $field);
         }
     }
 }
 /**
  * Parse a field item into components
  *
  * @param string $data The data to parse
  *
  * @return void
  */
 function parse($data)
 {
     parent::parse($data);
     $keep_original = $this->getField()->keep();
     // Is composite
     if (isset($this->separator[0]) && $this->getProps() instanceof CHL7v2DataTypeComposite) {
         $parts = CHL7v2::split($this->separator[0], $data, $keep_original);
         $component_specs = $this->getSpecs()->getItems();
         foreach ($component_specs as $i => $_component_spec) {
             if (array_key_exists($i, $parts)) {
                 $_comp = new CHL7v2Component($this, $_component_spec, $i, $this->separators);
                 $_comp->parse($parts[$i]);
                 $this->children[] = $_comp;
             } elseif ($_component_spec->isRequired()) {
                 $this->error(CHL7v2Exception::FIELD_EMPTY, $this->getPathString(), $this);
             }
         }
     } else {
         $this->data = $data;
         if (!$keep_original) {
             $this->data = $this->getMessage()->unescape($this->data);
         }
     }
 }
Exemplo n.º 5
0
 function handleLine(CHL7v2DOMElement $current_node, CHL7v2Entity $current_group)
 {
     // Increment du nb d'occurences
     $current_node->markUsed();
     // On enregistre le segment dans le groupe courant
     $_segment = new CHL7v2Segment($current_group);
     $_segment->parse($this->getCurrentLine());
     $current_group->appendChild($_segment);
     // On avance dans le fichier
     $this->current_line++;
     CHL7v2::d(" --> ### Creation du segment ###, ligne suivante : {$this->current_line}");
 }