Skip to content
Closed

Td 4697 #2844

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
namespace DigitalLearningSolutions.Data.DataServices.SelfAssessmentDataService
{
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Dapper;
using DigitalLearningSolutions.Data.Models.Common.Users;
using DigitalLearningSolutions.Data.Models.External.Filtered;
using DigitalLearningSolutions.Data.Models.Frameworks;
using DigitalLearningSolutions.Data.Models.SelfAssessments;
using DigitalLearningSolutions.Data.Models.SelfAssessments.Export;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;

public interface ISelfAssessmentDataService
{
Expand Down Expand Up @@ -171,6 +171,7 @@ int GetSelfAssessmentActivityDelegatesExportCount(string searchString, string so
ActivitySummaryCompetencySelfAssesment? GetActivitySummaryCompetencySelfAssesment(int CandidateAssessmentSupervisorVerificationsId);
bool IsUnsupervisedSelfAssessment(int selfAssessmentId);
bool IsCentreSelfAssessment(int selfAssessmentId, int centreId);
bool HasMinimumOptionalCompetencies(int selfAssessmentId, int delegateUserId);
}

public partial class SelfAssessmentDataService : ISelfAssessmentDataService
Expand Down Expand Up @@ -729,5 +730,24 @@ public bool IsCentreSelfAssessment(int selfAssessmentId, int centreId)
);
return ResultCount > 0;
}

public bool HasMinimumOptionalCompetencies(int selfAssessmentId, int delegateUserId)
{
return connection.ExecuteScalar<bool>(
@"SELECT CASE WHEN COUNT(SAS.ID)>=(SELECT MinimumOptionalCompetencies FROM SelfAssessments WHERE ID = @selfAssessmentId)
THEN 1 ELSE 0 END AS HasMinimumOptionalCompetencies
FROM CandidateAssessmentOptionalCompetencies AS CAOC
INNER JOIN CandidateAssessments AS CA
ON CAOC.CandidateAssessmentID = CA.ID AND CA.SelfAssessmentID = @selfAssessmentId
AND CA.DelegateUserID = @delegateUserId AND CA.RemovedDate IS NULL
INNER JOIN SelfAssessmentStructure AS SAS
ON CAOC.CompetencyID = SAS.CompetencyID AND CAOC.CompetencyGroupID = SAS.CompetencyGroupID
AND SAS.SelfAssessmentID = @selfAssessmentId
INNER JOIN SelfAssessments AS SA
ON SAS.SelfAssessmentID = SA.ID
WHERE (CAOC.IncludedInSelfAssessment = 1)",
new { selfAssessmentId, delegateUserId }
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
namespace DigitalLearningSolutions.Web.Controllers.LearningPortalController
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.Json;
using System.Threading.Tasks;
using DigitalLearningSolutions.Data.Enums;
using DigitalLearningSolutions.Data.Helpers;
using DigitalLearningSolutions.Data.Models.Centres;
using DigitalLearningSolutions.Data.Models.Common;
using DigitalLearningSolutions.Data.Models.SearchSortFilterPaginate;
using DigitalLearningSolutions.Data.Models.SelfAssessments;
using DigitalLearningSolutions.Data.Models.SessionData.SelfAssessments;
Expand All @@ -19,19 +15,19 @@
using DigitalLearningSolutions.Web.ViewModels.Common.SearchablePage;
using DigitalLearningSolutions.Web.ViewModels.LearningPortal.Current;
using DigitalLearningSolutions.Web.ViewModels.LearningPortal.SelfAssessments;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using GDS.MultiPageFormData.Enums;
using DigitalLearningSolutions.Data.Helpers;
using DigitalLearningSolutions.Web.Services;
using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Delegates.ViewDelegate;
using DocumentFormat.OpenXml.EMMA;
using DigitalLearningSolutions.Data.Models.Supervisor;
using DigitalLearningSolutions.Data.Models.Common;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.Json;
using System.Threading.Tasks;

public partial class LearningPortalController
{
Expand Down Expand Up @@ -426,6 +422,55 @@ public IActionResult AddSelfAssessmentOverviewFilter(SearchSelfAssessmentOvervie
return RedirectToAction("FilteredSelfAssessmentGroups", model);
}

[ServiceFilter(typeof(IsCentreAuthorizedSelfAssessment))]
[Route("LearningPortal/SelfAssessment/{selfAssessmentId}/{vocabulary}/AddOptional")]
public IActionResult AddOptionalCompetencies(int selfAssessmentId, string vocabulary)
{
var delegateUserId = User.GetUserIdKnownNotNull();
var assessment = selfAssessmentService.GetSelfAssessmentForCandidateById(delegateUserId, selfAssessmentId);
if (assessment == null)
{
logger.LogWarning(
$"Attempt to display self assessment overview for user {delegateUserId} with no self assessment"
);
return RedirectToAction("StatusCode", "LearningSolutions", new { code = 403 });
}

var optionalCompetencies = selfAssessmentService.GetCandidateAssessmentOptionalCompetencies(selfAssessmentId, delegateUserId);
if (optionalCompetencies.Any())
{
if (!selfAssessmentService.HasMinimumOptionalCompetencies(selfAssessmentId, delegateUserId))
{
var model = new AddOptionalCompetenciesViewModel { SelfAssessment = assessment };
return View("SelfAssessments/AddOptionalCompetencies", model);
}
}

return RedirectToAction("SelfAssessmentOverview", new { selfAssessmentId, vocabulary });
}

[HttpPost]
[Route("LearningPortal/SelfAssessment/{selfAssessmentId}/{vocabulary}/AddOptional")]
public IActionResult AddOptionalCompetencies(AddOptionalCompetenciesViewModel test)
{
//var delegateUserId = User.GetUserIdKnownNotNull();
//var selfAssessmentId = test.SelfAssessment.Id;
//var vocabulary = test.VocabPlural().ToString();

//var assessment = selfAssessmentService.GetSelfAssessmentForCandidateById(delegateUserId, test.SelfAssessment.Id);
//if (assessment == null)
//{
// logger.LogWarning(
// $"Attempt to display self assessment overview for user {delegateUserId} with no self assessment"
// );
// return RedirectToAction("StatusCode", "LearningSolutions", new { code = 403 });
//}
var a = 1;
var b = "2";

return RedirectToAction("SelfAssessmentOverview", new { a, b });
}

[ServiceFilter(typeof(IsCentreAuthorizedSelfAssessment))]
[Route("LearningPortal/SelfAssessment/{selfAssessmentId}/{vocabulary}/{competencyGroupId}")]
[Route("LearningPortal/SelfAssessment/{selfAssessmentId}/{vocabulary}")]
Expand Down Expand Up @@ -479,7 +524,7 @@ public IActionResult SelfAssessmentOverview(int selfAssessmentId, string vocabul
CompetencyGroups = competencies.GroupBy(competency => competency.CompetencyGroup),
PreviousCompetencyNumber = Math.Max(competencies.Count(), 1),
NumberOfOptionalCompetencies = optionalCompetencies.Count(),
NumberOfSelfAssessedOptionalCompetencies = optionalCompetencies.Count(x => x.IncludedInSelfAssessment ) ,
NumberOfSelfAssessedOptionalCompetencies = optionalCompetencies.Count(x => x.IncludedInSelfAssessment),
SupervisorSignOffs = supervisorSignOffs,
SearchViewModel = searchViewModel
};
Expand All @@ -495,6 +540,7 @@ public IActionResult SelfAssessmentOverview(int selfAssessmentId, string vocabul
ViewBag.SupervisorSelfAssessmentReview = assessment.SupervisorSelfAssessmentReview;
return View("SelfAssessments/SelfAssessmentOverview", model);
}

[HttpPost]
[ServiceFilter(typeof(IsCentreAuthorizedSelfAssessment))]
[SetDlsSubApplication(nameof(DlsSubApplication.LearningPortal))]
Expand Down Expand Up @@ -1440,8 +1486,9 @@ public IActionResult SubmitVerification()

[ServiceFilter(typeof(IsCentreAuthorizedSelfAssessment))]
[Route("/LearningPortal/SelfAssessment/{selfAssessmentId:int}/{vocabulary}/Optional")]
public IActionResult ManageOptionalCompetencies(int selfAssessmentId)
public IActionResult ManageOptionalCompetencies(int selfAssessmentId, string isFromAddOptional = null)
{
ModelState.Remove("isFromAddOptional");
var delegateUserId = User.GetUserIdKnownNotNull();
var assessment = selfAssessmentService.GetSelfAssessmentForCandidateById(delegateUserId, selfAssessmentId);
var optionalCompetencies =
Expand All @@ -1463,6 +1510,12 @@ public IActionResult ManageOptionalCompetencies(int selfAssessmentId)
CompetencyGroups = optionalCompetencies.GroupBy(competency => competency.CompetencyGroup),
IncludedSelfAssessmentStructureIds = includedSelfAssessmentStructureIds,
};

if (!string.IsNullOrEmpty(isFromAddOptional))
{
ViewBag.AddOptionalVocab = model.VocabPlural();
}

return View("SelfAssessments/ManageOptionalCompetencies", model);
}

Expand Down Expand Up @@ -1645,23 +1698,23 @@ public IActionResult WithdrawSupervisorSignOffRequest(
);
}


[Route("/LearningPortal/selfAssessments/{CandidateAssessmentId:int}/{vocabulary}/Certificate")]

public IActionResult CompetencySelfAssessmentCertificate(int CandidateAssessmentId, string vocabulary)
{
int supervisorDelegateId = 0;
var adminId = User.GetAdminId();
var competencymaindata = selfAssessmentService.GetCompetencySelfAssessmentCertificate(CandidateAssessmentId);
if ((competencymaindata == null)|| ( competencymaindata.LearnerId != User.GetUserIdKnownNotNull()) || (CandidateAssessmentId == 0))
var competencymaindata = selfAssessmentService.GetCompetencySelfAssessmentCertificate(CandidateAssessmentId);
if ((competencymaindata == null) || (competencymaindata.LearnerId != User.GetUserIdKnownNotNull()) || (CandidateAssessmentId == 0))
{
return RedirectToAction("StatusCode", "LearningSolutions", new { code = 403 });
}
var delegateUserId = competencymaindata.LearnerId;
if (vocabulary == "Supervise")
{
var supervisorDelegateDetails = supervisorService.GetSupervisorDelegateDetailsForAdminId(adminId.Value);
var checkSupervisorDelegate = supervisorDelegateDetails.Where(x=> x.DelegateUserID == competencymaindata.LearnerId).FirstOrDefault();
var checkSupervisorDelegate = supervisorDelegateDetails.Where(x => x.DelegateUserID == competencymaindata.LearnerId).FirstOrDefault();
if (checkSupervisorDelegate == null)
{
return RedirectToAction("StatusCode", "LearningSolutions", new { code = 403 });
Expand Down
14 changes: 9 additions & 5 deletions DigitalLearningSolutions.Web/Services/SelfAssessmentService.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
namespace DigitalLearningSolutions.Web.Services
{
using System;
using System.Collections.Generic;
using System.Linq;
using AngleSharp.Attributes;
using DigitalLearningSolutions.Data.DataServices.SelfAssessmentDataService;
using DigitalLearningSolutions.Data.Models.Centres;
using DigitalLearningSolutions.Data.Models.Common.Users;
using DigitalLearningSolutions.Data.Models.External.Filtered;
using DigitalLearningSolutions.Data.Models.Frameworks;
using DigitalLearningSolutions.Data.Models.SelfAssessments;
using DigitalLearningSolutions.Data.Models.SelfAssessments.Export;
using System;
using System.Collections.Generic;
using System.Linq;

public interface ISelfAssessmentService
{
Expand Down Expand Up @@ -150,6 +148,7 @@ public int GetSelfAssessmentActivityDelegatesExportCount(string searchString, st
bool IsUnsupervisedSelfAssessment(int selfAssessmentId);
IEnumerable<CandidateAssessment> GetCandidateAssessments(int delegateUserId, int selfAssessmentId);
bool IsCentreSelfAssessment(int selfAssessmentId, int centreId);
bool HasMinimumOptionalCompetencies(int selfAssessmentId, int delegateUserId);

}

Expand Down Expand Up @@ -554,5 +553,10 @@ public bool IsCentreSelfAssessment(int selfAssessmentId, int centreId)
{
return selfAssessmentDataService.IsCentreSelfAssessment(selfAssessmentId, centreId);
}

public bool HasMinimumOptionalCompetencies(int selfAssessmentId, int delegateUserId)
{
return selfAssessmentDataService.HasMinimumOptionalCompetencies(selfAssessmentId, delegateUserId);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using DigitalLearningSolutions.Data.Models.SelfAssessments;
using DigitalLearningSolutions.Web.Helpers;

namespace DigitalLearningSolutions.Web.ViewModels.LearningPortal.SelfAssessments
{
public class AddOptionalCompetenciesViewModel
{
public CurrentSelfAssessment SelfAssessment { get; set; }
public string VocabPlural()
{
return FrameworkVocabularyHelper.VocabularyPlural(SelfAssessment.Vocabulary);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@using DigitalLearningSolutions.Web.ViewModels.LearningPortal.SelfAssessments
@model AddOptionalCompetenciesViewModel
@{
ViewData["Title"] = "Add optional " + Model.VocabPlural();
Layout = "SelfAssessments/_Layout";
}
@section breadcrumbs {
<li class="nhsuk-breadcrumb__item">
<a class="nhsuk-breadcrumb__link" asp-action="SelfAssessment" asp-route-selfAssessmentId="@Model.SelfAssessment.Id">@(Model.SelfAssessment.Name) introduction</a>
</li>
<li class="nhsuk-breadcrumb__item">Add optional @(Model.VocabPlural().ToLower())?</li>
}

@section mobilebacklink
{
<p class="nhsuk-breadcrumb__back">
<a class="nhsuk-breadcrumb__backlink" asp-action="SelfAssessment"
asp-route-selfAssessmentId="@Model.SelfAssessment.Id">
Back to @Model.SelfAssessment.Name
</a>
</p>
}
<form method="post" asp-action="AddOptionalCompetencies">
<div class="nhsuk-grid-row">
<input type="hidden" name="FromAddOptional" value="@Model.VocabPlural()" />
<div class="nhsuk-grid-column-full">
<h1 id="page-heading" class="nhsuk-heading-xl">Add optional proficiency to your assessment?</h1>
</div>
<div class="nhsuk-grid-column-two-thirds">
<p class="nhsuk-u-padding-top-5">During your assessment you will need to add one or more optional proficiencies to your assessment to be certified within your role</p>
<details class="nhsuk-details">
<summary class="nhsuk-details__summary nhsuk-u-padding-10">
<span class="nhsuk-u-margin-bottom-0">
<span class="nhsuk-details__summary-text">What are optional proficiencies?</span>
</span>
</summary>
<div class="nhsuk-details__text nhsuk-u-margin-left-6 nhsuk-u-margin-top-2">
<p>Optional proficiencies refer to specific skills or competencies that are not part of the core requirements but may be added based on your role, specialisation, or the needs of your workplace.</p>
<p>These proficiencies might be different depending on your role or organisation, you may need to discuss this with your educator or manager.</p>
</div>
</details>
<p class="nhsuk-u-padding-bottom-5">These proficiencies might be different depending on your role or organization so you may need to discuss this with your educator or manager</p>

@* <a class="nhsuk-button trigger-loader"
asp-route-selfAssessmentId="@Model.SelfAssessment.Id"
asp-route-vocabulary="@Model.VocabPlural()"
asp-route-isFromAddOptional="True"
asp-action="ManageOptionalCompetencies"
role="button">
Add optional @Model.VocabPlural().ToLower() to assessment
</a> *@
<button class="nhsuk-button" type="submit">Add optional @Model.VocabPlural().ToLower() to assessment</button>
<a class="nhsuk-button nhsuk-button--secondary trigger-loader" role="button" asp-action="SelfAssessmentOverview" asp-route-vocabulary="@Model.VocabPlural()" asp-route-selfAssessmentId="@Model.SelfAssessment.Id">Remind me later</a>
</div>
</div>
</form>
Loading
Loading