Skip to content

Commit

Permalink
Merge pull request #4 from uwcirg/shlips-parent-repo
Browse files Browse the repository at this point in the history
Merge parent changes from jmandel/shlips
  • Loading branch information
daniellrgn authored Jun 9, 2023
2 parents 57224d9 + cb5aeca commit 0451a2d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
42 changes: 34 additions & 8 deletions src/lib/AddFile.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
const dispatch = createEventDispatcher<{ 'shc-retrieved': SHCRetrieveEvent }>();
let submitting = false;
let summaryUrl = EXAMPLE_IPS;
let uploadFiles: FileList | undefined;
let inputUrl: HTMLFormElement;
let label = 'SHL from ' + new Date().toISOString().slice(0, 10);
let expiration: number | null;
let summaryUrlValidated: URL | undefined = undefined;
$: {
try {
Expand All @@ -23,11 +27,20 @@
}
}
async function fetchIps(url?: URL) {
async function fetchIps() {
submitting = true;
try {
const contentResponse = await fetch(url!, { headers: { accept: 'application/fhir+json' } });
const content: any = await contentResponse.json();
let content;
if (uploadFiles?.[0] instanceof File) {
content = JSON.parse(new TextDecoder().decode(await uploadFiles[0].arrayBuffer()));
} else {
const contentResponse = await fetch(summaryUrlValidated!, {
headers: { accept: 'application/fhir+json' }
});
content = await contentResponse.json();
}
if (content.verifiableCredential) {
return dispatch('shc-retrieved', {
shc: content,
Expand All @@ -42,7 +55,8 @@
verifiableCredential: [shc]
},
content,
label
label,
exp: expiration ? new Date().getTime() / 1000 + expiration : undefined
});
} catch (e) {
console.log('Failed', e);
Expand All @@ -66,26 +80,38 @@
}
})
);
const signed = new jose.CompactSign(body)
.setProtectedHeader(fields)
.sign(await exampleSigningKey);
return signed;
}
</script>

<form bind:this={inputUrl} on:submit|preventDefault={() => fetchIps(summaryUrlValidated)}>
<form bind:this={inputUrl} on:submit|preventDefault={() => fetchIps()}>
<FormGroup>
<Label>Upload Bundle (<code>.json</code> or signed <code>.smart-health-card</code>)</Label>
<Input width="100%" type="file" name="file" bind:files={uploadFiles} />
</FormGroup>
<FormGroup>
<Label>Source of IPS data (query, local path, or signed <code>.smart-health-card</code>)</Label>
<!-- <Label>Bundle <code>.json</code>, or signed <code>.smart-health-card</code></Label> -->
<Label>Or fetch from URL</Label>
<Input width="100%" type="text" bind:value={summaryUrl} />
</FormGroup>
<FormGroup>
<Label>New SHLink Label</Label>
<Input width="100%" type="text" bind:value={label} />
</FormGroup>
<FormGroup>
<Label>Expires</Label>
<Input type="radio" bind:group={expiration} value={60 * 60} label="1 hour" />
<Input type="radio" bind:group={expiration} value={60 * 60 * 24 * 7} label="1 week" />
<Input type="radio" bind:group={expiration} value={60 * 60 * 24 * 7 * 365} label="1 year" />
<Input type="radio" bind:group={expiration} value={null} label="Never" />
</FormGroup>

<Button color="primary" disabled={!summaryUrlValidated || submitting} type="submit">
{#if !submitting}
Query for IPS
Fetch IPS
{:else}
Fetching...
{/if}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/HealthLink.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<CardBody>
{#if shl.exp}
<CardSubtitle color="success"
>Expires: {new Date(shl.exp * 1000).toISOString().slice(10)}
>Expires: {new Date(shl.exp * 1000).toISOString().slice(0, 10)}
</CardSubtitle>
{/if}

Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface SHCRetrieveEvent {
shc: SHCFile;
label?: string;
content: Bundle;
exp?: number;
}

export interface SHCFile {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/create/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let shlStore: Writable<SHLAdminParams[]> = getContext('shlStore');
async function newShlFromShc(details: SHCRetrieveEvent): Promise<SHLAdminParams> {
const shlCreated = await shlClient.createShl();
const shlCreated = await shlClient.createShl({exp: details.exp});
shlClient.addFile(shlCreated, details.shc, 'application/smart-health-card');
shlCreated.label = details.label;
return shlCreated;
Expand Down

0 comments on commit 0451a2d

Please sign in to comment.