From 5c9bcec0d708af6d01e4faeb9d43991431f2c955 Mon Sep 17 00:00:00 2001 From: Lee Render Date: Wed, 22 Mar 2023 16:39:54 +0800 Subject: [PATCH] rdrf #2425 handle consent --- rdrf/rdrf/helpers/utils.py | 15 +++++++++++++++ rdrf/rdrf/services/tasks.py | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/rdrf/rdrf/helpers/utils.py b/rdrf/rdrf/helpers/utils.py index f1c05db31..fad4a7a7f 100644 --- a/rdrf/rdrf/helpers/utils.py +++ b/rdrf/rdrf/helpers/utils.py @@ -1210,3 +1210,18 @@ def custom_text(registry_model, key, default): def has_died(patient): return patient.date_of_death + + +def has_consented_to_receive_proms_emails(patient): + from rdrf.models.definition.models import ConsentQuestion + + registry_model = patient.rdrf_registry.all()[0] + consent_code = registry_model.metadata["proms_consent_code"] + consent_model = ConsentQuestion.objects.get(code=consent_code) + + consent_answer = patient.get_consent(consent_model) + + if consent_answer: + return True + + return False diff --git a/rdrf/rdrf/services/tasks.py b/rdrf/rdrf/services/tasks.py index 410b48f5f..8fa3e3f71 100644 --- a/rdrf/rdrf/services/tasks.py +++ b/rdrf/rdrf/services/tasks.py @@ -208,6 +208,7 @@ def check_proms(registry_code, pid): from registry.patients.models import Patient from rdrf.scheduling.scheduling import PromsDataAnalyser, PromsAction from rdrf.helpers.utils import has_died + from rdrf.helpers.utils import has_consented_to_receive_proms_emails registry = Registry.objects.get(code=registry_code) patient = Patient.objects.get(id=pid) @@ -217,6 +218,12 @@ def check_proms(registry_code, pid): logger.debug("patient has died so won't be sent proms requests") return + if not has_consented_to_receive_proms_emails(patient): + logger.debug( + "patient not consented to receive emails so won't be sent proms requests" + ) + return + logger.debug(f"analysing proms for {pid}") proms_data_analyser = PromsDataAnalyser(registry, patient)