Search in sources :

Example 1 with MedicationRequestDispenseRequestComponent

use of org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestDispenseRequestComponent in project gpconnect-demonstrator by nhsconnect.

the class MedicationOrderResourceProvider method medicationOrderDetailsToMedicationOrderResourceConverter.

private MedicationRequest medicationOrderDetailsToMedicationOrderResourceConverter(MedicationOrderDetails medicationOrderDetails) {
    MedicationRequest medicationOrder = new MedicationRequest();
    String resourceId = String.valueOf(medicationOrderDetails.getId());
    String versionId = String.valueOf(medicationOrderDetails.getLastUpdated().getTime());
    String resourceType = medicationOrder.getResourceType().toString();
    IdType id = new IdType(resourceType, resourceId, versionId);
    medicationOrder.setId(id);
    medicationOrder.getMeta().setVersionId(versionId);
    medicationOrder.getMeta().setLastUpdated(medicationOrderDetails.getLastUpdated());
    switch(medicationOrderDetails.getOrderStatus().toLowerCase(Locale.UK)) {
        case "active":
            medicationOrder.setStatus(MedicationRequestStatus.ACTIVE);
            break;
        case "completed":
            medicationOrder.setStatus(MedicationRequestStatus.COMPLETED);
            break;
        case "draft":
            medicationOrder.setStatus(MedicationRequestStatus.DRAFT);
            break;
        case "entered_in_error":
            medicationOrder.setStatus(MedicationRequestStatus.ENTEREDINERROR);
            break;
        case "on_hold":
            medicationOrder.setStatus(MedicationRequestStatus.ONHOLD);
            break;
        case "stopped":
            medicationOrder.setStatus(MedicationRequestStatus.STOPPED);
            break;
    }
    if (medicationOrderDetails.getPatientId() != null) {
        medicationOrder.setSubject(new Reference("Patient/" + medicationOrderDetails.getPatientId()));
    } else {
        medicationOrder.setSubject(new Reference());
    }
    medicationOrder.setRecorder(new Reference("Practitioner/" + medicationOrderDetails.getAutherId()));
    medicationOrder.setMedication(new Reference("Medication/" + medicationOrderDetails.getMedicationId()));
    medicationOrder.addDosageInstruction().setText(medicationOrderDetails.getDosageText());
    MedicationRequestDispenseRequestComponent dispenseRequest = new MedicationRequestDispenseRequestComponent();
    dispenseRequest.addExtension(new Extension(SystemURL.SD_EXTENSION_MEDICATION_QUANTITY_TEXT, new StringDt(medicationOrderDetails.getDispenseQuantityText())));
    dispenseRequest.addExtension(new Extension(SystemURL.SD_EXTENSION_PERSCRIPTION_REPEAT_REVIEW_DATE, new DateTimeDt(medicationOrderDetails.getDispenseReviewDate())));
    dispenseRequest.setId("Medication/" + medicationOrderDetails.getDispenseMedicationId());
    dispenseRequest.setNumberOfRepeatsAllowed(medicationOrderDetails.getDispenseRepeatsAllowed());
    medicationOrder.setDispenseRequest(dispenseRequest);
    return medicationOrder;
}
Also used : DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) MedicationRequestDispenseRequestComponent(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestDispenseRequestComponent) StringDt(ca.uhn.fhir.model.primitive.StringDt)

Example 2 with MedicationRequestDispenseRequestComponent

use of org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestDispenseRequestComponent in project gpconnect-demonstrator by nhsconnect.

the class MedicationRequestResourceProvider method getDispenseRequestComponent.

private MedicationRequestDispenseRequestComponent getDispenseRequestComponent(MedicationRequestDetail requestDetail) {
    MedicationRequestDispenseRequestComponent dispenseRequest = new MedicationRequestDispenseRequestComponent();
    Period period = new Period().setStart(requestDetail.getDispenseRequestStartDate());
    if (requestDetail.getDispenseRequestEndDate() != null) {
        period.setEnd(requestDetail.getDispenseRequestEndDate());
    }
    dispenseRequest.setValidityPeriod(period);
    setDispenseQuantity(dispenseRequest, requestDetail);
    Duration duration = new Duration();
    duration.setSystem(SystemURL.CS_UNITS_OF_MEASURE);
    duration.setCode("d");
    duration.setValue(requestDetail.getExpectedSupplyDuration());
    duration.setUnit("day");
    // TODO - spec needs to clarify whether this should be populated or not
    dispenseRequest.setExpectedSupplyDuration(duration);
    dispenseRequest.setPerformer(new Reference(new IdType("Organization", requestDetail.getDispenseRequestOrganizationId())));
    return dispenseRequest;
}
Also used : MedicationRequestDispenseRequestComponent(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestDispenseRequestComponent)

Aggregations

MedicationRequestDispenseRequestComponent (org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestDispenseRequestComponent)2 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)1 StringDt (ca.uhn.fhir.model.primitive.StringDt)1