def nursePastAppt(): if not helper.check_nurse_privilege(): return redirect("/loadHomePage") end_date = datetime.datetime.strptime(request.form['endDate'], helper.DATE_FORMAT) nurse_id = current_user.get_id() if request.form['startDate']: start_date = datetime.datetime.strptime(request.form['startDate'], helper.DATE_FORMAT) apps = helper.dept_appts(user=current_user, period=(end_date-start_date).days,\ start_date=start_date).filter(Application.status==StatusEnum.finished) else: # if startDate is None then get all past appts apps = helper.dept_appts(user=current_user, direction="past",\ start_date=end_date).filter(Application.status==StatusEnum.finished) helper.load_id2name_map() return make_response( jsonify([{ "appID": app.id, "date": app.date.strftime(helper.DATE_FORMAT), "time": app.time.strftime(helper.TIME_FORMAT), "doctor": helper.id2name(app.doctor_id), "patient": helper.id2name(app.patient_id), "symptoms": app.symptoms } for app in apps]))
def viewMC(): if not (helper.check_doctor_privilege() or helper.check_nurse_privilege()): return redirect("/loadHomePage") patient_id = request.form['patientID'] helper.load_id2name_map() table = Application.query.filter( Application.patient_id == patient_id, Application.status == StatusEnum.finished).all() return make_response( jsonify({ 'patientID': str(patient_id), 'patientName': helper.id2name(patient_id), 'appts': [{ 'appID': str(table[i].id), 'mcID': table[i].mc_id, 'date': table[i].date.strftime(helper.DATE_FORMAT), 'time': table[i].time.strftime(helper.TIME_FORMAT), 'doctor': helper.id2name(table[i].doctor_id), 'symptoms': table[i].symptoms } for i in range(len(table))] }))
def nurseOnGoingAppt(): if not helper.check_nurse_privilege(): return redirect("/loadHomePage") helper.load_id2name_map() nurse_id = current_user.get_id() nowtime = datetime.datetime.now() # filter1: today's appts; filter2: status=approved today_approved_appts = helper.dept_appts(user=current_user, period=0).\ filter( Application.status == StatusEnum.approved ).all() # filter2: now() in timeslot now_approved_appts = [] for appt in today_approved_appts: appt_date_time = datetime.datetime.combine(appt.date, appt.time) if appt_date_time <= nowtime <= appt_date_time + timedelta(minutes=30): now_approved_appts.append(appt) return make_response( jsonify([{ "appID": appt.id, "date": appt.date.strftime(helper.DATE_FORMAT), "time": appt.time.strftime(helper.TIME_FORMAT), "doctor": helper.id2name(appt.doctor_id), "patient": helper.id2name(appt.patient_id), "symptoms": appt.symptoms } for appt in now_approved_appts]))
def response_generator(app): return { "appID": app.id, "date": app.date.strftime(helper.DATE_FORMAT), "time": app.time.strftime(helper.TIME_FORMAT), "doctor": helper.id2name(app.doctor_id), "patient": helper.id2name(app.patient_id), "symptoms": app.symptoms }
def patientFutureAppt(): if not helper.check_patient_privilege(): return redirect("/login") n_offset, n_tot_records, n_tot_page, page_count = helper.paginate( Application) patientID = current_user.get_id() total_number = len( Application.query.filter( Application.patient_id == patientID, Application.status == StatusEnum.approved, Application.date + Application.time >= datetime.datetime.today()).order_by(Application.date.desc(), Application.time.desc()).all()) apps = Application.query.filter( Application.patient_id == patientID, Application.status == StatusEnum.approved, Application.date + Application.date >= datetime.datetime.today()).order_by( Application.date.desc(), Application.time.desc()).offset(n_offset).limit(page_count).all() helper.load_id2name_map() return make_response( jsonify({ 'total_number': total_number, "apps": [{ "appID": app.id, "date": app.date.strftime(helper.DATE_FORMAT), "time": app.time.strftime(helper.TIME_FORMAT), "hospital": Hospital.query.filter(Hospital.id == helper.user2hosp( app.doctor_id, "doctor")).first().name, "department": helper.user2dept_name(app.doctor_id, "doctor"), "nurse": helper.id2name(app.approver_id), "patient": helper.id2name(app.patient_id), "doctor": helper.id2name(app.doctor_id), "symptoms": app.symptoms, } for app in apps] }))
def doctorTodayAppt(): if not helper.check_doctor_privilege(): return redirect("/login") doctorID = current_user.get_id() appt_list = helper.doc2appts(doctorID, 0) helper.load_id2name_map() return make_response( jsonify([{ "appID": str(appt_list[i].id), "date": appt_list[i].date.strftime(helper.DATE_FORMAT), "time": appt_list[i].time.strftime(helper.TIME_FORMAT), "nurse": helper.id2name(appt_list[i].approver_id), "patient": helper.id2name(appt_list[i].patient_id), "symptoms": appt_list[i].symptoms } for i in range(len(appt_list))]))
def doctorFutureAppt(): if not helper.check_doctor_privilege(): return redirect("/login") if request.method == "POST": start_date = request.form["startDate"] end_date = request.form["endDate"] elif request.method == "GET": start_date = 0 end_date = 0 doctorID = current_user.get_id() # if start date is given, use it directly; o.w. set it to today if start_date == datetime.datetime.today().strftime(helper.DATE_FORMAT): filter = True if start_date: start_date = datetime.datetime.strptime(start_date, helper.DATE_FORMAT) else: start_date = datetime.datetime.today() # similar to start date if end_date: end_date = datetime.datetime.strptime(end_date, helper.DATE_FORMAT) if end_date: apps = helper.doc2appts(doctorID, period=(end_date - start_date).days, start_date=start_date) else: apps = helper.doc2appts(doctorID, start_date=start_date, limit='no') if filter: for i in range(len(apps)): if datetime.datetime.combine( apps[i].date, apps[i].time ) < datetime.datetime.now() - timedelta(minutes=30): apps.pop(i) helper.load_id2name_map() return make_response( jsonify([{ "appID": app.id, "date": app.date.strftime(helper.DATE_FORMAT), "time": app.time.strftime(helper.TIME_FORMAT), "nurse": helper.id2name(app.approver_id), "patient": helper.id2name(app.patient_id), "symptoms": app.symptoms, } for app in apps]))
def goViewMC(): if not (helper.check_doctor_privilege() or helper.check_nurse_privilege()): return redirect("/loadHomePage") patient_id = request.form['patientID'] helper.load_id2name_map() return render_template('doctorNurseViewMC.html', patientID=patient_id, patientName=helper.id2name(patient_id))
def nurseGoViewAppt(appID): if not helper.check_nurse_privilege(): return redirect("/loadHomePage") appt_res = Application.query.filter(Application.id == appID).first() finished = False if appt_res.status.value == "finished": finished = True helper.load_id2name_map() return render_template('nurseViewAppt.html', appID=appt_res.id, date=appt_res.date.strftime(helper.DATE_FORMAT), time=appt_res.time.strftime(helper.TIME_FORMAT), doctor=helper.id2name(appt_res.doctor_id), patientID=appt_res.patient_id, patient=helper.id2name(appt_res.patient_id), symptoms=appt_res.symptoms, comments=appt_res.reject_reason, mcID=appt_res.mc_id, finished=finished)
def doctorPastAppt(): if not helper.check_doctor_privilege(): return redirect("/login") if request.method == "POST": start_date = request.form["startDate"] end_date = request.form["endDate"] elif request.method == "GET": start_date = 0 end_date = 0 doctorID = current_user.get_id() if start_date: start_date = datetime.datetime.strptime(start_date, helper.DATE_FORMAT) if end_date: end_date = datetime.datetime.strptime(end_date, helper.DATE_FORMAT) else: end_date = datetime.date.today() if start_date: apps = helper.doc2appts(doctorID, period=(end_date - start_date).days, direction='past', start_date=end_date) else: apps = helper.doc2appts(doctorID, start_date=start_date, direction='past', limit='no') helper.load_id2name_map() return make_response( jsonify([{ "appID": app.id, "date": app.date.strftime(helper.DATE_FORMAT), "time": app.time.strftime(helper.TIME_FORMAT), "nurse": helper.id2name(app.approver_id), "patient": helper.id2name(app.patient_id), "symptoms": app.symptoms, } for app in apps]))
def viewDoctorByID(doctorID): doctor = Doctor.query.join(Department, Doctor.department_id == Department.id).\ join(Hospital,Department.hospital_id == Hospital.id).filter(Doctor.id == doctorID).first() helper.load_id2name_map() doctorName = id2name(doctorID) hospital = doctor.department.hospital.name department = doctor.department.title return render_template('doctorPage.html', doctorID=doctorID, doctorName=doctorName, hospital=hospital, department=department)
def doctorOnGoingAppt(): if not helper.check_doctor_privilege(): return redirect("/login") doctorID = current_user.get_id() nowtime = datetime.datetime.now() appt_list = helper.doc2appts(doctorID, 0) now_approved_appts = [] for appt in appt_list: appt_date_time = datetime.datetime.combine(appt.date, appt.time) if appt_date_time <= nowtime <= appt_date_time + timedelta(minutes=30): now_approved_appts.append(appt) helper.load_id2name_map() return make_response( jsonify([{ "appID": appt.id, "date": appt.date.strftime(helper.DATE_FORMAT), "time": appt.time.strftime(helper.TIME_FORMAT), "nurse": helper.id2name(appt.approver_id), "patient": helper.id2name(appt.patient_id), "symptoms": appt.symptoms } for appt in now_approved_appts]))
def patientGetApp(): if not helper.check_patient_privilege(): return redirect("/login") app_id = request.form['appID'] app = Application.query.get(app_id) if not app: return make_response({"ret": "Appointment Not Found!"}) if current_user.get_id() != app.patient_id: return redirect("/login") return make_response( jsonify({ "date": app.date.strftime(helper.DATE_FORMAT), "time": app.time.strftime(helper.TIME_FORMAT), "doctor": helper.id2name(app.doctor_id), "symptoms": app.symptoms }))
def getPatientRecord(): if not helper.check_patient_privilege(): return redirect("/login") type = request.args.get('type') if type == "appointment": n_offset, n_tot_records, n_tot_page, page_count = helper.paginate( Application) patientID = current_user.get_id() total_number = len( Application.query.filter( Application.patient_id == patientID).order_by( Application.date.desc(), Application.time.desc()).all()) apps = Application.query.filter( Application.patient_id == patientID).order_by( Application.date.desc(), Application.time.desc()).offset( n_offset).limit(page_count).all() helper.load_id2name_map() return make_response( jsonify({ 'total_number': total_number, "apps": [ { "appID": app.id, "date": app.date.strftime(helper.DATE_FORMAT), "time": app.time.strftime(helper.TIME_FORMAT), "hospital": Hospital.query.filter(Hospital.id == helper.user2hosp( app.doctor_id, "doctor")).first().name, "department": helper.user2dept_name(app.doctor_id, "doctor"), "doctor": helper.id2name(app.doctor_id), "status": app.status.value, # "nurse": helper.id2name(app.approver_id) if app.approver_id else "", # "patient": helper.id2name(app.patient_id), # "symptoms": app.symptoms, # "reject_reason":app.reject_reason, } for app in apps ] })) elif type == "medical_record": n_offset, n_tot_records, n_tot_page, page_count = helper.paginate( Medical_record) patientID = current_user.get_id() apps = Application.query.filter( Application.patient_id == patientID, Application.status == StatusEnum.finished).order_by( Application.date.desc(), Application.time.desc()).offset( n_offset).limit(page_count).all() mcs = [ Medical_record.query.filter( Medical_record.id == app.mc_id).first() for app in apps ] helper.load_id2name_map() return make_response( jsonify({ 'total_number': len(mcs), "mcs": [{ "mcID": mcs[i].id, "appID": apps[i].id, "date": apps[i].date.strftime(helper.DATE_FORMAT), "time": apps[i].time.strftime(helper.TIME_FORMAT), "doctor": helper.id2name(apps[i].doctor_id), "hospital": Hospital.query.filter(Hospital.id == helper.user2hosp( apps[i].doctor_id, "doctor")).first().name, "department": helper.user2dept_name(apps[i].doctor_id, "doctor"), } for i in range(len(mcs))] }))