Skip to content

Commit

Permalink
refactoring EncounterSearchParams to use new BaseParams class
Browse files Browse the repository at this point in the history
  • Loading branch information
pmanko2 committed Jun 9, 2022
1 parent adeaf83 commit 096c69e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,7 @@ public void delete(@Nonnull String uuid) {
@Override
@Transactional(readOnly = true)
public IBundleProvider searchForEncounters(EncounterSearchParams searchParameters) {
SearchParameterMap theParams = new SearchParameterMap()
.addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, searchParameters.getDate())
.addParameter(FhirConstants.LOCATION_REFERENCE_SEARCH_HANDLER, searchParameters.getLocation())
.addParameter(FhirConstants.PARTICIPANT_REFERENCE_SEARCH_HANDLER, searchParameters.getParticipant())
.addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, searchParameters.getSubject())
.addParameter(FhirConstants.ENCOUNTER_TYPE_REFERENCE_SEARCH_HANDLER, searchParameters.getEncounterType())
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, searchParameters.getId())
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY,
searchParameters.getLastUpdated())
.addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, searchParameters.getIncludes())
.addParameter(FhirConstants.REVERSE_INCLUDE_SEARCH_HANDLER, searchParameters.getRevIncludes())
.addParameter(FhirConstants.HAS_SEARCH_HANDLER, searchParameters.getHasAndListParam())
.setSortSpec(searchParameters.getSort());
SearchParameterMap theParams = searchParameters.toSearchParameterMap();

IBundleProvider visitBundle = null;
IBundleProvider encounterBundle = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@
*/
package org.openmrs.module.fhir2.api.search.param;

import java.io.Serializable;
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.HasAndListParam;
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.openmrs.module.fhir2.FhirConstants;

import java.util.HashSet;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class EncounterSearchParams implements Serializable {
@EqualsAndHashCode(callSuper = true)
public class EncounterSearchParams extends BaseResourceSearchParams {

private DateRangeParam date;

Expand All @@ -39,17 +38,34 @@ public class EncounterSearchParams implements Serializable {

private TokenAndListParam encounterType;

private TokenAndListParam id;

private DateRangeParam lastUpdated;

private TokenAndListParam tag;

private HasAndListParam hasAndListParam;

private SortSpec sort;

private HashSet<Include> includes;
@Builder
public EncounterSearchParams(DateRangeParam date, ReferenceAndListParam location, ReferenceAndListParam participant,
ReferenceAndListParam subject, TokenAndListParam encounterType, TokenAndListParam tag,
HasAndListParam hasAndListParam, TokenAndListParam id, DateRangeParam lastUpdated, SortSpec sort,
HashSet<Include> includes, HashSet<Include> revIncludes) {

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

this.date = date;
this.location = location;
this.participant = participant;
this.subject = subject;
this.encounterType = encounterType;
this.tag = tag;
this.hasAndListParam = hasAndListParam;
}

private HashSet<Include> revIncludes;
@Override
public SearchParameterMap toSearchParameterMap() {
return baseSearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, getDate())
.addParameter(FhirConstants.LOCATION_REFERENCE_SEARCH_HANDLER, getLocation())
.addParameter(FhirConstants.PARTICIPANT_REFERENCE_SEARCH_HANDLER, getParticipant())
.addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, getSubject())
.addParameter(FhirConstants.ENCOUNTER_TYPE_REFERENCE_SEARCH_HANDLER, getEncounterType())
.addParameter(FhirConstants.HAS_SEARCH_HANDLER, getHasAndListParam());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public IBundleProvider searchEncounter(@OptionalParam(name = Encounter.SP_DATE)

return new SearchQueryBundleProviderR3Wrapper(encounterService
.searchForEncounters(new EncounterSearchParams(date, location, participantReference, subjectReference,
encounterType, id, lastUpdated, tag, hasAndListParam, sort, includes, revIncludes)));
encounterType, tag, hasAndListParam, id, lastUpdated, sort, includes, revIncludes)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public IBundleProvider searchEncounter(@OptionalParam(name = Encounter.SP_DATE)
revIncludes = null;
}

return encounterService.searchForEncounters(new EncounterSearchParams(date, location, participantReference,
subjectReference, encounterType, id, lastUpdated, tag, hasAndListParam, sort, includes, revIncludes));
return encounterService.searchForEncounters(new EncounterSearchParams(date, location, participantReference, subjectReference,
encounterType, tag, hasAndListParam, id, lastUpdated, sort, includes, revIncludes));
}

/**
Expand Down

0 comments on commit 096c69e

Please sign in to comment.