Skip to content

Commit

Permalink
FM2-481: Clean up parameter passing for MedicationRequest Service Sea…
Browse files Browse the repository at this point in the history
…rch (#512)
  • Loading branch information
mherman22 authored Jul 21, 2023
1 parent 0e395f0 commit 6f26ded
Show file tree
Hide file tree
Showing 11 changed files with 662 additions and 604 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,14 @@

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.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import org.hl7.fhir.r4.model.MedicationRequest;
import org.openmrs.module.fhir2.api.search.param.MedicationRequestSearchParams;

public interface FhirMedicationRequestService extends FhirService<MedicationRequest> {

@Override
MedicationRequest get(@Nonnull String uuid);

IBundleProvider searchForMedicationRequests(ReferenceAndListParam patientReference,
ReferenceAndListParam encounterReference, TokenAndListParam code, ReferenceAndListParam participantReference,
ReferenceAndListParam medicationReference, TokenAndListParam id, TokenAndListParam status,
TokenAndListParam fulfillerStatus, DateRangeParam lastUpdated, HashSet<Include> includes,
HashSet<Include> revIncludes);
IBundleProvider searchForMedicationRequests(MedicationRequestSearchParams medicationRequestSearchParams);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,17 @@
*/
package org.openmrs.module.fhir2.api.impl;

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.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.hl7.fhir.r4.model.MedicationRequest;
import org.openmrs.DrugOrder;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.FhirMedicationRequestService;
import org.openmrs.module.fhir2.api.dao.FhirMedicationRequestDao;
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.MedicationRequestSearchParams;
import org.openmrs.module.fhir2.api.translators.MedicationRequestTranslator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -49,26 +42,9 @@ public class FhirMedicationRequestServiceImpl extends BaseFhirService<Medication
private SearchQuery<DrugOrder, MedicationRequest, FhirMedicationRequestDao, MedicationRequestTranslator, SearchQueryInclude<MedicationRequest>> searchQuery;

@Override
public IBundleProvider searchForMedicationRequests(ReferenceAndListParam patientReference,
ReferenceAndListParam encounterReference, TokenAndListParam code, ReferenceAndListParam participantReference,
ReferenceAndListParam medicationReference, TokenAndListParam id, TokenAndListParam status,
TokenAndListParam fulfillerStatus, DateRangeParam lastUpdated, HashSet<Include> includes,
HashSet<Include> revIncludes) {

SearchParameterMap theParams = new SearchParameterMap()
.addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, encounterReference)
.addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientReference)
.addParameter(FhirConstants.CODED_SEARCH_HANDLER, code)
.addParameter(FhirConstants.PARTICIPANT_REFERENCE_SEARCH_HANDLER, participantReference)
.addParameter(FhirConstants.MEDICATION_REFERENCE_SEARCH_HANDLER, medicationReference)
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, id)
.addParameter(FhirConstants.STATUS_SEARCH_HANDLER, status)
.addParameter(FhirConstants.FULFILLER_STATUS_SEARCH_HANDLER, fulfillerStatus)
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated)
.addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes)
.addParameter(FhirConstants.REVERSE_INCLUDE_SEARCH_HANDLER, revIncludes);

return searchQuery.getQueryResults(theParams, dao, translator, searchQueryInclude);
public IBundleProvider searchForMedicationRequests(MedicationRequestSearchParams medicationRequestSearchParams) {
return searchQuery.getQueryResults(medicationRequestSearchParams.toSearchParameterMap(), dao, translator,
searchQueryInclude);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.openmrs.module.fhir2.api.search.param.EncounterSearchParams;
import org.openmrs.module.fhir2.api.search.param.LocationSearchParams;
import org.openmrs.module.fhir2.api.search.param.MedicationDispenseSearchParams;
import org.openmrs.module.fhir2.api.search.param.MedicationRequestSearchParams;
import org.openmrs.module.fhir2.api.search.param.ObservationSearchParams;
import org.openmrs.module.fhir2.api.search.param.PropParam;
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap;
Expand Down Expand Up @@ -270,8 +271,8 @@ private IBundleProvider handlePractitionerReverseInclude(ReferenceAndListParam p
encounterSearchParams.setParticipant(params);
return encounterService.searchForEncounters(encounterSearchParams);
case FhirConstants.MEDICATION_REQUEST:
return medicationRequestService.searchForMedicationRequests(null, null, null, params, null, null, null, null,
null, recursiveIncludes, recursiveRevIncludes);
return medicationRequestService.searchForMedicationRequests(new MedicationRequestSearchParams(null, null,
null, params, null, null, null, null, null, recursiveIncludes, recursiveRevIncludes));
case FhirConstants.PROCEDURE_REQUEST:
case FhirConstants.SERVICE_REQUEST:
return serviceRequestService.searchForServiceRequests(null, null, null, params, null, null, null, null);
Expand All @@ -291,8 +292,8 @@ private IBundleProvider handleEncounterReverseInclude(ReferenceAndListParam para
return diagnosticReportService.searchForDiagnosticReports(params, null, null, null, null, null, null, null,
null);
case FhirConstants.MEDICATION_REQUEST:
return medicationRequestService.searchForMedicationRequests(null, params, null, null, null, null, null, null,
null, recursiveIncludes, recursiveRevIncludes);
return medicationRequestService.searchForMedicationRequests(new MedicationRequestSearchParams(null, params,
null, null, null, null, null, null, null, recursiveIncludes, recursiveRevIncludes));
case FhirConstants.PROCEDURE_REQUEST:
case FhirConstants.SERVICE_REQUEST:
return serviceRequestService.searchForServiceRequests(null, null, params, null, null, null, null, null);
Expand All @@ -305,8 +306,8 @@ private IBundleProvider handleMedicationReverseInclude(ReferenceAndListParam par
HashSet<Include> recursiveIncludes, HashSet<Include> recursiveRevIncludes) {
switch (targetType) {
case FhirConstants.MEDICATION_REQUEST:
return medicationRequestService.searchForMedicationRequests(null, null, null, null, params, null, null, null,
null, recursiveIncludes, recursiveRevIncludes);
return medicationRequestService.searchForMedicationRequests(new MedicationRequestSearchParams(null, null,
null, null, params, null, null, null, null, recursiveIncludes, recursiveRevIncludes));
}

return null;
Expand Down Expand Up @@ -340,8 +341,8 @@ private IBundleProvider handlePatientReverseInclude(ReferenceAndListParam params
encounterSearchParams.setSubject(params);
return encounterService.searchForEncounters(encounterSearchParams);
case FhirConstants.MEDICATION_REQUEST:
return medicationRequestService.searchForMedicationRequests(params, null, null, null, null, null, null, null,
null, recursiveIncludes, recursiveRevIncludes);
return medicationRequestService.searchForMedicationRequests(new MedicationRequestSearchParams(params, null,
null, null, null, null, null, null, null, recursiveIncludes, recursiveRevIncludes));
case FhirConstants.SERVICE_REQUEST:
case FhirConstants.PROCEDURE_REQUEST:
return serviceRequestService.searchForServiceRequests(params, null, null, null, null, null, null, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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.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
@EqualsAndHashCode(callSuper = true)
public class MedicationRequestSearchParams extends BaseResourceSearchParams {

private ReferenceAndListParam patientReference;

private ReferenceAndListParam encounterReference;

private TokenAndListParam code;

private ReferenceAndListParam participantReference;

private ReferenceAndListParam medicationReference;

private TokenAndListParam status;

private TokenAndListParam fulfillerStatus;

@Builder
public MedicationRequestSearchParams(ReferenceAndListParam patientReference, ReferenceAndListParam encounterReference,
TokenAndListParam code, ReferenceAndListParam participantReference, ReferenceAndListParam medicationReference,
TokenAndListParam id, TokenAndListParam status, TokenAndListParam fulfillerStatus, DateRangeParam lastUpdated,
HashSet<Include> includes, HashSet<Include> revIncludes) {

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

this.patientReference = patientReference;
this.encounterReference = encounterReference;
this.code = code;
this.participantReference = participantReference;
this.medicationReference = medicationReference;
this.status = status;
this.fulfillerStatus = fulfillerStatus;
}

@Override
public SearchParameterMap toSearchParameterMap() {
return baseSearchParameterMap()
.addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, getEncounterReference())
.addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, getPatientReference())
.addParameter(FhirConstants.CODED_SEARCH_HANDLER, getCode())
.addParameter(FhirConstants.PARTICIPANT_REFERENCE_SEARCH_HANDLER, getParticipantReference())
.addParameter(FhirConstants.MEDICATION_REFERENCE_SEARCH_HANDLER, getMedicationReference())
.addParameter(FhirConstants.STATUS_SEARCH_HANDLER, getStatus())
.addParameter(FhirConstants.FULFILLER_STATUS_SEARCH_HANDLER, getFulfillerStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.openmrs.module.fhir2.api.FhirMedicationRequestService;
import org.openmrs.module.fhir2.api.annotations.R3Provider;
import org.openmrs.module.fhir2.api.search.SearchQueryBundleProviderR3Wrapper;
import org.openmrs.module.fhir2.api.search.param.MedicationRequestSearchParams;
import org.openmrs.module.fhir2.providers.util.FhirProviderUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -137,8 +138,8 @@ public IBundleProvider searchForMedicationRequests(
revIncludes = null;
}

return new SearchQueryBundleProviderR3Wrapper(medicationRequestService.searchForMedicationRequests(patientReference,
encounterReference, code, participantReference, medicationReference, id, status, fulfillerStatus, lastUpdated,
includes, revIncludes));
return new SearchQueryBundleProviderR3Wrapper(medicationRequestService.searchForMedicationRequests(
new MedicationRequestSearchParams(patientReference, encounterReference, code, participantReference,
medicationReference, id, status, fulfillerStatus, lastUpdated, includes, revIncludes)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.FhirMedicationRequestService;
import org.openmrs.module.fhir2.api.annotations.R4Provider;
import org.openmrs.module.fhir2.api.search.param.MedicationRequestSearchParams;
import org.openmrs.module.fhir2.providers.util.FhirProviderUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -134,7 +135,8 @@ public IBundleProvider searchForMedicationRequests(
revIncludes = null;
}

return fhirMedicationRequestService.searchForMedicationRequests(patientReference, encounterReference, code,
participantReference, medicationReference, id, status, fulfillerStatus, lastUpdated, includes, revIncludes);
return fhirMedicationRequestService.searchForMedicationRequests(
new MedicationRequestSearchParams(patientReference, encounterReference, code, participantReference,
medicationReference, id, status, fulfillerStatus, lastUpdated, includes, revIncludes));
}
}
Loading

0 comments on commit 6f26ded

Please sign in to comment.