diff --git a/manage_breast_screening/data/east_tester_one_week_ago_clinic_data.yml b/manage_breast_screening/data/east_tester_one_week_ago_clinic_data.yml index 979bd44b7..dcb1ea609 100644 --- a/manage_breast_screening/data/east_tester_one_week_ago_clinic_data.yml +++ b/manage_breast_screening/data/east_tester_one_week_ago_clinic_data.yml @@ -68,7 +68,7 @@ clinic: diagnosis_year: 2024 left_breast_procedure: NO_PROCEDURE right_breast_procedure: LUMPECTOMY - systemic_treatments: NO_RADIOTHERAPY + systemic_treatments: [NO_SYSTEMIC_TREATMENTS] intervention_location: NHS_HOSPITAL intervention_location_details: East Tester Hospital diff --git a/manage_breast_screening/data/east_tester_today_clinic_data.yml b/manage_breast_screening/data/east_tester_today_clinic_data.yml index 7374381c9..69a745d8f 100644 --- a/manage_breast_screening/data/east_tester_today_clinic_data.yml +++ b/manage_breast_screening/data/east_tester_today_clinic_data.yml @@ -39,7 +39,7 @@ clinic: diagnosis_year: 2024 left_breast_procedure: NO_PROCEDURE right_breast_procedure: LUMPECTOMY - systemic_treatments: NO_SYSTEMIC_TREATMENTS + systemic_treatments: [NO_SYSTEMIC_TREATMENTS] intervention_location: NHS_HOSPITAL intervention_location_details: East Tester Hospital implanted_medical_device_history_items: 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 158cadbd2..6b8c569e2 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 @@ -24,7 +24,10 @@ def __init__(self, breast_cancer_history_item): self.left_breast_treatment = self._format_multiple_choices( self._item.left_breast_treatment, BreastCancerHistoryItem.Treatment ) - self.systemic_treatments = self._item.get_systemic_treatments_display() + self.systemic_treatments = self._format_multiple_choices( + self._item.systemic_treatments, + BreastCancerHistoryItem.SystemicTreatment, + ) self.additional_details = nl2br(self._item.additional_details) @property diff --git a/manage_breast_screening/participants/migrations/0043_alter_breastcancerhistoryitem_systemic_treatments.py b/manage_breast_screening/participants/migrations/0043_alter_breastcancerhistoryitem_systemic_treatments.py new file mode 100644 index 000000000..bea957841 --- /dev/null +++ b/manage_breast_screening/participants/migrations/0043_alter_breastcancerhistoryitem_systemic_treatments.py @@ -0,0 +1,62 @@ +# Generated by Django 5.2.8 on 2025-11-17 16:08 + +import django.contrib.postgres.fields +from django.db import migrations, models + +import manage_breast_screening.nhsuk_forms.validators + + +class Migration(migrations.Migration): + + dependencies = [ + ("participants", "0042_alter_implantedmedicaldevicehistoryitem_device"), + ] + + operations = [ + migrations.AddField( + model_name="breastcancerhistoryitem", + name="systemic_treatments2", + field=django.contrib.postgres.fields.ArrayField( + base_field=models.CharField( + choices=[ + ("CHEMOTHERAPY", "Chemotherapy"), + ("HORMONE_THERAPY", "Hormone therapy"), + ("OTHER", "Other"), + ("NO_SYSTEMIC_TREATMENTS", "No systemic treatments"), + ] + ), + default=list, + size=None, + validators=[ + manage_breast_screening.nhsuk_forms.validators.ExcludesOtherOptionsValidator( + "NO_SYSTEMIC_TREATMENTS", "No systemic treatments" + ) + ], + ), + ), + migrations.AlterField( + model_name="breastcancerhistoryitem", + name="systemic_treatments", + field=models.CharField( + choices=[ + ("CHEMOTHERAPY", "Chemotherapy"), + ("HORMONE_THERAPY", "Hormone therapy"), + ("OTHER", "Other"), + ("NO_SYSTEMIC_TREATMENTS", "No systemic treatments"), + ], + db_default="NO_SYSTEMIC_TREATMENTS", # add a default so the migration is reversable + ), + ), + migrations.RunSQL( + sql="update participants_breastcancerhistoryitem set systemic_treatments2 = ARRAY[systemic_treatments]", + reverse_sql="update participants_breastcancerhistoryitem set systemic_treatments = systemic_treatments2[1]", + ), + migrations.RemoveField( + model_name="breastcancerhistoryitem", name="systemic_treatments" + ), + migrations.RenameField( + model_name="breastcancerhistoryitem", + old_name="systemic_treatments2", + new_name="systemic_treatments", + ), + ] diff --git a/manage_breast_screening/participants/migrations/max_migration.txt b/manage_breast_screening/participants/migrations/max_migration.txt index 4783d589f..0691fe7d3 100644 --- a/manage_breast_screening/participants/migrations/max_migration.txt +++ b/manage_breast_screening/participants/migrations/max_migration.txt @@ -1 +1 @@ -0042_alter_implantedmedicaldevicehistoryitem_device +0043_alter_breastcancerhistoryitem_systemic_treatments diff --git a/manage_breast_screening/participants/models/breast_cancer_history_item.py b/manage_breast_screening/participants/models/breast_cancer_history_item.py index 351a0a64d..afc21e38f 100644 --- a/manage_breast_screening/participants/models/breast_cancer_history_item.py +++ b/manage_breast_screening/participants/models/breast_cancer_history_item.py @@ -96,7 +96,16 @@ class InterventionLocation(models.TextChoices): ], ) - systemic_treatments = models.CharField(choices=SystemicTreatment) + systemic_treatments = ArrayField( + base_field=models.CharField(choices=SystemicTreatment), + default=list, + validators=[ + ExcludesOtherOptionsValidator( + SystemicTreatment.NO_SYSTEMIC_TREATMENTS.value, + SystemicTreatment.NO_SYSTEMIC_TREATMENTS.label, + ) + ], + ) systemic_treatments_other_treatment_details = models.CharField( blank=True, null=False, default="" ) diff --git a/manage_breast_screening/participants/tests/factories.py b/manage_breast_screening/participants/tests/factories.py index 64cea3fd8..dc37a67a2 100644 --- a/manage_breast_screening/participants/tests/factories.py +++ b/manage_breast_screening/participants/tests/factories.py @@ -173,9 +173,9 @@ class Meta: right_breast_other_surgery = [BreastCancerHistoryItem.Surgery.NO_SURGERY] left_breast_treatment = [BreastCancerHistoryItem.Treatment.NO_RADIOTHERAPY] right_breast_treatment = [BreastCancerHistoryItem.Treatment.NO_RADIOTHERAPY] - systemic_treatments = ( + systemic_treatments = [ BreastCancerHistoryItem.SystemicTreatment.NO_SYSTEMIC_TREATMENTS - ) + ] intervention_location = ( BreastCancerHistoryItem.InterventionLocation.EXACT_LOCATION_UNKNOWN @@ -195,6 +195,7 @@ class Meta: surgery_reason = MastectomyOrLumpectomyHistoryItem.SurgeryReason.OTHER_REASON additional_details = "" + class CystHistoryItemFactory(DjangoModelFactory): class Meta: model = models.CystHistoryItem diff --git a/manage_breast_screening/participants/tests/models/test_breast_cancer_history_item_test.py b/manage_breast_screening/participants/tests/models/test_breast_cancer_history_item.py similarity index 100% rename from manage_breast_screening/participants/tests/models/test_breast_cancer_history_item_test.py rename to manage_breast_screening/participants/tests/models/test_breast_cancer_history_item.py