def get(self, request, patient_id): # GET send a blank form for the patient template = 'patient_details.html' access_token = get_token() patient_api = PatientEndpoint(access_token) patient = patient_api.fetch(patient_id) return render(request, template, {'patient': patient})
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 = 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. return next(api.list())
def change_status(self, status, appointment): access_token = get_token() appointment_api = AppointmentEndpoint(access_token) if status == "Arrived": appointment_api.update(appointment.appointment_id, {'status': 'In Session'}) appointment.start_time = timezone.now() appointment.status = "In Session" appointment.save() elif status == "In Session": appointment_api.update(appointment.appointment_id, {'status': 'Complete'}) appointment.end_time = timezone.now() appointment.status = "Complete" appointment.save() else: print("Something went wrong here")
def post(self, request, patient_id): template = 'patient_demographics.html' # create a form instance and populate it with data from the request: patient = Patient.objects.get(patient_id=patient_id) # check whether it's valid: form = PatientDemographicForm(request.POST or None, instance=patient) if form.is_valid(): access_token = get_token() patient_api = PatientEndpoint(access_token) patient_api.update(patient_id, form.cleaned_data) patient.save() return HttpResponseRedirect('/finished/') return render(request, template, { 'form': form, 'patient_id': patient_id })
def test_get_token(self): self.user_model = get_user_model() self.user = self.user_model.objects.create_user( username='******', email='*****@*****.**') self.access_token = "secret" self.usa = UserSocialAuth.objects.create( user=self.user, provider='drchrono', uid='1234', extra_data={ "access_token": self.access_token, "expires_in": 172800, "refresh_token": "wWdSgnBSwLZs1XEwxxG0CE8JRFNAjm", "auth_time": 1575496917 }) token = utils.get_token() self.assertEqual(token, "secret") # make sure oauth_provider.extra_data['access_token'] is what it returns oauth_provider = UserSocialAuth.objects.get(provider='drchrono') self.assertEqual(token, oauth_provider.extra_data['access_token'])
def post(self, request, *args, **kwargs): # create a form instance and populate it with data from the request: form = CheckInForm(request.POST) # we need to get the list of pacents on the appointment to check if they are checking in or if its a walk-in data = request.POST.copy() ssn = data.get('ssn') access_token = get_token() appointment_api = AppointmentEndpoint(access_token) if form.is_valid() and check_ssn_format(ssn): first_name, last_name, date_of_birth = form.cleaned_data.get('first_name'), \ form.cleaned_data.get('last_name'), \ form.cleaned_data.get('date').strftime('%Y-%m-%d') # here we get data from App and Pa django objects instead p = Patient.objects.get(first_name=first_name, last_name=last_name, date_of_birth=date_of_birth, social_security_number=ssn) try: p = Patient.objects.get(first_name=first_name, last_name=last_name, date_of_birth=date_of_birth, social_security_number=ssn) except Patient.DoesNotExist: p = None if not p: return HttpResponseRedirect('/patient_new/') wi = form.cleaned_data.get('walk_in') if wi: doctor = next(DoctorEndpoint(get_token()).list()) create_appointment = { 'status': 'Arrived', 'duration': 30, 'date': timezone.now(), 'doctor': doctor.get('id'), 'patient': p.patient_id, 'scheduled_time': timezone.now(), 'exam_room': 0, 'office': 276816, # hardcoded for now 'notes': 'Walk-In' } created_appointment = appointment_api.create( create_appointment) appointment, created = Appointment.objects.get_or_create( appointment_id=created_appointment.get('id'), patient_id=p.patient_id, scheduled_time=created_appointment.get('scheduled_time'), notes=created_appointment.get('notes')) else: today = timezone.now() try: appointment = Appointment.objects.get( patient_id=p.patient_id, scheduled_time__year=today.year, scheduled_time__month=today.month, scheduled_time__day=today.day) except Appointment.DoesNotExist: form.add_error( 'first_name', "We are sorry, but we could not find you on todays list, is this a walk-in?" ) return render(request, 'patient_check_in.html', {'form': form}) appointment_api.update(appointment.appointment_id, {'status': 'Arrived'}) if (appointment.status == 'Arrived'): # Here we return that they have already checked in return redirect('patient_demographic_information', patient_id=p.patient_id) appointment.arrival_time = timezone.now() appointment.status = 'Arrived' appointment.save() # redirect to demographic information page return redirect('patient_demographic_information', patient_id=p.patient_id) form.add_error('ssn', "Please Enter a Valid SSN in format 123-44-1234") return render(request, 'patient_check_in.html', {'form': form})
def get(self, request, *args, **kwargs): # GET send a blank form for the patient template = 'patient_new.html' doctor = next(DoctorEndpoint(get_token()).list()) return render(request, template, {'doctor': doctor})
def get_patients(self): auth_token = get_token() patients = PatientEndpoint(auth_token) return patients.list()
def get_appointments_on_date(self, date): auth_token = get_token() appointments = AppointmentEndpoint(auth_token) return appointments.list(date=date)