def new_view(request): # Authentication check. #import pdb; pdb.set_trace() 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 Score"}) # Proceed with the rest of the view if request.method == 'POST': form = ScoreForm(request.POST) if form.is_valid(): score = form.generate() score.save() #logger.log(Action.ACTION_MESSAGE, 'Message sent', request.user.account) request.session['alert_success'] = "Successfully sent your score!" return HttpResponseRedirect('/score/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 = ScoreForm(default) form.clear_errors() template_data['form'] = form return render(request, 'healthnet/message/new_score.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 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 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 cancel_view(request): # Authentication check. authentication_result = views.authentication_check(request, [Account.ACCOUNT_PATIENT, Account.ACCOUNT_DOCTOR, Account.ACCOUNT_ADMIN], ['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: return HttpResponseRedirect('/error/denied/') # Get the template data from the session template_data = views.parse_session(request, {'appointment': appointment, 'form_action': "?pk=" + pk}) # Proceed with the rest of the view if request.method == 'POST': if 'yes' in request.POST: appointment.active = False appointment.save() logger.log(Action.ACTION_APPOINTMENT, 'Appointment cancelled', request.user) request.session[ 'alert_danger'] = "The appointment has been cancelled." # Use session when passing data through a redirect return HttpResponseRedirect('/appointment/list/') elif 'no' in request.POST: request.session[ 'alert_success'] = "The appointment was not cancelled." # Use session when passing data through a redirect return HttpResponseRedirect('/appointment/list/') return render(request, 'healthnet/appointment/cancel.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 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) template_data['messages'] = Score.objects.filter( owner=request.user.account) return render(request, 'healthnet/profile.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 if request.user.account.role == Account.ACCOUNT_PATIENT: appointments = Appointment.objects.filter(patient=request.user) elif request.user.account.role == Account.ACCOUNT_DOCTOR: appointments = Appointment.objects.filter(doctor=request.user) else: appointments = Appointment.objects.all() # Page sorting. template_data['query'] = appointments.order_by('date', 'startTime') if 'sort' in request.GET: if request.GET['sort'] == 'doctor': template_data['query'] = appointments.order_by('doctor__username', 'date', 'startTime') if request.GET['sort'] == 'patient': template_data['query'] = appointments.order_by('patient__username', 'date', 'startTime') if request.GET['sort'] == 'description': template_data['query'] = appointments.order_by('description', 'date', 'startTime') if request.GET['sort'] == 'hospital': template_data['query'] = appointments.order_by('hospital__name', 'date', 'startTime') if request.GET['sort'] == 'status': template_data['query'] = appointments.order_by('active', 'date', 'startTime') return render(request, 'healthnet/appointment/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)
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 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: medtest = MedicalTest.objects.get(pk=pk) except Exception: request.session[ 'alert_danger'] = "The requested medical test does not exist" return HttpResponseRedirect('/error/denied/') template_data = views.parse_session( request, { 'form_button': "Return to list of Medical Tests", 'form_action': "?pk=" + pk, 'medtest': medtest }) if request.method == 'GET': form = MedTestForm(medtest.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 else: return HttpResponseRedirect('/medtest/list') return render(request, 'healthnet/medtest/display.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.user.account.role == Account.ACCOUNT_DOCTOR: medtests = MedicalTest.objects.all() elif request.user.account.role == Account.ACCOUNT_NURSE: medtests = MedicalTest.objects.filter( hospital=request.user.account.profile.prefHospital) else: medtests = MedicalTest.objects.filter(patient=request.user, private=False) # Page sorting template_data['query'] = medtests.order_by('date') if 'sort' in request.GET: if request.GET['sort'] == 'doctor': template_data['query'] = medtests.order_by('doctor__username', 'date') if request.GET['sort'] == 'patient': template_data['query'] = medtests.order_by('patient__username', 'date') if request.GET['sort'] == 'description': template_data['query'] = medtests.order_by('description', 'date') if request.GET['sort'] == 'hospital': template_data['query'] = medtests.order_by('hospital__name', 'date') if request.GET['sort'] == 'name': template_data['query'] == medtests.order_by('name', 'date') 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 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 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 delete_view(request): # Authentication check. authentication_result = views.authentication_check( request, [Account.ACCOUNT_DOCTOR], ['pk']) if authentication_result is not None: return authentication_result # Validation Check. Make sure a prescription exists for the given pk. pk = request.GET['pk'] try: prescription = Prescription.objects.get(pk=pk) except ObjectDoesNotExist: return HttpResponseRedirect('/error/denied/') # Get the template data from the session template_data = views.parse_session(request, { 'prescription': prescription, 'form_action': "?pk=" + pk }) # Proceed with the rest of the view if request.method == 'POST': if 'yes' in request.POST: prescription.active = False prescription.save() logger.log(Action.ACTION_PRESCRIPTION, 'Prescription Cancelled', request.user) request.session[ 'alert_danger'] = "The prescription has been deleted." return HttpResponseRedirect('/prescription/list/') elif 'no' in request.POST: request.session[ 'alert_success'] = "The prescription was not deleted." return HttpResponseRedirect('/prescription/list/') return render(request, 'healthnet/prescription/delete.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 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, {'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/stats.html', template_data) #template_data = views.parse_session(request, {'query': Statistics.objects.all().order_by('freq')}) # Proceed with the rest of the view # if 'sort' in request.GET: # if request.GET['sort' == 'statistic': # template_data['query'] = Statistics.objects.all().order_by('statistics','freq')
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 list_view(request): # Authentication check. authentication_result = views.authentication_check(request, [ Account.ACCOUNT_PATIENT, Account.ACCOUNT_NURSE, Account.ACCOUNT_DOCTOR, 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 #appointment.parse_appointment_cancel(request, template_data) # Parse appointment cancelling if request.user.account.role == Account.ACCOUNT_PATIENT: template_data['query'] = Score.objects.filter( owner=request.user.account) elif request.user.account.role == Account.ACCOUNT_ADMIN: from django.db.models import Avg #import pdb; pdb.set_trace() template_data['query'] = Score.objects.all().values('owner').annotate( score=Avg('score')) template_data['query'] = [{ 'owner': Account.objects.get(pk=id['owner']), 'score': int(id['score']) } for id in template_data['query']] return render(request, 'healthnet/medtest/list_score_admin.html', template_data) else: template_data['query'] = Score.objects.all() return render(request, 'healthnet/medtest/list_score.html', template_data)
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 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 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 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 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 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 pay_view(request): authentication_result = views.authentication_check( request, [Account.ACCOUNT_PATIENT]) if authentication_result is not None: return authentication_result MedicalTest.objects.filter(patient=request.user, fees_paid=False).update(fees_paid=True) Appointment.objects.filter(patient=request.user, fees_paid=False).update(fees_paid=True) Admission.objects.filter(patient=request.user, fees_paid=False).update(fees_paid=True) return redirect('/profile')
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 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 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 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 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 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 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 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_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 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 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 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 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 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 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)
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 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 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)