|
5 | 5 |
|
6 | 6 | from botocore.exceptions import ClientError |
7 | 7 | from enums.lambda_error import LambdaError |
| 8 | +from enums.patient_ods_inactive_status import PatientOdsInactiveStatus |
8 | 9 | from enums.snomed_codes import SnomedCode, SnomedCodes |
9 | 10 | from models.document_reference import DocumentReference |
10 | 11 | from models.fhir.R4.fhir_document_reference import SNOMED_URL, Attachment |
|
24 | 25 | PdsErrorException, |
25 | 26 | ) |
26 | 27 | from utils.lambda_exceptions import CreateDocumentRefException |
| 28 | +from utils.ods_utils import PCSE_ODS_CODE |
27 | 29 | from utils.utilities import create_reference_id, get_pds_service, validate_nhs_number |
28 | 30 |
|
29 | 31 | logger = LoggingService(__name__) |
@@ -140,15 +142,19 @@ def _create_document_reference( |
140 | 142 | ) -> DocumentReference: |
141 | 143 | """Create a document reference model""" |
142 | 144 | 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 | + ) |
143 | 153 | document_reference = DocumentReference( |
144 | 154 | id=document_id, |
145 | 155 | nhs_number=nhs_number, |
146 | 156 | 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, |
152 | 158 | s3_bucket_name=self.staging_bucket_name, |
153 | 159 | author=fhir_doc.author[0].identifier.value, |
154 | 160 | content_type=fhir_doc.content[0].attachment.contentType, |
|
0 commit comments