From ef2543ebea0ccdde5592c5d34c7deb07df64e573 Mon Sep 17 00:00:00 2001 From: Jens Kristian Villadsen Date: Sun, 28 Apr 2024 14:05:44 +0200 Subject: [PATCH 1/3] Added feature for generating the parameters file --- .../org/mitre/synthea/export/Exporter.java | 25 +++++++++++++++++++ src/main/resources/synthea.properties | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/mitre/synthea/export/Exporter.java b/src/main/java/org/mitre/synthea/export/Exporter.java index 34dc2aac65..d9afaa7f53 100644 --- a/src/main/java/org/mitre/synthea/export/Exporter.java +++ b/src/main/java/org/mitre/synthea/export/Exporter.java @@ -24,6 +24,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; @@ -499,6 +501,29 @@ 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")); + + 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("http://localhost:8000/"+file.getName())))); + } + overwriteFile(outDirectory.toPath().resolve("parameters.json"), parser.encodeResourceToString(parameters)); + } + + if (options.deferExports) { ExporterRuntimeOptions nonDeferredOptions = new ExporterRuntimeOptions(options); nonDeferredOptions.deferExports = false; diff --git a/src/main/resources/synthea.properties b/src/main/resources/synthea.properties index 310ea91336..3f4729819f 100644 --- a/src/main/resources/synthea.properties +++ b/src/main/resources/synthea.properties @@ -21,7 +21,7 @@ exporter.fhir.use_us_core_ig = true 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.bulk_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. From 52bff28652c35d0654a8731c17dfc2bbe2d9c398 Mon Sep 17 00:00:00 2001 From: Jens Kristian Villadsen Date: Sun, 28 Apr 2024 14:08:09 +0200 Subject: [PATCH 2/3] Reverting back to default --- src/main/resources/synthea.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/synthea.properties b/src/main/resources/synthea.properties index 3f4729819f..310ea91336 100644 --- a/src/main/resources/synthea.properties +++ b/src/main/resources/synthea.properties @@ -21,7 +21,7 @@ exporter.fhir.use_us_core_ig = true 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 = true +exporter.fhir.bulk_data = false # 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. From c3584b41b1907af300f37d53b21ca77dc62c56eb Mon Sep 17 00:00:00 2001 From: Jens Kristian Villadsen Date: Tue, 30 Apr 2024 20:23:43 +0200 Subject: [PATCH 3/3] Added config option and fixed checkstyle remarks --- .../org/mitre/synthea/export/Exporter.java | 18 +++++++++++++----- src/main/resources/synthea.properties | 2 ++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/mitre/synthea/export/Exporter.java b/src/main/java/org/mitre/synthea/export/Exporter.java index d9afaa7f53..36490afce9 100644 --- a/src/main/java/org/mitre/synthea/export/Exporter.java +++ b/src/main/java/org/mitre/synthea/export/Exporter.java @@ -21,6 +21,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.function.Predicate; +import com.google.common.base.Strings; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; @@ -501,15 +502,19 @@ public static void runPostCompletionExports(Generator generator) { */ public static void runPostCompletionExports(Generator generator, ExporterRuntimeOptions options) { - if (Config.getAsBoolean("exporter.fhir.bulk_data")) - { + if (Config.getAsBoolean("exporter.fhir.bulk_data")) { IParser parser = FhirR4.getContext().newJsonParser(); parser.setPrettyPrint(false); - Parameters parameters = new Parameters().addParameter("inputFormat","application/fhir+ndjson"); + 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") @@ -518,9 +523,12 @@ public static void runPostCompletionExports(Generator generator, ExporterRuntime .setValue(new StringType(file.getName().split("\\.")[0]))) .addPart(new Parameters.ParametersParameterComponent() .setName("url") - .setValue(new StringType("http://localhost:8000/"+file.getName())))); + .setValue(new StringType(hostname + file.getName())))); } - overwriteFile(outDirectory.toPath().resolve("parameters.json"), parser.encodeResourceToString(parameters)); + overwriteFile(outDirectory. + toPath(). + resolve("parameters.json"), + parser.encodeResourceToString(parameters)); } diff --git a/src/main/resources/synthea.properties b/src/main/resources/synthea.properties index 310ea91336..d4d599b9a8 100644 --- a/src/main/resources/synthea.properties +++ b/src/main/resources/synthea.properties @@ -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.