-
Notifications
You must be signed in to change notification settings - Fork 24
Add CodeSystem $lookup operation to Frontend UI #3618
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import type { Actions } from './$types'; | ||
| import type { OperationOutcome, Parameters, ParametersParameter } from 'fhir/r4'; | ||
| import { resolve } from '$app/paths'; | ||
| import { fail } from '@sveltejs/kit'; | ||
|
|
||
| export const actions = { | ||
| default: async ({ request, fetch }) => { | ||
| const data = await request.formData(); | ||
| const system = data.get('system') as string; | ||
| const version = data.get('version') as string; | ||
| const code = data.get('code') as string; | ||
| const display = data.get('display') as string; | ||
| const displayLanguage = data.get('displayLanguage') as string; | ||
|
|
||
| const parameters: ParametersParameter[] = [ | ||
| { | ||
| name: 'system', | ||
| valueUri: system | ||
| }, | ||
| { | ||
| name: 'code', | ||
| valueCode: code | ||
| } | ||
| ]; | ||
|
|
||
| if (version !== '') { | ||
| parameters.push({ | ||
| name: 'version', | ||
| valueString: version | ||
| }); | ||
| } | ||
|
|
||
| if (display !== '') { | ||
| parameters.push({ | ||
| name: 'display', | ||
| valueString: display | ||
| }); | ||
| } | ||
|
|
||
| if (displayLanguage !== '') { | ||
| parameters.push({ | ||
| name: 'displayLanguage', | ||
| valueCode: displayLanguage | ||
| }); | ||
| } | ||
|
|
||
| const res = await fetch(resolve('/CodeSystem/$lookup'), { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/fhir+json', Accept: 'application/fhir+json' }, | ||
| body: JSON.stringify({ | ||
| resourceType: 'Parameters', | ||
| parameter: parameters | ||
| }) | ||
| }); | ||
|
|
||
| if (!res.ok) { | ||
| const error: OperationOutcome = await res.json(); | ||
| return fail(400, { | ||
| system, | ||
| version, | ||
| code, | ||
| display, | ||
| displayLanguage, | ||
| incorrect: true, | ||
| msg: error.issue[0]?.diagnostics ?? error.issue[0]?.details?.text | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. error.issue can be missing, so |
||
| }); | ||
| } | ||
|
|
||
| return { | ||
| system, | ||
| version, | ||
| code, | ||
| display, | ||
| displayLanguage, | ||
| result: (await res.json()) as Parameters | ||
| }; | ||
| } | ||
| } satisfies Actions; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <script lang="ts"> | ||
| import type { PageProps } from './$types'; | ||
|
|
||
| import Breadcrumb from '$lib/breadcrumb.svelte'; | ||
| import BreadcrumbEntryHome from '$lib/breadcrumb/home.svelte'; | ||
| import BreadcrumbEntryType from '$lib/breadcrumb/type.svelte'; | ||
| import BreadcrumbEntry from '$lib/breadcrumb/entry.svelte'; | ||
| import Form from '$lib/tailwind/form.svelte'; | ||
| import Section from '$lib/tailwind/form/section.svelte'; | ||
| import TextField from '$lib/tailwind/form/text-field.svelte'; | ||
| import SubmitButton from '$lib/tailwind/form/button-submit.svelte'; | ||
| import ResultList from './result-list.svelte'; | ||
|
|
||
| let { form }: PageProps = $props(); | ||
| </script> | ||
|
|
||
| <svelte:head> | ||
| <title>$lookup - CodeSystem - Blaze</title> | ||
| </svelte:head> | ||
|
|
||
| <header class="mx-auto max-w-7xl sm:px-6 lg:px-8"> | ||
| <Breadcrumb> | ||
| <BreadcrumbEntryHome /> | ||
| <BreadcrumbEntryType type="CodeSystem" /> | ||
| <BreadcrumbEntry> | ||
| <span class="ml-4 text-sm font-medium text-gray-500 dark:text-gray-400">$lookup</span> | ||
| </BreadcrumbEntry> | ||
| </Breadcrumb> | ||
| </header> | ||
|
|
||
| <main class="mx-auto max-w-7xl py-4 sm:px-6 lg:px-8 flex flex-col gap-4"> | ||
| <Form class="mt-4"> | ||
| <Section name="Parameters"> | ||
| <TextField id="system" label="System" value={form?.system} /> | ||
| <TextField id="version" label="Version" value={form?.version} /> | ||
| <TextField id="code" label="Code" value={form?.code} /> | ||
| <TextField id="display" label="Display" value={form?.display} /> | ||
| <TextField id="displayLanguage" label="Display Language" value={form?.displayLanguage} /> | ||
| </Section> | ||
| {#snippet buttons()} | ||
| <SubmitButton name="Submit" /> | ||
| {/snippet} | ||
| </Form> | ||
|
|
||
| {#if form?.incorrect} | ||
| <p class="text-red-600 dark:text-red-400">{form.msg}</p> | ||
| {/if} | ||
|
|
||
| {#if form?.result} | ||
| <ResultList parameters={form?.result} /> | ||
| {/if} | ||
| </main> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| <script lang="ts"> | ||
| import type { Parameters } from 'fhir/r4'; | ||
|
|
||
| import { parameter, parameterParts, parameterValue } from '$lib/fhir'; | ||
| import DescriptionList from '$lib/tailwind/description/left-aligned/list.svelte'; | ||
| import Row from '$lib/tailwind/description/left-aligned/row-3-2.svelte'; | ||
|
|
||
| interface Props { | ||
| parameters: Parameters; | ||
| } | ||
|
|
||
| let { parameters }: Props = $props(); | ||
| </script> | ||
|
|
||
| <DescriptionList> | ||
| <Row title="Name"> | ||
| {parameter(parameters, 'name')?.valueString} | ||
| </Row> | ||
| {@const version = parameter(parameters, 'version')?.valueString} | ||
| {#if version} | ||
| <Row title="Version"> | ||
| {version} | ||
| </Row> | ||
| {/if} | ||
| {@const display = parameter(parameters, 'display')?.valueString} | ||
| {#if display} | ||
| <Row title="Display"> | ||
| {display} | ||
| </Row> | ||
| {/if} | ||
| {@const definition = parameter(parameters, 'definition')?.valueString} | ||
| {#if definition} | ||
| <Row title="Definition"> | ||
| {definition} | ||
| </Row> | ||
| {/if} | ||
| {@const properties = parameterParts(parameters, 'property')} | ||
| {#if properties} | ||
| {#each properties as property, i} | ||
| <Row title={'Property[' + i + ']'}> | ||
| <DescriptionList> | ||
| {#each property.part as part} | ||
| <Row title={part.name}>{parameterValue(part)}</Row> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please look if you can use |
||
| {/each} | ||
| </DescriptionList> | ||
| </Row> | ||
| {/each} | ||
| {/if} | ||
| {@const designations = parameterParts(parameters, 'designation')} | ||
| {#if designations} | ||
| {#each designations as designation, i} | ||
| <Row title={'Designation[' + i + ']'}> | ||
| <DescriptionList> | ||
| {#each designation.part as part} | ||
| <Row title={part.name}>{parameterValue(part)}</Row> | ||
| {/each} | ||
| </DescriptionList> | ||
| </Row> | ||
| {/each} | ||
| {/if} | ||
| </DescriptionList> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import type { Actions } from './$types'; | ||
| import type { OperationOutcome, Parameters, ParametersParameter } from 'fhir/r4'; | ||
| import { resolve } from '$app/paths'; | ||
| import { fail } from '@sveltejs/kit'; | ||
|
|
||
| export const actions = { | ||
| default: async ({ request, fetch, params }) => { | ||
| const data = await request.formData(); | ||
| const code = data.get('code') as string; | ||
| const display = data.get('display') as string; | ||
| const displayLanguage = data.get('displayLanguage') as string; | ||
|
|
||
| const parameters: ParametersParameter[] = [ | ||
| { | ||
| name: 'code', | ||
| valueCode: code | ||
| } | ||
| ]; | ||
|
|
||
| if (display !== '') { | ||
| parameters.push({ | ||
| name: 'display', | ||
| valueString: display | ||
| }); | ||
| } | ||
|
|
||
| if (displayLanguage !== '') { | ||
| parameters.push({ | ||
| name: 'displayLanguage', | ||
| valueCode: displayLanguage | ||
| }); | ||
| } | ||
|
|
||
| const res = await fetch(resolve('/CodeSystem/[id=id]/$lookup', params), { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/fhir+json', Accept: 'application/fhir+json' }, | ||
| body: JSON.stringify({ | ||
| resourceType: 'Parameters', | ||
| parameter: parameters | ||
| }) | ||
| }); | ||
|
|
||
| if (!res.ok) { | ||
| const error: OperationOutcome = await res.json(); | ||
| return fail(400, { | ||
| code, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please deduplicate like in $validate-code/+page.server.ts |
||
| display, | ||
| displayLanguage, | ||
| incorrect: true, | ||
| msg: error.issue[0]?.diagnostics ?? error.issue[0]?.details?.text | ||
| }); | ||
| } | ||
|
|
||
| return { code, display, displayLanguage, result: (await res.json()) as Parameters }; | ||
| } | ||
| } satisfies Actions; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| <script lang="ts"> | ||
| import type { PageProps } from './$types'; | ||
|
|
||
| import Breadcrumb from '$lib/breadcrumb.svelte'; | ||
| import BreadcrumbEntryHome from '$lib/breadcrumb/home.svelte'; | ||
| import BreadcrumbEntryType from '$lib/breadcrumb/type.svelte'; | ||
| import BreadcrumbEntryResource from '$lib/breadcrumb/resource.svelte'; | ||
| import BreadcrumbEntry from '$lib/breadcrumb/entry.svelte'; | ||
| import Form from '$lib/tailwind/form.svelte'; | ||
| import Section from '$lib/tailwind/form/section.svelte'; | ||
| import TextField from '$lib/tailwind/form/text-field.svelte'; | ||
| import SubmitButton from '$lib/tailwind/form/button-submit.svelte'; | ||
| import ResultList from '../../$lookup/result-list.svelte'; | ||
|
|
||
| import { title } from '$lib/resource.js'; | ||
|
|
||
| let { data, form, params }: PageProps = $props(); | ||
| </script> | ||
|
|
||
| <svelte:head> | ||
| <title>$lookup - {title(data.codeSystem)} - Blaze</title> | ||
| </svelte:head> | ||
|
|
||
| <header class="mx-auto max-w-7xl sm:px-6 lg:px-8"> | ||
| <Breadcrumb> | ||
| <BreadcrumbEntryHome /> | ||
| <BreadcrumbEntryType type="CodeSystem" /> | ||
| <BreadcrumbEntryResource type="CodeSystem" {...params} resource={data.codeSystem} /> | ||
| <BreadcrumbEntry> | ||
| <span class="ml-4 text-sm font-medium text-gray-500 dark:text-gray-400">$lookup</span> | ||
| </BreadcrumbEntry> | ||
| </Breadcrumb> | ||
| </header> | ||
|
|
||
| <main class="mx-auto max-w-7xl py-4 sm:px-6 lg:px-8 flex flex-col gap-4"> | ||
| <h2 class="text-base/7 font-semibold text-gray-900 dark:text-gray-100"> | ||
| {title(data.codeSystem)} | ||
| </h2> | ||
| {#if data.codeSystem.description} | ||
| <p class="mt-1 max-w-2xl text-sm/6 text-gray-600">{data.codeSystem.description}</p> | ||
| {/if} | ||
|
|
||
| <Form class="mt-4"> | ||
| <Section name="Parameters"> | ||
| <TextField id="code" label="Code" value={form?.code} /> | ||
| <TextField id="display" label="Display" value={form?.display} /> | ||
| <TextField id="displayLanguage" label="Display Language" value={form?.displayLanguage} /> | ||
| </Section> | ||
| {#snippet buttons()} | ||
| <SubmitButton name="Submit" /> | ||
| {/snippet} | ||
| </Form> | ||
|
|
||
| {#if form?.incorrect} | ||
| <p class="text-red-600 dark:text-red-400">{form.msg}</p> | ||
| {/if} | ||
|
|
||
| {#if form?.result} | ||
| <ResultList parameters={form?.result} /> | ||
| {/if} | ||
| </main> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import type { PageLoad } from './$types'; | ||
| import type { Bundle, CodeSystem } from 'fhir/r4'; | ||
|
|
||
| import { resolve } from '$app/paths'; | ||
| import { error, type NumericRange } from '@sveltejs/kit'; | ||
|
|
||
| export const load: PageLoad = async ({ fetch, params }) => { | ||
| const res = await fetch( | ||
| `${resolve('/CodeSystem')}?_id=${params.id}&_elements=version,title,description`, | ||
| { | ||
| headers: { | ||
| Accept: 'application/fhir+json' | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| if (!res.ok) { | ||
| error(res.status as NumericRange<400, 599>, { | ||
| short: res.status == 404 ? 'Not Found' : res.status == 410 ? 'Gone' : undefined, | ||
| message: | ||
| res.status == 404 | ||
| ? `The CodeSystem with ID ${params.id} was not found.` | ||
| : res.status == 410 | ||
| ? `The CodeSystem with ID ${params.id} was deleted. Please look into the history.` | ||
| : `An error happened while loading the CodeSystem with ID ${params.id}. Please try again later.` | ||
| }); | ||
| } | ||
|
|
||
| const bundle: Bundle = await res.json(); | ||
|
|
||
| return { | ||
| codeSystem: bundle.entry?.[0].resource as CodeSystem | ||
| }; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please deduplicate like in $validate-code/+page.server.ts