From 73e0d5625fb6ac53073b6cb040a6e8fa9b09244c Mon Sep 17 00:00:00 2001 From: Julien VIGNAU-ESPINE Date: Mon, 7 Oct 2024 15:50:17 +0200 Subject: [PATCH 1/4] [FEAT](json): parsing of the header json to only get names and values --- src/content/series/Tags.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/content/series/Tags.tsx b/src/content/series/Tags.tsx index bbe981e6..cc80f76d 100644 --- a/src/content/series/Tags.tsx +++ b/src/content/series/Tags.tsx @@ -30,13 +30,25 @@ const Tags = ({ seriesId }: TagsProps) => { } ) + const json = JSON.parse(JSON.stringify(header, null, 2)) + const json_values = Object.values(json) + var names_list = [] + var values_list = [] + for (var index = 0; index < json_values.length; index++) { + names_list.push(json_values[index]["Name"]) + values_list.push(json_values[index]["Value"]) + } + + const jsonNameValues = Object.fromEntries(names_list.map((key, index) => [key, values_list[index]])); + if (!instances) return return ( <> setInstanceNumber(Number(event.target?.value))} />
-                {JSON.stringify(header, null, 2)}
-                {JSON.stringify(tags, null, 2)}
+                {JSON.stringify(jsonNameValues, null, 2)}
+                {JSON.stringify(header, null, 2)} 
+                {/* {JSON.stringify(tags, null, 2)} */}
             
) From 1bc0b17a99c9f55736737de4699bb373f45e9947 Mon Sep 17 00:00:00 2001 From: Julien VIGNAU-ESPINE Date: Mon, 7 Oct 2024 16:15:39 +0200 Subject: [PATCH 2/4] [FEAT](display): add display for tags and header --- src/content/series/Tags.tsx | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/content/series/Tags.tsx b/src/content/series/Tags.tsx index cc80f76d..c8a89c0b 100644 --- a/src/content/series/Tags.tsx +++ b/src/content/series/Tags.tsx @@ -38,16 +38,35 @@ const Tags = ({ seriesId }: TagsProps) => { names_list.push(json_values[index]["Name"]) values_list.push(json_values[index]["Value"]) } - const jsonNameValues = Object.fromEntries(names_list.map((key, index) => [key, values_list[index]])); + const json2 = JSON.parse(JSON.stringify(tags, null, 2)) + const json_values2 = Object.values(json2) + var names_list2 = [] + var values_list2 = [] + for (var index = 0; index < json_values2.length; index++) { + names_list2.push(json_values2[index]["Name"]) + values_list2.push(json_values2[index]["Value"]) + } + const jsonNameValues2 = Object.fromEntries(names_list2.map((key, index) => [key, values_list2[index]])); + if (!instances) return return ( <> setInstanceNumber(Number(event.target?.value))} />
-                {JSON.stringify(jsonNameValues, null, 2)}
-                {JSON.stringify(header, null, 2)} 
+                {Object.entries(jsonNameValues).map(([key, value]) => (
+                    
+ {key}: {JSON.stringify(value)} +
+ ))} +
+ {Object.entries(jsonNameValues2).map(([key, value]) => ( +
+ {key}: {JSON.stringify(value)} +
+ ))} + {/* {JSON.stringify(header, null, 2)} */} {/* {JSON.stringify(tags, null, 2)} */}
From f8040a1770b4dd796a2fc351c72017e3e3192dfa Mon Sep 17 00:00:00 2001 From: Julien VIGNAU-ESPINE Date: Mon, 7 Oct 2024 16:19:31 +0200 Subject: [PATCH 3/4] [FEAT](display): add lines --- src/content/series/Tags.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/content/series/Tags.tsx b/src/content/series/Tags.tsx index c8a89c0b..25f07554 100644 --- a/src/content/series/Tags.tsx +++ b/src/content/series/Tags.tsx @@ -58,12 +58,14 @@ const Tags = ({ seriesId }: TagsProps) => { {Object.entries(jsonNameValues).map(([key, value]) => (
{key}: {JSON.stringify(value)} +
))} -
+




{Object.entries(jsonNameValues2).map(([key, value]) => (
{key}: {JSON.stringify(value)} +
))} {/* {JSON.stringify(header, null, 2)} */} From e6e76d63d9cfe21fb58a1e2ba2852d06d4170403 Mon Sep 17 00:00:00 2001 From: Salim Kanoun Date: Tue, 8 Oct 2024 15:20:18 +0000 Subject: [PATCH 4/4] try refac --- src/content/series/Tags.tsx | 139 +++++++++++++++++++----------------- src/services/instances.ts | 24 +++++-- src/utils/types.ts | 38 +++++----- 3 files changed, 110 insertions(+), 91 deletions(-) diff --git a/src/content/series/Tags.tsx b/src/content/series/Tags.tsx index 25f07554..b6e9001f 100644 --- a/src/content/series/Tags.tsx +++ b/src/content/series/Tags.tsx @@ -1,78 +1,85 @@ -import { useState } from "react" -import { getInstancesOfSeries } from "../../services/orthanc" -import { Input, Spinner } from "../../ui" -import { useCustomQuery } from "../../utils" -import { instanceHeader, instanceTags } from "../../services/instances" +import { useMemo, useState } from "react"; +import { getInstancesOfSeries } from "../../services/orthanc"; +import { Input, Spinner } from "../../ui"; +import { useCustomQuery } from "../../utils"; +import { instanceHeader, instanceTags } from "../../services/instances"; type TagsProps = { - seriesId: string -} + seriesId: string; +}; const Tags = ({ seriesId }: TagsProps) => { + const { data: instances } = useCustomQuery( + ["series", seriesId, "instances"], + () => getInstancesOfSeries(seriesId) + ); + const [instanceNumber, setInstanceNumber] = useState(1); - const { data: instances } = useCustomQuery(['series', seriesId, 'instances'], () => getInstancesOfSeries(seriesId)) - const [instanceNumber, setInstanceNumber] = useState(1) + const currentInstanceId = + instanceNumber != null && instances != null + ? instances[instanceNumber - 1].id + : null; - const currentInstanceId = (instanceNumber != null && instances != null) ? instances[instanceNumber - 1].id : null + const { data: header } = useCustomQuery( + ["instances", currentInstanceId, "metadata"], + () => instanceHeader(currentInstanceId), + { + enabled: currentInstanceId !== null, + } + ); - const { data: header } = useCustomQuery( - ['instances', currentInstanceId, 'metadata'], - () => instanceHeader(currentInstanceId), - { - enabled: (currentInstanceId !== null) - } - ) + const { data: tags } = useCustomQuery( + ["instances", currentInstanceId, "tags"], + () => instanceTags(currentInstanceId), + { + enabled: currentInstanceId !== null, + } + ); - const { data: tags } = useCustomQuery( - ['instances', currentInstanceId, 'tags'], - () => instanceTags(currentInstanceId), - { - enabled: (currentInstanceId !== null) - } - ) + const metadata = useMemo(() => { + if (!header || !tags) return {}; + return { + ...header, + ...tags, + }; + }, [header, tags]); - const json = JSON.parse(JSON.stringify(header, null, 2)) - const json_values = Object.values(json) - var names_list = [] - var values_list = [] - for (var index = 0; index < json_values.length; index++) { - names_list.push(json_values[index]["Name"]) - values_list.push(json_values[index]["Value"]) + const getComponent = ( + tagName: string, + tag: string | Record[] + ) => { + if (Array.isArray(tag)) { + return tag.map((tagItem) => { + return Object.entries(tagItem).map(([key, tag]) => { + return getComponent(key, tag); + }); + }); + } else { + return ( + + {tagName}: {tag} + + ); } - const jsonNameValues = Object.fromEntries(names_list.map((key, index) => [key, values_list[index]])); + }; - const json2 = JSON.parse(JSON.stringify(tags, null, 2)) - const json_values2 = Object.values(json2) - var names_list2 = [] - var values_list2 = [] - for (var index = 0; index < json_values2.length; index++) { - names_list2.push(json_values2[index]["Name"]) - values_list2.push(json_values2[index]["Value"]) - } - const jsonNameValues2 = Object.fromEntries(names_list2.map((key, index) => [key, values_list2[index]])); + if (!instances) return ; - if (!instances) return - return ( - <> - setInstanceNumber(Number(event.target?.value))} /> -
-                {Object.entries(jsonNameValues).map(([key, value]) => (
-                    
- {key}: {JSON.stringify(value)} -
-
- ))} -




- {Object.entries(jsonNameValues2).map(([key, value]) => ( -
- {key}: {JSON.stringify(value)} -
-
- ))} - {/* {JSON.stringify(header, null, 2)} */} - {/* {JSON.stringify(tags, null, 2)} */} -
- - ) -} + return ( + <> + setInstanceNumber(Number(event.target?.value))} + /> +
    + {Object.entries(metadata).map(([key, tag]) => ( +
  • {getComponent(key, tag)}
  • + ))} +
+ + ); +}; -export default Tags \ No newline at end of file +export default Tags; diff --git a/src/services/instances.ts b/src/services/instances.ts index 45b08dce..6773f00d 100644 --- a/src/services/instances.ts +++ b/src/services/instances.ts @@ -1,5 +1,5 @@ import axios from "./axios"; -import { OrthancImportDicom } from "../utils/types"; +import { OrthancImportDicom, Tags } from "../utils/types"; export const sendDicom = (payload: Uint8Array): Promise => { return axios @@ -71,24 +71,34 @@ export const previewFrame = ( }); }; -export const instanceTags = (instanceId: string): Promise => { +export const instanceTags = ( + instanceId: string +): Promise => { return axios - .get("/api/instances/" + instanceId + "/tags") + .get("/api/instances/" + instanceId + "/tags?simplfy") .then((response) => { return response.data; }) .catch((error) => { - console.error(error); + if (error.response) { + throw error.response; + } + throw error; }); }; -export const instanceHeader = (instanceId: string): Promise => { +export const instanceHeader = ( + instanceId: string +): Promise => { return axios - .get("/api/instances/" + instanceId + "/header") + .get("/api/instances/" + instanceId + "/header?simplfy") .then((response) => { return response.data; }) .catch((error) => { - console.error(error); + if (error.response) { + throw error.response; + } + throw error; }); }; diff --git a/src/utils/types.ts b/src/utils/types.ts index d0687acb..90d79f25 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -139,7 +139,7 @@ export type ProcessingJob = { progress: number; state: string; id: string; - results : Record + results: Record; }; export type Peer = { @@ -302,7 +302,7 @@ export type Instances = { instanceCreationTime: string | null; instanceNumber: string | null; sopInstanceUID: string | null; - numberOfFrames: string|null; + numberOfFrames: string | null; }; parentSeries: string; type: string; @@ -343,7 +343,7 @@ export type PatientModifyPayload = { force: boolean; synchronous: boolean; keepSource: boolean; - keep : string[]; + keep: string[]; }; export type OrthancResponse = { @@ -364,19 +364,19 @@ export type Study = { }; export type AnonStudy = { - newPatientName : string, - newPatientId : string, - newStudyDescription : string, - newAccessionNumber : string, - originalStudy : Study; -} + newPatientName: string; + newPatientId: string; + newStudyDescription: string; + newAccessionNumber: string; + originalStudy: Study; +}; export type StudyModifyPayload = { - replace: Partial; + replace: Partial; remove: string[]; removePrivateTags: boolean; force: boolean; - keep : string[]; + keep: string[]; synchronous: boolean; keepSource: boolean; }; @@ -388,13 +388,15 @@ export type SeriesModifyPayload = { keepSource: boolean; force: boolean; synchronous: boolean; - keep : string[]; + keep: string[]; }; export type Queue = { - progress : number - state : string - id : string - results : Record - userId : number -} \ No newline at end of file + progress: number; + state: string; + id: string; + results: Record; + userId: number; +}; + +export type Tags = Record[]>;