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

Message::toString fails to detect repeated segments. #119

Open
nigulh opened this issue Mar 1, 2024 · 3 comments
Open

Message::toString fails to detect repeated segments. #119

nigulh opened this issue Mar 1, 2024 · 3 comments

Comments

@nigulh
Copy link

nigulh commented Mar 1, 2024

public function testfield_with_repetition_separator_can_be_split_into_array(): void
{
    $messageStr = "MSH|^~\&|||||||ADT^A01||P|2.3.1|\nPID|||3^0~4^1|\n";
    $message = new Message($messageStr, autoIncrementIndices: false);
    self::assertSame($messageStr, $message->toString(true));
}

This test fails, as it returns 3&0^4&1 instead of 3^0~4^1. I don't think that doNotSplitRepetition: true is the correct solution here.

@senaranya
Copy link
Owner

This is what doNotSplitRepetition is meant for. toString() just dumps how the Message object has interpreted the HL7 string as. If you don't want the repetition to be split in the output of toString(), you need to tell Message to treat it as a string and not an array, i.e., by using doNotSplitRepetition: true

@nigulh
Copy link
Author

nigulh commented Mar 4, 2024

Thanks for the response, and thanks for the project!
I would expect that 3^0~4^1 is parsed into [[3, 0], [4, 1]]. If I use doNotSplitRepetition, then it is parsed into [3, 0~4, 1], which is not correct in my case.

@senaranya
Copy link
Owner

With toString(), it'll always convert into string. If you need array you need to fetch the value directly from the field, i.e.

    public function testfield_with_repetition_separator_can_be_split_into_array(): void
    {
        $messageStr = "MSH|^~\&|||||||ADT^A01||P|2.3.1|\nPID|||3^0~4^1|\n";
        $message = new Message($messageStr, doNotSplitRepetition: false);
        $field = $message->getSegmentByIndex(1)->getField(3);
        self::assertIsArray($field);
        self::assertSame([['3', '0'], ['4', '1']], $field);
    }

Alternatively, you can also use the method meant for the given segment's given field, since you're using PID:

    public function testfield_with_repetition_separator_can_be_split_into_array(): void
    {
        $messageStr = "MSH|^~\&|||||||ADT^A01||P|2.3.1|\nPID|||3^0~4^1|\n";
        $message = new Message($messageStr, doNotSplitRepetition: false);
        $patientIdentifierList = $message->getFirstSegmentInstance('PID')->getPatientIdentifierList();
        self::assertIsArray($patientIdentifierList);
        self::assertSame([['3', '0'], ['4', '1']], $patientIdentifierList);
    }

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

No branches or pull requests

2 participants