Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
}
],
"require": {
"php": ">=5.4.0"
"php": ">=5.4.0",
"ext-ctype": "*"
},
"autoload": {
"classmap": [
Expand Down
3 changes: 1 addition & 2 deletions src/Exception/StructureException.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php

namespace PharmaIntelligence\HL7\Exception;

class StructureException extends \LogicException
{
}

?>
103 changes: 43 additions & 60 deletions src/Node/BaseNode.php
Original file line number Diff line number Diff line change
@@ -1,117 +1,100 @@
<?php

namespace PharmaIntelligence\HL7\Node;

#[\AllowDynamicProperties]
abstract class BaseNode implements \ArrayAccess, \Iterator, \Countable
{
protected $children = array();
protected $children = [];

protected $parent = null;

/**
*
* @return \PharmaIntelligence\HL7\Node\Message
*/
public function getRootNode() {
if(is_null($this->parent))
#[\ReturnTypeWillChange]
public function getRootNode()
{
if (is_null($this->parent)) {
return $this;
}

return $this->parent->getRootNode();
}

public function append(BaseNode $node) {

#[\ReturnTypeWillChange]
public function append(BaseNode $node)
{
$node->setParent($this);
array_push($this->children, $node);
}

public function setParent(BaseNode $node) {

#[\ReturnTypeWillChange]
public function setParent(BaseNode $node)
{
$this->parent = $node;
}

public function count() {

#[\ReturnTypeWillChange]
public function count()
{
return count($this->children);
}

public abstract function __toString();

/*
* (non-PHPdoc)
* @see Iterator::current()
*/

#[\ReturnTypeWillChange]
public abstract function __toString();

#[\ReturnTypeWillChange]
public function current()
{
return current($this->children);
}

/*
* (non-PHPdoc)
* @see Iterator::key()
*/

#[\ReturnTypeWillChange]
public function key()
{
return key($this->children);
}

/*
* (non-PHPdoc)
* @see Iterator::next()
*/

#[\ReturnTypeWillChange]
public function next()
{
return next($this->children);
}

/*
* (non-PHPdoc)
* @see Iterator::rewind()
*/

#[\ReturnTypeWillChange]
public function rewind()
{
return reset($this->children);
}

/*
* (non-PHPdoc)
* @see Iterator::valid()
*/

#[\ReturnTypeWillChange]
public function valid()
{
return isset($this->children[$this->key()]);
}

/*
* (non-PHPdoc)
* @see ArrayAccess::offsetExists()
*/

#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return array_key_exists($offset, $this->children);
}

/*
* (non-PHPdoc)
* @see ArrayAccess::offsetGet()
*/

#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->children[$offset];
}

/*
* (non-PHPdoc)
* @see ArrayAccess::offsetSet()
*/

#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$this->children[$offset] = $value;
}

/*
* (non-PHPdoc)
* @see ArrayAccess::offsetUnset()
*/

#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->children[$offset]);
}
}

?>
31 changes: 17 additions & 14 deletions src/Node/Component.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
<?php

namespace PharmaIntelligence\HL7\Node;

#[\AllowDynamicProperties]
class Component extends BaseNode
{
public $value = null;

public function __construct($value = null) {
$this->value = $value;
}

public function __toString() {
if(count($this->children) === 0) {
return $this->value;
}
return implode($this->getRootNode()->escapeSequences['subcomponent_delimiter'], $this->children);
}
}
public $value = null;

public function __construct($value = null)
{
$this->value = $value;
}

?>
public function __toString()
{
if (count($this->children) === 0) {
return $this->value;
}

return implode($this->getRootNode()->escapeSequences['subcomponent_delimiter'], $this->children);
}
}
8 changes: 4 additions & 4 deletions src/Node/Field.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace PharmaIntelligence\HL7\Node;

#[\AllowDynamicProperties]
class Field extends BaseNode
{

public function __toString() {
public function __toString()
{
return implode($this->getRootNode()->escapeSequences['repeat_delimiter'], $this->children);
}
}

?>
32 changes: 19 additions & 13 deletions src/Node/Message.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace PharmaIntelligence\HL7\Node;

#[\AllowDynamicProperties]
class Message extends BaseNode
{
public $escapeSequences = array(
Expand All @@ -11,54 +12,59 @@ class Message extends BaseNode
'escape_delimiter' => '\\',
'cursor_return' => '\r'
);


#[\ReturnTypeWillChange]
public function setEscapeSequences(array $escapeSequences) {
$this->escapeSequences = array_merge($this->escapeSequences, $escapeSequences);
}


#[\ReturnTypeWillChange]
public function getSegmentsByName($segmentName) {
$filtered = array_filter($this->children, function($segment) use ($segmentName) {
if($segment->getSegmentName() === $segmentName)
return true;
return true;
return false;
});
return array_values($filtered);
}


#[\ReturnTypeWillChange]
public function getMessageHeaderSegment() {
return $this->children[0];
}


#[\ReturnTypeWillChange]
public function getValueAtIndex($segmentIndex = 0, $fieldIndex = 0, $repetitionIndex = 0, $componentIndex = 0, $subComponentIndex = 0) {
if(!array_key_exists($segmentIndex, $this->children)) {
throw new \DomainException('No segment at index "'.$segmentIndex.'"');
}
$segment = $this->children[$segmentIndex];

if(!$segment->offsetExists($fieldIndex)) {
throw new \DomainException('Field is out of bounds at index "'.$fieldIndex.'"');
}
$field = $segment[$fieldIndex];

if(!$field->offsetExists($repetitionIndex)) {
throw new \DomainException('Repetition is out of bounds at index "'.$fieldIndex.'"');
}
$repetition = $field[$repetitionIndex];

if(!$repetition->offsetExists($componentIndex)) {
return $repetition->value;
}

$component = $repetition[$componentIndex];

if(!$component->offsetExists($subComponentIndex)) {
return $component->value;
}

return null;
}


#[\ReturnTypeWillChange]
public function __toString() {
return implode($this->getRootNode()->escapeSequences['cursor_return'], $this->children);
}
}

?>
32 changes: 18 additions & 14 deletions src/Node/Repetition.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<?php

namespace PharmaIntelligence\HL7\Node;

#[\AllowDynamicProperties]
class Repetition extends BaseNode
{
public $value = null;

public function __construct($value = null) {
$this->value = $value;
}

public function __toString() {
if(count($this->children) === 0) {
return $this->value;
}
return implode($this->getRootNode()->escapeSequences['component_delimiter'], $this->children);
}
}
public $value = null;

public function __construct($value = null)
{
$this->value = $value;
}

?>
#[\ReturnTypeWillChange]
public function __toString()
{
if (count($this->children) === 0) {
return $this->value;
}

return implode($this->getRootNode()->escapeSequences['component_delimiter'], $this->children);
}
}
10 changes: 5 additions & 5 deletions src/Node/Segment.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

use PharmaIntelligence\HL7\Exception\StructureException;

#[\AllowDynamicProperties]
class Segment extends BaseNode
{

protected $segmentName = '';

public function __construct($segmentName) {
Expand All @@ -14,15 +14,15 @@ public function __construct($segmentName) {
}
$this->segmentName = $segmentName;
}


#[\ReturnTypeWillChange]
public function getSegmentName() {
return $this->segmentName;
}


#[\ReturnTypeWillChange]
public function __toString() {
$children = array_merge(array($this->segmentName), $this->children);
return implode($this->getRootNode()->escapeSequences['field_delimiter'], $children);
}
}

?>
Loading