10
10
11
11
import java .awt .geom .Point2D ;
12
12
import java .io .IOException ;
13
+ import java .util .AbstractMap ;
13
14
import java .util .ArrayList ;
14
15
import java .util .Arrays ;
15
16
import java .util .Calendar ;
139
140
140
141
import org .mitre .synthea .engine .Components ;
141
142
import org .mitre .synthea .engine .Components .Attachment ;
143
+ import org .mitre .synthea .export .rif .CodeMapper ;
142
144
import org .mitre .synthea .helpers .Config ;
145
+ import org .mitre .synthea .helpers .RandomNumberGenerator ;
146
+ import org .mitre .synthea .helpers .RandomValueGenerator ;
143
147
import org .mitre .synthea .helpers .SimpleCSV ;
144
148
import org .mitre .synthea .helpers .Utilities ;
145
149
import org .mitre .synthea .identity .Entity ;
@@ -404,7 +408,7 @@ public static Bundle convertToFHIR(Person person, long stopTime) {
404
408
405
409
if (shouldExport (Condition .class )) {
406
410
for (HealthRecord .Entry condition : encounter .conditions ) {
407
- condition (personEntry , bundle , encounterEntry , condition );
411
+ condition (person , personEntry , bundle , encounterEntry , condition );
408
412
}
409
413
}
410
414
@@ -431,7 +435,7 @@ public static Bundle convertToFHIR(Person person, long stopTime) {
431
435
432
436
if (shouldExport (org .hl7 .fhir .r4 .model .Procedure .class )) {
433
437
for (Procedure procedure : encounter .procedures ) {
434
- procedure (personEntry , bundle , encounterEntry , procedure );
438
+ procedure (person , personEntry , bundle , encounterEntry , procedure );
435
439
}
436
440
}
437
441
@@ -849,6 +853,27 @@ private static BundleEntryComponent basicInfo(Person person, Bundle bundle, long
849
853
return newEntry (bundle , patientResource , (String ) person .attributes .get (Person .ID ));
850
854
}
851
855
856
+ /**
857
+ * Add a code translation (if available) of the supplied source code to the
858
+ * supplied CodeableConcept.
859
+ * @param codeSystem the code system of the translated code
860
+ * @param from the source code
861
+ * @param to the CodeableConcept to add the translation to
862
+ * @param rand a source of randomness
863
+ */
864
+ private static void addTranslation (String codeSystem , Code from ,
865
+ CodeableConcept to , RandomNumberGenerator rand ) {
866
+ CodeMapper mapper = Exporter .getCodeMapper (codeSystem );
867
+ if (mapper != null && mapper .canMap (from )) {
868
+ Coding coding = new Coding ();
869
+ Map .Entry <String , String > mappedCode = mapper .mapToCodeAndDescription (from , rand );
870
+ coding .setCode (mappedCode .getKey ());
871
+ coding .setDisplay (mappedCode .getValue ());
872
+ coding .setSystem (ExportHelper .getSystemURI ("ICD10-CM" ));
873
+ to .addCoding (coding );
874
+ }
875
+ }
876
+
852
877
/**
853
878
* Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
854
879
*
@@ -894,6 +919,8 @@ private static BundleEntryComponent encounter(Person person, BundleEntryComponen
894
919
if (encounter .reason != null ) {
895
920
encounterResource .addReasonCode ().addCoding ().setCode (encounter .reason .code )
896
921
.setDisplay (encounter .reason .display ).setSystem (SNOMED_URI );
922
+ addTranslation ("ICD10-CM" , encounter .reason ,
923
+ encounterResource .getReasonCodeFirstRep (), person );
897
924
}
898
925
899
926
Provider provider = encounter .provider ;
@@ -1607,6 +1634,7 @@ private static BundleEntryComponent explanationOfBenefit(BundleEntryComponent pe
1607
1634
* @return The added Entry
1608
1635
*/
1609
1636
private static BundleEntryComponent condition (
1637
+ RandomNumberGenerator rand ,
1610
1638
BundleEntryComponent personEntry , Bundle bundle , BundleEntryComponent encounterEntry ,
1611
1639
HealthRecord .Entry condition ) {
1612
1640
Condition conditionResource = new Condition ();
@@ -1630,7 +1658,9 @@ private static BundleEntryComponent condition(
1630
1658
conditionResource .setEncounter (new Reference (encounterEntry .getFullUrl ()));
1631
1659
1632
1660
Code code = condition .codes .get (0 );
1633
- conditionResource .setCode (mapCodeToCodeableConcept (code , SNOMED_URI ));
1661
+ CodeableConcept concept = mapCodeToCodeableConcept (code , SNOMED_URI );
1662
+ addTranslation ("ICD10-CM" , code , concept , rand );
1663
+ conditionResource .setCode (concept );
1634
1664
1635
1665
CodeableConcept verification = new CodeableConcept ();
1636
1666
verification .getCodingFirstRep ()
@@ -1964,13 +1994,14 @@ static org.hl7.fhir.r4.model.SampledData mapValueToSampledData(
1964
1994
/**
1965
1995
* Map the given Procedure into a FHIR Procedure resource, and add it to the given Bundle.
1966
1996
*
1997
+ * @param person The Person
1967
1998
* @param personEntry The Person entry
1968
1999
* @param bundle Bundle to add to
1969
2000
* @param encounterEntry The current Encounter entry
1970
2001
* @param procedure The Procedure
1971
2002
* @return The added Entry
1972
2003
*/
1973
- private static BundleEntryComponent procedure (
2004
+ private static BundleEntryComponent procedure (Person person ,
1974
2005
BundleEntryComponent personEntry , Bundle bundle , BundleEntryComponent encounterEntry ,
1975
2006
Procedure procedure ) {
1976
2007
org .hl7 .fhir .r4 .model .Procedure procedureResource = new org .hl7 .fhir .r4 .model .Procedure ();
@@ -2013,6 +2044,7 @@ private static BundleEntryComponent procedure(
2013
2044
// we didn't find a matching Condition,
2014
2045
// fallback to just reason code
2015
2046
procedureResource .addReasonCode (mapCodeToCodeableConcept (reason , SNOMED_URI ));
2047
+ addTranslation ("ICD10-CM" , reason , procedureResource .getReasonCodeFirstRep (), person );
2016
2048
}
2017
2049
}
2018
2050
@@ -2322,6 +2354,8 @@ && shouldExport(org.hl7.fhir.r4.model.Medication.class)) {
2322
2354
// we didn't find a matching Condition,
2323
2355
// fallback to just reason code
2324
2356
medicationResource .addReasonCode (mapCodeToCodeableConcept (reason , SNOMED_URI ));
2357
+ addTranslation ("ICD10-CM" , reason , medicationResource .getReasonCodeFirstRep (),
2358
+ person );
2325
2359
}
2326
2360
}
2327
2361
@@ -2474,6 +2508,8 @@ private static BundleEntryComponent medicationAdministration(
2474
2508
// we didn't find a matching Condition,
2475
2509
// fallback to just reason code
2476
2510
medicationResource .addReasonCode (mapCodeToCodeableConcept (reason , SNOMED_URI ));
2511
+ addTranslation ("ICD10-CM" , reason , medicationResource .getReasonCodeFirstRep (),
2512
+ person );
2477
2513
}
2478
2514
}
2479
2515
@@ -2717,6 +2753,8 @@ private static BundleEntryComponent carePlan(Person person,
2717
2753
activityDetailComponent .addReasonReference ().setReference (reasonCondition .getFullUrl ());
2718
2754
} else if (reason != null ) {
2719
2755
activityDetailComponent .addReasonCode (mapCodeToCodeableConcept (reason , SNOMED_URI ));
2756
+ addTranslation ("ICD10-CM" , reason , activityDetailComponent .getReasonCodeFirstRep (),
2757
+ person );
2720
2758
}
2721
2759
2722
2760
activityComponent .setDetail (activityDetailComponent );
@@ -2863,7 +2901,9 @@ private static BundleEntryComponent careTeam(Person person,
2863
2901
2864
2902
if (carePlan .reasons != null && !carePlan .reasons .isEmpty ()) {
2865
2903
for (Code code : carePlan .reasons ) {
2866
- careTeam .addReasonCode (mapCodeToCodeableConcept (code , SNOMED_URI ));
2904
+ CodeableConcept concept = mapCodeToCodeableConcept (code , SNOMED_URI );
2905
+ addTranslation ("ICD10-CM" , code , concept , person );
2906
+ careTeam .addReasonCode (concept );
2867
2907
}
2868
2908
}
2869
2909
0 commit comments