Skip to content

Commit

Permalink
Add missing HL7::withSegmentEndingFieldSeparator() (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
skeemer authored Feb 1, 2025
1 parent caa29fa commit 03ea6fe
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/HL7.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ public function withFieldSeparator(string $value): self
return $this->setGlobal('FIELD_SEPARATOR', $value);
}

/**
* Set whether the field separator should be added to the end of each segment. Default: true
*/
public function withSegmentEndingFieldSeparator(bool $value = true): self
{
return $this->setGlobal('WITH_SEGMENT_ENDING_FIELD_SEPARATOR', $value);
}

/**
* Set the segment separator to be used by the factory. Should be a single character. Default: \015
*
Expand Down Expand Up @@ -187,7 +195,7 @@ public function doNotSplitRepetition(bool $value = true): self
return $this;
}

private function setGlobal(string $name, string $value): self
private function setGlobal(string $name, bool|string $value): self
{
$this->hl7Globals[$name] = $value;
return $this;
Expand Down
34 changes: 34 additions & 0 deletions tests/HL7Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,42 @@ public function hl7_properties_can_be_set_using_chained_methods(): void
->withRepetitionSeparator('`')
->withEscapeCharacter('=')
->withHL7Version('555.666')
->withSegmentEndingFieldSeparator(false)
->createMessage();
self::assertStringContainsString('MSH#*`=}#', $msg->toString(true));
self::assertStringEndsWith('555.666[', $msg->toString(true));
}

/**
* @test
* @throws HL7Exception
*/
public function withSegmentEndingFieldSeparator_defaults_to_true(): void
{
$msg = HL7::build()
->withHL7Version('555.666')
->withSegmentEndingFieldSeparator()
->createMessage();
self::assertStringEndsWith('555.666|\n', $msg->toString());
}

/**
* @test
* @throws HL7Exception
*/
public function withSegmentEndingFieldSeparator_works_with_values(): void
{
$msg = HL7::build()
->withHL7Version('555.666')
->withSegmentEndingFieldSeparator(true)
->createMessage();
self::assertStringEndsWith('555.666|\n', $msg->toString());

$msg = HL7::build()
->withHL7Version('555.666')
->withSegmentEndingFieldSeparator(false)
->createMessage();
self::assertStringEndsWith('555.666\n', $msg->toString());
}

/**
Expand Down

0 comments on commit 03ea6fe

Please sign in to comment.