Skip to content

Commit c00cc46

Browse files
Add download status
1 parent fcb88a7 commit c00cc46

5 files changed

Lines changed: 64 additions & 5 deletions

File tree

app/enums.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ export const DownloadFormat = {
106106
SystmOne: 'XLSX for SystmOne (TPP)'
107107
}
108108

109+
/**
110+
* @readonly
111+
* @enum {string}
112+
*/
113+
export const DownloadStatus = {
114+
Processing: 'Processing',
115+
Ready: 'Ready'
116+
}
117+
109118
/**
110119
* @readonly
111120
* @enum {string}

app/locales/en.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,9 @@ export const en = {
742742
title: 'Select file format',
743743
label: 'File format'
744744
},
745+
status: {
746+
label: 'Status'
747+
},
745748
teams: {
746749
title: 'Select providers',
747750
label: 'Providers'

app/models/download.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { fakerEN_GB as faker } from '@faker-js/faker'
2+
import { addSeconds } from 'date-fns'
23
import xlsx from 'json-as-xlsx'
34

4-
import { DownloadFormat, DownloadType } from '../enums.js'
5+
import { DownloadFormat, DownloadStatus, DownloadType } from '../enums.js'
56
import { Programme, Session, Team, Vaccination, User } from '../models.js'
67
import {
78
convertIsoDateToObject,
89
convertObjectToIsoDate,
910
formatDate,
1011
today
1112
} from '../utils/date.js'
12-
import { formatList } from '../utils/string.js'
13+
import { getDownloadStatus } from '../utils/status.js'
14+
import { formatList, formatProgress, formatTag } from '../utils/string.js'
1315

1416
/**
1517
* @class Vaccination report download
@@ -320,6 +322,23 @@ export class Download {
320322
return [headers.join(','), ...rows].join('\n')
321323
}
322324

325+
get progress() {
326+
return 50
327+
}
328+
329+
get status() {
330+
if (this.createdAt) {
331+
const completedAt = addSeconds(this.createdAt, 30)
332+
const now = today()
333+
334+
if (completedAt < now) {
335+
return DownloadStatus.Ready
336+
}
337+
}
338+
339+
return DownloadStatus.Processing
340+
}
341+
323342
/**
324343
* Get formatted values
325344
*
@@ -342,6 +361,10 @@ export class Download {
342361
endAt: this.endAt
343362
? formatDate(this.endAt, { dateStyle: 'long' })
344363
: 'Latest recorded vaccination',
364+
status:
365+
this.status === DownloadStatus.Processing
366+
? formatProgress(this.progress)
367+
: formatTag(getDownloadStatus(this.status)),
345368
teams:
346369
this.teams.length > 0
347370
? formatList(this.teams.map(({ name }) => name))

app/utils/status.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
ConsentOutcome,
3+
DownloadStatus,
34
GillickCompetent,
45
InstructionOutcome,
56
PatientConsentStatus,
@@ -58,6 +59,28 @@ export function getConsentOutcomeStatus(consent) {
5859
}
5960
}
6061

62+
/**
63+
* Get download status properties
64+
*
65+
* @param {DownloadStatus} status - Download status
66+
* @returns {object} Status properties
67+
*/
68+
export function getDownloadStatus(status) {
69+
let colour
70+
switch (status) {
71+
case DownloadStatus.Ready:
72+
colour = 'green'
73+
break
74+
default:
75+
colour = 'white'
76+
}
77+
78+
return {
79+
colour,
80+
text: status
81+
}
82+
}
83+
6184
/**
6285
* Get consent outcome status properties
6386
*

app/views/download/list.njk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,14 @@
7676
heading: download.name,
7777
headingSize: "s",
7878
headingLevel: 4,
79-
href: download.uri + "/download",
80-
clickable: true
79+
href: download.uri + "/download" if download.status == DownloadStatus.Ready,
80+
clickable: true if download.status == DownloadStatus.Ready
8181
},
8282
rows: summaryRows(download, {
8383
createdAt: {},
8484
createdBy: {},
85-
type: {}
85+
type: {},
86+
status: {}
8687
})
8788
}) }}
8889
{% endfor %}

0 commit comments

Comments
 (0)