Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/patient-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import { stringToBoolean } from '../utils/string.js'
export const patientSessionController = {
read(request, response, next, nhsn) {
const { account } = request.app.locals
const { programme_id } = request.params
const { programme_id, session_id } = request.params
const { activity } = request.query
const { __ } = response.locals

const patientSession = PatientSession.findAll(request.session.data)
.filter(({ programme }) => programme.id === programme_id)
.filter(({ session }) => session.id === session_id)
.find(({ patient }) => patient.nhsn === nhsn)

const {
Expand Down
47 changes: 46 additions & 1 deletion app/controllers/patient.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ import {
AuditEventType,
PatientStatus,
ProgrammeType,
SessionPresetName,
SessionType,
VaccinationOutcome
} from '../enums.js'
import { PatientProgramme, Patient, Programme, Vaccination } from '../models.js'
import {
PatientProgramme,
Patient,
Programme,
Vaccination,
PatientSession,
Session
} from '../models.js'
import { today } from '../utils/date.js'
import { getResults, getPagination } from '../utils/pagination.js'
import { formatYearGroup } from '../utils/string.js'

Expand Down Expand Up @@ -388,6 +398,41 @@ export const patientController = {
response.redirect(patient.uri)
},

record(request, response) {
const { account } = request.app.locals
const { programme_id } = request.params
const { data } = request.session
const { patient } = response.locals

const session = Session.create(
{
createdBy_uid: account.uid,
date: today(),
type: SessionType.Clinic,
presetNames: SessionPresetName.Flu,
clinic_id: 'X99999'
},
data
)

const createdPatientSession = PatientSession.create(
{
createdBy_uid: account.uid,
patient_uuid: patient.uuid,
programme_id,
session_id: session.id
},
data
)

const patientSession = PatientSession.findOne(
createdPatientSession.uuid,
data
)

response.redirect(patientSession.uri)
},

vaccination(type) {
return (request, response) => {
const { account } = request.app.locals
Expand Down
4 changes: 2 additions & 2 deletions app/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1272,9 +1272,9 @@ export const en = {
}
},
record: {
title: 'Record {{programme.nameSentenceCase}} vaccination',
title: 'Record a new {{programme.nameSentenceCase}} vaccination',
titleWithMethod:
'Record {{programme.nameSentenceCase}} vaccination with {{method}}'
'Record a new {{programme.nameSentenceCase}} vaccination with {{method}}'
},
recordPrevious: {
title: 'Record a previous {{programme.nameSentenceCase}} vaccination'
Expand Down
8 changes: 3 additions & 5 deletions app/models/patient-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,9 @@ export class PatientSession {
get vaccinationOutcomes() {
try {
if (this.patient.vaccinations && this.programme_id) {
return this.patient.vaccinations
.filter(({ programme }) => programme.id === this.programme_id)
.filter(
({ patientSession_uuid }) => patientSession_uuid === this.uuid
)
return this.patient.vaccinations.filter(
({ programme }) => programme.id === this.programme_id
)
}
} catch (error) {
console.error('PatientSession.vaccinations', error.message)
Expand Down
2 changes: 2 additions & 0 deletions app/routes/patient.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ router.post('/:patient_uuid/archive', patient.archive)
router.all('/:patient_uuid/programmes{/:programme_id}', patient.readProgramme)
router.get('/:patient_uuid/programmes{/:programme_id}', patient.showProgramme)

router.post('/:patient_uuid/programmes/:programme_id/record', patient.record)

router.get(
'/:patient_uuid/programmes/:programme_id/new/vaccination',
patient.vaccination('new')
Expand Down
25 changes: 19 additions & 6 deletions app/views/patient/programme.njk
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{% from "patient/_navigation.njk" import patientNavigation with context %}

{% extends "_layouts/default.njk" %}
{% extends "_layouts/form.njk" %}

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

{% block beforeContent %}
{{ breadcrumb({
Expand All @@ -16,7 +19,7 @@
}) }}
{% endblock %}

{% block content %}
{% block form %}
{{ super() }}

{{ patientNavigation({
Expand Down Expand Up @@ -110,10 +113,20 @@
{% endfor %}
{% endif %}

{{ button({
classes: "nhsuk-button--secondary",
text: __("vaccination.new.alreadyVaccinated.title"),
href: patientProgramme.uri + "/new/vaccination"
{{ appButtonGroup({
buttons: [{
classes: "nhsuk-button--secondary",
text: __("patientSession.record.title", {
programme: patientProgramme.programme
}) | safe,
attributes: {
formaction: patientProgramme.uri + "/record?referrer=" + referrer
}
}, {
classes: "nhsuk-button--secondary",
text: __("vaccination.new.alreadyVaccinated.title"),
href: patientProgramme.uri + "/new/vaccination"
}]
}) if patientProgramme.status != PatientStatus.Vaccinated and patientProgramme.eligible }}
{% endcall %}

Expand Down