Skip to content

Commit f9941b0

Browse files
authored
[NDR-210] adding PCSE ods code to custodian (#755)
1 parent f3853fb commit f9941b0

File tree

6 files changed

+23
-7
lines changed

6 files changed

+23
-7
lines changed

lambdas/services/bulk_upload_service.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
validate_filename_with_patient_details_strict,
3939
validate_lg_file_names,
4040
)
41+
from utils.ods_utils import PCSE_ODS_CODE
4142
from utils.request_context import request_context
4243
from utils.unicode_utils import (
4344
contains_accent_char,
@@ -395,13 +396,17 @@ def convert_to_document_reference(
395396
).strftime("%Y-%m-%d")
396397
else:
397398
scan_date_formatted = None
399+
if current_gp_ods in PatientOdsInactiveStatus.list():
400+
custodian = PCSE_ODS_CODE
401+
else:
402+
custodian = current_gp_ods
398403
document_reference = DocumentReference(
399404
id=str(uuid.uuid4()),
400405
nhs_number=nhs_number,
401406
file_name=file_name,
402407
s3_bucket_name=s3_bucket_name,
403408
current_gp_ods=current_gp_ods,
404-
custodian=current_gp_ods,
409+
custodian=custodian,
405410
author=file_metadata.gp_practice_code,
406411
document_scan_creation=scan_date_formatted,
407412
doc_status="preliminary",

lambdas/services/post_fhir_document_reference_service.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from botocore.exceptions import ClientError
77
from enums.lambda_error import LambdaError
8+
from enums.patient_ods_inactive_status import PatientOdsInactiveStatus
89
from enums.snomed_codes import SnomedCode, SnomedCodes
910
from models.document_reference import DocumentReference
1011
from models.fhir.R4.fhir_document_reference import SNOMED_URL, Attachment
@@ -24,6 +25,7 @@
2425
PdsErrorException,
2526
)
2627
from utils.lambda_exceptions import CreateDocumentRefException
28+
from utils.ods_utils import PCSE_ODS_CODE
2729
from utils.utilities import create_reference_id, get_pds_service, validate_nhs_number
2830

2931
logger = LoggingService(__name__)
@@ -140,15 +142,19 @@ def _create_document_reference(
140142
) -> DocumentReference:
141143
"""Create a document reference model"""
142144
document_id = create_reference_id()
145+
146+
custodian = fhir_doc.custodian.identifier.value if fhir_doc.custodian else None
147+
if not custodian:
148+
custodian = (
149+
current_gp_ods
150+
if current_gp_ods not in PatientOdsInactiveStatus.list()
151+
else PCSE_ODS_CODE
152+
)
143153
document_reference = DocumentReference(
144154
id=document_id,
145155
nhs_number=nhs_number,
146156
current_gp_ods=current_gp_ods,
147-
custodian=(
148-
fhir_doc.custodian.identifier.value
149-
if fhir_doc.custodian
150-
else current_gp_ods
151-
),
157+
custodian=custodian,
152158
s3_bucket_name=self.staging_bucket_name,
153159
author=fhir_doc.author[0].identifier.value,
154160
content_type=fhir_doc.content[0].attachment.contentType,

lambdas/services/process_mns_message_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from services.document_service import DocumentService
1212
from utils.audit_logging_setup import LoggingService
1313
from utils.exceptions import PdsErrorException
14+
from utils.ods_utils import PCSE_ODS_CODE
1415
from utils.utilities import get_pds_service
1516

1617
logger = LoggingService(__name__)
@@ -24,7 +25,7 @@ def __init__(self):
2425
self.sqs_service = SQSService()
2526
self.queue = os.getenv("MNS_NOTIFICATION_QUEUE_URL")
2627
self.DOCUMENT_UPDATE_FIELDS = {"current_gp_ods", "custodian", "last_updated"}
27-
self.PCSE_ODS = "X4S4L"
28+
self.PCSE_ODS = PCSE_ODS_CODE
2829

2930
def handle_mns_notification(self, message: MNSSQSMessage):
3031
try:

lambdas/services/upload_document_reference_service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def _process_document_reference(
100100
logger.warning(f"Document {document_reference.id} failed virus scan")
101101
document_reference.file_size = object_size
102102
document_reference.uploaded = True
103+
document_reference.uploading = False
103104
self.update_dynamo_table(document_reference, virus_scan_result)
104105

105106
except Exception as e:
@@ -196,6 +197,7 @@ def update_dynamo_table(
196197
"file_location",
197198
"file_size",
198199
"uploaded",
200+
"uploading",
199201
}
200202

201203
self.document_service.update_document(

lambdas/tests/unit/services/test_upload_document_reference_service.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ def test_update_dynamo_table_clean_scan_result(service, mock_document_reference)
334334
"file_location",
335335
"file_size",
336336
"uploaded",
337+
"uploading",
337338
},
338339
)
339340

lambdas/utils/ods_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Sometimes, a patient will not have a generalPractitioner on PDS. Internally, we can also add codes to mark inactive
88
patients for reporting purposes. The only values that should be considered 'active' are valid ODS codes.
99
"""
10+
PCSE_ODS_CODE = "X4S4L"
1011

1112

1213
def is_ods_code_active(gp_ods) -> bool:

0 commit comments

Comments
 (0)