-
Notifications
You must be signed in to change notification settings - Fork 1
PRMP-643 MNS update with review table #840
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
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
89fccdc
[PRMP-643] Add document review models and status enumeration
NogaNHS 397eb0a
[PRMP-643] Refactor document review models and update document handli…
NogaNHS 1b6ff81
[PRMP-643] update MNS service tests for document reviews
NogaNHS 43975a1
Merge branch 'main' into PRMP-643
NogaNHS 81727f4
set default model class to DocumentReference in fetch_documents method
NogaNHS e403c16
Merge branch 'main' into PRMP-643
NogaNHS 65f132e
Update document review model and status enumeration
NogaNHS d713065
Refactor update_patient_ods_code to remove unnecessary table parameter
NogaNHS 88b2f1e
Merge branch 'main' into PRMP-643
NogaNHS 03309bb
Refactor type hints to use union operator for document return types
NogaNHS d0a9d61
Merge branch 'main' into PRMP-643
NogaNHS 88a3a6c
[PRMP-643] PR comments
NogaNHS 7af8e60
[PRMP-643] Implement DocumentReferenceService and DocumentUploadRevie…
NogaNHS 6cc2a43
[PRMP-643] Fix parameter names in document service fetch calls for co…
NogaNHS ef5149a
[PRMP-643] Add unit tests for DocumentUploadReviewService and update …
NogaNHS 8b97a84
[PRMP-643] Add unit tests for DocumentReferenceService and update Doc…
NogaNHS fb1a8be
[PRMP-643] format
NogaNHS 4af40b3
[PRMP-643] Add mock environment variables for DocumentUploadReviewSer…
NogaNHS 887b193
[PRMP-643]Update mock environment variable for DocumentReviewService …
NogaNHS 6cc9622
Merge branch 'main' into PRMP-643
NogaNHS 18c2c0a
Remove table_name from document fetch call
NogaNHS 6493f55
Merge branch 'main' into PRMP-643
NogaNHS 1c93545
Refactor document fetch call to use 'table_name' instead of 'table'
NogaNHS f7fd4ec
Refactor document fetch call to use 'table_name' instead of 'table' 2
NogaNHS 5dfb610
Merge branch 'main' into PRMP-643
NogaNHS ebd93b2
Add feature flag for document review iteration 3 and update related s…
NogaNHS 96dd4a6
Merge branch 'main' into PRMP-643
NogaNHS 5cb90e5
Refactor document service to use 'table_name' type hint and improve v…
NogaNHS db76083
Merge branch 'main' into PRMP-643
NogaNHS 0db6327
PRMP-643 Refactor document services to use cached environment variabl…
NogaNHS 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 hidden or 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,7 @@ | ||
| from enum import StrEnum | ||
|
|
||
|
|
||
| class DocumentReviewStatus(StrEnum): | ||
| PENDING_REVIEW = "PENDING_REVIEW" | ||
| APPROVED = "APPROVED" | ||
| REJECTED = "REJECTED" | ||
This file contains hidden or 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 hidden or 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 hidden or 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,48 @@ | ||
| import uuid | ||
| from typing import Optional | ||
|
|
||
| from enums.document_review_status import DocumentReviewStatus | ||
| from enums.metadata_field_names import DocumentReferenceMetadataFields | ||
| from enums.snomed_codes import SnomedCodes | ||
| from pydantic import BaseModel, ConfigDict, Field | ||
| from pydantic.alias_generators import to_pascal | ||
|
|
||
|
|
||
| class DocumentReviewFileDetails(BaseModel): | ||
| model_config = ConfigDict( | ||
| validate_by_alias=True, | ||
| validate_by_name=True, | ||
| alias_generator=to_pascal, | ||
| ) | ||
|
|
||
| file_name: str | ||
| file_location: str | ||
|
|
||
|
|
||
| class DocumentUploadReviewReference(BaseModel): | ||
| model_config = ConfigDict( | ||
| validate_by_alias=True, | ||
| validate_by_name=True, | ||
| alias_generator=to_pascal, | ||
| use_enum_values=True, | ||
| ) | ||
| id: str = Field( | ||
| default_factory=lambda: str(uuid.uuid4()), | ||
| alias=str(DocumentReferenceMetadataFields.ID.value), | ||
| ) | ||
| author: str | ||
| custodian: str | ||
| review_status: DocumentReviewStatus = Field( | ||
| default=DocumentReviewStatus.PENDING_REVIEW | ||
| ) | ||
| review_reason: str | ||
| review_date: int = Field(default=None) | ||
steph-torres-nhs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| reviewer: str = Field(default=None) | ||
| upload_date: int | ||
steph-torres-nhs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| files: list[DocumentReviewFileDetails] | ||
| nhs_number: str | ||
| ttl: Optional[int] = Field( | ||
| alias=str(DocumentReferenceMetadataFields.TTL.value), default=None | ||
| ) | ||
| document_reference_id: str = Field(default=None) | ||
| document_snomed_code_type: str = Field(default=SnomedCodes.LLOYD_GEORGE.value.code) | ||
This file contains hidden or 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,74 @@ | ||
| from datetime import datetime | ||
|
|
||
| from enums.supported_document_types import SupportedDocumentTypes | ||
| from models.document_reference import DocumentReference | ||
| from services.document_service import DocumentService | ||
| from utils.audit_logging_setup import LoggingService | ||
| from utils.dynamo_utils import filter_uploaded_docs_and_recently_uploading_docs | ||
| from utils.exceptions import FileUploadInProgress, NoAvailableDocument | ||
|
|
||
| logger = LoggingService(__name__) | ||
|
|
||
|
|
||
| class DocumentReferenceService(DocumentService): | ||
| """Service for handling DocumentReference operations.""" | ||
|
|
||
| def __init__(self, doc_type: SupportedDocumentTypes = SupportedDocumentTypes.LG): | ||
| super().__init__() | ||
| self.doc_type = doc_type | ||
|
|
||
| @property | ||
| def table_name(self) -> str: | ||
| return self.doc_type.get_dynamodb_table_name() | ||
steph-torres-nhs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @property | ||
| def model_class(self) -> type: | ||
| return DocumentReference | ||
|
|
||
| @property | ||
| def s3_bucket(self) -> str: | ||
| return self.doc_type.get_s3_bucket_name() | ||
|
|
||
| def get_available_lloyd_george_record_for_patient( | ||
| self, nhs_number: str | ||
| ) -> list[DocumentReference]: | ||
| """Get available Lloyd George records for a patient, checking for upload status.""" | ||
| filter_expression = filter_uploaded_docs_and_recently_uploading_docs() | ||
| available_docs = self.fetch_documents_from_table_with_nhs_number( | ||
| nhs_number, | ||
| query_filter=filter_expression, | ||
| ) | ||
|
|
||
| file_in_progress_message = ( | ||
| "The patients Lloyd George record is in the process of being uploaded" | ||
| ) | ||
| if not available_docs: | ||
| raise NoAvailableDocument() | ||
| for document in available_docs: | ||
| if document.uploading and not document.uploaded: | ||
| raise FileUploadInProgress(file_in_progress_message) | ||
| return available_docs | ||
|
|
||
| def update_patient_ods_code( | ||
| self, | ||
| patient_documents: list[DocumentReference], | ||
| updated_ods_code: str, | ||
| ) -> None: | ||
| update_field = {"current_gp_ods", "custodian", "last_updated"} | ||
| if not patient_documents: | ||
| return | ||
|
|
||
| for reference in patient_documents: | ||
| logger.info("Updating patient document reference...") | ||
|
|
||
| if ( | ||
| reference.current_gp_ods != updated_ods_code | ||
| or reference.custodian != updated_ods_code | ||
| ): | ||
| reference.current_gp_ods = updated_ods_code | ||
| reference.custodian = updated_ods_code | ||
| reference.last_updated = int(datetime.now().timestamp()) | ||
|
|
||
| self.update_document( | ||
| document=reference, update_fields_name=update_field | ||
| ) | ||
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.