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;
}
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;
}
Aggregations