diff --git a/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/DCSAReportDataService.cs b/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/DCSAReportDataService.cs index ed3800215e..744580c411 100644 --- a/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/DCSAReportDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/DCSAReportDataService.cs @@ -1,128 +1,129 @@ -namespace DigitalLearningSolutions.Data.DataServices.SelfAssessmentDataService -{ - using Dapper; - using DigitalLearningSolutions.Data.Models.SelfAssessments.Export; - using Microsoft.Extensions.Logging; - using System.Collections.Generic; - using System.Data; - - public interface IDCSAReportDataService - { - IEnumerable GetDelegateCompletionStatusForCentre(int centreId); - IEnumerable GetOutcomeSummaryForCentre(int centreId); - } - public partial class DCSAReportDataService : IDCSAReportDataService - { - private readonly IDbConnection connection; - private readonly ILogger logger; - - public DCSAReportDataService(IDbConnection connection, ILogger logger) - { - this.connection = connection; - this.logger = logger; - } - - public IEnumerable GetDelegateCompletionStatusForCentre(int centreId) - { - return connection.Query( - @"SELECT DATEPART(month, ca.StartedDate) AS EnrolledMonth, DATEPART(yyyy, ca.StartedDate) AS EnrolledYear, u.FirstName, u.LastName, COALESCE (ucd.Email, u.PrimaryEmail) AS Email, da.Answer1 AS CentreField1, da.Answer2 AS CentreField2, da.Answer3 AS CentreField3, - CASE WHEN (ca.SubmittedDate IS NOT NULL) THEN 'Submitted' WHEN (ca.UserBookmark LIKE N'/LearningPortal/SelfAssessment/1/Review' AND ca.SubmittedDate IS NULL) THEN 'Reviewing' ELSE 'Incomplete' END AS Status - FROM CandidateAssessments AS ca INNER JOIN - DelegateAccounts AS da ON ca.DelegateUserID = da.UserID INNER JOIN - Users AS u ON da.UserID = u.ID LEFT OUTER JOIN - UserCentreDetails AS ucd ON da.CentreID = ucd.CentreID AND u.ID = ucd.UserID - WHERE (ca.SelfAssessmentID = 1) AND (da.CentreID = @centreId) AND (u.Active = 1) AND (da.Active = 1)", - new { centreId } - ); - } - - public IEnumerable GetOutcomeSummaryForCentre(int centreId) - { - return connection.Query( - @"SELECT DATEPART(month, ca.StartedDate) AS EnrolledMonth, DATEPART(yyyy, ca.StartedDate) AS EnrolledYear, jg.JobGroupName AS JobGroup, da.Answer1 AS CentreField1, da.Answer2 AS CentreField2, da.Answer3 AS CentreField3, CASE WHEN (ca.SubmittedDate IS NOT NULL) - THEN 'Submitted' WHEN (ca.UserBookmark LIKE N'/LearningPortal/SelfAssessment/1/Review' AND ca.SubmittedDate IS NULL) THEN 'Reviewing' ELSE 'Incomplete' END AS Status, - (SELECT COUNT(*) AS LearningLaunched - FROM CandidateAssessmentLearningLogItems AS calli INNER JOIN - LearningLogItems AS lli ON calli.LearningLogItemID = lli.LearningLogItemID - WHERE (NOT (lli.LearningResourceReferenceID IS NULL)) AND (calli.CandidateAssessmentID = ca.ID)) + - (SELECT COUNT(*) AS FilteredLearning - FROM FilteredLearningActivity AS fla - WHERE (CandidateId = da.ID)) AS LearningCompleted, - (SELECT COUNT(*) AS LearningLaunched - FROM CandidateAssessmentLearningLogItems AS calli INNER JOIN - LearningLogItems AS lli ON calli.LearningLogItemID = lli.LearningLogItemID - WHERE (NOT (lli.LearningResourceReferenceID IS NULL)) AND (calli.CandidateAssessmentID = ca.ID) AND (NOT (lli.CompletedDate IS NULL))) + - (SELECT COUNT(*) AS FilteredCompleted - FROM FilteredLearningActivity AS fla - WHERE (CandidateId = da.ID) AND (CompletedDate IS NOT NULL)) AS LearningCompleted, - (SELECT AVG(sar.Result) AS AvgConfidence - FROM SelfAssessmentResults AS sar INNER JOIN - Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN - SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID - WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 1) AND (sas.CompetencyGroupID = 1)) AS DataInformationAndContentConfidence, - (SELECT AVG(sar.Result) AS AvgConfidence - FROM SelfAssessmentResults AS sar INNER JOIN - Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN - SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID - WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 2) AND (sas.CompetencyGroupID = 1)) AS DataInformationAndContentRelevance, - (SELECT AVG(sar.Result) AS AvgConfidence - FROM SelfAssessmentResults AS sar INNER JOIN - Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN - SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID - WHERE (sar.AssessmentQuestionID = 1) AND (sas.CompetencyGroupID = 2)) AS TeachingLearningAndSelfDevelopmentConfidence, - (SELECT AVG(sar.Result) AS AvgConfidence - FROM SelfAssessmentResults AS sar INNER JOIN - Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN - SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID - WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 2) AND (sas.CompetencyGroupID = 2)) AS TeachingLearningAndSelfDevelopmentRelevance, - (SELECT AVG(sar.Result) AS AvgConfidence - FROM SelfAssessmentResults AS sar INNER JOIN - Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN - SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID - WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 1) AND (sas.CompetencyGroupID = 3)) AS CommunicationCollaborationAndParticipationConfidence, - (SELECT AVG(sar.Result) AS AvgConfidence - FROM SelfAssessmentResults AS sar INNER JOIN - Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN - SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID - WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 2) AND (sas.CompetencyGroupID = 3)) AS CommunicationCollaborationAndParticipationRelevance, - (SELECT AVG(sar.Result) AS AvgConfidence - FROM SelfAssessmentResults AS sar INNER JOIN - Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN - SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID - WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 1) AND (sas.CompetencyGroupID = 4)) AS TechnicalProficiencyConfidence, - (SELECT AVG(sar.Result) AS AvgConfidence - FROM SelfAssessmentResults AS sar INNER JOIN - Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN - SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID - WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 2) AND (sas.CompetencyGroupID = 4)) AS TechnicalProficiencyRelevance, - (SELECT AVG(sar.Result) AS AvgConfidence - FROM SelfAssessmentResults AS sar INNER JOIN - Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN - SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID - WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 1) AND (sas.CompetencyGroupID = 5)) AS CreationInnovationAndResearchConfidence, - (SELECT AVG(sar.Result) AS AvgConfidence - FROM SelfAssessmentResults AS sar INNER JOIN - Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN - SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID - WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 2) AND (sas.CompetencyGroupID = 5)) AS CreationInnovationAndResearchRelevance, - (SELECT AVG(sar.Result) AS AvgConfidence - FROM SelfAssessmentResults AS sar INNER JOIN - Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN - SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID - WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 1) AND (sas.CompetencyGroupID = 6)) AS DigitalIdentityWellbeingSafetyAndSecurityConfidence, - (SELECT AVG(sar.Result) AS AvgConfidence - FROM SelfAssessmentResults AS sar INNER JOIN - Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN - SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID - WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 2) AND (sas.CompetencyGroupID = 6)) AS DigitalIdentityWellbeingSafetyAndSecurityRelevance - FROM CandidateAssessments AS ca INNER JOIN - DelegateAccounts AS da ON ca.DelegateUserID = da.UserID INNER JOIN - Users AS u ON da.UserID = u.ID INNER JOIN - JobGroups AS jg ON u.JobGroupID = jg.JobGroupID - WHERE (ca.SelfAssessmentID = 1) AND (da.CentreID = @centreId) AND (u.Active = 1) AND (da.Active = 1)", - new { centreId } - ); - } - - } -} +namespace DigitalLearningSolutions.Data.DataServices.SelfAssessmentDataService +{ + using Dapper; + using DigitalLearningSolutions.Data.Models.SelfAssessments.Export; + using Microsoft.Extensions.Logging; + using System.Collections.Generic; + using System.Data; + + public interface IDCSAReportDataService + { + IEnumerable GetDelegateCompletionStatusForCentre(int centreId); + IEnumerable GetOutcomeSummaryForCentre(int centreId); + } + public partial class DCSAReportDataService : IDCSAReportDataService + { + private readonly IDbConnection connection; + private readonly ILogger logger; + + public DCSAReportDataService(IDbConnection connection, ILogger logger) + { + this.connection = connection; + this.logger = logger; + } + + public IEnumerable GetDelegateCompletionStatusForCentre(int centreId) + { + return connection.Query( + @"SELECT DATEPART(month, ca.StartedDate) AS EnrolledMonth, DATEPART(yyyy, ca.StartedDate) AS EnrolledYear, u.FirstName, u.LastName, COALESCE (ucd.Email, u.PrimaryEmail) AS Email, da.Answer1 AS RegistrationAnswer1, da.Answer2 AS RegistrationAnswer2, da.Answer3 AS RegistrationAnswer3, + da.Answer4 AS RegistrationAnswer4, da.Answer5 AS RegistrationAnswer5, da.Answer6 AS RegistrationAnswer6, CASE WHEN (ca.SubmittedDate IS NOT NULL) THEN 'Submitted' WHEN (ca.UserBookmark LIKE N'/LearningPortal/SelfAssessment/1/Review' AND ca.SubmittedDate IS NULL) THEN 'Reviewing' ELSE 'Incomplete' END AS Status + FROM CandidateAssessments AS ca INNER JOIN + DelegateAccounts AS da ON ca.DelegateUserID = da.UserID INNER JOIN + Users AS u ON da.UserID = u.ID LEFT OUTER JOIN + UserCentreDetails AS ucd ON da.CentreID = ucd.CentreID AND u.ID = ucd.UserID + WHERE (ca.SelfAssessmentID = 1) AND (da.CentreID = @centreId) AND (u.Active = 1) AND (da.Active = 1)", + new { centreId } + ); + } + + public IEnumerable GetOutcomeSummaryForCentre(int centreId) + { + return connection.Query( + @"SELECT DATEPART(month, ca.StartedDate) AS EnrolledMonth, DATEPART(yyyy, ca.StartedDate) AS EnrolledYear, jg.JobGroupName AS JobGroup, da.Answer1 AS RegistrationAnswer1, da.Answer2 AS RegistrationAnswer2, da.Answer3 AS RegistrationAnswer3, + da.Answer4 AS RegistrationAnswer4, da.Answer5 AS RegistrationAnswer5, da.Answer6 AS RegistrationAnswer6, CASE WHEN (ca.SubmittedDate IS NOT NULL) + THEN 'Submitted' WHEN (ca.UserBookmark LIKE N'/LearningPortal/SelfAssessment/1/Review' AND ca.SubmittedDate IS NULL) THEN 'Reviewing' ELSE 'Incomplete' END AS Status, + (SELECT COUNT(*) AS LearningLaunched + FROM CandidateAssessmentLearningLogItems AS calli INNER JOIN + LearningLogItems AS lli ON calli.LearningLogItemID = lli.LearningLogItemID + WHERE (NOT (lli.LearningResourceReferenceID IS NULL)) AND (calli.CandidateAssessmentID = ca.ID)) + + (SELECT COUNT(*) AS FilteredLearning + FROM FilteredLearningActivity AS fla + WHERE (CandidateId = da.ID)) AS LearningCompleted, + (SELECT COUNT(*) AS LearningLaunched + FROM CandidateAssessmentLearningLogItems AS calli INNER JOIN + LearningLogItems AS lli ON calli.LearningLogItemID = lli.LearningLogItemID + WHERE (NOT (lli.LearningResourceReferenceID IS NULL)) AND (calli.CandidateAssessmentID = ca.ID) AND (NOT (lli.CompletedDate IS NULL))) + + (SELECT COUNT(*) AS FilteredCompleted + FROM FilteredLearningActivity AS fla + WHERE (CandidateId = da.ID) AND (CompletedDate IS NOT NULL)) AS LearningCompleted, + (SELECT AVG(sar.Result) AS AvgConfidence + FROM SelfAssessmentResults AS sar INNER JOIN + Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN + SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID + WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 1) AND (sas.CompetencyGroupID = 1)) AS DataInformationAndContentConfidence, + (SELECT AVG(sar.Result) AS AvgConfidence + FROM SelfAssessmentResults AS sar INNER JOIN + Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN + SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID + WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 2) AND (sas.CompetencyGroupID = 1)) AS DataInformationAndContentRelevance, + (SELECT AVG(sar.Result) AS AvgConfidence + FROM SelfAssessmentResults AS sar INNER JOIN + Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN + SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID + WHERE (sar.AssessmentQuestionID = 1) AND (sas.CompetencyGroupID = 2)) AS TeachingLearningAndSelfDevelopmentConfidence, + (SELECT AVG(sar.Result) AS AvgConfidence + FROM SelfAssessmentResults AS sar INNER JOIN + Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN + SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID + WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 2) AND (sas.CompetencyGroupID = 2)) AS TeachingLearningAndSelfDevelopmentRelevance, + (SELECT AVG(sar.Result) AS AvgConfidence + FROM SelfAssessmentResults AS sar INNER JOIN + Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN + SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID + WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 1) AND (sas.CompetencyGroupID = 3)) AS CommunicationCollaborationAndParticipationConfidence, + (SELECT AVG(sar.Result) AS AvgConfidence + FROM SelfAssessmentResults AS sar INNER JOIN + Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN + SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID + WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 2) AND (sas.CompetencyGroupID = 3)) AS CommunicationCollaborationAndParticipationRelevance, + (SELECT AVG(sar.Result) AS AvgConfidence + FROM SelfAssessmentResults AS sar INNER JOIN + Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN + SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID + WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 1) AND (sas.CompetencyGroupID = 4)) AS TechnicalProficiencyConfidence, + (SELECT AVG(sar.Result) AS AvgConfidence + FROM SelfAssessmentResults AS sar INNER JOIN + Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN + SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID + WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 2) AND (sas.CompetencyGroupID = 4)) AS TechnicalProficiencyRelevance, + (SELECT AVG(sar.Result) AS AvgConfidence + FROM SelfAssessmentResults AS sar INNER JOIN + Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN + SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID + WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 1) AND (sas.CompetencyGroupID = 5)) AS CreationInnovationAndResearchConfidence, + (SELECT AVG(sar.Result) AS AvgConfidence + FROM SelfAssessmentResults AS sar INNER JOIN + Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN + SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID + WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 2) AND (sas.CompetencyGroupID = 5)) AS CreationInnovationAndResearchRelevance, + (SELECT AVG(sar.Result) AS AvgConfidence + FROM SelfAssessmentResults AS sar INNER JOIN + Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN + SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID + WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 1) AND (sas.CompetencyGroupID = 6)) AS DigitalIdentityWellbeingSafetyAndSecurityConfidence, + (SELECT AVG(sar.Result) AS AvgConfidence + FROM SelfAssessmentResults AS sar INNER JOIN + Competencies AS co ON sar.CompetencyID = co.ID INNER JOIN + SelfAssessmentStructure AS sas ON co.ID = sas.CompetencyID + WHERE (sar.DelegateUserID = da.UserID) AND (sar.AssessmentQuestionID = 2) AND (sas.CompetencyGroupID = 6)) AS DigitalIdentityWellbeingSafetyAndSecurityRelevance + FROM CandidateAssessments AS ca INNER JOIN + DelegateAccounts AS da ON ca.DelegateUserID = da.UserID INNER JOIN + Users AS u ON da.UserID = u.ID INNER JOIN + JobGroups AS jg ON u.JobGroupID = jg.JobGroupID + WHERE (ca.SelfAssessmentID = 1) AND (da.CentreID = @centreId) AND (u.Active = 1) AND (da.Active = 1)", + new { centreId } + ); + } + + } +} diff --git a/DigitalLearningSolutions.Data/Models/SelfAssessments/Export/DCSADelegateCompletionStatus.cs b/DigitalLearningSolutions.Data/Models/SelfAssessments/Export/DCSADelegateCompletionStatus.cs index 31a69d5bc1..ee33332727 100644 --- a/DigitalLearningSolutions.Data/Models/SelfAssessments/Export/DCSADelegateCompletionStatus.cs +++ b/DigitalLearningSolutions.Data/Models/SelfAssessments/Export/DCSADelegateCompletionStatus.cs @@ -1,16 +1,31 @@ -namespace DigitalLearningSolutions.Data.Models.SelfAssessments.Export -{ - using System; - public class DCSADelegateCompletionStatus - { - public int? EnrolledMonth { get; set; } - public int? EnrolledYear { get; set; } - public string? FirstName { get; set; } - public string? LastName { get; set; } - public string? Email { get; set; } - public string? CentreField1 { get; set; } - public string? CentreField2 { get; set; } - public string? CentreField3 { get; set; } - public string? Status { get; set; } - } -} +namespace DigitalLearningSolutions.Data.Models.SelfAssessments.Export +{ + using System; + public class DCSADelegateCompletionStatus + { + public int? EnrolledMonth { get; set; } + public int? EnrolledYear { get; set; } + public string? FirstName { get; set; } + public string? LastName { get; set; } + public string? Email { get; set; } + public string? RegistrationAnswer1 { get; set; } + public string? RegistrationAnswer2 { get; set; } + public string? RegistrationAnswer3 { get; set; } + public string? RegistrationAnswer4 { get; set; } + public string? RegistrationAnswer5 { get; set; } + public string? RegistrationAnswer6 { get; set; } + public string? Status { get; set; } + + + public string?[] CentreRegistrationPrompts => + new[] + { + RegistrationAnswer1, + RegistrationAnswer2, + RegistrationAnswer3, + RegistrationAnswer4, + RegistrationAnswer5, + RegistrationAnswer6, + }; + } +} diff --git a/DigitalLearningSolutions.Data/Models/SelfAssessments/Export/DCSAOutcomeSummary.cs b/DigitalLearningSolutions.Data/Models/SelfAssessments/Export/DCSAOutcomeSummary.cs index adac779073..673130a83f 100644 --- a/DigitalLearningSolutions.Data/Models/SelfAssessments/Export/DCSAOutcomeSummary.cs +++ b/DigitalLearningSolutions.Data/Models/SelfAssessments/Export/DCSAOutcomeSummary.cs @@ -1,28 +1,42 @@ -namespace DigitalLearningSolutions.Data.Models.SelfAssessments.Export -{ - using System; - public class DCSAOutcomeSummary - { - public int? EnrolledMonth { get; set; } - public int? EnrolledYear { get; set; } - public string? JobGroup { get; set; } - public string? CentreField1 { get; set; } - public string? CentreField2 { get; set; } - public string? CentreField3 { get; set; } - public string? Status { get; set; } - public int? LearningLaunched { get; set; } - public int? LearningCompleted { get; set; } - public int? DataInformationAndContentConfidence { get; set; } - public int? DataInformationAndContentRelevance { get; set; } - public int? TeachinglearningAndSelfDevelopmentConfidence { get; set; } - public int? TeachinglearningAndSelfDevelopmentRelevance { get; set; } - public int? CommunicationCollaborationAndParticipationConfidence { get; set; } - public int? CommunicationCollaborationAndParticipationRelevance { get; set; } - public int? TechnicalProficiencyConfidence { get; set; } - public int? TechnicalProficiencyRelevance { get; set; } - public int? CreationInnovationAndResearchConfidence { get; set; } - public int? CreationInnovationAndResearchRelevance { get; set; } - public int? DigitalIdentityWellbeingSafetyAndSecurityConfidence { get; set; } - public int? DigitalIdentityWellbeingSafetyAndSecurityRelevance { get; set; } - } -} +namespace DigitalLearningSolutions.Data.Models.SelfAssessments.Export +{ + using System; + public class DCSAOutcomeSummary + { + public int? EnrolledMonth { get; set; } + public int? EnrolledYear { get; set; } + public string? JobGroup { get; set; } + public string? RegistrationAnswer1 { get; set; } + public string? RegistrationAnswer2 { get; set; } + public string? RegistrationAnswer3 { get; set; } + public string? RegistrationAnswer4 { get; set; } + public string? RegistrationAnswer5 { get; set; } + public string? RegistrationAnswer6 { get; set; } + public string? Status { get; set; } + public int? LearningLaunched { get; set; } + public int? LearningCompleted { get; set; } + public int? DataInformationAndContentConfidence { get; set; } + public int? DataInformationAndContentRelevance { get; set; } + public int? TeachinglearningAndSelfDevelopmentConfidence { get; set; } + public int? TeachinglearningAndSelfDevelopmentRelevance { get; set; } + public int? CommunicationCollaborationAndParticipationConfidence { get; set; } + public int? CommunicationCollaborationAndParticipationRelevance { get; set; } + public int? TechnicalProficiencyConfidence { get; set; } + public int? TechnicalProficiencyRelevance { get; set; } + public int? CreationInnovationAndResearchConfidence { get; set; } + public int? CreationInnovationAndResearchRelevance { get; set; } + public int? DigitalIdentityWellbeingSafetyAndSecurityConfidence { get; set; } + public int? DigitalIdentityWellbeingSafetyAndSecurityRelevance { get; set; } + + public string?[] CentreRegistrationPrompts => + new[] + { + RegistrationAnswer1, + RegistrationAnswer2, + RegistrationAnswer3, + RegistrationAnswer4, + RegistrationAnswer5, + RegistrationAnswer6, + }; + } +} diff --git a/DigitalLearningSolutions.Web/Services/SelfAssessmentReportService.cs b/DigitalLearningSolutions.Web/Services/SelfAssessmentReportService.cs index 33c7c71160..aff36d83f9 100644 --- a/DigitalLearningSolutions.Web/Services/SelfAssessmentReportService.cs +++ b/DigitalLearningSolutions.Web/Services/SelfAssessmentReportService.cs @@ -36,6 +36,28 @@ public class SelfAssessmentReportService : ISelfAssessmentReportService private const string SignOffRequested = "SignOffRequested"; private const string SignOffAchieved = "SignOffAchieved"; private const string ReviewedDate = "ReviewedDate"; + private const string EnrolledMonth = "EnrolledMonth"; + private const string EnrolledYear = "EnrolledYear"; + private const string FirstName = "FirstName"; + private const string LastName = "LastName"; + private const string Email = "Email"; + private const string Status = "Status"; + private const string LearningLaunched = "LearningLaunched"; + private const string LearningCompleted = "LearningCompleted"; + private const string DataInformationAndContentConfidence = "DataInformationAndContentConfidence"; + private const string DataInformationAndContentRelevance = "DataInformationAndContentRelevance"; + private const string TeachinglearningAndSelfDevelopmentConfidence = "TeachinglearningAndSelfDevelopmentConfidence"; + private const string TeachinglearningAndSelfDevelopmentRelevance = "TeachinglearningAndSelfDevelopmentRelevance"; + private const string CommunicationCollaborationAndParticipationConfidence = "CommunicationCollaborationAndParticipationConfidence"; + private const string CommunicationCollaborationAndParticipationRelevance = "CommunicationCollaborationAndParticipationRelevance"; + private const string TechnicalProficiencyConfidence = "TechnicalProficiencyConfidence"; + private const string TechnicalProficiencyRelevance = "TechnicalProficiencyRelevance"; + private const string CreationInnovationAndResearchConfidence = "CreationInnovationAndResearchConfidence"; + private const string CreationInnovationAndResearchRelevance = "CreationInnovationAndResearchRelevance"; + private const string DigitalIdentityWellbeingSafetyAndSecurityConfidence = "DigitalIdentityWellbeingSafetyAndSecurityConfidence"; + private const string DigitalIdentityWellbeingSafetyAndSecurityRelevance = "DigitalIdentityWellbeingSafetyAndSecurityRelevance"; + + private readonly IDCSAReportDataService dcsaReportDataService; private readonly ISelfAssessmentReportDataService selfAssessmentReportDataService; @@ -66,39 +88,46 @@ public IEnumerable GetSelfAssessmentsForReportList(int cen public byte[] GetSelfAssessmentExcelExportForCentre(int centreId, int selfAssessmentId) { using var workbook = new XLWorkbook(); - var selfAssessmentReportData = selfAssessmentReportDataService.GetSelfAssessmentReportDataForCentre(centreId, selfAssessmentId); - PopulateSelfAssessmentSheetForCentre(workbook, centreId, selfAssessmentReportData); + var selfAssessmentReportData = selfAssessmentReportDataService.GetSelfAssessmentReportDataForCentre(centreId, selfAssessmentId); + PopulateSelfAssessmentSheetForCentre(workbook, centreId, selfAssessmentReportData); using var stream = new MemoryStream(); workbook.SaveAs(stream); return stream.ToArray(); } public byte[] GetDigitalCapabilityExcelExportForCentre(int centreId) { - var delegateCompletionStatus = dcsaReportDataService.GetDelegateCompletionStatusForCentre(centreId); + + using var workbook = new XLWorkbook(); + GetDelegateCompletionStatusForCentre(workbook, centreId); + GetOutcomeSummaryForCentre(workbook, centreId); + using var stream = new MemoryStream(); + workbook.SaveAs(stream); + return stream.ToArray(); + } + + private void GetOutcomeSummaryForCentre(XLWorkbook workbook, int centreId) + { var outcomeSummary = dcsaReportDataService.GetOutcomeSummaryForCentre(centreId); - var summary = delegateCompletionStatus.Select( - x => new - { - x.EnrolledMonth, - x.EnrolledYear, - x.FirstName, - x.LastName, - Email = (Guid.TryParse(x.Email, out _) ? string.Empty : x.Email), - x.CentreField1, - x.CentreField2, - x.CentreField3, - x.Status - } - ); + + var sheet = workbook.Worksheets.Add("Assessment Outcome Summary"); + // Set sheet to have outlining expand buttons at the top of the expanded section. + sheet.Outline.SummaryVLocation = XLOutlineSummaryVLocation.Top; + var customRegistrationPrompts = + registrationPromptsService.GetCentreRegistrationPromptsByCentreId(centreId); + var dataTable = new DataTable(); + var details = outcomeSummary.Select( x => new { x.EnrolledMonth, x.EnrolledYear, x.JobGroup, - x.CentreField1, - x.CentreField2, - x.CentreField3, + x.RegistrationAnswer1, + x.RegistrationAnswer2, + x.RegistrationAnswer3, + x.RegistrationAnswer4, + x.RegistrationAnswer5, + x.RegistrationAnswer6, x.Status, x.LearningLaunched, x.LearningCompleted, @@ -115,13 +144,167 @@ public byte[] GetDigitalCapabilityExcelExportForCentre(int centreId) x.DigitalIdentityWellbeingSafetyAndSecurityConfidence, x.DigitalIdentityWellbeingSafetyAndSecurityRelevance } + ); + + // set the common header table for the excel sheet + SetUpCommonTableColumnsForOutcomeSummary(customRegistrationPrompts, dataTable); + + // insert the header table into the sheet starting at the first position + var headerTable = sheet.Cell(1, 1).InsertTable(dataTable); + + foreach (var report in outcomeSummary) + { + //iterate and add every record from the query to the datatable + AddOutcomeSummaryReportToSheet(sheet, dataTable, customRegistrationPrompts, report); + } + + var insertedDataRange = sheet.Cell(GetNextEmptyRowNumber(sheet), 1).InsertData(dataTable.Rows); + if (dataTable.Rows.Count > 0) + { + sheet.Rows(insertedDataRange.FirstRow().RowNumber(), insertedDataRange.LastRow().RowNumber()) + .Group(true); + } + + //format the sheet rows and content + sheet.Rows().Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + headerTable.Theme = XLTableTheme.TableStyleLight9; + + sheet.Columns().AdjustToContents(); + + + } + + private void AddOutcomeSummaryReportToSheet(IXLWorksheet sheet, DataTable dataTable, CentreRegistrationPrompts customRegistrationPrompts, DCSAOutcomeSummary report) + { + var row = dataTable.NewRow(); + row[EnrolledMonth] = report.EnrolledMonth; + row[EnrolledYear] = report.EnrolledYear; + row[JobGroup] = report.JobGroup; + + // map the individual registration fields with the centre registration custom prompts + foreach (var prompt in customRegistrationPrompts.CustomPrompts) + { + if (dataTable.Columns.Contains($"{prompt.PromptText} (Prompt {prompt.RegistrationField.Id})")) + { + row[$"{prompt.PromptText} (Prompt {prompt.RegistrationField.Id})"] = + report.CentreRegistrationPrompts[prompt.RegistrationField.Id - 1]; + } + else + { + row[prompt.PromptText] = + report.CentreRegistrationPrompts[prompt.RegistrationField.Id - 1]; + } + } + row[Status] = report.Status; + row[LearningLaunched] = report.LearningLaunched; + row[LearningCompleted] = report.LearningCompleted; + row[DataInformationAndContentConfidence] = report.DataInformationAndContentConfidence; + row[DataInformationAndContentRelevance] = report.DataInformationAndContentRelevance; + row[TeachinglearningAndSelfDevelopmentConfidence] = report.TeachinglearningAndSelfDevelopmentConfidence; + row[TeachinglearningAndSelfDevelopmentRelevance] = report.TeachinglearningAndSelfDevelopmentRelevance; + row[CommunicationCollaborationAndParticipationConfidence] = report.CommunicationCollaborationAndParticipationConfidence; + row[CommunicationCollaborationAndParticipationRelevance] = report.CommunicationCollaborationAndParticipationRelevance; + row[TechnicalProficiencyConfidence] = report.TechnicalProficiencyConfidence; + row[TechnicalProficiencyRelevance] = report.TechnicalProficiencyRelevance; + row[CreationInnovationAndResearchConfidence] = report.CreationInnovationAndResearchConfidence; + row[CreationInnovationAndResearchRelevance] = report.CreationInnovationAndResearchRelevance; + row[DigitalIdentityWellbeingSafetyAndSecurityConfidence] = report.DigitalIdentityWellbeingSafetyAndSecurityConfidence; + row[DigitalIdentityWellbeingSafetyAndSecurityRelevance] = report.DigitalIdentityWellbeingSafetyAndSecurityRelevance; + dataTable.Rows.Add(row); + } + + private void SetUpCommonTableColumnsForOutcomeSummary(CentreRegistrationPrompts customRegistrationPrompts, DataTable dataTable) + { + dataTable.Columns.AddRange( + new[] { + new DataColumn(EnrolledMonth), new DataColumn(EnrolledYear), new DataColumn(JobGroup) + } + ); + + foreach (var prompt in customRegistrationPrompts.CustomPrompts) + { + dataTable.Columns.Add( + !dataTable.Columns.Contains(prompt.PromptText) + ? prompt.PromptText + : $"{prompt.PromptText} (Prompt {prompt.RegistrationField.Id})" ); - using var workbook = new XLWorkbook(); - AddSheetToWorkbook(workbook, "Delegate Completion Status", summary); - AddSheetToWorkbook(workbook, "Assessment Outcome Summary", outcomeSummary); - using var stream = new MemoryStream(); - workbook.SaveAs(stream); - return stream.ToArray(); + } + + dataTable.Columns.AddRange( + new[] + { + new DataColumn(Status), new DataColumn(LearningLaunched),new DataColumn(LearningCompleted),new DataColumn(DataInformationAndContentConfidence), + new DataColumn(DataInformationAndContentRelevance), new DataColumn(TeachinglearningAndSelfDevelopmentConfidence), + new DataColumn(TeachinglearningAndSelfDevelopmentRelevance),new DataColumn(CommunicationCollaborationAndParticipationConfidence), + new DataColumn(CommunicationCollaborationAndParticipationRelevance), + new DataColumn(TechnicalProficiencyConfidence), + new DataColumn(TechnicalProficiencyRelevance), + new DataColumn(CreationInnovationAndResearchConfidence), + new DataColumn(CreationInnovationAndResearchRelevance), + new DataColumn(DigitalIdentityWellbeingSafetyAndSecurityConfidence), + new DataColumn(DigitalIdentityWellbeingSafetyAndSecurityRelevance) + } + ); + } + + private void GetDelegateCompletionStatusForCentre(XLWorkbook workbook, int centreId) + { + + var delegateCompletionStatus = dcsaReportDataService.GetDelegateCompletionStatusForCentre(centreId); + + var sheet = workbook.Worksheets.Add("Delegate Completion Status"); + // Set sheet to have outlining expand buttons at the top of the expanded section. + sheet.Outline.SummaryVLocation = XLOutlineSummaryVLocation.Top; + var customRegistrationPrompts = + registrationPromptsService.GetCentreRegistrationPromptsByCentreId(centreId); + var dataTable = new DataTable(); + + // did this to sequqence the element into a new form based on the order below + var summary = delegateCompletionStatus.Select( + x => new + { + x.EnrolledMonth, + x.EnrolledYear, + x.FirstName, + x.LastName, + Email = (Guid.TryParse(x.Email, out _) ? string.Empty : x.Email), + x.RegistrationAnswer1, + x.RegistrationAnswer2, + x.RegistrationAnswer3, + x.RegistrationAnswer4, + x.RegistrationAnswer5, + x.RegistrationAnswer6, + x.Status + } + + ); + + // set the common header table for the excel sheet + SetUpCommonTableColumnsForDelegateCompletion(customRegistrationPrompts, dataTable); + + // insert the header table into the sheet starting at the first position + var headerTable = sheet.Cell(1, 1).InsertTable(dataTable); + + foreach (var report in delegateCompletionStatus) + { + //iterate and add every record from the query to the datatable + AddDelegateCompletionReportToSheet(sheet, dataTable, customRegistrationPrompts, report); + } + + var insertedDataRange = sheet.Cell(GetNextEmptyRowNumber(sheet), 1).InsertData(dataTable.Rows); + if (dataTable.Rows.Count > 0) + { + sheet.Rows(insertedDataRange.FirstRow().RowNumber(), insertedDataRange.LastRow().RowNumber()) + .Group(true); + } + + //format the sheet rows and content + sheet.Rows().Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + headerTable.Theme = XLTableTheme.TableStyleLight9; + + sheet.Columns().AdjustToContents(); + + } private void PopulateSelfAssessmentSheetForCentre(IXLWorkbook workbook, int centreId, IEnumerable selfAssessmentReportData) @@ -215,9 +398,32 @@ private static void SetUpCommonTableColumnsForSelfAssessment(CentreRegistrationP ); } + private static void SetUpCommonTableColumnsForDelegateCompletion(CentreRegistrationPrompts centreRegistrationPrompts, DataTable dataTable) + { + dataTable.Columns.AddRange( + new[] {new DataColumn(EnrolledMonth), new DataColumn(EnrolledYear), new DataColumn(FirstName), new DataColumn(LastName), + new DataColumn(Email)} + ); + foreach (var prompt in centreRegistrationPrompts.CustomPrompts) + { + dataTable.Columns.Add( + !dataTable.Columns.Contains(prompt.PromptText) + ? prompt.PromptText + : $"{prompt.PromptText} (Prompt {prompt.RegistrationField.Id})" + ); + } + + dataTable.Columns.AddRange( + new[] + { + new DataColumn(Status) + } + ); + } + private static void AddSelfAssessmentReportToSheet(IXLWorksheet sheet, DataTable dataTable, CentreRegistrationPrompts centreRegistrationPrompts, SelfAssessmentReportData report) - { + { var row = dataTable.NewRow(); row[SelfAssessment] = report.SelfAssessment; row[Learner] = report.Learner; @@ -253,6 +459,34 @@ private static void AddSelfAssessmentReportToSheet(IXLWorksheet sheet, DataTable dataTable.Rows.Add(row); } + private static void AddDelegateCompletionReportToSheet(IXLWorksheet sheet, DataTable dataTable, CentreRegistrationPrompts centreRegistrationPrompts, + DCSADelegateCompletionStatus report) + { + var row = dataTable.NewRow(); + row[EnrolledMonth] = report.EnrolledMonth; + row[EnrolledYear] = report.EnrolledYear; + row[FirstName] = report.FirstName; + row[LastName] = report.LastName; + row[Email] = report.Email; + + // map the individual registration fields with the centre registration custom prompts + foreach (var prompt in centreRegistrationPrompts.CustomPrompts) + { + if (dataTable.Columns.Contains($"{prompt.PromptText} (Prompt {prompt.RegistrationField.Id})")) + { + row[$"{prompt.PromptText} (Prompt {prompt.RegistrationField.Id})"] = + report.CentreRegistrationPrompts[prompt.RegistrationField.Id - 1]; + } + else + { + row[prompt.PromptText] = + report.CentreRegistrationPrompts[prompt.RegistrationField.Id - 1]; + } + } + row[Status] = report.Status; + dataTable.Rows.Add(row); + } + private static int GetNextEmptyRowNumber(IXLWorksheet sheet) { return sheet.LastRowUsed().RowNumber() + 1;