Search in sources :

Example 21 with TokenAndListParam

use of ca.uhn.fhir.rest.param.TokenAndListParam in project openmrs-module-fhir2 by openmrs.

the class AllergyIntoleranceSearchQueryTest method searchForAllergies_shouldSearchForAllergiesByCategoryEnvironment.

@Test
public void searchForAllergies_shouldSearchForAllergiesByCategoryEnvironment() {
    TokenAndListParam category = new TokenAndListParam();
    category.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(CATEGORY_ENVIRONMENT)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CATEGORY_SEARCH_HANDLER, category);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(((AllergyIntolerance) resultList.iterator().next()).getCategory().get(0).getValue(), equalTo(AllergyIntolerance.AllergyIntoleranceCategory.ENVIRONMENT));
}
Also used : TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) 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) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 22 with TokenAndListParam

use of ca.uhn.fhir.rest.param.TokenAndListParam in project openmrs-module-fhir2 by openmrs.

the class AllergyIntoleranceSearchQueryTest method searchForAllergies_shouldReturnEmptyListByMismatchingUuidAndLastUpdated.

@Test
public void searchForAllergies_shouldReturnEmptyListByMismatchingUuidAndLastUpdated() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(ALLERGY_UUID));
    DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(DATE_VOIDED).setLowerBound(DATE_VOIDED);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, empty());
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) 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) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 23 with TokenAndListParam

use of ca.uhn.fhir.rest.param.TokenAndListParam in project openmrs-module-fhir2 by openmrs.

the class AllergyIntoleranceSearchQueryTest method searchForAllergies_shouldSearchForAllergiesByMatchingUuidAndLastUpdated.

@Test
public void searchForAllergies_shouldSearchForAllergiesByMatchingUuidAndLastUpdated() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(ALLERGY_UUID));
    DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(DATE_CREATED).setLowerBound(DATE_CREATED);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
    assertThat(((AllergyIntolerance) resultList.iterator().next()).getIdElement().getIdPart(), equalTo(ALLERGY_UUID));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) 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) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 24 with TokenAndListParam

use of ca.uhn.fhir.rest.param.TokenAndListParam in project openmrs-module-fhir2 by openmrs.

the class AllergyIntoleranceSearchQueryTest method searchForAllergies_shouldAddNotNullPatientToReturnedResults.

@Test
public void searchForAllergies_shouldAddNotNullPatientToReturnedResults() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(ALLERGY_UUID));
    HashSet<Include> includes = new HashSet<>();
    includes.add(new Include("AllergyIntolerance:patient"));
    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));
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    // included resource added as part of the result list
    assertThat(resultList.size(), equalTo(2));
    AllergyIntolerance returnedAllergy = (AllergyIntolerance) resultList.iterator().next();
    assertThat(resultList, hasItem(allOf(is(instanceOf(Patient.class)), hasProperty("id", equalTo(returnedAllergy.getPatient().getReferenceElement().getIdPart())))));
}
Also used : AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) 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 25 with TokenAndListParam

use of ca.uhn.fhir.rest.param.TokenAndListParam in project openmrs-module-fhir2 by openmrs.

the class AllergyIntoleranceSearchQueryTest method searchForAllergies_shouldSearchForMultipleAllergiesByCategory.

@Test
public void searchForAllergies_shouldSearchForMultipleAllergiesByCategory() {
    TokenAndListParam category = new TokenAndListParam();
    category.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(CATEGORY_FOOD)).addOr(new TokenParam().setValue(CATEGORY_MEDICATION)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CATEGORY_SEARCH_HANDLER, category);
    IBundleProvider results = search(theParams);
    List<AllergyIntolerance> resultList = get(results).stream().map(p -> (AllergyIntolerance) p).collect(Collectors.toList());
    assertThat(results, notNullValue());
    assertThat(resultList.size(), equalTo(2));
    assertThat(resultList, hasItem(hasProperty("category", hasItem(hasProperty("value", equalTo(AllergyIntolerance.AllergyIntoleranceCategory.FOOD))))));
    assertThat(resultList, hasItem(hasProperty("category", hasItem(hasProperty("value", equalTo(AllergyIntolerance.AllergyIntoleranceCategory.MEDICATION))))));
}
Also used : AllergyIntoleranceTranslator(org.openmrs.module.fhir2.api.translators.AllergyIntoleranceTranslator) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Matchers.not(org.hamcrest.Matchers.not) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) Allergy(org.openmrs.Allergy) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) HashSet(java.util.HashSet) FhirGlobalPropertyService(org.openmrs.module.fhir2.api.FhirGlobalPropertyService) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Map(java.util.Map) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) FhirConstants(org.openmrs.module.fhir2.FhirConstants) Patient(org.hl7.fhir.r4.model.Patient) Before(org.junit.Before) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) FhirAllergyIntoleranceDao(org.openmrs.module.fhir2.api.dao.FhirAllergyIntoleranceDao) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) SortOrderEnum(ca.uhn.fhir.rest.api.SortOrderEnum) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Matchers.allOf(org.hamcrest.Matchers.allOf) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) TestFhirSpringConfiguration(org.openmrs.module.fhir2.TestFhirSpringConfiguration) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) Collectors(java.util.stream.Collectors) Include(ca.uhn.fhir.model.api.Include) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) SortSpec(ca.uhn.fhir.rest.api.SortSpec) ContextConfiguration(org.springframework.test.context.ContextConfiguration) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) Matchers.is(org.hamcrest.Matchers.is) Matchers.endsWith(org.hamcrest.Matchers.endsWith) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) TokenParam(ca.uhn.fhir.rest.param.TokenParam) 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

TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)357 Test (org.junit.Test)347 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)340 TokenParam (ca.uhn.fhir.rest.param.TokenParam)312 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)260 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)247 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)211 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)119 HashSet (java.util.HashSet)79 Include (ca.uhn.fhir.model.api.Include)77 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)48 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)48 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)46 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)46 NumberParam (ca.uhn.fhir.rest.param.NumberParam)36 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)36 Observation (org.hl7.fhir.r4.model.Observation)24 StringParam (ca.uhn.fhir.rest.param.StringParam)21 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)21 ServiceRequest (org.hl7.fhir.r4.model.ServiceRequest)19