Пример #1
0
def message_detail(request, message_id):
    """
    Displays information associated with the selected message:
    To, From, Date & Time sent, Subject, and the message itself.
    Can delete the message.
    :param request: user
    :param message_id: id of the current message
    :return: renders message_detail.html on success
    """
    message = Message.objects.get(pk=message_id)
    if request.method == "GET":
        return render(request, 'healthnet/messaging/message_detail.html',
                      {'message': message})

    elif request.method == "POST":
        message.delete()

        # Add entry into the log
        logEntry = Entry()

        logEntry.user = request.user.username
        logEntry.trigger = "messaging.views.message_detail"
        logEntry.activity = "Deleted Message"
        logEntry.save()
        return HttpResponseRedirect("/messages/inbox")
Пример #2
0
    def post(self, request):
        """
        Processes the form for updating a patient.
        :param request: The browser request
        :return: The response view; the form view if the inputs where invalid
        or the user profile index if they were valid.
        """
        user_id = request.user.id
        patient = Patient.objects.get(user=user_id)
        patient_update_form = self.update_form_class(request.POST, instance=patient)

        if patient_update_form.is_valid():
            # Save model instance to db
            #        patient_update_form.update()
            patient.save()

            logEntry = Entry()
            logEntry.user = request.user.username
            logEntry.trigger = "userprofile.views.UpdateProfileView"
            logEntry.activity = "Updated Patient"
            logEntry.save()

            return redirect('userprofile:index')

        return render(request, self.template_name, {'patient_update_form': patient_update_form})
Пример #3
0
    def post(self, request):
        form = MessageForm(request.POST)
        if form.is_valid():
            message = form.save(commit=False)
            if User.objects.filter(email=message.to).exists():
                message.From = request.user.first_name + ' ' + request.user.last_name + '<' + request.user.email + '>'
                message.date = timezone.now()
                message.time = timezone.now()
                message.save()

                # Add entry into the log
                logEntry = Entry()

                # determining who sent the message
                sender = User.objects.get(email=request.user.email)

                logEntry.user = sender.username
                logEntry.trigger = "messaging.views.ComposeMessage"
                logEntry.activity = "Sent Message"
                logEntry.save()

                return HttpResponseRedirect('/messages')

            else:
                errormsg = '- The email that you tried to message does not exist.'
                return render(request, self.template, {
                    'form': form,
                    'errormsg': errormsg
                })

        return render(request, self.template, {'form': form})
Пример #4
0
def admit_patient(request):
    """
        View to admit patient to a hospital from a list of patients not in hospitals
    """
    employee = UserFactory.get_user(request)

    hospital = Hospital.objects.get(name="Not in hospital")

    if (request.method == "GET"):

        patient_list = Patient.objects.filter(hospital=hospital)

        context = {
            'patient_list': patient_list
        }
        return render(request, 'healthnet/employee/admit_patient.html', context)
    elif (request.method == "POST"):
        patient_id = request.POST.get('patient', None)
        patient = Patient.objects.get(id=patient_id)
        patient.hospital = employee.hospital
        patient.save()
        logEntry = Entry()
        logEntry.user = request.user.username
        logEntry.trigger = "employee.views.patient_admit"
        logEntry.activity = str(patient.user.username) + " admitted to " + str(patient.hospital)
        logEntry.save()
        return HttpResponseRedirect('patient_list')
Пример #5
0
def transfer_patient(request):
    """
        View to transfer patient for other hospital to his/her list of patients
    """
    doctor = UserFactory.get_user(request)
    if(request.method == "GET"):

        patient_list = UserFactory.getOtherPatients(doctor)


        context = {
            'patient_list': patient_list
        }
        return render(request, 'healthnet/employee/transfer_patient.html', context)
    elif(request.method == "POST"):
        patient_id = request.POST.get('patient', None)
        patient = Patient.objects.get(id = patient_id)
        patient.hospital = doctor.hospital
        patient.doctor = doctor
        patient.save()
        logEntry = Entry()
        logEntry.user = request.user.username
        logEntry.trigger = "employee.views.patient_tranfer"
        logEntry.activity = str(patient.user.username) + " transfered to " + str(patient.hospital)
        logEntry.save()        
        return HttpResponseRedirect('patient_list')
Пример #6
0
    def post(self, request, appointment_id):

        """ Submitting the for will update the current appointment

        :param request: The user who is requesting the page
        :param appointment_id: The unique id of the Appointment to be updated
        :return: If there form is valid, redirect the user to the views page.
            If the form is not valid, re-render the page
        """

        if request.user.is_authenticated():
            appointment = Appointment.objects.get(id=appointment_id)
            appointment_update_form = self.update_form_class(request.POST, instance=appointment)
            if appointment_update_form.is_valid():
                appointment.save()

                logEntry = Entry()
                logEntry.user = request.user.username
                logEntry.trigger = "appointment.views.AppointmentEdit"
                logEntry.activity = "Updated Appointment"
                logEntry.save()

                return redirect('/employee/appointment/view')

            return render(request, self.template_name, {'appointment_update_form': appointment_update_form})
        return redirect('/userprofile/login')
Пример #7
0
def export(request):

    # Add entry to the log
    username = request.user.username

    logEntry = Entry()
    logEntry.user = username
    logEntry.trigger = "userprofile.views.export"
    logEntry.activity = "Exported Information"
    logEntry.save()

    userPrescriptions = Prescription.objects.filter(patient=request.user.patient)

    prescriptionsString = ""

    for p in userPrescriptions:
        prescriptionsString += str(p.medication) + "\n"
        prescriptionsString += "\t" + "Description: " + str(p.description) + "\n"
        prescriptionsString += "\t" + "Dosage:  " + str(p.dosage) + "\n"
        prescriptionsString += "\t" + "Quantity: " + str(p.quantity) + "\n"

    userTests = TestResult.objects.filter(patient_ID=request.user.patient)

    testsString = ""

    for t in userTests:
        if t.released == True:
            testsString += str(t.title) + "\n"
            testsString += "\t"+ str(t.description) + "\n"

    # Convert user's medical information into a text document

    fileContent = "Medical Information for: " + str(request.user.first_name) + " " + str(request.user.last_name) + "\n"\
                  "Request Time: " + str(timezone.localtime(timezone.now())) + "\n" \
                  "==================================================================\n" \
                  "MEDICAL INFORMATION\n" \
                  "Date of Birth:     " + str(request.user.patient.date_of_birth) + "\n" \
                  "Gender:            " + str(request.user.patient.gender) + "\n" \
                  "Height:            " + str(request.user.patient.height) + "\n" \
                  "Weight:            " + str(request.user.patient.weight) + "\n" \
                  "Phone Number:      " + str(request.user.patient.phone_number) + "\n" \
                  "Address:           " + str(request.user.patient.address) + "\n" \
                  "Emergency Contact: " + str(request.user.patient.emergency_contact) + "\n" \
                  "Emergency Number:  " + str(request.user.patient.emergency_number) + "\n" \
                  "Doctor:            " + str(request.user.patient.doctor.user.get_full_name()) + "\n" \
                  "Hospital:          " + str(request.user.patient.hospital.name) + "\n" \
                  "==================================================================\n" \
                  "PRESCRIPTIONS\n" \
                  "\n" + prescriptionsString +\
                  "==================================================================\n" \
                  "TESTS\n" \
                  "\n" + testsString
    res = HttpResponse(fileContent)
    res['Content-Disposition'] = 'attachment; filename=Medical_Information_'+str(request.user.username)+'.txt'
    return res
Пример #8
0
    def post(self, request):
        form = DoctorAppointmentForm(request.POST)
        if form.is_valid():
            appointment = form.save(commit=False)

            # make sure to check if time start is greater than time end.
            if appointment.valid_end_time() and appointment.valid_date():
                # Nurses can only view the patients from the hospital the nurse belongs to
                # Doctors can only view their own patients
                user = UserFactory.get_user(request)
                if(UserFactory.isDoctor(request.user)):
                    appointment.doctor_ID = request.user.id
                elif(UserFactory.isNurse(request.user)):
                    appointment.doctor_ID = Patient.objects.get(id=appointment.patient_ID).doctor.id

                # filter appointments that have the appointments doctor and are on the same date
                # if appointment to be created starts within duration of start time, do not create
                try:
                    existing_appointment_list = Appointment.objects.filter(doctor_ID=user.id).filter(
                        date=appointment.date)
                    for existing_appointment in existing_appointment_list:
                        if existing_appointment.time <= appointment.time <= existing_appointment.endTime:
                            errormsg = 'Time not available'
                            return render(request, self.template_name, {'form': form, 'errormsg': errormsg})

                except ObjectDoesNotExist:
                    pass  # no need to check
                else:
                    pass

                appointment.save()

                logEntry = Entry()
                logEntry.user = request.user.username
                logEntry.trigger = "appointment.views.create"
                logEntry.activity = "Created Appointment"
                logEntry.save()
                return HttpResponseRedirect('/employee/appointment/view')

            # need to return an error message saying why page is being re-rendered
            elif not appointment.valid_date():
                errormsg = '- Appointment must be scheduled at a future date.'
                return render(request, self.template_name, {'form': form, 'errormsg': errormsg})

            elif not appointment.valid_end_time():
                errormsg = '- Appointment end time must be after start time.'
                return render(request, self.template_name, {'form': form, 'errormsg': errormsg})

            # need to return an error message saying why page is being re-rendered
            else:
                errormsg = '- Doctor is busy at this time, please try a different time or date.'
                return render(request, self.template_name, {'form': form, 'errormsg': errormsg})

        return render(request, self.template_name, {'form': form})
Пример #9
0
    def post(self, request):
        form = MedicalRecordModelForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()

            logEntry = Entry()
            logEntry.user = request.user.username
            logEntry.trigger = "appointment.views.create"
            logEntry.activity = "Created Appointment"
            logEntry.save()
            return HttpResponseRedirect('/medrecord/view/uploads')

        return render(request, self.template_name, {'form': form})
Пример #10
0
def logLogin(request):
    """
    This intercepts the login
    records an entry into the log
    redirects the login default next page (8000/accounts/profile/) to 8000/userprofile
    :param request: the user logging in
    :return: redirect the 8000/userprofile
    """

    logEntry = Entry()
    logEntry.user = request.user.username
    logEntry.trigger = "home.views.logLogin"
    logEntry.activity = "Logged In"
    logEntry.save()

    if UserFactory.isPatient(UserFactory.get_user(request)):
        return redirect('/userprofile')
    else:
        return redirect('/employee')
Пример #11
0
def goodbye(request):
    """
    The goodbye page to display when a user logs out
    adds an entry into the log
    logs out request
    :param request: the user
    :return: confirmation goodbye page
    """

    logEntry = Entry()
    # logEntry.user = "******"
    logEntry.user = request.user.username
    logEntry.trigger = "home.views.goodbye"
    logEntry.activity = "Logged Out"
    logEntry.save()
    logout(request)

    return render(
        request,
        'healthnet/goodbye.html',
    )
Пример #12
0
def doctor_appointment_detail(request, appointment_id):
    """ View details of an appointment

    :param request: The user who is requesting the page
    :param appointment_id: The unique id of the appointment to query
    :return: If the request is valid, return a page that renders the Appointment Information.
        If the request is invalid, return an Web page displaying error text.
    """

    # See if the appointment exists
    try:
        appointment = Appointment.objects.get(pk=appointment_id)
    except Appointment.DoesNotExist:
        raise Http404("Appointment does not exist")

    # Obtain the user from the UserFactory class
    user = UserFactory.get_user(request)

    # Nurses and Doctors are able to view any patients appointment
    # Patients can only view their appointments

    if user != None and appointment.can_view(user):

        if request.method == "GET":
            return render(request, 'healthnet/employee/doctor_appointment_details.html', {'appointment': appointment})

        # If the user selects Delete page

        elif request.method == "POST":
            appointment.delete()
            logEntry = Entry()
            logEntry.user = request.user.username
            logEntry.trigger = "appointment.views.appointment_detail"
            logEntry.activity = "Deleted Appointment"
            logEntry.save()

            return HttpResponseRedirect("/employee/appointment/view")
    else:
        return HttpResponse("You tried accessing an appointment that is not yours")
Пример #13
0
    def post(self, request):
        """
        Processes the form for creating a user
        :param request: The browser request
        :return: The response view; the form view if the inputs where invalid
        or the user profile index if they were valid.
        """
        user_form = self.form_class(request.POST)
        patient_form = self.secondary_form_class(request.POST)
        patient_medical_form = self.third_form_class(request.POST)

        if user_form.is_valid() and patient_form.is_valid() and patient_medical_form.is_valid():

            user = user_form.save(commit=False)
            user.first_name.capitalize()
            user.last_name.capitalize()


            # Clean data so that it will enter db nicely
            username = user_form.cleaned_data['username']
            password = user_form.cleaned_data['password']

            # Change users input for formatting purposes
            user.email = user_form.cleaned_data['email']

            user.first_name = user_form.cleaned_data['first_name']
            user.last_name = user_form.cleaned_data['last_name']

            # Cannot set user's password to normal text, have to use set_password
            user.set_password(password)

            # Save model instance to db
            user.save()

            # Hook up user to patient
            patient = patient_form.save(commit=False)

            # connect medical form to patient
            medical = patient_medical_form.save(commit=False)
            patient.gender = medical.gender
            patient.height = medical.height
            patient.weight = medical.weight
            patient.emergency_contact = medical.emergency_contact
            patient.emergency_number = medical.emergency_number

            # intentionally neglect to save medical form

            patient.user = user
            patient.save()

            logEntry = Entry()
            logEntry.user = username
            logEntry.trigger = "userprofile.views.PatientUserFormView"
            logEntry.activity = "Created Account"
            logEntry.save()

            # Returns User object if credentials are correct (logs them in)
            patient.user = authenticate(username=username, password=password)

            if patient.user is not None:
                if patient.user.is_active:
                    login(request, patient.user)
                    return redirect('userprofile:index')

        return render(request, self.template_name, {'user_form': user_form,
                                                    'patient_form': patient_form,
                                                    'patient_medical_form': patient_medical_form})
Пример #14
0
def patient_options(request, patient_id):
    """ View employee's options for a single patient. Inherits the view class.
    """
    try:
        patient = Patient.objects.get(pk=patient_id)
        request.patient = patient
    except Patient.DoesNotExist:
        raise Http404("Patient does not exist")

    # Obtain the user from the UserFactory class
    user = UserFactory.get_user(request)

    # block null user
    if user == None:
        return HttpResponse("You aren't a real doctor or nurse, get outta here!!")

    doctor = UserFactory.get_user(request)
    possible_patients = UserFactory.getPatients(doctor)

    # Get the forms
    prescription_form = PrescriptionModelForm
    test_form = TestResultModelForm
    discharge_form = DischargeForm
    medical_form = DoctorMedicalForm
    patient_info = patient.getInfo()

    patient_name = patient.__str__()
    user_is_doctor = UserFactory.isDoctor(user)
    prescription_form.field_order = ['patient', 'medication', 'dosage', 'quantity', 'description']
    test_form.field_order = ['title', 'description', 'released']

    context = {
        'patient_info': patient_info,
        'user': user,
        'prescription_form': prescription_form,
        'test_form': test_form,
        'discharge_form': discharge_form,
        'patient_name': patient_name,
        'user_is_doctor': user_is_doctor,
        'patient': patient,
        'medical_form': medical_form
    }
    # Get request to render page.
    if request.method == "GET":
        return render(request, 'healthnet/employee/patient_options.html', context)
    # Form is submitted and processed.
    elif request.method == "POST":
        prescription_form = prescription_form(request.POST)
        discharge_form = discharge_form(request.POST)
        medical_form = medical_form(request.POST, instance= patient)
        test_form = test_form(request.POST)
        if prescription_form.is_valid():
            prescription = prescription_form.save(commit=False)
            prescription.patient = patient
            prescription.save()
            logEntry = Entry()
            logEntry.user = request.user.username
            logEntry.trigger = "employee.views.patient_options"
            logEntry.activity = "Created prescription for " + str(patient.user.username)
            logEntry.save()
            return render(request, 'healthnet/employee/patient_options.html', context)
        elif medical_form.is_valid():
            medical_form.save()
            patient = Patient.objects.get(pk=patient_id)
            patient_info = patient.getInfo()
            context = {
                'patient_info': patient_info,
                'user': user,
                'prescription_form': prescription_form,
                'test_form': test_form,
                'discharge_form': discharge_form,
                'patient_name': patient_name,
                'user_is_doctor': user_is_doctor,
                'patient': patient,
                'medical_form': medical_form
            }
            logEntry = Entry()
            logEntry.user = request.user.username
            logEntry.trigger = "employee.views.patient_options"
            logEntry.activity = "Updated " + str(patient.user.username) + "'s medical information"
            logEntry.save()
            return render(request, 'healthnet/employee/patient_options.html', context)
        elif discharge_form.is_valid():
            prev_hospital = patient.hospital
            patient.hospital = Hospital.objects.get(name = "Not in hospital")
            patient.save()
            logEntry = Entry()
            logEntry.user = request.user.username
            logEntry.trigger = "employee.views.patient_options"
            logEntry.activity = "Discharged " + str(patient.user.username) + " from " + str(prev_hospital)
            logEntry.save()
            return render(request, 'healthnet/employee/patient_options.html', context)
        elif test_form.is_valid():
            test = test_form.save(commit=False)
            test.patient_ID = patient
            test.save()
            logEntry = Entry()
            logEntry.user = request.user.username
            logEntry.trigger = "employee.views.patient_options"
            logEntry.activity = "Created test for " + str(patient.user.username)
            logEntry.save()
            return render(request, 'healthnet/employee/patient_options.html', context)
        else:
            # How to redirect to same url and pop up window
            context['errormsg'] = "Error in form, did not save."

            return render(request, 'healthnet/employee/patient_options.html', context)