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 for Task Service class search method #442

Merged
merged 7 commits into from
Jun 30, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@
*/
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.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import org.hl7.fhir.r4.model.Task;
import org.openmrs.module.fhir2.api.search.param.TaskSearchParams;

/**
* Contains methods pertaining to creating/updating/voiding/searching Tasks
Expand All @@ -26,16 +20,7 @@ public interface FhirTaskService extends FhirService<Task> {

/**
ibacher marked this conversation as resolved.
Show resolved Hide resolved
* Get collection of tasks corresponding to the provided search parameters
*
* @param basedOnReference A reference list to basedOn resources
* @param ownerReference A reference list to owner resources
* @param status A list of statuses
* @param id The UUID of the requested task
* @param lastUpdated A date range corresponding to when the Tasks were last updated
* @param sort The sort parameters for the search results
* @return the collection of Tasks that match the search parameters
*/
IBundleProvider searchForTasks(ReferenceAndListParam basedOnReference, ReferenceAndListParam ownerReference,
TokenAndListParam status, TokenAndListParam id, DateRangeParam lastUpdated, SortSpec sort,
HashSet<Include> includes);
IBundleProvider searchForTasks(TaskSearchParams taskSearchParams);
}
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.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.hl7.fhir.r4.model.Task;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.FhirTaskService;
import org.openmrs.module.fhir2.api.dao.FhirTaskDao;
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.TaskSearchParams;
import org.openmrs.module.fhir2.api.translators.TaskTranslator;
import org.openmrs.module.fhir2.model.FhirTask;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -53,29 +45,11 @@ public class FhirTaskServiceImpl extends BaseFhirService<Task, FhirTask> impleme

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please retain the Javadoc comments, removing the parts that are no longer relevant and adding for the new parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* Get collection of tasks corresponding to the provided search parameters
*
* @param basedOnReference A reference list to basedOn resources
* @param ownerReference A reference list to owner resources
* @param status A list of statuses
* @param id The UUID of the requested task
* @param lastUpdated A date range corresponding to when the Tasks were last updated
* @param sort The sort parameters for the search results
* @return the collection of Tasks that match the search parameters
*/
@Override
@Transactional(readOnly = true)
public IBundleProvider searchForTasks(ReferenceAndListParam basedOnReference, ReferenceAndListParam ownerReference,
TokenAndListParam status, TokenAndListParam id, DateRangeParam lastUpdated, SortSpec sort,
HashSet<Include> includes) {

SearchParameterMap theParams = new SearchParameterMap()
.addParameter(FhirConstants.BASED_ON_REFERENCE_SEARCH_HANDLER, basedOnReference)
.addParameter(FhirConstants.OWNER_REFERENCE_SEARCH_HANDLER, ownerReference)
.addParameter(FhirConstants.STATUS_SEARCH_HANDLER, status)
.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 searchForTasks(TaskSearchParams taskSearchParams) {
return searchQuery.getQueryResults(taskSearchParams.toSearchParameterMap(), dao, translator, searchQueryInclude);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.ReferenceAndListParam;
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

Check warning on line 26 in api/src/main/java/org/openmrs/module/fhir2/api/search/param/TaskSearchParams.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/fhir2/api/search/param/TaskSearchParams.java#L25-L26

Added lines #L25 - L26 were not covered by tests
@EqualsAndHashCode(callSuper = true)
public class TaskSearchParams extends BaseResourceSearchParams {

/**
* Get collection of tasks corresponding to the provided search parameters
*
* @param basedOnReference A reference list to basedOn resources
* @param ownerReference A reference list to owner resources
* @param status A list of statuses
* @param id The UUID of the requested task
* @param lastUpdated A date range corresponding to when the Tasks were last updated
* @param sort The sort parameters for the search results
* @param includes request for specified referenced resources
* @return the collection of Tasks that match the search parameters
*/

private ReferenceAndListParam basedOnReference;
private ReferenceAndListParam ownerReference;
private TokenAndListParam status;

@Builder
public TaskSearchParams(ReferenceAndListParam basedOnReference, ReferenceAndListParam ownerReference,
TokenAndListParam status, TokenAndListParam id, DateRangeParam lastUpdated, SortSpec sort,

Check warning on line 49 in api/src/main/java/org/openmrs/module/fhir2/api/search/param/TaskSearchParams.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/fhir2/api/search/param/TaskSearchParams.java#L49

Added line #L49 was not covered by tests
HashSet<Include> includes) {

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

this.basedOnReference = basedOnReference;
this.ownerReference = ownerReference;
this.status = status;

}

@Override
public SearchParameterMap toSearchParameterMap() {
return baseSearchParameterMap()
.addParameter(FhirConstants.BASED_ON_REFERENCE_SEARCH_HANDLER, getBasedOnReference())
.addParameter(FhirConstants.OWNER_REFERENCE_SEARCH_HANDLER,getOwnerReference())
.addParameter(FhirConstants.STATUS_SEARCH_HANDLER, getStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.hl7.fhir.r4.model.ServiceRequest;
import org.hl7.fhir.r4.model.Task;
import org.openmrs.module.fhir2.api.FhirTaskService;
import org.openmrs.module.fhir2.api.search.param.TaskSearchParams;
import org.springframework.beans.factory.annotation.Autowired;

@Setter(AccessLevel.PROTECTED)
Expand All @@ -35,10 +36,10 @@
private FhirTaskService taskService;

protected ServiceRequest.ServiceRequestStatus determineServiceRequestStatus(String orderUuid) {
IBundleProvider results = taskService.searchForTasks(
IBundleProvider results = taskService.searchForTasks(new TaskSearchParams(

Check warning on line 39 in api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/BaseServiceRequestTranslator.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/BaseServiceRequestTranslator.java#L39

Added line #L39 was not covered by tests
new ReferenceAndListParam()
.addAnd(new ReferenceOrListParam().add(new ReferenceParam("ServiceRequest", null, orderUuid))),
null, null, null, null, null, null);
null, null, null, null, null, null));

Collection<Task> serviceRequestTasks = results.getResources(START_INDEX, END_INDEX).stream().map(p -> (Task) p)
.collect(Collectors.toList());
Expand Down Expand Up @@ -69,10 +70,10 @@
}

protected Reference determineServiceRequestPerformer(String orderUuid) {
IBundleProvider results = taskService.searchForTasks(
IBundleProvider results = taskService.searchForTasks(new TaskSearchParams(

Check warning on line 73 in api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/BaseServiceRequestTranslator.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/BaseServiceRequestTranslator.java#L73

Added line #L73 was not covered by tests
new ReferenceAndListParam()
.addAnd(new ReferenceOrListParam().add(new ReferenceParam("ServiceRequest", null, orderUuid))),
null, null, null, null, null, null);
null, null, null, null, null, null));

Collection<Task> serviceRequestTasks = results.getResources(START_INDEX, END_INDEX).stream().map(p -> (Task) p)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.openmrs.Provider;
import org.openmrs.TestOrder;
import org.openmrs.module.fhir2.api.FhirTaskService;
import org.openmrs.module.fhir2.api.search.param.TaskSearchParams;
import org.openmrs.module.fhir2.api.translators.ConceptTranslator;
import org.openmrs.module.fhir2.api.translators.EncounterReferenceTranslator;
import org.openmrs.module.fhir2.api.translators.OrderIdentifierTranslator;
Expand Down Expand Up @@ -133,10 +134,10 @@ private ServiceRequest.ServiceRequestStatus determineServiceRequestStatus(TestOr
}

private Reference determineServiceRequestPerformer(String orderUuid) {
IBundleProvider results = taskService.searchForTasks(
IBundleProvider results = taskService.searchForTasks(new TaskSearchParams(
new ReferenceAndListParam()
.addAnd(new ReferenceOrListParam().add(new ReferenceParam("ServiceRequest", null, orderUuid))),
null, null, null, null, null, null);
null, null, null, null, null, null));

Collection<Task> serviceRequestTasks = results.getResources(START_INDEX, END_INDEX).stream().map(p -> (Task) p)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.openmrs.module.fhir2.api.FhirTaskService;
import org.openmrs.module.fhir2.api.annotations.R3Provider;
import org.openmrs.module.fhir2.api.search.SearchQueryBundleProviderR3Wrapper;
import org.openmrs.module.fhir2.api.search.param.TaskSearchParams;
import org.openmrs.module.fhir2.providers.util.FhirProviderUtils;
import org.openmrs.module.fhir2.providers.util.TaskVersionConverter;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -105,6 +106,6 @@ public IBundleProvider searchTasks(
includes = null;
}
return new SearchQueryBundleProviderR3Wrapper(
fhirTaskService.searchForTasks(basedOnReference, ownerReference, status, id, lastUpdated, sort, includes));
fhirTaskService.searchForTasks(new TaskSearchParams(basedOnReference, ownerReference, status, id, lastUpdated, sort, includes)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.hl7.fhir.r4.model.Task;
import org.openmrs.module.fhir2.api.FhirTaskService;
import org.openmrs.module.fhir2.api.annotations.R4Provider;
import org.openmrs.module.fhir2.api.search.param.TaskSearchParams;
import org.openmrs.module.fhir2.providers.util.FhirProviderUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -94,6 +95,6 @@ public IBundleProvider searchTasks(
if (CollectionUtils.isEmpty(includes)) {
includes = null;
}
return service.searchForTasks(basedOnReference, ownerReference, status, id, lastUpdated, sort, includes);
return service.searchForTasks(new TaskSearchParams(basedOnReference, ownerReference, status, id, lastUpdated, sort, includes));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider;
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.TaskSearchParams;
import org.openmrs.module.fhir2.api.translators.TaskTranslator;
import org.openmrs.module.fhir2.model.FhirTask;

Expand Down Expand Up @@ -214,7 +215,7 @@ public void searchForTasks_shouldReturnTasksByParameters() {
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(translator.toFhirResource(openmrsTask)).thenReturn(task);

IBundleProvider results = fhirTaskService.searchForTasks(null, null, null, null, null, null, null);
IBundleProvider results = fhirTaskService.searchForTasks(new TaskSearchParams(null, null, null, null, null, null, null));

List<IBaseResource> resultList = get(results);

Expand Down
Loading