Пример #1
0
 def email_and_confirm_booking(self, booking):
     # email patient
     if not booking.email_sent_to_patient:
         mail.email_booking_to_patient(self, booking)
     
     # email provider
     if not booking.email_sent_to_provider:
         mail.email_booking_to_provider(self, booking)
         
     booking.confirmed = True
     booking.put()
     
     patient_user = booking.patient.get().user.get()
     patient_user.confirmed = True
     patient_user.put()
Пример #2
0
    def email_and_confirm_booking(self, booking):
        # email patient
        if not booking.email_sent_to_patient:
            mail.email_booking_to_patient(self, booking)

        # email provider
        if not booking.email_sent_to_provider:
            mail.email_booking_to_provider(self, booking)

        booking.confirmed = True
        booking.put()

        patient_user = booking.patient.get().user.get()
        patient_user.confirmed = True
        patient_user.put()
Пример #3
0
    def post(self, vanity_url=None):
        '''
            Booking process from public profile
        '''
        appointment_details_form = None
        provider = db.get_provider_from_vanity_url(vanity_url)

        user = self.get_current_user()
        if user:
            appointment_details_form = AppointmentDetailsForLoggedInUser(
            ).get_form(self.request.POST, provider=provider)
        else:
            appointment_details_form = AppointmentDetails().get_form(
                self.request.POST, provider=provider)

        provider = db.get_provider_from_vanity_url(vanity_url)
        if appointment_details_form.validate():
            # create the booking object
            booking = Booking()
            booking.provider = provider.key
            booking.booking_source = 'profile'

            booking_date = appointment_details_form['booking_date'].data
            booking_time = appointment_details_form['booking_time'].data
            booking.datetime = to_utc(
                datetime.strptime(booking_date + " " + booking_time,
                                  '%Y-%m-%d %H:%M'))
            booking.comments = appointment_details_form['comments'].data

            schedule = db.get_schedule_for_date_time(provider, booking_date,
                                                     booking_time)
            booking.schedule = schedule.key

            if appointment_details_form.__contains__('service'):
                service_key_from_form = appointment_details_form[
                    'service'].data
                if service_key_from_form:
                    service_key = ndb.Key(urlsafe=service_key_from_form)
                    provider_service = service_key.get()
                    if provider_service:
                        booking.service = service_key

            if user:
                # user is logged in, is this a patient?
                existing_patient = db.get_patient_from_user(user)
                if existing_patient:
                    booking.patient = existing_patient.key
                else:
                    self.link_user_to_new_patient(appointment_details_form,
                                                  user, booking)

                # confirm the booking since it is a "known" user
                booking.confirmed = True
                booking.email_sent_to_patient = False
                booking.email_sent_to_provider = False

                # save booking
                booking.put()

                # already logged in so go directly to bookings list
                self.redirect('/patient/bookings/' + booking.patient.urlsafe())

                # mail it to the patient
                mail.email_booking_to_patient(self, booking)

                # mail it to the provider
                mail.email_booking_to_provider(self, booking)

            else:
                # no user is logged in, check if the email address exists, this means they just didn't log in
                email = appointment_details_form['email'].data

                existing_user = db.get_user_from_email(email)
                if existing_user:
                    existing_patient = db.get_patient_from_user(existing_user)
                    if existing_patient:
                        # email is in datastore, but not logged in
                        # link booking to existing patient
                        booking.patient = existing_patient.key
                        booking.put()
                    else:
                        self.link_user_to_new_patient(appointment_details_form,
                                                      user, booking)

                    # confirm the booking since it is a "known" user
                    booking.confirmed = True
                    booking.email_sent_to_patient = False
                    booking.email_sent_to_provider = False

                    # save booking
                    booking.put()

                    # get the user to login
                    key = booking.key.urlsafe()
                    self.redirect('/login/booking/' + key)
                else:
                    # no patient, no user. get them to fill a profile in the form
                    booking.put()

                    patient_form = RegistrationDetailsForNewPatient().get_form(
                    )
                    patient_form['terms_agreement'].data = True
                    patient_form['booking_date'].data = booking_date
                    patient_form['booking_time'].data = booking_time
                    patient_form['booking_key'].data = booking.key.urlsafe()
                    patient_form['email'].data = email

                    self.render_template(
                        'provider/public/booking_new_patient.html',
                        provider=provider,
                        patient_form=patient_form)

            logging.info('Created booking from public profile: %s' % booking)

        else:
            self.render_template('provider/public/booking_details.html',
                                 provider=provider,
                                 booking_form=appointment_details_form)
Пример #4
0
    def post(self, vanity_url=None):
        '''
            Booking process from public profile
        '''
        appointment_details_form = None
        provider = db.get_provider_from_vanity_url(vanity_url)
    
        user = self.get_current_user()
        if user:
            appointment_details_form = AppointmentDetailsForLoggedInUser().get_form(self.request.POST, provider=provider)
        else:
            appointment_details_form = AppointmentDetails().get_form(self.request.POST, provider=provider)
        
        provider = db.get_provider_from_vanity_url(vanity_url)
        if appointment_details_form.validate():
            # create the booking object
            booking = Booking()
            booking.provider = provider.key
            booking.booking_source = 'profile'
            
            booking_date = appointment_details_form['booking_date'].data
            booking_time = appointment_details_form['booking_time'].data
            booking.datetime = to_utc(datetime.strptime(booking_date + " " + booking_time, '%Y-%m-%d %H:%M'))
            booking.comments = appointment_details_form['comments'].data

            schedule = db.get_schedule_for_date_time(provider, booking_date, booking_time)
            booking.schedule = schedule.key            
            
            if appointment_details_form.__contains__('service'):
                service_key_from_form = appointment_details_form['service'].data
                if service_key_from_form:
                    service_key = ndb.Key(urlsafe=service_key_from_form)
                    provider_service = service_key.get()
                    if provider_service:
                        booking.service = service_key

            if user:
                # user is logged in, is this a patient?
                existing_patient = db.get_patient_from_user(user)
                if existing_patient:
                    booking.patient = existing_patient.key
                else:
                    self.link_user_to_new_patient(appointment_details_form, user, booking)
                    
                # confirm the booking since it is a "known" user
                booking.confirmed = True
                booking.email_sent_to_patient = False
                booking.email_sent_to_provider = False
                
                # save booking
                booking.put()
                
                # already logged in so go directly to bookings list
                self.redirect('/patient/bookings/' + booking.patient.urlsafe())
                
                # mail it to the patient
                mail.email_booking_to_patient(self, booking)
                
                # mail it to the provider
                mail.email_booking_to_provider(self, booking)
                    
            else:
                # no user is logged in, check if the email address exists, this means they just didn't log in
                email = appointment_details_form['email'].data

                existing_user = db.get_user_from_email(email)
                if existing_user:
                    existing_patient = db.get_patient_from_user(existing_user)
                    if existing_patient:                        
                        # email is in datastore, but not logged in
                        # link booking to existing patient 
                        booking.patient = existing_patient.key
                        booking.put()
                    else:
                        self.link_user_to_new_patient(appointment_details_form, user, booking)       
                    
                    # confirm the booking since it is a "known" user
                    booking.confirmed = True
                    booking.email_sent_to_patient = False
                    booking.email_sent_to_provider = False
                    
                    # save booking
                    booking.put()

                    # get the user to login
                    key = booking.key.urlsafe()
                    self.redirect('/login/booking/' + key)
                else:
                    # no patient, no user. get them to fill a profile in the form
                    booking.put()
                    
                    patient_form = RegistrationDetailsForNewPatient().get_form()
                    patient_form['terms_agreement'].data = True
                    patient_form['booking_date'].data = booking_date
                    patient_form['booking_time'].data = booking_time
                    patient_form['booking_key'].data = booking.key.urlsafe()
                    patient_form['email'].data = email

                    self.render_template('provider/public/booking_new_patient.html', provider=provider, patient_form=patient_form)
                        
            logging.info('Created booking from public profile: %s' % booking)
            
        else:
            self.render_template('provider/public/booking_details.html', provider=provider, booking_form=appointment_details_form)