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

getComponent is not working if there is a repetition #77

Open
StefanoV1989 opened this issue May 19, 2022 · 2 comments
Open

getComponent is not working if there is a repetition #77

StefanoV1989 opened this issue May 19, 2022 · 2 comments

Comments

@StefanoV1989
Copy link

StefanoV1989 commented May 19, 2022

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       
@StefanoV1989 StefanoV1989 changed the title getComponent is not working if there is a repeatition getComponent is not working if there is a repetition May 19, 2022
@hitgeek
Copy link
Owner

hitgeek commented May 19, 2022

yea, I think this is an issue. v4 has a method called getFieldComponent(3, 1, 1) https://github.com/hitgeek/simple-hl7/blob/v4.0/lib/hl7/segment.js to make this easier.

In v3 you need to use getField() and split it like pid.getField(3, 1).split('^')[0]

@StefanoV1989
Copy link
Author

yea, I think this is an issue. v4 has a method called getFieldComponent(3, 1, 1) https://github.com/hitgeek/simple-hl7/blob/v4.0/lib/hl7/segment.js to make this easier.

In v3 you need to use getField() and split it like pid.getField(3, 1).split('^')[0]

Oh ok! I made a pull request with the fix mentioned and it works.
If you want to try it out to make a minor release just for now.

Thank you.

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