Skip to content

Commit

Permalink
Merge pull request #1288 from CDCgov/task/1243-ca_transform_obr4.3_mo…
Browse files Browse the repository at this point in the history
…dication

Transformation: Modified OBR-4.3 codingSystem
  • Loading branch information
jbiskie authored Sep 10, 2024
2 parents 1ce5113 + 684ee83 commit 6c599da
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
* Service Identifier (OBR-4)
*/
public class UpdateUniversalServiceIdentifier implements CustomFhirTransformation {

public static final String CHECK_VALUE_NAME = "checkValue";
public static final String CODING_SYSTEM_NAME = "codingSystem";
public static final String ALTERNATE_ID_NAME = "alternateId";

@Override
public void transform(FhirResource<?> resource, Map<String, String> args) {
Bundle bundle = (Bundle) resource.getUnderlyingResource();
Expand All @@ -26,19 +31,22 @@ public void transform(FhirResource<?> resource, Map<String, String> args) {
it -> {
var allCodings = it.getCode().getCoding();
var codingSystemContainer =
getCodingSystemContainer(allCodings, args.get("checkValue"));
getCodingSystemContainer(allCodings, args.get(CHECK_VALUE_NAME));

if (codingSystemContainer == null) {
// we're only interested in coding that matches the checkValue argument
return;
}

// check for the coding system label and create or override it
updateCodingSystemLabel(codingSystemContainer, args.get("codingSystem"));
updateCodingSystemLabel(codingSystemContainer, args.get(CODING_SYSTEM_NAME));

// the alt id is stored on a separate coding object, so we need to filter
// for it
updateAlternateCodingId(allCodings, args);
String alternateId = args.get(ALTERNATE_ID_NAME);
if (alternateId != null) {
updateAlternateCodingId(allCodings, alternateId);
}
});
}

Expand Down Expand Up @@ -81,7 +89,7 @@ private Coding getAltCodingContainer(List<Coding> allCodings) {
}

/** Find and create or update the "Alternate Id" object in a given List */
private void updateAlternateCodingId(List<Coding> allCodings, Map<String, String> args) {
private void updateAlternateCodingId(List<Coding> allCodings, String alternateId) {
var altCodingContainer = getAltCodingContainer(allCodings);

if (altCodingContainer == null) {
Expand All @@ -93,6 +101,6 @@ private void updateAlternateCodingId(List<Coding> allCodings, Map<String, String
altCodingContainer.addExtension(altCodingExtension);
allCodings.add(altCodingContainer);
}
altCodingContainer.setCode(args.get("alternateId"));
altCodingContainer.setCode(alternateId);
}
}
3 changes: 1 addition & 2 deletions etor/src/main/resources/transformation_definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@
"name": "UpdateUniversalServiceIdentifier",
"args": {
"checkValue": "54089-8",
"codingSystem": "LN",
"alternateId": "CDPHGSPEAP"
"codingSystem": "CDPHGSPEAP"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ class UpdateUniversalServiceIdentifierTest extends Specification {
def fhirResource
def args = Map.of(
"checkValue", "54089-8",
"codingSystem", "LN",
"alternateId", "CDPHGSPEAP"
)
"codingSystem", "CDPHGSPEAP",
"alternateId", "CDPHGSPEAP")
def argsNoAlternateId = [
"checkValue": "54089-8",
"codingSystem": "CDPHGSPEAP",
"alternateId": null] as Map

def setup() {
TestApplicationContext.reset()
Expand Down Expand Up @@ -102,10 +105,38 @@ class UpdateUniversalServiceIdentifierTest extends Specification {

then:
transformedObr4_1 == obr4_1
transformedObr4_3 == "LN"
transformedObr4_3 == "CDPHGSPEAP"
transformedObr4_4 == "CDPHGSPEAP"
}


def "update only obr4-1 through obr4-3 values when the code matches and alternate id is null"() {
given:
def bundle = fhirResource.getUnderlyingResource() as Bundle
def result = getObrSections(bundle)[2]
def obr4_1 = result[0]
def obr4_3 = result[1]
def obr4_4 = result[2]

expect:
obr4_1 == "54089-8"
obr4_3 == "NA"
obr4_4 == "This value should change"

when:
transformClass.transform(fhirResource, argsNoAlternateId)
bundle = fhirResource.getUnderlyingResource() as Bundle
def transformedResult = getObrSections(bundle)[2]
def transformedObr4_1 = transformedResult[0]
def transformedObr4_3 = transformedResult[1]
def transformedObr4_4 = transformedResult[2]

then:
transformedObr4_1 == obr4_1
transformedObr4_3 == "CDPHGSPEAP"
transformedObr4_4 == obr4_4
}

def "leave obr4 values unchanged if the code matches and they're already correct"() {
given:
def bundle = fhirResource.getUnderlyingResource() as Bundle
Expand All @@ -116,7 +147,7 @@ class UpdateUniversalServiceIdentifierTest extends Specification {

expect:
obr4_1 == "54089-8"
obr4_3 == "LN"
obr4_3 == "CDPHGSPEAP"
obr4_4 == "CDPHGSPEAP"

when:
Expand Down Expand Up @@ -156,7 +187,7 @@ class UpdateUniversalServiceIdentifierTest extends Specification {

then:
transformedObr4_1 == obr4_1
transformedObr4_3 == "LN"
transformedObr4_3 == "CDPHGSPEAP"
transformedObr4_4 == "CDPHGSPEAP"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3090,7 +3090,7 @@
},
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/cwe-coding-system",
"valueString": "LN"
"valueString": "CDPHGSPEAP"
}
],
"system": "http://loinc.org",
Expand Down Expand Up @@ -4267,7 +4267,7 @@
},
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/cwe-coding-system",
"valueString": "LN"
"valueString": "CDPHGSPEAP"
}
],
"system": "http://loinc.org",
Expand Down

0 comments on commit 6c599da

Please sign in to comment.