|
| 1 | +import argparse |
1 | 2 | import csv |
2 | 3 | import os |
3 | 4 | import shutil |
| 5 | +from datetime import date |
4 | 6 | from enum import StrEnum |
5 | 7 | from glob import glob |
6 | | -from typing import List, Dict, NamedTuple, Any |
7 | | -from datetime import date |
8 | | -import argparse |
| 8 | +from typing import Any, Dict, List, NamedTuple |
9 | 9 |
|
10 | 10 | import boto3 |
11 | 11 | from botocore.exceptions import ClientError |
@@ -196,25 +196,37 @@ def flatten(input_list: List[List[Any]]) -> List[Any]: |
196 | 196 | def build_valid_lg_file_name( |
197 | 197 | patient: Patient, file_count: int = 1, total_number: int = 3 |
198 | 198 | ) -> str: |
199 | | - return f"{file_count}of{total_number}_Lloyd_George_Record_[{patient.full_name}]_[{patient.nhs_number}]_[{patient.date_of_birth}].pdf" |
| 199 | + return ( |
| 200 | + f"{file_count}of{total_number}_Lloyd_George_Record_[" |
| 201 | + f"{patient.full_name}]_[{patient.nhs_number}]_[{patient.date_of_birth}].pdf" |
| 202 | + ) |
200 | 203 |
|
201 | 204 |
|
202 | 205 | def build_invalid_lg_file_name( |
203 | 206 | patient: Patient, file_count: int = 1, total_number: int = 3 |
204 | 207 | ) -> str: |
205 | | - return f"{file_count}of{total_number}_Lloyd_George_Record_[{patient.nhs_number}]_[{patient.full_name}]_[{patient.date_of_birth}].pdf" |
| 208 | + return ( |
| 209 | + f"{file_count}of{total_number}_Lloyd_George_Record_[" |
| 210 | + f"{patient.nhs_number}]_[{patient.full_name}]_[{patient.date_of_birth}].pdf" |
| 211 | + ) |
206 | 212 |
|
207 | 213 |
|
208 | 214 | def build_invalid_file_number_lg_file_name( |
209 | 215 | patient: Patient, file_count: int = 1, total_number: int = 3 |
210 | 216 | ) -> str: |
211 | | - return f"{file_count}of{total_number - 1}_Lloyd_George_Record[{patient.full_name}]_[{patient.nhs_number}]_[{patient.date_of_birth}].pdf" |
| 217 | + return ( |
| 218 | + f"{file_count}of{total_number - 1}_Lloyd_George_Record[" |
| 219 | + f"{patient.full_name}]_[{patient.nhs_number}]_[{patient.date_of_birth}].pdf" |
| 220 | + ) |
212 | 221 |
|
213 | 222 |
|
214 | 223 | def build_invalid_nhs_number_lg_file_name( |
215 | 224 | patient: Patient, file_count: int = 1, total_number: int = 3 |
216 | 225 | ) -> str: |
217 | | - return f"{file_count}of{total_number}_Lloyd_George_Record_[{patient.full_name}]_[{str(patient.nhs_number)[:-2]}01]_[{patient.date_of_birth}].pdf" |
| 226 | + return ( |
| 227 | + f"{file_count}of{total_number}_Lloyd_George_Record_[" |
| 228 | + f"{patient.full_name}]_[{str(patient.nhs_number)[:-2]}01]_[{patient.date_of_birth}].pdf" |
| 229 | + ) |
218 | 230 |
|
219 | 231 |
|
220 | 232 | def build_many_file_names(patient: Patient, total_number: int = 3) -> List[str]: |
@@ -305,7 +317,10 @@ def build_metadata_csv_rows(patient: Patient, total_number: int = 3) -> list[str |
305 | 317 | def build_metadata_csv( |
306 | 318 | patient_list: List[Patient], total_number_for_each: int = 3 |
307 | 319 | ) -> str: |
308 | | - header_row = "FILEPATH,PAGE COUNT,GP-PRACTICE-CODE,NHS-NO,SECTION,SUB-SECTION,SCAN-DATE,SCAN-ID,USER-ID,UPLOAD" |
| 320 | + header_row = ( |
| 321 | + "FILEPATH,PAGE COUNT,GP-PRACTICE-CODE,NHS-NO," |
| 322 | + "SECTION,SUB-SECTION,SCAN-DATE,SCAN-ID,USER-ID,UPLOAD" |
| 323 | + ) |
309 | 324 | all_rows = [] |
310 | 325 | for patient in patient_list: |
311 | 326 | row = build_metadata_csv_rows( |
@@ -374,7 +389,12 @@ def upload_lg_files_to_staging(): |
374 | 389 | files = ["metadata.csv"] + glob("*/*Lloyd_George_Record*.pdf") |
375 | 390 | client = boto3.client("s3") |
376 | 391 | for file in files: |
377 | | - client.upload_file(Filename=file, Bucket=STAGING_BUCKET, Key=file) |
| 392 | + client.upload_file( |
| 393 | + Filename=file, |
| 394 | + Bucket=STAGING_BUCKET, |
| 395 | + Key=file, |
| 396 | + ExtraArgs={"StorageClass": "INTELLIGENT_TIERING"}, |
| 397 | + ) |
378 | 398 |
|
379 | 399 | scan_result = "Clean" |
380 | 400 | if file.startswith(tuple(NHS_NUMBER_INFECTED)): |
@@ -580,15 +600,17 @@ def get_user_input(): |
580 | 600 | if ( |
581 | 601 | args.upload |
582 | 602 | or input( |
583 | | - "Would you like to upload the test files to S3 and add the virus-scan tag? (y/N) " |
| 603 | + "Would you like to upload the test files to S3 " |
| 604 | + "and add the virus-scan tag? (y/N) " |
584 | 605 | ).lower() |
585 | 606 | == "y" |
586 | 607 | ): |
587 | 608 | upload_lg_files_to_staging() |
588 | 609 | if ( |
589 | 610 | args.empty_lloydgeorge_store |
590 | 611 | or input( |
591 | | - "Would you like to remove all records from the LloydGeorgeRecord Bucket (y/N) " |
| 612 | + "Would you like to remove all records " |
| 613 | + "from the LloydGeorgeRecord Bucket (y/N) " |
592 | 614 | ).lower() |
593 | 615 | == "y" |
594 | 616 | ): |
|
0 commit comments