From 67c5e69cc702cfb41075a686e841494656ba8e6e Mon Sep 17 00:00:00 2001 From: zxenia Date: Tue, 29 Mar 2022 20:08:32 -0400 Subject: [PATCH 1/2] set extra_properties string filter to iexact lookup --- chord_metadata_service/patients/filters.py | 2 +- chord_metadata_service/patients/tests/test_api.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/chord_metadata_service/patients/filters.py b/chord_metadata_service/patients/filters.py index 25e2b91c5..a1c829680 100644 --- a/chord_metadata_service/patients/filters.py +++ b/chord_metadata_service/patients/filters.py @@ -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: diff --git a/chord_metadata_service/patients/tests/test_api.py b/chord_metadata_service/patients/tests/test_api.py index 88e99480f..cce827b71 100644 --- a/chord_metadata_service/patients/tests/test_api.py +++ b/chord_metadata_service/patients/tests/test_api.py @@ -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) @@ -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]) @@ -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]) From 36f3594cc537ce426983f37af0fa99d5065469b5 Mon Sep 17 00:00:00 2001 From: zxenia Date: Tue, 29 Mar 2022 20:15:53 -0400 Subject: [PATCH 2/2] update version in package.cfg --- chord_metadata_service/package.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chord_metadata_service/package.cfg b/chord_metadata_service/package.cfg index 6c713e093..66666ad57 100644 --- a/chord_metadata_service/package.cfg +++ b/chord_metadata_service/package.cfg @@ -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