Skip to content

Commit

Permalink
Merge pull request #238 from rcpch:eatyourpeas/issue234
Browse files Browse the repository at this point in the history
upload-csv-form-validation-fix-implements-single-submission
  • Loading branch information
eatyourpeas committed Aug 10, 2024
2 parents e46965a + 6776001 commit 3ca087d
Show file tree
Hide file tree
Showing 12 changed files with 528 additions and 300 deletions.
28 changes: 0 additions & 28 deletions project/npda/forms/patient_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ def validate(self, value):

class PatientForm(forms.ModelForm):

quarter = forms.ChoiceField(
choices=[
(1, 1),
(2, 2),
(3, 3),
(4, 4),
], # Initially empty, will be populated dynamically
required=True,
widget=forms.Select(attrs={"class": SELECT}),
label="Audit Year Quarter",
)

class Meta:
model = Patient
fields = [
Expand All @@ -61,7 +49,6 @@ class Meta:
"death_date",
"gp_practice_ods_code",
"gp_practice_postcode",
"quarter",
]
field_classes = {"nhs_number": NHSNumberField}
widgets = {
Expand All @@ -77,23 +64,8 @@ class Meta:
"death_date": DateInput(),
"gp_practice_ods_code": forms.TextInput(attrs={"class": TEXT_INPUT}),
"gp_practice_postcode": forms.TextInput(attrs={"class": TEXT_INPUT}),
"quarter": forms.Select(),
}

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
if self.instance.pk:
# this is a bound form, so we need to get the quarter from the submission related to the instance
Submission = apps.get_model("npda", "Submission")
self.initial["quarter"] = Submission.objects.get(
patients=self.instance
).quarter
else:
# this is an unbound form, so we need to set the quarter to current quarter
self.initial["quarter"] = retrieve_quarter_for_date(
date_instance=date.today()
)

def clean_postcode(self):
if not self.cleaned_data["postcode"]:
raise ValidationError("This field is required")
Expand Down
Loading

0 comments on commit 3ca087d

Please sign in to comment.