Skip to content

Commit

Permalink
Extract method for adding ICD10 translation codes, add to other types…
Browse files Browse the repository at this point in the history
… of resources that have a reason.
  • Loading branch information
hadleynet committed Oct 18, 2024
1 parent 3120e50 commit b9dec27
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions src/main/java/org/mitre/synthea/export/FhirR4.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public static Bundle convertToFHIR(Person person, long stopTime) {

if (shouldExport(org.hl7.fhir.r4.model.Procedure.class)) {
for (Procedure procedure : encounter.procedures) {
procedure(personEntry, bundle, encounterEntry, procedure);
procedure(person, personEntry, bundle, encounterEntry, procedure);
}
}

Expand Down Expand Up @@ -853,6 +853,27 @@ private static BundleEntryComponent basicInfo(Person person, Bundle bundle, long
return newEntry(bundle, patientResource, (String) person.attributes.get(Person.ID));
}

/**
* Add a code translation (if available) of the supplied source code to the
* supplied CodeableConcept.
* @param codeSystem the code system of the translated code
* @param from the source code
* @param to the CodeableConcept to add the translation to
* @param rand a source of randomness
*/
private static void addTranslation(String codeSystem, Code from,
CodeableConcept to, RandomNumberGenerator rand) {
CodeMapper mapper = Exporter.getCodeMapper(codeSystem);
if (mapper != null && mapper.canMap(from)) {
Coding coding = new Coding();
Map.Entry<String, String> mappedCode = mapper.mapToCodeAndDescription(from, rand);
coding.setCode(mappedCode.getKey());
coding.setDisplay(mappedCode.getValue());
coding.setSystem(ExportHelper.getSystemURI("ICD10-CM"));
to.addCoding(coding);
}
}

/**
* Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
*
Expand Down Expand Up @@ -898,16 +919,8 @@ private static BundleEntryComponent encounter(Person person, BundleEntryComponen
if (encounter.reason != null) {
encounterResource.addReasonCode().addCoding().setCode(encounter.reason.code)
.setDisplay(encounter.reason.display).setSystem(SNOMED_URI);
CodeMapper mapper = Exporter.getCodeMapper("ICD10-CM");
if (mapper != null && mapper.canMap(encounter.reason.code)) {
Coding coding = new Coding();
Map.Entry<String, String> mappedCode = mapper.mapToCodeAndDescription(
encounter.reason, person);
coding.setCode(mappedCode.getKey());
coding.setDisplay(mappedCode.getValue());
coding.setSystem(ExportHelper.getSystemURI("ICD10-CM"));
encounterResource.getReasonCodeFirstRep().addCoding(coding);
}
addTranslation("ICD10-CM", encounter.reason,
encounterResource.getReasonCodeFirstRep(), person);
}

Provider provider = encounter.provider;
Expand Down Expand Up @@ -1646,15 +1659,7 @@ private static BundleEntryComponent condition(

Code code = condition.codes.get(0);
CodeableConcept concept = mapCodeToCodeableConcept(code, SNOMED_URI);
CodeMapper mapper = Exporter.getCodeMapper("ICD10-CM");
if (mapper != null && mapper.canMap(code)) {
Coding coding = new Coding();
Map.Entry<String, String> mappedCode = mapper.mapToCodeAndDescription(code, rand);
coding.setCode(mappedCode.getKey());
coding.setDisplay(mappedCode.getValue());
coding.setSystem(ExportHelper.getSystemURI("ICD10-CM"));
concept.addCoding(coding);
}
addTranslation("ICD10-CM", code, concept, rand);
conditionResource.setCode(concept);

CodeableConcept verification = new CodeableConcept();
Expand Down Expand Up @@ -1989,13 +1994,14 @@ static org.hl7.fhir.r4.model.SampledData mapValueToSampledData(
/**
* Map the given Procedure into a FHIR Procedure resource, and add it to the given Bundle.
*
* @param person The Person
* @param personEntry The Person entry
* @param bundle Bundle to add to
* @param encounterEntry The current Encounter entry
* @param procedure The Procedure
* @return The added Entry
*/
private static BundleEntryComponent procedure(
private static BundleEntryComponent procedure(Person person,
BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry,
Procedure procedure) {
org.hl7.fhir.r4.model.Procedure procedureResource = new org.hl7.fhir.r4.model.Procedure();
Expand Down Expand Up @@ -2038,6 +2044,7 @@ private static BundleEntryComponent procedure(
// we didn't find a matching Condition,
// fallback to just reason code
procedureResource.addReasonCode(mapCodeToCodeableConcept(reason, SNOMED_URI));
addTranslation("ICD10-CM", reason, procedureResource.getReasonCodeFirstRep(), person);
}
}

Expand Down Expand Up @@ -2347,6 +2354,8 @@ && shouldExport(org.hl7.fhir.r4.model.Medication.class)) {
// we didn't find a matching Condition,
// fallback to just reason code
medicationResource.addReasonCode(mapCodeToCodeableConcept(reason, SNOMED_URI));
addTranslation("ICD10-CM", reason, medicationResource.getReasonCodeFirstRep(),
person);
}
}

Expand Down Expand Up @@ -2499,6 +2508,8 @@ private static BundleEntryComponent medicationAdministration(
// we didn't find a matching Condition,
// fallback to just reason code
medicationResource.addReasonCode(mapCodeToCodeableConcept(reason, SNOMED_URI));
addTranslation("ICD10-CM", reason, medicationResource.getReasonCodeFirstRep(),
person);
}
}

Expand Down Expand Up @@ -2742,6 +2753,8 @@ private static BundleEntryComponent carePlan(Person person,
activityDetailComponent.addReasonReference().setReference(reasonCondition.getFullUrl());
} else if (reason != null) {
activityDetailComponent.addReasonCode(mapCodeToCodeableConcept(reason, SNOMED_URI));
addTranslation("ICD10-CM", reason, activityDetailComponent.getReasonCodeFirstRep(),
person);
}

activityComponent.setDetail(activityDetailComponent);
Expand Down Expand Up @@ -2888,7 +2901,9 @@ private static BundleEntryComponent careTeam(Person person,

if (carePlan.reasons != null && !carePlan.reasons.isEmpty()) {
for (Code code : carePlan.reasons) {
careTeam.addReasonCode(mapCodeToCodeableConcept(code, SNOMED_URI));
CodeableConcept concept = mapCodeToCodeableConcept(code, SNOMED_URI);
addTranslation("ICD10-CM", code, concept, person);
careTeam.addReasonCode(concept);
}
}

Expand Down

0 comments on commit b9dec27

Please sign in to comment.