From 1be757d25fbb7abb71cd37359972fe5774746f08 Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Fri, 1 Sep 2023 15:42:37 -0400 Subject: [PATCH 1/2] fix: public_search_fields endpoint not returning values correctly --- chord_metadata_service/restapi/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chord_metadata_service/restapi/utils.py b/chord_metadata_service/restapi/utils.py index 0e175327e..eef83abcc 100644 --- a/chord_metadata_service/restapi/utils.py +++ b/chord_metadata_service/restapi/utils.py @@ -604,7 +604,7 @@ def get_distinct_field_values(field_props: dict) -> list[Any]: model, field = get_model_and_field(field_props["mapping"]) threshold = get_threshold() - values_with_counts = model.objects.values_list(field).annotate(count=Count(field, distinct=True)) + values_with_counts = model.objects.values_list(field).annotate(count=Count(field)) return [val for val, count in values_with_counts if count > threshold] From 7e3b760f149a59100f793bfc46d1521d5690a6e6 Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Fri, 1 Sep 2023 15:56:29 -0400 Subject: [PATCH 2/2] test: public search fields with large cell counts --- chord_metadata_service/patients/tests/test_api.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/chord_metadata_service/patients/tests/test_api.py b/chord_metadata_service/patients/tests/test_api.py index 97fd23129..949e47159 100644 --- a/chord_metadata_service/patients/tests/test_api.py +++ b/chord_metadata_service/patients/tests/test_api.py @@ -592,6 +592,15 @@ def test_public_filtering_mapping_for_search_filter(self): response_obj = response.json() self.assertEqual(1, response_obj["count"]) + @override_settings(CONFIG_PUBLIC=CONFIG_PUBLIC_TEST) + def test_public_overview_sex(self): + response = self.client.get('/api/public_search_fields') + self.assertEqual(response.status_code, status.HTTP_200_OK) + response_obj = response.json() + + # overview for sex should have entries due to large cell counts: MALE, FEMALE, UNKNOWN, OTHER + self.assertEqual(len(response_obj["sections"][0]["fields"][0]["options"]), 4) # path to sex field + class PublicFilteringIndividualsTestSmallCellCount(PublicFilteringIndividualsTest): num_individuals = 3 # below configured test threshold