Skip to content

Commit

Permalink
set metadata tree
Browse files Browse the repository at this point in the history
  • Loading branch information
salimkanoun committed Nov 25, 2024
1 parent 8cf9cea commit ccc9679
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
50 changes: 30 additions & 20 deletions src/content/series/Tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { getInstancesOfSeries } from "../../services/orthanc";
import { Input, Spinner } from "../../ui";
import { useCustomQuery } from "../../utils";
import { instanceHeader, instanceTags } from "../../services/instances";

import { Metadata, Tag } from "../../utils/types";
import { Meta } from "@storybook/react";
type TagsProps = {
seriesId: string;
};

const Tags = ({ seriesId }: TagsProps) => {
const { data: instances } = useCustomQuery(
["series", seriesId, "instances"],
Expand All @@ -19,15 +21,15 @@ const Tags = ({ seriesId }: TagsProps) => {
? instances[instanceNumber - 1].id
: null;

const { data: header } = useCustomQuery(
const { data: header } = useCustomQuery<Metadata>(
["instances", currentInstanceId, "metadata"],
() => instanceHeader(currentInstanceId),
{
enabled: currentInstanceId !== null,
}
);

const { data: tags } = useCustomQuery(
const { data: tags } = useCustomQuery<Metadata>(
["instances", currentInstanceId, "tags"],
() => instanceTags(currentInstanceId),
{
Expand All @@ -43,27 +45,33 @@ const Tags = ({ seriesId }: TagsProps) => {
};
}, [header, tags]);

const getComponent = (
tagName: string,
tag: string | Record<string, string>[]
) => {
if (Array.isArray(tag)) {
return tag.map((tagItem) => {
return Object.entries(tagItem).map(([key, tag]) => {
return getComponent(key, tag);
});
const getComponent = (tagAddress: string, tag: Tag) => {
if (Array.isArray(tag.Value)) {
return tag.Value.map((metadata) => {
return (
<li>
{tag.Name}
<ul className="list-disc">
{Object.entries(metadata).map(([adressTag, tag]) =>
getComponent(adressTag, tag)
)}
</ul>
</li>
);
});
} else {
return (
<span>
<strong>{tagName}:</strong> {tag}
</span>
<li className="ml-4 px-2" key={tag.Name}>
{tag.Name} - {tag.Value}
</li>
);
}
};

if (!instances) return <Spinner />;

console.log(metadata);

return (
<>
<Input
Expand All @@ -73,11 +81,13 @@ const Tags = ({ seriesId }: TagsProps) => {
value={instanceNumber ?? 1}
onChange={(event) => setInstanceNumber(Number(event.target?.value))}
/>
<ul>
{Object.entries(metadata).map(([key, tag]) => (
<li key={key}>{getComponent(key, tag)}</li>
))}
</ul>
<div>
<ul className="list-disc">
{Object.entries(metadata).map(([tagAdress, tag]) =>
getComponent(tagAdress, tag)
)}
</ul>
</div>
</>
);
};
Expand Down
6 changes: 3 additions & 3 deletions src/services/instances.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from "./axios";
import { OrthancImportDicom, Tags } from "../utils/types";
import { Metadata, OrthancImportDicom, Tags } from "../utils/types";

export const sendDicom = (payload: Uint8Array): Promise<OrthancImportDicom> => {
return axios
Expand Down Expand Up @@ -73,7 +73,7 @@ export const previewFrame = (

export const instanceTags = (
instanceId: string
): Promise<Tags> => {
): Promise<Metadata> => {
return axios
.get("/api/instances/" + instanceId + "/tags?simplfy")
.then((response) => {
Expand All @@ -89,7 +89,7 @@ export const instanceTags = (

export const instanceHeader = (
instanceId: string
): Promise<Tags> => {
): Promise<Metadata> => {
return axios
.get("/api/instances/" + instanceId + "/header?simplfy")
.then((response) => {
Expand Down
7 changes: 6 additions & 1 deletion src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,9 @@ export type Queue = {
userId: number;
};

export type Tags = Record<string, string | Record<string, string>[]>;
export type Tag = {
Name : string,
Type : string,
Value : string | Metadata[]
}
export type Metadata = Record<string, Tag>;

0 comments on commit ccc9679

Please sign in to comment.