Skip to content

Commit

Permalink
FM2-312: Fixing broken tests on the ServiceRequest resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruhanga committed Nov 9, 2020
1 parent 6766c83 commit 21d1aae
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public interface FhirMedicationRequestService extends FhirService<MedicationRequ
@Override
MedicationRequest get(@Nonnull String uuid);

IBundleProvider searchForMedicationRequests(ReferenceAndListParam patientReference,
ReferenceAndListParam encounterReference, TokenAndListParam code, ReferenceAndListParam participantReference,
ReferenceAndListParam medicationReference, TokenAndListParam identifier, TokenAndListParam id,
DateRangeParam lastUpdated, HashSet<Include> includes);

IBundleProvider searchForMedicationRequests(ReferenceAndListParam patientReference,
ReferenceAndListParam encounterReference, TokenAndListParam code, ReferenceAndListParam participantReference,
ReferenceAndListParam medicationReference, TokenAndListParam id, DateRangeParam lastUpdated,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ public interface FhirServiceRequestService extends FhirService<ServiceRequest> {
IBundleProvider searchForServiceRequests(ReferenceAndListParam patientReference, TokenAndListParam code,
ReferenceAndListParam encounterReference, ReferenceAndListParam participantReference, DateRangeParam occurrence,
TokenAndListParam uuid, DateRangeParam lastUpdated, HashSet<Include> includes);

IBundleProvider searchForServiceRequests(ReferenceAndListParam patientReference, TokenAndListParam code,
ReferenceAndListParam encounterReference, ReferenceAndListParam participantReference, DateRangeParam occurrence,
TokenAndListParam uuid, TokenAndListParam identifier, DateRangeParam lastUpdated, HashSet<Include> includes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package org.openmrs.module.fhir2.api.dao.impl;

import static org.hibernate.criterion.Restrictions.and;
import static org.hibernate.criterion.Restrictions.eq;
import static org.hibernate.criterion.Restrictions.or;

import java.util.Optional;
Expand Down Expand Up @@ -58,6 +59,11 @@ protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams
case FhirConstants.COMMON_SEARCH_HANDLER:
handleCommonSearchParameters(entry.getValue()).ifPresent(criteria::add);
break;
case FhirConstants.IDENTIFIER:
entry.getValue()
.forEach(orderNumber -> handleOrderNumber((TokenAndListParam) orderNumber.getParam())
.ifPresent(criteria::add));
break;
}
});
}
Expand All @@ -84,4 +90,11 @@ private Optional<Criterion> handleDateRange(DateRangeParam dateRangeParam) {
handleDate("autoExpireDate", dateRangeParam.getUpperBound())))))))));
}

private Optional<Criterion> handleOrderNumber(TokenAndListParam orderNumber) {
if (orderNumber != null) {
return handleAndListParam(orderNumber, param -> Optional.of(eq("orderNumber", param.getValue())));
}
return Optional.empty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public class FhirMedicationRequestServiceImpl extends BaseFhirService<Medication
@Override
public IBundleProvider searchForMedicationRequests(ReferenceAndListParam patientReference,
ReferenceAndListParam encounterReference, TokenAndListParam code, ReferenceAndListParam participantReference,
ReferenceAndListParam medicationReference, TokenAndListParam id, DateRangeParam lastUpdated,
HashSet<Include> includes) {
ReferenceAndListParam medicationReference, TokenAndListParam identifier, TokenAndListParam id,
DateRangeParam lastUpdated, HashSet<Include> includes) {

SearchParameterMap theParams = new SearchParameterMap()
.addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, encounterReference)
Expand All @@ -67,4 +67,14 @@ public IBundleProvider searchForMedicationRequests(ReferenceAndListParam patient
return searchQuery.getQueryResults(theParams, dao, translator, searchQueryInclude);
}

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

return searchForMedicationRequests(patientReference, encounterReference, code, participantReference,
medicationReference, null, id, lastUpdated, includes);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class FhirServiceRequestServiceImpl extends BaseFhirService<ServiceReques
@Override
public IBundleProvider searchForServiceRequests(ReferenceAndListParam patientReference, TokenAndListParam code,
ReferenceAndListParam encounterReference, ReferenceAndListParam participantReference, DateRangeParam occurrence,
TokenAndListParam uuid, DateRangeParam lastUpdated, HashSet<Include> includes) {
TokenAndListParam uuid, TokenAndListParam identifier, DateRangeParam lastUpdated, HashSet<Include> includes) {

SearchParameterMap theParams = new SearchParameterMap()
.addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientReference)
Expand All @@ -62,10 +62,20 @@ public IBundleProvider searchForServiceRequests(ReferenceAndListParam patientRef
.addParameter(FhirConstants.PARTICIPANT_REFERENCE_SEARCH_HANDLER, participantReference)
.addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, occurrence)
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid)
.addParameter(FhirConstants.IDENTIFIER, identifier)
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated)
.addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);

return searchQuery.getQueryResults(theParams, dao, translator, searchQueryInclude);
}

@Override
public IBundleProvider searchForServiceRequests(ReferenceAndListParam patientReference, TokenAndListParam code,
ReferenceAndListParam encounterReference, ReferenceAndListParam participantReference, DateRangeParam occurrence,
TokenAndListParam uuid, DateRangeParam lastUpdated, HashSet<Include> includes) {

return searchForServiceRequests(patientReference, code, encounterReference, participantReference, occurrence, uuid,
null, lastUpdated, includes);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public MedicationRequest toFhirResource(@Nonnull DrugOrder drugOrder) {
medicationRequest.setId(drugOrder.getUuid());
medicationRequest.setStatus(statusTranslator.toFhirResource(drugOrder));

medicationRequest.addIdentifier(orderIdTranslator.toFhirResource(drugOrder));
if (drugOrder.getOrderNumber() != null) {
medicationRequest.addIdentifier(orderIdTranslator.toFhirResource(drugOrder));
}

medicationRequest.setMedication(medicationReferenceTranslator.toFhirResource(drugOrder.getDrug()));
medicationRequest.setPriority(medicationRequestPriorityTranslator.toFhirResource(drugOrder.getUrgency()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public ServiceRequest toFhirResource(@Nonnull TestOrder order) {

serviceRequest.setId(order.getUuid());

serviceRequest.addIdentifier(orderIdTranslator.toFhirResource(order));
if (order.getOrderNumber() != null) {
serviceRequest.addIdentifier(orderIdTranslator.toFhirResource(order));
}

serviceRequest.setStatus(determineServiceRequestStatus(order.getUuid()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.hl7.fhir.r4.model.OperationOutcome;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Practitioner;
import org.hl7.fhir.r4.model.ServiceRequest;
import org.openmrs.module.fhir2.api.FhirMedicationRequestService;
import org.openmrs.module.fhir2.providers.util.FhirProviderUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -109,6 +110,7 @@ public IBundleProvider searchForMedicationRequests(
@OptionalParam(name = MedicationRequest.SP_ENCOUNTER, chainWhitelist = {
"" }, targetTypes = Encounter.class) ReferenceAndListParam encounterReference,
@OptionalParam(name = MedicationRequest.SP_CODE) TokenAndListParam code,
@OptionalParam(name = ServiceRequest.SP_IDENTIFIER) TokenAndListParam orderNumber,
@OptionalParam(name = MedicationRequest.SP_REQUESTER, chainWhitelist = { "", Practitioner.SP_IDENTIFIER,
Practitioner.SP_GIVEN, Practitioner.SP_FAMILY,
Practitioner.SP_NAME }, targetTypes = Practitioner.class) ReferenceAndListParam participantReference,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public IBundleProvider searchForServiceRequests(
Practitioner.SP_NAME }, targetTypes = Practitioner.class) ReferenceAndListParam participantReference,
@OptionalParam(name = ServiceRequest.SP_OCCURRENCE) DateRangeParam occurrence,
@OptionalParam(name = ServiceRequest.SP_RES_ID) TokenAndListParam uuid,
@OptionalParam(name = ServiceRequest.SP_IDENTIFIER) TokenAndListParam orderNumber,
@OptionalParam(name = "_lastUpdated") DateRangeParam lastUpdated,
@IncludeParam(allow = { "ServiceRequest:" + ServiceRequest.SP_PATIENT,
"ServiceRequest:" + ServiceRequest.SP_REQUESTER,
Expand All @@ -122,6 +123,6 @@ public IBundleProvider searchForServiceRequests(
}

return serviceRequestService.searchForServiceRequests(patientReference, code, encounterReference,
participantReference, occurrence, uuid, lastUpdated, includes);
participantReference, occurrence, uuid, orderNumber, lastUpdated, includes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void searchMedicationRequest_shouldReturnMatchingMedicationRequestUsingCo
code.addAnd(codingToken);

IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, code, null, null, null,
null, null);
null, null, null);

List<IBaseResource> resources = getResources(results, 1, 5);

Expand All @@ -143,7 +143,7 @@ public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenPat
patientParam.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Patient.SP_NAME)));

IBundleProvider results = resourceProvider.searchForMedicationRequests(patientParam, null, null, null, null, null,
null, null, null);
null, null, null, null);

List<IBaseResource> resources = getResources(results, 1, 5);

Expand All @@ -164,8 +164,8 @@ public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenMed
ReferenceAndListParam medicationParam = new ReferenceAndListParam();
medicationParam.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Medication.SP_IDENTIFIER)));

IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null, medicationParam,
null, null, null);
IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null, null,
medicationParam, null, null, null);

List<IBaseResource> resources = getResources(results, 1, 5);

Expand All @@ -186,8 +186,8 @@ public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenPar
ReferenceAndListParam participantParam = new ReferenceAndListParam();
participantParam.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Practitioner.SP_NAME)));

IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, participantParam,
null, null, null, null);
IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null,
participantParam, null, null, null, null);

List<IBaseResource> resources = getResources(results, 1, 5);

Expand All @@ -209,7 +209,7 @@ public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenEnc
encounterParam.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Encounter.SP_IDENTIFIER)));

IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, encounterParam, null, null, null,
null, null, null);
null, null, null, null);

List<IBaseResource> resources = getResources(results, 1, 5);

Expand All @@ -228,8 +228,8 @@ public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenUUI
fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any()))
.thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));

IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null, null, uuid,
null, null);
IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null, null, null,
uuid, null, null);

List<IBaseResource> resources = getResources(results, 1, 5);

Expand All @@ -249,7 +249,7 @@ public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenLas
.thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));

IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null, null, null,
lastUpdated, null);
null, lastUpdated, null);

List<IBaseResource> resources = getResources(results, 1, 5);

Expand All @@ -270,7 +270,7 @@ public void searchMedicationRequest_shouldAddRelatedMedicationsWhenIncluded() {
.thenReturn(new MockIBundleProvider<>(Arrays.asList(medicationRequest, new Practitioner()), 10, 1));

IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null, null, null,
null, includes);
null, null, includes);

List<IBaseResource> resources = getResources(results, 1, 5);

Expand All @@ -290,7 +290,7 @@ public void searchMedicationRequest_shouldNotAddRelatedMedicationsForEmptyInclud
isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));

IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null, null, null,
null, includes);
null, null, includes);

List<IBaseResource> resources = getResources(results, 1, 5);

Expand Down
Loading

0 comments on commit 21d1aae

Please sign in to comment.