Skip to content

getComponent is not working if there is a repetition #77

@StefanoV1989

Description

@StefanoV1989

I have this PID segment:
PID|1|124553|124553^^^TEST^PI~~~||JOHN^DOE|

If i use this code to get the name it works:
req.msg.getSegment('PID').getComponent(5, 1)

If i use this code to get the text "TEST", i get an empty string:
req.msg.getSegment('PID').getComponent(3, 4)

If i then remove the ~ repetition separator, then it works!

I can re-parse the message manually, but i prefer a more "elegant" solution.

const field = req.msg.getSegment('PID').getField(3, 1);
const reparse = new hl7.Parser().parseField(field);
console.log(reparse.value[0][3].toString());

Is there a bug about this, or am i wrong in something?

EDIT:

I think you can just check if you have repetition in the field adding something like this in the getComponent function.

if(components.value) components = components.value[0]; // HERE I CHECK IF I HAVE REPETITIONS       

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions