diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserRecentLearningActivities.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserRecentLearningActivities.sql index 6e516078..4097de29 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserRecentLearningActivities.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserRecentLearningActivities.sql @@ -7,6 +7,7 @@ -- 02-Sep-2025 SA Incorrect Syntax -- 23-09-2025 SA Added new columns for displaying video/Audio Progress -- 01-10-2025 SA added assesment score and passmark and provider details +-- 16-12-2025 SA TD-6322 added the condition to validate the certificate enabled is true for the latest resourceversion. ------------------------------------------------------------------------------- CREATE PROCEDURE [activity].[GetUserRecentLearningActivities] ( @userId INT, @@ -34,7 +35,8 @@ BEGIN r.ResourceTypeId AS ResourceType, rv.Title AS Title, --rv.[Description] AS ResourceDescription, - rv.CertificateEnabled AS CertificateEnabled, + -- Get CertificateEnabled from the latest resource version + rvCurrent.CertificateEnabled AS CertificateEnabled, ISNULL(ara.ActivityStatusId, ra.ActivityStatusId) AS ActivityStatus, ra.ActivityStart AS ActivityDate, -- ara.ActivityEnd, @@ -59,7 +61,10 @@ BEGIN FROM activity.ResourceActivity ra LEFT JOIN activity.ResourceActivity ara ON ara.LaunchResourceActivityId = ra.Id INNER JOIN [resources].[Resource] r ON ra.ResourceId = r.Id - INNER JOIN [resources].[ResourceVersion] rv ON rv.Id = ra.ResourceVersionId AND rv.Deleted = 0 + -- Version used in the activity + INNER JOIN [resources].[ResourceVersion] rv ON rv.Id = ra.ResourceVersionId AND rv.Deleted = 0 + -- Latest resource version + INNER JOIN [resources].[ResourceVersion] rvCurrent ON rvCurrent.Id = r.CurrentResourceVersionId LEFT JOIN ( SELECT rp.ResourceVersionId, diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUsersLearningHistory.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUsersLearningHistory.sql index 81669c47..542f39f5 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUsersLearningHistory.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUsersLearningHistory.sql @@ -6,6 +6,7 @@ -- Modification History -- 23-09-2025 SA Added new columns for displaying video/Audio Progress -- 01-10-2025 SA added assesment score and passmark and provider details +-- 16-12-2025 SA TD-6322 added the condition to validate the certificate enabled is true for the latest resourceversion. ------------------------------------------------------------------------------- CREATE PROCEDURE [activity].[GetUsersLearningHistory] ( @userId INT, @@ -31,7 +32,8 @@ BEGIN ra.NodePathId AS NodePathId, r.ResourceTypeId AS ResourceType, rv.Title AS Title, - rv.CertificateEnabled AS CertificateEnabled, + -- Get CertificateEnabled from the latest resource version + rvCurrent.CertificateEnabled AS CertificateEnabled, ISNULL(ara.ActivityStatusId, ra.ActivityStatusId) AS ActivityStatus, ra.ActivityStart AS ActivityDate, ISNULL(ara.DurationSeconds, 0) ActivityDurationSeconds, @@ -50,7 +52,10 @@ BEGIN LEFT JOIN activity.ResourceActivity ara ON ara.LaunchResourceActivityId = ra.Id INNER JOIN [resources].[Resource] r ON ra.ResourceId = r.Id - INNER JOIN [resources].[ResourceVersion] rv ON rv.Id = ra.ResourceVersionId AND rv.deleted =0 + -- Version used in the activity + INNER JOIN [resources].[ResourceVersion] rv ON rv.Id = ra.ResourceVersionId AND rv.Deleted = 0 + -- Latest resource version + INNER JOIN [resources].[ResourceVersion] rvCurrent ON rvCurrent.Id = r.CurrentResourceVersionId LEFT JOIN ( SELECT rp.ResourceVersionId, diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUsersLearningHistory_Search.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUsersLearningHistory_Search.sql index ba4d565d..cd850023 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUsersLearningHistory_Search.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUsersLearningHistory_Search.sql @@ -6,6 +6,7 @@ -- Modification History -- 23-09-2025 SA Added new columns for displaying video/Audio Progress -- 01-10-2025 SA added assesment score and passmark and provider details +-- 16-12-2025 SA TD-6322 added the condition to validate the certificate enabled is true for the latest resourceversion. ------------------------------------------------------------------------------- CREATE PROCEDURE [activity].[GetUsersLearningHistory_Search] ( @userId INT, @@ -34,7 +35,8 @@ BEGIN ra.NodePathId AS NodePathId, r.ResourceTypeId AS ResourceType, rv.Title AS Title, - rv.CertificateEnabled AS CertificateEnabled, + -- Get CertificateEnabled from the latest resource version + rvCurrent.CertificateEnabled AS CertificateEnabled, ISNULL(ara.ActivityStatusId, ra.ActivityStatusId) AS ActivityStatus, ra.ActivityStart AS ActivityDate, ISNULL(ara.DurationSeconds, 0) AS ActivityDurationSeconds, @@ -53,7 +55,10 @@ BEGIN LEFT JOIN activity.ResourceActivity ara ON ara.LaunchResourceActivityId = ra.Id INNER JOIN [resources].[Resource] r ON ra.ResourceId = r.Id - INNER JOIN [resources].[ResourceVersion] rv ON rv.Id = ra.ResourceVersionId AND rv.deleted =0 + -- Version used in the activity + INNER JOIN [resources].[ResourceVersion] rv ON rv.Id = ra.ResourceVersionId AND rv.Deleted = 0 + -- Latest resource version + INNER JOIN [resources].[ResourceVersion] rvCurrent ON rvCurrent.Id = r.CurrentResourceVersionId LEFT JOIN ( SELECT rp.ResourceVersionId, diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetUsercertificateDetails.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetUsercertificateDetails.sql index 50e795c8..59656ce9 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetUsercertificateDetails.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetUsercertificateDetails.sql @@ -9,6 +9,7 @@ -- 16-09-2025 Tobi Added null check for ResourceReferenceID --17-09-2025 Swapna Added resource version id -- 01-10-2025 SA added assesment score and passmark and provider details +-- 16=12-2025 SA TD-6322 added the condition to validate the certificate enabled is true for the latest resourceversion. ------------------------------------------------------------------------------- CREATE PROCEDURE [resources].[GetUsercertificateDetails] @UserId INT, @@ -26,7 +27,21 @@ BEGIN ResourceActivityId INT NOT NULL, PRIMARY KEY CLUSTERED (ResourceActivityId) ); - + -- to get the latest resourceVersion + ;WITH LatestResourceVersion AS ( + SELECT + rv.ResourceId, + rv.Id AS ResourceVersionId, + rv.CertificateEnabled + FROM resources.ResourceVersion rv + WHERE rv.Deleted = 0 + AND rv.Id = ( + SELECT MAX(rv2.Id) + FROM resources.ResourceVersion rv2 + WHERE rv2.ResourceId = rv.ResourceId + AND rv2.Deleted = 0 + ) +) INSERT INTO #MyActivity (ResourceId, ResourceActivityId) SELECT ra.ResourceId, @@ -34,10 +49,10 @@ BEGIN FROM activity.ResourceActivity ra JOIN resources.Resource r ON ra.ResourceId = r.Id - JOIN resources.ResourceVersion rv - ON rv.Id = ra.ResourceVersionId + JOIN LatestResourceVersion lrv + ON lrv.ResourceId = ra.ResourceId WHERE ra.UserId = @UserId - AND rv.CertificateEnabled = 1 + AND lrv.CertificateEnabled = 1 AND ( (r.ResourceTypeId IN (2, 7) AND ra.ActivityStatusId = 3) OR (ra.ActivityStart < '2020-09-07T00:00:00+00:00')