Exemplo n.º 1
0
    def confirm(self, request):
        # print pk
        pk = request.POST.get('pk', None)

        oauth_provider = UserSocialAuth.objects.get(provider='drchrono')
        access_token = oauth_provider.extra_data['access_token']
        endpoint = AppointmentEndpoint(access_token)

        res = endpoint.update(pk, {'status': 'Arrived'})
        api_data = endpoint.fetch(id=pk)

        try:
            model = Appointment.objects.get(pk=pk)
            serializer = AppointmentSerializer(model, data=api_data)

            if serializer.is_valid():
                serializer.save()

                message = 'Successfully check in.'
                return HttpResponse(message, status=200)

        except Appointment.DoesNotExist:
            pass

        message = 'Sorry, fail to check in.'
        return HttpResponse(message, status=403)
Exemplo n.º 2
0
def get_appointment(request):
    """
    This is an ajax call to get an appointment from drchrono api
    :param request: containing appointment_id in the request body
    :return: success msg with appointment data or API error
    """

    appointment_id = request.POST.get('appointment_id', '')

    if not appointment_id:
        return JsonResponse(
            {'msg': 'No appointment_id in the the request body'})

    access_token = UserSocialAuth.objects.get(
        provider='drchrono').extra_data['access_token']
    appointment_api = AppointmentEndpoint(access_token)

    try:
        appointment = appointment_api.fetch(appointment_id)
        if appointment:
            appointment = decorate_appointments([appointment], access_token)

    except APIException:
        return JsonResponse({'msg': 'No appointment is returned from api'})

    return JsonResponse({'msg': 'Success', 'appointment': appointment})
Exemplo n.º 3
0
def visit_patient(request):
    """
    This is an ajax call to update appointment status from 'Checked In' to 'In Session'
    :param request: request from doctor containing appointment_id
    :return: success msg with some appointment details
    """

    appointment_id = request.POST.get('appointment_id', '')

    if not appointment_id:
        return JsonResponse(
            {'msg': 'No appointment_id in the the request body'})

    access_token = UserSocialAuth.objects.get(
        provider='drchrono').extra_data['access_token']
    appointment_api = AppointmentEndpoint(access_token)

    try:
        appointment_api.update(appointment_id, {'status': 'In Session'})
        appointment = appointment_api.fetch(appointment_id)
        if appointment:
            appointment = decorate_appointments([appointment], access_token)
    except APIException:
        return JsonResponse(
            {'msg': 'Could not update the appointment in the api'})

    return JsonResponse({'msg': 'Success', 'appointment': appointment})
Exemplo n.º 4
0
def begin_appointment(request, id):
    access_token = get_token()
    api = AppointmentEndpoint(access_token)
    appointment = api.fetch(id=id)
    updated_at = dt.datetime.strptime(appointment['updated_at'],
                                      "%Y-%m-%dT%H:%M:%S")
    wait_time = dt.datetime.now() - updated_at
    diff = round(wait_time.total_seconds() / 60)
    wt = WaitTime(appointment_id=id, wait_time=diff)
    wt.save()
    api.update(id=id, data={"status": "In Session"})
    return redirect('/welcome')
Exemplo n.º 5
0
 def get_appointments(self, date=None, start=None, end=None):
     """
     Get appointments in certain date or range
     But in this Hackathon, only TODAY's appointments are pulled. 
     Using ID as key
     """
     access_token = self.get_token()
     api = AppointmentEndpoint(access_token)
     for appointment in list(api.list(None, date, start, end)):
         self.appointments[appointment['id']] = api.fetch(
             appointment['id'], 'verbose=true')
     return self.appointments
Exemplo n.º 6
0
 def form_valid(self, form):
     # Hit the Appointments API and confirm check-in
     appointment = form.cleaned_data['appointment']
     endpoint = AppointmentEndpoint()
     endpoint.update(appointment.id, {'status': 'Arrived'})
     # Re-sync the appointment info to update the status, and pick up any other updates since last time
     api_data = endpoint.fetch(id=appointment.id)
     serializer = AppointmentSerializer(data=api_data)
     if serializer.is_valid():
         serializer.save()  # Save updates from API
         # Redirect for the next visitor to check in
         return redirect('checkin_success', patient=form.patient)
     else:
         # TODO: set up logging framework properly
         # logger.error("Error saving appointment {}".format(appointment.id))
         return redirect('checkin_receptionist')
Exemplo n.º 7
0
    def cancelappointment(self, request, pk=None):
        oauth_provider = UserSocialAuth.objects.get(provider='drchrono')
        access_token = oauth_provider.extra_data['access_token']
        endpoint = AppointmentEndpoint(access_token)

        endpoint.update(pk, {'status':'Cancelled'})
        api_data = endpoint.fetch(id=pk)

        try:
            model = Appointment.objects.get(pk=pk)
            serializer = AppointmentSerializer(model, data=api_data)

            if serializer.is_valid():
                serializer.save()

        except Appointment.DoesNotExist:
            pass

        return redirect('index')
Exemplo n.º 8
0
def fetch(request, appointment_id):
    """
    Fetch an Appointment by `id`
    """
    api = AppointmentEndpoint(ChronoOauth.get_token())
    try:
        appointment = api.fetch(id = appointment_id)
    except NotFound:
        return JsonResponse(
            {
                'error' : "00101012992 Appointment #{} was not found in the Dr. Chrono Database".format(appointment_id)
            })

    appt_db = Appointment.objects.filter(appt_id=appointment_id).first()
    if appointment and appt_db:
        appointment['date_checked_in'] = appt_db.date_checked_in

    return JsonResponse({
            'success' : True,
            'appointment' : appointment
        })
    def verify_patient_has_appointment(params):
        """
        Verify that a patient has a confirmed appointment with the doctor before
        asking for their Demographics information.
        
        parameters = {
            'patient_id',
            'first_name',
            'last_name',
            'appointment_id',
            'override_late'  # Will not exclude this appointment from 
            }
        """

        current_date = datetime.now().strftime("%Y-%m-%d")

        # Check if the patient actually exists.
        patient_api = PatientEndpoint(ChronoOauth.get_token())
        patient = None
        if 'patient_id' in params:
            patient = patient_api.fetch(id=params['patient_id'])
        elif 'first_name' in params and 'last_name' in params:
            patient = PatientService.find_patient_by_name(
                params['first_name'], params['last_name'])

        if not patient:
            return {'error': 'Patient not found in the Doctor\'s database.'}

        api_appt = AppointmentEndpoint(ChronoOauth.get_token())
        if 'appointment_id' in params and params['appointment_id']:
            """
            Check a patient into a specific appointment.
            """
            target_appointment = api_appt.fetch(id=params['appointment_id'])

        else:
            """
            Grab a list of the nearest available Appointment.
            """

            current_appointments = api_appt.list(date=current_date)
            current_appointments_list = list(current_appointments)

            # Determine whether a patient can be seen by the doctor.
            # The api automatically sorts the schedules by the time.
            #TODO: Do not yet factor Early Checkin or Late Arrivals. Just deal with a single status.
            target_appointment = None
            for appointment in current_appointments_list:

                # If a patient has multiple schedules throughout the day,
                # that patient cannot be 'checked_in' twice.
                if appointment['patient'] == patient['id'] and \
                    appointment['status'] in settings.DRCHRONO_VALID_SEEABLE_PATIENTS:
                    break

                if appointment['patient'] == patient['id'] and \
                    appointment['status'] in settings.DRCHRONO_VALID_APPOINTMENTS:

                    # No time to debug this extra functionality...
                    #if 'override_late' not in params or not params['override_late']:
                    #    # If this appointment time is later than the Doctors Practice's
                    #    # Late limit, then skip this appointment.
                    #    scheduled_time = datetime.strptime (appointment['scheduled_time'], "%Y-%m-%dT%H:%M:%S")
                    #    schedule_epoch = (scheduled_time - datetime(1970, 1, 1)).total_seconds()
                    #
                    #    late_time = time.time() - schedule_epoch
                    #    if late_time > settings.PATIENT_LATE_CUTOFF_TIME*60:
                    #        print('wut? {} {}'.format(late_time, settings.PATIENT_LATE_CUTOFF_TIME))
                    #        continue

                    target_appointment = appointment
                    break

                elif appointment['patient'] == patient['id']:
                    pass

        if not target_appointment:
            return {
                'error' : 'Were sorry, it appears you have either: not confirmed an appointment, '+\
                        'have already checked in, are Late (over {} Minutes), rescheduled, etc'.\
                            format(settings.PATIENT_LATE_CUTOFF_TIME)
            }

        return target_appointment