Skip to content

Commit 2147f4b

Browse files
Recording a new vaccination (in a clinic) from the child record page
1 parent 45e6de2 commit 2147f4b

6 files changed

Lines changed: 74 additions & 16 deletions

File tree

app/controllers/patient-session.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ import { stringToBoolean } from '../utils/string.js'
2525
export const patientSessionController = {
2626
read(request, response, next, nhsn) {
2727
const { account } = request.app.locals
28-
const { programme_id } = request.params
28+
const { programme_id, session_id } = request.params
2929
const { activity } = request.query
3030
const { __ } = response.locals
3131

3232
const patientSession = PatientSession.findAll(request.session.data)
33-
.filter(({ programme }) => programme.id === programme_id)
33+
.filter(({ session }) => session.id === session_id)
3434
.find(({ patient }) => patient.nhsn === nhsn)
3535

3636
const {

app/controllers/patient.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@ import {
55
AuditEventType,
66
PatientStatus,
77
ProgrammeType,
8+
SessionPresetName,
9+
SessionType,
810
VaccinationOutcome
911
} from '../enums.js'
10-
import { PatientProgramme, Patient, Programme, Vaccination } from '../models.js'
12+
import {
13+
PatientProgramme,
14+
Patient,
15+
Programme,
16+
Vaccination,
17+
PatientSession,
18+
Session
19+
} from '../models.js'
20+
import { today } from '../utils/date.js'
1121
import { getResults, getPagination } from '../utils/pagination.js'
1222
import { formatYearGroup } from '../utils/string.js'
1323

@@ -388,6 +398,41 @@ export const patientController = {
388398
response.redirect(patient.uri)
389399
},
390400

401+
record(request, response) {
402+
const { account } = request.app.locals
403+
const { programme_id } = request.params
404+
const { data } = request.session
405+
const { patient } = response.locals
406+
407+
const session = Session.create(
408+
{
409+
createdBy_uid: account.uid,
410+
date: today(),
411+
type: SessionType.Clinic,
412+
presetNames: SessionPresetName.Flu,
413+
clinic_id: 'X99999'
414+
},
415+
data
416+
)
417+
418+
const createdPatientSession = PatientSession.create(
419+
{
420+
createdBy_uid: account.uid,
421+
patient_uuid: patient.uuid,
422+
programme_id,
423+
session_id: session.id
424+
},
425+
data
426+
)
427+
428+
const patientSession = PatientSession.findOne(
429+
createdPatientSession.uuid,
430+
data
431+
)
432+
433+
response.redirect(patientSession.uri)
434+
},
435+
391436
vaccination(type) {
392437
return (request, response) => {
393438
const { account } = request.app.locals

app/locales/en.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,9 +1272,9 @@ export const en = {
12721272
}
12731273
},
12741274
record: {
1275-
title: 'Record {{programme.nameSentenceCase}} vaccination',
1275+
title: 'Record a new {{programme.nameSentenceCase}} vaccination',
12761276
titleWithMethod:
1277-
'Record {{programme.nameSentenceCase}} vaccination with {{method}}'
1277+
'Record a new {{programme.nameSentenceCase}} vaccination with {{method}}'
12781278
},
12791279
recordPrevious: {
12801280
title: 'Record a previous {{programme.nameSentenceCase}} vaccination'

app/models/patient-session.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,9 @@ export class PatientSession {
418418
get vaccinationOutcomes() {
419419
try {
420420
if (this.patient.vaccinations && this.programme_id) {
421-
return this.patient.vaccinations
422-
.filter(({ programme }) => programme.id === this.programme_id)
423-
.filter(
424-
({ patientSession_uuid }) => patientSession_uuid === this.uuid
425-
)
421+
return this.patient.vaccinations.filter(
422+
({ programme }) => programme.id === this.programme_id
423+
)
426424
}
427425
} catch (error) {
428426
console.error('PatientSession.vaccinations', error.message)

app/routes/patient.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ router.post('/:patient_uuid/archive', patient.archive)
2323
router.all('/:patient_uuid/programmes{/:programme_id}', patient.readProgramme)
2424
router.get('/:patient_uuid/programmes{/:programme_id}', patient.showProgramme)
2525

26+
router.post('/:patient_uuid/programmes/:programme_id/record', patient.record)
27+
2628
router.get(
2729
'/:patient_uuid/programmes/:programme_id/new/vaccination',
2830
patient.vaccination('new')

app/views/patient/programme.njk

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{% from "patient/_navigation.njk" import patientNavigation with context %}
22

3-
{% extends "_layouts/default.njk" %}
3+
{% extends "_layouts/form.njk" %}
44

5+
{% set gridColumns = "full" %}
6+
{% set hideConfirmButton = true %}
57
{% set title = patient.fullName + "" + patient.programmes[programme.slug].name %}
8+
{% set formAction = patientProgramme.uri + "/record?referrer=" + referrer %}
69

710
{% block beforeContent %}
811
{{ breadcrumb({
@@ -16,7 +19,7 @@
1619
}) }}
1720
{% endblock %}
1821

19-
{% block content %}
22+
{% block form %}
2023
{{ super() }}
2124

2225
{{ patientNavigation({
@@ -110,10 +113,20 @@
110113
{% endfor %}
111114
{% endif %}
112115

113-
{{ button({
114-
classes: "nhsuk-button--secondary",
115-
text: __("vaccination.new.alreadyVaccinated.title"),
116-
href: patientProgramme.uri + "/new/vaccination"
116+
{{ appButtonGroup({
117+
buttons: [{
118+
classes: "nhsuk-button--secondary",
119+
text: __("patientSession.record.title", {
120+
programme: patientProgramme.programme
121+
}) | safe,
122+
attributes: {
123+
formaction: patientProgramme.uri + "/record?referrer=" + referrer
124+
}
125+
}, {
126+
classes: "nhsuk-button--secondary",
127+
text: __("vaccination.new.alreadyVaccinated.title"),
128+
href: patientProgramme.uri + "/new/vaccination"
129+
}]
117130
}) if patientProgramme.status != PatientStatus.Vaccinated and patientProgramme.eligible }}
118131
{% endcall %}
119132

0 commit comments

Comments
 (0)