Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NDJSON Exporter #1338

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/main/java/org/mitre/synthea/export/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ private static boolean exportRecord(Person person, String fileTag, long stopTime
writeNewFile(outFilePath, bundleJson);
}
}


if (Config.getAsBoolean("exporter.fhir.export")) {
File outDirectory = getOutputFolder("fhir", person);
if (Config.getAsBoolean("exporter.fhir.bulk_data")) {
Expand All @@ -236,13 +238,28 @@ private static boolean exportRecord(Person person, String fileTag, long stopTime
String entryJson = parser.encodeResourceToString(entry.getResource());
appendToFile(outFilePath, entryJson);
}
// } else if (Config.getAsBoolean("exporter.fhir.longitudinal_data")) {
} else if (Config.getAsBoolean("exporter.fhir.personal_data")) {
org.hl7.fhir.r4.model.Bundle bundle = FhirR4.convertToFHIR(person, stopTime);
//IParser parser = FhirR4.getContext().newNdJsonParser().setPrettyPrint(false);
IParser parser = FhirR4.getContext().newJsonParser().setPrettyPrint(false);
for (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent entry : bundle.getEntry()) {
String filename = entry.getResource().getResourceType().toString() + ".ndjson";
Path outFilePath = outDirectory.toPath().resolve(filename);
String entryJson = parser.encodeResourceToString(entry.getResource());
appendToFile(outFilePath, entryJson);
}
} else {
String bundleJson = FhirR4.convertToFHIRJson(person, stopTime);
Path outFilePath = outDirectory.toPath().resolve(filename(person, fileTag, "json"));
writeNewFile(outFilePath, bundleJson);
}
FhirGroupExporterR4.addPatient((String) person.attributes.get(Person.ID));
}




if (Config.getAsBoolean("exporter.ccda.export")) {
String ccdaXml = CCDAExporter.export(person, stopTime);
File outDirectory = getOutputFolder("ccda", person);
Expand All @@ -255,6 +272,17 @@ private static boolean exportRecord(Person person, String fileTag, long stopTime
Path outFilePath = outDirectory.toPath().resolve(filename(person, fileTag, "json"));
writeNewFile(outFilePath, json);
}

if (Config.getAsBoolean("exporter.ndjson.export")) {
// NDJSON Export
// String ndJson = NdJsonExporter.export(person);
String json = JSONExporter.export(person);
File outDirectory = getOutputFolder("ndjson", person);
Path outFilePath = outDirectory.toPath().resolve(filename(person, fileTag, "ndjson"));
writeNewFile(outFilePath, json);
}


if (Config.getAsBoolean("exporter.csv.export")) {
try {
CSVExporter.getInstance().export(person, stopTime);
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/synthea.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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
exporter.fhir.personal_data = true
# 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 All @@ -38,7 +39,9 @@ exporter.practitioner.fhir_dstu2.export = false
exporter.encoding = UTF-8
exporter.json.export = false
exporter.json.include_module_history = false
exporter.ndjson.export = false
exporter.csv.export = false

# if exporter.csv.append_mode = true, then each run will add new data to any existing CSVs. if false, each run will clear out the files and start fresh
exporter.csv.append_mode = false
# if exporter.csv.folder_per_run = true, then each run will have CSVs placed into a unique subfolder. if false, each run will only use the top-level csv folder
Expand Down
Loading