Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [ASL-4566] PIL-E course purpose HE or training #1632

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
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: 4 additions & 0 deletions pages/pil/unscoped/courses/content/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ module.exports = {
label: 'Course title',
hint: 'For your records'
},
coursePurpose: {
name: 'coursePurpose',
label: 'Course purpose'
},
startDate: {
label: 'Course start date',
hint: `This helps ensure the licences are approved in time. Licences will be valid for 3 months from the date of approval.
Expand Down
3 changes: 3 additions & 0 deletions pages/pil/unscoped/courses/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ module.exports = merge({}, baseContent, {
title: {
required: 'Enter a course title'
},
coursePurpose: {
required: 'Please select higher education or training'
},
startDate: {
required: 'Enter the course start date',
validDate: 'Enter a valid date',
Expand Down
30 changes: 26 additions & 4 deletions pages/pil/unscoped/courses/participants/add/content/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
title: 'Apply for category E licence',
title: 'Enter participant details',
description: 'You are applying for a PIL-E on behalf of this participant. A PIL-E is a personal licence for higher education and training courses.',
fields: {
firstName: {
label: 'First name'
Expand All @@ -14,9 +15,30 @@ module.exports = {
label: 'Date of birth',
hint: 'For example, 12 11 1980'
},
trainingNeed: {
label: 'Training need',
hint: 'Include details about the participant\'s organisation, job title, specialism and grade (for example, trainee doctor or registrar). Explain how their career will benefit from training.'
organisation: {
label: 'Organisation'
},
qualificationLevelAndSubject: {
label: 'Qualification level and subject',
hint: 'For example BSc Pharmacology'
},
applicantLearningUse: {
label: 'How will the applicant use this learning in future scientific work using living animals',
hint: 'Explain how they intent to use it to design, conduct or analyse research.'
},
jobTitleOrQualification: {
label: 'Job title, career stage or qualification',
hint: 'For example trainee doctor, consultant or registrar'
},
fieldOfExpertise: {
label: 'Field of expertise',
hint: 'For example head and neck surgeon'
},
applicantTrainingUseAtWork: {
label: 'How will the applicant use this training in their work'
},
otherNotes: {
label: 'Other notes (optional)'
}
},
errors: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { omit } = require('lodash');

function participantDetailsSchemaHelper (schema, trainingCourse) {
if (trainingCourse.coursePurpose === 'higher-education') {
return omit(schema, ['jobTitleOrQualification', 'fieldOfExpertise', 'applicantTrainingUseAtWork']);
} else if (trainingCourse.coursePurpose === 'training') {
return omit(schema, ['qualificationLevelAndSubject', 'applicantLearningUse']);
} else {
throw new Error(`Invalid course purpose: ${trainingCourse.coursePurpose}`);
}
}

module.exports = participantDetailsSchemaHelper;
12 changes: 10 additions & 2 deletions pages/pil/unscoped/courses/participants/add/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { page } = require('@asl/service/ui');
const { form } = require('../../../../../common/routers');
const { buildModel } = require('../../../../../../lib/utils');
const confirm = require('./routers/confirm');
const participantDetailsSchemaHelper = require('./helpers/participant-details-schema-helper');
const schema = require('./schema');

module.exports = () => {
Expand All @@ -11,17 +12,24 @@ module.exports = () => {
paths: ['/confirm']
});

let modifiedSchema;

app.use((req, res, next) => {
res.locals.static.course = req.trainingCourse;

modifiedSchema = participantDetailsSchemaHelper(schema, req.trainingCourse);
req.model = {
id: 'new-participant',
...buildModel(schema)
...buildModel(modifiedSchema)
};
next();
});

app.use(form({
schema,
configure: (req, res, next) => {
req.form.schema = modifiedSchema;
next();
},
process: (req, res, next) => {
const day = req.body['dob-day'];
const month = req.body['dob-month'];
Expand Down
32 changes: 31 additions & 1 deletion pages/pil/unscoped/courses/participants/add/schema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,40 @@ module.exports = {
{ dateIsBefore: 'now' }
]
},
trainingNeed: {
organisation: {
inputType: 'inputText',
validate: [
'required'
]
},
qualificationLevelAndSubject: {
inputType: 'inputText',
validate: [
'required'
]
},
applicantLearningUse: {
inputType: 'textarea',
validate: [
'required'
]
},
jobTitleOrQualification: {
inputType: 'inputText',
validate: [
'required'
]
},
fieldOfExpertise: {
inputType: 'inputText',
validate: [
'required'
]
},
applicantTrainingUseAtWork: {
inputType: 'textarea'
},
otherNotes: {
inputType: 'textarea'
}
};
14 changes: 10 additions & 4 deletions pages/pil/unscoped/courses/participants/add/views/confirm.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from 'react';
import { useSelector } from 'react-redux';
import pick from 'lodash/pick';
import { pick, omit } from 'lodash';
import { FormLayout, Header, Snippet, ModelSummary } from '@ukhomeoffice/asl-components';
import { format } from 'date-fns';
import { dateFormat } from '../../../../../../../constants';
import participantSchema from '../schema';
import courseSchema from '../../../schema';
import formatters from '../../../formatters';
import participantDetailsSchemaHelper from '../helpers/participant-details-schema-helper';

const localFormatters = {
dob: {
Expand All @@ -16,15 +17,20 @@ const localFormatters = {

export default function Confirm() {
const course = useSelector(state => state.static.course);
const coursePurposeSchema = participantDetailsSchemaHelper(participantSchema, course);

const selectedSchemaItems = ['firstName', 'lastName', 'email', 'dob'];
const selectedCourseSchemaItems = ['title', 'coursePurpose', 'startDate', 'species', 'projectId', 'projectTitle'];

return (
<FormLayout cancelLink="pils.courses.participants.add">
<Header
title={<Snippet>title</Snippet>}
subtitle={course.title}
/>
<ModelSummary schema={participantSchema} formatters={{ ...formatters, ...localFormatters }} />
<ModelSummary model={course} schema={pick(courseSchema, 'title', 'startDate')} formatters={formatters} />
<ModelSummary model={course} schema={pick(courseSchema, 'species', 'projectId', 'projectTitle')} formatters={formatters} />
<ModelSummary schema={pick(coursePurposeSchema, selectedSchemaItems)} formatters={{ ...formatters, ...localFormatters }} />
<ModelSummary model={course} schema={pick(courseSchema, selectedCourseSchemaItems)} formatters={formatters} />
<ModelSummary schema={omit(coursePurposeSchema, selectedSchemaItems)} formatters={{ ...formatters, ...localFormatters }} />
</FormLayout>
);
}
3 changes: 3 additions & 0 deletions pages/pil/unscoped/courses/participants/add/views/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { useSelector } from 'react-redux';
import { Header, Snippet, FormLayout } from '@ukhomeoffice/asl-components';
import * as schema from '../content/index';

export default function Page() {
const course = useSelector(state => state.static.course);
Expand All @@ -10,6 +11,8 @@ export default function Page() {
title={<Snippet>title</Snippet>}
subtitle={course.title}
/>

<p className="govuk-body">{schema.description}</p>
</FormLayout>
);
}
2 changes: 1 addition & 1 deletion pages/pil/unscoped/courses/read/schema/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { pick } = require('lodash');
const schema = require('../../schema');

module.exports = pick(schema, 'title', 'startDate', 'species', 'projectId', 'projectTitle');
module.exports = pick(schema, 'title', 'coursePurpose', 'startDate', 'species', 'projectId', 'projectTitle');
13 changes: 13 additions & 0 deletions pages/pil/unscoped/courses/schema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ module.exports = {
projectTitle: {
accessor: 'project.title'
},
coursePurpose: {
inputType: 'radioGroup',
options: [{
value: 'higher-education',
label: 'Higher education',
hint: 'For example a degree in pharmacology or physiology'
}, {
value: 'training',
label: 'Training',
hint: 'For example to learn a new surgical procedure'
}],
validate: ['required']
},
title: {
inputType: 'inputText',
show: true,
Expand Down
2 changes: 1 addition & 1 deletion pages/pil/unscoped/courses/schema/update.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { pick } = require('lodash');
const schema = require('./');

module.exports = pick(schema, 'title', 'startDate', 'species', 'projectId');
module.exports = pick(schema, 'title', 'coursePurpose', 'startDate', 'species', 'projectId');
13 changes: 13 additions & 0 deletions pages/task/read/views/components/task-details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ function EstablishmentLink({ establishment }) {
);
}

function OrgAndQualificationDetails({ course }) {
return (
<Fragment>
<dt>Organisation</dt>
<dd>
{course.organisation}
</dd>
</Fragment>
);
}

function EstablishmentsList({ establishments }) {
return (
<Fragment>
Expand Down Expand Up @@ -128,6 +139,7 @@ function ProjectDetails({ task }) {

function PilDetails({ task }) {
const profile = useSelector(state => state.static.profile) || get(task, 'data.modelData.profile');
const course = useSelector(state => state.static.course) || get(task, 'data.modelData.trainingCourse');
const pil = profile.pil;
const establishment = (pil && pil.establishment) ? pil.establishment : get(task, 'data.establishment');
const isApplication = task.type === 'application';
Expand All @@ -142,6 +154,7 @@ function PilDetails({ task }) {
<Link page="pil.read" establishmentId={establishment.id} profileId={profile.id} label={profile.pilLicenceNumber} />
</LicenceNumber>
}
<OrgAndQualificationDetails course={course} />
<EstablishmentLink establishment={establishment} />
</dl>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import participantDetailsSchemaHelper from '../../../../../pages/pil/unscoped/courses/participants/add/helpers/participant-details-schema-helper';
import { omit } from 'lodash';

describe('participantDetailsSchemaHelper', () => {
const schema = {
jobTitle: 'Developer',
fieldOfExpertise: 'Software Engineering',
applicantTrainingUse: 'Development',
qualificationLevelAndSubject: 'BSc Computer Science',
applicantLearning: 'Advanced Programming'
};

it('should omit jobTitle, fieldOfExpertise, and applicantTrainingUse for higher-education course purpose', () => {
const trainingCourse = { coursePurpose: 'higher-education' };
const result = participantDetailsSchemaHelper(schema, trainingCourse);
expect(result).toEqual(omit(schema, ['jobTitle', 'fieldOfExpertise', 'applicantTrainingUse']));
});

it('should omit qualificationLevelAndSubject and applicantLearning for training course purpose', () => {
const trainingCourse = { coursePurpose: 'training' };
const result = participantDetailsSchemaHelper(schema, trainingCourse);
expect(result).toEqual(omit(schema, ['qualificationLevelAndSubject', 'applicantLearning']));
});

it('should throw an error for invalid course purpose', () => {
const trainingCourse = { coursePurpose: 'invalid-purpose' };
expect(() => participantDetailsSchemaHelper(schema, trainingCourse)).toThrowError('Invalid course purpose: invalid-purpose');
});
});