Search in sources :

Example 81 with CodeType

use of org.hl7.fhir.r4.model.CodeType in project synthea by synthetichealth.

the class FhirR4 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 BundleEntryComponent procedure(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Procedure procedure) {
    org.hl7.fhir.r4.model.Procedure procedureResource = new org.hl7.fhir.r4.model.Procedure();
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-procedure");
        procedureResource.setMeta(meta);
    }
    procedureResource.setStatus(ProcedureStatus.COMPLETED);
    procedureResource.setSubject(new Reference(personEntry.getFullUrl()));
    procedureResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
    if (USE_US_CORE_IG) {
        org.hl7.fhir.r4.model.Encounter encounterResource = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
        procedureResource.setLocation(encounterResource.getLocationFirstRep().getLocation());
    }
    Code code = procedure.codes.get(0);
    CodeableConcept procCode = mapCodeToCodeableConcept(code, SNOMED_URI);
    procedureResource.setCode(procCode);
    if (procedure.stop != 0L) {
        Date startDate = new Date(procedure.start);
        Date endDate = new Date(procedure.stop);
        procedureResource.setPerformed(new Period().setStart(startDate).setEnd(endDate));
    } else {
        procedureResource.setPerformed(convertFhirDateTime(procedure.start, true));
    }
    if (!procedure.reasons.isEmpty()) {
        // Only one element in list
        Code reason = procedure.reasons.get(0);
        for (BundleEntryComponent entry : bundle.getEntry()) {
            if (entry.getResource().fhirType().equals("Condition")) {
                Condition condition = (Condition) entry.getResource();
                // Only one element in list
                Coding coding = condition.getCode().getCoding().get(0);
                if (reason.code.equals(coding.getCode())) {
                    procedureResource.addReasonReference().setReference(entry.getFullUrl()).setDisplay(reason.display);
                }
            }
        }
    }
    if (USE_SHR_EXTENSIONS) {
        procedureResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-procedure-ProcedurePerformed"));
        // required fields for this profile are action-PerformedContext-extension,
        // status, code, subject, performed[x]
        Extension performedContext = new Extension();
        performedContext.setUrl(SHR_EXT + "shr-action-PerformedContext-extension");
        performedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("completed"));
        procedureResource.addExtension(performedContext);
    }
    BundleEntryComponent procedureEntry = newEntry(rand, bundle, procedureResource);
    procedure.fullUrl = procedureEntry.getFullUrl();
    return procedureEntry;
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) Meta(org.hl7.fhir.r4.model.Meta) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Period(org.hl7.fhir.r4.model.Period) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Extension(org.hl7.fhir.r4.model.Extension) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Procedure(org.mitre.synthea.world.concepts.HealthRecord.Procedure) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) CodeType(org.hl7.fhir.r4.model.CodeType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 82 with CodeType

use of org.hl7.fhir.r4.model.CodeType in project synthea by synthetichealth.

the class FhirR4 method encounter.

/**
 * Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
 *
 * @param personEntry Entry for the Person
 * @param bundle      The Bundle to add to
 * @param encounter   The current Encounter
 * @return The added Entry
 */
private static BundleEntryComponent encounter(Person person, BundleEntryComponent personEntry, Bundle bundle, Encounter encounter) {
    org.hl7.fhir.r4.model.Encounter encounterResource = new org.hl7.fhir.r4.model.Encounter();
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-encounter");
        encounterResource.setMeta(meta);
    } else if (USE_SHR_EXTENSIONS) {
        encounterResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-encounter-EncounterPerformed"));
        Extension performedContext = new Extension();
        performedContext.setUrl(SHR_EXT + "shr-action-PerformedContext-extension");
        performedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("finished"));
        encounterResource.addExtension(performedContext);
    }
    Patient patient = (Patient) personEntry.getResource();
    encounterResource.setSubject(new Reference().setReference(personEntry.getFullUrl()).setDisplay(patient.getNameFirstRep().getNameAsSingleString()));
    encounterResource.setStatus(EncounterStatus.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));
    }
    Coding classCode = new Coding();
    classCode.setCode(EncounterType.fromString(encounter.type).code());
    classCode.setSystem("http://terminology.hl7.org/CodeSystem/v3-ActCode");
    encounterResource.setClass_(classCode);
    encounterResource.setPeriod(new Period().setStart(new Date(encounter.start)).setEnd(new Date(encounter.stop)));
    if (encounter.reason != null) {
        encounterResource.addReasonCode().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 Reference(ExportHelper.buildFhirSearchUrl("Organization", provider.getResourceID())));
    } else {
        String providerFullUrl = findProviderUrl(provider, bundle);
        if (providerFullUrl != null) {
            encounterResource.setServiceProvider(new Reference(providerFullUrl));
        } else {
            BundleEntryComponent providerOrganization = provider(person, bundle, provider);
            encounterResource.setServiceProvider(new Reference(providerOrganization.getFullUrl()));
        }
    }
    encounterResource.getServiceProvider().setDisplay(provider.name);
    if (USE_US_CORE_IG) {
        String referenceUrl;
        String display;
        if (TRANSACTION_BUNDLE) {
            if (encounter.type.equals(EncounterType.VIRTUAL.toString())) {
                referenceUrl = ExportHelper.buildFhirSearchUrl("Location", FhirR4PatientHome.getPatientHome().getId());
                display = "Patient's Home";
            } else {
                referenceUrl = ExportHelper.buildFhirSearchUrl("Location", provider.getResourceLocationID());
                display = provider.name;
            }
        } else {
            if (encounter.type.equals(EncounterType.VIRTUAL.toString())) {
                referenceUrl = addPatientHomeLocation(bundle);
                display = "Patient's Home";
            } else {
                referenceUrl = findLocationUrl(provider, bundle);
                display = provider.name;
            }
        }
        encounterResource.addLocation().setLocation(new Reference().setReference(referenceUrl).setDisplay(display));
    }
    if (encounter.clinician != null) {
        if (TRANSACTION_BUNDLE) {
            encounterResource.addParticipant().setIndividual(new Reference(ExportHelper.buildFhirNpiSearchUrl(encounter.clinician)));
        } else {
            String practitionerFullUrl = findPractitioner(encounter.clinician, bundle);
            if (practitionerFullUrl != null) {
                encounterResource.addParticipant().setIndividual(new Reference(practitionerFullUrl));
            } else {
                BundleEntryComponent practitioner = practitioner(person, bundle, encounter.clinician);
                encounterResource.addParticipant().setIndividual(new Reference(practitioner.getFullUrl()));
            }
        }
        encounterResource.getParticipantFirstRep().getIndividual().setDisplay(encounter.clinician.getFullname());
        encounterResource.getParticipantFirstRep().addType(mapCodeToCodeableConcept(new Code("http://terminology.hl7.org/CodeSystem/v3-ParticipationType", "PPRF", "primary performer"), null));
        encounterResource.getParticipantFirstRep().setPeriod(encounterResource.getPeriod());
    }
    if (encounter.discharge != null) {
        EncounterHospitalizationComponent hospitalization = new EncounterHospitalizationComponent();
        Code dischargeDisposition = new Code(DISCHARGE_URI, encounter.discharge.code, encounter.discharge.display);
        hospitalization.setDischargeDisposition(mapCodeToCodeableConcept(dischargeDisposition, DISCHARGE_URI));
        encounterResource.setHospitalization(hospitalization);
    }
    BundleEntryComponent entry = newEntry(person, bundle, encounterResource);
    if (USE_US_CORE_IG) {
        // US Core Encounters should have an identifier to support the required
        // Encounter.identifier search parameter
        encounterResource.addIdentifier().setUse(IdentifierUse.OFFICIAL).setSystem(SYNTHEA_IDENTIFIER).setValue(encounterResource.getId());
    }
    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) Patient(org.hl7.fhir.r4.model.Patient) Period(org.hl7.fhir.r4.model.Period) EncounterHospitalizationComponent(org.hl7.fhir.r4.model.Encounter.EncounterHospitalizationComponent) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Provider(org.mitre.synthea.world.agents.Provider) Extension(org.hl7.fhir.r4.model.Extension) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) CodeType(org.hl7.fhir.r4.model.CodeType)

Example 83 with CodeType

use of org.hl7.fhir.r4.model.CodeType in project synthea by synthetichealth.

the class FhirR4 method medicationRequest.

/**
 * Map the given Medication to a FHIR MedicationRequest resource, and add it to the given Bundle.
 *
 * @param person         The person being prescribed medication
 * @param personEntry    The Entry for the Person
 * @param bundle         Bundle to add the Medication to
 * @param encounterEntry Current Encounter entry
 * @param medication     The Medication
 * @return The added Entry
 */
private static BundleEntryComponent medicationRequest(Person person, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Medication medication) {
    MedicationRequest medicationResource = new MedicationRequest();
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-medicationrequest");
        medicationResource.setMeta(meta);
    } else if (USE_SHR_EXTENSIONS) {
        medicationResource.addExtension().setUrl(SHR_EXT + "shr-base-ActionCode-extension").setValue(PRESCRIPTION_OF_DRUG_CC);
        medicationResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-medication-MedicationRequested"));
        Extension requestedContext = new Extension();
        requestedContext.setUrl(SHR_EXT + "shr-action-RequestedContext-extension");
        requestedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("completed"));
        requestedContext.addExtension(SHR_EXT + "shr-action-RequestIntent-extension", new CodeType("original-order"));
        medicationResource.addExtension(requestedContext);
    }
    medicationResource.setSubject(new Reference(personEntry.getFullUrl()));
    medicationResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
    Code code = medication.codes.get(0);
    String system = code.system.equals("SNOMED-CT") ? SNOMED_URI : RXNORM_URI;
    medicationResource.setMedication(mapCodeToCodeableConcept(code, system));
    if (USE_US_CORE_IG && medication.administration) {
        // Occasionally, rather than use medication codes, we want to use a Medication
        // Resource. We only want to do this when we use US Core, to make sure we
        // sometimes produce a resource for the us-core-medication profile, and the
        // 'administration' flag is an arbitrary way to decide without flipping a coin.
        org.hl7.fhir.r4.model.Medication drugResource = new org.hl7.fhir.r4.model.Medication();
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-medication");
        drugResource.setMeta(meta);
        drugResource.setCode(mapCodeToCodeableConcept(code, system));
        drugResource.setStatus(MedicationStatus.ACTIVE);
        BundleEntryComponent drugEntry = newEntry(person, bundle, drugResource);
        medicationResource.setMedication(new Reference(drugEntry.getFullUrl()));
    }
    medicationResource.setAuthoredOn(new Date(medication.start));
    medicationResource.setIntent(MedicationRequestIntent.ORDER);
    org.hl7.fhir.r4.model.Encounter encounter = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
    medicationResource.setRequester(encounter.getParticipantFirstRep().getIndividual());
    if (medication.stop != 0L) {
        medicationResource.setStatus(MedicationRequestStatus.STOPPED);
    } else {
        medicationResource.setStatus(MedicationRequestStatus.ACTIVE);
    }
    if (!medication.reasons.isEmpty()) {
        // Only one element in list
        Code reason = medication.reasons.get(0);
        for (BundleEntryComponent entry : bundle.getEntry()) {
            if (entry.getResource().fhirType().equals("Condition")) {
                Condition condition = (Condition) entry.getResource();
                // Only one element in list
                Coding coding = condition.getCode().getCoding().get(0);
                if (reason.code.equals(coding.getCode())) {
                    medicationResource.addReasonReference().setReference(entry.getFullUrl());
                }
            }
        }
    }
    if (medication.prescriptionDetails != null) {
        JsonObject rxInfo = medication.prescriptionDetails;
        Dosage dosage = new Dosage();
        dosage.setSequence(1);
        // as_needed is true if present
        dosage.setAsNeeded(new BooleanType(rxInfo.has("as_needed")));
        if (rxInfo.has("as_needed")) {
            dosage.setText("Take as needed.");
        }
        // as_needed is false
        if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
            Timing timing = new Timing();
            TimingRepeatComponent timingRepeatComponent = new TimingRepeatComponent();
            timingRepeatComponent.setFrequency(rxInfo.get("dosage").getAsJsonObject().get("frequency").getAsInt());
            timingRepeatComponent.setPeriod(rxInfo.get("dosage").getAsJsonObject().get("period").getAsDouble());
            timingRepeatComponent.setPeriodUnit(convertUcumCode(rxInfo.get("dosage").getAsJsonObject().get("unit").getAsString()));
            timing.setRepeat(timingRepeatComponent);
            dosage.setTiming(timing);
            Quantity dose = new SimpleQuantity().setValue(rxInfo.get("dosage").getAsJsonObject().get("amount").getAsDouble());
            DosageDoseAndRateComponent dosageDetails = new DosageDoseAndRateComponent();
            dosageDetails.setType(new CodeableConcept().addCoding(new Coding().setCode(DoseRateType.ORDERED.toCode()).setSystem(DoseRateType.ORDERED.getSystem()).setDisplay(DoseRateType.ORDERED.getDisplay())));
            dosageDetails.setDose(dose);
            List<DosageDoseAndRateComponent> details = new ArrayList<DosageDoseAndRateComponent>();
            details.add(dosageDetails);
            dosage.setDoseAndRate(details);
            if (rxInfo.has("instructions")) {
                String text = "";
                for (JsonElement instructionElement : rxInfo.get("instructions").getAsJsonArray()) {
                    JsonObject instruction = instructionElement.getAsJsonObject();
                    Code instructionCode = new Code(SNOMED_URI, instruction.get("code").getAsString(), instruction.get("display").getAsString());
                    text += instructionCode.display + "\n";
                    dosage.addAdditionalInstruction(mapCodeToCodeableConcept(instructionCode, SNOMED_URI));
                }
                dosage.setText(text);
            }
        }
        List<Dosage> dosageInstruction = new ArrayList<Dosage>();
        dosageInstruction.add(dosage);
        medicationResource.setDosageInstruction(dosageInstruction);
    }
    BundleEntryComponent medicationEntry = newEntry(person, bundle, medicationResource);
    // create new claim for medication
    medicationClaim(person, personEntry, bundle, encounterEntry, medication.claim, medicationEntry);
    // Create new administration for medication, if needed
    if (medication.administration) {
        medicationAdministration(person, personEntry, bundle, encounterEntry, medication, medicationResource);
    }
    return medicationEntry;
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) DosageDoseAndRateComponent(org.hl7.fhir.r4.model.Dosage.DosageDoseAndRateComponent) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Dosage(org.hl7.fhir.r4.model.Dosage) Coding(org.hl7.fhir.r4.model.Coding) Medication(org.mitre.synthea.world.concepts.HealthRecord.Medication) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) TimingRepeatComponent(org.hl7.fhir.r4.model.Timing.TimingRepeatComponent) Condition(org.hl7.fhir.r4.model.Condition) MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) BooleanType(org.hl7.fhir.r4.model.BooleanType) SimpleQuantity(org.hl7.fhir.r4.model.SimpleQuantity) SimpleQuantity(org.hl7.fhir.r4.model.SimpleQuantity) Quantity(org.hl7.fhir.r4.model.Quantity) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Extension(org.hl7.fhir.r4.model.Extension) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) JsonElement(com.google.gson.JsonElement) CodeType(org.hl7.fhir.r4.model.CodeType) Timing(org.hl7.fhir.r4.model.Timing) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 84 with CodeType

use of org.hl7.fhir.r4.model.CodeType in project synthea by synthetichealth.

the class FhirR4 method immunization.

private static BundleEntryComponent immunization(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, HealthRecord.Entry immunization) {
    Immunization immResource = new Immunization();
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-immunization");
        immResource.setMeta(meta);
    } else if (USE_SHR_EXTENSIONS) {
        immResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-immunization-ImmunizationGiven"));
        Extension performedContext = new Extension();
        performedContext.setUrl(SHR_EXT + "shr-action-PerformedContext-extension");
        performedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("completed"));
        immResource.addExtension(performedContext);
    }
    immResource.setStatus(ImmunizationStatus.COMPLETED);
    immResource.setOccurrence(convertFhirDateTime(immunization.start, true));
    immResource.setVaccineCode(mapCodeToCodeableConcept(immunization.codes.get(0), CVX_URI));
    immResource.setPrimarySource(true);
    immResource.setPatient(new Reference(personEntry.getFullUrl()));
    immResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
    if (USE_US_CORE_IG) {
        org.hl7.fhir.r4.model.Encounter encounterResource = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
        immResource.setLocation(encounterResource.getLocationFirstRep().getLocation());
    }
    BundleEntryComponent immunizationEntry = newEntry(rand, bundle, immResource);
    immunization.fullUrl = immunizationEntry.getFullUrl();
    return immunizationEntry;
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) Immunization(org.hl7.fhir.r4.model.Immunization) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Extension(org.hl7.fhir.r4.model.Extension) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) CodeType(org.hl7.fhir.r4.model.CodeType) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter)

Example 85 with CodeType

use of org.hl7.fhir.r4.model.CodeType in project synthea by synthetichealth.

the class FhirStu3 method encounter.

/**
 * Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
 *
 * @param personEntry Entry for the Person
 * @param bundle The Bundle to add to
 * @param encounter The current Encounter
 * @return The added Entry
 */
private static BundleEntryComponent encounter(Person person, BundleEntryComponent personEntry, Bundle bundle, Encounter encounter) {
    org.hl7.fhir.dstu3.model.Encounter encounterResource = new org.hl7.fhir.dstu3.model.Encounter();
    encounterResource.setSubject(new Reference(personEntry.getFullUrl()));
    encounterResource.setStatus(EncounterStatus.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));
    }
    Coding classCode = new Coding();
    classCode.setCode(EncounterType.fromString(encounter.type).code());
    classCode.setSystem("http://terminology.hl7.org/CodeSystem/v3-ActCode");
    encounterResource.setClass_(classCode);
    encounterResource.setPeriod(new Period().setStart(new Date(encounter.start)).setEnd(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 Reference(ExportHelper.buildFhirSearchUrl("Organization", provider.getResourceID())));
    } else {
        String providerFullUrl = findProviderUrl(provider, bundle);
        if (providerFullUrl != null) {
            encounterResource.setServiceProvider(new Reference(providerFullUrl));
        } else {
            BundleEntryComponent providerOrganization = provider(bundle, provider);
            encounterResource.setServiceProvider(new Reference(providerOrganization.getFullUrl()));
        }
    }
    encounterResource.getServiceProvider().setDisplay(provider.name);
    if (encounter.clinician != null) {
        if (TRANSACTION_BUNDLE) {
            encounterResource.addParticipant().setIndividual(new Reference(ExportHelper.buildFhirNpiSearchUrl(encounter.clinician)));
        } else {
            String practitionerFullUrl = findPractitioner(encounter.clinician, bundle);
            if (practitionerFullUrl != null) {
                encounterResource.addParticipant().setIndividual(new Reference(practitionerFullUrl));
            } else {
                BundleEntryComponent practitioner = practitioner(bundle, encounter.clinician);
                encounterResource.addParticipant().setIndividual(new Reference(practitioner.getFullUrl()));
            }
        }
        encounterResource.getParticipantFirstRep().getIndividual().setDisplay(encounter.clinician.getFullname());
    }
    if (encounter.discharge != null) {
        EncounterHospitalizationComponent hospitalization = new EncounterHospitalizationComponent();
        Code dischargeDisposition = new Code(DISCHARGE_URI, encounter.discharge.code, encounter.discharge.display);
        hospitalization.setDischargeDisposition(mapCodeToCodeableConcept(dischargeDisposition, DISCHARGE_URI));
        encounterResource.setHospitalization(hospitalization);
    }
    if (USE_SHR_EXTENSIONS) {
        encounterResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-encounter-EncounterPerformed"));
        // required fields for this profile are status & action-PerformedContext-extension
        Extension performedContext = new Extension();
        performedContext.setUrl(SHR_EXT + "shr-action-PerformedContext-extension");
        performedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("finished"));
        encounterResource.addExtension(performedContext);
    }
    return newEntry(person, bundle, encounterResource);
}
Also used : Meta(org.hl7.fhir.dstu3.model.Meta) Reference(org.hl7.fhir.dstu3.model.Reference) Period(org.hl7.fhir.dstu3.model.Period) EncounterHospitalizationComponent(org.hl7.fhir.dstu3.model.Encounter.EncounterHospitalizationComponent) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Provider(org.mitre.synthea.world.agents.Provider) Extension(org.hl7.fhir.dstu3.model.Extension) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.dstu3.model.Coding) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) CodeType(org.hl7.fhir.dstu3.model.CodeType)

Aggregations

CodeType (org.hl7.fhir.r5.model.CodeType)52 ArrayList (java.util.ArrayList)31 CodeType (org.hl7.fhir.r4.model.CodeType)28 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)20 FHIRException (org.hl7.fhir.exceptions.FHIRException)18 CodeType (org.hl7.fhir.r4b.model.CodeType)17 Date (java.util.Date)15 CodeType (org.hl7.fhir.dstu3.model.CodeType)15 NotImplementedException (org.apache.commons.lang3.NotImplementedException)12 File (java.io.File)11 Extension (org.hl7.fhir.dstu3.model.Extension)10 XmlParser (org.hl7.fhir.r5.formats.XmlParser)10 StringType (org.hl7.fhir.r5.model.StringType)10 ValueSet (org.hl7.fhir.r5.model.ValueSet)10 Coding (org.hl7.fhir.r4.model.Coding)9 Coding (org.hl7.fhir.dstu3.model.Coding)8 FileOutputStream (java.io.FileOutputStream)7 List (java.util.List)7 Parameters (org.hl7.fhir.r4.model.Parameters)7 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)7