Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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,20 @@
SELECT cron.schedule_in_database(
's3_export_ab2d_prod_benes_searched',
'0 */6 * * *',
$$
SELECT *
FROM aws_s3.query_export_to_s3
(
'SELECT * FROM ab2d_prod_benes_searched',
aws_commons.create_s3_uri
(
'ab2d-prod-aurora-export-2025xxxxxxxxxxxxxxxxxxxxxx',
'ab2d-prod-benes-searched.csv',
'us-east-1'
),
options := 'format csv, HEADER true',
kms_key => '<aurora_export key arn>'
);
$$,
'main'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SELECT cron.schedule_in_database(
's3_export_ab2d_prod_benes_weekly',
'0 */6 * * *',
$$
SELECT *
FROM aws_s3.query_export_to_s3
(
'SELECT * FROM ab2d_prod_benes_weekly',
aws_commons.create_s3_uri
(
'ab2d-prod-aurora-export-2025xxxxxxxxxxxxxxxxxxxxxx',
'ab2d-prod-benes-weekly.csv',
'us-east-1'
),
options :='format csv, HEADER true',
kms_key => '<aurora_export key arn>'
);
$$,
'main'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SELECT cron.schedule_in_database(
's3_export_ab2d_prod_contracts_one_job_minimum',
'0 */6 * * *',
$$
SELECT *
FROM aws_s3.query_export_to_s3
(
'SELECT * FROM ab2d_prod_contracts_one_job_minimum',
aws_commons.create_s3_uri
(
'ab2d-prod-aurora-export-2025xxxxxxxxxxxxxxxxxxxxxx',
'ab2d-prod-contracts-one-job-minimum.csv',
'us-east-1'
),
options :='format csv, HEADER true',
kms_key => '<aurora_export key arn>'
);
$$,
'main'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SELECT cron.schedule_in_database(
's3_export_ab2d_prod_contracts_view',
'0 */6 * * *',
$$
SELECT *
FROM aws_s3.query_export_to_s3
(
'SELECT * FROM ab2d_prod_contracts_view',
aws_commons.create_s3_uri
(
'ab2d-prod-aurora-export-2025xxxxxxxxxxxxxxxxxxxxxx',
'ab2d-prod-contracts-view.csv',
'us-east-1'
),
options :='format csv, HEADER true',
kms_key => '<aurora_export key arn>'
);
$$,
'main'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SELECT cron.schedule_in_database(
's3_export_ab2d_prod_coverage_counts',
'0 */6 * * *',
$$
SELECT *
FROM aws_s3.query_export_to_s3
(
'SELECT * FROM ab2d_prod_coverage_counts',
aws_commons.create_s3_uri
(
'ab2d-prod-aurora-export-2025xxxxxxxxxxxxxxxxxxxxxx',
'ab2d-prod-coverage-counts.csv',
'us-east-1'
),
options :='format csv, HEADER true',
kms_key => '<aurora_export key arn>'
);
$$,
'main'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SELECT cron.schedule_in_database(
's3_export_ab2d_prod_eob_search_summaries_1',
'0 */6 * * *',
$$
SELECT *
FROM aws_s3.query_export_to_s3
(
'SELECT * FROM ab2d_prod_eob_search_summaries_1',
aws_commons.create_s3_uri
(
'ab2d-prod-aurora-export-2025xxxxxxxxxxxxxxxxxxxxxx',
'ab2d-prod-eob-search-summaries-1.csv',
'us-east-1'
),
options :='format csv, header true',
kms_key => '<aurora_export key arn>'
);
$$,
'main'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SELECT cron.schedule_in_database(
's3_export_ab2d_prod_eob_search_summaries_2',
'0 */6 * * *',
$$
SELECT *
FROM aws_s3.query_export_to_s3
(
'SELECT * FROM ab2d_prod_eob_search_summaries_2',
aws_commons.create_s3_uri
(
'ab2d-prod-aurora-export-2025xxxxxxxxxxxxxxxxxxxxxx',
'ab2d-prod-eob-search-summaries-2.csv',
'us-east-1'
),
options :='format csv, HEADER true',
kms_key => '<aurora_export key arn>'
);
$$,
'main'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SELECT cron.schedule_in_database(
's3_export_ab2d_prod_eob_search_summaries_event',
'0 */6 * * *',
$$
SELECT *
FROM aws_s3.query_export_to_s3
(
'SELECT * FROM ab2d_prod_eob_search_summaries_event',
aws_commons.create_s3_uri
(
'ab2d-prod-aurora-export-2025xxxxxxxxxxxxxxxxxxxxxx',
'ab2d-prod-eob-search-summaries-event.csv',
'us-east-1'
),
options :='format csv, HEADER true',
kms_key => '<aurora_export key arn>'
);
$$,
'main'
);
20 changes: 20 additions & 0 deletions terraform/services/insights/db-exports/ab2d-prod-job-view.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SELECT cron.schedule_in_database(
's3_export_ab2d_prod_job_view',
'0 */6 * * *',
$$
SELECT *
FROM aws_s3.query_export_to_s3
(
'SELECT * FROM ab2d_prod_job_view',
aws_commons.create_s3_uri
(
'ab2d-prod-aurora-export-2025xxxxxxxxxxxxxxxxxxxxxx',
'ab2d-prod-job-view.csv',
'us-east-1'
),
options :='format csv, HEADER true',
kms_key => '<aurora_export key arn>'
);
$$,
'main'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SELECT cron.schedule_in_database(
's3_export_ab2d_prod_summary_statistics',
'0 */6 * * *',
$$
SELECT *
FROM aws_s3.query_export_to_s3
(
'SELECT * FROM ab2d_prod_summary_statistics',
aws_commons.create_s3_uri
(
'ab2d-prod-aurora-export-2025xxxxxxxxxxxxxxxxxxxxxx',
'ab2d-prod-summary-statistics.csv',
'us-east-1'
),
options :='format csv, HEADER true',
kms_key => '<aurora_export key arn>'
);
$$,
'main'
);
20 changes: 20 additions & 0 deletions terraform/services/insights/db-exports/ab2d-prod-uptime-all.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SELECT cron.schedule_in_database(
's3_export_ab2d_prod_uptime_all',
'0 */6 * * *',
$$
SELECT *
FROM aws_s3.query_export_to_s3
(
'SELECT * FROM ab2d_prod_uptime_all',
aws_commons.create_s3_uri
(
'ab2d-prod-aurora-export-2025xxxxxxxxxxxxxxxxxxxxxx',
'ab2d-prod-uptime-all.csv',
'us-east-1'
),
options :='format csv, HEADER true',
kms_key => '<aurora_export key arn>'
);
$$,
'main'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
CREATE VIEW ab2d_prod_benes_searched AS
SELECT
*,
contract_number AS "Contract Number",
job_uuid AS "Job ID",
benes_searched AS "# Bene Searched",
completed_at AS "Completed At",
eobs_written AS "# EoBs Written",
data_start_time AS "Data Start Date (Since Date)",
fhir_version AS "FHIR Version",
to_char(time_to_complete, 'HH24:MI:SS') AS "Seconds Run",
created_at AS "Job Start Time",
completed_at AS "Job Complete Time",
to_char(time_to_complete, 'HH24:MI:SS') AS sec_run,
created_at AS job_start_time,
completed_at AS job_complete_time
FROM (
SELECT
s.contract_number,
j.job_uuid,
s.benes_searched,
j.created_at,
j.completed_at,
s.eobs_written,
j.completed_at - j.created_at as time_to_complete,
CASE
WHEN j.since is null
THEN
CASE
WHEN c.attested_on < '2020-01-01'
THEN '2020-01-01'
ELSE c.attested_on
END
ELSE j.since
END AS data_start_time,
j.since,
j.fhir_version,
j.status
FROM job j
LEFT JOIN event.event_bene_search s ON s.job_id = j.job_uuid
LEFT JOIN contract_view c ON c.contract_number = j.contract_number
WHERE j.started_by='PDP') t
ORDER BY "Job Start Time" DESC;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE VIEW ab2d_prod_benes_weekly AS
SELECT
week_start,
week_end,
SUM(t.total_benes) AS total_benes
FROM (
SELECT
jv.contract_number,
DATE_TRUNC('day', jv.week_start) AS week_start,
DATE_TRUNC('day', jv.week_end) AS week_end,
MAX(bs.benes_searched) AS total_benes
FROM ab2d.job_view AS jv
LEFT JOIN event.event_bene_search AS bs ON bs.job_id = jv.job_uuid
WHERE jv.status = 'SUCCESSFUL'
GROUP BY jv.contract_number, jv.week_start, jv.week_end) t
GROUP BY t.week_start, t.week_end
ORDER BY week_start DESC;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE VIEW ab2d_prod_contracts_one_job_minimum AS
SELECT
COUNT(DISTINCT c.contract_number) AS "Contracts, at least 1 Job"
FROM ab2d.contract_view c
INNER JOIN ab2d.job_view j ON j.contract_number = c.contract_number
WHERE c.contract_number NOT LIKE 'Z%';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE VIEW ab2d_prod_contracts_view AS
SELECT *
FROM contract_view;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
CREATE VIEW ab2d_prod_coverage_counts AS
SELECT
p.contract_number,
MAX(
CASE
WHEN p.service = 'AB2D'
THEN p.count
END
) AS AB2D,
MAX(
CASE
WHEN p.service = 'HPMS'
THEN p.count
END
) AS HPMS,
MAX(
CASE
WHEN p.service = 'BFD'
THEN p.count
END
) AS BFD,
year,
month
FROM (
SELECT DISTINCT ON (
contract_number,
service,
year,
month
) contract_number,
service,
create_at,
count,
year,
month
FROM lambda.coverage_counts
ORDER BY
contract_number,
service,
year,
month,
create_at desc) p
GROUP BY
contract_number,
year,
month;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
CREATE VIEW ab2d_prod_eob_search_summaries_1 AS
SELECT
event.event_bene_search.id AS "id[event_bene_search]",
time_of_event,
job_id,
event.event_bene_search.contract_number AS "contract_number[event_bene_search]",
benes_expected,
benes_searched,
num_opted_out,
benes_errored,
aws_id,
environment,
event.event_bene_search.organization AS "organization[event_bene_search]",
benes_queued,
eobs_fetched,
eobs_written,
eob_files,
benes_with_eobs,
job_view.id AS "id[job_view]",
job_uuid,
created_at,
completed_at,
expires_at,
resource_types,
status,
request_url,
output_format,
since,
fhir_version,
year_week,
week_start,
week_end,
job_view.organization AS "organization[job_view]",
job_view.contract_number AS "contract_number[job_view]",
contract_name
FROM event.event_bene_search
RIGHT JOIN job_view
ON job_id = job_uuid;
Loading