diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/addContactSectionToPatientResource.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/addContactSectionToPatientResource.java index 6ab116edd..942d0528c 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/addContactSectionToPatientResource.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/addContactSectionToPatientResource.java @@ -4,10 +4,13 @@ import gov.hhs.cdc.trustedintermediary.etor.metadata.EtorMetadataStep; import gov.hhs.cdc.trustedintermediary.etor.ruleengine.FhirResource; import gov.hhs.cdc.trustedintermediary.etor.ruleengine.transformation.CustomFhirTransformation; -import gov.hhs.cdc.trustedintermediary.external.hapi.HapiOrderConverterHelper; +import gov.hhs.cdc.trustedintermediary.external.hapi.HapiHelper; import gov.hhs.cdc.trustedintermediary.wrappers.MetricMetadata; +import java.util.List; import java.util.Map; import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.Coding; +import org.hl7.fhir.r4.model.Patient; /** Custom transformation to add a contact section to a patient resource. */ public class addContactSectionToPatientResource implements CustomFhirTransformation { @@ -18,7 +21,30 @@ public class addContactSectionToPatientResource implements CustomFhirTransformat @Override public void transform(FhirResource resource, Map args) { Bundle bundle = (Bundle) resource.getUnderlyingResource(); - HapiOrderConverterHelper.addContactSectionToPatientResource(bundle); + + HapiHelper.resourcesInBundle(bundle, Patient.class) + .forEach( + p -> { + var myContact = p.addContact(); + var motherRelationship = myContact.addRelationship(); + motherRelationship.setCoding( + List.of( + new Coding( + "http://terminology.hl7.org/CodeSystem/v3-RoleCode", + "MTH", + "mother"))); + + var mothersMaidenNameExtension = + p.getExtensionByUrl( + "http://hl7.org/fhir/StructureDefinition/patient-mothersMaidenName"); + if (mothersMaidenNameExtension != null) { + myContact.setName( + p.castToHumanName(mothersMaidenNameExtension.getValue())); + } + myContact.setTelecom(p.getTelecom()); + myContact.setAddress(p.getAddressFirstRep()); + }); + metadata.put(bundle.getId(), EtorMetadataStep.CONTACT_SECTION_ADDED_TO_PATIENT); } } diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/addEtorProcessingTag.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/addEtorProcessingTag.java index f01087a8a..fcadf1a04 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/addEtorProcessingTag.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/addEtorProcessingTag.java @@ -18,7 +18,13 @@ public class addEtorProcessingTag implements CustomFhirTransformation { @Override public void transform(FhirResource resource, Map args) { Bundle bundle = (Bundle) resource.getUnderlyingResource(); - HapiMessageConverterHelper.addEtorTagToBundle(bundle); + + var system = "http://localcodes.org/ETOR"; + var code = "ETOR"; + var display = "Processed by ETOR"; + + HapiMessageConverterHelper.addMetaTag(bundle, system, code, display); + metadata.put(bundle.getId(), EtorMetadataStep.ETOR_PROCESSING_TAG_ADDED_TO_MESSAGE_HEADER); } } diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/convertToOmlOrder.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/convertToOmlOrder.java index 80d7dfb02..4a40909b5 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/convertToOmlOrder.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/convertToOmlOrder.java @@ -4,7 +4,8 @@ import gov.hhs.cdc.trustedintermediary.etor.metadata.EtorMetadataStep; import gov.hhs.cdc.trustedintermediary.etor.ruleengine.FhirResource; import gov.hhs.cdc.trustedintermediary.etor.ruleengine.transformation.CustomFhirTransformation; -import gov.hhs.cdc.trustedintermediary.external.hapi.HapiOrderConverterHelper; +import gov.hhs.cdc.trustedintermediary.external.hapi.HapiMessageConverterHelper; +import gov.hhs.cdc.trustedintermediary.hl7fhir.FhirValuesHelper; import gov.hhs.cdc.trustedintermediary.wrappers.MetricMetadata; import java.util.Map; import org.hl7.fhir.r4.model.Bundle; @@ -18,7 +19,7 @@ public class convertToOmlOrder implements CustomFhirTransformation { @Override public void transform(FhirResource resource, Map args) { Bundle bundle = (Bundle) resource.getUnderlyingResource(); - HapiOrderConverterHelper.convertToOmlOrder(bundle); + HapiMessageConverterHelper.setMessageTypeCoding(bundle, FhirValuesHelper.OML_CODING); metadata.put(bundle.getId(), EtorMetadataStep.ORDER_CONVERTED_TO_OML); } } diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiMessageConverterHelper.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiMessageConverterHelper.java index 4547ec78a..68b5cabd5 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiMessageConverterHelper.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiMessageConverterHelper.java @@ -10,21 +10,23 @@ public class HapiMessageConverterHelper { private HapiMessageConverterHelper() {} - public static void addEtorTagToBundle(Bundle messageBundle) { + public static void addMetaTag( + Bundle messageBundle, String system, String code, String display) { var messageHeader = findOrInitializeMessageHeader(messageBundle); var meta = messageHeader.hasMeta() ? messageHeader.getMeta() : new Meta(); - var systemValue = "http://localcodes.org/ETOR"; - var codeValue = "ETOR"; - var displayValue = "Processed by ETOR"; - - if (meta.getTag(systemValue, codeValue) == null) { - meta.addTag(new Coding(systemValue, codeValue, displayValue)); + if (meta.getTag(system, code) == null) { + meta.addTag(new Coding(system, code, display)); } messageHeader.setMeta(meta); } + public static void setMessageTypeCoding(Bundle order, Coding coding) { + var messageHeader = HapiMessageConverterHelper.findOrInitializeMessageHeader(order); + messageHeader.setEvent(coding); + } + public static MessageHeader findOrInitializeMessageHeader(Bundle bundle) { var messageHeader = HapiHelper.resourcesInBundle(bundle, MessageHeader.class).findFirst().orElse(null); diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiOrderConverterHelper.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiOrderConverterHelper.java deleted file mode 100644 index ff69ee0f8..000000000 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiOrderConverterHelper.java +++ /dev/null @@ -1,46 +0,0 @@ -package gov.hhs.cdc.trustedintermediary.external.hapi; - -import java.util.List; -import org.hl7.fhir.r4.model.Bundle; -import org.hl7.fhir.r4.model.Coding; -import org.hl7.fhir.r4.model.Patient; - -/** Helper class with transformation methods that take an order Bundle and modifies it */ -public class HapiOrderConverterHelper { - - private static final Coding OML_CODING = - new Coding( - "http://terminology.hl7.org/CodeSystem/v2-0003", - "O21", - "OML - Laboratory order"); - - private static final List CODING_LIST = - List.of( - new Coding( - "http://terminology.hl7.org/CodeSystem/v3-RoleCode", "MTH", "mother")); - - public static void convertToOmlOrder(Bundle order) { - var messageHeader = HapiMessageConverterHelper.findOrInitializeMessageHeader(order); - messageHeader.setEvent(OML_CODING); - } - - public static void addContactSectionToPatientResource(Bundle order) { - HapiHelper.resourcesInBundle(order, Patient.class) - .forEach( - p -> { - var myContact = p.addContact(); - var motherRelationship = myContact.addRelationship(); - motherRelationship.setCoding(CODING_LIST); - - var mothersMaidenNameExtension = - p.getExtensionByUrl( - "http://hl7.org/fhir/StructureDefinition/patient-mothersMaidenName"); - if (mothersMaidenNameExtension != null) { - myContact.setName( - p.castToHumanName(mothersMaidenNameExtension.getValue())); - } - myContact.setTelecom(p.getTelecom()); - myContact.setAddress(p.getAddressFirstRep()); - }); - } -} diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/hl7fhir/FhirValuesHelper.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/hl7fhir/FhirValuesHelper.java new file mode 100644 index 000000000..199fe397d --- /dev/null +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/hl7fhir/FhirValuesHelper.java @@ -0,0 +1,18 @@ +package gov.hhs.cdc.trustedintermediary.hl7fhir; + +import java.util.List; +import org.hl7.fhir.r4.model.Coding; + +public class FhirValuesHelper { + + public static final List CODING_LIST = + List.of( + new Coding( + "http://terminology.hl7.org/CodeSystem/v3-RoleCode", "MTH", "mother")); + + public static final Coding OML_CODING = + new Coding( + "http://terminology.hl7.org/CodeSystem/v2-0003", + "O21", + "OML - Laboratory order"); +} 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 9f4854509..ad438e679 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 @@ -5,6 +5,7 @@ import org.hl7.fhir.r4.model.Resource; /** Helper class that works on HapiFHIR constructs. */ +public class HapiHelper { // not a public class so it is package-private (meaning only other classes in // this package can access it private HapiHelper() {}