Skip to content

Commit

Permalink
Merge pull request #26 from uwcirg/add-logging
Browse files Browse the repository at this point in the history
Add logging
  • Loading branch information
daniellrgn authored Jan 31, 2025
2 parents 6db44d3 + fb253cb commit 2340dea
Show file tree
Hide file tree
Showing 14 changed files with 348 additions and 32 deletions.
7 changes: 7 additions & 0 deletions default.env
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ COMPOSE_FILE=docker-compose.yaml:docker-compose.static-ingress.yaml
# Enable to use development overrides
# COMPOSE_FILE=docker-compose.yaml:docker-compose.dev.yaml

# Version string for Logging
#VITE_VERSION_STRING=

# Logging configuration
#VITE_LOG_URL=
#VITE_SYSTEM_URL=

# SHL Server API endpoint url
VITE_API_BASE=

Expand Down
3 changes: 3 additions & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ interface ImportMetaEnv {
readonly VITE_EPIC_CLIENT_ID: string
readonly VITE_CERNER_CLIENT_ID: string
readonly VITE_API_BASE: string
readonly VITE_LOG_URL: string
readonly VITE_SYSTEM_URL: string
readonly VITE_VIEWER_BASE: string
readonly VITE_INTERMEDIATE_FHIR_SERVER_BASE: string
readonly VITE_SOF_CLIENT_ID: string
Expand All @@ -16,6 +18,7 @@ interface ImportMetaEnv {
readonly VITE_OIDC_CHECK_SESSION_IFRAME: string
readonly VITE_INACTIVITY_TIMEOUT: string
readonly VITE_BACKUP_INACTIVITY_TIMEOUT: string
readonly VITE_VERSION_STRING: string
readonly DEV_SERVER_PORT: number
}

Expand Down
72 changes: 65 additions & 7 deletions src/lib/AddFileLTT.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SHLRetrieveEvent,
SHLSubmitEvent} from './types';
import RetrieveShl from './RetrieveSHL.svelte';
import { log } from '$lib/logger';
let shlStore: Writable<SHLAdminParams> = getContext('shlStore');
let shlClient: SHLClient = getContext('shlClient');
Expand Down Expand Up @@ -98,6 +99,18 @@
let result = await sofClient.postShl(shl, mostRecentDocRef, reportLabel);
$shlStore = shl;
console.log($shlStore);
log({
action: "create",
entity: {
detail: {
action: `Created SHL '${$shlStore.id}'`,
shl_session: $shlStore.sessionId ?? "",
shl: $shlStore.id,
patient: patient.id,
docref: mostRecentDocRef.id
}
}
});
shlReadyDispatch('shl-ready', true);
} else {
fetchError = "No Report found";
Expand Down Expand Up @@ -143,16 +156,50 @@
let reportLabel = `My Choices Report (${reportDate})`;
let result = await sofClient.postShl($shlStore, mostRecentDocRef, reportLabel);
$shlStore.label = result.label;
log({
action: "create",
entity: {
detail: {
action: `Created new SHL for updated report '${$shlStore.id}'`,
shl_session: $shlStore.sessionId ?? "",
shl: $shlStore.id,
patient: patient.id,
docref: mostRecentDocRef.id
}
}
});
updatedShl = true;
}
// The current SHL is most recent, so use it
shlReadyDispatch('shl-ready', true);
} else if (mostRecentDocRef) {
console.log(`Couldn't find FHIR record for SHL ${$shlStore.id} and session ${$shlStore.sessionId}, creating new SHL`);
log({
action: "read",
entity: {
detail: {
action: `Recreating SHL for '${$shlStore.sessionId}'`,
shl_session: $shlStore.sessionId ?? "",
shl: $shlStore.id
}
}
});
shlClient.deleteShl($shlStore);
newShl(patient, mostRecentDocRef);
} else {
fetchError = "No report found.";
log({
action: "read",
severity: "error",
entity: {
detail: {
action: `No report found for '${$shlStore.sessionId}'`,
shl_session: $shlStore.sessionId ?? "",
shl: $shlStore.id,
patient: patient.id
}
}
})
}
}
Expand All @@ -169,13 +216,24 @@
async function updateShl(details: SHLRetrieveEvent) {
shlResult = details;
if (shlResult.shl) {
// Trigger update in store
$shlStore = shlResult.shl;
} else {
createSHL = true;
}
checkedShl = true;
if (shlResult.shl) {
log({
action: "read",
entity: {
detail: {
action: `Loaded SHL '${shlResult.shl.id}'`,
shl_session: sessionId,
shl: shlResult.shl.id,
patient: patientId
}
}
});
// Trigger update in store
$shlStore = shlResult.shl;
} else {
createSHL = true;
}
checkedShl = true;
}
function createIpsPayload(patient:any, docref:any) {
Expand Down
12 changes: 12 additions & 0 deletions src/lib/CopyButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
Button,
Icon
} from 'sveltestrap';
import { log } from '$lib/logger';
let copyNotice = '';
export let id: string;
export let href: string;
async function copyShl() {
Expand All @@ -17,6 +19,16 @@
setTimeout(() => {
copyNotice = copyNoticePrev;
}, 8000);
log({
action: 'read',
entity: {
detail: {
action: `Copied SHL to clipboard`,
url: href,
Button: id
}
}
})
}
</script>
{#if copyNotice}
Expand Down
13 changes: 12 additions & 1 deletion src/lib/FetchSoFLTT.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { createEventDispatcher, onMount } from 'svelte';
import { Alert } from 'sveltestrap';
import type { SOFClient } from './sofClient';
import { log } from '$lib/logger';
const resourceDispatch = createEventDispatcher<{ updateResources: ResourceRetrieveEvent }>();
Expand Down Expand Up @@ -33,6 +34,16 @@
processing = false;
return resourceDispatch('updateResources', result);
} catch (e) {
log({
action: "read",
severity: "error",
entity: {
detail: {
action: `Error while fetching Resources`,
error: `${JSON.stringify(e)}`
}
}
});
processing = false;
console.error('Error while fetching data: ', e);
fetchError = "Unable to find your Report.";
Expand All @@ -43,6 +54,6 @@
{#if fetchError}
<Alert color="danger">
<h4 class="alert-heading text-capitalize">{fetchError}</h4>
You can try again later, click "Back" to choose another option, or reach out for help below.
If you have completed your Choices Report, reach out for help below. Otherwise, click "Back" to finish your Report.
</Alert>
{/if}
74 changes: 56 additions & 18 deletions src/lib/HealthLinkLTT.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,24 @@
import { fade } from 'svelte/transition';
import type { Writable } from 'svelte/store';
import type { SHLAdminParams, SHLClient } from './managementClient';
import { log } from '$lib/logger';
let open = false;
const toggle = () => (open = !open);
function toggle() {
open = !open
log({
action: "read",
entity: {
detail: {
action: (open ? "Open" : "Close") + " SHL reset dialogue"
}
}
})
};
let shlStore: Writable<SHLAdminParams> = getContext('shlStore');
let shlClient: SHLClient = getContext('shlClient');
let copyNotice = '';
let href: Promise<string>;
let qrCode: Promise<string>;
let exp: Date;
Expand Down Expand Up @@ -77,24 +86,35 @@
encryptionKey: shl.encryptionKey,
files: []
};
return await shlClient.toLink(shlMin);
}
async function copyShl() {
let copyNoticePrev = copyNotice;
copyNotice = '...';
let text = await getUrl($shlStore);
navigator.clipboard.writeText(text);
copyNotice = 'Copied!';
setTimeout(() => {
copyNotice = copyNoticePrev;
}, 1000);
let url = await shlClient.toLink(shlMin);
log({
action: "read",
entity: {
detail: {
action: `Load SHL '${shl.id}'`,
shl_session: shl.sessionId ?? "",
shl: shl.id,
url: url
}
}
})
return url;
}
async function deactivateShl() {
toggle();
await shlClient.deleteShl($shlStore);
// TODO: Implement post-deactivation flow
log({
action: "update",
entity: {
detail: {
action: `User deactivated SHL '${$shlStore.id}'`,
shl_session: $shlStore.sessionId ?? "",
shl: $shlStore.id
}
}
});
location.reload();
}
Expand All @@ -103,8 +123,26 @@
function updateInstructions(event) {
if (instructions && event.target.id.includes(instructions)) {
instructions = "";
log({
action: "update",
entity: {
detail: {
action: `Closed sharing instructions`,
id: event.target.id
}
}
});
} else {
instructions = event.target.id.split('-')[0];
log({
action: "update",
entity: {
detail: {
action: `Opened ${instructions} sharing instructions`,
id: event.target.id
}
}
});
}
}
</script>
Expand Down Expand Up @@ -178,7 +216,7 @@
{#await href then href}
<Row class="justify-content-center">
<Col xs="auto" class="mb-2">
<CopyButton href={href} />
<CopyButton id="email-copy" href={href} />
</Col>
</Row>
{/await}
Expand All @@ -204,7 +242,7 @@
{#await href then href}
<Row class="justify-content-center">
<Col xs="auto" class="mb-2">
<CopyButton href={href} />
<CopyButton id="text-copy" href={href} />
</Col>
</Row>
{/await}
Expand Down Expand Up @@ -276,7 +314,7 @@
</Row>
<Row class="justify-content-center">
<Col xs="auto" class="mb-2">
<CopyButton href={href} />
<CopyButton id="main-copy" href={href} />
</Col>
</Row>
{/await}
Expand Down
14 changes: 13 additions & 1 deletion src/lib/RetrieveSHL.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import type { SHLClient } from '$lib/managementClient';
import type { SHLRetrieveEvent } from './types';
import type { SOFClient } from '$lib/sofClient'
import { log } from '$lib/logger';
let shlClient: SHLClient = getContext('shlClient');
let sofClient: SOFClient = getContext('sofClient');
Expand All @@ -28,6 +29,17 @@
} catch (error) {
fetchError = "Unable to retrieve most recent sharing link.";
console.error(`Error retrieving SHL for patient ${patientId}: ${error}`);
log({
severity: "error",
action: "read",
entity: {
detail: {
action: `Retrieve SHL for patient ${patientId}`,
message: fetchError
}
},
outcome: `${JSON.stringify(error)}`
})
}
// Meanwhile, in FetchSOF:
// retrieve DocRefs for current patient (reports and shl metadata)
Expand All @@ -43,6 +55,6 @@
{#if fetchError}
<Alert color="danger">
<h4 class="alert-heading text-capitalize">{fetchError}</h4>
You can try again later, click "Back" to choose another option, or reach out for help below.
You can reach out for help below, or click "Back" for more options.
</Alert>
{/if}
5 changes: 5 additions & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
import { dev } from '$app/environment';
import { toMilliseconds } from '$lib/util';

export const VERSION_STRING = import.meta.env.VITE_VERSION_STRING;

export const LOG_URL = import.meta.env.VITE_LOG_URL;
export const SYSTEM_URL = import.meta.env.VITE_SYSTEM_URL;

export const API_BASE = import.meta.env.VITE_API_BASE;

export const INTERMEDIATE_FHIR_SERVER_BASE = import.meta.env.VITE_INTERMEDIATE_FHIR_SERVER_BASE;
Expand Down
Loading

0 comments on commit 2340dea

Please sign in to comment.