Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEGMENT_ENDING_BAR doesn't work with alternate field separators #128

Closed
skeemer opened this issue Jan 4, 2025 · 5 comments · Fixed by #129
Closed

SEGMENT_ENDING_BAR doesn't work with alternate field separators #128

skeemer opened this issue Jan 4, 2025 · 5 comments · Fixed by #129

Comments

@skeemer
Copy link
Contributor

skeemer commented Jan 4, 2025

Fails because the if statement explicitly removes "|".

$msg = new Message("MSH#^~\\&#1#\nABC###xxx#\n", ['SEGMENT_ENDING_BAR' => false]);
self::assertSame("MSH#^~\\&#1\nABC###xxx\n", $msg->toString(true), 'No ending field separator on each segment');

This can be simply fixed by substr($x, 0, -1) but I recommend deprecating the name SEGMENT_ENDING_BAR and variable $segmentEndingBar in favor of SEGMENT_ENDING_FIELD_SEPARATOR and $segmentEndingFieldSeparator.

Deprecation would include fallbacks like the following until the next major release.

$this->segmentEndingBar = $hl7Globals['SEGMENT_ENDING_FIELD_SEPARATOR'] ?? $hl7Globals['SEGMENT_ENDING_BAR'] ?? true

I would also move the if() statement from the toString() to the segmentToString() so that the setting doesn't get ignored if segmentToString() is called directly.

Please let me know which is the best way to create the PR. The test changes for a #127 fix require this to work.

@senaranya
Copy link
Owner

Glad you found the issue with it, and many thanks for reporting and offering to contribute.

I'd probably name it SEGMENT_ENDING_CHARACTER that accepts any character including '' (which is equivalent to false in the current case).

Since we'll be accepting only a single-character string, we need to add a validation for the same.

Regarding the segmentToString change, while I agree moving the ending character logic to it, this might be a breaking change for those who're already calling the method? May be we should do it in the next major release.

In the PR please update Readme, and mention SEGMENT_ENDING_BAR as deprecated, and that it'll be removed in the next major release.

@skeemer
Copy link
Contributor Author

skeemer commented Jan 9, 2025

SEGMENT_ENDING_BAR replacement

I don't think setting a separate character is the correct route because it has to be the same as the field separator to work with HL7 spec. Is this wrong?

Maybe a shorter version would be TRAILING_FIELD_SEPARATOR if that's a concern.

segmentToString() change

I agree with this possibly being a breaking change.

@senaranya
Copy link
Owner

senaranya commented Jan 11, 2025

Agreed that using a separate character than field-separators violates hl7 standard. Also, we already have a SEGMENT_SEPARATOR global.

I'd use the word "segment" and avoid "field" as we're essentially separating the segments with this. May be WITH_SEGMENT_ENDING_BAR? That should make it clear that it's meant for segment-endings, and accepts true/false value?

@skeemer
Copy link
Contributor Author

skeemer commented Jan 12, 2025

I think we need to stick with the 'field' term to relate it to the correct separator character. Also, WITH_SEGMENT_ENDING_BAR goes back to the original problem of defining using bar which is incorrect. It is the field separator.

I did check the spec to see if there was already existing terminology that we could use. But I just found that it actually violates the definition for the field separator.

Separates two adjacent data fields within a segment. It also separates the segment ID from the first data field in each segment.

The the spec doesn't allow for it, although it sounds like quite a few companies use it, so we need to support it. I'm not sure if this is something left over from v1 but it shouldn't have been used by anyone implementing v2. 🫤

After all of that, I think TRAILING_FIELD_SEPARATOR=t/f is the most descriptive of what is actually happening; we are allowing the use of a trailing field separator.

@senaranya
Copy link
Owner

That makes sense, but since we're talking about the presence of the separator at the end of a segment, wouldn't TRAILING_FIELD_SEPARATOR be a little confusing? As in, it doesn't say "what" it trails. May be SEGMENT_ENDING_FIELD_SEPARATOR as you had suggested earlier?

Also, since this field does not actually contain the separator but rather true/false, probably WITH_SEGMENT_ENDING_FIELD_SEPARATOR will be a better name? A little on the bigger side, but at least it conveys the intent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants