Skip to content

Commit

Permalink
Merge pull request #309 from bento-platform/patch/set-iexact-string-f…
Browse files Browse the repository at this point in the history
…ilter

Set iexact lookup for string search in extra_properties
  • Loading branch information
zxenia authored Mar 30, 2022
2 parents 308381e + 36f3594 commit 955a948
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion chord_metadata_service/package.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[package]
name = katsu
version = 2.9.0
version = 2.9.1
authors = Ksenia Zaytseva, David Lougheed, Simon Chénard, Romain Grégoire
2 changes: 1 addition & 1 deletion chord_metadata_service/patients/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def filter_extra_properties(self, qs, name, value):
for query_key, query_value in dict_item.items():
if query_key == search_field_key:
qs = qs.filter(
**{f"extra_properties__{search_field_key}__icontains": query_value}
**{f"extra_properties__{search_field_key}__iexact": query_value}
)
# add range filter for all string fields that are date format
if search_field_val["type"] == "string" and "format" in search_field_val:
Expand Down
12 changes: 6 additions & 6 deletions chord_metadata_service/patients/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ def test_public_filtering_sex(self):
def test_public_filtering_2_fields(self):
# sex and extra_properties string search
# test GET query string search for extra_properties field
response = self.client.get('/api/public?sex=female&extra_properties=[{"smoking": "Non-smoker"}]')
response = self.client.get('/api/public?sex=female&extra_properties=[{"smoking": "Smoker"}]')
self.assertEqual(response.status_code, status.HTTP_200_OK)
response_obj = response.json()
db_count = Individual.objects.filter(sex__iexact='female')\
.filter(extra_properties__contains={"smoking": "Non-smoker"}).count()
.filter(extra_properties__contains={"smoking": "Smoker"}).count()
self.assertIn(self.response_threshold_check(response_obj), [db_count, settings.INSUFFICIENT_DATA_AVAILABLE])
if db_count <= self.response_threshold:
self.assertEqual(response_obj, settings.INSUFFICIENT_DATA_AVAILABLE)
Expand Down Expand Up @@ -472,7 +472,7 @@ def test_public_filtering_extra_properties_range_string_2(self):
range_parameters = {
"extra_properties__lab_test_result_value__gte": 5,
"extra_properties__lab_test_result_value__lte": 900,
"extra_properties__covidstatus__icontains": "positive",
"extra_properties__covidstatus__iexact": "positive",
}
db_count = Individual.objects.filter(**range_parameters).count()
self.assertIn(self.response_threshold_check(response_obj), [db_count, settings.INSUFFICIENT_DATA_AVAILABLE])
Expand All @@ -486,14 +486,14 @@ def test_public_filtering_extra_properties_range_string_3(self):
# extra_properties range search (only max range) and extra_properties string search (multiple values)
response = self.client.get(
'/api/public?extra_properties=[{"lab_test_result_value": {"rangeMax": 400}}, '
'{"covidstatus": "positive"}, {"smoking": "Non-smoker"}]'
'{"covidstatus": "positive"}, {"smoking": "smoker"}]'
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
response_obj = response.json()
range_parameters = {
"extra_properties__lab_test_result_value__lte": 400,
"extra_properties__covidstatus__icontains": "positive",
"extra_properties__smoking__icontains": "Non-smoker",
"extra_properties__covidstatus__iexact": "positive",
"extra_properties__smoking__iexact": "smoker",
}
db_count = Individual.objects.filter(**range_parameters).count()
self.assertIn(self.response_threshold_check(response_obj), [db_count, settings.INSUFFICIENT_DATA_AVAILABLE])
Expand Down

0 comments on commit 955a948

Please sign in to comment.