Skip to content

Commit e914f16

Browse files
committed
Include appointment ID in record-a-mammogram URLs
1 parent 137803b commit e914f16

3 files changed

Lines changed: 48 additions & 16 deletions

File tree

manage_breast_screening/record_a_mammogram/tests/test_views.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def test_appointment_continued(self, client):
2222
response,
2323
reverse(
2424
"record_a_mammogram:ask_for_medical_information",
25+
kwargs={"id": self.appointment.pk},
2526
),
2627
)
2728

@@ -33,7 +34,11 @@ def test_appointment_stopped(self, client):
3334
{"decision": "dropout"},
3435
)
3536
assertRedirects(
36-
response, reverse("record_a_mammogram:appointment_cannot_go_ahead", kwargs={"id": self.appointment.pk})
37+
response,
38+
reverse(
39+
"record_a_mammogram:appointment_cannot_go_ahead",
40+
kwargs={"id": self.appointment.pk},
41+
),
3742
)
3843

3944
def test_renders_invalid_form(self, client):

manage_breast_screening/record_a_mammogram/urls.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,20 @@
1616
name="start_screening",
1717
),
1818
path(
19-
"ask-for-medical-information/",
19+
"appointments/<int:id>/ask-for-medical-information/",
2020
views.AskForMedicalInformation.as_view(),
2121
name="ask_for_medical_information",
2222
),
2323
path(
24-
"record-medical-information/",
24+
"appointments/<int:id>/record-medical-information/",
2525
views.RecordMedicalInformation.as_view(),
2626
name="record_medical_information",
2727
),
28-
path("awaiting-images/", views.awaiting_images, name="awaiting_images"),
28+
path(
29+
"appointments/<int:id>/awaiting-images/",
30+
views.awaiting_images,
31+
name="awaiting_images",
32+
),
2933
path(
3034
"appointments/<int:id>/cannot-go-ahead/",
3135
views.appointment_cannot_go_ahead,

manage_breast_screening/record_a_mammogram/views.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
RecordMedicalInformationForm,
1515
ScreeningAppointmentForm,
1616
)
17-
from manage_breast_screening.clinics.models import Appointment
1817

1918
Status = Appointment.Status
2019

@@ -88,56 +87,80 @@ def form_valid(self, form):
8887
form.save()
8988

9089
if form.cleaned_data["decision"] == "continue":
91-
return redirect("record_a_mammogram:ask_for_medical_information")
90+
return redirect(
91+
"record_a_mammogram:ask_for_medical_information",
92+
id=self.get_appointment().pk,
93+
)
9294
else:
93-
return redirect("record_a_mammogram:appointment_cannot_go_ahead", id=self.get_appointment().pk)
95+
return redirect(
96+
"record_a_mammogram:appointment_cannot_go_ahead",
97+
id=self.get_appointment().pk,
98+
)
9499

95100

96101
class AskForMedicalInformation(FormView):
97102
template_name = "record_a_mammogram/ask_for_medical_information.jinja"
98103
form_class = AskForMedicalInformationForm
99104

105+
def get_appointment(self):
106+
id = self.kwargs["id"]
107+
108+
return Appointment.objects.get(pk=id)
109+
100110
def form_valid(self, form):
101111
form.save()
102112

113+
appointment = self.get_appointment()
114+
103115
if form.cleaned_data["decision"] == "continue":
104-
return redirect("record_a_mammogram:record_medical_information")
116+
return redirect(
117+
"record_a_mammogram:record_medical_information", id=appointment.pk
118+
)
105119
else:
106-
return redirect("record_a_mammogram:awaiting_images")
120+
return redirect("record_a_mammogram:awaiting_images", id=appointment.pk)
107121

108122

109123
class RecordMedicalInformation(FormView):
110124
template_name = "record_a_mammogram/record_medical_information.jinja"
111125
form_class = RecordMedicalInformationForm
112126

127+
def get_appointment(self):
128+
id = self.kwargs["id"]
129+
130+
return Appointment.objects.get(pk=id)
131+
113132
def form_valid(self, form):
114133
form.save()
115134

135+
appointment = self.get_appointment()
136+
116137
if form.cleaned_data["decision"] == "continue":
117-
return redirect("record_a_mammogram:awaiting_images")
138+
return redirect("record_a_mammogram:awaiting_images", id=appointment.pk)
118139
else:
119-
return redirect("record_a_mammogram:appointment_cannot_go_ahead", id=self.appointment.pk)
140+
return redirect(
141+
"record_a_mammogram:appointment_cannot_go_ahead", id=appointment.pk
142+
)
120143

121144

122145
def appointment_cannot_go_ahead(request, id):
123146
appointment = Appointment.objects.get(pk=id)
124147
participant = appointment.screening_episode.participant
125-
if request.method == 'POST':
148+
if request.method == "POST":
126149
form = AppointmentCannotGoAheadForm(request.POST, instance=appointment)
127150
if form.is_valid():
128151
form.save()
129-
return redirect('clinics:index')
152+
return redirect("clinics:index")
130153
else:
131154
form = AppointmentCannotGoAheadForm(instance=appointment)
132155

133156
return render(
134157
request,
135-
'record_a_mammogram/appointment_cannot_go_ahead.jinja',
136-
{'form': form, 'participant': participant}
158+
"record_a_mammogram/appointment_cannot_go_ahead.jinja",
159+
{"form": form, "participant": participant},
137160
)
138161

139162

140-
def awaiting_images(request):
163+
def awaiting_images(request, id):
141164
return render(request, "record_a_mammogram/awaiting_images.jinja", {})
142165

143166

0 commit comments

Comments
 (0)