use of org.mitre.synthea.world.agents.Clinician in project synthea by synthetichealth.
the class FhirPractitionerExporterR4 method export.
/**
* Export the practitioner in FHIR R4 format.
*/
public static void export(RandomNumberGenerator rand, long stop) {
if (Config.getAsBoolean("exporter.practitioner.fhir.export")) {
Bundle bundle = new Bundle();
if (Config.getAsBoolean("exporter.fhir.transaction_bundle")) {
bundle.setType(BundleType.BATCH);
} else {
bundle.setType(BundleType.COLLECTION);
}
for (Provider h : Provider.getProviderList()) {
// filter - exports only those hospitals in use
Table<Integer, String, AtomicInteger> utilization = h.getUtilization();
int totalEncounters = utilization.column(Provider.ENCOUNTERS).values().stream().mapToInt(ai -> ai.get()).sum();
if (totalEncounters > 0) {
Map<String, ArrayList<Clinician>> clinicians = h.clinicianMap;
for (String specialty : clinicians.keySet()) {
ArrayList<Clinician> docs = clinicians.get(specialty);
for (Clinician doc : docs) {
if (doc.getEncounterCount() > 0) {
BundleEntryComponent entry = FhirR4.practitioner(rand, bundle, doc);
Practitioner practitioner = (Practitioner) entry.getResource();
practitioner.addExtension().setUrl(EXTENSION_URI).setValue(new IntegerType(doc.getEncounterCount()));
}
}
}
}
}
String bundleJson = FhirR4.getContext().newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle);
// get output folder
List<String> folders = new ArrayList<>();
folders.add("fhir");
String baseDirectory = Config.get("exporter.baseDirectory");
File f = Paths.get(baseDirectory, folders.toArray(new String[0])).toFile();
f.mkdirs();
Path outFilePath = f.toPath().resolve("practitionerInformation" + stop + ".json");
try {
Files.write(outFilePath, Collections.singleton(bundleJson), StandardOpenOption.CREATE_NEW);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Aggregations