function parse($data, $parse_body = true, CInteropActor $actor = null) { $this->actor = $actor; try { self::isWellFormed($data, $this->strict_segment_terminator); } catch (CHL7v2Exception $e) { $this->error($e->getMessage(), $e->extraData); //return false; } // remove all chars before MSH $msh_pos = strpos($data, self::$header_segment_name); if ($msh_pos === false) { throw new CHL7v2Exception(CHL7v2Exception::SEGMENT_INVALID_SYNTAX, $data); } $data = substr($data, $msh_pos); $data = self::fixRawER7($data, $this->strict_segment_terminator); parent::parse($data); $message = $this->data; // 4 to 7 if (!isset($message[7])) { throw new CHL7v2Exception(CHL7v2Exception::SEGMENT_INVALID_SYNTAX, $message); } $this->fieldSeparator = $message[3]; $nextDelimiter = strpos($message, $this->fieldSeparator, 4); if ($nextDelimiter > 4) { // usually ^ $this->componentSeparator = $message[4]; } if ($nextDelimiter > 5) { // usually ~ $this->repetitionSeparator = $message[5]; } if ($nextDelimiter > 6) { // usually \ $this->escapeCharacter = $message[6]; } if ($nextDelimiter > 7) { // usually & $this->subcomponentSeparator = $message[7]; } // replace the special case of ^~& with ^~\& if ("^~&|" == substr($message, 4, 4)) { $this->escapeCharacter = "\\"; $this->subcomponentSeparator = "&"; $this->repetitionSeparator = "~"; $this->componentSeparator = "^"; } $this->initEscapeSequences(); $this->lines = CHL7v2::split($this->segmentTerminator, $this->data); // we extract the first line info "by hand" $first_line = CHL7v2::split($this->fieldSeparator, reset($this->lines)); if (!isset($first_line[11])) { throw new CHL7v2Exception(CHL7v2Exception::SEGMENT_INVALID_SYNTAX, $message); } // version if (array_key_exists(16, $first_line)) { $this->parseRawVersion($first_line[11], $first_line[16]); } else { $this->parseRawVersion($first_line[11]); } // message type $message_type = explode($this->componentSeparator, $first_line[8]); if ($message_type[0]) { $this->name = $message_type[0]; if ($this->name == "ACK") { $this->event_name = $message_type[0]; } else { if (isset($message_type[2]) && $message_type[2] && !preg_match("/^[A-Z]{3}_[A-Z\\d]{2}\\d\$/", $message_type[2])) { throw new CHL7v2Exception(CHL7v2Exception::WRONG_MESSAGE_TYPE, $message_type[2]); } if (strlen($message_type[0]) != 3 || strlen($message_type[1]) != 3) { $msg = $message_type[0] . $this->componentSeparator . $message_type[1]; throw new CHL7v2Exception(CHL7v2Exception::WRONG_MESSAGE_TYPE, $msg); } $this->event_name = $message_type[0] . $message_type[1]; } } else { $this->event_name = preg_replace("/[^A-Z0-9]/", "", $message_type[2]); $this->name = substr($message_type[2], 0, 3); } if (!($spec = $this->getSpecs())) { throw new CHL7v2Exception(CHL7v2Exception::UNKNOWN_MSG_CODE); } $this->description = $spec->queryTextNode("description"); $this->readHeader(); if ($parse_body) { $this->readSegments(); } }
/** * flatten * * @param bool $highlight highlight * * @return mixed|string */ function flatten($highlight = false) { $string = parent::flatten($highlight); if ($highlight) { return $string; } $lines = preg_split("/[\r\n]+/", $string); $lines_after = array(); $max_length = 210; // 200 pour ĂȘtre "large" (220 normalement) foreach ($lines as $_line) { if (strlen($_line) < $max_length) { $lines_after[] = $_line; continue; } $pos = strpos($_line, $this->fieldSeparator, $max_length - 1); if ($pos === false) { $pos = $max_length; } $lines_after[] = substr($_line, 0, $pos); while (strlen($_line) > $max_length) { $_line = substr($_line, $pos); $lines_after[] = "A{$this->fieldSeparator}" . $_line; $length = min($max_length, strlen($_line)); $pos = strpos($_line, $this->fieldSeparator, $length - 1); if ($pos === false) { $pos = min($max_length, strlen($_line)); } } } return implode("\r\n", $lines_after); }
function flatten($highlight = false) { $old = self::$decorateToString; self::$decorateToString = $highlight; $str = $this->__toString(); if ($highlight) { $str = "<pre class='er7'>{$str}</pre>"; } self::$decorateToString = $old; return $str; }