diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/FhirPractitionerService.java b/api/src/main/java/org/openmrs/module/fhir2/api/FhirPractitionerService.java index d890cc7dd..07dbae22d 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/FhirPractitionerService.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/FhirPractitionerService.java @@ -9,19 +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.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.Practitioner; +import org.openmrs.module.fhir2.api.search.param.PractitionerSearchParams; public interface FhirPractitionerService extends FhirService { - IBundleProvider searchForPractitioners(TokenAndListParam identifier, StringAndListParam name, StringAndListParam given, - StringAndListParam family, StringAndListParam city, StringAndListParam state, StringAndListParam postalCode, - StringAndListParam country, TokenAndListParam id, DateRangeParam lastUpdated, HashSet revIncludes); - + IBundleProvider searchForPractitioners(PractitionerSearchParams practitionerSearchParams); } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirPractitionerServiceImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirPractitionerServiceImpl.java index 3ed28ea33..63d251221 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirPractitionerServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirPractitionerServiceImpl.java @@ -11,13 +11,7 @@ import javax.annotation.Nonnull; -import java.util.HashSet; - -import ca.uhn.fhir.model.api.Include; 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 ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; @@ -27,7 +21,6 @@ import org.hl7.fhir.r4.model.Practitioner; import org.openmrs.Provider; import org.openmrs.User; -import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.FhirGlobalPropertyService; import org.openmrs.module.fhir2.api.FhirPractitionerService; import org.openmrs.module.fhir2.api.FhirUserService; @@ -36,6 +29,7 @@ import org.openmrs.module.fhir2.api.search.SearchQuery; import org.openmrs.module.fhir2.api.search.SearchQueryInclude; import org.openmrs.module.fhir2.api.search.TwoSearchQueryBundleProvider; +import org.openmrs.module.fhir2.api.search.param.PractitionerSearchParams; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.PractitionerTranslator; import org.springframework.beans.factory.annotation.Autowired; @@ -96,24 +90,11 @@ public Practitioner create(@Nonnull Practitioner newResource) { } @Override - public IBundleProvider searchForPractitioners(TokenAndListParam identifier, StringAndListParam name, - StringAndListParam given, StringAndListParam family, StringAndListParam city, StringAndListParam state, - StringAndListParam postalCode, StringAndListParam country, TokenAndListParam id, DateRangeParam lastUpdated, - HashSet revIncludes) { - SearchParameterMap theParams = new SearchParameterMap() - .addParameter(FhirConstants.IDENTIFIER_SEARCH_HANDLER, identifier) - .addParameter(FhirConstants.NAME_SEARCH_HANDLER, FhirConstants.NAME_PROPERTY, name) - .addParameter(FhirConstants.NAME_SEARCH_HANDLER, FhirConstants.GIVEN_PROPERTY, given) - .addParameter(FhirConstants.NAME_SEARCH_HANDLER, FhirConstants.FAMILY_PROPERTY, family) - .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.REVERSE_INCLUDE_SEARCH_HANDLER, revIncludes); - - IBundleProvider providerBundle = searchQuery.getQueryResults(theParams, dao, translator, searchQueryInclude); + @Transactional(readOnly = true) + public IBundleProvider searchForPractitioners(PractitionerSearchParams practitionerSearchParams) { + IBundleProvider providerBundle = searchQuery.getQueryResults(practitionerSearchParams.toSearchParameterMap(), dao, + translator, searchQueryInclude); + SearchParameterMap theParams = new SearchParameterMap(); IBundleProvider userBundle = userService.searchForUsers(theParams); if (!providerBundle.isEmpty() && !userBundle.isEmpty()) { diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/search/param/PractitionerSearchParams.java b/api/src/main/java/org/openmrs/module/fhir2/api/search/param/PractitionerSearchParams.java new file mode 100644 index 000000000..ee7b661d7 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/fhir2/api/search/param/PractitionerSearchParams.java @@ -0,0 +1,73 @@ +/* + * 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.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 PractitionerSearchParams extends BaseResourceSearchParams { + + private TokenAndListParam identifier; + + private StringAndListParam name; + + private StringAndListParam given; + + private StringAndListParam family; + + private StringAndListParam city; + + private StringAndListParam state; + + private StringAndListParam postalCode; + + private StringAndListParam country; + + @Builder + public PractitionerSearchParams(TokenAndListParam identifier, StringAndListParam name, StringAndListParam given, + StringAndListParam family, StringAndListParam city, StringAndListParam state, StringAndListParam postalCode, + StringAndListParam country, TokenAndListParam id, DateRangeParam lastUpdated, HashSet revIncludes) { + + super(id, lastUpdated, null, null, revIncludes); + + this.identifier = identifier; + this.name = name; + this.given = given; + this.family = family; + this.city = city; + this.state = state; + this.postalCode = postalCode; + this.country = country; + } + + @Override + public SearchParameterMap toSearchParameterMap() { + return baseSearchParameterMap().addParameter(FhirConstants.IDENTIFIER_SEARCH_HANDLER, getIdentifier()) + .addParameter(FhirConstants.NAME_SEARCH_HANDLER, getName()) + .addParameter(FhirConstants.NAME_SEARCH_HANDLER, getGiven()) + .addParameter(FhirConstants.NAME_SEARCH_HANDLER, getFamily()) + .addParameter(FhirConstants.CITY_SEARCH_HANDLER, getCity()) + .addParameter(FhirConstants.STATE_SEARCH_HANDLER, getState()) + .addParameter(FhirConstants.POSTALCODE_SEARCH_HANDLER, getPostalCode()) + .addParameter(FhirConstants.COUNTRY_SEARCH_HANDLER, getCountry()); + } +} diff --git a/api/src/main/java/org/openmrs/module/fhir2/providers/r3/PractitionerFhirResourceProvider.java b/api/src/main/java/org/openmrs/module/fhir2/providers/r3/PractitionerFhirResourceProvider.java index 271e3c9c1..79efb4399 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/providers/r3/PractitionerFhirResourceProvider.java +++ b/api/src/main/java/org/openmrs/module/fhir2/providers/r3/PractitionerFhirResourceProvider.java @@ -47,6 +47,7 @@ import org.openmrs.module.fhir2.api.FhirPractitionerService; import org.openmrs.module.fhir2.api.annotations.R3Provider; import org.openmrs.module.fhir2.api.search.SearchQueryBundleProviderR3Wrapper; +import org.openmrs.module.fhir2.api.search.param.PractitionerSearchParams; import org.openmrs.module.fhir2.providers.util.FhirProviderUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -120,8 +121,9 @@ public IBundleProvider searchForPractitioners(@OptionalParam(name = Practitioner revIncludes = null; } - return new SearchQueryBundleProviderR3Wrapper(practitionerService.searchForPractitioners(identifier, name, given, - family, city, state, postalCode, country, id, lastUpdated, revIncludes)); + return new SearchQueryBundleProviderR3Wrapper( + practitionerService.searchForPractitioners(new PractitionerSearchParams(identifier, name, given, family, + city, state, postalCode, country, id, lastUpdated, revIncludes))); } } diff --git a/api/src/main/java/org/openmrs/module/fhir2/providers/r4/PractitionerFhirResourceProvider.java b/api/src/main/java/org/openmrs/module/fhir2/providers/r4/PractitionerFhirResourceProvider.java index c19db4838..4ecea9dd2 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/providers/r4/PractitionerFhirResourceProvider.java +++ b/api/src/main/java/org/openmrs/module/fhir2/providers/r4/PractitionerFhirResourceProvider.java @@ -48,6 +48,7 @@ import org.hl7.fhir.r4.model.ServiceRequest; import org.openmrs.module.fhir2.api.FhirPractitionerService; import org.openmrs.module.fhir2.api.annotations.R4Provider; +import org.openmrs.module.fhir2.api.search.param.PractitionerSearchParams; import org.openmrs.module.fhir2.providers.util.FhirProviderUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -129,7 +130,7 @@ public IBundleProvider searchForPractitioners(@OptionalParam(name = Practitioner revIncludes = null; } - return practitionerService.searchForPractitioners(identifier, name, given, family, city, state, postalCode, country, - id, lastUpdated, revIncludes); + return practitionerService.searchForPractitioners(new PractitionerSearchParams(identifier, name, given, family, city, + state, postalCode, country, id, lastUpdated, revIncludes)); } } diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirPractitionerServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirPractitionerServiceImplTest.java index 75979971d..84b950502 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirPractitionerServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirPractitionerServiceImplTest.java @@ -9,7 +9,6 @@ */ package org.openmrs.module.fhir2.api.impl; -import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.hasItem; @@ -63,6 +62,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.PractitionerSearchParams; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.PractitionerTranslator; @@ -220,8 +220,8 @@ public void shouldSearchForPractitionersByNameWhoIsProvider() { when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, name, null, null, null, null, null, null, - null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, name, null, null, null, null, null, null, null, null, null)); List resultList = get(results); assertThat(results, notNullValue()); @@ -239,8 +239,8 @@ public void shouldSearchForPractitionersByNameWhoIsUser() { when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider(practitioner2)); - IBundleProvider results = practitionerService.searchForPractitioners(null, name, null, null, null, null, null, null, - null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, name, null, null, null, null, null, null, null, null, null)); List resultList = get(results); @@ -263,8 +263,8 @@ public void shouldSearchForPractitionersByNameWhoIsUserAndProvider() { when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider(practitioner2)); - IBundleProvider results = practitionerService.searchForPractitioners(null, name, null, null, null, null, null, null, - null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, name, null, null, null, null, null, null, null, null, null)); List resultList = get(results); @@ -283,8 +283,8 @@ public void shouldReturnEmptyCollectionByWrongName() { when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, name, null, null, null, null, null, null, - null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, name, null, null, null, null, null, null, null, null, null)); List resultList = get(results); @@ -305,8 +305,8 @@ public void shouldSearchForPractitionersByIdentifier() { when(practitionerTranslator.toFhirResource(provider)).thenReturn(practitioner); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(identifier, null, null, null, null, null, null, - null, null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(identifier, null, null, null, null, null, null, null, null, null, null)); List resultList = get(results); @@ -326,8 +326,8 @@ public void shouldReturnEmptyCollectionByWrongIdentifier() { when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(identifier, null, null, null, null, null, null, - null, null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(identifier, null, null, null, null, null, null, null, null, null, null)); List resultList = get(results); @@ -350,8 +350,8 @@ public void shouldSearchForPractitionersByGivenNameWhoIsUserAndProvider() { when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider(practitioner2)); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, givenName, null, null, null, null, - null, null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, givenName, null, null, null, null, null, null, null, null)); List resultList = get(results); @@ -372,8 +372,8 @@ public void shouldReturnEmptyCollectionByWrongGivenName() { when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, givenName, null, null, null, null, - null, null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, givenName, null, null, null, null, null, null, null, null)); List resultList = get(results); @@ -395,8 +395,8 @@ public void shouldSearchForPractitionersByFamilyNameWhoIsProvider() { when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, familyName, null, null, null, - null, null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, familyName, null, null, null, null, null, null, null)); List resultList = get(results); @@ -415,8 +415,8 @@ public void shouldSearchForPractitionersByFamilyNameWhoIsUser() { practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude)); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider(practitioner2)); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, familyName, null, null, null, - null, null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, familyName, null, null, null, null, null, null, null)); List resultList = get(results); @@ -439,8 +439,8 @@ public void shouldSearchForPractitionersByFamilyNameWhoIsUserAndProvider() { when(practitionerTranslator.toFhirResource(provider)).thenReturn(practitioner); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider(practitioner2)); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, familyName, null, null, null, - null, null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, familyName, null, null, null, null, null, null, null)); List resultList = get(results); @@ -460,8 +460,8 @@ public void shouldReturnEmptyCollectionByWrongFamilyName() { practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude)); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, familyName, null, null, null, - null, null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, familyName, null, null, null, null, null, null, null)); List resultList = get(results); @@ -482,8 +482,8 @@ public void shouldSearchForPractitionersByAddressCity() { when(practitionerTranslator.toFhirResource(provider)).thenReturn(practitioner); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, city, null, null, null, - null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, city, null, null, null, null, null, null)); List resultList = get(results); @@ -503,8 +503,8 @@ public void shouldReturnEmptyCollectionByWrongAddressCity() { practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude)); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, city, null, null, null, - null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, city, null, null, null, null, null, null)); List resultList = get(results); @@ -525,8 +525,8 @@ public void shouldSearchForPractitionersByAddressState() { when(practitionerTranslator.toFhirResource(provider)).thenReturn(practitioner); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, null, state, null, null, - null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, state, null, null, null, null, null)); List resultList = get(results); @@ -546,8 +546,8 @@ public void shouldReturnEmptyCollectionByWrongAddressState() { practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude)); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, null, state, null, null, - null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, state, null, null, null, null, null)); List resultList = get(results); @@ -568,8 +568,8 @@ public void shouldSearchForPractitionersByAddressPostalCode() { when(practitionerTranslator.toFhirResource(provider)).thenReturn(practitioner); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, null, null, postalCode, - null, null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, postalCode, null, null, null, null)); List resultList = get(results); @@ -589,8 +589,8 @@ public void shouldReturnEmptyCollectionByWrongAddressPostalCode() { practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude)); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, null, null, postalCode, - null, null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, postalCode, null, null, null, null)); List resultList = get(results); @@ -611,8 +611,8 @@ public void shouldSearchForPractitionersByAddressCountry() { when(practitionerTranslator.toFhirResource(provider)).thenReturn(practitioner); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, null, null, null, - country, null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, country, null, null, null)); List resultList = get(results); @@ -632,8 +632,8 @@ public void shouldReturnEmptyCollectionByWrongAddressCountry() { practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude)); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, null, null, null, - country, null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, country, null, null, null)); List resultList = get(results); @@ -655,8 +655,8 @@ public void shouldSearchForPractitionersByUUID() { when(practitionerTranslator.toFhirResource(provider)).thenReturn(practitioner); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, null, null, null, null, - uuid, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, uuid, null, null)); List resultList = get(results); @@ -677,8 +677,8 @@ public void shouldReturnEmptyCollectionByWrongUUID() { practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude)); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, null, null, null, null, - uuid, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, uuid, null, null)); List resultList = get(results); @@ -700,8 +700,8 @@ public void shouldSearchForPractitionersByLastUpdated() { when(practitionerTranslator.toFhirResource(provider)).thenReturn(practitioner); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, null, null, null, null, - null, lastUpdated, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, null, lastUpdated, null)); List resultList = get(results); @@ -723,8 +723,8 @@ public void shouldReturnEmptyCollectionByWrongLastUpdated() { practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude)); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, null, null, null, null, - null, lastUpdated, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, null, lastUpdated, null)); List resultList = get(results); @@ -749,8 +749,8 @@ public void shouldAddRelatedResourcesToReturnedResultsWhenReverseIncluded() { when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, null, null, null, null, - null, null, revIncludes); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, null, null, revIncludes)); List resultList = get(results); @@ -775,8 +775,8 @@ public void shouldNotAddRelatedResourcesToReturnedResultsForEmptyReverseInclude( when(practitionerTranslator.toFhirResource(provider)).thenReturn(practitioner); when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider()); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, null, null, null, null, - null, null, revIncludes); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, null, null, revIncludes)); List resultList = get(results); @@ -805,8 +805,8 @@ public void shouldAddRelatedResourcesFromProviderAndUserWhenReverseIncluded() { when(userPractitionerSearchQueryBundleProvider.getResources(anyInt(), anyInt())) .thenReturn(Arrays.asList(practitioner2, new Encounter())); - IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, null, null, null, null, - null, null, revIncludes); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, null, null, revIncludes)); List resultList = get(results); diff --git a/api/src/test/java/org/openmrs/module/fhir2/providers/r3/PractitionerFhirResourceProviderTest.java b/api/src/test/java/org/openmrs/module/fhir2/providers/r3/PractitionerFhirResourceProviderTest.java index 03ce0e58b..6bdba2ec6 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/providers/r3/PractitionerFhirResourceProviderTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/providers/r3/PractitionerFhirResourceProviderTest.java @@ -19,9 +19,7 @@ import static org.hamcrest.Matchers.hasSize; 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; @@ -56,6 +54,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.FhirPractitionerService; +import org.openmrs.module.fhir2.api.search.param.PractitionerSearchParams; import org.openmrs.module.fhir2.providers.r4.MockIBundleProvider; @RunWith(MockitoJUnitRunner.class) @@ -175,8 +174,8 @@ public void getPractitionerByWithWrongId_shouldThrowResourceNotFoundException() public void findPractitionersByName_shouldReturnMatchingBundleOfPractitioners() { StringAndListParam nameParam = new StringAndListParam() .addAnd(new StringOrListParam().add(new StringParam(GIVEN_NAME))); - when(practitionerService.searchForPractitioners(isNull(), argThat(is(nameParam)), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn( + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, nameParam, null, null, null, null, null, null, null, null, null))).thenReturn( new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(nameParam, null, null, null, null, null, null, @@ -193,8 +192,8 @@ public void findPractitionersByName_shouldReturnMatchingBundleOfPractitioners() public void findPractitionersByWrongName_shouldReturnBundleWithEmptyEntries() { StringAndListParam nameParam = new StringAndListParam() .addAnd(new StringOrListParam().add(new StringParam(WRONG_NAME))); - when(practitionerService.searchForPractitioners(isNull(), argThat(is(nameParam)), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, nameParam, null, null, null, null, null, null, null, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(nameParam, null, null, null, null, null, null, @@ -209,12 +208,13 @@ public void findPractitionersByWrongName_shouldReturnBundleWithEmptyEntries() { @Test public void findPractitionersByIdentifier_shouldReturnMatchingBundleOfPractitioners() { TokenAndListParam identifier = new TokenAndListParam().addAnd(new TokenOrListParam().add(PRACTITIONER_IDENTIFIER)); - when(practitionerService.searchForPractitioners(argThat(is(identifier)), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(identifier, null, null, null, null, null, null, null, null, null, null))) + .thenReturn( + new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); - IBundleProvider results = practitionerService.searchForPractitioners(identifier, null, null, null, null, null, null, - null, null, null, null); + IBundleProvider results = practitionerService.searchForPractitioners( + new PractitionerSearchParams(identifier, null, null, null, null, null, null, null, null, null, null)); List resultList = get(results); @@ -227,8 +227,8 @@ public void findPractitionersByIdentifier_shouldReturnMatchingBundleOfPractition public void findPractitionersByWrongIdentifier_shouldReturnBundleWithEmptyEntries() { TokenAndListParam identifier = new TokenAndListParam() .addAnd(new TokenOrListParam().add(WRONG_PRACTITIONER_IDENTIFIER)); - when(practitionerService.searchForPractitioners(argThat(is(identifier)), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(identifier, null, null, null, null, null, null, null, null, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, identifier, null, null, null, null, null, @@ -243,8 +243,8 @@ public void findPractitionersByWrongIdentifier_shouldReturnBundleWithEmptyEntrie @Test public void findPractitionersByGivenName_shouldReturnMatchingBundleOfPractitioners() { StringAndListParam givenName = new StringAndListParam().addAnd(new StringParam(PRACTITIONER_GIVEN_NAME)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), argThat(is(givenName)), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn( + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, givenName, null, null, null, null, null, null, null, null))).thenReturn( new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, givenName, null, null, null, null, @@ -260,8 +260,8 @@ public void findPractitionersByGivenName_shouldReturnMatchingBundleOfPractitione @Test public void findPractitionersByWrongGivenName_shouldReturnBundleWithEmptyEntries() { StringAndListParam givenName = new StringAndListParam().addAnd(new StringParam(WRONG_GIVEN_NAME)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), argThat(is(givenName)), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, givenName, null, null, null, null, null, null, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, givenName, null, null, null, null, @@ -276,9 +276,10 @@ public void findPractitionersByWrongGivenName_shouldReturnBundleWithEmptyEntries @Test public void findPractitionersByFamilyName_shouldReturnMatchingBundleOfPractitioners() { StringAndListParam familyName = new StringAndListParam().addAnd(new StringParam(PRACTITIONER_FAMILY_NAME)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), argThat(is(familyName)), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, familyName, null, null, null, null, null, null, null))) + .thenReturn( + new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, familyName, null, null, null, null, null, null, null); @@ -293,8 +294,8 @@ public void findPractitionersByFamilyName_shouldReturnMatchingBundleOfPractition @Test public void findPractitionersByWrongFamilyName_shouldReturnBundleWithEmptyEntries() { StringAndListParam familyName = new StringAndListParam().addAnd(new StringParam(WRONG_FAMILY_NAME)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), argThat(is(familyName)), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, familyName, null, null, null, null, null, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, familyName, null, null, null, @@ -309,8 +310,8 @@ public void findPractitionersByWrongFamilyName_shouldReturnBundleWithEmptyEntrie @Test public void findPractitionersByAddressCity_shouldReturnMatchingBundleOfPractitioners() { StringAndListParam city = new StringAndListParam().addAnd(new StringParam(CITY)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), argThat(is(city)), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn( + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, city, null, null, null, null, null, null))).thenReturn( new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, city, null, null, null, @@ -326,8 +327,8 @@ public void findPractitionersByAddressCity_shouldReturnMatchingBundleOfPractitio @Test public void findPractitionersByWrongAddressCity_shouldReturnBundleWithEmptyEntries() { StringAndListParam city = new StringAndListParam().addAnd(new StringParam(WRONG_CITY)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), argThat(is(city)), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, city, null, null, null, null, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, city, null, null, null, @@ -342,8 +343,8 @@ public void findPractitionersByWrongAddressCity_shouldReturnBundleWithEmptyEntri @Test public void findPractitionersByAddressState_shouldReturnMatchingBundleOfPractitioners() { StringAndListParam state = new StringAndListParam().addAnd(new StringParam(STATE)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), argThat(is(state)), - isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn( + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, state, null, null, null, null, null))).thenReturn( new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, state, null, null, @@ -359,8 +360,8 @@ public void findPractitionersByAddressState_shouldReturnMatchingBundleOfPractiti @Test public void findPractitionersByWrongAddressState_shouldReturnBundleWithEmptyEntries() { StringAndListParam state = new StringAndListParam().addAnd(new StringParam(WRONG_STATE)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), argThat(is(state)), - isNull(), isNull(), isNull(), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, state, null, null, null, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, state, null, null, @@ -375,9 +376,10 @@ public void findPractitionersByWrongAddressState_shouldReturnBundleWithEmptyEntr @Test public void findPractitionersByAddressPostalCode_shouldReturnMatchingBundleOfPractitioners() { StringAndListParam postalCode = new StringAndListParam().addAnd(new StringParam(POSTAL_CODE)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - argThat(is(postalCode)), isNull(), isNull(), isNull(), isNull())).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, postalCode, null, null, null, null))) + .thenReturn( + new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, postalCode, null, null, null, null); @@ -392,8 +394,8 @@ public void findPractitionersByAddressPostalCode_shouldReturnMatchingBundleOfPra @Test public void findPractitionersByWrongAddressPostalCode_shouldReturnBundleWithEmptyEntries() { StringAndListParam postalCode = new StringAndListParam().addAnd(new StringParam(WRONG_POSTAL_CODE)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - argThat(is(postalCode)), isNull(), isNull(), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, postalCode, null, null, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, postalCode, @@ -408,8 +410,8 @@ public void findPractitionersByWrongAddressPostalCode_shouldReturnBundleWithEmpt @Test public void findPractitionersByAddressCountry_shouldReturnMatchingBundleOfPractitioners() { StringAndListParam country = new StringAndListParam().addAnd(new StringParam(COUNTRY)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - argThat(is(country)), isNull(), isNull(), isNull())).thenReturn( + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, country, null, null, null))).thenReturn( new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, null, country, @@ -425,8 +427,8 @@ public void findPractitionersByAddressCountry_shouldReturnMatchingBundleOfPracti @Test public void findPractitionersByWrongAddressCountry_shouldReturnBundleWithEmptyEntries() { StringAndListParam country = new StringAndListParam().addAnd(new StringParam(WRONG_COUNTRY)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - argThat(is(country)), isNull(), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, country, null, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, null, country, @@ -441,8 +443,8 @@ public void findPractitionersByWrongAddressCountry_shouldReturnBundleWithEmptyEn @Test public void findPractitionersByUUID_shouldReturnMatchingBundleOfPractitioners() { TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(PRACTITIONER_UUID)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), argThat(is(uuid)), isNull(), isNull())).thenReturn( + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, uuid, null, null))).thenReturn( new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, null, null, @@ -458,8 +460,8 @@ public void findPractitionersByUUID_shouldReturnMatchingBundleOfPractitioners() @Test public void findPractitionersByWrongUUID_shouldReturnBundleWithEmptyEntries() { TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(WRONG_PRACTITIONER_UUID)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), argThat(is(uuid)), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, uuid, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, null, null, @@ -474,9 +476,10 @@ public void findPractitionersByWrongUUID_shouldReturnBundleWithEmptyEntries() { @Test public void findPractitionersByLastUpdated_shouldReturnMatchingBundleOfPractitioners() { DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(LAST_UPDATED_DATE).setLowerBound(LAST_UPDATED_DATE); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), argThat(is(lastUpdated)), isNull())).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, null, lastUpdated, null))) + .thenReturn( + new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, null, null, null, lastUpdated, null); @@ -492,8 +495,8 @@ public void findPractitionersByLastUpdated_shouldReturnMatchingBundleOfPractitio public void findPractitionersByWrongLastUpdated_shouldReturnBundleWithEmptyEntries() { DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(WRONG_LAST_UPDATED_DATE) .setLowerBound(WRONG_LAST_UPDATED_DATE); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), argThat(is(lastUpdated)), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, null, lastUpdated, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, null, null, @@ -510,9 +513,10 @@ public void findPractitioners_shouldAddRelatedResourcesWhenReverseIncluded() { HashSet revIncludes = new HashSet<>(); revIncludes.add(new Include("Encounter:participant")); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), argThat(is(revIncludes)))).thenReturn( - new MockIBundleProvider<>(Arrays.asList(practitioner, new Encounter()), PREFERRED_PAGE_SIZE, COUNT)); + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, null, null, revIncludes))) + .thenReturn( + new MockIBundleProvider<>(Arrays.asList(practitioner, new Encounter()), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, null, null, null, null, revIncludes); @@ -530,8 +534,8 @@ public void findPractitioners_shouldAddRelatedResourcesWhenReverseIncluded() { public void findPractitioners_shouldNotAddRelatedResourcesForEmptyReverseInclude() { HashSet revIncludes = new HashSet<>(); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull())).thenReturn( + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, null, null, null))).thenReturn( new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, null, null, diff --git a/api/src/test/java/org/openmrs/module/fhir2/providers/r4/PractitionerFhirResourceProviderTest.java b/api/src/test/java/org/openmrs/module/fhir2/providers/r4/PractitionerFhirResourceProviderTest.java index 24216a8d8..23c47c767 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/providers/r4/PractitionerFhirResourceProviderTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/providers/r4/PractitionerFhirResourceProviderTest.java @@ -17,9 +17,7 @@ import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.hasSize; -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; @@ -53,6 +51,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.FhirPractitionerService; +import org.openmrs.module.fhir2.api.search.param.PractitionerSearchParams; import org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest; @RunWith(MockitoJUnitRunner.class) @@ -172,8 +171,8 @@ public void getPractitionerByWithWrongId_shouldThrowResourceNotFoundException() public void findPractitionersByName_shouldReturnMatchingBundleOfPractitioners() { StringAndListParam nameParam = new StringAndListParam() .addAnd(new StringOrListParam().add(new StringParam(GIVEN_NAME))); - when(practitionerService.searchForPractitioners(isNull(), argThat(is(nameParam)), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn( + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, nameParam, null, null, null, null, null, null, null, null, null))).thenReturn( new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(nameParam, null, null, null, null, null, null, @@ -190,8 +189,8 @@ public void findPractitionersByName_shouldReturnMatchingBundleOfPractitioners() public void findPractitionersByWrongName_shouldReturnBundleWithEmptyEntries() { StringAndListParam nameParam = new StringAndListParam() .addAnd(new StringOrListParam().add(new StringParam(WRONG_NAME))); - when(practitionerService.searchForPractitioners(isNull(), argThat(is(nameParam)), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, nameParam, null, null, null, null, null, null, null, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(nameParam, null, null, null, null, null, null, @@ -206,9 +205,10 @@ public void findPractitionersByWrongName_shouldReturnBundleWithEmptyEntries() { @Test public void findPractitionersByIdentifier_shouldReturnMatchingBundleOfPractitioners() { TokenAndListParam identifier = new TokenAndListParam().addAnd(new TokenOrListParam().add(PRACTITIONER_IDENTIFIER)); - when(practitionerService.searchForPractitioners(argThat(is(identifier)), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(identifier, null, null, null, null, null, null, null, null, null, null))) + .thenReturn( + new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, identifier, null, null, null, null, null, null, null, null, null); @@ -224,8 +224,8 @@ public void findPractitionersByIdentifier_shouldReturnMatchingBundleOfPractition public void findPractitionersByWrongIdentifier_shouldReturnBundleWithEmptyEntries() { TokenAndListParam identifier = new TokenAndListParam() .addAnd(new TokenOrListParam().add(WRONG_PRACTITIONER_IDENTIFIER)); - when(practitionerService.searchForPractitioners(argThat(is(identifier)), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(identifier, null, null, null, null, null, null, null, null, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, identifier, null, null, null, null, null, @@ -240,8 +240,8 @@ public void findPractitionersByWrongIdentifier_shouldReturnBundleWithEmptyEntrie @Test public void findPractitionersByGivenName_shouldReturnMatchingBundleOfPractitioners() { StringAndListParam givenName = new StringAndListParam().addAnd(new StringParam(PRACTITIONER_GIVEN_NAME)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), argThat(is(givenName)), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn( + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, givenName, null, null, null, null, null, null, null, null))).thenReturn( new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, givenName, null, null, null, null, @@ -257,8 +257,8 @@ public void findPractitionersByGivenName_shouldReturnMatchingBundleOfPractitione @Test public void findPractitionersByWrongGivenName_shouldReturnBundleWithEmptyEntries() { StringAndListParam givenName = new StringAndListParam().addAnd(new StringParam(WRONG_GIVEN_NAME)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), argThat(is(givenName)), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, givenName, null, null, null, null, null, null, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, givenName, null, null, null, null, @@ -273,9 +273,10 @@ public void findPractitionersByWrongGivenName_shouldReturnBundleWithEmptyEntries @Test public void findPractitionersByFamilyName_shouldReturnMatchingBundleOfPractitioners() { StringAndListParam familyName = new StringAndListParam().addAnd(new StringParam(PRACTITIONER_FAMILY_NAME)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), argThat(is(familyName)), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, familyName, null, null, null, null, null, null, null))) + .thenReturn( + new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, familyName, null, null, null, null, null, null, null); @@ -290,8 +291,8 @@ public void findPractitionersByFamilyName_shouldReturnMatchingBundleOfPractition @Test public void findPractitionersByWrongFamilyName_shouldReturnBundleWithEmptyEntries() { StringAndListParam familyName = new StringAndListParam().addAnd(new StringParam(WRONG_FAMILY_NAME)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), argThat(is(familyName)), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, familyName, null, null, null, null, null, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, familyName, null, null, null, @@ -306,8 +307,8 @@ public void findPractitionersByWrongFamilyName_shouldReturnBundleWithEmptyEntrie @Test public void findPractitionersByAddressCity_shouldReturnMatchingBundleOfPractitioners() { StringAndListParam city = new StringAndListParam().addAnd(new StringParam(CITY)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), argThat(is(city)), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn( + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, city, null, null, null, null, null, null))).thenReturn( new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, city, null, null, null, @@ -323,8 +324,8 @@ public void findPractitionersByAddressCity_shouldReturnMatchingBundleOfPractitio @Test public void findPractitionersByWrongAddressCity_shouldReturnBundleWithEmptyEntries() { StringAndListParam city = new StringAndListParam().addAnd(new StringParam(WRONG_CITY)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), argThat(is(city)), isNull(), - isNull(), isNull(), isNull(), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, city, null, null, null, null, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, city, null, null, null, @@ -339,8 +340,8 @@ public void findPractitionersByWrongAddressCity_shouldReturnBundleWithEmptyEntri @Test public void findPractitionersByAddressState_shouldReturnMatchingBundleOfPractitioners() { StringAndListParam state = new StringAndListParam().addAnd(new StringParam(STATE)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), argThat(is(state)), - isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn( + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, state, null, null, null, null, null))).thenReturn( new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, state, null, null, @@ -356,8 +357,8 @@ public void findPractitionersByAddressState_shouldReturnMatchingBundleOfPractiti @Test public void findPractitionersByWrongAddressState_shouldReturnBundleWithEmptyEntries() { StringAndListParam state = new StringAndListParam().addAnd(new StringParam(WRONG_STATE)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), argThat(is(state)), - isNull(), isNull(), isNull(), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, state, null, null, null, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, state, null, null, @@ -372,9 +373,10 @@ public void findPractitionersByWrongAddressState_shouldReturnBundleWithEmptyEntr @Test public void findPractitionersByAddressPostalCode_shouldReturnMatchingBundleOfPractitioners() { StringAndListParam postalCode = new StringAndListParam().addAnd(new StringParam(POSTAL_CODE)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - argThat(is(postalCode)), isNull(), isNull(), isNull(), isNull())).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, postalCode, null, null, null, null))) + .thenReturn( + new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, postalCode, null, null, null, null); @@ -389,8 +391,8 @@ public void findPractitionersByAddressPostalCode_shouldReturnMatchingBundleOfPra @Test public void findPractitionersByWrongAddressPostalCode_shouldReturnBundleWithEmptyEntries() { StringAndListParam postalCode = new StringAndListParam().addAnd(new StringParam(WRONG_POSTAL_CODE)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - argThat(is(postalCode)), isNull(), isNull(), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, postalCode, null, null, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, postalCode, @@ -405,8 +407,8 @@ public void findPractitionersByWrongAddressPostalCode_shouldReturnBundleWithEmpt @Test public void findPractitionersByAddressCountry_shouldReturnMatchingBundleOfPractitioners() { StringAndListParam country = new StringAndListParam().addAnd(new StringParam(COUNTRY)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - argThat(is(country)), isNull(), isNull(), isNull())).thenReturn( + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, country, null, null, null))).thenReturn( new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, null, country, @@ -422,8 +424,8 @@ public void findPractitionersByAddressCountry_shouldReturnMatchingBundleOfPracti @Test public void findPractitionersByWrongAddressCountry_shouldReturnBundleWithEmptyEntries() { StringAndListParam country = new StringAndListParam().addAnd(new StringParam(WRONG_COUNTRY)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - argThat(is(country)), isNull(), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, country, null, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, null, country, @@ -438,8 +440,8 @@ public void findPractitionersByWrongAddressCountry_shouldReturnBundleWithEmptyEn @Test public void findPractitionersByUUID_shouldReturnMatchingBundleOfPractitioners() { TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(PRACTITIONER_UUID)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), argThat(is(uuid)), isNull(), isNull())).thenReturn( + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, uuid, null, null))).thenReturn( new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, null, null, @@ -455,8 +457,8 @@ public void findPractitionersByUUID_shouldReturnMatchingBundleOfPractitioners() @Test public void findPractitionersByWrongUUID_shouldReturnBundleWithEmptyEntries() { TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(WRONG_PRACTITIONER_UUID)); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), argThat(is(uuid)), isNull(), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, uuid, null, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, null, null, @@ -471,9 +473,10 @@ public void findPractitionersByWrongUUID_shouldReturnBundleWithEmptyEntries() { @Test public void findPractitionersByLastUpdated_shouldReturnMatchingBundleOfPractitioners() { DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(LAST_UPDATED_DATE).setLowerBound(LAST_UPDATED_DATE); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), argThat(is(lastUpdated)), isNull())).thenReturn( - new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, null, lastUpdated, null))) + .thenReturn( + new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, null, null, null, lastUpdated, null); @@ -489,8 +492,8 @@ public void findPractitionersByLastUpdated_shouldReturnMatchingBundleOfPractitio public void findPractitionersByWrongLastUpdated_shouldReturnBundleWithEmptyEntries() { DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(WRONG_LAST_UPDATED_DATE) .setLowerBound(WRONG_LAST_UPDATED_DATE); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), argThat(is(lastUpdated)), isNull())) + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, null, lastUpdated, null))) .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, null, null, @@ -507,9 +510,10 @@ public void findPractitioners_shouldAddRelatedResourcesWhenReverseIncluded() { HashSet revIncludes = new HashSet<>(); revIncludes.add(new Include("Encounter:participant")); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), argThat(is(revIncludes)))).thenReturn( - new MockIBundleProvider<>(Arrays.asList(practitioner, new Encounter()), PREFERRED_PAGE_SIZE, COUNT)); + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, null, null, revIncludes))) + .thenReturn( + new MockIBundleProvider<>(Arrays.asList(practitioner, new Encounter()), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, null, null, null, null, revIncludes); @@ -527,8 +531,8 @@ public void findPractitioners_shouldAddRelatedResourcesWhenReverseIncluded() { public void findPractitioners_shouldNotAddRelatedResourcesForEmptyReverseInclude() { HashSet revIncludes = new HashSet<>(); - when(practitionerService.searchForPractitioners(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), - isNull(), isNull(), isNull(), isNull())).thenReturn( + when(practitionerService.searchForPractitioners( + new PractitionerSearchParams(null, null, null, null, null, null, null, null, null, null, null))).thenReturn( new MockIBundleProvider<>(Collections.singletonList(practitioner), PREFERRED_PAGE_SIZE, COUNT)); IBundleProvider results = resourceProvider.searchForPractitioners(null, null, null, null, null, null, null, null, diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/PractitionerFhirResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/PractitionerFhirResourceProviderIntegrationTest.java index 3be6c235a..8235200ba 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/PractitionerFhirResourceProviderIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/PractitionerFhirResourceProviderIntegrationTest.java @@ -385,7 +385,7 @@ public void shouldPatchExistingPractitionerUsingJsonMergePatch() throws Exceptio } MockHttpServletResponse response = patch("/Practitioner/" + PRACTITIONER_UUID).jsonMergePatch(jsonPractitionerPatch) - .accept(FhirMediaTypes.JSON).go(); + .accept(FhirMediaTypes.JSON).go(); assertThat(response, isOk()); assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); @@ -409,7 +409,7 @@ public void shouldPatchExistingPractitionerUsingJsonPatch() throws Exception { } MockHttpServletResponse response = patch("/Practitioner/" + PRACTITIONER_UUID).jsonPatch(jsonPractitionerPatch) - .accept(FhirMediaTypes.JSON).go(); + .accept(FhirMediaTypes.JSON).go(); assertThat(response, isOk()); assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); diff --git a/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/PractitionerFhirResourceProviderWebTest.java b/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/PractitionerFhirResourceProviderWebTest.java index 1651db090..7912c1eab 100644 --- a/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/PractitionerFhirResourceProviderWebTest.java +++ b/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/PractitionerFhirResourceProviderWebTest.java @@ -32,13 +32,8 @@ import java.io.InputStream; import java.util.Calendar; import java.util.Collections; -import java.util.HashSet; import java.util.Objects; -import ca.uhn.fhir.model.api.Include; -import ca.uhn.fhir.rest.param.DateRangeParam; -import ca.uhn.fhir.rest.param.StringAndListParam; -import ca.uhn.fhir.rest.param.TokenAndListParam; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import lombok.AccessLevel; import lombok.Getter; @@ -55,6 +50,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.FhirPractitionerService; +import org.openmrs.module.fhir2.api.search.param.PractitionerSearchParams; import org.openmrs.module.fhir2.providers.r4.MockIBundleProvider; import org.springframework.mock.web.MockHttpServletResponse; @@ -98,16 +94,7 @@ public class PractitionerFhirResourceProviderWebTest extends BaseFhirR3ResourceP private FhirPractitionerService practitionerService; @Captor - private ArgumentCaptor stringAndListParamArgumentCaptor; - - @Captor - private ArgumentCaptor tokenAndListParamArgumentCaptor; - - @Captor - private ArgumentCaptor dateRangeParamArgumentCaptor; - - @Captor - private ArgumentCaptor> includeArgumentCaptor; + private ArgumentCaptor practitionerSearchParamsArgumentCaptor; @Before @Override @@ -142,13 +129,12 @@ public void getEncounterByWrongUuid_shouldReturn404() throws Exception { public void findPractitionersByName_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?name=%s", NAME)); - verify(practitionerService).searchForPractitioners(any(), stringAndListParamArgumentCaptor.capture(), any(), any(), - any(), any(), any(), any(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(stringAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens() - .get(0).getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getName(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getName().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getName().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(NAME)); } @@ -156,13 +142,12 @@ public void findPractitionersByName_shouldReturnBundleOfPractitioners() throws E public void findPractitionersByIdentifier_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?identifier=%s", PRACTITIONER_IDENTIFIER)); - verify(practitionerService).searchForPractitioners(tokenAndListParamArgumentCaptor.capture(), any(), any(), any(), - any(), any(), any(), any(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(tokenAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0) - .getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getIdentifier(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getIdentifier().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getIdentifier().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(PRACTITIONER_IDENTIFIER)); } @@ -170,13 +155,12 @@ public void findPractitionersByIdentifier_shouldReturnBundleOfPractitioners() th public void findPractitionersByGivenName_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?given=%s", PRACTITIONER_GIVEN_NAME)); - verify(practitionerService).searchForPractitioners(any(), any(), stringAndListParamArgumentCaptor.capture(), any(), - any(), any(), any(), any(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(stringAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens() - .get(0).getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getGiven(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getGiven().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getGiven().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(PRACTITIONER_GIVEN_NAME)); } @@ -184,13 +168,12 @@ public void findPractitionersByGivenName_shouldReturnBundleOfPractitioners() thr public void findPractitionersByFamilyName_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?family=%s", PRACTITIONER_FAMILY_NAME)); - verify(practitionerService).searchForPractitioners(any(), any(), any(), stringAndListParamArgumentCaptor.capture(), - any(), any(), any(), any(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(stringAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens() - .get(0).getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getFamily(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getFamily().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getFamily().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(PRACTITIONER_FAMILY_NAME)); } @@ -198,13 +181,12 @@ public void findPractitionersByFamilyName_shouldReturnBundleOfPractitioners() th public void findPractitionersByAddressCity_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?address-city=%s", CITY)); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), - stringAndListParamArgumentCaptor.capture(), any(), any(), any(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(stringAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens() - .get(0).getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getCity(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getCity().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getCity().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(CITY)); } @@ -212,13 +194,12 @@ public void findPractitionersByAddressCity_shouldReturnBundleOfPractitioners() t public void findPractitionersByAddressState_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?address-state=%s", STATE)); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), - stringAndListParamArgumentCaptor.capture(), any(), any(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(stringAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens() - .get(0).getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getState(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getState().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getState().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(STATE)); } @@ -226,13 +207,12 @@ public void findPractitionersByAddressState_shouldReturnBundleOfPractitioners() public void findPractitionersByAddressPostalCode_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?address-postalcode=%s", POSTAL_CODE)); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), - stringAndListParamArgumentCaptor.capture(), any(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(stringAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens() - .get(0).getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getPostalCode(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getPostalCode().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getPostalCode().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(POSTAL_CODE)); } @@ -240,13 +220,12 @@ public void findPractitionersByAddressPostalCode_shouldReturnBundleOfPractitione public void findPractitionersByAddressCountry_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?address-country=%s", COUNTRY)); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), - stringAndListParamArgumentCaptor.capture(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(stringAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens() - .get(0).getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getCountry(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getCountry().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getCountry().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(COUNTRY)); } @@ -254,13 +233,12 @@ public void findPractitionersByAddressCountry_shouldReturnBundleOfPractitioners( public void findPractitionersByUUID_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?_id=%s", PRACTITIONER_UUID)); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), any(), - tokenAndListParamArgumentCaptor.capture(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(tokenAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0) - .getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getId(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getId().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getId().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(PRACTITIONER_UUID)); } @@ -268,17 +246,16 @@ public void findPractitionersByUUID_shouldReturnBundleOfPractitioners() throws E public void findPractitionersByLastUpdatedDate_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?_lastUpdated=%s", LAST_UPDATED_DATE)); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), any(), any(), - dateRangeParamArgumentCaptor.capture(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(dateRangeParamArgumentCaptor.getValue(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getLastUpdated(), notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(2020, Calendar.SEPTEMBER, 3); - assertThat(dateRangeParamArgumentCaptor.getValue().getLowerBound().getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getLastUpdated().getLowerBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); - assertThat(dateRangeParamArgumentCaptor.getValue().getUpperBound().getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getLastUpdated().getUpperBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); } @@ -286,28 +263,27 @@ public void findPractitionersByLastUpdatedDate_shouldReturnBundleOfPractitioners public void findPractitioners_shouldReverseIncludeEncounters() throws Exception { verifyUri("/Practitioner?_revinclude=Encounter:participant"); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), any(), any(), - any(), includeArgumentCaptor.capture()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(includeArgumentCaptor.getValue(), notNullValue()); - assertThat(includeArgumentCaptor.getValue().size(), equalTo(1)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamName(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().size(), equalTo(1)); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_PARTICIPANT_PARAM)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamType(), equalTo(FhirConstants.ENCOUNTER)); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().iterator().next().getParamType(), + equalTo(FhirConstants.ENCOUNTER)); } @Test public void findPractitioners_shouldReverseIncludeMedicationRequests() throws Exception { verifyUri("/Practitioner?_revinclude=MedicationRequest:requester"); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), any(), any(), - any(), includeArgumentCaptor.capture()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(includeArgumentCaptor.getValue(), notNullValue()); - assertThat(includeArgumentCaptor.getValue().size(), equalTo(1)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamName(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().size(), equalTo(1)); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_REQUESTER_PARAM)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamType(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().iterator().next().getParamType(), equalTo(FhirConstants.MEDICATION_REQUEST)); } @@ -315,14 +291,13 @@ public void findPractitioners_shouldReverseIncludeMedicationRequests() throws Ex public void findPractitioners_shouldReverseIncludeProcedureRequests() throws Exception { verifyUri("/Practitioner?_revinclude=ProcedureRequest:requester"); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), any(), any(), - any(), includeArgumentCaptor.capture()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(includeArgumentCaptor.getValue(), notNullValue()); - assertThat(includeArgumentCaptor.getValue().size(), equalTo(1)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamName(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().size(), equalTo(1)); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_REQUESTER_PARAM)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamType(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().iterator().next().getParamType(), equalTo(FhirConstants.PROCEDURE_REQUEST)); } @@ -330,15 +305,14 @@ public void findPractitioners_shouldReverseIncludeProcedureRequests() throws Exc public void findPractitioners_shouldHandleMultipleReverseIncludes() throws Exception { verifyUri("/Practitioner?_revinclude=ProcedureRequest:requester&_revinclude=Encounter:participant"); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), any(), any(), - any(), includeArgumentCaptor.capture()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(includeArgumentCaptor.getValue(), notNullValue()); - assertThat(includeArgumentCaptor.getValue().size(), equalTo(2)); - assertThat(includeArgumentCaptor.getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().size(), equalTo(2)); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_REQUESTER_PARAM)), hasProperty("paramType", equalTo(FhirConstants.PROCEDURE_REQUEST))))); - assertThat(includeArgumentCaptor.getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_PARTICIPANT_PARAM)), hasProperty("paramType", equalTo(FhirConstants.ENCOUNTER))))); } @@ -348,15 +322,14 @@ public void findPractitioners_shouldAddReverseIncludedMedicationRequestsWithIter throws Exception { verifyUri("/Practitioner?_revinclude=MedicationRequest:requester&_revinclude=MedicationDispense:prescription"); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), any(), any(), - any(), includeArgumentCaptor.capture()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(includeArgumentCaptor.getValue(), notNullValue()); - assertThat(includeArgumentCaptor.getValue().size(), equalTo(2)); - assertThat(includeArgumentCaptor.getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().size(), equalTo(2)); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_REQUESTER_PARAM)), hasProperty("paramType", equalTo(FhirConstants.MEDICATION_REQUEST))))); - assertThat(includeArgumentCaptor.getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_PRESCRIPTION_PARAM)), hasProperty("paramType", equalTo(FhirConstants.MEDICATION_DISPENSE))))); } @@ -365,27 +338,26 @@ public void findPractitioners_shouldAddReverseIncludedMedicationRequestsWithIter public void findPractitioners_shouldHandleComplexQuery() throws Exception { verifyUri(String.format("/Practitioner?identifier=%s&name=%s", PRACTITIONER_IDENTIFIER, NAME)); - verify(practitionerService).searchForPractitioners(tokenAndListParamArgumentCaptor.capture(), - stringAndListParamArgumentCaptor.capture(), any(), any(), any(), any(), any(), any(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(stringAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens() - .get(0).getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getName(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getName().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getName().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(NAME)); - assertThat(tokenAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0) - .getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getIdentifier(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getIdentifier().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getIdentifier().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(PRACTITIONER_IDENTIFIER)); } private void verifyUri(String uri) throws Exception { Practitioner practitioner = new Practitioner(); practitioner.setId(PRACTITIONER_UUID); - when(practitionerService.searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), - any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(practitioner), 10, 1)); + when(practitionerService.searchForPractitioners(any())) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(practitioner), 10, 1)); MockHttpServletResponse response = get(uri).accept(FhirMediaTypes.JSON).go(); diff --git a/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/PractitionerFhirResourceProviderWebTest.java b/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/PractitionerFhirResourceProviderWebTest.java index 6b32836e0..9a8528a38 100644 --- a/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/PractitionerFhirResourceProviderWebTest.java +++ b/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/PractitionerFhirResourceProviderWebTest.java @@ -32,13 +32,9 @@ import java.io.InputStream; import java.util.Calendar; import java.util.Collections; -import java.util.HashSet; import java.util.Objects; -import ca.uhn.fhir.model.api.Include; -import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.StringAndListParam; -import ca.uhn.fhir.rest.param.TokenAndListParam; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import lombok.AccessLevel; import lombok.Getter; @@ -55,6 +51,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.FhirPractitionerService; +import org.openmrs.module.fhir2.api.search.param.PractitionerSearchParams; import org.springframework.mock.web.MockHttpServletResponse; @RunWith(MockitoJUnitRunner.class) @@ -97,16 +94,7 @@ public class PractitionerFhirResourceProviderWebTest extends BaseFhirR4ResourceP private FhirPractitionerService practitionerService; @Captor - private ArgumentCaptor stringAndListParamArgumentCaptor; - - @Captor - private ArgumentCaptor tokenAndListParamArgumentCaptor; - - @Captor - private ArgumentCaptor dateRangeParamArgumentCaptor; - - @Captor - private ArgumentCaptor> includeArgumentCaptor; + private ArgumentCaptor practitionerSearchParamsArgumentCaptor; @Before @Override @@ -141,27 +129,24 @@ public void getEncounterByWrongUuid_shouldReturn404() throws Exception { public void findPractitionersByName_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?name=%s", NAME)); - verify(practitionerService).searchForPractitioners(any(), stringAndListParamArgumentCaptor.capture(), any(), any(), - any(), any(), any(), any(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); + StringAndListParam name = practitionerSearchParamsArgumentCaptor.getValue().getName(); - assertThat(stringAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens() - .get(0).getValue(), - equalTo(NAME)); + assertThat(name, notNullValue()); + assertThat(name.getValuesAsQueryTokens(), not(empty())); + assertThat(name.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(), equalTo(NAME)); } @Test public void findPractitionersByIdentifier_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?identifier=%s", PRACTITIONER_IDENTIFIER)); - verify(practitionerService).searchForPractitioners(tokenAndListParamArgumentCaptor.capture(), any(), any(), any(), - any(), any(), any(), any(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(tokenAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0) - .getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getIdentifier(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getIdentifier().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getIdentifier().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(PRACTITIONER_IDENTIFIER)); } @@ -169,13 +154,12 @@ public void findPractitionersByIdentifier_shouldReturnBundleOfPractitioners() th public void findPractitionersByGivenName_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?given=%s", PRACTITIONER_GIVEN_NAME)); - verify(practitionerService).searchForPractitioners(any(), any(), stringAndListParamArgumentCaptor.capture(), any(), - any(), any(), any(), any(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(stringAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens() - .get(0).getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getGiven(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getGiven().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getGiven().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(PRACTITIONER_GIVEN_NAME)); } @@ -183,13 +167,12 @@ public void findPractitionersByGivenName_shouldReturnBundleOfPractitioners() thr public void findPractitionersByFamilyName_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?family=%s", PRACTITIONER_FAMILY_NAME)); - verify(practitionerService).searchForPractitioners(any(), any(), any(), stringAndListParamArgumentCaptor.capture(), - any(), any(), any(), any(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(stringAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens() - .get(0).getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getFamily(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getFamily().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getFamily().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(PRACTITIONER_FAMILY_NAME)); } @@ -197,13 +180,12 @@ public void findPractitionersByFamilyName_shouldReturnBundleOfPractitioners() th public void findPractitionersByAddressCity_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?address-city=%s", CITY)); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), - stringAndListParamArgumentCaptor.capture(), any(), any(), any(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(stringAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens() - .get(0).getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getCity(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getCity().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getCity().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(CITY)); } @@ -211,13 +193,12 @@ public void findPractitionersByAddressCity_shouldReturnBundleOfPractitioners() t public void findPractitionersByAddressState_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?address-state=%s", STATE)); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), - stringAndListParamArgumentCaptor.capture(), any(), any(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(stringAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens() - .get(0).getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getState(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getState().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getState().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(STATE)); } @@ -225,13 +206,12 @@ public void findPractitionersByAddressState_shouldReturnBundleOfPractitioners() public void findPractitionersByAddressPostalCode_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?address-postalcode=%s", POSTAL_CODE)); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), - stringAndListParamArgumentCaptor.capture(), any(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(stringAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens() - .get(0).getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getPostalCode(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getPostalCode().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getPostalCode().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(POSTAL_CODE)); } @@ -239,13 +219,12 @@ public void findPractitionersByAddressPostalCode_shouldReturnBundleOfPractitione public void findPractitionersByAddressCountry_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?address-country=%s", COUNTRY)); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), - stringAndListParamArgumentCaptor.capture(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(stringAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens() - .get(0).getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getCountry(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getCountry().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getCountry().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(COUNTRY)); } @@ -253,13 +232,12 @@ public void findPractitionersByAddressCountry_shouldReturnBundleOfPractitioners( public void findPractitionersByUUID_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?_id=%s", PRACTITIONER_UUID)); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), any(), - tokenAndListParamArgumentCaptor.capture(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(tokenAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0) - .getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getId(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getId().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getId().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(PRACTITIONER_UUID)); } @@ -267,17 +245,16 @@ public void findPractitionersByUUID_shouldReturnBundleOfPractitioners() throws E public void findPractitionersByLastUpdatedDate_shouldReturnBundleOfPractitioners() throws Exception { verifyUri(String.format("/Practitioner?_lastUpdated=%s", LAST_UPDATED_DATE)); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), any(), any(), - dateRangeParamArgumentCaptor.capture(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(dateRangeParamArgumentCaptor.getValue(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getLastUpdated(), notNullValue()); Calendar calendar = Calendar.getInstance(); calendar.set(2020, Calendar.SEPTEMBER, 3); - assertThat(dateRangeParamArgumentCaptor.getValue().getLowerBound().getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getLastUpdated().getLowerBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); - assertThat(dateRangeParamArgumentCaptor.getValue().getUpperBound().getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getLastUpdated().getUpperBound().getValue(), equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE))); } @@ -285,28 +262,27 @@ public void findPractitionersByLastUpdatedDate_shouldReturnBundleOfPractitioners public void findPractitioners_shouldReverseIncludeEncounters() throws Exception { verifyUri("/Practitioner?_revinclude=Encounter:participant"); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), any(), any(), - any(), includeArgumentCaptor.capture()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(includeArgumentCaptor.getValue(), notNullValue()); - assertThat(includeArgumentCaptor.getValue().size(), equalTo(1)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamName(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().size(), equalTo(1)); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_PARTICIPANT_PARAM)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamType(), equalTo(FhirConstants.ENCOUNTER)); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().iterator().next().getParamType(), + equalTo(FhirConstants.ENCOUNTER)); } @Test public void findPractitioners_shouldReverseIncludeMedicationRequests() throws Exception { verifyUri("/Practitioner?_revinclude=MedicationRequest:requester"); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), any(), any(), - any(), includeArgumentCaptor.capture()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(includeArgumentCaptor.getValue(), notNullValue()); - assertThat(includeArgumentCaptor.getValue().size(), equalTo(1)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamName(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().size(), equalTo(1)); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_REQUESTER_PARAM)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamType(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().iterator().next().getParamType(), equalTo(FhirConstants.MEDICATION_REQUEST)); } @@ -314,14 +290,13 @@ public void findPractitioners_shouldReverseIncludeMedicationRequests() throws Ex public void findPractitioners_shouldReverseIncludeServiceRequests() throws Exception { verifyUri("/Practitioner?_revinclude=ServiceRequest:requester"); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), any(), any(), - any(), includeArgumentCaptor.capture()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(includeArgumentCaptor.getValue(), notNullValue()); - assertThat(includeArgumentCaptor.getValue().size(), equalTo(1)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamName(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().size(), equalTo(1)); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_REQUESTER_PARAM)); - assertThat(includeArgumentCaptor.getValue().iterator().next().getParamType(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().iterator().next().getParamType(), equalTo(FhirConstants.SERVICE_REQUEST)); } @@ -329,15 +304,14 @@ public void findPractitioners_shouldReverseIncludeServiceRequests() throws Excep public void findPractitioners_shouldHandleMultipleReverseIncludes() throws Exception { verifyUri("/Practitioner?_revinclude=ServiceRequest:requester&_revinclude=Encounter:participant"); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), any(), any(), - any(), includeArgumentCaptor.capture()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(includeArgumentCaptor.getValue(), notNullValue()); - assertThat(includeArgumentCaptor.getValue().size(), equalTo(2)); - assertThat(includeArgumentCaptor.getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().size(), equalTo(2)); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_REQUESTER_PARAM)), hasProperty("paramType", equalTo(FhirConstants.SERVICE_REQUEST))))); - assertThat(includeArgumentCaptor.getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_PARTICIPANT_PARAM)), hasProperty("paramType", equalTo(FhirConstants.ENCOUNTER))))); } @@ -347,15 +321,14 @@ public void findPractitioners_shouldAddReverseIncludedMedicationRequestsWithIter throws Exception { verifyUri("/Practitioner?_revinclude=MedicationRequest:requester&_revinclude=MedicationDispense:prescription"); - verify(practitionerService).searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), any(), any(), - any(), includeArgumentCaptor.capture()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(includeArgumentCaptor.getValue(), notNullValue()); - assertThat(includeArgumentCaptor.getValue().size(), equalTo(2)); - assertThat(includeArgumentCaptor.getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes().size(), equalTo(2)); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_REQUESTER_PARAM)), hasProperty("paramType", equalTo(FhirConstants.MEDICATION_REQUEST))))); - assertThat(includeArgumentCaptor.getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getRevIncludes(), hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_PRESCRIPTION_PARAM)), hasProperty("paramType", equalTo(FhirConstants.MEDICATION_DISPENSE))))); } @@ -364,27 +337,26 @@ public void findPractitioners_shouldAddReverseIncludedMedicationRequestsWithIter public void findPractitioners_shouldHandleComplexQuery() throws Exception { verifyUri(String.format("/Practitioner?identifier=%s&name=%s", PRACTITIONER_IDENTIFIER, NAME)); - verify(practitionerService).searchForPractitioners(tokenAndListParamArgumentCaptor.capture(), - stringAndListParamArgumentCaptor.capture(), any(), any(), any(), any(), any(), any(), any(), any(), any()); + verify(practitionerService).searchForPractitioners(practitionerSearchParamsArgumentCaptor.capture()); - assertThat(stringAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(stringAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens() - .get(0).getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getName(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getName().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getName().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(NAME)); - assertThat(tokenAndListParamArgumentCaptor.getValue(), notNullValue()); - assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty())); - assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0) - .getValue(), + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getIdentifier(), notNullValue()); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getIdentifier().getValuesAsQueryTokens(), not(empty())); + assertThat(practitionerSearchParamsArgumentCaptor.getValue().getIdentifier().getValuesAsQueryTokens().get(0) + .getValuesAsQueryTokens().get(0).getValue(), equalTo(PRACTITIONER_IDENTIFIER)); } private void verifyUri(String uri) throws Exception { Practitioner practitioner = new Practitioner(); practitioner.setId(PRACTITIONER_UUID); - when(practitionerService.searchForPractitioners(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), - any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(practitioner), 10, 1)); + when(practitionerService.searchForPractitioners(any())) + .thenReturn(new MockIBundleProvider<>(Collections.singletonList(practitioner), 10, 1)); MockHttpServletResponse response = get(uri).accept(FhirMediaTypes.JSON).go();