Skip to content

Commit

Permalink
Fix merge conflict.
Browse files Browse the repository at this point in the history
  • Loading branch information
jawalonoski committed May 17, 2024
2 parents bd4c558 + b249772 commit 025e0f0
Show file tree
Hide file tree
Showing 192 changed files with 692 additions and 157 deletions.
5 changes: 3 additions & 2 deletions src/main/java/org/mitre/synthea/export/CSVExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private static List<String> propStringToList(String fileListString) {
*/
private void writeCSVHeaders() throws IOException {
patients.write("Id,BIRTHDATE,DEATHDATE,SSN,DRIVERS,PASSPORT,"
+ "PREFIX,FIRST,LAST,SUFFIX,MAIDEN,MARITAL,RACE,ETHNICITY,GENDER,BIRTHPLACE,"
+ "PREFIX,FIRST,MIDDLE,LAST,SUFFIX,MAIDEN,MARITAL,RACE,ETHNICITY,GENDER,BIRTHPLACE,"
+ "ADDRESS,CITY,STATE,COUNTY,FIPS,ZIP,LAT,LON,"
+ "HEALTHCARE_EXPENSES,HEALTHCARE_COVERAGE,INCOME");
patients.write(NEWLINE);
Expand Down Expand Up @@ -625,6 +625,7 @@ private String patient(Person person, long time) throws IOException {
Person.IDENTIFIER_PASSPORT,
Person.NAME_PREFIX,
Person.FIRST_NAME,
Person.MIDDLE_NAME,
Person.LAST_NAME,
Person.NAME_SUFFIX,
Person.MAIDEN_NAME,
Expand Down Expand Up @@ -2021,4 +2022,4 @@ private OutputStreamWriter getWriter(Path outputDirectory, String filename, bool
append = append && file.exists();
return new OutputStreamWriter(new FileOutputStream(file, append), charset);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/mitre/synthea/export/ExportHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public static String getSystemURI(String system) {
}

/**
* Translate the the official FHIR system URI (e.g. http://snomed.info/sct)
* Translate the official FHIR system URI (e.g. http://snomed.info/sct)
* into system name (e.g. SNOMED-CT).
* @param uri http://snomed.info/sct, http://loinc.org, etc.
* @return The internal short name used by Synthea, or "Unknown"
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/org/mitre/synthea/export/Exporter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.mitre.synthea.export;

import ca.uhn.fhir.parser.IParser;
import com.google.common.base.Strings;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
Expand All @@ -24,6 +26,8 @@
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;

import org.hl7.fhir.r4.model.Parameters;
import org.hl7.fhir.r4.model.StringType;
import org.mitre.synthea.engine.Generator;
import org.mitre.synthea.export.flexporter.Actions;
import org.mitre.synthea.export.flexporter.FhirPathUtils;
Expand Down Expand Up @@ -500,6 +504,34 @@ public static void runPostCompletionExports(Generator generator) {
*/
public static void runPostCompletionExports(Generator generator, ExporterRuntimeOptions options) {

if (Config.getAsBoolean("exporter.fhir.bulk_data")) {
IParser parser = FhirR4.getContext().newJsonParser();
parser.setPrettyPrint(false);
Parameters parameters = new Parameters()
.addParameter("inputFormat","application/fhir+ndjson");
File outDirectory = getOutputFolder("fhir", null);

File[] files = outDirectory.listFiles(pathname -> pathname.getName().endsWith("ndjson"));

String configHostname = Config.get("exporter.fhir.bulk_data.parameter_hostname");
String hostname = Strings.isNullOrEmpty(configHostname)
? "http://localhost:8080/" : configHostname;

for (File file : files) {
parameters.addParameter(
new Parameters.ParametersParameterComponent().setName("input")
.addPart(new Parameters.ParametersParameterComponent()
.setName("type")
.setValue(new StringType(file.getName().split("\\.")[0])))
.addPart(new Parameters.ParametersParameterComponent()
.setName("url")
.setValue(new StringType(hostname + file.getName()))));
}
overwriteFile(outDirectory.toPath().resolve("parameters.json"),
parser.encodeResourceToString(parameters));
}


if (options.deferExports) {
ExporterRuntimeOptions nonDeferredOptions = new ExporterRuntimeOptions(options);
nonDeferredOptions.deferExports = false;
Expand Down
127 changes: 86 additions & 41 deletions src/main/java/org/mitre/synthea/export/FhirR4.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -188,18 +189,28 @@ public class FhirR4 {
protected static boolean TRANSACTION_BUNDLE =
Config.getAsBoolean("exporter.fhir.transaction_bundle");

/* For the most part the US Core changes from v4 -> v5 are backwards compatible,
* so for those cases just check USE_US_CORE_IG.
* If there are version differences then use USE_US_CORE_(#) to separate them out.
*/
protected static boolean USE_US_CORE_IG =
Config.getAsBoolean("exporter.fhir.use_us_core_ig");
protected static String US_CORE_VERSION =
Config.get("exporter.fhir.us_core_version", "5.0.1");
Config.get("exporter.fhir.us_core_version", "6.1.0");

private static Table<String, String, String> US_CORE_MAPPING;
private static final Table<String, String, String> US_CORE_3_MAPPING;
private static final Table<String, String, String> US_CORE_4_MAPPING;
private static final Table<String, String, String> US_CORE_5_MAPPING;
private static final Table<String, String, String> US_CORE_6_MAPPING;

public static enum USCoreVersion {
v311, v400, v501, v610
}

protected static boolean useUSCore3() {
boolean useUSCore3 = USE_US_CORE_IG && US_CORE_VERSION.startsWith("3");
if (useUSCore3) {
US_CORE_MAPPING = US_CORE_3_MAPPING;
}
return useUSCore3;
}

protected static boolean useUSCore4() {
boolean useUSCore4 = USE_US_CORE_IG && US_CORE_VERSION.startsWith("4");
Expand All @@ -217,6 +228,14 @@ protected static boolean useUSCore5() {
return useUSCore5;
}

protected static boolean useUSCore6() {
boolean useUSCore6 = USE_US_CORE_IG && US_CORE_VERSION.startsWith("6");
if (useUSCore6) {
US_CORE_MAPPING = US_CORE_6_MAPPING;
}
return useUSCore6;
}

private static final String COUNTRY_CODE = Config.get("generate.geography.country_code");

private static final Table<String, String, String> SHR_MAPPING =
Expand All @@ -229,15 +248,21 @@ protected static boolean useUSCore5() {
reloadIncludeExclude();

Map<String, Table<String, String, String>> usCoreMappings =
loadMappingWithVersions("us_core_mapping.csv", "4", "5");
loadMappingWithVersions("us_core_mapping.csv", "3", "4", "5", "6");

US_CORE_3_MAPPING = usCoreMappings.get("3");
US_CORE_4_MAPPING = usCoreMappings.get("4");
US_CORE_5_MAPPING = usCoreMappings.get("5");
US_CORE_6_MAPPING = usCoreMappings.get("6");

if (US_CORE_VERSION.startsWith("4")) {
if (US_CORE_VERSION.startsWith("3")) {
US_CORE_MAPPING = US_CORE_3_MAPPING;
} else if (US_CORE_VERSION.startsWith("4")) {
US_CORE_MAPPING = US_CORE_4_MAPPING;
} else if (US_CORE_VERSION.startsWith("5")) {
US_CORE_MAPPING = US_CORE_5_MAPPING;
} else if (US_CORE_VERSION.startsWith("6")) {
US_CORE_MAPPING = US_CORE_6_MAPPING;
}
}

Expand Down Expand Up @@ -364,17 +389,15 @@ private static Table<String, String, String> loadMapping(String filename) {
String url = line.get("URL");
String version = line.get("VERSION");

if (StringUtils.isBlank(version)) {
// blank means applies to ALL versions
versions.values().forEach(table -> table.put(system, code, url));
} else {
Table<String, String, String> mappingTable = versions.get(version);
if (mappingTable == null) {
throw new IllegalArgumentException("Error in loading mapping from file " + filename
+ ". File contains row with version '" + version
+ "' but supported version numbers are: " + String.join(",", supportedVersions));
for (Entry<String, Table<String, String, String>> e : versions.entrySet()) {
String versionKey = e.getKey();
Table<String, String, String> mappingTable = e.getValue();

if (StringUtils.isBlank(version) || version.contains(versionKey)) {
// blank means applies to ALL versions
// version.contains allows for things like "4,5,6"
mappingTable.put(system, code, url);
}
mappingTable.put(system, code, url);
}
}

Expand Down Expand Up @@ -1649,7 +1672,7 @@ private static BundleEntryComponent condition(

if (USE_US_CORE_IG) {
Meta meta = new Meta();
if (useUSCore5()) {
if (useUSCore5() || useUSCore6()) {
meta.addProfile(
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-condition-encounter-diagnosis");
} else {
Expand Down Expand Up @@ -1880,29 +1903,51 @@ private static BundleEntryComponent observation(
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-lab");
}

if (useUSCore5() && observation.category != null) {
switch (observation.category) {
case "imaging":
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-imaging");
break;
case "social-history":
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-social-history");
break;
case "survey":
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-survey");
// note that the -sdoh-assessment profile is a subset of -survey,
// those are handled by code in US_CORE_MAPPING above
break;
case "exam":
// this one is a little nebulous -- are all exams also clinical tests?
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-clinical-test");

observationResource.addCategory().addCoding().setCode("clinical-test")
.setSystem("http://hl7.org/fhir/us/core/CodeSystem/us-core-observation-category")
.setDisplay("Clinical Test");
break;
default:
// do nothing
if (observation.category != null) {
if (useUSCore6()) {
switch (observation.category) {
case "imaging":
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-clinical-result");
break;
case "social-history":
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-simple-observation");
break;
case "survey":
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-screening-assessment");
break;
case "exam":
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-clinical-result");
break;
case "laboratory":
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-lab");
break;
default:
// do nothing
}
} else if (useUSCore5()) {
switch (observation.category) {
case "imaging":
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-imaging");
break;
case "social-history":
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-social-history");
break;
case "survey":
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-survey");
// note that the -sdoh-assessment profile is a subset of -survey,
// those are handled by code in US_CORE_MAPPING above
break;
case "exam":
// this one is a little nebulous -- are all exams also clinical tests?
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-clinical-test");

observationResource.addCategory().addCoding().setCode("clinical-test")
.setSystem("http://hl7.org/fhir/us/core/CodeSystem/us-core-observation-category")
.setDisplay("Clinical Test");
break;
default:
// do nothing
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ String getDualEligibilityCode(Person person, boolean medicareAge,
}

/**
* The the current beneficiary ID code (CRNT_BIC).
* The current beneficiary ID code (CRNT_BIC).
* @param person The person.
* @param ageThisYear The person's current age (at the end of the year).
* @param disabled If the person is disabled according to SSD.
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/org/mitre/synthea/modules/covid/C19Vaccine.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ public enum EUASet {
*/
public static void initialize() {
EUAs.put(EUASet.PFIZER,
new C19Vaccine("SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, "
+ "preservative free, 30 mcg/0.3mL dose", "208", true, 0.531,
new C19Vaccine("COVID-19, mRNA, LNP-S, PF, 30 mcg/0.3 mL dose",
"208", true, 0.531,
Utilities.convertTime("days", 21)));
EUAs.put(EUASet.MODERNA,
new C19Vaccine("SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, "
+ "preservative free, 100 mcg/0.5mL dose", "207", true, 0.398,
new C19Vaccine("COVID-19, mRNA, LNP-S, PF, 100 mcg/0.5mL dose or 50 mcg/0.25mL dose",
"207", true, 0.398,
Utilities.convertTime("days", 28)));
EUAs.put(EUASet.JANSSEN,
new C19Vaccine("SARS-COV-2 (COVID-19) vaccine, vector non-replicating, "
+ "recombinant spike protein-Ad26, preservative free, 0.5 mL",
new C19Vaccine("COVID-19 vaccine, vector-nr, rS-Ad26, PF, 0.5 mL",
"212", false, 0.071, 0));

List<Pair<EUASet, Double>> pmf = EUAs.entrySet().stream()
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/costs/procedures.csv
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CODE,MIN,MODE,MAX,COMMENTS
167995008,3048.51,6097.0171,12194.03,Sputum microscopy (procedure)
91602002,7753.63,15507.25552,31014.51,Thoracentesis (procedure)
432231006,7753.63,15507.25552,31014.51,Fine needle aspiration biopsy of lung (procedure)
173160006,4245.28,8490.5551,16981.11,Diagnostic fiberoptic bronchoscopy (procedure)
85765000,4245.28,8490.5551,16981.11,Fiberoptic bronchoscopy (procedure)
698354004,5103.68,10207.35977,20414.72,Magnetic resonance imaging for measurement of brain volume (procedure)
430193006,250.00,500,1000.00,Medication Reconciliation (procedure)
180030006,10671.22,21342.44596,42684.89,Amputation of right foot
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/modules/lung_cancer.json
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@
"codes": [
{
"system": "SNOMED-CT",
"code": "173160006",
"display": "Diagnostic fiberoptic bronchoscopy (procedure)"
"code": "85765000",
"display": "Fiberoptic bronchoscopy (procedure)"
}
],
"direct_transition": "End_Diagnosis_Encounter_III"
Expand Down
9 changes: 7 additions & 2 deletions src/main/resources/modules/sepsis.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,13 @@
"codes": [
{
"system": "LOINC",
"code": "2713-6",
"display": "Oxygen saturation Calculated from oxygen partial pressure in Blood"
"code": "2708-6",
"display": "Oxygen saturation in Arterial blood"
},
{
"system": "LOINC",
"code": "59408-5",
"display": "Oxygen saturation in Arterial blood by Pulse oximetry"
}
],
"direct_transition": "Lactate_Level1",
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/modules/veteran_lung_cancer.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@
"codes": [
{
"system": "SNOMED-CT",
"code": "173160006",
"display": "Diagnostic fiberoptic bronchoscopy (procedure)"
"code": "85765000",
"display": "Fiberoptic bronchoscopy (procedure)"
}
],
"direct_transition": "End_Diagnosis_Encounter_III"
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/synthea.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ exporter.fhir.us_core_version = 5.0.1
exporter.fhir.transaction_bundle = true
# using bulk_data=true will ignore exporter.pretty_print
exporter.fhir.bulk_data = false
# hostname embedded into the generated parameters file. Defaults to http://localhost:8000/
#exporter.fhir.bulk_data.parameter_hostname = http://example.org/
# included_ and excluded_resources list out the resource types to include/exclude in the csv exporters.
# only one of these may be set at a time, if both are set then both will be ignored.
# if neither is set, then all resource types will be included.
Expand Down
Loading

0 comments on commit 025e0f0

Please sign in to comment.