Skip to content

Commit

Permalink
Merge branch 'main' into chores/add-more-ca-test-files
Browse files Browse the repository at this point in the history
  • Loading branch information
basiliskus authored Jul 31, 2024
2 parents 026e2a7 + c436c91 commit 55ed0ad
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import org.hl7.fhir.r4.model.ServiceRequest;

/**
* Updates Placer Order Number (ORC-2) with content from Placer Group Number (ORC-4). It also
* replaces Placer Order Number's Entity Identifier (ORC-2.1) and Namespace Id (ORC-2.2) with Placer
* Group Number's Entity Identifier (ORC-4.1) and Namespace Id (ORC-4.2) respectively. Effectively,
* we're swapping ORC-2 for ORC-4 and vice versa.
* Updates Placer Order Number in ORC and OBR (ORC-2 and OBR-4) with content from Placer Group
* Number (ORC-4). Specifically, it updated ORC-2.1/OBR-2.1 with OBR-4.1, and ORC-2.2/OBR-2.2 with
* OBR-4.2. It also updates Placer Group Number (ORC-4) with the original value for Placer Order
* Number (ORC-2). Specifically, it updates ORC-4.1 and ORC-4.2 with the original values in ORC-2.1
* and ORC-2.2 respectively.
*/
public class SwapPlacerOrderAndGroupNumbers implements CustomFhirTransformation {

Expand All @@ -28,6 +29,8 @@ public void transform(FhirResource<?> resource, Map<String, String> args) {

HapiHelper.setORC2_1Value(serviceRequest, orc4_1);
HapiHelper.setORC2_2Value(serviceRequest, orc4_2);
HapiHelper.setOBR2_1Value(serviceRequest, orc4_1);
HapiHelper.setOBR2_2Value(serviceRequest, orc4_2);
HapiHelper.setORC4_1Value(serviceRequest, orc2_1);
HapiHelper.setORC4_2Value(serviceRequest, orc2_2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ public static HapiMessageHelper getInstance() {
private HapiMessageHelper() {}

public String extractPlacerOrderNumber(Bundle messageBundle) {
// Placer Order Number can be extracted from ORC-2 and OBR-2, but the value is always the
// same
// if available on both
return fhirEngine.getStringFromFhirPath(
messageBundle, Hl7FhirMappingPath.PLACER_ORDER_NUMBER.getFhirPath());
messageBundle, Hl7FhirMappingPath.PLACER_ORDER_NUMBER_ORC_2.getFhirPath());
}

public String extractSendingApplicationNamespace(Bundle messageBundle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
* defines the HL7 field names.
*/
public enum Hl7FhirMappingPath {
PLACER_ORDER_NUMBER(
PLACER_ORDER_NUMBER_ORC_2(
"ORC.2",
"""
Bundle.entry.resource.ofType(ServiceRequest).identifier.where(type.coding.code = 'PLAC').value
"""),
PLACER_ORDER_NUMBER_OBR_2(
"OBR.2",
"""
Bundle.entry.resource.ofType(ServiceRequest).extension.where(url = 'https://reportstream.cdc.gov/fhir/StructureDefinition/obr-observation-request').extension.where(url = 'OBR.2').value
"""),
SENDING_FACILITY_NAMESPACE(
"",
"""
Expand Down
2 changes: 1 addition & 1 deletion etor/src/main/resources/transformation_definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
},
{
"name": "ucsdOruSwapPlacerOrderAndGroupNumbers",
"description": "Swaps UCSD ORU's Placer Order Number (ORC-2) and Placer Group Number (ORC-4)",
"description": "Swaps UCSD ORU's Placer Order Number (ORC-2) and Placer Group Number (ORC-4). It also update OBR-2 with the original value for ORC-4",
"message": "",
"conditions": [
"Bundle.entry.resource.ofType(MessageHeader).destination.receiver.resolve().identifier.where(extension.value = 'HD.1').value in ('R797' | 'R508')",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,41 @@ class SwapPlacerOrderAndGroupNumbersTest extends Specification {
transformClass = new SwapPlacerOrderAndGroupNumbers()
}

def "swap ORC-2.1 with ORC-4.1 and ORC-2.2 with ORC-4.2"() {
def "swap ORC-2.1 + OBR-2.1 with ORC-4.1 and ORC-2.2 + OBR-2.2 with ORC-4.2"() {
given:
def fhirResource = ExamplesHelper.getExampleFhirResource("../MN/004_MN_ORU_R01_NBS_1_hl7_translation.fhir")
def bundle = fhirResource.getUnderlyingResource() as Bundle

def serviceRequest = HapiHelper.resourceInBundle(bundle, ServiceRequest)
def orc2_1 = HapiHelper.getORC2_1Value(serviceRequest)
def obr2_1 = HapiHelper.getOBR2_1Value(serviceRequest)
def orc2_2 = HapiHelper.getORC2_2Value(serviceRequest)
def obr2_2 = HapiHelper.getOBR2_2Value(serviceRequest)
def orc4_1 = HapiHelper.getORC4_1Value(serviceRequest)
def orc4_2 = HapiHelper.getORC4_2Value(serviceRequest)

expect:
orc2_1 == "423787478"
obr2_1 == "423787478"
orc2_2 == "EPIC"
obr2_2 == "EPIC"
orc4_1 == null
orc4_2 == null

when:
transformClass.transform(fhirResource, null)
def actualOrc2_1 = HapiHelper.getORC2_1Value(serviceRequest)
def actualObr2_1 = HapiHelper.getOBR2_1Value(serviceRequest)
def actualOrc2_2 = HapiHelper.getORC2_2Value(serviceRequest)
def actualObr2_2 = HapiHelper.getOBR2_2Value(serviceRequest)
def actualOrc4_1 = HapiHelper.getORC4_1Value(serviceRequest)
def actualOrc4_2 = HapiHelper.getORC4_2Value(serviceRequest)

then:
actualOrc2_1 == orc4_1
actualObr2_1 == orc4_1
actualOrc2_2 == orc4_2
actualObr2_2 == orc4_2
actualOrc4_1 == orc2_1
actualOrc4_2 == orc2_2
}
Expand Down
2 changes: 1 addition & 1 deletion shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies {
//logging
implementation 'org.slf4j:slf4j-api:2.0.13'
implementation 'ch.qos.logback:logback-classic:1.5.6'
implementation 'net.logstash.logback:logstash-logback-encoder:7.4'
implementation 'net.logstash.logback:logstash-logback-encoder:8.0'

//jackson
implementation 'com.fasterxml.jackson.core:jackson-core:2.17.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ private HapiHelper() {}
public static final StringType EXTENSION_HD2_HD3_DATA_TYPE = new StringType("HD.2,HD.3");
public static final StringType EXTENSION_ORC2_DATA_TYPE = new StringType("ORC.2");
public static final StringType EXTENSION_ORC4_DATA_TYPE = new StringType("ORC.4");
public static final StringType EXTENSION_OBR2_DATA_TYPE = new StringType("OBR.2");

public static final String EXTENSION_CODING_SYSTEM =
"https://reportstream.cdc.gov/fhir/StructureDefinition/cwe-coding-system";
Expand All @@ -61,6 +62,9 @@ private HapiHelper() {}
"O21",
"OML - Laboratory order");

public static final String EXTENSION_OBR_URL =
"https://reportstream.cdc.gov/fhir/StructureDefinition/obr-observation-request";

/**
* Returns a {@link Stream} of FHIR resources inside the provided {@link Bundle} that match the
* given resource type.
Expand Down Expand Up @@ -411,6 +415,53 @@ public static String getORC21Value(ServiceRequest serviceRequest) {

// OBR - Observation Request

// OBR-2 - Placer Order Number
public static Identifier getOBR2Identifier(ServiceRequest serviceRequest) {
if (!serviceRequest.hasExtension(EXTENSION_OBR_URL)
|| !serviceRequest
.getExtensionByUrl(EXTENSION_OBR_URL)
.hasExtension(EXTENSION_OBR2_DATA_TYPE.toString())) {
return null;
}
var extension =
serviceRequest
.getExtensionByUrl(EXTENSION_OBR_URL)
.getExtensionByUrl(EXTENSION_OBR2_DATA_TYPE.toString());
return extension.castToIdentifier(extension.getValue());
}

// OBR-2.1 - Entity Identifier
public static String getOBR2_1Value(ServiceRequest serviceRequest) {
var identifier = getOBR2Identifier(serviceRequest);
if (identifier == null) {
return null;
}
return getEI1Value(identifier);
}

public static void setOBR2_1Value(ServiceRequest serviceRequest, String value) {
var identifier = getOBR2Identifier(serviceRequest);
if (identifier != null) {
setEI1Value(identifier, value);
}
}

// OBR-2.2 - Namespace ID
public static String getOBR2_2Value(ServiceRequest serviceRequest) {
var identifier = getOBR2Identifier(serviceRequest);
if (identifier == null) {
return null;
}
return getEI2Value(identifier);
}

public static void setOBR2_2Value(ServiceRequest serviceRequest, String value) {
var identifier = getOBR2Identifier(serviceRequest);
if (identifier != null) {
setEI2Value(identifier, value);
}
}

// OBR-4 - Universal Service Identifier

// OBR-4.1 - Identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,38 @@ class HapiHelperTest extends Specification {
HapiHelper.getORC21Value(sr) == null
}

// OBR-2 - Placer Order Number
def "obr-2 getter and setter methods work as expected"() {
given:
def obr2_1 = "obr2_1"
def obr2_2 = "obr2_2"
def bundle = new Bundle()
def serviceRequest = new ServiceRequest()
bundle.addEntry(new Bundle.BundleEntryComponent().setResource(serviceRequest))

expect:
HapiHelper.getOBR2Identifier(serviceRequest) == null
HapiHelper.getOBR2_1Value(serviceRequest) == null
HapiHelper.getOBR2_2Value(serviceRequest) == null

when:
HapiFhirHelper.setOBR2Extension(serviceRequest, new Identifier())

then:
HapiHelper.getOBR2Identifier(serviceRequest) != null
HapiHelper.getOBR2_1Value(serviceRequest) == null
HapiHelper.getOBR2_2Value(serviceRequest) == null

when:
HapiHelper.setOBR2_1Value(serviceRequest, obr2_1)
HapiHelper.setOBR2_2Value(serviceRequest, obr2_2)


then:
HapiHelper.getOBR2_1Value(serviceRequest) == obr2_1
HapiHelper.getOBR2_2Value(serviceRequest) == obr2_2
}

// OBR-4.1 - Observation Identifier
def "getOBR4_1Value returns the correct value"() {
given:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ class HapiFhirHelper {
organization.addExtension().setUrl(HapiHelper.EXTENSION_XON_ORGANIZATION_URL).addExtension(HapiHelper.EXTENSION_XON10_URL, new StringType(value))
}

// OBR - Placer Order Number
static void setOBR2Extension(ServiceRequest serviceRequest, Identifier identifier) {
serviceRequest.addExtension().setUrl(HapiHelper.EXTENSION_OBR_URL).addExtension(HapiHelper.EXTENSION_OBR2_DATA_TYPE.toString(), identifier)
}

// OBR-4 - Universal Service Identifier
static void setOBR4_1Value(ServiceRequest serviceRequest, String value) {
serviceRequest.setCode(new CodeableConcept().addCoding(new Coding().setCode(value)))
Expand Down

0 comments on commit 55ed0ad

Please sign in to comment.