Search in sources :

Example 1 with MedicationDispense

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;
}
Also used : Coding(org.hl7.fhir.dstu3.model.Coding) MedicationDispense(org.hl7.fhir.dstu3.model.MedicationDispense) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) Medication(org.hl7.fhir.dstu3.model.Medication) MedicationDispenseDetail(uk.gov.hscic.model.medication.MedicationDispenseDetail) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) MedicationDispenseSearch(uk.gov.hscic.medication.dispense.MedicationDispenseSearch) Search(ca.uhn.fhir.rest.annotation.Search)

Aggregations

Search (ca.uhn.fhir.rest.annotation.Search)1 ArrayList (java.util.ArrayList)1 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)1 Coding (org.hl7.fhir.dstu3.model.Coding)1 Medication (org.hl7.fhir.dstu3.model.Medication)1 MedicationDispense (org.hl7.fhir.dstu3.model.MedicationDispense)1 Reference (org.hl7.fhir.dstu3.model.Reference)1 MedicationDispenseSearch (uk.gov.hscic.medication.dispense.MedicationDispenseSearch)1 MedicationDispenseDetail (uk.gov.hscic.model.medication.MedicationDispenseDetail)1