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, 'page/appointment/cancel.html', template_data)
def read_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: message = Message.objects.get(pk=pk) except Exception: request.session[ 'alert_danger'] = "The requested message does not exist." return HttpResponseRedirect('/error/denied/') # Get the template data from the session if request.user.account == message.target and not message.read: message.read = True message.save() logger.log(Action.ACTION_MESSAGE, 'Message read', request.user) template_data = views.parse_session( request, { 'to': message.target.profile, 'from': message.sender.profile, 'header': message.header, 'body': message.body }) # Proceed with the rest of the view return render(request, 'page/message/read.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, 'page/prescription/delete.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: medtest = 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': medtest}) # 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(medtest) medtest.save() logger.log(Action.ACTION_MEDTEST, 'Medical Test updated', request.user) template_data['alert_success'] = "The medical test has been updated!" template_data['form'] = form else: form = MedTestForm(medtest.get_populated_fields()) if request.user.account.role == Account.ACCOUNT_DOCTOR: form.disable_field('doctor') template_data['form'] = form return render(request, 'page/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) 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, 'page/profile/password.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, 'page/medtest/list.html', template_data)
def admit_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': "Admit"}) # Proceed with the rest of the view default = {} request.POST._mutable = True request.POST.update(default) form = AdmissionForm(request.POST) if request.method == 'POST': if form.is_valid(): admiss = Admission( patient=form.cleaned_data['patient'].user, reason=form.cleaned_data['reason'], hospital=form.cleaned_data['hospital'], time=form.cleaned_data['time'], date=form.cleaned_data['date'], ) admiss.save() logger.log(Action.ACTION_ADMISSION, 'Admitted Patient', request.user) form = AdmissionForm( default) # Clean the form when the page is redisplayed form._errors = {} template_data['alert_success'] = "Successfully admitted patient!" else: form._errors = {} template_data['form'] = form return render(request, 'page/admission/admit.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, 'page/medtest/display.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, 'page/appointment/list.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 messages = Message.objects.filter( Q(sender=request.user.account) | Q(target=request.user.account)) # Page sorting. template_data['query'] = messages.order_by('timestamp') if 'sort' in request.GET: if request.GET['sort'] == 'to': template_data['query'] = messages.order_by('target__profile', 'timestamp') if request.GET['sort'] == 'from': template_data['query'] = messages.order_by('sender__profile', 'timestamp') if request.GET['sort'] == 'subject': template_data['query'] = messages.order_by('header', 'timestamp') if request.GET['sort'] == 'time': template_data['query'] = messages.order_by('timestamp') if request.GET['sort'] == 'read': template_data['query'] = messages.order_by('read', 'timestamp') return render(request, 'page/message/list.html', template_data)
def discharge_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 an admission exists for the given pk. pk = request.GET['pk'] try: admission = Admission.objects.get(pk=pk) except Exception: return HttpResponseRedirect('/error/denied/') # Get the template data from the session template_data = views.parse_session(request, { 'admission': admission, 'form_action': "?pk=" + pk }) # Proceed with the rest of the view if request.method == 'POST': if 'yes' in request.POST: admission.active = False admission.save() logger.log(Action.ACTION_ADMISSION, 'Discharged Patient', request.user) request.session[ 'alert_danger'] = "The patient has been discharged." # Use session when passing data through a redirect return HttpResponseRedirect('/admission/list/') elif 'no' in request.POST: request.session[ 'alert_success'] = "The patient was not discharged." # Use session when passing data through a redirect return HttpResponseRedirect('/admission/list/') return render(request, 'page/admission/discharge.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, 'page/profile.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, 'page/medicalinfo/patient.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, 'page/medicalinfo/list.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': 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, 'page/profile/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 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'].user, doctor=form.cleaned_data['doctor'].user, 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) form = PrescriptionForm( default) # Clean the form when the page is redisplayed form._errors = {} template_data[ 'alert_success'] = "Successfully added your prescription!" 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, 'page/prescription/create.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, 'page/appointment/create.html', template_data)
def update_view(request): # Authentication check. authentication_result = views.authentication_check( request, [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. 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/') # Get the template data from the session template_data = views.parse_session( request, { 'form_button': "Update Medical Info", 'form_action': "?pk=" + pk, 'medicalinfo': medicalinfo }) # Proceed with the rest of the view request.POST._mutable = True request.POST['patient'] = medicalinfo.patient.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) template_data[ 'alert_success'] = "The medical info has been updated!" template_data['form'] = form else: form = MedicalInfoForm(medicalinfo.get_populated_fields()) form.disable_field('patient') template_data['form'] = form return render(request, 'page/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': "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, 'page/medtest/upload.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: prescriptions = Prescription.objects.filter(doctor=request.user) elif request.user.account.role == Account.ACCOUNT_PATIENT: prescriptions = Prescription.objects.filter(patient=request.user) else: prescriptions = Prescription.objects.all() template_data['query'] = prescriptions.order_by('date') if 'sort' in request.GET: if request.GET['sort'] == 'doctor': template_data['query'] = prescriptions.order_by( 'doctor__username', 'date') elif request.GET['sort'] == 'patient': template_data['query'] = prescriptions.order_by( 'patient__username', 'date') elif request.GET['sort'] == 'medi cation': template_data['query'] = prescriptions.order_by( 'medication', 'date') elif request.GET['sort'] == 'strength': template_data['query'] = prescriptions.order_by('strength', 'date') elif request.GET['sort'] == 'refill': template_data['query'] = prescriptions.order_by('refill', 'date') elif request.GET['sort'] == 'status': template_data['query'] = prescriptions.order_by( 'active', 'date', ) return render(request, 'page/prescription/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 admissions = Admission.objects.all() # Page sorting. template_data['query'] = admissions.order_by('date', 'time') if 'sort' in request.GET: if request.GET['sort'] == 'patient': template_data['query'] = admissions.order_by( 'patient__username', 'date', 'time') if request.GET['sort'] == 'reason': template_data['query'] = admissions.order_by( 'reason', 'date', 'time') if request.GET['sort'] == 'hospital': template_data['query'] = admissions.order_by( 'hospital__name', 'date', 'time') return render(request, 'page/admission/list.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"}) if request.method == 'POST': form = MessageForm(request.POST) if form.is_valid(): message = Message( target=form.cleaned_data['target'], sender=request.user.account, header=form.cleaned_data['header'], body=form.cleaned_data['body'], ) message.save() logger.log(Action.ACTION_MESSAGE, 'Message sent', request.user) form = MessageForm() # Clean the form when the page is redisplayed template_data['alert_success'] = "Successfully sent your message!" else: form = MessageForm() template_data['form'] = form return render(request, 'page/message/new.html', template_data)