Skip to content

Commit

Permalink
Update RDI summary after creation Needs Adjudication tickets (#4185)
Browse files Browse the repository at this point in the history
* fix statistics after HardDocumentDeduplication

* black

* upd tests

* more fixes

* refactor

* refactor

* review

* black

* black
  • Loading branch information
pavlo-mk authored Sep 11, 2024
1 parent 647200d commit 71024fe
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _clear_deduplication_individuals_fields(individuals: Sequence[Individual]) -
individual.deduplication_batch_status = UNIQUE_IN_BATCH
individual.deduplication_golden_record_results = {}
individual.deduplication_batch_results = {}
HardDocumentDeduplication().deduplicate(individual.documents.all())
HardDocumentDeduplication().deduplicate(individual.documents.all(), individual.registration_data_import)
Individual.objects.bulk_update(
individuals,
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def execute(self, should_populate_index: bool, individuals_ids: List[str]) -> No

if business_area.postpone_deduplication:
logger.info("Postponing deduplication for business area %s", business_area)
HardDocumentDeduplication().deduplicate(Document.objects.filter(individual_id__in=individuals_ids))
HardDocumentDeduplication().deduplicate(
Document.objects.filter(individual_id__in=individuals_ids),
)
return

DeduplicateTask(business_area.slug, individuals.first().program_id).deduplicate_individuals_from_other_source(
Expand Down Expand Up @@ -65,4 +67,6 @@ def execute(self, should_populate_index: bool, individuals_ids: List[str]) -> No
if business_area.screen_beneficiary:
CheckAgainstSanctionListPreMergeTask.execute()

HardDocumentDeduplication().deduplicate(Document.objects.filter(individual_id__in=individuals_ids))
HardDocumentDeduplication().deduplicate(
Document.objects.filter(individual_id__in=individuals_ids),
)
14 changes: 14 additions & 0 deletions backend/hct_mis_api/apps/registration_data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ 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 bulk_update_household_size(self) -> None:
# AB#208387
if self.program and self.program.data_collecting_type.recalculate_composition:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,8 @@ def deduplicate_documents() -> bool:
documents_query,
registration_data_import=rdi,
)
rdi.update_needs_adjudication_tickets_statistic()

with transaction.atomic():
documents_query = Document.objects.filter(
status=Document.STATUS_PENDING, individual__registration_data_import__isnull=True
)
HardDocumentDeduplication().deduplicate(
documents_query,
)
return True


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ def execute(self, registration_data_import_id: str) -> None:
CheckAgainstSanctionListPreMergeTask.execute(registration_data_import=obj_hct)
logger.info(f"RDI:{registration_data_import_id} Checked against sanction list")

obj_hct.update_needs_adjudication_tickets_statistic()
obj_hct.status = RegistrationDataImport.MERGED
obj_hct.save()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ def test_hard_documents_deduplication_for_the_diff_program(self) -> None:
new_document_from_other_program.refresh_from_db()
self.assertEqual(new_document_from_other_program.status, Document.STATUS_PENDING)

HardDocumentDeduplication().deduplicate(self.get_documents_query([new_document_from_other_program]))
HardDocumentDeduplication().deduplicate(
self.get_documents_query([new_document_from_other_program]), self.registration_data_import
)
new_document_from_other_program.refresh_from_db()
self.assertEqual(new_document_from_other_program.status, Document.STATUS_VALID)

Expand Down

0 comments on commit 71024fe

Please sign in to comment.