Skip to content

Commit 2cddc89

Browse files
authored
Merge pull request #1227 from NHSDigital/DTOSS-12519-render-breast-features-on-check-info
Render breast features on check information page
2 parents 2ecafac + e852c89 commit 2cddc89

24 files changed

+282
-41
lines changed

manage_breast_screening/assets/js/breast-diagram.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ export class BreastDiagram extends ConfigurableComponent {
106106
render() {
107107
const { $imageMap, markers, values } = this
108108

109-
values.forEach(({ id, x, y }, index) => {
110-
const $path = $imageMap.getPathById(id)
111-
const point = $imageMap.createPoint(x, y, id)
109+
values.forEach(({ region_id, x, y }, index) => {
110+
const $path = $imageMap.getPathById(region_id)
111+
const point = $imageMap.createPoint(x, y, region_id)
112112

113113
// Render active region
114114
$imageMap.setState('active', $path)
@@ -180,7 +180,7 @@ export class BreastDiagram extends ConfigurableComponent {
180180
}
181181

182182
$debugInput.textContent =
183-
this.values.map(({ id }) => id).join(', ') || 'N/A'
183+
this.values.map(({ region_id }) => region_id).join(', ') || 'N/A'
184184

185185
if (!$debugX || !$debugY || !$debugRegion) {
186186
return
@@ -205,8 +205,8 @@ export class BreastDiagram extends ConfigurableComponent {
205205
}
206206

207207
this.add({
208-
id: $path.classList.value,
209-
name: 'Pending',
208+
id: 'pending',
209+
region_id: $path.classList.value,
210210
x: point.x,
211211
y: point.y
212212
})
@@ -242,7 +242,7 @@ export class BreastDiagram extends ConfigurableComponent {
242242
}
243243

244244
const index = values.indexOf(entry)
245-
const $path = $imageMap.getPathById(entry.id)
245+
const $path = $imageMap.getPathById(entry.region_id)
246246

247247
$imageMap.setState('active', $path, false)
248248
values.splice(index, 1)
@@ -343,10 +343,12 @@ function isValidObject(value) {
343343
return false
344344
}
345345

346+
const keys = new Set(['id', 'region_id', 'x', 'y'])
347+
346348
return (
347-
Object.keys(value).every((key) => ['id', 'name', 'x', 'y'].includes(key)) &&
349+
Object.keys(value).every((key) => keys.has(key)) &&
348350
typeof value.id === 'string' &&
349-
typeof value.name === 'string' &&
351+
typeof value.region_id === 'string' &&
350352
typeof value.x === 'number' &&
351353
typeof value.y === 'number'
352354
)
@@ -378,8 +380,8 @@ function isValid(value) {
378380
* Breast feature input value
379381
*
380382
* @typedef {object} BreastFeature
381-
* @property {string} id - Image map region ID
382-
* @property {string} name - Breast feature name
383+
* @property {string} id - Breast feature ID
384+
* @property {string} region_id - Image map region ID
383385
* @property {number} x - X coordinate of breast feature
384386
* @property {number} y - Y coordinate of breast feature
385387
*/

manage_breast_screening/assets/js/breast-diagram.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ jest.mock('./image-map', () => {
2121
* @type {DOMPoint}
2222
*/
2323
const dummyPoint = {
24-
x: 0,
25-
y: 0,
24+
x: 133,
25+
y: 82,
2626
w: null,
2727
z: null,
2828
matrixTransform: jest.fn(),
@@ -35,8 +35,8 @@ const dummyPoint = {
3535
* @type {BreastFeature}
3636
*/
3737
const dummyFeature = {
38-
id: 'abc',
39-
name: 'Pending',
38+
id: 'pending',
39+
region_id: 'right_upper_outer',
4040
x: dummyPoint.x,
4141
y: dummyPoint.y
4242
}
@@ -58,7 +58,7 @@ describe('Breast diagram', () => {
5858

5959
const diagramWithAFeatureMarked = `
6060
<form>
61-
<input name="features" type="hidden" value='[{"x": 0, "y": 0, "name": "Pending", "id": "abc"}]'>
61+
<input name="features" type="hidden" value='[{"id": "pending", "region_id": "right_upper_outer", "x": 133, "y": 82}]'>
6262
<div data-module="app-breast-diagram">
6363
<div data-module="app-image-map"></div>
6464
</div>
@@ -105,7 +105,7 @@ describe('Breast diagram', () => {
105105
component.write()
106106

107107
expect(component.$input.value).toBe(
108-
'[{"x":0,"y":0,"name":"Pending","id":"abc"}]'
108+
'[{"id":"pending","region_id":"right_upper_outer","x":133,"y":82}]'
109109
)
110110
})
111111
})

manage_breast_screening/core/jinja2/components/breast-diagram/template.jinja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% from "nhsuk/macros/attributes.jinja" import nhsukAttributes -%}
2+
{% from "nhsuk/components/summary-list/macro.jinja" import summaryList %}
23

34
<div {{- nhsukAttributes({
45
"class": "app-breast-diagram",

manage_breast_screening/data/east_tester_one_week_ago_clinic_data.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,16 @@ clinic:
595595
exact_date: '2025-01-17'
596596
date_type: EXACT
597597
created_at: '2019-12-10'
598+
breast_features:
599+
annotations_json:
600+
[
601+
{
602+
'id': 'scar',
603+
'region_id': 'left_axilla',
604+
'x': 711.7478637695312,
605+
'y': 53.868194580078125
606+
}
607+
]
598608
- id: bce8bbbe-0a1c-41d0-b1dc-2512b401a7e8
599609
duration_in_minutes: 8
600610
starts_at_time: '11:32'

manage_breast_screening/data/west_tester_three_years_ago_clinic_data.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,16 @@ clinic:
574574
location_details: In the radiology department
575575
exact_date: '2025-07-25'
576576
date_type: EXACT
577+
breast_features:
578+
annotations_json:
579+
[
580+
{
581+
'id': 'scar',
582+
'region_id': 'left_axilla',
583+
'x': 711.7478637695312,
584+
'y': 53.868194580078125
585+
}
586+
]
577587
- id: 6de03637-f52c-48dc-a793-18169b5882bd
578588
duration_in_minutes: 8
579589
starts_at_time: '12:56'

manage_breast_screening/data/west_tester_today_clinic_data.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,17 @@ clinic:
580580
exact_date: '2025-01-17'
581581
date_type: EXACT
582582
created_at: '2020-04-03'
583+
breast_features:
584+
annotations_json:
585+
[
586+
{
587+
'id': 'mole',
588+
'region_id': 'right_central',
589+
'x': 237.82235717773438,
590+
'y': 193.69627380371094
591+
}
592+
]
593+
583594
- id: 989966b5-a4d8-4a31-8a38-7407d8df2e71
584595
duration_in_minutes: 8
585596
starts_at_time: '11:32'
@@ -636,6 +647,16 @@ clinic:
636647
location_details: In the radiology department
637648
exact_date: '2025-07-25'
638649
date_type: EXACT
650+
breast_features:
651+
annotations_json:
652+
[
653+
{
654+
'id': 'scar',
655+
'region_id': 'left_axilla',
656+
'x': 711.7478637695312,
657+
'y': 53.868194580078125
658+
}
659+
]
639660
- id: c09d8676-953d-4643-8cf7-ebb7328e4bae
640661
duration_in_minutes: 8
641662
starts_at_time: '11:48'

manage_breast_screening/mammograms/forms/breast_feature_form.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ class BreastFeatureForm(Form):
2020
"type": "object",
2121
"properties": {
2222
"id": {"type": "string"},
23-
"name": {"type": "string"},
23+
"region_id": {"type": "string"},
2424
"x": {"type": "number"},
2525
"y": {"type": "number"},
2626
},
27-
"required": ["id", "name", "x", "y"],
27+
"required": ["id", "region_id", "x", "y"],
2828
"additionalProperties": False,
2929
},
3030
}
@@ -55,6 +55,18 @@ def clean_features(self):
5555
code="invalid",
5656
)
5757

58+
for feature in data:
59+
if feature["id"] not in BreastFeatureAnnotation.FeatureType:
60+
if feature["id"] == "pending":
61+
# Temporarily allow.
62+
# Remove this once the breast diagram component is fully complete.
63+
pass
64+
else:
65+
raise ValidationError(
66+
message="Select a feature type",
67+
code="invalid",
68+
)
69+
5870
return data
5971

6072

manage_breast_screening/mammograms/jinja2/mammograms/check_information/medical_information_card.jinja

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
"value" : { "html": medical_history(presented_medical_information.symptoms, 'No symptoms recorded') },
3636
"actions": presented_medical_information.symptoms_action
3737
},
38+
{
39+
"key": { "text": "Breast features" },
40+
"value" : { "html": medical_history(presented_medical_information.breast_features, 'No breast features recorded') },
41+
"actions": presented_medical_information.breast_features_action
42+
},
3843
{
3944
"key": { "text": "Other relevant information" },
4045
"value" : { "html": medical_history(presented_medical_information.other_relevant_information, 'No other information added') },

manage_breast_screening/mammograms/jinja2/mammograms/medical_information/breast_features/form.jinja

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{% extends "layout-app.jinja" %}
22

33
{% from "nhsuk/components/button/macro.jinja" import button %}
4-
{% from "nhsuk/components/card/macro.jinja" import card %}
5-
{% from "nhsuk/components/input/macro.jinja" import input %}
6-
{% from "nhsuk/components/summary-list/macro.jinja" import summaryList %}
74
{% from "nhsuk/macros/attributes.jinja" import nhsukAttributes %}
85
{% from "django_form_helpers.jinja" import form_error_summary %}
96

manage_breast_screening/mammograms/jinja2/mammograms/medical_information/section_cards.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
{% endif %}
113113
{% endmacro %}
114114

115-
{% macro breast_features_content(presented_medical_info, read_only=false) %}
115+
{% macro breast_features_content(presented_medical_info, read_only=false, debug=false) %}
116116
<p>Non-surgical scars, moles and other features that may appear on mammogram images</p>
117117
{% if presented_medical_info.breast_features %}
118118
{% set count = presented_medical_info.breast_features.feature_count %}
@@ -123,6 +123,7 @@
123123
<div class="nhsuk-grid-column-two-thirds">
124124
{{ app_breast_diagram({
125125
"read_only": true,
126+
"debug": debug,
126127
"text": count ~ " breast " ~ "feature" | plural(count) ~ " recorded",
127128
"version": presented_medical_info.breast_features.diagram_version
128129
}) }}

0 commit comments

Comments
 (0)