Search in sources :

Example 1 with Practitioner

use of ca.uhn.fhir.model.dstu2.resource.Practitioner in project synthea by synthetichealth.

the class FhirDstu2 method encounter.

/**
 * Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
 *
 * @param person
 *          Patient at the encounter.
 * @param personEntry
 *          Entry for the Person
 * @param bundle
 *          The Bundle to add to
 * @param encounter
 *          The current Encounter
 * @return The added Entry
 */
private static Entry encounter(Person person, Entry personEntry, Bundle bundle, Encounter encounter) {
    ca.uhn.fhir.model.dstu2.resource.Encounter encounterResource = new ca.uhn.fhir.model.dstu2.resource.Encounter();
    encounterResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
    encounterResource.setStatus(EncounterStateEnum.FINISHED);
    if (encounter.codes.isEmpty()) {
        // wellness encounter
        encounterResource.addType().addCoding().setCode("185349003").setDisplay("Encounter for check up").setSystem(SNOMED_URI);
    } else {
        Code code = encounter.codes.get(0);
        encounterResource.addType(mapCodeToCodeableConcept(code, SNOMED_URI));
    }
    EncounterClassEnum encounterClass = EncounterClassEnum.forCode(encounter.type);
    if (encounterClass == null) {
        encounterClass = EncounterClassEnum.AMBULATORY;
    }
    encounterResource.setClassElement(encounterClass);
    encounterResource.setPeriod(new PeriodDt().setStart(new DateTimeDt(new Date(encounter.start))).setEnd(new DateTimeDt(new Date(encounter.stop))));
    if (encounter.reason != null) {
        encounterResource.addReason().addCoding().setCode(encounter.reason.code).setDisplay(encounter.reason.display).setSystem(SNOMED_URI);
    }
    Provider provider = encounter.provider;
    if (provider == null) {
        // no associated provider, patient goes to wellness provider
        provider = person.getProvider(EncounterType.WELLNESS, encounter.start);
    }
    if (TRANSACTION_BUNDLE) {
        encounterResource.setServiceProvider(new ResourceReferenceDt(ExportHelper.buildFhirSearchUrl("Organization", provider.getResourceID())));
    } else {
        String providerFullUrl = findProviderUrl(provider, bundle);
        if (providerFullUrl != null) {
            encounterResource.setServiceProvider(new ResourceReferenceDt(providerFullUrl));
        } else {
            Entry providerOrganization = provider(bundle, provider);
            encounterResource.setServiceProvider(new ResourceReferenceDt(providerOrganization.getFullUrl()));
        }
    }
    encounterResource.getServiceProvider().setDisplay(provider.name);
    if (encounter.clinician != null) {
        if (TRANSACTION_BUNDLE) {
            encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(ExportHelper.buildFhirNpiSearchUrl(encounter.clinician)));
        } else {
            String practitionerFullUrl = findPractitioner(encounter.clinician, bundle);
            if (practitionerFullUrl != null) {
                encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(practitionerFullUrl));
            } else {
                Entry practitioner = practitioner(bundle, encounter.clinician);
                encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(practitioner.getFullUrl()));
            }
        }
        encounterResource.getParticipantFirstRep().getIndividual().setDisplay(encounter.clinician.getFullname());
    }
    if (encounter.discharge != null) {
        Hospitalization hospitalization = new Hospitalization();
        Code dischargeDisposition = new Code(DISCHARGE_URI, encounter.discharge.code, encounter.discharge.display);
        hospitalization.setDischargeDisposition(mapCodeToCodeableConcept(dischargeDisposition, DISCHARGE_URI));
        encounterResource.setHospitalization(hospitalization);
    }
    return newEntry(person, bundle, encounterResource);
}
Also used : ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) PeriodDt(ca.uhn.fhir.model.dstu2.composite.PeriodDt) Hospitalization(ca.uhn.fhir.model.dstu2.resource.Encounter.Hospitalization) EncounterClassEnum(ca.uhn.fhir.model.dstu2.valueset.EncounterClassEnum) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Provider(org.mitre.synthea.world.agents.Provider) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter)

Example 2 with Practitioner

use of ca.uhn.fhir.model.dstu2.resource.Practitioner in project synthea by synthetichealth.

the class FhirPractitionerExporterDstu2 method export.

/**
 * Export the practitioner in FHIR DSTU2 format.
 */
public static void export(long stop) {
    if (Config.getAsBoolean("exporter.practitioner.fhir_dstu2.export")) {
        Bundle bundle = new Bundle();
        if (Config.getAsBoolean("exporter.fhir.transaction_bundle")) {
            bundle.setType(BundleTypeEnum.BATCH);
        } else {
            bundle.setType(BundleTypeEnum.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) {
                            Entry entry = FhirDstu2.practitioner(bundle, doc);
                            Practitioner practitioner = (Practitioner) entry.getResource();
                            ExtensionDt extension = new ExtensionDt();
                            extension.setUrl(EXTENSION_URI);
                            extension.setValue(new IntegerDt(doc.getEncounterCount()));
                            practitioner.addUndeclaredExtension(extension);
                        }
                    }
                }
            }
        }
        String bundleJson = FhirDstu2.getContext().newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle);
        // get output folder
        List<String> folders = new ArrayList<>();
        folders.add("fhir_dstu2");
        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 : Config(org.mitre.synthea.helpers.Config) Files(java.nio.file.Files) Clinician(org.mitre.synthea.world.agents.Clinician) ExtensionDt(ca.uhn.fhir.model.api.ExtensionDt) IntegerDt(ca.uhn.fhir.model.primitive.IntegerDt) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException) Bundle(ca.uhn.fhir.model.dstu2.resource.Bundle) File(java.io.File) BundleTypeEnum(ca.uhn.fhir.model.dstu2.valueset.BundleTypeEnum) ArrayList(java.util.ArrayList) Provider(org.mitre.synthea.world.agents.Provider) List(java.util.List) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) Practitioner(ca.uhn.fhir.model.dstu2.resource.Practitioner) Paths(java.nio.file.Paths) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Table(com.google.common.collect.Table) Path(java.nio.file.Path) Collections(java.util.Collections) Path(java.nio.file.Path) IntegerDt(ca.uhn.fhir.model.primitive.IntegerDt) Bundle(ca.uhn.fhir.model.dstu2.resource.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(ca.uhn.fhir.model.dstu2.resource.Practitioner) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File) ExtensionDt(ca.uhn.fhir.model.api.ExtensionDt)

Example 3 with Practitioner

use of ca.uhn.fhir.model.dstu2.resource.Practitioner in project eCRNow by drajer-health.

the class Dstu2CdaHeaderGenerator method getEncompassingEncounter.

public static String getEncompassingEncounter(Encounter en, Practitioner pr, Location loc, Organization org, LaunchDetails details) {
    StringBuilder sb = new StringBuilder(2000);
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.COMPONENT_OF_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.ENCOMPASSING_ENC_EL_NAME));
    if (en != null) {
        sb.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), en.getId().getIdPart()));
        // Add all the encounter identifiers to the Ids
        List<IdentifierDt> ids = en.getIdentifier();
        if (ids != null) {
            for (IdentifierDt id : ids) {
                if (id.getSystem() != null && id.getValue() != null) {
                    sb.append(CdaGeneratorUtils.getXmlForII(CdaGeneratorUtils.getRootOid(id.getSystem(), details.getAssigningAuthorityId()), id.getValue()));
                }
            }
        }
        sb.append(Dstu2CdaFhirUtilities.getCodeableConceptXml(en.getType(), CdaGeneratorConstants.CODE_EL_NAME, false));
        sb.append(Dstu2CdaFhirUtilities.getPeriodXml(en.getPeriod(), CdaGeneratorConstants.EFF_TIME_EL_NAME));
    } else {
        sb.append(CdaGeneratorUtils.getXmlForIIUsingGuid());
        sb.append(CdaGeneratorUtils.getXmlForNullCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.NF_NI));
        sb.append(CdaGeneratorUtils.getXmlForNullEffectiveTime(CdaGeneratorConstants.EFF_TIME_EL_NAME, CdaGeneratorConstants.NF_NI));
    }
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.RESP_PARTY_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.ASSIGNED_ENTITY_EL_NAME));
    sb.append(getPractitionerXml(pr));
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.REP_ORG_EL_NAME));
    sb.append(getOrganizationXml(org, details));
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.REP_ORG_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ASSIGNED_ENTITY_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.RESP_PARTY_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.LOCATION_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.HEALTHCARE_FACILITY_EL_NAME));
    sb.append(getLocationXml(loc));
    sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.SERVICE_PROVIDER_ORG_EL_NAME));
    sb.append(getOrganizationXml(org, details));
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.SERVICE_PROVIDER_ORG_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.HEALTHCARE_FACILITY_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.LOCATION_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ENCOMPASSING_ENC_EL_NAME));
    sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.COMPONENT_OF_EL_NAME));
    return sb.toString();
}
Also used : IdentifierDt(ca.uhn.fhir.model.dstu2.composite.IdentifierDt)

Example 4 with Practitioner

use of ca.uhn.fhir.model.dstu2.resource.Practitioner in project eCRNow by drajer-health.

the class Dstu2CdaEicrGenerator method convertDstu2FhirBundletoCdaEicr.

public static String convertDstu2FhirBundletoCdaEicr(Dstu2FhirData data, LaunchDetails details, Eicr ecr) {
    StringBuilder eICR = new StringBuilder();
    if (data != null) {
        Bundle bundle = data.getData();
        if (bundle != null) {
            List<Entry> entries = bundle.getEntry();
            for (Entry ent : entries) {
                // Populate data ..this can be moved to the APIs where the bundle is getting created.
                if (ent.getResource() instanceof Patient) {
                    logger.info(" Bundle contains Patient ");
                    data.setPatient((Patient) ent.getResource());
                } else if (ent.getResource() instanceof Practitioner) {
                    logger.info(" Bundle contains Practitioner ");
                    data.setPractitioner((Practitioner) ent.getResource());
                } else if (ent.getResource() instanceof Encounter) {
                    logger.info(" Bundle contains Encounter ");
                    data.setEncounter((Encounter) ent.getResource());
                } else if (ent.getResource() instanceof Location) {
                    logger.info(" Bundle contains Location ");
                    data.setLocation((Location) ent.getResource());
                } else if (ent.getResource() instanceof Organization) {
                    logger.info(" Bundle contains Organization ");
                    data.setOrganization((Organization) ent.getResource());
                } else if (ent.getResource() instanceof Condition) {
                    logger.info(" Bundle contains Condition ");
                    data.getConditions().add((Condition) ent.getResource());
                } else if (ent.getResource() instanceof Observation) {
                    Observation obs = (Observation) ent.getResource();
                    if (obs.getCategory() != null && obs.getCategory().getCodingFirstRep() != null && obs.getCategory().getCodingFirstRep().getCode() != null && obs.getCategory().getCodingFirstRep().getCode().contentEquals(CdaGeneratorConstants.FHIR_LAB_RESULT_CATEGORY)) {
                        logger.info(" Bundle contains Lab Results ");
                        data.getLabResults().add((Observation) ent.getResource());
                    } else if (obs.getCategory() != null && obs.getCategory().getCodingFirstRep() != null && obs.getCategory().getCodingFirstRep().getCode() != null) {
                        logger.info("Code for Observation Category =  " + obs.getCategory().getCodingFirstRep().getCode());
                    }
                // Compare Code for Travel Obs
                // Compare Codes for Pregnancy Obs and sort it out.
                } else if (ent.getResource() instanceof DiagnosticReport) {
                    logger.info(" Bundle contains Diagnostic Report ");
                    data.getDiagReports().add((DiagnosticReport) ent.getResource());
                } else if (ent.getResource() instanceof DiagnosticOrder) {
                    logger.info(" Bundle contains Diagnostic Order ");
                    data.getDiagOrders().add((DiagnosticOrder) ent.getResource());
                } else if (ent.getResource() instanceof MedicationStatement) {
                    logger.info(" Bundle contains MedicationStatement ");
                    data.getMedications().add((MedicationStatement) ent.getResource());
                } else if (ent.getResource() instanceof Immunization) {
                    logger.info(" Bundle contains Immunization ");
                    data.getImmunizations().add((Immunization) ent.getResource());
                }
            }
            eICR.append(Dstu2CdaHeaderGenerator.createCdaHeader(data, details));
            eICR.append(Dstu2CdaBodyGenerator.generateCdaBody(data, details));
            eICR.append(CdaGeneratorUtils.getEndXMLHeaderForCdaDocument());
        }
    } else {
        logger.error(" No Fhir Bundle Available to create CDA Documents ");
    }
    return eICR.toString();
}
Also used : Condition(ca.uhn.fhir.model.dstu2.resource.Condition) Immunization(ca.uhn.fhir.model.dstu2.resource.Immunization) Organization(ca.uhn.fhir.model.dstu2.resource.Organization) Bundle(ca.uhn.fhir.model.dstu2.resource.Bundle) Patient(ca.uhn.fhir.model.dstu2.resource.Patient) DiagnosticReport(ca.uhn.fhir.model.dstu2.resource.DiagnosticReport) DiagnosticOrder(ca.uhn.fhir.model.dstu2.resource.DiagnosticOrder) Practitioner(ca.uhn.fhir.model.dstu2.resource.Practitioner) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) Observation(ca.uhn.fhir.model.dstu2.resource.Observation) Encounter(ca.uhn.fhir.model.dstu2.resource.Encounter) MedicationStatement(ca.uhn.fhir.model.dstu2.resource.MedicationStatement) Location(ca.uhn.fhir.model.dstu2.resource.Location)

Example 5 with Practitioner

use of ca.uhn.fhir.model.dstu2.resource.Practitioner in project eCRNow by drajer-health.

the class Dstu2CdaFhirUtilities method getPractitioner.

public static Practitioner getPractitioner(List<Entry> entries, Encounter en) {
    List<Participant> participants = en.getParticipant();
    if (participants != null && participants.size() > 0) {
        for (Participant part : participants) {
            if (part.getIndividual().getReference().hasIdPart()) {
                logger.info(" Individual is present ");
                List<BoundCodeableConceptDt<ParticipantTypeEnum>> types = part.getType();
                for (BoundCodeableConceptDt<ParticipantTypeEnum> conc : types) {
                    List<CodingDt> typeCodes = conc.getCoding();
                    for (CodingDt cd : typeCodes) {
                        if (cd.getCode().contentEquals(ParticipantTypeEnum.PPRF.getCode())) {
                            // Found the participant.
                            // Look for the Practitioner.
                            Entry ent = getResourceEntryForId(part.getIndividual().getReference().getIdPart(), "Practitioner", entries);
                            if (ent != null) {
                                logger.info(" Found Practitioner for Id " + part.getIndividual().getReference().getIdPart());
                                return (Practitioner) ent.getResource();
                            } else {
                                logger.info(" Did not find the practitioner for : " + part.getIndividual().getReference().getIdPart());
                            }
                        }
                    }
                }
            }
        }
    }
    logger.info(" Did not find the practitioner for encounter ");
    return null;
}
Also used : Practitioner(ca.uhn.fhir.model.dstu2.resource.Practitioner) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) Participant(ca.uhn.fhir.model.dstu2.resource.Encounter.Participant) ParticipantTypeEnum(ca.uhn.fhir.model.dstu2.valueset.ParticipantTypeEnum) CodingDt(ca.uhn.fhir.model.dstu2.composite.CodingDt) BoundCodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.BoundCodeableConceptDt)

Aggregations

Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)7 Practitioner (ca.uhn.fhir.model.dstu2.resource.Practitioner)7 Bundle (ca.uhn.fhir.model.dstu2.resource.Bundle)4 Organization (ca.uhn.fhir.model.dstu2.resource.Organization)4 ArrayList (java.util.ArrayList)4 IdentifierDt (ca.uhn.fhir.model.dstu2.composite.IdentifierDt)3 ResourceReferenceDt (ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt)3 Condition (ca.uhn.fhir.model.dstu2.resource.Condition)3 DiagnosticOrder (ca.uhn.fhir.model.dstu2.resource.DiagnosticOrder)3 DiagnosticReport (ca.uhn.fhir.model.dstu2.resource.DiagnosticReport)3 Encounter (ca.uhn.fhir.model.dstu2.resource.Encounter)3 Participant (ca.uhn.fhir.model.dstu2.resource.Encounter.Participant)3 Observation (ca.uhn.fhir.model.dstu2.resource.Observation)3 Patient (ca.uhn.fhir.model.dstu2.resource.Patient)3 List (java.util.List)3 FhirContext (ca.uhn.fhir.context.FhirContext)2 BaseContainedDt (ca.uhn.fhir.model.base.composite.BaseContainedDt)2 BaseResourceReferenceDt (ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt)2 AddressDt (ca.uhn.fhir.model.dstu2.composite.AddressDt)2 Location (ca.uhn.fhir.model.dstu2.resource.Encounter.Location)2