From cb479c7f6a40e19b070aa6cd5d11c59ffc0ae282 Mon Sep 17 00:00:00 2001 From: marekbiczysko Date: Thu, 14 Nov 2024 16:14:24 +0100 Subject: [PATCH 1/3] 2219214_rdi_dedup_statistics_against_population --- .../apps/registration_data/models.py | 25 +++++++++---------- .../apps/registration_datahub/celery_tasks.py | 1 - .../registration_datahub/tasks/rdi_merge.py | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/hct_mis_api/apps/registration_data/models.py b/src/hct_mis_api/apps/registration_data/models.py index d9ff67d28a..f91e5e98b4 100644 --- a/src/hct_mis_api/apps/registration_data/models.py +++ b/src/hct_mis_api/apps/registration_data/models.py @@ -12,6 +12,7 @@ from django.db.models import Count, OuterRef, Q, Subquery from django.utils.translation import gettext_lazy as _ +from apps.household.models import DUPLICATE from hct_mis_api.apps.activity_log.utils import create_mapping_dict from hct_mis_api.apps.core.models import BusinessArea from hct_mis_api.apps.household.models import ( @@ -19,6 +20,7 @@ Individual, PendingHousehold, PendingIndividual, + NEEDS_ADJUDICATION, ) from hct_mis_api.apps.registration_datahub.apis.deduplication_engine import ( SimilarityPair, @@ -241,19 +243,16 @@ def refresh_population_statistics(self) -> None: def biometric_deduplication_enabled(self) -> bool: return self.program.biometric_deduplication_enabled - def update_needs_adjudication_tickets_statistic(self) -> None: - from hct_mis_api.apps.grievance.models import GrievanceTicket - - # AB#201950 - self.golden_record_possible_duplicates = ( - self.grievanceticket_set.filter( - category=GrievanceTicket.CATEGORY_NEEDS_ADJUDICATION, - registration_data_import=self, - ) - .exclude(status=GrievanceTicket.STATUS_CLOSED) - .count() - ) - self.save(update_fields=["golden_record_possible_duplicates"]) + def update_duplicates_against_population_statistics(self) -> None: + self.golden_record_duplicates = Individual.objects.filter( + registration_data_import_id=self.id, + deduplication_golden_record_status=DUPLICATE, + ).count() + self.golden_record_possible_duplicates = Individual.objects.filter( + registration_data_import_id=self.id, + deduplication_golden_record_status=NEEDS_ADJUDICATION, + ).count() + self.save(update_fields=["golden_record_duplicates", "golden_record_possible_duplicates"]) def bulk_update_household_size(self) -> None: # AB#208387 diff --git a/src/hct_mis_api/apps/registration_datahub/celery_tasks.py b/src/hct_mis_api/apps/registration_datahub/celery_tasks.py index 7d13661f2e..4c7f162b2a 100644 --- a/src/hct_mis_api/apps/registration_datahub/celery_tasks.py +++ b/src/hct_mis_api/apps/registration_datahub/celery_tasks.py @@ -382,7 +382,6 @@ def deduplicate_documents(rdi_id: str) -> bool: documents_query, registration_data_import=rdi, ) - rdi.update_needs_adjudication_tickets_statistic() return True diff --git a/src/hct_mis_api/apps/registration_datahub/tasks/rdi_merge.py b/src/hct_mis_api/apps/registration_datahub/tasks/rdi_merge.py index 1da82d4b82..10a9424df8 100644 --- a/src/hct_mis_api/apps/registration_datahub/tasks/rdi_merge.py +++ b/src/hct_mis_api/apps/registration_datahub/tasks/rdi_merge.py @@ -364,9 +364,9 @@ def execute(self, registration_data_import_id: str) -> None: dedupe_service.create_grievance_tickets_for_duplicates(obj_hct) dedupe_service.update_rdis_deduplication_statistics(obj_hct.program, exclude_rdi=obj_hct) - obj_hct.update_needs_adjudication_tickets_statistic() obj_hct.status = RegistrationDataImport.MERGED obj_hct.save() + obj_hct.update_duplicates_against_population_statistics() # create household and individual collections - only for Program Population Import if obj_hct.data_source == RegistrationDataImport.PROGRAM_POPULATION: From a14962a6afe9fa4475aa34c06134093bea11f15e Mon Sep 17 00:00:00 2001 From: marekbiczysko Date: Thu, 14 Nov 2024 16:15:04 +0100 Subject: [PATCH 2/3] import fix --- src/hct_mis_api/apps/registration_data/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hct_mis_api/apps/registration_data/models.py b/src/hct_mis_api/apps/registration_data/models.py index f91e5e98b4..1a70811f38 100644 --- a/src/hct_mis_api/apps/registration_data/models.py +++ b/src/hct_mis_api/apps/registration_data/models.py @@ -12,7 +12,6 @@ from django.db.models import Count, OuterRef, Q, Subquery from django.utils.translation import gettext_lazy as _ -from apps.household.models import DUPLICATE from hct_mis_api.apps.activity_log.utils import create_mapping_dict from hct_mis_api.apps.core.models import BusinessArea from hct_mis_api.apps.household.models import ( @@ -21,6 +20,7 @@ PendingHousehold, PendingIndividual, NEEDS_ADJUDICATION, + DUPLICATE ) from hct_mis_api.apps.registration_datahub.apis.deduplication_engine import ( SimilarityPair, From d39a565d08ad2cf3f670bfccb865ffacf9316185 Mon Sep 17 00:00:00 2001 From: marekbiczysko Date: Thu, 14 Nov 2024 16:21:40 +0100 Subject: [PATCH 3/3] lint --- src/hct_mis_api/apps/registration_data/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hct_mis_api/apps/registration_data/models.py b/src/hct_mis_api/apps/registration_data/models.py index 1a70811f38..adcbca029c 100644 --- a/src/hct_mis_api/apps/registration_data/models.py +++ b/src/hct_mis_api/apps/registration_data/models.py @@ -15,12 +15,12 @@ from hct_mis_api.apps.activity_log.utils import create_mapping_dict from hct_mis_api.apps.core.models import BusinessArea from hct_mis_api.apps.household.models import ( + DUPLICATE, + NEEDS_ADJUDICATION, Household, Individual, PendingHousehold, PendingIndividual, - NEEDS_ADJUDICATION, - DUPLICATE ) from hct_mis_api.apps.registration_datahub.apis.deduplication_engine import ( SimilarityPair,