Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions manage_breast_screening/mammograms/forms/symptom_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from manage_breast_screening.nhsuk_forms.forms import FormWithConditionalFields
from manage_breast_screening.nhsuk_forms.utils import YesNo, yes_no, yes_no_field
from manage_breast_screening.participants.models.symptom import (
HighlightToReaderChoices,
NippleChangeChoices,
RelativeDateChoices,
SkinChangeChoices,
Expand Down Expand Up @@ -80,6 +81,13 @@ class CommonFields:
widget=Textarea(attrs={"rows": 5}),
error_messages={"required": "Enter details of any investigations"},
)
highlight_to_readers = ChoiceField(
choices=HighlightToReaderChoices,
label="Highlight this symptom to readers?",
error_messages={
"required": "Select whether this symptom should be highlighted to image readers"
},
)
additional_information = CharField(
required=False,
label="Additional info (optional)",
Expand Down Expand Up @@ -151,6 +159,9 @@ def initial_values(self, instance):
"when_resolved": instance.when_resolved,
"investigated": yes_no(instance.investigated),
"investigation_details": instance.investigation_details,
"highlight_to_readers": HighlightToReaderChoices.YES
if instance.highlight_to_readers
else HighlightToReaderChoices.NO,
"additional_information": instance.additional_information,
}

Expand Down Expand Up @@ -184,6 +195,10 @@ def model_values(self):
intermittent = self.cleaned_data.get("intermittent", False)
recently_resolved = self.cleaned_data.get("recently_resolved", False)
when_resolved = self.cleaned_data.get("when_resolved", "")
highlight_to_readers = (
self.cleaned_data.get("highlight_to_readers", HighlightToReaderChoices.YES)
== HighlightToReaderChoices.YES
)
additional_information = self.cleaned_data.get("additional_information", "")

return dict(
Expand All @@ -199,6 +214,7 @@ def model_values(self):
intermittent=intermittent,
recently_resolved=recently_resolved,
when_resolved=when_resolved,
highlight_to_readers=highlight_to_readers,
additional_information=additional_information,
)

Expand Down Expand Up @@ -470,6 +486,7 @@ class OtherSymptomForm(SymptomForm):
when_resolved = CommonFields.when_resolved
investigated = CommonFields.investigated
investigation_details = CommonFields.investigation_details
highlight_to_readers = CommonFields.highlight_to_readers
additional_information = CommonFields.additional_information

def __init__(self, instance=None, **kwargs):
Expand Down Expand Up @@ -514,6 +531,7 @@ class BreastPainForm(SymptomForm):
when_resolved = CommonFields.when_resolved
investigated = CommonFields.investigated
investigation_details = CommonFields.investigation_details
highlight_to_readers = CommonFields.highlight_to_readers
additional_information = CommonFields.additional_information

def __init__(self, instance=None, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@
{% set symptom_rows = presented_medical_info.read_only_symptom_rows if read_only else presented_medical_info.symptom_rows %}
<p {%- if not read_only and not symptom_rows %} class="nhsuk-u-margin-bottom-3"{% endif %}>Any problems or symptoms, including lumps, swelling, rashes or nipple changes</p>
{% if symptom_rows %}
{{ summaryList({
"rows": symptom_rows
}) }}
{{ symptoms_summary(symptom_rows) }}
{% else %}
{% set insetHtml %}
<p>No symptoms have been recorded for this participant.</p>
Expand Down Expand Up @@ -244,3 +242,21 @@
]
}) }}
{% endmacro %}

{% macro symptoms_summary(symptom_rows, classes='') %}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

symptoms_summary adds "Highlight to image readers" tag if required, then calls summaryList.

Alternative to formatting HTML in SymptomPresenter.

{% set rows = [] %}
{% for row in symptom_rows %}
{% set key_html %}
{{ row.symptom_name }}
{% if row.highlight_to_readers %}
<br><strong class="nhsuk-tag app-nowrap nhsuk-tag--yellow">Highlight to image readers</strong>
{% endif %}
{% endset %}
{% set _ = rows.append({
"key": {"html": key_html},
"value": {"html": row.html},
"actions": row.actions if row.actions else {"items": []}
}) %}
{% endfor %}
{{ summaryList({"rows": rows, "classes": classes}) }}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{% extends "layout-confirmation.jinja" %}
{% from 'nhsuk/components/summary-list/macro.jinja' import summaryList %}
{% from "mammograms/medical_information/section_cards.jinja" import symptoms_summary %}
{% from 'nhsuk/components/inset-text/macro.jinja' import insetText %}

{% block details %}
{{ summaryList({
"rows": [summary_list_row],
"classes": "nhsuk-summary-list--no-border"
}) }}
{{ symptoms_summary([summary_list_row], classes="nhsuk-summary-list--no-border") }}

{% set insetTextHtml %}
<p>This action is final and cannot be undone.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

{{ form.investigated.as_field_group() }}

{{ form.highlight_to_readers.as_field_group() }}

{{ form.additional_information.as_field_group() }}

<div class="nhsuk-button-group">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
{% from "nhsuk/components/fieldset/macro.jinja" import fieldset %}

{% block form %}
{% if heading_description %}
<div class="nhsuk-inset-text nhsuk-u-margin-top-0 nhsuk-u-margin-bottom-4">
<p>{{ heading_description }}</p>
</div>
{% endif %}

{% do form.symptom_sub_type.add_conditional_html('NIPPLE_CHANGE_OTHER', form.symptom_sub_type_details.as_field_group()) %}

{% do form.when_started.add_divider_after("OVER_THREE_YEARS", "or") %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

{{ form.investigated.as_field_group() }}

{{ form.highlight_to_readers.as_field_group() }}

{{ form.additional_information.as_field_group() }}

<div class="nhsuk-button-group">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
{% from "nhsuk/components/fieldset/macro.jinja" import fieldset %}

{% block form %}
{% if heading_description %}
<div class="nhsuk-inset-text nhsuk-u-margin-top-0 nhsuk-u-margin-bottom-4">
<p>{{ heading_description }}</p>
</div>
{% endif %}

{% include "mammograms/medical_information/symptoms/forms/inline_area_radios.jinja" %}

{% do form.symptom_sub_type.add_conditional_html('SKIN_CHANGE_OTHER', form.symptom_sub_type_details.as_field_group()) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ def build_summary_list_row(self, include_actions=True):
)

result = {
"key": {"text": self._symptom.symptom_type.name},
"value": {"html": html},
"symptom_name": self._symptom.symptom_type.name,
"highlight_to_readers": self._symptom.highlight_to_readers,
"html": html,
}

if include_actions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
from manage_breast_screening.nhsuk_forms.choices import YesNo
from manage_breast_screening.participants.models.symptom import (
HighlightToReaderChoices,
NippleChangeChoices,
SkinChangeChoices,
SymptomAreas,
Expand Down Expand Up @@ -588,6 +589,7 @@ def test_valid_form(self):
"symptom_sub_type": SkinChangeChoices.COLOUR_CHANGE,
"when_started": RelativeDateChoices.LESS_THAN_THREE_MONTHS,
"investigated": YesNo.NO,
"highlight_to_readers": HighlightToReaderChoices.YES,
}
)
)
Expand All @@ -603,6 +605,9 @@ def test_missing_required_fields(self):
"symptom_sub_type_details": ["Enter a description of the symptom"],
"investigated": ["Select whether the symptom has been investigated or not"],
"area": ["Select the location of the symptom"],
"highlight_to_readers": [
"Select whether this symptom should be highlighted to image readers"
],
}

def test_missing_conditionally_required_fields(self):
Expand All @@ -614,6 +619,7 @@ def test_missing_conditionally_required_fields(self):
"symptom_sub_type_details": "abc symptom",
"when_started": RelativeDateChoices.SINCE_A_SPECIFIC_DATE,
"investigated": YesNo.YES,
"highlight_to_readers": HighlightToReaderChoices.YES,
}
)
)
Expand Down Expand Up @@ -641,6 +647,7 @@ def test_valid_form_with_conditionally_required_fields(self):
"specific_date_0": "2",
"specific_date_1": "2025",
"investigation_details": "def",
"highlight_to_readers": HighlightToReaderChoices.YES,
}
)
)
Expand All @@ -658,6 +665,7 @@ def test_valid_form(self):
"area_description_left_breast": "uoq",
"when_started": RelativeDateChoices.LESS_THAN_THREE_MONTHS,
"investigated": YesNo.NO,
"highlight_to_readers": HighlightToReaderChoices.YES,
}
)
)
Expand All @@ -672,6 +680,9 @@ def test_missing_required_fields(self):
"when_started": ["Select how long the symptom has existed"],
"investigated": ["Select whether the symptom has been investigated or not"],
"area": ["Select the location of the pain"],
"highlight_to_readers": [
"Select whether this symptom should be highlighted to image readers"
],
}

def test_missing_conditionally_required_fields(self):
Expand All @@ -683,6 +694,7 @@ def test_missing_conditionally_required_fields(self):
"when_started": RelativeDateChoices.SINCE_A_SPECIFIC_DATE,
"investigated": YesNo.YES,
"recently_resolved": True,
"highlight_to_readers": HighlightToReaderChoices.YES,
}
)
)
Expand Down Expand Up @@ -712,6 +724,7 @@ def test_valid_form_with_conditionally_required_fields(self):
"investigation_details": "def",
"recently_resolved": True,
"when_resolved": "3 months ago",
"highlight_to_readers": HighlightToReaderChoices.YES,
}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ def test_formats_symptoms_summary_list(self):
area=SymptomAreas.BOTH_BREASTS,
)

symptom3 = SymptomFactory.create(
other=True,
appointment=appointment,
when_started=RelativeDateChoices.LESS_THAN_THREE_MONTHS,
area=SymptomAreas.RIGHT_BREAST,
symptom_sub_type_details="abc",
)

symptom4 = SymptomFactory.create(
other=True,
appointment=appointment,
when_started=RelativeDateChoices.LESS_THAN_THREE_MONTHS,
area=SymptomAreas.LEFT_BREAST,
highlight_to_readers=False,
symptom_sub_type_details="xyz",
)

presenter = MedicalInformationPresenter(appointment)

assert presenter.symptom_rows == [
Expand All @@ -65,12 +82,39 @@ def test_formats_symptoms_summary_list(self):
},
],
},
"key": {
"text": "Lump",
"symptom_name": "Lump",
"highlight_to_readers": True,
"html": "Left breast<br>Not sure<br>Symptom is intermittent<br>Stopped: resolved date<br>Not investigated<br>Additional information: abc",
},
{
"actions": {
"items": [
{
"text": "Change",
"classes": "nhsuk-link--no-visited-state",
"visuallyHiddenText": "other",
"href": f"/mammograms/{appointment.id}/record-medical-information/other/{symptom3.id}/",
},
],
},
"value": {
"html": "Left breast<br>Not sure<br>Symptom is intermittent<br>Stopped: resolved date<br>Not investigated<br>Additional information: abc",
"symptom_name": "Other",
"highlight_to_readers": True,
"html": "Description: abc<br>Right breast<br>Less than 3 months ago<br>Not investigated",
},
{
"actions": {
"items": [
{
"text": "Change",
"classes": "nhsuk-link--no-visited-state",
"visuallyHiddenText": "other",
"href": f"/mammograms/{appointment.id}/record-medical-information/other/{symptom4.id}/",
}
]
},
"symptom_name": "Other",
"highlight_to_readers": False,
"html": "Description: xyz<br>Left breast<br>Less than 3 months ago<br>Not investigated",
},
{
"actions": {
Expand All @@ -83,12 +127,9 @@ def test_formats_symptoms_summary_list(self):
},
],
},
"key": {
"text": "Swelling or shape change",
},
"value": {
"html": "Both breasts<br>Less than 3 months ago<br>Not investigated",
},
"symptom_name": "Swelling or shape change",
"highlight_to_readers": True,
"html": "Both breasts<br>Less than 3 months ago<br>Not investigated",
},
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_formats_intermittent_stopped_and_additional_information(self):
assert presenter.intermittent_line == "Symptom is intermittent"
assert presenter.additional_information_line == "Additional information: abc"

def test_formats_for_summary_list(self):
def test_formats_lump_for_summary_list(self):
symptom = SymptomFactory.create(
lump=True,
when_started=RelativeDateChoices.NOT_SURE,
Expand All @@ -158,12 +158,36 @@ def test_formats_for_summary_list(self):
},
],
},
"key": {
"text": "Lump",
},
"value": {
"html": "Left breast<br>Not sure<br>Symptom is intermittent<br>Stopped: resolved date<br>Not investigated<br>Additional information: abc",
"symptom_name": "Lump",
"highlight_to_readers": True,
"html": "Left breast<br>Not sure<br>Symptom is intermittent<br>Stopped: resolved date<br>Not investigated<br>Additional information: abc",
}

@pytest.mark.parametrize("highlight_to_readers", [True, False])
def test_formats_other_for_summary_list(self, highlight_to_readers):
symptom = SymptomFactory.create(
breast_pain=True,
when_started=RelativeDateChoices.LESS_THAN_THREE_MONTHS,
area=SymptomAreas.LEFT_BREAST,
highlight_to_readers=highlight_to_readers,
)

presenter = SymptomPresenter(symptom)

assert presenter.summary_list_row == {
"actions": {
"items": [
{
"text": "Change",
"classes": "nhsuk-link--no-visited-state",
"visuallyHiddenText": "breast pain",
"href": f"/mammograms/{symptom.appointment_id}/record-medical-information/breast-pain/{symptom.id}/",
}
]
},
"symptom_name": "Breast pain",
"highlight_to_readers": highlight_to_readers,
"html": "Left breast<br>Less than 3 months ago<br>Not investigated",
}

def test_delete_message_html(self):
Expand Down
Loading
Loading