Beispiel #1
0
def AppointmentModify(request):

    if request.method == 'POST':
        # check if the session is a patient; change the form accordingly
        if 'is_patient' in request.session:
            should_render = False
            form = AppointmentFormPatient(request.POST)
            if form.is_valid():
                id = request.session['app_id']
                old_app = Appointment.objects.get(pk = id).delete()
                start_date=form.cleaned_data['start_date']
                start_time=form.cleaned_data['start_time']
                end_time=form.cleaned_data['end_time']
                doctor=form.cleaned_data['doctor']
                new_app = Appointment(pk = id, start_date = start_date, start_time = start_time, end_time = end_time, doctor = doctor, patient = request.user.patient)
                new_app.save()
                request.session.pop('app_id')
                # Log this activity.
                newLog = ActivityLog(user=request.user.username,time_logged=datetime.now(),message=request.user.username + ' has modified an appointment.')
                newLog.save()
                return HttpResponseRedirect('/profile/')
            else:
                return render_to_response('appointment_view.html', {'form': form, 'should_render': should_render}, context_instance=RequestContext(request))
        else:
            should_render = True

        form = AppointmentFormNurse(request.POST)
        if form.is_valid():
            id = request.session['app_id']
            old_app = Appointment.objects.get(pk = id).delete()
            start_date=form.cleaned_data['start_date']
            start_time=form.cleaned_data['start_time']
            end_time=form.cleaned_data['end_time']
            doctor=form.cleaned_data['doctor']
            patient=form.cleaned_data['patient']
            new_app = Appointment(pk = id, start_date = start_date, start_time = start_time, end_time = end_time, doctor = doctor, patient = patient)
            new_app.save()
            request.session.pop('app_id')
            # Log this activity.
            newLog = ActivityLog(user=request.user.username,time_logged=datetime.now(),message=request.user.username + ' has modified an appointment.')
            newLog.save()
            return HttpResponseRedirect('/profile/')
        else:
            return render_to_response('appointment_view.html', {'form': form, 'should_render': should_render}, context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect('/profile/')
Beispiel #2
0
def CreateAppointment(request):

    type = 'none'

    if request.method == 'POST':

        try:
            doctor = request.user.doctor
            form = AppointmentFormDoctor(request.POST)
            type = 'doctor'
            appointments = doctor.getAppointments()
        except ObjectDoesNotExist:
            try:
                patient = request.user.patient
                form = AppointmentFormPatient(request.POST)
                type = 'patient'
                appointments = patient.getAppointments()
            except ObjectDoesNotExist:
                nurse = request.user.nurse
                form = AppointmentFormNurse(request.POST)
                appointments = Appointment.objects.all()
                type = 'nurse'

        if form.is_valid():
            start_date = form.cleaned_data['start_date']
            start_time = form.cleaned_data['start_time']
            end_time = form.cleaned_data['end_time']

            if type == 'doctor':
                patient = form.cleaned_data['patient']
                new_app = Appointment(start_date = start_date, start_time = start_time, end_time = end_time, doctor = request.user.doctor, patient = patient)
                new_app.save()
            elif type == 'patient':
                doctor = form.cleaned_data['doctor']
                new_app = Appointment(start_date = start_date, start_time = start_time, end_time = end_time, doctor = doctor, patient = request.user.patient)
                new_app.save()
            elif type == 'nurse':
                doctor = form.cleaned_data['doctor']
                patient = form.cleaned_data['patient']
                new_app = Appointment(start_date = start_date, start_time = start_time, end_time = end_time, doctor = doctor, patient = patient)
                new_app.save()
            # Log this activity.
            newLog = ActivityLog(user=request.user.username,time_logged=datetime.now(),message=request.user.username + ' has made a new appointment.')
            newLog.save()
            return HttpResponseRedirect('/profile/')
        else:
            # Push the error messages to the current page
            return render_to_response('appointment.html', {'form': form, 'appointments': appointments}, context_instance=RequestContext(request))

    elif request.method == "DELETE":
        Appointment.objects.get(pk=request.DELETE['id']).delete()

    else:
        # get request; generate form based on user type
        try:
            doctor = request.user.doctor
            appointments = doctor.getAppointments()
            form = AppointmentFormDoctor()
            type = 'doctor'
        except ObjectDoesNotExist:
            try:
                patient = request.user.patient
                appointments = patient.getAppointments()
                form = AppointmentFormPatient()
                type = 'patient'
            except ObjectDoesNotExist:
                nurse = request.user.nurse
                form = AppointmentFormNurse()
                appointments = nurse.getAppointments()
                queryform = QueryForm()
                context = {'form': form, 'appointments': appointments, 'queryform': queryform}
                return render_to_response("appointment.html", context, context_instance=RequestContext(request))


        queryform = QueryForm()
        context = {'form': form, 'appointments': appointments, 'queryform': queryform}
        return render_to_response("appointment.html", context, context_instance=RequestContext(request))