Search in sources :

Example 76 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_IDENTIFIER)));
    IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null, medicationParam, 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 77 with MedicationRequest

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

the class MedicationRequestFhirResourceProviderTest method createMedicationRequest_shouldCreateMedicationRequest.

@Test
public void createMedicationRequest_shouldCreateMedicationRequest() {
    when(fhirMedicationRequestService.create(any(org.hl7.fhir.r4.model.MedicationRequest.class))).thenReturn(medicationRequest);
    MethodOutcome result = resourceProvider.createMedicationRequest(MedicationRequest30_40.convertMedicationRequest(medicationRequest));
    assertThat(result, notNullValue());
    assertThat(result.getCreated(), is(true));
    assertThat(result.getResource().getIdElement().getIdPart(), equalTo(medicationRequest.getId()));
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) Test(org.junit.Test)

Example 78 with MedicationRequest

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

the class MedicationRequestFhirResourceProviderTest method searchMedicationRequest_shouldReturnMatchingMedicationRequestUsingCode.

@Test
public void searchMedicationRequest_shouldReturnMatchingMedicationRequestUsingCode() {
    when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
    TokenAndListParam code = new TokenAndListParam();
    TokenParam codingToken = new TokenParam();
    codingToken.setValue("1000");
    code.addAnd(codingToken);
    IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, code, null, null, 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) 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 79 with MedicationRequest

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

the class MedicationRequestFhirResourceProviderTest method getMedicationRequestByUuid_shouldReturnMatchingMedicationRequest.

@Test
public void getMedicationRequestByUuid_shouldReturnMatchingMedicationRequest() {
    when(fhirMedicationRequestService.get(MEDICATION_REQUEST_UUID)).thenReturn(medicationRequest);
    IdType id = new IdType();
    id.setValue(MEDICATION_REQUEST_UUID);
    MedicationRequest medicationRequest = resourceProvider.getMedicationRequestById(id);
    assertThat(medicationRequest, notNullValue());
    assertThat(medicationRequest.getId(), notNullValue());
    assertThat(medicationRequest.getId(), equalTo(MEDICATION_REQUEST_UUID));
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.Test)

Example 80 with MedicationRequest

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

the class MedicationRequestFhirResourceProviderTest method searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenEncounterParamIsSpecified.

@Test
public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenEncounterParamIsSpecified() {
    when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
    ReferenceAndListParam encounterParam = new ReferenceAndListParam();
    encounterParam.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Encounter.SP_IDENTIFIER)));
    IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, encounterParam, null, null, null, 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)

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