Skip to content

Commit

Permalink
Refactored to create more generic helper functions and move logic to …
Browse files Browse the repository at this point in the history
…transformation method
  • Loading branch information
basiliskus committed May 9, 2024
1 parent 04693bf commit fd8c958
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -18,7 +21,30 @@ public class addContactSectionToPatientResource implements CustomFhirTransformat
@Override
public void transform(FhirResource<?> resource, Map<String, String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ public class addEtorProcessingTag implements CustomFhirTransformation {
@Override
public void transform(FhirResource<?> resource, Map<String, String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,7 +19,7 @@ public class convertToOmlOrder implements CustomFhirTransformation {
@Override
public void transform(FhirResource<?> resource, Map<String, String> args) {
Bundle bundle = (Bundle) resource.getUnderlyingResource();
HapiOrderConverterHelper.convertToOmlOrder(bundle);
HapiMessageConverterHelper.setMessageTypeCoding(bundle, FhirValuesHelper.OML_CODING);
metadata.put(bundle.getId(), EtorMetadataStep.ORDER_CONVERTED_TO_OML);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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> 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");
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down

0 comments on commit fd8c958

Please sign in to comment.