Пример #1
0
    def test_get_enabled_doctors(test_user):
        inactive_user = UserFactory(is_active=False)
        active_doctor = DoctorProfileFactory(user=test_user)
        DoctorProfileFactory(user=inactive_user)

        doctors = DoctorProfileSelector.get_enabled_doctors()
        assert isinstance(doctors, QuerySet)
        assert doctors.count() == 1
        assert doctors.first() == active_doctor
Пример #2
0
    def create(cls,
               doctor_uuid,
               visitor,
               date,
               time,
               site=AppointmentSite.IN_PLACE):
        doctor = DoctorProfileSelector.get_by_uuid(doctor_uuid)
        status = AppointmentStatus.ACCEPTED if doctor.auto_confirmation else AppointmentStatus.REQUESTED

        try:
            return Appointment.objects.create(
                consultation_duration=doctor.consultation_duration,
                doctor=doctor,
                visitor=visitor,
                site=site,
                status=status,
                date=date,
                time=time,
            )
        except IntegrityError:
            raise SimpleValidationError(**UNAVAILABLE_DATETIME)
Пример #3
0
    def create(self, request, **kwargs):
        serializer = CreateAppointmentSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        appointment = AppointmentService.create(
            serializer.validated_data['doctor_uuid'],
            visitor=request.user,
            date=serializer.validated_data['date'],
            time=serializer.validated_data['time'],
            site=serializer.validated_data['site'],
        )

        # Send email, it could be async
        AppointmentService.send_reminder(appointment)

        week = DoctorProfileService.get_week_number(
            serializer.validated_data['date'],
            serializer.validated_data['time'],
        )
        doctor = DoctorProfileSelector.get_by_uuid(serializer.validated_data['doctor_uuid'])
        week_days = DoctorProfileService.week_calendar(doctor, week=week)
        return Response({
            'appointment': AppointmentSerializer(appointment).data,
            'week_days': week_days
        })
Пример #4
0
 def test_get_enabled_doctors_empty():
     inactive_user = UserFactory(is_active=False)
     DoctorProfileFactory(user=inactive_user)
     doctors = DoctorProfileSelector.get_enabled_doctors()
     assert isinstance(doctors, QuerySet)
     assert doctors.count() == 0
Пример #5
0
 def test_get_by_uuid_not_found():
     with pytest.raises(NotFound) as exec_info:
         DoctorProfileSelector.get_by_uuid(faker.uuid4())
     assert exec_info.value.detail.code == DOCTOR_NOT_FOUND['code']
Пример #6
0
 def test_get_by_uuid():
     doctor_profile = DoctorProfileFactory()
     selected_doctor_profile = DoctorProfileSelector.get_by_uuid(
         str(doctor_profile.uuid))
     assert isinstance(doctor_profile, DoctorProfile)
     assert selected_doctor_profile == doctor_profile
Пример #7
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data()
     context['doctors'] = DoctorProfileSelector.get_enabled_doctors()
     return context
Пример #8
0
    def calendar(self, request, doctor_uuid, **kwargs):
        week = clean_int(request.query_params.get('week'))
        professional = DoctorProfileSelector.get_by_uuid(doctor_uuid)

        calendar = DoctorProfileService.week_calendar(professional, week=week)
        return Response(calendar)
Пример #9
0
    def appointments(self, request, doctor_uuid, **kwargs):
        """It shows the appointments to the professionals."""

        doctor = DoctorProfileSelector.get_by_uuid(doctor_uuid)
        appointments = AppointmentSelector.doctor_appointments(doctor)
        return Response(AppointmentSerializer(appointments, many=True).data)
Пример #10
0
 def retrieve(self, request, doctor_uuid, **kwargs):
     doctor = DoctorProfileSelector.get_by_uuid(doctor_uuid)
     return Response(DoctorProfileSerializer(doctor).data)
Пример #11
0
 def list(self, request, **kwargs):
     doctors = DoctorProfileSelector.get_enabled_doctors()
     return Response(DoctorProfileSerializer(doctors, many=True).data)