コード例 #1
0
 def test__str__(self):
     u = User(first_name="John", last_name="Smith")
     u.save()
     patient = Patient(user=u,
                       gender='M',
                       mobile="+447476666555",
                       date_of_birth=date(year=1995, month=1, day=1))
     patient.save()
     self.assertEqual(str(patient), 'John Smith')
コード例 #2
0
 def form_valid(self, form):
     user = form.save(commit=False)
     user.username = user.email
     user.save()
     patient = Patient(user=user,
                       date_of_birth=form.cleaned_data['date_of_birth'],
                       gender=form.cleaned_data['gender'],
                       mobile=form.cleaned_data['mobile']
                       )
     patient.save()
     send_patient_confirm_email(patient, get_current_site(self.request))
     return super().form_valid(form)
コード例 #3
0
 def test_send_email_confirmed(self):
     user = User.objects.create_user(username='******',
                                     password='******',
                                     first_name="Woof",
                                     last_name="Meow",
                                     email="*****@*****.**")
     user.save()
     patient = Patient(user=user,
                       gender='M',
                       mobile="+447476666555",
                       date_of_birth=date(year=1995, month=1, day=1))
     patient.save()
     send_patient_email_confirmed(patient)
     self.assertEqual(len(mail.outbox), 1)
コード例 #4
0
 def test_when_patient_valid_and_valid_butemail_not_confirmed(self):
     user = User.objects.create_user(username='******',
                                     password='******')
     patient = Patient(user=user,
                       date_of_birth=date(year=1995, month=2, day=20),
                       gender='M',
                       mobile='+447476565333',
                       email_confirmed=False)
     patient.save()
     form = PatientLoginForm(data={
         'username': '******',
         'password': '******'
     })
     self.assertFalse(form.is_valid())
コード例 #5
0
    def test_edit_email(self):
        user = User.objects.create_user(username='******',
                                        password='******',
                                        first_name='John',
                                        last_name='Smith')
        patient = Patient(user=user,
                          date_of_birth=date(year=1995, month=2, day=20),
                          gender='M',
                          mobile='+447476565333')
        patient.save()

        patient = PatientUserForm(instance=user,
                                  data={
                                      'first_name':
                                      'John',
                                      'last_name':
                                      'Smith',
                                      'gender':
                                      'M',
                                      'date_of_birth':
                                      date(year=1995, month=2, day=20),
                                      'email':
                                      '*****@*****.**',
                                      'mobile':
                                      '+447476565333',
                                  })
        patient.save()
        self.assertTrue(patient.is_valid())
        self.assertEqual(str(user.email), '*****@*****.**')
コード例 #6
0
class ReviewSelectedAppointmentsView(UserPassesTestMixin, TemplateView):
    template_name = 'connect_therapy/patient/bookings/review-selection.html'
    login_url = reverse_lazy('connect_therapy:patient-login')
    patient = Patient()

    def test_func(self):
        if self.request.user.is_anonymous:
            return False
        try:
            self.patient = Patient.objects.get(user=self.request.user)
            return self.patient.email_confirmed
        except (Patient.DoesNotExist, AttributeError) as e:
            return False

    """
        TODO: To help fix the 'update basket content issue' you might wanna do this:
            - Add to the post method below to load the contents of the basket to the deal with appointments part.
            - In deal with appointments, add to the basket rather than overriding the session variable
    """

    def post(self, request, *args, **kwargs):
        app_ids = request.POST.getlist('app_id')
        practitioner_id = kwargs['pk']

        if len(app_ids) == 0:
            messages.warning(request, "You haven't selected any appointments")
            return redirect('connect_therapy:patient-book-appointment', pk=practitioner_id)
        return self._deal_with_appointments(request=request, app_ids=app_ids, practitioner_id=practitioner_id)

    def _deal_with_appointments(self, request, app_ids, practitioner_id):
        valid_appointments = Appointment.check_validity(selected_appointments_id=app_ids,
                                                        selected_practitioner=practitioner_id)

        if valid_appointments is not False:
            overlap_free, appointments_to_book = Appointment.get_appointment_overlaps(valid_appointments,
                                                                                      patient=self.patient)
            if overlap_free is False:
                # valid appointments but overlap exists
                clashes = appointments_to_book
                return render(request, self.get_template_names(), context={"clashes": clashes})
            else:
                # all valid
                bookable_appointments, merged_appointments = Appointment.merge_appointments(appointments_to_book)

                if len(merged_appointments) > 1:
                    messages.success(request, str(len(merged_appointments)) + " appointments were merged")

                # add to session data - used by the checkout
                request.session['bookable_appointments'] = Appointment.appointments_to_dictionary_list(
                    bookable_appointments)
                request.session['merged_appointments'] = Appointment.appointments_to_dictionary_list(
                    merged_appointments)
                request.session['patient_id'] = self.patient.id
                return render(request, self.get_template_names(), {"bookable_appointments": bookable_appointments,
                                                                   "merged_appointments": merged_appointments,
                                                                   "practitioner_id": practitioner_id})
        else:
            # appointments not valid
            invalid_appointments = True
            return render(request, self.get_template_names(), context={"invalid_appointments": invalid_appointments})
    def test_multiple_appointments_booked(self):
        user = User.objects.create_user(username='******',
                                        password='******',
                                        first_name="Robert",
                                        last_name="Greener",
                                        email="*****@*****.**")
        user.save()
        practitioner = Practitioner(user=user,
                                    mobile="+447476605233",
                                    bio="ABC",
                                    address_line_1="XXX",
                                    address_line_2="XXXXX",
                                    is_approved=True)
        practitioner.save()

        user2 = User.objects.create_user(username='******',
                                         password='******',
                                         first_name="Woof",
                                         last_name="Meow",
                                         email="*****@*****.**")
        user2.save()
        patient = Patient(user=user2,
                          gender='M',
                          mobile="+447476605233",
                          date_of_birth=date(year=1995, month=1, day=1))
        patient.save()
        appointment1 = Appointment(practitioner=practitioner,
                                   patient=patient,
                                   start_date_and_time=datetime(year=2018,
                                                                month=4,
                                                                day=17,
                                                                hour=15,
                                                                minute=10),
                                   length=timedelta(hours=1))
        appointment1.save()
        appointment2 = Appointment(practitioner=practitioner,
                                   patient=patient,
                                   start_date_and_time=datetime(year=2018,
                                                                month=4,
                                                                day=19,
                                                                hour=15,
                                                                minute=10),
                                   length=timedelta(hours=1))
        appointment2.save()
        multiple_appointments_booked((appointment1, appointment2))
        self.assertEqual(len(mail.outbox), 4)
    def setUp(self):
        # Create two users
        test_user_1 = User.objects.create_user(username='******',
                                               email="*****@*****.**")
        test_user_1.set_password('12345')
        test_user_1.save()

        test_pat_1 = Patient(user=test_user_1,
                             email_confirmed=True,
                             gender='M',
                             mobile="+447476666555",
                             date_of_birth=date(year=1995, month=1, day=1))
        test_pat_1.save()

        test_user_2 = User.objects.create_user(username='******',
                                               email="*****@*****.**")
        test_user_2.set_password('12345')
        test_user_2.save()

        test_pat_2 = Patient(user=test_user_2,
                             email_confirmed=False,
                             gender='M',
                             mobile="+447476666555",
                             date_of_birth=date(year=1995, month=1, day=1))
        test_pat_2.save()

        # create 2 test practitioners
        test_user_3 = User.objects.create_user(username='******',
                                               email="*****@*****.**")
        test_user_3.set_password('12345')

        test_user_3.save()

        test_prac_1 = Practitioner(user=test_user_3,
                                   email_confirmed=True,
                                   address_line_1="My home",
                                   postcode="EC12 1CV",
                                   mobile="+447577293232",
                                   bio="Hello")
        test_prac_1.save()

        test_user_4 = User.objects.create_user(username='******',
                                               email="*****@*****.**")
        test_user_4.set_password('12345')

        test_user_4.save()

        test_prac_2 = Practitioner(user=test_user_4,
                                   email_confirmed=False,
                                   address_line_1="My home",
                                   postcode="EC12 1CV",
                                   mobile="+447577293232",
                                   bio="Hello")
        test_prac_2.save()
コード例 #9
0
    def test_send_practitioner_reminders(self):
        user = User.objects.create_user(username='******',
                                        password='******',
                                        first_name="Robert",
                                        last_name="Greener",
                                        email="*****@*****.**"
                                        )
        user.save()
        practitioner = Practitioner(user=user,
                                    mobile="+447476605233",
                                    bio="ABC",
                                    address_line_1="XXX",
                                    address_line_2="XXXXX",
                                    is_approved=True
                                    )
        practitioner.save()

        user2 = User.objects.create_user(username='******',
                                         password='******',
                                         first_name="Woof",
                                         last_name="Meow",
                                         email="*****@*****.**"
                                         )
        user2.save()
        patient = Patient(user=user2,
                          gender='M',
                          mobile="+447476605233",
                          date_of_birth=date(year=1995, month=1, day=1))
        patient.save()
        appointment1 = Appointment(practitioner=practitioner,
                                   patient=patient,
                                   start_date_and_time=timezone.now(),
                                   length=timedelta(hours=1))
        appointment1.save()

        appointment2 = Appointment(practitioner=practitioner,
                                   patient=patient,
                                   start_date_and_time=timezone.now(),
                                   length=timedelta(minutes=30))
        appointment2.save()

        send_practitioner_appointment_reminders()
コード例 #10
0
    def test_send_patient_practitioner_has_cancelled(self):
        user = User.objects.create_user(username='******',
                                        password='******',
                                        first_name="Robert",
                                        last_name="Greener",
                                        email="*****@*****.**")
        user.save()
        practitioner = Practitioner(user=user,
                                    mobile="+44848482732",
                                    bio="ABC",
                                    address_line_1="XXX",
                                    address_line_2="XXXXX",
                                    is_approved=True)
        practitioner.save()

        user2 = User.objects.create_user(username='******',
                                         password='******',
                                         first_name="Woof",
                                         last_name="Meow",
                                         email="*****@*****.**")
        user2.save()
        patient = Patient(user=user2,
                          gender='M',
                          mobile="+447476666555",
                          date_of_birth=date(year=1995, month=1, day=1))
        patient.save()
        appointment = Appointment(practitioner=practitioner,
                                  patient=patient,
                                  start_date_and_time=datetime(year=2018,
                                                               month=4,
                                                               day=17,
                                                               hour=15,
                                                               minute=10),
                                  length=timedelta(hours=1))
        appointment.save()
        send_patient_practitioner_has_cancelled(appointment)
        send_patient_practitioner_has_cancelled(appointment, "Hello")
        self.assertEqual(len(mail.outbox), 2)
コード例 #11
0
    def test_is_live_when_too_early(self):
        u = User(first_name="John", last_name="Smith")
        u.save()
        patient = Patient(user=u,
                          gender='M',
                          mobile="+447476666555",
                          date_of_birth=date(year=1995, month=1, day=1))

        patient.save()

        practitioner = Practitioner(user=u,
                                    address_line_1="My home",
                                    postcode="EC12 1CV",
                                    mobile="+447577293232",
                                    bio="Hello")
        practitioner.save()

        appointment = Appointment(practitioner=practitioner,
                                  patient=patient,
                                  start_date_and_time=timezone.now() +
                                  timedelta(minutes=10),
                                  length=timedelta(hours=1))
        appointment.save()
        self.assertFalse(appointment.is_live())
コード例 #12
0
    def test_when_valid_patient(self):
        user = User.objects.create_user(username='******',
                                        password='******'
                                        )
        user.save()
        patient = Patient(user=user,
                          gender='M',
                          mobile="+447476666555",
                          date_of_birth=date(year=1995, month=1, day=1))
        patient.save()

        uidb64 = urlsafe_base64_encode(force_bytes(patient.user.id))
        token = account_activation_token.make_token(patient.user)
        request = self.factory.get('/activate/{0}/{1}'.format(uidb64, token))
        middleware = SessionMiddleware()
        middleware.process_request(request)
        request.session.save()
        request.user = AnonymousUser()
        response = activate(request, uidb64, token)
        self.assertEqual(request.user, user)
        patient.refresh_from_db()
        self.assertTrue(patient.email_confirmed)
コード例 #13
0
class CheckoutView(UserPassesTestMixin, TemplateView):
    login_url = reverse_lazy('connect_therapy:patient-login')
    template_name = "connect_therapy/patient/bookings/checkout.html"
    patient = Patient()

    def test_func(self):
        if self.request.user.is_anonymous:
            return False
        try:
            self.patient = Patient.objects.get(user=self.request.user)
            return self.patient.email_confirmed
        except (Patient.DoesNotExist, AttributeError) as e:
            return False

    def get(self, request, *args, **kwargs):
        appointments_to_book = []
        try:
            appointment_dictionary = request.session['bookable_appointments']
        except KeyError:
            return render(request, self.get_template_names(), {"appointments": appointments_to_book})
        appointments_to_book = Appointment.convert_dictionaries_to_appointments(appointment_dictionary)
        return render(request, self.get_template_names(), {"appointments": appointments_to_book})

    def post(self, request, *args, **kwargs):

        if 'delete' in request.POST:
            apps = request.session['bookable_appointments']
            app_list = Appointment.convert_dictionaries_to_appointments(apps)

            for app in app_list:
                if app.session_id == request.POST['delete']:
                    app_list.remove(app)
                    # delete the appointment and update the session data
                    request.session['bookable_appointments'] = Appointment.appointments_to_dictionary_list(app_list)
                    return self.get(request, args, kwargs)

            return self.get(request, args, kwargs)
        elif 'checkout' in request.POST:
            # TODO: Add payment gateway stuff here...probably
            try:
                appointment_dictionary = request.session['bookable_appointments']
            except KeyError:
                return self.get(request, *args, **kwargs)
            del request.session['bookable_appointments']  # empty the shopping basket

            appointments_to_book = Appointment.convert_dictionaries_to_appointments(appointment_dictionary)

            # first delete the appointments we merged, if any
            merged_dictionary = request.session['merged_appointments']
            del request.session['merged_appointments']  # delete the merged appointments
            if merged_dictionary is not None:
                merged_appointment_list = Appointment.convert_dictionaries_to_appointments(merged_dictionary)
                Appointment.delete_appointments(merged_appointment_list)

            # go ahead and book those appointments
            if Appointment.book_appointments(appointments_to_book, self.patient):

                notifications.multiple_appointments_booked(appointments_to_book)  # call method from notifications.py
                return render(request, "connect_therapy/patient/bookings/booking-success.html", {
                    'appointment': appointments_to_book})
            else:
                return HttpResponse("Failed to book. Patient object doesnt exist.")