Skip to content

Commit f68b2d6

Browse files
Merge branch 'main' into kc/APP-675-JSON-API-plumbing
2 parents 89f9a9a + 10ac00c commit f68b2d6

4 files changed

Lines changed: 2575 additions & 14 deletions

File tree

apps/report-execution/src/libraries/nbs_custom.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,4 @@ def execute(
1919

2020
header = f'Custom Report For Table: {data_source_name}'
2121

22-
# TODO: datetimes are formatted '%0m/%0d/%Y %0H:%0M:%0S' in sas. # noqa: FIX002
23-
# Should this be a util/post processing/sql step in python land?
24-
2522
return ReportResult(content_type='table', content=content, header=header)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
config:
2+
seed: 19
3+
nbs:
4+
fk_tables: []
5+
6+
tables:
7+
- table_name: "[RDB].[dbo].[DM_INV_STD]"
8+
row_count: 500
9+
columns:
10+
- column_name: program_jurisdiction_oid
11+
data: random.choice(["1300400010", "1300400011", "1300400008", "1300400009", "1300400014", "1300400015", "1300400012"])
12+
- column_name: PATIENT_LOCAL_ID
13+
data: random.choice(["PSN20067002GA01", "PSN30076044GA01", "PSN10082059GA01", "PSN10087055GA01", "PSN10087069GA01", "PSN10087071GA01", "PSN10088042GA01", "PSN10089067GA01", "PSN10089161GA01", "PSN10094077GA01", "PSN10094080GA01"])
14+
- column_name: EVENT_DATE
15+
data: fake.date_between(start_date=date(2018, 5, 5), end_date=date(2025, 1, 5))
Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,83 @@
1+
import datetime
2+
import decimal
3+
14
import pytest
5+
import yaml
26

37
from src.execute_report import execute_report
48
from src.models import ReportSpec
59

10+
faker_schema = 'dm_inv_std.yaml'
11+
612

7-
@pytest.mark.usefixtures('setup_containers')
13+
@pytest.mark.usefixtures('setup_containers', 'fake_db_table')
814
@pytest.mark.integration
915
class TestIntegrationNbsCustomLibrary:
1016
"""Integration tests for the nbs_custom library."""
1117

12-
def test_execute_report(self):
18+
def test_execute_report_check_data(self, snapshot):
1319
report_spec = ReportSpec.model_validate(
1420
{
1521
'is_export': True,
1622
'is_builtin': True,
1723
'report_title': 'NBS Custom',
1824
'library_name': 'nbs_custom',
19-
# Filter operator is used here as it is a stable, small table
20-
'data_source_name': '[NBS_ODSE].[dbo].[Filter_operator]',
21-
'subset_query': 'SELECT * FROM [NBS_ODSE].[dbo].[Filter_operator]',
25+
'data_source_name': '[NBS_RDB].[dbo].[DM_INV_STD]',
26+
'subset_query': """
27+
SELECT PROGRAM_JURISDICTION_OID,
28+
PATIENT_LOCAL_ID,
29+
EVENT_DATE
30+
FROM rdb.dbo.DM_INV_STD
31+
ORDER BY PROGRAM_JURISDICTION_OID,
32+
PATIENT_LOCAL_ID,
33+
EVENT_DATE
34+
""",
2235
}
2336
)
2437

2538
result = execute_report(report_spec)
26-
assert result.header == (
27-
'Custom Report For Table: [NBS_ODSE].[dbo].[Filter_operator]'
39+
assert result.content_type == 'table'
40+
41+
data = result.content.data
42+
assert len(data) == 500
43+
assert len(data[0]) == len(result.content.columns)
44+
assert result.content.columns == [
45+
'PROGRAM_JURISDICTION_OID',
46+
'PATIENT_LOCAL_ID',
47+
'EVENT_DATE',
48+
]
49+
50+
snapshot.assert_match(yaml.dump(data), 'snapshot.yml')
51+
52+
for data in result.content.data:
53+
assert isinstance(data[0], decimal.Decimal)
54+
assert isinstance(data[1], str)
55+
assert isinstance(data[2], datetime.datetime)
56+
57+
def test_execute_report_no_data(self, snapshot):
58+
report_spec = ReportSpec.model_validate(
59+
{
60+
'is_export': True,
61+
'is_builtin': True,
62+
'report_title': 'NBS Custom',
63+
'library_name': 'nbs_custom',
64+
'data_source_name': '[NBS_RDB].[dbo].[DM_INV_STD]',
65+
'subset_query': """
66+
SELECT PROGRAM_JURISDICTION_OID,
67+
PATIENT_LOCAL_ID,
68+
EVENT_DATE
69+
FROM rdb.dbo.DM_INV_STD
70+
WHERE 1 = 2
71+
""",
72+
}
2873
)
29-
assert result.subheader is None
30-
assert result.description is None
74+
75+
result = execute_report(report_spec)
3176
assert result.content_type == 'table'
3277

33-
assert len(result.content.data) == 11
34-
assert len(result.content.data[0]) == len(result.content.columns)
78+
assert len(result.content.data) == 0
79+
assert result.content.columns == [
80+
'PROGRAM_JURISDICTION_OID',
81+
'PATIENT_LOCAL_ID',
82+
'EVENT_DATE',
83+
]

0 commit comments

Comments
 (0)