Search in sources :

Example 61 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.

the class MedicationRequestTranslatorImplTest method toOpenMrsType_shouldTranslateRequesterToOpenMrsType.

@Test
public void toOpenMrsType_shouldTranslateRequesterToOpenMrsType() {
    Provider provider = new Provider();
    provider.setUuid(PRACTITIONER_UUID);
    Reference requesterReference = new Reference();
    requesterReference.setReference(FhirConstants.PRACTITIONER + "/" + PRACTITIONER_UUID);
    medicationRequest.setRequester(requesterReference);
    when(providerPractitionerReferenceTranslator.toOpenmrsType(requesterReference)).thenReturn(provider);
    DrugOrder result = medicationRequestTranslator.toOpenmrsType(new DrugOrder(), medicationRequest);
    assertThat(result, notNullValue());
    assertThat(result.getOrderer(), notNullValue());
    assertThat(result.getOrderer().getUuid(), equalTo(PRACTITIONER_UUID));
}
Also used : DrugOrder(org.openmrs.DrugOrder) Reference(org.hl7.fhir.r4.model.Reference) Provider(org.openmrs.Provider) Test(org.junit.Test)

Example 62 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.

the class MedicationRequestTranslatorImplTest method toFhirResource_shouldConvertActiveStatusToFhirType.

@Test
public void toFhirResource_shouldConvertActiveStatusToFhirType() {
    when(medicationRequestStatusTranslator.toFhirResource(drugOrder)).thenReturn(MedicationRequest.MedicationRequestStatus.ACTIVE);
    MedicationRequest result = medicationRequestTranslator.toFhirResource(drugOrder);
    assertThat(result, notNullValue());
    assertThat(result.getStatus(), notNullValue());
    assertThat(result.getStatus(), equalTo(MedicationRequest.MedicationRequestStatus.ACTIVE));
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) Test(org.junit.Test)

Example 63 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.

the class MedicationRequestTranslatorImplTest method toFhirResource_shouldTranslateDrugToMedicationReference.

@Test
public void toFhirResource_shouldTranslateDrugToMedicationReference() {
    Drug drug = new Drug();
    drug.setUuid(DRUG_UUID);
    drugOrder.setDrug(drug);
    Reference medicationRef = new Reference();
    medicationRef.setReference(FhirConstants.MEDICATION_REQUEST + "/" + DRUG_UUID);
    when(medicationReferenceTranslator.toFhirResource(drug)).thenReturn(medicationRef);
    MedicationRequest result = medicationRequestTranslator.toFhirResource(drugOrder);
    assertThat(result, notNullValue());
    assertThat(result.getMedication(), notNullValue());
    assertThat(result.getMedication(), equalTo(medicationRef));
}
Also used : Drug(org.openmrs.Drug) MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) Reference(org.hl7.fhir.r4.model.Reference) Test(org.junit.Test)

Example 64 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.

the class MedicationRequestTranslatorImplTest method toFhirResource_shouldTranslatePatientToFhirType.

@Test
public void toFhirResource_shouldTranslatePatientToFhirType() {
    Patient patient = new Patient();
    patient.setUuid(PATIENT_UUID);
    drugOrder.setPatient(patient);
    Reference patientReference = new Reference();
    patientReference.setReference(FhirConstants.PATIENT + "/" + PATIENT_UUID);
    when(patientReferenceTranslator.toFhirResource(patient)).thenReturn(patientReference);
    MedicationRequest result = medicationRequestTranslator.toFhirResource(drugOrder);
    assertThat(result, notNullValue());
    assertThat(result.getSubject(), notNullValue());
    assertThat(result.getSubject().getReference(), equalTo(patientReference.getReference()));
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) Reference(org.hl7.fhir.r4.model.Reference) Patient(org.openmrs.Patient) Test(org.junit.Test)

Example 65 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest 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)

Aggregations

MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)128 Test (org.junit.Test)128 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)78 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)58 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)48 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)44 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)44 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)44 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)36 Test (org.junit.jupiter.api.Test)35 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)33 Resource (org.hl7.fhir.r4.model.Resource)31 MedicationRequest (org.hl7.fhir.dstu3.model.MedicationRequest)26 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)23 TokenParam (ca.uhn.fhir.rest.param.TokenParam)23 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)23 ArrayList (java.util.ArrayList)19 Include (ca.uhn.fhir.model.api.Include)15 HashSet (java.util.HashSet)15