From be5a11b0279affb9f6a4b099e50f5b34e1eac21b Mon Sep 17 00:00:00 2001 From: simonlabarere Date: Thu, 17 Jul 2025 13:29:52 +0100 Subject: [PATCH] CCM-11292: Add failed reason code to completed comms and completed batch reports --- ...ll_resource_request_item_plan_status_table.tf | 16 ++++++++++++++++ .../null_resource_request_item_status_table.tf | 16 ++++++++++++++++ .../sql/ingestion/request_item_plan_status.sql | 4 ++++ .../sql/ingestion/request_item_status.sql | 4 ++++ .../sql/reports/completed_batch_report.sql | 4 +++- .../sql/reports/completed_comms_report.sql | 4 +++- .../scripts/sql/views/completed_comms.sql | 4 +++- 7 files changed, 49 insertions(+), 3 deletions(-) diff --git a/infrastructure/terraform/components/reporting/null_resource_request_item_plan_status_table.tf b/infrastructure/terraform/components/reporting/null_resource_request_item_plan_status_table.tf index 994bbd77..1cf55337 100644 --- a/infrastructure/terraform/components/reporting/null_resource_request_item_plan_status_table.tf +++ b/infrastructure/terraform/components/reporting/null_resource_request_item_plan_status_table.tf @@ -76,3 +76,19 @@ resource "null_resource" "request_item_plan_status_templateid_column" { depends_on = [null_resource.request_item_plan_status_recipientcontactid_column] } + +resource "null_resource" "request_item_plan_status_failedreasoncode_column" { + triggers = { + always_run = timestamp() + } + provisioner "local-exec" { + command = <)[LOWER(supplier)] AS templateid, + failedreasoncode, CAST("$classification".timestamp AS BIGINT) AS timestamp FROM ${source_table} WHERE (sk LIKE 'REQUEST_ITEM_PLAN#%') AND @@ -65,6 +66,7 @@ WHEN MATCHED AND (source.timestamp > target.timestamp) THEN UPDATE SET ordernumber = source.ordernumber, recipientcontactid = source.recipientcontactid, templateid = source.templateid, + failedreasoncode = source.failedreasoncode, timestamp = source.timestamp WHEN NOT MATCHED THEN INSERT ( clientid, @@ -88,6 +90,7 @@ WHEN NOT MATCHED THEN INSERT ( ordernumber, recipientcontactid, templateid, + failedreasoncode, timestamp ) VALUES ( @@ -112,5 +115,6 @@ VALUES ( source.ordernumber, source.recipientcontactid, source.templateid, + source.failedreasoncode, source.timestamp ) diff --git a/infrastructure/terraform/components/reporting/scripts/sql/ingestion/request_item_status.sql b/infrastructure/terraform/components/reporting/scripts/sql/ingestion/request_item_status.sql index ac13e8b3..09be4a72 100644 --- a/infrastructure/terraform/components/reporting/scripts/sql/ingestion/request_item_status.sql +++ b/infrastructure/terraform/components/reporting/scripts/sql/ingestion/request_item_status.sql @@ -29,6 +29,7 @@ USING ( failedreason, patientodscode, billingref, + failedreasoncode, CAST("$classification".timestamp AS BIGINT) AS timestamp FROM ${source_table} WHERE (sk LIKE 'REQUEST_ITEM#%') AND @@ -61,6 +62,7 @@ WHEN MATCHED AND (source.timestamp > target.timestamp) THEN UPDATE SET failedreason = source.failedreason, patientodscode = source.patientodscode, billingref = source.billingref, + failedreasoncode = source.failedreasoncode, timestamp = source.timestamp WHEN NOT MATCHED THEN INSERT ( clientid, @@ -82,6 +84,7 @@ WHEN NOT MATCHED THEN INSERT ( failedreason, patientodscode, billingref, + failedreasoncode, timestamp ) VALUES ( @@ -104,5 +107,6 @@ VALUES ( source.failedreason, source.patientodscode, source.billingref, + source.failedreasoncode, source.timestamp ) diff --git a/infrastructure/terraform/components/reporting/scripts/sql/reports/completed_batch_report.sql b/infrastructure/terraform/components/reporting/scripts/sql/reports/completed_batch_report.sql index a6420042..455b1fc7 100644 --- a/infrastructure/terraform/components/reporting/scripts/sql/reports/completed_batch_report.sql +++ b/infrastructure/terraform/components/reporting/scripts/sql/reports/completed_batch_report.sql @@ -16,6 +16,8 @@ SELECT communicationtype, channeltype, requestitemplanfailedreason, - templateid + templateid, + requestitemplanfailedreasoncode, + requestitemfailedreasoncode FROM completed_comms WHERE clientid = ? AND requestid = ? diff --git a/infrastructure/terraform/components/reporting/scripts/sql/reports/completed_comms_report.sql b/infrastructure/terraform/components/reporting/scripts/sql/reports/completed_comms_report.sql index 0cb6798b..d24c7629 100644 --- a/infrastructure/terraform/components/reporting/scripts/sql/reports/completed_comms_report.sql +++ b/infrastructure/terraform/components/reporting/scripts/sql/reports/completed_comms_report.sql @@ -16,7 +16,9 @@ SELECT communicationtype, channeltype, requestitemplanfailedreason, - templateid + templateid, + requestitemplanfailedreasoncode, + requestitemfailedreasoncode FROM completed_comms WHERE clientid = ? AND diff --git a/infrastructure/terraform/components/reporting/scripts/sql/views/completed_comms.sql b/infrastructure/terraform/components/reporting/scripts/sql/views/completed_comms.sql index ae1e2178..14a1425c 100644 --- a/infrastructure/terraform/components/reporting/scripts/sql/views/completed_comms.sql +++ b/infrastructure/terraform/components/reporting/scripts/sql/views/completed_comms.sql @@ -18,7 +18,9 @@ SELECT rip.communicationtype as communicationtype, rip.channeltype as channeltype, rip.failedreason as requestitemplanfailedreason, - rip.templateid as templateid + rip.templateid as templateid, + rip.failedreasoncode as requestitemplanfailedreasoncode, + ri.failedreasoncode as requestitemfailedreasoncode FROM request_item_status ri LEFT OUTER JOIN request_item_plan_status rip ON ri.requestitemid = rip.requestitemid AND