Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d877963
Bump fast-xml-builder from 1.1.5 to 1.2.0
dependabot[bot] May 8, 2026
41c91fc
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas May 11, 2026
342270f
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas May 12, 2026
a62c429
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas May 12, 2026
8ae2bb7
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas May 13, 2026
7016a1c
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas May 14, 2026
2f9926e
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas May 19, 2026
d646a3e
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas May 20, 2026
e76ab80
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas May 26, 2026
cf71581
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas May 27, 2026
6fc4d8d
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas May 27, 2026
e639e05
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas Jun 1, 2026
dc9c625
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas Jun 1, 2026
d21bac5
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas Jun 4, 2026
d8e6c6b
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas Jun 8, 2026
deba56d
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas Jun 8, 2026
7707931
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas Jun 10, 2026
6a7b1ef
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas Jun 12, 2026
bcb7763
TTAHUB-5378 Fix CLASS same grant matching and align widget/page counts
kryswisnaskas Jun 16, 2026
e3eff6d
Fix the cleanup helper
kryswisnaskas Jun 16, 2026
04fe0c5
Merge remote-tracking branch 'origin/main' into kw/ttahub-5378
kryswisnaskas Jun 16, 2026
bb63b86
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas Jun 16, 2026
1f02608
align QA CLASS widget counts and detail rows by grant
kryswisnaskas Jun 17, 2026
55a6897
Merge remote-tracking branch 'origin/main' into kw/ttahub-5378
kryswisnaskas Jun 18, 2026
6971932
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas Jun 18, 2026
632b175
Remove unused http-proxy-middleware package
thewatermethod Jun 18, 2026
7ffdc7a
Merge remote-tracking branch 'origin/mb/TTAHUB-5465/remove-http-proxy…
kryswisnaskas Jun 18, 2026
78e9549
Merge branch 'main' of https://github.com/HHS/Head-Start-TTADP
kryswisnaskas Jun 22, 2026
39b491e
Merge branch 'main' into kw/ttahub-5378
kryswisnaskas Jun 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 162 additions & 70 deletions src/queries/api/dashboards/qa/class.sql
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,10 @@ END $$;
WITH
requested_datasets AS (
SELECT
(
NULLIF(current_setting('ssdi.dataSetSelection', true), '') IS NULL
OR COALESCE(NULLIF(current_setting('ssdi.dataSetSelection', true), ''), '[]')::jsonb @> '["with_class_widget"]'::jsonb
) AS include_with_class_widget,
(
NULLIF(current_setting('ssdi.dataSetSelection', true), '') IS NULL
OR COALESCE(NULLIF(current_setting('ssdi.dataSetSelection', true), ''), '[]')::jsonb @> '["with_class_page"]'::jsonb
Expand All @@ -781,10 +785,7 @@ WITH
),
with_class AS (
SELECT
r.id,
COUNT(DISTINCT fg.id) FILTER (WHERE COALESCE(g."goalTemplateId",0) = 18172) > 0 has_class,
COUNT(DISTINCT mcs.id) > 0 has_scores,
COUNT(DISTINCT gr.id) FILTER (WHERE COALESCE(g."goalTemplateId",0) = 18172 AND fg.id IS NOT NULL AND mcs.id IS NOT NULL) grant_count
DISTINCT r.id
FROM "Recipients" r
JOIN has_current_grant hcg
ON r.id = hcg.rid
Expand All @@ -794,107 +795,198 @@ WITH
ON gr.id = fgr.id
LEFT JOIN "Goals" g
ON gr.id = g."grantId"
LEFT JOIN filtered_goals fg
ON g.id = fg.id
LEFT JOIN "MonitoringReviewGrantees" mrg
ON gr.number = mrg."grantNumber"
LEFT JOIN "MonitoringReviews" mr
ON mrg."reviewId" = mr."reviewId"
AND mr."reviewType" in ('CLASS', 'PR-CLASS', 'AIAN CLASS Self-Observations', 'AIAN-CLASS', 'VP-CLASS', 'CLASS-Video')
LEFT JOIN "MonitoringReviewStatuses" mrs
ON mr."statusId" = mrs."statusId"
LEFT JOIN "MonitoringClassSummaries" mcs
ON mr."reviewId" = mcs."reviewId"
WHERE hcg.has_current_active_grant
AND g."deletedAt" IS NULL
AND (mrs.id IS NULL OR mrs.name = 'Complete')
AND g."mapsToParentGoalId" IS NULL
GROUP BY 1
),
with_class_widget AS (
grant_class_reviews AS (
SELECT
(COALESCE(COUNT(DISTINCT wc.id) FILTER (WHERE wc.has_class AND wc.has_scores)::decimal/
NULLIF(COUNT(DISTINCT wc.id), 0), 0)*100)::decimal(5,2) "% recipients with class",
COUNT(DISTINCT wc.id) FILTER (WHERE wc.has_class AND wc.has_scores) "recipients with class",
COUNT(DISTINCT wc.id) total,
SUM(grant_count) "grants with class"
FROM with_class wc
gr.id "grantId",
mr."reportDeliveryDate",
mcs."emotionalSupport",
mcs."classroomOrganization",
mcs."instructionalSupport",
ROW_NUMBER() OVER (
PARTITION BY gr.id, mr."reportDeliveryDate"
ORDER BY mcs.id DESC, mr.id DESC
) "reviewRank"
FROM "Grants" gr
JOIN filtered_grants fgr
ON gr.id = fgr.id
JOIN "MonitoringReviewGrantees" mrg
ON gr.number = mrg."grantNumber"
JOIN "MonitoringReviews" mr
ON mrg."reviewId" = mr."reviewId"
AND mr."reviewType" in ('CLASS', 'PR-CLASS', 'AIAN CLASS Self-Observations', 'AIAN-CLASS', 'VP-CLASS', 'CLASS-Video')
LEFT JOIN "MonitoringReviewStatuses" mrs
ON mr."statusId" = mrs."statusId"
JOIN "MonitoringClassSummaries" mcs
ON mr."reviewId" = mcs."reviewId"
AND gr.number = mcs."grantNumber"
WHERE (mrs.id IS NULL OR mrs.name = 'Complete')
AND mr."reportDeliveryDate" IS NOT NULL
AND mcs."emotionalSupport" IS NOT NULL
),
with_class_page AS (
class_goals_with_activity AS (
SELECT
r.id "recipientId",
r.name "recipientName",
gr.number "grantNumber",
gr."regionId",
(ARRAY_AGG(g.id ORDER BY g.id DESC) FILTER (WHERE fg.id IS NOT NULL))[1] "goalId",
(ARRAY_AGG(g."createdAt" ORDER BY g.id DESC) FILTER (WHERE fg.id IS NOT NULL))[1] "goalCreatedAt",
(ARRAY_AGG(g.status ORDER BY g.id DESC) FILTER (WHERE fg.id IS NOT NULL))[1] "goalStatus",
(ARRAY_AGG(a."startDate" ORDER BY a."startDate" DESC) FILTER (WHERE fg.id IS NOT NULL))[1] "lastARStartDate",
(ARRAY_AGG(mcs."emotionalSupport" ORDER BY mr."reportDeliveryDate" DESC) FILTER (WHERE mr.id IS NOT NULL AND fg.id IS NOT NULL))[1] "emotionalSupport",
(ARRAY_AGG(mcs."classroomOrganization" ORDER BY mr."reportDeliveryDate" DESC) FILTER (WHERE mr.id IS NOT NULL AND fg.id IS NOT NULL))[1] "classroomOrganization",
(ARRAY_AGG(mcs."instructionalSupport" ORDER BY mr."reportDeliveryDate" DESC) FILTER (WHERE mr.id IS NOT NULL AND fg.id IS NOT NULL))[1] "instructionalSupport",
(ARRAY_AGG(mr."reportDeliveryDate" ORDER BY mr."reportDeliveryDate" DESC) FILTER (WHERE mr.id IS NOT NULL AND fg.id IS NOT NULL))[1] "reportDeliveryDate",
(ARRAY_AGG(DISTINCT u.name || ', ' || COALESCE(ur.agg_roles, 'No Roles')) FILTER (WHERE ct.name = 'Creator' AND fg.id IS NOT NULL))[1] "creator",
(ARRAY_AGG(DISTINCT u.name || ', ' || COALESCE(ur.agg_roles, 'No Roles')) FILTER (WHERE ct.name = 'Collaborator' AND fg.id IS NOT NULL)) "collaborators"
FROM requested_datasets rd
JOIN with_class wc
ON rd.include_with_class_page
JOIN "Recipients" r
r.id "recipientId",
gr.id "grantId",
g.id "goalId",
MAX(a."startDate") "lastARStartDate"
FROM "Recipients" r
JOIN has_current_grant hcg
ON r.id = hcg.rid
ON wc.id = r.id
AND (has_class OR has_scores)
JOIN "Grants" gr
ON r.id = gr."recipientId"
JOIN filtered_grants fgr
ON gr.id = fgr.id
LEFT JOIN "Goals" g
JOIN "Goals" g
ON gr.id = g."grantId"
AND has_class
AND g."goalTemplateId" = 18172
LEFT JOIN filtered_goals fg
JOIN filtered_goals fg
ON g.id = fg.id
LEFT JOIN "ActivityReportGoals" arg
ON g.id = arg."goalId"
LEFT JOIN "ActivityReports" a
ON arg."activityReportId" = a.id
AND a."calculatedStatus" = 'approved'
WHERE hcg.has_current_active_grant
AND g."deletedAt" IS NULL
AND g."mapsToParentGoalId" IS NULL
GROUP BY 1, 2, 3
HAVING MAX(a."startDate") IS NOT NULL
),
matched_class_goals AS (
SELECT
cgwa."recipientId",
cgwa."grantId",
cgwa."goalId",
cgwa."lastARStartDate",
gcr."emotionalSupport",
gcr."classroomOrganization",
gcr."instructionalSupport",
gcr."reportDeliveryDate",
ROW_NUMBER() OVER (
PARTITION BY cgwa."goalId"
ORDER BY gcr."reportDeliveryDate" DESC, cgwa."lastARStartDate" DESC, cgwa."grantId" DESC
) "matchRank"
FROM class_goals_with_activity cgwa
JOIN grant_class_reviews gcr
ON cgwa."grantId" = gcr."grantId"
AND gcr."reviewRank" = 1
AND cgwa."lastARStartDate"::date >= gcr."reportDeliveryDate"::date
),
qualifying_class_goal_rows AS (
SELECT
"recipientId",
"grantId",
"goalId",
"lastARStartDate",
"emotionalSupport",
"classroomOrganization",
"instructionalSupport",
"reportDeliveryDate"
FROM matched_class_goals
WHERE "matchRank" = 1
),
class_page_rows AS (
SELECT
qcgr."recipientId",
r.name "recipientName",
gr.id "grantId",
gr.number "grantNumber",
gr."regionId",
qcgr."goalId",
g."createdAt" "goalCreatedAt",
g.status "goalStatus",
qcgr."lastARStartDate",
qcgr."emotionalSupport",
qcgr."classroomOrganization",
qcgr."instructionalSupport",
qcgr."reportDeliveryDate"
FROM requested_datasets rd
JOIN qualifying_class_goal_rows qcgr
ON rd.include_with_class_page
JOIN "Recipients" r
ON qcgr."recipientId" = r.id
JOIN "Grants" gr
ON qcgr."grantId" = gr.id
JOIN "Goals" g
ON qcgr."goalId" = g.id
),
class_goal_collaborators AS (
SELECT
cpr."goalId",
MIN(u.name || ', ' || COALESCE(ur.agg_roles, 'No Roles')) FILTER (
WHERE ct.name = 'Creator'
AND vf.name = 'Goals'
) "creator",
STRING_AGG(
DISTINCT u.name || ', ' || COALESCE(ur.agg_roles, 'No Roles'),
', '
ORDER BY u.name || ', ' || COALESCE(ur.agg_roles, 'No Roles')
) FILTER (
WHERE ct.name = 'Collaborator'
AND vf.name = 'Goals'
) "collaborators"
FROM class_page_rows cpr
LEFT JOIN "GoalCollaborators" gc
ON g.id = gc."goalId"
ON cpr."goalId" = gc."goalId"
LEFT JOIN "CollaboratorTypes" ct
ON gc."collaboratorTypeId" = ct.id
AND ct.name IN ('Creator', 'Collaborator')
LEFT JOIN "ValidFor" vf
ON ct."validForId" = vf.id
AND vf.name = 'Goals'
LEFT JOIN "Users" u
ON gc."userId" = u.id
LEFT JOIN LATERAL (
SELECT ur."userId", STRING_AGG(r.name, ', ') AS agg_roles
SELECT STRING_AGG(r.name, ', ') AS agg_roles
FROM "UserRoles" ur
JOIN "Roles" r ON ur."roleId" = r.id
WHERE ur."userId" = u.id
GROUP BY ur."userId"
) ur ON u.id = ur."userId"
LEFT JOIN "ActivityReportGoals" arg
ON g.id = arg."goalId"
LEFT JOIN "ActivityReports" a
ON arg."activityReportId" = a.id
AND a."calculatedStatus" = 'approved'
LEFT JOIN "MonitoringReviewGrantees" mrg
ON gr.number = mrg."grantNumber"
LEFT JOIN "MonitoringReviews" mr
ON mrg."reviewId" = mr."reviewId"
AND mr."reviewType" in ('CLASS', 'PR-CLASS', 'AIAN CLASS Self-Observations', 'AIAN-CLASS', 'VP-CLASS', 'CLASS-Video')
LEFT JOIN "MonitoringReviewStatuses" mrs
ON mr."statusId" = mrs."statusId"
LEFT JOIN "MonitoringClassSummaries" mcs
ON mr."reviewId" = mcs."reviewId"
WHERE hcg.has_current_active_grant
AND (has_class OR has_scores)
AND (g.id IS NOT NULL OR mcs.id IS NOT NULL)
AND (mrs.id IS NULL OR mrs.name = 'Complete')
AND (mcs.id IS NOT NULL)
AND g."deletedAt" IS NULL
AND g."mapsToParentGoalId" IS NULL
GROUP BY 1, 2, 3, 4
HAVING (ARRAY_AGG(mcs."emotionalSupport" ORDER BY mr."reportDeliveryDate" DESC) FILTER (WHERE mr.id IS NOT NULL AND fg.id IS NOT NULL))[1] IS NOT NULL
ORDER BY 1, 3
) ur ON true
GROUP BY 1
),
with_class_widget AS (
SELECT
(COALESCE(COUNT(DISTINCT qcgr."recipientId")::decimal/
NULLIF(COUNT(DISTINCT wc.id), 0), 0)*100)::decimal(5,2) "% recipients with class",
COUNT(DISTINCT qcgr."recipientId") "recipients with class",
COUNT(DISTINCT wc.id) total,
COUNT(DISTINCT qcgr."grantId") "grants with class"
FROM requested_datasets rd
JOIN with_class wc
ON rd.include_with_class_widget
LEFT JOIN qualifying_class_goal_rows qcgr
ON wc.id = qcgr."recipientId"
),
with_class_page AS (
SELECT
cpr."recipientId",
cpr."recipientName",
cpr."grantNumber",
cpr."regionId",
cpr."goalId",
cpr."goalCreatedAt",
cpr."goalStatus",
cpr."lastARStartDate",
cpr."emotionalSupport",
cpr."classroomOrganization",
cpr."instructionalSupport",
cpr."reportDeliveryDate",
COALESCE(cgc."creator", '') "creator",
COALESCE(cgc."collaborators", '') "collaborators"
FROM class_page_rows cpr
LEFT JOIN class_goal_collaborators cgc
ON cpr."goalId" = cgc."goalId"
ORDER BY cpr."recipientId", cpr."reportDeliveryDate" DESC, cpr."lastARStartDate" DESC, cpr."goalId" DESC
),

-- CTE for fetching active filters using NULLIF() to handle empty strings
Expand Down
Loading
Loading