예제 #1
0
 def get(self, request):
     today = timezone.localtime(timezone.now()).date()
     token = get_access_token(request)
     appointments = ApiHelper.get_appointments(token,
                                               date=today,
                                               **request.GET)
     data = {'appointments': [], 'current': None}
     patients = ApiHelper.get_patients(token, rec=True)
     patient_table = {patient['id']: patient for patient in patients}
     for appointment in appointments:
         appointment['patient'] = patient_table[appointment['patient']]
         if appointment['status'] == 'Arrived':
             app = AppointmentProfile.objects.get(app_id=appointment['id'])
             appointment['time_waited'] = int(
                 (timezone.now() - app.arrival_time).total_seconds())
         elif appointment['status'] in ['In Session', 'Complete']:
             app = AppointmentProfile.objects.get(app_id=appointment['id'])
             appointment['time_waited'] = int(
                 (app.started_time - app.arrival_time).total_seconds())
         else:
             appointment['time_waited'] = None
         if appointment['status'] == 'In Session':
             data['current'] = appointment
         else:
             data['appointments'].append(appointment)
     return JsonResponse({'success': True, 'data': data})
예제 #2
0
def generate_api_appointments():
    now = timezone.now()
    for i in range(9, 19):
        shuffle(PATIENT)
        shuffle(DURATIONS)
        scheduled_time = now.replace(hour=i, minute=0)
        print ApiHelper.post_appointments(TOKEN, doctor=DOCTOR, duration=DURATIONS[0], exam_room=randint(1, 4),
                                          office=OFFICE,
                                          status='Confirmed',
                                          patient=PATIENT[0],
                                          scheduled_time=scheduled_time).content
예제 #3
0
def delete_all_appointment():
    today = localtime(timezone.now()).date()
    today_apps = ApiHelper.get_appointments(TOKEN, date=today)
    app_ids = [app['id'] for app in today_apps]
    for id in app_ids:
        requests.delete('https://drchrono.com/api/appointments/{}'.format(id),
                        headers={'Authorization': 'Bearer {}'.format(TOKEN), })
예제 #4
0
 def post(self, request):
     if 'id' not in request.POST:
         return JsonResponse({
             "success": False,
             'error': 'id is not specified'
         })
     token = get_access_token(request)
     res = ApiHelper.patch_appointments(token, **request.POST)
     if res.status_code != 204:
         return JsonResponse({"success": False, "error": res.json()})
     # generate or synchronize AppointmentProfile locally except when status is no show
     if 'status' in request.POST and request.POST['status'] != 'No Show':
         doctor = Doctor.objects.get(doctor_id=request.session['doc_id'])
         appointment, _ = AppointmentProfile.objects.get_or_create(
             doctor=doctor, app_id=request.POST['id'])
         status = request.POST['status']
         if status == 'In Session':
             appointment.started_time = timezone.now()
             doctor.lifetime_appointment_count += 1
             doctor.lifetime_waiting += (appointment.started_time -
                                         appointment.arrival_time)
             doctor.save()
         elif status == 'Complete':
             appointment.completed_time = timezone.now()
         appointment.save()
     return JsonResponse({"success": True})
예제 #5
0
 def get(self, request):
     token = get_access_token(request)
     response = ApiHelper.get_patients(token, **request.GET)
     # if id is specified, then a response obj is returned, otherwise a recursive get will return a list of obj
     if 'id' in request.GET:
         return JsonResponse({
             'success': response.status_code == 200,
             'data': response.json()
         })
     return JsonResponse({'success': True, 'data': response})
예제 #6
0
 def post(self, request):
     if 'id' not in request.POST:
         return JsonResponse({
             "success": False,
             'error': 'id is not specified'
         })
     token = get_access_token(request)
     res = ApiHelper.patch_patients(token, **request.POST)
     if res.status_code != 204:
         return JsonResponse({"success": False, "error": res.json()})
     return JsonResponse({"success": True})
예제 #7
0
def reset_all_appointment():
    today = localtime(timezone.now()).date()
    today_apps = ApiHelper.get_appointments(TOKEN, date=today)
    app_ids = [app['id'] for app in today_apps]
    for id in app_ids:
        ApiHelper.patch_appointments(TOKEN, id=id, status='Confirmed')