Search in sources :

Example 26 with Person

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

the class PersonSearchQueryTest method shouldReturnEmptyCollectionForNoMatchOnGender.

@Test
public void shouldReturnEmptyCollectionForNoMatchOnGender() {
    TokenAndListParam gender = new TokenAndListParam().addAnd(new TokenOrListParam().add(WRONG_GENDER));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.GENDER_SEARCH_HANDLER, gender);
    IBundleProvider people = search(theParams);
    List<Person> resultList = get(people);
    assertThat(people, notNullValue());
    assertThat(resultList, is(empty()));
}
Also used : TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) Person(org.hl7.fhir.r4.model.Person) 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 27 with Person

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

the class PersonSearchQueryTest method shouldReturnCollectionOfPeopleForMatchOnState.

@Test
public void shouldReturnCollectionOfPeopleForMatchOnState() {
    StringAndListParam state = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(STATE)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.STATE_PROPERTY, state);
    IBundleProvider people = search(theParams);
    assertThat(people, notNullValue());
    assertThat(people.size(), greaterThanOrEqualTo(1));
    List<Person> resultList = get(people);
    assertThat(resultList, not(empty()));
    assertThat(resultList.get(0).getAddressFirstRep().getState(), equalTo(STATE));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) Person(org.hl7.fhir.r4.model.Person) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 28 with Person

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

the class PersonSearchQueryTest method shouldReturnCollectionOfPeopleForMatchOnCountry.

@Test
public void shouldReturnCollectionOfPeopleForMatchOnCountry() {
    StringAndListParam country = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(COUNTRY)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.COUNTRY_PROPERTY, country);
    IBundleProvider people = search(theParams);
    assertThat(people, notNullValue());
    assertThat(people.size(), greaterThanOrEqualTo(1));
    List<Person> resultList = get(people);
    assertThat(resultList, not(empty()));
    assertThat(resultList.get(0).getAddressFirstRep().getCountry(), equalTo(COUNTRY));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) Person(org.hl7.fhir.r4.model.Person) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 29 with Person

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

the class PersonSearchQueryTest method shouldReturnCollectionOfPeopleSortedByCountry.

@Test
public void shouldReturnCollectionOfPeopleSortedByCountry() throws Exception {
    executeDataSet(ADDRESS_SEARCH_FILE);
    SortSpec sort = new SortSpec();
    sort.setParamName(SP_ADDRESS_COUNTRY);
    sort.setOrder(SortOrderEnum.ASC);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.COUNTRY_PROPERTY, new StringAndListParam().addAnd(new StringParam("F"))).setSortSpec(sort);
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), greaterThan(1));
    List<Person> people = get(results);
    assertThat(people, hasSize(greaterThan(1)));
    for (int i = 1; i < people.size(); i++) {
        assertThat(people.get(i - 1).getAddressFirstRep().getCountry(), lessThanOrEqualTo(people.get(i).getAddressFirstRep().getCountry()));
    }
    sort.setOrder(SortOrderEnum.DESC);
    theParams.setSortSpec(sort);
    results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), greaterThan(1));
    people = get(results);
    assertThat(people, hasSize(greaterThan(1)));
    for (int i = 1; i < people.size(); i++) {
        assertThat(people.get(i - 1).getAddressFirstRep().getCountry(), greaterThanOrEqualTo(people.get(i).getAddressFirstRep().getCountry()));
    }
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) Person(org.hl7.fhir.r4.model.Person) SortSpec(ca.uhn.fhir.rest.api.SortSpec) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 30 with Person

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

the class PersonSearchQueryTest method shouldReturnCollectionOfPeopleSortedByBirthDate.

@Test
public void shouldReturnCollectionOfPeopleSortedByBirthDate() {
    SortSpec sort = new SortSpec();
    sort.setParamName(SP_BIRTHDATE);
    sort.setOrder(SortOrderEnum.ASC);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "birthdate", new DateRangeParam().setLowerBound("1900-01-01").setUpperBoundInclusive(new Date())).setSortSpec(sort);
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), greaterThan(1));
    List<Person> people = get(results);
    assertThat(people, hasSize(greaterThan(1)));
    for (int i = 1; i < people.size(); i++) {
        assertThat(people.get(i - 1).getBirthDate(), sameOrBefore(people.get(i).getBirthDate()));
    }
    sort.setOrder(SortOrderEnum.DESC);
    theParams.setSortSpec(sort);
    results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), greaterThan(1));
    people = get(results);
    assertThat(people, hasSize(greaterThan(1)));
    for (int i = 1; i < people.size(); i++) {
        assertThat(people.get(i - 1).getBirthDate(), sameOrAfter(people.get(i).getBirthDate()));
    }
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) Person(org.hl7.fhir.r4.model.Person) SortSpec(ca.uhn.fhir.rest.api.SortSpec) Date(java.util.Date) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)181 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)54 Date (java.util.Date)50 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)48 Person (org.hl7.fhir.r4.model.Person)47 Person (model.Person)44 Person (com.google.api.services.people.v1.model.Person)38 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)37 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)32 Reference (org.hl7.fhir.r4.model.Reference)31 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)30 StringParam (ca.uhn.fhir.rest.param.StringParam)30 VCard (ezvcard.VCard)30 Person (org.openmrs.Person)29 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)23 List (java.util.List)22 Collectors (java.util.stream.Collectors)22 Person (org.hl7.fhir.dstu3.model.Person)22 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)22 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)21