diff --git a/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs b/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs index ad32f35ba2..094c6a69c8 100644 --- a/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs @@ -296,7 +296,12 @@ FROM SelfAssessments COALESCE(ucd.Email, u.PrimaryEmail) AS DelegateEmail, da.Active AS IsDelegateActive, sa.Name AS [Name], - MAX(casv.Verified) as SignedOff, + CASE + WHEN MAX(sar.[DateTime]) >= MAX(casv.Verified) THEN NULL + ELSE ( + MAX(casv.Verified) + ) + END AS SignedOff, sa.SupervisorSelfAssessmentReview, sa.SupervisorResultsReview"; @@ -311,6 +316,8 @@ LEFT OUTER JOIN Users AS uEnrolledBy WITH (NOLOCK) ON uEnrolledBy.ID = aaEnrolle LEFT JOIN dbo.CandidateAssessmentSupervisors AS cas WITH (NOLOCK) ON ca.ID = cas.CandidateAssessmentID LEFT JOIN dbo.CandidateAssessmentSupervisorVerifications AS casv WITH (NOLOCK) ON cas.ID = casv.CandidateAssessmentSupervisorID AND (casv.Verified IS NOT NULL AND casv.SignedOff = 1) + LEFT JOIN SelfAssessmentResults AS sar ON ca.SelfAssessmentID = sar.SelfAssessmentID AND + ca.DelegateUserID = sar.DelegateUserID WHERE sa.ID = @selfAssessmentId AND da.CentreID = @centreID AND csa.CentreID = @centreID @@ -349,7 +356,8 @@ LEFT JOIN dbo.CandidateAssessmentSupervisorVerifications AS casv WITH (NOLOCK) O if (signedOff != null) { - groupBy += (bool)signedOff ? " HAVING MAX(casv.Verified) IS NOT NULL " : " HAVING MAX(casv.Verified) IS NULL "; + groupBy += (bool)signedOff ? " HAVING MAX(sar.[DateTime]) < MAX(casv.Verified) AND MAX(casv.Verified) IS NOT NULL " : + " HAVING MAX(sar.[DateTime]) >= MAX(casv.Verified) OR MAX(casv.Verified) IS NULL "; } string orderBy; diff --git a/DigitalLearningSolutions.Data/DataServices/SupervisorDataService.cs b/DigitalLearningSolutions.Data/DataServices/SupervisorDataService.cs index 0f7be59b6b..bb98cf4ebe 100644 --- a/DigitalLearningSolutions.Data/DataServices/SupervisorDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/SupervisorDataService.cs @@ -106,16 +106,33 @@ INNER JOIN AdminAccounts AS aa "; private const string delegateSelfAssessmentFields = "ca.ID, sa.ID AS SelfAssessmentID, sa.Name AS RoleName, sa.SupervisorSelfAssessmentReview, sa.SupervisorResultsReview, COALESCE (sasr.RoleName, 'Supervisor') AS SupervisorRoleTitle, ca.StartedDate"; - private const string signedOffFields = @"(SELECT TOP (1) casv.Verified -FROM CandidateAssessmentSupervisorVerifications AS casv INNER JOIN - CandidateAssessmentSupervisors AS cas ON casv.CandidateAssessmentSupervisorID = cas.ID -WHERE(cas.CandidateAssessmentID = ca.ID) AND(casv.Requested IS NOT NULL) AND(casv.Verified IS NOT NULL) -ORDER BY casv.Requested DESC) AS SignedOffDate, -(SELECT TOP(1) casv.SignedOff -FROM CandidateAssessmentSupervisorVerifications AS casv INNER JOIN - CandidateAssessmentSupervisors AS cas ON casv.CandidateAssessmentSupervisorID = cas.ID -WHERE(cas.CandidateAssessmentID = ca.ID) AND(casv.Requested IS NOT NULL) AND(casv.Verified IS NOT NULL) -ORDER BY casv.Requested DESC) AS SignedOff,"; + private const string signedOffFields = @"(SELECT CASE + WHEN MAX(sar.[DateTime]) >= MAX(casv.Verified) THEN NULL + ELSE MAX(casv.Verified) + END AS Verified + FROM CandidateAssessmentSupervisorVerifications AS casv INNER JOIN + CandidateAssessmentSupervisors AS cas ON casv.CandidateAssessmentSupervisorID = cas.ID INNER JOIN + CandidateAssessments AS ca1 ON cas.CandidateAssessmentID = ca1.ID LEFT JOIN + SelfAssessmentResults AS sar ON ca1.SelfAssessmentID = sar.SelfAssessmentID AND ca1.DelegateUserID = sar.DelegateUserID + WHERE(cas.CandidateAssessmentID = ca.ID) AND(casv.Requested IS NOT NULL) AND(casv.Verified IS NOT NULL) + GROUP BY ca1.ID ) AS SignedOffDate, + + (SELECT CASE + WHEN MAX(sar.[DateTime]) >= MAX(casv.Verified) THEN NULL + ELSE ( + SELECT TOP(1) casv.SignedOff + FROM CandidateAssessmentSupervisorVerifications AS casv INNER JOIN + CandidateAssessmentSupervisors AS cas ON casv.CandidateAssessmentSupervisorID = cas.ID + WHERE(cas.CandidateAssessmentID = ca.ID) AND(casv.Requested IS NOT NULL) AND(casv.Verified IS NOT NULL) + ORDER BY casv.Verified DESC + ) + END AS SignedOff + FROM CandidateAssessmentSupervisorVerifications AS casv INNER JOIN + CandidateAssessmentSupervisors AS cas ON casv.CandidateAssessmentSupervisorID = cas.ID INNER JOIN + CandidateAssessments AS ca1 ON cas.CandidateAssessmentID = ca1.ID LEFT JOIN + SelfAssessmentResults AS sar ON ca1.SelfAssessmentID = sar.SelfAssessmentID AND ca1.DelegateUserID = sar.DelegateUserID + WHERE(cas.CandidateAssessmentID = ca.ID) AND(casv.Requested IS NOT NULL) AND(casv.Verified IS NOT NULL) + GROUP BY ca1.ID) AS SignedOff,"; public SupervisorDataService(IDbConnection connection, ILogger logger) { @@ -583,7 +600,7 @@ public bool RemoveSupervisorDelegateById(int supervisorDelegateId, int delegateU public IEnumerable GetSelfAssessmentsForSupervisorDelegateId(int supervisorDelegateId, int? adminIdCategoryId) { return connection.Query( - @$"SELECT {delegateSelfAssessmentFields}, COALESCE(ca.LastAccessed, ca.StartedDate) AS LastAccessed, ca.CompleteByDate, ca.LaunchCount, ca.CompletedDate, r.CompetencyAssessment, sg.SubGroup, pg.ProfessionalGroup,CONVERT(BIT, IIF(cas.CandidateAssessmentID IS NULL, 0, 1)) AS IsAssignedToSupervisor,ca.DelegateUserID, + @$"SELECT {delegateSelfAssessmentFields}, COALESCE(ca.LastAccessed, ca.StartedDate) AS LastAccessed, ca.CompleteByDate, ca.LaunchCount, ca.CompletedDate, r.RoleProfile, sg.SubGroup, pg.ProfessionalGroup,CONVERT(BIT, IIF(cas.CandidateAssessmentID IS NULL, 0, 1)) AS IsAssignedToSupervisor,ca.DelegateUserID, (SELECT COUNT(*) AS Expr1 FROM CandidateAssessmentSupervisorVerifications AS casv WHERE (CandidateAssessmentSupervisorID = cas.ID) AND (Requested IS NOT NULL) AND (Verified IS NULL)) AS SignOffRequested, @@ -785,7 +802,7 @@ FROM NRPProfessionalGroups (SELECT SubGroup FROM NRPSubGroups WHERE (ID = rp.NRPSubGroupID)) AS NRPSubGroup, - (SELECT CompetencyAssessment + (SELECT RoleProfile FROM NRPRoles WHERE (ID = rp.NRPRoleID)) AS NRPRole, 0 AS SelfAssessmentReviewID FROM SelfAssessments AS rp INNER JOIN @@ -816,7 +833,7 @@ FROM NRPProfessionalGroups (SELECT SubGroup FROM NRPSubGroups WHERE (ID = rp.NRPSubGroupID)) AS NRPSubGroup, - (SELECT CompetencyAssessment + (SELECT RoleProfile FROM NRPRoles WHERE (ID = rp.NRPRoleID)) AS NRPRole, 0 AS SelfAssessmentReviewID FROM SelfAssessments AS rp @@ -1147,7 +1164,7 @@ FROM CandidateAssessmentSupervisors { return connection.Query( @"SELECT ca.ID, ca.SelfAssessmentID, sa.Name AS RoleName, sa.ReviewerCommentsLabel, COALESCE (sasr.SelfAssessmentReview, 1) AS SelfAssessmentReview, COALESCE (sasr.ResultsReview, 1) AS SupervisorResultsReview, COALESCE (sasr.RoleName, 'Supervisor') AS SupervisorRoleTitle, ca.StartedDate, - ca.LastAccessed, ca.CompleteByDate, ca.LaunchCount, ca.CompletedDate, npg.ProfessionalGroup, nsg.SubGroup, nr.CompetencyAssessment, casv.ID AS CandidateAssessmentSupervisorVerificationId, + ca.LastAccessed, ca.CompleteByDate, ca.LaunchCount, ca.CompletedDate, npg.ProfessionalGroup, nsg.SubGroup, nr.RoleProfile, casv.ID AS CandidateAssessmentSupervisorVerificationId, (SELECT COUNT(sas1.CompetencyID) AS CompetencyAssessmentQuestionCount FROM SelfAssessmentStructure AS sas1 INNER JOIN CandidateAssessments AS ca1 ON sas1.SelfAssessmentID = ca1.SelfAssessmentID INNER JOIN diff --git a/DigitalLearningSolutions.Web/Controllers/TrackingSystem/Delegates/ActivityDelegatesController.cs b/DigitalLearningSolutions.Web/Controllers/TrackingSystem/Delegates/ActivityDelegatesController.cs index f806ab1991..3352b34d74 100644 --- a/DigitalLearningSolutions.Web/Controllers/TrackingSystem/Delegates/ActivityDelegatesController.cs +++ b/DigitalLearningSolutions.Web/Controllers/TrackingSystem/Delegates/ActivityDelegatesController.cs @@ -244,6 +244,7 @@ public IActionResult Index( saDelegate.LastAccessed = DateHelper.GetLocalDateTime(saDelegate.LastAccessed); saDelegate.SubmittedDate = DateHelper.GetLocalDateTime(saDelegate.SubmittedDate); saDelegate.RemovedDate = DateHelper.GetLocalDateTime(saDelegate.RemovedDate); + saDelegate.SignedOff = saDelegate.SignedOff is null ? null : DateHelper.GetLocalDateTime(saDelegate.SignedOff.Value); } } diff --git a/DigitalLearningSolutions.Web/Views/LearningPortal/SelfAssessments/SelfAssessmentOverview.cshtml b/DigitalLearningSolutions.Web/Views/LearningPortal/SelfAssessments/SelfAssessmentOverview.cshtml index 61eca271ee..4f3bed409c 100644 --- a/DigitalLearningSolutions.Web/Views/LearningPortal/SelfAssessments/SelfAssessmentOverview.cshtml +++ b/DigitalLearningSolutions.Web/Views/LearningPortal/SelfAssessments/SelfAssessmentOverview.cshtml @@ -178,7 +178,8 @@ view-data="@(new ViewDataDictionary(ViewData) { { "IsSupervisorResultsReviewed", Model.SelfAssessment.IsSupervisorResultsReviewed } })" />

@Model.SelfAssessment.SignOffRoleName Sign-off

(int)c["questionsCount"]) == competencySummaries.Sum(c => (int)c["verifiedCount"]) }})" /> + view-data="@(new ViewDataDictionary(ViewData) { { "IsAllCompetencyConfirmed", competencySummaries.Sum(c => (int)c["questionsCount"]) == competencySummaries.Sum(c => (int)c["verifiedCount"]) }, + { "IsOngoingSelfAssessment", latestResult > latestSignoff }})" /> @if (Model.AllQuestionsVerifiedOrNotRequired) { @if (!Model.SupervisorSignOffs.Any()) diff --git a/DigitalLearningSolutions.Web/Views/Supervisor/ReviewSelfAssessment.cshtml b/DigitalLearningSolutions.Web/Views/Supervisor/ReviewSelfAssessment.cshtml index b1362017bd..9d02973275 100644 --- a/DigitalLearningSolutions.Web/Views/Supervisor/ReviewSelfAssessment.cshtml +++ b/DigitalLearningSolutions.Web/Views/Supervisor/ReviewSelfAssessment.cshtml @@ -177,10 +177,10 @@ @if (!string.IsNullOrWhiteSpace(competency.Description) && !competency.AlwaysShowDescription) {
- - - @competency.Name - + + + @competency.Name +
@(Html.Raw(@competency.Description)) @@ -225,7 +225,8 @@ {

Self Assessment Sign-off Status

- +
} @if (Model.CompetencyGroups.Any()) diff --git a/DigitalLearningSolutions.Web/Views/Supervisor/Shared/_SupervisorSignOffSummary.cshtml b/DigitalLearningSolutions.Web/Views/Supervisor/Shared/_SupervisorSignOffSummary.cshtml index 744dbc0ca9..f6d72fdb2c 100644 --- a/DigitalLearningSolutions.Web/Views/Supervisor/Shared/_SupervisorSignOffSummary.cshtml +++ b/DigitalLearningSolutions.Web/Views/Supervisor/Shared/_SupervisorSignOffSummary.cshtml @@ -5,13 +5,14 @@ @if (Model.Any()) { + var notValidated = Model.FirstOrDefault().Verified != null && Model.FirstOrDefault().SignedOff && (bool)ViewData["IsOngoingSelfAssessment"];
@Model.FirstOrDefault().SupervisorRoleName
- @Model.FirstOrDefault().SupervisorName (@Model.FirstOrDefault().SupervisorEmail) + @(notValidated ? "" : $"{Model.FirstOrDefault().SupervisorName} ({Model.FirstOrDefault().SupervisorEmail})") @if (Model.FirstOrDefault().Removed != null) { Removed @Model.FirstOrDefault().Removed.Value.ToShortDateString() @@ -34,6 +35,10 @@ { Requested @Model.FirstOrDefault().Requested.Value.ToShortDateString() } + else if (notValidated) + { + Not validated + } else if (Model.FirstOrDefault().SignedOff && Model.FirstOrDefault().Verified != null) { Signed off @Model.FirstOrDefault().Verified.Value.ToShortDateString() @@ -44,7 +49,7 @@ }
- @if (Model.FirstOrDefault().Verified == null && Model.FirstOrDefault().Removed == null) + @if (!notValidated && Model.FirstOrDefault().Verified == null && Model.FirstOrDefault().Removed == null) { @if (Model.FirstOrDefault().EmailSent == null || Model.FirstOrDefault().EmailSent.Value.ToShortDateString() != ClockUtility.UtcNow.ToShortDateString()) { @@ -54,7 +59,8 @@ } } - @if (Context.Request.Path.Value!.Contains("SelfAssessment")) { + @if (Context.Request.Path.Value!.Contains("SelfAssessment")) + { Withdraw } @@ -66,7 +72,10 @@ Comments
- @Model.FirstOrDefault().Comments + @if (!notValidated) + { + @Model.FirstOrDefault().Comments + }
@if ((Model.Count() - 1) > 0) {