diff --git a/CSETWebApi/CSETWeb_Api/ProcViewSerializer/App.config b/CSETWebApi/CSETWeb_Api/ProcViewSerializer/App.config index bd70693a99..1d16ab563c 100644 --- a/CSETWebApi/CSETWeb_Api/ProcViewSerializer/App.config +++ b/CSETWebApi/CSETWeb_Api/ProcViewSerializer/App.config @@ -4,9 +4,9 @@ - + - + \ No newline at end of file diff --git a/Database Scripts/Functions/func_AM.func.sql b/Database Scripts/Functions/func_AM.func.sql index 5f9babaf35..dd4968099a 100644 --- a/Database Scripts/Functions/func_AM.func.sql +++ b/Database Scripts/Functions/func_AM.func.sql @@ -1,10 +1,3 @@ -USE [CSETWeb] -GO -/****** Object: UserDefinedFunction [dbo].[func_AM] Script Date: 10/11/2023 8:17:35 AM ******/ -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: Randy Woods -- Create date: 10-OCT-2023 @@ -13,7 +6,7 @@ GO -- for the sub model are returned. Otherwise all maturity answers -- are returned for the assessment. -- ============================================= -ALTER FUNCTION [dbo].[func_AM] +CREATE FUNCTION [dbo].[func_AM] ( @assessmentId int ) diff --git a/Database Scripts/Functions/func_MQ.func.sql b/Database Scripts/Functions/func_MQ.func.sql index 9010f45511..6891159cf2 100644 --- a/Database Scripts/Functions/func_MQ.func.sql +++ b/Database Scripts/Functions/func_MQ.func.sql @@ -1,10 +1,3 @@ -USE [CSETWeb] -GO -/****** Object: UserDefinedFunction [dbo].[func_MQ] Script Date: 10/11/2023 8:18:33 AM ******/ -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: Randy Woods -- Create date: 10-OCT-2023 @@ -13,7 +6,7 @@ GO -- sub model are returned. Otherwise, all questions for the assessment's -- model are returned. -- ============================================= -ALTER FUNCTION [dbo].[func_MQ] +CREATE FUNCTION [dbo].[func_MQ] ( @assessmentId int ) diff --git a/Database Scripts/Stored Procedures/Acet_GetActionItemsForReport.proc.sql b/Database Scripts/Stored Procedures/Acet_GetActionItemsForReport.proc.sql new file mode 100644 index 0000000000..9e9dae0951 --- /dev/null +++ b/Database Scripts/Stored Procedures/Acet_GetActionItemsForReport.proc.sql @@ -0,0 +1,32 @@ +-- ============================================= +-- Author: mrwinston +-- Create date: 11/4/2022 +-- Description: loads in the Action_Items for ACET ISE's MERIT and Examination reports +-- ============================================= +CREATE PROCEDURE [dbo].[Acet_GetActionItemsForReport] + @Assessment_Id int, + @Exam_Level int, + @Additional_Exam_Level int +AS +BEGIN + SELECT a.Parent_Question_Id, a.Mat_Question_Id,a.Finding_Id,a.Question_Title,a.answer_text,Regulatory_Citation, isnull(b.action_items_override,a.Action_Items) as Action_Items, a.Maturity_Level_Id + FROM (select m.mat_question_id,m.Question_Title, m.Parent_Question_Id,i.Action_Items, Regulatory_Citation, a.Answer_Text,m.Maturity_Level_Id, mf.Finding_Id + from [MATURITY_QUESTIONS] AS [m] + join [ANSWER] [a] on m.Mat_Question_Id = a.Question_Or_Requirement_Id and a.Question_Type = 'Maturity' and Assessment_Id = @Assessment_Id + join (select a1.Question_Or_Requirement_Id,f1.Finding_Id,f1.Auto_Generated from ANSWER a1 join FINDING f1 on a1.Answer_Id=f1.Answer_Id where Assessment_Id = @Assessment_Id and a1.Question_Type = 'Maturity') mf on m.Parent_Question_Id = mf.Question_Or_Re +quirement_Id + INNER JOIN [ISE_ACTIONS] AS [i] ON [m].[Mat_Question_Id] = [i].[Mat_Question_Id] + where a.Answer_Text = 'N' or Auto_Generated = 0 + ) a + + left join (select a.Assessment_Id,a.Question_Or_Requirement_Id,f.Finding_Id,i0.Action_Items_Override,i0.Mat_Question_Id + from [ANSWER] [a] + JOIN [FINDING] AS [f] ON [a].[Answer_Id] = [f].[Answer_Id] + LEFT JOIN [ISE_ACTIONS_FINDINGS] AS [i0] ON f.Finding_Id = i0.Finding_Id + WHERE [a].[Assessment_Id] = @Assessment_Id and a.Question_Type = 'Maturity' + ) b on a.Parent_Question_Id = b.Question_Or_Requirement_Id and a.Mat_Question_Id = b.Mat_Question_Id and a.Finding_Id = b.Finding_Id + + where a.Maturity_Level_Id = @Exam_Level or a.Maturity_Level_Id = @Additional_Exam_Level + order by a.Mat_Question_Id + +END diff --git a/Database Scripts/Stored Procedures/GetAnswerDistribGroupings.proc.sql b/Database Scripts/Stored Procedures/GetAnswerDistribGroupings.proc.sql new file mode 100644 index 0000000000..00692004db --- /dev/null +++ b/Database Scripts/Stored Procedures/GetAnswerDistribGroupings.proc.sql @@ -0,0 +1,29 @@ +-- ============================================= +-- Author: Randy Woods +-- Create date: 15 November 2022 +-- Description: Tallies answer counts for all maturity groupings +-- at the top level. +-- TODO: What if we want to target the children of a +-- specific grouping? g.Parent_Id = X +-- ============================================= +CREATE PROCEDURE [dbo].[GetAnswerDistribGroupings] + @assessmentId int +AS +BEGIN + SET NOCOUNT ON; + exec FillEmptyMaturityQuestionsForAnalysis @assessmentId + + declare @maturityModelId int = (select model_id from AVAILABLE_MATURITY_MODELS where Assessment_Id = @assessmentId) + + select [grouping_id], [title], [answer_text], count(answer_text) as [answer_count] + from ( + select g.grouping_id, g.title, g.sequence, a.Answer_Text + from maturity_groupings g + left join maturity_questions q on q.grouping_id = g.Grouping_Id + left join ANSWER a on a.Question_Or_Requirement_Id = q.Mat_Question_Id + where a.Assessment_Id = @assessmentId and g.Parent_Id is null and + g.maturitY_model_id = @maturityModelId + ) N + group by n.answer_text, n.grouping_id, n.title, n.Sequence + order by n.Sequence +END diff --git a/Database Scripts/Stored Procedures/GetAnswerDistribMaturity.proc.sql b/Database Scripts/Stored Procedures/GetAnswerDistribMaturity.proc.sql new file mode 100644 index 0000000000..258e6ff5dc --- /dev/null +++ b/Database Scripts/Stored Procedures/GetAnswerDistribMaturity.proc.sql @@ -0,0 +1,42 @@ +-- ============================================= +-- Author: Randy Woods +-- Create date: 11 November 2022 +-- Description: Get a generic answer distribution for an assessment +-- without having to worry about which answers it supports. +-- ============================================= +CREATE PROCEDURE [dbo].[GetAnswerDistribMaturity] + @assessment_id int +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + -- build list of answer options supported by the assessment's model + declare @ao varchar(20) + select @ao = answer_options + from maturity_models mm + left join AVAILABLE_MATURITY_MODELS amm on mm.Maturity_Model_Id = amm.model_id + where amm.Assessment_Id = @assessment_id + + select * into #ao from STRING_SPLIT(@ao, ',') + insert into #ao (value) values ('U') + update #ao set value = TRIM(value) + + + select a.Answer_Full_Name, a.Answer_Text, + isnull(m.qc,0) as [qc], + isnull(m.Total,0) as [Total], + IsNull(Cast(IsNull(Round((Cast((qc) as float)/(IsNull(NullIf(Total,0),1)))*100, 2), 0) as float),0) as [Percent] + from + (select * from ANSWER_LOOKUP where Answer_Text in (select value from #ao)) a left join ( +SELECT a.Answer_Text, isnull(count(question_or_requirement_id),0) qc , SUM(count(Question_Or_Requirement_Id)) OVER(PARTITION BY assessment_id) AS Total + FROM Answer_Maturity a + join MATURITY_LEVELS l on a.Maturity_Level_Id = l.Maturity_Level_Id + where a.Assessment_Id = @assessment_id and Is_Maturity = 1 + group by a.Assessment_Id, a.Answer_Text) + m on a.Answer_Text = m.Answer_Text + LEFT JOIN ANSWER_ORDER o on a.Answer_Text = o.answer_text + order by o.answer_order + +END diff --git a/Database Scripts/Stored Procedures/GetChildrenAnswers.proc.sql b/Database Scripts/Stored Procedures/GetChildrenAnswers.proc.sql new file mode 100644 index 0000000000..710fc30680 --- /dev/null +++ b/Database Scripts/Stored Procedures/GetChildrenAnswers.proc.sql @@ -0,0 +1,19 @@ +-- ============================================= +-- Author: +-- Create date: +-- Description: +-- ============================================= +CREATE PROCEDURE [dbo].[GetChildrenAnswers] + @Parent_Id int, + @Assess_Id int + +AS +BEGIN + SET NOCOUNT ON; + SELECT [Mat_Question_Id], [Question_Title], [Question_Text], + [Answer_Text], [Maturity_Level_Id], [Parent_Question_Id], + [Ranking], [Grouping_Id] FROM MATURITY_QUESTIONS + JOIN ANSWER + ON MATURITY_QUESTIONS.Mat_Question_Id = ANSWER.Question_Or_Requirement_Id + WHERE ([Parent_Question_Id] = @Parent_Id) AND ([Assessment_Id] = @Assess_Id) +END diff --git a/Database Scripts/Stored Procedures/GetRelevantAnswers.proc.sql b/Database Scripts/Stored Procedures/GetRelevantAnswers.proc.sql index cec70be1ce..91d3dace6b 100644 --- a/Database Scripts/Stored Procedures/GetRelevantAnswers.proc.sql +++ b/Database Scripts/Stored Procedures/GetRelevantAnswers.proc.sql @@ -21,10 +21,15 @@ BEGIN -- get currently selected sets IF OBJECT_ID('tempdb..#mySets') IS NOT NULL DROP TABLE #mySets select set_name into #mySets from AVAILABLE_STANDARDS where Assessment_Id = @assessment_Id and Selected = 1 + + IF OBJECT_ID('tempdb..#relevantAnswers') IS NOT NULL DROP TABLE #relevantAnswers + CREATE TABLE #relevantAnswers (assessment_id int, answer_id int, is_requirement bit, question_or_requirement_id int, mark_for_review bit, + comment ntext, alternate_justification ntext, question_number int, answer_text nvarchar(50), + component_guid nvarchar(36), is_component bit, custom_question_guid nvarchar(50), is_framework bit, old_answer_id int, reviewed bit) if(@ApplicationMode = 'Questions Based') begin - + insert into #relevantAnswers select distinct a.assessment_id, a.answer_id, a.is_requirement, a.question_or_requirement_id, a.mark_for_review, a.comment, a.alternate_justification, a.question_number, a.answer_text, a.component_guid, a.is_component, a.custom_question_guid, a.is_framework, a.old_answer_id, a.reviewed @@ -46,7 +51,7 @@ BEGIN end else begin - + insert into #relevantAnswers select distinct a.assessment_id, a.answer_id, a.is_requirement, a.question_or_requirement_id,a.mark_for_review, a.comment, a.alternate_justification, a.question_number, a.answer_text, a.component_guid, a.is_component, a.custom_question_guid, a.is_framework, a.old_answer_id, a.reviewed @@ -61,6 +66,17 @@ BEGIN where rs.Set_Name in (select set_name from #mySets) and a.Assessment_Id = @assessment_id and rl.Standard_Level = u.Universal_Sal_Level - end + -- Get all of the component questions. The questions available are not currently filtered by SAL level, so just get them all. + insert into #relevantAnswers + select distinct a.assessment_id, a.answer_id, a.is_requirement, a.question_or_requirement_id,a.mark_for_review, + a.comment, a.alternate_justification, a.question_number, a.answer_text, + a.component_guid, a.is_component, a.custom_question_guid, a.is_framework, a.old_answer_id, a.reviewed + from ANSWER a + where a.Assessment_Id = @assessment_id and a.Question_Type = 'Component' + + select a.assessment_id, a.answer_id, a.is_requirement, a.question_or_requirement_id,a.mark_for_review, + a.comment, a.alternate_justification, a.question_number, a.answer_text, + a.component_guid, a.is_component, a.custom_question_guid, a.is_framework, a.old_answer_id, a.reviewed + from #relevantAnswers a END diff --git a/Database Scripts/Stored Procedures/Get_Merge_Conflicts.proc.sql b/Database Scripts/Stored Procedures/Get_Merge_Conflicts.proc.sql index 769cd2247e..486450f57f 100644 --- a/Database Scripts/Stored Procedures/Get_Merge_Conflicts.proc.sql +++ b/Database Scripts/Stored Procedures/Get_Merge_Conflicts.proc.sql @@ -137,7 +137,6 @@ WHERE ((a.Answer_Text != 'U' AND h.Answer_Text != 'U') AND (a.Answer_Text != h.Answer_Text)) OR ((a.Answer_Text != 'U' AND i.Answer_Text != 'U') AND (a.Answer_Text != i.Answer_Text)) OR ((a.Answer_Text != 'U' AND j.Answer_Text != 'U') AND (a.Answer_Text != j.Answer_Text)) OR - (a.Answer_Text = 'A') OR (a.Comment != NULL) OR -- Compare Exam 2 (b) to all other exams being merged ((b.Answer_Text != 'U' AND c.Answer_Text != 'U') AND (b.Answer_Text != c.Answer_Text)) OR @@ -148,17 +147,15 @@ WHERE ((b.Answer_Text != 'U' AND h.Answer_Text != 'U') AND (b.Answer_Text != h.Answer_Text)) OR ((b.Answer_Text != 'U' AND i.Answer_Text != 'U') AND (b.Answer_Text != i.Answer_Text)) OR ((b.Answer_Text != 'U' AND j.Answer_Text != 'U') AND (b.Answer_Text != j.Answer_Text)) OR - (b.Answer_Text = 'A') OR (b.Comment != NULL) OR -- Compare Exam 3 (c) ((c.Answer_Text != 'U' AND d.Answer_Text != 'U') AND (c.Answer_Text != d.Answer_Text)) OR ((c.Answer_Text != 'U' AND e.Answer_Text != 'U') AND (c.Answer_Text != e.Answer_Text)) OR ((c.Answer_Text != 'U' AND f.Answer_Text != 'U') AND (c.Answer_Text != f.Answer_Text)) OR - ((c.Answer_Text != 'U' AND g.Answer_Text != 'U') AND (c.Answer_Text != g.Answer_Text)) OR + ((c.Answer_Text != 'U' AND g.Answer_Text != 'U') AND (c.Answer_Text != g.Answer_Text)) OR ((c.Answer_Text != 'U' AND h.Answer_Text != 'U') AND (c.Answer_Text != h.Answer_Text)) OR ((c.Answer_Text != 'U' AND i.Answer_Text != 'U') AND (c.Answer_Text != i.Answer_Text)) OR ((c.Answer_Text != 'U' AND j.Answer_Text != 'U') AND (c.Answer_Text != j.Answer_Text)) OR - (c.Answer_Text = 'A') OR (c.Comment != 'NULL') OR -- Compare Exam 4 (d) ((d.Answer_Text != 'U' AND e.Answer_Text != 'U') AND (d.Answer_Text != e.Answer_Text)) OR @@ -167,7 +164,6 @@ WHERE ((d.Answer_Text != 'U' AND h.Answer_Text != 'U') AND (d.Answer_Text != h.Answer_Text)) OR ((d.Answer_Text != 'U' AND i.Answer_Text != 'U') AND (d.Answer_Text != i.Answer_Text)) OR ((d.Answer_Text != 'U' AND j.Answer_Text != 'U') AND (d.Answer_Text != j.Answer_Text)) OR - (d.Answer_Text = 'A') OR (d.Comment != 'NULL') OR -- Compare Exam 5 (e) ((e.Answer_Text != 'U' AND f.Answer_Text != 'U') AND (e.Answer_Text != f.Answer_Text)) OR @@ -175,30 +171,25 @@ WHERE ((e.Answer_Text != 'U' AND h.Answer_Text != 'U') AND (e.Answer_Text != h.Answer_Text)) OR ((e.Answer_Text != 'U' AND i.Answer_Text != 'U') AND (e.Answer_Text != i.Answer_Text)) OR ((e.Answer_Text != 'U' AND j.Answer_Text != 'U') AND (e.Answer_Text != j.Answer_Text)) OR - (e.Answer_Text = 'A') OR (e.Comment != 'NULL') OR -- Compare Exam 6 (f) ((f.Answer_Text != 'U' AND g.Answer_Text != 'U') AND (f.Answer_Text != g.Answer_Text)) OR ((f.Answer_Text != 'U' AND h.Answer_Text != 'U') AND (f.Answer_Text != h.Answer_Text)) OR ((f.Answer_Text != 'U' AND i.Answer_Text != 'U') AND (f.Answer_Text != i.Answer_Text)) OR ((f.Answer_Text != 'U' AND j.Answer_Text != 'U') AND (f.Answer_Text != j.Answer_Text)) OR - (f.Answer_Text = 'A') OR (f.Comment != 'NULL') OR -- Compare Exam 7 (g) ((g.Answer_Text != 'U' AND g.Answer_Text != 'U') AND (g.Answer_Text != g.Answer_Text)) OR ((g.Answer_Text != 'U' AND h.Answer_Text != 'U') AND (g.Answer_Text != h.Answer_Text)) OR ((g.Answer_Text != 'U' AND i.Answer_Text != 'U') AND (g.Answer_Text != i.Answer_Text)) OR ((g.Answer_Text != 'U' AND j.Answer_Text != 'U') AND (g.Answer_Text != j.Answer_Text)) OR - (g.Answer_Text = 'A') OR (g.Comment != 'NULL') OR -- Compare Exam 8 (h) ((h.Answer_Text != 'U' AND i.Answer_Text != 'U') AND (h.Answer_Text != i.Answer_Text)) OR ((h.Answer_Text != 'U' AND j.Answer_Text != 'U') AND (h.Answer_Text != j.Answer_Text)) OR - (h.Answer_Text = 'A') OR (h.Comment != 'NULL') OR -- Compare Exam 9 (i) - ((i.Answer_Text != 'U' AND j.Answer_Text != 'U') AND (i.Answer_Text != j.Answer_Text)) OR - (i.Answer_Text = 'A') OR (i.Comment != 'NULL') + ((i.Answer_Text != 'U' AND j.Answer_Text != 'U') AND (i.Answer_Text != j.Answer_Text)) END diff --git a/Database Scripts/Stored Procedures/IseAnswerDistribution.proc.sql b/Database Scripts/Stored Procedures/IseAnswerDistribution.proc.sql new file mode 100644 index 0000000000..5465c4a1f7 --- /dev/null +++ b/Database Scripts/Stored Procedures/IseAnswerDistribution.proc.sql @@ -0,0 +1,32 @@ + +-- ============================================= +-- Author: mrwinston +-- Create date: 10/10/2022 +-- Description: Gets all the AnswerText values, excluding parent questions +-- ============================================= +CREATE PROCEDURE [dbo].[IseAnswerDistribution] + @Assessment_Id int, + @targetLevel int +AS +BEGIN + + SET NOCOUNT ON; + + exec FillEmptyMaturityQuestionsForAnalysis @assessment_id + + declare @model_id int + select @model_id = (select model_id from AVAILABLE_MATURITY_MODELS where assessment_id = @Assessment_id and selected = 1) + + + select a.Answer_Text, count(*) as [Count] from maturity_questions q + left join answer a on a.Question_Or_Requirement_Id = q.Mat_Question_Id + left join maturity_levels l on q.Maturity_Level_Id = l.Maturity_Level_Id + where a.Question_Type = 'Maturity' and q.Maturity_Model_Id = @model_id + and l.Maturity_Level_Id = @targetLevel + and a.Assessment_Id = @assessment_id + and q.Parent_Question_Id IS NOT NULL + and q.Maturity_Level_Id != 19 + group by Answer_Text + + +END diff --git a/Database Scripts/Stored Procedures/usp_Assessments_Completion_For_Access_Key.proc.sql b/Database Scripts/Stored Procedures/usp_Assessments_Completion_For_Access_Key.proc.sql new file mode 100644 index 0000000000..c67b71aa07 --- /dev/null +++ b/Database Scripts/Stored Procedures/usp_Assessments_Completion_For_Access_Key.proc.sql @@ -0,0 +1,241 @@ + + + + +CREATE PROCEDURE [dbo].[usp_Assessments_Completion_For_Access_Key] +@accessKey varchar(20) +AS +BEGIN + SET NOCOUNT ON; + + --This procedure returns the number of answers and total number of available standard, maturity, and diagram questions + -- available for each of the user's assessments. + + --Creating table variables + declare @AssessmentCompletedQuestions table(AssessmentId INT, CompletedCount INT) + declare @AssessmentTotalMaturityQuestionsCount table(AssessmentId INT, TotalMaturityQuestionsCount INT) + declare @AssessmentTotalStandardQuestionsCount table(AssessmentId INT, TotalStandardQuestionsCount INT) + declare @AssessmentTotalDiagramQuestionsCount table(AssessmentId INT, TotalDiagramQuestionsCount INT) + + declare @ParentMatIds table(Id INT) + insert into @ParentMatIds select Parent_Question_Id from MATURITY_QUESTIONS where Parent_Question_Id is not null + + --Creating temp tables to hold applicable questions for each type of question + select a.Assessment_Id, mq.Mat_Question_Id into #AvailableMatQuestions + from MATURITY_QUESTIONS mq + join AVAILABLE_MATURITY_MODELS amm on amm.model_id = mq.Maturity_Model_Id + join MATURITY_MODELS mm on amm.model_id = mm.Maturity_Model_Id + join ASSESSMENTS a on a.Assessment_Id = amm.Assessment_Id + join ACCESS_KEY_ASSESSMENT aka on a.Assessment_Id = aka.Assessment_Id and aka.AccessKey = @accessKey + where a.UseMaturity = 1 and mm.Maturity_Level_Usage_Type = 'Static' + and mq.Mat_Question_Id not in (select Id from @ParentMatIds) + + + select a.Assessment_Id, mq.Mat_Question_Id, mq.Maturity_Level_Id into #AvailableMatQuestionsWithLevels + from MATURITY_QUESTIONS mq + join AVAILABLE_MATURITY_MODELS amm on amm.model_id = mq.Maturity_Model_Id + join MATURITY_MODELS mm on amm.model_id = mm.Maturity_Model_Id + join ASSESSMENTS a on a.Assessment_Id = amm.Assessment_Id + join ACCESS_KEY_ASSESSMENT aka on a.Assessment_Id = aka.Assessment_Id and aka.AccessKey = @accessKey + join ASSESSMENT_SELECTED_LEVELS asl on asl.Assessment_Id = a.Assessment_Id + join MATURITY_LEVELS ml on ml.Maturity_Level_Id = mq.Maturity_Level_Id + where a.UseMaturity = 1 + and asl.Level_Name = 'Maturity_Level' and asl.Standard_Specific_Sal_Level >= ml.Level and mm.Maturity_Level_Usage_Type = 'User_Selected' + and mq.Mat_Question_Id not in (select Id from @ParentMatIds) + + + -- special case for ISE + select a.Assessment_Id, mq.Mat_Question_Id, mq.Maturity_Level_Id into #AvailableMatQuestionsForIse + from MATURITY_QUESTIONS mq + join AVAILABLE_MATURITY_MODELS amm on amm.model_id = mq.Maturity_Model_Id + join ASSESSMENTS a on a.Assessment_Id = amm.Assessment_Id + join ACCESS_KEY_ASSESSMENT aka on a.Assessment_Id = aka.Assessment_Id and aka.AccessKey = @accessKey + join ASSESSMENT_SELECTED_LEVELS asl on asl.Assessment_Id = a.Assessment_Id and asl.Level_Name = 'Maturity_Level' + join MATURITY_LEVELS ml on ml.Maturity_Level_Id = mq.Maturity_Level_Id + where a.UseMaturity = 1 + and amm.model_id = 10 AND ml.Maturity_Level_Id = mq.Maturity_Level_Id AND ml.level = asl.Standard_Specific_Sal_Level + and mq.Mat_Question_Id not in (select Id from @ParentMatIds) + + + -- special case for VADR + select a.Assessment_Id, mq.Mat_Question_Id into #AvailableMatQuestionsForVadr + from MATURITY_QUESTIONS mq + join AVAILABLE_MATURITY_MODELS amm on amm.model_id = mq.Maturity_Model_Id + join ASSESSMENTS a on a.Assessment_Id = amm.Assessment_Id + join ACCESS_KEY_ASSESSMENT aka on a.Assessment_Id = aka.Assessment_Id and aka.AccessKey = @accessKey + where a.UseMaturity = 1 and amm.model_id = 7 + and mq.Parent_Question_Id is null + + + select a.Assessment_Id, q.question_Id into #AvailableQuestionBasedStandard + from NEW_QUESTION q + join NEW_QUESTION_SETS qs on q.Question_Id = qs.Question_Id + join NEW_QUESTION_LEVELS nql on qs.New_Question_Set_Id = nql.New_Question_Set_Id + join UNIVERSAL_SUB_CATEGORY_HEADINGS usch on q.Heading_Pair_Id = usch.Heading_Pair_Id + join AVAILABLE_STANDARDS stand on qs.Set_Name = stand.Set_Name + join QUESTION_GROUP_HEADING qgh on usch.Question_Group_Heading_Id = qgh.Question_Group_Heading_Id + join UNIVERSAL_SUB_CATEGORIES usc on usch.Universal_Sub_Category_Id = usc.Universal_Sub_Category_Id + join ASSESSMENTS a on a.Assessment_Id = stand.Assessment_Id + join STANDARD_SELECTION ss on ss.Assessment_Id = stand.Assessment_Id and Application_Mode = 'Questions Based' + join UNIVERSAL_SAL_LEVEL usl on ss.Selected_Sal_Level = usl.Full_Name_Sal + join ACCESS_KEY_ASSESSMENT aka on a.Assessment_Id = aka.Assessment_Id and aka.AccessKey = @accessKey + where a.UseStandard = 1 and stand.Selected = 1 and nql.Universal_Sal_Level = usl.Universal_Sal_Level + + + select a.Assessment_Id, r.Requirement_Id into #AvailableRequirementBasedStandard + from REQUIREMENT_SETS rs + join AVAILABLE_STANDARDS stand on stand.Set_Name = rs.Set_Name and stand.Selected = 1 + join NEW_REQUIREMENT r on r.Requirement_Id = rs.Requirement_Id + join ASSESSMENTS a on a.Assessment_Id = stand.Assessment_Id + join STANDARD_SELECTION ss on ss.Assessment_Id = a.assessment_Id and Application_Mode = 'Requirements Based' + join UNIVERSAL_SAL_LEVEL usl on usl.Full_Name_Sal = ss.Selected_Sal_Level + join REQUIREMENT_LEVELS rl on rl.Requirement_Id = r.Requirement_Id + join ACCESS_KEY_ASSESSMENT aka on a.Assessment_Id = aka.Assessment_Id and aka.AccessKey = @accessKey + where a.UseStandard = 1 and rl.Standard_Level = usl.Universal_Sal_Level + + + select a.Assessment_Id, q.Question_Id into #AvailableDiagramQuestions + from STANDARD_SELECTION ss + join + (select q.question_id, adc.assessment_id + from ASSESSMENT_DIAGRAM_COMPONENTS adc + join component_questions q on adc.Component_Symbol_Id = q.Component_Symbol_Id + join STANDARD_SELECTION ss on adc.Assessment_Id = ss.Assessment_Id + join new_question nq on q.question_id = nq.question_id + join new_question_sets qs on nq.question_id = qs.question_id + join DIAGRAM_CONTAINER l on adc.Layer_id = l.Container_Id + left join DIAGRAM_CONTAINER z on adc.Zone_Id = z.Container_Id + join NEW_QUESTION_LEVELS nql on qs.New_Question_Set_Id = nql.New_Question_Set_Id + where l.visible = 1) f on ss.assessment_id = f.assessment_id + join NEW_QUESTION q on f.Question_Id = q.Question_Id + join vQUESTION_HEADINGS h on q.Heading_Pair_Id = h.Heading_Pair_Id + join UNIVERSAL_SUB_CATEGORY_HEADINGS usch on usch.Heading_Pair_Id = h.Heading_Pair_Id + join Answer_Components ac on f.Question_Id = ac.Question_Or_Requirement_Id and f.assessment_id = ac.assessment_id + join ASSESSMENTS a on a.Assessment_Id = ss.Assessment_Id + join ACCESS_KEY_ASSESSMENT aka on a.Assessment_Id = aka.Assessment_Id and aka.AccessKey = @accessKey + where a.UseDiagram = 1 + + + insert into @AssessmentCompletedQuestions + select + AssessmentId = a.Assessment_Id, + CompletedCount = COUNT(DISTINCT(ans.Answer_Id)) + from ASSESSMENTS a + join ANSWER ans on ans.Assessment_Id = a.Assessment_Id + join ACCESS_KEY_ASSESSMENT aka on a.Assessment_Id = aka.Assessment_Id and aka.AccessKey = @accessKey + where ans.Answer_Text != 'U' + and --This ensures the completed question counts are accurate even if users switch assessments types later on + (ans.Question_Or_Requirement_Id in (select Mat_Question_Id from #AvailableMatQuestions amq + where amq.Assessment_Id = a.Assessment_Id) + or + ans.Question_Or_Requirement_Id in (select Mat_Question_Id from #AvailableMatQuestionsWithLevels amql + join ASSESSMENT_SELECTED_LEVELS asl on asl.Assessment_Id = a.Assessment_Id + join MATURITY_LEVELS ml on ml.Maturity_Level_Id = amql.Maturity_Level_Id + where asl.Level_Name = 'Maturity_Level' and asl.Standard_Specific_Sal_Level >= ml.Level) + or + ans.Question_Or_Requirement_Id in (select Question_Id from #AvailableQuestionBasedStandard aqbs + where aqbs.Assessment_Id = a.Assessment_Id) + or + ans.Question_Or_Requirement_Id in (select Requirement_Id from #AvailableRequirementBasedStandard arbs + where arbs.Assessment_Id = a.Assessment_Id) + or + ans.Question_Or_Requirement_Id in (select Question_Id from #AvailableDiagramQuestions ads + where ads.Assessment_Id = a.Assessment_Id) + OR + ans.Question_Or_Requirement_Id in (select Mat_Question_Id from #AvailableMatQuestionsForIse amqi + join ASSESSMENT_SELECTED_LEVELS asl on asl.Assessment_Id = a.Assessment_Id + join MATURITY_LEVELS ml on ml.Maturity_Level_Id = amqi.Maturity_Level_Id + where asl.Level_Name = 'Maturity_Level' and asl.Standard_Specific_Sal_Level = ml.Level) + or + ans.Question_Or_Requirement_Id in (select Mat_Question_Id from #AvailableMatQuestionsForVadr amqv + where amqv.Assessment_Id = a.Assessment_Id)) + group by a.Assessment_Id + + + --Place 0 in completed questions count for assessments that have no answers yet + insert into @AssessmentCompletedQuestions + select + AssessmentId = a.Assessment_Id, + CompletedCount = 0 + from ASSESSMENTS a + join ACCESS_KEY_ASSESSMENT aka on a.Assessment_Id = aka.Assessment_Id and aka.AccessKey = @accessKey + WHERE a.Assessment_Id + not in (select AssessmentId from @AssessmentCompletedQuestions) + + + --Maturity questions count (For maturity models with level selection) available to answer + insert into @AssessmentTotalMaturityQuestionsCount + select + AssessmentId = Assessment_Id, + TotalMaturityQuestionsCount = COUNT(DISTINCT(Mat_Question_Id)) + from #AvailableMatQuestionsWithLevels + group by Assessment_Id + + + --Total Maturity questions count (for maturity models without level selection) available to answer + insert into @AssessmentTotalMaturityQuestionsCount + select + AssessmentId = Assessment_Id, + TotalMaturityQuestionsCount = COUNT(DISTINCT(Mat_Question_Id)) + from #AvailableMatQuestions + group by Assessment_Id + + + --Total Maturity questions count for ISE available to answer + insert into @AssessmentTotalMaturityQuestionsCount + select + AssessmentId = Assessment_Id, + TotalMaturityQuestionsCount = COUNT(DISTINCT(Mat_Question_Id)) + from #AvailableMatQuestionsForIse + group by Assessment_Id + + + --Total Maturity questions count for VADR available to answer + insert into @AssessmentTotalMaturityQuestionsCount + select + AssessmentId = Assessment_Id, + TotalMaturityQuestionsCount = COUNT(DISTINCT(Mat_Question_Id)) + from #AvailableMatQuestionsForVadr + group by Assessment_Id + + + --Requirements based questions count + insert into @AssessmentTotalStandardQuestionsCount + select + AssessmentId = Assessment_Id, + TotalStandardQuestionsCount = COUNT(DISTINCT(Requirement_Id)) + from #AvailableRequirementBasedStandard + group by Assessment_Id + + + --Questions based standards questions count + insert into @AssessmentTotalStandardQuestionsCount + select + AssessmentId = Assessment_Id, + TotalStandardQuestionsCount = COUNT(DISTINCT(Question_Id)) + from #AvailableQuestionBasedStandard + group by Assessment_Id + + + --Total diagram questions count + insert into @AssessmentTotalDiagramQuestionsCount + select + AssessmentId = a.Assessment_Id, + TotalDiagramQuestionsCount = COUNT(ans.Answer_Id) + from ANSWER ans + join ASSESSMENTS a on a.Assessment_Id = ans.Assessment_Id + join ACCESS_KEY_ASSESSMENT aka on a.Assessment_Id = aka.Assessment_Id and aka.AccessKey = @accessKey + where a.UseDiagram = 1 and ans.Question_Type = 'Component' + group by a.Assessment_Id + + select + AssessmentId = acq.AssessmentId, + CompletedCount = acq.CompletedCount, + TotalMaturityQuestionsCount = atmq.TotalMaturityQuestionsCount, + TotalStandardQuestionsCount = atsq.TotalStandardQuestionsCount, + TotalDiagramQuestionsCount = atdq.TotalDiagramQuestionsCount + from @AssessmentCompletedQuestions acq + full join @AssessmentTotalMaturityQuestionsCount atmq on atmq.AssessmentId = acq.AssessmentId + full join @AssessmentTotalStandardQuestionsCount atsq on atsq.AssessmentId = acq.AssessmentId + full join @AssessmentTotalDiagramQuestionsCount atdq on atdq.AssessmentId = acq.AssessmentId +END diff --git a/Database Scripts/Stored Procedures/usp_Assessments_Completion_For_User.proc.sql b/Database Scripts/Stored Procedures/usp_Assessments_Completion_For_User.proc.sql index 159a882678..9e0b3a483b 100644 --- a/Database Scripts/Stored Procedures/usp_Assessments_Completion_For_User.proc.sql +++ b/Database Scripts/Stored Procedures/usp_Assessments_Completion_For_User.proc.sql @@ -1,4 +1,6 @@ + + CREATE PROCEDURE [dbo].[usp_Assessments_Completion_For_User] @User_Id int AS @@ -14,41 +16,62 @@ BEGIN declare @AssessmentTotalStandardQuestionsCount table(AssessmentId INT, TotalStandardQuestionsCount INT) declare @AssessmentTotalDiagramQuestionsCount table(AssessmentId INT, TotalDiagramQuestionsCount INT) - -- I don't like hardcoding in these model ids, but we have to manually declare which models utilize user selected levels to - -- filter questions since some maturity models default to ML 1, but also have questions above that level. - declare @MaturityModelsWithLevels table(ModelId INT) - declare @MaturityModelsWithoutLevels table (ModelId INT) - insert into @MaturityModelsWithLevels values (1), (2), (6), (7), (9), (10) - insert into @MaturityModelsWithoutLevels values (3), (4), (8), (5) - declare @ParentMatIds table(Id INT) insert into @ParentMatIds select Parent_Question_Id from MATURITY_QUESTIONS where Parent_Question_Id is not null + IF OBJECT_ID('tempdb..#AvailableMatQuestions') IS NOT NULL drop table #availableMatQuestions --Creating temp tables to hold applicable questions for each type of question select a.Assessment_Id, mq.Mat_Question_Id into #AvailableMatQuestions from MATURITY_QUESTIONS mq join AVAILABLE_MATURITY_MODELS amm on amm.model_id = mq.Maturity_Model_Id - full join ASSESSMENTS a on a.Assessment_Id = amm.Assessment_Id + join MATURITY_MODELS mm on amm.model_id = mm.Maturity_Model_Id + join ASSESSMENTS a on a.Assessment_Id = amm.Assessment_Id join USERS u on a.AssessmentCreatorId = u.UserId join ASSESSMENT_CONTACTS c on a.Assessment_Id = c.Assessment_Id and c.UserId = @User_Id - where u.UserId = @User_Id and a.UseMaturity = 1 and amm.model_id in (select ModelId from @MaturityModelsWithoutLevels) + where u.UserId = @User_Id and a.UseMaturity = 1 and mm.Maturity_Level_Usage_Type = 'Static' and mq.Mat_Question_Id not in (select Id from @ParentMatIds) - + IF OBJECT_ID('tempdb..#AvailableMatQuestionsWithLevels') IS NOT NULL drop table #AvailableMatQuestionsWithLevels select a.Assessment_Id, mq.Mat_Question_Id, mq.Maturity_Level_Id into #AvailableMatQuestionsWithLevels from MATURITY_QUESTIONS mq join AVAILABLE_MATURITY_MODELS amm on amm.model_id = mq.Maturity_Model_Id - full join ASSESSMENTS a on a.Assessment_Id = amm.Assessment_Id + join MATURITY_MODELS mm on amm.model_id = mm.Maturity_Model_Id + join ASSESSMENTS a on a.Assessment_Id = amm.Assessment_Id join USERS u on a.AssessmentCreatorId = u.UserId join ASSESSMENT_CONTACTS c on a.Assessment_Id = c.Assessment_Id and c.UserId = @User_Id join ASSESSMENT_SELECTED_LEVELS asl on asl.Assessment_Id = a.Assessment_Id join MATURITY_LEVELS ml on ml.Maturity_Level_Id = mq.Maturity_Level_Id where u.UserId = @User_Id and a.UseMaturity = 1 - and asl.Level_Name = 'Maturity_Level' and asl.Standard_Specific_Sal_Level >= ml.Level and amm.model_id in (select ModelId from @MaturityModelsWithLevels) + and asl.Level_Name = 'Maturity_Level' and asl.Standard_Specific_Sal_Level >= ml.Level and mm.Maturity_Level_Usage_Type = 'User_Selected' + and mq.Mat_Question_Id not in (select Id from @ParentMatIds) + + -- special case for ISE + IF OBJECT_ID('tempdb..#AvailableMatQuestionsForIse') IS NOT NULL drop table #AvailableMatQuestionsForIse + select a.Assessment_Id, mq.Mat_Question_Id, mq.Maturity_Level_Id into #AvailableMatQuestionsForIse + from MATURITY_QUESTIONS mq + join AVAILABLE_MATURITY_MODELS amm on amm.model_id = mq.Maturity_Model_Id + join ASSESSMENTS a on a.Assessment_Id = amm.Assessment_Id + join USERS u on a.AssessmentCreatorId = u.UserId + join ASSESSMENT_CONTACTS c on a.Assessment_Id = c.Assessment_Id and c.UserId = @User_Id + join ASSESSMENT_SELECTED_LEVELS asl on asl.Assessment_Id = a.Assessment_Id and asl.Level_Name = 'Maturity_Level' + join MATURITY_LEVELS ml on ml.Maturity_Level_Id = mq.Maturity_Level_Id + where u.UserId = @User_Id and a.UseMaturity = 1 + and amm.model_id = 10 AND ml.Maturity_Level_Id = mq.Maturity_Level_Id AND ml.level = asl.Standard_Specific_Sal_Level and mq.Mat_Question_Id not in (select Id from @ParentMatIds) + -- special case for VADR + IF OBJECT_ID('tempdb..#AvailableMatQuestionsForVadr') IS NOT NULL drop table #availableMatQuestionsForVadr + select a.Assessment_Id, mq.Mat_Question_Id into #AvailableMatQuestionsForVadr + from MATURITY_QUESTIONS mq + join AVAILABLE_MATURITY_MODELS amm on amm.model_id = mq.Maturity_Model_Id + join ASSESSMENTS a on a.Assessment_Id = amm.Assessment_Id + join USERS u on a.AssessmentCreatorId = u.UserId + join ASSESSMENT_CONTACTS c on a.Assessment_Id = c.Assessment_Id and c.UserId = @User_Id + where u.UserId = @User_Id and a.UseMaturity = 1 and amm.model_id = 7 + and mq.Parent_Question_Id is null - select a.Assessment_Id, q.question_Id into #AvailableQuestionBasedStandard + IF OBJECT_ID('tempdb..#AvailableQuestionBasedStandard') IS NOT NULL drop table #AvailableQuestionBasedStandard + select a.Assessment_Id, q.question_Id, ss.Selected_Sal_Level into #AvailableQuestionBasedStandard from NEW_QUESTION q join NEW_QUESTION_SETS qs on q.Question_Id = qs.Question_Id join NEW_QUESTION_LEVELS nql on qs.New_Question_Set_Id = nql.New_Question_Set_Id @@ -56,19 +79,19 @@ BEGIN join AVAILABLE_STANDARDS stand on qs.Set_Name = stand.Set_Name join QUESTION_GROUP_HEADING qgh on usch.Question_Group_Heading_Id = qgh.Question_Group_Heading_Id join UNIVERSAL_SUB_CATEGORIES usc on usch.Universal_Sub_Category_Id = usc.Universal_Sub_Category_Id - full join ASSESSMENTS a on a.Assessment_Id = stand.Assessment_Id + join ASSESSMENTS a on a.Assessment_Id = stand.Assessment_Id join STANDARD_SELECTION ss on ss.Assessment_Id = stand.Assessment_Id and Application_Mode = 'Questions Based' join UNIVERSAL_SAL_LEVEL usl on ss.Selected_Sal_Level = usl.Full_Name_Sal join USERS u on a.AssessmentCreatorId = u.UserId join ASSESSMENT_CONTACTS c on a.Assessment_Id = c.Assessment_Id and c.UserId = @User_Id - where u.UserId = @User_Id and a.UseStandard = 1 and stand.Selected = 1 and nql.Universal_Sal_Level = usl.Universal_Sal_Level - + where u.UserId = @User_Id and a.UseStandard = 1 and stand.Selected = 1 and nql.Universal_Sal_Level = usl.Universal_Sal_Level + IF OBJECT_ID('tempdb..#AvailableRequirementBasedStandard') IS NOT NULL drop table #AvailableRequirementBasedStandard select a.Assessment_Id, r.Requirement_Id into #AvailableRequirementBasedStandard from REQUIREMENT_SETS rs join AVAILABLE_STANDARDS stand on stand.Set_Name = rs.Set_Name and stand.Selected = 1 join NEW_REQUIREMENT r on r.Requirement_Id = rs.Requirement_Id - full join ASSESSMENTS a on a.Assessment_Id = stand.Assessment_Id + join ASSESSMENTS a on a.Assessment_Id = stand.Assessment_Id join STANDARD_SELECTION ss on ss.Assessment_Id = a.assessment_Id and Application_Mode = 'Requirements Based' join UNIVERSAL_SAL_LEVEL usl on usl.Full_Name_Sal = ss.Selected_Sal_Level join REQUIREMENT_LEVELS rl on rl.Requirement_Id = r.Requirement_Id @@ -76,7 +99,7 @@ BEGIN join ASSESSMENT_CONTACTS c on a.Assessment_Id = c.Assessment_Id and c.UserId = @User_Id where u.UserId = @User_Id and a.UseStandard = 1 and rl.Standard_Level = usl.Universal_Sal_Level - + IF OBJECT_ID('tempdb..#AvailableDiagramQuestions') IS NOT NULL drop table #AvailableDiagramQuestions select a.Assessment_Id, q.Question_Id into #AvailableDiagramQuestions from STANDARD_SELECTION ss join @@ -94,7 +117,7 @@ BEGIN join vQUESTION_HEADINGS h on q.Heading_Pair_Id = h.Heading_Pair_Id join UNIVERSAL_SUB_CATEGORY_HEADINGS usch on usch.Heading_Pair_Id = h.Heading_Pair_Id join Answer_Components ac on f.Question_Id = ac.Question_Or_Requirement_Id and f.assessment_id = ac.assessment_id - full join ASSESSMENTS a on a.Assessment_Id = ss.Assessment_Id + join ASSESSMENTS a on a.Assessment_Id = ss.Assessment_Id join USERS u on a.AssessmentCreatorId = u.UserId join ASSESSMENT_CONTACTS c on a.Assessment_Id = c.Assessment_Id and c.UserId = @User_Id where u.UserId = @User_Id and a.UseDiagram = 1 @@ -103,25 +126,38 @@ BEGIN insert into @AssessmentCompletedQuestions select AssessmentId = a.Assessment_Id, - CompletedCount = COUNT(ans.Answer_Id) + CompletedCount = COUNT(DISTINCT(ans.Answer_Id)) from ASSESSMENTS a join ANSWER ans on ans.Assessment_Id = a.Assessment_Id join USERS u on a.AssessmentCreatorId = u.UserId join ASSESSMENT_CONTACTS c on a.Assessment_Id = c.Assessment_Id and c.UserId = @User_Id - where u.UserId = @User_Id and ans.Answer_Text != 'U' + where u.UserId = @User_Id and ans.Answer_Text != 'U' and --This ensures the completed question counts are accurate even if users switch assessments types later on - (ans.Question_Or_Requirement_Id in (select Mat_Question_Id from #AvailableMatQuestions) + (ans.Question_Or_Requirement_Id in (select Mat_Question_Id from #AvailableMatQuestions avq + where avq.Assessment_Id = a.Assessment_Id) or ans.Question_Or_Requirement_Id in (select Mat_Question_Id from #AvailableMatQuestionsWithLevels amql join ASSESSMENT_SELECTED_LEVELS asl on asl.Assessment_Id = a.Assessment_Id join MATURITY_LEVELS ml on ml.Maturity_Level_Id = amql.Maturity_Level_Id where asl.Level_Name = 'Maturity_Level' and asl.Standard_Specific_Sal_Level >= ml.Level) or - ans.Question_Or_Requirement_Id in (select Question_Id from #AvailableQuestionBasedStandard) + ans.Question_Or_Requirement_Id in (select aqbs.Question_Id from #AvailableQuestionBasedStandard aqbs + where aqbs.Assessment_Id = a.Assessment_Id) + or + ans.Question_Or_Requirement_Id in (select Requirement_Id from #AvailableRequirementBasedStandard arbs + where arbs.Assessment_Id = a.Assessment_Id) or - ans.Question_Or_Requirement_Id in (select Requirement_Id from #AvailableRequirementBasedStandard) + ans.Question_Or_Requirement_Id in (select Question_Id from #AvailableDiagramQuestions adq + where adq.Assessment_Id = a.Assessment_Id) or - ans.Question_Or_Requirement_Id in (select Question_Id from #AvailableDiagramQuestions)) + ans.Question_Or_Requirement_Id in (select Mat_Question_Id from #AvailableMatQuestionsForIse amqi + join ASSESSMENT_SELECTED_LEVELS asl on asl.Assessment_Id = a.Assessment_Id + join MATURITY_LEVELS ml on ml.Maturity_Level_Id = amqi.Maturity_Level_Id + where asl.Level_Name = 'Maturity_Level' and asl.Standard_Specific_Sal_Level = ml.Level) + or + ans.Question_Or_Requirement_Id in (select Mat_Question_Id from #AvailableMatQuestionsForVadr amqv + where amqv.Assessment_Id = a.Assessment_Id) + ) group by a.Assessment_Id @@ -152,8 +188,26 @@ BEGIN TotalMaturityQuestionsCount = COUNT(DISTINCT(Mat_Question_Id)) from #AvailableMatQuestions group by Assessment_Id + + + --Total Maturity questions count for ISE available to answer + insert into @AssessmentTotalMaturityQuestionsCount + select + AssessmentId = Assessment_Id, + TotalMaturityQuestionsCount = COUNT(DISTINCT(Mat_Question_Id)) + from #AvailableMatQuestionsForIse + group by Assessment_Id + --Total Maturity questions count for VADR available to answer + insert into @AssessmentTotalMaturityQuestionsCount + select + AssessmentId = Assessment_Id, + TotalMaturityQuestionsCount = COUNT(DISTINCT(Mat_Question_Id)) + from #AvailableMatQuestionsForVadr + group by Assessment_Id + + --Requirements based questions count insert into @AssessmentTotalStandardQuestionsCount select @@ -184,6 +238,7 @@ BEGIN where u.UserId = @User_Id and a.UseDiagram = 1 and ans.Question_Type = 'Component' group by a.Assessment_Id + select AssessmentId = acq.AssessmentId, CompletedCount = acq.CompletedCount, @@ -194,4 +249,5 @@ BEGIN full join @AssessmentTotalMaturityQuestionsCount atmq on atmq.AssessmentId = acq.AssessmentId full join @AssessmentTotalStandardQuestionsCount atsq on atsq.AssessmentId = acq.AssessmentId full join @AssessmentTotalDiagramQuestionsCount atdq on atdq.AssessmentId = acq.AssessmentId + END diff --git a/Database Scripts/Stored Procedures/usp_Assessments_For_User.proc.sql b/Database Scripts/Stored Procedures/usp_Assessments_For_User.proc.sql index c3feb0bace..2ac94dc257 100644 --- a/Database Scripts/Stored Procedures/usp_Assessments_For_User.proc.sql +++ b/Database Scripts/Stored Procedures/usp_Assessments_For_User.proc.sql @@ -37,6 +37,8 @@ select UseMaturity, workflow, SelectedMaturityModel = m.Model_Name, + iseSubmitted = i.Ise_Submitted, + submittedDate = i.Submitted_Date, SelectedStandards = string_agg(s.Short_Name, ', '), case when a.assessment_id in (select assessment_id from @ATM) then CAST(1 AS BIT) else CAST(0 AS BIT) END as AltTextMissing, c.UserId @@ -71,7 +73,8 @@ select where c.UserId = @User_Id group by a.Assessment_Id, Assessment_Name, Assessment_Date, AssessmentCreatedDate, LastModifiedDate, mark_for_review, UseDiagram, - UseStandard, UseMaturity, Workflow, Model_Name, c.UserId + UseStandard, UseMaturity, Workflow, Model_Name, + Ise_Submitted, Submitted_Date, c.UserId diff --git a/Database Scripts/Stored Procedures/usp_countsForLevelsByGroupMaturityModel.proc.sql b/Database Scripts/Stored Procedures/usp_countsForLevelsByGroupMaturityModel.proc.sql new file mode 100644 index 0000000000..59e6c8cb67 --- /dev/null +++ b/Database Scripts/Stored Procedures/usp_countsForLevelsByGroupMaturityModel.proc.sql @@ -0,0 +1,24 @@ +-- ============================================= +-- Author: hansbk +-- Create date: 11/3/2022 +-- Description: getting all the counts for a mat,grouping,level and answer +-- ============================================= +CREATE PROCEDURE [dbo].[usp_countsForLevelsByGroupMaturityModel] + -- Add the parameters for the stored procedure here + @assessment_id int, + @mat_model_id int +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + select a.*,b.Answer_Text as Answer_Text2,b.answer_count from ( + select distinct GROUPING_ID,Maturity_Level_Id, Answer_Text + from MATURITY_QUESTIONS, (select ANSWER_text from ANSWER_LOOKUP where Answer_Text in ('Y','U','N')) ans + where Maturity_Model_Id = @mat_model_id) a left join ( + select q.Grouping_Id,q.Maturity_Level_Id, a.Answer_Text, count(a.Answer_Text) answer_count from ANSWER a + join MATURITY_QUESTIONS q on a.Question_Or_Requirement_Id = q.Mat_Question_Id + join MATURITY_LEVELS l on q.Maturity_Level_Id = l.Maturity_Level_Id + where a.Question_Type = 'Maturity' and Assessment_Id = @assessment_id + group by q.Grouping_Id, q.Maturity_Level_Id, a.Answer_Text) b on a.Grouping_Id=b.Grouping_Id and a.Maturity_Level_Id=b.Maturity_Level_Id and a.Answer_Text=b.Answer_Text +END diff --git a/Database Scripts/Stored Procedures/usp_getCSETQuestionsForCRRM.proc.sql b/Database Scripts/Stored Procedures/usp_getCSETQuestionsForCRRM.proc.sql new file mode 100644 index 0000000000..a83a6bf8e7 --- /dev/null +++ b/Database Scripts/Stored Procedures/usp_getCSETQuestionsForCRRM.proc.sql @@ -0,0 +1,32 @@ +-- ============================================= +-- Author: hansbk +-- Create date: 8/15/2023 +-- Description: gets the general questions regardless of maturity,new_question,or new_requirement +-- ============================================= +CREATE PROCEDURE [dbo].[usp_getCSETQuestionsForCRRM] + -- Add the parameters for the stored procedure here + @setname varchar(100) +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + select Type='q', q.question_id as Id,Simple_Question as question,r.Supplemental_Info as Info,h.Question_Group_Heading as Heading,h.Universal_Sub_Category as SubHeading,Set_Name as SetName + from NEW_QUESTION q + join REQUIREMENT_QUESTIONS_SETS s on q.Question_Id=s.Question_Id + join NEW_REQUIREMENT r on s.Requirement_Id=r.Requirement_Id + join vQUESTION_HEADINGS h on q.Heading_Pair_Id=h.Heading_Pair_Id + where s.Set_Name = @setname + union + select Type='r', r.Requirement_Id as Id, r.Requirement_Text as question,r.Supplemental_Info as Info,r.Standard_Category as Heading,r.Standard_Sub_Category as SubHeading,s.Set_Name as setname + from REQUIREMENT_QUESTIONS_SETS s + join NEW_REQUIREMENT r on s.Requirement_Id=r.Requirement_Id + where s.Set_Name = @setname + union + select Type='m', mat_question_id as Id ,Question_Text as queestion,Supplemental_Info as Info,g.Title as Heading, Question_Title as SubHeading, m.Model_Name as setname + from MATURITY_QUESTIONS q + join MATURITY_GROUPINGS g on q.Grouping_Id=g.Grouping_Id + join MATURITY_MODELS m on q.Maturity_Model_Id=m.Maturity_Model_Id and g.Maturity_Model_Id=m.Maturity_Model_Id + where m.Model_Name = @setname +END diff --git a/Database Scripts/Stored Procedures/usp_getFinancialQuestions.proc.sql b/Database Scripts/Stored Procedures/usp_getFinancialQuestions.proc.sql index cd2f60c100..7c7b8104b8 100644 --- a/Database Scripts/Stored Procedures/usp_getFinancialQuestions.proc.sql +++ b/Database Scripts/Stored Procedures/usp_getFinancialQuestions.proc.sql @@ -13,12 +13,12 @@ BEGIN -- Insert statements for procedure here select r.Requirement_title, r.Requirement_text, a.Answer_text, m.MaturityLevel from - filtersNormalized f - join FINANCIAL_GROUPS g on f.domainid = g.domainid and f.MaturityId = g.MaturityId - join FINANCIAL_MATURITY m on g.MaturityId = m.MaturityId + FINANCIAL_DOMAIN_FILTERS_V2 f + join FINANCIAL_GROUPS g on f.domainid = g.domainid and f.Financial_Level_Id = g.Financial_Level_Id + join FINANCIAL_MATURITY m on g.Financial_Level_Id = m.Financial_Level_Id join FINANCIAL_DETAILS fd on g.FinancialGroupId = fd.FinancialGroupId join FINANCIAL_REQUIREMENTS fr on fd.StmtNumber = fr.StmtNumber join NEW_REQUIREMENT r on fr.Requirement_Id=r.Requirement_Id join Answer_Requirements a on r.requirement_id = a.Question_Or_Requirement_Id -where a.assessment_id = @assessment_id and f.assessment_id = @assessment_id +where a.assessment_id = @assessment_id and f.assessment_id = @assessment_id and f.IsOn = 1 END diff --git a/Database Scripts/Stored Procedures/usp_getRRASummary.proc.sql b/Database Scripts/Stored Procedures/usp_getRRASummary.proc.sql index 315baf1fae..f29188b9ed 100644 --- a/Database Scripts/Stored Procedures/usp_getRRASummary.proc.sql +++ b/Database Scripts/Stored Procedures/usp_getRRASummary.proc.sql @@ -1,16 +1,9 @@ -USE [CSETWeb] -GO -/****** Object: StoredProcedure [dbo].[usp_getRRASummary] Script Date: 10/11/2023 8:20:28 AM ******/ -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= -ALTER PROCEDURE [dbo].[usp_getRRASummary] +CREATE PROCEDURE [dbo].[usp_getRRASummary] @assessment_id int AS BEGIN diff --git a/Database Scripts/Stored Procedures/usp_getRRASummaryByGoal.proc.sql b/Database Scripts/Stored Procedures/usp_getRRASummaryByGoal.proc.sql index 68b2f66980..4027b08bbd 100644 --- a/Database Scripts/Stored Procedures/usp_getRRASummaryByGoal.proc.sql +++ b/Database Scripts/Stored Procedures/usp_getRRASummaryByGoal.proc.sql @@ -1,21 +1,16 @@ -USE [CSETWeb] -GO -/****** Object: StoredProcedure [dbo].[usp_getRRASummaryByGoal] Script Date: 10/11/2023 8:20:54 AM ******/ -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= -ALTER PROCEDURE [dbo].[usp_getRRASummaryByGoal] +CREATE PROCEDURE [dbo].[usp_getRRASummaryByGoal] @assessment_id int AS BEGIN SET NOCOUNT ON; + --select Answer_Full_Name = N'Yes',Title=N'Robust Data Backup (DB)', Sequence=1, Answer_Text=N'Y',qc=0,Total=0,[Percent]=0 + select * into #MQ from [dbo].[func_MQ](@assessment_id) select * into #AM from [dbo].[func_AM](@assessment_id) select * into #MG from MATURITY_GROUPINGS where grouping_id in (select grouping_id from #MQ) @@ -29,7 +24,7 @@ BEGIN (select * from #MG, ANSWER_LOOKUP where Maturity_Model_Id = 5 and answer_text in ('Y','N','U') and Group_Level = 2) a left join ( SELECT g.Title, g.Sequence, a.Answer_Text, isnull(count(question_or_requirement_id),0) qc , SUM(count(Answer_Text)) OVER(PARTITION BY Title) AS Total - FROM Answer_Maturity a + FROM #AM a join ( select q.Mat_Question_Id, g.* from #MQ q join #MG g on q.Grouping_Id = g.Grouping_Id and q.Maturity_Model_Id = g.Maturity_Model_Id diff --git a/Database Scripts/Stored Procedures/usp_getRRASummaryByGoalOverall.proc.sql b/Database Scripts/Stored Procedures/usp_getRRASummaryByGoalOverall.proc.sql index d504690512..19af38f356 100644 --- a/Database Scripts/Stored Procedures/usp_getRRASummaryByGoalOverall.proc.sql +++ b/Database Scripts/Stored Procedures/usp_getRRASummaryByGoalOverall.proc.sql @@ -1,16 +1,9 @@ -USE [CSETWeb] -GO -/****** Object: StoredProcedure [dbo].[usp_getRRASummaryByGoalOverall] Script Date: 10/11/2023 8:21:17 AM ******/ -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= -ALTER PROCEDURE [dbo].[usp_getRRASummaryByGoalOverall] +CREATE PROCEDURE [dbo].[usp_getRRASummaryByGoalOverall] @assessment_id int AS BEGIN diff --git a/Database Scripts/Stored Procedures/usp_getRRASummaryOverall.proc.sql b/Database Scripts/Stored Procedures/usp_getRRASummaryOverall.proc.sql index d74d58c358..b25997312c 100644 --- a/Database Scripts/Stored Procedures/usp_getRRASummaryOverall.proc.sql +++ b/Database Scripts/Stored Procedures/usp_getRRASummaryOverall.proc.sql @@ -1,16 +1,9 @@ -USE [CSETWeb] -GO -/****** Object: StoredProcedure [dbo].[usp_getRRASummaryOverall] Script Date: 10/11/2023 8:19:56 AM ******/ -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= -ALTER PROCEDURE [dbo].[usp_getRRASummaryOverall] +CREATE PROCEDURE [dbo].[usp_getRRASummaryOverall] @assessment_id int AS BEGIN diff --git a/Database Scripts/Stored Procedures/usp_getStandardsResultsByCategory.proc.sql b/Database Scripts/Stored Procedures/usp_getStandardsResultsByCategory.proc.sql index 63a5f2d176..4b8055a058 100644 --- a/Database Scripts/Stored Procedures/usp_getStandardsResultsByCategory.proc.sql +++ b/Database Scripts/Stored Procedures/usp_getStandardsResultsByCategory.proc.sql @@ -10,6 +10,9 @@ BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; + + SET TRANSACTION ISOLATION LEVEL read uncommitted + /* TODO this needs to take into account requirements vs questions get the question set then for all the questions take the total risk (in this set only) diff --git a/Database Scripts/Stored Procedures/usp_getVADRSummaryByGoal.proc.sql b/Database Scripts/Stored Procedures/usp_getVADRSummaryByGoal.proc.sql index fbe78a337a..f7e699622f 100644 --- a/Database Scripts/Stored Procedures/usp_getVADRSummaryByGoal.proc.sql +++ b/Database Scripts/Stored Procedures/usp_getVADRSummaryByGoal.proc.sql @@ -1,34 +1,37 @@ -- ============================================= --- Author: Luke Galloway, Lilianne Cantillo +-- Author: Luke Galloway, Lilianne Cantillo -- Create date: 5-17-2022 --- Description: Gets the summary data for VADR report. +-- Description: Gets the summary data for VADR report. -- ============================================= CREATE PROCEDURE [dbo].[usp_getVADRSummaryByGoal] @assessment_id int AS BEGIN - SET NOCOUNT ON; + SET NOCOUNT ON; - select a.Answer_Full_Name, a.Title, a.Sequence, a.Answer_Text, - isnull(m.qc,0) as [qc], - isnull(m.Total,0) as [Total], - IsNull(Cast(IsNull(Round((Cast((qc) as float)/(IsNull(NullIf(Total,0),1)))*100, 2), 0) as float),0) as [Percent] - from - (select * from MATURITY_GROUPINGS, ANSWER_LOOKUP - where Maturity_Model_Id = 7 and answer_text in ('Y','N','A','U') and Group_Level = 2) a left join ( - SELECT g.Title, g.Sequence, a.Answer_Text, isnull(count(question_or_requirement_id),0) qc , SUM(count(Answer_Text)) OVER(PARTITION BY Title) AS Total - FROM Answer_Maturity a - join ( - select q.Mat_Question_Id, g.* - from MATURITY_QUESTIONS q - join MATURITY_GROUPINGS g on q.Grouping_Id=g.Grouping_Id and q.Maturity_Model_Id = g.Maturity_Model_Id - where q.Parent_Question_Id is null -- don't count child freeform text questions; they aren't answered y,n, etc. - and g.Maturity_Model_Id = 7 and Group_Level = 2 - ) g on a.Question_Or_Requirement_Id = g.Mat_Question_Id - where a.Assessment_Id = @assessment_id and Is_Maturity = 1 - group by a.Assessment_Id, g.Title, g.Sequence, a.Answer_Text) - m on a.Title = m.Title and a.Answer_Text = m.Answer_Text - join ANSWER_ORDER o on a.Answer_Text = o.answer_text - order by a.Sequence, o.answer_order + select a.Answer_Full_Name, a.Title, a.Sequence, a.Answer_Text, + isnull(m.qc,0) as [qc], + isnull(m.Total,0) as [Total], + IsNull(Cast(IsNull(Round((Cast((qc) as float)/(IsNull(NullIf(Total,0),1)))*100, 2), 0) as float),0) as [Percent] + from + (select * from MATURITY_GROUPINGS, ANSWER_LOOKUP + where Maturity_Model_Id = 7 and answer_text in ('Y','N','A','U') and Group_Level = 2) a left join ( + SELECT g.Title, g.Sequence, a.Answer_Text, isnull(count(question_or_requirement_id),0) qc , SUM(count(Answer_Text)) OVER(PARTITION BY Title) AS Total + FROM Answer_Maturity a + join ( + select q.Mat_Question_Id, g.* + from MATURITY_QUESTIONS q + join MATURITY_GROUPINGS g on q.Grouping_Id=g.Grouping_Id and q.Maturity_Model_Id = g.Maturity_Model_Id + where q.Parent_Question_Id is null -- don't count child freeform text questions; they aren't answered y,n, etc. + and g.Maturity_Model_Id = 7 and Group_Level = 2 + ) g on a.Question_Or_Requirement_Id = g.Mat_Question_Id + where a.Assessment_Id = @assessment_id and Is_Maturity = 1 + group by a.Assessment_Id, g.Title, g.Sequence, a.Answer_Text) + m on a.Title = m.Title and a.Answer_Text = m.Answer_Text + join ANSWER_ORDER o on a.Answer_Text = o.answer_text + order by a.Sequence, o.answer_order END + + + diff --git a/Database Scripts/Stored Procedures/usp_getVADRSummaryByGoalOverall.proc.sql b/Database Scripts/Stored Procedures/usp_getVADRSummaryByGoalOverall.proc.sql index af3dc86993..4187f72d38 100644 --- a/Database Scripts/Stored Procedures/usp_getVADRSummaryByGoalOverall.proc.sql +++ b/Database Scripts/Stored Procedures/usp_getVADRSummaryByGoalOverall.proc.sql @@ -1,33 +1,34 @@ -- ============================================= --- Author: Luke Galloway, Lilianne Cantillo +-- Author: Luke Galloway, Lilianne Cantillo -- Create date: 5-17-2022 --- Description: Gets the summary data for VADR report. +-- Description: Gets the summary data for VADR report. -- ============================================= CREATE PROCEDURE [dbo].[usp_getVADRSummaryByGoalOverall] @assessment_id int AS BEGIN - SET NOCOUNT ON; + SET NOCOUNT ON; - select a.Title, - isnull(m.qc,0) as [qc], - isnull(m.Total,0) as [Total], - IsNull(Cast(IsNull(Round((Cast((qc) as float)/(IsNull(NullIf(Total,0),1)))*100, 2), 0) as float),0) as [Percent] - from - (select * from MATURITY_GROUPINGS - where Maturity_Model_Id = 7 and Group_Level = 2) a left join ( - SELECT g.Title, isnull(count(question_or_requirement_id),0) qc , SUM(count(Title)) OVER(PARTITION BY assessment_id) AS Total - FROM Answer_Maturity a - join ( - select q.Mat_Question_Id, g.* - from MATURITY_QUESTIONS q - join MATURITY_GROUPINGS g on q.Grouping_Id=g.Grouping_Id and q.Maturity_Model_Id=g.Maturity_Model_Id - where q.Parent_Question_Id is null -- don't count child freeform text questions; they aren't answered y,n, etc. - and g.Maturity_Model_Id=7 and Group_Level = 2 - ) g on a.Question_Or_Requirement_Id=g.Mat_Question_Id - where a.Assessment_Id = @assessment_id and Is_Maturity = 1 --@assessment_id - group by a.Assessment_Id, g.Title) - m on a.Title=m.Title - order by a.Sequence + select a.Title, + isnull(m.qc,0) as [qc], + isnull(m.Total,0) as [Total], + IsNull(Cast(IsNull(Round((Cast((qc) as float)/(IsNull(NullIf(Total,0),1)))*100, 2), 0) as float),0) as [Percent] + from + (select * from MATURITY_GROUPINGS + where Maturity_Model_Id = 7 and Group_Level = 2) a left join ( + SELECT g.Title, isnull(count(question_or_requirement_id),0) qc , SUM(count(Title)) OVER(PARTITION BY assessment_id) AS Total + FROM Answer_Maturity a + join ( + select q.Mat_Question_Id, g.* + from MATURITY_QUESTIONS q + join MATURITY_GROUPINGS g on q.Grouping_Id=g.Grouping_Id and q.Maturity_Model_Id=g.Maturity_Model_Id + where q.Parent_Question_Id is null -- don't count child freeform text questions; they aren't answered y,n, etc. + and g.Maturity_Model_Id=7 and Group_Level = 2 + ) g on a.Question_Or_Requirement_Id=g.Mat_Question_Id + where a.Assessment_Id = @assessment_id and Is_Maturity = 1 --@assessment_id + group by a.Assessment_Id, g.Title) + m on a.Title=m.Title + order by a.Sequence END + diff --git a/Database Scripts/Views/Answer_Components.view.sql b/Database Scripts/Views/Answer_Components.view.sql index 002c7612ff..3717bc97f9 100644 --- a/Database Scripts/Views/Answer_Components.view.sql +++ b/Database Scripts/Views/Answer_Components.view.sql @@ -1,8 +1,7 @@ - - CREATE VIEW [dbo].[Answer_Components] AS -SELECT Answer_Id, Assessment_Id, Mark_For_Review, Comment, Alternate_Justification, Is_Requirement, Question_Or_Requirement_Id, Question_Number, Answer_Text, Component_Guid, Is_Component, Is_Framework, - Reviewed, FeedBack -FROM dbo.ANSWER -WHERE (Is_Requirement = 0) AND (Is_Component = 1) +SELECT a.Answer_Id, a.Assessment_Id, a.Mark_For_Review, a.Comment, a.Alternate_Justification, a.Is_Requirement, a.Question_Or_Requirement_Id, a.Question_Number, a.Answer_Text, a.Component_Guid, a.Is_Component, a.Is_Framework, + a.Reviewed, a.FeedBack, q.Simple_Question AS QuestionText +FROM dbo.ANSWER AS a INNER JOIN + dbo.NEW_QUESTION AS q ON q.Question_Id = a.Question_Or_Requirement_Id +WHERE (a.Is_Requirement = 0) AND (a.Is_Component = 1) diff --git a/Database Scripts/Views/vFinancialGroups.view.sql b/Database Scripts/Views/vFinancialGroups.view.sql index d1ed958c03..e5d37f6beb 100644 --- a/Database Scripts/Views/vFinancialGroups.view.sql +++ b/Database Scripts/Views/vFinancialGroups.view.sql @@ -1,9 +1,10 @@ + CREATE VIEW [dbo].[vFinancialGroups] AS SELECT dbo.FINANCIAL_GROUPS.FinancialGroupId, dbo.FINANCIAL_DOMAINS.Domain, dbo.FINANCIAL_MATURITY.MaturityLevel, dbo.FINANCIAL_ASSESSMENT_FACTORS.AssessmentFactor, dbo.FINANCIAL_COMPONENTS.FinComponent FROM dbo.FINANCIAL_GROUPS INNER JOIN dbo.FINANCIAL_DOMAINS ON dbo.FINANCIAL_GROUPS.DomainId = dbo.FINANCIAL_DOMAINS.DomainId INNER JOIN - dbo.FINANCIAL_MATURITY ON dbo.FINANCIAL_GROUPS.MaturityId = dbo.FINANCIAL_MATURITY.MaturityId INNER JOIN + dbo.FINANCIAL_MATURITY ON dbo.FINANCIAL_GROUPS.Financial_Level_Id = dbo.FINANCIAL_MATURITY.Financial_Level_Id INNER JOIN dbo.FINANCIAL_ASSESSMENT_FACTORS ON dbo.FINANCIAL_GROUPS.AssessmentFactorId = dbo.FINANCIAL_ASSESSMENT_FACTORS.AssessmentFactorId INNER JOIN dbo.FINANCIAL_COMPONENTS ON dbo.FINANCIAL_GROUPS.FinComponentId = dbo.FINANCIAL_COMPONENTS.FinComponentId