diff --git a/corehq/apps/case_search/tests/test_case_search_endpoint.py b/corehq/apps/case_search/tests/test_case_search_endpoint.py index e4ce2974950c..56d918427c58 100644 --- a/corehq/apps/case_search/tests/test_case_search_endpoint.py +++ b/corehq/apps/case_search/tests/test_case_search_endpoint.py @@ -33,9 +33,9 @@ def setUpClass(cls): super().setUpClass() cls.user = create_user("admin", "123") CaseSearchConfig.objects.create(domain=cls.domain, enabled=True) - household_1 = str(uuid.uuid4()) + cls.household_1 = str(uuid.uuid4()) case_blocks = [CaseBlock( - case_id=household_1, + case_id=cls.household_1, case_type='household', case_name="Villanueva", create=True, @@ -48,10 +48,10 @@ def setUpClass(cls): update=properties, index={'parent': IndexAttrs('household', household_id, 'child')} if household_id else None, ) for name, properties, household_id in [ - ("Jane", {"family": "Villanueva"}, household_1), - ("Xiomara", {"family": "Villanueva"}, household_1), - ("Alba", {"family": "Villanueva"}, household_1), - ("Rogelio", {"family": "de la Vega"}, household_1), + ("Jane", {"family": "Villanueva"}, cls.household_1), + ("Xiomara", {"family": "Villanueva"}, cls.household_1), + ("Alba", {"family": "Villanueva"}, cls.household_1), + ("Rogelio", {"family": "de la Vega"}, cls.household_1), ("Jane", {"family": "Ramos"}, None), ]]) case_search_es_setup(cls.domain, case_blocks) @@ -77,6 +77,10 @@ def test_basic(self): case.name for case in res ]) + def test_case_id_criteia(self): + res = get_case_search_results(self.domain, ['household'], [SearchCriteria('case_id', self.household_1)]) + self.assertItemsEqual(["Villanueva"], [case.name for case in res]) + def test_dynamic_property(self): res = get_case_search_results(self.domain, ['person'], [SearchCriteria('family', 'Ramos')]) self.assertItemsEqual(["Jane"], [case.name for case in res]) diff --git a/corehq/apps/case_search/utils.py b/corehq/apps/case_search/utils.py index 35bcb71b0402..8d65fe223c91 100644 --- a/corehq/apps/case_search/utils.py +++ b/corehq/apps/case_search/utils.py @@ -16,6 +16,7 @@ from corehq import toggles from corehq.apps.app_manager.dbaccessors import get_app_cached from corehq.apps.app_manager.util import module_offers_search +from corehq.apps.es import cases as case_es from corehq.apps.case_search.const import ( CASE_SEARCH_MAX_RESULTS, COMMCARE_PROJECT, @@ -269,6 +270,8 @@ def _apply_filter(self, search_es, criteria): for xpath in xpaths: search_es = search_es.filter(self._build_filter_from_xpath(xpath)) return search_es + elif criteria.key == 'case_id': + return search_es.filter(case_es.case_ids(criteria.value)) elif criteria.key == 'owner_id': if not criteria.is_empty: return search_es.filter(case_search.owner(criteria.value))