use of org.hl7.fhir.dstu3.model.MedicationDispense in project gpconnect-demonstrator by nhsconnect.
the class MedicationDispenseResourceProvider method getMedicationDispensesForPatientId.
@Search
public List<MedicationDispense> getMedicationDispensesForPatientId(@RequiredParam(name = "patient") String patientId) {
ArrayList<MedicationDispense> medicationDispenses = new ArrayList<>();
List<MedicationDispenseDetail> medicationDispenseDetailList = medicationDispenseSearch.findMedicationDispenseForPatient(Long.parseLong(patientId));
if (medicationDispenseDetailList != null && !medicationDispenseDetailList.isEmpty()) {
for (MedicationDispenseDetail medicationDispenseDetail : medicationDispenseDetailList) {
MedicationDispense medicationDispense = new MedicationDispense();
medicationDispense.setId(String.valueOf(medicationDispenseDetail.getId()));
medicationDispense.getMeta().setLastUpdated(medicationDispenseDetail.getLastUpdated());
medicationDispense.getMeta().setVersionId(String.valueOf(medicationDispenseDetail.getLastUpdated().getTime()));
switch(medicationDispenseDetail.getStatus().toLowerCase(Locale.UK)) {
case "completed":
medicationDispense.setStatus(MedicationDispenseStatus.COMPLETED);
break;
case "entered_in_error":
medicationDispense.setStatus(MedicationDispenseStatus.ENTEREDINERROR);
break;
case "in_progress":
medicationDispense.setStatus(MedicationDispenseStatus.INPROGRESS);
break;
case "on_hold":
medicationDispense.setStatus(MedicationDispenseStatus.ONHOLD);
break;
case "stopped":
medicationDispense.setStatus(MedicationDispenseStatus.STOPPED);
break;
}
medicationDispense.setSubject(new Reference("Patient/" + patientId));
medicationDispense.setAuthorizingPrescription(Collections.singletonList(new Reference("MedicationOrder/" + medicationDispenseDetail.getMedicationOrderId())));
Medication medication = new Medication();
Coding coding = new Coding();
coding.setCode(String.valueOf(medicationDispenseDetail.getMedicationId()));
coding.setDisplay(medicationDispenseDetail.getMedicationName());
CodeableConcept codeableConcept = new CodeableConcept();
codeableConcept.setCoding(Collections.singletonList(coding));
medication.setCode(codeableConcept);
medicationDispense.addDosageInstruction().setText(medicationDispenseDetail.getDosageText());
medicationDispenses.add(medicationDispense);
}
}
return medicationDispenses;
}
Aggregations