=> {
+ e.preventDefault();
+ setLoading(true);
+ try {
+ const documentRef = getDocumentReferenceFromFhir(doc);
+ setDocumentReference({ ...documentRef, url: '' });
+
+ navigate(routeChildren.DOCUMENT_VIEW_VERSION_HISTORY, { state: isActiveVersion });
+
+ if (documentRef.url) {
+ const blobUrl = await fetchBlob(documentRef.url);
+ setDocumentReference({ ...documentRef, url: URL.createObjectURL(blobUrl) });
+ }
+ } catch (e) {
+ const error = e as AxiosError;
+ setLoading(false);
+ if (error.response?.status === 403) {
+ navigate(routes.SESSION_EXPIRED);
+ } else if (error.response?.status && error.response?.status >= 500) {
+ navigate(routes.SERVER_ERROR + errorToParams(error));
+ }
+
+ navigate(routes.SERVER_ERROR);
+ }
+ };
+
const renderVersionHistoryTimeline = (): React.JSX.Element => {
+ if (loading) {
+ return ;
+ }
if (!versionHistory?.entry || versionHistory.entry.length === 0) {
return No version history available for this document.
;
}
@@ -91,14 +144,27 @@ const DocumentVersionHistoryPage = ({
return (
{sortedEntries.map((entry, index) => {
- const isCurrentVersion = index === 0;
- const status = isCurrentVersion
+ const maxVersion = versionHistory.entry?.sort(
+ (a, b) =>
+ Number(getVersionId(b.resource)) - Number(getVersionId(a.resource)),
+ )[0];
+
+ if (!maxVersion) {
+ return <>>;
+ }
+
+ const isActiveVersion = entry.resource.id === maxVersion.resource.id;
+ const status = isActiveVersion
? TimelineStatus.Active
: TimelineStatus.Inactive;
const isLastItem = index === versionHistory.entry!.length - 1;
const doc = entry.resource;
const version = getVersionId(doc);
- const heading = `${docTypeLabel}: version ${version}`;
+ const heading =
+ docConfig?.content.getValueFormatString(
+ 'versionHistoryTimelineHeader',
+ { version },
+ ) || `${docTypeLabel}: version ${version}`;
return (
- {isCurrentVersion && (
+ {isActiveVersion && (
This is the current version shown in this patient's record
@@ -125,11 +191,15 @@ const DocumentVersionHistoryPage = ({
dateUploaded={getFormatDateWithAtTime(getCreatedDate(doc))}
/>
- {isCurrentVersion ? (
+ {isActiveVersion ? (
,
+ ): Promise => handleViewVersion(e, doc, isActiveVersion)}
>
View
@@ -138,6 +208,9 @@ const DocumentVersionHistoryPage = ({
diff --git a/app/src/types/blocks/lloydGeorgeActions.ts b/app/src/types/blocks/lloydGeorgeActions.ts
index 08637e2c2..3a79221db 100644
--- a/app/src/types/blocks/lloydGeorgeActions.ts
+++ b/app/src/types/blocks/lloydGeorgeActions.ts
@@ -84,7 +84,7 @@ export const VersionHistoryAction = (
index: 4,
label: label,
key: ACTION_LINK_KEY.HISTORY,
- type: RECORD_ACTION.UPDATE, // This could be a different type if needed
+ type: RECORD_ACTION.UPDATE,
unauthorised: [],
onClick,
showIfRecordInStorage: true,
diff --git a/app/src/types/fhirR4/bundle.ts b/app/src/types/fhirR4/bundle.ts
index 87be6e27b..5413cb3bd 100644
--- a/app/src/types/fhirR4/bundle.ts
+++ b/app/src/types/fhirR4/bundle.ts
@@ -131,12 +131,6 @@ export interface BundleEntry {
fullUrl?: string;
/** A resource in the bundle */
resource: T;
- /** Search related information */
- search?: BundleEntrySearch;
- /** Additional execution information (transaction/batch/history) */
- request?: BundleEntryRequest;
- /** Results of execution (transaction/batch/history) */
- response?: BundleEntryResponse;
}
// ─── Bundle Resource ─────────────────────────────────────────────────────────