Skip to content

Commit 250b981

Browse files
TD-3671 changing the business rule for current and available activities
1 parent 7b45728 commit 250b981

16 files changed

+413
-110
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace DigitalLearningSolutions.Data.Migrations
2+
{
3+
using FluentMigrator;
4+
5+
[Migration(202405091044)]
6+
public class AlterGetCurrentCoursesForCandidate_V2 : Migration
7+
{
8+
public override void Up()
9+
{
10+
Execute.Sql(Properties.Resources.TD_3671_Alter_GetCurrentCoursesForCandidate_V2_proc_up );
11+
Execute.Sql(Properties.Resources.TD_3671_Alter_CheckDelegateStatusForCustomisation_func_up );
12+
}
13+
public override void Down()
14+
{
15+
Execute.Sql(Properties.Resources.TD_3671_Alter_GetCurrentCoursesForCandidate_V2_proc_down);
16+
Execute.Sql(Properties.Resources.TD_3671_Alter_CheckDelegateStatusForCustomisation_func_down);
17+
}
18+
}
19+
}

DigitalLearningSolutions.Data.Migrations/DigitalLearningSolutions.Data.Migrations.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
<ItemGroup>
3737
<EmbeddedResource Update="Properties\Resources.resx">
38-
<Generator>ResXFileCodeGenerator</Generator>
38+
<Generator>PublicResXFileCodeGenerator</Generator>
3939
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
4040
</EmbeddedResource>
4141
</ItemGroup>

DigitalLearningSolutions.Data.Migrations/Properties/Resources.Designer.cs

Lines changed: 180 additions & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DigitalLearningSolutions.Data.Migrations/Properties/Resources.resx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,16 @@
376376
<data name="TD_4015_Update_GetCompletedCoursesForCandidate_proc_down" type="System.Resources.ResXFileRef, System.Windows.Forms">
377377
<value>..\Scripts\TD-4015-GetCompletedCoursesForCandidateFix_down.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16</value>
378378
</data>
379+
<data name="TD_3671_Alter_CheckDelegateStatusForCustomisation_func_down" type="System.Resources.ResXFileRef, System.Windows.Forms">
380+
<value>..\Resources\TD-3671-Alter_CheckDelegateStatusForCustomisation_func_down.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
381+
</data>
382+
<data name="TD_3671_Alter_CheckDelegateStatusForCustomisation_func_up" type="System.Resources.ResXFileRef, System.Windows.Forms">
383+
<value>..\Resources\TD_3671_Alter_CheckDelegateStatusForCustomisation_func_up.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
384+
</data>
385+
<data name="TD_3671_Alter_GetCurrentCoursesForCandidate_V2_proc_down" type="System.Resources.ResXFileRef, System.Windows.Forms">
386+
<value>..\Resources\TD-3671-Alter_GetCurrentCoursesForCandidate_V2_proc_down.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
387+
</data>
388+
<data name="TD_3671_Alter_GetCurrentCoursesForCandidate_V2_proc_up" type="System.Resources.ResXFileRef, System.Windows.Forms">
389+
<value>..\Resources\TD-3671-Alter_GetCurrentCoursesForCandidate_V2_proc_up.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
390+
</data>
379391
</root>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/****** Object: UserDefinedFunction [dbo].[CheckDelegateStatusForCustomisation] Script Date: 08/05/2024 11:27:59 ******/
2+
SET ANSI_NULLS ON
3+
GO
4+
SET QUOTED_IDENTIFIER ON
5+
GO
6+
-- =============================================
7+
-- Author: Kevin Whittaker
8+
-- Create date: 22/12/2016
9+
-- Description: Checks if learner has progress record against customisation.
10+
-- Returns:
11+
-- 0: None
12+
-- 1: Expired
13+
-- 2: Complete
14+
-- 3: Current
15+
-- =============================================
16+
-- 18/09/2018 Adds return val of 4 for removed progress. Also excluded removed progress from current and expired checks.
17+
-- 17/20/2023 Excludes progress that is marked as removed from the query with a return value of 2 (Complete).
18+
ALTER FUNCTION [dbo].[CheckDelegateStatusForCustomisation]
19+
(
20+
-- Add the parameters for the function here
21+
@CustomisationID Int,
22+
@CandidateID Int
23+
)
24+
RETURNS int
25+
AS
26+
BEGIN
27+
-- Declare the return variable here
28+
DECLARE @ResultVar int
29+
Set @ResultVar = 0
30+
31+
-- Add the T-SQL statements to compute the return value here
32+
33+
-- Check of current:
34+
if @CustomisationID IN (SELECT CustomisationID
35+
FROM Progress AS p
36+
WHERE (Completed IS NULL) AND (RemovedDate IS NULL) AND (CandidateID = @CandidateID) AND ((SubmittedTime > DATEADD(M, - 6, GETDATE()) OR (EnrollmentMethodID <> 1)) OR NOT p.CompleteByDate IS NULL))
37+
begin
38+
Set @ResultVar = 3
39+
goto onExit
40+
end
41+
--Check if Complete:
42+
if @CustomisationID IN (SELECT CustomisationID
43+
FROM Progress AS p
44+
WHERE (Completed IS NOT NULL) AND (RemovedDate IS NULL) AND (CandidateID = @CandidateID))
45+
begin
46+
Set @ResultVar = 2
47+
goto onExit
48+
end
49+
--Check if Expired:
50+
if @CustomisationID IN (SELECT CustomisationID
51+
FROM Progress AS p
52+
WHERE (Completed IS NULL) AND (RemovedDate IS NULL) AND (CandidateID = @CandidateID) AND ((SubmittedTime <= DATEADD(M, - 6, GETDATE())) AND (EnrollmentMethodID = 1)) AND (p.CompleteByDate IS NULL))
53+
begin
54+
Set @ResultVar = 1
55+
goto onExit
56+
end
57+
--Check if Removed:
58+
if @CustomisationID IN (SELECT CustomisationID
59+
FROM Progress AS p
60+
WHERE (Completed IS NULL) AND (RemovedDate IS NOT NULL) AND (CandidateID = @CandidateID) AND (p.CompleteByDate IS NULL))
61+
begin
62+
Set @ResultVar = 4
63+
goto onExit
64+
end
65+
-- Return the result of the function
66+
onExit:
67+
RETURN @ResultVar
68+
69+
END
70+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
/****** Object: StoredProcedure [dbo].[GetCurrentCoursesForCandidate_V2] Script Date: 08/05/2024 10:34:29 ******/
3+
SET ANSI_NULLS ON
4+
GO
5+
SET QUOTED_IDENTIFIER ON
6+
GO
7+
-- =============================================
8+
-- Author: Kevin Whittaker
9+
-- Create date: 16/12/2016
10+
-- Description: Returns a list of active progress records for the candidate.
11+
-- Change 18/09/2018: Adds logic to exclude Removed courses from returned results.
12+
-- =============================================
13+
ALTER PROCEDURE [dbo].[GetCurrentCoursesForCandidate_V2]
14+
-- Add the parameters for the stored procedure here
15+
@CandidateID int
16+
AS
17+
BEGIN
18+
-- SET NOCOUNT ON added to prevent extra result sets from
19+
-- interfering with SELECT statements.
20+
SET NOCOUNT ON;
21+
22+
-- Insert statements for procedure here
23+
SELECT p.ProgressID, (CASE WHEN cu.CustomisationName <> '' THEN a.ApplicationName + ' - ' + cu.CustomisationName ELSE a.ApplicationName END) AS CourseName, p.CustomisationID, p.SubmittedTime AS LastAccessed,
24+
p.FirstSubmittedTime AS StartedDate, p.DiagnosticScore, p.PLLocked, cu.IsAssessed, dbo.CheckCustomisationSectionHasDiagnostic(p.CustomisationID, 0)
25+
AS HasDiagnostic, dbo.CheckCustomisationSectionHasLearning(p.CustomisationID, 0) AS HasLearning,
26+
COALESCE
27+
((SELECT COUNT(Passes) AS Passes
28+
FROM (SELECT COUNT(AssessAttemptID) AS Passes
29+
FROM AssessAttempts AS aa
30+
WHERE (CandidateID = p.CandidateID) AND (CustomisationID = p.CustomisationID) AND (Status = 1)
31+
GROUP BY SectionNumber) AS derivedtbl_2), 0) AS Passes,
32+
(SELECT COUNT(SectionID) AS Sections
33+
FROM Sections AS s
34+
WHERE (ApplicationID = cu.ApplicationID)) AS Sections, p.CompleteByDate, CAST(CASE WHEN p.CompleteByDate IS NULL THEN 0 WHEN p.CompleteByDate < getDate()
35+
THEN 2 WHEN p.CompleteByDate < DATEADD(M, + 1, getDate()) THEN 1 ELSE 0 END AS INT) AS OverDue, p.EnrollmentMethodID, dbo.GetCohortGroupCustomisationID(p.ProgressID) AS GroupCustomisationID, p.SupervisorAdminID
36+
37+
FROM Progress AS p INNER JOIN
38+
Customisations AS cu ON p.CustomisationID = cu.CustomisationID INNER JOIN
39+
Applications AS a ON cu.ApplicationID = a.ApplicationID
40+
WHERE (p.Completed IS NULL) AND (p.RemovedDate IS NULL) AND (p.CandidateID = @CandidateID)AND (cu.CustomisationName <> 'ESR') AND (a.ArchivedDate IS NULL) AND (cu.Active = 1) AND ((p.SubmittedTime > DATEADD(M, -6, getDate())) OR NOT p.CompleteByDate IS NULL)
41+
ORDER BY p.SubmittedTime Desc
42+
END
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
/****** Object: UserDefinedFunction [dbo].[CheckDelegateStatusForCustomisation] Script Date: 09/05/2024 11:41:58 ******/
3+
SET ANSI_NULLS ON
4+
GO
5+
SET QUOTED_IDENTIFIER ON
6+
GO
7+
-- =============================================
8+
-- Author: Kevin Whittaker
9+
-- Create date: 22/12/2016
10+
-- Description: Checks if learner has progress record against customisation.
11+
-- Returns:
12+
-- 0: None
13+
-- 1: Expired
14+
-- 2: Complete
15+
-- 3: Current
16+
-- =============================================
17+
-- 18/09/2018 Adds return val of 4 for removed progress. Also excluded removed progress from current and expired checks.
18+
-- 17/20/2023 Excludes progress that is marked as removed from the query with a return value of 2 (Complete).
19+
ALTER FUNCTION [dbo].[CheckDelegateStatusForCustomisation]
20+
(
21+
-- Add the parameters for the function here
22+
@CustomisationID Int,
23+
@CandidateID Int
24+
)
25+
RETURNS int
26+
AS
27+
BEGIN
28+
-- Declare the return variable here
29+
DECLARE @ResultVar int
30+
Set @ResultVar = 0
31+
32+
-- Add the T-SQL statements to compute the return value here
33+
34+
-- Check of current:
35+
if @CustomisationID IN (SELECT CustomisationID
36+
FROM Progress AS p
37+
WHERE (Completed IS NULL) AND (RemovedDate IS NULL) AND (CandidateID = @CandidateID) AND ((SubmittedTime > DATEADD(M, - 6, GETDATE()) OR (EnrollmentMethodID <> 1)) OR NOT p.CompleteByDate IS NULL))
38+
begin
39+
Set @ResultVar = 3
40+
goto onExit
41+
end
42+
--Check if Complete:
43+
if @CustomisationID IN (SELECT CustomisationID
44+
FROM Progress AS p
45+
WHERE (Completed IS NOT NULL) AND (RemovedDate IS NULL) AND (CandidateID = @CandidateID))
46+
begin
47+
Set @ResultVar = 2
48+
goto onExit
49+
end
50+
--Check if Expired:
51+
if @CustomisationID IN (SELECT CustomisationID
52+
FROM Progress AS p
53+
WHERE (Completed IS NULL) AND (RemovedDate IS NULL) AND (CandidateID = @CandidateID) AND ((SubmittedTime <= DATEADD(M, - 6, GETDATE())) AND (EnrollmentMethodID = 1)) AND (p.CompleteByDate IS NULL))
54+
begin
55+
Set @ResultVar = 1
56+
goto onExit
57+
end
58+
--Check if Removed:
59+
if @CustomisationID IN (SELECT CustomisationID
60+
FROM Progress AS p
61+
WHERE (Completed IS NULL) AND (RemovedDate IS NOT NULL) AND (CandidateID = @CandidateID) AND (p.CompleteByDate IS NULL))
62+
begin
63+
Set @ResultVar = 4
64+
goto onExit
65+
end
66+
-- Return the result of the function
67+
onExit:
68+
RETURN @ResultVar
69+
70+
END

DigitalLearningSolutions.Data/DataServices/ProgressDataService.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface IProgressDataService
1515
{
1616
IEnumerable<Progress> GetDelegateProgressForCourse(int delegateId, int customisationId);
1717

18-
void UpdateProgressSupervisorAndCompleteByDate(int progressId, int supervisorAdminId, DateTime? completeByDate,DateTime submittedTime);
18+
void UpdateProgressSupervisorAndCompleteByDate(int progressId, int supervisorAdminId, DateTime? completeByDate, int enrollmentMethodID);
1919

2020
int CreateNewDelegateProgress(
2121
int delegateId,
@@ -143,16 +143,17 @@ FROM Progress
143143
public void UpdateProgressSupervisorAndCompleteByDate(
144144
int progressId,
145145
int supervisorAdminId,
146-
DateTime? completeByDate, DateTime submittedTime
146+
DateTime? completeByDate,
147+
int enrollmentMethodID
147148
)
148149
{
149150
connection.Execute(
150151
@"UPDATE Progress SET
151152
SupervisorAdminID = @supervisorAdminId,
152153
CompleteByDate = @completeByDate,
153-
SubmittedTime = @submittedTime
154+
EnrollmentMethodID = @enrollmentMethodID
154155
WHERE ProgressID = @progressId",
155-
new { progressId, supervisorAdminId, completeByDate, submittedTime }
156+
new { progressId, supervisorAdminId, completeByDate, enrollmentMethodID }
156157
);
157158
}
158159

0 commit comments

Comments
 (0)