Skip to content

Conversation

@malcolmbaig
Copy link
Contributor

@malcolmbaig malcolmbaig commented Nov 18, 2025

Description

Add the form for adding a benign lump history item.

See commit messages for summary of changes.

Validation errors — no data submitted

Screenshot 2025-11-19 at 16 35 46

Validation errors — no location details

Screenshot 2025-11-24 at 10 51 28

Jira link

https://nhsd-jira.digital.nhs.uk/browse/DTOSS-11451

Review notes

  • The YearField isn't customizable in terms of the range it checks for. Does it need to be at this stage? < no longer the case after the changes introduced following this comment Add benign lump form #739 (comment)

Review checklist

  • Check database queries are correctly scoped to current_provider

@malcolmbaig malcolmbaig force-pushed the 11451-add-benign-lump branch 2 times, most recently from c07c407 to e4e0a15 Compare November 19, 2025 15:45
@malcolmbaig malcolmbaig changed the title [wip] Add benign lump form Add benign lump form Nov 19, 2025
@malcolmbaig malcolmbaig marked this pull request as ready for review November 19, 2025 16:39
@malcolmbaig malcolmbaig requested a review from a team as a code owner November 19, 2025 16:39
@malcolmbaig malcolmbaig force-pushed the 11451-add-benign-lump branch from cb048cf to 1665396 Compare November 19, 2025 16:40
@swebberuk
Copy link
Contributor

Do we need to add a test_benign_lump_history_item_views.py?

I found we'd done something similar for sympton views:
https://github.com/NHSDigital/dtos-manage-breast-screening/blob/main/manage_breast_screening/mammograms/tests/views/test_symptom_views.py

So I did the same for the implanted medical devices changes I made:
https://github.com/NHSDigital/dtos-manage-breast-screening/blob/main/manage_breast_screening/mammograms/tests/views/test_implanted_medical_device_history_views.py

Maybe we feel that behaviour is already sufficiently covered by the playwright tests in test_benign_lump_history.py?

**kwargs,
):
if min_value is None:
min_value = date.today().year - 80
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noticed a possible problem here - fields can be created when the form is declared, rather than when the form is instantiated, so the field's validation could get stale if the app doesn't restart. Maybe less of an issue here, but definitely in the SplitDateField.

Is it possible to make min_value/max_value a callable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good point. I've attempted to address this in 6cc2573. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

looks good to me 👍🏻

messages.add_message(
self.request,
messages.SUCCESS,
"Added benign lump history",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the pattern elsewhere is "Noun added" rather than "Added noun" - not sure which we prefer but they should be consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

Copy link
Contributor

@MatMoore MatMoore left a comment

Choose a reason for hiding this comment

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

I think there might be some visually hidden text missing - see inline comment

@MatMoore MatMoore mentioned this pull request Nov 20, 2025
1 task
@edwardhorsford
Copy link
Contributor

We'll want a specific error for the conditional text inputs for treatment location.

@malcolmbaig
Copy link
Contributor Author

Do we need to add a test_benign_lump_history_item_views.py?

Maybe we feel that behaviour is already sufficiently covered by the playwright tests in test_benign_lump_history.py?

@swebberuk exactly this — I tend to add view tests if there's some complex behaviour (or permutations of some kind) that aren't adequately covered by the system test. In this case, I think the system test is sufficient.

"max_value", "Year must be less than %(max_value)s"
),
code="max_value",
params={"max_value": max_value},
Copy link
Contributor

@swebberuk swebberuk Nov 21, 2025

Choose a reason for hiding this comment

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

If using the message "Year must be less than %(max_value)s" then should this be: params={"max_value": max_value + 1},

It was suggested on Slack that the error message could be "Year of procedure cannot be in the future" - so don't know if we need to make it configurable? To avoid blocking merging this PR, maybe we can review the error message as part of a separate ticket?

Here is a link to a related comment from a different PR: #742 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can raise another ticket that looks at both the YearField and the SplitDateField? Both will need some tweaking to the error messages I think

Copy link
Contributor Author

@malcolmbaig malcolmbaig Nov 24, 2025

Choose a reason for hiding this comment

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

I think a ticket to revisit these would be a good idea, including potentially making the error message configurable. For this PR, I'll adjust these to "Year must be (value) or later" and "Year must be (value) or earlier".

"min_value", "Year must be greater than %(min_value)s"
),
code="min_value",
params={"min_value": min_value},
Copy link
Contributor

@swebberuk swebberuk Nov 21, 2025

Choose a reason for hiding this comment

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

Similar question as for max value validation, should this be: params={"min_value": min_value - 1},

@malcolmbaig
Copy link
Contributor Author

We'll want a specific error for the conditional text inputs for treatment location.

Updated in 6ba8a1c and screenshot replaced in PR description

@github-actions
Copy link

github-actions bot commented Nov 24, 2025

The review app at this URL has been deleted:
https://pr-739.manage-breast-screening.non-live.screening.nhs.uk

bounds["max"] = 2002
form = TestForm(data={"field": 2003})
assert not form.is_valid()
assert form.errors["field"] == ["Year must be less than 2002"]
Copy link
Contributor

@swebberuk swebberuk Nov 24, 2025

Choose a reason for hiding this comment

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

Need to change to Year must be 2002 or earlier and line 56 to Year must be 2000 or later.

Introduce the initial template, form object and routing for creating
benign lump history items on the medical info screen.
- Introduce YearField as a specific type of IntegerField that validates
  for a year between 80 years ago and today.
- Use this in the benign lump history item form.
Matching the choice in the prototype to make this heading
aria-hidden=true.
The current YearField validation on min and max value is implemented in
a way that means values based on the current year will only be evaluated
on module import. An application restart after moving from one year to
the next would be needed to ensure current year is correct.

This isn't a huge bug necessarily with our current use cases, but it's
an inconvenient issue to leave in the codebase.

This commit switches to using min_value_callable and max_value_callable
to determine the year bounds. These can be overridden, but by default
specify a range of 80 years to current year.
Copy link
Contributor

@swebberuk swebberuk left a comment

Choose a reason for hiding this comment

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

👍

@malcolmbaig malcolmbaig merged commit 81a64ea into main Nov 24, 2025
13 checks passed
@malcolmbaig malcolmbaig deleted the 11451-add-benign-lump branch November 24, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants