Search in sources :

Example 16 with Dosage

use of org.hl7.fhir.r5.model.Dosage in project nia-patient-switching-standard-adaptor by NHSDigital.

the class MedicationMapperUtils method buildDosage.

public static Dosage buildDosage(List<RCMRMT030101UK04PertinentInformation> pertinentInformationList) {
    Dosage dosage = new Dosage();
    var pertinentInformationDosage = pertinentInformationList.stream().filter(RCMRMT030101UK04PertinentInformation::hasPertinentMedicationDosage).map(RCMRMT030101UK04PertinentInformation::getPertinentMedicationDosage).filter(RCMRMT030101UK04MedicationDosage::hasText).map(RCMRMT030101UK04MedicationDosage::getText).findFirst();
    pertinentInformationDosage.ifPresentOrElse(dosage::setText, () -> dosage.setText(NO_INFORMATION_AVAILABLE));
    return dosage;
}
Also used : RCMRMT030101UK04PertinentInformation(org.hl7.v3.RCMRMT030101UK04PertinentInformation) RCMRMT030101UK04MedicationDosage(org.hl7.v3.RCMRMT030101UK04MedicationDosage) Dosage(org.hl7.fhir.dstu3.model.Dosage) RCMRMT030101UK04MedicationDosage(org.hl7.v3.RCMRMT030101UK04MedicationDosage)

Example 17 with Dosage

use of org.hl7.fhir.r5.model.Dosage in project gpconnect-demonstrator by nhsconnect.

the class MedicationRequestResourceProvider method getMedicationRequestFromDetail.

private MedicationRequest getMedicationRequestFromDetail(MedicationRequestDetail requestDetail) {
    MedicationRequest medicationRequest = new MedicationRequest();
    medicationRequest.setId(requestDetail.getId().toString());
    List<Identifier> identifiers = new ArrayList<>();
    Identifier identifier = new Identifier().setSystem("https://fhir.nhs.uk/Id/cross-care-setting-identifier").setValue(requestDetail.getGuid());
    identifiers.add(identifier);
    medicationRequest.setIdentifier(identifiers);
    medicationRequest.setMeta(new Meta().addProfile(SystemURL.SD_GPC_MEDICATION_REQUEST));
    setBasedOnReferences(medicationRequest, requestDetail);
    if (requestDetail.getPrescriptionTypeCode().contains("repeat")) {
        medicationRequest.setGroupIdentifier(new Identifier().setValue(requestDetail.getGroupIdentifier()));
    }
    try {
        medicationRequest.setStatus(MedicationRequestStatus.fromCode(requestDetail.getStatusCode()));
    } catch (FHIRException e) {
        throw new UnprocessableEntityException(e.getMessage());
    }
    try {
        medicationRequest.setIntent(MedicationRequestIntent.fromCode(requestDetail.getIntentCode()));
    } catch (FHIRException e) {
        throw new UnprocessableEntityException(e.getMessage());
    }
    if (requestDetail.getMedicationId() != null) {
        medicationRequest.setMedication(new Reference(new IdType("Medication", requestDetail.getMedicationId())));
    }
    if (requestDetail.getPatientId() != null) {
        medicationRequest.setSubject(new Reference(new IdType("Patient", requestDetail.getPatientId())));
    }
    if (requestDetail.getAuthorisingPractitionerId() != null) {
        medicationRequest.setRecorder(new Reference(new IdType("Practitioner", requestDetail.getAuthorisingPractitionerId())));
    }
    if (requestDetail.getPriorMedicationRequestId() != null) {
        medicationRequest.setPriorPrescription(new Reference(new IdType("MedicationRequest", requestDetail.getPriorMedicationRequestId())));
    }
    medicationRequest.setAuthoredOn(requestDetail.getAuthoredOn());
    medicationRequest.setDispenseRequest(getDispenseRequestComponent(requestDetail));
    // medicationRequest.setRequester(getRequesterComponent(requestDetail)); //TODO - spec needs to clarify whether this should be populated or not
    setReasonCodes(medicationRequest, requestDetail);
    setNotes(medicationRequest, requestDetail);
    if (medicationRequest.getIntent() != MedicationRequestIntent.ORDER) {
        setRepeatInformation(medicationRequest, requestDetail);
    }
    setPrescriptionType(medicationRequest, requestDetail);
    setStatusReason(medicationRequest, requestDetail);
    String dosageInstructionText = requestDetail.getDosageText();
    medicationRequest.addDosageInstruction(new Dosage().setText(dosageInstructionText == null || dosageInstructionText.trim().isEmpty() ? NO_INFORMATION_AVAILABLE : dosageInstructionText).setPatientInstruction(requestDetail.getDosageInstructions()));
    return medicationRequest;
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) ArrayList(java.util.ArrayList) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 18 with Dosage

use of org.hl7.fhir.r5.model.Dosage in project bunsen by cerner.

the class TestData method newMedicationRequest.

/**
 * Returns a new MedicationRequest for testing.
 *
 * @return a FHIR MedicationRequest for testing.
 */
public static MedicationRequest newMedicationRequest() {
    MedicationRequest medicationRequest = new MedicationRequest();
    medicationRequest.setId("test-medication-request");
    CodeableConcept itemCodeableConcept = new CodeableConcept();
    itemCodeableConcept.addCoding().setSystem("http://www.nlm.nih.gov/research/umls/rxnorm").setCode("103109").setDisplay("Vitamin E 3 MG Oral Tablet [Ephynal]").setUserSelected(true);
    medicationRequest.setMedication(itemCodeableConcept);
    medicationRequest.setSubject(new Reference("Patient/12345").setDisplay("Here is a display for you."));
    medicationRequest.setDosageInstruction(ImmutableList.of(new Dosage().setTiming(new Timing().setRepeat(new TimingRepeatComponent().setCount(10)))));
    medicationRequest.setSubstitution(new MedicationRequestSubstitutionComponent().setAllowed(true));
    return medicationRequest;
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) MedicationRequestSubstitutionComponent(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestSubstitutionComponent) Reference(org.hl7.fhir.dstu3.model.Reference) TimingRepeatComponent(org.hl7.fhir.dstu3.model.Timing.TimingRepeatComponent) Timing(org.hl7.fhir.dstu3.model.Timing) Dosage(org.hl7.fhir.dstu3.model.Dosage) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 19 with Dosage

use of org.hl7.fhir.r5.model.Dosage in project synthea by synthetichealth.

the class FhirR4 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
 * @param medicationRequest The related medicationRequest
 * @return The added Entry
 */
private static BundleEntryComponent medicationAdministration(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Medication medication, MedicationRequest medicationRequest) {
    MedicationAdministration medicationResource = new MedicationAdministration();
    medicationResource.setSubject(new Reference(personEntry.getFullUrl()));
    medicationResource.setContext(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));
    medicationResource.setEffective(new DateTimeType(new Date(medication.start)));
    medicationResource.setStatus(MedicationAdministration.MedicationAdministrationStatus.COMPLETED);
    if (medication.prescriptionDetails != null) {
        JsonObject rxInfo = medication.prescriptionDetails;
        MedicationAdministrationDosageComponent dosage = new MedicationAdministrationDosageComponent();
        // as_needed is false
        if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
            Quantity dose = new SimpleQuantity().setValue(rxInfo.get("dosage").getAsJsonObject().get("amount").getAsDouble());
            dosage.setDose((SimpleQuantity) dose);
            if (rxInfo.has("instructions")) {
                for (JsonElement instructionElement : rxInfo.get("instructions").getAsJsonArray()) {
                    JsonObject instruction = instructionElement.getAsJsonObject();
                    dosage.setText(instruction.get("display").getAsString());
                }
            }
        }
        if (rxInfo.has("refills")) {
            SimpleQuantity rate = new SimpleQuantity();
            rate.setValue(rxInfo.get("refills").getAsLong());
            dosage.setRate(rate);
        }
        medicationResource.setDosage(dosage);
    }
    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());
                }
            }
        }
    }
    BundleEntryComponent medicationAdminEntry = newEntry(rand, bundle, medicationResource);
    return medicationAdminEntry;
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) SimpleQuantity(org.hl7.fhir.r4.model.SimpleQuantity) JsonObject(com.google.gson.JsonObject) 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) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) MedicationAdministrationDosageComponent(org.hl7.fhir.r4.model.MedicationAdministration.MedicationAdministrationDosageComponent) Coding(org.hl7.fhir.r4.model.Coding) JsonElement(com.google.gson.JsonElement) MedicationAdministration(org.hl7.fhir.r4.model.MedicationAdministration)

Example 20 with Dosage

use of org.hl7.fhir.r5.model.Dosage in project gpconnect-demonstrator by nhsconnect.

the class MedicationStatementResourceProvider method getMedicationStatementResource.

public MedicationStatement getMedicationStatementResource(MedicationStatementDetail statementDetail) {
    MedicationStatement medicationStatement = new MedicationStatement();
    medicationStatement.setId(statementDetail.getId().toString());
    List<Identifier> identifiers = new ArrayList<>();
    Identifier identifier = new Identifier().setSystem("https://fhir.nhs.uk/Id/cross-care-setting-identifier").setValue(statementDetail.getGuid());
    identifiers.add(identifier);
    medicationStatement.setIdentifier(identifiers);
    medicationStatement.setMeta(new Meta().addProfile(SystemURL.SD_GPC_MEDICATION_STATEMENT));
    medicationStatement.addExtension(new Extension(SystemURL.SD_CC_EXT_MEDICATION_STATEMENT_LAST_ISSUE, new DateTimeType(statementDetail.getLastIssueDate(), TemporalPrecisionEnum.DAY)));
    if (statementDetail.getMedicationRequestPlanId() != null) {
        medicationStatement.addBasedOn(new Reference(new IdType("MedicationRequest", statementDetail.getMedicationRequestPlanId())));
    }
    try {
        medicationStatement.setStatus(MedicationStatementStatus.fromCode(statementDetail.getStatusCode()));
    } catch (FHIRException e) {
        throw new UnprocessableEntityException(e.getMessage());
    }
    if (statementDetail.getMedicationId() != null) {
        medicationStatement.setMedication(new Reference(new IdType("Medication", statementDetail.getMedicationId())));
    }
    medicationStatement.setEffective(new Period().setStart(statementDetail.getStartDate()).setEnd(statementDetail.getEndDate()));
    medicationStatement.setDateAsserted(statementDetail.getDateAsserted());
    if (statementDetail.getPatientId() != null)
        medicationStatement.setSubject(new Reference(new IdType("Patient", statementDetail.getPatientId())));
    try {
        medicationStatement.setTaken(statementDetail.getTakenCode() != null ? MedicationStatementTaken.fromCode(statementDetail.getTakenCode()) : MedicationStatementTaken.UNK);
    } catch (FHIRException e) {
        throw new UnprocessableEntityException(e.getMessage());
    }
    setReasonCodes(medicationStatement, statementDetail);
    setNotes(medicationStatement, statementDetail);
    String dosageText = statementDetail.getDosageText();
    medicationStatement.addDosage(new Dosage().setText(dosageText == null || dosageText.trim().isEmpty() ? NO_INFORMATION_AVAILABLE : dosageText).setPatientInstruction(statementDetail.getDosagePatientInstruction()));
    String prescribingAgency = statementDetail.getPrescribingAgency();
    if (prescribingAgency != null && !prescribingAgency.trim().isEmpty()) {
        String prescribingAgencyDisplay = "";
        if (prescribingAgency.equalsIgnoreCase("prescribed-at-gp-practice")) {
            prescribingAgencyDisplay = "Prescribed at GP practice";
        } else if (prescribingAgency.equalsIgnoreCase("prescribed-by-another-organisation")) {
            prescribingAgencyDisplay = "Prescribed by another organisation";
        }
        Coding coding = new Coding(SystemURL.CS_CC_PRESCRIBING_AGENCY_STU3, prescribingAgency, prescribingAgencyDisplay);
        CodeableConcept codeableConcept = new CodeableConcept().addCoding(coding);
        medicationStatement.addExtension(new Extension(SystemURL.SD_EXTENSION_CC_PRESCRIBING_AGENCY, codeableConcept));
    }
    // #281 1.2.5 add dosageLastChanged
    Date dosageLastChanged = statementDetail.getDosageLastChanged();
    if (dosageLastChanged != null) {
        medicationStatement.addExtension(new Extension(SystemURL.SD_EXTENSION_CC_DOSAGE_LAST_CHANGED, new DateTimeType(dosageLastChanged)));
    }
    return medicationStatement;
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) ArrayList(java.util.ArrayList) FHIRException(org.hl7.fhir.exceptions.FHIRException) Date(java.util.Date)

Aggregations

Dosage (org.hl7.fhir.r4.model.Dosage)8 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)8 Date (java.util.Date)6 ArrayList (java.util.ArrayList)5 Reference (org.hl7.fhir.dstu3.model.Reference)5 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)5 Test (org.junit.Test)5 JsonElement (com.google.gson.JsonElement)4 JsonObject (com.google.gson.JsonObject)4 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)4 Dosage (org.hl7.fhir.dstu3.model.Dosage)4 Coding (org.hl7.fhir.r4.model.Coding)4 Quantity (org.hl7.fhir.r4.model.Quantity)4 NotImplementedException (org.apache.commons.lang3.NotImplementedException)3 Coding (org.hl7.fhir.dstu3.model.Coding)3 Quantity (org.hl7.fhir.dstu3.model.Quantity)3 Timing (org.hl7.fhir.dstu3.model.Timing)3 BooleanType (org.hl7.fhir.r4.model.BooleanType)3 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)3 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)3