Search in sources :

Example 81 with MedicationRequest

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

the class MedicationRequestFhirResourceProviderTest method deleteMedicationRequest_shouldDeleteMedicationRequest.

@Test
public void deleteMedicationRequest_shouldDeleteMedicationRequest() {
    when(fhirMedicationRequestService.delete(MEDICATION_REQUEST_UUID)).thenReturn(medicationRequest);
    OperationOutcome result = resourceProvider.deleteMedicationRequest(new IdType().setValue(MEDICATION_REQUEST_UUID));
    assertThat(result, notNullValue());
    assertThat(result.getIssue(), notNullValue());
    assertThat(result.getIssueFirstRep().getSeverity(), equalTo(OperationOutcome.IssueSeverity.INFORMATION));
    assertThat(result.getIssueFirstRep().getDetails().getCodingFirstRep().getCode(), equalTo("MSG_DELETED"));
}
Also used : OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.Test)

Example 82 with MedicationRequest

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

the class MedicationRequestFhirResourceProviderTest method searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenUUIDIsSpecified.

@Test
public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenUUIDIsSpecified() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(MEDICATION_REQUEST_UUID));
    when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
    IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null, null, uuid, 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) TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) Test(org.junit.Test)

Example 83 with MedicationRequest

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

the class MedicationRequestFhirResourceProviderTest method searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenLastUpdatedIsSpecified.

@Test
public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenLastUpdatedIsSpecified() {
    DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(LAST_UPDATED_DATE).setLowerBound(LAST_UPDATED_DATE);
    when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
    IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null, null, null, lastUpdated, null);
    List<IBaseResource> resources = results.getResources(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 : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Test(org.junit.Test)

Example 84 with MedicationRequest

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

the class MedicationRequestFhirResourceProviderTest method searchMedicationRequest_shouldNotAddRelatedMedicationsForEmptyInclude.

@Test
public void searchMedicationRequest_shouldNotAddRelatedMedicationsForEmptyInclude() {
    HashSet<Include> includes = new HashSet<>();
    when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
    IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null, null, null, null, includes);
    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) Include(ca.uhn.fhir.model.api.Include) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 85 with MedicationRequest

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

the class MedicationRequestFhirResourceProviderTest method getMedicationRequestByUuid_shouldThrowResourceNotFoundException.

@Test(expected = ResourceNotFoundException.class)
public void getMedicationRequestByUuid_shouldThrowResourceNotFoundException() {
    IdType id = new IdType();
    id.setValue(WRONG_MEDICATION_REQUEST_UUID);
    MedicationRequest medicationRequest = resourceProvider.getMedicationRequestById(id);
    assertThat(medicationRequest, nullValue());
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.Test)

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