160 lines
4.8 KiB
Python
160 lines
4.8 KiB
Python
from django import forms
|
|
from django.utils.translation import gettext_lazy as _
|
|
from .models import DocumentTemplate, ClinicalNote, NoteAddendum
|
|
|
|
|
|
class DocumentTemplateForm(forms.ModelForm):
|
|
"""
|
|
Form for creating and editing document templates.
|
|
"""
|
|
class Meta:
|
|
model = DocumentTemplate
|
|
fields = ['name', 'category', 'description', 'content', 'is_active']
|
|
widgets = {
|
|
'name': forms.TextInput(attrs={
|
|
'class': 'form-control',
|
|
'placeholder': _('Enter template name')
|
|
}),
|
|
'category': forms.Select(attrs={
|
|
'class': 'form-select'
|
|
}),
|
|
'description': forms.Textarea(attrs={
|
|
'class': 'form-control',
|
|
'rows': 3,
|
|
'placeholder': _('Brief description of this template')
|
|
}),
|
|
'content': forms.Textarea(attrs={
|
|
'class': 'form-control',
|
|
'rows': 15,
|
|
'placeholder': _('Template content. Use {{variable_name}} for dynamic fields.')
|
|
}),
|
|
'is_active': forms.CheckboxInput(attrs={
|
|
'class': 'form-check-input'
|
|
}),
|
|
}
|
|
|
|
|
|
class ClinicalNoteForm(forms.ModelForm):
|
|
"""
|
|
Form for creating and editing clinical notes.
|
|
"""
|
|
class Meta:
|
|
model = ClinicalNote
|
|
fields = ['patient', 'template', 'title', 'content', 'status']
|
|
widgets = {
|
|
'patient': forms.Select(attrs={
|
|
'class': 'form-select select2',
|
|
'data-placeholder': _('Select patient')
|
|
}),
|
|
'template': forms.Select(attrs={
|
|
'class': 'form-select select2',
|
|
'data-placeholder': _('Select template (optional)')
|
|
}),
|
|
'title': forms.TextInput(attrs={
|
|
'class': 'form-control',
|
|
'placeholder': _('Enter note title')
|
|
}),
|
|
'content': forms.Textarea(attrs={
|
|
'class': 'form-control',
|
|
'rows': 20,
|
|
'placeholder': _('Enter note content')
|
|
}),
|
|
'status': forms.Select(attrs={
|
|
'class': 'form-select'
|
|
}),
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
self.user = kwargs.pop('user', None)
|
|
super().__init__(*args, **kwargs)
|
|
|
|
# Make template optional
|
|
self.fields['template'].required = False
|
|
|
|
# Filter active templates only
|
|
self.fields['template'].queryset = DocumentTemplate.objects.filter(is_active=True)
|
|
|
|
def save(self, commit=True):
|
|
instance = super().save(commit=False)
|
|
if self.user and not instance.author_id:
|
|
instance.author = self.user
|
|
if commit:
|
|
instance.save()
|
|
return instance
|
|
|
|
|
|
class NoteAddendumForm(forms.ModelForm):
|
|
"""
|
|
Form for adding addendums to clinical notes.
|
|
"""
|
|
class Meta:
|
|
model = NoteAddendum
|
|
fields = ['reason', 'content']
|
|
widgets = {
|
|
'reason': forms.TextInput(attrs={
|
|
'class': 'form-control',
|
|
'placeholder': _('Reason for addendum')
|
|
}),
|
|
'content': forms.Textarea(attrs={
|
|
'class': 'form-control',
|
|
'rows': 10,
|
|
'placeholder': _('Addendum content')
|
|
}),
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
self.user = kwargs.pop('user', None)
|
|
self.note = kwargs.pop('note', None)
|
|
super().__init__(*args, **kwargs)
|
|
|
|
def save(self, commit=True):
|
|
instance = super().save(commit=False)
|
|
if self.user:
|
|
instance.author = self.user
|
|
if self.note:
|
|
instance.note = self.note
|
|
if commit:
|
|
instance.save()
|
|
return instance
|
|
|
|
|
|
class NoteSearchForm(forms.Form):
|
|
"""
|
|
Form for searching clinical notes.
|
|
"""
|
|
patient = forms.CharField(
|
|
required=False,
|
|
widget=forms.TextInput(attrs={
|
|
'class': 'form-control',
|
|
'placeholder': _('Patient name or ID')
|
|
})
|
|
)
|
|
status = forms.ChoiceField(
|
|
required=False,
|
|
choices=[('', _('All Statuses'))] + ClinicalNote.STATUS_CHOICES,
|
|
widget=forms.Select(attrs={
|
|
'class': 'form-select'
|
|
})
|
|
)
|
|
date_from = forms.DateField(
|
|
required=False,
|
|
widget=forms.DateInput(attrs={
|
|
'class': 'form-control',
|
|
'type': 'date'
|
|
})
|
|
)
|
|
date_to = forms.DateField(
|
|
required=False,
|
|
widget=forms.DateInput(attrs={
|
|
'class': 'form-control',
|
|
'type': 'date'
|
|
})
|
|
)
|
|
author = forms.CharField(
|
|
required=False,
|
|
widget=forms.TextInput(attrs={
|
|
'class': 'form-control',
|
|
'placeholder': _('Author name')
|
|
})
|
|
)
|