Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FM2-481: Clean up parameter passing in Person Service class search method #441

Merged
merged 8 commits into from
May 12, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,11 @@
*/
package org.openmrs.module.fhir2.api;

import java.util.HashSet;

import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import org.hl7.fhir.r4.model.Person;
import org.openmrs.module.fhir2.api.search.param.PersonSearchParams;

public interface FhirPersonService extends FhirService<Person> {

IBundleProvider searchForPeople(StringAndListParam name, TokenAndListParam gender, DateRangeParam birthDate,
StringAndListParam city, StringAndListParam state, StringAndListParam postalCode, StringAndListParam country,
TokenAndListParam id, DateRangeParam lastUpdated, SortSpec sort, HashSet<Include> includes);

IBundleProvider searchForPeople(PersonSearchParams personSearchParams);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,16 @@
*/
package org.openmrs.module.fhir2.api.impl;

import java.util.HashSet;

import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.hl7.fhir.r4.model.Person;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.FhirPersonService;
import org.openmrs.module.fhir2.api.dao.FhirPersonDao;
import org.openmrs.module.fhir2.api.search.SearchQuery;
import org.openmrs.module.fhir2.api.search.SearchQueryInclude;
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap;
import org.openmrs.module.fhir2.api.search.param.PersonSearchParams;
import org.openmrs.module.fhir2.api.translators.PersonTranslator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -51,23 +43,8 @@ public class FhirPersonServiceImpl extends BaseFhirService<Person, org.openmrs.P
private SearchQuery<org.openmrs.Person, Person, FhirPersonDao, PersonTranslator, SearchQueryInclude<Person>> searchQuery;

@Override
public IBundleProvider searchForPeople(StringAndListParam name, TokenAndListParam gender, DateRangeParam birthDate,
StringAndListParam city, StringAndListParam state, StringAndListParam postalCode, StringAndListParam country,
TokenAndListParam id, DateRangeParam lastUpdated, SortSpec sort, HashSet<Include> includes) {

SearchParameterMap theParams = new SearchParameterMap()
.addParameter(FhirConstants.NAME_SEARCH_HANDLER, FhirConstants.NAME_PROPERTY, name)
.addParameter(FhirConstants.GENDER_SEARCH_HANDLER, gender)
.addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, birthDate)
.addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.CITY_PROPERTY, city)
.addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.STATE_PROPERTY, state)
.addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.POSTAL_CODE_PROPERTY, postalCode)
.addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.COUNTRY_PROPERTY, country)
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, id)
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated)
.addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes).setSortSpec(sort);

return searchQuery.getQueryResults(theParams, dao, translator, searchQueryInclude);
public IBundleProvider searchForPeople(PersonSearchParams personSearchParams) {
return searchQuery.getQueryResults(personSearchParams.toSearchParameterMap(), dao, translator, searchQueryInclude);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.fhir2.api.search.param;

import java.util.HashSet;

import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.openmrs.module.fhir2.FhirConstants;

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class PersonSearchParams extends BaseResourceSearchParams {

private StringAndListParam name;

private TokenAndListParam gender;

private DateRangeParam birthDate;

private StringAndListParam city;

private StringAndListParam state;

private StringAndListParam postalCode;

private StringAndListParam country;

@Builder
public PersonSearchParams(StringAndListParam name, TokenAndListParam gender, DateRangeParam birthDate,
StringAndListParam city, StringAndListParam state, StringAndListParam postalCode, StringAndListParam country,
TokenAndListParam id, DateRangeParam lastUpdated, SortSpec sort, HashSet<Include> includes) {

super(id, lastUpdated, sort, includes, null);

this.name = name;
this.gender = gender;
this.birthDate = birthDate;
this.city = city;
this.state = state;
this.postalCode = postalCode;
this.country = country;
}

@Override
public SearchParameterMap toSearchParameterMap() {
return baseSearchParameterMap()
.addParameter(FhirConstants.NAME_SEARCH_HANDLER, FhirConstants.NAME_PROPERTY, getName())
.addParameter(FhirConstants.GENDER_SEARCH_HANDLER, getGender())
.addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, getBirthDate())
.addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.CITY_PROPERTY, getCity())
.addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.STATE_PROPERTY, getState())
.addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.POSTAL_CODE_PROPERTY, getPostalCode())
.addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.COUNTRY_PROPERTY, getCountry());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.openmrs.module.fhir2.api.FhirPersonService;
import org.openmrs.module.fhir2.api.annotations.R3Provider;
import org.openmrs.module.fhir2.api.search.SearchQueryBundleProviderR3Wrapper;
import org.openmrs.module.fhir2.api.search.param.PersonSearchParams;
import org.openmrs.module.fhir2.providers.util.FhirProviderUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -115,8 +116,9 @@ public IBundleProvider searchPeople(@OptionalParam(name = Person.SP_NAME) String
includes = null;
}

return new SearchQueryBundleProviderR3Wrapper(personService.searchForPeople(name, gender, birthDate, city, state,
postalCode, country, id, lastUpdated, sort, includes));
return new SearchQueryBundleProviderR3Wrapper(personService.searchForPeople(new PersonSearchParams(name, gender,
birthDate, city, state, postalCode, country, id, lastUpdated, sort, includes)));

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.hl7.fhir.r4.model.Person;
import org.openmrs.module.fhir2.api.FhirPersonService;
import org.openmrs.module.fhir2.api.annotations.R4Provider;
import org.openmrs.module.fhir2.api.search.param.PersonSearchParams;
import org.openmrs.module.fhir2.providers.util.FhirProviderUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -110,8 +111,8 @@ public IBundleProvider searchPeople(@OptionalParam(name = Person.SP_NAME) String
includes = null;
}

return fhirPersonService.searchForPeople(name, gender, birthDate, city, state, postalCode, country, id, lastUpdated,
sort, includes);
return fhirPersonService.searchForPeople(new PersonSearchParams(name, gender, birthDate, city, state, postalCode,
country, id, lastUpdated, sort, includes));
}

}