374 lines
14 KiB
Python
374 lines
14 KiB
Python
"""
|
|
Django views for psychology app.
|
|
"""
|
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from django.urls import reverse_lazy
|
|
from django.views.generic import (
|
|
ListView, DetailView, CreateView, UpdateView, DeleteView
|
|
)
|
|
from django.contrib import messages
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from .models import (
|
|
PsychologyConsultation,
|
|
PsychologyAssessment,
|
|
PsychologySession,
|
|
PsychologyGoal,
|
|
PsychologyProgressReport,
|
|
)
|
|
from .forms import (
|
|
PsychologyConsultationForm,
|
|
PsychologyAssessmentForm,
|
|
PsychologySessionForm,
|
|
PsychologyGoalForm,
|
|
PsychologyProgressReportForm,
|
|
)
|
|
|
|
|
|
# ============================================================================
|
|
# Psychology Consultation Views
|
|
# ============================================================================
|
|
|
|
class PsychologyConsultationListView(LoginRequiredMixin, ListView):
|
|
"""List all psychology consultations."""
|
|
model = PsychologyConsultation
|
|
template_name = 'psychology/consultation_list.html'
|
|
context_object_name = 'consultations'
|
|
paginate_by = 20
|
|
|
|
def get_queryset(self):
|
|
queryset = super().get_queryset()
|
|
# Filter by patient if provided
|
|
patient_id = self.request.GET.get('patient')
|
|
if patient_id:
|
|
queryset = queryset.filter(patient_id=patient_id)
|
|
# Filter by provider if provided
|
|
provider_id = self.request.GET.get('provider')
|
|
if provider_id:
|
|
queryset = queryset.filter(provider_id=provider_id)
|
|
return queryset.select_related('patient', 'provider', 'tenant')
|
|
|
|
|
|
class PsychologyConsultationDetailView(LoginRequiredMixin, DetailView):
|
|
"""View details of a psychology consultation."""
|
|
model = PsychologyConsultation
|
|
template_name = 'psychology/consultation_detail.html'
|
|
context_object_name = 'consultation'
|
|
|
|
def get_queryset(self):
|
|
return super().get_queryset().select_related(
|
|
'patient', 'provider', 'tenant', 'appointment'
|
|
).prefetch_related('goals')
|
|
|
|
|
|
class PsychologyConsultationCreateView(LoginRequiredMixin, CreateView):
|
|
"""Create a new psychology consultation."""
|
|
model = PsychologyConsultation
|
|
form_class = PsychologyConsultationForm
|
|
template_name = 'psychology/consultation_form.html'
|
|
success_url = reverse_lazy('psychology:consultation_list')
|
|
|
|
def form_valid(self, form):
|
|
messages.success(self.request, _('Psychology consultation created successfully.'))
|
|
return super().form_valid(form)
|
|
|
|
|
|
class PsychologyConsultationUpdateView(LoginRequiredMixin, UpdateView):
|
|
"""Update an existing psychology consultation."""
|
|
model = PsychologyConsultation
|
|
form_class = PsychologyConsultationForm
|
|
template_name = 'psychology/consultation_form.html'
|
|
success_url = reverse_lazy('psychology:consultation_list')
|
|
|
|
def form_valid(self, form):
|
|
messages.success(self.request, _('Psychology consultation updated successfully.'))
|
|
return super().form_valid(form)
|
|
|
|
|
|
class PsychologyConsultationDeleteView(LoginRequiredMixin, DeleteView):
|
|
"""Delete a psychology consultation."""
|
|
model = PsychologyConsultation
|
|
template_name = 'psychology/consultation_confirm_delete.html'
|
|
success_url = reverse_lazy('psychology:consultation_list')
|
|
|
|
def delete(self, request, *args, **kwargs):
|
|
messages.success(self.request, _('Psychology consultation deleted successfully.'))
|
|
return super().delete(request, *args, **kwargs)
|
|
|
|
|
|
# ============================================================================
|
|
# Psychology Assessment Views
|
|
# ============================================================================
|
|
|
|
class PsychologyAssessmentListView(LoginRequiredMixin, ListView):
|
|
"""List all psychology assessments."""
|
|
model = PsychologyAssessment
|
|
template_name = 'psychology/assessment_list.html'
|
|
context_object_name = 'assessments'
|
|
paginate_by = 20
|
|
|
|
def get_queryset(self):
|
|
queryset = super().get_queryset()
|
|
# Filter by patient if provided
|
|
patient_id = self.request.GET.get('patient')
|
|
if patient_id:
|
|
queryset = queryset.filter(patient_id=patient_id)
|
|
# Filter by assessment type if provided
|
|
assessment_type = self.request.GET.get('type')
|
|
if assessment_type:
|
|
queryset = queryset.filter(assessment_type=assessment_type)
|
|
return queryset.select_related('patient', 'provider', 'tenant')
|
|
|
|
|
|
class PsychologyAssessmentDetailView(LoginRequiredMixin, DetailView):
|
|
"""View details of a psychology assessment."""
|
|
model = PsychologyAssessment
|
|
template_name = 'psychology/assessment_detail.html'
|
|
context_object_name = 'assessment'
|
|
|
|
def get_queryset(self):
|
|
return super().get_queryset().select_related(
|
|
'patient', 'provider', 'tenant', 'appointment'
|
|
)
|
|
|
|
|
|
class PsychologyAssessmentCreateView(LoginRequiredMixin, CreateView):
|
|
"""Create a new psychology assessment."""
|
|
model = PsychologyAssessment
|
|
form_class = PsychologyAssessmentForm
|
|
template_name = 'psychology/assessment_form.html'
|
|
success_url = reverse_lazy('psychology:assessment_list')
|
|
|
|
def form_valid(self, form):
|
|
messages.success(self.request, _('Psychology assessment created successfully.'))
|
|
return super().form_valid(form)
|
|
|
|
|
|
class PsychologyAssessmentUpdateView(LoginRequiredMixin, UpdateView):
|
|
"""Update an existing psychology assessment."""
|
|
model = PsychologyAssessment
|
|
form_class = PsychologyAssessmentForm
|
|
template_name = 'psychology/assessment_form.html'
|
|
success_url = reverse_lazy('psychology:assessment_list')
|
|
|
|
def form_valid(self, form):
|
|
messages.success(self.request, _('Psychology assessment updated successfully.'))
|
|
return super().form_valid(form)
|
|
|
|
|
|
class PsychologyAssessmentDeleteView(LoginRequiredMixin, DeleteView):
|
|
"""Delete a psychology assessment."""
|
|
model = PsychologyAssessment
|
|
template_name = 'psychology/assessment_confirm_delete.html'
|
|
success_url = reverse_lazy('psychology:assessment_list')
|
|
|
|
def delete(self, request, *args, **kwargs):
|
|
messages.success(self.request, _('Psychology assessment deleted successfully.'))
|
|
return super().delete(request, *args, **kwargs)
|
|
|
|
|
|
# ============================================================================
|
|
# Psychology Session Views
|
|
# ============================================================================
|
|
|
|
class PsychologySessionListView(LoginRequiredMixin, ListView):
|
|
"""List all psychology sessions."""
|
|
model = PsychologySession
|
|
template_name = 'psychology/session_list.html'
|
|
context_object_name = 'sessions'
|
|
paginate_by = 20
|
|
|
|
def get_queryset(self):
|
|
queryset = super().get_queryset()
|
|
# Filter by patient if provided
|
|
patient_id = self.request.GET.get('patient')
|
|
if patient_id:
|
|
queryset = queryset.filter(patient_id=patient_id)
|
|
# Filter by session type if provided
|
|
session_type = self.request.GET.get('type')
|
|
if session_type:
|
|
queryset = queryset.filter(session_type=session_type)
|
|
return queryset.select_related('patient', 'provider', 'tenant')
|
|
|
|
|
|
class PsychologySessionDetailView(LoginRequiredMixin, DetailView):
|
|
"""View details of a psychology session."""
|
|
model = PsychologySession
|
|
template_name = 'psychology/session_detail.html'
|
|
context_object_name = 'session'
|
|
|
|
def get_queryset(self):
|
|
return super().get_queryset().select_related(
|
|
'patient', 'provider', 'tenant', 'appointment'
|
|
)
|
|
|
|
|
|
class PsychologySessionCreateView(LoginRequiredMixin, CreateView):
|
|
"""Create a new psychology session."""
|
|
model = PsychologySession
|
|
form_class = PsychologySessionForm
|
|
template_name = 'psychology/session_form.html'
|
|
success_url = reverse_lazy('psychology:session_list')
|
|
|
|
def form_valid(self, form):
|
|
messages.success(self.request, _('Psychology session created successfully.'))
|
|
return super().form_valid(form)
|
|
|
|
|
|
class PsychologySessionUpdateView(LoginRequiredMixin, UpdateView):
|
|
"""Update an existing psychology session."""
|
|
model = PsychologySession
|
|
form_class = PsychologySessionForm
|
|
template_name = 'psychology/session_form.html'
|
|
success_url = reverse_lazy('psychology:session_list')
|
|
|
|
def form_valid(self, form):
|
|
messages.success(self.request, _('Psychology session updated successfully.'))
|
|
return super().form_valid(form)
|
|
|
|
|
|
class PsychologySessionDeleteView(LoginRequiredMixin, DeleteView):
|
|
"""Delete a psychology session."""
|
|
model = PsychologySession
|
|
template_name = 'psychology/session_confirm_delete.html'
|
|
success_url = reverse_lazy('psychology:session_list')
|
|
|
|
def delete(self, request, *args, **kwargs):
|
|
messages.success(self.request, _('Psychology session deleted successfully.'))
|
|
return super().delete(request, *args, **kwargs)
|
|
|
|
|
|
# ============================================================================
|
|
# Psychology Goal Views
|
|
# ============================================================================
|
|
|
|
class PsychologyGoalListView(LoginRequiredMixin, ListView):
|
|
"""List all psychology goals."""
|
|
model = PsychologyGoal
|
|
template_name = 'psychology/goal_list.html'
|
|
context_object_name = 'goals'
|
|
paginate_by = 20
|
|
|
|
def get_queryset(self):
|
|
queryset = super().get_queryset()
|
|
# Filter by patient if provided
|
|
patient_id = self.request.GET.get('patient')
|
|
if patient_id:
|
|
queryset = queryset.filter(patient_id=patient_id)
|
|
# Filter by status if provided
|
|
status = self.request.GET.get('status')
|
|
if status:
|
|
queryset = queryset.filter(status=status)
|
|
return queryset.select_related('patient', 'consultation')
|
|
|
|
|
|
class PsychologyGoalDetailView(LoginRequiredMixin, DetailView):
|
|
"""View details of a psychology goal."""
|
|
model = PsychologyGoal
|
|
template_name = 'psychology/goal_detail.html'
|
|
context_object_name = 'goal'
|
|
|
|
def get_queryset(self):
|
|
return super().get_queryset().select_related('patient', 'consultation')
|
|
|
|
|
|
class PsychologyGoalCreateView(LoginRequiredMixin, CreateView):
|
|
"""Create a new psychology goal."""
|
|
model = PsychologyGoal
|
|
form_class = PsychologyGoalForm
|
|
template_name = 'psychology/goal_form.html'
|
|
success_url = reverse_lazy('psychology:goal_list')
|
|
|
|
def form_valid(self, form):
|
|
messages.success(self.request, _('Psychology goal created successfully.'))
|
|
return super().form_valid(form)
|
|
|
|
|
|
class PsychologyGoalUpdateView(LoginRequiredMixin, UpdateView):
|
|
"""Update an existing psychology goal."""
|
|
model = PsychologyGoal
|
|
form_class = PsychologyGoalForm
|
|
template_name = 'psychology/goal_form.html'
|
|
success_url = reverse_lazy('psychology:goal_list')
|
|
|
|
def form_valid(self, form):
|
|
messages.success(self.request, _('Psychology goal updated successfully.'))
|
|
return super().form_valid(form)
|
|
|
|
|
|
class PsychologyGoalDeleteView(LoginRequiredMixin, DeleteView):
|
|
"""Delete a psychology goal."""
|
|
model = PsychologyGoal
|
|
template_name = 'psychology/goal_confirm_delete.html'
|
|
success_url = reverse_lazy('psychology:goal_list')
|
|
|
|
def delete(self, request, *args, **kwargs):
|
|
messages.success(self.request, _('Psychology goal deleted successfully.'))
|
|
return super().delete(request, *args, **kwargs)
|
|
|
|
|
|
# ============================================================================
|
|
# Psychology Progress Report Views
|
|
# ============================================================================
|
|
|
|
class PsychologyProgressReportListView(LoginRequiredMixin, ListView):
|
|
"""List all psychology progress reports."""
|
|
model = PsychologyProgressReport
|
|
template_name = 'psychology/progress_report_list.html'
|
|
context_object_name = 'reports'
|
|
paginate_by = 20
|
|
|
|
def get_queryset(self):
|
|
queryset = super().get_queryset()
|
|
# Filter by patient if provided
|
|
patient_id = self.request.GET.get('patient')
|
|
if patient_id:
|
|
queryset = queryset.filter(patient_id=patient_id)
|
|
return queryset.select_related('patient', 'provider', 'tenant')
|
|
|
|
|
|
class PsychologyProgressReportDetailView(LoginRequiredMixin, DetailView):
|
|
"""View details of a psychology progress report."""
|
|
model = PsychologyProgressReport
|
|
template_name = 'psychology/progress_report_detail.html'
|
|
context_object_name = 'report'
|
|
|
|
def get_queryset(self):
|
|
return super().get_queryset().select_related('patient', 'provider', 'tenant')
|
|
|
|
|
|
class PsychologyProgressReportCreateView(LoginRequiredMixin, CreateView):
|
|
"""Create a new psychology progress report."""
|
|
model = PsychologyProgressReport
|
|
form_class = PsychologyProgressReportForm
|
|
template_name = 'psychology/progress_report_form.html'
|
|
success_url = reverse_lazy('psychology:progress_report_list')
|
|
|
|
def form_valid(self, form):
|
|
messages.success(self.request, _('Psychology progress report created successfully.'))
|
|
return super().form_valid(form)
|
|
|
|
|
|
class PsychologyProgressReportUpdateView(LoginRequiredMixin, UpdateView):
|
|
"""Update an existing psychology progress report."""
|
|
model = PsychologyProgressReport
|
|
form_class = PsychologyProgressReportForm
|
|
template_name = 'psychology/progress_report_form.html'
|
|
success_url = reverse_lazy('psychology:progress_report_list')
|
|
|
|
def form_valid(self, form):
|
|
messages.success(self.request, _('Psychology progress report updated successfully.'))
|
|
return super().form_valid(form)
|
|
|
|
|
|
class PsychologyProgressReportDeleteView(LoginRequiredMixin, DeleteView):
|
|
"""Delete a psychology progress report."""
|
|
model = PsychologyProgressReport
|
|
template_name = 'psychology/progress_report_confirm_delete.html'
|
|
success_url = reverse_lazy('psychology:progress_report_list')
|
|
|
|
def delete(self, request, *args, **kwargs):
|
|
messages.success(self.request, _('Psychology progress report deleted successfully.'))
|
|
return super().delete(request, *args, **kwargs)
|