Skip to content

Commit d03c196

Browse files
committed
minor fixes
1 parent 94f88f7 commit d03c196

File tree

8 files changed

+242
-126
lines changed

8 files changed

+242
-126
lines changed

app/src/components/blocks/_patientDocuments/documentView/DocumentView.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';
22
import { describe, it, expect, vi, beforeEach, Mock } from 'vitest';
3-
import DocumentView, { DOCUMENT_VIEW_STATE } from './DocumentView';
3+
import DocumentView from './DocumentView';
44
import usePatient from '../../../../helpers/hooks/usePatient';
55
import useTitle from '../../../../helpers/hooks/useTitle';
66
import {

app/src/components/blocks/_patientDocuments/documentView/DocumentView.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ const DocumentView = ({
401401
<PatientSummary.Child item={PatientInfo.BIRTH_DATE} />
402402
</PatientSummary>
403403

404+
{/* PRMP-1584 hide this button */}
404405
{viewState === DOCUMENT_VIEW_STATE.VERSION_HISTORY && !isActiveVersion && (
405406
<Button
406407
data-testid="view-restore-version-button"

app/src/helpers/requests/getDocument.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type GetDocumentArgs = {
88
baseUrl: string;
99
baseHeaders: AuthHeaders;
1010
documentId: string;
11+
version?: string;
1112
};
1213

1314
export type GetDocumentResponse = {
@@ -20,6 +21,7 @@ const getDocument = async ({
2021
baseUrl,
2122
baseHeaders,
2223
documentId,
24+
version,
2325
}: GetDocumentArgs): Promise<GetDocumentResponse> => {
2426
if (isLocal) {
2527
return {
@@ -28,7 +30,9 @@ const getDocument = async ({
2830
};
2931
}
3032

31-
const gatewayUrl = baseUrl + endpoints.DOCUMENT_REFERENCE + `/${documentId}`;
33+
const gatewayUrl = version
34+
? `${baseUrl}${endpoints.DOCUMENT_REFERENCE}/${documentId}/_history/${version}`
35+
: `${baseUrl}${endpoints.DOCUMENT_REFERENCE}/${documentId}`;
3236

3337
try {
3438
const { data } = await axios.get<GetDocumentResponse>(gatewayUrl, {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ describe('getDocumentVersionHistoryResponse', () => {
206206
const result = await module.getDocumentVersionHistoryResponse(mockArgs);
207207

208208
const versions = result.entry!.map((e) => e.resource.meta?.versionId);
209-
expect(versions).toEqual(['3', '2', '1']);
209+
expect(versions).toEqual(['2', '4', '1', '5', '3']);
210210
});
211211
});
212212
});

app/src/helpers/test/getMockVersionHistory.ts

Lines changed: 134 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ import { DocumentReferenceStatus } from '../../types/fhirR4/documentReference';
55
export const mockDocumentVersionHistoryResponse: Bundle<FhirDocumentReference> = {
66
resourceType: 'Bundle',
77
type: 'history',
8-
total: 3,
8+
total: 5,
99
entry: [
1010
{
11-
fullUrl: 'urn:uuid:2a7a270e-aa1d-532e-8648-d5d8e3defb82',
11+
fullUrl: 'urn:uuid:c889dbbf-2e3a-5860-ab90-9421b5e29b86',
1212
resource: {
1313
resourceType: 'DocumentReference',
14-
id: '2a7a270e-aa1d-532e-8648-d5d8e3defb82',
14+
id: 'c889dbbf-2e3a-5860-ab90-9421b5e29b86',
1515
meta: {
16-
versionId: '3',
17-
lastUpdated: '2025-12-15T10:30:00Z',
16+
versionId: '2',
17+
lastUpdated: '2025-11-10T14:00:00Z',
1818
},
19-
status: DocumentReferenceStatus.Current,
19+
status: DocumentReferenceStatus.Superseded,
2020
type: {
2121
coding: [
2222
{
@@ -32,7 +32,7 @@ export const mockDocumentVersionHistoryResponse: Bundle<FhirDocumentReference> =
3232
value: '9000000009',
3333
},
3434
},
35-
date: '2025-12-15T10:30:00Z',
35+
date: '2025-11-10T14:00:00Z',
3636
author: [
3737
{
3838
identifier: {
@@ -53,23 +53,23 @@ export const mockDocumentVersionHistoryResponse: Bundle<FhirDocumentReference> =
5353
{
5454
attachment: {
5555
contentType: 'application/pdf',
56-
url: '/dev/testFile1.pdf',
57-
size: 3072,
58-
title: 'document_v3.pdf',
59-
creation: '2025-12-15T10:30:00Z',
56+
url: '/dev/testFile.pdf',
57+
size: 2048,
58+
title: 'document_v2.pdf',
59+
creation: '2025-11-10T14:00:00Z',
6060
},
6161
},
6262
],
6363
},
6464
},
6565
{
66-
fullUrl: 'urn:uuid:c889dbbf-2e3a-5860-ab90-9421b5e29b86',
66+
fullUrl: 'urn:uuid:a4f3c812-7e90-4b21-9f3d-6c1a2e84d057',
6767
resource: {
6868
resourceType: 'DocumentReference',
69-
id: 'c889dbbf-2e3a-5860-ab90-9421b5e29b86',
69+
id: 'a4f3c812-7e90-4b21-9f3d-6c1a2e84d057',
7070
meta: {
71-
versionId: '2',
72-
lastUpdated: '2025-11-10T14:00:00Z',
71+
versionId: '4',
72+
lastUpdated: '2026-01-20T08:45:00Z',
7373
},
7474
status: DocumentReferenceStatus.Superseded,
7575
type: {
@@ -87,31 +87,31 @@ export const mockDocumentVersionHistoryResponse: Bundle<FhirDocumentReference> =
8787
value: '9000000009',
8888
},
8989
},
90-
date: '2025-11-10T14:00:00Z',
90+
date: '2026-01-20T08:45:00Z',
9191
author: [
9292
{
9393
identifier: {
9494
system: 'https://fhir.nhs.uk/Id/ods-organization-code',
95-
value: 'Y12345',
95+
value: 'B67890',
9696
},
97-
display: 'Y12345',
97+
display: 'B67890',
9898
},
9999
],
100100
custodian: {
101101
identifier: {
102102
system: 'https://fhir.nhs.uk/Id/ods-organization-code',
103-
value: 'Y12345',
103+
value: 'B67890',
104104
},
105-
display: 'Y12345',
105+
display: 'B67890',
106106
},
107107
content: [
108108
{
109109
attachment: {
110110
contentType: 'application/pdf',
111-
url: '/dev/testFile.pdf',
112-
size: 2048,
113-
title: 'document_v2.pdf',
114-
creation: '2025-11-10T14:00:00Z',
111+
url: '/dev/testFile4.pdf',
112+
size: 4096,
113+
title: 'document_v4.pdf',
114+
creation: '2026-01-20T08:45:00Z',
115115
},
116116
},
117117
],
@@ -172,5 +172,115 @@ export const mockDocumentVersionHistoryResponse: Bundle<FhirDocumentReference> =
172172
],
173173
},
174174
},
175+
{
176+
fullUrl: 'urn:uuid:e7b1d94f-3c62-4a87-b5e0-8f2d1a6c9340',
177+
resource: {
178+
resourceType: 'DocumentReference',
179+
id: 'e7b1d94f-3c62-4a87-b5e0-8f2d1a6c9340',
180+
meta: {
181+
versionId: '5',
182+
lastUpdated: '2026-02-28T16:15:00Z',
183+
},
184+
status: DocumentReferenceStatus.Current,
185+
type: {
186+
coding: [
187+
{
188+
system: 'http://snomed.info/sct',
189+
code: '16521000000101',
190+
display: 'Lloyd George record folder',
191+
},
192+
],
193+
},
194+
subject: {
195+
identifier: {
196+
system: 'https://fhir.nhs.uk/Id/nhs-number',
197+
value: '9000000009',
198+
},
199+
},
200+
date: '2026-02-28T16:15:00Z',
201+
author: [
202+
{
203+
identifier: {
204+
system: 'https://fhir.nhs.uk/Id/ods-organization-code',
205+
value: 'Y12345',
206+
},
207+
display: 'Y12345',
208+
},
209+
],
210+
custodian: {
211+
identifier: {
212+
system: 'https://fhir.nhs.uk/Id/ods-organization-code',
213+
value: 'Y12345',
214+
},
215+
display: 'Y12345',
216+
},
217+
content: [
218+
{
219+
attachment: {
220+
contentType: 'application/pdf',
221+
url: '/dev/testFile5.pdf',
222+
size: 5120,
223+
title: 'document_v5.pdf',
224+
creation: '2026-02-28T16:15:00Z',
225+
},
226+
},
227+
],
228+
},
229+
},
230+
{
231+
fullUrl: 'urn:uuid:2a7a270e-aa1d-532e-8648-d5d8e3defb82',
232+
resource: {
233+
resourceType: 'DocumentReference',
234+
id: '2a7a270e-aa1d-532e-8648-d5d8e3defb82',
235+
meta: {
236+
versionId: '3',
237+
lastUpdated: '2025-12-15T10:30:00Z',
238+
},
239+
status: DocumentReferenceStatus.Superseded,
240+
type: {
241+
coding: [
242+
{
243+
system: 'http://snomed.info/sct',
244+
code: '16521000000101',
245+
display: 'Lloyd George record folder',
246+
},
247+
],
248+
},
249+
subject: {
250+
identifier: {
251+
system: 'https://fhir.nhs.uk/Id/nhs-number',
252+
value: '9000000009',
253+
},
254+
},
255+
date: '2025-12-15T10:30:00Z',
256+
author: [
257+
{
258+
identifier: {
259+
system: 'https://fhir.nhs.uk/Id/ods-organization-code',
260+
value: 'Y12345',
261+
},
262+
display: 'Y12345',
263+
},
264+
],
265+
custodian: {
266+
identifier: {
267+
system: 'https://fhir.nhs.uk/Id/ods-organization-code',
268+
value: 'Y12345',
269+
},
270+
display: 'Y12345',
271+
},
272+
content: [
273+
{
274+
attachment: {
275+
contentType: 'application/pdf',
276+
url: '/dev/testFile1.pdf',
277+
size: 3072,
278+
title: 'document_v3.pdf',
279+
creation: '2025-12-15T10:30:00Z',
280+
},
281+
},
282+
],
283+
},
284+
},
175285
],
176286
};

app/src/helpers/utils/getPdfObjectUrl.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ export const fetchBlob = async (url: string): Promise<Blob> => {
2222
});
2323
return data;
2424
};
25+
26+
export const getObjectUrl = async (cloudFrontUrl: string): Promise<string> => {
27+
const data = await fetchBlob(cloudFrontUrl);
28+
29+
return URL.createObjectURL(data);
30+
};

0 commit comments

Comments
 (0)