Skip to content

Commit

Permalink
FM2-481: Clean up parameter passing for Practitioner Service Search m…
Browse files Browse the repository at this point in the history
…ethod (#504)
  • Loading branch information
mherman22 authored Jul 7, 2023
1 parent 735449c commit b5d5453
Show file tree
Hide file tree
Showing 11 changed files with 433 additions and 432 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Practitioner> {

IBundleProvider searchForPractitioners(TokenAndListParam identifier, StringAndListParam name, StringAndListParam given,
StringAndListParam family, StringAndListParam city, StringAndListParam state, StringAndListParam postalCode,
StringAndListParam country, TokenAndListParam id, DateRangeParam lastUpdated, HashSet<Include> revIncludes);

IBundleProvider searchForPractitioners(PractitionerSearchParams practitionerSearchParams);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<Include> 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()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Include> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
Loading

0 comments on commit b5d5453

Please sign in to comment.