Hi,
I have created the following ADT message with 2 Z-segments(ZIN and ZPV) using HAPI 2.3.1 :
MSH|^~\&|SENDING_APPLICATION|SENDING_FACILITY|RECEIVING_APPLICATION|RECEIVING_FACILITY|20110613083617||ADT^A01|934576120110613083617|P|2.3.1||||
EVN|A01|20110613083617|||
PID|1||135769||MOUSE^MICKEY^||19281118|M|||123 Main St.^^Lake Buena Vista^FL^32830||(407)939-1289^^^theMainMouse@disney.com|||||1719|99999999||||||||||||||||||||
PV1|1|O|||||^^^^^^^^|^^^^^^^^
ZIN|1|Z-Segment-1
ZIN|2|Z-Segment-2
ZPV|1|Z-Segment-1
Generally, In HAPI, Z-segments are generated at the bottom after generating all the standard segments such as MSH EVN PID..... so on.
The question is how do I move a Z-Segment from the bottom of the message and insert it after a particular standard segment, in this case, I want to move ZPV just after the PV1 segment as a part of user requirement at the sender side?
Please help me on how to acheive this
Can anyone please help me solve this problem ?
Can you provide some sample code on how you create this message? Do you need to send it or receive/parse it?
Hi Chris,
The following is the sample code thru I created it and I need to send this created message over some destination:
public static void main(String args[]) throws HL7Exception, IOException
any update on this?
Did you already try the method message.addNonstandardSegment(String name, int index)? With this method you should be able to insert your custom segment at the "index" position in the message or message group
Hi Chris, I tried with the method message.addNonstandardSegment(String name, int index) too, but how do I let the method know exactly after which standard segment I need to place the custom segment.
As an example I tried setting message.addNonstandardSegment("ZPV",20); to the code, but it does not comes after PV1.
What should I do to acheive this?
What do try to achieve with 20?
First thing I urgently recommend you to get a copy of the HL7 specification (https://www.hl7.org/implement/standards/product_brief.cfm?product_id=185; yes, you need to have an account!). Sometimes, an online tool like http://hl7-definition.caristix.com:9010/ is also sufficient.
From the ADT_A01 definition, you can see that PV1 is the 10th segment in the message. As the index is zero-based, message.addNonstandardSegment("ZPV", 10); will add a ZPV segment after PV1.
The IN1 segment is the first segment of the INSURANCE group, so you have to add it after this.
Note that repetitions of segments are also zero-based.
So, if you change your code like this:
you will get
Thank you Chris, your idea solved my problem. You may close this ticket.