diff --git a/shared/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiHelper.java b/shared/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiHelper.java index da12af1be..746bb72b7 100644 --- a/shared/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiHelper.java +++ b/shared/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiHelper.java @@ -158,10 +158,21 @@ public static Identifier getMSH6_1Identifier(Bundle bundle) { return getHD1Identifier(identifiers); } + public static Identifier createMSH6_1Identifier() { + Identifier identifier = new Identifier(); + setHD1Identifier(identifier); + return identifier; + } + public static void setMSH6_1Value(Bundle bundle, String value) { Identifier identifier = getMSH6_1Identifier(bundle); if (identifier == null) { - return; + identifier = createMSH6_1Identifier(); + Organization receivingFacility = getMSH6Organization(bundle); + if (receivingFacility == null) { + return; + } + receivingFacility.addIdentifier(identifier); } identifier.setValue(value); } @@ -403,7 +414,7 @@ public static String getORC21Value(ServiceRequest serviceRequest) { // OBR-4.1 - Identifier public static String getOBR4_1Value(ServiceRequest serviceRequest) { CodeableConcept cc = serviceRequest.getCode(); - if (cc == null || cc.getCoding().isEmpty()) { + if (cc.getCoding().isEmpty()) { return null; } return getCWE1Value(cc.getCoding().get(0)); @@ -419,6 +430,10 @@ public static Identifier getHD1Identifier(List identifiers) { return hd1Identifiers.get(0); } + public static void setHD1Identifier(Identifier identifier) { + setHl7FieldExtensionValue(identifier, EXTENSION_HD1_DATA_TYPE); + } + // CWE - Coded with Exceptions public static String getCWE1Value(Coding coding) { return coding.getCode(); diff --git a/shared/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiHelperTest.groovy b/shared/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiHelperTest.groovy index a81077e55..8532a9d18 100644 --- a/shared/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiHelperTest.groovy +++ b/shared/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiHelperTest.groovy @@ -2,7 +2,6 @@ package gov.hhs.cdc.trustedintermediary.external.hapi import org.hl7.fhir.r4.model.Bundle import org.hl7.fhir.r4.model.Coding -import org.hl7.fhir.r4.model.DiagnosticReport import org.hl7.fhir.r4.model.Extension import org.hl7.fhir.r4.model.Identifier import org.hl7.fhir.r4.model.MessageHeader @@ -254,15 +253,30 @@ class HapiHelperTest extends Specification { then: HapiHelper.getMSH6Organization(bundle) == null + when: + HapiHelper.setMSH6_1Value(bundle, msh6_1) + + then: + HapiHelper.getMSH6_1Identifier(bundle) == null + when: def receivingFacility = HapiFhirHelper.createOrganization() HapiFhirHelper.setMSH6Organization(bundle, receivingFacility) HapiHelper.setMSH6_1Value(bundle, msh6_1) + then: + HapiHelper.getMSH6_1Identifier(bundle) != null + HapiFhirHelper.getMSH6_1Value(bundle) == msh6_1 + + when: + receivingFacility = HapiFhirHelper.createOrganization() + HapiFhirHelper.setMSH6Organization(bundle, receivingFacility) + HapiHelper.setMSH6_1Value(bundle, msh6_1) + then: HapiHelper.getMSH6Organization(bundle).equalsDeep(receivingFacility) - HapiHelper.getMSH6_1Identifier(bundle) == null - HapiFhirHelper.getMSH6_1Value(bundle) != msh6_1 + HapiHelper.getMSH6_1Identifier(bundle) != null + HapiFhirHelper.getMSH6_1Value(bundle) == msh6_1 when: HapiFhirHelper.setMSH6_1Identifier(bundle, new Identifier()) @@ -502,6 +516,7 @@ class HapiHelperTest extends Specification { def "orc-4.1 methods work as expected"() { given: def orc4_1 = "orc4_1" + def orc4_1b = "orc4_1b" def bundle = new Bundle() def dr = HapiFhirHelper.createDiagnosticReport(bundle) def sr = HapiFhirHelper.createBasedOnServiceRequest(dr) @@ -514,12 +529,19 @@ class HapiHelperTest extends Specification { then: HapiHelper.getORC4_1Value(sr) == orc4_1 + + when: + HapiHelper.setORC4_1Value(sr, orc4_1b) + + then: + HapiHelper.getORC4_1Value(sr) == orc4_1b } // ORC-4.2 - Namespace ID def "orc-4.2 methods work as expected"() { given: def orc4_2 = "orc4_2" + def orc4_2b = "orc4_2b" def bundle = new Bundle() def dr = HapiFhirHelper.createDiagnosticReport(bundle) def sr = HapiFhirHelper.createBasedOnServiceRequest(dr) @@ -532,6 +554,12 @@ class HapiHelperTest extends Specification { then: HapiHelper.getORC4_2Value(sr) == orc4_2 + + when: + HapiHelper.setORC4_2Value(sr, orc4_2b) + + then: + HapiHelper.getORC4_2Value(sr) == orc4_2b } def "orc-21 methods work as expected"() { @@ -589,6 +617,12 @@ class HapiHelperTest extends Specification { then: HapiHelper.getOBR4_1Value(sr) == expectedValue + + when: + sr.setCode(null) + + then: + HapiHelper.getOBR4_1Value(sr) == null } // HD - Hierarchic Designator