diff --git a/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/CandidateAssessmentsDataService.cs b/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/CandidateAssessmentsDataService.cs index 20f9f52ab2..2390d54147 100644 --- a/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/CandidateAssessmentsDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/CandidateAssessmentsDataService.cs @@ -8,6 +8,85 @@ public partial class SelfAssessmentDataService { + public IEnumerable GetSelfAssessmentsForCandidate(int delegateUserId, int centreId, int? adminIdCategoryID) + { + return connection.Query( + @"SELECT SelfAssessment.Id, + SelfAssessment.Name, + SelfAssessment.Description, + SelfAssessment.IncludesSignposting, + SelfAssessment.IncludeRequirementsFilters, + SelfAssessment. IsSupervisorResultsReviewed, + SelfAssessment.ReviewerCommentsLabel, + SelfAssessment. Vocabulary, + SelfAssessment. NumberOfCompetencies, + SelfAssessment.StartedDate, + SelfAssessment.LastAccessed, + SelfAssessment.CompleteByDate, + SelfAssessment.CandidateAssessmentId, + SelfAssessment.UserBookmark, + SelfAssessment.UnprocessedUpdates, + SelfAssessment.LaunchCount, + SelfAssessment. IsSelfAssessment, + SelfAssessment.SubmittedDate, + SelfAssessment. CentreName, + SelfAssessment.EnrolmentMethodId, + Signoff.SignedOff, + Signoff.Verified, + EnrolledByForename +' '+EnrolledBySurname AS EnrolledByFullName + FROM (SELECT + CA.SelfAssessmentID AS Id, + SA.Name, + SA.Description, + SA.IncludesSignposting, + SA.IncludeRequirementsFilters, + SA.SupervisorResultsReview AS IsSupervisorResultsReviewed, + SA.ReviewerCommentsLabel, + COALESCE(SA.Vocabulary, 'Capability') AS Vocabulary, + COUNT(C.ID) AS NumberOfCompetencies, + CA.StartedDate, + CA.LastAccessed, + CA.CompleteByDate, + CA.ID AS CandidateAssessmentId, + CA.UserBookmark, + CA.UnprocessedUpdates, + CA.LaunchCount, + 1 AS IsSelfAssessment, + CA.SubmittedDate, + CR.CentreName AS CentreName, + CA.EnrolmentMethodId, + uEnrolledBy.FirstName AS EnrolledByForename, + uEnrolledBy.LastName AS EnrolledBySurname + FROM Centres AS CR INNER JOIN + CandidateAssessments AS CA INNER JOIN + SelfAssessments AS SA ON CA.SelfAssessmentID = SA.ID ON CR.CentreID = CA.CentreID INNER JOIN + CentreSelfAssessments AS csa ON csa.SelfAssessmentID = SA.ID AND csa.CentreID = @centreId LEFT OUTER JOIN + Competencies AS C RIGHT OUTER JOIN + SelfAssessmentStructure AS SAS ON C.ID = SAS.CompetencyID ON CA.SelfAssessmentID = SAS.SelfAssessmentID LEFT OUTER JOIN + CandidateAssessmentSupervisors AS cas ON ca.ID =cas.CandidateAssessmentID LEFT OUTER JOIN + CandidateAssessmentSupervisorVerifications AS casv ON casv.CandidateAssessmentSupervisorID = cas.ID LEFT OUTER JOIN + AdminAccounts AS aaEnrolledBy ON aaEnrolledBy.ID = CA.EnrolledByAdminID LEFT OUTER JOIN + Users AS uEnrolledBy ON uEnrolledBy.ID = aaEnrolledBy.UserID + WHERE (CA.DelegateUserID = @delegateUserId) AND (CA.RemovedDate IS NULL) AND (CA.CompletedDate IS NULL) + AND (ISNULL(@adminIdCategoryID, 0) = 0 OR sa.CategoryID = @adminIdCategoryId) + GROUP BY + CA.SelfAssessmentID, SA.Name, SA.Description, SA.IncludesSignposting, SA.SupervisorResultsReview, + SA.ReviewerCommentsLabel, SA.IncludeRequirementsFilters, + COALESCE(SA.Vocabulary, 'Capability'), CA.StartedDate, CA.LastAccessed, CA.CompleteByDate, + CA.ID, + CA.UserBookmark, CA.UnprocessedUpdates, CA.LaunchCount, CA.SubmittedDate, CR.CentreName,CA.EnrolmentMethodId, + uEnrolledBy.FirstName,uEnrolledBy.LastName)SelfAssessment LEFT OUTER JOIN + (SELECT SelfAssessmentID,casv.SignedOff,MAX(casv.Verified) Verified FROM + CandidateAssessments AS CA LEFT OUTER JOIN + CandidateAssessmentSupervisors AS cas ON ca.ID =cas.CandidateAssessmentID LEFT OUTER JOIN + CandidateAssessmentSupervisorVerifications AS casv ON casv.CandidateAssessmentSupervisorID = cas.ID + WHERE (CA.DelegateUserID = @delegateUserId) AND (CA.RemovedDate IS NULL) AND (CA.CompletedDate IS NULL) AND (casv.SignedOff = 1) AND + (casv.Verified IS NOT NULL) + GROUP BY SelfAssessmentID,casv.SignedOff + )Signoff ON SelfAssessment.Id =Signoff.SelfAssessmentID", + new { delegateUserId, centreId, adminIdCategoryID } + ); + } public IEnumerable GetSelfAssessmentsForCandidate(int delegateUserId, int centreId) { return connection.Query( @@ -86,7 +165,6 @@ CandidateAssessments AS CA LEFT OUTER JOIN new { delegateUserId, centreId } ); } - public CurrentSelfAssessment? GetSelfAssessmentForCandidateById(int delegateUserId, int selfAssessmentId) { return connection.QueryFirstOrDefault( diff --git a/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs b/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs index e10185bf18..0528c7f907 100644 --- a/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs @@ -72,8 +72,8 @@ int competencyId // CandidateAssessmentsDataService + IEnumerable GetSelfAssessmentsForCandidate(int delegateUserId, int centreId, int? adminIdCategoryID); IEnumerable GetSelfAssessmentsForCandidate(int delegateUserId, int centreId); - CurrentSelfAssessment? GetSelfAssessmentForCandidateById(int delegateUserId, int selfAssessmentId); void UpdateLastAccessed(int selfAssessmentId, int delegateUserId); @@ -174,7 +174,6 @@ int GetSelfAssessmentActivityDelegatesExportCount(string searchString, string so bool HasMinimumOptionalCompetencies(int selfAssessmentId, int delegateUserId); int GetSelfAssessmentCategoryId(int selfAssessmentId); } - public partial class SelfAssessmentDataService : ISelfAssessmentDataService { private readonly IDbConnection connection; diff --git a/DigitalLearningSolutions.Web/Controllers/TrackingSystem/Delegates/ViewDelegateController.cs b/DigitalLearningSolutions.Web/Controllers/TrackingSystem/Delegates/ViewDelegateController.cs index 32589d77a9..22ca66bb84 100644 --- a/DigitalLearningSolutions.Web/Controllers/TrackingSystem/Delegates/ViewDelegateController.cs +++ b/DigitalLearningSolutions.Web/Controllers/TrackingSystem/Delegates/ViewDelegateController.cs @@ -83,7 +83,7 @@ public IActionResult Index(int delegateId, string? callType) } var selfAssessments = - selfAssessmentService.GetSelfAssessmentsForCandidate(delegateEntity.UserAccount.Id, centreId); + selfAssessmentService.GetSelfAssessmentsForCandidate(delegateEntity.UserAccount.Id, centreId, categoryIdFilter); foreach (var selfassessment in selfAssessments) { diff --git a/DigitalLearningSolutions.Web/Services/SelfAssessmentService.cs b/DigitalLearningSolutions.Web/Services/SelfAssessmentService.cs index 61e92bb72b..37b44e8e34 100644 --- a/DigitalLearningSolutions.Web/Services/SelfAssessmentService.cs +++ b/DigitalLearningSolutions.Web/Services/SelfAssessmentService.cs @@ -15,8 +15,8 @@ public interface ISelfAssessmentService //Self Assessments string? GetSelfAssessmentNameById(int selfAssessmentId); // Candidate Assessments + IEnumerable GetSelfAssessmentsForCandidate(int delegateUserId, int centreId, int? adminIdCategoryID); IEnumerable GetSelfAssessmentsForCandidate(int delegateUserId, int centreId); - CurrentSelfAssessment? GetSelfAssessmentForCandidateById(int delegateUserId, int selfAssessmentId); void SetBookmark(int selfAssessmentId, int delegateUserId, string bookmark); @@ -404,11 +404,14 @@ public IEnumerable GetCandidateAssessmentOptionalCompetencies(int se return selfAssessmentDataService.GetCandidateAssessmentOptionalCompetencies(selfAssessmentId, delegateUserId); } + public IEnumerable GetSelfAssessmentsForCandidate(int delegateUserId, int centreId, int? adminIdCategoryID) + { + return selfAssessmentDataService.GetSelfAssessmentsForCandidate(delegateUserId, centreId, adminIdCategoryID); + } public IEnumerable GetSelfAssessmentsForCandidate(int delegateUserId, int centreId) { return selfAssessmentDataService.GetSelfAssessmentsForCandidate(delegateUserId, centreId); } - public IEnumerable GetMostRecentResults(int selfAssessmentId, int delegateId) { return selfAssessmentDataService.GetMostRecentResults(selfAssessmentId, delegateId);