Skip to content

Commit bb03a4d

Browse files
Bugfix for dates and progress (#46)
1 parent 4d4477a commit bb03a4d

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

app/lib/utils/readings.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const getClinicReadingStatus = (data, clinicId) => {
7373
status,
7474
statusColor: getStatusTagColour(status),
7575
daysSinceScreening: readableEvents[0] ?
76-
dayjs().diff(dayjs(readableEvents[0].timing.startTime), 'days') : 0
76+
dayjs().startOf('day').diff(dayjs(readableEvents[0].timing.startTime).startOf('day'), 'days') : 0
7777
}
7878
}
7979

@@ -112,6 +112,7 @@ const getFirstUnreadEventOverall = (data) => {
112112
*/
113113
const getReadingProgress = (events, currentEventId, skippedEvents = []) => {
114114
const currentIndex = events.findIndex(e => e.id === currentEventId)
115+
console.log({currentIndex})
115116

116117
// Sequential navigation
117118
const nextEventId = currentIndex < events.length - 1 ?

app/routes/reading.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ module.exports = router => {
6363
})
6464

6565
const events = getReadableEvents(data, clinicId)
66+
console.log("Events length:")
67+
console.log(events.length)
6668
console.log({clinicId})
6769

6870
const progress = getReadingProgress(
@@ -90,10 +92,13 @@ module.exports = router => {
9092
router.get('/reading/clinics/:clinicId', (req, res) => {
9193
const { clinicId } = req.params
9294
const data = req.session.data
95+
const clinic = data.clinics.find(c => c.id === clinicId)
96+
97+
if (!clinic) return res.redirect('/reading')
98+
9399

94100
const readingStatus = getClinicReadingStatus(data, clinicId)
95101
const events = getReadableEvents(data, clinicId)
96-
const clinic = data.clinics.find(c => c.id === clinicId)
97102

98103
res.render('reading/list', {
99104
clinic,
@@ -177,9 +182,7 @@ module.exports = router => {
177182
// Generic result recording route
178183
router.post('/reading/clinics/:clinicId/events/:eventId/result-:resultType', (req, res) => {
179184
console.log('result recording route')
180-
const { clinicId, eventId } = req.params
181-
const resultType = req.params.resultType
182-
console.log({resultType})
185+
const { clinicId, eventId, resultType } = req.params
183186
const { reason, annotations } = req.body
184187
const data = req.session.data
185188

@@ -215,7 +218,8 @@ module.exports = router => {
215218
data.events[eventIndex].reads.push(readResult)
216219
}
217220

218-
const progress = getReadingProgress(data.events, eventId)
221+
const events = getReadableEvents(data, clinicId)
222+
const progress = getReadingProgress(events, eventId)
219223

220224
// Redirect to next participant if available
221225
if (progress.hasNextUnread) {

app/views/reading/_includes/new-assessment.njk

Whitespace-only changes.

app/views/reading/_includes/update-assessment.njk

Whitespace-only changes.

0 commit comments

Comments
 (0)