0

I receive an ORM_O01 messages from various vendors. Previously we work only with version 2.3 and 2.6. Now, we receive order with version 2.5. And I can't support 3 copy-pasted code in same time.

Is it possible to treat all messages with ca.uhn.hl7v2.model.v26. package? All HL7 versions are backward compatible, so by logic I can use v26 to parse orders with older versions. Currently I was able to parse it as generic message, but I have no idea how to deal with it. From first look, it will be more easy to write own parser than use generic message API.

degr
  • 1,559
  • 1
  • 19
  • 37

1 Answers1

0

I found solution on HAPI website - https://hapifhir.github.io/hapi-hl7v2/xref/ca/uhn/hl7v2/examples/HandlingMultipleVersions.html

         String v23Message = "hl7 message with version 2.3";
         HapiContext context = new DefaultHapiContext();
         CanonicalModelClassFactory mcf = new CanonicalModelClassFactory("2.5");
         context.setModelClassFactory(mcf);
         PipeParser parser = context.getPipeParser();

         ca.uhn.hl7v2.model.v25.message.ORU_R01 msg = (ca.uhn.hl7v2.model.v25.message.ORU_R01) parser.parse(v23message);
degr
  • 1,559
  • 1
  • 19
  • 37