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
18 changes: 9 additions & 9 deletions app/controllers/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ReplyDecision,
ScreenOutcome
} from '../enums.js'
import { generateParent } from '../generators/parent.js'
import { generateContact } from '../generators/contact.js'
import {
AuditEvent,
Gillick,
Expand Down Expand Up @@ -61,12 +61,12 @@ export const activityController = {
(vaccination) => !vaccination.given
)

// Parent for use in Notify activities; force having both email and phone
const parent = generateParent(patient?.lastName)
parent.email =
parent.email ||
`${parent.fullName.replace(' ', '.').toLowerCase()}@example.com`
parent.tel = parent.tel || '07700 900000'
// Contact for use in Notify activities; force having both email and phone
const contact = generateContact(patient?.lastName)
contact.email =
contact.email ||
`${contact.fullName.replace(' ', '.').toLowerCase()}@example.com`
contact.tel = contact.tel || '07700 900000'

const activityLog = [
{
Expand Down Expand Up @@ -189,8 +189,8 @@ export const activityController = {
'vaccination-deleted'
].map((name) =>
auditEvent({
name: activity.notify[name](parent),
messageRecipient: parent,
name: activity.notify[name](contact),
messageRecipient: contact,
messageTemplate: name,
patient_uuid: patient?.uuid,
programme_ids: session?.programme_ids,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/appointment.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export const appointmentController = {
// // Add to session
// patient.addToSession(patientSession)

// // Invite parent to give consent
// // Invite contact to give consent
// patient.requestConsent(patientSession)

// // Link consent with patient record
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/book-into-a-clinic.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const bookIntoClinicController = {
* - Child DOB
* - ...
* - Appointment time <-- final page of the per-child appointment journey; iterate to next child if required
* - Parent info
* - Contact info
* - Check answers
* - Health questions?
* - Health question 1 <-- first page of the per-child health question journey
Expand Down Expand Up @@ -147,10 +147,10 @@ export const bookIntoClinicController = {
),
[`/${booking_uuid}/new/add-another`]: {},

// Parent journey
[`/${booking_uuid}/new/parent`]: {
// Contact journey
[`/${booking_uuid}/new/contact`]: {
[`/${booking_uuid}/new/offer-health-questions`]: () =>
!request.session.data.booking?.parent?.tel
!request.session.data.booking?.contact?.tel
},
[`/${booking_uuid}/new/contact-preference`]: {},

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const consentController = {
// Add to session
patient.addToSession(patientSession)

// Invite parent to give consent
// Invite contact to give consent
patient.requestConsent(patientSession)

// Link consent with patient record
Expand Down
140 changes: 140 additions & 0 deletions app/controllers/contact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { Contact, Patient } from '../models.js'

export const contactController = {
/**
* @type {import("express").RequestParamHandler}
*/
read(request, response, next, contact_uuid) {
response.locals.contact = Contact.findOne(
contact_uuid,
request.session.data
)

next()
},

/**
* @type {import("express").RequestHandler}
*/
new(request, response) {
const { patient_uuid } = request.query
const { data } = request.session

const contact = Contact.create(
{
patient_uuid
},
data.wizard
)

return response.redirect(`${contact.uri}/new`)
},

/**
* @param {string} [type] - Form type
* @returns {import("express").RequestHandler} - Request handler
*/
update(type) {
return (request, response) => {
const { contact_uuid } = request.params
const { data } = request.session
const { __, back } = response.locals

// Update session data
let contact
if (type === 'new') {
contact = Contact.create(
data.wizard.contacts[String(contact_uuid)],
data
)

// Add contact to patient contacts
const patient = Patient.findOne(contact.patient_uuid, data)
patient.addContact(contact)
} else {
contact = Contact.update(
contact_uuid,
data.wizard.contacts[String(contact_uuid)],
data
)
}

// Clean up session data
delete data.contact
delete data.wizard

request.flash('success', __(`contact.${type}.success`, { contact }))

return response.redirect(back)
}
},

/**
* @param {string} type - Form type
* @returns {import("express").RequestHandler} - Request handler
*/
readForm(type) {
return (request, response, next) => {
const { contact_uuid } = request.params
const { data } = request.session

// Setup wizard if not already setup
let contact = Contact.findOne(contact_uuid, data.wizard)
if (!contact) {
contact = Contact.create(response.locals.contact, data.wizard)
}

response.locals.contact = new Contact(contact, data)
response.locals.back = `/patients/${contact.patient_uuid}/contacts`
response.locals.type = type

next()
}
},

/**
* @type {import("express").RequestHandler}
*/
showForm(request, response) {
return response.render(`contact/form/edit`)
},

updateForm(request, response, next) {
const { contact_uuid } = request.params
const { data } = request.session

Contact.update(contact_uuid, request.body.contact, data.wizard)

return next()
},

/**
* @param {string} type - Form type
* @returns {import("express").RequestHandler} - Request handler
*/
action(type) {
return (request, response) => {
const { contact } = response.locals

response.render('contact/action', {
back: `/patients/${contact.patient_uuid}/contacts`,
type
})
}
},

/**
* @type {import("express").RequestHandler}
*/
delete(request, response) {
const { contact_uuid } = request.params
const { data } = request.session
const { __, contact } = response.locals

Contact.delete(contact_uuid, data)

request.flash('success', __(`contact.delete.success`))

return response.redirect(`/patients/${contact.patient_uuid}/contacts`)
}
}
21 changes: 9 additions & 12 deletions app/controllers/give-or-refuse-consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import {
SessionPresetName,
SessionType
} from '../enums.js'
import { generateChild } from '../generators/child.js'
import { generateParent } from '../generators/parent.js'
import { Consent, Session } from '../models.js'
import { Consent, Patient, Session } from '../models.js'
import { getHealthQuestionPaths } from '../utils/consent.js'
import { formatList, kebabToCamelCase } from '../utils/string.js'

Expand Down Expand Up @@ -53,15 +51,14 @@ export const giveOrRefuseConsentController = {

// Text and email messages
if (view === 'emails' || view === 'texts') {
const child = generateChild()
const parent = generateParent(child.lastName)
const patient = Patient.findAll(data)[0]

response.locals.assetsName = 'prototype'

response.locals.consent = new Consent(
{
child,
parent,
child: patient,
contact_uuid: patient.contact_uuids[0],
session_id: session.id
},
data
Expand Down Expand Up @@ -98,7 +95,7 @@ export const giveOrRefuseConsentController = {
consent = new Consent(consent, data)

return request.session.save((error) => {
if (!error) response.redirect(`${consent.parentUri}/new/child`)
if (!error) response.redirect(`${consent.publicUri}/new/child`)
})
},

Expand Down Expand Up @@ -155,10 +152,10 @@ export const giveOrRefuseConsentController = {
[`/${session_id}/${consent_uuid}/new/school`]: {}
}
: {}),
// Parent journey
[`/${session_id}/${consent_uuid}/new/parent`]: {
// Contact journey
[`/${session_id}/${consent_uuid}/new/contact`]: {
[`/${session_id}/parental-responsibility`]: {
data: 'consent.parent.hasParentalResponsibility',
data: 'consent.contact_.hasParentalResponsibility',
value: 'false'
}
},
Expand Down Expand Up @@ -269,7 +266,7 @@ export const giveOrRefuseConsentController = {
: ReplyDecision.OnlyMenACWY
}))
} else if (session.presetNames.includes(SessionPresetName.Flu)) {
// Flu: Ask which vaccine the parent would prefer
// Flu: Ask which vaccine the contact would prefer
response.locals.decisionItems = [
{
text: __('consent.decision.nasal.label'),
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/patient-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export const patientSessionController = {

request.flash(
'success',
__('patientSession.invite.success', { parent: patient.parent1 })
__('patientSession.invite.success', { contact: patient.contacts[0] })
)

return response.redirect(back)
Expand All @@ -333,7 +333,7 @@ export const patientSessionController = {
{
createdBy_uid: account.uid
},
patient.parent1
patient.contacts[0]
)

return response.redirect(back)
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/patient.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const patientController = {
current: currentPath === patient.uri
},
{
text: __('patient.parents.label'),
text: __('patient.contacts.label'),
href: `${patient.uri}/contacts`,
current: currentPath === `${patient.uri}/contacts`
},
Expand Down Expand Up @@ -413,10 +413,10 @@ export const patientController = {
showForm(request, response) {
let { view } = request.params

// Parent forms share same view
if (view.includes('parent')) {
// Contact forms share same view
if (view.includes('contact')) {
response.locals.parentId = String(view).split('-')[1]
view = 'parent'
view = 'contact'
}

return response.render(`patient/form/${view}`)
Expand Down Expand Up @@ -478,7 +478,7 @@ export const patientController = {
clinicProgramme_ids = stringToArray(clinicProgramme_ids)
}

// Send comms to parents and record in audit trail
// Send comms to contacts and record in audit trail
const patient = Patient.findOne(patient_uuid, data)
patient.inviteToClinic(clinicProgramme_ids)
Patient.update(patient.uuid, patient, data)
Expand Down Expand Up @@ -612,7 +612,7 @@ export const patientController = {
]

if (invitedProgramme_ids.length) {
// Send comms to parents and record in audit trail
// Send comms to contacts and record in audit trail
patient.inviteToClinic(invitedProgramme_ids)
Patient.update(patient.uuid, patient, data)

Expand Down
Loading