Skip to content

Commit

Permalink
Ran ProcViewSerializer to put latest procs into source control
Browse files Browse the repository at this point in the history
  • Loading branch information
randywoods1 committed Dec 13, 2023
1 parent f1976ef commit 7efa341
Show file tree
Hide file tree
Showing 25 changed files with 633 additions and 149 deletions.
4 changes: 2 additions & 2 deletions CSETWebApi/CSETWeb_Api/ProcViewSerializer/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<connectionStrings>
<add name="CSET_DB" connectionString="data source=(localdb)\mssqllocaldb;initial catalog=CSETWeb;persist security info=True;Integrated Security=SSPI;MultipleActiveResultSets=True"/>
<add name="CSET_DB" connectionString="data source=nhswebdev1;initial catalog=CSETWebtest;persist security info=True;Integrated Security=SSPI;MultipleActiveResultSets=True"/>
</connectionStrings>
<appSettings>
<add key="Destination Path" value="C:\src\Repos\cset\Database Scripts"/>
<add key="Destination Path" value="C:\src\repos\cset\cset\Database Scripts"/>
</appSettings>
</configuration>
9 changes: 1 addition & 8 deletions Database Scripts/Functions/func_AM.func.sql
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
)
Expand Down
9 changes: 1 addition & 8 deletions Database Scripts/Functions/func_MQ.func.sql
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions Database Scripts/Stored Procedures/GetChildrenAnswers.proc.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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
22 changes: 19 additions & 3 deletions Database Scripts/Stored Procedures/GetRelevantAnswers.proc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
13 changes: 2 additions & 11 deletions Database Scripts/Stored Procedures/Get_Merge_Conflicts.proc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -167,38 +164,32 @@ 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
((e.Answer_Text != 'U' AND g.Answer_Text != 'U') AND (e.Answer_Text != g.Answer_Text)) OR
((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
32 changes: 32 additions & 0 deletions Database Scripts/Stored Procedures/IseAnswerDistribution.proc.sql
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 7efa341

Please sign in to comment.