Beispiel #1
0
def release_test(request, test_id):
    test = get_object_or_404(Test, pk=test_id)
    doctor = get_object_or_404(Doctor, user=request.user)
    if request.method == 'POST':
        form = ReleaseTestForm(request.POST)

        if form.is_valid():
            if test.patient.admitted_hospital != doctor.hospital:
                error = "Cannot release " + test.name + ". Patient is not in " + doctor.hospital.name + "."
                return render(request, 'error.html', {'error': error})

            obj = form.save(commit=False)
            test.result = obj.result
            test.comments = obj.comments
            test.save()
            Log.create_log(
                Log, request.user.username,
                " released test for " + test.patient.user.username + ".",
                timezone.now())
            return redirect('/medicalinfo/')

    else:
        form = ReleaseTestForm()

    return render(request, 'release_test.html', {'form': form})
Beispiel #2
0
    def save(self, commit=True):
        user = super(PatientCreationForm, self).save(commit=False)
        user.first_name = self.cleaned_data.get('first_name')
        user.last_name = self.cleaned_data.get('last_name')
        user.save()
        '''
        Log registration.
        '''
        Log.create_log(Log, user.username, " registered as a Patient.",
                       timezone.now())

        try:
            patient = Patient(
                user=user,
                dateOfBirth=self.cleaned_data.get('dateOfBirth'),
                height=self.cleaned_data.get('height'),
                weight=self.cleaned_data.get('weight'),
                insurer=self.cleaned_data.get('insurer'),
                address=self.cleaned_data.get('address'),
            )
        except:
            # patient creation failed. Delete the user so they can try again
            user.delete()

        if commit:
            patient.save()
        return patient
Beispiel #3
0
def admit_redirect(request, patient_id):
    patient = get_object_or_404(Patient, id=patient_id)
    try:
        nurse = Nurse.objects.get(user=request.user)
    except:
        nurse = None

    try:
        doctor = Doctor.objects.get(user=request.user)
    except:
        doctor = None

    if nurse != None:
        patient.admitted_hospital = nurse.hospital
        patient.save()
    else:
        patient.admitted_hospital = doctor.hospital
        patient.save()
    """ Activity Log Stuff """
    patUser = patient.user.username
    hospName = Hospital.__str__(patient.admitted_hospital)
    Log.create_log(Log, request.user.username,
                   " admitted " + patUser + " to " + hospName + ".",
                   timezone.now())
    """ Activity Log Stuff """
    return redirect('/admissions/')
Beispiel #4
0
def edit_d(request):
    instance = Doctor.objects.filter(user=request.user).first()
    form = UpdateDoctorForm(request.POST or None, instance=instance)
    if form.is_valid():
        form.save()
        Log.create_log(Log, request.user.username,
                       " has updated their profile.", timezone.now())
        return redirect('/profile')
    return render(request, 'edit.html', {'form': form})
Beispiel #5
0
def edit(request, appointment_id):
    instance = get_object_or_404(Appointment, id=appointment_id)
    form = UpdateAppointmentForm(request.POST or None, instance=instance)
    if form.is_valid():
        form.save()
        Log.create_log(Log, request.user.username,
                       " has updated one of their appointments.",
                       timezone.now())
        return redirect('/appointments')

    return render(request, 'edit.html', {'form': form})
Beispiel #6
0
def discharge_redirect(request, patient_id):
    patient = get_object_or_404(Patient, id=patient_id)
    """ Activity Log Stuff """
    patUser = patient.user.username
    hospName = Hospital.__str__(patient.admitted_hospital)
    Log.create_log(Log, request.user.username,
                   " discharged " + patUser + " from " + hospName + ".",
                   timezone.now())
    """ Activity Log Stuff """
    patient.admitted_hospital = None
    patient.save()
    return redirect('/admissions/')
Beispiel #7
0
def edit_patient(request):
    instance = Patient.objects.get(user=request.user)
    form = UpdatePatientForm(request.POST or None, instance=instance)
    if form.is_valid():
        form.save()
        Stat.patientStats()
        Log.create_log(Log, request.user.username,
                       " has updated their profile.", timezone.now())

        return redirect('/profile')

    return render(request, 'edit.html', {'form': form})
Beispiel #8
0
def transfer_patient(request, patient_id):
    if request.method == 'POST':
        doctor = Doctor.objects.get(user=request.user)
        patient = Patient.objects.get(pk=patient_id)
        patient.admitted_hospital = doctor.hospital
        patient.save()

        log_message = " transferred user " + patient.user.username + " to " + doctor.hospital.name + "."
        Log.create_log(Log, request.user.username, log_message, timezone.now())

        return redirect('/medicalinfo/')

    return render(request, 'transfer_patient.html')
Beispiel #9
0
def doctor_edit(request, appointment_id):
    instance = get_object_or_404(Appointment, id=appointment_id)
    form = UpdateAppointmentForm3(request.POST, instance=instance)
    if form.is_valid():

        obj = form.save(commit=False)
        obj.doctor = get_object_or_404(Doctor, user=request.user)
        obj.location = obj.doctor.hospital
        obj.save()
        Log.create_log(Log, request.user.username,
                       " has updated one of their appointments.",
                       timezone.now())
        return redirect('/appointments')

    return render(request, 'edit.html', {'form': form})
Beispiel #10
0
def patient_redirect(request, year, month, day, hour, minute, doc_id):
    app_time = datetime(year=int(year),
                        month=int(month),
                        day=int(day),
                        hour=int(hour),
                        minute=int(minute),
                        tzinfo=timezone.now().tzinfo)
    doctor = get_object_or_404(Doctor, id=doc_id)
    app = Appointment(time=app_time,
                      location=doctor.hospital,
                      doctor=doctor,
                      patient=get_object_or_404(Patient, user=request.user))
    app.save()

    Log.create_log(
        Log, request.user.username,
        " scheduled an appointment with " + doctor.user.username + ".",
        timezone.now())

    return redirect('/appointments/')
Beispiel #11
0
def add_test(request, patient_id):
    if request.method == 'POST':
        form = AddTestForm(request.POST)

        if form.is_valid():
            obj = form.save(commit=False)
            obj.patient = Patient.objects.get(pk=patient_id)
            obj.result = 'Pending'
            obj.comments = ''
            obj.save()
            Log.create_log(
                Log, request.user.username,
                " created test for " + obj.patient.user.username + ".",
                timezone.now())
            return redirect('/medicalinfo/patientinfo/' + patient_id)

    else:
        form = AddTestForm()

    return render(request, 'add_test.html', {'form': form})
Beispiel #12
0
def edit_medical(request, patient_id):
    if request.method == 'POST':
        form = MedicalInfoForm(request.POST)

        if form.is_valid():
            patient = Patient.objects.get(pk=patient_id)
            patient.height = form.cleaned_data['height']
            patient.weight = form.cleaned_data['weight']
            patient.save()

            log_message = " updated user " + patient.user.username + "'s medical information."
            Log.create_log(Log, request.user.username, log_message,
                           timezone.now())
            Stat.patientStats()

            return redirect('/medicalinfo/patientinfo/' + patient_id)

    else:
        form = MedicalInfoForm()

    return render(request, 'edit_medical.html', {'form': form})
Beispiel #13
0
def logout_view(request):
    Log.create_log(Log, request.user.username, " has logged out.",
                   timezone.now())
    logout(request)
    return redirect('/login')
Beispiel #14
0
 def delete(self, request, *args, **kwargs):
     Log.create_log(Log, request.user.username,
                    " has deleted one of their appointments.",
                    timezone.now())
     return super().delete(request, *args, **kwargs)
Beispiel #15
0
def logout_view(request):
    Log.create_log(Log, request.user.username, " has logged out.",
                   timezone.now())
    logout(request)
    return render(request, 'logout_view.html')