Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
resource "aws_athena_named_query" "pds_cleared_failures" {
name = "pds_cleared_failures"
description = "Query to report which pds changes may have resulted in the correction of a temporary or permanent failure"
workgroup = aws_athena_workgroup.user.id
database = aws_glue_catalog_database.reporting.name
query = file("${path.module}/scripts/sql/reports/pds_cleared_failures.sql")

depends_on = [
null_resource.request_item_status_table,
null_resource.request_item_plan_status_table
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
SELECT rip_success.requestitemid, rip_success.completedtime, rip_success.communicationtype, rip_success.recipientcontactid
FROM (
SELECT ri.nhsnumberhash, rip.communicationtype, ri.requestitemid AS secondrequestitemid,
LAG(ri.requestitemid,1) OVER (PARTITION BY ri.nhsnumberhash, rip.communicationtype ORDER BY ri.createdtime) AS firstrequestitemid
FROM request_item_status ri
INNER JOIN request_item_plan_status rip ON
rip.requestitemid = ri.requestitemid
WHERE (rip.communicationtype = 'EMAIL' OR rip.communicationtype = 'SMS')
) AS tx
INNER JOIN request_item_plan_status rip_success ON
rip_success.requestitemid = tx.secondrequestitemid AND
rip_success.communicationtype = tx.communicationtype
INNER JOIN request_item_plan_status rip_failed ON
rip_failed.requestitemid = firstrequestitemid AND
rip_failed.communicationtype = tx.communicationtype
WHERE
rip_success.communicationtype IN ('SMS', 'EMAIL') AND
rip_success.communicationtype = rip_failed.communicationtype AND
rip_success.status = 'DELIVERED' AND
rip_failed.status = 'FAILED' AND
(rip_failed.failedreason LIKE '%TEMPORARY%' OR rip_failed.failedreason LIKE '%PERMANENT%')
ORDER BY rip_success.completedtime
Loading