def get_context_data(self, **kwargs): kwargs = super(DoctorWelcome, self).get_context_data(**kwargs) access_token = get_token() dt_api = DoctorEndpoint(access_token) ap_api = AppointmentEndpoint(access_token) pt_api = PatientSummaryEndpoint(access_token) doctor = next(dt_api.list()) appointments = list(ap_api.list(date=dt.date.today())) app_list = [] for a in appointments: patient_info = pt_api.fetch(id=a["patient"]) a["patient_info"] = patient_info a['start_time'] = dt.datetime.strptime(a["scheduled_time"], "%Y-%m-%dT%H:%M:%S") a['end_time'] = a["start_time"]\ + dt.timedelta(minutes=int(a["duration"])) updated_at = dt.datetime.strptime(a['updated_at'], "%Y-%m-%dT%H:%M:%S") wait_time = dt.datetime.now() - updated_at a["wait_time"] = round(wait_time.total_seconds() / 60) app_list.append(a) confirmed = filter(lambda x: x["status"] == "", app_list) current = filter(lambda x: x["status"] == "In Session", app_list) arrived = filter(lambda x: x["status"] == "Arrived", app_list) complete = filter(lambda x: x["status"] == "Complete", app_list) kwargs['doctor'] = doctor kwargs['confirmed'] = confirmed kwargs['current'] = current kwargs['arrived'] = arrived kwargs['complete'] = complete return kwargs
def list(self, request): oauth_provider = UserSocialAuth.objects.get(provider='drchrono') access_token = oauth_provider.extra_data['access_token'] api = DoctorEndpoint(access_token) doctor = next(api.list()) request.session['doctor'] = doctor['id'] today = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) # today = datetime.strptime("2019-12-16", "%Y-%m-%d") tomorrow = today + timedelta(days=1) queryset = Appointment.objects.filter( scheduled_time__gte=today, scheduled_time__lte=tomorrow, doctor=doctor['id'] ).order_by('scheduled_time') serializer = retrieveAppointmentSerializer(queryset, many=True) avg_wait_time = Appointment.objects.filter( scheduled_time__gte=today, scheduled_time__lte=tomorrow, doctor=doctor['id'], waiting_time__isnull=False ).aggregate(models.Avg('waiting_time'))['waiting_time__avg'] if avg_wait_time: avg_wait_time = round(avg_wait_time, 2) return Response({'appointments': serializer.data, 'avg_wait_time' : avg_wait_time, 'current_time':now()}, template_name='index.html')
def doc_db_save(self, token): """ Save doctor info to doctor table """ doc_api = DoctorEndpoint(token) for p in doc_api.list(): doctor = models.Doctor(doctor_id=p[u'id'], first_name=p[u'first_name'], last_name=p[u'last_name'], \ specialty=p[u'specialty'], cell_phone=p[u'cell_phone'], email=p[u'email']) doctor.save() return
def make_doctor_api_request(request, access_token): doctor_api = DoctorEndpoint(access_token) detail = next(doctor_api.list()) doctor, _ = Doctor.objects.get_or_create( id=detail["id"], user=request.user, first_name=detail["first_name"], last_name=detail["last_name"], office_phone=detail["office_phone"]) return DoctorSerializer(instance=doctor).data
def get_doctor(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 api = DoctorEndpoint(self.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. return next(api.list())
def get_doctors(self): """ Get all doctors (without pagenating), should only contain 1, for developer API Using ID as key """ access_token = self.get_token() api = DoctorEndpoint(access_token) for doctor in list(api.list()): self.doctors[doctor['id']] = doctor return self.doctors
def manage_doctor(request): if request.method == 'POST': oauth_provider = UserSocialAuth.objects.get(provider='drchrono') access_token = oauth_provider.extra_data['access_token'] api = DoctorEndpoint(access_token) for p in api.list(): doctor = models.Doctor(doctor_id=p[u'id'], first_name=p[u'first_name'], last_name=p[u'last_name'], \ specialty=p[u'specialty'], cell_phone=p[u'cell_phone'], email=p[u'email']) doctor.save() else: pass doctor_db = models.Doctor.objects.all() return render(request, 'patient_checkin.html', {})
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 = utility.get_token() api = DoctorEndpoint(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. # u'date_of_last_appointment': u'2020-02-14' gives todays appnt return next(api.list())
def get_current_doctor(self, user): """ 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 """ access_token = self.get_token() api = DoctorEndpoint(access_token) doctor_data = next(api.list()) Doctor.objects.update_or_create(defaults={ 'user': user, 'first_name': doctor_data['first_name'], 'last_name': doctor_data['last_name'], 'office_phone': doctor_data['office_phone'] }, id=doctor_data['id']) return doctor_data
def doctor_details(self): access_token = self.get_token() api = DoctorEndpoint(access_token) return next(api.list())