diff --git a/src/main/java/io/github/linuxforhealth/hl7/HL7ToFHIRConverter.java b/src/main/java/io/github/linuxforhealth/hl7/HL7ToFHIRConverter.java index 8f37d8fc..ff7f1605 100644 --- a/src/main/java/io/github/linuxforhealth/hl7/HL7ToFHIRConverter.java +++ b/src/main/java/io/github/linuxforhealth/hl7/HL7ToFHIRConverter.java @@ -118,7 +118,7 @@ public String convert(String hl7MessageData) { public String convert(String hl7MessageData, ConverterOptions options) { HL7MessageEngine engine = getMessageEngine(options); - Bundle bundle = convertToBundle(hl7MessageData, options); + Bundle bundle = convertToBundle(hl7MessageData, options, engine); return engine.getFHIRContext().encodeResourceToString(bundle); } @@ -127,14 +127,16 @@ public String convert(String hl7MessageData, ConverterOptions options) { * * @param hl7MessageData Message to convert * @param options Options for conversion - * + * @param engine Hl7Message engine * @return Bundle {@link Bundle} resource. * @throws UnsupportedOperationException - if message type is not supported */ - public Bundle convertToBundle(String hl7MessageData, ConverterOptions options) { + public Bundle convertToBundle(String hl7MessageData, ConverterOptions options, HL7MessageEngine engine) { Preconditions.checkArgument(StringUtils.isNotBlank(hl7MessageData), "Input HL7 message cannot be blank"); - HL7MessageEngine engine = getMessageEngine(options); + if(engine == null) { + engine = getMessageEngine(options); + } Message hl7message = getHl7Message(hl7MessageData); if (hl7message != null) { diff --git a/src/test/java/io/github/linuxforhealth/FHIRConverterTest.java b/src/test/java/io/github/linuxforhealth/FHIRConverterTest.java index 26785885..20378d97 100644 --- a/src/test/java/io/github/linuxforhealth/FHIRConverterTest.java +++ b/src/test/java/io/github/linuxforhealth/FHIRConverterTest.java @@ -58,7 +58,7 @@ void test_patient_encounter_bundle_return() throws IOException { "MRG|MR2^^^XYZ\n"; HL7ToFHIRConverter ftv = new HL7ToFHIRConverter(); - Bundle b = ftv.convertToBundle(hl7message, OPTIONS); + Bundle b = ftv.convertToBundle(hl7message, OPTIONS, null); assertThat(b.getType()).isEqualTo(BundleType.COLLECTION);