def __init__(self, *args, **kwargs):
     instance = kwargs.pop('instance')
     super(AppointmentInfoForm, self).__init__(*args, **kwargs)
     # TODO: schedule updates for all practices to run once a night
     drchrono = drchronoAPI(instance.user.practice)
     drchrono.update_doctors_for_user()
     drchrono.update_offices_for_user()
     drchrono.update_appointment_profiles()
     for office in instance.user.offices.all():
         drchrono.activate_online_scheduling(office=office)
     self.fields['profile'].choices = [(p.id, p) for p in instance.user.appointment_profiles.all()]
     self.fields['doctor'].choices = [(d.id, d) for d in instance.user.doctors.all()]
     self.fields['office'].choices= [(o.id, o) for o in instance.user.offices.all()]
 def forms_valid(self, forms):
     for key, form in forms.iteritems():
         form.save()
     patient = self.request.user.patient
     drchrono = drchronoAPI(patient.practice.practice)
     drchrono.patch_patient(patient.id, data={
         'first_name':patient.first_name,
         'last_name':patient.last_name,
         'cell_phone':patient.cell_phone,
         'email':patient.email,
         'gender':patient.gender,
     })
     return self.get_success_url()
 def dispatch(self, *args, **kwargs):
     practice_id = self.kwargs.get('practice_id', None)
     self.practice = get_object_or_404(Practice, user_id=practice_id)
     self.drchrono = drchronoAPI(self.practice)
     return super(SignupFormView, self).dispatch(*args, **kwargs)