Skip to content

Commit

Permalink
FM2-537: SearchQueryBundleProvider should use Integer primary keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ibacher committed Dec 1, 2022
1 parent bc9fda0 commit 4930275
Show file tree
Hide file tree
Showing 62 changed files with 449 additions and 363 deletions.
Expand Up @@ -39,9 +39,9 @@ public interface FhirCohortMembershipDao extends FhirDao<CohortMembership> {

@Override
@Authorized(PrivilegeConstants.GET_PATIENT_COHORTS)
List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams);
List<Integer> getSearchResultIds(@Nonnull SearchParameterMap theParams);

@Override
@Authorized(PrivilegeConstants.GET_PATIENT_COHORTS)
List<CohortMembership> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<String> resourceUuids);
List<CohortMembership> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<Integer> resourceIds);
}
Expand Up @@ -43,6 +43,8 @@
@RunWith(MockitoJUnitRunner.class)
public class FhirGroupMemberService_2_1Test {

private static final Integer GROUP_MEMBER_ID = 123;

private static final String GROUP_MEMBER_UUID = "1359f03d-55d9-4961-b8f8-9a59eddc1f59";

private static final String BAD_GROUP_MEMBER_UUID = "02ed36f0-6167-4372-a641-d27b92f7deae";
Expand Down Expand Up @@ -93,7 +95,7 @@ public void shouldSearchForGroupMembersByGroupUuid() {
GROUP_MEMBER_UUID);

when(dao.getSearchResults(any(), any())).thenReturn(memberships);
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(GROUP_MEMBER_UUID));
when(dao.getSearchResultIds(any())).thenReturn(Collections.singletonList(GROUP_MEMBER_ID));
when(translator.toFhirResource(cohortMembership)).thenReturn(groupMember);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(
new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
Expand Down
Expand Up @@ -59,14 +59,14 @@ public Condition delete(@Nonnull String uuid) {

@Override
@Authorized(PrivilegeConstants.GET_CONDITIONS)
public List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams) {
return super.getSearchResultUuids(theParams);
public List<Integer> getSearchResultIds(@Nonnull SearchParameterMap theParams) {
return super.getSearchResultIds(theParams);
}

@Override
@Authorized(PrivilegeConstants.GET_CONDITIONS)
public List<Condition> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<String> resourceUuids) {
return super.getSearchResults(theParams, resourceUuids);
public List<Condition> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<Integer> resourceIds) {
return super.getSearchResults(theParams, resourceIds);
}

private ConditionClinicalStatus convertStatus(String status) {
Expand Down
Expand Up @@ -60,6 +60,8 @@
@RunWith(MockitoJUnitRunner.class)
public class FhirConditionServiceImpl_2_2Test {

private static final Integer CONDITION_ID = 123;

private static final String CONDITION_UUID = "43578769-f1a4-46af-b08b-d9fe8a07066f";

private static final String WRONG_CONDITION_UUID = "90378769-f1a4-46af-b08b-d9fe8a09034j";
Expand Down Expand Up @@ -254,7 +256,7 @@ public void searchConditions_shouldReturnTranslatedConditionReturnedByDao() {
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated)
.setSortSpec(sort);

when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(CONDITION_UUID));
when(dao.getSearchResultIds(any())).thenReturn(Collections.singletonList(CONDITION_ID));
when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(openmrsCondition));
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(
new SearchQueryBundleProvider<>(theParams, dao, conditionTranslator, globalPropertyService, searchQueryInclude));
Expand Down
Expand Up @@ -337,8 +337,8 @@ public void searchForConditions_shouldReturnUniqueConditionsByPatientGivenName()
assertThat(results, notNullValue());
assertThat(results.size(), equalTo(2));

Set<String> resultSet = new HashSet<>(dao.getSearchResultUuids(theParams));
assertThat(resultSet.size(), equalTo(2)); // 6 with repetitions
Set<Integer> resultSet = new HashSet<>(dao.getSearchResultIds(theParams));
assertThat(resultSet, hasSize(2)); // 6 with repetitions
}

@Test
Expand Down Expand Up @@ -444,8 +444,8 @@ public void searchForConditions_shouldReturnUniqueConditionsByPatientFamilyName(
assertThat(results, notNullValue());
assertThat(results.size(), equalTo(2));

Set<String> resultSet = new HashSet<>(dao.getSearchResultUuids(theParams));
assertThat(resultSet.size(), equalTo(2)); // 9 with repetitions
Set<Integer> resultSet = new HashSet<>(dao.getSearchResultIds(theParams));
assertThat(resultSet, hasSize(2)); // 9 with repetitions
}

@Test
Expand Down Expand Up @@ -534,9 +534,8 @@ public void searchForConditions_shouldReturnUniqueConditionsByPatientName() {
assertThat(results, notNullValue());
assertThat(results.size(), equalTo(2));

List<String> resultSet = dao.getSearchResultUuids(theParams);

assertThat(resultSet.size(), equalTo(2));
List<Integer> resultSet = dao.getSearchResultIds(theParams);
assertThat(resultSet, hasSize(2));
}

@Test
Expand Down
Expand Up @@ -54,15 +54,15 @@ public MedicationDispense delete(@Nonnull String uuid) {

@Override
@Authorized(PrivilegeConstants.GET_MEDICATION_DISPENSE)
public List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams) {
return super.getSearchResultUuids(theParams);
public List<Integer> getSearchResultIds(@Nonnull SearchParameterMap theParams) {
return super.getSearchResultIds(theParams);
}

@Override
@Authorized(PrivilegeConstants.GET_MEDICATION_DISPENSE)
public List<MedicationDispense> getSearchResults(@Nonnull SearchParameterMap theParams,
@Nonnull List<String> resourceUuids) {
return super.getSearchResults(theParams, resourceUuids);
@Nonnull List<Integer> resourceIds) {
return super.getSearchResults(theParams, resourceIds);
}

@Override
Expand Down
Expand Up @@ -10,11 +10,12 @@
package org.openmrs.module.fhir2.api.dao.impl;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;

import java.util.List;

Expand Down Expand Up @@ -125,10 +126,10 @@ public void shouldGetSearchResultUuidsForMatchingPatients() {
SearchParameterMap theParams = new SearchParameterMap();
theParams.addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientAndParam);

List<String> results = dao.getSearchResultUuids(theParams);
assertThat(results.size(), equalTo(2));
assertThat(results.contains("7a0282eb-b686-11ec-8065-0242ac110002"), is(true));
assertThat(results.contains("1bcb299c-b687-11ec-8065-0242ac110002"), is(true));
List<Integer> results = dao.getSearchResultIds(theParams);
assertThat(results, hasSize(2));
assertThat(results, hasItem(10));
assertThat(results, hasItem(11));
}

@Test
Expand All @@ -139,9 +140,9 @@ public void shouldGetSearchResultUuidsForMatchingEncounters() {
SearchParameterMap theParams = new SearchParameterMap();
theParams.addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, param);

List<String> results = dao.getSearchResultUuids(theParams);
assertThat(results.size(), equalTo(1));
assertThat(results.contains("7a0282eb-b686-11ec-8065-0242ac110002"), is(true));
List<Integer> results = dao.getSearchResultIds(theParams);
assertThat(results, hasSize(1));
assertThat(results, hasItem(10));
}

@Test
Expand All @@ -152,9 +153,9 @@ public void shouldGetSearchResultUuidsForMatchingDrugOrders() {
SearchParameterMap theParams = new SearchParameterMap();
theParams.addParameter(FhirConstants.MEDICATION_REQUEST_REFERENCE_SEARCH_HANDLER, param);

List<String> results = dao.getSearchResultUuids(theParams);
assertThat(results.size(), equalTo(1));
assertThat(results.contains("b75c5c9e-b66c-11ec-8065-0242ac110002"), is(true));
List<Integer> results = dao.getSearchResultIds(theParams);
assertThat(results, hasSize(1));
assertThat(results, hasItem(1));
}

@Test
Expand Down
Expand Up @@ -56,9 +56,11 @@
@RunWith(MockitoJUnitRunner.class)
public class FhirMedicationDispenseServiceImpl_2_6Test {

public static final String MEDICATION_DISPENSE_UUID = "43578769-f1a4-46af-b08b-d9fe8a07066f";
private static final Integer MEDICATION_DISPENSE_ID = 123;

public static final String NEW_DISPENSE_UUID = "a15e4988-d07a-11ec-8307-0242ac110002";
private static final String MEDICATION_DISPENSE_UUID = "43578769-f1a4-46af-b08b-d9fe8a07066f";

private static final String NEW_DISPENSE_UUID = "a15e4988-d07a-11ec-8307-0242ac110002";

@Mock
private FhirMedicationDispenseDao<MedicationDispense> dao;
Expand Down Expand Up @@ -231,7 +233,7 @@ public void searchMedicationDispenses_shouldGetSearchResults() {
.addParameter(FhirConstants.MEDICATION_REQUEST_REFERENCE_SEARCH_HANDLER, medicationRequestParam)
.addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes).setSortSpec(sortParam);

when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(MEDICATION_DISPENSE_UUID));
when(dao.getSearchResultIds(any())).thenReturn(Collections.singletonList(MEDICATION_DISPENSE_ID));
when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(openmrsDispense));
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(
new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
Expand Down
Expand Up @@ -9,6 +9,16 @@
*/
package org.openmrs.module.fhir2.api.search;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.iterableWithSize;
import static org.hamcrest.Matchers.notNullValue;

import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.TokenAndListParam;
Expand All @@ -28,16 +38,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;

import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.iterableWithSize;
import static org.hamcrest.Matchers.notNullValue;

@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false)
public class EncounterSearchQueryImpl_2_6Test extends BaseModuleContextSensitiveTest {

Expand Down
Expand Up @@ -14,6 +14,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;

Expand Down Expand Up @@ -91,7 +92,7 @@ public void searchForMedicationRequest_shouldReturnMedicationRequestByPatientUui
List<IBaseResource> resultList = get(results);

assertThat(resultList, not(empty()));
assertThat(resultList.size(), equalTo(7));
assertThat(resultList, hasSize(7));
assertThat(resultList, hasItem(hasProperty("id", equalTo(MEDICATION_REQUEST_UUID)))); // order 2
assertThat(resultList, hasItem(hasProperty("id", equalTo("2662e6c2-697b-11e3-bd76-0800271c1b75")))); // order 222
assertThat(resultList, hasItem(hasProperty("id", equalTo("e3d621f0-a4d5-47d1-a4e1-5ace3f66d43a")))); // order 3
Expand Down
Expand Up @@ -34,5 +34,5 @@ public interface FhirAllergyIntoleranceDao extends FhirDao<Allergy> {

@Override
@Authorized(PrivilegeConstants.GET_ALLERGIES)
List<Allergy> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<String> resourceUuids);
List<Allergy> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<Integer> resourceIds);
}
Expand Up @@ -39,7 +39,7 @@ public interface FhirConceptDao extends FhirDao<Concept> {

@Override
@Authorized(PrivilegeConstants.GET_CONCEPTS)
List<Concept> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<String> resourceUuids);
List<Concept> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<Integer> resourceIds);

@Authorized(PrivilegeConstants.GET_CONCEPTS)
List<Concept> getConceptsWithAnyMappingInSource(ConceptSource conceptSource, String mappingCode);
Expand Down
Expand Up @@ -29,8 +29,8 @@ public interface FhirConditionDao<T extends OpenmrsObject & Auditable> extends F
T delete(@Nonnull String uuid);

@Override
List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams);
List<Integer> getSearchResultIds(@Nonnull SearchParameterMap theParams);

@Override
List<T> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<String> resourceUuids);
List<T> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<Integer> resourceIds);
}
Expand Up @@ -32,7 +32,7 @@ public interface FhirDao<T extends OpenmrsObject & Auditable> extends Serializab

T delete(@Nonnull String uuid);

List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams);
List<Integer> getSearchResultIds(@Nonnull SearchParameterMap theParams);

List<T> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<String> resourceUuids);
List<T> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<Integer> resourceIds);
}
Expand Up @@ -34,9 +34,9 @@ public interface FhirDiagnosticReportDao extends FhirDao<FhirDiagnosticReport> {

@Override
@Authorized(PrivilegeConstants.GET_OBS)
List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams);
List<Integer> getSearchResultIds(@Nonnull SearchParameterMap theParams);

@Override
@Authorized(PrivilegeConstants.GET_OBS)
List<FhirDiagnosticReport> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<String> resourceUuids);
List<FhirDiagnosticReport> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<Integer> resourceIds);
}
Expand Up @@ -33,10 +33,13 @@ public interface FhirEncounterDao extends FhirDao<Encounter> {
Encounter delete(@Nonnull String uuid);

@Override
@Authorized(PrivilegeConstants.GET_ENCOUNTERS)
List<Integer> getSearchResultIds(@Nonnull SearchParameterMap theParams);

@Authorized(PrivilegeConstants.GET_ENCOUNTERS)
List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams);

@Override
@Authorized(PrivilegeConstants.GET_ENCOUNTERS)
List<Encounter> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<String> resourceUuids);
List<Encounter> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<Integer> resourceIds);
}
Expand Up @@ -41,11 +41,11 @@ List<LocationAttribute> getActiveAttributesByLocationAndAttributeTypeUuid(@Nonnu

@Override
@Authorized(PrivilegeConstants.GET_LOCATIONS)
List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams);
List<Integer> getSearchResultIds(@Nonnull SearchParameterMap theParams);

@Override
@Authorized(PrivilegeConstants.GET_LOCATIONS)
List<Location> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<String> resourceUuids);
List<Location> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<Integer> resourceIds);

@Authorized({ PrivilegeConstants.GET_LOCATIONS })
LocationTag getLocationTagByName(@Nonnull String tag);
Expand Down
Expand Up @@ -34,9 +34,9 @@ public interface FhirMedicationDao extends FhirDao<Drug> {

@Override
@Authorized(PrivilegeConstants.GET_CONCEPTS)
List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams);
List<Integer> getSearchResultIds(@Nonnull SearchParameterMap theParams);

@Override
@Authorized(PrivilegeConstants.GET_CONCEPTS)
List<Drug> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<String> resourceUuids);
List<Drug> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<Integer> resourceIds);
}
Expand Up @@ -29,8 +29,8 @@ public interface FhirMedicationDispenseDao<T extends OpenmrsObject & Auditable>
T delete(@Nonnull String uuid);

@Override
List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams);
List<Integer> getSearchResultIds(@Nonnull SearchParameterMap theParams);

@Override
List<T> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<String> resourceUuids);
List<T> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<Integer> resourceIds);
}
Expand Up @@ -34,9 +34,9 @@ public interface FhirMedicationRequestDao extends FhirDao<DrugOrder> {

@Override
@Authorized(PrivilegeConstants.GET_ORDERS)
List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams);
List<Integer> getSearchResultIds(@Nonnull SearchParameterMap theParams);

@Override
@Authorized(PrivilegeConstants.GET_ORDERS)
List<DrugOrder> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<String> resourceUuids);
List<DrugOrder> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<Integer> resourceIds);
}
Expand Up @@ -34,9 +34,9 @@ public interface FhirObservationDao extends FhirDao<Obs> {

@Override
@Authorized(PrivilegeConstants.GET_OBS)
List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams);
List<Integer> getSearchResultIds(@Nonnull SearchParameterMap theParams);

@Override
@Authorized(PrivilegeConstants.GET_OBS)
List<Obs> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<String> resourceUuids);
List<Obs> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<Integer> resourceIds);
}
Expand Up @@ -45,9 +45,9 @@ public interface FhirPatientDao extends FhirDao<Patient> {

@Override
@Authorized(PrivilegeConstants.GET_PATIENTS)
List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams);
List<Integer> getSearchResultIds(@Nonnull SearchParameterMap theParams);

@Override
@Authorized(PrivilegeConstants.GET_PATIENTS)
List<Patient> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<String> resourceUuids);
List<Patient> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<Integer> resourceIds);
}
Expand Up @@ -39,9 +39,9 @@ List<PersonAttribute> getActiveAttributesByPersonAndAttributeTypeUuid(@Nonnull P

@Override
@Authorized(PrivilegeConstants.GET_PERSONS)
List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams);
List<Integer> getSearchResultIds(@Nonnull SearchParameterMap theParams);

@Override
@Authorized(PrivilegeConstants.GET_PERSONS)
List<Person> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<String> resourceUuids);
List<Person> getSearchResults(@Nonnull SearchParameterMap theParams, @Nonnull List<Integer> resourceIds);
}

0 comments on commit 4930275

Please sign in to comment.