Exemplo n.º 1
0
    def post(self, request, *args, **kwargs):
        # create a form instance and populate it with data from the request:
        form = CheckInForm(request.POST)

        if form.is_valid():
            # update status to Arrived on the api
            oauth_provider = UserSocialAuth.objects.get(provider='drchrono')
            access_token = oauth_provider.extra_data['access_token']
            appointments_client = AppointmentEndpoint(access_token)
            appointments_client.update(form.cleaned_data.get('appointment_id'), {'status': 'Arrived'})

            # locally set status to Arrived, and arrival_time to right now
            visit = Visit.objects.get(appointment_id=form.cleaned_data.get('appointment_id'),
                                      patient_id=form.cleaned_data.get('patient_id'))
            visit.arrival_time = timezone.now()
            visit.status = 'Arrived'
            visit.save()

            # redirect to demographics page
            return HttpResponseRedirect(f'/demographics/?patient_id={form.cleaned_data.get("patient_id")}')
        return render(request, 'check_in.html', {'form': form})
Exemplo n.º 2
0
 def post(self, request, **kwargs):
     form = CheckInForm(request.POST)
     if form.is_valid():
         fname, lname, dob = self.collectCheckInData(form)
         patient_id = self.get_patient_details_with_first_last_dob(
             fname, lname, dob)
         if patient_id:
             url = "/update_information/" + str(patient_id)
             return redirect(url)
         else:
             return render(
                 request, self.template_name, {
                     'form':
                     CheckInForm(),
                     'error': [
                         "No matching records were found. Please check your name."
                     ]
                 })
     elif form.errors:
         error = [str(value) for value in form.errors.values()]
         return render(request, self.template_name, {
             'form': CheckInForm(),
             'error': error
         })
Exemplo n.º 3
0
 def get(self, request, **kwargs):
     error_code = int(self.kwargs['e_code'])
     form = CheckInForm()
     error = []
     success = []
     if error_code != 0 and error_code != 100:
         error += [
             'Sorry, Looks like you have no appointments today.',
             "Looks like something's wrong. Please try again."
         ]
         error = [error[error_code - 1]]
     elif error_code == 100:
         error = []
         avg_time = "%.2f" % (self.get_average_wait_time())
         success = [
             'You are all set. Have a seat! Currently, the average waiting time is '
             + str(avg_time) + ' minutes.'
         ]
     return render(request, self.template_name, {
         'form': form,
         'error': error,
         'success': success
     })
Exemplo n.º 4
0
    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})
Exemplo n.º 5
0
    def get(self, request, *args, **kwargs):
        # GET send a blank form for the pacent
        template = 'patient_check_in.html'
        form = CheckInForm()

        return render(request, template, {'form': form})
Exemplo n.º 6
0
 def get(self, request, *args, **kwargs):
     return render(request, 'check_in.html', {'form': CheckInForm()})