Skip to content

Commit 6423289

Browse files
Add first versions of clinics, participants, routes, etc
1 parent 5072c19 commit 6423289

File tree

9 files changed

+359
-6
lines changed

9 files changed

+359
-6
lines changed

app/data/session-data-defaults.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,29 @@
33
const users = require("./users");
44
const breastScreeningUnits = require("./breast-screening-units");
55
const ethnicities = require("./ethnicities");
6+
const path = require('path');
7+
const fs = require('fs');
8+
9+
// Check if generated data folder exists
10+
const generatedDataPath = path.join(__dirname, 'generated');
611

7-
// Load generated data
812
let participants = [];
913
let clinics = [];
1014
let events = [];
1115

16+
// Generate data if folder doesn't exist
17+
if (!fs.existsSync(generatedDataPath)) {
18+
console.log('Generating seed data...');
19+
require('../lib/generate-seed-data.js');
20+
}
21+
22+
// Load generated data
1223
try {
1324
participants = require("./generated/participants.json").participants;
1425
clinics = require("./generated/clinics.json").clinics;
1526
events = require("./generated/events.json").events;
1627
} catch (err) {
17-
console.warn('Generated data files not found. Please run the data generator first.');
28+
console.warn('Error loading generated data:', err);
1829
}
1930

2031
module.exports = {

app/lib/utils/clinics.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ const getTodaysClinics = (clinics) => {
2424
* @param {string} clinicId - Clinic ID to filter by
2525
*/
2626
const getClinicEvents = (events, clinicId) => {
27+
if (!events || !clinicId) return [];
28+
console.log(`Looking for events with clinicId: ${clinicId}`);
29+
console.log(`Found ${events.filter(e => e.clinicId === clinicId).length} events`);
2730
return events.filter(e => e.clinicId === clinicId);
2831
};
2932

33+
3034
/**
3135
* Format clinic time slot
3236
* @param {string} dateTime - ISO date string

app/routes.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const express = require('express');
33

44
const router = express.Router();
55

6+
require('./routes/clinics')(router);
7+
8+
69
// Add your routes here - above the module.exports line
710

811
module.exports = router;

app/routes/clinics.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// app/routes/clinics.js
2+
3+
const dayjs = require('dayjs');
4+
5+
/**
6+
* Get clinic and its related data from id
7+
*/
8+
function getClinicData(data, clinicId) {
9+
const clinic = data.clinics.find(c => c.id === clinicId);
10+
11+
if (!clinic) {
12+
return null;
13+
}
14+
15+
// Get all events for this clinic
16+
const clinicEvents = data.events.filter(e => e.clinicId === clinic.id);
17+
18+
// Get all participants for these events and add their details to the events
19+
const eventsWithParticipants = clinicEvents.map(event => {
20+
const participant = data.participants.find(p => p.id === event.participantId);
21+
return {
22+
...event,
23+
participant
24+
};
25+
});
26+
27+
// Get screening unit details
28+
const unit = data.breastScreeningUnits.find(u => u.id === clinic.breastScreeningUnitId);
29+
30+
return {
31+
clinic,
32+
events: eventsWithParticipants,
33+
unit
34+
};
35+
}
36+
37+
module.exports = router => {
38+
// Single clinic view
39+
router.get('/clinics/:id', (req, res) => {
40+
const clinicData = getClinicData(req.session.data, req.params.id);
41+
42+
if (!clinicData) {
43+
res.redirect('/clinics');
44+
return;
45+
}
46+
47+
res.render('clinics/show', {
48+
clinicId: req.params.id,
49+
clinic: clinicData.clinic,
50+
events: clinicData.events,
51+
unit: clinicData.unit,
52+
formatDate: (date) => dayjs(date).format('D MMMM YYYY'),
53+
formatTime: (date) => dayjs(date).format('HH:mm')
54+
});
55+
});
56+
57+
// View participant within clinic context
58+
router.get('/clinics/:clinicId/participants/:participantId', (req, res) => {
59+
const participant = req.session.data.participants.find(p => p.id === req.params.participantId);
60+
const clinic = req.session.data.clinics.find(c => c.id === req.params.clinicId);
61+
const event = req.session.data.events.find(e =>
62+
e.clinicId === req.params.clinicId &&
63+
e.participantId === req.params.participantId
64+
);
65+
66+
if (!participant || !clinic || !event) {
67+
res.redirect('/clinics/' + req.params.clinicId);
68+
return;
69+
}
70+
71+
res.render('participants/show', {
72+
participant,
73+
clinic,
74+
event,
75+
clinicId: req.params.clinicId,
76+
participantId: req.params.participantId
77+
});
78+
});
79+
80+
81+
82+
};

app/views/clinics.html

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
{% extends 'layout-app.html' %}
3+
4+
{% set pageHeading = "Today’s clinics" %}
5+
6+
7+
{% block pageContent %}
8+
9+
{% set todaysClinics = data.clinics | getTodaysClinics %}
10+
11+
12+
<h1>
13+
{{pageHeading}}
14+
</h1>
15+
16+
{% if todaysClinics.length === 0 %}
17+
<p class="govuk-body">No clinics scheduled for today.</p>
18+
{% else %}
19+
<table class="govuk-table">
20+
<thead class="govuk-table__head">
21+
<tr>
22+
<th class="govuk-table__header">Location</th>
23+
<th class="govuk-table__header">Time</th>
24+
<th class="govuk-table__header">Actions</th>
25+
</tr>
26+
</thead>
27+
<tbody class="govuk-table__body">
28+
{% for clinic in todaysClinics %}
29+
{% set unit = data.breastScreeningUnits | findById(clinic.breastScreeningUnitId) %}
30+
{% set events = data.events | getClinicEvents(clinic.id) %}
31+
<tr class="govuk-table__row">
32+
<td class="govuk-table__cell">{{ unit.name }}</td>
33+
<td class="govuk-table__cell">{{ clinic.date | formatDate }}</td>
34+
<td class="govuk-table__cell">
35+
<a href="/clinics/{{ clinic.id }}" class="govuk-link">View clinic</a>
36+
({{ events.length }} participants)
37+
</td>
38+
</tr>
39+
{% endfor %}
40+
</tbody>
41+
</table>
42+
{% endif %}
43+
44+
{% endblock %}

app/views/clinics/show.html

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
2+
{% extends 'layout-app.html' %}
3+
4+
{% set pageHeading = "Today’s clinics" %}
5+
6+
7+
{% block pageContent %}
8+
{% set unit = data.breastScreeningUnits | findById(clinic.breastScreeningUnitId) %}
9+
{% set events = data.events | getClinicEvents(clinicId) %}
10+
11+
<h1 class="nhsuk-heading-l">
12+
<span class="nhsuk-caption-l">{{ unit.name }}</span>
13+
Clinic on {{ clinic.date | formatDate }}
14+
</h1>
15+
16+
{% if events.length === 0 %}
17+
<p class="nhsuk-body">No participants scheduled for this clinic.</p>
18+
{% else %}
19+
<table class="nhsuk-table">
20+
<caption class="nhsuk-table__caption">
21+
{{ events.length }} scheduled participants
22+
</caption>
23+
<thead class="nhsuk-table__head">
24+
<tr>
25+
<th scope="col" class="nhsuk-table__header">Time</th>
26+
<th scope="col" class="nhsuk-table__header">Name</th>
27+
<th scope="col" class="nhsuk-table__header">SX number</th>
28+
<th scope="col" class="nhsuk-table__header">Status</th>
29+
<th scope="col" class="nhsuk-table__header">Actions</th>
30+
</tr>
31+
</thead>
32+
<tbody class="nhsuk-table__body">
33+
{% for event in events %}
34+
{% set participant = data.participants | findById(event.participantId) %}
35+
<tr class="nhsuk-table__row">
36+
<td class="nhsuk-table__cell">
37+
{{ event.statusHistory[0].timestamp | formatTime }}
38+
</td>
39+
<td class="nhsuk-table__cell">
40+
<a href="/clinics/{{ clinicId }}/participants/{{ participant.id }}" class="nhsuk-link">
41+
{{ participant | getFullName }}
42+
</a>
43+
</td>
44+
<td class="nhsuk-table__cell">
45+
{{ participant.sxNumber }}
46+
</td>
47+
<td class="nhsuk-table__cell">
48+
{{ event.status | replace("_", " ") | capitalize }}
49+
</td>
50+
<td class="nhsuk-table__cell">
51+
{% if event.status === 'scheduled' %}
52+
<a href="/clinics/{{ clinicId }}/check-in/{{ event.id }}" class="nhsuk-link">Check in</a>
53+
{% endif %}
54+
</td>
55+
</tr>
56+
{% endfor %}
57+
</tbody>
58+
</table>
59+
{% endif %}
60+
61+
<h2 class="nhsuk-heading-m">Details</h2>
62+
<dl class="nhsuk-summary-list">
63+
<div class="nhsuk-summary-list__row">
64+
<dt class="nhsuk-summary-list__key">Location</dt>
65+
<dd class="nhsuk-summary-list__value">
66+
{{ unit.name }}<br>
67+
{{ unit.address | replace("\n", "<br>") | safe }}
68+
</dd>
69+
</div>
70+
<div class="nhsuk-summary-list__row">
71+
<dt class="nhsuk-summary-list__key">Phone</dt>
72+
<dd class="nhsuk-summary-list__value">{{ unit.phoneNumber }}</dd>
73+
</div>
74+
<div class="nhsuk-summary-list__row">
75+
<dt class="nhsuk-summary-list__key">Date</dt>
76+
<dd class="nhsuk-summary-list__value">{{ clinic.date | formatDate }}</dd>
77+
</div>
78+
<div class="nhsuk-summary-list__row">
79+
<dt class="nhsuk-summary-list__key">Type</dt>
80+
<dd class="nhsuk-summary-list__value">
81+
{{ clinic.clinicType | replace("_", " ") | capitalize }}
82+
</dd>
83+
</div>
84+
</dl>
85+
86+
<a href="/clinics" class="nhsuk-back-link">Back to today's clinics</a>
87+
88+
{% endblock %}

app/views/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ <h1>
1616

1717
{# {{ data.people[0].name() | log}} #}
1818

19-
{{ data.participants }}
2019

2120
{# {% set person = data.helpers.people.findById(personId) %} #}
2221
{{ person.fullName }}
2322

24-
{{ data.utils | log}}
23+
2524

2625
{{ button({
2726
text: "Go to dashboard",
2827
href: "/dashboard"
2928
}) }}
3029

30+
<p><a href="/clinics">Clinics</a></p>
31+
3132
{% endblock %}

0 commit comments

Comments
 (0)