def security_shifts_new(self): if self.request.redirect_forbidden: return HTTPFound(location="/forbidden/") elif userhelpers.checkUserPasswordChangeNeed(self.request): return HTTPFound(location="/settings/me/edit/") _ = self.request.translate shift = SecurityShift() if self.request.method == "POST": shift.starts = helpers.parseFinnishDateFromString(self.request.POST.get("starts").strip()) shift.ends = helpers.parseFinnishDateFromString(self.request.POST.get("ends").strip()) # shift.leader_id = helpers.decodeString(self.request.POST.get('leader_id').strip()) shift.notes = helpers.decodeString(self.request.POST.get("notes").strip()) if type(shift.starts) is datetime and type(shift.ends) is datetime and shift.starts < shift.ends: DBSession.add(shift) DBSession.flush() userAudit = UserAudit(self.request.user.id) userAudit.model = "SecurityShift" userAudit.model_id = shift.id userAudit.action = "Create" userAudit.revision = shift.metadata_revision DBSession.add(userAudit) DBSession.flush() self.request.session.flash(_(u"Shift created."), "success") return HTTPFound(location="/security/shifts/view/" + str(shift.id) + "/") else: self.request.session.flash(_(u"Error creating shift. Shift ends before it begins."), "error") self.request.bread.append({"url": "/security/", "text": _("Security")}) self.request.bread.append({"url": "/security/shifts/", "text": _("Shifts")}) self.request.bread.append({"url": "/security/shifts/new/", "text": _("Create")}) return {"shift": shift}
def security_shifts_view(self): if self.request.redirect_forbidden: return HTTPFound(location="/forbidden/") elif userhelpers.checkUserPasswordChangeNeed(self.request): return HTTPFound(location="/settings/me/edit/") _ = self.request.translate shift_id = self.request.matchdict["shift_id"] shift = DBSession.query(SecurityShift).filter(SecurityShift.id == shift_id).first() if self.request.method == "POST": logitem = SecurityLogItem() logitem.event_type = self.request.POST.get("event_type") logitem.shift_id = shift_id logitem.notified_by = self.request.POST.get("notified_by") logitem.task = self.request.POST.get("task") logitem.content = self.request.POST.get("content") logitem.deleted = False logitem.people_present = self.request.POST.get("people_present") logitem.started = helpers.parseFinnishDateFromString(self.request.POST.get("started"), default_now=True) logitem.ended = helpers.parseFinnishDateFromString(self.request.POST.get("ended")) DBSession.add(logitem) DBSession.flush() userAudit = UserAudit(self.request.user.id) userAudit.model = "SecurityLogItem" userAudit.model_id = logitem.id userAudit.action = "Create" userAudit.revision = logitem.metadata_revision DBSession.add(userAudit) DBSession.flush() self.request.session.flash(_(u"Log item created."), "success") return HTTPFound(location="/security/shifts/view/" + shift_id + "/") logitems = ( DBSession.query(SecurityLogItem) .filter(SecurityLogItem.shift_id == shift_id, SecurityLogItem.deleted == False) .order_by(SecurityLogItem.started.desc()) .all() ) self.request.bread.append({"url": "/security/", "text": _("Security")}) self.request.bread.append({"url": "/security/shifts/", "text": _("Shifts")}) self.request.bread.append({"url": "/security/shifts/view/" + shift_id + "/", "text": _("View")}) return {"shift": shift, "logitems": logitems}
def kitchen_frontpage(self): if self.request.redirect_forbidden: return HTTPFound(location='/forbidden/') elif userhelpers.checkUserPasswordChangeNeed(self.request): return HTTPFound(location='/settings/me/edit/') _ = self.request.translate if self.request.method == 'POST' and self.request.POST.get('date') != None and self.request.POST.get('date').strip() != '': day = helpers.parseFinnishDateFromString(self.request.POST.get('date').strip()) else: day = datetime.date.today() subcamps = DBSession.query(Subcamp).all() first_day = DBSession.query(Setting).with_entities(Setting.setting_key, Setting.setting_value).filter(Setting.setting_key == 'camp_first_day').first() last_day = DBSession.query(Setting).with_entities(Setting.setting_key, Setting.setting_value).filter(Setting.setting_key == 'camp_last_day').first() eating_times_breakfast = DBSession.query(Setting).with_entities(Setting.setting_key, Setting.setting_value).filter(Setting.setting_key == 'eating_times_breakfast').first() eating_times_lunch = DBSession.query(Setting).with_entities(Setting.setting_key, Setting.setting_value).filter(Setting.setting_key == 'eating_times_lunch').first() eating_times_dinner = DBSession.query(Setting).with_entities(Setting.setting_key, Setting.setting_value).filter(Setting.setting_key == 'eating_times_dinner').first() eating_times_supper = DBSession.query(Setting).with_entities(Setting.setting_key, Setting.setting_value).filter(Setting.setting_key == 'eating_times_supper').first() start_dt = helpers.parseFinnishDateFromString(first_day[1]) end_dt = helpers.parseFinnishDateFromString(last_day[1]) day_count = (end_dt - start_dt).days + 1 dates = [] dates.append(day) days = { 'start_dt':start_dt, 'end_dt':end_dt, 'dates':dates } eating_times = { 'eating_times_breakfast':eating_times_breakfast[1], 'eating_times_lunch':eating_times_lunch[1], 'eating_times_dinner':eating_times_dinner[1], 'eating_times_supper':eating_times_supper[1], } self.request.bread.append({'url':'/kitchen/', 'text':_('Kitchen')}) return {'day':day,'subcamps':subcamps, 'days':days, 'eating_times':eating_times}
def kitchen_frontpage_all(self): if self.request.redirect_forbidden: return HTTPFound(location='/forbidden/') elif userhelpers.checkUserPasswordChangeNeed(self.request): return HTTPFound(location='/settings/me/edit/') _ = self.request.translate subcamps = DBSession.query(Subcamp).all() first_day = DBSession.query(Setting).with_entities(Setting.setting_key, Setting.setting_value).filter(Setting.setting_key == 'camp_first_day').first() last_day = DBSession.query(Setting).with_entities(Setting.setting_key, Setting.setting_value).filter(Setting.setting_key == 'camp_last_day').first() eating_times_breakfast = DBSession.query(Setting).with_entities(Setting.setting_key, Setting.setting_value).filter(Setting.setting_key == 'eating_times_breakfast').first() eating_times_lunch = DBSession.query(Setting).with_entities(Setting.setting_key, Setting.setting_value).filter(Setting.setting_key == 'eating_times_lunch').first() eating_times_dinner = DBSession.query(Setting).with_entities(Setting.setting_key, Setting.setting_value).filter(Setting.setting_key == 'eating_times_dinner').first() eating_times_supper = DBSession.query(Setting).with_entities(Setting.setting_key, Setting.setting_value).filter(Setting.setting_key == 'eating_times_supper').first() start_dt = helpers.parseFinnishDateFromString(first_day[1]) end_dt = helpers.parseFinnishDateFromString(last_day[1]) day_count = (end_dt - start_dt).days + 1 dates = [] for single_date in (start_dt + timedelta(n) for n in range(day_count)): dates.append(single_date) days = { 'start_dt':start_dt, 'end_dt':end_dt, 'dates':dates } eating_times = { 'eating_times_breakfast':eating_times_breakfast[1], 'eating_times_lunch':eating_times_lunch[1], 'eating_times_dinner':eating_times_dinner[1], 'eating_times_supper':eating_times_supper[1], } self.request.bread.append({'url':'/kitchen/', 'text':_('Kitchen')}) return {'subcamps':subcamps, 'days':days, 'eating_times':eating_times}
def security_participant_view(self): _ = self.request.translate participant_id = self.request.matchdict["participant_id"] participant = DBSession.query(Participant).get(participant_id) if ( self.request.method == "POST" and self.request.POST.get("participant_new_status_id") != None and self.request.POST.get("participant_new_status_id").isdigit() ): participantStatus = ParticipantStatus() participantStatus.participant_id = participant.id participantStatus.status_id = int(self.request.POST.get("participant_new_status_id")) description = self.request.POST.get("participant_new_status_description") if description != None and description.strip() != "": participantStatus.description = description expected_next_change = self.request.POST.get("participant_new_status_expected_next_change") if expected_next_change != None and expected_next_change.strip() != "": participantStatus.expected_next_change = helpers.parseFinnishDateFromString( expected_next_change.strip() ) DBSession.add(participantStatus) DBSession.flush() participant.latest_status_key = int(self.request.POST.get("participant_new_status_id")) DBSession.add(participant) DBSession.flush() self.request.session.flash(_(u"Added new status for participant."), "success") return HTTPFound(location="/security/participant/view/" + str(participant.id) + "/") participant.getParticipantAddressData() participant.getParticipantPhoneData() participant.getParticipantLanguageData() participant.getParticipantPresenceData() participant.getParticipantNextOfKinData() participant.getParticipantMetaData() self.request.bread.append({"url": "/security/", "text": _("Security")}) self.request.bread.append({"url": "/security/participant/search/", "text": _("Search")}) self.request.bread.append( { "url": "/security/participant/view/" + participant_id + "/", "text": _("Participant") + " " + helpers.decodeString(participant.firstname) + " " + helpers.decodeString(participant.lastname), } ) return {"participant": participant}
def medical_statistics(self): if self.request.redirect_forbidden: return HTTPFound(location='/forbidden/') elif userhelpers.checkUserPasswordChangeNeed(self.request): return HTTPFound(location='/settings/me/edit/') _ = self.request.translate reasons = DBSession.query(MedicalReason).order_by(MedicalReason.title).all() treatmenttypes = DBSession.query(MedicalTreatmentType).order_by(MedicalTreatmentType.title).all() methodsofarrival = DBSession.query(MedicalMethodOfArrival).order_by(MedicalMethodOfArrival.title).all() filters = [] start_datetime = '' end_datetime = '' if self.request.method == 'POST' and self.request.POST.get('start').strip() != '': start_datetime = self.request.POST.get('start').strip() start_dt = helpers.parseFinnishDateFromString(start_datetime) if self.request.POST.get('end').strip() != '': end_datetime = self.request.POST.get('end').strip() end_dt = helpers.parseFinnishDateFromString(end_datetime) else: end_dt = start_dt + relativedelta( days = +1 ) end_datetime = helpers.modDateTime(end_dt) filters.append(MedicalCard.hospital_in >= start_dt) filters.append(MedicalCard.hospital_in <= end_dt) stats = {} reason_stats = {} treatmenttypes_stats = {} methodsofarrival_stats = {} for reason in reasons: report = DBSession.query(MedicalCard) if len(filters) > 0: report = report.filter(and_(*filters)) report = report.filter(MedicalCard.reason_id==reason.id) reason_stats[reason.id] = report.count() for treatmenttype in treatmenttypes: report = DBSession.query(MedicalCard) if len(filters) > 0: report = report.filter(and_(*filters)) report = report.filter(MedicalCard.treatment_type==treatmenttype.id) treatmenttypes_stats[treatmenttype.id] = report.count() for methodofarrival in methodsofarrival: report = DBSession.query(MedicalCard) if len(filters) > 0: report = report.filter(and_(*filters)) report = report.filter(MedicalCard.method_of_arrival==methodofarrival.id) methodsofarrival_stats[methodofarrival.id] = report.count() stats = { 'reason_stats':reason_stats, 'treatmenttypes_stats':treatmenttypes_stats, 'methodsofarrival_stats':methodsofarrival_stats } self.request.bread.append({'url':'/medical/', 'text':_('Medical')}) self.request.bread.append({'url':'/medical/statistics/', 'text':_('Statistics')}) return {'stats':stats, 'start':start_datetime, 'end':end_datetime}
def medical_card_edit(self): if self.request.redirect_forbidden: return HTTPFound(location='/forbidden/') elif userhelpers.checkUserPasswordChangeNeed(self.request): return HTTPFound(location='/settings/me/edit/') _ = self.request.translate card_id = self.request.matchdict['card_id'] medicalCard = DBSession.query(MedicalCard).filter(MedicalCard.id==card_id).first() participant_id = medicalCard.participant_id participant = DBSession.query(Participant).filter(Participant.id==participant_id).first() participant.getParticipantMedicalData() medicalCardEvents = DBSession.query(MedicalCardEvent).filter(MedicalCardEvent.card_id==card_id).order_by(MedicalCardEvent.event_time).all() medicalParticipantAdditional = DBSession.query(MedicalParticipantAdditional).filter(MedicalParticipantAdditional.participant_id==participant_id).first() reasons = DBSession.query(MedicalReason).order_by(MedicalReason.title).all() treatmenttypes = DBSession.query(MedicalTreatmentType).order_by(MedicalTreatmentType.title).all() methodsofarrival = DBSession.query(MedicalMethodOfArrival).order_by(MedicalMethodOfArrival.title).all() if self.request.method == 'POST': # save card medicalCard.hospital_in = helpers.parseFinnishDateFromString(self.request.POST.get('hospital_in'), True) medicalCard.hospital_out = helpers.parseFinnishDateFromString(self.request.POST.get('hospital_out')) medicalCard.method_of_arrival = int(self.request.POST.get('method_of_arrival')) medicalCard.medications = int(self.request.POST.get('medications')) medicalCard.medications_info = self.request.POST.get('medications_info').strip() medicalCard.treatment_type = int(self.request.POST.get('treatment_type')) medicalCard.reason_id = int(self.request.POST.get('reason_id')) medicalCard.diagnose = self.request.POST.get('diagnose').strip() medicalCard.followup_going = self.request.POST.get('followup_going').strip() medicalCard.followup_notes = self.request.POST.get('followup_notes').strip() medicalCard.card_status = int(self.request.POST.get('card_status').strip()) DBSession.add(medicalCard) DBSession.flush() #save participant additional medicalParticipantAdditional.hetu = self.request.POST.get('additional_hetu').strip() medicalParticipantAdditional.notes = self.request.POST.get('additional_notes').strip() medicalParticipantAdditional.insurance = int(self.request.POST.get('additional_insurance')) medicalParticipantAdditional.insurance_company = self.request.POST.get('additional_insurance_company').strip() medicalParticipantAdditional.insurance_number = self.request.POST.get('additional_insurance_number').strip() DBSession.add(medicalParticipantAdditional) DBSession.flush() #save card event if len(self.request.POST.getall('event_id')) > 0: event_ids = self.request.POST.getall('event_id') if len(medicalCardEvents) > 0: for medicalCardEvent in medicalCardEvents: if str(medicalCardEvent.id) not in event_ids: DBSession.delete(medicalCardEvent) DBSession.flush() event_times = self.request.POST.getall('event_time') event_writers = self.request.POST.getall('event_writer') event_types = self.request.POST.getall('event_type') event_notes = self.request.POST.getall('event_notes') for key, event_note in enumerate(event_notes): if event_note != '': event_time = event_times[key] event_id = event_ids[key] event_writer = event_writers[key] event_type = event_types[key] event_time_dt = helpers.parseFinnishDateFromString(event_time) if int(event_ids[key]) == 0: tmp_event = MedicalCardEvent() tmp_event.card_id = medicalCard.id else: tmp_event = DBSession.query(MedicalCardEvent).get(event_ids[key]) tmp_event.notes = event_note tmp_event.event_time = helpers.parseFinnishDateFromString(event_time) tmp_event.writer = event_writer tmp_event.event_type = event_type DBSession.add(tmp_event) DBSession.flush() elif len(medicalCardEvents) > 0: for event in medicalCardEvents: DBSession.delete(event) DBSession.flush() # save participant medical if len(self.request.POST.getall('medical_diet'))>0: participant.medical_data.diets = DBSession.query(ParticipantMedicalDiet).filter(ParticipantMedicalDiet.id.in_(self.request.POST.getall('medical_diet'))).all() if len(self.request.POST.getall('medical_food_allergy'))>0: participant.medical_data.food_allergies = DBSession.query(ParticipantMedicalFoodAllergy).filter(ParticipantMedicalFoodAllergy.id.in_(self.request.POST.getall('medical_food_allergy'))).all() participant.medical_data.additional_food = self.request.POST.get('medical_additional_food').strip() participant.medical_data.drugs_help = int(self.request.POST.get('medical_drugs_help')) participant.medical_data.illnesses = self.request.POST.get('medical_illnesses').strip() if len(self.request.POST.getall('medical_allergy'))>0: participant.medical_data.allergies = DBSession.query(ParticipantMedicalAllergy).filter(ParticipantMedicalAllergy.id.in_(self.request.POST.getall('medical_allergy'))).all() participant.medical_data.additional_health = self.request.POST.get('medical_additional_health').strip() participant.medical_data.week_of_pregnancy = self.request.POST.get('medical_week_of_pregnancy').strip() participant.medical_data.participant_id = participant_id DBSession.add(participant.medical_data) DBSession.flush() return HTTPFound(location='/medical/card/view/'+str(medicalCard.id)+'/') self.request.bread.append({'url':'/medical/', 'text':_('Medical')}) self.request.bread.append({'url':'/medical/card/edit/'+str(card_id)+'/', 'text':_('Edit card')}) return {'medicalCard':medicalCard, 'participant':participant, 'medicalParticipantAdditional':medicalParticipantAdditional, 'medicalCardEvents':medicalCardEvents, 'reasons':reasons, 'treatmenttypes':treatmenttypes, 'methodsofarrival':methodsofarrival}