Skip to content

Commit

Permalink
Merge pull request #1452 from trifork/feat/support-bulk-import-format
Browse files Browse the repository at this point in the history
Added feature for generating the parameters file
  • Loading branch information
jawalonoski authored May 16, 2024
2 parents 34bcc75 + c3584b4 commit ecc34a8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/main/java/org/mitre/synthea/export/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
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

0 comments on commit ecc34a8

Please sign in to comment.