-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PRMP-1063] blank bulk upload reports don't create a file #455
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aff278e
[PRMP-1063] blank bulk upload reports don't create a file
AndyFlintNHS 62866aa
[PRMP-1063] moved CSV creation and upload logic into separate function
AndyFlintNHS 801e89b
[PRMP-1063] correcting log typo, adding param types to function
AndyFlintNHS a7076d3
Merge branch 'main' into PRMP-1063
AndyFlintNHS 1279026
[PRMP-1063] created unit test for csv and s3 writer, mocked existing …
AndyFlintNHS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,16 +158,19 @@ def generate_success_report(self, ods_reports: list[OdsReport]): | |
[str(patient[0]), str(report.uploader_ods_code), str(patient[1])] | ||
) | ||
|
||
self.write_additional_report_items_to_csv( | ||
file_name=file_name, headers=headers, rows_to_write=data_rows | ||
) | ||
if data_rows: | ||
self.write_additional_report_items_to_csv( | ||
file_name=file_name, headers=headers, rows_to_write=data_rows | ||
) | ||
|
||
logger.info("Uploading daily success report file to S3") | ||
self.s3_service.upload_file( | ||
s3_bucket_name=self.reports_bucket, | ||
file_key=f"{self.s3_key_prefix}/{file_name}", | ||
file_name=f"/tmp/{file_name}", | ||
) | ||
logger.info("Uploading daily success report file to S3") | ||
self.s3_service.upload_file( | ||
s3_bucket_name=self.reports_bucket, | ||
file_key=f"{self.s3_key_prefix}/{file_name}", | ||
file_name=f"/tmp/{file_name}", | ||
) | ||
else: | ||
logger.info("No data to report for daily success report file") | ||
|
||
def generate_suspended_report(self, ods_reports: list[OdsReport]): | ||
file_name = ( | ||
|
@@ -186,16 +189,19 @@ def generate_suspended_report(self, ods_reports: list[OdsReport]): | |
[str(patient[0]), str(report.uploader_ods_code), str(patient[1])] | ||
) | ||
|
||
self.write_additional_report_items_to_csv( | ||
file_name=file_name, headers=headers, rows_to_write=data_rows | ||
) | ||
if data_rows: | ||
self.write_additional_report_items_to_csv( | ||
file_name=file_name, headers=headers, rows_to_write=data_rows | ||
) | ||
|
||
logger.info("Uploading daily suspended report file to S3") | ||
self.s3_service.upload_file( | ||
s3_bucket_name=self.reports_bucket, | ||
file_key=f"{self.s3_key_prefix}/{file_name}", | ||
file_name=f"/tmp/{file_name}", | ||
) | ||
logger.info("Uploading daily suspended report file to S3") | ||
self.s3_service.upload_file( | ||
s3_bucket_name=self.reports_bucket, | ||
file_key=f"{self.s3_key_prefix}/{file_name}", | ||
file_name=f"/tmp/{file_name}", | ||
) | ||
else: | ||
logger.info("No data to report for daily suspended report file") | ||
|
||
def generate_deceased_report(self, ods_reports: list[OdsReport]): | ||
file_name = ( | ||
|
@@ -220,16 +226,19 @@ def generate_deceased_report(self, ods_reports: list[OdsReport]): | |
] | ||
) | ||
|
||
self.write_additional_report_items_to_csv( | ||
file_name=file_name, headers=headers, rows_to_write=data_rows | ||
) | ||
if data_rows: | ||
self.write_additional_report_items_to_csv( | ||
file_name=file_name, headers=headers, rows_to_write=data_rows | ||
) | ||
|
||
logger.info("Uploading daily deceased report file to S3") | ||
self.s3_service.upload_file( | ||
s3_bucket_name=self.reports_bucket, | ||
file_key=f"{self.s3_key_prefix}/{file_name}", | ||
file_name=f"/tmp/{file_name}", | ||
) | ||
logger.info("Uploading daily deceased report file to S3") | ||
self.s3_service.upload_file( | ||
s3_bucket_name=self.reports_bucket, | ||
file_key=f"{self.s3_key_prefix}/{file_name}", | ||
file_name=f"/tmp/{file_name}", | ||
) | ||
else: | ||
logger.info("No data to report for daily deceased report file") | ||
|
||
def generate_restricted_report(self, ods_reports: list[OdsReport]): | ||
file_name = ( | ||
|
@@ -248,16 +257,19 @@ def generate_restricted_report(self, ods_reports: list[OdsReport]): | |
[str(patient[0]), str(report.uploader_ods_code), str(patient[1])] | ||
) | ||
|
||
self.write_additional_report_items_to_csv( | ||
file_name=file_name, headers=headers, rows_to_write=data_rows | ||
) | ||
if data_rows: | ||
self.write_additional_report_items_to_csv( | ||
file_name=file_name, headers=headers, rows_to_write=data_rows | ||
) | ||
|
||
logger.info("Uploading daily restricted report file to S3") | ||
self.s3_service.upload_file( | ||
s3_bucket_name=self.reports_bucket, | ||
file_key=f"{self.s3_key_prefix}/{file_name}", | ||
file_name=f"/tmp/{file_name}", | ||
) | ||
logger.info("Uploading daily restricted report file to S3") | ||
self.s3_service.upload_file( | ||
s3_bucket_name=self.reports_bucket, | ||
file_key=f"{self.s3_key_prefix}/{file_name}", | ||
file_name=f"/tmp/{file_name}", | ||
) | ||
else: | ||
logger.info("No data to report for daily deceased report file") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. daily restricted* There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corrected |
||
|
||
def generate_rejected_report(self, ods_reports: list[OdsReport]): | ||
file_name = ( | ||
|
@@ -283,16 +295,19 @@ def generate_rejected_report(self, ods_reports: list[OdsReport]): | |
] | ||
) | ||
|
||
self.write_additional_report_items_to_csv( | ||
file_name=file_name, headers=headers, rows_to_write=data_rows | ||
) | ||
if data_rows: | ||
self.write_additional_report_items_to_csv( | ||
file_name=file_name, headers=headers, rows_to_write=data_rows | ||
) | ||
|
||
logger.info("Uploading daily rejected report file to S3") | ||
self.s3_service.upload_file( | ||
s3_bucket_name=self.reports_bucket, | ||
file_key=f"{self.s3_key_prefix}/{file_name}", | ||
file_name=f"/tmp/{file_name}", | ||
) | ||
logger.info("Uploading daily rejected report file to S3") | ||
self.s3_service.upload_file( | ||
s3_bucket_name=self.reports_bucket, | ||
file_key=f"{self.s3_key_prefix}/{file_name}", | ||
file_name=f"/tmp/{file_name}", | ||
) | ||
else: | ||
logger.info("No data to report for daily rejected report file") | ||
|
||
@staticmethod | ||
def write_items_to_csv(items: list[BulkUploadReport], csv_file_path: str): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to take this out to a new function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like scope creep to me as the only functionality that has changed properly is line 173, though I agree that the code would be cleaner this way. @abbas-khan10 what do you reckon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no preference, I had considered this when first implementing as there is repetition. What were you thinking @NogaNHS? Something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bool would serve as a way of customising the log message for each report type as we want to be specific with which report wasn't created (open to discussion obviously) e.g. for the code above:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As opposed to doing a true/false return, I was going to suggest something more like this, so that it only calls 'write and upload' if it actually needs to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic has been broken out into a new function