Skip to content

Commit

Permalink
Merge pull request #2088 from NMDSdevopsServiceAdm/test
Browse files Browse the repository at this point in the history
Mandatory training and WDF fixes from Staging to Live
  • Loading branch information
aaron-russell authored Apr 15, 2020
2 parents a8dfb57 + f634f44 commit b5584a7
Show file tree
Hide file tree
Showing 129 changed files with 3,119 additions and 1,161 deletions.
6 changes: 3 additions & 3 deletions server/data/parentWDFReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SELECT
"DataPermissions",
"EmployerTypeValue",
"EmployerTypeSavedAt",
CASE WHEN "OverallWdfEligibility" > :effectiveDate THEN "OverallWdfEligibility" ELSE NULL END AS "CurrentWdfEligibilityStatus",
CASE WHEN "OverallWdfEligibility" > :effectiveDate THEN true ELSE NULL END AS "CurrentWdfEligibilityStatus",
CASE WHEN "OverallWdfEligibility" > :effectiveDate THEN to_char("OverallWdfEligibility", :timeFormat) ELSE NULL END AS "DateEligibilityAchieved",
MainService.name AS "MainService",
"MainServiceFKValue",
Expand Down Expand Up @@ -123,8 +123,8 @@ SELECT
"StartersValue",
"LeaversValue",
"NumberOfStaffValue",
updated,
CASE WHEN updated > :effectiveDate THEN to_char(updated, :timeFormat) ELSE NULL END AS "LastUpdatedDate",
to_char(updated, :timeFormat) updated,
CASE WHEN updated > :effectiveDate THEN true ELSE NULL END AS "LastUpdatedDate",
"ShareDataWithCQC",
"ShareDataWithLA",
(select count("LeaveReasonFK") from cqc."Worker" where "EstablishmentFK" = "Establishment"."EstablishmentID") as "ReasonsForLeaving",
Expand Down
20 changes: 19 additions & 1 deletion server/data/trainingReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const db = rfr('server/utils/datastore');
const getTrainingDataQuery =
`
SELECT
a."NameOrIdValue", a."ID", c."Category", b."Title", to_char(b."Completed", :timeFormat) as "Completed",
a."NameOrIdValue", a."ID", c."Category", c."ID" AS "CategoryID", b."Title", to_char(b."Completed", :timeFormat) as "Completed",
to_char(b."Expires", :timeFormat) as "ExpiredOn", b."Accredited", b."Expires", a."MainJobFKValue"
FROM
cqc."Worker" a
Expand All @@ -22,6 +22,13 @@ WHERE
a."Archived" = :falseValue;
`;

const getMndatoryTrainingDetailsQuery =
`SELECT count(:zero)
FROM cqc."MandatoryTraining"
WHERE "EstablishmentFK" = :establishmentId
AND "TrainingCategoryFK" = :categoryId
AND "JobFK" = :jobId`

const getJobNameQuery =
`
select "JobName" from cqc."Job" where "JobID" = :jobId
Expand All @@ -37,6 +44,17 @@ exports.getTrainingData = async establishmentId =>
type: db.QueryTypes.SELECT
});

exports.getMndatoryTrainingDetails = async (trainingData, establishmentId) =>
db.query(getMndatoryTrainingDetailsQuery, {
replacements: {
establishmentId,
jobId: trainingData.MainJobFKValue,
categoryId: trainingData.CategoryID,
zero: 0
},
type: db.QueryTypes.SELECT
});

exports.getJobName = async jobId =>
db.query(getJobNameQuery, {
replacements: {
Expand Down
2 changes: 1 addition & 1 deletion server/models/BulkImport/csv/workers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2667,7 +2667,7 @@ class Worker {
status = !this._validateDisplayId() ? false : status;
status = !this._validateStatus() ? false : status;

// only continue to process validation, if the status is not UNCHECKED or DELETED
// only continue to process validation, if the status is not UNCHECKED, DELETED OR UNCHANGED
if (!STOP_VALIDATING_ON.includes(this._status)) {
status = !this._validateContractType() ? false : status;
status = !this._validateNINumber() ? false : status;
Expand Down
29 changes: 26 additions & 3 deletions server/models/classes/establishment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*
* Also includes representation as JSON, in one or more presentations.
*/
const moment = require('moment');

const uuid = require('uuid');

// Shorthand for hasOwnProperty that also works with bare objects
Expand Down Expand Up @@ -914,8 +916,9 @@ class Establishment extends EntityValidator {
// the saving of an Establishment can be initiated within
// an external transaction
const thisTransaction = externalTransaction || t;
const buChanged = this._status === 'NOCHANGE';
// now append the extendable properties
const modifedUpdateDocument = this._properties.save(savedBy.toLowerCase(), {});
const modifedUpdateDocument = this._properties.save(savedBy.toLowerCase(), {}, buChanged);
if(modifedUpdateDocument && !modifedUpdateDocument.ShareDataValue){
modifedUpdateDocument.shareWithCQC = false;
modifedUpdateDocument.shareWithLA = false;
Expand Down Expand Up @@ -1852,11 +1855,30 @@ class Establishment extends EntityValidator {
return allExistAndValid;
}

async canConfirm (effectiveFrom, lastEligibility, wdfPropertyValues) {
const hasEligibleProperties = wdfPropertyValues.every(thisWdfProperty => (thisWdfProperty.isEligible !== 'No'));

if (!hasEligibleProperties) {
return false;
}

effectiveFrom = moment(effectiveFrom);
lastEligibility = moment(lastEligibility);

if (lastEligibility.isAfter(effectiveFrom)) {
return false;
}

return true;
}

// returns true if this establishment is WDF eligible as referenced from the
// given effective date; otherwise returns false
async isWdfEligible(effectiveFrom) {
const wdfByProperty = await this.wdf(effectiveFrom);
const wdfPropertyValues = Object.values(wdfByProperty);
const lastEligibility = this._lastWdfEligibility ? this._lastWdfEligibility.toISOString() : null;
const canConfirm = await this.canConfirm(effectiveFrom, lastEligibility, wdfPropertyValues);

// This establishment is eligible only if the overall eligible date is later than the effective date
// The WDF by property will show the current eligibility of each property
Expand All @@ -1870,9 +1892,10 @@ class Establishment extends EntityValidator {
(thisWdfProperty.isEligible === 'Yes' && thisWdfProperty.updatedSinceEffectiveDate) ||
thisWdfProperty.isEligible === 'Not relevant'
),

// Can the Establishment confirm their up-to-date information?
canConfirm: canConfirm,
// The date just the establishment fields were last wdf valid
lastEligibility: this._lastWdfEligibility ? this._lastWdfEligibility.toISOString() : null,
lastEligibility: lastEligibility,
...wdfByProperty,
};
}
Expand Down
Loading

0 comments on commit b5584a7

Please sign in to comment.