240 lines
7.7 KiB
Python
240 lines
7.7 KiB
Python
"""
|
|
Forms for MDT (Multi-Disciplinary Team) app.
|
|
"""
|
|
|
|
from django import forms
|
|
from django.utils.translation import gettext_lazy as _
|
|
from crispy_forms.helper import FormHelper
|
|
from crispy_forms.layout import Layout, Fieldset, Row, Column, Submit, HTML
|
|
|
|
from .models import MDTNote, MDTContribution, MDTApproval, MDTAttachment
|
|
from core.models import User, Clinic
|
|
|
|
|
|
class MDTNoteForm(forms.ModelForm):
|
|
"""Form for creating/editing MDT notes."""
|
|
|
|
class Meta:
|
|
model = MDTNote
|
|
fields = ['patient', 'title', 'purpose', 'summary', 'recommendations']
|
|
widgets = {
|
|
'purpose': forms.Textarea(attrs={'rows': 4}),
|
|
'summary': forms.Textarea(attrs={'rows': 4}),
|
|
'recommendations': forms.Textarea(attrs={'rows': 4}),
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
self.user = kwargs.pop('user', None)
|
|
self.tenant = kwargs.pop('tenant', None)
|
|
super().__init__(*args, **kwargs)
|
|
|
|
# Filter patients by tenant
|
|
if self.tenant:
|
|
self.fields['patient'].queryset = self.fields['patient'].queryset.filter(
|
|
tenant=self.tenant
|
|
)
|
|
|
|
self.helper = FormHelper()
|
|
self.helper.form_method = 'post'
|
|
self.helper.layout = Layout(
|
|
Fieldset(
|
|
_('MDT Note Information'),
|
|
Row(
|
|
Column('patient', css_class='col-md-6'),
|
|
Column('title', css_class='col-md-6'),
|
|
),
|
|
'purpose',
|
|
),
|
|
Fieldset(
|
|
_('Summary & Recommendations'),
|
|
'summary',
|
|
'recommendations',
|
|
),
|
|
Submit('submit', _('Save MDT Note'), css_class='btn btn-primary')
|
|
)
|
|
|
|
|
|
class MDTContributionForm(forms.ModelForm):
|
|
"""Form for adding/editing MDT contributions."""
|
|
|
|
mention_users = forms.ModelMultipleChoiceField(
|
|
queryset=User.objects.none(),
|
|
required=False,
|
|
widget=forms.CheckboxSelectMultiple,
|
|
label=_("Mention Users"),
|
|
help_text=_("Tag other professionals to request their input")
|
|
)
|
|
|
|
class Meta:
|
|
model = MDTContribution
|
|
fields = ['clinic', 'content', 'is_final']
|
|
widgets = {
|
|
'content': forms.Textarea(attrs={'rows': 6}),
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
self.user = kwargs.pop('user', None)
|
|
self.tenant = kwargs.pop('tenant', None)
|
|
self.mdt_note = kwargs.pop('mdt_note', None)
|
|
super().__init__(*args, **kwargs)
|
|
|
|
# Filter clinics by tenant
|
|
if self.tenant:
|
|
self.fields['clinic'].queryset = Clinic.objects.filter(
|
|
tenant=self.tenant,
|
|
is_active=True
|
|
)
|
|
|
|
# Filter users by tenant for mentions
|
|
if self.tenant:
|
|
self.fields['mention_users'].queryset = User.objects.filter(
|
|
tenant=self.tenant,
|
|
is_active=True
|
|
).exclude(id=self.user.id if self.user else None)
|
|
|
|
# Set default clinic if user has one
|
|
if self.user and hasattr(self.user, 'provider_profile'):
|
|
provider = self.user.provider_profile
|
|
if provider.specialties.exists():
|
|
self.fields['clinic'].initial = provider.specialties.first()
|
|
|
|
self.helper = FormHelper()
|
|
self.helper.form_method = 'post'
|
|
self.helper.layout = Layout(
|
|
Fieldset(
|
|
_('Your Contribution'),
|
|
'clinic',
|
|
'content',
|
|
'is_final',
|
|
),
|
|
Fieldset(
|
|
_('Mention Colleagues'),
|
|
'mention_users',
|
|
css_class='collapse'
|
|
),
|
|
Submit('submit', _('Add Contribution'), css_class='btn btn-primary')
|
|
)
|
|
|
|
|
|
class MDTApprovalForm(forms.ModelForm):
|
|
"""Form for approving MDT notes."""
|
|
|
|
class Meta:
|
|
model = MDTApproval
|
|
fields = ['clinic', 'comments']
|
|
widgets = {
|
|
'comments': forms.Textarea(attrs={'rows': 3}),
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
self.user = kwargs.pop('user', None)
|
|
self.tenant = kwargs.pop('tenant', None)
|
|
super().__init__(*args, **kwargs)
|
|
|
|
# Filter clinics by tenant
|
|
if self.tenant:
|
|
self.fields['clinic'].queryset = Clinic.objects.filter(
|
|
tenant=self.tenant,
|
|
is_active=True
|
|
)
|
|
|
|
# Set default clinic if user has one
|
|
if self.user and hasattr(self.user, 'provider_profile'):
|
|
provider = self.user.provider_profile
|
|
if provider.specialties.exists():
|
|
self.fields['clinic'].initial = provider.specialties.first()
|
|
|
|
self.helper = FormHelper()
|
|
self.helper.form_method = 'post'
|
|
self.helper.layout = Layout(
|
|
Fieldset(
|
|
_('Approval Information'),
|
|
'clinic',
|
|
'comments',
|
|
),
|
|
Submit('submit', _('Approve MDT Note'), css_class='btn btn-success')
|
|
)
|
|
|
|
|
|
class MDTAttachmentForm(forms.ModelForm):
|
|
"""Form for uploading attachments to MDT notes."""
|
|
|
|
class Meta:
|
|
model = MDTAttachment
|
|
fields = ['file', 'file_type', 'description']
|
|
widgets = {
|
|
'description': forms.Textarea(attrs={'rows': 2}),
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
self.user = kwargs.pop('user', None)
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.helper = FormHelper()
|
|
self.helper.form_method = 'post'
|
|
self.helper.form_enctype = 'multipart/form-data'
|
|
self.helper.layout = Layout(
|
|
Fieldset(
|
|
_('Upload Attachment'),
|
|
'file',
|
|
Row(
|
|
Column('file_type', css_class='col-md-6'),
|
|
Column('description', css_class='col-md-6'),
|
|
),
|
|
),
|
|
Submit('submit', _('Upload'), css_class='btn btn-primary')
|
|
)
|
|
|
|
|
|
class MDTSearchForm(forms.Form):
|
|
"""Form for searching/filtering MDT notes."""
|
|
|
|
patient = forms.CharField(
|
|
required=False,
|
|
label=_("Patient MRN or Name"),
|
|
widget=forms.TextInput(attrs={'placeholder': _('Search by MRN or name...')})
|
|
)
|
|
status = forms.ChoiceField(
|
|
required=False,
|
|
choices=[('', _('All Statuses'))] + list(MDTNote.Status.choices),
|
|
label=_("Status")
|
|
)
|
|
contributor = forms.ModelChoiceField(
|
|
queryset=User.objects.none(),
|
|
required=False,
|
|
label=_("Contributor")
|
|
)
|
|
date_from = forms.DateField(
|
|
required=False,
|
|
label=_("From Date"),
|
|
widget=forms.DateInput(attrs={'type': 'date'})
|
|
)
|
|
date_to = forms.DateField(
|
|
required=False,
|
|
label=_("To Date"),
|
|
widget=forms.DateInput(attrs={'type': 'date'})
|
|
)
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
tenant = kwargs.pop('tenant', None)
|
|
super().__init__(*args, **kwargs)
|
|
|
|
if tenant:
|
|
self.fields['contributor'].queryset = User.objects.filter(
|
|
tenant=tenant,
|
|
is_active=True
|
|
)
|
|
|
|
self.helper = FormHelper()
|
|
self.helper.form_method = 'get'
|
|
self.helper.layout = Layout(
|
|
Row(
|
|
Column('patient', css_class='col-md-3'),
|
|
Column('status', css_class='col-md-2'),
|
|
Column('contributor', css_class='col-md-3'),
|
|
Column('date_from', css_class='col-md-2'),
|
|
Column('date_to', css_class='col-md-2'),
|
|
),
|
|
Submit('submit', _('Search'), css_class='btn btn-primary')
|
|
)
|