Skip to content

Commit bb866b1

Browse files
4 July fixes (#114)
* Fix ethnicity answers not showing * Make titles safe so html entities are escaped * Remove reduntant logs from templates * Dynamically route event routes * Fix wrong path
1 parent b5f0e11 commit bb866b1

39 files changed

+113
-188
lines changed

app/assets/javascript/mammogram-viewer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ document.addEventListener('DOMContentLoaded', function() {
2626
const participantName = document.querySelector('meta[name="participant-name"]')?.getAttribute('content');
2727
const eventId = document.querySelector('meta[name="event-id"]')?.getAttribute('content');
2828

29-
console.log("Mammogram viewer check:", shouldShowViewer ? "SHOW" : "HIDE", "Event ID:", eventId);
29+
// console.log("Mammogram viewer check:", shouldShowViewer ? "SHOW" : "HIDE", "Event ID:", eventId);
3030

3131
// Update our reading context flag
3232
window.inReadingContext = shouldShowViewer;
@@ -58,7 +58,7 @@ document.addEventListener('DOMContentLoaded', function() {
5858
}
5959
} else if (!shouldShowViewer) {
6060
// We're on a page that should NOT show the viewer
61-
console.log("Page lacks viewer meta tag or has it set to hide - closing viewer");
61+
// console.log("Page lacks viewer meta tag or has it set to hide - closing viewer");
6262
MammogramViewer.close();
6363
currentEventId = '';
6464
}
@@ -205,7 +205,7 @@ const MammogramViewer = {
205205

206206
// Close the viewer window - but only if it actually exists
207207
close: function() {
208-
console.log("Attempting to close mammogram viewer");
208+
// console.log("Attempting to close mammogram viewer");
209209

210210
// Only close if we're not in the middle of navigation
211211
if (isNavigating) {

app/lib/utils/event-data.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const updateEvent = (data, eventId, updatedEvent) => {
4343

4444
/**
4545
* Update event status and add to history
46+
* Also updates the temporary event data if it exists
4647
* @param {Object} data - Session data
4748
* @param {string} eventId - Event ID
4849
* @param {string} newStatus - New status
@@ -66,7 +67,14 @@ const updateEventStatus = (data, eventId, newStatus) => {
6667
],
6768
}
6869

70+
// Update main data
6971
data.events[eventIndex] = updatedEvent
72+
73+
// Also update temp event data if it exists and matches this event
74+
if (data.event && data.event.id === eventId) {
75+
data.event = { ...updatedEvent }
76+
}
77+
7078
return updatedEvent
7179
}
7280

app/routes/clinics.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { getFilteredClinics, getClinicEvents } = require('../lib/utils/clinics')
55
const { filterEventsByStatus } = require('../lib/utils/status')
66
const { getReturnUrl, urlWithReferrer, appendReferrer } = require('../lib/utils/referrers')
77
const { getParticipant } = require('../lib/utils/participants')
8+
const { updateEventStatus } = require('../lib/utils/event-data')
89

910
/**
1011
* Get clinic and its related data from id
@@ -236,17 +237,7 @@ module.exports = router => {
236237
}
237238

238239
// Update the event
239-
data.events[eventIndex] = {
240-
...event,
241-
status: 'event_checked_in',
242-
statusHistory: [
243-
...event.statusHistory,
244-
{
245-
status: 'event_checked_in',
246-
timestamp: new Date().toISOString(),
247-
},
248-
],
249-
}
240+
updateEventStatus(data, eventId, 'event_checked_in')
250241

251242
// Save back to session
252243
req.session.data = data

app/routes/events.js

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const { generateMammogramImages } = require('../lib/generators/mammogram-generat
66
const { getEvent, saveTempEventToEvent, updateEventStatus } = require('../lib/utils/event-data')
77
const generateId = require('../lib/utils/id-generator')
88
const { getReturnUrl, urlWithReferrer, appendReferrer } = require('../lib/utils/referrers')
9+
const { createDynamicTemplateRoute } = require('../lib/utils/dynamic-routing')
10+
911

1012
/**
1113
* Get single event and its related data
@@ -123,6 +125,8 @@ module.exports = router => {
123125
})
124126
})
125127

128+
129+
126130
router.post('/clinics/:clinicId/events/:eventId/personal-details/ethnicity-answer', (req, res) => {
127131
const { clinicId, eventId } = req.params
128132
const data = req.session.data
@@ -217,7 +221,7 @@ module.exports = router => {
217221
// Main route in to starting an event - used to clear any temp data
218222
router.get('/clinics/:clinicId/events/:eventId/previous-mammograms/add', (req, res) => {
219223
delete req.session.data?.event?.previousMammogramTemp
220-
res.render('events/mammography/previous-mammograms/edit')
224+
res.render('events/previous-mammograms/edit')
221225
})
222226

223227
// Save data about a mammogram
@@ -581,42 +585,6 @@ module.exports = router => {
581585
res.redirect(urlWithReferrer(`/clinics/${clinicId}/events/${eventId}/medical-information/symptoms/type`, req.query.referrerChain))
582586
})
583587

584-
const MAMMOGRAPHY_VIEWS = [
585-
'medical-information-check',
586-
'record-medical-information',
587-
'ready-for-imaging',
588-
'awaiting-images',
589-
590-
'confirm',
591-
'screening-complete',
592-
'attended-not-screened-reason',
593-
'previous-mammograms/edit',
594-
'previous-mammograms/appointment-should-not-proceed',
595-
'previous-mammograms/proceed-anyway',
596-
'medical-information/symptoms/type',
597-
'medical-information/symptoms/details',
598-
'personal-details/ethnicity',
599-
600-
// Completed screenings
601-
'images',
602-
'medical-information',
603-
]
604-
605-
// Event within clinic context
606-
router.get('/clinics/:clinicId/events/:eventId/*', (req, res, next) => {
607-
const view = req.params[0] // Gets the wildcard part
608-
609-
if (MAMMOGRAPHY_VIEWS.some(viewPath => viewPath === view)) {
610-
res.render(`events/mammography/${view}`, {})
611-
} else {
612-
next()
613-
}
614-
})
615-
616-
// Event within clinic context
617-
router.get('/clinics/:clinicId/events/:eventId/medical-information/:view', (req, res, next) => {
618-
res.render(`events/mammography/medical-information/${req.params.view}`, {})
619-
})
620588

621589
// Specific route for imaging view
622590
router.get('/clinics/:clinicId/events/:eventId/imaging', (req, res) => {
@@ -637,7 +605,7 @@ module.exports = router => {
637605
res.locals.event = data.event
638606
}
639607

640-
res.render('events/mammography/imaging', {})
608+
res.render('events/imaging', {})
641609
})
642610

643611

@@ -660,7 +628,7 @@ module.exports = router => {
660628
router.post('/clinics/:clinicId/events/:eventId/record-medical-information-answer', (req, res) => {
661629
const { clinicId, eventId } = req.params
662630
const data = req.session.data
663-
const imagingCanProceed = data.event.appointment.imagingCanProceed
631+
const imagingCanProceed = data?.event?.appointment?.imagingCanProceed
664632

665633
if (!imagingCanProceed) {
666634
res.redirect(`/clinics/${clinicId}/events/${eventId}/record-medical-information`)
@@ -758,4 +726,12 @@ module.exports = router => {
758726
// res.redirect(`/clinics/${clinicId}/events/${eventId}/screening-complete`)
759727
})
760728

729+
// General purpose dynamic template route for events
730+
// This should come after any more specific routes
731+
router.get('/clinics/:clinicId/events/:eventId/*',
732+
createDynamicTemplateRoute({
733+
templatePrefix: 'events'
734+
})
735+
)
736+
761737
}

app/views/_includes/reading/opinion-ui.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% set existingRead = event | getReadForUser %}
2-
{{ event | log("Existing Read")}}
2+
{{ existingRead | log("Existing Read")}}
33
{% set existingResult = existingRead.result %}
44
{% set hasSymptoms = event.medicalInformation.symptoms | length > 0 %}
55

app/views/_includes/summary-lists/rows/ethnicity.njk

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
{%- endset %}
1111
{% endif %}
1212

13+
{% set ethnicityHtml %}
14+
{{ ethnicGroup if ethnicGroup }}
15+
{% if ethnicBackground and ethnicBackground != 'Prefer not to say' %}
16+
({{ ethnicBackground | replace('Other', 'other') }})
17+
{% elseif ethnicBackground == "Prefer not to say" %}
18+
{{ ethnicBackground }}
19+
{% endif %}
20+
{% endset %}
21+
1322

1423
{% set ethnicityRow = {
1524
key: {

app/views/_templates/layout-app.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@
8282

8383
{% block content %}
8484

85+
{% if eventId and data.event %}
86+
{{ data.event | log("Event data") }}
87+
{% endif %}
88+
89+
{% if participantId and data.participant %}
90+
{{ data.participant | log("Participant data") }}
91+
{% endif %}
92+
93+
{% if clinicId and clinic %}
94+
{{ clinic | log("Clinic data") }}
95+
{% endif %}
96+
8597
<div class="nhsuk-grid-row">
8698
<div class="nhsuk-grid-column-two-thirds">
8799

app/views/_templates/layout-reading.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
{# Custom header with image reading stats and participant name #}
2323
{% block header %}
2424
{{ super()}}
25-
{{ participant | log("Participant") }}
26-
{{ event | log("Event") }}
25+
2726
{{ data.imageReadingTemp | log("ImageReadingTemp")}}
2827
{{ batch | log("Batch")}}
2928
<div class="app-reading-status">

app/views/_templates/layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<!-- Set the page title -->
2626
{% block pageTitle -%}
2727
{%- if pageHeading -%}
28-
{{- pageHeading }} -
28+
{{- pageHeading | safe }} -
2929
{%- endif -%}
3030
{{ " " + serviceName }} - NHS
3131
{%- endblock %}

app/views/clinics/show.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
{# {% set events = data.events | getClinicEvents(clinicId) %} #}
1414
{% set events = allEvents %}
1515

16-
{{ clinic | log("Clinic") }}
17-
1816
{# {% set clinicRiskType %}
1917
{% if clinic.riskLevels | length == 1 %}
2018
{{ clinic.riskLevels[0] }}

0 commit comments

Comments
 (0)