Search in sources :

Example 6 with Clinician

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();
        }
    }
}
Also used : RandomNumberGenerator(org.mitre.synthea.helpers.RandomNumberGenerator) Config(org.mitre.synthea.helpers.Config) Files(java.nio.file.Files) Clinician(org.mitre.synthea.world.agents.Clinician) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException) File(java.io.File) ArrayList(java.util.ArrayList) Provider(org.mitre.synthea.world.agents.Provider) FhirContext(ca.uhn.fhir.context.FhirContext) List(java.util.List) Paths(java.nio.file.Paths) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) BundleType(org.hl7.fhir.r4.model.Bundle.BundleType) Table(com.google.common.collect.Table) Path(java.nio.file.Path) Collections(java.util.Collections) IntegerType(org.hl7.fhir.r4.model.IntegerType) Practitioner(org.hl7.fhir.r4.model.Practitioner) Path(java.nio.file.Path) Bundle(org.hl7.fhir.r4.model.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Provider(org.mitre.synthea.world.agents.Provider) Clinician(org.mitre.synthea.world.agents.Clinician) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Practitioner(org.hl7.fhir.r4.model.Practitioner) IntegerType(org.hl7.fhir.r4.model.IntegerType) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File)

Aggregations

Clinician (org.mitre.synthea.world.agents.Clinician)6 Provider (org.mitre.synthea.world.agents.Provider)6 Table (com.google.common.collect.Table)5 File (java.io.File)5 IOException (java.io.IOException)5 Path (java.nio.file.Path)5 ArrayList (java.util.ArrayList)5 Collections (java.util.Collections)5 List (java.util.List)5 Map (java.util.Map)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Config (org.mitre.synthea.helpers.Config)5 Files (java.nio.file.Files)3 Paths (java.nio.file.Paths)3 StandardOpenOption (java.nio.file.StandardOpenOption)3 FhirContext (ca.uhn.fhir.context.FhirContext)2 JsonObject (com.google.gson.JsonObject)2 FileOutputStream (java.io.FileOutputStream)2 BigDecimal (java.math.BigDecimal)2 RoundingMode (java.math.RoundingMode)2