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
Expand Up @@ -8,12 +8,14 @@ resource "null_resource" "billing_transactions_view" {
${path.module}/scripts/create_replace_view.sh \
${aws_athena_workgroup.setup.name} \
${aws_glue_catalog_database.reporting.name} \
billing_transactions
billing_transactions \
sms_nudge_client_id "${local.sms_nudge_client_id}"
EOT
}

depends_on = [
null_resource.request_item_plan_status_table,
null_resource.request_item_status_table
null_resource.request_item_status_table,
null_resource.request_item_plan_status_smsnudge_view
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE OR REPLACE VIEW ${view_name} AS
SELECT
WITH joined_request_item_plans AS (
SELECT
DATE(rip.completedtime) AS billingdate,
rip.clientid,
rip.campaignid,
Expand All @@ -10,22 +11,77 @@
rip.specificationbillingid,
rip.messagelength,
rip.messagelengthunits,
COUNT(*) AS messagecount
FROM request_item_plan_status rip
INNER JOIN request_item_status ri
ON
rip.clientid = ri.clientid AND
rip.requestitemid = ri.requestitemid
rip.status,
rip.sendtime
FROM request_item_plan_status rip
INNER JOIN request_item_status ri
ON rip.clientid = ri.clientid
AND rip.requestitemid = ri.requestitemid
WHERE ri.clientid != ${sms_nudge_client_id}
UNION ALL
SELECT
DATE(rip.completedtime) AS billingdate,
rip.originatingclientid AS clientid,
rip.originatingcampaignid AS campaignid,
rip.originatingbillingref AS billingref,
orip.senderodscode,
rip.communicationtype,
rip.specificationid,
rip.specificationbillingid,
rip.messagelength,
rip.messagelengthunits,
rip.status,
rip.sendtime
FROM request_item_plan_status_smsnudge rip
INNER JOIN request_item_plan_status orip
ON rip.originatingclientid = orip.clientid
AND rip.originatingrequestitemplanid = orip.requestitemplanid
)

SELECT
billingdate,
clientid,
campaignid,
billingref,
senderodscode,
communicationtype,
specificationid,
specificationbillingid,
messagelength,
messagelengthunits,
COUNT(*) AS messagecount
FROM joined_request_item_plans
WHERE
rip.completedtime IS NOT NULL AND
billingdate IS NOT NULL
AND (
(
(
--Bill for all text messages forwarded to the supplier
(rip.communicationtype ='SMS') AND (rip.status IN ('DELIVERED', 'FAILED')) AND (sendtime IS NOT NULL)
) OR (
--Bill for all letters accepted by the supplier
(rip.communicationtype ='LETTER') AND (rip.status='DELIVERED')
)
-- Bill for all text messages forwarded to the supplier
(communicationtype = 'SMS') AND (status IN ('DELIVERED', 'FAILED')) AND (sendtime IS NOT NULL)
)
OR (
-- Bill for all letters accepted by the supplier
(communicationtype = 'LETTER') AND (status = 'DELIVERED')
)
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
ORDER BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
)
GROUP BY
billingdate,
clientid,
campaignid,
billingref,
senderodscode,
communicationtype,
specificationid,
specificationbillingid,
messagelength,
messagelengthunits
ORDER BY
billingdate,

Check warning on line 78 in infrastructure/terraform/components/reporting/scripts/sql/views/billing_transactions.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add ASC in order to make the order explicit.

See more on https://sonarcloud.io/project/issues?id=NHSDigital_nhs-notify-reporting&issues=AZzYa9VPDzOv35t3m8CK&open=AZzYa9VPDzOv35t3m8CK&pullRequest=217
clientid,

Check warning on line 79 in infrastructure/terraform/components/reporting/scripts/sql/views/billing_transactions.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add ASC in order to make the order explicit.

See more on https://sonarcloud.io/project/issues?id=NHSDigital_nhs-notify-reporting&issues=AZzYa9VPDzOv35t3m8CL&open=AZzYa9VPDzOv35t3m8CL&pullRequest=217
campaignid,

Check warning on line 80 in infrastructure/terraform/components/reporting/scripts/sql/views/billing_transactions.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add ASC in order to make the order explicit.

See more on https://sonarcloud.io/project/issues?id=NHSDigital_nhs-notify-reporting&issues=AZzYa9VPDzOv35t3m8CM&open=AZzYa9VPDzOv35t3m8CM&pullRequest=217
billingref,

Check warning on line 81 in infrastructure/terraform/components/reporting/scripts/sql/views/billing_transactions.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add ASC in order to make the order explicit.

See more on https://sonarcloud.io/project/issues?id=NHSDigital_nhs-notify-reporting&issues=AZzYa9VPDzOv35t3m8CN&open=AZzYa9VPDzOv35t3m8CN&pullRequest=217
senderodscode,

Check warning on line 82 in infrastructure/terraform/components/reporting/scripts/sql/views/billing_transactions.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add ASC in order to make the order explicit.

See more on https://sonarcloud.io/project/issues?id=NHSDigital_nhs-notify-reporting&issues=AZzYa9VPDzOv35t3m8CO&open=AZzYa9VPDzOv35t3m8CO&pullRequest=217
communicationtype,

Check warning on line 83 in infrastructure/terraform/components/reporting/scripts/sql/views/billing_transactions.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add ASC in order to make the order explicit.

See more on https://sonarcloud.io/project/issues?id=NHSDigital_nhs-notify-reporting&issues=AZzYa9VPDzOv35t3m8CP&open=AZzYa9VPDzOv35t3m8CP&pullRequest=217
specificationid,

Check warning on line 84 in infrastructure/terraform/components/reporting/scripts/sql/views/billing_transactions.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add ASC in order to make the order explicit.

See more on https://sonarcloud.io/project/issues?id=NHSDigital_nhs-notify-reporting&issues=AZzYa9VPDzOv35t3m8CQ&open=AZzYa9VPDzOv35t3m8CQ&pullRequest=217
specificationbillingid,

Check warning on line 85 in infrastructure/terraform/components/reporting/scripts/sql/views/billing_transactions.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add ASC in order to make the order explicit.

See more on https://sonarcloud.io/project/issues?id=NHSDigital_nhs-notify-reporting&issues=AZzYa9VPDzOv35t3m8CR&open=AZzYa9VPDzOv35t3m8CR&pullRequest=217
messagelength,

Check warning on line 86 in infrastructure/terraform/components/reporting/scripts/sql/views/billing_transactions.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add ASC in order to make the order explicit.

See more on https://sonarcloud.io/project/issues?id=NHSDigital_nhs-notify-reporting&issues=AZzYa9VPDzOv35t3m8CS&open=AZzYa9VPDzOv35t3m8CS&pullRequest=217
messagelengthunits;

Check warning on line 87 in infrastructure/terraform/components/reporting/scripts/sql/views/billing_transactions.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add ASC in order to make the order explicit.

See more on https://sonarcloud.io/project/issues?id=NHSDigital_nhs-notify-reporting&issues=AZzYa9VPDzOv35t3m8CT&open=AZzYa9VPDzOv35t3m8CT&pullRequest=217
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ SELECT
rip.*,
ris.originatingclientid,
ris.originatingcampaignid,
ris.originatingbillingrefid,
ris.originatingbillingref,
ris.originatingrequestitemid,
ris.originatingrequestitemplanid,
original_ri.sendinggroupid AS originalsendinggroupid
original_ri.sendinggroupid AS originatingsendinggroupid
FROM request_item_plan_status rip
LEFT JOIN request_item_status_smsnudge_staging ris
ON rip.requestitemid = ris.requestitemid
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE OR REPLACE VIEW ${view_name} AS
SELECT
ris.*,
rips.originalsendinggroupid
rips.originatingsendinggroupid
FROM request_item_status_smsnudge_staging ris
LEFT JOIN request_item_plan_status_smsnudge rips
ON ris.requestitemid = rips.requestitemid
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SELECT
ris.*,
NULLIF(split_part(ris.billingref, '|', 1), '') AS originatingclientid,
NULLIF(split_part(ris.billingref, '|', 2), '') AS originatingcampaignid,
NULLIF(split_part(ris.billingref, '|', 3), '') AS originatingbillingrefid,
NULLIF(split_part(ris.billingref, '|', 3), '') AS originatingbillingref,
NULLIF(split_part(ris.requestitemrefid, '_', 1), '') AS originatingrequestitemid,
NULLIF(split_part(ris.requestitemrefid, '_', 2), '') AS originatingrequestitemplanid
FROM request_item_status ris
Expand Down
Loading