Exemple #1
0
def AppointmentQuery(request):
    if request.method == 'POST':
        form = QueryForm(request.POST)
        if form.is_valid():
            id = form.cleaned_data['id']
            request.session['app_id'] = id
            app = Appointment.objects.get(id = id)
            modifyForm = AppointmentFormNurse(instance=app)
            # Determine whether to render the patient field for the modify form!
            if 'is_patient' in request.session:
                should_render = False
            else:
                should_render = True
            context = {'form': modifyForm, 'should_render': should_render}
            return render_to_response("appointment_view.html", context, context_instance=RequestContext(request))
        else:
            return render_to_response('appointment.html', {'form': form}, context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect("/profile/")
Exemple #2
0
def DeleteUser(request):

    if request.method == 'POST':
        deleteform = QueryForm(request.POST)
        if deleteform.is_valid():
            id = deleteform.cleaned_data['id']
            if request.session['type'] == 'doctor':
                doc = Doctor.objects.get(pk = id)
                doc.user.is_active = False
                # clear all relations to patients
                doc.patient_set.clear()
                # remove all related prescriptions and appointments
                Appointment.objects.filter(doctor = doc).delete()
                Prescription.objects.filter(doctor = doc).delete()
                doc.user.save()
            elif request.session['type'] == 'patient':
                pat = Patient.objects.get(pk = id)
                pat.user.is_active = False
                # clear this patient from the doctor's list
                pat.doctor.patient_set.remove(pat)
                # remove all related prescriptions and appointments
                Appointment.objects.filter(patient = pat).delete()
                Prescription.objects.filter(patient = pat).delete()
                pat.user.save()
            elif request.session['type'] == 'nurse':
                nur = Nurse.objects.get(pk = id)
                nur.user.is_active = False
                nur.user.save()
            elif request.session['type'] == 'administrator':
                adm = Administrator.objects.get(pk = id)
                adm.user.is_active = False
                adm.user.save()

            del request.session['type']
            return HttpResponseRedirect('/profile/')

        else:
            return HttpResponseRedirect('/profile/')

    else:
        return HttpResponseRedirect('/profile/')
Exemple #3
0
def DeletePrescription(request):

    if request.method == 'POST':

        form = QueryForm(request.POST)

        if form.is_valid():
            id = form.cleaned_data['id']
            try:
                # grab the patient's name then delete the prescriptions
                prescription = Prescription.objects.get(pk=id)
                patient = prescription.patient
                prescription.delete()
                newLog = ActivityLog(user=request.user.username,time_logged=datetime.now(),message=request.user.username + ' has deleted a prescription for ' + patient.first_name)
                newLog.save()
            except Exception:
                pass
           
            return HttpResponseRedirect('/profile/')
        else:
            return HttpResponseRedirect('/profile/')
    else:
        return HttpResponseRedirect('/')