Skip to content

Commit 603c9a2

Browse files
authored
[PRMP-1064] - Update bulk upload summary and ODS reports to contain t… (#457)
* [PRMP-1064] - Update bulk upload summary and ODS reports to contain total ingested * [prmp-1064] - refactor code to make total_ingested a set and add to it in the currently existing loops
1 parent 5271e16 commit 603c9a2

File tree

7 files changed

+45
-0
lines changed

7 files changed

+45
-0
lines changed

lambdas/models/bulk_upload_report_output.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def __init__(
1919
self.total_suspended = set()
2020
self.total_deceased = set()
2121
self.total_restricted = set()
22+
self.total_ingested = set()
2223

2324
def get_total_successful_nhs_numbers(self) -> list:
2425
if self.total_successful:
@@ -40,6 +41,9 @@ def get_total_deceased_count(self) -> int:
4041
def get_total_restricted_count(self) -> int:
4142
return len(self.total_restricted)
4243

44+
def get_total_ingested_count(self) -> int:
45+
return len(self.total_ingested)
46+
4347
@staticmethod
4448
def get_sorted(to_sort: set) -> list:
4549
return sorted(to_sort, key=lambda x: x[0]) if to_sort else []
@@ -64,6 +68,7 @@ def populate_report(self):
6468
logger.info(f"Generating ODS report file for {self.uploader_ods_code}")
6569

6670
for item in self.report_items:
71+
self.total_ingested.add(item.nhs_number)
6772
if item.upload_status == UploadStatus.COMPLETE:
6873
self.process_successful_report_item(item)
6974
elif item.upload_status == UploadStatus.FAILED:
@@ -143,6 +148,7 @@ def populate_report(self):
143148
ods_code_success_total = {}
144149

145150
for report in self.ods_reports:
151+
self.total_ingested.update(report.total_ingested)
146152
self.total_successful.update(report.total_successful)
147153
self.total_registered_elsewhere.update(report.total_registered_elsewhere)
148154
self.total_suspended.update(report.total_suspended)

lambdas/services/bulk_upload_report_service.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def generate_individual_ods_report(
8686

8787
self.write_summary_data_to_csv(
8888
file_name=file_name,
89+
total_ingested=ods_report.get_total_ingested_count(),
8990
total_successful=ods_report.get_total_successful_count(),
9091
total_registered_elsewhere=ods_report.get_total_registered_elsewhere_count(),
9192
total_suspended=ods_report.get_total_suspended_count(),
@@ -113,6 +114,7 @@ def generate_summary_report(self, ods_reports: list[OdsReport]):
113114

114115
self.write_summary_data_to_csv(
115116
file_name=file_name,
117+
total_ingested=summary_report.get_total_ingested_count(),
116118
total_successful=summary_report.get_total_successful_count(),
117119
total_registered_elsewhere=summary_report.get_total_registered_elsewhere_count(),
118120
total_suspended=summary_report.get_total_suspended_count(),
@@ -287,6 +289,7 @@ def write_items_to_csv(items: list[BulkUploadReport], csv_file_path: str):
287289
@staticmethod
288290
def write_summary_data_to_csv(
289291
file_name: str,
292+
total_ingested: int,
290293
total_successful: int,
291294
total_registered_elsewhere: int,
292295
total_suspended: int,
@@ -298,6 +301,7 @@ def write_summary_data_to_csv(
298301
writer = csv.writer(output_file)
299302

300303
writer.writerow(["Type", "Description", "Count"])
304+
writer.writerow(["Total", "Total Ingested", total_ingested])
301305
writer.writerow(["Total", "Total Successful", total_successful])
302306
writer.writerow(
303307
[

lambdas/tests/unit/helpers/data/bulk_upload/expected_bulk_upload_summary_report.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Type,Description,Count
2+
Total,Total Ingested,16
23
Total,Total Successful,10
34
Total,Successful - Registered Elsewhere,2
45
Total,Successful - Suspended,2

lambdas/tests/unit/helpers/data/bulk_upload/expected_ods_report_for_uploader_1.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Type,Description,Count
2+
Total,Total Ingested,8
23
Total,Total Successful,5
34
Total,Successful - Registered Elsewhere,1
45
Total,Successful - Suspended,1

lambdas/tests/unit/helpers/data/bulk_upload/expected_ods_report_for_uploader_2.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Type,Description,Count
2+
Total,Total Ingested,8
23
Total,Total Successful,5
34
Total,Successful - Registered Elsewhere,1
45
Total,Successful - Suspended,1

lambdas/tests/unit/models/test_bulk_upload_report_output.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ def test_report_base_get_sorted_returns_empty():
7878
def test_ods_report_populate_report_populates_successfully():
7979
expected = {
8080
"generated_at": get_timestamp(),
81+
"total_ingested": {
82+
"9000000000",
83+
"9000000001",
84+
"9000000002",
85+
"9000000003",
86+
"9000000004",
87+
"9000000005",
88+
"9000000006",
89+
"9000000007",
90+
},
8191
"total_successful": {
8292
("9000000000", "2012-01-13"),
8393
("9000000001", "2012-01-13"),
@@ -211,6 +221,7 @@ def test_ods_report_get_unsuccessful_reasons_data_rows_returns_correct_rows():
211221
def test_ods_report_populate_report_empty_list_populates_successfully():
212222
expected = {
213223
"generated_at": get_timestamp(),
224+
"total_ingested": set(),
214225
"total_successful": set(),
215226
"total_registered_elsewhere": set(),
216227
"total_suspended": set(),
@@ -275,6 +286,24 @@ def test_summary_report_populate_report_populates_successfully():
275286

276287
expected = {
277288
"generated_at": get_timestamp(),
289+
"total_ingested": {
290+
"9000000006",
291+
"9000000009",
292+
"9000000005",
293+
"9000000010",
294+
"9000000013",
295+
"9000000016",
296+
"9000000004",
297+
"9000000007",
298+
"9000000012",
299+
"9000000011",
300+
"9000000002",
301+
"9000000003",
302+
"9000000001",
303+
"9000000000",
304+
"9000000014",
305+
"9000000015",
306+
},
278307
"total_successful": {
279308
("9000000000", "2012-01-13"),
280309
("9000000001", "2012-01-13"),
@@ -336,6 +365,7 @@ def test_summary_report_populate_report_empty_reports_objects_populate_successfu
336365

337366
expected = {
338367
"generated_at": get_timestamp(),
368+
"total_ingested": set(),
339369
"total_successful": set(),
340370
"total_registered_elsewhere": set(),
341371
"total_suspended": set(),
@@ -359,6 +389,7 @@ def test_summary_report_populate_report_empty_reports_objects_populate_successfu
359389
def test_summary_report_populate_report_no_report_objects_populate_successfully():
360390
expected = {
361391
"generated_at": get_timestamp(),
392+
"total_ingested": set(),
362393
"total_successful": set(),
363394
"total_registered_elsewhere": set(),
364395
"total_suspended": set(),

lambdas/tests/unit/services/test_bulk_upload_report_service.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ def test_generate_individual_ods_report_creates_ods_report(
357357

358358
mock_write_summary_data_to_csv.assert_called_with(
359359
file_name=f"daily_statistical_report_bulk_upload_ods_summary_{MOCK_TIMESTAMP}_uploaded_by_{TEST_CURRENT_GP_ODS}.csv",
360+
total_ingested=8,
360361
total_successful=5,
361362
total_registered_elsewhere=1,
362363
total_suspended=1,

0 commit comments

Comments
 (0)