From 33600fef4a5d7099cba68cfbc8df4cf7d4717841 Mon Sep 17 00:00:00 2001 From: Mark Pullan Date: Tue, 11 Mar 2025 12:53:56 +0000 Subject: [PATCH 1/2] Put contact corrections query under source control --- ...ena_named_query_pds_contact_corrections.tf | 12 ++++++++++ .../sql/reports/pds_contact_corrections.sql | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 infrastructure/terraform/components/reporting/athena_named_query_pds_contact_corrections.tf create mode 100644 infrastructure/terraform/components/reporting/scripts/sql/reports/pds_contact_corrections.sql diff --git a/infrastructure/terraform/components/reporting/athena_named_query_pds_contact_corrections.tf b/infrastructure/terraform/components/reporting/athena_named_query_pds_contact_corrections.tf new file mode 100644 index 00000000..58e9ed1d --- /dev/null +++ b/infrastructure/terraform/components/reporting/athena_named_query_pds_contact_corrections.tf @@ -0,0 +1,12 @@ +resource "aws_athena_named_query" "pds_contact_corrections" { + name = "pds_contact_corrections" + 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_contact_corrections.sql") + + depends_on = [ + null_resource.request_item_status_table, + null_resource.request_item_plan_status_table + ] +} diff --git a/infrastructure/terraform/components/reporting/scripts/sql/reports/pds_contact_corrections.sql b/infrastructure/terraform/components/reporting/scripts/sql/reports/pds_contact_corrections.sql new file mode 100644 index 00000000..cb1e298d --- /dev/null +++ b/infrastructure/terraform/components/reporting/scripts/sql/reports/pds_contact_corrections.sql @@ -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 From 0428820cc01f9ac0f35f90702ef3c86b846f3a75 Mon Sep 17 00:00:00 2001 From: Mark Pullan Date: Tue, 11 Mar 2025 13:25:44 +0000 Subject: [PATCH 2/2] Rename query --- ...ctions.tf => athena_named_query_pds_cleared_failures.tf} | 6 +++--- ...pds_contact_corrections.sql => pds_cleared_failures.sql} | 0 2 files changed, 3 insertions(+), 3 deletions(-) rename infrastructure/terraform/components/reporting/{athena_named_query_pds_contact_corrections.tf => athena_named_query_pds_cleared_failures.tf} (64%) rename infrastructure/terraform/components/reporting/scripts/sql/reports/{pds_contact_corrections.sql => pds_cleared_failures.sql} (100%) diff --git a/infrastructure/terraform/components/reporting/athena_named_query_pds_contact_corrections.tf b/infrastructure/terraform/components/reporting/athena_named_query_pds_cleared_failures.tf similarity index 64% rename from infrastructure/terraform/components/reporting/athena_named_query_pds_contact_corrections.tf rename to infrastructure/terraform/components/reporting/athena_named_query_pds_cleared_failures.tf index 58e9ed1d..4d2c65aa 100644 --- a/infrastructure/terraform/components/reporting/athena_named_query_pds_contact_corrections.tf +++ b/infrastructure/terraform/components/reporting/athena_named_query_pds_cleared_failures.tf @@ -1,9 +1,9 @@ -resource "aws_athena_named_query" "pds_contact_corrections" { - name = "pds_contact_corrections" +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_contact_corrections.sql") + query = file("${path.module}/scripts/sql/reports/pds_cleared_failures.sql") depends_on = [ null_resource.request_item_status_table, diff --git a/infrastructure/terraform/components/reporting/scripts/sql/reports/pds_contact_corrections.sql b/infrastructure/terraform/components/reporting/scripts/sql/reports/pds_cleared_failures.sql similarity index 100% rename from infrastructure/terraform/components/reporting/scripts/sql/reports/pds_contact_corrections.sql rename to infrastructure/terraform/components/reporting/scripts/sql/reports/pds_cleared_failures.sql