Search in sources :

Example 1 with Organization

use of ca.uhn.fhir.model.dstu2.resource.Organization 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 Organization

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

the class HospitalExporterDstu2 method addHospitalExtensions.

/**
 * Add FHIR extensions to capture additional information.
 */
public static void addHospitalExtensions(Provider h, Organization organizationResource) {
    Table<Integer, String, AtomicInteger> utilization = h.getUtilization();
    // calculate totals for utilization
    int totalEncounters = utilization.column(Provider.ENCOUNTERS).values().stream().mapToInt(ai -> ai.get()).sum();
    ExtensionDt encountersExtension = new ExtensionDt();
    encountersExtension.setUrl(SYNTHEA_URI + "utilization-encounters-extension");
    IntegerDt encountersValue = new IntegerDt(totalEncounters);
    encountersExtension.setValue(encountersValue);
    organizationResource.addUndeclaredExtension(encountersExtension);
    int totalProcedures = utilization.column(Provider.PROCEDURES).values().stream().mapToInt(ai -> ai.get()).sum();
    ExtensionDt proceduresExtension = new ExtensionDt();
    proceduresExtension.setUrl(SYNTHEA_URI + "utilization-procedures-extension");
    IntegerDt proceduresValue = new IntegerDt(totalProcedures);
    proceduresExtension.setValue(proceduresValue);
    organizationResource.addUndeclaredExtension(proceduresExtension);
    int totalLabs = utilization.column(Provider.LABS).values().stream().mapToInt(ai -> ai.get()).sum();
    ExtensionDt labsExtension = new ExtensionDt();
    labsExtension.setUrl(SYNTHEA_URI + "utilization-labs-extension");
    IntegerDt labsValue = new IntegerDt(totalLabs);
    labsExtension.setValue(labsValue);
    organizationResource.addUndeclaredExtension(labsExtension);
    int totalPrescriptions = utilization.column(Provider.PRESCRIPTIONS).values().stream().mapToInt(ai -> ai.get()).sum();
    ExtensionDt prescriptionsExtension = new ExtensionDt();
    prescriptionsExtension.setUrl(SYNTHEA_URI + "utilization-prescriptions-extension");
    IntegerDt prescriptionsValue = new IntegerDt(totalPrescriptions);
    prescriptionsExtension.setValue(prescriptionsValue);
    organizationResource.addUndeclaredExtension(prescriptionsExtension);
    Integer bedCount = h.getBedCount();
    if (bedCount != null) {
        ExtensionDt bedCountExtension = new ExtensionDt();
        bedCountExtension.setUrl(SYNTHEA_URI + "bed-count-extension");
        IntegerDt bedCountValue = new IntegerDt(bedCount);
        bedCountExtension.setValue(bedCountValue);
        organizationResource.addUndeclaredExtension(bedCountExtension);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Config(org.mitre.synthea.helpers.Config) Organization(ca.uhn.fhir.model.dstu2.resource.Organization) Files(java.nio.file.Files) 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) Paths(java.nio.file.Paths) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Table(com.google.common.collect.Table) Path(java.nio.file.Path) Collections(java.util.Collections) IntegerDt(ca.uhn.fhir.model.primitive.IntegerDt) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExtensionDt(ca.uhn.fhir.model.api.ExtensionDt)

Example 3 with Organization

use of ca.uhn.fhir.model.dstu2.resource.Organization 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 Organization

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

the class Dstu2CdaHeaderGenerator method getOrganizationXml.

public static String getOrganizationXml(Organization org, LaunchDetails details) {
    StringBuilder sb = new StringBuilder(200);
    if (org != null) {
        IdentifierDt id = org.getIdentifierFirstRep();
        if (id != null && !id.isEmpty()) {
            sb.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), id.getValue()));
        } else {
            sb.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), org.getId().getValue()));
        }
        sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.NAME_EL_NAME, org.getName()));
        sb.append(Dstu2CdaFhirUtilities.getTelecomXml(org.getTelecom()));
        sb.append(Dstu2CdaFhirUtilities.getAddressXml(org.getAddress()));
    } else {
        // ***************
        // NOTE : THIS IS TEMPORARY --------
        // For Connectathon testing add defaults, this needs to be removed after connectathon and
        // replaced with the commented out code.
        // ***************
        sb.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), "UtahOutpatientClinic"));
        sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.NAME_EL_NAME, "Utah Outpatient Clinic"));
        List<ContactPointDt> cps = new ArrayList<ContactPointDt>();
        ContactPointDt cp = new ContactPointDt();
        cp.setSystem(ContactPointSystemEnum.PHONE);
        cp.setUse(ContactPointUseEnum.HOME);
        cp.setValue("5557770123");
        cps.add(cp);
        sb.append(Dstu2CdaFhirUtilities.getTelecomXml(cps));
        List<AddressDt> addrs = new ArrayList<AddressDt>();
        AddressDt addr = new AddressDt();
        List<StringDt> addrLine = new ArrayList<StringDt>();
        addrLine.add(new StringDt("0987 Facility Drive"));
        addr.setLine(addrLine);
        addr.setCity("alt Lake City");
        addr.setState("UT");
        addr.setCountry("US");
        addr.setPostalCode("84101");
        addr.setUse(AddressUseEnum.WORK);
        addrs.add(addr);
        sb.append(Dstu2CdaFhirUtilities.getAddressXml(addrs));
    /* sb.append(CdaGeneratorUtils.getNFXMLForII(CdaGeneratorConstants.NF_NI));
      sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.NAME_EL_NAME, CdaGeneratorConstants.UNKNOWN_VALUE));

      List<ContactPointDt> cps = null;
      sb.append(CdaFhirUtilities.getTelecomXml(cps));

      List<AddressDt> addrs = null;
      sb.append(CdaFhirUtilities.getAddressXml(addrs)); */
    }
    return sb.toString();
}
Also used : IdentifierDt(ca.uhn.fhir.model.dstu2.composite.IdentifierDt) AddressDt(ca.uhn.fhir.model.dstu2.composite.AddressDt) ArrayList(java.util.ArrayList) StringDt(ca.uhn.fhir.model.primitive.StringDt) ContactPointDt(ca.uhn.fhir.model.dstu2.composite.ContactPointDt)

Example 5 with Organization

use of ca.uhn.fhir.model.dstu2.resource.Organization 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)

Aggregations

Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)7 Organization (ca.uhn.fhir.model.dstu2.resource.Organization)7 Bundle (ca.uhn.fhir.model.dstu2.resource.Bundle)5 ArrayList (java.util.ArrayList)5 Practitioner (ca.uhn.fhir.model.dstu2.resource.Practitioner)4 List (java.util.List)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 Observation (ca.uhn.fhir.model.dstu2.resource.Observation)3 Patient (ca.uhn.fhir.model.dstu2.resource.Patient)3 Provider (org.mitre.synthea.world.agents.Provider)3 FhirContext (ca.uhn.fhir.context.FhirContext)2 ExtensionDt (ca.uhn.fhir.model.api.ExtensionDt)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