Search in sources :

Example 6 with AllergyIntolerance

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));
}
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 7 with AllergyIntolerance

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));
}
Also used : AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) 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) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 8 with AllergyIntolerance

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())))));
}
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 9 with AllergyIntolerance

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));
}
Also used : AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) 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) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 10 with AllergyIntolerance

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

Test (org.junit.Test)158 AllergyIntolerance (org.hl7.fhir.r4.model.AllergyIntolerance)93 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)53 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)53 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)43 AllergyIntolerance (org.hl7.fhir.dstu3.model.AllergyIntolerance)42 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)29 TokenParam (ca.uhn.fhir.rest.param.TokenParam)29 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)26 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)25 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)25 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)23 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)23 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)23 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)21 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)14 InputStream (java.io.InputStream)12 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)12 Date (java.util.Date)10 IdType (org.hl7.fhir.r4.model.IdType)10