132 lines
3.9 KiB
Python
132 lines
3.9 KiB
Python
"""
|
|
Physicians Forms
|
|
|
|
Forms for doctor rating imports and filtering.
|
|
"""
|
|
from django import forms
|
|
|
|
from apps.organizations.models import Hospital
|
|
|
|
|
|
class DoctorRatingImportForm(forms.Form):
|
|
"""
|
|
Form for importing doctor ratings from CSV.
|
|
"""
|
|
hospital = forms.ModelChoiceField(
|
|
queryset=Hospital.objects.filter(status='active'),
|
|
label="Hospital",
|
|
help_text="Select the hospital these ratings belong to"
|
|
)
|
|
|
|
csv_file = forms.FileField(
|
|
label="CSV File",
|
|
help_text="Upload the Doctor Rating Report CSV file",
|
|
widget=forms.FileInput(attrs={'accept': '.csv'})
|
|
)
|
|
|
|
skip_header_rows = forms.IntegerField(
|
|
label="Skip Header Rows",
|
|
initial=6,
|
|
min_value=0,
|
|
max_value=20,
|
|
help_text="Number of rows to skip before the column headers (Doctor Rating Report typically has 6 header rows)"
|
|
)
|
|
|
|
def __init__(self, user, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
|
|
# Filter hospital choices based on user role
|
|
if user.is_px_admin():
|
|
self.fields['hospital'].queryset = Hospital.objects.filter(status='active')
|
|
elif user.hospital:
|
|
self.fields['hospital'].queryset = Hospital.objects.filter(id=user.hospital.id)
|
|
self.fields['hospital'].initial = user.hospital
|
|
else:
|
|
self.fields['hospital'].queryset = Hospital.objects.none()
|
|
|
|
def clean_csv_file(self):
|
|
csv_file = self.cleaned_data['csv_file']
|
|
|
|
# Check file extension
|
|
if not csv_file.name.endswith('.csv'):
|
|
raise forms.ValidationError("File must be a CSV file (.csv extension)")
|
|
|
|
# Check file size (max 10MB)
|
|
if csv_file.size > 10 * 1024 * 1024:
|
|
raise forms.ValidationError("File size must be less than 10MB")
|
|
|
|
return csv_file
|
|
|
|
|
|
class DoctorRatingFilterForm(forms.Form):
|
|
"""
|
|
Form for filtering individual doctor ratings.
|
|
"""
|
|
hospital = forms.ModelChoiceField(
|
|
queryset=Hospital.objects.filter(status='active'),
|
|
required=False,
|
|
label="Hospital"
|
|
)
|
|
|
|
doctor_id = forms.CharField(
|
|
required=False,
|
|
label="Doctor ID",
|
|
widget=forms.TextInput(attrs={'placeholder': 'e.g., 10738'})
|
|
)
|
|
|
|
doctor_name = forms.CharField(
|
|
required=False,
|
|
label="Doctor Name",
|
|
widget=forms.TextInput(attrs={'placeholder': 'Search by doctor name'})
|
|
)
|
|
|
|
rating_min = forms.IntegerField(
|
|
required=False,
|
|
min_value=1,
|
|
max_value=5,
|
|
label="Min Rating",
|
|
widget=forms.NumberInput(attrs={'placeholder': '1-5'})
|
|
)
|
|
|
|
rating_max = forms.IntegerField(
|
|
required=False,
|
|
min_value=1,
|
|
max_value=5,
|
|
label="Max Rating",
|
|
widget=forms.NumberInput(attrs={'placeholder': '1-5'})
|
|
)
|
|
|
|
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'})
|
|
)
|
|
|
|
source = forms.ChoiceField(
|
|
required=False,
|
|
label="Source",
|
|
choices=[('', 'All Sources')] + [
|
|
('his_api', 'HIS API'),
|
|
('csv_import', 'CSV Import'),
|
|
('manual', 'Manual Entry')
|
|
]
|
|
)
|
|
|
|
def __init__(self, user, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
|
|
# Filter hospital choices based on user role
|
|
if user.is_px_admin():
|
|
self.fields['hospital'].queryset = Hospital.objects.filter(status='active')
|
|
elif user.hospital:
|
|
self.fields['hospital'].queryset = Hospital.objects.filter(id=user.hospital.id)
|
|
self.fields['hospital'].initial = user.hospital
|
|
else:
|
|
self.fields['hospital'].queryset = Hospital.objects.none()
|