-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* lloyd george document manifest lambda and test * lloyd george manifest code tidy up * Separate dynamoDB repo code into service * Filter documents by type in the manifest handler * [PRMDR-270] Adding explicit import for proper compiling Fixing test so it can be run by Windows users * [PRMDR-180] finished on the code; need to rework a few tests due to refactoring * PRMDR-180 * PRMDR-180 Adding more tests, some renaming, some refactoring, some import cleanup * PRMDR-180 Finished testing the Manifest Dynamo Service * PRMDR-180 Small cleanup, removing unnecessary comments and imports * Tests * PRMDR-180 Fix for existing tests * PRMDR-180 More test fixes * PRMDR-180 Adding final bits for comprehensive unit tests * PRMDR-180 Making changes and refactors as per code review * PRMDR-180 fixes for tests based on code review changes * PRMDR-180 Changing doctype validation logic and adding test as per code review * PRMDR-180 Changes as per code review --------- Co-authored-by: Richard Smith <richard.smith33@nhs.net>
- Loading branch information
1 parent
40bafad
commit d2a43ae
Showing
11 changed files
with
502 additions
and
106 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import logging | ||
import os | ||
|
||
from enums.supported_document_types import SupportedDocumentTypes | ||
from services.dynamo_service import DynamoDBService | ||
from enums.metadata_field_names import DocumentReferenceMetadataFields | ||
from models.document import Document | ||
from utils.exceptions import DynamoDbException | ||
|
||
logger = logging.getLogger() | ||
logger.setLevel(logging.INFO) | ||
|
||
|
||
class ManifestDynamoService(DynamoDBService): | ||
|
||
def discover_uploaded_documents( | ||
self, nhs_number: str, doc_types: str | ||
) -> list[Document]: | ||
arf_documents = [] | ||
lg_documents = [] | ||
|
||
if SupportedDocumentTypes.ARF.name in doc_types: | ||
arf_documents = self.fetch_documents_from_table(nhs_number, os.environ["DOCUMENT_STORE_DYNAMODB_NAME"]) | ||
if SupportedDocumentTypes.LG.name in doc_types: | ||
lg_documents = self.fetch_documents_from_table(nhs_number, os.environ["LLOYD_GEORGE_DYNAMODB_NAME"]) | ||
|
||
return arf_documents + lg_documents | ||
|
||
def fetch_documents_from_table(self, nhs_number: str, table: str) -> list[Document]: | ||
documents = [] | ||
response = self.query_service( | ||
table, | ||
"NhsNumberIndex", | ||
"NhsNumber", | ||
nhs_number, | ||
[ | ||
DocumentReferenceMetadataFields.FILE_NAME, | ||
DocumentReferenceMetadataFields.FILE_LOCATION, | ||
DocumentReferenceMetadataFields.VIRUS_SCAN_RESULT, | ||
], | ||
) | ||
|
||
for item in response["Items"]: | ||
document = Document( | ||
nhs_number=nhs_number, | ||
file_name=item[DocumentReferenceMetadataFields.FILE_NAME.field_name], | ||
virus_scanner_result=item[ | ||
DocumentReferenceMetadataFields.VIRUS_SCAN_RESULT.field_name | ||
], | ||
file_location=item[ | ||
DocumentReferenceMetadataFields.FILE_LOCATION.field_name | ||
], | ||
) | ||
documents.append(document) | ||
return documents |
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.