Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transformation Engine To Use Map<String,Object> As Args #1362

Merged
merged 27 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
34de06c
changes:
jorg3lopez Sep 26, 2024
c65c374
unit test:
jorg3lopez Sep 27, 2024
91d8444
rename test case
jorg3lopez Sep 27, 2024
93e01cb
args.get('name') not a string test case for UpdateSendingFacilityName…
jorg3lopez Sep 27, 2024
f47255c
added casting of Object to test cases in UpdateSendingFacilityNamespa…
jorg3lopez Sep 27, 2024
13dc16d
unit test when args.get('name') is not a string, for UpdateReceivingA…
jorg3lopez Sep 27, 2024
0820b6d
added (Object) casting to test case in UpdateReceivingApplicationName…
jorg3lopez Sep 27, 2024
4ce96ac
null check for RemoveObservationrequests
jorg3lopez Sep 27, 2024
ffbefc9
NoExceptionThrown when args.get('universalServiceIdentifier') is not …
jorg3lopez Sep 27, 2024
8411a4b
null check for receiving application and args.get('name') in UpdateRe…
jorg3lopez Sep 27, 2024
1d4b6f6
edited unit test: receiving application not in bundle, from UpdateRec…
jorg3lopez Sep 27, 2024
d9684b4
Merge branch 'main' into feature/transformation-engine/map-object-args
jorg3lopez Sep 27, 2024
ad04607
Merge branch 'main' into feature/transformation-engine/map-object-args
jorg3lopez Sep 28, 2024
b6624e0
Map<String, String> -> Map<String, Object> for MapLocalObservationCodes
jorg3lopez Sep 29, 2024
9bfa3d4
refactored unit tests:
jorg3lopez Sep 29, 2024
f76b505
refactored MapLocalObservationcodesTest:
jorg3lopez Sep 29, 2024
e11cbdf
refactored MapLocalObservationcodesTest:
jorg3lopez Sep 29, 2024
f930187
refactored MapLocalObservationCodesTest:
jorg3lopez Sep 29, 2024
a334835
refactored MapLocalObservationCodesTest:
jorg3lopez Sep 29, 2024
fa5325a
refactored MapLocalObservationCodesTest:
jorg3lopez Sep 29, 2024
a64f4fe
deleted unused helper method
jorg3lopez Sep 29, 2024
6af658b
deleted comment
jorg3lopez Sep 29, 2024
c3d4bc9
remove null check when casthing to string
jorg3lopez Sep 30, 2024
dcbfcfa
Merge branch 'main' into feature/transformation-engine/map-object-args
jorg3lopez Sep 30, 2024
e2cec4a
remove casting method
jorg3lopez Oct 1, 2024
454be60
Merge remote-tracking branch 'origin/feature/transformation-engine/ma…
jorg3lopez Oct 1, 2024
b8ac665
Merge branch 'main' into feature/transformation-engine/map-object-args
jorg3lopez Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
* implemented by classes in the custom/ folder.
*/
public interface CustomFhirTransformation {
void transform(FhirResource<?> resource, Map<String, String> args);
void transform(FhirResource<?> resource, Map<String, Object> args);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void runRule(FhirResource<?> resource) {
private void applyTransformation(
TransformationRuleMethod transformation, FhirResource<?> resource) {
String name = transformation.name();
Map<String, String> args = transformation.args();
Map<String, Object> args = transformation.args();
logger.logInfo("Applying transformation: " + name);

CustomFhirTransformation transformationInstance = getTransformationInstance(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
* @param name The name of the transformation.
* @param args The arguments to pass to the transformation method.
*/
public record TransformationRuleMethod(String name, Map<String, String> args) {}
public record TransformationRuleMethod(String name, Map<String, Object> args) {}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class AddContactSectionToPatientResource implements CustomFhirTransformat
ApplicationContext.getImplementation(MetricMetadata.class);

@Override
public void transform(FhirResource<?> resource, Map<String, String> args) {
public void transform(FhirResource<?> resource, Map<String, Object> args) {
Bundle bundle = (Bundle) resource.getUnderlyingResource();

HapiHelper.resourcesInBundle(bundle, Patient.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class AddEtorProcessingTag implements CustomFhirTransformation {
ApplicationContext.getImplementation(MetricMetadata.class);

@Override
public void transform(FhirResource<?> resource, Map<String, String> args) {
public void transform(FhirResource<?> resource, Map<String, Object> args) {
Bundle bundle = (Bundle) resource.getUnderlyingResource();

var system = "http://localcodes.org/ETOR";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ConvertToOmlOrder implements CustomFhirTransformation {
ApplicationContext.getImplementation(MetricMetadata.class);

@Override
public void transform(FhirResource<?> resource, Map<String, String> args) {
public void transform(FhirResource<?> resource, Map<String, Object> args) {
Bundle bundle = (Bundle) resource.getUnderlyingResource();
HapiHelper.setMSH9Coding(bundle, HapiHelper.OML_CODING);
metadata.put(bundle.getId(), EtorMetadataStep.ORDER_CONVERTED_TO_OML);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class CopyOrcOrderProviderToObrOrderProvider implements CustomFhirTransformation {

@Override
public void transform(FhirResource<?> resource, Map<String, String> args) {
public void transform(FhirResource<?> resource, Map<String, Object> args) {
Bundle bundle = (Bundle) resource.getUnderlyingResource();
DiagnosticReport diagnosticReport = HapiHelper.getDiagnosticReport(bundle);
if (diagnosticReport == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public MapLocalObservationCodes() {
}

@Override
public void transform(FhirResource<?> resource, Map<String, String> args) {
public void transform(FhirResource<?> resource, Map<String, Object> args) {
var bundle = (Bundle) resource.getUnderlyingResource();
var observations = HapiHelper.resourcesInBundle(bundle, Observation.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class RemoveMessageTypeStructure implements CustomFhirTransformation {

@Override
public void transform(FhirResource<?> resource, Map<String, String> args) {
public void transform(FhirResource<?> resource, Map<String, Object> args) {
Bundle bundle = (Bundle) resource.getUnderlyingResource();
String msh9_3 = HapiHelper.getMSH9_3Value(bundle);
if (msh9_3 == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
public class RemoveObservationRequests implements CustomFhirTransformation {

@Override
public void transform(FhirResource<?> resource, Map<String, String> args) {
public void transform(FhirResource<?> resource, Map<String, Object> args) {
Bundle bundle = (Bundle) resource.getUnderlyingResource();
// Let it fail if it is not a String
String universalServiceIdentifier = (String) args.get("universalServiceIdentifier");

String universalServiceIdentifier = args.get("universalServiceIdentifier");
Set<Resource> resourcesToRemove = new HashSet<>();
List<Reference> observationReferences = new ArrayList<>();
DiagnosticReport singleDiagnosticReport = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class RemovePatientIdentifiers implements CustomFhirTransformation {

@Override
public void transform(FhirResource<?> resource, Map<String, String> args) {
public void transform(FhirResource<?> resource, Map<String, Object> args) {
Bundle bundle = (Bundle) resource.getUnderlyingResource();
HapiHelper.setPID3_4Value(bundle, ""); // remove PID.3-4
HapiHelper.setPID3_5Value(bundle, ""); // remove PID.3-5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class RemovePatientNameTypeCode implements CustomFhirTransformation {

@Override
public void transform(final FhirResource<?> resource, final Map<String, String> args) {
public void transform(final FhirResource<?> resource, final Map<String, Object> args) {
Bundle bundle = (Bundle) resource.getUnderlyingResource();
// Need to set the value for extension to empty instead of removing the extension,
// otherwise RS will set its own value in its place
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class SwapPlacerOrderAndGroupNumbers implements CustomFhirTransformation {

@Override
public void transform(FhirResource<?> resource, Map<String, String> args) {
public void transform(FhirResource<?> resource, Map<String, Object> args) {
Bundle bundle = (Bundle) resource.getUnderlyingResource();
var serviceRequests = HapiHelper.resourcesInBundle(bundle, ServiceRequest.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@
public class UpdateReceivingApplicationNamespace implements CustomFhirTransformation {

@Override
public void transform(FhirResource<?> resource, Map<String, String> args) {
public void transform(FhirResource<?> resource, Map<String, Object> args) {
Bundle bundle = (Bundle) resource.getUnderlyingResource();
// Let it fail if it is not a string
String name = (String) args.get("name");
var receivingApplication = HapiHelper.getMSH5MessageDestinationComponent(bundle);

if (receivingApplication == null) {
return;
}

receivingApplication.removeExtension(HapiHelper.EXTENSION_UNIVERSAL_ID_URL);
receivingApplication.removeExtension(HapiHelper.EXTENSION_UNIVERSAL_ID_TYPE_URL);
receivingApplication.setName(args.get("name"));
receivingApplication.setName(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class UpdateReceivingFacilityWithOrderingFacilityIdentifier
implements CustomFhirTransformation {

@Override
public void transform(FhirResource<?> resource, Map<String, String> args) {
public void transform(FhirResource<?> resource, Map<String, Object> args) {
Bundle bundle = (Bundle) resource.getUnderlyingResource();
DiagnosticReport diagnosticReport = HapiHelper.getDiagnosticReport(bundle);
if (diagnosticReport == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import gov.hhs.cdc.trustedintermediary.external.hapi.HapiHelper;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Identifier;

Expand All @@ -15,14 +16,18 @@
public class UpdateSendingFacilityNamespace implements CustomFhirTransformation {

@Override
public void transform(FhirResource<?> resource, Map<String, String> args) {
public void transform(FhirResource<?> resource, Map<String, Object> args) {
Bundle bundle = (Bundle) resource.getUnderlyingResource();
Identifier namespaceIdentifier = HapiHelper.getMSH4_1Identifier(bundle);
if (namespaceIdentifier == null) {
return;
}
namespaceIdentifier.setValue(args.get("name"));
HapiHelper.getMSH4Organization(bundle)

// Let it fail if it is not a string
String name = (String) args.get("name");

namespaceIdentifier.setValue(name);
Objects.requireNonNull(HapiHelper.getMSH4Organization(bundle))
.setIdentifier(Collections.singletonList(namespaceIdentifier));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,41 @@ public class UpdateUniversalServiceIdentifier implements CustomFhirTransformatio
public static final String ALTERNATE_ID_NAME = "alternateId";

@Override
public void transform(FhirResource<?> resource, Map<String, String> args) {
public void transform(FhirResource<?> resource, Map<String, Object> args) {
Bundle bundle = (Bundle) resource.getUnderlyingResource();
var serviceRequests = HapiHelper.resourcesInBundle(bundle, ServiceRequest.class);

serviceRequests.forEach(
it -> {
var allCodings = it.getCode().getCoding();
var codingSystemContainer =
getCodingSystemContainer(allCodings, args.get(CHECK_VALUE_NAME));
getCodingSystemContainer(
allCodings, castToString(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(CODING_SYSTEM_NAME));
updateCodingSystemLabel(
codingSystemContainer, castToString(args.get(CODING_SYSTEM_NAME)));

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

// Returns null if it is not a String
private String castToString(Object obj) {
jorg3lopez marked this conversation as resolved.
Show resolved Hide resolved
// Let it fail if it is not a string
return (String) obj;
}

/**
* Extract the first "Coding System" object that matches a given string from a given list of
* Codings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.hl7.fhir.r4.model.Coding
class HappyPathCustomTransformationMockClass implements CustomFhirTransformation {

@Override
public void transform(final FhirResource<?> resource, final Map<String, String> args) {
public void transform(final FhirResource<?> resource, final Map<String, Object> args) {
Bundle bundle = (Bundle) resource.getUnderlyingResource()

def system = "http://terminology.hl7.org/CodeSystem/v2-0003"
Expand Down
Loading