Search in sources :

Example 71 with MedicationRequest

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

the class MedicationRequestFhirResourceProviderTest method searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenParticipantParamIsSpecified.

@Test
public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenParticipantParamIsSpecified() {
    when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
    ReferenceAndListParam participantParam = new ReferenceAndListParam();
    participantParam.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Practitioner.SP_NAME)));
    IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, participantParam, null, null, null, null);
    List<IBaseResource> resources = getResources(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 : ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) Test(org.junit.Test)

Example 72 with MedicationRequest

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

the class MedicationRequestFhirResourceProviderTest method deleteTask_shouldDeleteMedicationRequest.

@Test
public void deleteTask_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.r4.model.OperationOutcome) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 73 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(MedicationRequest.class))).thenReturn(medicationRequest);
    MethodOutcome result = resourceProvider.updateMedicationRequest(new IdType().setValue(MEDICATION_REQUEST_UUID), medicationRequest);
    assertThat(result, notNullValue());
    assertThat(result.getResource(), notNullValue());
    assertThat(result.getResource().getIdElement().getIdPart(), equalTo(medicationRequest.getId()));
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 74 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<IBaseResource> resources = getResources(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 : TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) Test(org.junit.Test)

Example 75 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<IBaseResource> resources = getResources(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 : Include(ca.uhn.fhir.model.api.Include) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) HashSet(java.util.HashSet) 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