From 3928ceea8b89303c2370a7c0dff621aa7c15fdf5 Mon Sep 17 00:00:00 2001 From: herman Date: Fri, 4 Nov 2022 13:06:55 +0300 Subject: [PATCH 1/3] search params for fhir person service --- .../module/fhir2/api/FhirPersonService.java | 13 +- .../fhir2/api/impl/FhirPersonServiceImpl.java | 29 +-- .../api/search/param/PersonSearchParams.java | 72 ++++++ .../r3/PersonFhirResourceProvider.java | 6 +- .../r4/PersonFhirResourceProvider.java | 5 +- .../api/impl/FhirPersonServiceImplTest.java | 85 +++---- .../r3/PersonFhirResourceProviderTest.java | 67 +++--- .../r4/PersonFhirResourceProviderTest.java | 67 +++--- .../r3/PersonFhirResourceProviderWebTest.java | 210 +++++++++--------- .../r4/PersonFhirResourceProviderWebTest.java | 210 +++++++++--------- 10 files changed, 403 insertions(+), 361 deletions(-) create mode 100644 api/src/main/java/org/openmrs/module/fhir2/api/search/param/PersonSearchParams.java diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/FhirPersonService.java b/api/src/main/java/org/openmrs/module/fhir2/api/FhirPersonService.java index e9a7d173e..3a4705f40 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/FhirPersonService.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/FhirPersonService.java @@ -9,20 +9,11 @@ */ package org.openmrs.module.fhir2.api; -import java.util.HashSet; - -import ca.uhn.fhir.model.api.Include; -import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.server.IBundleProvider; -import ca.uhn.fhir.rest.param.DateRangeParam; -import ca.uhn.fhir.rest.param.StringAndListParam; -import ca.uhn.fhir.rest.param.TokenAndListParam; import org.hl7.fhir.r4.model.Person; +import org.openmrs.module.fhir2.api.search.param.PersonSearchParams; public interface FhirPersonService extends FhirService { - IBundleProvider searchForPeople(StringAndListParam name, TokenAndListParam gender, DateRangeParam birthDate, - StringAndListParam city, StringAndListParam state, StringAndListParam postalCode, StringAndListParam country, - TokenAndListParam id, DateRangeParam lastUpdated, SortSpec sort, HashSet includes); - + IBundleProvider searchForPeople(PersonSearchParams personSearchParams); } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirPersonServiceImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirPersonServiceImpl.java index a40b2be76..c0f7238c2 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirPersonServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirPersonServiceImpl.java @@ -9,24 +9,16 @@ */ package org.openmrs.module.fhir2.api.impl; -import java.util.HashSet; - -import ca.uhn.fhir.model.api.Include; -import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.server.IBundleProvider; -import ca.uhn.fhir.rest.param.DateRangeParam; -import ca.uhn.fhir.rest.param.StringAndListParam; -import ca.uhn.fhir.rest.param.TokenAndListParam; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; import org.hl7.fhir.r4.model.Person; -import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.FhirPersonService; import org.openmrs.module.fhir2.api.dao.FhirPersonDao; import org.openmrs.module.fhir2.api.search.SearchQuery; import org.openmrs.module.fhir2.api.search.SearchQueryInclude; -import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; +import org.openmrs.module.fhir2.api.search.param.PersonSearchParams; import org.openmrs.module.fhir2.api.translators.PersonTranslator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -51,23 +43,8 @@ public class FhirPersonServiceImpl extends BaseFhirService> searchQuery; @Override - public IBundleProvider searchForPeople(StringAndListParam name, TokenAndListParam gender, DateRangeParam birthDate, - StringAndListParam city, StringAndListParam state, StringAndListParam postalCode, StringAndListParam country, - TokenAndListParam id, DateRangeParam lastUpdated, SortSpec sort, HashSet includes) { - - SearchParameterMap theParams = new SearchParameterMap() - .addParameter(FhirConstants.NAME_SEARCH_HANDLER, FhirConstants.NAME_PROPERTY, name) - .addParameter(FhirConstants.GENDER_SEARCH_HANDLER, gender) - .addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, birthDate) - .addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.CITY_PROPERTY, city) - .addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.STATE_PROPERTY, state) - .addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.POSTAL_CODE_PROPERTY, postalCode) - .addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.COUNTRY_PROPERTY, country) - .addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, id) - .addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated) - .addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes).setSortSpec(sort); - - return searchQuery.getQueryResults(theParams, dao, translator, searchQueryInclude); + public IBundleProvider searchForPeople(PersonSearchParams personSearchParams) { + return searchQuery.getQueryResults(personSearchParams.toSearchParameterMap(), dao, translator, searchQueryInclude); } @Override diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/search/param/PersonSearchParams.java b/api/src/main/java/org/openmrs/module/fhir2/api/search/param/PersonSearchParams.java new file mode 100644 index 000000000..92fa39885 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/fhir2/api/search/param/PersonSearchParams.java @@ -0,0 +1,72 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.fhir2.api.search.param; + +import java.util.HashSet; + +import ca.uhn.fhir.model.api.Include; +import ca.uhn.fhir.rest.api.SortSpec; +import ca.uhn.fhir.rest.param.DateRangeParam; +import ca.uhn.fhir.rest.param.StringAndListParam; +import ca.uhn.fhir.rest.param.TokenAndListParam; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.openmrs.module.fhir2.FhirConstants; + +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class PersonSearchParams extends BaseResourceSearchParams { + + private StringAndListParam name; + + private TokenAndListParam gender; + + private DateRangeParam birthDate; + + private StringAndListParam city; + + private StringAndListParam state; + + private StringAndListParam postalCode; + + private StringAndListParam country; + + @Builder + public PersonSearchParams(StringAndListParam name, TokenAndListParam gender, DateRangeParam birthDate, + StringAndListParam city, StringAndListParam state, StringAndListParam postalCode, StringAndListParam country, + TokenAndListParam id, DateRangeParam lastUpdated, SortSpec sort, HashSet includes) { + + super(id, lastUpdated, sort, includes, null); + + this.name = name; + this.gender = gender; + this.birthDate = birthDate; + this.city = city; + this.state = state; + this.postalCode = postalCode; + this.country = country; + } + + @Override + public SearchParameterMap toSearchParameterMap() { + return baseSearchParameterMap() + .addParameter(FhirConstants.NAME_SEARCH_HANDLER, FhirConstants.NAME_PROPERTY, getName()) + .addParameter(FhirConstants.GENDER_SEARCH_HANDLER, getGender()) + .addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, getBirthDate()) + .addParameter(FhirConstants.CITY_SEARCH_HANDLER, FhirConstants.CITY_PROPERTY, getCity()) + .addParameter(FhirConstants.STATE_SEARCH_HANDLER, FhirConstants.STATE_PROPERTY, getState()) + .addParameter(FhirConstants.POSTALCODE_SEARCH_HANDLER, FhirConstants.POSTAL_CODE_PROPERTY, getPostalCode()) + .addParameter(FhirConstants.COUNTRY_SEARCH_HANDLER, FhirConstants.COUNTRY_PROPERTY, getCountry()); + } + +} diff --git a/api/src/main/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProvider.java b/api/src/main/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProvider.java index b4da32253..fbd0ab67c 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProvider.java +++ b/api/src/main/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProvider.java @@ -45,6 +45,7 @@ import org.openmrs.module.fhir2.api.FhirPersonService; import org.openmrs.module.fhir2.api.annotations.R3Provider; import org.openmrs.module.fhir2.api.search.SearchQueryBundleProviderR3Wrapper; +import org.openmrs.module.fhir2.api.search.param.PersonSearchParams; import org.openmrs.module.fhir2.providers.util.FhirProviderUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -115,8 +116,9 @@ public IBundleProvider searchPeople(@OptionalParam(name = Person.SP_NAME) String includes = null; } - return new SearchQueryBundleProviderR3Wrapper(personService.searchForPeople(name, gender, birthDate, city, state, - postalCode, country, id, lastUpdated, sort, includes)); + return new SearchQueryBundleProviderR3Wrapper(personService.searchForPeople(new PersonSearchParams(name, gender, + birthDate, city, state, postalCode, country, id, lastUpdated, sort, includes))); + } } diff --git a/api/src/main/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProvider.java b/api/src/main/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProvider.java index 7f9b71a54..11c069e29 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProvider.java +++ b/api/src/main/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProvider.java @@ -43,6 +43,7 @@ import org.hl7.fhir.r4.model.Person; import org.openmrs.module.fhir2.api.FhirPersonService; import org.openmrs.module.fhir2.api.annotations.R4Provider; +import org.openmrs.module.fhir2.api.search.param.PersonSearchParams; import org.openmrs.module.fhir2.providers.util.FhirProviderUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -110,8 +111,8 @@ public IBundleProvider searchPeople(@OptionalParam(name = Person.SP_NAME) String includes = null; } - return fhirPersonService.searchForPeople(name, gender, birthDate, city, state, postalCode, country, id, lastUpdated, - sort, includes); + return fhirPersonService.searchForPeople(new PersonSearchParams(name, gender, birthDate, city, state, postalCode, + country, id, lastUpdated, sort, includes)); } } diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirPersonServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirPersonServiceImplTest.java index 35a88e946..d84f23d74 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirPersonServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirPersonServiceImplTest.java @@ -56,6 +56,7 @@ import org.openmrs.module.fhir2.api.search.SearchQuery; import org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider; import org.openmrs.module.fhir2.api.search.SearchQueryInclude; +import org.openmrs.module.fhir2.api.search.param.PersonSearchParams; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.PersonTranslator; @@ -184,8 +185,8 @@ public void searchForPeople_shouldReturnCollectionOfPersonForGivenNameMatched() when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet()); when(personTranslator.toFhirResource(person)).thenReturn(fhirPerson); - IBundleProvider results = personService.searchForPeople(stringAndListParam, null, null, null, null, null, null, null, - null, null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(stringAndListParam, null, null, null, null, null, null, null, null, null, null)); List resultList = get(results); @@ -209,8 +210,8 @@ public void searchForPeople_shouldReturnCollectionOfPersonForPartialMatchOnName( when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet()); when(personTranslator.toFhirResource(person)).thenReturn(fhirPerson); - IBundleProvider results = personService.searchForPeople(stringAndListParam, null, null, null, null, null, null, null, - null, null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(stringAndListParam, null, null, null, null, null, null, null, null, null, null)); List resultList = get(results); @@ -231,8 +232,8 @@ public void searchForPeople_shouldReturnEmptyCollectionWhenPersonNameNotMatched( when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( new SearchQueryBundleProvider<>(theParams, dao, personTranslator, globalPropertyService, searchQueryInclude)); - IBundleProvider results = personService.searchForPeople(stringAndListParam, null, null, null, null, null, null, null, - null, null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(stringAndListParam, null, null, null, null, null, null, null, null, null, null)); List resultList = get(results); @@ -254,8 +255,8 @@ public void searchForPeople_shouldReturnCollectionOfPersonWhenPersonGenderMatche when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet()); when(personTranslator.toFhirResource(person)).thenReturn(fhirPerson); - IBundleProvider results = personService.searchForPeople(null, tokenAndListParam, null, null, null, null, null, null, - null, null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(null, tokenAndListParam, null, null, null, null, null, null, null, null, null)); List resultList = get(results); @@ -275,8 +276,8 @@ public void searchForPeople_shouldReturnEmptyCollectionWhenPersonGenderNotMatche when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( new SearchQueryBundleProvider<>(theParams, dao, personTranslator, globalPropertyService, searchQueryInclude)); - IBundleProvider results = personService.searchForPeople(null, tokenAndListParam, null, null, null, null, null, null, - null, null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(null, tokenAndListParam, null, null, null, null, null, null, null, null, null)); List resultList = get(results); @@ -302,8 +303,8 @@ public void searchForPeople_shouldReturnCollectionOfPersonWhenPersonBirthDateMat when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet()); when(personTranslator.toFhirResource(person)).thenReturn(fhirPerson); - IBundleProvider results = personService.searchForPeople(null, null, dateRangeParam, null, null, null, null, null, - null, null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(null, null, dateRangeParam, null, null, null, null, null, null, null, null)); List resultList = get(results); @@ -324,8 +325,8 @@ public void searchForPeople_shouldReturnEmptyCollectionWhenPersonBirthDateNotMat when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( new SearchQueryBundleProvider<>(theParams, dao, personTranslator, globalPropertyService, searchQueryInclude)); - IBundleProvider results = personService.searchForPeople(null, null, dateRangeParam, null, null, null, null, null, - null, null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(null, null, dateRangeParam, null, null, null, null, null, null, null, null)); List resultList = get(results); @@ -348,8 +349,8 @@ public void searchForPeople_shouldReturnCollectionOfPersonWhenPersonCityMatched( when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet()); when(personTranslator.toFhirResource(person)).thenReturn(fhirPerson); - IBundleProvider results = personService.searchForPeople(null, null, null, stringAndListParam, null, null, null, null, - null, null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(null, null, null, stringAndListParam, null, null, null, null, null, null, null)); List resultList = get(results); @@ -370,8 +371,8 @@ public void searchForPeople_shouldReturnEmptyCollectionWhenPersonCityNotMatched( when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( new SearchQueryBundleProvider<>(theParams, dao, personTranslator, globalPropertyService, searchQueryInclude)); - IBundleProvider results = personService.searchForPeople(null, null, null, stringAndListParam, null, null, null, null, - null, null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(null, null, null, stringAndListParam, null, null, null, null, null, null, null)); List resultList = get(results); @@ -394,8 +395,8 @@ public void searchForPeople_shouldReturnCollectionOfPersonWhenPersonStateMatched when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet()); when(personTranslator.toFhirResource(person)).thenReturn(fhirPerson); - IBundleProvider results = personService.searchForPeople(null, null, null, null, stringAndListParam, null, null, null, - null, null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(null, null, null, null, stringAndListParam, null, null, null, null, null, null)); List resultList = get(results); @@ -416,8 +417,8 @@ public void searchForPeople_shouldReturnEmptyCollectionWhenPersonStateNotMatched when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( new SearchQueryBundleProvider<>(theParams, dao, personTranslator, globalPropertyService, searchQueryInclude)); - IBundleProvider results = personService.searchForPeople(null, null, null, null, stringAndListParam, null, null, null, - null, null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(null, null, null, null, stringAndListParam, null, null, null, null, null, null)); List resultList = get(results); @@ -440,8 +441,8 @@ public void searchForPeople_shouldReturnCollectionOfPersonWhenPersonPostalCodeMa when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet()); when(personTranslator.toFhirResource(person)).thenReturn(fhirPerson); - IBundleProvider results = personService.searchForPeople(null, null, null, null, null, stringAndListParam, null, null, - null, null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, stringAndListParam, null, null, null, null, null)); List resultList = get(results); @@ -462,8 +463,8 @@ public void searchForPeople_shouldReturnEmptyCollectionWhenPersonPostalCodeNotMa when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( new SearchQueryBundleProvider<>(theParams, dao, personTranslator, globalPropertyService, searchQueryInclude)); - IBundleProvider results = personService.searchForPeople(null, null, null, null, null, stringAndListParam, null, null, - null, null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, stringAndListParam, null, null, null, null, null)); List resultList = get(results); @@ -486,8 +487,8 @@ public void searchForPeople_shouldReturnCollectionOfPersonWhenPersonCountryMatch when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet()); when(personTranslator.toFhirResource(person)).thenReturn(fhirPerson); - IBundleProvider results = personService.searchForPeople(null, null, null, null, null, null, stringAndListParam, null, - null, null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, null, stringAndListParam, null, null, null, null)); List resultList = get(results); @@ -508,8 +509,8 @@ public void searchForPeople_shouldReturnEmptyCollectionWhenPersonCountryNotMatch when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( new SearchQueryBundleProvider<>(theParams, dao, personTranslator, globalPropertyService, searchQueryInclude)); - IBundleProvider results = personService.searchForPeople(null, null, null, null, null, null, stringAndListParam, null, - null, null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, null, stringAndListParam, null, null, null, null)); List resultList = get(results); @@ -531,8 +532,8 @@ public void searchForPeople_shouldReturnCollectionOfPeopleWhenUUIDMatched() { when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet()); when(personTranslator.toFhirResource(person)).thenReturn(fhirPerson); - IBundleProvider results = personService.searchForPeople(null, null, null, null, null, null, null, uuid, null, null, - null); + IBundleProvider results = personService + .searchForPeople(new PersonSearchParams(null, null, null, null, null, null, null, uuid, null, null, null)); assertThat(results, notNullValue()); assertThat(get(results), not(empty())); @@ -550,8 +551,8 @@ public void searchForPeople_shouldReturnEmptyCollectionWhenUUIDNotMatched() { when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( new SearchQueryBundleProvider<>(theParams, dao, personTranslator, globalPropertyService, searchQueryInclude)); - IBundleProvider results = personService.searchForPeople(null, null, null, null, null, null, null, uuid, null, null, - null); + IBundleProvider results = personService + .searchForPeople(new PersonSearchParams(null, null, null, null, null, null, null, uuid, null, null, null)); assertThat(results, notNullValue()); assertThat(get(results), empty()); @@ -571,8 +572,8 @@ public void searchForPeople_shouldReturnCollectionOfPeopleWhenLastUpdatedMatched when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet()); when(personTranslator.toFhirResource(person)).thenReturn(fhirPerson); - IBundleProvider results = personService.searchForPeople(null, null, null, null, null, null, null, null, lastUpdated, - null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, null, null, null, lastUpdated, null, null)); assertThat(results, notNullValue()); assertThat(get(results), not(empty())); @@ -591,8 +592,8 @@ public void searchForPeople_shouldReturnEmptyCollectionWhenLastUpdatedNotMatched when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( new SearchQueryBundleProvider<>(theParams, dao, personTranslator, globalPropertyService, searchQueryInclude)); - IBundleProvider results = personService.searchForPeople(null, null, null, null, null, null, null, null, lastUpdated, - null, null); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, null, null, null, lastUpdated, null, null)); assertThat(results, notNullValue()); assertThat(get(results), empty()); @@ -612,8 +613,8 @@ public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() { when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.singleton(new Patient())); when(personTranslator.toFhirResource(person)).thenReturn(fhirPerson); - IBundleProvider results = personService.searchForPeople(null, null, null, null, null, null, null, null, null, null, - includes); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, null, null, null, null, null, includes)); List resultList = get(results); @@ -636,8 +637,8 @@ public void searchForPeople_shouldNotAddRelatedResourcesForEmptyInclude() { when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet()); when(personTranslator.toFhirResource(person)).thenReturn(fhirPerson); - IBundleProvider results = personService.searchForPeople(null, null, null, null, null, null, null, null, null, null, - includes); + IBundleProvider results = personService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, null, null, null, null, null, includes)); List resultList = get(results); diff --git a/api/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderTest.java b/api/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderTest.java index dfe14cb01..2afed22d2 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderTest.java @@ -55,6 +55,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.FhirPersonService; +import org.openmrs.module.fhir2.api.search.param.PersonSearchParams; import org.openmrs.module.fhir2.providers.r4.MockIBundleProvider; @RunWith(MockitoJUnitRunner.class) @@ -151,9 +152,9 @@ public void getPersonByWithWrongId_shouldThrowResourceNotFoundException() { public void searchPeople_shouldReturnMatchingBundleOfPeopleByName() { StringAndListParam nameParam = new StringAndListParam() .addAnd(new StringOrListParam().add(new StringParam(GIVEN_NAME))); - when(fhirPersonService.searchForPeople(argThat(is(nameParam)), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(argThat(is(nameParam)), isNull(), isNull(), isNull(), + isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(nameParam, null, null, null, null, null, null, null, null, null, null); @@ -168,9 +169,9 @@ public void searchPeople_shouldReturnMatchingBundleOfPeopleByName() { @Test public void searchForPeople_shouldReturnMatchingBundleOfPeopleByGender() { TokenAndListParam genderParam = new TokenAndListParam().addAnd(new TokenOrListParam().add(GENDER)); - when(fhirPersonService.searchForPeople(isNull(), argThat(is(genderParam)), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), argThat(is(genderParam)), isNull(), isNull(), + isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, genderParam, null, null, null, null, null, null, null, null, null); @@ -185,9 +186,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByGender() { @Test public void searchForPeople_shouldReturnMatchingBundleOfPeopleByBirthDate() { DateRangeParam birthDateParam = new DateRangeParam().setLowerBound(BIRTH_DATE).setUpperBound(BIRTH_DATE); - when(fhirPersonService.searchForPeople(isNull(), isNull(), argThat(is(birthDateParam)), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), argThat(is(birthDateParam)), + isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, birthDateParam, null, null, null, null, null, null, null, null); @@ -202,9 +203,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByBirthDate() { @Test public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCity() { StringAndListParam cityParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(CITY))); - when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), argThat(is(cityParam)), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), argThat(is(cityParam)), + isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, cityParam, null, null, null, null, null, null, null); @@ -219,9 +220,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCity() { @Test public void searchForPeople_shouldReturnMatchingBundleOfPeopleByState() { StringAndListParam stateParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(STATE))); - when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), argThat(is(stateParam)), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), + argThat(is(stateParam)), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, stateParam, null, null, null, null, null, null); @@ -237,9 +238,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByState() { public void searchForPeople_shouldReturnMatchingBundleOfPeopleByPostalCode() { StringAndListParam postalCodeParam = new StringAndListParam() .addAnd(new StringOrListParam().add(new StringParam(POSTAL_CODE))); - when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), - argThat(is(postalCodeParam)), isNull(), isNull(), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), + argThat(is(postalCodeParam)), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, postalCodeParam, null, null, null, null, null); @@ -255,9 +256,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByPostalCode() { public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCountry() { StringAndListParam countryParam = new StringAndListParam() .addAnd(new StringOrListParam().add(new StringParam(COUNTRY))); - when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - argThat(is(countryParam)), isNull(), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), + isNull(), argThat(is(countryParam)), isNull(), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, countryParam, null, null, null, null); @@ -273,9 +274,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCountry() { public void searchForPeople_shouldReturnMatchingBundleOfPeopleByUUID() { TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(PERSON_UUID)); - when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - argThat(is(uuid)), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), + isNull(), isNull(), argThat(is(uuid)), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, uuid, null, null, null); @@ -291,9 +292,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByUUID() { public void searchForPeople_shouldReturnMatchingBundleOfPeopleByLastUpdated() { DateRangeParam lastUpdated = new DateRangeParam().setLowerBound(LAST_UPDATED_DATE).setUpperBound(LAST_UPDATED_DATE); - when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), argThat(is(lastUpdated)), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), + isNull(), isNull(), isNull(), argThat(is(lastUpdated)), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, null, lastUpdated, null, null); @@ -310,9 +311,9 @@ public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() { HashSet includes = new HashSet<>(); includes.add(new Include("Person:patient")); - when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), argThat(is(includes)))) - .thenReturn(new MockIBundleProvider<>(Arrays.asList(person, new Patient()), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), + isNull(), isNull(), isNull(), isNull(), isNull(), argThat(is(includes))))).thenReturn( + new MockIBundleProvider<>(Arrays.asList(person, new Patient()), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, null, null, null, includes); @@ -329,9 +330,9 @@ public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() { public void searchForPeople_shouldNotAddRelatedResourcesForEmptyInclude() { HashSet includes = new HashSet<>(); - when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), + isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, null, null, null, includes); diff --git a/api/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderTest.java b/api/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderTest.java index 438a9b441..f15970a44 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderTest.java @@ -52,6 +52,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.FhirPersonService; +import org.openmrs.module.fhir2.api.search.param.PersonSearchParams; import org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest; @RunWith(MockitoJUnitRunner.class) @@ -148,9 +149,9 @@ public void getPersonByWithWrongId_shouldThrowResourceNotFoundException() { public void searchPeople_shouldReturnMatchingBundleOfPeopleByName() { StringAndListParam nameParam = new StringAndListParam() .addAnd(new StringOrListParam().add(new StringParam(GIVEN_NAME))); - when(fhirPersonService.searchForPeople(argThat(is(nameParam)), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(argThat(is(nameParam)), isNull(), isNull(), isNull(), + isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(nameParam, null, null, null, null, null, null, null, null, null, null); @@ -165,9 +166,9 @@ public void searchPeople_shouldReturnMatchingBundleOfPeopleByName() { @Test public void searchForPeople_shouldReturnMatchingBundleOfPeopleByGender() { TokenAndListParam genderParam = new TokenAndListParam().addAnd(new TokenOrListParam().add(GENDER)); - when(fhirPersonService.searchForPeople(isNull(), argThat(is(genderParam)), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), argThat(is(genderParam)), isNull(), isNull(), + isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, genderParam, null, null, null, null, null, null, null, null, null); @@ -182,9 +183,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByGender() { @Test public void searchForPeople_shouldReturnMatchingBundleOfPeopleByBirthDate() { DateRangeParam birthDateParam = new DateRangeParam().setLowerBound(BIRTH_DATE).setUpperBound(BIRTH_DATE); - when(fhirPersonService.searchForPeople(isNull(), isNull(), argThat(is(birthDateParam)), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), argThat(is(birthDateParam)), + isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, birthDateParam, null, null, null, null, null, null, null, null); @@ -199,9 +200,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByBirthDate() { @Test public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCity() { StringAndListParam cityParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(CITY))); - when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), argThat(is(cityParam)), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), argThat(is(cityParam)), + isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, cityParam, null, null, null, null, null, null, null); @@ -216,9 +217,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCity() { @Test public void searchForPeople_shouldReturnMatchingBundleOfPeopleByState() { StringAndListParam stateParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(STATE))); - when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), argThat(is(stateParam)), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), + argThat(is(stateParam)), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, stateParam, null, null, null, null, null, null); @@ -234,9 +235,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByState() { public void searchForPeople_shouldReturnMatchingBundleOfPeopleByPostalCode() { StringAndListParam postalCodeParam = new StringAndListParam() .addAnd(new StringOrListParam().add(new StringParam(POSTAL_CODE))); - when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), - argThat(is(postalCodeParam)), isNull(), isNull(), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), + argThat(is(postalCodeParam)), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, postalCodeParam, null, null, null, null, null); @@ -252,9 +253,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByPostalCode() { public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCountry() { StringAndListParam countryParam = new StringAndListParam() .addAnd(new StringOrListParam().add(new StringParam(COUNTRY))); - when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - argThat(is(countryParam)), isNull(), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), + isNull(), argThat(is(countryParam)), isNull(), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, countryParam, null, null, null, null); @@ -270,9 +271,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCountry() { public void searchForPeople_shouldReturnMatchingBundleOfPeopleByUUID() { TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(PERSON_UUID)); - when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - argThat(is(uuid)), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), + isNull(), isNull(), argThat(is(uuid)), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, uuid, null, null, null); @@ -288,9 +289,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByUUID() { public void searchForPeople_shouldReturnMatchingBundleOfPeopleByLastUpdated() { DateRangeParam lastUpdated = new DateRangeParam().setLowerBound(LAST_UPDATED_DATE).setUpperBound(LAST_UPDATED_DATE); - when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), argThat(is(lastUpdated)), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), + isNull(), isNull(), isNull(), argThat(is(lastUpdated)), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, null, lastUpdated, null, null); @@ -307,9 +308,9 @@ public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() { HashSet includes = new HashSet<>(); includes.add(new Include("Person:patient")); - when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), argThat(is(includes)))) - .thenReturn(new MockIBundleProvider<>(Arrays.asList(person, new Patient()), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), + isNull(), isNull(), isNull(), isNull(), isNull(), argThat(is(includes))))).thenReturn( + new MockIBundleProvider<>(Arrays.asList(person, new Patient()), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, null, null, null, includes); @@ -326,9 +327,9 @@ public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() { public void searchForPeople_shouldNotAddRelatedResourcesForEmptyInclude() { HashSet includes = new HashSet<>(); - when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull())) - .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), + isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( + new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, null, null, null, includes); diff --git a/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderWebTest.java b/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderWebTest.java index 6450c1235..9918a7a4b 100644 --- a/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderWebTest.java +++ b/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderWebTest.java @@ -20,7 +20,6 @@ import static org.hamcrest.Matchers.nullValue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -53,6 +52,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.FhirPersonService; +import org.openmrs.module.fhir2.api.search.param.PersonSearchParams; import org.openmrs.module.fhir2.providers.r4.MockIBundleProvider; import org.springframework.mock.web.MockHttpServletResponse; @@ -88,16 +88,7 @@ public class PersonFhirResourceProviderWebTest extends BaseFhirR3ResourceProvide private PersonFhirResourceProvider resourceProvider; @Captor - private ArgumentCaptor stringAndListCaptor; - - @Captor - private ArgumentCaptor tokenAndListCaptor; - - @Captor - private ArgumentCaptor dateRangeCaptor; - - @Captor - private ArgumentCaptor> includeArgumentCaptor; + private ArgumentCaptor personSearchParamsCaptor; @Before @Override @@ -135,12 +126,12 @@ public void shouldReturn404IfPersonNotFound() throws Exception { public void shouldGetPersonByName() throws Exception { verifyUri(String.format("/Person/?name=%s", PERSON_NAME)); - verify(personService).searchForPeople(stringAndListCaptor.capture(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + StringAndListParam personName = personSearchParamsCaptor.getValue().getName(); - assertThat(stringAndListCaptor.getValue(), notNullValue()); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(personName, notNullValue()); + assertThat(personName.getValuesAsQueryTokens(), not(empty())); + assertThat(personName.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(PERSON_NAME)); } @@ -148,12 +139,12 @@ public void shouldGetPersonByName() throws Exception { public void shouldGetPersonByGender() throws Exception { verifyUri(String.format("/Person/?gender=%s", PERSON_GENDER)); - verify(personService).searchForPeople(isNull(), tokenAndListCaptor.capture(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + TokenAndListParam gender = personSearchParamsCaptor.getValue().getGender(); - assertThat(tokenAndListCaptor.getValue(), notNullValue()); - assertThat(tokenAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(tokenAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(gender, notNullValue()); + assertThat(gender.getValuesAsQueryTokens(), not(empty())); + assertThat(gender.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(PERSON_GENDER)); } @@ -161,16 +152,17 @@ public void shouldGetPersonByGender() throws Exception { public void shouldGetPersonByBirthDate() throws Exception { verifyUri("/Person/?birthdate=eq1975-02-02"); - verify(personService).searchForPeople(isNull(), isNull(), dateRangeCaptor.capture(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull()); - assertThat(dateRangeCaptor.getValue(), notNullValue()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); + + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); - assertThat(dateRangeCaptor.getValue().getLowerBound().getValue(), + assertThat(birthdate.getLowerBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); - assertThat(dateRangeCaptor.getValue().getUpperBound().getValue(), + assertThat(birthdate.getUpperBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); } @@ -178,47 +170,50 @@ public void shouldGetPersonByBirthDate() throws Exception { public void shouldGetPersonByBirthDateGreaterThanOrEqualTo() throws Exception { verifyUri("/Person/?birthdate=ge1975-02-02"); - verify(personService).searchForPeople(isNull(), isNull(), dateRangeCaptor.capture(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull()); - assertThat(dateRangeCaptor.getValue(), notNullValue()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); + + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); - assertThat(dateRangeCaptor.getValue().getLowerBound().getValue(), + assertThat(birthdate.getLowerBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); - assertThat(dateRangeCaptor.getValue().getUpperBound(), nullValue()); + assertThat(birthdate.getUpperBound(), nullValue()); } @Test public void shouldGetPersonByBirthDateGreaterThan() throws Exception { verifyUri("/Person/?birthdate=gt1975-02-02"); - verify(personService).searchForPeople(isNull(), isNull(), dateRangeCaptor.capture(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull()); - assertThat(dateRangeCaptor.getValue(), notNullValue()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); + + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); - assertThat(dateRangeCaptor.getValue().getLowerBound().getValue(), + assertThat(birthdate.getLowerBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); - assertThat(dateRangeCaptor.getValue().getUpperBound(), nullValue()); + assertThat(birthdate.getUpperBound(), nullValue()); } @Test public void shouldGetPersonByBirthDateLessThanOrEqualTo() throws Exception { verifyUri("/Person/?birthdate=le1975-02-02"); - verify(personService).searchForPeople(isNull(), isNull(), dateRangeCaptor.capture(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull()); - assertThat(dateRangeCaptor.getValue(), notNullValue()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); + + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); - assertThat(dateRangeCaptor.getValue().getLowerBound(), nullValue()); - assertThat(dateRangeCaptor.getValue().getUpperBound().getValue(), + assertThat(birthdate.getLowerBound(), nullValue()); + assertThat(birthdate.getUpperBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); } @@ -226,15 +221,16 @@ public void shouldGetPersonByBirthDateLessThanOrEqualTo() throws Exception { public void shouldGetPersonByBirthDateLessThan() throws Exception { verifyUri("/Person/?birthdate=lt1975-02-02"); - verify(personService).searchForPeople(isNull(), isNull(), dateRangeCaptor.capture(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull()); - assertThat(dateRangeCaptor.getValue(), notNullValue()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); + + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); - assertThat(dateRangeCaptor.getValue().getLowerBound(), nullValue()); - assertThat(dateRangeCaptor.getValue().getUpperBound().getValue(), + assertThat(birthdate.getLowerBound(), nullValue()); + assertThat(birthdate.getUpperBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); } @@ -242,18 +238,18 @@ public void shouldGetPersonByBirthDateLessThan() throws Exception { public void shouldGetPersonByBirthDateBetween() throws Exception { verifyUri("/Person/?birthdate=ge1975-02-02&birthdate=le1980-02-02"); - verify(personService).searchForPeople(isNull(), isNull(), dateRangeCaptor.capture(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); Calendar lowerBound = Calendar.getInstance(); lowerBound.set(1975, Calendar.FEBRUARY, 2); Calendar upperBound = Calendar.getInstance(); upperBound.set(1980, Calendar.FEBRUARY, 2); - assertThat(dateRangeCaptor.getValue(), notNullValue()); - assertThat(dateRangeCaptor.getValue().getLowerBound().getValue(), + assertThat(birthdate, notNullValue()); + assertThat(birthdate.getLowerBound().getValue(), equalTo(DateUtils.truncate(lowerBound.getTime(), Calendar.DATE))); - assertThat(dateRangeCaptor.getValue().getUpperBound().getValue(), + assertThat(birthdate.getUpperBound().getValue(), equalTo(DateUtils.truncate(upperBound.getTime(), Calendar.DATE))); } @@ -261,12 +257,12 @@ public void shouldGetPersonByBirthDateBetween() throws Exception { public void shouldGetPersonByCity() throws Exception { verifyUri(String.format("/Person/?address-city=%s", ADDRESS_FIELD)); - verify(personService).searchForPeople(isNull(), isNull(), isNull(), stringAndListCaptor.capture(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + StringAndListParam city = personSearchParamsCaptor.getValue().getCity(); - assertThat(stringAndListCaptor.getValue(), notNullValue()); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(city, notNullValue()); + assertThat(city.getValuesAsQueryTokens(), not(empty())); + assertThat(city.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(ADDRESS_FIELD)); } @@ -274,12 +270,12 @@ public void shouldGetPersonByCity() throws Exception { public void shouldGetPersonByState() throws Exception { verifyUri(String.format("/Person/?address-state=%s", ADDRESS_FIELD)); - verify(personService).searchForPeople(isNull(), isNull(), isNull(), isNull(), stringAndListCaptor.capture(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + StringAndListParam state = personSearchParamsCaptor.getValue().getState(); - assertThat(stringAndListCaptor.getValue(), notNullValue()); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(state, notNullValue()); + assertThat(state.getValuesAsQueryTokens(), not(empty())); + assertThat(state.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(ADDRESS_FIELD)); } @@ -287,12 +283,12 @@ public void shouldGetPersonByState() throws Exception { public void shouldGetPersonByPostalCode() throws Exception { verifyUri(String.format("/Person/?address-postalcode=%s", POSTAL_CODE)); - verify(personService).searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), - stringAndListCaptor.capture(), isNull(), isNull(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + StringAndListParam postalcode = personSearchParamsCaptor.getValue().getPostalCode(); - assertThat(stringAndListCaptor.getValue(), notNullValue()); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(postalcode, notNullValue()); + assertThat(postalcode.getValuesAsQueryTokens(), not(empty())); + assertThat(postalcode.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(POSTAL_CODE)); } @@ -300,12 +296,12 @@ public void shouldGetPersonByPostalCode() throws Exception { public void shouldGetPersonByCountry() throws Exception { verifyUri(String.format("/Person/?address-country=%s", ADDRESS_FIELD)); - verify(personService).searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - stringAndListCaptor.capture(), isNull(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + StringAndListParam country = personSearchParamsCaptor.getValue().getCountry(); - assertThat(stringAndListCaptor.getValue(), notNullValue()); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(country, notNullValue()); + assertThat(country.getValuesAsQueryTokens(), not(empty())); + assertThat(country.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(ADDRESS_FIELD)); } @@ -313,12 +309,12 @@ public void shouldGetPersonByCountry() throws Exception { public void shouldGetPersonByUUID() throws Exception { verifyUri(String.format("/Person?_id=%s", PERSON_UUID)); - verify(personService).searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - tokenAndListCaptor.capture(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + TokenAndListParam uuid = personSearchParamsCaptor.getValue().getId(); - assertThat(tokenAndListCaptor.getValue(), notNullValue()); - assertThat(tokenAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(tokenAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(uuid, notNullValue()); + assertThat(uuid.getValuesAsQueryTokens(), not(empty())); + assertThat(uuid.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(PERSON_UUID)); } @@ -326,17 +322,17 @@ public void shouldGetPersonByUUID() throws Exception { public void shouldGetPersonByLastUpdatedDate() throws Exception { verifyUri(String.format("/Person?_lastUpdated=%s", LAST_UPDATED_DATE)); - verify(personService).searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - dateRangeCaptor.capture(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + DateRangeParam lastUpdated = personSearchParamsCaptor.getValue().getBirthDate(); - assertThat(dateRangeCaptor.getValue(), notNullValue()); + assertThat(lastUpdated, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(2020, Calendar.SEPTEMBER, 3); - assertThat(dateRangeCaptor.getValue().getLowerBound().getValue(), + assertThat(lastUpdated.getLowerBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); - assertThat(dateRangeCaptor.getValue().getUpperBound().getValue(), + assertThat(lastUpdated.getUpperBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); } @@ -344,27 +340,29 @@ public void shouldGetPersonByLastUpdatedDate() throws Exception { public void shouldGetPersonByComplexQuery() throws Exception { verifyUri(String.format("/Person/?name=%s&gender=%s&birthdate=eq1975-02-02", PERSON_NAME, PERSON_GENDER)); - verify(personService).searchForPeople(stringAndListCaptor.capture(), tokenAndListCaptor.capture(), - dateRangeCaptor.capture(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + StringAndListParam name = personSearchParamsCaptor.getValue().getName(); + TokenAndListParam gender = personSearchParamsCaptor.getValue().getGender(); + DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); - assertThat(stringAndListCaptor.getValue(), notNullValue()); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(name, notNullValue()); + assertThat(name.getValuesAsQueryTokens(), not(empty())); + assertThat(name.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(PERSON_NAME)); - assertThat(tokenAndListCaptor.getValue(), notNullValue()); - assertThat(tokenAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(tokenAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(gender, notNullValue()); + assertThat(gender.getValuesAsQueryTokens(), not(empty())); + assertThat(gender.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(PERSON_GENDER)); - assertThat(dateRangeCaptor.getValue(), notNullValue()); + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); - assertThat(dateRangeCaptor.getValue().getLowerBound().getValue(), + assertThat(birthdate.getLowerBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); - assertThat(dateRangeCaptor.getValue().getUpperBound().getValue(), + assertThat(birthdate.getUpperBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); } @@ -372,35 +370,35 @@ public void shouldGetPersonByComplexQuery() throws Exception { public void shouldAddPatientsToResultListWhenIncluded() throws Exception { verifyUri("/Person?_include=Person:patient"); - verify(personService).searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), includeArgumentCaptor.capture()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + HashSet includes = personSearchParamsCaptor.getValue().getIncludes(); - assertThat(includeArgumentCaptor.getValue(), notNullValue()); - assertThat(includeArgumentCaptor.getValue().size(), equalTo(1)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamName(), + assertThat(includes, notNullValue()); + assertThat(includes.size(), equalTo(1)); + assertThat(includes.iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_PATIENT_PARAM)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamType(), equalTo(FhirConstants.PERSON)); + assertThat(includes.iterator().next().getParamType(), equalTo(FhirConstants.PERSON)); } @Test public void shouldAddLinksToResultListWhenIncluded() throws Exception { verifyUri("/Person?_include=Person:link:Patient"); - verify(personService).searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), includeArgumentCaptor.capture()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + HashSet includes = personSearchParamsCaptor.getValue().getIncludes(); - assertThat(includeArgumentCaptor.getValue(), notNullValue()); - assertThat(includeArgumentCaptor.getValue().size(), equalTo(1)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamName(), + assertThat(includes, notNullValue()); + assertThat(includes.size(), equalTo(1)); + assertThat(includes.iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_LINK_PARAM)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamType(), equalTo(FhirConstants.PERSON)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamTargetType(), equalTo(FhirConstants.PATIENT)); + assertThat(includes.iterator().next().getParamType(), equalTo(FhirConstants.PERSON)); + assertThat(includes.iterator().next().getParamTargetType(), equalTo(FhirConstants.PATIENT)); } private void verifyUri(String uri) throws Exception { Person person = new Person(); person.setId(PERSON_UUID); - when(personService.searchForPeople(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())) + when(personService.searchForPeople(any())) .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), 10, 1)); MockHttpServletResponse response = get(uri).accept(FhirMediaTypes.JSON).go(); diff --git a/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderWebTest.java b/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderWebTest.java index f57d70144..12f9c7558 100644 --- a/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderWebTest.java +++ b/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderWebTest.java @@ -20,7 +20,6 @@ import static org.hamcrest.Matchers.nullValue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -54,6 +53,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.FhirPersonService; +import org.openmrs.module.fhir2.api.search.param.PersonSearchParams; import org.springframework.mock.web.MockHttpServletResponse; @RunWith(MockitoJUnitRunner.class) @@ -88,16 +88,7 @@ public class PersonFhirResourceProviderWebTest extends BaseFhirR4ResourceProvide private PersonFhirResourceProvider resourceProvider; @Captor - private ArgumentCaptor stringAndListCaptor; - - @Captor - private ArgumentCaptor tokenAndListCaptor; - - @Captor - private ArgumentCaptor dateRangeCaptor; - - @Captor - private ArgumentCaptor> includeArgumentCaptor; + private ArgumentCaptor personSearchParamsCaptor; @Before @Override @@ -135,12 +126,12 @@ public void shouldReturn404IfPersonNotFound() throws Exception { public void shouldGetPersonByName() throws Exception { verifyUri(String.format("/Person/?name=%s", PERSON_NAME)); - verify(personService).searchForPeople(stringAndListCaptor.capture(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + StringAndListParam personName = personSearchParamsCaptor.getValue().getName(); - assertThat(stringAndListCaptor.getValue(), notNullValue()); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(personName, notNullValue()); + assertThat(personName.getValuesAsQueryTokens(), not(empty())); + assertThat(personName.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(PERSON_NAME)); } @@ -148,12 +139,12 @@ public void shouldGetPersonByName() throws Exception { public void shouldGetPersonByGender() throws Exception { verifyUri(String.format("/Person/?gender=%s", PERSON_GENDER)); - verify(personService).searchForPeople(isNull(), tokenAndListCaptor.capture(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + TokenAndListParam gender = personSearchParamsCaptor.getValue().getGender(); - assertThat(tokenAndListCaptor.getValue(), notNullValue()); - assertThat(tokenAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(tokenAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(gender, notNullValue()); + assertThat(gender.getValuesAsQueryTokens(), not(empty())); + assertThat(gender.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(PERSON_GENDER)); } @@ -161,16 +152,17 @@ public void shouldGetPersonByGender() throws Exception { public void shouldGetPersonByBirthDate() throws Exception { verifyUri("/Person/?birthdate=eq1975-02-02"); - verify(personService).searchForPeople(isNull(), isNull(), dateRangeCaptor.capture(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull()); - assertThat(dateRangeCaptor.getValue(), notNullValue()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); + + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); - assertThat(dateRangeCaptor.getValue().getLowerBound().getValue(), + assertThat(birthdate.getLowerBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); - assertThat(dateRangeCaptor.getValue().getUpperBound().getValue(), + assertThat(birthdate.getUpperBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); } @@ -178,47 +170,50 @@ public void shouldGetPersonByBirthDate() throws Exception { public void shouldGetPersonByBirthDateGreaterThanOrEqualTo() throws Exception { verifyUri("/Person/?birthdate=ge1975-02-02"); - verify(personService).searchForPeople(isNull(), isNull(), dateRangeCaptor.capture(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull()); - assertThat(dateRangeCaptor.getValue(), notNullValue()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); + + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); - assertThat(dateRangeCaptor.getValue().getLowerBound().getValue(), + assertThat(birthdate.getLowerBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); - assertThat(dateRangeCaptor.getValue().getUpperBound(), nullValue()); + assertThat(birthdate.getUpperBound(), nullValue()); } @Test public void shouldGetPersonByBirthDateGreaterThan() throws Exception { verifyUri("/Person/?birthdate=gt1975-02-02"); - verify(personService).searchForPeople(isNull(), isNull(), dateRangeCaptor.capture(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull()); - assertThat(dateRangeCaptor.getValue(), notNullValue()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); + + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); - assertThat(dateRangeCaptor.getValue().getLowerBound().getValue(), + assertThat(birthdate.getLowerBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); - assertThat(dateRangeCaptor.getValue().getUpperBound(), nullValue()); + assertThat(birthdate.getUpperBound(), nullValue()); } @Test public void shouldGetPersonByBirthDateLessThanOrEqualTo() throws Exception { verifyUri("/Person/?birthdate=le1975-02-02"); - verify(personService).searchForPeople(isNull(), isNull(), dateRangeCaptor.capture(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull()); - assertThat(dateRangeCaptor.getValue(), notNullValue()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); + + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); - assertThat(dateRangeCaptor.getValue().getLowerBound(), nullValue()); - assertThat(dateRangeCaptor.getValue().getUpperBound().getValue(), + assertThat(birthdate.getLowerBound(), nullValue()); + assertThat(birthdate.getUpperBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); } @@ -226,15 +221,16 @@ public void shouldGetPersonByBirthDateLessThanOrEqualTo() throws Exception { public void shouldGetPersonByBirthDateLessThan() throws Exception { verifyUri("/Person/?birthdate=lt1975-02-02"); - verify(personService).searchForPeople(isNull(), isNull(), dateRangeCaptor.capture(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull()); - assertThat(dateRangeCaptor.getValue(), notNullValue()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); + + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); - assertThat(dateRangeCaptor.getValue().getLowerBound(), nullValue()); - assertThat(dateRangeCaptor.getValue().getUpperBound().getValue(), + assertThat(birthdate.getLowerBound(), nullValue()); + assertThat(birthdate.getUpperBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); } @@ -242,18 +238,18 @@ public void shouldGetPersonByBirthDateLessThan() throws Exception { public void shouldGetPersonByBirthDateBetween() throws Exception { verifyUri("/Person/?birthdate=ge1975-02-02&birthdate=le1980-02-02"); - verify(personService).searchForPeople(isNull(), isNull(), dateRangeCaptor.capture(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); Calendar lowerBound = Calendar.getInstance(); lowerBound.set(1975, Calendar.FEBRUARY, 2); Calendar upperBound = Calendar.getInstance(); upperBound.set(1980, Calendar.FEBRUARY, 2); - assertThat(dateRangeCaptor.getValue(), notNullValue()); - assertThat(dateRangeCaptor.getValue().getLowerBound().getValue(), + assertThat(birthdate, notNullValue()); + assertThat(birthdate.getLowerBound().getValue(), equalTo(DateUtils.truncate(lowerBound.getTime(), Calendar.DATE))); - assertThat(dateRangeCaptor.getValue().getUpperBound().getValue(), + assertThat(birthdate.getUpperBound().getValue(), equalTo(DateUtils.truncate(upperBound.getTime(), Calendar.DATE))); } @@ -261,12 +257,12 @@ public void shouldGetPersonByBirthDateBetween() throws Exception { public void shouldGetPersonByCity() throws Exception { verifyUri(String.format("/Person/?address-city=%s", ADDRESS_FIELD)); - verify(personService).searchForPeople(isNull(), isNull(), isNull(), stringAndListCaptor.capture(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + StringAndListParam city = personSearchParamsCaptor.getValue().getCity(); - assertThat(stringAndListCaptor.getValue(), notNullValue()); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(city, notNullValue()); + assertThat(city.getValuesAsQueryTokens(), not(empty())); + assertThat(city.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(ADDRESS_FIELD)); } @@ -274,12 +270,12 @@ public void shouldGetPersonByCity() throws Exception { public void shouldGetPersonByState() throws Exception { verifyUri(String.format("/Person/?address-state=%s", ADDRESS_FIELD)); - verify(personService).searchForPeople(isNull(), isNull(), isNull(), isNull(), stringAndListCaptor.capture(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + StringAndListParam state = personSearchParamsCaptor.getValue().getState(); - assertThat(stringAndListCaptor.getValue(), notNullValue()); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(state, notNullValue()); + assertThat(state.getValuesAsQueryTokens(), not(empty())); + assertThat(state.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(ADDRESS_FIELD)); } @@ -287,12 +283,12 @@ public void shouldGetPersonByState() throws Exception { public void shouldGetPersonByPostalCode() throws Exception { verifyUri(String.format("/Person/?address-postalcode=%s", POSTAL_CODE)); - verify(personService).searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), - stringAndListCaptor.capture(), isNull(), isNull(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + StringAndListParam postalcode = personSearchParamsCaptor.getValue().getPostalCode(); - assertThat(stringAndListCaptor.getValue(), notNullValue()); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(postalcode, notNullValue()); + assertThat(postalcode.getValuesAsQueryTokens(), not(empty())); + assertThat(postalcode.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(POSTAL_CODE)); } @@ -300,12 +296,12 @@ public void shouldGetPersonByPostalCode() throws Exception { public void shouldGetPersonByCountry() throws Exception { verifyUri(String.format("/Person/?address-country=%s", ADDRESS_FIELD)); - verify(personService).searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - stringAndListCaptor.capture(), isNull(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + StringAndListParam country = personSearchParamsCaptor.getValue().getCountry(); - assertThat(stringAndListCaptor.getValue(), notNullValue()); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(country, notNullValue()); + assertThat(country.getValuesAsQueryTokens(), not(empty())); + assertThat(country.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(ADDRESS_FIELD)); } @@ -313,12 +309,12 @@ public void shouldGetPersonByCountry() throws Exception { public void shouldGetPersonByUUID() throws Exception { verifyUri(String.format("/Person?_id=%s", PERSON_UUID)); - verify(personService).searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - tokenAndListCaptor.capture(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + TokenAndListParam uuid = personSearchParamsCaptor.getValue().getId(); - assertThat(tokenAndListCaptor.getValue(), notNullValue()); - assertThat(tokenAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(tokenAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(uuid, notNullValue()); + assertThat(uuid.getValuesAsQueryTokens(), not(empty())); + assertThat(uuid.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(PERSON_UUID)); } @@ -326,17 +322,17 @@ public void shouldGetPersonByUUID() throws Exception { public void shouldGetPersonByLastUpdatedDate() throws Exception { verifyUri(String.format("/Person?_lastUpdated=%s", LAST_UPDATED_DATE)); - verify(personService).searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - dateRangeCaptor.capture(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + DateRangeParam last_updated_date = personSearchParamsCaptor.getValue().getLastUpdated(); - assertThat(dateRangeCaptor.getValue(), notNullValue()); + assertThat(last_updated_date, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(2020, Calendar.SEPTEMBER, 3); - assertThat(dateRangeCaptor.getValue().getLowerBound().getValue(), + assertThat(last_updated_date.getLowerBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); - assertThat(dateRangeCaptor.getValue().getUpperBound().getValue(), + assertThat(last_updated_date.getUpperBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); } @@ -344,27 +340,29 @@ public void shouldGetPersonByLastUpdatedDate() throws Exception { public void shouldGetPersonByComplexQuery() throws Exception { verifyUri(String.format("/Person/?name=%s&gender=%s&birthdate=eq1975-02-02", PERSON_NAME, PERSON_GENDER)); - verify(personService).searchForPeople(stringAndListCaptor.capture(), tokenAndListCaptor.capture(), - dateRangeCaptor.capture(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + StringAndListParam name = personSearchParamsCaptor.getValue().getName(); + TokenAndListParam gender = personSearchParamsCaptor.getValue().getGender(); + DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); - assertThat(stringAndListCaptor.getValue(), notNullValue()); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(name, notNullValue()); + assertThat(name.getValuesAsQueryTokens(), not(empty())); + assertThat(name.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(PERSON_NAME)); - assertThat(tokenAndListCaptor.getValue(), notNullValue()); - assertThat(tokenAndListCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(tokenAndListCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), + assertThat(gender, notNullValue()); + assertThat(gender.getValuesAsQueryTokens(), not(empty())); + assertThat(gender.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(PERSON_GENDER)); - assertThat(dateRangeCaptor.getValue(), notNullValue()); + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); - assertThat(dateRangeCaptor.getValue().getLowerBound().getValue(), + assertThat(birthdate.getLowerBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); - assertThat(dateRangeCaptor.getValue().getUpperBound().getValue(), + assertThat(birthdate.getUpperBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); } @@ -372,35 +370,35 @@ public void shouldGetPersonByComplexQuery() throws Exception { public void shouldAddPatientsToResultListWhenIncluded() throws Exception { verifyUri("/Person?_include=Person:patient"); - verify(personService).searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), includeArgumentCaptor.capture()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + HashSet include = personSearchParamsCaptor.getValue().getIncludes(); - assertThat(includeArgumentCaptor.getValue(), notNullValue()); - assertThat(includeArgumentCaptor.getValue().size(), equalTo(1)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamName(), + assertThat(include, notNullValue()); + assertThat(include.size(), equalTo(1)); + assertThat(include.iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_PATIENT_PARAM)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamType(), equalTo(FhirConstants.PERSON)); + assertThat(include.iterator().next().getParamType(), equalTo(FhirConstants.PERSON)); } @Test public void shouldAddLinksToResultListWhenIncluded() throws Exception { verifyUri("/Person?_include=Person:link:Patient"); - verify(personService).searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), includeArgumentCaptor.capture()); + verify(personService).searchForPeople(personSearchParamsCaptor.capture()); + HashSet include = personSearchParamsCaptor.getValue().getIncludes(); - assertThat(includeArgumentCaptor.getValue(), notNullValue()); - assertThat(includeArgumentCaptor.getValue().size(), equalTo(1)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamName(), + assertThat(include, notNullValue()); + assertThat(include.size(), equalTo(1)); + assertThat(include.iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_LINK_PARAM)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamType(), equalTo(FhirConstants.PERSON)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamTargetType(), equalTo(FhirConstants.PATIENT)); + assertThat(include.iterator().next().getParamType(), equalTo(FhirConstants.PERSON)); + assertThat(include.iterator().next().getParamTargetType(), equalTo(FhirConstants.PATIENT)); } private void verifyUri(String uri) throws Exception { Person person = new Person(); person.setId(PERSON_UUID); - when(personService.searchForPeople(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())) + when(personService.searchForPeople(any())) .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), 10, 1)); MockHttpServletResponse response = get(uri).accept(FhirMediaTypes.JSON).go(); From 16089733610d3b56f2b80676385f49a791def4af Mon Sep 17 00:00:00 2001 From: herman Date: Fri, 4 Nov 2022 15:39:39 +0300 Subject: [PATCH 2/3] ensuring all the tests are running as intended --- .../r3/PersonFhirResourceProviderTest.java | 68 +++++++++---------- .../r4/PersonFhirResourceProviderTest.java | 68 +++++++++---------- .../r3/PersonFhirResourceProviderWebTest.java | 2 +- .../r4/PersonFhirResourceProviderWebTest.java | 58 ++++++---------- 4 files changed, 88 insertions(+), 108 deletions(-) diff --git a/api/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderTest.java b/api/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderTest.java index 2afed22d2..b318aba59 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderTest.java @@ -18,9 +18,7 @@ import static org.hamcrest.Matchers.nullValue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.when; -import static org.mockito.hamcrest.MockitoHamcrest.argThat; import java.util.Arrays; import java.util.Collections; @@ -152,9 +150,9 @@ public void getPersonByWithWrongId_shouldThrowResourceNotFoundException() { public void searchPeople_shouldReturnMatchingBundleOfPeopleByName() { StringAndListParam nameParam = new StringAndListParam() .addAnd(new StringOrListParam().add(new StringParam(GIVEN_NAME))); - when(fhirPersonService.searchForPeople(new PersonSearchParams(argThat(is(nameParam)), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(nameParam, null, null, null, null, null, null, null, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(nameParam, null, null, null, null, null, null, null, null, null, null); @@ -169,9 +167,9 @@ public void searchPeople_shouldReturnMatchingBundleOfPeopleByName() { @Test public void searchForPeople_shouldReturnMatchingBundleOfPeopleByGender() { TokenAndListParam genderParam = new TokenAndListParam().addAnd(new TokenOrListParam().add(GENDER)); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), argThat(is(genderParam)), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, genderParam, null, null, null, null, null, null, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, genderParam, null, null, null, null, null, null, null, null, null); @@ -186,9 +184,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByGender() { @Test public void searchForPeople_shouldReturnMatchingBundleOfPeopleByBirthDate() { DateRangeParam birthDateParam = new DateRangeParam().setLowerBound(BIRTH_DATE).setUpperBound(BIRTH_DATE); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), argThat(is(birthDateParam)), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, birthDateParam, null, null, null, null, null, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, birthDateParam, null, null, null, null, null, null, null, null); @@ -203,9 +201,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByBirthDate() { @Test public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCity() { StringAndListParam cityParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(CITY))); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), argThat(is(cityParam)), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, null, cityParam, null, null, null, null, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, cityParam, null, null, null, null, null, null, null); @@ -220,9 +218,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCity() { @Test public void searchForPeople_shouldReturnMatchingBundleOfPeopleByState() { StringAndListParam stateParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(STATE))); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), - argThat(is(stateParam)), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, null, null, stateParam, null, null, null, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, stateParam, null, null, null, null, null, null); @@ -238,9 +236,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByState() { public void searchForPeople_shouldReturnMatchingBundleOfPeopleByPostalCode() { StringAndListParam postalCodeParam = new StringAndListParam() .addAnd(new StringOrListParam().add(new StringParam(POSTAL_CODE))); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), - argThat(is(postalCodeParam)), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, postalCodeParam, null, null, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, postalCodeParam, null, null, null, null, null); @@ -256,9 +254,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByPostalCode() { public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCountry() { StringAndListParam countryParam = new StringAndListParam() .addAnd(new StringOrListParam().add(new StringParam(COUNTRY))); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), argThat(is(countryParam)), isNull(), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, null, countryParam, null, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, countryParam, null, null, null, null); @@ -274,9 +272,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCountry() { public void searchForPeople_shouldReturnMatchingBundleOfPeopleByUUID() { TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(PERSON_UUID)); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), argThat(is(uuid)), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, null, null, uuid, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, uuid, null, null, null); @@ -292,9 +290,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByUUID() { public void searchForPeople_shouldReturnMatchingBundleOfPeopleByLastUpdated() { DateRangeParam lastUpdated = new DateRangeParam().setLowerBound(LAST_UPDATED_DATE).setUpperBound(LAST_UPDATED_DATE); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), argThat(is(lastUpdated)), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, null, null, null, lastUpdated, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, null, lastUpdated, null, null); @@ -311,9 +309,9 @@ public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() { HashSet includes = new HashSet<>(); includes.add(new Include("Person:patient")); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), argThat(is(includes))))).thenReturn( - new MockIBundleProvider<>(Arrays.asList(person, new Patient()), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, null, null, null, null, null, includes))) + .thenReturn(new MockIBundleProvider<>(Arrays.asList(person, new Patient()), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, null, null, null, includes); @@ -330,9 +328,9 @@ public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() { public void searchForPeople_shouldNotAddRelatedResourcesForEmptyInclude() { HashSet includes = new HashSet<>(); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, null, null, null, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, null, null, null, includes); diff --git a/api/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderTest.java b/api/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderTest.java index f15970a44..b8c04bab4 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderTest.java @@ -16,9 +16,7 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.when; -import static org.mockito.hamcrest.MockitoHamcrest.argThat; import java.util.Arrays; import java.util.Collections; @@ -149,9 +147,9 @@ public void getPersonByWithWrongId_shouldThrowResourceNotFoundException() { public void searchPeople_shouldReturnMatchingBundleOfPeopleByName() { StringAndListParam nameParam = new StringAndListParam() .addAnd(new StringOrListParam().add(new StringParam(GIVEN_NAME))); - when(fhirPersonService.searchForPeople(new PersonSearchParams(argThat(is(nameParam)), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(nameParam, null, null, null, null, null, null, null, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(nameParam, null, null, null, null, null, null, null, null, null, null); @@ -166,9 +164,9 @@ public void searchPeople_shouldReturnMatchingBundleOfPeopleByName() { @Test public void searchForPeople_shouldReturnMatchingBundleOfPeopleByGender() { TokenAndListParam genderParam = new TokenAndListParam().addAnd(new TokenOrListParam().add(GENDER)); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), argThat(is(genderParam)), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, genderParam, null, null, null, null, null, null, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, genderParam, null, null, null, null, null, null, null, null, null); @@ -183,9 +181,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByGender() { @Test public void searchForPeople_shouldReturnMatchingBundleOfPeopleByBirthDate() { DateRangeParam birthDateParam = new DateRangeParam().setLowerBound(BIRTH_DATE).setUpperBound(BIRTH_DATE); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), argThat(is(birthDateParam)), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, birthDateParam, null, null, null, null, null, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, birthDateParam, null, null, null, null, null, null, null, null); @@ -200,9 +198,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByBirthDate() { @Test public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCity() { StringAndListParam cityParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(CITY))); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), argThat(is(cityParam)), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, null, cityParam, null, null, null, null, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, cityParam, null, null, null, null, null, null, null); @@ -217,9 +215,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCity() { @Test public void searchForPeople_shouldReturnMatchingBundleOfPeopleByState() { StringAndListParam stateParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(STATE))); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), - argThat(is(stateParam)), isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, null, null, stateParam, null, null, null, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, stateParam, null, null, null, null, null, null); @@ -235,9 +233,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByState() { public void searchForPeople_shouldReturnMatchingBundleOfPeopleByPostalCode() { StringAndListParam postalCodeParam = new StringAndListParam() .addAnd(new StringOrListParam().add(new StringParam(POSTAL_CODE))); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), - argThat(is(postalCodeParam)), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, postalCodeParam, null, null, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, postalCodeParam, null, null, null, null, null); @@ -253,9 +251,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByPostalCode() { public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCountry() { StringAndListParam countryParam = new StringAndListParam() .addAnd(new StringOrListParam().add(new StringParam(COUNTRY))); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), argThat(is(countryParam)), isNull(), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, null, countryParam, null, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, countryParam, null, null, null, null); @@ -271,9 +269,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCountry() { public void searchForPeople_shouldReturnMatchingBundleOfPeopleByUUID() { TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(PERSON_UUID)); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), argThat(is(uuid)), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, null, null, uuid, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, uuid, null, null, null); @@ -289,9 +287,9 @@ public void searchForPeople_shouldReturnMatchingBundleOfPeopleByUUID() { public void searchForPeople_shouldReturnMatchingBundleOfPeopleByLastUpdated() { DateRangeParam lastUpdated = new DateRangeParam().setLowerBound(LAST_UPDATED_DATE).setUpperBound(LAST_UPDATED_DATE); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), argThat(is(lastUpdated)), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, null, null, null, lastUpdated, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, null, lastUpdated, null, null); @@ -308,9 +306,9 @@ public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() { HashSet includes = new HashSet<>(); includes.add(new Include("Person:patient")); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), argThat(is(includes))))).thenReturn( - new MockIBundleProvider<>(Arrays.asList(person, new Patient()), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, null, null, null, null, null, includes))) + .thenReturn(new MockIBundleProvider<>(Arrays.asList(person, new Patient()), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, null, null, null, includes); @@ -327,9 +325,9 @@ public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() { public void searchForPeople_shouldNotAddRelatedResourcesForEmptyInclude() { HashSet includes = new HashSet<>(); - when(fhirPersonService.searchForPeople(new PersonSearchParams(isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull()))).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); + when(fhirPersonService.searchForPeople( + new PersonSearchParams(null, null, null, null, null, null, null, null, null, null, null))) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, null, null, null, includes); diff --git a/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderWebTest.java b/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderWebTest.java index 9918a7a4b..70ced81b4 100644 --- a/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderWebTest.java +++ b/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderWebTest.java @@ -323,7 +323,7 @@ public void shouldGetPersonByLastUpdatedDate() throws Exception { verifyUri(String.format("/Person?_lastUpdated=%s", LAST_UPDATED_DATE)); verify(personService).searchForPeople(personSearchParamsCaptor.capture()); - DateRangeParam lastUpdated = personSearchParamsCaptor.getValue().getBirthDate(); + DateRangeParam lastUpdated = personSearchParamsCaptor.getValue().getLastUpdated(); assertThat(lastUpdated, notNullValue()); diff --git a/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderWebTest.java b/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderWebTest.java index 12f9c7558..ef43ed3c7 100644 --- a/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderWebTest.java +++ b/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderWebTest.java @@ -154,16 +154,14 @@ public void shouldGetPersonByBirthDate() throws Exception { verify(personService).searchForPeople(personSearchParamsCaptor.capture()); DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); - + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); - assertThat(birthdate.getLowerBound().getValue(), - equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); - assertThat(birthdate.getUpperBound().getValue(), - equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); + assertThat(birthdate.getLowerBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); + assertThat(birthdate.getUpperBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); } @Test @@ -172,14 +170,13 @@ public void shouldGetPersonByBirthDateGreaterThanOrEqualTo() throws Exception { verify(personService).searchForPeople(personSearchParamsCaptor.capture()); DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); - + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); - assertThat(birthdate.getLowerBound().getValue(), - equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); + assertThat(birthdate.getLowerBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); assertThat(birthdate.getUpperBound(), nullValue()); } @@ -189,14 +186,13 @@ public void shouldGetPersonByBirthDateGreaterThan() throws Exception { verify(personService).searchForPeople(personSearchParamsCaptor.capture()); DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); - + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); - assertThat(birthdate.getLowerBound().getValue(), - equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); + assertThat(birthdate.getLowerBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); assertThat(birthdate.getUpperBound(), nullValue()); } @@ -206,15 +202,14 @@ public void shouldGetPersonByBirthDateLessThanOrEqualTo() throws Exception { verify(personService).searchForPeople(personSearchParamsCaptor.capture()); DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); - + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); assertThat(birthdate.getLowerBound(), nullValue()); - assertThat(birthdate.getUpperBound().getValue(), - equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); + assertThat(birthdate.getUpperBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); } @Test @@ -223,15 +218,14 @@ public void shouldGetPersonByBirthDateLessThan() throws Exception { verify(personService).searchForPeople(personSearchParamsCaptor.capture()); DateRangeParam birthdate = personSearchParamsCaptor.getValue().getBirthDate(); - + assertThat(birthdate, notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); assertThat(birthdate.getLowerBound(), nullValue()); - assertThat(birthdate.getUpperBound().getValue(), - equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); + assertThat(birthdate.getUpperBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); } @Test @@ -247,10 +241,8 @@ public void shouldGetPersonByBirthDateBetween() throws Exception { upperBound.set(1980, Calendar.FEBRUARY, 2); assertThat(birthdate, notNullValue()); - assertThat(birthdate.getLowerBound().getValue(), - equalTo(DateUtils.truncate(lowerBound.getTime(), Calendar.DATE))); - assertThat(birthdate.getUpperBound().getValue(), - equalTo(DateUtils.truncate(upperBound.getTime(), Calendar.DATE))); + assertThat(birthdate.getLowerBound().getValue(), equalTo(DateUtils.truncate(lowerBound.getTime(), Calendar.DATE))); + assertThat(birthdate.getUpperBound().getValue(), equalTo(DateUtils.truncate(upperBound.getTime(), Calendar.DATE))); } @Test @@ -262,8 +254,7 @@ public void shouldGetPersonByCity() throws Exception { assertThat(city, notNullValue()); assertThat(city.getValuesAsQueryTokens(), not(empty())); - assertThat(city.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), - equalTo(ADDRESS_FIELD)); + assertThat(city.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(ADDRESS_FIELD)); } @Test @@ -275,8 +266,7 @@ public void shouldGetPersonByState() throws Exception { assertThat(state, notNullValue()); assertThat(state.getValuesAsQueryTokens(), not(empty())); - assertThat(state.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), - equalTo(ADDRESS_FIELD)); + assertThat(state.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(ADDRESS_FIELD)); } @Test @@ -314,8 +304,7 @@ public void shouldGetPersonByUUID() throws Exception { assertThat(uuid, notNullValue()); assertThat(uuid.getValuesAsQueryTokens(), not(empty())); - assertThat(uuid.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), - equalTo(PERSON_UUID)); + assertThat(uuid.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(PERSON_UUID)); } @Test @@ -347,8 +336,7 @@ public void shouldGetPersonByComplexQuery() throws Exception { assertThat(name, notNullValue()); assertThat(name.getValuesAsQueryTokens(), not(empty())); - assertThat(name.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), - equalTo(PERSON_NAME)); + assertThat(name.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(PERSON_NAME)); assertThat(gender, notNullValue()); assertThat(gender.getValuesAsQueryTokens(), not(empty())); @@ -360,10 +348,8 @@ public void shouldGetPersonByComplexQuery() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(1975, Calendar.FEBRUARY, 2); - assertThat(birthdate.getLowerBound().getValue(), - equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); - assertThat(birthdate.getUpperBound().getValue(), - equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); + assertThat(birthdate.getLowerBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); + assertThat(birthdate.getUpperBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); } @Test @@ -375,8 +361,7 @@ public void shouldAddPatientsToResultListWhenIncluded() throws Exception { assertThat(include, notNullValue()); assertThat(include.size(), equalTo(1)); - assertThat(include.iterator().next().getParamName(), - equalTo(FhirConstants.INCLUDE_PATIENT_PARAM)); + assertThat(include.iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_PATIENT_PARAM)); assertThat(include.iterator().next().getParamType(), equalTo(FhirConstants.PERSON)); } @@ -389,8 +374,7 @@ public void shouldAddLinksToResultListWhenIncluded() throws Exception { assertThat(include, notNullValue()); assertThat(include.size(), equalTo(1)); - assertThat(include.iterator().next().getParamName(), - equalTo(FhirConstants.INCLUDE_LINK_PARAM)); + assertThat(include.iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_LINK_PARAM)); assertThat(include.iterator().next().getParamType(), equalTo(FhirConstants.PERSON)); assertThat(include.iterator().next().getParamTargetType(), equalTo(FhirConstants.PATIENT)); } From 866e1d0a246559cd5e39d88642bcc524a09c7aa5 Mon Sep 17 00:00:00 2001 From: herman Date: Sat, 5 Nov 2022 11:19:05 +0300 Subject: [PATCH 3/3] replace addresses with ADDRESS_SEARCH_HANDLER --- .../module/fhir2/api/search/param/PersonSearchParams.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/search/param/PersonSearchParams.java b/api/src/main/java/org/openmrs/module/fhir2/api/search/param/PersonSearchParams.java index 92fa39885..8a73d5781 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/search/param/PersonSearchParams.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/search/param/PersonSearchParams.java @@ -63,10 +63,10 @@ public SearchParameterMap toSearchParameterMap() { .addParameter(FhirConstants.NAME_SEARCH_HANDLER, FhirConstants.NAME_PROPERTY, getName()) .addParameter(FhirConstants.GENDER_SEARCH_HANDLER, getGender()) .addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, getBirthDate()) - .addParameter(FhirConstants.CITY_SEARCH_HANDLER, FhirConstants.CITY_PROPERTY, getCity()) - .addParameter(FhirConstants.STATE_SEARCH_HANDLER, FhirConstants.STATE_PROPERTY, getState()) - .addParameter(FhirConstants.POSTALCODE_SEARCH_HANDLER, FhirConstants.POSTAL_CODE_PROPERTY, getPostalCode()) - .addParameter(FhirConstants.COUNTRY_SEARCH_HANDLER, FhirConstants.COUNTRY_PROPERTY, getCountry()); + .addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.CITY_PROPERTY, getCity()) + .addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.STATE_PROPERTY, getState()) + .addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.POSTAL_CODE_PROPERTY, getPostalCode()) + .addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.COUNTRY_PROPERTY, getCountry()); } }