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));
}
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());
}
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));
}
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())))));
}
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))))));
}
Aggregations