Skip to content

Commit

Permalink
Merge pull request #2323 from HHS/main
Browse files Browse the repository at this point in the history
[Prod] Address Support issue migration, clean-up SSDI for fake FEI goals
  • Loading branch information
Jones-QuarteyDana authored Aug 21, 2024
2 parents 8c6744d + 127d7bb commit ddaec1f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ module.exports = {
ELSE NULL -- optional, in case you want to handle cases where all are NULL
END AS "supportType",
bool_or(aro."objectiveCreatedHere") "objectiveCreatedHere",
array_agg(aro.id) "aroIds"
array_agg(aro.id order by aro.id) "aroIds"
FROM temp_dup_aro_sets das
JOIN "ActivityReportObjectives" aro
ON aro.id = ANY (das."aroIds")
Expand Down
27 changes: 22 additions & 5 deletions src/queries/fake-fei-goals.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @name: Fake FEI Goals
* @description: A report of all goals realting to under/full enrollment that are not linked to the official FEI template.
* @description: A report of all goals relating to under/full enrollment that are not linked to the official FEI template.
* @defaultOutputName: fake_fei_report
*
* This query collects goals realting to under/full enrollment that are not linked to the official FEI template.
* This query collects goals relating to under/full enrollment that are not linked to the official FEI template.
*
* The query results are filterable by the SSDI flags. All SSDI flags are passed as an array of values
* The following are the available flags within this script:
Expand All @@ -27,15 +27,16 @@ SELECT
gr."regionId",
g.id "goal id",
g.status "goal status",
g."createdAt",
g."createdAt" "goal creation time",
COUNT(DISTINCT a.id) FILTER (WHERE a."calculatedStatus" = 'approved') "approved reports",
COUNT(DISTINCT a.id) FILTER (WHERE a."calculatedStatus" IN ('draft', 'submitted')) "pending reports",
GREATEST(
similarity(gt."templateName", g.name),
similarity(gt."templateName", LEFT(g.name, LENGTH(gt."templateName"))),
similarity(gt."templateName", RIGHT(g.name, LENGTH(gt."templateName")))
) similarity,
g.name
STRINGAGG(DISTINCT u.name, ';') "goal user list",
g.name "goal text"
FROM "Goals" g
JOIN "GoalTemplates" gt
-- Real FEI goal is in the production DATABASE with an id of 19017 in the GoalTemplates table
Expand All @@ -48,8 +49,20 @@ LEFT JOIN "ActivityReportGoals" arg
ON g.id = arg."goalId"
LEFT JOIN "ActivityReports" a
ON arg."activityReportId" = a.id
JOIN "CollaboratorTypes" ct
ON "validForId" = 1
AND ct.name = 'Linker'
LEFT JOIN "GoalCollaborators" gc
ON g.id = gc."goalId"
AND gc."collaboratorTypeId" = ct.id
LEFT JOIN "Users" u
ON u.id = gc."userId"
OR u.id = a."userId"
WHERE g."deletedAt" IS NULL
AND g."mapsToParentGoalId" IS NULL
-- excluding goals attached to deleted grants and goals only on TRs, because those are invisible to users
AND NOT gr.deleted
AND NOT (g."createdVia" = 'tr' AND a.id IS NULL)
AND g.name ~* '(^|[^a-zA-Z])(under[- ]?enrollment|full[- ]?enrollment|fei)($|[^a-zA-Z])'
AND COALESCE(g."goalTemplateId", 0) != gt.id
-- Filter for regionIds if ssdi.regionIds is defined
Expand Down Expand Up @@ -88,5 +101,9 @@ AND (NULLIF(current_setting('ssdi.status', true), '') IS NULL
SELECT value::text AS my_array
FROM json_array_elements_text(COALESCE(NULLIF(current_setting('ssdi.status', true), ''),'[]')::json) AS value
))
GROUP BY 1,2,3,4,5,6,7,8,11,12
GROUP BY 1,2,3,4,5,6,7,8,11,13
-- Ghost goal filter
HAVING NOT (g."createdVia" = 'activityReport'
AND COUNT(DISTINCT a.id) FILTER (WHERE a."calculatedStatus" = 'approved') = 0
AND COUNT(DISTINCT a.id) FILTER (WHERE a."calculatedStatus" IN ('draft', 'submitted')) = 0)
ORDER BY 5,11 desc;

0 comments on commit ddaec1f

Please sign in to comment.