Fix syntax errors in forms.py files
This commit is contained in:
parent
da0ca4ee19
commit
3b9468748c
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
RCA (Root Cause Analysis) forms
|
RCA (Root Cause Analysis) forms
|
||||||
"""
|
"""
|
||||||
RCA (Root Cause Analysis) forms
|
|
||||||
"""
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from apps.core.models import PriorityChoices
|
from apps.core.models import PriorityChoices
|
||||||
@ -26,59 +25,46 @@ class RootCauseAnalysisForm(HospitalFieldMixin, forms.ModelForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = RootCauseAnalysis
|
model = RootCauseAnalysis
|
||||||
fields = [
|
fields = [
|
||||||
'title',
|
"title",
|
||||||
'description',
|
"description",
|
||||||
'background',
|
"background",
|
||||||
'hospital',
|
"hospital",
|
||||||
'department',
|
"department",
|
||||||
'status',
|
"status",
|
||||||
'severity',
|
"severity",
|
||||||
'priority',
|
"priority",
|
||||||
'assigned_to',
|
"assigned_to",
|
||||||
'target_completion_date',
|
"target_completion_date",
|
||||||
'root_cause_summary',
|
"root_cause_summary",
|
||||||
]
|
]
|
||||||
widgets = {
|
widgets = {
|
||||||
'title': forms.TextInput(attrs={
|
"title": forms.TextInput(attrs={"class": "form-control", "placeholder": "Enter RCA title"}),
|
||||||
'class': 'form-control',
|
"description": forms.Textarea(
|
||||||
'placeholder': 'Enter RCA title'
|
attrs={"class": "form-control", "rows": 4, "placeholder": "Describe the incident or issue"}
|
||||||
}),
|
),
|
||||||
'description': forms.Textarea(attrs={
|
"background": forms.Textarea(
|
||||||
'class': 'form-control',
|
attrs={"class": "form-control", "rows": 3, "placeholder": "Provide background information and context"}
|
||||||
'rows': 4,
|
),
|
||||||
'placeholder': 'Describe the incident or issue'
|
"hospital": forms.Select(attrs={"class": "form-select"}),
|
||||||
}),
|
"department": forms.Select(attrs={"class": "form-select"}),
|
||||||
'background': forms.Textarea(attrs={
|
"status": forms.Select(attrs={"class": "form-select"}),
|
||||||
'class': 'form-control',
|
"severity": forms.Select(attrs={"class": "form-select"}),
|
||||||
'rows': 3,
|
"priority": forms.Select(attrs={"class": "form-select"}),
|
||||||
'placeholder': 'Provide background information and context'
|
"assigned_to": forms.Select(attrs={"class": "form-select"}),
|
||||||
}),
|
"target_completion_date": forms.DateInput(attrs={"class": "form-control", "type": "date"}),
|
||||||
'hospital': forms.Select(attrs={'class': 'form-select'}),
|
"root_cause_summary": forms.Textarea(
|
||||||
'department': forms.Select(attrs={'class': 'form-select'}),
|
attrs={"class": "form-control", "rows": 4, "placeholder": "Summary of root cause analysis findings"}
|
||||||
'status': forms.Select(attrs={'class': 'form-select'}),
|
),
|
||||||
'severity': forms.Select(attrs={'class': 'form-select'}),
|
|
||||||
'priority': forms.Select(attrs={'class': 'form-select'}),
|
|
||||||
'assigned_to': forms.Select(attrs={'class': 'form-select'}),
|
|
||||||
'target_completion_date': forms.DateInput(attrs={
|
|
||||||
'class': 'form-control',
|
|
||||||
'type': 'date'
|
|
||||||
}),
|
|
||||||
'root_cause_summary': forms.Textarea(attrs={
|
|
||||||
'class': 'form-control',
|
|
||||||
'rows': 4,
|
|
||||||
'placeholder': 'Summary of root cause analysis findings'
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# Filter assigned_to to show only active users
|
# Filter assigned_to to show only active users
|
||||||
if 'assigned_to' in self.fields:
|
if "assigned_to" in self.fields:
|
||||||
from apps.accounts.models import User
|
from apps.accounts.models import User
|
||||||
self.fields['assigned_to'].queryset = User.objects.filter(
|
|
||||||
is_active=True
|
self.fields["assigned_to"].queryset = User.objects.filter(is_active=True).order_by("email")
|
||||||
).order_by('email')
|
|
||||||
|
|
||||||
|
|
||||||
class RCARootCauseForm(forms.ModelForm):
|
class RCARootCauseForm(forms.ModelForm):
|
||||||
@ -87,54 +73,38 @@ class RCARootCauseForm(forms.ModelForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = RCARootCause
|
model = RCARootCause
|
||||||
fields = [
|
fields = [
|
||||||
'description',
|
"description",
|
||||||
'category',
|
"category",
|
||||||
'contributing_factors',
|
"contributing_factors",
|
||||||
'likelihood',
|
"likelihood",
|
||||||
'impact',
|
"impact",
|
||||||
'evidence',
|
"evidence",
|
||||||
]
|
]
|
||||||
widgets = {
|
widgets = {
|
||||||
'description': forms.Textarea(attrs={
|
"description": forms.Textarea(
|
||||||
'class': 'form-control',
|
attrs={"class": "form-control", "rows": 3, "placeholder": "Describe the root cause"}
|
||||||
'rows': 3,
|
),
|
||||||
'placeholder': 'Describe the root cause'
|
"category": forms.Select(attrs={"class": "form-select"}),
|
||||||
}),
|
"contributing_factors": forms.Textarea(
|
||||||
'category': forms.Select(attrs={'class': 'form-select'}),
|
attrs={"class": "form-control", "rows": 2, "placeholder": "Factors that contributed to this root cause"}
|
||||||
'contributing_factors': forms.Textarea(attrs={
|
),
|
||||||
'class': 'form-control',
|
"likelihood": forms.NumberInput(attrs={"class": "form-control", "min": 1, "max": 5, "placeholder": "1-5"}),
|
||||||
'rows': 2,
|
"impact": forms.NumberInput(attrs={"class": "form-control", "min": 1, "max": 5, "placeholder": "1-5"}),
|
||||||
'placeholder': 'Factors that contributed to this root cause'
|
"evidence": forms.Textarea(
|
||||||
}),
|
attrs={"class": "form-control", "rows": 2, "placeholder": "Evidence supporting this root cause"}
|
||||||
'likelihood': forms.NumberInput(attrs={
|
),
|
||||||
'class': 'form-control',
|
|
||||||
'min': 1,
|
|
||||||
'max': 5,
|
|
||||||
'placeholder': '1-5'
|
|
||||||
}),
|
|
||||||
'impact': forms.NumberInput(attrs={
|
|
||||||
'class': 'form-control',
|
|
||||||
'min': 1,
|
|
||||||
'max': 5,
|
|
||||||
'placeholder': '1-5'
|
|
||||||
}),
|
|
||||||
'evidence': forms.Textarea(attrs={
|
|
||||||
'class': 'form-control',
|
|
||||||
'rows': 2,
|
|
||||||
'placeholder': 'Evidence supporting this root cause'
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def clean_likelihood(self):
|
def clean_likelihood(self):
|
||||||
likelihood = self.cleaned_data.get('likelihood')
|
likelihood = self.cleaned_data.get("likelihood")
|
||||||
if likelihood and (likelihood < 1 or likelihood > 5):
|
if likelihood and (likelihood < 1 or likelihood > 5):
|
||||||
raise forms.ValidationError('Likelihood must be between 1 and 5')
|
raise forms.ValidationError("Likelihood must be between 1 and 5")
|
||||||
return likelihood
|
return likelihood
|
||||||
|
|
||||||
def clean_impact(self):
|
def clean_impact(self):
|
||||||
impact = self.cleaned_data.get('impact')
|
impact = self.cleaned_data.get("impact")
|
||||||
if impact and (impact < 1 or impact > 5):
|
if impact and (impact < 1 or impact > 5):
|
||||||
raise forms.ValidationError('Impact must be between 1 and 5')
|
raise forms.ValidationError("Impact must be between 1 and 5")
|
||||||
return impact
|
return impact
|
||||||
|
|
||||||
|
|
||||||
@ -144,209 +114,159 @@ class RCACorrectiveActionForm(forms.ModelForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = RCACorrectiveAction
|
model = RCACorrectiveAction
|
||||||
fields = [
|
fields = [
|
||||||
'description',
|
"description",
|
||||||
'action_type',
|
"action_type",
|
||||||
'root_cause',
|
"root_cause",
|
||||||
'responsible_person',
|
"responsible_person",
|
||||||
'target_date',
|
"target_date",
|
||||||
'completion_date',
|
"completion_date",
|
||||||
'status',
|
"status",
|
||||||
'effectiveness_measure',
|
"effectiveness_measure",
|
||||||
'effectiveness_assessment',
|
"effectiveness_assessment",
|
||||||
'effectiveness_score',
|
"effectiveness_score",
|
||||||
'obstacles',
|
"obstacles",
|
||||||
]
|
]
|
||||||
widgets = {
|
widgets = {
|
||||||
'description': forms.Textarea(attrs={
|
"description": forms.Textarea(
|
||||||
'class': 'form-control',
|
attrs={"class": "form-control", "rows": 3, "placeholder": "Describe the corrective action"}
|
||||||
'rows': 3,
|
),
|
||||||
'placeholder': 'Describe the corrective action'
|
"action_type": forms.Select(attrs={"class": "form-select"}),
|
||||||
}),
|
"root_cause": forms.Select(attrs={"class": "form-select"}),
|
||||||
'action_type': forms.Select(attrs={'class': 'form-select'}),
|
"responsible_person": forms.Select(attrs={"class": "form-select"}),
|
||||||
'root_cause': forms.Select(attrs={'class': 'form-select'}),
|
"target_date": forms.DateInput(attrs={"class": "form-control", "type": "date"}),
|
||||||
'responsible_person': forms.Select(attrs={'class': 'form-select'}),
|
"completion_date": forms.DateInput(attrs={"class": "form-control", "type": "date"}),
|
||||||
'target_date': forms.DateInput(attrs={
|
"status": forms.Select(attrs={"class": "form-select"}),
|
||||||
'class': 'form-control',
|
"effectiveness_measure": forms.Textarea(
|
||||||
'type': 'date'
|
attrs={"class": "form-control", "rows": 2, "placeholder": "How will effectiveness be measured?"}
|
||||||
}),
|
),
|
||||||
'completion_date': forms.DateInput(attrs={
|
"effectiveness_assessment": forms.Textarea(
|
||||||
'class': 'form-control',
|
attrs={"class": "form-control", "rows": 2, "placeholder": "Assessment of action effectiveness"}
|
||||||
'type': 'date'
|
),
|
||||||
}),
|
"effectiveness_score": forms.NumberInput(
|
||||||
'status': forms.Select(attrs={'class': 'form-select'}),
|
attrs={"class": "form-control", "min": 1, "max": 5, "placeholder": "1-5"}
|
||||||
'effectiveness_measure': forms.Textarea(attrs={
|
),
|
||||||
'class': 'form-control',
|
"obstacles": forms.Textarea(
|
||||||
'rows': 2,
|
attrs={"class": "form-control", "rows": 2, "placeholder": "Obstacles encountered during implementation"}
|
||||||
'placeholder': 'How will effectiveness be measured?'
|
),
|
||||||
}),
|
|
||||||
'effectiveness_assessment': forms.Textarea(attrs={
|
|
||||||
'class': 'form-control',
|
|
||||||
'rows': 2,
|
|
||||||
'placeholder': 'Assessment of action effectiveness'
|
|
||||||
}),
|
|
||||||
'effectiveness_score': forms.NumberInput(attrs={
|
|
||||||
'class': 'form-control',
|
|
||||||
'min': 1,
|
|
||||||
'max': 5,
|
|
||||||
'placeholder': '1-5'
|
|
||||||
}),
|
|
||||||
'obstacles': forms.Textarea(attrs={
|
|
||||||
'class': 'form-control',
|
|
||||||
'rows': 2,
|
|
||||||
'placeholder': 'Obstacles encountered during implementation'
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
rca = kwargs.pop('rca', None)
|
rca = kwargs.pop("rca", None)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# Filter root_cause to show only for this RCA
|
# Filter root_cause to show only for this RCA
|
||||||
if 'root_cause' in self.fields and rca:
|
if "root_cause" in self.fields and rca:
|
||||||
self.fields['root_cause'].queryset = rca.root_causes.all()
|
self.fields["root_cause"].queryset = rca.root_causes.all()
|
||||||
|
|
||||||
def clean_effectiveness_score(self):
|
def clean_effectiveness_score(self):
|
||||||
score = self.cleaned_data.get('effectiveness_score')
|
score = self.cleaned_data.get("effectiveness_score")
|
||||||
if score and (score < 1 or score > 5):
|
if score and (score < 1 or score > 5):
|
||||||
raise forms.ValidationError('Effectiveness score must be between 1 and 5')
|
raise forms.ValidationError("Effectiveness score must be between 1 and 5")
|
||||||
return score
|
return score
|
||||||
|
|
||||||
|
|
||||||
class RCAFilterForm(forms.Form):
|
class RCAFilterForm(forms.Form):
|
||||||
"""Form for filtering RCA list"""
|
"""Form for filtering RCA list"""
|
||||||
|
|
||||||
status = forms.ChoiceField(
|
status = forms.ChoiceField(
|
||||||
required=False,
|
required=False,
|
||||||
choices=[('', 'All Statuses')] + list(RCAStatus.choices),
|
choices=[("", "All Statuses")] + list(RCAStatus.choices),
|
||||||
widget=forms.Select(attrs={'class': 'form-select'})
|
widget=forms.Select(attrs={"class": "form-select"}),
|
||||||
)
|
)
|
||||||
severity = forms.ChoiceField(
|
severity = forms.ChoiceField(
|
||||||
required=False,
|
required=False,
|
||||||
choices=[('', 'All Severities')] + list(RCASeverity.choices),
|
choices=[("", "All Severities")] + list(RCASeverity.choices),
|
||||||
widget=forms.Select(attrs={'class': 'form-select'})
|
widget=forms.Select(attrs={"class": "form-select"}),
|
||||||
)
|
)
|
||||||
priority = forms.ChoiceField(
|
priority = forms.ChoiceField(
|
||||||
required=False,
|
required=False,
|
||||||
choices=[('', 'All Priorities')] + list(PriorityChoices.choices),
|
choices=[("", "All Priorities")] + list(PriorityChoices.choices),
|
||||||
widget=forms.Select(attrs={'class': 'form-select'})
|
widget=forms.Select(attrs={"class": "form-select"}),
|
||||||
)
|
)
|
||||||
hospital = forms.ChoiceField(
|
hospital = forms.ChoiceField(
|
||||||
required=False,
|
required=False, choices=[("", "All Hospitals")], widget=forms.Select(attrs={"class": "form-select"})
|
||||||
choices=[('', 'All Hospitals')],
|
|
||||||
widget=forms.Select(attrs={'class': 'form-select'})
|
|
||||||
)
|
)
|
||||||
department = forms.ChoiceField(
|
department = forms.ChoiceField(
|
||||||
required=False,
|
required=False, choices=[("", "All Departments")], widget=forms.Select(attrs={"class": "form-select"})
|
||||||
choices=[('', 'All Departments')],
|
|
||||||
widget=forms.Select(attrs={'class': 'form-select'})
|
|
||||||
)
|
)
|
||||||
search = forms.CharField(
|
search = forms.CharField(
|
||||||
required=False,
|
required=False, widget=forms.TextInput(attrs={"class": "form-control", "placeholder": "Search RCAs..."})
|
||||||
widget=forms.TextInput(attrs={
|
|
||||||
'class': 'form-control',
|
|
||||||
'placeholder': 'Search RCAs...'
|
|
||||||
})
|
|
||||||
)
|
|
||||||
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'})
|
|
||||||
)
|
)
|
||||||
|
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"}))
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# Populate hospital choices
|
# Populate hospital choices
|
||||||
from apps.organizations.models import Hospital
|
from apps.organizations.models import Hospital
|
||||||
hospital_choices = [('', 'All Hospitals')]
|
|
||||||
hospital_choices.extend([
|
hospital_choices = [("", "All Hospitals")]
|
||||||
(h.id, h.name)
|
hospital_choices.extend([(h.id, h.name) for h in Hospital.objects.all()])
|
||||||
for h in Hospital.objects.all()
|
self.fields["hospital"].choices = hospital_choices
|
||||||
])
|
|
||||||
self.fields['hospital'].choices = hospital_choices
|
|
||||||
|
|
||||||
|
|
||||||
class RCAStatusChangeForm(forms.Form):
|
class RCAStatusChangeForm(forms.Form):
|
||||||
"""Form for changing RCA status"""
|
"""Form for changing RCA status"""
|
||||||
new_status = forms.ChoiceField(
|
|
||||||
choices=RCAStatus.choices,
|
new_status = forms.ChoiceField(choices=RCAStatus.choices, widget=forms.Select(attrs={"class": "form-select"}))
|
||||||
widget=forms.Select(attrs={'class': 'form-select'})
|
|
||||||
)
|
|
||||||
notes = forms.CharField(
|
notes = forms.CharField(
|
||||||
required=False,
|
required=False,
|
||||||
widget=forms.Textarea(attrs={
|
widget=forms.Textarea(
|
||||||
'class': 'form-control',
|
attrs={"class": "form-control", "rows": 3, "placeholder": "Add notes about this status change"}
|
||||||
'rows': 3,
|
),
|
||||||
'placeholder': 'Add notes about this status change'
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class RCAApprovalForm(forms.Form):
|
class RCAApprovalForm(forms.Form):
|
||||||
"""Form for approving RCA"""
|
"""Form for approving RCA"""
|
||||||
|
|
||||||
approval_notes = forms.CharField(
|
approval_notes = forms.CharField(
|
||||||
required=False,
|
required=False,
|
||||||
widget=forms.Textarea(attrs={
|
widget=forms.Textarea(attrs={"class": "form-control", "rows": 3, "placeholder": "Add approval notes"}),
|
||||||
'class': 'form-control',
|
|
||||||
'rows': 3,
|
|
||||||
'placeholder': 'Add approval notes'
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class RCAClosureForm(forms.Form):
|
class RCAClosureForm(forms.Form):
|
||||||
"""Form for closing RCA"""
|
"""Form for closing RCA"""
|
||||||
|
|
||||||
closure_notes = forms.CharField(
|
closure_notes = forms.CharField(
|
||||||
required=True,
|
required=True,
|
||||||
widget=forms.Textarea(attrs={
|
widget=forms.Textarea(
|
||||||
'class': 'form-control',
|
attrs={"class": "form-control", "rows": 3, "placeholder": "Provide closure notes and summary"}
|
||||||
'rows': 3,
|
),
|
||||||
'placeholder': 'Provide closure notes and summary'
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
actual_completion_date = forms.DateField(
|
actual_completion_date = forms.DateField(
|
||||||
required=True,
|
required=True, widget=forms.DateInput(attrs={"class": "form-control", "type": "date"})
|
||||||
widget=forms.DateInput(attrs={
|
|
||||||
'class': 'form-control',
|
|
||||||
'type': 'date'
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
# Set default to today
|
# Set default to today
|
||||||
self.fields['actual_completion_date'].initial = timezone.now().date()
|
self.fields["actual_completion_date"].initial = timezone.now().date()
|
||||||
|
|
||||||
|
|
||||||
class RCAAttachmentForm(forms.ModelForm):
|
class RCAAttachmentForm(forms.ModelForm):
|
||||||
"""Form for uploading RCA attachments"""
|
"""Form for uploading RCA attachments"""
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = RCAAttachment
|
model = RCAAttachment
|
||||||
fields = ['file', 'description']
|
fields = ["file", "description"]
|
||||||
widgets = {
|
widgets = {
|
||||||
'file': forms.FileInput(attrs={'class': 'form-control'}),
|
"file": forms.FileInput(attrs={"class": "form-control"}),
|
||||||
'description': forms.Textarea(attrs={
|
"description": forms.Textarea(
|
||||||
'class': 'form-control',
|
attrs={"class": "form-control", "rows": 2, "placeholder": "Describe this attachment"}
|
||||||
'rows': 2,
|
),
|
||||||
'placeholder': 'Describe this attachment'
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class RCANoteForm(forms.ModelForm):
|
class RCANoteForm(forms.ModelForm):
|
||||||
"""Form for adding RCA notes"""
|
"""Form for adding RCA notes"""
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = RCANote
|
model = RCANote
|
||||||
fields = ['note', 'is_internal']
|
fields = ["note", "is_internal"]
|
||||||
widgets = {
|
widgets = {
|
||||||
'note': forms.Textarea(attrs={
|
"note": forms.Textarea(attrs={"class": "form-control", "rows": 3, "placeholder": "Add a note"}),
|
||||||
'class': 'form-control',
|
"is_internal": forms.CheckboxInput(attrs={"class": "form-check-input"}),
|
||||||
'rows': 3,
|
}
|
||||||
'placeholder': 'Add a note'
|
|
||||||
}),
|
|
||||||
'is_internal': forms.CheckboxInput(attrs={
|
|
||||||
'class': 'form-check-input'
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user