Search in sources :

Example 86 with MedicationRequest

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

the class MedicationRequestFhirResourceProviderTest method searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenMedicationParamIsSpecified.

@Test
public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenMedicationParamIsSpecified() {
    when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
    ReferenceAndListParam medicationParam = new ReferenceAndListParam();
    medicationParam.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Medication.SP_RES_ID)));
    IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null, medicationParam, null, null, null);
    List<MedicationRequest> resources = get(results, 1, 5);
    assertThat(results, notNullValue());
    assertThat(resources, hasSize(equalTo(1)));
    assertThat(resources.get(0), notNullValue());
    assertThat(resources.get(0).fhirType(), equalTo(FhirConstants.MEDICATION_REQUEST));
    assertThat(resources.get(0).getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID));
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) Test(org.junit.Test)

Example 87 with MedicationRequest

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

the class MedicationRequestFhirResourceProviderTest method updateMedicationRequest_shouldUpdateMedicationRequest.

@Test
public void updateMedicationRequest_shouldUpdateMedicationRequest() {
    when(fhirMedicationRequestService.update(eq(MEDICATION_REQUEST_UUID), any(org.hl7.fhir.r4.model.MedicationRequest.class))).thenReturn(medicationRequest);
    MethodOutcome result = resourceProvider.updateMedicationRequest(new IdType().setValue(MEDICATION_REQUEST_UUID), MedicationRequest30_40.convertMedicationRequest(medicationRequest));
    assertThat(result, notNullValue());
    assertThat(result.getResource(), notNullValue());
    assertThat(result.getResource().getIdElement().getIdPart(), equalTo(medicationRequest.getId()));
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.Test)

Example 88 with MedicationRequest

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

the class MedicationRequestTranslatorImpl method toFhirResource.

@Override
public MedicationRequest toFhirResource(@Nonnull DrugOrder drugOrder) {
    notNull(drugOrder, "The DrugOrder object should not be null");
    MedicationRequest medicationRequest = new MedicationRequest();
    medicationRequest.setId(drugOrder.getUuid());
    medicationRequest.setStatus(statusTranslator.toFhirResource(drugOrder));
    medicationRequest.setMedication(medicationReferenceTranslator.toFhirResource(drugOrder.getDrug()));
    medicationRequest.setPriority(medicationRequestPriorityTranslator.toFhirResource(drugOrder.getUrgency()));
    medicationRequest.setRequester(practitionerReferenceTranslator.toFhirResource(drugOrder.getOrderer()));
    medicationRequest.setEncounter(encounterReferenceTranslator.toFhirResource(drugOrder.getEncounter()));
    medicationRequest.setSubject(patientReferenceTranslator.toFhirResource(drugOrder.getPatient()));
    medicationRequest.setIntent(MedicationRequest.MedicationRequestIntent.ORDER);
    medicationRequest.addNote(new Annotation().setText(drugOrder.getCommentToFulfiller()));
    medicationRequest.addReasonCode(conceptTranslator.toFhirResource(drugOrder.getOrderReason()));
    medicationRequest.addDosageInstruction(dosageTranslator.toFhirResource(drugOrder));
    if (drugOrder.getPreviousOrder() != null && (drugOrder.getAction() == Order.Action.DISCONTINUE || drugOrder.getAction() == Order.Action.REVISE)) {
        medicationRequest.setPriorPrescription(createOrderReference(drugOrder.getPreviousOrder()).setIdentifier(orderIdentifierTranslator.toFhirResource(drugOrder.getPreviousOrder())));
    } else if (drugOrder.getPreviousOrder() != null && drugOrder.getAction() == Order.Action.RENEW) {
        medicationRequest.setBasedOn(Collections.singletonList(createOrderReference(drugOrder.getPreviousOrder()).setIdentifier(orderIdentifierTranslator.toFhirResource(drugOrder.getPreviousOrder()))));
    }
    return medicationRequest;
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) Annotation(org.hl7.fhir.r4.model.Annotation)

Example 89 with MedicationRequest

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

the class MedicationRequestFhirResourceProviderWebTest method verifyUri.

private void verifyUri(String uri) throws Exception {
    MedicationRequest medicationRequest = new MedicationRequest();
    medicationRequest.setId(MEDICATION_REQUEST_UUID);
    when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
    MockHttpServletResponse response = get(uri).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
    Bundle results = readBundleResponse(response);
    assertThat(results.getEntry(), notNullValue());
    assertThat(results.getEntry(), not(empty()));
    assertThat(results.getEntry().get(0).getResource(), notNullValue());
    assertThat(results.getEntry().get(0).getResource().getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID));
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) Bundle(org.hl7.fhir.dstu3.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 90 with MedicationRequest

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

the class MedicationRequestFhirResourceProviderWebTest method verifyUri.

private void verifyUri(String uri) throws Exception {
    when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
    MockHttpServletResponse response = get(uri).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
    Bundle results = readBundleResponse(response);
    assertThat(results.getEntry(), notNullValue());
    assertThat(results.getEntry(), not(empty()));
    assertThat(results.getEntry().get(0).getResource(), notNullValue());
    assertThat(results.getEntry().get(0).getResource().getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID));
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

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