diff --git a/app/controllers/parent.js b/app/controllers/parent.js index 65457cc31..743ccb3d9 100644 --- a/app/controllers/parent.js +++ b/app/controllers/parent.js @@ -150,7 +150,7 @@ export const parentController = { data: 'consent.decision', value: ReplyDecision.Refused }, - [`/${session_id}/${consent_uuid}/new/first-dose`]: { + [`/${session_id}/${consent_uuid}/new/first-dose-country`]: { data: 'consent.decision', value: ReplyDecision.AlreadyVaccinated } @@ -181,7 +181,7 @@ export const parentController = { ReplyRefusal.Medical ] }, - [`/${session_id}/${consent_uuid}/new/first-dose`]: { + [`/${session_id}/${consent_uuid}/new/first-dose-country`]: { data: 'consent.refusalReason', value: ReplyRefusal.AlreadyVaccinatedMMR }, @@ -195,8 +195,10 @@ export const parentController = { [`/${session_id}/${consent_uuid}/new/check-answers`]: true }, // First and second dose journey - [`/${session_id}/${consent_uuid}/new/first-dose`]: {}, - [`/${session_id}/${consent_uuid}/new/second-dose`]: { + [`/${session_id}/${consent_uuid}/new/first-dose-country`]: {}, + [`/${session_id}/${consent_uuid}/new/first-dose-date`]: {}, + [`/${session_id}/${consent_uuid}/new/second-dose-country`]: {}, + [`/${session_id}/${consent_uuid}/new/second-dose-date`]: { [`/${session_id}/${consent_uuid}/new/check-answers`]: true } } @@ -330,8 +332,8 @@ export const parentController = { // All previous dose questions use the same view if (view.includes('-dose')) { - key = `${kebabToCamelCase(view.replace('-dose', ''))}Dose` - view = 'previous-dose' + key = `${view.match(/^(first|second)-dose/)?.[1]}Dose` + view = view.replace(/(?:first|second)(-)/g, 'previous$1') } // Only ask for details if question does not have sub-questions diff --git a/app/enums.js b/app/enums.js index 3963fdcdb..753101871 100644 --- a/app/enums.js +++ b/app/enums.js @@ -518,7 +518,7 @@ export const ReplyRefusal = { GelatineMMR: 'Do not want my child to have the MMR vaccine that contains gelatine', AlreadyVaccinated: 'Vaccine already received', - AlreadyVaccinatedMMR: 'Already had both doses of the MMR vaccination', + AlreadyVaccinatedMMR: 'Already had both doses of the MMR vaccine', GettingElsewhere: 'Vaccine will be given elsewhere', Medical: 'Medical reasons', OutsideSchool: 'Do not want vaccination in school', diff --git a/app/locales/en.js b/app/locales/en.js index ca01f279e..5a15548a4 100644 --- a/app/locales/en.js +++ b/app/locales/en.js @@ -524,7 +524,7 @@ export const en = { hint: 'This is suitable for children who do not use gelatine products, or if they cannot have the nasal spray vaccine for medical reasons' }, alreadyVaccinated: { - label: 'My child has already had both doses of the MMR vaccination', + label: 'My child has already had both doses of the MMR vaccine', hint: 'Children need 2 doses of the MMR vaccine to be fully protected' }, no: { @@ -578,7 +578,7 @@ export const en = { other: ReplyRefusal.AlreadyVaccinated.replace('Vaccine', 'Vaccines') }, alreadyVaccinatedMMR: - 'My child has already had both doses of the MMR vaccination', + 'My child has already had both doses of the MMR vaccine', gettingElsewhere: { one: ReplyRefusal.GettingElsewhere, other: ReplyRefusal.GettingElsewhere.replace('Vaccine', 'Vaccines') @@ -599,36 +599,43 @@ export const en = { label: 'Details of 1st MMR dose', title: 'When and where did your child get their 1st MMR dose?', description: 'The 1st dose is usually offered at 12 months', + country: { + title: + 'Which country was the 1st dose of the MMR vaccination given in?', + label: 'Country' + }, createdAt: { + title: 'When was the 1st dose given?', label: 'Date of vaccination' }, - location: { - label: 'Location' - }, - country: { - label: 'Country' + scheduled: { + title: 'Was the 1st dose given when your child was 12 months old?', + hint: 'This is usually the child’s age when the 1st dose is offered' } }, secondDose: { label: 'Details of 2nd MMR dose', title: 'When and where did your child get their 2nd MMR dose?', description: - 'The 2nd dose is usually offered when children are 3 years old' - }, - previousDose: { - createdAt: { - label: 'Date', - title: 'Date of vaccination', - hint: 'If you do not know the exact date of the vaccination, you can leave the day field empty and enter your best guess for the month' + 'The 2nd dose is usually offered when children are 3 years and 4 months old', + country: { + title: + 'Which country was the 2nd dose of the MMR vaccination given in?', + label: 'Country' }, - location: { - label: 'Location', - title: 'Location', - hint: 'Give the name and address of the GP surgery if you can remember it' + createdAt: { + title: 'When was the 2nd dose given?', + label: 'Date of vaccination' }, + scheduled: { + title: + 'Was the 2nd dose given when your child was 3 years and 4 months old?', + hint: 'This is usually the child’s age when the 2nd dose is offered' + } + }, + previousDose: { country: { label: 'Country', - title: 'Country', england: 'England', scotland: 'Scotland', wales: 'Wales', @@ -637,6 +644,14 @@ export const en = { }, countryOther: { title: 'Which country was the vaccination given in?' + }, + createdAt: { + label: 'Date', + hint: 'If you do not know the exact date of the vaccination, leave the day field empty and enter your best guess for the month' + }, + scheduled: { + yes: 'Yes', + no: 'No' } }, healthAnswers: { diff --git a/app/models/reply.js b/app/models/reply.js index 9a434c509..144d2f5c9 100644 --- a/app/models/reply.js +++ b/app/models/reply.js @@ -1,4 +1,5 @@ import { fakerEN_GB as faker } from '@faker-js/faker' +import { addMonths } from 'date-fns' import _ from 'lodash' import vaccines from '../datasets/vaccines.js' @@ -87,7 +88,7 @@ export class Reply { // Some values only valid if the consent request was received if (this.delivered) { this.decision = - options.refusalReason === ReplyRefusal.AlreadyVaccinatedMMR + options?.refusalReason === ReplyRefusal.AlreadyVaccinatedMMR ? ReplyDecision.AlreadyVaccinated : options?.decision this.alternative = @@ -111,8 +112,17 @@ export class Reply { if (this.decision === ReplyDecision.AlreadyVaccinated) { this.firstDose = options?.firstDose && new Vaccination(options.firstDose) + + if (options?.firstDose?.scheduled) { + this.firstDose.createdAt = addMonths(this.child?.dob, 12) + } + this.secondDose = options?.secondDose && new Vaccination(options.secondDose) + + if (options?.secondDose?.scheduled) { + this.secondDose.createdAt = addMonths(this.child?.dob, 40) + } } if ( diff --git a/app/models/vaccination.js b/app/models/vaccination.js index 33e4fc3c6..b9f31544b 100644 --- a/app/models/vaccination.js +++ b/app/models/vaccination.js @@ -74,6 +74,7 @@ import { * @property {number} [dose] - Dosage (ml) * @property {string} [sequence] - Dose sequence * @property {string} [protocol] - Protocol + * @property {boolean} [scheduled] - Vaccination date was on schedule * @property {string} [note] - Note * @property {string} [country] - Country * @property {string} [clinic_id] - Clinic ID @@ -100,7 +101,7 @@ export class Vaccination { this.updatedAt = options?.updatedAt && new Date(options.updatedAt) this.locationType = options?.locationType this.country = options?.country - this.countryOther = options?.countryOther + this.countryOther = this.country === 'Other' && options?.countryOther this.selfId = options?.selfId && stringToBoolean(options.selfId) this.identifiedBy = this.selfId !== true && options?.identifiedBy this.outcome = options?.outcome @@ -116,6 +117,7 @@ export class Vaccination { this.protocol = this.given ? options?.protocol || VaccinationProtocol.PGD : undefined + this.scheduled = stringToBoolean(options.scheduled) this.note = options?.note || '' this.country = 'England' this.clinic_id = options?.clinic_id diff --git a/app/views/parent/form/check-answers.njk b/app/views/parent/form/check-answers.njk index c38dde6c1..062c30884 100644 --- a/app/views/parent/form/check-answers.njk +++ b/app/views/parent/form/check-answers.njk @@ -187,18 +187,13 @@ rows: summaryRows(consent, { createdAt: { label: __("consent.previousDose.createdAt.label"), - value: consent.firstDose.formatted.createdAt, - href: editPath("first-dose") - }, - location: { - label: __("consent.previousDose.location.label"), - value: consent.firstDose.location, - href: editPath("first-dose") + value: consent.firstDose.formatted.createdAt_date, + href: editPath("first-dose-date") }, country: { label: __("consent.previousDose.country.label"), value: consent.firstDose.formatted.country, - href: editPath("first-dose") + href: editPath("first-dose-country") } }) }) if consent.decision == ReplyDecision.AlreadyVaccinated }} @@ -211,18 +206,13 @@ rows: summaryRows(consent, { createdAt: { label: __("consent.previousDose.createdAt.label"), - value: consent.secondDose.formatted.createdAt, - href: editPath("second-dose") - }, - location: { - label: __("consent.previousDose.location.label"), - value: consent.secondDose.location, - href: editPath("second-dose") + value: consent.secondDose.formatted.createdAt_date, + href: editPath("second-dose-date") }, country: { label: __("consent.previousDose.country.label"), value: consent.secondDose.formatted.country, - href: editPath("second-dose") + href: editPath("second-dose-country") } }) }) if consent.decision == ReplyDecision.AlreadyVaccinated }} diff --git a/app/views/parent/form/previous-dose.njk b/app/views/parent/form/previous-dose-country.njk similarity index 63% rename from app/views/parent/form/previous-dose.njk rename to app/views/parent/form/previous-dose-country.njk index b472c88aa..f9f851c99 100644 --- a/app/views/parent/form/previous-dose.njk +++ b/app/views/parent/form/previous-dose-country.njk @@ -1,51 +1,14 @@ {% extends "_layouts/form.njk" %} -{% set title = __("consent." + key + ".title") %} +{% set title = __("consent." + key + ".country.title") %} {% block form %} - {{ appHeading({ - title: title - }) }} - - {{ __("consent." + key + ".description") | nhsukMarkdown }} - - {{ input({ - type: "hidden", - value: VaccinationOutcome.AlreadyVaccinated, - decorate: ["consent", key, "outcome"] - }) }} - - {{ input({ - type: "hidden", - value: "1P" if key == "firstDose" else "2P", - decorate: ["consent", key, "sequence"] - }) }} - - {{ dateInput({ - fieldset: { - legend: { - text: __("consent.previousDose.createdAt.title"), - size: "m" - } - }, - hint: { text: __("consent.previousDose.createdAt.hint") }, - decorate: ["consent", key, "createdAt_"] - }) }} - - {{ input({ - label: { - text: __("consent.previousDose.location.title"), - size: "m" - }, - hint: { text: __("consent.previousDose.location.hint") }, - decorate: ["consent", key, "location"] - }) }} - {{ radios({ fieldset: { legend: { - text: __("consent.previousDose.country.title"), - size: "m" + isPageHeading: true, + text: title, + size: "l" } }, items: [ @@ -66,6 +29,7 @@ }, { text: __("consent.previousDose.country.other"), + value: "Other", conditional: { html: select({ label: { text: __("consent.previousDose.countryOther.title") }, @@ -80,4 +44,16 @@ ], decorate: ["consent", key, "country"] }) }} + + {{ input({ + type: "hidden", + value: VaccinationOutcome.AlreadyVaccinated, + decorate: ["consent", key, "outcome"] + }) }} + + {{ input({ + type: "hidden", + value: "1P" if key == "firstDose" else "2P", + decorate: ["consent", key, "sequence"] + }) }} {% endblock %} diff --git a/app/views/parent/form/previous-dose-date.njk b/app/views/parent/form/previous-dose-date.njk new file mode 100644 index 000000000..755c3553b --- /dev/null +++ b/app/views/parent/form/previous-dose-date.njk @@ -0,0 +1,57 @@ +{% extends "_layouts/form.njk" %} + +{% set domestic = consent[key].country in ["England", "Scotland", "Wales", "Northern Ireland"] %} +{% if domestic %} + {% set title = __("consent." + key + ".scheduled.title") %} +{% else %} + {% set title = __("consent." + key + ".createdAt.title") %} +{% endif %} + +{% block form %} + {% if domestic %} + {{ radios({ + fieldset: { + legend: { + isPageHeading: true, + text: title, + size: "l" + } + }, + hint: { + text: __("consent." + key + ".scheduled.hint") + }, + items: [ + { + text: __("consent.previousDose.scheduled.yes") + }, + { + text: __("consent.previousDose.scheduled.no"), + conditional: { + html: dateInput({ + fieldset: { + legend: { + text: __("consent." + key + ".createdAt.title") + } + }, + hint: { text: __("consent.previousDose.createdAt.hint") }, + decorate: ["consent", key, "createdAt_"] + }) + } + } + ], + decorate: ["consent", key, "scheduled"] + }) }} + {% else %} + {{ dateInput({ + fieldset: { + legend: { + isPageHeading: true, + text: title, + size: "l" + } + }, + hint: { text: __("consent.previousDose.createdAt.hint") }, + decorate: ["consent", key, "createdAt_"] + }) }} + {% endif %} +{% endblock %}