Menu

#247 Insert a Z Segment after a standard segment

2.3
open
Z Segment (1)
5
2018-05-25
2018-04-21
No

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

Discussion

  • SWAROOP CHAKRABORTY

    Can anyone please help me solve this problem ?

     
  • Christian Ohr

    Christian Ohr - 2018-04-25

    Can you provide some sample code on how you create this message? Do you need to send it or receive/parse it?

     
  • SWAROOP CHAKRABORTY

    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

    {
    
        ADT_A01 adt= new ADT_A01();
        try {
            adt.initQuickstart("ADT", "A01", "P");
            MSH mshSegment=adt.getMSH();
            PID pid=adt.getPID();
            PV1 pv1=adt.getPV1();
            IN1 in1=adt.getINSURANCE().getIN1();
            in1.getIn11_SetIDIN1().setValue("1");
            pid.getPid1_SetIDPID().setValue("1");
            pv1.getPv11_SetIDPV1().setValue("1");
            HapiContext context = new DefaultHapiContext();
            Parser parser = context.getPipeParser();
            String encodedMessage = parser.encode(adt);
            PipeParser pipeParser = new PipeParser();
            Message message = pipeParser.parse(encodedMessage);
    
            Terser terser = new Terser(message);
            message.addNonstandardSegment("ZPV");
            message.addNonstandardSegment("ZIN");
    
            terser.set("/.ZIN(1)-1","1");
            terser.set("/ZIN(1)-2","Z-Segment-1ZIN");
    
            terser.set("/ZIN(2)-1","2");
            terser.set("/ZIN(2)-2","Z-Segment-2ZIN");
    
            terser.set("/.ZPV(1)-1","1");
            terser.set("/ZPV(1)-2","Z-Segment-1ZPV");
    
            System.out.println(message.encode());
    
            //return encodedMessage;
        } catch (HL7Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
    }
    
     
  • SWAROOP CHAKRABORTY

    Post awaiting moderation.
  • SWAROOP CHAKRABORTY

    Post awaiting moderation.
  • SWAROOP CHAKRABORTY

    any update on this?

     
  • Christian Ohr

    Christian Ohr - 2018-05-01

    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

     
  • SWAROOP CHAKRABORTY

    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?

     
  • Christian Ohr

    Christian Ohr - 2018-05-02

    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:

    ADT_A01 adt = new ADT_A01();
    adt.initQuickstart("ADT", "A01", "P");
    PID pid = adt.getPID();
    PV1 pv1 = adt.getPV1();
    ADT_A01_INSURANCE insurance = adt.getINSURANCE();
    IN1 in1 = insurance.getIN1();
    in1.getIn11_SetIDIN1().setValue("1");
    pid.getPid1_SetIDPID().setValue("1");
    pv1.getPv11_SetIDPV1().setValue("1");
    
    adt.addNonstandardSegment("ZPV", 10);
    Terser terser = new Terser(adt);
    terser.set("/ZPV(0)-1","1");
    terser.set("/ZPV(0)-2","Z-Segment-1ZPV");
    
    insurance.addNonstandardSegment("ZIN", 1);
    terser.set("/.ZIN(0)-1","1");
    terser.set("/.ZIN(0)-2","Z-Segment-1ZPV");
    terser.set("/.ZIN(1)-1","2");
    terser.set("/.ZIN(1)-2","Z-Segment-2ZPV");
    
    System.out.println(adt.encode().replace('\r', '\n'));
    

    you will get

    MSH|^~\&|||||20180502112533.85+0200||ADT^A01^ADT_A01|5601|P|2.8.1
    PID|1
    PV1|1
    ZPV|1|Z-Segment-1ZPV
    IN1|1
    ZIN|1|Z-Segment-1ZPV
    ZIN|2|Z-Segment-2ZPV
    
     
  • SWAROOP CHAKRABORTY

    Thank you Chris, your idea solved my problem. You may close this ticket.

     

Log in to post a comment.