Search in sources :

Example 16 with Code

use of org.mitre.synthea.world.concepts.HealthRecord.Code in project synthea by synthetichealth.

the class FhirR4 method observation.

/**
 * Map the given Observation into a FHIR Observation resource, and add it to the given Bundle.
 *
 * @param rand           Source of randomness to use when generating ids etc
 * @param personEntry    The Person Entry
 * @param bundle         The Bundle to add to
 * @param encounterEntry The current Encounter entry
 * @param observation    The Observation
 * @return The added Entry
 */
private static BundleEntryComponent observation(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Observation observation) {
    org.hl7.fhir.r4.model.Observation observationResource = new org.hl7.fhir.r4.model.Observation();
    observationResource.setSubject(new Reference(personEntry.getFullUrl()));
    observationResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
    observationResource.setStatus(ObservationStatus.FINAL);
    Code code = observation.codes.get(0);
    observationResource.setCode(mapCodeToCodeableConcept(code, LOINC_URI));
    // add extra codes, if there are any...
    if (observation.codes.size() > 1) {
        for (int i = 1; i < observation.codes.size(); i++) {
            code = observation.codes.get(i);
            Coding coding = new Coding();
            coding.setCode(code.code);
            coding.setDisplay(code.display);
            coding.setSystem(LOINC_URI);
            observationResource.getCode().addCoding(coding);
        }
    }
    observationResource.addCategory().addCoding().setCode(observation.category).setSystem("http://terminology.hl7.org/CodeSystem/observation-category").setDisplay(observation.category);
    if (observation.value != null) {
        Type value = mapValueToFHIRType(observation.value, observation.unit);
        observationResource.setValue(value);
    } else if (observation.observations != null && !observation.observations.isEmpty()) {
        // multi-observation (ex blood pressure)
        for (Observation subObs : observation.observations) {
            ObservationComponentComponent comp = new ObservationComponentComponent();
            comp.setCode(mapCodeToCodeableConcept(subObs.codes.get(0), LOINC_URI));
            Type value = mapValueToFHIRType(subObs.value, subObs.unit);
            comp.setValue(value);
            observationResource.addComponent(comp);
        }
    }
    observationResource.setEffective(convertFhirDateTime(observation.start, true));
    observationResource.setIssued(new Date(observation.start));
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        // add the specific profile based on code
        String codeMappingUri = US_CORE_MAPPING.get(LOINC_URI, code.code);
        if (codeMappingUri != null) {
            meta.addProfile(codeMappingUri);
            if (!codeMappingUri.contains("/us/core/") && observation.category.equals("vital-signs")) {
                meta.addProfile("http://hl7.org/fhir/StructureDefinition/vitalsigns");
            }
        } else if (observation.report != null && observation.category.equals("laboratory")) {
            meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-lab");
        }
        if (meta.hasProfile()) {
            observationResource.setMeta(meta);
        }
    } else if (USE_SHR_EXTENSIONS) {
        Meta meta = new Meta();
        // all Observations are Observations
        meta.addProfile(SHR_EXT + "shr-finding-Observation");
        if ("vital-signs".equals(observation.category)) {
            meta.addProfile(SHR_EXT + "shr-vital-VitalSign");
        }
        // add the specific profile based on code
        String codeMappingUri = SHR_MAPPING.get(LOINC_URI, code.code);
        if (codeMappingUri != null) {
            meta.addProfile(codeMappingUri);
        }
        observationResource.setMeta(meta);
    }
    BundleEntryComponent entry = newEntry(rand, bundle, observationResource);
    observation.fullUrl = entry.getFullUrl();
    return entry;
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Date(java.util.Date) IntegerType(org.hl7.fhir.r4.model.IntegerType) BooleanType(org.hl7.fhir.r4.model.BooleanType) BundleType(org.hl7.fhir.r4.model.Bundle.BundleType) EncounterType(org.mitre.synthea.world.concepts.HealthRecord.EncounterType) DeviceNameType(org.hl7.fhir.r4.model.Device.DeviceNameType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) AllergyIntoleranceType(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceType) DecimalType(org.hl7.fhir.r4.model.DecimalType) CodeType(org.hl7.fhir.r4.model.CodeType) NodeType(org.hl7.fhir.utilities.xhtml.NodeType) StringType(org.hl7.fhir.r4.model.StringType) DateType(org.hl7.fhir.r4.model.DateType) PositiveIntType(org.hl7.fhir.r4.model.PositiveIntType) Type(org.hl7.fhir.r4.model.Type) DoseRateType(org.hl7.fhir.r4.model.codesystems.DoseRateType) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) ObservationComponentComponent(org.hl7.fhir.r4.model.Observation.ObservationComponentComponent) Observation(org.mitre.synthea.world.concepts.HealthRecord.Observation)

Example 17 with Code

use of org.mitre.synthea.world.concepts.HealthRecord.Code in project synthea by synthetichealth.

the class FhirDstu2 method procedure.

/**
 * Map the given Procedure into a FHIR Procedure resource, and add it to the given Bundle.
 *
 * @param rand
 *          Source of randomness to use when generating ids etc
 * @param personEntry
 *          The Person entry
 * @param bundle
 *          Bundle to add to
 * @param encounterEntry
 *          The current Encounter entry
 * @param procedure
 *          The Procedure
 * @return The added Entry
 */
private static Entry procedure(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Procedure procedure) {
    ca.uhn.fhir.model.dstu2.resource.Procedure procedureResource = new ca.uhn.fhir.model.dstu2.resource.Procedure();
    procedureResource.setStatus(ProcedureStatusEnum.COMPLETED);
    procedureResource.setSubject(new ResourceReferenceDt(personEntry.getFullUrl()));
    procedureResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
    Code code = procedure.codes.get(0);
    procedureResource.setCode(mapCodeToCodeableConcept(code, SNOMED_URI));
    if (procedure.stop != 0L) {
        Date startDate = new Date(procedure.start);
        Date endDate = new Date(procedure.stop);
        procedureResource.setPerformed(new PeriodDt().setStart(new DateTimeDt(startDate)).setEnd(new DateTimeDt(endDate)));
    } else {
        procedureResource.setPerformed(convertFhirDateTime(procedure.start, true));
    }
    if (!procedure.reasons.isEmpty()) {
        // Only one element in list
        Code reason = procedure.reasons.get(0);
        for (Entry entry : bundle.getEntry()) {
            if (entry.getResource().getResourceName().equals("Condition")) {
                Condition condition = (Condition) entry.getResource();
                // Only one element in list
                CodingDt coding = condition.getCode().getCoding().get(0);
                if (reason.code.equals(coding.getCode())) {
                    procedureResource.setReason(new ResourceReferenceDt(entry.getFullUrl()));
                }
            }
        }
    }
    Entry procedureEntry = newEntry(rand, bundle, procedureResource);
    procedure.fullUrl = procedureEntry.getFullUrl();
    return procedureEntry;
}
Also used : Condition(ca.uhn.fhir.model.dstu2.resource.Condition) ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) PeriodDt(ca.uhn.fhir.model.dstu2.composite.PeriodDt) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) CodingDt(ca.uhn.fhir.model.dstu2.composite.CodingDt) Procedure(org.mitre.synthea.world.concepts.HealthRecord.Procedure)

Example 18 with Code

use of org.mitre.synthea.world.concepts.HealthRecord.Code in project synthea by synthetichealth.

the class FhirDstu2 method condition.

/**
 * Map the Condition into a FHIR Condition resource, and add it to the given Bundle.
 *
 * @param rand
 *          Source of randomness to use when generating ids etc
 * @param personEntry
 *          The Entry for the Person
 * @param bundle
 *          The Bundle to add to
 * @param encounterEntry
 *          The current Encounter entry
 * @param condition
 *          The Condition
 * @return The added Entry
 */
private static Entry condition(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, HealthRecord.Entry condition) {
    Condition conditionResource = new Condition();
    conditionResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
    conditionResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
    Code code = condition.codes.get(0);
    conditionResource.setCode(mapCodeToCodeableConcept(code, SNOMED_URI));
    conditionResource.setCategory(ConditionCategoryCodesEnum.DIAGNOSIS);
    conditionResource.setVerificationStatus(ConditionVerificationStatusEnum.CONFIRMED);
    conditionResource.setClinicalStatus(ConditionClinicalStatusCodesEnum.ACTIVE);
    conditionResource.setOnset(convertFhirDateTime(condition.start, true));
    conditionResource.setDateRecorded(new DateDt(new Date(condition.start)));
    if (condition.stop != 0) {
        conditionResource.setAbatement(convertFhirDateTime(condition.stop, true));
        conditionResource.setClinicalStatus(ConditionClinicalStatusCodesEnum.RESOLVED);
    }
    Entry conditionEntry = newEntry(rand, bundle, conditionResource);
    condition.fullUrl = conditionEntry.getFullUrl();
    return conditionEntry;
}
Also used : Condition(ca.uhn.fhir.model.dstu2.resource.Condition) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) DateDt(ca.uhn.fhir.model.primitive.DateDt) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date)

Example 19 with Code

use of org.mitre.synthea.world.concepts.HealthRecord.Code 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 20 with Code

use of org.mitre.synthea.world.concepts.HealthRecord.Code in project synthea by synthetichealth.

the class FhirDstu2 method medicationAdministration.

/**
 * Add a MedicationAdministration if needed for the given medication.
 *
 * @param rand              Source of randomness to use when generating ids etc
 * @param personEntry       The Entry for the Person
 * @param bundle            Bundle to add the MedicationAdministration to
 * @param encounterEntry    Current Encounter entry
 * @param medication        The Medication
 * @return The added Entry
 */
private static Entry medicationAdministration(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Medication medication) {
    MedicationAdministration medicationResource = new MedicationAdministration();
    medicationResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
    medicationResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
    Code code = medication.codes.get(0);
    String system = code.system.equals("SNOMED-CT") ? SNOMED_URI : RXNORM_URI;
    medicationResource.setMedication(mapCodeToCodeableConcept(code, system));
    medicationResource.setEffectiveTime(new DateTimeDt(new Date(medication.start)));
    medicationResource.setStatus(MedicationAdministrationStatusEnum.COMPLETED);
    if (medication.prescriptionDetails != null) {
        JsonObject rxInfo = medication.prescriptionDetails;
        MedicationAdministration.Dosage dosage = new MedicationAdministration.Dosage();
        // as_needed is true if present
        if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
            SimpleQuantityDt dose = new SimpleQuantityDt();
            dose.setValue(rxInfo.get("dosage").getAsJsonObject().get("amount").getAsDouble());
            dosage.setQuantity(dose);
            if (rxInfo.has("instructions")) {
                for (JsonElement instructionElement : rxInfo.get("instructions").getAsJsonArray()) {
                    JsonObject instruction = instructionElement.getAsJsonObject();
                    dosage.setText(instruction.get("display").getAsString());
                }
            }
        }
        medicationResource.setDosage(dosage);
    }
    if (!medication.reasons.isEmpty()) {
        // Only one element in list
        Code reason = medication.reasons.get(0);
        for (Entry entry : bundle.getEntry()) {
            if (entry.getResource().getResourceName().equals("Condition")) {
                Condition condition = (Condition) entry.getResource();
                // Only one element in list
                CodeableConceptDt coding = condition.getCode();
                if (reason.code.equals(coding.getCodingFirstRep().getCode())) {
                    medicationResource.addReasonGiven(coding);
                }
            }
        }
    }
    Entry medicationAdminEntry = newEntry(rand, bundle, medicationResource);
    return medicationAdminEntry;
}
Also used : Condition(ca.uhn.fhir.model.dstu2.resource.Condition) ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) CodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt) SimpleQuantityDt(ca.uhn.fhir.model.dstu2.composite.SimpleQuantityDt) JsonObject(com.google.gson.JsonObject) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) JsonElement(com.google.gson.JsonElement) MedicationAdministration(ca.uhn.fhir.model.dstu2.resource.MedicationAdministration)

Aggregations

Code (org.mitre.synthea.world.concepts.HealthRecord.Code)152 Test (org.junit.Test)64 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)49 HealthRecord (org.mitre.synthea.world.concepts.HealthRecord)48 Date (java.util.Date)30 CardiovascularDiseaseModule (org.mitre.synthea.modules.CardiovascularDiseaseModule)30 DeathModule (org.mitre.synthea.modules.DeathModule)30 EncounterModule (org.mitre.synthea.modules.EncounterModule)30 LifecycleModule (org.mitre.synthea.modules.LifecycleModule)30 QualityOfLifeModule (org.mitre.synthea.modules.QualityOfLifeModule)30 WeightLossModule (org.mitre.synthea.modules.WeightLossModule)29 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)20 JsonObject (com.google.gson.JsonObject)19 Person (org.mitre.synthea.world.agents.Person)19 Medication (org.mitre.synthea.world.concepts.HealthRecord.Medication)15 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)14 Reference (org.hl7.fhir.r4.model.Reference)14 Provider (org.mitre.synthea.world.agents.Provider)14 Meta (org.hl7.fhir.r4.model.Meta)13