Skip to content

Commit

Permalink
folder per provider
Browse files Browse the repository at this point in the history
  • Loading branch information
dehall committed Sep 8, 2023
1 parent 02955f2 commit 2e5a557
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/main/java/org/mitre/synthea/export/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
import org.mitre.synthea.identity.Variant;
import org.mitre.synthea.modules.DeathModule;
import org.mitre.synthea.world.agents.Person;
import org.mitre.synthea.world.agents.Provider;
import org.mitre.synthea.world.concepts.Claim;
import org.mitre.synthea.world.concepts.HealthRecord;
import org.mitre.synthea.world.concepts.HealthRecord.Encounter;
import org.mitre.synthea.world.concepts.HealthRecord.EncounterType;
import org.mitre.synthea.world.concepts.HealthRecord.Observation;
import org.mitre.synthea.world.concepts.HealthRecord.Report;

Expand Down Expand Up @@ -727,6 +729,15 @@ public static File getOutputFolder(String folderName, Person person) {
folders.add(id.substring(0, 3));
}

if (person != null && person.hasMultipleRecords
&& Config.getAsBoolean("exporter.split_records.subfolders_by_provider")) {
// person.record has already been set to a single split record
Provider providerOrganization = person.record.provider;
// TODO: can this be null?
String providerId = providerOrganization.getResourceID();
folders.add(providerId);
}

String baseDirectory = Config.get("exporter.baseDirectory");

File f = Paths.get(baseDirectory, folders.toArray(new String[0])).toFile();
Expand Down
59 changes: 56 additions & 3 deletions src/main/java/org/mitre/synthea/export/FhirR4.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import ca.uhn.fhir.context.FhirContext;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Table;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
Expand All @@ -14,6 +16,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -127,7 +130,6 @@
import org.hl7.fhir.r4.model.Type;
import org.hl7.fhir.r4.model.codesystems.DoseRateType;

import org.hl7.fhir.r4.model.codesystems.LocationPhysicalType;
import org.hl7.fhir.utilities.xhtml.NodeType;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;

Expand Down Expand Up @@ -533,8 +535,8 @@ private static BundleEntryComponent basicInfo(Person person, Bundle bundle, long

Extension nationalityCodingExtension = new Extension("code");
CodeableConcept nationalityCC = new CodeableConcept();
Coding nationalityCoding = new Coding();
nationalityCoding.setCode(nationality);
Coding nationalityCoding = nationalityToCoding(nationality);

nationalityCC.addCoding(nationalityCoding);
nationalityCodingExtension.setValue(nationalityCC);
nationalityExtension.addExtension(nationalityCodingExtension);
Expand Down Expand Up @@ -720,6 +722,57 @@ private static BundleEntryComponent basicInfo(Person person, Bundle bundle, long
return newEntry(bundle, patientResource, (String) person.attributes.get(Person.ID));
}

private static final BiMap<String, String> NATIONALITY_CODES = createNationalityCodeMap();

private static BiMap<String, String> createNationalityCodeMap() {
try {
String nationalityCodeData = Utilities.readResourceAndStripBOM("geography/nationalities.csv");
Iterator<LinkedHashMap<String,String>> lines = SimpleCSV.parseLineByLine(nationalityCodeData);

BiMap<String, String> codeMap = HashBiMap.create();

while (lines.hasNext()) {
LinkedHashMap<String,String> line = lines.next();
codeMap.put(line.get("code").toUpperCase(), line.get("display").toLowerCase());
}
return codeMap;

} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
}

public static Coding nationalityToCoding(String nationality) {
Coding nationalityCoding = new Coding();
if (nationality == null) {
nationalityCoding.setCode("00");
nationalityCoding.setDisplay("Unknown");
} else if (nationality.length() == 2) {
// "B5", "E5", etc
nationalityCoding.setCode(nationality.toUpperCase());

String display = NATIONALITY_CODES.get(nationality.toUpperCase());
if (display != null) {
nationalityCoding.setDisplay(display);
}
} else {
// "English"
nationalityCoding.setDisplay(nationality);

String code = NATIONALITY_CODES.inverse().get(nationality);

if (code == null) {
code = NATIONALITY_CODES.inverse().get(nationality.toLowerCase());
}

if (code != null) {
nationalityCoding.setCode(code.toUpperCase());
}
}

return nationalityCoding;
}

/**
* Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
*
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/synthea.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exporter.years_of_history = 10
# split records allows patients to have one record per provider organization
exporter.split_records = false
exporter.split_records.duplicate_data = false
exporter.split_records.subfolders_by_provider = true
exporter.metadata.export = true
exporter.ccda.export = false
exporter.fhir.export = true
Expand Down

0 comments on commit 2e5a557

Please sign in to comment.