use of org.hl7.fhir.r4.model.AllergyIntolerance 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 org.hl7.fhir.r4.model.AllergyIntolerance in project openmrs-module-fhir2 by openmrs.
the class AllergyIntoleranceSearchQueryTest method searchForAllergies_shouldSearchForAllergiesByPatientGivenName.
@Test
public void searchForAllergies_shouldSearchForAllergiesByPatientGivenName() {
ReferenceAndListParam referenceParam = new ReferenceAndListParam();
ReferenceParam allergyParam = new ReferenceParam();
allergyParam.setValue(PATIENT_GIVEN_NAME);
allergyParam.setChain(Patient.SP_GIVEN);
referenceParam.addValue(new ReferenceOrListParam().add(allergyParam));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, referenceParam);
IBundleProvider results = search(theParams);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
assertThat(((AllergyIntolerance) resultList.iterator().next()).getIdElement().getIdPart(), equalTo(ALLERGY_UUID));
}
use of org.hl7.fhir.r4.model.AllergyIntolerance 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 org.hl7.fhir.r4.model.AllergyIntolerance in project openmrs-module-fhir2 by openmrs.
the class AllergyIntoleranceSearchQueryTest method searchForAllergies_shouldSearchForAllergiesByPatientFamilyNameAndGivenName.
@Test
public void searchForAllergies_shouldSearchForAllergiesByPatientFamilyNameAndGivenName() {
ReferenceAndListParam referenceParam = new ReferenceAndListParam();
ReferenceParam allergyParamName = new ReferenceParam();
ReferenceParam allergyParamGiven = new ReferenceParam();
allergyParamName.setValue(PATIENT_FAMILY_NAME);
allergyParamName.setChain(Patient.SP_FAMILY);
allergyParamGiven.setValue(PATIENT_GIVEN_NAME);
allergyParamGiven.setChain(Patient.SP_GIVEN);
referenceParam.addValue(new ReferenceOrListParam().add(allergyParamName)).addAnd(new ReferenceOrListParam().add(allergyParamGiven));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, referenceParam);
IBundleProvider results = search(theParams);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
assertThat(((AllergyIntolerance) resultList.iterator().next()).getIdElement().getIdPart(), equalTo(ALLERGY_UUID));
}
use of org.hl7.fhir.r4.model.AllergyIntolerance 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