def signup_patient_view(request): if(request.method == 'POST'): user_form = forms.User_Form(request.POST) patient_form = forms.Patient_Form(request.POST) if(user_form.is_valid() & patient_form.is_valid()): user = user_form.save() patient = patient_form.save(commit = False) patient.user = user patient.patient_name = user.first_name + ' ' + user.last_name patient.patient_email = user.email patient.is_validated = False try: patient.save() login(request, user) existing_patient = All_Patient.objects.filter(patient_email = user.email) if(len(existing_patient) == 0): new_patient = All_Patient() new_patient.patient_email = user.email else: new_patient = existing_patient[0] new_patient.admission_date = datetime.date.today() new_patient.discharge_date = None new_patient.patient_name = user.first_name + ' ' + user.last_name new_patient.save() return redirect('patient:homepage') except IntegrityError: user.delete() return render(request, 'already_exists.html', http_dict_func(request)) else: user_form = forms.User_Form() patient_form = forms.Patient_Form() http_dict = http_dict_func(request) http_dict['user_form'] = user_form http_dict['patient_form'] = patient_form return render(request, 'accounts/signup_patient.html', http_dict)
def signup_staff_view(request): if(request.method == 'POST'): user_form = forms.User_Form(request.POST) staff_form = forms.Staff_Form(request.POST) if(user_form.is_valid() & staff_form.is_valid()): user = user_form.save() staff = staff_form.save(commit = False) staff.user = user staff.staff_email = user.email staff.is_validated = False try: staff.save() login(request, user) existing_staff = All_Staff.objects.filter(staff_email = user.email) if(len(existing_staff) == 0): new_staff = All_Staff() new_staff.staff_email = user.email else: new_staff = existing_staff[0] new_staff.staff_name = user.first_name + ' ' + user.last_name new_staff.save() return redirect('staff:homepage') except IntegrityError: user.delete() return render(request, 'already_exists.html', http_dict_func(request)) else: user_form = forms.User_Form() staff_form = forms.Staff_Form() http_dict = http_dict_func(request) http_dict['user_form'] = user_form http_dict['staff_form'] = staff_form return render(request, 'accounts/signup_staff.html', http_dict)
def view_indiv_health_status(request): if (request.method == 'POST'): patient_id = [x for x in request.POST.keys() if x.startswith('ID_')] assert (len(patient_id) == 1) patient_id = int(patient_id[0].split('_')[1]) http_dict = http_dict_func(request) http_dict['patient_id'] = patient_id return render(request, 'staff/indiv_health_status.html', http_dict)
def stats_view(request): patient_db = Patient.objects.filter(is_validated = True) all_patient_db = All_Patient.objects.all() staff_db = Staff.objects.all() bill_db = Bill_entry.objects.all() stats.room_occupancy(patient_db) stats.monthly_billing(bill_db) stats.gender_ratio(staff_db) stats.daily_billing(bill_db) stats.patient_geomap(patient_db) stats.age_histogram(patient_db) stats.admission_discharge_rate(all_patient_db) http_dict = http_dict_func(request) #return HttpResponse("Admin Stats") return render(request, 'administration/stats.html', http_dict)
def edit_staff(request): if(request.method == 'POST'): user_form = forms.User_Form(request.POST, instance = request.user) staff_form = forms.Staff_Form(request.POST, instance = request.user.staff) if(user_form.is_valid() & staff_form.is_valid()): user = user_form.save() staff = staff_form.save(commit = False) staff.user = user staff.save() login(request, user) return redirect('staff:homepage') else: user_form = forms.User_Form(instance = request.user) staff_form = forms.Staff_Form(instance = request.user.staff) http_dict = http_dict_func(request) http_dict['user_form'] = user_form http_dict['staff_form'] = staff_form return render(request, 'accounts/edit_staff.html', http_dict)
def edit_patient(request): if(request.method == 'POST'): user_form = forms.User_Form(request.POST, instance = request.user) patient_form = forms.Patient_Form(request.POST, instance = request.user.patient) if(user_form.is_valid() & patient_form.is_valid()): user = user_form.save() patient = patient_form.save(commit = False) patient.user = user patient.save() login(request, user) return redirect('patient:homepage') else: user_form = forms.User_Form(instance = request.user) patient_form = forms.Patient_Form(instance = request.user.patient) http_dict = http_dict_func(request) http_dict['user_form'] = user_form http_dict['patient_form'] = patient_form return render(request, 'accounts/edit_patient.html', http_dict)
def login_view(request): if(request.method == 'POST'): user_form = AuthenticationForm(data = request.POST) if(user_form.is_valid()): user = user_form.get_user() login(request, user) if('next' in request.POST): return redirect(request.POST.get('next')) else: if(user.is_superuser): return redirect('administration:homepage') else: try: _ = user.patient return redirect('patient:homepage') except: return redirect('staff:homepage') else: user_form = AuthenticationForm() http_dict = http_dict_func(request) http_dict['user_form'] = user_form return render(request, 'accounts/login.html', http_dict)
def remove_staff(request): if(request.method == 'POST'): for key in request.POST: if(key != 'csrfmiddlewaretoken'): valid_user = User.objects.get(username = key) valid_all_staff = All_Staff.objects.get(staff_email = valid_user.email) valid_all_staff.discharge_date = datetime.date.today() valid_all_staff.save() valid_user.delete() return redirect('administration:homepage') else: staffs = Staff.objects.all() validated_staffs = [] for staff in staffs: try: _ = staff.all_staff validated_staffs.append(staff) except: pass http_dict = http_dict_func(request) http_dict['valid_staffs'] = validated_staffs return render(request, 'administration/remove_staff.html', http_dict)
def validate_staff(request): if(request.method == 'POST'): for key in request.POST: if(key != 'csrfmiddlewaretoken'): valid_user = User.objects.get(username = key) valid_user.staff.is_validated = True valid_all_staff = All_Staff.objects.get(staff_email = valid_user.email) valid_all_staff.staff = valid_user.staff valid_user.staff.save() valid_all_staff.save() return redirect('administration:homepage') else: staffs = Staff.objects.all() unvalidated_staffs = [] for staff in staffs: try: _ = staff.all_staff except: unvalidated_staffs.append(staff) http_dict = http_dict_func(request) http_dict['unvalid_staffs'] = unvalidated_staffs return render(request, 'administration/validate_staff.html', http_dict)
def validate_patient(request): if (request.method == 'POST'): for key in request.POST: if (key != 'csrfmiddlewaretoken'): valid_user = User.objects.get(username=key) valid_user.patient.is_validated = True valid_all_patient = All_Patient.objects.get( patient_email=valid_user.email) valid_all_patient.patient = valid_user.patient valid_user.patient.save() valid_all_patient.save() return redirect('staff:homepage') else: patients = Patient.objects.all() unvalidated_patients = [] for patient in patients: try: _ = patient.all_patient except: unvalidated_patients.append(patient) http_dict = http_dict_func(request) http_dict['unvalid_patients'] = unvalidated_patients return render(request, 'staff/validate_patient.html', http_dict)
def remove_patient(request): if (request.method == 'POST'): for key in request.POST: if (key != 'csrfmiddlewaretoken'): valid_user = User.objects.get(username=key) valid_all_patient = All_Patient.objects.get( patient_email=valid_user.email) valid_all_patient.discharge_date = date.today() valid_all_patient.save() valid_user.delete() return redirect('staff:homepage') else: patients = Patient.objects.all() validated_patients = [] for patient in patients: try: _ = patient.all_patient validated_patients.append(patient) except: pass http_dict = http_dict_func(request) http_dict['valid_patients'] = validated_patients return render(request, 'staff/remove_patient.html', http_dict)
def view_health_status(request): patients = Patient.objects.all() patients_health = [] for patient in patients: health_status = patient.health_status_set.all() if (len(health_status) > 0): health_status = health_status.order_by('-recorded_time')[0] health_status_dict = {} health_status_dict['name'] = patient health_status_dict['patient_id'] = patient.id health_status_dict['room_number'] = patient.room_number health_status_dict['temperature'] = health_status.temperature health_status_dict['spO2'] = health_status.spO2 health_status_dict['bpm'] = health_status.bpm health_status_dict[ 'recorded_time'] = health_status.recorded_time.replace( tzinfo=None) patients_health.append(health_status_dict) http_dict = http_dict_func(request) http_dict['health_status'] = patients_health return render(request, 'staff/view_health_status.html', http_dict)
def homepage_view(request): return render(request, 'homepage.html', http_dict_func(request))
def unauthorized_view(request): return render(request, 'unauthorized.html', http_dict_func(request))
def contact_view(request): return render(request, 'contact.html', http_dict_func(request))
def homepage_view(request): http_dict = http_dict_func(request) return render(request, 'patient/homepage.html', http_dict)
def about_view(request): return render(request, 'about.html', http_dict_func(request))
def features_view(request): return render(request, 'features.html', http_dict_func(request))
def health_status_view(request): http_dict = http_dict_func(request) http_dict['patient_id'] = request.user.patient.id return render(request, 'patient/patient_health_status.html', http_dict)
def homepage_view(request): http_dict = http_dict_func(request) return render(request, 'administration/homepage.html', http_dict)