Search in sources :

Example 1 with IPrescription

use of ch.elexis.core.model.IPrescription in project elexis-server by elexis.

the class MedicationRequestResourceProvider method findMedicationsByPatient.

@Search()
public List<MedicationRequest> findMedicationsByPatient(@RequiredParam(name = MedicationRequest.SP_PATIENT) IdType thePatientId) {
    if (thePatientId != null && !thePatientId.isEmpty()) {
        Optional<IPatient> patient = modelService.load(thePatientId.getIdPart(), IPatient.class);
        if (patient.isPresent()) {
            if (patient.get().isPatient()) {
                IQuery<IPrescription> query = modelService.getQuery(IPrescription.class);
                query.and(ModelPackage.Literals.IPRESCRIPTION__PATIENT, COMPARATOR.EQUALS, patient.get());
                // TODO
                // qbe.add(Prescription_.rezeptID, JPAQuery.QUERY.EQUALS, null);
                List<IPrescription> prescriptions = query.execute();
                if (prescriptions != null && !prescriptions.isEmpty()) {
                    List<MedicationRequest> ret = new ArrayList<MedicationRequest>();
                    for (IPrescription prescription : prescriptions) {
                        Optional<MedicationRequest> fhirMedicationOrder = getTransformer().getFhirObject(prescription);
                        fhirMedicationOrder.ifPresent(fmo -> ret.add(fmo));
                    }
                    return ret;
                }
            }
        }
    }
    return null;
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) IPrescription(ch.elexis.core.model.IPrescription) ArrayList(java.util.ArrayList) IPatient(ch.elexis.core.model.IPatient) Search(ca.uhn.fhir.rest.annotation.Search)

Example 2 with IPrescription

use of ch.elexis.core.model.IPrescription in project elexis-server by elexis.

the class MedicationRequestResourceProvider method updateMedicationOrder.

@Update
public MethodOutcome updateMedicationOrder(@ResourceParam MedicationRequest updateOrder) {
    Optional<IPrescription> localObject = getTransformer().getLocalObject(updateOrder);
    MethodOutcome outcome = new MethodOutcome();
    outcome.setCreated(false);
    if (localObject.isPresent()) {
        try {
            Optional<IPrescription> updated = getTransformer().updateLocalObject(updateOrder, localObject.get());
            updated.ifPresent(prescription -> {
                outcome.setCreated(true);
                outcome.setId(new IdType(prescription.getId()));
            });
        } catch (RuntimeException e) {
            OperationOutcome issueOutcome = new OperationOutcome();
            issueOutcome.addIssue().setDiagnostics("Update failed. " + e.getMessage());
            outcome.setOperationOutcome(issueOutcome);
        }
    } else {
        OperationOutcome issueOutcome = new OperationOutcome();
        issueOutcome.addIssue().setDiagnostics("No local object found");
        outcome.setOperationOutcome(issueOutcome);
    }
    return outcome;
}
Also used : IPrescription(ch.elexis.core.model.IPrescription) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) IdType(org.hl7.fhir.r4.model.IdType) Update(ca.uhn.fhir.rest.annotation.Update)

Aggregations

IPrescription (ch.elexis.core.model.IPrescription)2 Search (ca.uhn.fhir.rest.annotation.Search)1 Update (ca.uhn.fhir.rest.annotation.Update)1 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)1 IPatient (ch.elexis.core.model.IPatient)1 ArrayList (java.util.ArrayList)1 IdType (org.hl7.fhir.r4.model.IdType)1 MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)1 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)1