diff --git a/manage_breast_screening/mammograms/forms/__init__.py b/manage_breast_screening/mammograms/forms/__init__.py index 773232cfd..8cc1bc721 100644 --- a/manage_breast_screening/mammograms/forms/__init__.py +++ b/manage_breast_screening/mammograms/forms/__init__.py @@ -1,11 +1,19 @@ from .appointment_cannot_go_ahead_form import AppointmentCannotGoAheadForm from .appointment_note_form import AppointmentNoteForm from .ask_for_medical_information_form import AskForMedicalInformationForm -from .breast_augmentation_history_form import BreastAugmentationHistoryForm -from .cyst_history_form import CystHistoryForm -from .implanted_medical_device_history_form import ImplantedMedicalDeviceHistoryForm -from .mastectomy_or_lumpectomy_history_form import MastectomyOrLumpectomyHistoryForm -from .other_procedure_history_form import OtherProcedureHistoryForm +from .medical_history.breast_augmentation_history_item_form import ( + BreastAugmentationHistoryItemForm, +) +from .medical_history.cyst_history_item_form import CystHistoryItemForm +from .medical_history.implanted_medical_device_history_item_form import ( + ImplantedMedicalDeviceHistoryItemForm, +) +from .medical_history.mastectomy_or_lumpectomy_history_item_form import ( + MastectomyOrLumpectomyHistoryItemForm, +) +from .medical_history.other_procedure_history_item_form import ( + OtherProcedureHistoryItemForm, +) from .record_medical_information_form import RecordMedicalInformationForm from .screening_appointment_form import ScreeningAppointmentForm from .special_appointment_forms import ( @@ -17,13 +25,13 @@ "AppointmentCannotGoAheadForm", "AskForMedicalInformationForm", "AppointmentNoteForm", - "BreastAugmentationHistoryForm", - "CystHistoryForm", + "BreastAugmentationHistoryItemForm", + "CystHistoryItemForm", "RecordMedicalInformationForm", "ScreeningAppointmentForm", "ProvideSpecialAppointmentDetailsForm", "MarkReasonsTemporaryForm", - "MastectomyOrLumpectomyHistoryForm", - "ImplantedMedicalDeviceHistoryForm", - "OtherProcedureHistoryForm", + "MastectomyOrLumpectomyHistoryItemForm", + "ImplantedMedicalDeviceHistoryItemForm", + "OtherProcedureHistoryItemForm", ] diff --git a/manage_breast_screening/mammograms/forms/medical_history/__init__.py b/manage_breast_screening/mammograms/forms/medical_history/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/manage_breast_screening/mammograms/forms/benign_lump_history_item_form.py b/manage_breast_screening/mammograms/forms/medical_history/benign_lump_history_item_form.py similarity index 96% rename from manage_breast_screening/mammograms/forms/benign_lump_history_item_form.py rename to manage_breast_screening/mammograms/forms/medical_history/benign_lump_history_item_form.py index 3406bdec4..cef4a452e 100644 --- a/manage_breast_screening/mammograms/forms/benign_lump_history_item_form.py +++ b/manage_breast_screening/mammograms/forms/medical_history/benign_lump_history_item_form.py @@ -8,7 +8,7 @@ ) from manage_breast_screening.nhsuk_forms.fields.integer_field import YearField from manage_breast_screening.nhsuk_forms.forms import FormWithConditionalFields -from manage_breast_screening.participants.models.benign_lump_history_item import ( +from manage_breast_screening.participants.models.medical_history.benign_lump_history_item import ( BenignLumpHistoryItem, ) @@ -104,8 +104,8 @@ class BenignLumpHistoryItemForm(FormWithConditionalFields): hint="Include any other relevant information about the procedure (optional)", ) - def __init__(self, *args, **kwargs): - self.instance = kwargs.pop("instance", None) + def __init__(self, *args, instance=None, **kwargs): + self.instance = instance if self.instance: kwargs["initial"] = self.initial_values(self.instance) @@ -152,6 +152,9 @@ def create(self, appointment, request): return benign_lump_history_item def update(self, request): + if self.instance is None: + raise ValueError("Form has no instance") + auditor = Auditor.from_request(request) self.instance.left_breast_procedures = self.cleaned_data.get( diff --git a/manage_breast_screening/mammograms/forms/breast_augmentation_history_form.py b/manage_breast_screening/mammograms/forms/medical_history/breast_augmentation_history_item_form.py similarity index 86% rename from manage_breast_screening/mammograms/forms/breast_augmentation_history_form.py rename to manage_breast_screening/mammograms/forms/medical_history/breast_augmentation_history_item_form.py index 1bc65e751..1cb78079f 100644 --- a/manage_breast_screening/mammograms/forms/breast_augmentation_history_form.py +++ b/manage_breast_screening/mammograms/forms/medical_history/breast_augmentation_history_item_form.py @@ -9,12 +9,12 @@ YearField, ) from manage_breast_screening.nhsuk_forms.fields.choice_fields import MultipleChoiceField -from manage_breast_screening.participants.models.breast_augmentation_history_item import ( +from manage_breast_screening.participants.models.medical_history.breast_augmentation_history_item import ( BreastAugmentationHistoryItem, ) -class BreastAugmentationHistoryBaseForm(Form): +class BreastAugmentationHistoryItemForm(Form): right_breast_procedures = MultipleChoiceField( label="Right breast", label_classes="nhsuk-fieldset__legend--s", @@ -64,6 +64,21 @@ class BreastAugmentationHistoryBaseForm(Form): error_messages={"max_words": "Additional details must be 500 words or less"}, ) + def __init__(self, *args, instance=None, **kwargs): + self.instance = instance + + if instance: + kwargs["initial"] = { + "right_breast_procedures": instance.right_breast_procedures, + "left_breast_procedures": instance.left_breast_procedures, + "procedure_year": instance.procedure_year, + "implants_have_been_removed": instance.implants_have_been_removed, + "removal_year": instance.removal_year, + "additional_details": instance.additional_details, + } + + super().__init__(*args, **kwargs) + def model_values(self): return dict( left_breast_procedures=self.cleaned_data.get("left_breast_procedures", []), @@ -107,8 +122,6 @@ def clean(self): return cleaned_data - -class BreastAugmentationHistoryForm(BreastAugmentationHistoryBaseForm): def create(self, appointment, request): auditor = Auditor.from_request(request) field_values = self.model_values() @@ -122,23 +135,10 @@ def create(self, appointment, request): return breast_augmentation_history - -class BreastAugmentationHistoryUpdateForm(BreastAugmentationHistoryBaseForm): - def __init__(self, instance, *args, **kwargs): - self.instance = instance - - kwargs["initial"] = { - "right_breast_procedures": instance.right_breast_procedures, - "left_breast_procedures": instance.left_breast_procedures, - "procedure_year": instance.procedure_year, - "implants_have_been_removed": instance.implants_have_been_removed, - "removal_year": instance.removal_year, - "additional_details": instance.additional_details, - } - - super().__init__(*args, **kwargs) - def update(self, request): + if self.instance is None: + raise ValueError("Form has no instance") + # fmt: off self.instance.right_breast_procedures = self.cleaned_data["right_breast_procedures"] self.instance.left_breast_procedures = self.cleaned_data["left_breast_procedures"] diff --git a/manage_breast_screening/mammograms/forms/breast_cancer_history_form.py b/manage_breast_screening/mammograms/forms/medical_history/breast_cancer_history_item_form.py similarity index 83% rename from manage_breast_screening/mammograms/forms/breast_cancer_history_form.py rename to manage_breast_screening/mammograms/forms/medical_history/breast_cancer_history_item_form.py index e33c9cca7..571dd78c8 100644 --- a/manage_breast_screening/mammograms/forms/breast_cancer_history_form.py +++ b/manage_breast_screening/mammograms/forms/medical_history/breast_cancer_history_item_form.py @@ -7,16 +7,14 @@ ChoiceField, MultipleChoiceField, ) -from manage_breast_screening.nhsuk_forms.fields.integer_field import ( - YearField, -) +from manage_breast_screening.nhsuk_forms.fields.integer_field import YearField from manage_breast_screening.nhsuk_forms.forms import FormWithConditionalFields -from manage_breast_screening.participants.models.breast_cancer_history_item import ( +from manage_breast_screening.participants.models.medical_history.breast_cancer_history_item import ( BreastCancerHistoryItem, ) -class BreastCancerHistoryBaseForm(FormWithConditionalFields): +class BreastCancerHistoryItemForm(FormWithConditionalFields): class DiagnosisLocationChoices(TextChoices): RIGHT_BREAST = "RIGHT_BREAST", "Right breast" LEFT_BREAST = "LEFT_BREAST", "Left breast" @@ -26,8 +24,8 @@ class DiagnosisLocationChoices(TextChoices): def form_value_to_model_field(form_value): match form_value: case [ - BreastCancerHistoryBaseForm.DiagnosisLocationChoices.RIGHT_BREAST, - BreastCancerHistoryBaseForm.DiagnosisLocationChoices.LEFT_BREAST, + BreastCancerHistoryItemForm.DiagnosisLocationChoices.RIGHT_BREAST, + BreastCancerHistoryItemForm.DiagnosisLocationChoices.LEFT_BREAST, ]: return BreastCancerHistoryItem.DiagnosisLocationChoices.BOTH_BREASTS case [other]: @@ -145,7 +143,29 @@ def model_field_to_form_value(cls, model_field): error_messages={"required": "Select where surgery and treatment took place"}, ) - def __init__(self, **kwargs): + def __init__(self, instance=None, **kwargs): + self.instance = instance + self.appointment = instance.appointment if instance else None + + if instance: + kwargs["initial"] = { + "diagnosis_location": self.DiagnosisLocationChoices.model_field_to_form_value( + instance.diagnosis_location + ), + "diagnosis_year": instance.diagnosis_year, + "right_breast_procedure": instance.right_breast_procedure, + "left_breast_procedure": instance.left_breast_procedure, + "right_breast_other_surgery": instance.right_breast_other_surgery, + "left_breast_other_surgery": instance.left_breast_other_surgery, + "right_breast_treatment": instance.right_breast_treatment, + "left_breast_treatment": instance.left_breast_treatment, + "systemic_treatments": instance.systemic_treatments, + "systemic_treatments_other_treatment_details": instance.systemic_treatments_other_treatment_details, + "intervention_location": instance.intervention_location, + f"intervention_location_details_{instance.intervention_location.lower()}": instance.intervention_location_details, + "additional_details": instance.additional_details, + } + super().__init__(**kwargs) self.given_field_value( @@ -205,8 +225,6 @@ def model_values(self): additional_details=self.cleaned_data.get("additional_details"), ) - -class BreastCancerHistoryForm(BreastCancerHistoryBaseForm): def create(self, appointment, request): auditor = Auditor.from_request(request) field_values = self.model_values() @@ -219,33 +237,10 @@ def create(self, appointment, request): return instance - -class BreastCancerHistoryUpdateForm(BreastCancerHistoryBaseForm): - def __init__(self, instance, **kwargs): - self.instance = instance - self.appointment = instance.appointment - - kwargs["initial"] = { - "diagnosis_location": self.DiagnosisLocationChoices.model_field_to_form_value( - instance.diagnosis_location - ), - "diagnosis_year": instance.diagnosis_year, - "right_breast_procedure": instance.right_breast_procedure, - "left_breast_procedure": instance.left_breast_procedure, - "right_breast_other_surgery": instance.right_breast_other_surgery, - "left_breast_other_surgery": instance.left_breast_other_surgery, - "right_breast_treatment": instance.right_breast_treatment, - "left_breast_treatment": instance.left_breast_treatment, - "systemic_treatments": instance.systemic_treatments, - "systemic_treatments_other_treatment_details": instance.systemic_treatments_other_treatment_details, - "intervention_location": instance.intervention_location, - f"intervention_location_details_{instance.intervention_location.lower()}": instance.intervention_location_details, - "additional_details": instance.additional_details, - } - - super().__init__(**kwargs) - def update(self, request): + if self.instance is None: + raise ValueError("Form has no instance") + auditor = Auditor.from_request(request) field_values = self.model_values() @@ -254,6 +249,6 @@ def update(self, request): self.instance.save() - auditor.audit_create(self.instance) + auditor.audit_update(self.instance) return self.instance diff --git a/manage_breast_screening/mammograms/forms/cyst_history_form.py b/manage_breast_screening/mammograms/forms/medical_history/cyst_history_item_form.py similarity index 77% rename from manage_breast_screening/mammograms/forms/cyst_history_form.py rename to manage_breast_screening/mammograms/forms/medical_history/cyst_history_item_form.py index 33cbffdb6..c00ffb03e 100644 --- a/manage_breast_screening/mammograms/forms/cyst_history_form.py +++ b/manage_breast_screening/mammograms/forms/medical_history/cyst_history_item_form.py @@ -3,13 +3,21 @@ from manage_breast_screening.core.services.auditor import Auditor from manage_breast_screening.nhsuk_forms.fields import CharField, ChoiceField -from manage_breast_screening.participants.models.cyst_history_item import ( +from manage_breast_screening.participants.models.medical_history.cyst_history_item import ( CystHistoryItem, ) -class CystHistoryBaseForm(Form): - def __init__(self, *args, participant, **kwargs): +class CystHistoryItemForm(Form): + def __init__(self, *args, participant, instance=None, **kwargs): + self.instance = instance + + if instance: + kwargs["initial"] = { + "treatment": instance.treatment, + "additional_details": instance.additional_details, + } + super().__init__(*args, **kwargs) self.fields["treatment"] = ChoiceField( @@ -35,8 +43,6 @@ def model_values(self): additional_details=self.cleaned_data.get("additional_details", ""), ) - -class CystHistoryForm(CystHistoryBaseForm): def create(self, appointment, request): auditor = Auditor.from_request(request) field_values = self.model_values() @@ -50,20 +56,10 @@ def create(self, appointment, request): return cyst_history - -class CystHistoryUpdateForm(CystHistoryBaseForm): - def __init__(self, instance, *args, **kwargs): - self.instance = instance - - kwargs["participant"] = instance.participant - kwargs["initial"] = { - "treatment": instance.treatment, - "additional_details": instance.additional_details, - } - - super().__init__(*args, **kwargs) - def update(self, request): + if self.instance is None: + raise ValueError("Form has no instance") + self.instance.treatment = self.cleaned_data["treatment"] self.instance.additional_details = self.cleaned_data["additional_details"] self.instance.save() diff --git a/manage_breast_screening/mammograms/forms/implanted_medical_device_history_form.py b/manage_breast_screening/mammograms/forms/medical_history/implanted_medical_device_history_item_form.py similarity index 84% rename from manage_breast_screening/mammograms/forms/implanted_medical_device_history_form.py rename to manage_breast_screening/mammograms/forms/medical_history/implanted_medical_device_history_item_form.py index a86a928ac..b93639d20 100644 --- a/manage_breast_screening/mammograms/forms/implanted_medical_device_history_form.py +++ b/manage_breast_screening/mammograms/forms/medical_history/implanted_medical_device_history_item_form.py @@ -9,13 +9,25 @@ YearField, ) from manage_breast_screening.nhsuk_forms.forms import FormWithConditionalFields -from manage_breast_screening.participants.models.implanted_medical_device_history_item import ( +from manage_breast_screening.participants.models.medical_history.implanted_medical_device_history_item import ( ImplantedMedicalDeviceHistoryItem, ) -class ImplantedMedicalDeviceHistoryBaseForm(FormWithConditionalFields): - def __init__(self, *args, participant, **kwargs): +class ImplantedMedicalDeviceHistoryItemForm(FormWithConditionalFields): + def __init__(self, *args, participant, instance=None, **kwargs): + self.instance = instance + + if instance: + kwargs["initial"] = { + "device": instance.device, + "other_medical_device_details": instance.other_medical_device_details, + "device_has_been_removed": instance.device_has_been_removed, + "removal_year": instance.removal_year, + "procedure_year": instance.procedure_year, + "additional_details": instance.additional_details, + } + super().__init__(*args, **kwargs) self.fields["device"] = ChoiceField( @@ -100,8 +112,6 @@ def clean(self): ), ) - -class ImplantedMedicalDeviceHistoryForm(ImplantedMedicalDeviceHistoryBaseForm): def create(self, appointment, request): auditor = Auditor.from_request(request) field_values = self.model_values() @@ -117,24 +127,10 @@ def create(self, appointment, request): return implanted_medical_device_history - -class ImplantedMedicalDeviceHistoryUpdateForm(ImplantedMedicalDeviceHistoryBaseForm): - def __init__(self, instance, *args, **kwargs): - self.instance = instance - - kwargs["participant"] = instance.participant - kwargs["initial"] = { - "device": instance.device, - "other_medical_device_details": instance.other_medical_device_details, - "device_has_been_removed": instance.device_has_been_removed, - "removal_year": instance.removal_year, - "procedure_year": instance.procedure_year, - "additional_details": instance.additional_details, - } - - super().__init__(*args, **kwargs) - def update(self, request): + if self.instance is None: + raise ValueError("Form has no instance") + self.instance.device = self.cleaned_data["device"] self.instance.other_medical_device_details = self.cleaned_data[ "other_medical_device_details" diff --git a/manage_breast_screening/mammograms/forms/mastectomy_or_lumpectomy_history_form.py b/manage_breast_screening/mammograms/forms/medical_history/mastectomy_or_lumpectomy_history_item_form.py similarity index 95% rename from manage_breast_screening/mammograms/forms/mastectomy_or_lumpectomy_history_form.py rename to manage_breast_screening/mammograms/forms/medical_history/mastectomy_or_lumpectomy_history_item_form.py index 9b52244d4..490e3d4f2 100644 --- a/manage_breast_screening/mammograms/forms/mastectomy_or_lumpectomy_history_form.py +++ b/manage_breast_screening/mammograms/forms/medical_history/mastectomy_or_lumpectomy_history_item_form.py @@ -2,21 +2,15 @@ from django.forms.widgets import RadioSelect, Textarea from manage_breast_screening.core.services.auditor import Auditor -from manage_breast_screening.nhsuk_forms.fields import ( - CharField, - ChoiceField, - YearField, -) -from manage_breast_screening.nhsuk_forms.fields.choice_fields import ( - MultipleChoiceField, -) +from manage_breast_screening.nhsuk_forms.fields import CharField, ChoiceField, YearField +from manage_breast_screening.nhsuk_forms.fields.choice_fields import MultipleChoiceField from manage_breast_screening.nhsuk_forms.forms import FormWithConditionalFields -from manage_breast_screening.participants.models.mastectomy_or_lumpectomy_history_item import ( +from manage_breast_screening.participants.models.medical_history.mastectomy_or_lumpectomy_history_item import ( MastectomyOrLumpectomyHistoryItem, ) -class MastectomyOrLumpectomyHistoryForm(FormWithConditionalFields): +class MastectomyOrLumpectomyHistoryItemForm(FormWithConditionalFields): right_breast_procedure = ChoiceField( label="Right breast", visually_hidden_label_prefix="What procedure have they had in their ", diff --git a/manage_breast_screening/mammograms/forms/other_procedure_history_form.py b/manage_breast_screening/mammograms/forms/medical_history/other_procedure_history_item_form.py similarity index 96% rename from manage_breast_screening/mammograms/forms/other_procedure_history_form.py rename to manage_breast_screening/mammograms/forms/medical_history/other_procedure_history_item_form.py index b110346ab..d81e1645b 100644 --- a/manage_breast_screening/mammograms/forms/other_procedure_history_form.py +++ b/manage_breast_screening/mammograms/forms/medical_history/other_procedure_history_item_form.py @@ -4,12 +4,12 @@ from manage_breast_screening.nhsuk_forms.fields import CharField, ChoiceField from manage_breast_screening.nhsuk_forms.fields.integer_field import YearField from manage_breast_screening.nhsuk_forms.forms import FormWithConditionalFields -from manage_breast_screening.participants.models.other_procedure_history_item import ( +from manage_breast_screening.participants.models.medical_history.other_procedure_history_item import ( OtherProcedureHistoryItem, ) -class OtherProcedureHistoryForm(FormWithConditionalFields): +class OtherProcedureHistoryItemForm(FormWithConditionalFields): PROCEDURE_DETAIL_FIELDS = { OtherProcedureHistoryItem.Procedure.BREAST_REDUCTION: "breast_reduction_details", OtherProcedureHistoryItem.Procedure.BREAST_SYMMETRISATION: "breast_symmetrisation_details", diff --git a/manage_breast_screening/mammograms/presenters/benign_lump_history_item_presenter.py b/manage_breast_screening/mammograms/presenters/benign_lump_history_item_presenter.py index 08797d49a..e695796d0 100644 --- a/manage_breast_screening/mammograms/presenters/benign_lump_history_item_presenter.py +++ b/manage_breast_screening/mammograms/presenters/benign_lump_history_item_presenter.py @@ -1,7 +1,7 @@ from django.urls import reverse from manage_breast_screening.core.template_helpers import multiline_content, nl2br -from manage_breast_screening.participants.models.benign_lump_history_item import ( +from manage_breast_screening.participants.models.medical_history.benign_lump_history_item import ( BenignLumpHistoryItem, ) diff --git a/manage_breast_screening/mammograms/presenters/breast_augmentation_history_item_presenter.py b/manage_breast_screening/mammograms/presenters/breast_augmentation_history_item_presenter.py index 12068d84c..7344a4193 100644 --- a/manage_breast_screening/mammograms/presenters/breast_augmentation_history_item_presenter.py +++ b/manage_breast_screening/mammograms/presenters/breast_augmentation_history_item_presenter.py @@ -1,7 +1,7 @@ from django.urls import reverse from manage_breast_screening.core.template_helpers import multiline_content, nl2br -from manage_breast_screening.participants.models.breast_augmentation_history_item import ( +from manage_breast_screening.participants.models.medical_history.breast_augmentation_history_item import ( BreastAugmentationHistoryItem, ) diff --git a/manage_breast_screening/mammograms/presenters/breast_cancer_history_item_presenter.py b/manage_breast_screening/mammograms/presenters/breast_cancer_history_item_presenter.py index 714569ad4..881ba8a82 100644 --- a/manage_breast_screening/mammograms/presenters/breast_cancer_history_item_presenter.py +++ b/manage_breast_screening/mammograms/presenters/breast_cancer_history_item_presenter.py @@ -1,7 +1,7 @@ from django.urls import reverse from manage_breast_screening.core.template_helpers import multiline_content, nl2br -from manage_breast_screening.participants.models.breast_cancer_history_item import ( +from manage_breast_screening.participants.models.medical_history.breast_cancer_history_item import ( BreastCancerHistoryItem, ) diff --git a/manage_breast_screening/mammograms/presenters/mastectomy_or_lumpectomy_history_item_presenter.py b/manage_breast_screening/mammograms/presenters/mastectomy_or_lumpectomy_history_item_presenter.py index 87453cddd..481c1303b 100644 --- a/manage_breast_screening/mammograms/presenters/mastectomy_or_lumpectomy_history_item_presenter.py +++ b/manage_breast_screening/mammograms/presenters/mastectomy_or_lumpectomy_history_item_presenter.py @@ -1,7 +1,7 @@ from django.urls import reverse from manage_breast_screening.core.template_helpers import multiline_content, nl2br -from manage_breast_screening.participants.models.mastectomy_or_lumpectomy_history_item import ( +from manage_breast_screening.participants.models.medical_history.mastectomy_or_lumpectomy_history_item import ( MastectomyOrLumpectomyHistoryItem, ) diff --git a/manage_breast_screening/mammograms/tests/forms/medical_history/__init__.py b/manage_breast_screening/mammograms/tests/forms/medical_history/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/manage_breast_screening/mammograms/tests/forms/test_benign_lump_history_item_form.py b/manage_breast_screening/mammograms/tests/forms/medical_history/test_benign_lump_history_item_form.py similarity index 97% rename from manage_breast_screening/mammograms/tests/forms/test_benign_lump_history_item_form.py rename to manage_breast_screening/mammograms/tests/forms/medical_history/test_benign_lump_history_item_form.py index 32e07fb43..fb30db8d9 100644 --- a/manage_breast_screening/mammograms/tests/forms/test_benign_lump_history_item_form.py +++ b/manage_breast_screening/mammograms/tests/forms/medical_history/test_benign_lump_history_item_form.py @@ -5,10 +5,10 @@ from django.http import QueryDict from django.test import RequestFactory -from manage_breast_screening.mammograms.forms.benign_lump_history_item_form import ( +from manage_breast_screening.mammograms.forms.medical_history.benign_lump_history_item_form import ( BenignLumpHistoryItemForm, ) -from manage_breast_screening.participants.models.benign_lump_history_item import ( +from manage_breast_screening.participants.models.medical_history.benign_lump_history_item import ( BenignLumpHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( diff --git a/manage_breast_screening/mammograms/tests/forms/test_breast_augmentation_history_form.py b/manage_breast_screening/mammograms/tests/forms/medical_history/test_breast_augmentation_history_item_form.py similarity index 92% rename from manage_breast_screening/mammograms/tests/forms/test_breast_augmentation_history_form.py rename to manage_breast_screening/mammograms/tests/forms/medical_history/test_breast_augmentation_history_item_form.py index 42e08c6ce..c3240b78e 100644 --- a/manage_breast_screening/mammograms/tests/forms/test_breast_augmentation_history_form.py +++ b/manage_breast_screening/mammograms/tests/forms/medical_history/test_breast_augmentation_history_item_form.py @@ -6,7 +6,7 @@ from django.test import RequestFactory from manage_breast_screening.core.models import AuditLog -from manage_breast_screening.participants.models.breast_augmentation_history_item import ( +from manage_breast_screening.participants.models.medical_history.breast_augmentation_history_item import ( BreastAugmentationHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( @@ -14,19 +14,31 @@ BreastAugmentationHistoryItemFactory, ) -from ...forms.breast_augmentation_history_form import ( - BreastAugmentationHistoryForm, - BreastAugmentationHistoryUpdateForm, +from ....forms.medical_history.breast_augmentation_history_item_form import ( + BreastAugmentationHistoryItemForm, ) @pytest.mark.django_db -class TestBreastAugmentationHistoryForm: +class TestBreastAugmentationHistoryItemForm: + @pytest.fixture + def instance(self): + return BreastAugmentationHistoryItemFactory( + right_breast_procedures=[ + BreastAugmentationHistoryItem.Procedure.BREAST_IMPLANTS + ], + left_breast_procedures=[ + BreastAugmentationHistoryItem.Procedure.BREAST_IMPLANTS + ], + procedure_year=2000, + implants_have_been_removed=False, + ) + def test_no_data(self, clinical_user): request = RequestFactory().get("/test-form") request.user = clinical_user - form = BreastAugmentationHistoryForm(QueryDict()) + form = BreastAugmentationHistoryItemForm(QueryDict()) assert not form.is_valid() assert form.errors == { @@ -38,7 +50,7 @@ def test_procedure_year_invalid_format(self, clinical_user): request = RequestFactory().get("/test-form") request.user = clinical_user - form = BreastAugmentationHistoryForm( + form = BreastAugmentationHistoryItemForm( QueryDict( urlencode( { @@ -82,7 +94,7 @@ def test_no_procedures_and_other_options( request = RequestFactory().get("/test-form") request.user = clinical_user - form = BreastAugmentationHistoryForm( + form = BreastAugmentationHistoryItemForm( QueryDict( urlencode( { @@ -103,7 +115,7 @@ def test_no_procedures_and_other_options( ] } - form = BreastAugmentationHistoryForm( + form = BreastAugmentationHistoryItemForm( QueryDict( urlencode( { @@ -128,7 +140,7 @@ def test_removal_year_invalid_format(self, clinical_user): request = RequestFactory().get("/test-form") request.user = clinical_user - form = BreastAugmentationHistoryForm( + form = BreastAugmentationHistoryItemForm( QueryDict( urlencode( { @@ -174,7 +186,7 @@ def test_procedure_year_outside_range(self, clinical_user, procedure_year): if procedure_year > max_year else (f"Year must be {min_year} or later") ) - form = BreastAugmentationHistoryForm( + form = BreastAugmentationHistoryItemForm( QueryDict( urlencode( { @@ -215,7 +227,7 @@ def test_removal_year_outside_range(self, clinical_user, removal_year): if removal_year > max_year else (f"Year must be {min_year} or later") ) - form = BreastAugmentationHistoryForm( + form = BreastAugmentationHistoryItemForm( QueryDict( urlencode( { @@ -254,7 +266,7 @@ def test_removal_year_before_procedure_year( request = RequestFactory().get("/test-form") request.user = clinical_user - form = BreastAugmentationHistoryForm( + form = BreastAugmentationHistoryItemForm( QueryDict( urlencode( { @@ -283,7 +295,7 @@ def test_removal_year_when_not_removed(self, clinical_user): request = RequestFactory().get("/test-form") request.user = clinical_user - form = BreastAugmentationHistoryForm( + form = BreastAugmentationHistoryItemForm( QueryDict( urlencode( { @@ -411,19 +423,21 @@ def test_removal_year_when_not_removed(self, clinical_user): }, ], ) - def test_success(self, clinical_user, data): + def test_valid_create(self, clinical_user, data): appointment = AppointmentFactory() request = RequestFactory().get("/test-form") request.user = clinical_user - form = BreastAugmentationHistoryForm( + form = BreastAugmentationHistoryItemForm( QueryDict(urlencode(data, doseq=True)), ) assert form.is_valid() existing_log_count = AuditLog.objects.count() + obj = form.create(appointment=appointment, request=request) + assert AuditLog.objects.count() == existing_log_count + 1 audit_log = AuditLog.objects.filter( object_id=obj.pk, operation=AuditLog.Operations.CREATE @@ -439,33 +453,8 @@ def test_success(self, clinical_user, data): assert obj.removal_year == data.get("removal_year", None) assert obj.additional_details == data.get("additional_details", "") - -@pytest.mark.django_db -class TestBreastAugmentationHistoryUpdateForm: - @pytest.fixture - def instance(self): - return BreastAugmentationHistoryItemFactory( - right_breast_procedures=[ - BreastAugmentationHistoryItem.Procedure.BREAST_IMPLANTS - ], - left_breast_procedures=[ - BreastAugmentationHistoryItem.Procedure.BREAST_IMPLANTS - ], - procedure_year=2000, - implants_have_been_removed=False, - ) - - def test_no_data(self, instance): - form = BreastAugmentationHistoryUpdateForm(instance, QueryDict()) - - assert not form.is_valid() - assert form.errors == { - "left_breast_procedures": ["Select procedures for the left breast"], - "right_breast_procedures": ["Select procedures for the right breast"], - } - def test_initial(self, instance): - form = BreastAugmentationHistoryUpdateForm(instance, QueryDict()) + form = BreastAugmentationHistoryItemForm(instance=instance, data=QueryDict()) assert form.initial == { "right_breast_procedures": [ BreastAugmentationHistoryItem.Procedure.BREAST_IMPLANTS @@ -480,9 +469,9 @@ def test_initial(self, instance): } def test_success(self, instance, dummy_request): - form = BreastAugmentationHistoryUpdateForm( - instance, - QueryDict( + form = BreastAugmentationHistoryItemForm( + instance=instance, + data=QueryDict( urlencode( { "right_breast_procedures": [ diff --git a/manage_breast_screening/mammograms/tests/forms/test_breast_cancer_history_form.py b/manage_breast_screening/mammograms/tests/forms/medical_history/test_breast_cancer_history_item_form.py similarity index 84% rename from manage_breast_screening/mammograms/tests/forms/test_breast_cancer_history_form.py rename to manage_breast_screening/mammograms/tests/forms/medical_history/test_breast_cancer_history_item_form.py index 8dd65993a..1614dae80 100644 --- a/manage_breast_screening/mammograms/tests/forms/test_breast_cancer_history_form.py +++ b/manage_breast_screening/mammograms/tests/forms/medical_history/test_breast_cancer_history_item_form.py @@ -6,11 +6,10 @@ from django.http import QueryDict from django.test import RequestFactory -from manage_breast_screening.mammograms.forms.breast_cancer_history_form import ( - BreastCancerHistoryForm, - BreastCancerHistoryUpdateForm, +from manage_breast_screening.mammograms.forms.medical_history.breast_cancer_history_item_form import ( + BreastCancerHistoryItemForm, ) -from manage_breast_screening.participants.models.breast_cancer_history_item import ( +from manage_breast_screening.participants.models.medical_history.breast_cancer_history_item import ( BreastCancerHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( @@ -31,9 +30,18 @@ def incoming_request(clinical_user): return request -class TestBreastCancerHistoryForm: +class TestBreastCancerHistoryItemForm: + @pytest.fixture + def instance(self, appointment): + return BreastCancerHistoryItemFactory( + appointment=appointment, + diagnosis_location=BreastCancerHistoryItem.DiagnosisLocationChoices.BOTH_BREASTS, + left_breast_procedure=BreastCancerHistoryItem.Procedure.LUMPECTOMY, + right_breast_procedure=BreastCancerHistoryItem.Procedure.LUMPECTOMY, + ) + def test_no_data_not_valid(self): - form = BreastCancerHistoryForm(data=QueryDict()) + form = BreastCancerHistoryItemForm(data=QueryDict()) assert not form.is_valid() assert form.errors == { "diagnosis_location": ["Select which breasts cancer was diagnosed in"], @@ -62,7 +70,7 @@ def test_no_data_not_valid(self): def test_valid_form(self, time_machine): time_machine.move_to(date(2025, 1, 1)) - form = BreastCancerHistoryForm( + form = BreastCancerHistoryItemForm( data=QueryDict( urlencode( { @@ -87,7 +95,7 @@ def test_valid_form(self, time_machine): def test_invalid_date(self, time_machine): time_machine.move_to(date(2025, 1, 1)) - form = BreastCancerHistoryForm( + form = BreastCancerHistoryItemForm( data=QueryDict( urlencode( { @@ -111,7 +119,7 @@ def test_invalid_date(self, time_machine): assert form.errors == {"diagnosis_year": ["Year must be 1945 or later"]} def test_missing_intervention_location_details(self): - form = BreastCancerHistoryForm( + form = BreastCancerHistoryItemForm( data=QueryDict( urlencode( { @@ -137,7 +145,7 @@ def test_missing_intervention_location_details(self): } def test_missing_systemic_treatments_other_treatment_details(self): - form = BreastCancerHistoryForm( + form = BreastCancerHistoryItemForm( data=QueryDict( urlencode( { @@ -165,7 +173,7 @@ def test_missing_systemic_treatments_other_treatment_details(self): @pytest.mark.django_db def test_create(self, appointment, incoming_request): - form = BreastCancerHistoryForm( + form = BreastCancerHistoryItemForm( data=QueryDict( urlencode( { @@ -213,47 +221,9 @@ def test_create(self, appointment, incoming_request): "systemic_treatments_other_treatment_details": "", } - -@pytest.mark.django_db -class TestBreastCancerHistoryUpdateForm: - @pytest.fixture - def instance(self, appointment): - return BreastCancerHistoryItemFactory( - appointment=appointment, - diagnosis_location=BreastCancerHistoryItem.DiagnosisLocationChoices.BOTH_BREASTS, - left_breast_procedure=BreastCancerHistoryItem.Procedure.LUMPECTOMY, - right_breast_procedure=BreastCancerHistoryItem.Procedure.LUMPECTOMY, - ) - - def test_no_data_not_valid(self, instance): - form = BreastCancerHistoryUpdateForm(instance=instance, data=QueryDict()) - assert not form.is_valid() - assert form.errors == { - "diagnosis_location": ["Select which breasts cancer was diagnosed in"], - "intervention_location": ["Select where surgery and treatment took place"], - "left_breast_other_surgery": [ - "Select any other surgery they have had in the left breast" - ], - "left_breast_procedure": [ - "Select which procedure they have had in the left breast" - ], - "left_breast_treatment": [ - "Select what treatment they have had in the left breast" - ], - "right_breast_other_surgery": [ - "Select any other surgery they have had in the right breast" - ], - "right_breast_procedure": [ - "Select which procedure they have had in the right breast" - ], - "right_breast_treatment": [ - "Select what treatment they have had in the right breast" - ], - "systemic_treatments": ["Select what systemic treatments they have had"], - } - + @pytest.mark.django_db def test_update(self, appointment, instance, incoming_request): - form = BreastCancerHistoryUpdateForm( + form = BreastCancerHistoryItemForm( instance=instance, data=QueryDict( urlencode( diff --git a/manage_breast_screening/mammograms/tests/forms/test_cyst_history_form.py b/manage_breast_screening/mammograms/tests/forms/medical_history/test_cyst_history_item_form.py similarity index 77% rename from manage_breast_screening/mammograms/tests/forms/test_cyst_history_form.py rename to manage_breast_screening/mammograms/tests/forms/medical_history/test_cyst_history_item_form.py index c43c1a5db..e4d0e332f 100644 --- a/manage_breast_screening/mammograms/tests/forms/test_cyst_history_form.py +++ b/manage_breast_screening/mammograms/tests/forms/medical_history/test_cyst_history_item_form.py @@ -3,7 +3,7 @@ import pytest from django.http import QueryDict -from manage_breast_screening.participants.models.cyst_history_item import ( +from manage_breast_screening.participants.models.medical_history.cyst_history_item import ( CystHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( @@ -11,14 +11,14 @@ CystHistoryItemFactory, ) -from ...forms.cyst_history_form import CystHistoryForm, CystHistoryUpdateForm +from ....forms.medical_history.cyst_history_item_form import CystHistoryItemForm @pytest.mark.django_db class TestCystHistoryForm: def test_no_data(self): appointment = AppointmentFactory() - form = CystHistoryForm(QueryDict(), participant=appointment.participant) + form = CystHistoryItemForm(QueryDict(), participant=appointment.participant) assert not form.is_valid() assert form.errors == {"treatment": ["Select the treatment type"]} @@ -42,9 +42,9 @@ def test_no_data(self): }, ], ) - def test_success(self, data, dummy_request): + def test_valid_create(self, data, dummy_request): appointment = AppointmentFactory() - form = CystHistoryForm( + form = CystHistoryItemForm( QueryDict(urlencode(data, doseq=True)), participant=appointment.participant, ) @@ -57,21 +57,12 @@ def test_success(self, data, dummy_request): assert obj.treatment == data.get("treatment") assert obj.additional_details == data.get("additional_details", "") - -@pytest.mark.django_db -class TestCystHistoryUpdateForm: @pytest.fixture def instance(self): return CystHistoryItemFactory( treatment=CystHistoryItem.Treatment.DRAINAGE_OR_REMOVAL ) - def test_no_data(self, instance): - form = CystHistoryUpdateForm(instance, QueryDict()) - - assert not form.is_valid() - assert form.errors == {"treatment": ["Select the treatment type"]} - @pytest.mark.parametrize( "data", [ @@ -91,10 +82,11 @@ def test_no_data(self, instance): }, ], ) - def test_success(self, instance, data, dummy_request): - form = CystHistoryUpdateForm( - instance, - QueryDict(urlencode(data, doseq=True)), + def test_valid_update(self, instance, data, dummy_request): + form = CystHistoryItemForm( + instance=instance, + participant=instance.appointment.participant, + data=QueryDict(urlencode(data, doseq=True)), ) assert form.is_valid() diff --git a/manage_breast_screening/mammograms/tests/forms/test_implanted_medical_device_history_form.py b/manage_breast_screening/mammograms/tests/forms/medical_history/test_implanted_medical_device_history_item_form.py similarity index 89% rename from manage_breast_screening/mammograms/tests/forms/test_implanted_medical_device_history_form.py rename to manage_breast_screening/mammograms/tests/forms/medical_history/test_implanted_medical_device_history_item_form.py index 1b6ff13ce..0ec72026a 100644 --- a/manage_breast_screening/mammograms/tests/forms/test_implanted_medical_device_history_form.py +++ b/manage_breast_screening/mammograms/tests/forms/medical_history/test_implanted_medical_device_history_item_form.py @@ -5,7 +5,7 @@ from django.http import QueryDict from django.test import RequestFactory -from manage_breast_screening.participants.models.implanted_medical_device_history_item import ( +from manage_breast_screening.participants.models.medical_history.implanted_medical_device_history_item import ( ImplantedMedicalDeviceHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( @@ -13,9 +13,8 @@ ImplantedMedicalDeviceHistoryItemFactory, ) -from ...forms.implanted_medical_device_history_form import ( - ImplantedMedicalDeviceHistoryForm, - ImplantedMedicalDeviceHistoryUpdateForm, +from ....forms.medical_history.implanted_medical_device_history_item_form import ( + ImplantedMedicalDeviceHistoryItemForm, ) @@ -27,10 +26,10 @@ def dummy_request(clinical_user): @pytest.mark.django_db -class TestImplantedMedicalDeviceHistoryForm: +class TestImplantedMedicalDeviceHistoryItemForm: def test_no_data(self): appointment = AppointmentFactory() - form = ImplantedMedicalDeviceHistoryForm( + form = ImplantedMedicalDeviceHistoryItemForm( QueryDict(), participant=appointment.participant ) @@ -40,7 +39,7 @@ def test_no_data(self): def test_other_device_without_information(self): appointment = AppointmentFactory() - form = ImplantedMedicalDeviceHistoryForm( + form = ImplantedMedicalDeviceHistoryItemForm( QueryDict( urlencode( { @@ -59,7 +58,7 @@ def test_other_device_without_information(self): def test_procedure_year_invalid_format(self): appointment = AppointmentFactory() - form = ImplantedMedicalDeviceHistoryForm( + form = ImplantedMedicalDeviceHistoryItemForm( QueryDict( urlencode( { @@ -77,7 +76,7 @@ def test_procedure_year_invalid_format(self): def test_removal_year_invalid_format(self): appointment = AppointmentFactory() - form = ImplantedMedicalDeviceHistoryForm( + form = ImplantedMedicalDeviceHistoryItemForm( QueryDict( urlencode( { @@ -117,7 +116,7 @@ def test_procedure_year_outside_range(self, procedure_year): if procedure_year > max_year else (f"Year must be {min_year} or later") ) - form = ImplantedMedicalDeviceHistoryForm( + form = ImplantedMedicalDeviceHistoryItemForm( QueryDict( urlencode( { @@ -152,7 +151,7 @@ def test_removal_year_outside_range(self, removal_year): if removal_year > max_year else (f"Year must be {min_year} or later") ) - form = ImplantedMedicalDeviceHistoryForm( + form = ImplantedMedicalDeviceHistoryItemForm( QueryDict( urlencode( { @@ -183,7 +182,7 @@ def test_removal_year_outside_range(self, removal_year): def test_removal_year_before_procedure_year(self, procedure_year, removal_year): appointment = AppointmentFactory() - form = ImplantedMedicalDeviceHistoryForm( + form = ImplantedMedicalDeviceHistoryItemForm( QueryDict( urlencode( { @@ -205,7 +204,7 @@ def test_removal_year_before_procedure_year(self, procedure_year, removal_year): def test_removal_year_when_not_removed(self, dummy_request): appointment = AppointmentFactory() - form = ImplantedMedicalDeviceHistoryForm( + form = ImplantedMedicalDeviceHistoryItemForm( QueryDict( urlencode( { @@ -273,10 +272,10 @@ def test_removal_year_when_not_removed(self, dummy_request): }, ], ) - def test_success(self, data, dummy_request): + def test_valid_create(self, data, dummy_request): appointment = AppointmentFactory() - form = ImplantedMedicalDeviceHistoryForm( + form = ImplantedMedicalDeviceHistoryItemForm( QueryDict(urlencode(data, doseq=True)), participant=appointment.participant, ) @@ -294,21 +293,12 @@ def test_success(self, data, dummy_request): assert obj.removal_year == data.get("removal_year", None) assert obj.additional_details == data.get("additional_details", "") - -@pytest.mark.django_db -class TestImplantedMedicalDeviceHistoryUpdateForm: @pytest.fixture def instance(self): return ImplantedMedicalDeviceHistoryItemFactory( device=ImplantedMedicalDeviceHistoryItem.Device.CARDIAC_DEVICE ) - def test_no_data(self, instance): - form = ImplantedMedicalDeviceHistoryUpdateForm(instance, QueryDict()) - - assert not form.is_valid() - assert form.errors == {"device": ["Select the device type"]} - @pytest.mark.parametrize( "data", [ @@ -325,10 +315,11 @@ def test_no_data(self, instance): }, ], ) - def test_success(self, instance, data, dummy_request): - form = ImplantedMedicalDeviceHistoryUpdateForm( - instance, - QueryDict(urlencode(data, doseq=True)), + def test_valid_update(self, instance, data, dummy_request): + form = ImplantedMedicalDeviceHistoryItemForm( + instance=instance, + participant=instance.appointment.participant, + data=QueryDict(urlencode(data, doseq=True)), ) assert form.is_valid() diff --git a/manage_breast_screening/mammograms/tests/forms/test_mastectomy_or_lumpectomy_history_form.py b/manage_breast_screening/mammograms/tests/forms/medical_history/test_mastectomy_or_lumpectomy_history_item_form.py similarity index 90% rename from manage_breast_screening/mammograms/tests/forms/test_mastectomy_or_lumpectomy_history_form.py rename to manage_breast_screening/mammograms/tests/forms/medical_history/test_mastectomy_or_lumpectomy_history_item_form.py index 8ddf7bace..ba4ca4887 100644 --- a/manage_breast_screening/mammograms/tests/forms/test_mastectomy_or_lumpectomy_history_form.py +++ b/manage_breast_screening/mammograms/tests/forms/medical_history/test_mastectomy_or_lumpectomy_history_item_form.py @@ -6,7 +6,7 @@ from django.test import RequestFactory from manage_breast_screening.core.models import AuditLog -from manage_breast_screening.participants.models.mastectomy_or_lumpectomy_history_item import ( +from manage_breast_screening.participants.models.medical_history.mastectomy_or_lumpectomy_history_item import ( MastectomyOrLumpectomyHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( @@ -14,8 +14,8 @@ MastectomyOrLumpectomyHistoryItemFactory, ) -from ...forms.mastectomy_or_lumpectomy_history_form import ( - MastectomyOrLumpectomyHistoryForm, +from ....forms.medical_history.mastectomy_or_lumpectomy_history_item_form import ( + MastectomyOrLumpectomyHistoryItemForm, ) @@ -28,8 +28,24 @@ def dummy_request(clinical_user): @pytest.mark.django_db class TestMastectomyOrLumpectomyHistoryItemForm: + @pytest.fixture + def instance(self): + return MastectomyOrLumpectomyHistoryItemFactory( + right_breast_procedure=MastectomyOrLumpectomyHistoryItem.Procedure.NO_PROCEDURE, + left_breast_procedure=MastectomyOrLumpectomyHistoryItem.Procedure.NO_PROCEDURE, + right_breast_other_surgery=[ + MastectomyOrLumpectomyHistoryItem.Surgery.NO_OTHER_SURGERY, + ], + left_breast_other_surgery=[ + MastectomyOrLumpectomyHistoryItem.Surgery.NO_OTHER_SURGERY, + ], + year_of_surgery=None, + surgery_reason=MastectomyOrLumpectomyHistoryItem.SurgeryReason.RISK_REDUCTION, + additional_details="", + ) + def test_missing_required_fields(self): - form = MastectomyOrLumpectomyHistoryForm(QueryDict()) + form = MastectomyOrLumpectomyHistoryItemForm(QueryDict()) assert not form.is_valid() assert form.errors == { @@ -49,7 +65,7 @@ def test_missing_required_fields(self): } def test_right_breast_other_surgery_no_other_surgery_and_others(self): - form = MastectomyOrLumpectomyHistoryForm( + form = MastectomyOrLumpectomyHistoryItemForm( QueryDict( urlencode( { @@ -78,7 +94,7 @@ def test_right_breast_other_surgery_no_other_surgery_and_others(self): } def test_left_breast_other_surgery_no_other_surgery_and_others(self): - form = MastectomyOrLumpectomyHistoryForm( + form = MastectomyOrLumpectomyHistoryItemForm( QueryDict( urlencode( { @@ -116,7 +132,7 @@ def test_left_breast_other_surgery_no_other_surgery_and_others(self): ], ) def test_year_of_surgery_outside_range(self, year_of_surgery): - form = MastectomyOrLumpectomyHistoryForm( + form = MastectomyOrLumpectomyHistoryItemForm( QueryDict( urlencode( { @@ -144,7 +160,7 @@ def test_year_of_surgery_outside_range(self, year_of_surgery): } def test_year_of_surgery_invalid(self): - form = MastectomyOrLumpectomyHistoryForm( + form = MastectomyOrLumpectomyHistoryItemForm( QueryDict( urlencode( { @@ -170,7 +186,7 @@ def test_year_of_surgery_invalid(self): } def test_other_reason_without_details(self): - form = MastectomyOrLumpectomyHistoryForm( + form = MastectomyOrLumpectomyHistoryItemForm( QueryDict( urlencode( { @@ -197,7 +213,7 @@ def test_other_reason_without_details(self): def test_other_reason_details_when_not_other_reason(self, dummy_request): appointment = AppointmentFactory() - form = MastectomyOrLumpectomyHistoryForm( + form = MastectomyOrLumpectomyHistoryItemForm( QueryDict( urlencode( { @@ -289,10 +305,10 @@ def test_other_reason_details_when_not_other_reason(self, dummy_request): }, ], ) - def test_success(self, clinical_user, data, dummy_request): + def test_valid_create(self, clinical_user, data, dummy_request): appointment = AppointmentFactory() - form = MastectomyOrLumpectomyHistoryForm( + form = MastectomyOrLumpectomyHistoryItemForm( QueryDict(urlencode(data, doseq=True)), ) @@ -328,45 +344,6 @@ def create_year_outside_range_error_messsage(self, request_year): else (f"Year must be {min_year} or later") ) - -@pytest.mark.django_db -class TestUpdateMastectomyOrLumpectomyHistoryForm: - @pytest.fixture - def instance(self): - return MastectomyOrLumpectomyHistoryItemFactory( - right_breast_procedure=MastectomyOrLumpectomyHistoryItem.Procedure.NO_PROCEDURE, - left_breast_procedure=MastectomyOrLumpectomyHistoryItem.Procedure.NO_PROCEDURE, - right_breast_other_surgery=[ - MastectomyOrLumpectomyHistoryItem.Surgery.NO_OTHER_SURGERY, - ], - left_breast_other_surgery=[ - MastectomyOrLumpectomyHistoryItem.Surgery.NO_OTHER_SURGERY, - ], - year_of_surgery=None, - surgery_reason=MastectomyOrLumpectomyHistoryItem.SurgeryReason.RISK_REDUCTION, - additional_details="", - ) - - def test_no_data(self, instance): - form = MastectomyOrLumpectomyHistoryForm(QueryDict(), instance=instance) - - assert not form.is_valid() - assert form.errors == { - "right_breast_procedure": [ - "Select which procedure they have had in the right breast", - ], - "left_breast_procedure": [ - "Select which procedure they have had in the left breast", - ], - "right_breast_other_surgery": [ - "Select any other surgery they have had in the right breast", - ], - "left_breast_other_surgery": [ - "Select any other surgery they have had in the left breast", - ], - "surgery_reason": ["Select the reason for surgery"], - } - @pytest.mark.parametrize( "data", [ @@ -386,8 +363,8 @@ def test_no_data(self, instance): }, ], ) - def test_success(self, instance, data, dummy_request): - form = MastectomyOrLumpectomyHistoryForm( + def test_valid_update(self, instance, data, dummy_request): + form = MastectomyOrLumpectomyHistoryItemForm( QueryDict(urlencode(data, doseq=True)), instance=instance, ) diff --git a/manage_breast_screening/mammograms/tests/forms/test_other_procedure_history_form.py b/manage_breast_screening/mammograms/tests/forms/medical_history/test_other_procedure_history_form.py similarity index 92% rename from manage_breast_screening/mammograms/tests/forms/test_other_procedure_history_form.py rename to manage_breast_screening/mammograms/tests/forms/medical_history/test_other_procedure_history_form.py index 3808efd05..5ee67b5f8 100644 --- a/manage_breast_screening/mammograms/tests/forms/test_other_procedure_history_form.py +++ b/manage_breast_screening/mammograms/tests/forms/medical_history/test_other_procedure_history_form.py @@ -4,7 +4,7 @@ import pytest from django.http import QueryDict -from manage_breast_screening.participants.models.other_procedure_history_item import ( +from manage_breast_screening.participants.models.medical_history.other_procedure_history_item import ( OtherProcedureHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( @@ -12,7 +12,9 @@ OtherProcedureHistoryItemFactory, ) -from ...forms.other_procedure_history_form import OtherProcedureHistoryForm +from ....forms.medical_history.other_procedure_history_item_form import ( + OtherProcedureHistoryItemForm, +) @pytest.mark.django_db @@ -26,7 +28,7 @@ def instance(self): def test_create_with_no_data(self): appointment = AppointmentFactory() - form = OtherProcedureHistoryForm( + form = OtherProcedureHistoryItemForm( QueryDict(), participant=appointment.participant ) @@ -35,7 +37,7 @@ def test_create_with_no_data(self): def test_update_with_no_data(self, instance): appointment = AppointmentFactory() - form = OtherProcedureHistoryForm( + form = OtherProcedureHistoryItemForm( QueryDict(), instance=instance, participant=appointment.participant ) @@ -63,7 +65,7 @@ def test_update_with_no_data(self, instance): def test_procedure_without_details(self, procedure, procedure_details_field): appointment = AppointmentFactory() - form = OtherProcedureHistoryForm( + form = OtherProcedureHistoryItemForm( QueryDict( urlencode( { @@ -82,7 +84,7 @@ def test_procedure_without_details(self, procedure, procedure_details_field): def test_procedure_year_invalid_format(self): appointment = AppointmentFactory() - form = OtherProcedureHistoryForm( + form = OtherProcedureHistoryItemForm( QueryDict( urlencode( { @@ -118,7 +120,7 @@ def test_procedure_year_outside_range(self, procedure_year): if procedure_year > max_year else (f"Year must be {min_year} or later") ) - form = OtherProcedureHistoryForm( + form = OtherProcedureHistoryItemForm( QueryDict( urlencode( { @@ -163,7 +165,7 @@ def test_procedure_year_outside_range(self, procedure_year): ) def test_create_success(self, data, dummy_request): appointment = AppointmentFactory() - form = OtherProcedureHistoryForm( + form = OtherProcedureHistoryItemForm( QueryDict(urlencode(data, doseq=True)), participant=appointment.participant, ) @@ -180,7 +182,7 @@ def test_create_success(self, data, dummy_request): ) def test_update_success(self, instance, data, dummy_request): appointment = AppointmentFactory() - form = OtherProcedureHistoryForm( + form = OtherProcedureHistoryItemForm( QueryDict(urlencode(data, doseq=True)), instance=instance, participant=appointment.participant, diff --git a/manage_breast_screening/mammograms/tests/presenters/test_benign_lump_history_item_presenter.py b/manage_breast_screening/mammograms/tests/presenters/test_benign_lump_history_item_presenter.py index e29a5bfbb..98a2a167b 100644 --- a/manage_breast_screening/mammograms/tests/presenters/test_benign_lump_history_item_presenter.py +++ b/manage_breast_screening/mammograms/tests/presenters/test_benign_lump_history_item_presenter.py @@ -1,7 +1,7 @@ from manage_breast_screening.mammograms.presenters.benign_lump_history_item_presenter import ( BenignLumpHistoryItemPresenter, ) -from manage_breast_screening.participants.models.benign_lump_history_item import ( +from manage_breast_screening.participants.models.medical_history.benign_lump_history_item import ( BenignLumpHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( diff --git a/manage_breast_screening/mammograms/tests/presenters/test_breast_augmentation_history_item_presenter.py b/manage_breast_screening/mammograms/tests/presenters/test_breast_augmentation_history_item_presenter.py index 30d3ac020..359e482f8 100644 --- a/manage_breast_screening/mammograms/tests/presenters/test_breast_augmentation_history_item_presenter.py +++ b/manage_breast_screening/mammograms/tests/presenters/test_breast_augmentation_history_item_presenter.py @@ -1,7 +1,7 @@ from manage_breast_screening.mammograms.presenters.breast_augmentation_history_item_presenter import ( BreastAugmentationHistoryItemPresenter, ) -from manage_breast_screening.participants.models.breast_augmentation_history_item import ( +from manage_breast_screening.participants.models.medical_history.breast_augmentation_history_item import ( BreastAugmentationHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( diff --git a/manage_breast_screening/mammograms/tests/presenters/test_breast_cancer_history_item_presenter.py b/manage_breast_screening/mammograms/tests/presenters/test_breast_cancer_history_item_presenter.py index d32340794..7ba0cff89 100644 --- a/manage_breast_screening/mammograms/tests/presenters/test_breast_cancer_history_item_presenter.py +++ b/manage_breast_screening/mammograms/tests/presenters/test_breast_cancer_history_item_presenter.py @@ -1,7 +1,7 @@ from manage_breast_screening.mammograms.presenters.breast_cancer_history_item_presenter import ( BreastCancerHistoryItemPresenter, ) -from manage_breast_screening.participants.models.breast_cancer_history_item import ( +from manage_breast_screening.participants.models.medical_history.breast_cancer_history_item import ( BreastCancerHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( diff --git a/manage_breast_screening/mammograms/tests/presenters/test_cyst_history_item_presenter.py b/manage_breast_screening/mammograms/tests/presenters/test_cyst_history_item_presenter.py index 6b0146a0e..292cd6466 100644 --- a/manage_breast_screening/mammograms/tests/presenters/test_cyst_history_item_presenter.py +++ b/manage_breast_screening/mammograms/tests/presenters/test_cyst_history_item_presenter.py @@ -1,7 +1,7 @@ from manage_breast_screening.mammograms.presenters.cyst_history_item_presenter import ( CystHistoryItemPresenter, ) -from manage_breast_screening.participants.models.cyst_history_item import ( +from manage_breast_screening.participants.models.medical_history.cyst_history_item import ( CystHistoryItem, ) from manage_breast_screening.participants.tests.factories import CystHistoryItemFactory diff --git a/manage_breast_screening/mammograms/tests/presenters/test_implanted_medical_device_history_item_presenter.py b/manage_breast_screening/mammograms/tests/presenters/test_implanted_medical_device_history_item_presenter.py index dd06b015c..7af0002a3 100644 --- a/manage_breast_screening/mammograms/tests/presenters/test_implanted_medical_device_history_item_presenter.py +++ b/manage_breast_screening/mammograms/tests/presenters/test_implanted_medical_device_history_item_presenter.py @@ -1,7 +1,7 @@ from manage_breast_screening.mammograms.presenters.implanted_medical_device_history_item_presenter import ( ImplantedMedicalDeviceHistoryItemPresenter, ) -from manage_breast_screening.participants.models.implanted_medical_device_history_item import ( +from manage_breast_screening.participants.models.medical_history.implanted_medical_device_history_item import ( ImplantedMedicalDeviceHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( diff --git a/manage_breast_screening/mammograms/tests/presenters/test_mastectomy_or_lumpectomy_history_item_presenter.py b/manage_breast_screening/mammograms/tests/presenters/test_mastectomy_or_lumpectomy_history_item_presenter.py index b330a561d..55f496e6f 100644 --- a/manage_breast_screening/mammograms/tests/presenters/test_mastectomy_or_lumpectomy_history_item_presenter.py +++ b/manage_breast_screening/mammograms/tests/presenters/test_mastectomy_or_lumpectomy_history_item_presenter.py @@ -1,7 +1,7 @@ from manage_breast_screening.mammograms.presenters.mastectomy_or_lumpectomy_history_item_presenter import ( MastectomyOrLumpectomyHistoryItemPresenter, ) -from manage_breast_screening.participants.models.mastectomy_or_lumpectomy_history_item import ( +from manage_breast_screening.participants.models.medical_history.mastectomy_or_lumpectomy_history_item import ( MastectomyOrLumpectomyHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( diff --git a/manage_breast_screening/mammograms/tests/presenters/test_other_procedure_history_item_presenter.py b/manage_breast_screening/mammograms/tests/presenters/test_other_procedure_history_item_presenter.py index 0d95ae0d2..692f2cf49 100644 --- a/manage_breast_screening/mammograms/tests/presenters/test_other_procedure_history_item_presenter.py +++ b/manage_breast_screening/mammograms/tests/presenters/test_other_procedure_history_item_presenter.py @@ -1,7 +1,7 @@ from manage_breast_screening.mammograms.presenters.other_procedure_history_item_presenter import ( OtherProcedureHistoryItemPresenter, ) -from manage_breast_screening.participants.models.other_procedure_history_item import ( +from manage_breast_screening.participants.models.medical_history.other_procedure_history_item import ( OtherProcedureHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( diff --git a/manage_breast_screening/mammograms/tests/views/medical_history/__init__.py b/manage_breast_screening/mammograms/tests/views/medical_history/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/manage_breast_screening/mammograms/tests/views/test_breast_augmentation_history_views.py b/manage_breast_screening/mammograms/tests/views/medical_history/test_breast_augmentation_history_views.py similarity index 97% rename from manage_breast_screening/mammograms/tests/views/test_breast_augmentation_history_views.py rename to manage_breast_screening/mammograms/tests/views/medical_history/test_breast_augmentation_history_views.py index 74aafad7e..a3edcd5f1 100644 --- a/manage_breast_screening/mammograms/tests/views/test_breast_augmentation_history_views.py +++ b/manage_breast_screening/mammograms/tests/views/medical_history/test_breast_augmentation_history_views.py @@ -6,7 +6,7 @@ from django.urls import reverse from pytest_django.asserts import assertInHTML, assertMessages, assertRedirects -from manage_breast_screening.participants.models.breast_augmentation_history_item import ( +from manage_breast_screening.participants.models.medical_history.breast_augmentation_history_item import ( BreastAugmentationHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( diff --git a/manage_breast_screening/mammograms/tests/views/test_breast_cancer_history_views.py b/manage_breast_screening/mammograms/tests/views/medical_history/test_breast_cancer_history_views.py similarity index 98% rename from manage_breast_screening/mammograms/tests/views/test_breast_cancer_history_views.py rename to manage_breast_screening/mammograms/tests/views/medical_history/test_breast_cancer_history_views.py index 9c5f95f75..69c4253ee 100644 --- a/manage_breast_screening/mammograms/tests/views/test_breast_cancer_history_views.py +++ b/manage_breast_screening/mammograms/tests/views/medical_history/test_breast_cancer_history_views.py @@ -3,7 +3,7 @@ from django.urls import reverse from pytest_django.asserts import assertInHTML, assertMessages, assertRedirects -from manage_breast_screening.participants.models.breast_cancer_history_item import ( +from manage_breast_screening.participants.models.medical_history.breast_cancer_history_item import ( BreastCancerHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( diff --git a/manage_breast_screening/mammograms/tests/views/test_cyst_history_views.py b/manage_breast_screening/mammograms/tests/views/medical_history/test_cyst_history_views.py similarity index 97% rename from manage_breast_screening/mammograms/tests/views/test_cyst_history_views.py rename to manage_breast_screening/mammograms/tests/views/medical_history/test_cyst_history_views.py index 57ef80a19..7c56d25f2 100644 --- a/manage_breast_screening/mammograms/tests/views/test_cyst_history_views.py +++ b/manage_breast_screening/mammograms/tests/views/medical_history/test_cyst_history_views.py @@ -3,7 +3,7 @@ from django.urls import reverse from pytest_django.asserts import assertInHTML, assertMessages, assertRedirects -from manage_breast_screening.participants.models.cyst_history_item import ( +from manage_breast_screening.participants.models.medical_history.cyst_history_item import ( CystHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( diff --git a/manage_breast_screening/mammograms/tests/views/test_implanted_medical_device_history_views.py b/manage_breast_screening/mammograms/tests/views/medical_history/test_implanted_medical_device_history_views.py similarity index 97% rename from manage_breast_screening/mammograms/tests/views/test_implanted_medical_device_history_views.py rename to manage_breast_screening/mammograms/tests/views/medical_history/test_implanted_medical_device_history_views.py index c0b1b4bfb..932d16610 100644 --- a/manage_breast_screening/mammograms/tests/views/test_implanted_medical_device_history_views.py +++ b/manage_breast_screening/mammograms/tests/views/medical_history/test_implanted_medical_device_history_views.py @@ -3,7 +3,7 @@ from django.urls import reverse from pytest_django.asserts import assertInHTML, assertMessages, assertRedirects -from manage_breast_screening.participants.models.implanted_medical_device_history_item import ( +from manage_breast_screening.participants.models.medical_history.implanted_medical_device_history_item import ( ImplantedMedicalDeviceHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( diff --git a/manage_breast_screening/mammograms/tests/views/test_mastectomy_or_lumpectomy_history_views.py b/manage_breast_screening/mammograms/tests/views/medical_history/test_mastectomy_or_lumpectomy_history_views.py similarity index 98% rename from manage_breast_screening/mammograms/tests/views/test_mastectomy_or_lumpectomy_history_views.py rename to manage_breast_screening/mammograms/tests/views/medical_history/test_mastectomy_or_lumpectomy_history_views.py index dc8940fba..b013f0a6b 100644 --- a/manage_breast_screening/mammograms/tests/views/test_mastectomy_or_lumpectomy_history_views.py +++ b/manage_breast_screening/mammograms/tests/views/medical_history/test_mastectomy_or_lumpectomy_history_views.py @@ -3,7 +3,7 @@ from django.urls import reverse from pytest_django.asserts import assertInHTML, assertMessages, assertRedirects -from manage_breast_screening.participants.models.mastectomy_or_lumpectomy_history_item import ( +from manage_breast_screening.participants.models.medical_history.mastectomy_or_lumpectomy_history_item import ( MastectomyOrLumpectomyHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( diff --git a/manage_breast_screening/mammograms/tests/views/test_other_procedure_history_view.py b/manage_breast_screening/mammograms/tests/views/medical_history/test_other_procedure_history_views.py similarity index 98% rename from manage_breast_screening/mammograms/tests/views/test_other_procedure_history_view.py rename to manage_breast_screening/mammograms/tests/views/medical_history/test_other_procedure_history_views.py index 7ab80c6b7..e568293ce 100644 --- a/manage_breast_screening/mammograms/tests/views/test_other_procedure_history_view.py +++ b/manage_breast_screening/mammograms/tests/views/medical_history/test_other_procedure_history_views.py @@ -3,7 +3,7 @@ from django.urls import reverse from pytest_django.asserts import assertInHTML, assertMessages, assertRedirects -from manage_breast_screening.participants.models.other_procedure_history_item import ( +from manage_breast_screening.participants.models.medical_history.other_procedure_history_item import ( OtherProcedureHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( diff --git a/manage_breast_screening/mammograms/urls.py b/manage_breast_screening/mammograms/urls.py index 4282aa30f..1ddc27e31 100644 --- a/manage_breast_screening/mammograms/urls.py +++ b/manage_breast_screening/mammograms/urls.py @@ -1,16 +1,14 @@ from django.urls import path -from .views import ( - appointment_views, +from .views import appointment_views, special_appointment_views, symptom_views +from .views.medical_history import ( benign_lump_history_item_views, - breast_augmentation_history_views, - breast_cancer_history_views, - cyst_history_view, - implanted_medical_device_history_view, - mastectomy_or_lumpectomy_history_view, - other_procedure_history_view, - special_appointment_views, - symptom_views, + breast_augmentation_history_item_views, + breast_cancer_history_item_views, + cyst_history_item_views, + implanted_medical_device_history_item_views, + mastectomy_or_lumpectomy_history_item_views, + other_procedure_history_item_views, ) app_name = "mammograms" @@ -133,47 +131,47 @@ ), path( "/record-medical-information/breast-cancer-history/", - breast_cancer_history_views.AddBreastCancerHistoryView.as_view(), + breast_cancer_history_item_views.AddBreastCancerHistoryView.as_view(), name="add_breast_cancer_history_item", ), path( "/record-medical-information/breast-cancer-history/", - breast_cancer_history_views.ChangeBreastCancerHistoryView.as_view(), + breast_cancer_history_item_views.UpdateBreastCancerHistoryView.as_view(), name="change_breast_cancer_history_item", ), path( "/record-medical-information/breast-cancer-history//delete", - breast_cancer_history_views.DeleteBreastCancerHistoryView.as_view(), + breast_cancer_history_item_views.DeleteBreastCancerHistoryView.as_view(), name="delete_breast_cancer_history_item", ), path( "/record-medical-information/implanted-medical-device-history/", - implanted_medical_device_history_view.AddImplantedMedicalDeviceHistoryView.as_view(), + implanted_medical_device_history_item_views.AddImplantedMedicalDeviceHistoryView.as_view(), name="add_implanted_medical_device_history_item", ), path( "/record-medical-information/implanted-medical-device-history/", - implanted_medical_device_history_view.ChangeImplantedMedicalDeviceHistoryView.as_view(), + implanted_medical_device_history_item_views.UpdateImplantedMedicalDeviceHistoryView.as_view(), name="change_implanted_medical_device_history_item", ), path( "/record-medical-information/cyst-history/", - cyst_history_view.AddCystHistoryView.as_view(), + cyst_history_item_views.AddCystHistoryView.as_view(), name="add_cyst_history_item", ), path( "/record-medical-information/cyst-history/", - cyst_history_view.ChangeCystHistoryView.as_view(), + cyst_history_item_views.UpdateCystHistoryView.as_view(), name="change_cyst_history_item", ), path( "/record-medical-information/breast-augmentation-history/", - breast_augmentation_history_views.AddBreastAugmentationHistoryView.as_view(), + breast_augmentation_history_item_views.AddBreastAugmentationHistoryView.as_view(), name="add_breast_augmentation_history_item", ), path( "/record-medical-information/breast-augmentation-history/", - breast_augmentation_history_views.ChangeBreastAugmentationHistoryView.as_view(), + breast_augmentation_history_item_views.UpdateBreastAugmentationHistoryView.as_view(), name="change_breast_augmentation_history_item", ), path( @@ -188,27 +186,27 @@ ), path( "/record-medical-information/mastectomy-or-lumpectomy-history/", - mastectomy_or_lumpectomy_history_view.AddMastectomyOrLumpectomyHistoryView.as_view(), + mastectomy_or_lumpectomy_history_item_views.AddMastectomyOrLumpectomyHistoryView.as_view(), name="add_mastectomy_or_lumpectomy_history_item", ), path( "/record-medical-information/mastectomy-or-lumpectomy-history/", - mastectomy_or_lumpectomy_history_view.UpdateMastectomyOrLumpectomyHistoryView.as_view(), + mastectomy_or_lumpectomy_history_item_views.UpdateMastectomyOrLumpectomyHistoryView.as_view(), name="change_mastectomy_or_lumpectomy_history_item", ), path( "/record-medical-information/other-procedure-history/", - other_procedure_history_view.AddOtherProcedureHistoryView.as_view(), + other_procedure_history_item_views.AddOtherProcedureHistoryView.as_view(), name="add_other_procedure_history_item", ), path( "/record-medical-information/other-procedure-history/", - other_procedure_history_view.ChangeOtherProcedureHistoryView.as_view(), + other_procedure_history_item_views.UpdateOtherProcedureHistoryView.as_view(), name="change_other_procedure_history_item", ), path( "/record-medical-information/other-procedure-history//delete", - other_procedure_history_view.DeleteOtherProcedureHistoryView.as_view(), + other_procedure_history_item_views.DeleteOtherProcedureHistoryView.as_view(), name="delete_other_procedure_history_item", ), ] diff --git a/manage_breast_screening/mammograms/views/medical_history/__init__.py b/manage_breast_screening/mammograms/views/medical_history/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/manage_breast_screening/mammograms/views/benign_lump_history_item_views.py b/manage_breast_screening/mammograms/views/medical_history/benign_lump_history_item_views.py similarity index 93% rename from manage_breast_screening/mammograms/views/benign_lump_history_item_views.py rename to manage_breast_screening/mammograms/views/medical_history/benign_lump_history_item_views.py index 12b5b67a1..8d5f500ff 100644 --- a/manage_breast_screening/mammograms/views/benign_lump_history_item_views.py +++ b/manage_breast_screening/mammograms/views/medical_history/benign_lump_history_item_views.py @@ -7,14 +7,14 @@ from django.urls import reverse from django.views.generic import FormView -from manage_breast_screening.mammograms.forms.benign_lump_history_item_form import ( +from manage_breast_screening.mammograms.forms.medical_history.benign_lump_history_item_form import ( BenignLumpHistoryItemForm, ) -from manage_breast_screening.participants.models.benign_lump_history_item import ( +from manage_breast_screening.participants.models.medical_history.benign_lump_history_item import ( BenignLumpHistoryItem, ) -from .mixins import InProgressAppointmentMixin +from ..mixins import InProgressAppointmentMixin logger = logging.getLogger(__name__) diff --git a/manage_breast_screening/mammograms/views/breast_augmentation_history_views.py b/manage_breast_screening/mammograms/views/medical_history/breast_augmentation_history_item_views.py similarity index 89% rename from manage_breast_screening/mammograms/views/breast_augmentation_history_views.py rename to manage_breast_screening/mammograms/views/medical_history/breast_augmentation_history_item_views.py index 349691424..6478368bf 100644 --- a/manage_breast_screening/mammograms/views/breast_augmentation_history_views.py +++ b/manage_breast_screening/mammograms/views/medical_history/breast_augmentation_history_item_views.py @@ -6,15 +6,14 @@ from django.urls import reverse from django.views.generic import FormView -from manage_breast_screening.participants.models.breast_augmentation_history_item import ( +from manage_breast_screening.participants.models.medical_history.breast_augmentation_history_item import ( BreastAugmentationHistoryItem, ) -from ..forms.breast_augmentation_history_form import ( - BreastAugmentationHistoryForm, - BreastAugmentationHistoryUpdateForm, +from ...forms.medical_history.breast_augmentation_history_item_form import ( + BreastAugmentationHistoryItemForm, ) -from .mixins import InProgressAppointmentMixin +from ..mixins import InProgressAppointmentMixin logger = logging.getLogger(__name__) @@ -53,7 +52,7 @@ def get_context_data(self, **kwargs): class AddBreastAugmentationHistoryView(BreastAugmentationHistoryBaseView): - form_class = BreastAugmentationHistoryForm + form_class = BreastAugmentationHistoryItemForm def form_valid(self, form): form.create(appointment=self.appointment, request=self.request) @@ -79,8 +78,8 @@ def get_context_data(self, **kwargs): return context -class ChangeBreastAugmentationHistoryView(BreastAugmentationHistoryBaseView): - form_class = BreastAugmentationHistoryUpdateForm +class UpdateBreastAugmentationHistoryView(BreastAugmentationHistoryBaseView): + form_class = BreastAugmentationHistoryItemForm def get_instance(self): try: diff --git a/manage_breast_screening/mammograms/views/breast_cancer_history_views.py b/manage_breast_screening/mammograms/views/medical_history/breast_cancer_history_item_views.py similarity index 91% rename from manage_breast_screening/mammograms/views/breast_cancer_history_views.py rename to manage_breast_screening/mammograms/views/medical_history/breast_cancer_history_item_views.py index 4c811c50a..fd05ef4c0 100644 --- a/manage_breast_screening/mammograms/views/breast_cancer_history_views.py +++ b/manage_breast_screening/mammograms/views/medical_history/breast_cancer_history_item_views.py @@ -8,15 +8,14 @@ from django.views.generic import FormView from manage_breast_screening.core.views.generic import DeleteWithAuditView -from manage_breast_screening.mammograms.forms.breast_cancer_history_form import ( - BreastCancerHistoryForm, - BreastCancerHistoryUpdateForm, +from manage_breast_screening.mammograms.forms.medical_history.breast_cancer_history_item_form import ( + BreastCancerHistoryItemForm, ) -from manage_breast_screening.participants.models.breast_cancer_history_item import ( +from manage_breast_screening.participants.models.medical_history.breast_cancer_history_item import ( BreastCancerHistoryItem, ) -from .mixins import InProgressAppointmentMixin +from ..mixins import InProgressAppointmentMixin logger = logging.getLogger(__name__) @@ -54,7 +53,7 @@ def get_context_data(self, **kwargs): class AddBreastCancerHistoryView(BaseBreastCancerHistoryView): - form_class = BreastCancerHistoryForm + form_class = BreastCancerHistoryItemForm def form_valid(self, form): form.create(appointment=self.appointment, request=self.request) @@ -80,8 +79,8 @@ def get_context_data(self, **kwargs): return context -class ChangeBreastCancerHistoryView(BaseBreastCancerHistoryView): - form_class = BreastCancerHistoryUpdateForm +class UpdateBreastCancerHistoryView(BaseBreastCancerHistoryView): + form_class = BreastCancerHistoryItemForm def get_instance(self): try: diff --git a/manage_breast_screening/mammograms/views/cyst_history_view.py b/manage_breast_screening/mammograms/views/medical_history/cyst_history_item_views.py similarity index 89% rename from manage_breast_screening/mammograms/views/cyst_history_view.py rename to manage_breast_screening/mammograms/views/medical_history/cyst_history_item_views.py index 3766d307e..34ce630c6 100644 --- a/manage_breast_screening/mammograms/views/cyst_history_view.py +++ b/manage_breast_screening/mammograms/views/medical_history/cyst_history_item_views.py @@ -6,12 +6,12 @@ from django.urls import reverse from django.views.generic import FormView -from manage_breast_screening.participants.models.cyst_history_item import ( +from manage_breast_screening.participants.models.medical_history.cyst_history_item import ( CystHistoryItem, ) -from ..forms.cyst_history_form import CystHistoryForm, CystHistoryUpdateForm -from .mixins import InProgressAppointmentMixin +from ...forms.medical_history.cyst_history_item_form import CystHistoryItemForm +from ..mixins import InProgressAppointmentMixin logger = logging.getLogger(__name__) @@ -51,7 +51,7 @@ def get_context_data(self, **kwargs): class AddCystHistoryView(BaseCystHistoryView): - form_class = CystHistoryForm + form_class = CystHistoryItemForm def form_valid(self, form): form.create(appointment=self.appointment, request=self.request) @@ -82,8 +82,8 @@ def get_form_kwargs(self): return kwargs -class ChangeCystHistoryView(BaseCystHistoryView): - form_class = CystHistoryUpdateForm +class UpdateCystHistoryView(BaseCystHistoryView): + form_class = CystHistoryItemForm def get_instance(self): try: @@ -112,6 +112,7 @@ def post(self, *args, **kwargs): def get_form_kwargs(self): kwargs = super().get_form_kwargs() kwargs["instance"] = self.instance + kwargs["participant"] = self.participant return kwargs def form_valid(self, form): diff --git a/manage_breast_screening/mammograms/views/implanted_medical_device_history_view.py b/manage_breast_screening/mammograms/views/medical_history/implanted_medical_device_history_item_views.py similarity index 90% rename from manage_breast_screening/mammograms/views/implanted_medical_device_history_view.py rename to manage_breast_screening/mammograms/views/medical_history/implanted_medical_device_history_item_views.py index adcca9d47..1a4160ac5 100644 --- a/manage_breast_screening/mammograms/views/implanted_medical_device_history_view.py +++ b/manage_breast_screening/mammograms/views/medical_history/implanted_medical_device_history_item_views.py @@ -6,15 +6,14 @@ from django.urls import reverse from django.views.generic import FormView -from manage_breast_screening.participants.models.implanted_medical_device_history_item import ( +from manage_breast_screening.participants.models.medical_history.implanted_medical_device_history_item import ( ImplantedMedicalDeviceHistoryItem, ) -from ..forms.implanted_medical_device_history_form import ( - ImplantedMedicalDeviceHistoryForm, - ImplantedMedicalDeviceHistoryUpdateForm, +from ...forms.medical_history.implanted_medical_device_history_item_form import ( + ImplantedMedicalDeviceHistoryItemForm, ) -from .mixins import InProgressAppointmentMixin +from ..mixins import InProgressAppointmentMixin logger = logging.getLogger(__name__) @@ -54,7 +53,7 @@ def get_context_data(self, **kwargs): class AddImplantedMedicalDeviceHistoryView(BaseImplantedMedicalDeviceHistoryView): - form_class = ImplantedMedicalDeviceHistoryForm + form_class = ImplantedMedicalDeviceHistoryItemForm def form_valid(self, form): form.create(appointment=self.appointment, request=self.request) @@ -98,8 +97,8 @@ def get_form_kwargs(self): return kwargs -class ChangeImplantedMedicalDeviceHistoryView(BaseImplantedMedicalDeviceHistoryView): - form_class = ImplantedMedicalDeviceHistoryUpdateForm +class UpdateImplantedMedicalDeviceHistoryView(BaseImplantedMedicalDeviceHistoryView): + form_class = ImplantedMedicalDeviceHistoryItemForm def get_instance(self): try: diff --git a/manage_breast_screening/mammograms/views/mastectomy_or_lumpectomy_history_view.py b/manage_breast_screening/mammograms/views/medical_history/mastectomy_or_lumpectomy_history_item_views.py similarity index 91% rename from manage_breast_screening/mammograms/views/mastectomy_or_lumpectomy_history_view.py rename to manage_breast_screening/mammograms/views/medical_history/mastectomy_or_lumpectomy_history_item_views.py index 9988a68ad..33df8dac2 100644 --- a/manage_breast_screening/mammograms/views/mastectomy_or_lumpectomy_history_view.py +++ b/manage_breast_screening/mammograms/views/medical_history/mastectomy_or_lumpectomy_history_item_views.py @@ -10,14 +10,14 @@ from manage_breast_screening.mammograms.presenters.medical_information_presenter import ( MedicalInformationPresenter, ) -from manage_breast_screening.participants.models.mastectomy_or_lumpectomy_history_item import ( +from manage_breast_screening.participants.models.medical_history.mastectomy_or_lumpectomy_history_item import ( MastectomyOrLumpectomyHistoryItem, ) -from ..forms.mastectomy_or_lumpectomy_history_form import ( - MastectomyOrLumpectomyHistoryForm, +from ...forms.medical_history.mastectomy_or_lumpectomy_history_item_form import ( + MastectomyOrLumpectomyHistoryItemForm, ) -from .mixins import InProgressAppointmentMixin +from ..mixins import InProgressAppointmentMixin logger = logging.getLogger(__name__) @@ -61,7 +61,7 @@ def participant(self): class AddMastectomyOrLumpectomyHistoryView(BaseMastectomyOrLumpectomyHistoryView): - form_class = MastectomyOrLumpectomyHistoryForm + form_class = MastectomyOrLumpectomyHistoryItemForm def form_valid(self, form): form.create(appointment=self.appointment, request=self.request) @@ -88,7 +88,7 @@ def get_context_data(self, **kwargs): class UpdateMastectomyOrLumpectomyHistoryView(BaseMastectomyOrLumpectomyHistoryView): - form_class = MastectomyOrLumpectomyHistoryForm + form_class = MastectomyOrLumpectomyHistoryItemForm def get_instance(self): try: diff --git a/manage_breast_screening/mammograms/views/other_procedure_history_view.py b/manage_breast_screening/mammograms/views/medical_history/other_procedure_history_item_views.py similarity index 92% rename from manage_breast_screening/mammograms/views/other_procedure_history_view.py rename to manage_breast_screening/mammograms/views/medical_history/other_procedure_history_item_views.py index e3901fad7..0d9a09d5b 100644 --- a/manage_breast_screening/mammograms/views/other_procedure_history_view.py +++ b/manage_breast_screening/mammograms/views/medical_history/other_procedure_history_item_views.py @@ -7,14 +7,14 @@ from django.views.generic import FormView from manage_breast_screening.core.views.generic import DeleteWithAuditView -from manage_breast_screening.participants.models.other_procedure_history_item import ( +from manage_breast_screening.participants.models.medical_history.other_procedure_history_item import ( OtherProcedureHistoryItem, ) -from ..forms.other_procedure_history_form import ( - OtherProcedureHistoryForm, +from ...forms.medical_history.other_procedure_history_item_form import ( + OtherProcedureHistoryItemForm, ) -from .mixins import InProgressAppointmentMixin +from ..mixins import InProgressAppointmentMixin logger = logging.getLogger(__name__) @@ -52,7 +52,7 @@ def get_context_data(self, **kwargs): class AddOtherProcedureHistoryView(BaseOtherProcedureHistoryView): - form_class = OtherProcedureHistoryForm + form_class = OtherProcedureHistoryItemForm def form_valid(self, form): form.create(appointment=self.appointment, request=self.request) @@ -83,8 +83,8 @@ def get_form_kwargs(self): return kwargs -class ChangeOtherProcedureHistoryView(BaseOtherProcedureHistoryView): - form_class = OtherProcedureHistoryForm +class UpdateOtherProcedureHistoryView(BaseOtherProcedureHistoryView): + form_class = OtherProcedureHistoryItemForm def get_instance(self): try: diff --git a/manage_breast_screening/participants/models/__init__.py b/manage_breast_screening/participants/models/__init__.py index 060a9bc55..abc914578 100644 --- a/manage_breast_screening/participants/models/__init__.py +++ b/manage_breast_screening/participants/models/__init__.py @@ -1,12 +1,18 @@ from .appointment import Appointment, AppointmentNote, AppointmentStatus -from .benign_lump_history_item import BenignLumpHistoryItem -from .breast_augmentation_history_item import BreastAugmentationHistoryItem -from .breast_cancer_history_item import BreastCancerHistoryItem -from .cyst_history_item import CystHistoryItem from .ethnicity import Ethnicity -from .implanted_medical_device_history_item import ImplantedMedicalDeviceHistoryItem -from .mastectomy_or_lumpectomy_history_item import MastectomyOrLumpectomyHistoryItem -from .other_procedure_history_item import OtherProcedureHistoryItem +from .medical_history.benign_lump_history_item import BenignLumpHistoryItem +from .medical_history.breast_augmentation_history_item import ( + BreastAugmentationHistoryItem, +) +from .medical_history.breast_cancer_history_item import BreastCancerHistoryItem +from .medical_history.cyst_history_item import CystHistoryItem +from .medical_history.implanted_medical_device_history_item import ( + ImplantedMedicalDeviceHistoryItem, +) +from .medical_history.mastectomy_or_lumpectomy_history_item import ( + MastectomyOrLumpectomyHistoryItem, +) +from .medical_history.other_procedure_history_item import OtherProcedureHistoryItem from .participant import Participant, ParticipantAddress from .reported_mammograms import ParticipantReportedMammogram, SupportReasons from .screening_episode import ScreeningEpisode diff --git a/manage_breast_screening/participants/models/medical_history/__init__.py b/manage_breast_screening/participants/models/medical_history/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/manage_breast_screening/participants/models/benign_lump_history_item.py b/manage_breast_screening/participants/models/medical_history/benign_lump_history_item.py similarity index 94% rename from manage_breast_screening/participants/models/benign_lump_history_item.py rename to manage_breast_screening/participants/models/medical_history/benign_lump_history_item.py index 95877374d..5ff29f600 100644 --- a/manage_breast_screening/participants/models/benign_lump_history_item.py +++ b/manage_breast_screening/participants/models/medical_history/benign_lump_history_item.py @@ -1,8 +1,8 @@ from django.contrib.postgres.fields import ArrayField from django.db import models -from ...core.models import BaseModel -from .appointment import Appointment +from ....core.models import BaseModel +from ..appointment import Appointment class BenignLumpHistoryItem(BaseModel): diff --git a/manage_breast_screening/participants/models/breast_augmentation_history_item.py b/manage_breast_screening/participants/models/medical_history/breast_augmentation_history_item.py similarity index 100% rename from manage_breast_screening/participants/models/breast_augmentation_history_item.py rename to manage_breast_screening/participants/models/medical_history/breast_augmentation_history_item.py diff --git a/manage_breast_screening/participants/models/breast_cancer_history_item.py b/manage_breast_screening/participants/models/medical_history/breast_cancer_history_item.py similarity index 98% rename from manage_breast_screening/participants/models/breast_cancer_history_item.py rename to manage_breast_screening/participants/models/medical_history/breast_cancer_history_item.py index df015d11c..57fb96f37 100644 --- a/manage_breast_screening/participants/models/breast_cancer_history_item.py +++ b/manage_breast_screening/participants/models/medical_history/breast_cancer_history_item.py @@ -3,8 +3,8 @@ from manage_breast_screening.nhsuk_forms.validators import ExcludesOtherOptionsValidator -from ...core.models import BaseModel -from .appointment import Appointment +from ....core.models import BaseModel +from ..appointment import Appointment class BreastCancerHistoryItem(BaseModel): diff --git a/manage_breast_screening/participants/models/cyst_history_item.py b/manage_breast_screening/participants/models/medical_history/cyst_history_item.py similarity index 88% rename from manage_breast_screening/participants/models/cyst_history_item.py rename to manage_breast_screening/participants/models/medical_history/cyst_history_item.py index b0700185e..80526e31e 100644 --- a/manage_breast_screening/participants/models/cyst_history_item.py +++ b/manage_breast_screening/participants/models/medical_history/cyst_history_item.py @@ -1,7 +1,7 @@ from django.db import models -from ...core.models import BaseModel -from .appointment import Appointment +from ....core.models import BaseModel +from ..appointment import Appointment class CystHistoryItem(BaseModel): diff --git a/manage_breast_screening/participants/models/implanted_medical_device_history_item.py b/manage_breast_screening/participants/models/medical_history/implanted_medical_device_history_item.py similarity index 93% rename from manage_breast_screening/participants/models/implanted_medical_device_history_item.py rename to manage_breast_screening/participants/models/medical_history/implanted_medical_device_history_item.py index 819f68745..fa3a9c0fb 100644 --- a/manage_breast_screening/participants/models/implanted_medical_device_history_item.py +++ b/manage_breast_screening/participants/models/medical_history/implanted_medical_device_history_item.py @@ -1,7 +1,7 @@ from django.db import models -from ...core.models import BaseModel -from .appointment import Appointment +from ....core.models import BaseModel +from ..appointment import Appointment class ImplantedMedicalDeviceHistoryItem(BaseModel): diff --git a/manage_breast_screening/participants/models/mastectomy_or_lumpectomy_history_item.py b/manage_breast_screening/participants/models/medical_history/mastectomy_or_lumpectomy_history_item.py similarity index 96% rename from manage_breast_screening/participants/models/mastectomy_or_lumpectomy_history_item.py rename to manage_breast_screening/participants/models/medical_history/mastectomy_or_lumpectomy_history_item.py index d02d57c8c..0664d2efe 100644 --- a/manage_breast_screening/participants/models/mastectomy_or_lumpectomy_history_item.py +++ b/manage_breast_screening/participants/models/medical_history/mastectomy_or_lumpectomy_history_item.py @@ -1,8 +1,8 @@ from django.contrib.postgres.fields import ArrayField from django.db import models -from ...core.models import BaseModel -from .appointment import Appointment +from ....core.models import BaseModel +from ..appointment import Appointment class MastectomyOrLumpectomyHistoryItem(BaseModel): diff --git a/manage_breast_screening/participants/models/other_procedure_history_item.py b/manage_breast_screening/participants/models/medical_history/other_procedure_history_item.py similarity index 91% rename from manage_breast_screening/participants/models/other_procedure_history_item.py rename to manage_breast_screening/participants/models/medical_history/other_procedure_history_item.py index 82da79c34..7993918c1 100644 --- a/manage_breast_screening/participants/models/other_procedure_history_item.py +++ b/manage_breast_screening/participants/models/medical_history/other_procedure_history_item.py @@ -1,7 +1,7 @@ from django.db import models -from ...core.models import BaseModel -from .appointment import Appointment +from ....core.models import BaseModel +from ..appointment import Appointment class OtherProcedureHistoryItem(BaseModel): diff --git a/manage_breast_screening/participants/tests/models/test_breast_cancer_history_item.py b/manage_breast_screening/participants/tests/models/test_breast_cancer_history_item.py index 844d3f6f5..bf20e904d 100644 --- a/manage_breast_screening/participants/tests/models/test_breast_cancer_history_item.py +++ b/manage_breast_screening/participants/tests/models/test_breast_cancer_history_item.py @@ -1,7 +1,7 @@ import pytest from django.forms import ValidationError -from manage_breast_screening.participants.models.breast_cancer_history_item import ( +from manage_breast_screening.participants.models.medical_history.breast_cancer_history_item import ( BreastCancerHistoryItem, ) from manage_breast_screening.participants.tests.factories import ( diff --git a/manage_breast_screening/tests/system/clinical/test_benign_lump_history.py b/manage_breast_screening/tests/system/clinical/test_benign_lump_history.py index ac05b30ae..bfbb26c91 100644 --- a/manage_breast_screening/tests/system/clinical/test_benign_lump_history.py +++ b/manage_breast_screening/tests/system/clinical/test_benign_lump_history.py @@ -1,7 +1,7 @@ from django.urls import reverse from playwright.sync_api import expect -from manage_breast_screening.participants.models.benign_lump_history_item import ( +from manage_breast_screening.participants.models.medical_history.benign_lump_history_item import ( BenignLumpHistoryItem, ) from manage_breast_screening.participants.tests.factories import (