コード例 #1
0
 def get(self, request):
     oauth_provider = get_object_or_404(UserSocialAuth, provider='drchrono')
     access_token = oauth_provider.extra_data['access_token']
     patient_client = PatientEndpoint(access_token)
     patient = patient_client.fetch(request.GET.get('patient_id'))
     return render(request, 'demographics.html',
                   {'form': DemographicForm(initial=patient), 'patient_id': request.GET.get('patient_id')})
コード例 #2
0
 def get_patient(self, patient_id):
     """
     Load a patient by id
     """
     access_token = self.get_token()
     api = PatientEndpoint(access_token)
     return api.fetch(patient_id)
コード例 #3
0
 def form_valid(self, form):
     patients_api = PatientEndpoint(self.request.session["access_token"])
     try:
         patients_api.update(self.request.session["patient_id"],
                             form.cleaned_data)
     except APIException:
         return render(
             self.request,
             "patient_checkin.html",
             {
                 "error": "There was an error updating your information",
                 "form": form
             },
         )
     appointments_api = AppointmentEndpoint(
         self.request.session["access_token"])
     for appointment_id in self.request.session["appointment_ids"]:
         try:
             appointments_api.update(appointment_id, {"status": "Arrived"})
         except APIException:
             return render(
                 self.request,
                 "patient_checkin.html",
                 {
                     "error":
                     "There was an error checking in to your appointment",
                     "form": form,
                 },
             )
         appointment = Appointment.objects.get(api_id=appointment_id)
         appointment.status = "Arrived"
         appointment.check_in_time = timezone.now()
         appointment.save()
     return super(PatientDemographicsView, self).form_valid(form)
コード例 #4
0
ファイル: views.py プロジェクト: hjt486/api-example-django
 def fetch_a_patient(self, id='None'):
     """
     Fetch a patient using ID, return the result
     """
     access_token = self.get_token()
     api = PatientEndpoint(access_token)
     return api.fetch(id)
コード例 #5
0
ファイル: views.py プロジェクト: vpinnaka/api-example-django
    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 = self.get_token()
        self.request.session['access_token'] = access_token

        doctor_api = DoctorEndpoint(access_token)
        patient_api = PatientEndpoint(access_token)
        apppointment_api = AppointmentEndpoint(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.
        doctor = doctor_api.get_and_store_data()
        self.request.session['doctor'] = doctor.id
        # Get patients and appointments for the doctor and store it in the local DB
        patient_api.get_and_store_data(doctor=doctor)

        date = datetime.now(
            tz=pytz.timezone(doctor.timezone)).strftime('%Y-%m-%d')
        apppointment_api.get_and_store_data(doctor=doctor, date=date)

        return doctor
コード例 #6
0
ファイル: utils.py プロジェクト: shiv4m/dr_chrono_hackathon
 def get_patient_details_with_first_last_dob(self, fname, lname, dob):
     api = PatientEndpoint(self.get_token())
     for patients in api.list():
         if patients['first_name'] == fname and patients[
                 'last_name'] == lname and str(
                     patients['date_of_birth']) == str(dob):
             return patients['id']
コード例 #7
0
    def clean(self):
        try:
            oauth_provider = UserSocialAuth.objects.get(provider='drchrono')
            access_token = oauth_provider.extra_data['access_token']
        except UserSocialAuth.DoesNotExist:
            raise forms.ValidationError(
                "We had a problem authenticating with the drchrono API.")

        full_name = f"{self.cleaned_data.get('first_name')} {self.cleaned_data.get('last_name')}"

        appointments_client = AppointmentEndpoint(access_token)
        patient_client = PatientEndpoint(access_token)
        self.cleaned_data['appointment_id'] = None
        self.cleaned_data['patient_id'] = None

        # get a list of patients, make a list of their full names to search through
        patients = list(patient_client.list())
        patients_full_names = [
            f"{patient.get('first_name')} {patient.get('last_name')}"
            for patient in list(patient_client.list())
        ]
        patient_found = full_name in patients_full_names
        if not patient_found:
            raise forms.ValidationError(
                "Couldn't find a patient matching your name.")

        patient = patients[patients_full_names.index(full_name)]
        self.cleaned_data['patient_id'] = patient.get('id')

        # okay, we found them. do they have an appt. ?
        today = timezone.now()
        today_str = today.strftime('%m-%d-%y')
        appointments = list(
            appointments_client.list(
                {'patient': self.cleaned_data.get('patient_id')},
                start=today_str,
                end=today_str))
        patient_has_appointment_today = len(appointments) > 0
        if not patient_has_appointment_today:
            raise forms.ValidationError(
                "Couldn't find an appointment for you today.")

        # if they have any appointments set their status to Arrived
        for appointment in appointments:
            self.cleaned_data['appointment_id'] = appointment.get('id')
            import random
            if random.randrange(20) % 4:
                appointments_client.update(self.cleaned_data['appointment_id'],
                                           {'status': 'Arrived'})

            # create a Visit object
            visit, created = Visit.objects.get_or_create(
                appointment_id=self.cleaned_data['appointment_id'],
                patient_id=self.cleaned_data['patient_id'])

            # if there was already a Visit object and it is set to Arrived, they already checked in!
            if not created and visit.status == 'Arrived':
                raise forms.ValidationError(
                    "You already checked in for your appointment today.")
コード例 #8
0
    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})
コード例 #9
0
ファイル: utils.py プロジェクト: xjshi1994/Hackathon
    def get_patient(self, first_name=None, last_name=None, date_of_birth=None):

        api = PatientEndpoint(self.access_token)

        params = {'first_name': first_name, 'last_name': last_name, 'date_of_birth': date_of_birth}

        # grab one
        return next(api.list(params))
コード例 #10
0
ファイル: utils.py プロジェクト: xjshi1994/Hackathon
    def get_patient_id(self, patient_id):
        """
        :param patient_id:
        :return:
        """

        api = PatientEndpoint(self.access_token)
        return api.fetch(patient_id)
コード例 #11
0
ファイル: views.py プロジェクト: hjt486/api-example-django
 def change_patient(self, id="None", data={}):
     '''
     Submit request to change an patient with ID
     All request data is in dict 'data',
     '''
     access_token = self.get_token()
     api = PatientEndpoint(access_token)
     return api.update(id, data)
コード例 #12
0
ファイル: views.py プロジェクト: ranitdey/api-example-django
    def post(self, request, appointment_id, patient_id):
        form = self.patient_demographics(request.POST)

        if form.is_valid():
            try:
                PatientEndpoint(access_token=get_token()).update(patient_id, form.cleaned_data)
                updated_patient_dmg = PatientEndpoint(access_token=get_token()).fetch(patient_id)
                patient_object, created = Patient.objects.update_or_create(
                    patient_id=updated_patient_dmg['id'],
                    defaults={
                        'gender': updated_patient_dmg['gender'],
                        'doctor_id': updated_patient_dmg['doctor'],
                        'first_name': updated_patient_dmg['first_name'],
                        'last_name': updated_patient_dmg['last_name'],
                        'email': updated_patient_dmg['email'],
                        'patient_photo': updated_patient_dmg['patient_photo']
                    }
                )

                appointment_details = AppointmentEndpoint(access_token=get_token()).fetch(appointment_id)

                updated_appointment = {
                    'doctor': appointment_details['doctor'],
                    'duration': appointment_details['duration'],
                    'exam_room': appointment_details['exam_room'],
                    'office': appointment_details['office'],
                    'patient': appointment_details['patient'],
                    'scheduled_time': appointment_details['scheduled_time'],
                    'status': 'Arrived'
                }
                AppointmentEndpoint(access_token=get_token()).update(appointment_id,updated_appointment)

                user_timezone = request.COOKIES.get('tzname_from_user')
                time_now = datetime.now(pytz.timezone('UTC'))
                arrival_time = time_now.astimezone(pytz.timezone(user_timezone))

                appointment_object, created = Appointment.objects.update_or_create(
                    appointment_id=appointment_details['id'],
                    defaults={
                        'status': 'Arrived',
                        'patient': Patient.objects.get(patient_id=appointment_details['patient']),
                        'check_in_time': arrival_time,
                        'scheduled_time': appointment_details['scheduled_time']
                    }
                )

                return render(request, 'finish_check_in.html', {"patient": updated_patient_dmg})
            except APIException:
                form.add_error(None, 'Error in updating form. Please try again.')

        return render(
            request,
            self.template_name,
            {
                'form': form,
                'appointment_id': appointment_id,
                'patient_id': patient_id,
            })
コード例 #13
0
ファイル: views.py プロジェクト: vpinnaka/api-example-django
    def form_valid(self, form):
        # This method is called when valid form data has been POSTed.
        # It should return an HttpResponse.
        date_of_birth = form.cleaned_data.get('date_of_birth')
        gender = form.cleaned_data.get('gender')
        address = form.cleaned_data.get('address')
        zip_code = form.cleaned_data.get('zip_code')
        city = form.cleaned_data.get('city')
        state = form.cleaned_data.get('state')
        email = form.cleaned_data.get('email')
        cell_phone = form.cleaned_data.get('cell_phone')
        emergency_contact_name = form.cleaned_data.get(
            'emergency_contact_name')
        emergency_contact_phone = form.cleaned_data.get(
            'emergency_contact_phone')

        patient_id = self.request.session.get('checkedin_patient')

        patient = get_object_or_none(Patient, pk=patient_id)

        if patient:
            access_token = self.request.session.get('access_token')
            patient_api = PatientEndpoint(access_token)

            updated_fields = {
                'email': email,
                'gender': gender,
                'date_of_birth': date_of_birth,
                'address': address,
                'city': city,
                'state': state,
                'zip_code': zip_code,
                'cell_phone': cell_phone,
            }

            response = {}
            try:
                response = patient_api.update(patient_id, updated_fields)

                updated_patient, created = update_or_create_object(
                    Patient, updated_fields, pk=patient_id)
                return super(DemographicsView, self).form_valid(form)
            except APIException:
                context = {
                    'form':
                    form,
                    'message':
                    'Trouble updating your data, Please consult a staff member',
                }
                return render(self.request, "checkin.html", context)

        context = {
            'form':
            form,
            'message':
            'Patient demographics not updated, please check with attendent',
        }
        return render(self.request, "checkin.html", context)
コード例 #14
0
ファイル: views.py プロジェクト: joyoon/api-example-django
    def getPatients(self):
        access_token = self.get_token()
        api = PatientEndpoint(access_token)
        params = {}
        params['doctor'] = 252849
        # params['first_name'] = firstName
        # params['last_name'] = lastName

        return api.list(params=params)
コード例 #15
0
def post_patientInfo(token, data, id):
    """
    This is a helper function that once patient update their info, it can post update data to Patient API.
    """
    patient_api = PatientEndpoint(token)
    try:
        response = patient_api.update(id, data)
    except:
        return HttpResponse('Please make sure your info is input correctly')
コード例 #16
0
 def form_valid(self, form):
     patient_id = self.kwargs['p_id']
     appointment_id = self.kwargs['a_id']
     access_token = get_token()
     api = PatientEndpoint(access_token)
     ap_api = AppointmentEndpoint(access_token)
     data = form.cleaned_data
     api.update(id=patient_id, data=data)
     ap_api.update(id=appointment_id, data={"status": "Arrived"})
     return super(PatientInformationView, self).form_valid(form)
コード例 #17
0
ファイル: views.py プロジェクト: hjt486/api-example-django
 def get_patients(self):
     """
     Get all patients (without pagenating)
     Using ID as key
     """
     access_token = self.get_token()
     api = PatientEndpoint(access_token)
     for patient in list(api.list()):
         self.patients[patient['id']] = patient
     return self.patients
コード例 #18
0
 def fetch_one_patient(self, id):
     """
     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 = self.get_token()
     api = PatientEndpoint(access_token)
     # Fetch one patient.
     return api.fetch(id=id)
コード例 #19
0
 def get(self, request, *args, **kwargs):
     '''
     Return patient details
     '''
     patient = request.GET.get('patient')
     doctor_welcome = DoctorWelcome()
     access_token = doctor_welcome.get_token()
     api = PatientEndpoint(access_token)
     patient_data = api.fetch(patient)
     return JsonResponse(patient_data)
コード例 #20
0
 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 = self.get_token()
     api = PatientEndpoint(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())
コード例 #21
0
 def get_initial(self):
     """
     Returns the initial data to use for forms on this view.
     """
     initial = super(PatientInformationView, self).get_initial()
     patient_id = self.kwargs['p_id']
     access_token = get_token()
     api = PatientEndpoint(access_token)
     patient_info = api.fetch(id=patient_id)
     initial = merge_two_dicts(patient_info, initial)
     return initial
コード例 #22
0
def debug(request):
    oauth_provider = UserSocialAuth.objects.get(provider='drchrono')
    access_token = oauth_provider.extra_data['access_token']

    endpoint = PatientEndpoint(access_token)
    print next(endpoint.list())
    # queryset = Appointment.objects.all()

    # serializer_class = retrieveAppointmentSerializer(queryset, many=True)
    # content = serializer_class.data
    # print content
    return render(request, 'debug.html', {'data': next(endpoint.list())})
コード例 #23
0
    def post(self, request):
        # create a form instance and populate it with data from the request:
        form = DemographicForm(request.POST)
        patient_id = request.POST.get('patient_id')

        if form.is_valid():
            oauth_provider = get_object_or_404(UserSocialAuth,
                                               provider='drchrono')
            access_token = oauth_provider.extra_data['access_token']
            patient_client = PatientEndpoint(access_token)
            patient_client.update(patient_id, form.cleaned_data)
            return HttpResponseRedirect('/finished/')
        return render(request, 'demographics.html', {'form': form})
コード例 #24
0
    def form_valid(self, form):
        oauth_provider = UserSocialAuth.objects.get(provider='drchrono')
        access_token = oauth_provider.extra_data['access_token']
        endpoint = PatientEndpoint(access_token)

        params = {}
        for field in form.cleaned_data:
            if form.cleaned_data[field] != "" and form.cleaned_data[field] != None:
                params[field] = form.cleaned_data[field]

        endpoint.update(self.kwargs['patient'], params)

        return redirect('index')
コード例 #25
0
ファイル: api_helper.py プロジェクト: weiyang7965298/kiosk
def make_patient_api_request(access_token):
    patient_api = PatientEndpoint(access_token)
    for patient in patient_api.list():
        Patient.objects.update_or_create(
            pk=patient["id"],
            defaults={
                "doctor": Doctor.objects.get(id=patient["doctor"]),
                "first_name": patient["first_name"],
                "last_name": patient["last_name"],
                "date_of_birth": patient["date_of_birth"],
                "social_security_number": patient["social_security_number"],
                "gender": patient["gender"]
            })
コード例 #26
0
    def patient_db_save(self, token):
        """
        Save patients info to patient table
        """

        patient_api = PatientEndpoint(token)

        for p in patient_api.list():
            patient = models.Patient(patient_id=p[u'id'], first_name=p[u'first_name'], last_name=p[u'last_name'], \
                                     date_of_birth=p[u'date_of_birth'], gender=p[u'gender'], address=p[u'address'], \
                                     ssn=p[u'social_security_number'], cell_phone=p[u'cell_phone'], email=p[u'email'], \
                                     city=p[u'city'], state=p[u'state'])
            patient.save()
        return
コード例 #27
0
ファイル: views.py プロジェクト: joyoon/api-example-django
    def createPatient(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 = self.get_token()
        api = PatientEndpoint(access_token)
        params = {}
        params['doctor'] = 252849
        params['gender'] = 'Male'
        params['first_name'] = 'Joe'
        params['last_name'] = 'Blow'

        return api.create(data=params)
コード例 #28
0
 def save(self, commit=True):
     appointment = self.cleaned_data.pop('appointment')
     appointment.checked_in_at = now()
     appointment.save()
     instance = super(PatientCheckinForm, self).save(commit=commit)
     api = PatientEndpoint(instance.doctor.token)
     data = {
         'first_name': instance.first_name,
         'last_name': instance.last_name,
         'social_security_number': instance.social_security_number,
         'race': instance.race,
         'ethnicity': instance.ethnicity,
         'date_of_birth': instance.date_of_birth,
     }
     api.update(instance.drchrono_id, data=data)
コード例 #29
0
 def get_context_data(self, **kwargs):
     """
     :return: dictionary to populate template data
     """
     print('PatientUpdateProfile get_context_data')
     print('self = ', self)
     print('self.kwargs[patient_id]=', self.kwargs['patient_id'])
     kwargs = super(PatientUpdateProfile, self).get_context_data(**kwargs)
     # get patient using patient_id
     access_token = utility.get_token()
     patient_api = PatientEndpoint(access_token)
     patient = patient_api.fetch(id=str(self.kwargs['patient_id']))
     patient = utility.convert_unicode_to_string(patient)
     print('cellphone = ', patient['cell_phone'])
     kwargs['patient'] = patient
     return kwargs
コード例 #30
0
def manage_patient(request):
    if request.method == 'POST':
        oauth_provider = UserSocialAuth.objects.get(provider='drchrono')
        access_token = oauth_provider.extra_data['access_token']
        api = PatientEndpoint(access_token)
        for p in api.list():
            patient = models.Patient(patient_id=p[u'id'], first_name=p[u'first_name'], last_name=p[u'last_name'], \
                                     date_of_birth=p[u'date_of_birth'], gender=p[u'gender'], address=p[u'address'], \
                                     ssn=p[u'social_security_number'], cell_phone=p[u'cell_phone'], email=p[u'email'], \
                                     city=p[u'city'], state=p[u'state'], \
                                     doctor_id=p[u'doctor'], last_app=p[u'date_of_first_appointment'], is_checkin=False)
            patient.save()
    else:
        pass
    patient_db = models.Patient.objects.all()
    return render(request, 'patient_checkin.html', {})