Skip to content

Commit

Permalink
getEntry compatibility with ResourceSelector views
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellrgn committed Jan 16, 2025
1 parent d288407 commit cb82f95
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
54 changes: 51 additions & 3 deletions src/lib/components/app/ResourceSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,10 @@
<Button
size="sm"
color="secondary"
outline
on:click={() => setJson($resourcesByTypeStore[resourceType][key])}
>
JSON
View
</Button>
</Col>
{/if}
Expand All @@ -292,7 +293,7 @@
<Label style="width: 100%">
<CardBody>
<Row style="overflow:hidden">
<Col xs=auto class="d-flex align-items-center pe-0">
<Col xs=auto class="d-flex align-items-top pt-4 pe-0">
{#if resourceType === "Patient"}
<Input id={key} type="radio" bind:group={selectedPatient} value={key} />
{:else}
Expand All @@ -301,7 +302,11 @@
</Col>
<Col>
{#if resourceType in components}
<svelte:component this={components[resourceType]} resource={$resourcesByTypeStore[resourceType][key].resource} />
<svelte:component
this={components[resourceType]}
content={{
resource: $resourcesByTypeStore[resourceType][key].resource,
entries: resourceCollection.flattenResources($resourcesByTypeStore)}} />
<!-- ResourceType: {resourceType}
Resource: {JSON.stringify($resourcesByTypeStore[resourceType][key].resource)} -->
{:else if $resourcesByTypeStore[resourceType][key].resource.text?.div}
Expand All @@ -325,6 +330,49 @@
</AccordionItem>

<style>
/* Table styling */
:global(table) {
border-collapse: collapse !important;
width: 100% !important;
}
:global(th) {
border: 1px solid lightgray !important;
padding: 0 7px !important;
text-align: center !important;
}
:global(td) {
margin-left: 2em !important;
}
:global(thead) {
background-color: #0c63e4;
color: white;
}
/* Alternating table row coloring */
:global(tbody tr:nth-child(odd)) {
background-color: #fff;
border: 1px solid lightgray;
}
:global(tbody tr:nth-child(even)) {
background-color: #e7f1ff;
border: 1px solid lightgray;
}
/* Sticky table header */
:global(th) {
background: #0c63e4;
position: sticky;
top: -17px;
}
/* First column of generated table is usually most important */
:global(td:first-child) {
font-weight: bold;
}
.code {
overflow:auto;
margin: 0;
Expand Down
4 changes: 4 additions & 0 deletions src/lib/utils/IPSResourceCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ export class IPSResourceCollection {
return selectedIPSResources;
}

flattenResources(resourcesByType: Record<string, Record<string, ResourceHelper>>) {
return Object.values(resourcesByType).flatMap(types => Object.values(types))
}

toJson(): string {
let resourcesByType = get(this.resourcesByType);
let extensionSections = get(this.extensionSections);
Expand Down
9 changes: 6 additions & 3 deletions src/lib/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ export function getEntry(entries: Array<BundleEntry>, reference: string) {
// Attempt to match based on resource and uuid
let splitReference = reference.split('/');
let referenceId = splitReference?.pop();
let referenceResourceType = splitReference?.pop();
if (referenceResourceType === entry.resource?.resourceType && referenceId && entry.fullUrl?.includes(referenceId)) {
return entry.resource;
if (entry.resource?.resourceType && splitReference.includes(entry.resource?.resourceType) && referenceId) {
if (entry.fullUrl?.includes(referenceId)) {
return entry.resource;
} else if (entry.resource?.id?.includes(referenceId)) {
return entry.resource;
}
}
}
}
Expand Down

0 comments on commit cb82f95

Please sign in to comment.