def createemployee_view(request): # Authentication check. authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN]) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session( request, {'form_button': "Register"} ) # Proceed with the rest of the view if request.method == 'POST': form = EmployeeRegisterForm(request.POST) if form.is_valid(): user = views.register_user( form.cleaned_data['email'], form.cleaned_data['password_first'], form.cleaned_data['firstname'], form.cleaned_data['lastname'], form.cleaned_data['employee'] ) logger.log(Action.ACTION_ADMIN, 'Admin registered ' + user.username, request.user.account) request.session['alert_success'] = "Successfully created new employee account." return HttpResponseRedirect('/admin/users/') else: form = EmployeeRegisterForm() template_data['form'] = form return render(request, 'healthnet/admin/createemployee.html', template_data)
def add_hospital_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_ADMIN] ) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session( request, {'form_button': "Add Hospital"} ) # Proceed with the rest of the view if request.method == 'POST': form = HospitalForm(request.POST) if form.is_valid(): location = Location( city=form.cleaned_data['city'], zip=form.cleaned_data['zip'], state=form.cleaned_data['state'], address=form.cleaned_data['address'] ) location.save() hospital = Hospital( name=form.cleaned_data['name'], phone=form.cleaned_data['phone'], location=location, ) hospital.save() form = HospitalForm() # Clean the form when the page is redisplayed template_data['alert_success'] = "Successfully added the hospital!" else: form = HospitalForm() template_data['form'] = form return render(request, 'healthnet/admin/add_hospital.html', template_data)
def admit_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_NURSE, Account.ACCOUNT_DOCTOR] ) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session( request, {'form_button': "Admit"} ) # Proceed with the rest of the view default = {} # Prefill some of the form values if 'hospital' not in request.POST and request.user.account.profile.prefHospital is not None: default['hospital'] = request.user.account.profile.prefHospital.pk if 'timestamp' not in request.POST: default['timestamp'] = datetime.now().strftime("%Y-%m-%d %H:%M") request.POST._mutable = True request.POST.update(default) form = AdmissionForm(request.POST) if request.method == 'POST': if form.is_valid(): admission = form.generate() admission.save() logger.log(Action.ACTION_ADMISSION, 'Admitted Patient', request.user.account) form = AdmissionForm(default) # Clean the form when the page is redisplayed form.clear_errors() request.session['alert_success'] = "Successfully admitted patient." # Use session when passing data through a redirect return HttpResponseRedirect('/admission/list/') else: form._errors = {} template_data['form'] = form return render(request, 'healthnet/admission/admit.html', template_data)
def setup_view(request): if Account.objects.all().count() > 0: request.session['alert_success'] = "Setup has already been completed." return HttpResponseRedirect('/') # Get the template data from the session template_data = views.parse_session(request, {'form_button': "Register"}) # Proceed with the rest of the view if request.method == 'POST': form = AccountRegisterForm(request.POST) if form.is_valid(): views.register_user( form.cleaned_data['email'], form.cleaned_data['password_first'], form.cleaned_data['firstname'], form.cleaned_data['lastname'], Account.ACCOUNT_ADMIN ) user = authenticate( username=form.cleaned_data['email'].lower(), # Make sure it's lowercase password=form.cleaned_data['password_first'] ) logger.log(Action.ACTION_ACCOUNT, "Account login", user.account) login(request, user) request.session['alert_success'] = "Successfully setup HealthNet's primary admin account." return HttpResponseRedirect('/profile/') else: form = AccountRegisterForm() template_data['form'] = form return render(request, 'healthnet/setup.html', template_data)
def register_view(request): # Authentication check. Users logged in cannot view this page. if request.user.is_authenticated(): return HttpResponseRedirect('/profile/') elif Account.objects.all().count() == 0: return HttpResponseRedirect('/setup/') # Get the template data from the session template_data = views.parse_session(request, {'form_button': "Register"}) # Proceed with the rest of the view if request.method == 'POST': form = PatientRegisterForm(request.POST) if form.is_valid(): views.register_user( form.cleaned_data['email'], form.cleaned_data['password_first'], form.cleaned_data['firstname'], form.cleaned_data['lastname'], Account.ACCOUNT_PATIENT, form.cleaned_data['insurance'] ) user = authenticate( username=form.cleaned_data['email'].lower(), # Make sure it's lowercase password=form.cleaned_data['password_first'] ) logger.log(Action.ACTION_ACCOUNT, "Account login", user.account) login(request, user) request.session['alert_success'] = "Successfully registered with HealthNet." return HttpResponseRedirect('/profile/') else: form = PatientRegisterForm() template_data['form'] = form return render(request, 'healthnet/register.html', template_data)
def update_view(request): # Authentication check. authentication_result = views.authentication_check(request) if authentication_result is not None: return authentication_result # Get the template data from the asession template_data = views.parse_session(request, {'form_button': "Update profile"}) # Proceed with the rest of the view profile = request.user.account.profile if request.method == 'POST': if request.user.account.role != Account.ACCOUNT_PATIENT: form = EmployeeProfileForm(request.POST) else: form = ProfileForm(request.POST) if form.is_valid(): form.assign(profile) profile.save() logger.log(Action.ACTION_ACCOUNT, "Account updated info", request.user.account) template_data['alert_success'] = "Your profile has been updated!" else: if request.user.account.role != Account.ACCOUNT_PATIENT: form = EmployeeProfileForm(profile.get_populated_fields()) else: form = ProfileForm(profile.get_populated_fields()) template_data['form'] = form return render(request, 'healthnet/profile/update.html', template_data)
def new_view(request): # Authentication check. authentication_result = views.authentication_check(request) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session( request, {'form_button': "Send Message"} ) # Proceed with the rest of the view if request.method == 'POST': form = MessageForm(request.POST) if form.is_valid(): message = form.generate(request.user.account) message.save() logger.log(Action.ACTION_MESSAGE, 'Message sent', request.user.account) request.session['alert_success'] = "Successfully sent your message!" return HttpResponseRedirect('/message/list/') else: # Validation Check. Make sure a message exists for the given pk. default = {} if 'pk' in request.GET: pk = request.GET['pk'] try: account = Account.objects.get(pk=pk) default['target'] = pk except Exception: template_data['alert_danger'] = "We couldn't find the person you're replying to. Please try again.." form = MessageForm(default) form.clear_errors() template_data['form'] = form return render(request, 'healthnet/message/new.html', template_data)
def list_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_DOCTOR, Account.ACCOUNT_NURSE, Account.ACCOUNT_PATIENT] ) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view if request.method == 'POST': if 'delete' in request.POST and 'pk' in request.POST: pk = request.POST['pk'] try: prescription = Prescription.objects.get(pk=pk) prescription.active = False prescription.save() logger.log(Action.ACTION_PRESCRIPTION, 'Prescription Cancelled', request.user.account) template_data['alert_success'] = "The prescription has been deleted." except Exception: template_data['alert_danger'] = "Unable to delete the prescription. Please try again later." if request.user.account.role == Account.ACCOUNT_DOCTOR: prescriptions = Prescription.objects.filter(doctor=request.user.account) elif request.user.account.role == Account.ACCOUNT_PATIENT: prescriptions = Prescription.objects.filter(patient=request.user.account) else: prescriptions = Prescription.objects.all() template_data['query'] = prescriptions.order_by('date') return render(request, 'healthnet/prescription/list.html', template_data)
def error_denied_view(request): # Authentication check. authentication_result = views.authentication_check(request) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view return render(request, 'healthnet/error/denied.html', template_data)
def profile_view(request): # Authentication check. authentication_result = views.authentication_check(request) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view return render(request, 'healthnet/profile.html', template_data)
def update_view(request): # Authentication check. authentication_result = views.authentication_check(request, None, ['pk']) if authentication_result is not None: return authentication_result # Validation Check. Make sure an appointment exists for the given pk. pk = request.GET['pk'] try: appointment = Appointment.objects.get(pk=pk) except Exception: request.session['alert_danger'] = "The requested appointment does not exist." return HttpResponseRedirect('/error/denied/') # Get the template data from the session template_data = views.parse_session( request, { 'form_button': "Update Appointment", 'form_action': "?pk=" + pk, 'appointment': appointment } ) # Proceed with the rest of the view request.POST._mutable = True if request.user.account.role == Account.ACCOUNT_PATIENT: request.POST['patient'] = request.user.account.pk elif request.user.account.role == Account.ACCOUNT_DOCTOR: request.POST['doctor'] = request.user.account.pk if request.method == 'POST': form = AppointmentForm(request.POST) if form.is_valid(): form.assign(appointment) if Appointment.objects.filter( ~Q(pk=appointment.pk), Q(status="Active"), Q(doctor=appointment.doctor) | Q(patient=appointment.patient), Q(startTime__range=(appointment.startTime, appointment.endTime)) | Q(endTime__range=(appointment.startTime, appointment.endTime))).count(): form.mark_error('startTime', 'That time conflicts with another appointment.') form.mark_error('endTime', 'That time conflicts with another appointment.') else: appointment.save() logger.log(Action.ACTION_APPOINTMENT, 'Appointment updated', request.user.account) template_data['alert_success'] = "The appointment has been updated!" template_data['form'] = form if request.user.account.role == Account.ACCOUNT_PATIENT: message.send_appointment_update(request, appointment, appointment.doctor) elif request.user.account.role == Account.ACCOUNT_DOCTOR: message.send_appointment_update(request, appointment, appointment.patient) else: message.send_appointment_update(request, appointment, appointment.doctor) message.send_appointment_update(request, appointment, appointment.patient) else: form = AppointmentForm(appointment.get_populated_fields()) if request.user.account.role == Account.ACCOUNT_PATIENT: form.disable_field('patient') elif request.user.account.role == Account.ACCOUNT_DOCTOR: form.disable_field('doctor') template_data['form'] = form return render(request, 'healthnet/appointment/update.html', template_data)
def activity_view(request): # Authentication check. authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN]) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view # Parse search sorting template_data['query'] = Action.objects.all().order_by('-timePerformed') return render(request, 'healthnet/admin/activity.html', template_data)
def list_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_NURSE, Account.ACCOUNT_DOCTOR]) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view template_data['query'] = MedicalInfo.objects.filter( account__role=Account.ACCOUNT_PATIENT) return render(request, 'healthnet/medicalinfo/list.html', template_data)
def list_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_NURSE, Account.ACCOUNT_DOCTOR] ) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view template_data['query'] = MedicalInfo.objects.filter(account__role=Account.ACCOUNT_PATIENT) return render(request, 'healthnet/medicalinfo/list.html', template_data)
def create_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_PATIENT, Account.ACCOUNT_NURSE, Account.ACCOUNT_DOCTOR] ) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request, {'form_button': "Create"}) # Proceed with the rest of the view default = {} if request.user.account.role == Account.ACCOUNT_PATIENT: default['patient'] = request.user.account.pk if 'doctor' not in request.POST and request.user.account.profile.primaryCareDoctor is not None: default['doctor'] = request.user.account.profile.primaryCareDoctor.pk elif request.user.account.role == Account.ACCOUNT_DOCTOR: default['doctor'] = request.user.account.pk if 'hospital' not in request.POST and request.user.account.profile.prefHospital is not None: default['hospital'] = request.user.account.profile.prefHospital.pk request.POST._mutable = True request.POST.update(default) form = AppointmentForm(request.POST) if request.method == 'POST': if form.is_valid(): appointment = form.generate() if Appointment.objects.filter( Q(status="Active"), Q(doctor=appointment.doctor) | Q(patient=appointment.patient), Q(startTime__range=(appointment.startTime, appointment.endTime)) | Q(endTime__range=(appointment.startTime, appointment.endTime))).count(): form.mark_error('startTime', 'That time conflicts with another appointment.') form.mark_error('endTime', 'That time conflicts with another appointment.') else: appointment.save() logger.log(Action.ACTION_APPOINTMENT, 'Appointment created', request.user.account) form = AppointmentForm(default) # Clean the form when the page is redisplayed form._errors = {} request.session['alert_success'] = "Successfully created your appointment!" if request.user.account.role == Account.ACCOUNT_PATIENT: message.send_appointment_create(request, appointment, appointment.doctor) elif request.user.account.role == Account.ACCOUNT_DOCTOR: message.send_appointment_create(request, appointment, appointment.patient) else: message.send_appointment_create(request, appointment, appointment.doctor) message.send_appointment_create(request, appointment, appointment.patient) return HttpResponseRedirect('/appointment/list/') else: form._errors = {} if request.user.account.role == Account.ACCOUNT_PATIENT: form.disable_field('patient') elif request.user.account.role == Account.ACCOUNT_DOCTOR: form.disable_field('doctor') template_data['form'] = form return render(request, 'healthnet/appointment/create.html', template_data)
def hospital_list(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_ADMIN] ) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view template_data['query'] = Hospital.objects.all() return render(request, 'healthnet/admin/list_hospital.html', template_data)
def statistic_view(request): # Authentication check. authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN]) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request,{'form_button': "Get Statistics"}) # Proceed with the rest of the view default = {} request.POST._mutable = True request.POST.update(default) predate_filter = Action.objects.all() template_data['pre_filter'] = predate_filter.count() form = StatisticsForm(request.POST) if request.method == 'POST': if form.is_valid(): statistics = Statistics( startDate = form.cleaned_data['startDate'], endDate = form.cleaned_data['endDate'], ) date_filter = Action.objects.all().filter(timePerformed__range = (statistics.startDate, statistics.endDate)) template_data['temp'] = date_filter.count() template_data['start'] = statistics.startDate template_data['end'] = statistics.endDate template_data['total_logins'] = Action.objects.filter(description__icontains="Account login",timePerformed__range = (statistics.startDate, statistics.endDate) ).count() template_data['total_logouts'] = Action.objects.filter(description__icontains="Account logout",timePerformed__range = (statistics.startDate, statistics.endDate)).count() template_data['total_admitted'] = Action.objects.filter(description__icontains="Admitted Patient",timePerformed__range = (statistics.startDate, statistics.endDate)).count() template_data['total_discharged'] = Action.objects.filter(description__icontains="Discharged Patient",timePerformed__range = (statistics.startDate, statistics.endDate)).count() template_data['total_appointments'] = Action.objects.filter(description__icontains="Appointment created",timePerformed__range = (statistics.startDate, statistics.endDate)).count() template_data['total_med_tests'] = Action.objects.filter(description__icontains="Medical Test created",timePerformed__range = (statistics.startDate, statistics.endDate)).count() template_data['total_registered'] = Action.objects.filter(description__icontains="registered",timePerformed__range = (statistics.startDate, statistics.endDate)).count() else: form._errors = {} statistics = Statistics( startDate = 0, endDate = 0, ) errdate_filter = Action.objects.all() template_data['error_datefilter'] = errdate_filter.count() template_data['start'] = statistics.startDate template_data['end'] = statistics.endDate template_data['total_logins'] = 0 template_data['total_logouts'] = 0 template_data['total_admitted'] = 0 template_data['total_discharged'] = 0 template_data['total_appointments'] = 0 template_data['total_med_tests'] = 0 template_data['total_registered'] = 0 template_data['form'] = form return render(request, 'healthnet/admin/statistics.html', template_data)
def list_view(request): # Authentication check. authentication_result = views.authentication_check(request) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view # Parse search sorting message.parse_message_archive(request, template_data) template_data['messages'] = Message.objects.filter(Q(target=request.user.account) | Q(sender=request.user.account)) template_data['account'] = sanitize_js(request.user.account.profile.__str__()) return render(request, 'healthnet/message/list.html', template_data)
def detail_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_PATIENT]) if authentication_result is not None: return authentication_result # Validation Check. Make sure an appointment exists for the given pk. if 'pk' in request.GET: if request.user.account.role != Account.ACCOUNT_DOCTOR and request.user.account.role != Account.ACCOUNT_NURSE: request.session[ 'alert_danger'] = "You don't have permission to view that page." return HttpResponseRedirect('/error/denied/') pk = request.GET['pk'] try: medicalinfo = MedicalInfo.objects.get(pk=pk) except Exception: request.session[ 'alert_danger'] = "The requested medical info does not exist." return HttpResponseRedirect('/error/denied/') else: medicalinfo = MedicalInfo.objects.get(account=request.user.account) # Get the template data from the session template_data = views.parse_session(request, { 'form_button': "Update Medical Info", }) if 'pk' in request.GET: template_data['form_action'] = "?pk=" + pk # Proceed with the rest of the view request.POST._mutable = True request.POST['account'] = medicalinfo.account.pk if request.method == 'POST': form = MedicalInfoForm(request.POST) if form.is_valid(): form.assign(medicalinfo) medicalinfo.save() logger.log(Action.ACTION_MEDICALINFO, 'Medical info updated', request.user.account) template_data[ 'alert_success'] = "The medical info has been updated!" else: form = MedicalInfoForm(medicalinfo.get_populated_fields()) template_data['form'] = form form.disable_field('account') form.disable_field('bloodType') form.disable_field('allergy') form.disable_field('alzheimer') form.disable_field('asthma') form.disable_field('diabetes') form.disable_field('stroke') form.disable_field('other') form.disable_field('comments') return render(request, 'healthnet/medicalinfo/view.html', template_data)
def calendar_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_PATIENT, Account.ACCOUNT_NURSE, Account.ACCOUNT_DOCTOR] ) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view # Parse search sorting appointment.parse_appointment_cancel(request, template_data) # Parse appointment cancelling template_data['events'] = appointment.parse_appointments(request) # Build list of appointments return render(request, 'healthnet/appointment/appointment_calendar.html', template_data)
def calendar_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_PATIENT, Account.ACCOUNT_NURSE, Account.ACCOUNT_DOCTOR] ) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view # Parse search sorting appointment.parse_appointment_cancel(request, template_data) # Parse appointment cancelling template_data['events'] = appointment.parse_appointments(request) # Build list of appointments return render(request, 'healthnet/appointment/calendar.html', template_data)
def list_view(request): authentication_result = views.authentication_check( request, [Account.ACCOUNT_PATIENT]) if authentication_result is not None: return authentication_result template_data = views.parse_session(request, {'form_button': 'Pay'}) template_data['medtests'] = MedicalTest.objects.filter( patient=request.user, fees_paid=False) template_data['appointments'] = Appointment.objects.filter( patient=request.user, fees_paid=False) template_data['admissions'] = Admission.objects.filter( patient=request.user, fees_paid=False) return render(request, 'healthnet/medical_fees.html', template_data)
def users_view_doctor(request): # Authentication check. authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN]) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view if request.method == 'POST': pk = request.POST.get('pk') pk2 = request.POST.get('pk2') role = request.POST.get('role') account = Account.objects.get(pk=pk) del_ = request.POST.get('del') limit = request.POST.get('limits') #import pdb; pdb.set_trace() if account is not None: if del_: pro = Profile.objects.get(pk=pk2) pro.hide = True pro.save() template_data[ 'alert_danger'] = "Hidden " + account.user.username + "!!" elif limit: pro = Profile.objects.get(pk=pk2) pro.limit_users = limit pro.save() logger.log( Action.ACTION_ADMIN, 'Admin modified ' + account.user.username + "'s Patient limits", request.user.account) template_data[ 'alert_success'] = "Updated " + account.user.username + "'s Patient limits!" else: account.role = role account.save() logger.log( Action.ACTION_ADMIN, 'Admin modified ' + account.user.username + "'s role", request.user.account) template_data[ 'alert_success'] = "Updated " + account.user.username + "'s role!" # else: # pk = request.GET['pk'] # account = Account.objects.get(pk=pk) # account.delete() # Parse search sorting template_data['query'] = Account.objects.filter(role=30).filter( profile__hide=False) return render(request, 'healthnet/admin/users_doctor.html', template_data)
def list_view(request): # Authentication check. authentication_result = views.authentication_check(request) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view # Parse search sorting message.parse_message_archive(request, template_data) template_data['messages'] = Message.objects.filter( Q(target=request.user.account) | Q(sender=request.user.account)) template_data['account'] = sanitize_js( request.user.account.profile.__str__()) return render(request, 'healthnet/message/list.html', template_data)
def csv_export_view(request): # Authentication check. authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN]) if authentication_result is not None: return authentication_result template_data = views.parse_session(request, {'form_button': "Submit"}) if request.method == 'POST': if 'export' in request.POST: if request.POST['export'] == 'hospitals': return generate_hospital_csv() elif request.POST['export'] == 'users': return generate_user_csv() else: template_data['alert_danger'] = 'Please choose a file to download' else: template_data['alert_danger'] = 'Please choose a file to download' template_data['form'] = ExportForm() return render(request, 'healthnet/admin/export.html', template_data)
def display_view(request): # Authentication check. authentication_result = views.authentication_check( request, None, ['pk'] ) if authentication_result is not None: return authentication_result # Validation Check. Make sure a medical test exists for the given pk. pk = request.GET['pk'] try: medicaltest = MedicalTest.objects.get(pk=pk) except Exception: request.session['alert_danger'] = "The requested medical test does not exist" return HttpResponseRedirect('/error/denied/') # Get the template data from the session template_data = views.parse_session( request, { 'form_button': "Return to list of Medical Tests", 'form_action': "?pk=" + pk, 'medtest': medicaltest }) # Proceed with the rest of the view if request.method == 'GET': form = MedTestDisplayForm(medicaltest.get_populated_fields()) form.disable_field('name') form.disable_field('date') form.disable_field('hospital') form.disable_field('description') form.disable_field('doctor') form.disable_field('patient') form.disable_field('private') form.disable_field('completed') template_data['form'] = form template_data['img'] = medicaltest.image1 template_data['img2'] = medicaltest.image2 template_data['img3'] = medicaltest.image3 template_data['img4'] = medicaltest.image4 template_data['img5'] = medicaltest.image5 else: return HttpResponseRedirect('/medtest/list') return render(request, 'healthnet/medtest/display.html', template_data)
def patient_view(request): authentication_result = views.authentication_check( request, [Account.ACCOUNT_PATIENT]) if authentication_result is not None: return authentication_result default = {} template_data = views.parse_session(request) if request.user.account.role == Account.ACCOUNT_PATIENT: default['patient'] = request.user.account.pk else: request.session[ 'alert_danger'] = "The requested medical info does not exist." return HttpResponseRedirect('/error/denied/') request.POST._mutable = True request.POST.update(default) form = MedicalInfoForm(request.POST) form.disable_field('patient') template_data['form'] = form return render(request, 'healthnet/medicalinfo/patient.html', template_data)
def list_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_PATIENT, Account.ACCOUNT_NURSE, Account.ACCOUNT_DOCTOR] ) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view appointment.parse_appointment_cancel(request, template_data) # Parse appointment cancelling if request.user.account.role == Account.ACCOUNT_PATIENT: template_data['query'] = Appointment.objects.filter(patient=request.user.account) elif request.user.account.role == Account.ACCOUNT_DOCTOR: template_data['query'] = Appointment.objects.filter(doctor=request.user.account) else: template_data['query'] = Appointment.objects.all() return render(request, 'healthnet/appointment/list.html', template_data)
def list_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_DOCTOR, Account.ACCOUNT_NURSE, Account.ACCOUNT_PATIENT] ) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view # Parse search sorting if request.user.account.role == Account.ACCOUNT_DOCTOR: template_data['query'] = MedicalTest.objects.all() elif request.user.account.role == Account.ACCOUNT_NURSE: template_data['query'] = MedicalTest.objects.filter(hospital=request.user.account.profile.prefHospital) else: template_data['query'] = MedicalTest.objects.filter(patient=request.user, private=False) return render(request, 'healthnet/medtest/list.html', template_data)
def list_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_NURSE, Account.ACCOUNT_DOCTOR]) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view medicalinfoes = MedicalInfo.objects.all() # Page sorting. template_data['query'] = medicalinfoes.order_by('patient') if 'sort' in request.GET: if request.GET['sort'] == 'patient': template_data['query'] = medicalinfoes.order_by('patient') if request.GET['sort'] == 'bloodType': template_data['query'] = medicalinfoes.order_by('bloodType') if request.GET['sort'] == 'allergy': template_data['query'] = medicalinfoes.order_by('allergy') return render(request, 'healthnet/medicalinfo/list.html', template_data)
def users_view(request): # Authentication check. authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN]) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view if request.method == 'POST': pk = request.POST['pk'] role = request.POST['role'] account = Account.objects.get(pk=pk) if account is not None: account.role = role account.save() logger.log(Action.ACTION_ADMIN, 'Admin modified ' + account.user.username + "'s role", request.user.account) template_data['alert_success'] = "Updated " + account.user.username + "'s role!" # Parse search sorting template_data['query'] = Account.objects.all().order_by('-role') return render(request, 'healthnet/admin/users.html', template_data)
def create_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_DOCTOR]) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request, {'form_button': "Add Prescription"}) default = {} if request.user.account.role == Account.ACCOUNT_DOCTOR: default['doctor'] = request.user.account.pk if 'date' not in request.POST: default['date'] = datetime.now().strftime("%Y-%m-%d") request.POST._mutable = True request.POST.update(default) form = PrescriptionForm(request.POST) if request.method == 'POST': if form.is_valid(): pres = Prescription( patient=form.cleaned_data['patient'], doctor=form.cleaned_data['doctor'], date=form.cleaned_data['date'], medication=form.cleaned_data['medication'], strength=form.cleaned_data['strength'], instruction=form.cleaned_data['instruction'], refill=form.cleaned_data['refill'], ) pres.save() logger.log(Action.ACTION_PRESCRIPTION, 'Prescription Created', request.user.account) form = PrescriptionForm( default) # Clean the form when the page is redisplayed form._errors = {} request.session[ 'alert_success'] = "Successfully added the prescription." return HttpResponseRedirect('/prescription/list/') else: form._errors = {} if request.user.account.role == Account.ACCOUNT_DOCTOR: form.disable_field('doctor') form.date = datetime.today() template_data['form'] = form return render(request, 'healthnet/prescription/create.html', template_data)
def list_view(request): # Authentication check. authentication_result = views.authentication_check(request, [ Account.ACCOUNT_DOCTOR, Account.ACCOUNT_NURSE, Account.ACCOUNT_PATIENT ]) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view # Parse search sorting if request.user.account.role == Account.ACCOUNT_DOCTOR: template_data['query'] = MedicalTest.objects.all() elif request.user.account.role == Account.ACCOUNT_NURSE: template_data['query'] = MedicalTest.objects.filter( hospital=request.user.account.profile.prefHospital) else: template_data['query'] = MedicalTest.objects.filter( patient=request.user, private=False) return render(request, 'healthnet/medtest/list.html', template_data)
def csv_import_view(request): # Authentication check. authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN]) if authentication_result is not None: return authentication_result template_data = views.parse_session(request, {'form_button': "Submit"}) if request.method == 'POST': form = ImportForm(request.POST, request.FILES) if form.is_valid(): file = request.FILES['upload'] for line in file: first_word = re.split('[,]', line.decode("utf-8").strip())[0].lower() if first_word == 'firstname': count = handle_user_csv(file) m = str( count[0]) + ' users are successfully uploaded, ' + str( count[1]) + ' duplicate accounts.' if count[0] == 0: template_data['alert_danger'] = m else: template_data['alert_success'] = m elif first_word == 'name': count = handle_hospital_csv(file) m = str(count[0] ) + ' hospitals are successfully uploaded, ' + str( count[1]) + ' duplicate hospitals.' if count[0] == 0: template_data['alert_danger'] = m else: template_data['alert_success'] = m else: template_data['alert_danger'] = "Invalid CSV format." template_data['form'] = form return render(request, 'healthnet/admin/import.html', template_data) else: template_data['alert_danger'] = "File type not supported" else: template_data['alert_danger'] = "Please choose a file to upload" form = ImportForm() template_data['form'] = form return render(request, 'healthnet/admin/import.html', template_data)
def update_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_PATIENT, Account.ACCOUNT_DOCTOR, Account.ACCOUNT_NURSE] ) if authentication_result is not None: return authentication_result # Validation Check. Make sure an appointment exists for the given pk. if 'pk' in request.GET: if request.user.account.role != Account.ACCOUNT_DOCTOR and request.user.account.role != Account.ACCOUNT_NURSE: request.session['alert_danger'] = "You don't have permission to view that page." return HttpResponseRedirect('/error/denied/') pk = request.GET['pk'] try: medicalinfo = MedicalInfo.objects.get(pk=pk) except Exception: request.session['alert_danger'] = "The requested medical info does not exist." return HttpResponseRedirect('/error/denied/') else: medicalinfo = MedicalInfo.objects.get(account=request.user.account) # Get the template data from the session template_data = views.parse_session( request, { 'form_button': "Update Medical Info", }) if 'pk' in request.GET: template_data['form_action'] = "?pk=" + pk # Proceed with the rest of the view request.POST._mutable = True request.POST['account'] = medicalinfo.account.pk if request.method == 'POST': form = MedicalInfoForm(request.POST) if form.is_valid(): form.assign(medicalinfo) medicalinfo.save() logger.log(Action.ACTION_MEDICALINFO, 'Medical info updated', request.user.account) template_data['alert_success'] = "The medical info has been updated!" else: form = MedicalInfoForm(medicalinfo.get_populated_fields()) template_data['form'] = form form.disable_field('account') return render(request, 'healthnet/medicalinfo/update.html', template_data)
def hospital_update(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_ADMIN] ) if authentication_result is not None: return authentication_result # Validation Check. Make sure an appointment exists for the given pk. if 'pk' in request.GET: if request.user.account.role != Account.ACCOUNT_ADMIN: request.session['alert_danger'] = "You don't have permission to view that page." return HttpResponseRedirect('/error/denied/') pk = request.GET['pk'] try: hospital = Hospital.objects.get(pk=pk) except Exception: request.session['alert_danger'] = "The requested hospital does not exist." return HttpResponseRedirect('/error/denied/') else: hospital = Hospital.objects.all() # Get the template data from the session template_data = views.parse_session( request, { 'form_button': "Update Hospital Info", }) if 'pk' in request.GET: template_data['form_action'] = "?pk=" + pk # Proceed with the rest of the view request.POST._mutable = True request.POST['account'] = hospital.pk if request.method == 'POST': form = HospitalForm(request.POST) if form.is_valid(): form.assign(hospital) medicalinfo.save() logger.log(Action.ACTION_MEDICALINFO, 'Hospital info updated', request.user.account) template_data['alert_success'] = "The Hospital info has been updated!" else: form = HospitalForm(hospital.get_populated_fields()) template_data['form'] = form form.disable_field('name') return render(request, 'healthnet/admin/update_hospital.html', template_data)
def create_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_DOCTOR]) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request, {'form_button': "Upload"}) # Proceed with the rest of the view default = {} if request.user.account.role == Account.ACCOUNT_DOCTOR: default['doctor'] = request.user.account.pk request.POST._mutable = True request.POST.update(default) form = MedTestForm(request.POST) if request.method == 'POST': if form.is_valid(): medtest = MedicalTest( name=form.cleaned_data['name'], date=form.cleaned_data['date'], hospital=form.cleaned_data['hospital'], description=form.cleaned_data['description'], doctor=form.cleaned_data['doctor'].user, patient=form.cleaned_data['patient'].user, private=form.cleaned_data['private'], completed=form.cleaned_data['completed'], ) medtest.save() logger.log(Action.ACTION_MEDTEST, 'Medical Test created', request.user) form = MedTestForm( default) # Clean the form when the page is redisplayed form.disable_field('doctor') form._errors = {} template_data[ 'alert_success'] = "Successfully uploaded the medical test!" else: form._errors = {} form.disable_field('doctor') # if request.user.account.role == Account.ACCOUNT_DOCTOR: # form.disable_field('performedBy') template_data['form'] = form return render(request, 'healthnet/medtest/upload.html', template_data)
def display_view(request): # Authentication check. authentication_result = views.authentication_check(request, None, ['pk']) if authentication_result is not None: return authentication_result # Validation Check. Make sure a medical test exists for the given pk. pk = request.GET['pk'] try: medicaltest = MedicalTest.objects.get(pk=pk) except Exception: request.session[ 'alert_danger'] = "The requested medical test does not exist" return HttpResponseRedirect('/error/denied/') # Get the template data from the session template_data = views.parse_session( request, { 'form_button': "Return to list of Medical Tests", 'form_action': "?pk=" + pk, 'medtest': medicaltest }) # Proceed with the rest of the view if request.method == 'GET': form = MedTestDisplayForm(medicaltest.get_populated_fields()) form.disable_field('name') form.disable_field('date') form.disable_field('hospital') form.disable_field('description') form.disable_field('doctor') form.disable_field('patient') form.disable_field('private') form.disable_field('completed') template_data['form'] = form template_data['img'] = medicaltest.image1 template_data['img2'] = medicaltest.image2 template_data['img3'] = medicaltest.image3 template_data['img4'] = medicaltest.image4 template_data['img5'] = medicaltest.image5 else: return HttpResponseRedirect('/medtest/list') return render(request, 'healthnet/medtest/display.html', template_data)
def list_view_admin(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_ADMIN, Account.ACCOUNT_DOCTOR]) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) #import pdb; pdb.set_trace() #if request.method == 'get': try: pk = request.GET.get('own') owner = Account.objects.get(pk=pk) #import pdb; pdb.set_trace() request.session['owner'] = owner template_data['query'] = Score.objects.filter(owner=owner) return render(request, 'healthnet/medtest/list_score.html', template_data) except: pass return render(request, 'healthnet/medtest/list_score.html', template_data)
def activity_view(request): # Authentication check. authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN]) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session( request, {'query': Action.objects.all().order_by('-timePerformed')}) # Proceed with the rest of the view if 'sort' in request.GET: if request.GET['sort'] == 'description': template_data['query'] = Action.objects.all().order_by( 'description', '-timePerformed') if request.GET['sort'] == 'user': template_data['query'] = Action.objects.all().order_by( 'user__username', '-timePerformed') if request.GET['sort'] == 'type': template_data['query'] = Action.objects.all().order_by( 'type', 'description', '-timePerformed') return render(request, 'healthnet/admin/activity.html', template_data)
def create_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_DOCTOR] ) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request, {'form_button': "Add Prescription"}) default = {} if request.user.account.role == Account.ACCOUNT_DOCTOR: default['doctor'] = request.user.account.pk if 'date' not in request.POST: default['date'] = datetime.now().strftime("%Y-%m-%d") request.POST._mutable = True request.POST.update(default) form = PrescriptionForm(request.POST) if request.method == 'POST': if form.is_valid(): pres = Prescription( patient=form.cleaned_data['patient'], doctor=form.cleaned_data['doctor'], date=form.cleaned_data['date'], medication=form.cleaned_data['medication'], strength=form.cleaned_data['strength'], instruction=form.cleaned_data['instruction'], refill=form.cleaned_data['refill'], ) pres.save() logger.log(Action.ACTION_PRESCRIPTION, 'Prescription Created', request.user.account) form = PrescriptionForm(default) # Clean the form when the page is redisplayed form._errors = {} request.session['alert_success'] = "Successfully added the prescription." return HttpResponseRedirect('/prescription/list/') else: form._errors = {} if request.user.account.role == Account.ACCOUNT_DOCTOR: form.disable_field('doctor') form.date = datetime.today() template_data['form'] = form return render(request, 'healthnet/prescription/create.html', template_data)
def admit_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_NURSE, Account.ACCOUNT_DOCTOR] ) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session( request, {'form_button': "Admit"} ) # Proceed with the rest of the view default = {} # Prefill some of the form values if 'hospital' not in request.POST and request.user.account.profile.prefHospital is not None: default['hospital'] = request.user.account.profile.prefHospital.pk if 'timestamp' not in request.POST: default['timestamp'] = datetime.now().strftime("%Y-%m-%d %H:%M") request.POST._mutable = True request.POST.update(default) form = AdmitCreateForm(request.POST) # import pdb; pdb.set_trace() if request.method == 'POST' and request.user.account.profile.limit_users > 0: if form.is_valid(): admission = form.jugaad() admission.doctor = request.user.account admission.save() dec = Profile.objects.get(pk=request.user.account.profile.pk) dec.limit_users -= 1 dec.totat_patients += 1 dec.save() logger.log(Action.ACTION_ADMISSION, 'Admitted Patient', request.user.account) form = AdmissionForm(default) # Clean the form when the page is redisplayed form.clear_errors() request.session['alert_success'] = "Successfully admitted patient." # Use session when passing data through a redirect return HttpResponseRedirect('/admission/list/') else: form._errors = {} template_data['form'] = form return render(request, 'healthnet/admission/admit.html', template_data)
def profile_view(request): # Authentication check. authentication_result = views.authentication_check(request) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view if request.user.account.role != Account.ACCOUNT_ADMIN: appointment.parse_appointment_cancel(request, template_data) # Parse appointment cancelling template_data['events'] = appointment.parse_appointments(request) # Build list of appointments else: template_data['total_logins'] = Action.objects.filter(description__icontains="Account login").count() template_data['total_logouts'] = Action.objects.filter(description__icontains="Account logout").count() template_data['total_admitted'] = Action.objects.filter(description__icontains="Admitted Patient").count() template_data['total_discharged'] = Action.objects.filter(description__icontains="Discharged Patient").count() template_data['total_appointments'] = Action.objects.filter(description__icontains="Appointment created").count() template_data['total_med_tests'] = Action.objects.filter(description__icontains="Medical Test created").count() template_data['total_registered'] = Action.objects.filter(description__icontains="registered").count() message.parse_message_archive(request, template_data) template_data['messages'] = Message.objects.filter(target=request.user.account, target_deleted=False) return render(request, 'healthnet/profile.html', template_data)
def profile_view(request): # Authentication check. authentication_result = views.authentication_check(request) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view if request.user.account.role == Account.ACCOUNT_PATIENT: template_data['appointments'] = Appointment.objects.filter( patient=request.user) template_data['prescriptions'] = Prescription.objects.filter( patient=request.user) template_path = 'healthnet/dashboard_patient.html' else: template_data['inpatients'] = Admission.objects.filter( hospital=request.user.account.profile.prefHospital) template_data['appointments'] = Appointment.objects.filter( doctor=request.user) template_path = 'healthnet/dashboard_employee.html' return render(request, template_path, template_data)
def update_view(request): # Authentication check. authentication_result = views.authentication_check(request) if authentication_result is not None: return authentication_result # Get the template data from the asession template_data = views.parse_session(request, {'form_button': "Update profile"}) # Proceed with the rest of the view profile = request.user.account.profile if request.method == 'POST': form = ProfileForm(request.POST) if form.is_valid(): form.assign(profile) profile.save() logger.log(Action.ACTION_ACCOUNT, "Account updated info", request.user) template_data['alert_success'] = "Your profile has been updated!" else: form = ProfileForm(profile.get_populated_fields()) template_data['form'] = form return render(request, 'healthnet/profile/update.html', template_data)
def create_view(request): # Authentication check. authentication_result = views.authentication_check(request, [Account.ACCOUNT_PATIENT, Account.ACCOUNT_NURSE, Account.ACCOUNT_DOCTOR]) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request, {'form_button': "Create"}) # Proceed with the rest of the view default = {} if request.user.account.role == Account.ACCOUNT_PATIENT: default['patient'] = request.user.account.pk elif request.user.account.role == Account.ACCOUNT_DOCTOR: default['doctor'] = request.user.account.pk request.POST._mutable = True request.POST.update(default) form = AppointmentForm(request.POST) if request.method == 'POST': if form.is_valid(): appt = Appointment( doctor=form.cleaned_data['doctor'].user, patient=form.cleaned_data['patient'].user, description=form.cleaned_data['description'], hospital=form.cleaned_data['hospital'], startTime=form.cleaned_data['startTime'], endTime=form.cleaned_data['endTime'], date=form.cleaned_data['date'], ) appt.save() logger.log(Action.ACTION_APPOINTMENT, 'Appointment created', request.user) form = AppointmentForm(default) # Clean the form when the page is redisplayed form._errors = {} template_data['alert_success'] = "Successfully created your appointment!" else: form._errors = {} if request.user.account.role == Account.ACCOUNT_PATIENT: form.disable_field('patient') elif request.user.account.role == Account.ACCOUNT_DOCTOR: form.disable_field('doctor') template_data['form'] = form return render(request, 'healthnet/appointment/create.html', template_data)
def update_view(request): # Authentication check. authentication_result = views.authentication_check(request, None, ['pk']) if authentication_result is not None: return authentication_result # Validation Check. Make sure a medical test exists for the given pk. pk = request.GET['pk'] try: medicaltest = MedicalTest.objects.get(pk=pk) except Exception: request.session[ 'alert_danger'] = "The requested medical test does not exist" return HttpResponseRedirect('/error/denied/') # Get the template data from the session template_data = views.parse_session( request, { 'form_button': "Update Medical Test", 'form_action': "?pk=" + pk, 'medtest': medicaltest }) # Proceed with the rest of the view request.POST._mutable = True if request.user.account.role == Account.ACCOUNT_DOCTOR: request.POST['doctor'] = request.user.account.pk if request.method == 'POST': form = MedTestForm(request.POST) if form.is_valid(): form.assign(medicaltest) medicaltest.save() logger.log(Action.ACTION_MEDTEST, 'Medical Test updated', request.user.account) template_data[ 'alert_success'] = "The medical test has been updated!" template_data['form'] = form else: form = MedTestForm(medicaltest.get_populated_fields()) if request.user.account.role == Account.ACCOUNT_DOCTOR: form.disable_field('doctor') template_data['form'] = form return render(request, 'healthnet/medtest/update.html', template_data)
def update_view(request): # Authentication check. authentication_result = views.authentication_check(request, None, ['pk']) if authentication_result is not None: return authentication_result # Validation Check. Make sure a medical test exists for the given pk. pk = request.GET['pk'] try: medicaltest = MedicalTest.objects.get(pk=pk) except Exception: request.session['alert_danger'] = "The requested medical test does not exist" return HttpResponseRedirect('/error/denied/') # Get the template data from the session template_data = views.parse_session( request, { 'form_button': "Update Medical Test", 'form_action': "?pk=" + pk, 'medtest': medicaltest }) # Proceed with the rest of the view request.POST._mutable = True if request.user.account.role == Account.ACCOUNT_DOCTOR: request.POST['doctor'] = request.user.account.pk if request.method == 'POST': form = MedTestForm(request.POST) if form.is_valid(): form.assign(medicaltest) medicaltest.save() logger.log(Action.ACTION_MEDTEST, 'Medical Test updated', request.user.account) template_data['alert_success'] = "The medical test has been updated!" template_data['form'] = form else: form = MedTestForm(medicaltest.get_populated_fields()) if request.user.account.role == Account.ACCOUNT_DOCTOR: form.disable_field('doctor') template_data['form'] = form return render(request, 'healthnet/medtest/update.html', template_data)
def csv_import_view(request): # Authentication check. authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN]) if authentication_result is not None: return authentication_result template_data = views.parse_session(request, {'form_button': "Submit"}) if request.method == 'POST': form = ImportForm(request.POST, request.FILES) if form.is_valid(): file = request.FILES['upload'] for line in file: first_word = re.split('[,]', line.decode("utf-8").strip())[0].lower() if first_word == 'firstname': count = handle_user_csv(file) m = str(count[0])+' users are successfully uploaded, '+str(count[1])+' duplicate accounts.' if count[0] == 0: template_data['alert_danger'] = m else: template_data['alert_success'] = m elif first_word == 'name': count = handle_hospital_csv(file) m = str(count[0])+' hospitals are successfully uploaded, '+str(count[1])+' duplicate hospitals.' if count[0] == 0: template_data['alert_danger'] = m else: template_data['alert_success'] = m else: template_data['alert_danger'] = "Invalid CSV format." template_data['form'] = form return render(request, 'healthnet/admin/import.html', template_data) else: template_data['alert_danger'] = "File type not supported" else: template_data['alert_danger'] = "Please choose a file to upload" form = ImportForm() template_data['form'] = form return render(request, 'healthnet/admin/import.html', template_data)
def login_view(request): # Authentication check. Users currently logged in cannot view this page. if request.user.is_authenticated(): return HttpResponseRedirect('/profile/') elif Account.objects.all().count() == 0: return HttpResponseRedirect('/setup/') # Get the template data from the session template_data = views.parse_session(request, {'form_button': "Login"}) # Proceed with the rest of the view if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): user = authenticate( username=form.cleaned_data['email'].lower(), # Make sure it's lowercase password=form.cleaned_data['password'] ) login(request, user) logger.log(Action.ACTION_ACCOUNT, "Account login", request.user.account) request.session['alert_success'] = "Successfully logged into HealthNet." return HttpResponseRedirect('/profile/') else: form = LoginForm() template_data['form'] = form return render(request, 'healthnet/login.html', template_data)
def create_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_DOCTOR] ) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request, {'form_button': "Upload"}) # Proceed with the rest of the view default = {} if request.user.account.role == Account.ACCOUNT_DOCTOR: default['doctor'] = request.user.account.pk if 'hospital' not in request.POST and request.user.account.profile.prefHospital is not None: default['hospital'] = request.user.account.profile.prefHospital.pk if 'date' not in request.POST: default['date'] = datetime.now().strftime("%Y-%m-%d") request.POST._mutable = True request.POST.update(default) form = MedTestForm(request.POST, request.FILES) if request.method == 'POST': if form.is_valid(): medicaltest = form.generate() medicaltest.save() logger.log(Action.ACTION_MEDTEST, 'Medical Test created', request.user.account) form = MedTestForm(default) # Clean the form when the page is redisplayed form.disable_field('doctor') form._errors = {} template_data['alert_success'] = "Successfully uploaded the medical test!" else: form._errors = {} form.disable_field('doctor') # if request.user.account.role == Account.ACCOUNT_DOCTOR: # form.disable_field('performedBy') template_data['form'] = form return render(request, 'healthnet/medtest/upload.html', template_data)
def list_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_NURSE, Account.ACCOUNT_DOCTOR] ) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request) # Proceed with the rest of the view if request.method == 'POST': if 'discharge' in request.POST and 'pk' in request.POST: pk = request.POST['pk'] try: admission = Admission.objects.get(pk=pk) admission.active = False admission.discharged_timestamp = datetime.now() admission.save() logger.log(Action.ACTION_ADMISSION, 'Discharged Patient', request.user.account) template_data['alert_success'] = "The patient has been discharged." except Exception: template_data['alert_danger'] = "Unable to discharge the requested patient. Please try again later." template_data['query'] = Admission.objects.all() return render(request, 'healthnet/admission/list.html', template_data)
def password_view(request): # Authentication check. authentication_result = views.authentication_check(request) if authentication_result is not None: return authentication_result # Get the template data from the session template_data = views.parse_session(request, {'form_button': "Change password"}) # Proceed with the rest of the view if request.method == 'POST': form = PasswordForm(request.POST) if form.is_valid(): user = authenticate(username=request.user.username, password=form.cleaned_data['password_current']) if user is None: form.mark_error('password_current', 'Incorrect password') else: user = request.user user.set_password(form.cleaned_data['password_first']) user.save() logger.log(Action.ACTION_ACCOUNT, "Account password change", request.user.account) form = PasswordForm() # Clean the form when the page is redisplayed template_data['alert_success'] = "Your password has been changed!" else: form = PasswordForm() template_data['form'] = form return render(request, 'healthnet/profile/password.html', template_data)