Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/senaranya/HL7
Browse files Browse the repository at this point in the history
  • Loading branch information
Aranya Sen committed Aug 3, 2018
2 parents 69a35a3 + 2a29324 commit d7db213
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/HL7/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public function __construct(string $msgStr = null, array $hl7Globals = null, boo
$segments = preg_split("/[\n\r" . $this->segmentSeparator . ']/', $msgStr, -1, PREG_SPLIT_NO_EMPTY);

// The first segment should be the control segment
preg_match('/^([A-Z0-9]{3})(.)(.)(.)(.)(.)(.)/', $segments[0], $matches);
if (!preg_match('/^([A-Z0-9]{3})(.)(.)(.)(.)(.)(.)/', $segments[0], $matches)) {
throw new HL7Exception('Not a valid message: invalid control segment', E_USER_ERROR);
}

[$dummy, $hdr, $fieldSep, $compSep, $repSep, $esc, $subCompSep, $fieldSepCtrl] = $matches;

Expand Down
10 changes: 10 additions & 0 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,14 @@ public function a_segment_can_be_retrieved_as_a_string()
$this->assertSame('1', $msg->getSegmentFieldAsString(0, 3), 'MSH(3) as string');
$this->assertSame('a^b1&b2^c', $msg->getSegmentFieldAsString(1, 2), 'XXX(2) as string');
}

/**
* @test
* @expectedException Aranyasen\Exceptions\HL7Exception
* @expectedExceptionMessage Not a valid message: invalid control segment
*/
public function an_exception_will_be_throw_in_invalid_string()
{
$msg = new Message("I'm an invalid message");
}
}

0 comments on commit d7db213

Please sign in to comment.