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 (Rebuild) #1353

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
18 changes: 18 additions & 0 deletions src/main/java/org/mitre/synthea/export/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ 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.personal_data")) {
// org.hl7.fhir.r4.model.Bundle bundle = FhirR4.convertToFHIR(person, stopTime);
// 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"));
Expand All @@ -255,6 +264,15 @@ 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")) {
String ndjson = JSONExporter.export(person);
File outDirectory = getOutputFolder("ndjson", person);
Path outFilePath = outDirectory.toPath().resolve(filename(person, fileTag, "ndjson"));
writeNewFile(outFilePath, ndjson);
}


if (Config.getAsBoolean("exporter.csv.export")) {
try {
CSVExporter.getInstance().export(person, stopTime);
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,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,6 +39,7 @@ 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
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/mitre/synthea/TestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public static void exportOff() {
Config.set("exporter.practitioner.fhir_stu3.export", "false");
Config.set("exporter.practitioner.fhir_dstu2.export", "false");
Config.set("exporter.json.export", "false");
Config.set("exporter.ndjson.export", "false");
Config.set("exporter.csv.export", "false");
Config.set("exporter.cpcds.export", "false");
Config.set("exporter.bfd.export", "false");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void export() throws Exception {
List<String> validationErrors = new ArrayList<>();
TestHelper.exportOff();
Config.set("exporter.json.export", "true");
Config.set("exporter.ndjson.export", "true");
boolean moduleExport = person.randBoolean();
Config.set("exporter.json.include_module_history", String.valueOf(moduleExport));
String personJson = JSONExporter.export(person);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void endToEnd() throws Exception {
TestHelper.exportOff();
Config.set("exporter.fhir.export", "true");
Config.set("exporter.json.export", "true");
Config.set("exporter.ndjson.export", "true");
Generator.DEFAULT_STATE = "North Carolina";
Path baseDirectory = tempFolder.newFolder().toPath();
Config.set("exporter.baseDirectory", baseDirectory.toString());
Expand Down