Skip to content

Commit dfc2768

Browse files
[PRMP-780] Fix add document journey (#875)
1 parent 835ef48 commit dfc2768

File tree

6 files changed

+60
-15
lines changed

6 files changed

+60
-15
lines changed

app/src/helpers/requests/uploadDocument.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ describe('uploadDocuments', () => {
9696
documentReferenceId,
9797
});
9898

99+
const requestBody = JSON.parse(mockedAxios.put.mock.calls[0][1] as string);
100+
99101
expect(mockedAxios.put).toHaveBeenCalledTimes(1);
100102
expect(mockedAxios.put).toHaveBeenCalledWith(
101103
baseUrl + endpoints.DOCUMENT_UPLOAD + `/${documentReferenceId}`,
@@ -107,6 +109,36 @@ describe('uploadDocuments', () => {
107109
},
108110
},
109111
);
112+
113+
expect(requestBody).toMatchObject({
114+
resourceType: 'DocumentReference',
115+
subject: {
116+
identifier: {
117+
system: 'https://fhir.nhs.uk/Id/nhs-number',
118+
value: nhsNumber,
119+
},
120+
},
121+
type: {
122+
coding: [
123+
{
124+
system: 'http://snomed.info/sct',
125+
code: '22151000087106',
126+
},
127+
],
128+
},
129+
content: [
130+
{
131+
attachment: expect.objectContaining({
132+
fileName: documents[0].file.name,
133+
contentType: documents[0].file.type,
134+
docType: documents[0].docType,
135+
clientId: documents[0].id,
136+
versionId: documents[0].versionId,
137+
}),
138+
},
139+
],
140+
});
141+
110142
expect(result).toEqual(mockUploadSession);
111143
});
112144

@@ -458,6 +490,7 @@ describe('uploadDocuments', () => {
458490
contentType: documents[0].file.type,
459491
docType: documents[0].docType,
460492
clientId: documents[0].id,
493+
versionId: documents[0].versionId,
461494
});
462495
});
463496
});

app/src/helpers/requests/uploadDocuments.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ const uploadDocuments = async ({
8282
baseHeaders,
8383
documentReferenceId,
8484
}: UploadDocumentsArgs): Promise<UploadSession> => {
85+
const attachments = documents.map((doc) => ({
86+
fileName: doc.file.name,
87+
contentType: doc.file.type,
88+
docType: doc.docType,
89+
clientId: doc.id,
90+
versionId: doc.versionId,
91+
}));
8592
const requestBody = {
8693
resourceType: 'DocumentReference',
8794
subject: {
@@ -100,13 +107,7 @@ const uploadDocuments = async ({
100107
},
101108
content: [
102109
{
103-
attachment: documents.map((doc) => ({
104-
fileName: doc.file.name,
105-
contentType: doc.file.type,
106-
docType: doc.docType,
107-
clientId: doc.id,
108-
versionId: doc.versionId,
109-
})),
110+
attachment: documentReferenceId ? attachments[0] : attachments,
110111
},
111112
],
112113
created: new Date(Date.now()).toISOString(),

app/src/helpers/test/testBuilders.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const buildDocument = (
8080
id: uuidv4(),
8181
docType: docType ?? DOCUMENT_TYPE.ARF,
8282
attempts: 0,
83+
versionId: '1',
8384
};
8485
return mockDocument;
8586
};

lambdas/services/update_document_reference_service.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from services.document_service import DocumentService
1111
from services.put_fhir_document_reference_service import PutFhirDocumentReferenceService
1212
from utils.audit_logging_setup import LoggingService
13-
from utils.common_query_filters import CurrentStatusFile
13+
from utils.common_query_filters import CurrentStatusFile, NotDeleted
1414
from utils.constants.ssm import UPLOAD_PILOT_ODS_ALLOWED_LIST
1515
from utils.dynamo_utils import DocTypeTableRouter
1616
from utils.exceptions import (
@@ -155,7 +155,15 @@ def parse_document(self, document: dict) -> UploadRequestDocument:
155155

156156
return validated_doc
157157

158-
def stop_if_upload_is_in_progress(self, previous_records: list[DocumentReference]):
158+
def stop_if_upload_is_in_progress(self, nhs_number: str):
159+
previous_records = (
160+
self.document_service.fetch_available_document_references_by_type(
161+
nhs_number=nhs_number,
162+
doc_type=SupportedDocumentTypes.LG,
163+
query_filter=NotDeleted,
164+
)
165+
)
166+
159167
if any(
160168
self.document_service.is_upload_in_process(document)
161169
for document in previous_records

lambdas/services/upload_document_reference_service.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from botocore.exceptions import ClientError
55
from enums.metadata_field_names import DocumentReferenceMetadataFields
66
from enums.virus_scan_result import VirusScanResult
7-
from lambdas.enums.lambda_error import LambdaError
8-
from lambdas.enums.snomed_codes import SnomedCodes
9-
from lambdas.utils.dynamo_utils import DocTypeTableRouter
10-
from lambdas.utils.lambda_exceptions import InvalidDocTypeException
11-
from lambdas.utils.s3_utils import DocTypeS3BucketRouter
7+
from enums.lambda_error import LambdaError
8+
from enums.snomed_codes import SnomedCodes
9+
from utils.dynamo_utils import DocTypeTableRouter
10+
from utils.lambda_exceptions import InvalidDocTypeException
11+
from utils.s3_utils import DocTypeS3BucketRouter
1212
from models.document_reference import DocumentReference
1313
from services.base.dynamo_service import DynamoDBService
1414
from services.base.s3_service import S3Service

lambdas/tests/e2e/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
LLOYD_GEORGE_S3_BUCKET = os.environ.get("NDR_S3_BUCKET") or ""
1818
APIM_ENDPOINT = "internal-dev.api.service.nhs.uk"
1919
PDM_SNOMED = 717391000000106
20-
20+
MTLS_ENDPOINT = os.environ.get("MTLS_ENDPOINT")
21+
CLIENT_CERT_PATH = os.environ.get("CLIENT_CERT_PATH")
22+
CLIENT_KEY_PATH = os.environ.get("CLIENT_KEY_PATH")
2123

2224
@pytest.fixture
2325
def test_data():

0 commit comments

Comments
 (0)