Skip to content

Commit

Permalink
Merge pull request #34834 from dimagi/jt/smartlink-could-not-select-c…
Browse files Browse the repository at this point in the history
…ase-error-fix

Smartlink Error with Inline Case Search Fix
  • Loading branch information
Jtang-1 authored Jun 28, 2024
2 parents beb020c + da63e26 commit 8b315dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
16 changes: 10 additions & 6 deletions corehq/apps/case_search/tests/test_case_search_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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])
Expand Down
3 changes: 3 additions & 0 deletions corehq/apps/case_search/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 8b315dd

Please sign in to comment.