Skip to content

Commit

Permalink
Fix UCSD ORU transformation to update MSH-6.1 with ORC-21.10 (#1165)
Browse files Browse the repository at this point in the history
* Added helper methods to create MSH-6.1 identifier in case it doesn't exist

* Update HapiHelperTest.groovy

Fixed unit test and included some additional coverage cases

* Update HapiHelperTest.groovy

Add testCase for null coding on ServiceRequest

* Update HapiHelper.java

The code element on serviceRequest is created on get when null, so we don't need the check in the if

* 100% coverage on HapiHelper

---------

Co-authored-by: Luis Pabon <[email protected]>
  • Loading branch information
basiliskus and luis-pabon-tf authored Jul 9, 2024
1 parent 14f6ece commit 783ce7d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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));
Expand All @@ -419,6 +430,10 @@ public static Identifier getHD1Identifier(List<Identifier> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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"() {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 783ce7d

Please sign in to comment.