3

I am trying to create an HL7 message using code similar to the following:

Message message = new DefaultModelClassFactory().getMessageClass("ADT_A01", "2.3", false).newInstance();
Terser terser = new Terser(message);
terser.set("FHS-1-1","|");
... similar terser.set calls for other FHS fields
terser.set("BHS-1-1","|");
... similar terser.set calls for other BHS fields
terser.set("MSH-1-1","|");
... similar terser.set calls for other MSH fields

and what I need is that the generated message would have the segments in the order: FHS BHS MSH

while the actual result is: FHS MSH BHS

so my question is, is there a way to control the order of the generated segments when using HAPI terser? or is there a way to force the terser to generate the segments in the same order as they are created using the set method?

Nawar Khoury
  • 170
  • 2
  • 13

1 Answers1

1

According the defintion .getMessageClass(String theName, String theVersion, boolean isExplicit) your usage of .getMessageClass seems to be wrong.

Try something like that

DefaultModelClassFactory().getMessageClass("ADT_A01", "2.5",false).newInstance();
sqlab
  • 6,412
  • 1
  • 14
  • 29
  • well you are right about that, but it is not the problem, it was a typo when I wrote the code here, but in my code I am setting the version and message type correctly...sorry about that I am just wondering if there is a way to control the order in which the segments get generated, it seems random to me, I am sure there is some logic behind it, but I just couldn't find anything regarding that in the documentations. – Nawar Khoury Apr 13 '16 at 05:44
  • Did you check your template for ADT^A01? I guess you could create a new template or modify an already existing one according your needs. – sqlab Apr 13 '16 at 07:36
  • good point, but I actually got the same result with all templates that I tried. – Nawar Khoury Apr 13 '16 at 07:50
  • I tried using a generic message, like this message = new GenericMessage.UnknownVersion(new DefaultModelClassFactory()); and also got the same result... – Nawar Khoury Apr 13 '16 at 07:51
  • Maybe hapi does not support batch file processing. – sqlab Apr 13 '16 at 08:25
  • yeah I think it doesn't... I wrote my own code that manipulates the message to fit my requirement... thank you very much for your help :) – Nawar Khoury Apr 13 '16 at 09:05