Advice about HL7 Message creations for repeating loop items
Hello,
I am trying to create a HL7 message (REF_I12 message) using variables extracted from a Dynamic Object and need some advice about segment creation issues that I am having. Some background info: I receive a JSON response from an API call and used %FromJSON to convert the response to an Dynamic Object. Some of the items in the response are repeated such as NOKName, NOKrelationship.
Using the methods suggested in this post (https://community.intersystems.com/post/advice-about-json-conversions-and-reading-outputs-dynamic-objects), I have been able to extract the values from the response and set them to be variables. For example like so:
set NOKName = object.%Get(i).referral.nextOfKin.%Get(k).name
As part of the loop to extract the value, a command has been entered to create a new NTE segment like so:
d PBTRefMessage.SetValueAt("1", "NTE():SetIDNTE")
d PBTRefMessage.SetValueAt("P", "NTE():SourceofComment")
d PBTRefMessage.SetValueAt("NOKName", "NTE():Comment(1)")
As the NOKname has multiple values from the response, the segment in the message created only shows the last NOKName value in the loop and does not produce an NTE segment/value for each NOKName which is what I would like it to do. I have tried a few different things with the NTE ID substituted and still not able to get a different answer. The final output only has one of the NOKName values.
The schema for the REF_I12 message is as follows:
Raw Definition
2.4Epic:MSH~[~2.4Epic:RF1~]~[~2.4Epic:ZF1~]~[~2.4Epic:AUT~[~2.4Epic:CTD~]~]~[~{~2.4Epic:PRD~[~{~2.4Epic:CTD~}~]~}~]~2.4Epic:PID~[~{~2.4Epic:NK1~}~]~[~{~2.4Epic:GT1~}~]~[~{~2.4Epic:IN1~[~2.4Epic:IN2~]~[~2.4Epic:IN3~]~}~]~[~2.4Epic:ACC~]~[~{~2.4Epic:DG1~}~]~[~{~2.4Epic:DRG~}~]~[~{~2.4Epic:AL1~}~]~[~{~2.4Epic:PR1~[~2.4Epic:AUT~[~2.4Epic:CTD~]~]~}~]~[~{~2.4Epic:OBR~[~{~2.4Epic:NTE~}~]~[~{~2.4Epic:OBX~[~{~2.4Epic:NTE~}~]~}~]~}~]~[~2.4Epic:PV1~[~2.4Epic:PV2~]~]~[~{~2.4Epic:NTE~}~] |
Any suggestions on how I can get each NOKName value to have it's own NTE segment created/or added as an additional value in the existing segment as an second(or third etc) comment in the same segment?