Esempio n. 1
0
def view_medical_information(request, patient_id):
    """
    Displays the medical information for a requested patient
    Only nurses and doctors have this permission, as do patients
    to view their own information
    """
    patient = get_object_or_404(Patient, pk=patient_id)

    medical_information = list(Diagnosis.objects.filter(patient=patient).filter(treatment_session=None))
    medical_information.extend(TreatmentSession.objects.filter(patient=patient))

    medical_information.sort(
        reverse=True,
        key=lambda item: item.creation_timestamp if isinstance(item, Diagnosis) else item.admission_timestamp
    )

    can_transfer = False
    if patient.get_current_treatment_session() is not None:
        if request.user.has_perm("hospital.transfer_patient_receiving_hospital"):
            can_transfer = get_account_from_user(request.user).hospital != \
                           patient.get_current_treatment_session().treating_hospital

    return render(request, 'medical/patient/medical_information.html', {
        'medical_information': medical_information, 'patient': patient,
        'user_has_edit_permission': request.user.has_perm('medical.change_diagnosis'),
        'user_has_add_permission': request.user.has_perm('medical.add_diagnosis'),
        'can_discharge': request.user.has_perm('hospital.discharge_patient'),
        'can_transfer': can_transfer,
    })
Esempio n. 2
0
def statisticsView(request):
    account = get_account_from_user(request.user)
    if account is None:
        stats_list = [Statistics(h) for h in Hospital.objects.all()]
    else:
        stats_list = [Statistics(account.hospital)]

    return render(request, 'hospital/viewstatistics.html', {"stats_list": stats_list})
Esempio n. 3
0
def admit_patient(request, patient_id):
    patient = get_object_or_404(Patient, pk=patient_id)
    if request.method == 'POST':
        if patient.get_current_treatment_session() is None:
            hospital = get_account_from_user(request.user).hospital
            TreatmentSession.objects.create(patient=patient, treating_hospital=hospital)
            CreateLogEntry(request.user.username, "Patient admitted.")

    return redirect('medical:view_medical_information', patient_id=patient_id)
Esempio n. 4
0
def transfer_patient_as_doctor(request, patient_id):
    patient = get_object_or_404(Patient, pk=patient_id)
    session = patient.get_current_treatment_session()

    if session is None:
        return redirect('medical:view_medical_information', patient_id=patient_id)

    if session.treating_hospital is get_account_from_user(request.user).hospital:
        return render(request, 'transfer/cant_transfer.html')

    if request.method == 'POST':
        session.discharge_timestamp = datetime.now()
        session.save()
        hospital = get_account_from_user(request.user).hospital
        new_session = TreatmentSession.objects.create(patient=patient, treating_hospital=hospital)
        new_session.previous_session = session
        new_session.save()
        CreateLogEntry(request.user.username, "Patient transferred.")
        return render(request, 'transfer/transfer_done.html', {'patient_id': patient_id})

    return render(request, 'transfer/doctor_transfer.html')
Esempio n. 5
0
def view_patients(request):
    """
    Nurses and Doctors are able to view the patients in their hospital
    """
    account = get_account_from_user(request.user)
    hospital = account.hospital

    patients = Patient.objects.all()
    if request.user.profile_information.account_type == Nurse.ACCOUNT_TYPE:
        patients = [p for p in patients if p.get_admitted_hospital() == hospital or p.preferred_hospital == hospital]

    context = {'patient_list': patients, 'hospital': hospital}

    return render(request, 'patient/view_patients.html', context)
Esempio n. 6
0
def export_information(request):
    """
    Patients are able to export their personal medical information
    such as the prescriptions they have and any relevant
    diagnoses. Also they can export test results
    :param request: the requesting user (Patient)
    :return: none
    """
    patient = get_account_from_user(request.user)
    prescriptions = Prescription.objects.all()
    tests = Test.objects.all()

    file_path = os.path.join(settings.MEDIA_ROOT, 'media/medical_information/%s.txt' % request.user.username)
    """Write all the information to the file to be served"""
    with open(file_path, 'w') as info_file:
        info_file.write("Medical Information for " + patient.user.first_name + " " + patient.user.last_name +
                        "\n\nPrescriptions:\n\n")
        if not prescriptions:
            info_file.write("You have no prescriptions.")
        else:
            for prescription in prescriptions:
                if prescription.diagnosis.patient == patient:
                    info_file.write(
                        "Diagnosis: " + prescription.diagnosis.summary + "\nDrug: " + prescription.drug.name + "\n" +
                        "Prescribing Doctor: Dr. " + prescription.doctor.user.first_name + " "
                        + prescription.doctor.user.last_name + "\n" + "Amount: " + prescription.quantity_info() +
                        "\nDirections: " + prescription.instruction + "\n\n")
        info_file.write("\n\nTest Results:\n\n")
        if not tests:
            info_file.write("You have no test results.")
        else:
            for test in tests:
                if test.diagnosis.patient == patient and test.released:
                    info_file.write(
                        "Test Released by Doctor: Dr. " + test.doctor.user.first_name + test.doctor.user.last_name +
                        "\n" + "Description: " + test.description + "\n" + "Results: " + test.results + "\n\n")

        info_file.close()

    if os.path.exists(file_path):
        with open(file_path, 'rb') as fh:
            response = HttpResponse(fh.read(), content_type="application/text;charset=UTF-8")
            response['Content-Disposition'] = 'inline; filename=medical_information.txt'
            CreateLogEntry(request.user.username, "Patient exported medical information.")
            return response
    else:
        raise Http404
Esempio n. 7
0
def view_patients_admin(request):
    """
    Administrators are able to transfer patients to other hospitals
    so they must also be able to see patients for any hospital
    """
    admin = get_account_from_user(request.user)
    hospital = admin.hospital
    list_patients = []
    patients = Patient.objects.all()
    for patient in patients:
        session = patient.get_current_treatment_session()
        if session:
            if session.treating_hospital == hospital:
                list_patients.append(patient)

    context = {'patient_list': list_patients, 'hospital': hospital}

    return render(request, 'patient/view_patients_admin.html', context)
Esempio n. 8
0
    def get_for_user_in_week_starting_at_date(cls, user, starting_date):
        """
        Get the list of appointments this user have in the week starting at the given date.
        :param user: A user object.
        :param starting_date: A datetime.date object representing the first day of the week.
        :return: The list of appointments this user have in the week;
                 Or, an empty list if the user doesn't have any appointment;
                 Or, None if the user is a type of account that's not supposed to have any appointment.
        """

        account = get_account_from_user(user)
        try:
            return account.appointment_set.exclude(cancelled=True).filter(
                date__gte=starting_date).filter(date__lt=starting_date +
                                                timedelta(days=7)).order_by(
                                                    'date', 'start_time')
        except AttributeError:
            return None
Esempio n. 9
0
def nurse(request):
    nurse_name = get_account_from_user(request.user)
    return render(request, 'index/nurse.html', {'nurse': nurse_name})
Esempio n. 10
0
def doctor(request):
    doctor_name = get_account_from_user(request.user)
    return render(request, 'index/doctor.html', {'doctor': doctor_name})
Esempio n. 11
0
def patient(request):
    patient = get_account_from_user(request.user)
    context = {'patient': patient}
    return render(request, 'index/patient.html', context)
Esempio n. 12
0
def medical_view_options(request):
    """Second screen of options that a patient can view"""
    patient = get_account_from_user(request.user)
    context = {'patient': patient}
    return render(request, 'medical/patient/medical_view_options.html', context)