예제 #1
0
    def get(self, request, *args, **kwargs):

        # Clearing any leftover sessions
        [
            request.session.pop(key, None)
            for key in ['quiz', 'individual', 'guardian']
        ]

        # Get the patient email and ensure they exist
        patient_email = get_jwt_email(request=request, verify=False)

        try:

            # If in demo mode, do not check participant and prior submissions
            if not self.demo(request):

                FHIR.check_patient(patient_email)

                # Check response
                FHIR.check_consent(PPM.Study.ASD.value, patient_email)

            # Create the form
            form = ASDTypeForm()

            context = {'form': form, 'return_url': self.return_url}

            return render(request,
                          template_name='consent/asd.html',
                          context=context)

        except FHIR.PatientDoesNotExist:
            logger.warning('Patient does not exist')
            return render_error(
                request,
                title='Patient Does Not Exist',
                message=
                'A FHIR resource does not yet exist for the current user. '
                'Please sign into the People-Powered dashboard to '
                'create your user.',
                support=False)

        except FHIR.QuestionnaireDoesNotExist:
            logger.warning('Consent does not exist: NEER')
            return render_error(
                request,
                title='Consent Does Not Exist',
                message='The requested consent does not exist!',
                support=False)

        except FHIR.ConsentAlreadyExists:
            logger.warning('Consent already finished')
            return render_error(
                request,
                title='Consent Already Completed',
                message='You have already filled out and submitted this '
                'consent.',
                support=False)

        except Exception as e:
            logger.error("Error while rendering consent: {}".format(e),
                         exc_info=True,
                         extra={
                             'request': request,
                             'project': 'asd',
                         })
            return render_error(
                request,
                title='Application Error',
                message='The application has experienced an unknown error{}'.
                format(': {}'.format(e) if settings.DEBUG else '.'),
                support=False)
예제 #2
0
    def get(self, request, *args, **kwargs):

        # Get the patient email and ensure they exist
        patient_email = get_jwt_email(request=request, verify=False)

        try:
            # If in demo mode, do not check participant and prior submissions
            if not self.demo(request):

                # Ensure the current user has a record
                FHIR.check_patient(patient_email)

                # Check response
                FHIR.check_consent(self.study, patient_email)

            # Create the form
            form = self.Form()

            context = {
                'study': self.study,
                'form': form,
                'return_url': self.return_url
            }

            # Build the template response
            response = render(request,
                              template_name='consent/{}.html'.format(
                                  self.study),
                              context=context)

            return response

        except FHIR.PatientDoesNotExist:
            logger.warning('Patient does not exist')
            return render_error(
                request,
                title='Patient Does Not Exist',
                message=
                'A FHIR resource does not yet exist for the current user. '
                'Please sign into the People-Powered dashboard to '
                'create your user.',
                support=False)

        except FHIR.QuestionnaireDoesNotExist:
            logger.warning('Consent does not exist: {}'.format(
                PPM.Study.title(self.study)))
            return render_error(
                request,
                title='Consent Does Not Exist: {}'.format(
                    self.questionnaire_id),
                message='The requested consent does not exist!',
                support=False)

        except FHIR.ConsentAlreadyExists:
            logger.warning('Consent already finished')
            return render_error(
                request,
                title='Consent Already Completed',
                message='You have already filled out and submitted this '
                'consent.',
                support=False)

        except Exception as e:
            logger.error("Error while rendering consent: {}".format(e),
                         exc_info=True,
                         extra={
                             'request': request,
                             'project': self.study,
                             'questionnaire': self.questionnaire_id,
                             'form': self.Form
                         })
            return render_error(
                request,
                title='Application Error',
                message='The application has experienced an unknown error{}'.
                format(': {}'.format(e) if settings.DEBUG else '.'),
                support=False)