Exemplo n.º 1
0
    def _send_email(self):
        from rdrf.services.io.notifications.email_notification import process_notification
        from rdrf.events.events import EventType
        from registry.patients.models import Patient
        from registry.patients.models import ParentGuardian

        patient = Patient.objects.get(id=self.patient_id)
        try:
            parent = ParentGuardian.objects.get(patient=patient)
            participant_name = "%s %s" % (parent.first_name, parent.last_name)
        except ParentGuardian.DoesNotExist:
            participant_name = "No parent"

        patient_name = "%s %s" % (patient.given_names, patient.family_name)
        if self.clinician_other.speciality:
            speciality = self.clinician_other.speciality.name
        else:
            speciality = "Unspecified"

        template_data = {
            "speciality": speciality,
            "clinician_last_name": self.clinician_other.clinician_last_name,
            "participant_name": participant_name,
            "clinician_email": self.clinician_other.clinician_email,
            "patient_name": patient_name,
            "registration_link": self._construct_registration_link()
        }

        process_notification(self.registry.code,
                             EventType.CLINICIAN_SIGNUP_REQUEST, template_data)
Exemplo n.º 2
0
def send_participant_notification(registry_model, clinician_user,
                                  patient_model, diagnosis):
    from rdrf.services.io.notifications.email_notification import process_notification
    from rdrf.events.events import EventType
    from registry.patients.models import ParentGuardian
    if diagnosis is None:
        return
    participants = [
        pg for pg in ParentGuardian.objects.filter(patient=patient_model)
    ]
    if len(participants) > 0:
        participant = participants[0]
    else:
        raise Exception("No participant associated with patient")

    patient_name = "%s %s" % (patient_model.given_names,
                              patient_model.family_name)

    template_data = {
        "participant_email": participant.user.email,
        "diagnosis": diagnosis,
        "patient_name": patient_name,
        "clinician_name": clinician_user.last_name,
    }

    process_notification(registry_model.code,
                         EventType.PARTICIPANT_CLINICIAN_NOTIFICATION,
                         template_data)
Exemplo n.º 3
0
    def send(self):
        if self.state == SurveyRequestStates.REQUESTED:
            try:
                self._send_proms_request()
            except PromsRequestError as pre:
                logger.error("Error sending survey request %s: %s" % (self.pk,
                                                                      pre))
                self._set_error(pre)
                return False

            if (self.communication_type == 'email'):
                try:
                    # As we don't know how friendly the message needs to be, admin can pick the name format.
                    template_data = {
                        "display_name": f"{self.patient.given_names} {self.patient.family_name}",
                        "combined_name": self.patient.combined_name,
                        "given_names": self.patient.given_names,
                        "family_name": self.patient.family_name,
                        "patient_email": self.patient.email,
                        "email_link": self.email_link,
                        "registry_name": self.registry.name,
                        "survey_name": self.survey_name
                    }
                    process_notification(self.registry.code,
                                         EventType.SURVEY_REQUEST,
                                         template_data)

                    return True
                except PromsEmailError as pe:
                    logger.error("Error emailing survey request %s: %s" % (self.pk,
                                                                           pe))
                    self._set_error(pe)
                    return False
Exemplo n.º 4
0
def user_activated_callback(sender, user, request, **kwargs):
    from rdrf.services.io.notifications.email_notification import process_notification
    from rdrf.events.events import EventType
    from registry.patients.models import Patient
    from registry.patients.models import ParentGuardian

    parent = patient = None
    email_notification_description = EventType.ACCOUNT_VERIFIED
    template_data = {}

    if user.is_patient:
        patient = Patient.objects.get(user=user)

    elif user.is_parent:
        # is the user is a parent they will have created 1 patient (only?)
        parent = ParentGuardian.objects.get(user=user)
        patients = [p for p in parent.patient.all()]
        if len(patients) >= 1:
            patient = patients[0]

    if patient:
        template_data["patient"] = patient

    if parent:
        template_data["parent"] = parent

    template_data["user"] = user

    for registry_model in user.registry.all():
        registry_code = registry_model.code
        process_notification(registry_code, email_notification_description,
                             template_data)
Exemplo n.º 5
0
    def process(self):
        registry_code = self.request.POST['registry_code']
        registry = self._get_registry_object(registry_code)
        preferred_language = self.request.POST.get("preferred_language", "en")
        if self.clinician_signup:
            logger.debug("signing up clinician")
            self._do_clinician_signup(registry)
            return

        user = self._create_django_user(self.request,
                                        self.user,
                                        registry,
                                        is_parent=True)
        user.preferred_language = preferred_language
        # Initially UNALLOCATED
        working_group, status = WorkingGroup.objects.get_or_create(
            name=self._UNALLOCATED_GROUP, registry=registry)

        user.working_groups = [working_group]
        user.save()
        logger.debug("AngelmanRegistration process - created user")

        patient = Patient.objects.create(
            consent=True,
            family_name=self.request.POST["surname"],
            given_names=self.request.POST["first_name"],
            date_of_birth=self.request.POST["date_of_birth"],
            sex=self.request.POST["gender"])

        patient.rdrf_registry.add(registry)
        patient.working_groups.add(working_group)
        patient.home_phone = self.request.POST["phone_number"]
        patient.email = user.username
        patient.user = None

        patient.save()
        logger.debug("AngelmanRegistration process - created patient")

        address = self._create_patient_address(patient, self.request)
        address.save()
        logger.debug("AngelmanRegistration process - created patient address")

        parent_guardian = self._create_parent(self.request)

        parent_guardian.patient.add(patient)
        parent_guardian.user = user
        parent_guardian.save()
        logger.debug("AngelmanRegistration process - created parent")

        template_data = {
            "patient": patient,
            "parent": parent_guardian,
            "registration": RegistrationProfile.objects.get(user=user)
        }

        process_notification(registry_code, EventType.NEW_PATIENT,
                             template_data)
        logger.debug(
            "AngelmanRegistration process - sent notification for NEW_PATIENT")
Exemplo n.º 6
0
    def _send_email_notification(self, user, days_left):
        template_data = {
            'user': user,
            'days_left': days_left,
        }

        for registry_model in user.registry.all():
            process_notification(registry_model.code,
                                 EventType.PASSWORD_EXPIRY_WARNING,
                                 template_data)
Exemplo n.º 7
0
def account_lockout_handler(sender, user=None, **kwargs):
    from rdrf.services.io.notifications.email_notification import process_notification

    template_data = {
        "user": user,
    }

    for registry_model in user.registry.all():
        process_notification(registry_model.code, EventType.ACCOUNT_LOCKED,
                             template_data)
Exemplo n.º 8
0
    def notify_participant_on_verification(self, diagnosis=""):
        from registry.patients.models import Patient
        patient = Patient.objects.get(id=self.patient_id)
        participants = self._get_participants(patient)
        event_type = EventType.PARTICIPANT_CLINICIAN_NOTIFICATION
        template_data = {
            "diagnosis": diagnosis,
            "clinician_name": self.clinican_other.clinician_name,
            "participants": participants,
            "patient_name": "%s" % patient,
        }

        from rdrf.services.io.notifications.email_notification import process_notification
        process_notification(self.registry.code, event_type, template_data)
Exemplo n.º 9
0
    def _do_clinician_signup(self, registry_model):
        from rdrf.helpers.utils import get_site
        user = self._create_django_user(self.request,
                                        self.user,
                                        registry_model,
                                        is_parent=False,
                                        is_clinician=True)

        logger.debug("created django user for clinician")

        # working group should be the working group of the patient
        patient = Patient.objects.get(id=self.clinician_signup.patient_id)

        user.working_groups = [wg for wg in patient.working_groups.all()]
        user.save()
        logger.debug("set clinician working groups to patient's")
        self.clinician_signup.clinician_other.user = user
        self.clinician_signup.clinician_other.use_other = False
        self.clinician_signup.clinician_other.save()
        self.clinician_signup.state = "signed-up"  # at this stage the user is created but not active
        self.clinician_signup.save()
        patient.clinician = user
        patient.save()
        logger.debug("made this clinician the clinician of the patient")

        site_url = get_site()

        activation_template_data = {
            "site_url": site_url,
            "clinician_email": self.clinician_signup.clinician_email,
            "clinician_lastname":
            self.clinician_signup.clinician_other.clinician_last_name,
            "registration": RegistrationProfile.objects.get(user=user)
        }

        process_notification(registry_model.code,
                             EventType.CLINICIAN_ACTIVATION,
                             activation_template_data)
        logger.debug(
            "AngelmanRegistration process - sent activation link for registered clinician"
        )