Skip to content

Commit

Permalink
custom exporter concept
Browse files Browse the repository at this point in the history
  • Loading branch information
dehall committed Aug 17, 2023
1 parent a0a3b68 commit 982eef9
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ dependencies {
// JfreeChart for drawing physiology charts
implementation 'org.jfree:jfreechart:1.5.3'

implementation fileTree(dir: 'lib/custom', include: '*.jar')

// Use JUnit test framework
testImplementation('junit:junit') {
version {
Expand Down
Empty file added lib/custom/.keep
Empty file.
1 change: 1 addition & 0 deletions src/main/java/org/mitre/synthea/engine/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ private void init() {
if (Config.getAsBoolean("exporter.cdw.export")) {
CDWExporter.getInstance().setKeyStart((stateIndex * 1_000_000) + 1);
}
Exporter.loadCustomExporters();

this.populationRandom = new DefaultRandomNumberGenerator(options.seed);
this.clinicianRandom = new DefaultRandomNumberGenerator(options.clinicianSeed);
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/org/mitre/synthea/export/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ServiceLoader;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
Expand Down Expand Up @@ -57,6 +58,28 @@ public enum SupportedFhirVersion {

private static final int FILE_BUFFER_SIZE = 4 * 1024 * 1024;

private static List<PatientExporter> patientExporters;
private static List<PostCompletionExporter> postCompletionExporters;

public static void loadCustomExporters() {
if (Config.getAsBoolean("exporter.enable_custom_exporters", false)) {
patientExporters = new LinkedList<>();
postCompletionExporters = new LinkedList<>();

ServiceLoader<PatientExporter> loader = ServiceLoader.load(PatientExporter.class);
for (PatientExporter instance : loader) {
System.out.println(instance.getClass().getCanonicalName());
patientExporters.add(instance);
}

ServiceLoader<PostCompletionExporter> loader2 = ServiceLoader.load(PostCompletionExporter.class);
for (PostCompletionExporter instance : loader2) {
System.out.println(instance.getClass().getCanonicalName());
postCompletionExporters.add(instance);
}
}
}

/**
* Runtime configuration of the record exporter.
*/
Expand Down Expand Up @@ -318,6 +341,13 @@ private static boolean exportRecord(Person person, String fileTag, long stopTime
String consolidatedNotes = ClinicalNoteExporter.export(person);
writeNewFile(outFilePath, consolidatedNotes);
}

if (patientExporters != null && !patientExporters.isEmpty()) {
for (PatientExporter patientExporter : patientExporters) {
patientExporter.export(person, stopTime, options);
}
}

if (options.isQueueEnabled()) {
try {
switch (options.queuedFhirVersion()) {
Expand Down Expand Up @@ -508,6 +538,12 @@ public static void runPostCompletionExports(Generator generator, ExporterRuntime
e.printStackTrace();
}
}

if (postCompletionExporters != null && !postCompletionExporters.isEmpty()) {
for (PostCompletionExporter postCompletionExporter : postCompletionExporters) {
postCompletionExporter.export(generator, options);
}
}

closeOpenFiles();
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/mitre/synthea/export/PatientExporter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.mitre.synthea.export;

import org.mitre.synthea.export.Exporter.ExporterRuntimeOptions;
import org.mitre.synthea.world.agents.Person;

/**
*
*
*/
public interface PatientExporter {

/**
*
* @param person Patient to export
* @param stopTime Time at which the simulation stopped
* @param options Runtime exporter options
*/
void export(Person person, long stopTime, ExporterRuntimeOptions options);
}
17 changes: 17 additions & 0 deletions src/main/java/org/mitre/synthea/export/PostCompletionExporter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.mitre.synthea.export;

import org.mitre.synthea.engine.Generator;
import org.mitre.synthea.export.Exporter.ExporterRuntimeOptions;

/**
*
*
*/
public interface PostCompletionExporter {
/**
*
* @param generator
* @param options
*/
void export(Generator generator, ExporterRuntimeOptions options);
}
3 changes: 3 additions & 0 deletions src/main/resources/synthea.properties
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ exporter.symptoms.csv.append_mode = false
exporter.symptoms.csv.folder_per_run = false
exporter.symptoms.text.export = false

# enable searching for custom exporter implementations
exporter.enable_custom_exporters = true

# the number of patients to generate, by default
# this can be overridden by passing a different value to the Generator constructor
generate.default_population = 1
Expand Down

0 comments on commit 982eef9

Please sign in to comment.