Skip to content

Commit 640ce42

Browse files
authored
Merge pull request #816 from NHSDigital/DTOSS-11781-cleanup-medical-history
Cleanup medical history - use consistent naming
2 parents fa75177 + 0303a5a commit 640ce42

File tree

55 files changed

+351
-436
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+351
-436
lines changed
Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
from .appointment_cannot_go_ahead_form import AppointmentCannotGoAheadForm
22
from .appointment_note_form import AppointmentNoteForm
33
from .ask_for_medical_information_form import AskForMedicalInformationForm
4-
from .breast_augmentation_history_form import BreastAugmentationHistoryForm
5-
from .cyst_history_form import CystHistoryForm
6-
from .implanted_medical_device_history_form import ImplantedMedicalDeviceHistoryForm
7-
from .mastectomy_or_lumpectomy_history_form import MastectomyOrLumpectomyHistoryForm
8-
from .other_procedure_history_form import OtherProcedureHistoryForm
4+
from .medical_history.breast_augmentation_history_item_form import (
5+
BreastAugmentationHistoryItemForm,
6+
)
7+
from .medical_history.cyst_history_item_form import CystHistoryItemForm
8+
from .medical_history.implanted_medical_device_history_item_form import (
9+
ImplantedMedicalDeviceHistoryItemForm,
10+
)
11+
from .medical_history.mastectomy_or_lumpectomy_history_item_form import (
12+
MastectomyOrLumpectomyHistoryItemForm,
13+
)
14+
from .medical_history.other_procedure_history_item_form import (
15+
OtherProcedureHistoryItemForm,
16+
)
917
from .record_medical_information_form import RecordMedicalInformationForm
1018
from .screening_appointment_form import ScreeningAppointmentForm
1119
from .special_appointment_forms import (
@@ -17,13 +25,13 @@
1725
"AppointmentCannotGoAheadForm",
1826
"AskForMedicalInformationForm",
1927
"AppointmentNoteForm",
20-
"BreastAugmentationHistoryForm",
21-
"CystHistoryForm",
28+
"BreastAugmentationHistoryItemForm",
29+
"CystHistoryItemForm",
2230
"RecordMedicalInformationForm",
2331
"ScreeningAppointmentForm",
2432
"ProvideSpecialAppointmentDetailsForm",
2533
"MarkReasonsTemporaryForm",
26-
"MastectomyOrLumpectomyHistoryForm",
27-
"ImplantedMedicalDeviceHistoryForm",
28-
"OtherProcedureHistoryForm",
34+
"MastectomyOrLumpectomyHistoryItemForm",
35+
"ImplantedMedicalDeviceHistoryItemForm",
36+
"OtherProcedureHistoryItemForm",
2937
]

manage_breast_screening/mammograms/forms/medical_history/__init__.py

Whitespace-only changes.

manage_breast_screening/mammograms/forms/benign_lump_history_item_form.py renamed to manage_breast_screening/mammograms/forms/medical_history/benign_lump_history_item_form.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
)
99
from manage_breast_screening.nhsuk_forms.fields.integer_field import YearField
1010
from manage_breast_screening.nhsuk_forms.forms import FormWithConditionalFields
11-
from manage_breast_screening.participants.models.benign_lump_history_item import (
11+
from manage_breast_screening.participants.models.medical_history.benign_lump_history_item import (
1212
BenignLumpHistoryItem,
1313
)
1414

@@ -104,8 +104,8 @@ class BenignLumpHistoryItemForm(FormWithConditionalFields):
104104
hint="Include any other relevant information about the procedure (optional)",
105105
)
106106

107-
def __init__(self, *args, **kwargs):
108-
self.instance = kwargs.pop("instance", None)
107+
def __init__(self, *args, instance=None, **kwargs):
108+
self.instance = instance
109109

110110
if self.instance:
111111
kwargs["initial"] = self.initial_values(self.instance)
@@ -152,6 +152,9 @@ def create(self, appointment, request):
152152
return benign_lump_history_item
153153

154154
def update(self, request):
155+
if self.instance is None:
156+
raise ValueError("Form has no instance")
157+
155158
auditor = Auditor.from_request(request)
156159

157160
self.instance.left_breast_procedures = self.cleaned_data.get(

manage_breast_screening/mammograms/forms/breast_augmentation_history_form.py renamed to manage_breast_screening/mammograms/forms/medical_history/breast_augmentation_history_item_form.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
YearField,
1010
)
1111
from manage_breast_screening.nhsuk_forms.fields.choice_fields import MultipleChoiceField
12-
from manage_breast_screening.participants.models.breast_augmentation_history_item import (
12+
from manage_breast_screening.participants.models.medical_history.breast_augmentation_history_item import (
1313
BreastAugmentationHistoryItem,
1414
)
1515

1616

17-
class BreastAugmentationHistoryBaseForm(Form):
17+
class BreastAugmentationHistoryItemForm(Form):
1818
right_breast_procedures = MultipleChoiceField(
1919
label="Right breast",
2020
label_classes="nhsuk-fieldset__legend--s",
@@ -64,6 +64,21 @@ class BreastAugmentationHistoryBaseForm(Form):
6464
error_messages={"max_words": "Additional details must be 500 words or less"},
6565
)
6666

67+
def __init__(self, *args, instance=None, **kwargs):
68+
self.instance = instance
69+
70+
if instance:
71+
kwargs["initial"] = {
72+
"right_breast_procedures": instance.right_breast_procedures,
73+
"left_breast_procedures": instance.left_breast_procedures,
74+
"procedure_year": instance.procedure_year,
75+
"implants_have_been_removed": instance.implants_have_been_removed,
76+
"removal_year": instance.removal_year,
77+
"additional_details": instance.additional_details,
78+
}
79+
80+
super().__init__(*args, **kwargs)
81+
6782
def model_values(self):
6883
return dict(
6984
left_breast_procedures=self.cleaned_data.get("left_breast_procedures", []),
@@ -107,8 +122,6 @@ def clean(self):
107122

108123
return cleaned_data
109124

110-
111-
class BreastAugmentationHistoryForm(BreastAugmentationHistoryBaseForm):
112125
def create(self, appointment, request):
113126
auditor = Auditor.from_request(request)
114127
field_values = self.model_values()
@@ -122,23 +135,10 @@ def create(self, appointment, request):
122135

123136
return breast_augmentation_history
124137

125-
126-
class BreastAugmentationHistoryUpdateForm(BreastAugmentationHistoryBaseForm):
127-
def __init__(self, instance, *args, **kwargs):
128-
self.instance = instance
129-
130-
kwargs["initial"] = {
131-
"right_breast_procedures": instance.right_breast_procedures,
132-
"left_breast_procedures": instance.left_breast_procedures,
133-
"procedure_year": instance.procedure_year,
134-
"implants_have_been_removed": instance.implants_have_been_removed,
135-
"removal_year": instance.removal_year,
136-
"additional_details": instance.additional_details,
137-
}
138-
139-
super().__init__(*args, **kwargs)
140-
141138
def update(self, request):
139+
if self.instance is None:
140+
raise ValueError("Form has no instance")
141+
142142
# fmt: off
143143
self.instance.right_breast_procedures = self.cleaned_data["right_breast_procedures"]
144144
self.instance.left_breast_procedures = self.cleaned_data["left_breast_procedures"]

manage_breast_screening/mammograms/forms/breast_cancer_history_form.py renamed to manage_breast_screening/mammograms/forms/medical_history/breast_cancer_history_item_form.py

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@
77
ChoiceField,
88
MultipleChoiceField,
99
)
10-
from manage_breast_screening.nhsuk_forms.fields.integer_field import (
11-
YearField,
12-
)
10+
from manage_breast_screening.nhsuk_forms.fields.integer_field import YearField
1311
from manage_breast_screening.nhsuk_forms.forms import FormWithConditionalFields
14-
from manage_breast_screening.participants.models.breast_cancer_history_item import (
12+
from manage_breast_screening.participants.models.medical_history.breast_cancer_history_item import (
1513
BreastCancerHistoryItem,
1614
)
1715

1816

19-
class BreastCancerHistoryBaseForm(FormWithConditionalFields):
17+
class BreastCancerHistoryItemForm(FormWithConditionalFields):
2018
class DiagnosisLocationChoices(TextChoices):
2119
RIGHT_BREAST = "RIGHT_BREAST", "Right breast"
2220
LEFT_BREAST = "LEFT_BREAST", "Left breast"
@@ -26,8 +24,8 @@ class DiagnosisLocationChoices(TextChoices):
2624
def form_value_to_model_field(form_value):
2725
match form_value:
2826
case [
29-
BreastCancerHistoryBaseForm.DiagnosisLocationChoices.RIGHT_BREAST,
30-
BreastCancerHistoryBaseForm.DiagnosisLocationChoices.LEFT_BREAST,
27+
BreastCancerHistoryItemForm.DiagnosisLocationChoices.RIGHT_BREAST,
28+
BreastCancerHistoryItemForm.DiagnosisLocationChoices.LEFT_BREAST,
3129
]:
3230
return BreastCancerHistoryItem.DiagnosisLocationChoices.BOTH_BREASTS
3331
case [other]:
@@ -145,7 +143,29 @@ def model_field_to_form_value(cls, model_field):
145143
error_messages={"required": "Select where surgery and treatment took place"},
146144
)
147145

148-
def __init__(self, **kwargs):
146+
def __init__(self, instance=None, **kwargs):
147+
self.instance = instance
148+
self.appointment = instance.appointment if instance else None
149+
150+
if instance:
151+
kwargs["initial"] = {
152+
"diagnosis_location": self.DiagnosisLocationChoices.model_field_to_form_value(
153+
instance.diagnosis_location
154+
),
155+
"diagnosis_year": instance.diagnosis_year,
156+
"right_breast_procedure": instance.right_breast_procedure,
157+
"left_breast_procedure": instance.left_breast_procedure,
158+
"right_breast_other_surgery": instance.right_breast_other_surgery,
159+
"left_breast_other_surgery": instance.left_breast_other_surgery,
160+
"right_breast_treatment": instance.right_breast_treatment,
161+
"left_breast_treatment": instance.left_breast_treatment,
162+
"systemic_treatments": instance.systemic_treatments,
163+
"systemic_treatments_other_treatment_details": instance.systemic_treatments_other_treatment_details,
164+
"intervention_location": instance.intervention_location,
165+
f"intervention_location_details_{instance.intervention_location.lower()}": instance.intervention_location_details,
166+
"additional_details": instance.additional_details,
167+
}
168+
149169
super().__init__(**kwargs)
150170

151171
self.given_field_value(
@@ -205,8 +225,6 @@ def model_values(self):
205225
additional_details=self.cleaned_data.get("additional_details"),
206226
)
207227

208-
209-
class BreastCancerHistoryForm(BreastCancerHistoryBaseForm):
210228
def create(self, appointment, request):
211229
auditor = Auditor.from_request(request)
212230
field_values = self.model_values()
@@ -219,33 +237,10 @@ def create(self, appointment, request):
219237

220238
return instance
221239

222-
223-
class BreastCancerHistoryUpdateForm(BreastCancerHistoryBaseForm):
224-
def __init__(self, instance, **kwargs):
225-
self.instance = instance
226-
self.appointment = instance.appointment
227-
228-
kwargs["initial"] = {
229-
"diagnosis_location": self.DiagnosisLocationChoices.model_field_to_form_value(
230-
instance.diagnosis_location
231-
),
232-
"diagnosis_year": instance.diagnosis_year,
233-
"right_breast_procedure": instance.right_breast_procedure,
234-
"left_breast_procedure": instance.left_breast_procedure,
235-
"right_breast_other_surgery": instance.right_breast_other_surgery,
236-
"left_breast_other_surgery": instance.left_breast_other_surgery,
237-
"right_breast_treatment": instance.right_breast_treatment,
238-
"left_breast_treatment": instance.left_breast_treatment,
239-
"systemic_treatments": instance.systemic_treatments,
240-
"systemic_treatments_other_treatment_details": instance.systemic_treatments_other_treatment_details,
241-
"intervention_location": instance.intervention_location,
242-
f"intervention_location_details_{instance.intervention_location.lower()}": instance.intervention_location_details,
243-
"additional_details": instance.additional_details,
244-
}
245-
246-
super().__init__(**kwargs)
247-
248240
def update(self, request):
241+
if self.instance is None:
242+
raise ValueError("Form has no instance")
243+
249244
auditor = Auditor.from_request(request)
250245
field_values = self.model_values()
251246

@@ -254,6 +249,6 @@ def update(self, request):
254249

255250
self.instance.save()
256251

257-
auditor.audit_create(self.instance)
252+
auditor.audit_update(self.instance)
258253

259254
return self.instance

manage_breast_screening/mammograms/forms/cyst_history_form.py renamed to manage_breast_screening/mammograms/forms/medical_history/cyst_history_item_form.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@
33

44
from manage_breast_screening.core.services.auditor import Auditor
55
from manage_breast_screening.nhsuk_forms.fields import CharField, ChoiceField
6-
from manage_breast_screening.participants.models.cyst_history_item import (
6+
from manage_breast_screening.participants.models.medical_history.cyst_history_item import (
77
CystHistoryItem,
88
)
99

1010

11-
class CystHistoryBaseForm(Form):
12-
def __init__(self, *args, participant, **kwargs):
11+
class CystHistoryItemForm(Form):
12+
def __init__(self, *args, participant, instance=None, **kwargs):
13+
self.instance = instance
14+
15+
if instance:
16+
kwargs["initial"] = {
17+
"treatment": instance.treatment,
18+
"additional_details": instance.additional_details,
19+
}
20+
1321
super().__init__(*args, **kwargs)
1422

1523
self.fields["treatment"] = ChoiceField(
@@ -35,8 +43,6 @@ def model_values(self):
3543
additional_details=self.cleaned_data.get("additional_details", ""),
3644
)
3745

38-
39-
class CystHistoryForm(CystHistoryBaseForm):
4046
def create(self, appointment, request):
4147
auditor = Auditor.from_request(request)
4248
field_values = self.model_values()
@@ -50,20 +56,10 @@ def create(self, appointment, request):
5056

5157
return cyst_history
5258

53-
54-
class CystHistoryUpdateForm(CystHistoryBaseForm):
55-
def __init__(self, instance, *args, **kwargs):
56-
self.instance = instance
57-
58-
kwargs["participant"] = instance.participant
59-
kwargs["initial"] = {
60-
"treatment": instance.treatment,
61-
"additional_details": instance.additional_details,
62-
}
63-
64-
super().__init__(*args, **kwargs)
65-
6659
def update(self, request):
60+
if self.instance is None:
61+
raise ValueError("Form has no instance")
62+
6763
self.instance.treatment = self.cleaned_data["treatment"]
6864
self.instance.additional_details = self.cleaned_data["additional_details"]
6965
self.instance.save()

manage_breast_screening/mammograms/forms/implanted_medical_device_history_form.py renamed to manage_breast_screening/mammograms/forms/medical_history/implanted_medical_device_history_item_form.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,25 @@
99
YearField,
1010
)
1111
from manage_breast_screening.nhsuk_forms.forms import FormWithConditionalFields
12-
from manage_breast_screening.participants.models.implanted_medical_device_history_item import (
12+
from manage_breast_screening.participants.models.medical_history.implanted_medical_device_history_item import (
1313
ImplantedMedicalDeviceHistoryItem,
1414
)
1515

1616

17-
class ImplantedMedicalDeviceHistoryBaseForm(FormWithConditionalFields):
18-
def __init__(self, *args, participant, **kwargs):
17+
class ImplantedMedicalDeviceHistoryItemForm(FormWithConditionalFields):
18+
def __init__(self, *args, participant, instance=None, **kwargs):
19+
self.instance = instance
20+
21+
if instance:
22+
kwargs["initial"] = {
23+
"device": instance.device,
24+
"other_medical_device_details": instance.other_medical_device_details,
25+
"device_has_been_removed": instance.device_has_been_removed,
26+
"removal_year": instance.removal_year,
27+
"procedure_year": instance.procedure_year,
28+
"additional_details": instance.additional_details,
29+
}
30+
1931
super().__init__(*args, **kwargs)
2032

2133
self.fields["device"] = ChoiceField(
@@ -100,8 +112,6 @@ def clean(self):
100112
),
101113
)
102114

103-
104-
class ImplantedMedicalDeviceHistoryForm(ImplantedMedicalDeviceHistoryBaseForm):
105115
def create(self, appointment, request):
106116
auditor = Auditor.from_request(request)
107117
field_values = self.model_values()
@@ -117,24 +127,10 @@ def create(self, appointment, request):
117127

118128
return implanted_medical_device_history
119129

120-
121-
class ImplantedMedicalDeviceHistoryUpdateForm(ImplantedMedicalDeviceHistoryBaseForm):
122-
def __init__(self, instance, *args, **kwargs):
123-
self.instance = instance
124-
125-
kwargs["participant"] = instance.participant
126-
kwargs["initial"] = {
127-
"device": instance.device,
128-
"other_medical_device_details": instance.other_medical_device_details,
129-
"device_has_been_removed": instance.device_has_been_removed,
130-
"removal_year": instance.removal_year,
131-
"procedure_year": instance.procedure_year,
132-
"additional_details": instance.additional_details,
133-
}
134-
135-
super().__init__(*args, **kwargs)
136-
137130
def update(self, request):
131+
if self.instance is None:
132+
raise ValueError("Form has no instance")
133+
138134
self.instance.device = self.cleaned_data["device"]
139135
self.instance.other_medical_device_details = self.cleaned_data[
140136
"other_medical_device_details"

0 commit comments

Comments
 (0)