hl7hapihl7-v2

How to add extra components to HL7 message using Java Hapi?


I am working on building a replacement to MIRTH and it looks like we are sending out non-standard HL7 ORU_R01 messages. OBR.5 should be just a single field but looks like we are sending a bunch of other data in this section.

<OBR.5>
   <OBR.5.1>XXXX</OBR.5.1>
   <OBR.5.2>XXXX</OBR.5.2>
   <OBR.5.3>XXXXX</OBR.5.3>
   <OBR.5.5>XXXXX</OBR.5.5>
   <OBR.5.6>XXXX</OBR.5.6>
   <OBR.5.7/>
   <OBR.5.8>XXXXXXXXXX</OBR.5.8>
   <OBR.5.10>XXXXXXX</OBR.5.10>
   <OBR.5.11>X</OBR.5.11>
   <OBR.5.12>X</OBR.5.12>
   <OBR.5.13>XXXXX</OBR.5.13>
   <OBR.5.15>XXXXXXX</OBR.5.15>
 </OBR.5>

It seems like I should be able to something like the following.

 obr.getObr5_Priority().getExtraComponents().getComponent(2).setData(...)

But I am having issues trying to find the correct way to set the different segments. All the fields are Strings.


Solution

  • Found something that I think has ended up working for us.

    ID expirationDate = new ID(obr.getMessage(), 502);                                     
    expirationDate.setValue(format2.format(date));
    obr.getObr5_Priority().getExtraComponents().getComponent(0).setData(expirationDate);
    

    Where 503 refers to which element you want to set. In this case I am trying to set OBR-5.2. getComponent(0) because it's the first extra component I am adding for this particular segment. I am not sure entirely if my explanation here is correct but it creates a message we need and parses as I'd expect so its my best guess.

    Dereived the answer from this old email thread https://sourceforge.net/p/hl7api/mailman/hl7api-devel/thread/0C32A03544668145A925DD2C339F2BED017924D8%40FFX-INF-EX-V1.cgifederal.com/#msg19632481