Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sof fix #66

Merged
merged 7 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/components/app/AddFile.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@
</form>
</Row>
{/if}
<span class="text-danger">{fetchError}</span>
{/if}
<span class="text-danger">{fetchError}</span>
{#if $mode === "advanced"}
<br>
<em class="text-secondary">* Advanced features for demo purposes only</em>
Expand Down
6 changes: 4 additions & 2 deletions src/lib/components/app/FetchSoF.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@
sofHost = sofHostAuthd;
sofHostSelection = sofHost.id;
await fetchData();
sessionStorage.removeItem(key);
sessionStorage.removeItem('SMART_KEY');
if (result.resources.length > 0) {
sessionStorage.removeItem(key);
sessionStorage.removeItem('SMART_KEY');
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/components/app/FetchUrl.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
let headers: any = { accept: 'application/fhir+json' };
if (summaryUrlValidated?.toString().includes('meditech')) {
headers['authorization'] = `Bearer ${BEARER_AUTHORIZATION['Meditech']}`
} else if (summaryUrlValidated?.toString().includes('openfhir')) {
headers['epic-client-id'] = `${BEARER_AUTHORIZATION['EpicHIMSS']}`;
}
const contentResponse = await fetch(summaryUrlValidated!, {
headers: headers
Expand Down
32 changes: 17 additions & 15 deletions src/lib/components/layout/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
NavbarToggler,
Row
} from 'sveltestrap';
import { onMount, getContext } from 'svelte';
import { onMount, onDestroy, getContext } from 'svelte';
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { type Writable } from 'svelte/store';
Expand All @@ -36,8 +36,6 @@

let mode: Writable<string> = getContext('mode');

let currentUser: Promise<User | undefined>;

let activeItem: ("home" | "summaries" | "create" | "") = "";
$: {
if ($page.url.pathname.includes("home")) {
Expand All @@ -51,23 +49,21 @@
}
}

let haveUser = false;
function handleAuthenticationEvent(event) {
haveUser = true;
return;
}

onMount(async () => {
window.onscroll = function() {scrollFunction()};
scrollFunction();
$isOpen = false;

try {
currentUser = await authService.signinCallback();
} catch (error) {
console.warn("No authentication parameters found, checking for current user");
} finally {
currentUser = authService.getUser().then(async (user) => {
if (user) {
$shlStore = await shlClient.getUserShls();
}
return user;
});
}
window.addEventListener('userFound', handleAuthenticationEvent);
});
onDestroy(() => {
window.removeEventListener('userFound', handleAuthenticationEvent);
});

function scrollFunction() {
Expand Down Expand Up @@ -151,6 +147,7 @@
<NavItem>
<NavLink href={"/"} active={ activeItem === "home" }>Home</NavLink>
</NavItem>
{#if haveUser}
{#await authService.getProfile() then profile}
{#if profile}
<NavItem>
Expand Down Expand Up @@ -207,6 +204,11 @@
</NavItem>
{/if}
{/await}
{:else}
<NavItem>
<NavLink on:click={() => authService.login()}><Icon name="person-circle"/> Sign In</NavLink>
</NavItem>
{/if}
</Nav>
</Collapse>
</Navbar>
Expand Down
16 changes: 13 additions & 3 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,26 @@ export const SOF_HOSTS = [
// clientId: import.meta.env.VITE_ECW_HIMSS_CLIENT_ID,
// note: "zhangwei / Cures@2022"
// },
{
id: "epic-himss",
name: "Epic - HIMSS Demo",
url: " https://ihe-nimbus.epic.com/Interconnect-FHIR/api/FHIR/R4",
clientId: import.meta.env.VITE_EPIC_CLIENT_ID,
note: "user / pass"
},
{
id: "epic",
name: "Epic Demo",
url: "https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4",
clientId: import.meta.env.VITE_EPIC_CLIENT_ID,
note: "<a href='https://fhir.epic.com/Documentation?docId=testpatients' target='_blank' rel='noreferrer'>Test patient credentials <Icon name='box-arrow-up-right' /></a>"
note: "fhircamila / epicepic1 <br> <a style='color: grey; font-size: small' href='https://fhir.epic.com/Documentation?docId=testpatients' target='_blank' rel='noreferrer'>More credentials <span style='vertical-align: text-top; font-size: x-small' class='bi-box-arrow-up-right' /></a>"
},
{
id: "cerner",
name: "Oracle Cerner Demo",
url: "https://fhir-myrecord.cerner.com/r4/ec2458f2-1e24-41c8-b71b-0e701af7583d",
clientId: import.meta.env.VITE_CERNER_CLIENT_ID,
note: "<a href='https://docs.google.com/document/u/1/d/e/2PACX-1vQwyX3px4qi5t1O6_El6022zYt4ymKAWCrcgxcX5NvYGUJAkJ4WFwOnLoikow6rEccpFZzDWBdcBqsQ/pub' target='_blank' rel='noreferrer'>Test patient credentials <Icon name='box-arrow-up-right' /></a>"
note: "nancysmart / Cerner01 <br> <a style='color: grey; font-size: small' href='https://docs.google.com/document/u/1/d/e/2PACX-1vQwyX3px4qi5t1O6_El6022zYt4ymKAWCrcgxcX5NvYGUJAkJ4WFwOnLoikow6rEccpFZzDWBdcBqsQ/pub' target='_blank' rel='noreferrer'>More credentials <span style='vertical-align: text-top; font-size: x-small' class='bi-box-arrow-up-right' /></a>"
},
{
id: "smit",
Expand Down Expand Up @@ -87,7 +94,8 @@ export const CARIN_HOSTS = [
]

export const BEARER_AUTHORIZATION = {
'Meditech': import.meta.env.VITE_MEDITECH_BEARER_TOKEN
'Meditech': import.meta.env.VITE_MEDITECH_BEARER_TOKEN,
'EpicHIMSS': import.meta.env.VITE_EPIC_CLIENT_ID
}
export const SOF_REDIRECT_URI = '/create';
export const SOF_RESOURCES = [
Expand Down Expand Up @@ -136,6 +144,7 @@ export const SOF_PATIENT_RESOURCES = [
];

export const CARIN_RESOURCES = [
'Patient',
'Coverage',
'Practitioner',
'Organization',
Expand All @@ -154,6 +163,7 @@ export const PATIENT_IPS = {
'Peter Kieth Jordan': 'https://terminz.azurewebsites.net/fhir/Patient/$summary?profile=http://hl7.org/fhir/uv/ips/StructureDefinition/Bundle-uv-ips&identifier=https://standards.digital.health.nz/ns/nhi-id|NNJ9186&_format=json'
}
export const EXAMPLE_IPS = {
'Epic HIMSS': 'https://ihe-nimbus.epic.com/Interconnect-FHIR-Open/api/FHIR/R4/Patient/e1o-b5iIsAPxRiD2Ct8KekQ3/$summary',
'Maria SEATTLE Gravitate': 'https://fhir.ips-demo.dev.cirg.uw.edu/fhir/Patient/14599/$summary',
'Peter Kieth Jordan': 'https://raw.githubusercontent.com/jddamore/IPSviewer/4eedba9df34afbf3eb20d98c49d36afc7f9ce104/samples/connectathon_Jan2025/new_IPS_Example.json',
'Johanna Petronella Maria (Jo) van Putten-van der Giessen': "https://raw.githubusercontent.com/jddamore/IPSviewer/4eedba9df34afbf3eb20d98c49d36afc7f9ce104/samples/connectathon_archive/NL_core_patient_01.json",
Expand Down
3 changes: 3 additions & 0 deletions src/lib/utils/sofClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ async function getResources() {

async function getResourcesWithReferences(depth=1) {
let resources = await getResources();
if (resources === undefined) {
return [];
}
let allResources = [].concat(...resources);
let referenceMap = {};
let retrievedResources = {};
Expand Down
49 changes: 19 additions & 30 deletions src/routes/(app)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Col,
Row
} from 'sveltestrap';
import { page } from '$app/stores';
import { AuthService } from '$lib/utils/AuthService';
import { User } from 'oidc-client-ts';
import { type SHLAdminParams, type SHLClient } from '$lib/utils/managementClient';
Expand All @@ -18,38 +19,26 @@
let currentUser: Promise<User | undefined>;

onMount(async () => {
let newUser: User | undefined;
try {
newUser = await authService.signinCallback();
} catch (error) {
console.warn("No authentication parameters found, checking for current user");
} finally {
currentUser = authService.getUser().then((user) => {
if (user) {
let now = Date.now() / 1000;
if ((user.expires_at ?? 0) < now) {
return user ?? undefined;
}
}
if (!user) {
return authService.login().then(() => {
return authService.getUser().then((user) => user ?? undefined);
});
} else {
if (newUser) {
let redirectUrl = authService.getRedirectUrl();
if (redirectUrl) {
goto(redirectUrl);
}
}
currentUser = authService.getUser().then((user) => {
if (user) {
let now = Date.now() / 1000;
if ((user.expires_at ?? 0) < now) {
return user ?? undefined;
}
});
currentUser.then(async (user) => {
$shlStore = await shlClient.getUserShls();
return user;
});
}
} else {
return authService.login().then(() => {
return authService.getUser().then((user) => user ?? undefined);
});
}
});
// Split promise to shortcut body 'await' block resolution
currentUser.then(async (user) => {
window.dispatchEvent(new CustomEvent('userFound', {
detail: { message: 'Hello from another component!' }
}));
$shlStore = await shlClient.getUserShls();
return user;
});
});

</script>
Expand Down
12 changes: 0 additions & 12 deletions src/routes/(app)/auth/+page.svelte

This file was deleted.

35 changes: 35 additions & 0 deletions src/routes/auth/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<script lang="ts">
import {
Styles
} from 'sveltestrap';
import { onMount } from 'svelte';
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import AuthService from '$lib/utils/AuthService';
import type { User } from 'oidc-client-ts';

let authService = AuthService.Instance;
onMount(async () => {
let newUser: User | undefined;
try {
newUser = await authService.signinCallback();
if (newUser) {
let redirectUrl = authService.getRedirectUrl();
// avoid redirecting to the same page
if (redirectUrl && !redirectUrl.includes($page.url.pathname)) {
goto(redirectUrl);
} else {
goto('/home');
}
}
} catch (error) {
console.error("No authentication parameters found.");
console.error(error);
authService.login();
}
});
</script>
<Styles />
<svelte:head>
<title>Auth - WA Verify+</title>
</svelte:head>