diff --git a/src/main/java/org/mitre/synthea/export/Exporter.java b/src/main/java/org/mitre/synthea/export/Exporter.java index 34dc2aac65..36490afce9 100644 --- a/src/main/java/org/mitre/synthea/export/Exporter.java +++ b/src/main/java/org/mitre/synthea/export/Exporter.java @@ -21,9 +21,12 @@ 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; +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 +502,36 @@ 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; 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.