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

Added feature for generating the parameters file #1452

Merged
Merged
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
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
Loading