/** * Fill a field item with data * * @param array $data The data to add to the current component * * @return void */ function fill($data) { // Is composite if ($this->getProps() instanceof CHL7v2DataTypeComposite) { if (!is_array($data)) { $data = array($data); } $component_specs = $this->getSpecs()->getItems(); foreach ($component_specs as $i => $_component_spec) { if (array_key_exists($i, $data)) { $_comp = new CHL7v2Component($this, $_component_spec, $i, $this->separators); $_comp->fill($data[$i]); $this->children[] = $_comp; } elseif ($_component_spec->isRequired()) { $this->error(CHL7v2Exception::FIELD_EMPTY, $this->getPathString(), $this); } } } else { if (is_array($data)) { $this->error(CHL7v2Exception::INVALID_DATA_FORMAT, var_export($data, true), $this); return; } $this->data = trim($this->getProps()->toHL7($data, $this->getField())); } }