Skip to content

Commit 3dead20

Browse files
Content fixes (#274)
* Clean up mammogram data bugs and data display * Make hint dates dynamic
1 parent 9cf20ca commit 3dead20

5 files changed

Lines changed: 71 additions & 40 deletions

File tree

app/lib/utils/dates.js

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -704,13 +704,15 @@ const calculateDurationMinutes = (startTime, endTime) => {
704704
if (!startTime || !endTime) return 0
705705

706706
// If it looks like just a time (contains no date), prefix with dummy date
707-
const startDatetime = startTime.includes('T') || startTime.includes('-')
708-
? startTime
709-
: `2000-01-01T${startTime}`
710-
711-
const endDatetime = endTime.includes('T') || endTime.includes('-')
712-
? endTime
713-
: `2000-01-01T${endTime}`
707+
const startDatetime =
708+
startTime.includes('T') || startTime.includes('-')
709+
? startTime
710+
: `2000-01-01T${startTime}`
711+
712+
const endDatetime =
713+
endTime.includes('T') || endTime.includes('-')
714+
? endTime
715+
: `2000-01-01T${endTime}`
714716

715717
const start = dayjs(startDatetime)
716718
const end = dayjs(endDatetime)
@@ -790,6 +792,34 @@ const remove = (dateInput, amount, unit) => {
790792
return add(dateInput, -amount, unit)
791793
}
792794

795+
/**
796+
* Get the season name and year for a given date
797+
*
798+
* @param {string} dateInput - ISO date string
799+
* @returns {string} Season and year, e.g. 'winter 2025', 'summer 2026'
800+
* @example
801+
* toSeason('2025-12-01') // 'winter 2025'
802+
* toSeason('2026-06-15') // 'summer 2026'
803+
*/
804+
const toSeason = (dateInput) => {
805+
if (!dateInput) return ''
806+
807+
const date = dayjs(dateInput)
808+
if (!date.isValid()) return ''
809+
810+
// dayjs month() is 0-based, convert to 1-based
811+
const month = date.month() + 1
812+
const year = date.year()
813+
814+
let season
815+
if (month >= 3 && month <= 5) season = 'spring'
816+
else if (month >= 6 && month <= 8) season = 'summer'
817+
else if (month >= 9 && month <= 11) season = 'autumn'
818+
else season = 'winter'
819+
820+
return `${season} ${year}`
821+
}
822+
793823
module.exports = {
794824
arrayOrObjectToDateObject,
795825
monthYearToDateObject,
@@ -818,7 +848,8 @@ module.exports = {
818848
isWithinDayRange,
819849
calculateDurationMinutes,
820850
add,
821-
remove
851+
remove,
852+
toSeason
822853
}
823854

824855
/**

app/routes/events.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,9 +679,34 @@ module.exports = (router) => {
679679

680680
// Helper function to build mammogram object with ID and metadata
681681
const buildMammogramObject = (tempData, additionalFields = {}) => {
682+
const cleaned = { ...tempData }
683+
684+
// approximateDate can arrive as an array if both conditional inputs
685+
// (moreThanSixMonths and lessThanSixMonths) are submitted together.
686+
// Pick the first non-empty value.
687+
if (Array.isArray(cleaned.approximateDate)) {
688+
cleaned.approximateDate = cleaned.approximateDate.find(v => v) || ''
689+
}
690+
691+
// Clear date fields not relevant to the selected dateType
692+
if (cleaned.dateType === 'dateKnown') {
693+
delete cleaned.approximateDate
694+
}
695+
else {
696+
delete cleaned.dateTaken
697+
}
698+
699+
// Clear location-specific fields that weren't selected
700+
if (cleaned.location !== 'bsu') delete cleaned.bsu
701+
if (cleaned.location !== 'otherUk') delete cleaned.otherUk
702+
if (cleaned.location !== 'otherNonUk') delete cleaned.otherNonUk
703+
704+
// Clear previousName if the same name was used
705+
if (cleaned.sameName !== 'differentName') delete cleaned.previousName
706+
682707
const mammogram = {
683-
id: tempData.id || generateId(),
684-
...tempData,
708+
id: cleaned.id || generateId(),
709+
...cleaned,
685710
...additionalFields
686711
}
687712

app/views/_includes/medical-information/mammogram-history.njk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@
4646
previousMammogram.dateTaken | formatDate + " (" + (previousMammogram.dateTaken | formatDate | formatRelativeDate | asHint) + ")"
4747
) %}
4848
{% elseif previousMammogram.dateType == 'moreThanSixMonths' %}
49-
{% set dateText = "Approximately taken 6 months or more ago" %}
49+
{% set dateText = "Taken 6 months or more ago" %}
5050
{% if previousMammogram.approximateDate %}
5151
{% set dateText = dateText + ": " + previousMammogram.approximateDate %}
5252
{% endif %}
5353
{% set mammogramValueLines = mammogramValueLines | push(dateText) %}
5454
{% elseif previousMammogram.dateType == 'lessThanSixMonths' %}
55-
{% set dateText = "Approximately taken less than 6 months ago" %}
55+
{% set dateText = "Taken less than 6 months ago" %}
5656
{% if previousMammogram.approximateDate %}
5757
{% set dateText = dateText + ": " + previousMammogram.approximateDate %}
5858
{% endif %}
@@ -65,7 +65,7 @@
6565
{% if previousMammogram.location == "currentBsu" %}
6666
{% set mammogramValueLines = mammogramValueLines | push(unit.name) %}
6767
{% elseif previousMammogram.location == "bsu" %}
68-
{% set mammogramValueLines = mammogramValueLines | push(previousMammogram.bsu) %}
68+
{% set mammogramValueLines = mammogramValueLines | push("NHS BSU: " + previousMammogram.bsu) %}
6969
{% elseif previousMammogram.location == "otherUk" %}
7070
{% set mammogramValueLines = mammogramValueLines | push("In the UK: " + (previousMammogram.otherUk | nl2br | safe)) %}
7171
{% elseif previousMammogram.location == "otherNonUk" %}

app/views/events/previous-mammograms/form.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ <h1 class="nhsuk-heading-l">
174174
text: "Approximate date"
175175
},
176176
hint: {
177-
text: "For example, April 2018 or summer 2021"
177+
text: "For example, " + (now() | remove(1, 'year') | formatDate('MMMM YYYY')) + " or " + (now() | remove(1, 'year') | toSeason)
178178
},
179179
classes: "nhsuk-u-width-two-thirds",
180180
value: event.previousMammogramTemp.approximateDate
@@ -191,7 +191,7 @@ <h1 class="nhsuk-heading-l">
191191
text: "Approximate date"
192192
},
193193
hint: {
194-
text: "For example, April 2018 or summer 2021"
194+
text: "For example, " + (now() | remove(3, 'months') | formatDate('MMMM YYYY')) + " or " + (now() | remove(3, 'months') | toSeason)
195195
},
196196
classes: "nhsuk-u-width-two-thirds",
197197
value: event.previousMammogramTemp.approximateDate

docs/IMAGE-READING-TECHNICAL-SUMMARY.md

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,6 @@ This document provides a technical overview of the image reading section of the
66

77
## Refactoring Plan
88

9-
### Completed
10-
11-
- [x] Created `reading/workflow/opinion.html` - main entry point with opinion UI inline
12-
- [x] Moved workflow pages to `reading/workflow/` folder
13-
- [x] Updated routes to render from `workflow/` subfolder
14-
- [x] Deleted `_includes/reading/opinion-ui.njk` (now inline in opinion.html)
15-
- [x] Removed opinion-ui include from layout
16-
- [x] Added `isReadingWorkflow` flag in routes middleware
17-
- [x] Extracted status bar to `_includes/reading/reading-status-bar.njk`
18-
- [x] Extracted navigation to `_includes/reading/workflow-navigation.njk`
19-
- [x] Simplified `layout-reading.html` (204 → 51 lines)
20-
- [x] Primary nav swap - shows "Batch list" link when in reading workflow
21-
- [x] Deleted legacy files: assessment.html, medical-information.html, images.html, participant-details.html, awaiting-annotations.html
22-
- [x] Removed legacy steps array from routes
23-
- [x] Deleted unused `_includes/reading/secondary-navigation.njk`
24-
- [x] Navigation refactor: `showWorkflowNav` flag for opinion page, back link default for child pages
25-
- [x] Removed `hideSecondaryNavigation` from child pages (replaced by unified back link logic)
26-
- [x] Created `review.html` - confirmation page before saving opinion
27-
- [x] Created `existing-read.html` - view saved read with option to change
28-
- [x] Route renamed: `/assessment-answer``/opinion-answer`
29-
- [x] Route renamed: `/result-:resultType``/save-opinion`
30-
- [x] Form data now saves directly to `imageReadingTemp` via form binding
31-
- [x] Base event route auto-redirects to `existing-read` or `opinion` based on read status
32-
- [x] Simplified workflow navigation - all links go to base event URL
33-
349
### Future Work
3510

3611
- [ ] Make sure fields correctly save to data.imageReadingTemp

0 commit comments

Comments
 (0)