Search in sources :

Example 11 with Medication

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

the class FhirMedicationServiceImplTest method searchForMedications_shouldSearchMedicationsByUUID.

@Test
public void searchForMedications_shouldSearchMedicationsByUUID() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(MEDICATION_UUID));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid);
    when(medicationDao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(MEDICATION_UUID));
    when(medicationDao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(drug));
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, medicationDao, medicationTranslator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(medicationTranslator.toFhirResource(drug)).thenReturn(medication);
    IBundleProvider result = fhirMedicationService.searchForMedications(null, null, null, uuid, null, null);
    List<IBaseResource> resultList = get(result);
    assertThat(result, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
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) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 12 with Medication

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

the class MedicationRequestSearchQueryTest method searchForMedicationRequests_shouldHandleMultipleIncludes.

@Test
public void searchForMedicationRequests_shouldHandleMultipleIncludes() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(MEDICATION_REQUEST_UUID));
    HashSet<Include> includes = new HashSet<>();
    includes.add(new Include("MedicationRequest:medication"));
    includes.add(new Include("MedicationRequest:requester"));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
    IBundleProvider results = search(theParams);
    assertThat(results.size(), equalTo(1));
    assertThat(results, notNullValue());
    List<IBaseResource> resultList = results.getResources(0, 10);
    assertThat(resultList, not(empty()));
    // included resources (medication + requester) added as part of the result list
    assertThat(resultList.size(), equalTo(3));
    assertThat(((MedicationRequest) resultList.iterator().next()).getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID));
    MedicationRequest returnedMedicationRequest = (MedicationRequest) resultList.iterator().next();
    assertThat(resultList, hasItem(allOf(is(instanceOf(Medication.class)), hasProperty("id", equalTo((returnedMedicationRequest.getMedicationReference().getReferenceElement().getIdPart()))))));
    assertThat(resultList, hasItem(allOf(is(instanceOf(Practitioner.class)), hasProperty("id", equalTo(returnedMedicationRequest.getRequester().getReferenceElement().getIdPart())))));
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Include(ca.uhn.fhir.model.api.Include) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 13 with Medication

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

the class MedicationSearchQueryTest method searchForMedications_shouldHandleComplexQuery.

@Test
public void searchForMedications_shouldHandleComplexQuery() {
    TokenAndListParam code = new TokenAndListParam();
    code.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(CONCEPT_UUID)));
    TokenAndListParam dosageForm = new TokenAndListParam();
    dosageForm.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(DOSAGE_FORM_UUID)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CODED_SEARCH_HANDLER, code).addParameter(FhirConstants.DOSAGE_FORM_SEARCH_HANDLER, dosageForm);
    IBundleProvider result = search(theParams);
    assertThat(result, notNullValue());
    assertThat(result.size(), greaterThanOrEqualTo(1));
    List<Medication> resultList = get(result);
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(resultList.get(0).getCode().getCodingFirstRep().getCode(), equalTo(CONCEPT_UUID));
    assertThat(resultList.get(0).getForm().getCodingFirstRep().getCode(), equalTo(DOSAGE_FORM_UUID));
}
Also used : TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Medication(org.hl7.fhir.r4.model.Medication) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 14 with Medication

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

the class MedicationSearchQueryTest method searchForMedications_shouldSearchMedicationsByWrongIngredientCode.

@Test
public void searchForMedications_shouldSearchMedicationsByWrongIngredientCode() {
    TokenAndListParam ingredientCode = new TokenAndListParam();
    ingredientCode.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(WRONG_INGREDIENT_CODE_UUID)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INGREDIENT_SEARCH_HANDLER, ingredientCode);
    IBundleProvider result = search(theParams);
    assertThat(result, notNullValue());
    assertThat(result.size(), equalTo(0));
    List<Medication> resultList = get(result);
    assertThat(resultList, empty());
}
Also used : TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Medication(org.hl7.fhir.r4.model.Medication) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 15 with Medication

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

the class MedicationSearchQueryTest method searchForMedications_shouldSearchMedicationsByWrongCode.

@Test
public void searchForMedications_shouldSearchMedicationsByWrongCode() {
    TokenAndListParam code = new TokenAndListParam();
    code.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(WRONG_CONCEPT_UUID)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CODED_SEARCH_HANDLER, code);
    IBundleProvider result = search(theParams);
    List<Medication> resultList = get(result);
    assertThat(result, notNullValue());
    assertThat(resultList, empty());
}
Also used : TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Medication(org.hl7.fhir.r4.model.Medication) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)112 Medication (org.hl7.fhir.r4.model.Medication)62 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)43 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)34 Medication (org.hl7.fhir.dstu3.model.Medication)33 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)30 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)24 TokenParam (ca.uhn.fhir.rest.param.TokenParam)24 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)20 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)20 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)19 MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)18 InputStream (java.io.InputStream)17 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)16 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)14 Coding (org.hl7.fhir.r4.model.Coding)14 Date (java.util.Date)13 ArrayList (java.util.ArrayList)12 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)12 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)11