Skip to content

Commit

Permalink
FM2-312: MedicationRequestFihrResourceProvider to hundle 'identifier'…
Browse files Browse the repository at this point in the history
… parameter + fixing failing tests
  • Loading branch information
Ruhanga committed Nov 9, 2020
1 parent 21d1aae commit 65ef032
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
*/
package org.openmrs.module.fhir2.api.dao.impl;

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

import java.util.Optional;

import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import lombok.AccessLevel;
import lombok.Setter;
import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;
import org.openmrs.DrugOrder;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.dao.FhirMedicationRequestDao;
Expand Down Expand Up @@ -50,6 +55,10 @@ 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 @@ -64,4 +73,11 @@ private void handleCodedConcept(Criteria criteria, TokenAndListParam code) {
}
}

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 @@ -59,10 +59,9 @@ 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));
case FhirConstants.IDENTIFIER:
entry.getValue().forEach(orderNumber -> handleOrderNumber((TokenAndListParam) orderNumber.getParam())
.ifPresent(criteria::add));
break;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public IBundleProvider searchForMedicationRequests(ReferenceAndListParam patient
.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.IDENTIFIER, identifier)
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated)
.addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,6 @@ public IBundleProvider searchForMedicationRequests(
}

return fhirMedicationRequestService.searchForMedicationRequests(patientReference, encounterReference, code,
participantReference, medicationReference, id, lastUpdated, includes);
participantReference, medicationReference, orderNumber, id, lastUpdated, includes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ private List<IBaseResource> getResources(IBundleProvider results, int theFromInd
@Test
public void searchMedicationRequest_shouldReturnMatchingMedicationRequestUsingCode() {

when(
fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any()))
.thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any(),
any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));

TokenAndListParam code = new TokenAndListParam();
TokenParam codingToken = new TokenParam();
Expand All @@ -135,9 +134,8 @@ public void searchMedicationRequest_shouldReturnMatchingMedicationRequestUsingCo
@Test
public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenPatientParamIsSpecified() {

when(
fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any()))
.thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any(),
any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));

ReferenceAndListParam patientParam = new ReferenceAndListParam();
patientParam.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Patient.SP_NAME)));
Expand All @@ -157,9 +155,8 @@ public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenPat
@Test
public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenMedicationParamIsSpecified() {

when(
fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any()))
.thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any(),
any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));

ReferenceAndListParam medicationParam = new ReferenceAndListParam();
medicationParam.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Medication.SP_IDENTIFIER)));
Expand All @@ -179,9 +176,8 @@ public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenMed
@Test
public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenParticipantParamIsSpecified() {

when(
fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any()))
.thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any(),
any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));

ReferenceAndListParam participantParam = new ReferenceAndListParam();
participantParam.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Practitioner.SP_NAME)));
Expand All @@ -201,9 +197,8 @@ public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenPar
@Test
public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenEncounterParamIsSpecified() {

when(
fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any()))
.thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any(),
any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));

ReferenceAndListParam encounterParam = new ReferenceAndListParam();
encounterParam.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Encounter.SP_IDENTIFIER)));
Expand All @@ -224,9 +219,8 @@ public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenEnc
public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenUUIDIsSpecified() {
TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(MEDICATION_REQUEST_UUID));

when(
fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any()))
.thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
when(fhirMedicationRequestService.searchForMedicationRequests(any(), 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, null,
uuid, null, null);
Expand All @@ -244,9 +238,8 @@ public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenUUI
public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenLastUpdatedIsSpecified() {
DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(LAST_UPDATED_DATE).setLowerBound(LAST_UPDATED_DATE);

when(
fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any()))
.thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
when(fhirMedicationRequestService.searchForMedicationRequests(any(), 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, null,
null, lastUpdated, null);
Expand All @@ -265,9 +258,8 @@ public void searchMedicationRequest_shouldAddRelatedMedicationsWhenIncluded() {
HashSet<Include> includes = new HashSet<>();
includes.add(new Include("MedicationRequest:requester"));

when(
fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any()))
.thenReturn(new MockIBundleProvider<>(Arrays.asList(medicationRequest, new Practitioner()), 10, 1));
when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any(),
any())).thenReturn(new MockIBundleProvider<>(Arrays.asList(medicationRequest, new Practitioner()), 10, 1));

IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null, null, null,
null, null, includes);
Expand All @@ -286,7 +278,7 @@ public void searchMedicationRequest_shouldAddRelatedMedicationsWhenIncluded() {
public void searchMedicationRequest_shouldNotAddRelatedMedicationsForEmptyInclude() {
HashSet<Include> includes = new HashSet<>();

when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(),
when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any(),
isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));

IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null, null, null,
Expand Down
Loading

0 comments on commit 65ef032

Please sign in to comment.