Пример #1
0
    def get(self, request):
        if self.request.is_ajax() and self.request.GET.get(
                'listtype') == 'current':
            current_appointment = Appointment.current.first()

            response_data = None
            if current_appointment:
                response_data = current_appointment
            else:
                nextappointment = Appointment.future.first()
                if nextappointment:
                    nextappointment.queue_status = 'current'
                    nextappointment.save()
                    response_data = nextappointment
            if response_data == None:
                return JsonResponse({"data": None})
            context = {
                'appointment': response_data,
            }
            return render(request, 'appointment_current.html', context)

        else:
            access_token = self.request.session.get('access_token')
            apppointment_api = AppointmentEndpoint(access_token)
            apppointment_api.get_and_store_data()
            context = {
                'future': Appointment.future.all(),
                'past': Appointment.past.all(),
            }
            return render(request, 'appointment_list.html', context)
Пример #2
0
    def make_api_request(self):
        """
        Use the token we have stored in the DB to make an API request and get
        doctor details. If this succeeds, we've proved that the OAuth setup is working
        """
        # We can create an instance of an endpoint resource class, and use it to fetch details
        access_token = self.get_token()
        self.request.session['access_token'] = access_token

        doctor_api = DoctorEndpoint(access_token)
        patient_api = PatientEndpoint(access_token)
        apppointment_api = AppointmentEndpoint(access_token)

        # Grab the first doctor from the list; normally this would be the whole
        # practice group, but your hackathon account probably only has one doctor in it.
        doctor = doctor_api.get_and_store_data()
        self.request.session['doctor'] = doctor.id
        # Get patients and appointments for the doctor and store it in the local DB
        patient_api.get_and_store_data(doctor=doctor)

        date = datetime.now(
            tz=pytz.timezone(doctor.timezone)).strftime('%Y-%m-%d')
        apppointment_api.get_and_store_data(doctor=doctor, date=date)

        return doctor