From 34ab2a2d1370871356a309a6061ac4c8aedc2aa1 Mon Sep 17 00:00:00 2001 From: rivalee Date: Wed, 22 Jul 2026 15:19:42 +0100 Subject: [PATCH 1/6] Redesign HRT, pregnancy, breastfeeding questions into something more simplified --- app/assets/javascript/main.js | 56 +++++++ app/lib/utils/medical-information.js | 64 ++------ .../appointments/medical-information.js | 95 +++++++++++ .../_includes/medical-information/index.njk | 14 +- .../other-relevant-information.njk | 151 ++++++------------ .../other-medical-information.html | 17 +- 6 files changed, 234 insertions(+), 163 deletions(-) diff --git a/app/assets/javascript/main.js b/app/assets/javascript/main.js index bfe28e13..3411f63e 100644 --- a/app/assets/javascript/main.js +++ b/app/assets/javascript/main.js @@ -95,6 +95,9 @@ document.addEventListener('DOMContentLoaded', () => { // Handle reset data in background setupResetSessionLink() + // Auto-save breast density factors when changed + setupBreastDensityFactorsAutosave() + // Reading workflow: auto-dismiss the opinion banner after a delay const opinionBanner = document.querySelector('[data-reading-opinion-banner]') if (opinionBanner) { @@ -185,6 +188,59 @@ document.addEventListener('DOMContentLoaded', () => { } }) +function setupBreastDensityFactorsAutosave() { + const saveTarget = document.querySelector('[data-breast-density-factors-save-url]') + if (!saveTarget) { + return + } + + const saveUrl = saveTarget.dataset.breastDensityFactorsSaveUrl + if (!saveUrl) { + return + } + + const selector = + 'input[name="appointment[medicalInformation][breastDensityFactors]"]' + const checkboxes = document.querySelectorAll(selector) + + if (checkboxes.length === 0) { + return + } + + const saveFactors = async () => { + const formData = new URLSearchParams() + const selectedCheckboxes = document.querySelectorAll(`${selector}:checked`) + + selectedCheckboxes.forEach((checkbox) => { + formData.append( + 'appointment[medicalInformation][breastDensityFactors]', + checkbox.value + ) + }) + + try { + const response = await fetch(saveUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'X-Requested-With': 'XMLHttpRequest' + }, + body: formData.toString() + }) + + if (!response.ok) { + throw new Error('Breast density factors auto-save failed') + } + } catch (error) { + console.error(error) + } + } + + checkboxes.forEach((checkbox) => { + checkbox.addEventListener('change', saveFactors) + }) +} + // Quick settings modal — press backtick (`) to open settings in a modal overlay. // On close, the page reloads to pick up any changes. document.addEventListener('keydown', (e) => { diff --git a/app/lib/utils/medical-information.js b/app/lib/utils/medical-information.js index 1834ab14..df9dbfae 100644 --- a/app/lib/utils/medical-information.js +++ b/app/lib/utils/medical-information.js @@ -429,59 +429,23 @@ const summariseOtherRelevantInformation = (medicalInformation) => { const summaries = [] - // HRT summary - const hrt = medicalInformation.hrt - if (hrt) { - if (hrt.hrtQuestion === 'yes') { - summaries.push( - `Taking HRT (started ${hrt.hrtDateStarted || 'date not specified'})` - ) - } else if (hrt.hrtQuestion === 'no-recently-stopped') { - if (hrt.hrtDateStopped) { - summaries.push(`Recently stopped HRT (stopped ${hrt.hrtDateStopped})`) - } else { - summaries.push('Recently stopped HRT') - } - } - // Don't add anything for 'no' - that's the default/negative state + const breastDensityFactorsRaw = medicalInformation.breastDensityFactors + const breastDensityFactors = Array.isArray(breastDensityFactorsRaw) + ? breastDensityFactorsRaw + : breastDensityFactorsRaw + ? [breastDensityFactorsRaw] + : [] + + if (breastDensityFactors.includes('hrt')) { + summaries.push('Taking HRT') } - // Pregnancy and breastfeeding summary - const pregBf = medicalInformation.pregnancyAndBreastfeeding - if (pregBf) { - // Pregnancy - if (pregBf.pregnancyStatus === 'yes') { - if (pregBf.pregnancyDueDate) { - summaries.push(`Pregnant (due ${pregBf.pregnancyDueDate})`) - } else { - summaries.push('Pregnant') - } - } else if (pregBf.pregnancyStatus === 'noButRecently') { - if (pregBf.pregnancyEndDate) { - summaries.push(`Recently pregnant (ended ${pregBf.pregnancyEndDate})`) - } else { - summaries.push('Recently pregnant') - } - } + if (breastDensityFactors.includes('pregnant')) { + summaries.push('Pregnant') + } - // Breastfeeding - if (pregBf.breastfeedingStatus === 'yes') { - if (pregBf.breastfeedingStartDate) { - summaries.push( - `Breastfeeding (started ${pregBf.breastfeedingStartDate})` - ) - } else { - summaries.push('Breastfeeding') - } - } else if (pregBf.breastfeedingStatus === 'recentlyStopped') { - if (pregBf.breastfeedingStopDate) { - summaries.push( - `Recently breastfeeding (stopped ${pregBf.breastfeedingStopDate})` - ) - } else { - summaries.push('Recently breastfeeding') - } - } + if (breastDensityFactors.includes('breastfeeding')) { + summaries.push('Breastfeeding') } // Other medical information (free text) diff --git a/app/routes/appointments/medical-information.js b/app/routes/appointments/medical-information.js index aee90aad..e77cdd3e 100644 --- a/app/routes/appointments/medical-information.js +++ b/app/routes/appointments/medical-information.js @@ -7,8 +7,103 @@ const { getReturnUrl, modalBreakout } = require('../../lib/utils/referrers') +const { getAppointmentData } = require('../../lib/utils/appointment-data') module.exports = (router) => { + // Auto-save breast density factors when checkboxes are changed + router.post( + '/clinics/:clinicId/appointments/:appointmentId/medical-information/breast-density-factors-save', + (req, res) => { + const data = req.session.data + const postedFactors = req.body?.appointment?.medicalInformation?.breastDensityFactors + + // No posted factors means all options are currently unchecked + const factors = Array.isArray(postedFactors) + ? postedFactors + : postedFactors + ? [postedFactors] + : [] + + if (!data.appointment) { + data.appointment = {} + } + + if (!data.appointment.medicalInformation) { + data.appointment.medicalInformation = {} + } + + data.appointment.medicalInformation.breastDensityFactors = factors + + // Keep a draft cache outside auto-stored form keys so later form posts + // cannot accidentally clear the latest autosaved checkbox state. + if (!data._medicalInformationDraft) { + data._medicalInformationDraft = {} + } + data._medicalInformationDraft.breastDensityFactors = factors + + res.status(204).send() + } + ) + + // Save other medical information while preserving breast density factors + router.post( + '/clinics/:clinicId/appointments/:appointmentId/medical-information/other-medical-information-save', + (req, res) => { + const { clinicId, appointmentId } = req.params + const data = req.session.data + const referrerChain = req.query.referrerChain + const scrollTo = req.query.scrollTo + + const appointmentMedicalInformation = data?.appointment?.medicalInformation + const postedBreastDensityFactors = + appointmentMedicalInformation?.breastDensityFactors + const cachedBreastDensityFactors = + data?._medicalInformationDraft?.breastDensityFactors + + const normalisedPostedBreastDensityFactors = + Array.isArray(postedBreastDensityFactors) + ? postedBreastDensityFactors + : postedBreastDensityFactors + ? [postedBreastDensityFactors] + : undefined + + if (normalisedPostedBreastDensityFactors) { + if (!data._medicalInformationDraft) { + data._medicalInformationDraft = {} + } + data._medicalInformationDraft.breastDensityFactors = + normalisedPostedBreastDensityFactors + } + + // If this submission did not include factors, keep the last saved values + if (!normalisedPostedBreastDensityFactors) + { + const savedAppointmentData = getAppointmentData(data, clinicId, appointmentId) + const savedBreastDensityFactors = + savedAppointmentData?.appointment?.medicalInformation?.breastDensityFactors + + if (cachedBreastDensityFactors) + { + data.appointment.medicalInformation.breastDensityFactors = + cachedBreastDensityFactors + } + else if (savedBreastDensityFactors) + { + data.appointment.medicalInformation.breastDensityFactors = + savedBreastDensityFactors + } + } + + const returnUrl = getReturnUrl( + `/clinics/${clinicId}/appointments/${appointmentId}/review-medical-information`, + referrerChain, + scrollTo + ) + + res.redirect(modalBreakout(returnUrl)) + } + ) + // Save breast features (includes converting JSON string to structured data) router.post( '/clinics/:clinicId/appointments/:appointmentId/medical-information/record-breast-features/save', diff --git a/app/views/_includes/medical-information/index.njk b/app/views/_includes/medical-information/index.njk index 78da700f..9237bfb3 100644 --- a/app/views/_includes/medical-information/index.njk +++ b/app/views/_includes/medical-information/index.njk @@ -229,19 +229,13 @@ {% include "_includes/summary-lists/medical-information/other-relevant-information.njk" %} {% endset %} -{% set otherRelevantInformationCount = 0 %} +{% set selectedBreastDensityFactors = appointment.medicalInformation.breastDensityFactors %} -{% if appointment.medicalInformation.hrt.hrtQuestion == 'yes' %} - {% set otherRelevantInformationCount = otherRelevantInformationCount + 1 %} +{% if selectedBreastDensityFactors and not (selectedBreastDensityFactors | isArray) %} + {% set selectedBreastDensityFactors = [selectedBreastDensityFactors] %} {% endif %} -{% if appointment.medicalInformation.pregnancyAndBreastfeeding.pregnancyStatus == 'yes' %} - {% set otherRelevantInformationCount = otherRelevantInformationCount + 1 %} -{% endif %} - -{% if appointment.medicalInformation.pregnancyAndBreastfeeding.breastfeedingStatus == 'yes' %} - {% set otherRelevantInformationCount = otherRelevantInformationCount + 1 %} -{% endif %} +{% set otherRelevantInformationCount = selectedBreastDensityFactors | length if selectedBreastDensityFactors else 0 %} {% if otherRelevantInformationCount > 0 %} {% set otherRelevantInformationSummary = otherRelevantInformationCount ~ " other relevant information added" %} diff --git a/app/views/_includes/summary-lists/medical-information/other-relevant-information.njk b/app/views/_includes/summary-lists/medical-information/other-relevant-information.njk index 9e969635..871914b5 100644 --- a/app/views/_includes/summary-lists/medical-information/other-relevant-information.njk +++ b/app/views/_includes/summary-lists/medical-information/other-relevant-information.njk @@ -1,121 +1,68 @@ {# app/views/_includes/summary-lists/medical-information/other-relevant-information #} -{% set hrtHtml %} - {% set hrtData = appointment.medicalInformation.hrt %} +{% set selectedBreastDensityFactors = appointment.medicalInformation.breastDensityFactors %} - {% if hrtData %} - {% if hrtData.hrtQuestion == 'yes' %} -

- Currently taking HRT -

-

- {# Example: "Started: September 2022" #} - Started: {{ hrtData.hrtDateStarted }} -

- {% elseif hrtData.hrtQuestion == 'no-recently-stopped' %} -

- Recently stopped taking HRT -

-

- Duration taken: {{ hrtData.hrtDurationBeforeStopping }}
- Date stopped: {{ hrtData.hrtDateStopped }}
-

- {% elseif hrtData.hrtQuestion == 'no' %} - Not taking HRT - {% else %} - No information provided - {% endif %} +{% if selectedBreastDensityFactors and not (selectedBreastDensityFactors | isArray) %} + {% set selectedBreastDensityFactors = [selectedBreastDensityFactors] %} +{% endif %} + +{% set breastDensityFactorsSummaryHtml %} + {% if selectedBreastDensityFactors and selectedBreastDensityFactors | length > 0 %} + {% else %} - {{ valueHtml }} +

No breast density factors added

{% endif %} {% endset %} -{% set pregnancyAndBreastfeedingHtml %} - {% set pregnancyAndBreastfeedingData = appointment.medicalInformation.pregnancyAndBreastfeeding %} - - {% if pregnancyAndBreastfeedingData %} - {% if pregnancyAndBreastfeedingData.pregnancyStatus == 'yes' %} -

- Currently pregnant -

-

- {# Example: "Due date: June 2026" #} - Due date: {{ pregnancyAndBreastfeedingData.pregnancyDueDate }} -

- {% elseif pregnancyAndBreastfeedingData.pregnancyStatus == 'noButRecently' %} -

- Recently pregnant -

-

- Pregnancy ended: {{ pregnancyAndBreastfeedingData.pregnancyEndDate }} -

- {% elseif pregnancyAndBreastfeedingData.pregnancyStatus == 'noNotPregnant' %} -

Not pregnant

- {% else %} -

No information provided

- {% endif %} - - {% if pregnancyAndBreastfeedingData.breastfeedingStatus == 'yes' %} -

- Currently breastfeeding -

-

- {# Example: "Started: January 2026" #} - Started: {{ pregnancyAndBreastfeedingData.breastfeedingStartDate }} -

- {% elseif pregnancyAndBreastfeedingData.breastfeedingStatus == 'recentlyStopped' %} -

- Recently breastfeeding -

-

- Date stopped: {{ pregnancyAndBreastfeedingData.breastfeedingStopDate }} -

- {% elseif pregnancyAndBreastfeedingData.breastfeedingStatus == 'no' %} -

Not breastfeeding

- {% else %} -

No information provided

- {% endif %} - {% else %} - {{ valueHtml }} - {% endif %} +{% set breastDensityFactorsInputHtml %} +
+ {{ checkboxes({ + name: "appointment[medicalInformation][breastDensityFactors]", + values: selectedBreastDensityFactors, + classes: "nhsuk-checkboxes--small", + hint: { + text: "Select any current or recent considerations" + }, + items: [ + { + value: "hrt", + text: "HRT (hormone replacement therapy)" + }, + { + value: "pregnant", + text: "Pregnant" + }, + { + value: "breastfeeding", + text: "Breastfeeding" + } + ] + }) }} {% endset %} {{ summaryList({ rows: [ { key: { - text: "Hormone replacement therapy (HRT)" + text: "Breast density factors" }, value: { - html: hrtHtml - }, - actions: { - items: [ - { - href: contextUrl + "/medical-information/hormone-replacement-therapy" | urlWithReferrer(referrerChain | appendReferrer(currentUrl), scrollTo), - text: "Change", - visuallyHiddenText: "hormone replacement therapy (HRT)" - } - ] - } if allowEdits - }, - { - key: { - text: "Pregnancy and breastfeeding" - }, - value: { - html: pregnancyAndBreastfeedingHtml - }, - actions: { - items: [ - { - href: contextUrl + "/medical-information/pregnancy-and-breastfeeding" | urlWithReferrer(referrerChain | appendReferrer(currentUrl), scrollTo), - text: "Change", - visuallyHiddenText: "pregnancy and breastfeeding" - } - ] - } if allowEdits + html: breastDensityFactorsInputHtml if allowEdits else breastDensityFactorsSummaryHtml + } }, { key: { diff --git a/app/views/appointments/medical-information/other-medical-information.html b/app/views/appointments/medical-information/other-medical-information.html index a83beb76..77d881d4 100644 --- a/app/views/appointments/medical-information/other-medical-information.html +++ b/app/views/appointments/medical-information/other-medical-information.html @@ -6,10 +6,16 @@ {% set gridColumn = "nhsuk-grid-column-two-thirds" %} -{% set formAction = './../review-medical-information' | getReturnUrl(referrerChain, query.scrollTo) %} +{% set formAction = './other-medical-information-save' | urlWithReferrer(referrerChain, query.scrollTo) %} {% block pageContent %} + {% set selectedBreastDensityFactors = appointment.medicalInformation.breastDensityFactors %} + + {% if selectedBreastDensityFactors and not (selectedBreastDensityFactors | isArray) %} + {% set selectedBreastDensityFactors = [selectedBreastDensityFactors] %} + {% endif %} +

{{ participant | getFullName }} @@ -26,6 +32,15 @@

rows: 10 }) }} + {% if selectedBreastDensityFactors %} + {% for factor in selectedBreastDensityFactors %} + {{ appHiddenInput({ + name: "appointment[medicalInformation][breastDensityFactors]", + value: factor + }) }} + {% endfor %} + {% endif %} + {{ button({ text: "Save" }) }} From ff0fa2d3fccc9e368fa9a86851386ccc3228c349 Mon Sep 17 00:00:00 2001 From: rivalee Date: Mon, 27 Jul 2026 10:01:49 +0100 Subject: [PATCH 2/6] Split other relevant medical info into two sections and two review pages --- app/assets/javascript/main.js | 23 ++++- app/lib/utils/medical-information.js | 13 ++- .../appointments/medical-information.js | 46 +++++++++- .../_includes/medical-information/index.njk | 86 +++++++++++------- .../summary-lists/medical-info-summary.njk | 69 ++++++++++---- .../breast-density-factors.njk | 90 +++++++++++++++++++ .../other-relevant-information.njk | 64 +------------ app/views/appointments/check-information.html | 20 ++++- .../breast-density-factors.html | 45 ++++++++++ .../other-relevant-information.html | 12 ++- .../other-medical-information.html | 22 ++++- 11 files changed, 354 insertions(+), 136 deletions(-) create mode 100644 app/views/_includes/summary-lists/medical-information/breast-density-factors.njk create mode 100644 app/views/appointments/confirm-information/breast-density-factors.html diff --git a/app/assets/javascript/main.js b/app/assets/javascript/main.js index 3411f63e..416077ca 100644 --- a/app/assets/javascript/main.js +++ b/app/assets/javascript/main.js @@ -199,17 +199,21 @@ function setupBreastDensityFactorsAutosave() { return } - const selector = + const checkboxSelector = 'input[name="appointment[medicalInformation][breastDensityFactors]"]' - const checkboxes = document.querySelectorAll(selector) + const hrtRadioSelector = + 'input[name="appointment[medicalInformation][breastDensityFactorsHrt]"]' + const checkboxes = document.querySelectorAll(checkboxSelector) + const hrtRadios = document.querySelectorAll(hrtRadioSelector) - if (checkboxes.length === 0) { + if (checkboxes.length === 0 && hrtRadios.length === 0) { return } const saveFactors = async () => { const formData = new URLSearchParams() - const selectedCheckboxes = document.querySelectorAll(`${selector}:checked`) + const selectedCheckboxes = document.querySelectorAll(`${checkboxSelector}:checked`) + const selectedHrtRadio = document.querySelector(`${hrtRadioSelector}:checked`) selectedCheckboxes.forEach((checkbox) => { formData.append( @@ -218,6 +222,13 @@ function setupBreastDensityFactorsAutosave() { ) }) + if (selectedHrtRadio) { + formData.append( + 'appointment[medicalInformation][breastDensityFactorsHrt]', + selectedHrtRadio.value + ) + } + try { const response = await fetch(saveUrl, { method: 'POST', @@ -239,6 +250,10 @@ function setupBreastDensityFactorsAutosave() { checkboxes.forEach((checkbox) => { checkbox.addEventListener('change', saveFactors) }) + + hrtRadios.forEach((radio) => { + radio.addEventListener('change', saveFactors) + }) } // Quick settings modal — press backtick (`) to open settings in a modal overlay. diff --git a/app/lib/utils/medical-information.js b/app/lib/utils/medical-information.js index df9dbfae..df79a46f 100644 --- a/app/lib/utils/medical-information.js +++ b/app/lib/utils/medical-information.js @@ -435,10 +435,9 @@ const summariseOtherRelevantInformation = (medicalInformation) => { : breastDensityFactorsRaw ? [breastDensityFactorsRaw] : [] - - if (breastDensityFactors.includes('hrt')) { - summaries.push('Taking HRT') - } + const breastDensityFactorsHrt = + medicalInformation.breastDensityFactorsHrt || + (breastDensityFactors.includes('hrt') ? 'yes' : undefined) if (breastDensityFactors.includes('pregnant')) { summaries.push('Pregnant') @@ -448,6 +447,12 @@ const summariseOtherRelevantInformation = (medicalInformation) => { summaries.push('Breastfeeding') } + if (breastDensityFactorsHrt === 'yes') { + summaries.push('Taking HRT') + } else if (breastDensityFactorsHrt === 'no') { + summaries.push('Not taking HRT') + } + // Other medical information (free text) if (medicalInformation.otherMedicalInformation) { // Truncate if very long, otherwise show as-is diff --git a/app/routes/appointments/medical-information.js b/app/routes/appointments/medical-information.js index e77cdd3e..9fade30a 100644 --- a/app/routes/appointments/medical-information.js +++ b/app/routes/appointments/medical-information.js @@ -16,6 +16,7 @@ module.exports = (router) => { (req, res) => { const data = req.session.data const postedFactors = req.body?.appointment?.medicalInformation?.breastDensityFactors + const postedHrt = req.body?.appointment?.medicalInformation?.breastDensityFactorsHrt // No posted factors means all options are currently unchecked const factors = Array.isArray(postedFactors) @@ -23,6 +24,7 @@ module.exports = (router) => { : postedFactors ? [postedFactors] : [] + const nonHrtFactors = factors.filter((factor) => factor !== 'hrt') if (!data.appointment) { data.appointment = {} @@ -32,14 +34,22 @@ module.exports = (router) => { data.appointment.medicalInformation = {} } - data.appointment.medicalInformation.breastDensityFactors = factors + data.appointment.medicalInformation.breastDensityFactors = nonHrtFactors + + if (postedHrt === 'yes' || postedHrt === 'no') { + data.appointment.medicalInformation.breastDensityFactorsHrt = postedHrt + } // Keep a draft cache outside auto-stored form keys so later form posts // cannot accidentally clear the latest autosaved checkbox state. if (!data._medicalInformationDraft) { data._medicalInformationDraft = {} } - data._medicalInformationDraft.breastDensityFactors = factors + data._medicalInformationDraft.breastDensityFactors = nonHrtFactors + + if (postedHrt === 'yes' || postedHrt === 'no') { + data._medicalInformationDraft.breastDensityFactorsHrt = postedHrt + } res.status(204).send() } @@ -57,8 +67,12 @@ module.exports = (router) => { const appointmentMedicalInformation = data?.appointment?.medicalInformation const postedBreastDensityFactors = appointmentMedicalInformation?.breastDensityFactors + const postedBreastDensityFactorsHrt = + appointmentMedicalInformation?.breastDensityFactorsHrt const cachedBreastDensityFactors = data?._medicalInformationDraft?.breastDensityFactors + const cachedBreastDensityFactorsHrt = + data?._medicalInformationDraft?.breastDensityFactorsHrt const normalisedPostedBreastDensityFactors = Array.isArray(postedBreastDensityFactors) @@ -72,7 +86,15 @@ module.exports = (router) => { data._medicalInformationDraft = {} } data._medicalInformationDraft.breastDensityFactors = - normalisedPostedBreastDensityFactors + normalisedPostedBreastDensityFactors.filter((factor) => factor !== 'hrt') + } + + if (postedBreastDensityFactorsHrt === 'yes' || postedBreastDensityFactorsHrt === 'no') { + if (!data._medicalInformationDraft) { + data._medicalInformationDraft = {} + } + data._medicalInformationDraft.breastDensityFactorsHrt = + postedBreastDensityFactorsHrt } // If this submission did not include factors, keep the last saved values @@ -94,6 +116,24 @@ module.exports = (router) => { } } + if (!postedBreastDensityFactorsHrt) + { + const savedAppointmentData = getAppointmentData(data, clinicId, appointmentId) + const savedBreastDensityFactorsHrt = + savedAppointmentData?.appointment?.medicalInformation?.breastDensityFactorsHrt + + if (cachedBreastDensityFactorsHrt) + { + data.appointment.medicalInformation.breastDensityFactorsHrt = + cachedBreastDensityFactorsHrt + } + else if (savedBreastDensityFactorsHrt) + { + data.appointment.medicalInformation.breastDensityFactorsHrt = + savedBreastDensityFactorsHrt + } + } + const returnUrl = getReturnUrl( `/clinics/${clinicId}/appointments/${appointmentId}/review-medical-information`, referrerChain, diff --git a/app/views/_includes/medical-information/index.njk b/app/views/_includes/medical-information/index.njk index 9237bfb3..0091efeb 100644 --- a/app/views/_includes/medical-information/index.njk +++ b/app/views/_includes/medical-information/index.njk @@ -219,54 +219,80 @@ {% endswitch %} {# -------------------------------------------------------------- #} -{# Other relevant information #} -{% set sectionHeading = "Other relevant information" %} -{% set subHeading = "Including HRT, pregnancy, breastfeeding and mammographer notes" %} -{% set sectionId = sectionHeading | kebabCase %} -{% set scrollTo = sectionId %} +{# Breast density factors #} +{% set breastDensitySectionId = "breast-density-factors" %} +{% set scrollTo = breastDensitySectionId %} -{% set otherRelevantInformationHtml %} - {% include "_includes/summary-lists/medical-information/other-relevant-information.njk" %} +{% set breastDensityFactorsHtml %} + {% include "_includes/summary-lists/medical-information/breast-density-factors.njk" %} {% endset %} -{% set selectedBreastDensityFactors = appointment.medicalInformation.breastDensityFactors %} +{# Count selected breast density factors for expander summary #} +{% set _bdf = appointment.medicalInformation.breastDensityFactors %} +{% if _bdf and not (_bdf | isArray) %}{% set _bdf = [_bdf] %}{% endif %} +{% set _bdfHrt = appointment.medicalInformation.breastDensityFactorsHrt %} +{% if not _bdfHrt and _bdf and _bdf | includes("hrt") %}{% set _bdfHrt = "yes" %}{% endif %} +{% set breastDensityCount = 0 %} +{% if _bdfHrt == "yes" %}{% set breastDensityCount = breastDensityCount + 1 %}{% endif %} +{% if _bdf and _bdf | includes("pregnant") %}{% set breastDensityCount = breastDensityCount + 1 %}{% endif %} +{% if _bdf and _bdf | includes("breastfeeding") %}{% set breastDensityCount = breastDensityCount + 1 %}{% endif %} +{% set breastDensityContentsSummary = breastDensityCount ~ (" breast density factor added" if breastDensityCount == 1 else " breast density factors added") if breastDensityCount > 0 else "No breast density factors added" %} -{% if selectedBreastDensityFactors and not (selectedBreastDensityFactors | isArray) %} - {% set selectedBreastDensityFactors = [selectedBreastDensityFactors] %} -{% endif %} +{% switch displayFormat %} + {% case 'flat' %} +

Breast density factors

+ {{ breastDensityFactorsHtml | safe }} + {% case 'card' %} + {% call card({ + heading: "Breast density factors", + attributes: { + id: breastDensitySectionId + } + }) %} + {{ breastDensityFactorsHtml | safe }} + {% endcall %} + {% default %} + {{ appDetails({ + id: breastDensitySectionId, + classes: "nhsuk-expander js-expandable-section js-track-expanded", + summaryText: "Breast density factors", + contentsSummary: breastDensityContentsSummary, + html: breastDensityFactorsHtml, + status: "To review" + }) }} +{% endswitch %} -{% set otherRelevantInformationCount = selectedBreastDensityFactors | length if selectedBreastDensityFactors else 0 %} +{# -------------------------------------------------------------- #} +{# Other medical information #} +{% set otherMedicalInfoSectionId = "other-medical-information" %} +{% set scrollTo = otherMedicalInfoSectionId %} -{% if otherRelevantInformationCount > 0 %} - {% set otherRelevantInformationSummary = otherRelevantInformationCount ~ " other relevant information added" %} -{% else %} - {% set otherRelevantInformationSummary = "No other relevant information added" %} -{% endif %} +{% set otherMedicalInformationHtml %} + {% include "_includes/summary-lists/medical-information/other-relevant-information.njk" %} +{% endset %} + +{% set otherMedicalInfoContentsSummary = "Other medical information added" if appointment.medicalInformation.otherMedicalInformation else "No other medical information added" %} {% switch displayFormat %} {% case 'flat' %} -

{{ sectionHeading }}

- {{ otherRelevantInformationHtml | safe }} +

Other medical information

+ {{ otherMedicalInformationHtml | safe }} {% case 'card' %} {% call card({ - heading: sectionHeading, + heading: "Other medical information", attributes: { - id: sectionId + id: otherMedicalInfoSectionId } }) %} -

- {{ subHeading }} -

- {{ otherRelevantInformationHtml | safe }} + {{ otherMedicalInformationHtml | safe }} {% endcall %} {% default %} {{ appDetails({ - id: sectionId, + id: otherMedicalInfoSectionId, classes: "nhsuk-expander js-expandable-section js-track-expanded", - summaryText: sectionHeading, - subtitle: subHeading, - contentsSummary: otherRelevantInformationSummary, - html: otherRelevantInformationHtml, + summaryText: "Other medical information", + contentsSummary: otherMedicalInfoContentsSummary, + html: otherMedicalInformationHtml, status: "To review" }) }} {% endswitch %} diff --git a/app/views/_includes/summary-lists/medical-info-summary.njk b/app/views/_includes/summary-lists/medical-info-summary.njk index 4fb122de..9991a268 100644 --- a/app/views/_includes/summary-lists/medical-info-summary.njk +++ b/app/views/_includes/summary-lists/medical-info-summary.njk @@ -127,23 +127,36 @@ {# Build referrer chain for add journey: confirmation -> review #} {% set mammogramsAddReferrerChain = currentUrl | appendReferrer(contextUrl + "/confirm-information/previous-mammograms") %} -{# Other relevant information summary #} -{# Get other relevant information summaries #} -{% set otherRelevantInfoSummaries = appointment.medicalInformation | summariseOtherRelevantInformation %} -{% set otherRelevantInfoCount = otherRelevantInfoSummaries | length %} +{# Breast density factors summary #} +{% set _bdf = appointment.medicalInformation.breastDensityFactors %} +{% if _bdf and not (_bdf | isArray) %}{% set _bdf = [_bdf] %}{% endif %} +{% set _bdfHrt = appointment.medicalInformation.breastDensityFactorsHrt %} +{% if not _bdfHrt and _bdf and _bdf | includes("hrt") %}{% set _bdfHrt = "yes" %}{% endif %} -{# Build other relevant information HTML #} -{% set otherRelevantInfoHtml %} - {% if otherRelevantInfoCount == 0 %} -

No other information added

- {% elif otherRelevantInfoCount == 1 %} -

{{ otherRelevantInfoSummaries[0] }}

- {% else %} +{% set breastDensityFactorsHtml %} + {% if _bdfHrt == "yes" or (_bdf and _bdf | length > 0) %}
    - {% for summary in otherRelevantInfoSummaries %} -
  • {{ summary }}
  • - {% endfor %} + {% if _bdfHrt == "yes" %}
  • Taking HRT
  • {% endif %} + {% if _bdf and _bdf | includes("pregnant") %}
  • Pregnant
  • {% endif %} + {% if _bdf and _bdf | includes("breastfeeding") %}
  • Breastfeeding
  • {% endif %}
+ {% else %} +

No breast density factors added

+ {% endif %} +{% endset %} + +{% set breastDensityCount = 0 %} +{% if _bdfHrt == "yes" %}{% set breastDensityCount = breastDensityCount + 1 %}{% endif %} +{% if _bdf and _bdf | includes("pregnant") %}{% set breastDensityCount = breastDensityCount + 1 %}{% endif %} +{% if _bdf and _bdf | includes("breastfeeding") %}{% set breastDensityCount = breastDensityCount + 1 %}{% endif %} + +{# Other medical information summary #} +{% set otherMedicalInfo = appointment.medicalInformation.otherMedicalInformation %} +{% set otherMedicalInfoHtml %} + {% if otherMedicalInfo %} +

{{ otherMedicalInfo }}

+ {% else %} +

No other medical information added

{% endif %} {% endset %} @@ -266,20 +279,40 @@ }) %} {% endif %} -{% if not showOnlyPopulated or otherRelevantInfoCount > 0 %} +{% if not showOnlyPopulated or breastDensityCount > 0 %} + {% set rows = rows | push({ + key: { + text: "Breast density factors" + }, + value: { + html: breastDensityFactorsHtml + }, + actions: { + items: [ + { + href: ("./confirm-information/breast-density-factors") | urlWithReferrer(currentUrl), + text: "View or change", + visuallyHiddenText: "breast density factors" + } + ] + } if allowEdits + }) %} +{% endif %} + +{% if not showOnlyPopulated or otherMedicalInfo %} {% set rows = rows | push({ key: { - text: "Other relevant information" + text: "Other medical information" }, value: { - html: otherRelevantInfoHtml + html: otherMedicalInfoHtml }, actions: { items: [ { href: ("./confirm-information/other-relevant-information") | urlWithReferrer(currentUrl), text: "View or change", - visuallyHiddenText: "other relevant information" + visuallyHiddenText: "other medical information" } ] } if allowEdits diff --git a/app/views/_includes/summary-lists/medical-information/breast-density-factors.njk b/app/views/_includes/summary-lists/medical-information/breast-density-factors.njk new file mode 100644 index 00000000..efbd26bc --- /dev/null +++ b/app/views/_includes/summary-lists/medical-information/breast-density-factors.njk @@ -0,0 +1,90 @@ +{# app/views/_includes/summary-lists/medical-information/breast-density-factors.njk #} + +{% set selectedBreastDensityFactors = appointment.medicalInformation.breastDensityFactors %} +{% set breastDensityFactorsHrt = appointment.medicalInformation.breastDensityFactorsHrt %} + +{% if selectedBreastDensityFactors and not (selectedBreastDensityFactors | isArray) %} + {% set selectedBreastDensityFactors = [selectedBreastDensityFactors] %} +{% endif %} + +{% if not breastDensityFactorsHrt and selectedBreastDensityFactors and selectedBreastDensityFactors | includes("hrt") %} + {% set breastDensityFactorsHrt = "yes" %} +{% endif %} + +{% set breastDensityFactorsSummaryHtml %} + {% if breastDensityFactorsHrt == "yes" or (selectedBreastDensityFactors and selectedBreastDensityFactors | length > 0) %} +
    + {% if breastDensityFactorsHrt == "yes" or (selectedBreastDensityFactors and selectedBreastDensityFactors | includes("hrt")) %} +
  • Taking HRT
  • + {% endif %} + {% if selectedBreastDensityFactors | includes("pregnant") %} +
  • Pregnant
  • + {% endif %} + {% if selectedBreastDensityFactors | includes("breastfeeding") %} +
  • Breastfeeding
  • + {% endif %} +
+ {% else %} +

No breast density factors added

+ {% endif %} +{% endset %} + +{% set breastDensityFactorsInputHtml %} +
+ +

Select any current or recent considerations

+ + {{ checkboxes({ + name: "appointment[medicalInformation][breastDensityFactors]", + values: selectedBreastDensityFactors, + classes: "nhsuk-checkboxes--small", + items: [ + { + value: "pregnant", + text: "Pregnant" + }, + { + value: "breastfeeding", + text: "Breastfeeding" + } + ] + }) }} + + {{ radios({ + name: "appointment[medicalInformation][breastDensityFactorsHrt]", + value: breastDensityFactorsHrt, + classes: "nhsuk-radios--inline nhsuk-radios--small", + fieldset: { + legend: { + text: "HRT (hormone replacement therapy)", + classes: "nhsuk-fieldset__legend--s" + } + }, + items: [ + { + value: "yes", + text: "Yes" + }, + { + value: "no", + text: "No" + } + ] + }) }} +{% endset %} + +{{ summaryList({ + rows: [ + { + key: { + text: "Breast density factors" + }, + value: { + html: breastDensityFactorsInputHtml if allowEdits else breastDensityFactorsSummaryHtml + } + } + ] +} | openInModal | handleSummaryListMissingInformation | removeLastRowBorder ) }} diff --git a/app/views/_includes/summary-lists/medical-information/other-relevant-information.njk b/app/views/_includes/summary-lists/medical-information/other-relevant-information.njk index 871914b5..6a3aa8ef 100644 --- a/app/views/_includes/summary-lists/medical-information/other-relevant-information.njk +++ b/app/views/_includes/summary-lists/medical-information/other-relevant-information.njk @@ -1,69 +1,9 @@ {# app/views/_includes/summary-lists/medical-information/other-relevant-information #} - -{% set selectedBreastDensityFactors = appointment.medicalInformation.breastDensityFactors %} - -{% if selectedBreastDensityFactors and not (selectedBreastDensityFactors | isArray) %} - {% set selectedBreastDensityFactors = [selectedBreastDensityFactors] %} -{% endif %} - -{% set breastDensityFactorsSummaryHtml %} - {% if selectedBreastDensityFactors and selectedBreastDensityFactors | length > 0 %} -
    - {% if selectedBreastDensityFactors | includes("hrt") %} -
  • Taking HRT
  • - {% endif %} - {% if selectedBreastDensityFactors | includes("pregnant") %} -
  • Pregnant
  • - {% endif %} - {% if selectedBreastDensityFactors | includes("breastfeeding") %} -
  • Breastfeeding
  • - {% endif %} -
- {% else %} -

No breast density factors added

- {% endif %} -{% endset %} - -{% set breastDensityFactorsInputHtml %} -
- - {{ checkboxes({ - name: "appointment[medicalInformation][breastDensityFactors]", - values: selectedBreastDensityFactors, - classes: "nhsuk-checkboxes--small", - hint: { - text: "Select any current or recent considerations" - }, - items: [ - { - value: "hrt", - text: "HRT (hormone replacement therapy)" - }, - { - value: "pregnant", - text: "Pregnant" - }, - { - value: "breastfeeding", - text: "Breastfeeding" - } - ] - }) }} -{% endset %} +{# Shows only the other medical information (free-text) row. + Breast density factors have their own include: breast-density-factors.njk #} {{ summaryList({ rows: [ - { - key: { - text: "Breast density factors" - }, - value: { - html: breastDensityFactorsInputHtml if allowEdits else breastDensityFactorsSummaryHtml - } - }, { key: { text: "Other medical information" diff --git a/app/views/appointments/check-information.html b/app/views/appointments/check-information.html index ea32df8d..8a061f52 100644 --- a/app/views/appointments/check-information.html +++ b/app/views/appointments/check-information.html @@ -144,16 +144,28 @@ } }) }} - {# Other relevant information card #} - {% set otherRelevantInformationHtml %} + {# Breast density factors card #} + {% set breastDensityFactorsHtml %} + {% include "_includes/summary-lists/medical-information/breast-density-factors.njk" %} + {% endset %} + + {{ card({ + heading: "Breast density factors", + headingLevel: "2", + feature: true, + descriptionHtml: breastDensityFactorsHtml + }) }} + + {# Other medical information card #} + {% set otherMedicalInformationHtml %} {% include "_includes/summary-lists/medical-information/other-relevant-information.njk" %} {% endset %} {{ card({ - heading: "Other relevant medical information", + heading: "Other medical information", headingLevel: "2", feature: true, - descriptionHtml: otherRelevantInformationHtml + descriptionHtml: otherMedicalInformationHtml }) }} {% endset %} diff --git a/app/views/appointments/confirm-information/breast-density-factors.html b/app/views/appointments/confirm-information/breast-density-factors.html new file mode 100644 index 00000000..18cae417 --- /dev/null +++ b/app/views/appointments/confirm-information/breast-density-factors.html @@ -0,0 +1,45 @@ +{# app/views/appointments/confirm-information/breast-density-factors.html #} + +{% extends 'layout-appointment.html' %} + +{% set pageHeading = "Review breast density factors" %} +{% set showNavigation = false %} +{% set activeWorkflowStep = 'check-information' %} +{% set hideBackLink = true %} + +{% set allowEdits = true %} + +{% set gridColumn = "nhsuk-grid-column-full" %} + +{% set scrollTo = "breast-density-factors" %} + +{% block pageContent %} + + {# TODO: Ideally this would be before the main element #} + {{ backLink({ + href: "../check-information" | getReturnUrl(referrerChain), + text: "Back", + classes: "nhsuk-u-margin-top-0 nhsuk-u-margin-bottom-4" + }) }} + +

{{ pageHeading }}

+ + {% set breastDensityFactorsHtml %} + {% include "_includes/summary-lists/medical-information/breast-density-factors.njk" %} + {% endset %} + + {{ card({ + heading: "Breast density factors", + headingLevel: "2", + feature: true, + descriptionHtml: breastDensityFactorsHtml + }) }} + +
+ {{ button({ + text: "Continue", + href: "../check-information" | getReturnUrl(referrerChain) + }) }} +
+ +{% endblock %} diff --git a/app/views/appointments/confirm-information/other-relevant-information.html b/app/views/appointments/confirm-information/other-relevant-information.html index 8b4a3761..a72a2be8 100644 --- a/app/views/appointments/confirm-information/other-relevant-information.html +++ b/app/views/appointments/confirm-information/other-relevant-information.html @@ -2,7 +2,7 @@ {% extends 'layout-appointment.html' %} -{% set pageHeading = "Review other relevant information" %} +{% set pageHeading = "Review other medical information" %} {% set showNavigation = false %} {% set activeWorkflowStep = 'check-information' %} {% set hideBackLink = true %} @@ -11,7 +11,7 @@ {% set gridColumn = "nhsuk-grid-column-full" %} -{% set scrollTo = "other-relevant-information" %} +{% set scrollTo = "other-medical-information" %} {% block pageContent %} @@ -24,19 +24,17 @@

{{ pageHeading }}

- {# Include the full other relevant information summary in a feature card #} - {% set otherRelevantInformationHtml %} + {% set otherMedicalInformationHtml %} {% include "_includes/summary-lists/medical-information/other-relevant-information.njk" %} {% endset %} {{ card({ - heading: "Other relevant medical information", + heading: "Other medical information", headingLevel: "2", feature: true, - descriptionHtml: otherRelevantInformationHtml + descriptionHtml: otherMedicalInformationHtml }) }} - {# Continue button back to check information #}
{{ button({ text: "Continue", diff --git a/app/views/appointments/medical-information/other-medical-information.html b/app/views/appointments/medical-information/other-medical-information.html index 77d881d4..de2d8873 100644 --- a/app/views/appointments/medical-information/other-medical-information.html +++ b/app/views/appointments/medical-information/other-medical-information.html @@ -11,11 +11,16 @@ {% block pageContent %} {% set selectedBreastDensityFactors = appointment.medicalInformation.breastDensityFactors %} + {% set breastDensityFactorsHrt = appointment.medicalInformation.breastDensityFactorsHrt %} {% if selectedBreastDensityFactors and not (selectedBreastDensityFactors | isArray) %} {% set selectedBreastDensityFactors = [selectedBreastDensityFactors] %} {% endif %} + {% if not breastDensityFactorsHrt and selectedBreastDensityFactors and selectedBreastDensityFactors | includes("hrt") %} + {% set breastDensityFactorsHrt = "yes" %} + {% endif %} +

{{ participant | getFullName }} @@ -34,13 +39,22 @@

{% if selectedBreastDensityFactors %} {% for factor in selectedBreastDensityFactors %} - {{ appHiddenInput({ - name: "appointment[medicalInformation][breastDensityFactors]", - value: factor - }) }} + {% if factor != "hrt" %} + {{ appHiddenInput({ + name: "appointment[medicalInformation][breastDensityFactors]", + value: factor + }) }} + {% endif %} {% endfor %} {% endif %} + {% if breastDensityFactorsHrt %} + {{ appHiddenInput({ + name: "appointment[medicalInformation][breastDensityFactorsHrt]", + value: breastDensityFactorsHrt + }) }} + {% endif %} + {{ button({ text: "Save" }) }} From 005896832baec8641293ce9e90f311484ec658be Mon Sep 17 00:00:00 2001 From: rivalee Date: Mon, 27 Jul 2026 10:50:36 +0100 Subject: [PATCH 3/6] Fix bug --- app/assets/javascript/main.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/assets/javascript/main.js b/app/assets/javascript/main.js index 416077ca..e59dd167 100644 --- a/app/assets/javascript/main.js +++ b/app/assets/javascript/main.js @@ -210,6 +210,34 @@ function setupBreastDensityFactorsAutosave() { return } + const updateBreastDensityFactorsSummary = () => { + // Find the breast-density-factors section and update its contents summary + const section = document.getElementById('breast-density-factors') + if (!section) { + return + } + + // Count selected factors + const selectedCheckboxes = document.querySelectorAll(`${checkboxSelector}:checked`) + const selectedHrtRadio = document.querySelector(`${hrtRadioSelector}:checked`) + let count = selectedCheckboxes.length + if (selectedHrtRadio && selectedHrtRadio.value === 'yes') { + count += 1 + } + + // Find and update the contents summary span + const summarySpan = section.querySelector('.app-details__contents-summary') + if (summarySpan) { + if (count === 0) { + summarySpan.textContent = 'No breast density factors added' + } else if (count === 1) { + summarySpan.textContent = '1 breast density factor added' + } else { + summarySpan.textContent = count + ' breast density factors added' + } + } + } + const saveFactors = async () => { const formData = new URLSearchParams() const selectedCheckboxes = document.querySelectorAll(`${checkboxSelector}:checked`) @@ -242,6 +270,9 @@ function setupBreastDensityFactorsAutosave() { if (!response.ok) { throw new Error('Breast density factors auto-save failed') } + + // Update the summary text in the section after successful save + updateBreastDensityFactorsSummary() } catch (error) { console.error(error) } From 67f8c9e673eb13e602aea0783965c69b72a66d54 Mon Sep 17 00:00:00 2001 From: rivalee Date: Mon, 27 Jul 2026 14:22:24 +0100 Subject: [PATCH 4/6] fix order of things --- app/views/_includes/summary-lists/medical-info-summary.njk | 5 +++-- .../medical-information/breast-density-factors.njk | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/views/_includes/summary-lists/medical-info-summary.njk b/app/views/_includes/summary-lists/medical-info-summary.njk index 9991a268..a0e72818 100644 --- a/app/views/_includes/summary-lists/medical-info-summary.njk +++ b/app/views/_includes/summary-lists/medical-info-summary.njk @@ -134,11 +134,12 @@ {% if not _bdfHrt and _bdf and _bdf | includes("hrt") %}{% set _bdfHrt = "yes" %}{% endif %} {% set breastDensityFactorsHtml %} - {% if _bdfHrt == "yes" or (_bdf and _bdf | length > 0) %} + {% if _bdfHrt == "yes" or _bdfHrt == "no" or (_bdf and _bdf | length > 0) %}
    - {% if _bdfHrt == "yes" %}
  • Taking HRT
  • {% endif %} {% if _bdf and _bdf | includes("pregnant") %}
  • Pregnant
  • {% endif %} {% if _bdf and _bdf | includes("breastfeeding") %}
  • Breastfeeding
  • {% endif %} + {% if _bdfHrt == "yes" %}
  • Taking HRT
  • {% endif %} + {% if _bdfHrt == "no" %}
  • Not taking HRT
  • {% endif %}
{% else %}

No breast density factors added

diff --git a/app/views/_includes/summary-lists/medical-information/breast-density-factors.njk b/app/views/_includes/summary-lists/medical-information/breast-density-factors.njk index efbd26bc..cbd1276f 100644 --- a/app/views/_includes/summary-lists/medical-information/breast-density-factors.njk +++ b/app/views/_includes/summary-lists/medical-information/breast-density-factors.njk @@ -14,15 +14,15 @@ {% set breastDensityFactorsSummaryHtml %} {% if breastDensityFactorsHrt == "yes" or (selectedBreastDensityFactors and selectedBreastDensityFactors | length > 0) %}
    - {% if breastDensityFactorsHrt == "yes" or (selectedBreastDensityFactors and selectedBreastDensityFactors | includes("hrt")) %} -
  • Taking HRT
  • - {% endif %} {% if selectedBreastDensityFactors | includes("pregnant") %}
  • Pregnant
  • {% endif %} {% if selectedBreastDensityFactors | includes("breastfeeding") %}
  • Breastfeeding
  • {% endif %} + {% if breastDensityFactorsHrt == "yes" or (selectedBreastDensityFactors and selectedBreastDensityFactors | includes("hrt")) %} +
  • Taking HRT
  • + {% endif %}
{% else %}

No breast density factors added

From e0dece3e8e3a9dc57b5858ff52c11963e32eef1c Mon Sep 17 00:00:00 2001 From: rivalee Date: Thu, 30 Jul 2026 11:35:32 +0100 Subject: [PATCH 5/6] Restructure question and edit content --- .../appointments/medical-information.js | 4 +- .../breast-density-factors.njk | 84 ++++++++++++------- 2 files changed, 55 insertions(+), 33 deletions(-) diff --git a/app/routes/appointments/medical-information.js b/app/routes/appointments/medical-information.js index 9fade30a..ab0d6ddd 100644 --- a/app/routes/appointments/medical-information.js +++ b/app/routes/appointments/medical-information.js @@ -24,7 +24,7 @@ module.exports = (router) => { : postedFactors ? [postedFactors] : [] - const nonHrtFactors = factors.filter((factor) => factor !== 'hrt') + const nonHrtFactors = factors.filter((factor) => factor && factor !== 'hrt') if (!data.appointment) { data.appointment = {} @@ -86,7 +86,7 @@ module.exports = (router) => { data._medicalInformationDraft = {} } data._medicalInformationDraft.breastDensityFactors = - normalisedPostedBreastDensityFactors.filter((factor) => factor !== 'hrt') + normalisedPostedBreastDensityFactors.filter((factor) => factor && factor !== 'hrt') } if (postedBreastDensityFactorsHrt === 'yes' || postedBreastDensityFactorsHrt === 'no') { diff --git a/app/views/_includes/summary-lists/medical-information/breast-density-factors.njk b/app/views/_includes/summary-lists/medical-information/breast-density-factors.njk index cbd1276f..eb5c2a2d 100644 --- a/app/views/_includes/summary-lists/medical-information/breast-density-factors.njk +++ b/app/views/_includes/summary-lists/medical-information/breast-density-factors.njk @@ -11,8 +11,17 @@ {% set breastDensityFactorsHrt = "yes" %} {% endif %} -{% set breastDensityFactorsSummaryHtml %} - {% if breastDensityFactorsHrt == "yes" or (selectedBreastDensityFactors and selectedBreastDensityFactors | length > 0) %} +{% set participantName = participant | getFullName %} + +{% set breastDensityFactorsHrtQuestion = "Has " + participantName + " begun course of HRT since their last screening appointment?" %} +{% set pregnantOrBreastfeedingQuestion = "Is " + participantName + " pregnant or breastfeeding?" %} + +{% set breastDensityFactorsHrtSummaryHtml %} + {{ "Yes" if breastDensityFactorsHrt == "yes" or (selectedBreastDensityFactors and selectedBreastDensityFactors | includes("hrt")) else "No" }} +{% endset %} + +{% set pregnantOrBreastfeedingSummaryHtml %} + {% if selectedBreastDensityFactors and (selectedBreastDensityFactors | includes("pregnant") or selectedBreastDensityFactors | includes("breastfeeding")) %}
    {% if selectedBreastDensityFactors | includes("pregnant") %}
  • Pregnant
  • @@ -20,46 +29,27 @@ {% if selectedBreastDensityFactors | includes("breastfeeding") %}
  • Breastfeeding
  • {% endif %} - {% if breastDensityFactorsHrt == "yes" or (selectedBreastDensityFactors and selectedBreastDensityFactors | includes("hrt")) %} -
  • Taking HRT
  • - {% endif %}
{% else %} -

No breast density factors added

+

No

{% endif %} {% endset %} -{% set breastDensityFactorsInputHtml %} -
+
-

Select any current or recent considerations

- - {{ checkboxes({ - name: "appointment[medicalInformation][breastDensityFactors]", - values: selectedBreastDensityFactors, - classes: "nhsuk-checkboxes--small", - items: [ - { - value: "pregnant", - text: "Pregnant" - }, - { - value: "breastfeeding", - text: "Breastfeeding" - } - ] - }) }} +

Select any current or recent considerations

+{% set breastDensityFactorsHrtInputHtml %} {{ radios({ name: "appointment[medicalInformation][breastDensityFactorsHrt]", value: breastDensityFactorsHrt, classes: "nhsuk-radios--inline nhsuk-radios--small", fieldset: { legend: { - text: "HRT (hormone replacement therapy)", + text: breastDensityFactorsHrtQuestion, classes: "nhsuk-fieldset__legend--s" } }, @@ -76,14 +66,46 @@ }) }} {% endset %} +{% set pregnantOrBreastfeedingInputHtml %} + {{ checkboxes({ + name: "appointment[medicalInformation][breastDensityFactors]", + values: selectedBreastDensityFactors, + classes: "nhsuk-checkboxes--small", + fieldset: { + legend: { + text: pregnantOrBreastfeedingQuestion, + classes: "nhsuk-fieldset__legend--s" + } + }, + items: [ + { + value: "pregnant", + text: "Pregnant" + }, + { + value: "breastfeeding", + text: "Breastfeeding" + } + ] + }) }} +{% endset %} + {{ summaryList({ rows: [ { key: { - text: "Breast density factors" + text: "HRT (Hormone replacement therapy)" + }, + value: { + html: breastDensityFactorsHrtInputHtml if allowEdits else breastDensityFactorsHrtSummaryHtml + } + }, + { + key: { + text: "Pregnant or breastfeeding" }, value: { - html: breastDensityFactorsInputHtml if allowEdits else breastDensityFactorsSummaryHtml + html: pregnantOrBreastfeedingInputHtml if allowEdits else pregnantOrBreastfeedingSummaryHtml } } ] From 10fa76bc357ef5d13e85eecc0527cc6f5995e136 Mon Sep 17 00:00:00 2001 From: rivalee Date: Thu, 30 Jul 2026 13:08:28 +0100 Subject: [PATCH 6/6] . --- app/views/_includes/summary-lists/medical-info-summary.njk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/_includes/summary-lists/medical-info-summary.njk b/app/views/_includes/summary-lists/medical-info-summary.njk index a0e72818..d4bbab01 100644 --- a/app/views/_includes/summary-lists/medical-info-summary.njk +++ b/app/views/_includes/summary-lists/medical-info-summary.njk @@ -136,10 +136,10 @@ {% set breastDensityFactorsHtml %} {% if _bdfHrt == "yes" or _bdfHrt == "no" or (_bdf and _bdf | length > 0) %}
    - {% if _bdf and _bdf | includes("pregnant") %}
  • Pregnant
  • {% endif %} - {% if _bdf and _bdf | includes("breastfeeding") %}
  • Breastfeeding
  • {% endif %} {% if _bdfHrt == "yes" %}
  • Taking HRT
  • {% endif %} {% if _bdfHrt == "no" %}
  • Not taking HRT
  • {% endif %} + {% if _bdf and _bdf | includes("pregnant") %}
  • Pregnant
  • {% endif %} + {% if _bdf and _bdf | includes("breastfeeding") %}
  • Breastfeeding
  • {% endif %}
{% else %}

No breast density factors added