Skip to content

Commit ad066f6

Browse files
Add support for check-in
1 parent cc4e885 commit ad066f6

File tree

5 files changed

+72
-13
lines changed

5 files changed

+72
-13
lines changed

app/routes/clinics.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module.exports = router => {
6767
};
6868
});
6969

70-
// Get filtered clinics
70+
// Filter for just the clinics we want
7171
const filteredClinics = getFilteredClinics(clinicsWithData, filter);
7272

7373
res.render('clinics/index', {
@@ -77,7 +77,6 @@ module.exports = router => {
7777
formatDate: (date) => dayjs(date).format('D MMMM YYYY')
7878
});
7979

80-
8180
});
8281

8382
// View participant within clinic context
@@ -103,6 +102,49 @@ module.exports = router => {
103102
});
104103
});
105104

105+
// Handle check-in
106+
router.get('/clinics/:clinicId/check-in/:eventId', (req, res) => {
107+
const { clinicId, eventId } = req.params;
108+
const data = req.session.data;
109+
110+
// Get current filter from query param, or default to the current page's filter
111+
const currentFilter = req.query.filter || req.query.currentFilter || 'all';
112+
113+
// Find the event
114+
const eventIndex = data.events.findIndex(e => e.id === eventId && e.clinicId === clinicId);
115+
116+
if (eventIndex === -1) {
117+
return res.redirect(`/clinics/${clinicId}/${currentFilter}`);
118+
}
119+
120+
// Update the event status
121+
const event = data.events[eventIndex];
122+
123+
// Only allow check-in if currently scheduled
124+
if (event.status !== 'scheduled') {
125+
return res.redirect(`/clinics/${clinicId}/${currentFilter}`);
126+
}
127+
128+
// Update the event
129+
data.events[eventIndex] = {
130+
...event,
131+
status: 'checked_in',
132+
statusHistory: [
133+
...event.statusHistory,
134+
{
135+
status: 'checked_in',
136+
timestamp: new Date().toISOString()
137+
}
138+
]
139+
};
140+
141+
// Save back to session
142+
req.session.data = data;
143+
144+
// Redirect back to the same filter view
145+
res.redirect(`/clinics/${clinicId}/${currentFilter}`);
146+
});
147+
106148
function filterEvents(events, filter) {
107149
switch(filter) {
108150
case 'scheduled':

app/views/_templates/layout-app.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
primaryLinks: [
3636
{
37-
url: "/dashboard",
37+
url: "#",
3838
label: "Home"
3939
},
4040
{

app/views/clinics/index.html

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11

22
{% extends 'layout-app.html' %}
33

4-
{% set pageHeading = "Clinics" %}
4+
{% set pageHeading %}
5+
{% switch filter %}
6+
{% case 'today' %}
7+
Today’s clinics
8+
{% case 'upcoming' %}
9+
Upcoming clinics
10+
{% case 'completed' %}
11+
Completed clinics
12+
{% default %}
13+
All clinics
14+
{% endswitch %}
15+
{% endset %}
16+
17+
{% set hideBackLink = true %}
18+
519
{% set gridColumn = "nhsuk-grid-column-full" %}
620

7-
{% set back = {
21+
{# {% set back = {
822
href: "/dashboard",
923
text: "Dashboard"
10-
} %}
24+
} %} #}
1125

1226
{% block pageContent %}
13-
<h1>{{pageHeading}} ({{filter}})</h1>
27+
<h1>{{pageHeading}}</h1>
1428

1529
{% set secondaryNavItems = [] %}
1630

app/views/clinics/show.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
{% set back = {
77
href: "/clinics",
8-
text: "All clinics"
8+
text: "Clinics"
99
} %}
1010

1111
{% block pageContent %}
@@ -45,7 +45,7 @@ <h1 class="nhsuk-heading-l">
4545
{% if filteredEvents.length === 0 %}
4646
<p>No participants scheduled for this clinic.</p>
4747
{% else %}
48-
<p>{{ filteredEvents.length }} scheduled participants</p>
48+
{# <p>{{ filteredEvents.length }} scheduled participants</p> #}
4949

5050
<table class="nhsuk-table">
5151
<thead class="nhsuk-table__head">
@@ -78,7 +78,7 @@ <h1 class="nhsuk-heading-l">
7878
</td>
7979
<td class="nhsuk-table__cell">
8080
{% if event.status === 'scheduled' %}
81-
<a href="#/clinics/{{ clinicId }}/check-in/{{ event.id }}" class="nhsuk-link">
81+
<a href="/clinics/{{ clinicId }}/check-in/{{ event.id }}?currentFilter={{ currentFilter }}" class="nhsuk-link">
8282
{{ "Check in" | noWrap }}
8383
</a>
8484
{% endif %}

app/views/participants/show.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11

22
{% extends 'layout-app.html' %}
33

4-
{% set pageHeading = "Today’s clinics" %}
4+
5+
{% set pageHeading = participant | getFullName %}
6+
7+
58

69
{% set back = {
710
href: "/clinics",
8-
text: "All clinics"
11+
text: "Clinics"
912
} %}
1013

1114
{% block pageContent %}
@@ -16,7 +19,7 @@ <h1 class="nhsuk-heading-l">
1619
<span class="nhsuk-caption-l">
1720
{{ unit.name }} - {{ clinic.date | formatDate }}
1821
</span>
19-
{{ participant | getFullName }}
22+
{{ pageHeading }}
2023
</h1>
2124

2225

0 commit comments

Comments
 (0)