def put(self, id): json_data = request.get_json() if 'counter_id' not in json_data: json_data['counter_id'] = counter_id if not json_data: return {'message': 'No input data received for updating citizen'}, 400 csr = CSR.find_by_username(g.oidc_token_info['username']) citizen = Citizen.query.filter_by(citizen_id=id).first() my_print("==> PUT /citizens/" + str(citizen.citizen_id) + '/, Ticket: ' + str(citizen.ticket_number)) try: citizen = self.citizen_schema.load(json_data, instance=citizen, partial=True).data except ValidationError as err: return {'message': err.messages}, 422 db.session.add(citizen) db.session.commit() # If this put request is the result of an appointment checkin, make a Snowplow call. if ('snowplow_addcitizen' in json_data) and (json_data['snowplow_addcitizen'] == True): SnowPlow.add_citizen(citizen, csr) result = self.citizen_schema.dump(citizen) socketio.emit('update_active_citizen', result.data, room=csr.office_id) return {'citizen': result.data, 'errors': result.errors}, 200
def put(self, id): csr = CSR.find_by_username(g.oidc_token_info['username']) json_data = request.get_json() if not json_data: return { "message": "No input data received for updating an series of appointments" } appointments = Appointment.query.filter_by(recurring_uuid=id)\ .filter_by(office_id=csr.office_id)\ .all() for appointment in appointments: appointment, warning = self.appointment_schema.load( json_data, instance=appointment, partial=True) if warning: logging.warning('WARNING: %s', warning) return {"message": warning}, 422 db.session.add(appointment) db.session.commit() result = self.appointment_schema.dump(appointments) if not application.config['DISABLE_AUTO_REFRESH']: socketio.emit('appointment_update', result.data) return {"appointments": result.data, "errors": result.errors}, 200
def put(self, id): json_data = request.get_json() if not json_data: return {'message': 'No input data received for updating CSR'}, 400 auth_csr = CSR.find_by_username(g.oidc_token_info['username']) edit_csr = CSR.query.filter_by(csr_id=id).first_or_404() if auth_csr.csr_id != edit_csr.csr_id: return {'message': 'You do not have permission to edit this CSR'}, 403 try: edit_csr = self.csr_schema.load(json_data, instance=edit_csr, partial=True).data except ValidationError as err: return {'message': err.messages}, 422 db.session.add(edit_csr) db.session.commit() result = self.csr_schema.dump(edit_csr) socketio.emit('csr_update', \ { "csr_id": edit_csr.csr_id, \ "receptionist_ind" : edit_csr.receptionist_ind }, \ room=auth_csr.office_id) # Purge cache of old CSR record so the new one can be fetched by the next request for it. CSR.delete_user_cache(g.oidc_token_info['username']) return {'service_request': result.data, 'errors': result.errors}, 200
def post(self): my_print("==> In AppointmentDraftPost, POST /appointments/draft") json_data = request.get_json() office_id = json_data.get('office_id') service_id = json_data.get('service_id') start_time = parse(json_data.get('start_time')) end_time = parse(json_data.get('end_time')) office = Office.find_by_id(office_id) service = Service.query.get(int(service_id)) if service_id else None # end_time can be null for CSRs when they click; whereas citizens know end-time. if not end_time: end_time = add_delta_to_time(start_time, minutes=office.appointment_duration, timezone=office.timezone.timezone_name) # Unauthenticated requests from citizens won't have name, so we set a fallback if (hasattr(g, 'oidc_token_info') and hasattr(g.oidc_token_info, 'username')): user = PublicUser.find_by_username(g.oidc_token_info['username']) citizen_name = user.display_name else: citizen_name = 'Draft' # Delete all expired drafts before checking availability Appointment.delete_expired_drafts() csr = None if (hasattr(g, 'oidc_token_info')): csr = CSR.find_by_username(g.oidc_token_info['username']) # CSRs are not limited by drafts, can always see other CSRs drafts # This mitigates two CSRs in office creating at same time for same meeting # Ensure there's no race condition when submitting a draft if not csr and not AvailabilityService.has_available_slots( office=office, start_time=start_time, end_time=end_time, service=service): return {"code": "CONFLICT_APPOINTMENT", "message": "Cannot create appointment due to scheduling conflict. Please pick another time."}, 400 # Set draft specific data json_data['is_draft'] = True json_data['citizen_name'] = citizen_name appointment, warning = self.appointment_schema.load(json_data) if warning: logging.warning("WARNING: %s", warning) return {"message": warning}, 422 db.session.add(appointment) db.session.commit() result = self.appointment_schema.dump(appointment) socketio.emit('appointment_create', result.data) return {"appointment": result.data, "warning" : warning}, 201
def post(self, id): csr = CSR.find_by_username(g.oidc_token_info['username']) citizen = Citizen.query.filter_by(citizen_id=id, office_id=csr.office_id).first() sr_state = SRState.get_state_by_name("Complete") for service_request in citizen.service_reqs: service_request.sr_state_id = sr_state.sr_state_id for p in service_request.periods: if p.time_end is None: p.time_end = datetime.now() citizen.cs = CitizenState.query.filter_by( cs_state_name='Left before receiving services').first() if self.clear_comments_flag: citizen.citizen_comments = None if citizen.start_time.date() != datetime.now().date(): citizen.accurate_time_ind = 0 db.session.add(citizen) db.session.commit() SnowPlow.snowplow_event(citizen.citizen_id, csr, "customerleft") socketio.emit('citizen_invited', {}, room='sb-%s' % csr.office.office_number) result = self.citizen_schema.dump(citizen) socketio.emit('update_active_citizen', result.data, room=csr.office_id) return {'citizen': result.data, 'errors': result.errors}, 200
def put(self, id): json_data = request.get_json() if not json_data: return {'message': 'No input data received for updating CSR'}, 400 auth_csr = CSR.find_by_username(g.jwt_oidc_token_info['username']) edit_csr = CSR.query.filter_by(csr_id=id).first_or_404() if auth_csr.csr_id != edit_csr.csr_id: return { 'message': 'You do not have permission to edit this CSR' }, 403 # Get Invited and Being Served states, to see if CSR has any open tickets. period_state_invited = PeriodState.get_state_by_name("Invited") period_state_being_served = PeriodState.get_state_by_name( "Being Served") # See if CSR has any open tickets. citizen = Citizen.query \ .join(Citizen.service_reqs) \ .join(ServiceReq.periods) \ .filter(Period.time_end.is_(None)) \ .filter(Period.csr_id==id) \ .filter(or_(Period.ps_id==period_state_invited.ps_id, Period.ps_id==period_state_being_served.ps_id)) \ .all() if len(citizen) != 0: return { 'message': 'CSR has an open ticket and cannot be edited.' }, 403 try: edit_csr = self.csr_schema.load(json_data, instance=edit_csr, partial=True) except ValidationError as err: return {'message': err.messages}, 422 db.session.add(edit_csr) db.session.commit() # Purge CSR cache, otherwise lazy loaded relationships # like Office will be out of date. CSR.update_user_cache(id) result = self.csr_schema.dump(edit_csr) socketio.emit('csr_update', \ { "csr_id": edit_csr.csr_id, \ "receptionist_ind" : edit_csr.receptionist_ind }, \ room=auth_csr.office.office_name) # Purge cache of old CSR record so the new one can be fetched by the next request for it. CSR.delete_user_cache(g.jwt_oidc_token_info['username']) return { 'csr': result, 'errors': self.csr_schema.validate(edit_csr) }, 200
def delete(self, id): Appointment.delete_draft([id]) if not application.config['DISABLE_AUTO_REFRESH']: socketio.emit('appointment_delete', id) return {}, 204
def post(self, id): csr = CSR.find_by_username(g.oidc_token_info['username']) citizen = Citizen.query.filter_by(citizen_id=id, office_id=csr.office_id).first() active_service_request = citizen.get_active_service_request() if active_service_request is None: return {"message": "Citizen has no active service requests"} quantity = active_service_request.quantity active_service_request.finish_service(csr) citizen_state = CitizenState.query.filter_by( cs_state_name="Received Services").first() citizen.cs_id = citizen_state.cs_id pending_service_state = SRState.get_state_by_name("Complete") active_service_request.sr_state_id = pending_service_state.sr_state_id db.session.add(citizen) db.session.commit() SnowPlow.snowplow_event(citizen.citizen_id, csr, "finish", quantity=quantity) socketio.emit('citizen_invited', {}, room='sb-%s' % csr.office.office_number) result = self.citizen_schema.dump(citizen) socketio.emit('update_active_citizen', result.data, room=csr.office_id) return {'citizen': result.data, 'errors': result.errors}, 200
def put(self, id): json_data = request.get_json() if not json_data: return {'message': 'No input data received for updating citizen'}, 400 csr = CSR.find_by_username(g.oidc_token_info['username']) service_request = ServiceReq.query.filter_by(sr_id=id) \ .join(ServiceReq.citizen, aliased=True) \ .filter_by(office_id=csr.office_id).first_or_404() try: service_request = self.service_request_schema.load(json_data, instance=service_request, partial=True).data except ValidationError as err: return {'message': err.messages}, 422 db.session.add(service_request) db.session.commit() SnowPlow.choose_service(service_request, csr, "chooseservice") result = self.service_request_schema.dump(service_request) citizen_result = self.citizen_schema.dump(service_request.citizen) socketio.emit('update_active_citizen', citizen_result.data, room=csr.office_id) return {'service_request': result.data, 'errors': result.errors}, 200
def put(self, id): json_data = request.get_json() if not json_data: return { 'message': 'No input data received for updating citizen' }, 400 csr = CSR.find_by_username(g.oidc_token_info['username']) citizen = Citizen.query.filter_by(citizen_id=id, office_id=csr.office_id).first() try: citizen = self.citizen_schema.load(json_data, instance=citizen, partial=True).data except ValidationError as err: return {'message': err.messages}, 422 db.session.add(citizen) db.session.commit() result = self.citizen_schema.dump(citizen) socketio.emit('update_active_citizen', result.data, room=csr.office_id) return {'citizen': result.data, 'errors': result.errors}, 200
def post(self, id): csr = CSR.find_by_username(g.jwt_oidc_token_info['username']) citizen = Citizen.query\ .options(joinedload(Citizen.service_reqs).joinedload(ServiceReq.periods).options(raiseload(Period.sr),joinedload(Period.csr).raiseload('*')),joinedload(Citizen.office),raiseload(Citizen.user)) \ .filter_by(citizen_id=id, office_id=csr.office_id) citizen = citizen.first() my_print("==> POST /citizens/" + str(citizen.citizen_id) + '/place_on_hold/, Ticket: ' + citizen.ticket_number) active_service_request = citizen.get_active_service_request() if active_service_request is None: return {"message": "Citizen has no active service requests"} active_service_request.place_on_hold(csr) pending_service_state = SRState.get_state_by_name("Active") active_service_request.sr_state_id = pending_service_state.sr_state_id db.session.add(citizen) db.session.commit() socketio.emit('update_customer_list', {}, room=csr.office.office_name) result = self.citizen_schema.dump(citizen) socketio.emit('update_active_citizen', result, room=csr.office.office_name) return {'citizen': result, 'errors': self.citizen_schema.validate(citizen)}, 200
def put(self, id): json_data = request.get_json() counter = Counter.query.filter(Counter.counter_name == "Counter")[0] if 'counter_id' not in json_data: json_data['counter_id'] = counter.counter_id if not json_data: return { 'message': 'No input data received for updating citizen' }, 400 csr = CSR.find_by_username(g.oidc_token_info['username']) citizen = Citizen.query.filter_by(citizen_id=id, office_id=csr.office_id).first() my_print("==> PUT /citizens/" + str(citizen.citizen_id) + '/, Ticket: ' + str(citizen.ticket_number)) try: citizen = self.citizen_schema.load(json_data, instance=citizen, partial=True).data except ValidationError as err: return {'message': err.messages}, 422 db.session.add(citizen) db.session.commit() result = self.citizen_schema.dump(citizen) socketio.emit('update_active_citizen', result.data, room=csr.office_id) return {'citizen': result.data, 'errors': result.errors}, 200
def delete(self, id): appointment = Appointment.query.filter_by(appointment_id=id)\ .first_or_404() Appointment.delete_draft([id]) socketio.emit('appointment_delete', id) return {}, 204
def post(self, id): csr = CSR.find_by_username(g.jwt_oidc_token_info['username']) citizen = Citizen.query.filter_by(citizen_id=id).first() my_print("==> POST /citizens/" + str(citizen.citizen_id) + '/finish_service/, Ticket: ' + citizen.ticket_number) active_service_request = citizen.get_active_service_request() inaccurate = request.args.get('inaccurate') if active_service_request is None: return {"message": "Citizen has no active service requests"} # If citizen here overnight, or inaccurate time flag set, update accurate time flag. if citizen.start_time.date() != datetime.now().date( ) or inaccurate == 'true': citizen.accurate_time_ind = 0 SnowPlow.snowplow_event( citizen.citizen_id, csr, "finish", quantity=active_service_request.quantity, current_sr_number=active_service_request.sr_number) active_sr_id = active_service_request.sr_id active_service_request.finish_service(csr, self.clear_comments_flag) citizen_state = CitizenState.query.filter_by( cs_state_name="Received Services").first() citizen.cs_id = citizen_state.cs_id pending_service_state = SRState.get_state_by_name("Complete") active_service_request.sr_state_id = pending_service_state.sr_state_id # remove walkin unique id when service is finished citizen.walkin_unique_id = None db.session.add(citizen) db.session.commit() # Loop to stop all services in the service stopped state (which are all except the active service) if len(citizen.service_reqs) != 1: for sr in citizen.service_reqs: if sr.sr_id != active_sr_id: SnowPlow.snowplow_event(citizen.citizen_id, csr, "finishstopped", quantity=sr.quantity, current_sr_number=sr.sr_number) socketio.emit('citizen_invited', {}, room='sb-%s' % csr.office.office_number) result = self.citizen_schema.dump(citizen) socketio.emit('update_active_citizen', result, room=csr.office_id) return { 'citizen': result, 'errors': self.citizen_schema.validate(citizen) }, 200
def post(self, id): csr = CSR.find_by_username(g.jwt_oidc_token_info['username']) lock = FileLock("lock/begin_citizen_{}.lock".format(csr.office_id)) with lock: citizen = Citizen.query\ .options(joinedload(Citizen.service_reqs).options(joinedload(ServiceReq.periods).options(joinedload(Period.ps).options(raiseload('*')),joinedload(Period.csr).options(raiseload('*')),raiseload('*')), joinedload(ServiceReq.service).options(joinedload(Service.parent).options(raiseload(Service.parent).options(raiseload('*'))),raiseload('*'))), joinedload(Citizen.office).options(joinedload(Office.sb),raiseload('*')), raiseload(Citizen.user)) \ .filter_by(citizen_id=id) citizen = citizen.first() pending_service_state = SRState.get_state_by_name("Active") if citizen is None: print( "==> POST /citizen/<id>/begin_service/ error. No citizen with id " + str(id)) return {"message": "No citizen found with id " + str(id)} else: my_print("==> POST /citizens/" + str(citizen.citizen_id) + '/begin_service/, Ticket: ' + citizen.ticket_number) active_service_request = citizen.get_active_service_request() if active_service_request is None: return {"message": "Citizen has no active service requests"} try: # Get Snowplow call. active_period = active_service_request.get_active_period() snowplow_event = "beginservice" if active_period.ps.ps_name == "On hold": snowplow_event = "invitefromhold" if active_period.ps.ps_name == "Ticket Creation": snowplow_event = "servecitizen" active_service_request.begin_service(csr, snowplow_event) except TypeError: return {"message": "Citizen has already been invited"}, 400 active_service_request.sr_state_id = pending_service_state.sr_state_id db.session.add(citizen) db.session.commit() if snowplow_event != "beginservice": socketio.emit('update_customer_list', {}, room=csr.office.office_name) result = self.citizen_schema.dump(citizen) socketio.emit('update_active_citizen', result, room=csr.office.office_name) return { 'citizen': result, 'errors': self.citizen_schema.validate(citizen) }, 200
def post(self, id): csr = CSR.find_by_username(g.jwt_oidc_token_info['username']) service_request = ServiceReq.query.filter_by(sr_id=id) \ .join(ServiceReq.citizen, aliased=True) \ .filter_by(office_id=csr.office_id).first_or_404() active_service_state = SRState.get_state_by_name("Active") complete_service_state = SRState.get_state_by_name("Complete") # Find the currently active service_request and close it current_sr_number = 0 for req in service_request.citizen.service_reqs: if req.sr_state_id == active_service_state.sr_state_id: req.sr_state_id = complete_service_state.sr_state_id req.finish_service(csr, clear_comments=False) current_sr_number = req.sr_number db.session.add(req) # Then set the requested service to active service_request.sr_state_id = active_service_state.sr_state_id period_state_being_served = PeriodState.get_state_by_name( "Being Served") new_period = Period(sr_id=service_request.sr_id, csr_id=csr.csr_id, reception_csr_ind=csr.receptionist_ind, ps_id=period_state_being_served.ps_id, time_start=datetime.utcnow()) db.session.add(new_period) db.session.add(service_request) db.session.commit() # To make service active, stop current service, restart previous service. SnowPlow.snowplow_event(service_request.citizen.citizen_id, csr, "stopservice", current_sr_number=current_sr_number) SnowPlow.snowplow_event(service_request.citizen.citizen_id, csr, "restartservice", current_sr_number=service_request.sr_number) citizen_result = self.citizen_schema.dump(service_request.citizen) socketio.emit('update_active_citizen', citizen_result, room=csr.office_id) result = self.service_request_schema.dump(service_request) return { 'service_request': result, 'errors': self.service_request_schema.validate(service_request) }, 200
def delete(self, id): appointment = Appointment.query.filter_by(appointment_id=id)\ .first_or_404() Appointment.delete_draft([id]) if not application.config['DISABLE_AUTO_REFRESH']: socketio.emit('appointment_delete', id) return {}, 204
def post(self, id): csr = CSR.find_by_username(g.oidc_token_info['username']) citizen = Citizen.query.filter_by(citizen_id=id, office_id=csr.office_id).first() sr_state = SRState.get_state_by_name("Complete") # Create parameters for and make snowplow call. Default is no service request, CSR pressed cancel. quantity = 0 sr_number = 1 active_sr = 0 status = "service-creation" if len(citizen.service_reqs) != 0: active_service_request = citizen.get_active_service_request() quantity = active_service_request.quantity sr_number = active_service_request.sr_number active_sr = active_service_request.sr_id active_period = active_service_request.get_active_period() if active_period.ps.ps_name == "Invited": status = "at-prep" else: status = "being-served" SnowPlow.snowplow_event(citizen.citizen_id, csr, ("left/" + status), quantity = quantity, current_sr_number= sr_number) for service_request in citizen.service_reqs: service_request.sr_state_id = sr_state.sr_state_id for p in service_request.periods: if p.time_end is None: p.time_end = datetime.now() # Make snowplow calls to finish any stopped services if service_request.sr_id != active_sr: SnowPlow.snowplow_event(citizen.citizen_id, csr, "finishstopped", quantity = service_request.quantity, current_sr_number= service_request.sr_number) citizen.cs = CitizenState.query.filter_by(cs_state_name='Left before receiving services').first() if self.clear_comments_flag: citizen.citizen_comments = None if citizen.start_time.date() != datetime.now().date(): citizen.accurate_time_ind = 0 db.session.add(citizen) db.session.commit() socketio.emit('citizen_invited', {}, room='sb-%s' % csr.office.office_number) result = self.citizen_schema.dump(citizen) socketio.emit('update_active_citizen', result.data, room=csr.office_id) return {'citizen': result.data, 'errors': result.errors}, 200
def edit_view(self): """ Edit model view """ return_url = self.get_return_url() model = self.validate_model() if not model: return redirect(return_url) csr_id = get_mdict_item_or_list(request.args, 'id') form = self.edit_form(obj=model) if not hasattr(form, '_validated_ruleset') or not form._validated_ruleset: self._validate_form_instance(ruleset=self._form_edit_rules, form=form) if self.validate_form(form) and self.update_model(form, model): # Trim the user name, if necessary. updated_csr = CSR.query.filter_by(csr_id=csr_id).first() check_uservalues(updated_csr) socketio.emit('clear_csr_cache', {"id": csr_id}) socketio.emit('csr_update', { "csr_id": csr_id, "receptionist_ind": updated_csr.receptionist_ind }, room=current_user.office_id) flash(gettext('''Record was successfully saved.'''), 'success') request_redirect(self, return_url, model, request) if request.method == 'GET' or form.errors: self.on_form_prefill(form, id) form_opts = FormOpts(widget_args=self.form_widget_args, form_rules=self._form_edit_rules) if self.edit_modal and request.args.get('modal'): template = self.edit_modal_template else: template = self.edit_template return self.render(template, model=model, form=form, form_opts=form_opts, return_url=return_url)
def delete(self, id): appointments = Appointment.query.filter_by(recurring_uuid=id)\ .all() for appointment in appointments: db.session.delete(appointment) db.session.commit() if not application.config['DISABLE_AUTO_REFRESH']: socketio.emit('appointment_delete', id) return {}, 204
def post(self, id): csr = CSR.find_by_username(g.oidc_token_info['username']) citizen = Citizen.query.filter_by(citizen_id=id, office_id=csr.office_id).first() active_service_request = citizen.get_active_service_request() inaccurate = request.args.get('inaccurate') if active_service_request is None: return {"message": "Citizen has no active service requests"} SnowPlow.snowplow_event( citizen.citizen_id, csr, "finish", quantity=active_service_request.quantity, current_sr_number=active_service_request.sr_number) active_sr_id = active_service_request.sr_id active_service_request.finish_service(csr, self.clear_comments_flag) citizen_state = CitizenState.query.filter_by( cs_state_name="Received Services").first() citizen.cs_id = citizen_state.cs_id pending_service_state = SRState.get_state_by_name("Complete") active_service_request.sr_state_id = pending_service_state.sr_state_id if citizen.start_time.date() != datetime.now().date( ) or inaccurate == 'true': citizen.accurate_time_ind = 0 db.session.add(citizen) db.session.commit() # Loop to stop all services in the service stopped state (which are all except the active service) if len(citizen.service_reqs) != 1: for sr in citizen.service_reqs: if sr.sr_id != active_sr_id: SnowPlow.snowplow_event(citizen.citizen_id, csr, "finishstopped", quantity=sr.quantity, current_sr_number=sr.sr_number) socketio.emit('citizen_invited', {}, room='sb-%s' % csr.office.office_number) result = self.citizen_schema.dump(citizen) socketio.emit('update_active_citizen', result.data, room=csr.office_id) return {'citizen': result.data, 'errors': result.errors}, 200
def delete(self, id): csr = CSR.find_by_username(g.oidc_token_info['username']) appointments = Appointment.query.filter_by(recurring_uuid=id)\ .filter_by(office_id=csr.office_id)\ .all() for appointment in appointments: db.session.delete(appointment) db.session.commit() socketio.emit('appointment_delete', id) return {}, 204
def delete(self, id): csr = CSR.find_by_username(g.jwt_oidc_token_info['username']) appointments = Appointment.query.filter_by(recurring_uuid=id)\ .filter_by(office_id=csr.office_id)\ .all() for appointment in appointments: db.session.delete(appointment) db.session.commit() if not application.config['DISABLE_AUTO_REFRESH']: socketio.emit('appointment_delete', id) return {}, 204
def post(self, id): csr = CSR.find_by_username(g.oidc_token_info['username']) service_request = ServiceReq.query.filter_by(sr_id=id) \ .join(ServiceReq.citizen, aliased=True) \ .filter_by(office_id=csr.office_id).first_or_404() active_service_state = SRState.get_state_by_name("Active") complete_service_state = SRState.get_state_by_name("Complete") # Find the currently active service_request and close it for req in service_request.citizen.service_reqs: if req.sr_state_id == active_service_state.sr_state_id: req.sr_state_id = complete_service_state.sr_state_id req.finish_service(csr, clear_comments=False) db.session.add(req) # Then set the requested service to active service_request.sr_state_id = active_service_state.sr_state_id period_state_being_served = PeriodState.get_state_by_name( "Being Served") new_period = Period(sr_id=service_request.sr_id, csr_id=csr.csr_id, reception_csr_ind=csr.receptionist_ind, ps_id=period_state_being_served.ps_id, time_start=datetime.now()) db.session.add(new_period) db.session.add(service_request) citizen_obj = Citizen.query.get(service_request.citizen_id) citizen_obj.service_count = citizen_obj.service_count + 1 db.session.commit() SnowPlow.choose_service(service_request, csr, "additionalservice") citizen_result = self.citizen_schema.dump(service_request.citizen) socketio.emit('update_active_citizen', citizen_result.data, room=csr.office_id) result = self.service_request_schema.dump(service_request) return {'service_request': result.data, 'errors': result.errors}, 200
def delete(self, id): appointment = Appointment.query.filter_by(appointment_id=id) \ .first_or_404() csr = None if is_public_user() else CSR.find_by_username( g.oidc_token_info['username']) user: PublicUser = PublicUser.find_by_username( g.oidc_token_info['username']) if is_public_user() else None if is_public_user(): # Check if it's a public user citizen = Citizen.find_citizen_by_id(appointment.citizen_id) if not citizen or citizen.citizen_id != appointment.citizen_id: abort(403) # Must call this prior to deleting from DB, so cannot # combine with repeated is_draft check below if not appointment.is_draft: SnowPlow.snowplow_appointment(None, csr, appointment, 'appointment_delete') db.session.delete(appointment) db.session.commit() if not application.config['DISABLE_AUTO_REFRESH']: socketio.emit('appointment_delete', id) # Do not log snowplow events or send emails if it's a draft. if not appointment.is_draft: # If the appointment is public user's and if staff deletes it send email if csr: office = Office.find_by_id(appointment.office_id) # Send blackout email try: pprint('Sending email for appointment cancellation') send_email( generate_ches_token(), *get_cancel_email_contents(appointment, user, office, office.timezone)) except Exception as exc: pprint(f'Error on token generation - {exc}') return {}, 204
def post(self, id): csr = CSR.find_by_username(g.oidc_token_info['username']) lock = FileLock("lock/begin_citizen_{}.lock".format(csr.office_id)) with lock: citizen = Citizen.query.filter_by(citizen_id=id, office_id=csr.office_id).first() pending_service_state = SRState.get_state_by_name("Active") my_print("==> POST /citizens/" + str(citizen.citizen_id) + '/begin_service, Ticket: ' + citizen.ticket_number) active_service_request = citizen.get_active_service_request() if active_service_request is None: return {"message": "Citizen has no active service requests"} try: # Get Snowplow call. active_period = active_service_request.get_active_period() snowplow_event = "beginservice" if active_period.ps.ps_name == "On hold": snowplow_event = "invitefromhold" if active_period.ps.ps_name == "Ticket Creation": snowplow_event = "servecitizen" active_service_request.begin_service(csr, snowplow_event) except TypeError: return {"message": "Citizen has already been invited"}, 400 active_service_request.sr_state_id = pending_service_state.sr_state_id db.session.add(citizen) db.session.commit() if snowplow_event != "beginservice": socketio.emit('update_customer_list', {}, room=csr.office_id) result = self.citizen_schema.dump(citizen) socketio.emit('update_active_citizen', result.data, room=csr.office_id) return {'citizen': result.data, 'errors': result.errors}, 200
def post(self, id): lock = FileLock("lock/begin_citizen.lock") with lock: csr = CSR.query.filter_by(username=g.oidc_token_info['username']. split("idir/")[-1]).first() citizen = Citizen.query.filter_by(citizen_id=id, office_id=csr.office_id).first() pending_service_state = SRState.query.filter_by( sr_code='Active').first() active_service_request = citizen.get_active_service_request() if active_service_request is None: return {"message": "Citizen has no active service requests"} try: # Get Snowplow call. active_period = active_service_request.get_active_period() snowplow_event = "beginservice" if (active_period.ps.ps_name == "On hold"): snowplow_event = "invitefromhold" if (active_period.ps.ps_name == "Waiting"): snowplow_event = "invitefromlist" active_service_request.begin_service(csr, snowplow_event) except TypeError: return {"message": "Citizen has already been invited"}, 400 active_service_request.sr_state_id = pending_service_state.sr_state_id db.session.add(citizen) db.session.commit() socketio.emit('update_customer_list', {}, room=csr.office_id) result = self.citizen_schema.dump(citizen) socketio.emit('update_active_citizen', result.data, room=csr.office_id) return {'citizen': result.data, 'errors': result.errors}, 200
def post(self, id): lock = FileLock("lock/invite_citizen.lock") with lock: csr = CSR.find_by_username(g.oidc_token_info['username']) citizen = db.session.query(Citizen).with_lockmode('update').filter_by(citizen_id=id).first() active_service_state = SRState.get_state_by_name("Active") active_service_request = citizen.get_active_service_request() if active_service_request is None: return {"message": "Citizen has no active service requests"}, 400 try: active_service_request.invite(csr, invite_type="specific", sr_count = len(citizen.service_reqs)) except TypeError: return {"message": "Citizen has already been invited"}, 400 active_service_request.sr_state_id = active_service_state.sr_state_id db.session.add(citizen) db.session.commit() socketio.emit('update_customer_list', {}, room=csr.office_id) socketio.emit('citizen_invited', {}, room='sb-%s' % csr.office.office_number) result = self.citizen_schema.dump(citizen) socketio.emit('update_active_citizen', result.data, room=csr.office_id) return {'citizen': result.data, 'errors': result.errors}, 200
def post(self, id): csr = CSR.query.filter_by( username=g.oidc_token_info['username'].split("idir/")[-1]).first() citizen = Citizen.query.filter_by(citizen_id=id, office_id=csr.office_id).first() active_service_request = citizen.get_active_service_request() if active_service_request is None: return {"message": "Citizen has no active service requests"} # Figure out what Snowplow call to make. snowplow_call = "returntoqueue" if ((len(citizen.service_reqs) == 1) and (len(active_service_request.periods) == 1)): snowplow_call = "addtoqueue" active_service_request.add_to_queue(csr, snowplow_call) pending_service_state = SRState.query.filter_by( sr_code='Pending').first() active_service_request.sr_state_id = pending_service_state.sr_state_id db.session.add(citizen) db.session.commit() socketio.emit('update_customer_list', {}, room=csr.office_id) socketio.emit('citizen_invited', {}, room='sb-%s' % csr.office.office_number) result = self.citizen_schema.dump(citizen) socketio.emit('update_active_citizen', result.data, room=csr.office_id) return {'citizen': result.data, 'errors': result.errors}, 200
def on_model_change(self, form, model, is_created): csr = CSR.find_by_username(current_user.username) socketio.emit('clear_csr_cache', { "id": csr.csr_id}) socketio.emit('csr_update', {"csr_id": csr.csr_id, "receptionist_ind": csr.receptionist_ind}, room=csr.office_id) socketio.emit('digital_signage_msg_update')