From b0c7060a4fc5edb1f5c88ba5616105a7cbe1d191 Mon Sep 17 00:00:00 2001 From: Aranya Sen Date: Sat, 11 Nov 2023 14:02:41 +0530 Subject: [PATCH 1/2] Add support for MSH.9.3 Message Structure --- src/HL7/Segments/MSH.php | 23 ++++++++++------------- tests/Segments/MSHTest.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/HL7/Segments/MSH.php b/src/HL7/Segments/MSH.php index 0ef97e0..aa860a3 100644 --- a/src/HL7/Segments/MSH.php +++ b/src/HL7/Segments/MSH.php @@ -128,26 +128,23 @@ public function setSecurity($value, int $position = 8) * * Sets message type to MSH segment. * - * If trigger event is already set, then it is preserved + * Note: If trigger event is already set, then it is preserved * - * Example: - * - * If field value is ORU^R01 and you call - * - * ``` - * $msh->setMessageType('ORM'); - * ``` - * - * Then the new field value will be ORM^R01. - * If it was empty then the new value will be just ORM. + * Example: If field value is ORU^R01 and you call $msh->setMessageType('ORM'), then the new field value will be + * ORM^R01. If it was empty then the new value will be just ORM. * + * Ref: https://hl7-definition.caristix.com/v2/HL7v2.5/Fields/MSH.9 * @param string $value */ public function setMessageType($value, int $position = 9): bool { $typeField = $this->getField($position); - if (is_array($typeField) && !empty($typeField[1])) { - $value = [$value, $typeField[1]]; + if (is_array($typeField)) { + if (!empty($typeField[2])) { + $value = [$value, $typeField[1], $typeField[2]]; + } elseif (!empty($typeField[1])) { + $value = [$value, $typeField[1]]; + } } return $this->setField($position, $value); } diff --git a/tests/Segments/MSHTest.php b/tests/Segments/MSHTest.php index 0970213..87bf146 100644 --- a/tests/Segments/MSHTest.php +++ b/tests/Segments/MSHTest.php @@ -68,4 +68,38 @@ public function index_2_in_MSH_accepts_only_4_character_strings(): void $msh->setField(2, 'yyyyy'); self::assertSame('xxxx', $msh->getField(2), 'Special fields not changed'); } + + /** @test */ + public function messageType_can_be_set_in_message(): void + { + $msh = new MSH(); + $msh->setMessageType('ORM'); + self::assertSame('ORM', $msh->getField(9)); + $msh->setMessageType('ORM^O01'); + self::assertSame('ORM^O01', $msh->getField(9)); + + $msh = new MSH(); + $msh->setMessageType(['ORU', 'R01']); // For v2.3 + self::assertSame(['ORU', 'R01'], $msh->getField(9)); + + $msh = new MSH(); + $msh->setMessageType(['ORU', 'R01', 'ORU_R01']); // For 2.5 + self::assertSame(['ORU', 'R01', 'ORU_R01'], $msh->getField(9)); + } + + /** @test */ + public function messageType_can_be_changed_in_message(): void + { + // For v2.3... + $msh = new MSH(); + $msh->setMessageType(['ORU', 'R01']); + $msh->setMessageType('ORM'); + self::assertSame(['ORM', 'R01'], $msh->getField(9)); + + // For v2.5... + $msh = new MSH(); + $msh->setMessageType(['ORU', 'R01', 'ORU_R01']); + $msh->setMessageType('ORM'); + self::assertSame(['ORM', 'R01', 'ORU_R01'], $msh->getField(9)); + } } From 9ca71c6aaed707a1a01bed5cf5bc21e986d3505b Mon Sep 17 00:00:00 2001 From: Aranya Sen Date: Sun, 10 Dec 2023 09:53:06 +0530 Subject: [PATCH 2/2] Fix param type declaration in phpdoc --- src/HL7/Segments/MSH.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HL7/Segments/MSH.php b/src/HL7/Segments/MSH.php index 59f015c..d051b8e 100644 --- a/src/HL7/Segments/MSH.php +++ b/src/HL7/Segments/MSH.php @@ -134,7 +134,7 @@ public function setSecurity($value, int $position = 8) * ORM^R01. If it was empty then the new value will be just ORM. * * Ref: https://hl7-definition.caristix.com/v2/HL7v2.5/Fields/MSH.9 - * @param string $value + * @param string|array $value */ public function setMessageType($value, int $position = 9): bool {