Skip to content

Commit

Permalink
Merge pull request #6342 from NMDSdevopsServiceAdm/featureBranch/leve…
Browse files Browse the repository at this point in the history
…l2-care-certificate

Feature branch/level2 care certificate
  • Loading branch information
duncanc19 authored Sep 3, 2024
2 parents 1c6f277 + 791566b commit 0d19c18
Show file tree
Hide file tree
Showing 33 changed files with 1,696 additions and 38 deletions.
78 changes: 78 additions & 0 deletions backend/migrations/20240827102746-addLevel2CareCertificate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
'use strict';

const table = { tableName: 'Worker', schema: 'cqc' };

module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction((transaction) => {
return Promise.all([
queryInterface.addColumn(
table,
'Level2CareCertificateValue',
{
type: Sequelize.DataTypes.TEXT,
allowNull: true,
},
{ transaction },
),
queryInterface.addColumn(
table,
'Level2CareCertificateYear',
{
type: Sequelize.DataTypes.INTEGER,
allowNull: true,
},
{ transaction },
),
queryInterface.addColumn(
table,
'Level2CareCertificateSavedAt',
{
type: Sequelize.DataTypes.DATE,
allowNull: true,
},
{ transaction },
),
queryInterface.addColumn(
table,
'Level2CareCertificateChangedAt',
{
type: Sequelize.DataTypes.DATE,
allowNull: true,
},
{ transaction },
),
queryInterface.addColumn(
table,
'Level2CareCertificateSavedBy',
{
type: Sequelize.DataTypes.TEXT,
allowNull: true,
},
{ transaction },
),
queryInterface.addColumn(
table,
'Level2CareCertificateChangedBy',
{
type: Sequelize.DataTypes.TEXT,
allowNull: true,
},
{ transaction },
),
]);
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction((transaction) => {
return Promise.all([
queryInterface.removeColumn(table, 'Level2CareCertificateValue', { transaction }),
queryInterface.removeColumn(table, 'Level2CareCertificateYear', { transaction }),
queryInterface.removeColumn(table, 'Level2CareCertificateSavedAt', { transaction }),
queryInterface.removeColumn(table, 'Level2CareCertificateChangedAt', { transaction }),
queryInterface.removeColumn(table, 'Level2CareCertificateSavedBy', { transaction }),
queryInterface.removeColumn(table, 'Level2CareCertificateChangedBy', { transaction }),
]);
});
},
};
6 changes: 6 additions & 0 deletions backend/server/models/classes/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ class Worker extends EntityValidator {
return this._properties.get('CareCertificate') ? this._properties.get('CareCertificate').property : null;
}

get level2CareCertificate() {
return this._properties.get('Level2CareCertificate')
? this._properties.get('Level2CareCertificate').property
: null;
}

get approvedMentalHealthWorker() {
return this._properties.get('ApprovedMentalHealthWorker')
? this._properties.get('ApprovedMentalHealthWorker').property
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// the level 2 care certificate property is an enumeration
const ChangePropertyPrototype = require('../../properties/changePrototype').ChangePropertyPrototype;

const LEVEL_2_CARE_CERTIFICATE_TYPE = ['Yes, completed', 'Yes, started', 'No'];
exports.WorkerLevel2CareCertificateProperty = class WorkerLevel2CareCertificateProperty extends (
ChangePropertyPrototype
) {
constructor() {
super('Level2CareCertificate');
this._allowNull = true;
}

static clone() {
return new WorkerLevel2CareCertificateProperty();
}

// concrete implementations
async restoreFromJson(document) {
const completedInYearSinceLevel2CareCertIntroduced = (year) => {
const yearLevel2CareCertificateIntroduced = 2024;
const thisYear = new Date().getFullYear();
return year >= yearLevel2CareCertificateIntroduced && document.level2CareCertificate.year <= thisYear
? true
: false;
};

if (document.level2CareCertificate) {
if (
[LEVEL_2_CARE_CERTIFICATE_TYPE[1], LEVEL_2_CARE_CERTIFICATE_TYPE[2]].includes(
document.level2CareCertificate.value,
)
) {
this.property = {
value: document.level2CareCertificate.value,
year: null,
};
return;
}

if (document.level2CareCertificate.value === LEVEL_2_CARE_CERTIFICATE_TYPE[0]) {
if (
document.level2CareCertificate.year &&
Number.isInteger(document.level2CareCertificate.year) &&
completedInYearSinceLevel2CareCertIntroduced(document.level2CareCertificate.year)
) {
this.property = {
value: document.level2CareCertificate.value,
year: document.level2CareCertificate.year,
};
} else {
this.property = {
value: document.level2CareCertificate.value,
year: null,
};
}
return;
}
this.property = null;
}
}

restorePropertyFromSequelize(document) {
let level2CareCertificate = {
value: document.Level2CareCertificateValue,
year: document.Level2CareCertificateYear,
};
return level2CareCertificate;
}

savePropertyToSequelize() {
return {
Level2CareCertificateValue: this.property.value,
Level2CareCertificateYear:
this.property.value === 'Yes, completed' && this.property.year ? this.property.year : null,
};
}

isEqual(currentValue, newValue) {
// not a simple (enum'd) string compare; if "Yes, completed", also need to compare the year (just an integer)

if (currentValue && newValue && currentValue.value === 'Yes, completed') {
if (currentValue.year === newValue.year) {
return currentValue.value === newValue.value;
}
return false;
}

return currentValue && newValue && currentValue.value === newValue.value;
}

toJSON(withHistory = false, showPropertyHistoryOnly = true) {
if (!withHistory) {
// simple form
return {
level2CareCertificate: this.property,
};
}

return {
level2CareCertificate: {
currentValue: this.property,
...this.changePropsToJSON(showPropertyHistoryOnly),
},
};
}
};
5 changes: 4 additions & 1 deletion backend/server/models/classes/worker/workerProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const establishmentFkProperty = require('./properties/establishmentFkProperty').
const longTermAbsenceProperty = require('./properties/longTermAbsenceProperty').LongTermAbsenceProperty;
const healthAndCareVisaProperty = require('./properties/healthAndCareVisa').HealthAndCareVisaProperty;
const employedFromOutsideUkProperty = require('./properties/employedFromOutsideUk').EmployedFromOutsideUkProperty;
const level2CareCertificateProperty =
require('./properties/level2CareCertificateProperty').WorkerLevel2CareCertificateProperty;

class WorkerPropertyManager {
constructor() {
Expand Down Expand Up @@ -78,6 +80,7 @@ class WorkerPropertyManager {
this._thisManager.registerProperty(weeklyHoursContractedProperty);
this._thisManager.registerProperty(annualHourlyPayProperty);
this._thisManager.registerProperty(careCertificateProperty);
this._thisManager.registerProperty(level2CareCertificateProperty);
this._thisManager.registerProperty(apprenticeshipProperty);
this._thisManager.registerProperty(qualificationInSocialCareProperty);
this._thisManager.registerProperty(socialCareQualificationProperty);
Expand All @@ -90,7 +93,7 @@ class WorkerPropertyManager {
this._thisManager.registerProperty(establishmentFkProperty);
this._thisManager.registerProperty(longTermAbsenceProperty);
this._thisManager.registerProperty(healthAndCareVisaProperty);
this._thisManager.registerProperty(employedFromOutsideUkProperty)
this._thisManager.registerProperty(employedFromOutsideUkProperty);
}

get manager() {
Expand Down
2 changes: 2 additions & 0 deletions backend/server/models/establishment.js
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,8 @@ module.exports = function (sequelize, DataTypes) {
'ApprovedMentalHealthWorkerValue',
'QualificationInSocialCareValue',
'OtherQualificationsValue',
'Level2CareCertificateValue',
'Level2CareCertificateYear',
],
as: 'workers',
where: {
Expand Down
31 changes: 31 additions & 0 deletions backend/server/models/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,37 @@ module.exports = function (sequelize, DataTypes) {
allowNull: true,
field: '"CareCertificateChangedBy"',
},
Level2CareCertificateValue: {
type: DataTypes.ENUM,
allowNull: true,
values: ['Yes, completed', 'Yes, started', 'No'],
field: '"Level2CareCertificateValue"',
},
Level2CareCertificateYear: {
type: DataTypes.INTEGER,
allowNull: true,
field: '"Level2CareCertificateYear"',
},
Level2CareCertificateSavedAt: {
type: DataTypes.DATE,
allowNull: true,
field: '"Level2CareCertificateSavedAt"',
},
Level2CareCertificateChangedAt: {
type: DataTypes.DATE,
allowNull: true,
field: '"Level2CareCertificateChangedAt"',
},
Level2CareCertificateSavedBy: {
type: DataTypes.TEXT,
allowNull: true,
field: '"Level2CareCertificateSavedBy"',
},
Level2CareCertificateChangedBy: {
type: DataTypes.TEXT,
allowNull: true,
field: '"Level2CareCertificateChangedBy"',
},
HealthAndCareVisaValue: {
type: DataTypes.ENUM,
allowNull: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const workerHeaders = [
'YEAROFENTRY',
'DISABLED',
'CARECERT',
'L2CARECERT',
'RECSOURCE',
'HANDCVISA',
'INOUTUK',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const _convertYesNoDontKnow = (value) => {
// takes the given Worker entity and writes it out to CSV string (one line)
const toCSV = (establishmentId, entity, MAX_QUALIFICATIONS, downloadType) => {
// ["LOCALESTID","UNIQUEWORKERID","STATUS","DISPLAYID","NINUMBER","POSTCODE","DOB","GENDER","ETHNICITY","NATIONALITY","BRITISHCITIZENSHIP","COUNTRYOFBIRTH","YEAROFENTRY","DISABLED",
// "CARECERT","RECSOURCE","HANDCVISA","INOUTUK","STARTDATE","STARTINSECT","APPRENTICE","EMPLSTATUS","ZEROHRCONT","DAYSSICK","SALARYINT","SALARY","HOURLYRATE","MAINJOBROLE","MAINJRDESC","CONTHOURS","AVGHOURS",
// "CARECERT","L2CARECERT","RECSOURCE","HANDCVISA","INOUTUK","STARTDATE","STARTINSECT","APPRENTICE","EMPLSTATUS","ZEROHRCONT","DAYSSICK","SALARYINT","SALARY","HOURLYRATE","MAINJOBROLE","MAINJRDESC","CONTHOURS","AVGHOURS",
// "NMCREG","NURSESPEC","AMHP","SCQUAL","NONSCQUAL","QUALACH01","QUALACH01NOTES","QUALACH02","QUALACH02NOTES","QUALACH03","QUALACH03NOTES"];
const columns = [];

Expand Down Expand Up @@ -175,6 +175,25 @@ const toCSV = (establishmentId, entity, MAX_QUALIFICATIONS, downloadType) => {
}
columns.push(careCert);

// "L2CARECERT"
let l2CareCert = '';
switch (entity.Level2CareCertificateValue) {
case 'Yes, completed':
if (entity.Level2CareCertificateYear) {
l2CareCert = `1;${entity.Level2CareCertificateYear}`;
} else {
l2CareCert = '1;';
}
break;
case 'Yes, started':
l2CareCert = '2';
break;
case 'No':
l2CareCert = '3';
break;
}
columns.push(l2CareCert);

// "RECSOURCE"
let recruitmentSource = '';
switch (entity.RecruitedFromValue) {
Expand Down
1 change: 1 addition & 0 deletions backend/server/test/integration/utils/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports.apiWorkerBuilder = build('Worker', {
YearArrivedValue: oneOf('Yes', 'No', "Don't know"),
DisabilityValue: oneOf('Yes', 'No', "Don't know", 'Undisclosed'),
CareCertificateValue: oneOf('Yes, completed', 'No', 'Yes, in progress or partially completed'),
Level2CareCertificateValue: oneOf('Yes, completed', 'Yes, started', 'No'),
RecruitedFromValue: oneOf('Yes', 'No'),
MainJobStartDateValue: fake((f) => f.helpers.replaceSymbolWithNumber('####-##-##')),
recruitedFrom: {
Expand Down
1 change: 1 addition & 0 deletions backend/server/test/unit/mockdata/workers.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ exports.knownHeaders = [
'YEAROFENTRY',
'DISABLED',
'CARECERT',
'L2CARECERT',
'RECSOURCE',
'HANDCVISA',
'INOUTUK',
Expand Down
Loading

0 comments on commit 0d19c18

Please sign in to comment.