cod-dicomweb-server 1.2.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/cjs/1104a37b16dee0d2ada1.ts +14 -0
- package/dist/cjs/7d4e5892d21def245792.ts +14 -0
- package/dist/cjs/main.js +1957 -0
- package/dist/{types → esm}/classes/CodDicomWebServer.d.ts +2 -1
- package/dist/esm/classes/CodDicomWebServer.js +323 -0
- package/dist/esm/classes/customClasses.d.ts +19 -0
- package/dist/esm/classes/customClasses.js +13 -0
- package/dist/esm/classes/index.d.ts +2 -0
- package/dist/esm/classes/index.js +2 -0
- package/dist/esm/classes/utils.js +102 -0
- package/dist/esm/constants/dataRetrieval.js +3 -0
- package/dist/{types → esm}/constants/enums.d.ts +4 -0
- package/dist/esm/constants/enums.js +24 -0
- package/dist/{types → esm}/constants/index.d.ts +3 -3
- package/dist/esm/constants/index.js +6 -0
- package/dist/esm/constants/url.js +3 -0
- package/dist/esm/dataRetrieval/dataRetrievalManager.d.ts +17 -0
- package/dist/esm/dataRetrieval/dataRetrievalManager.js +54 -0
- package/dist/esm/dataRetrieval/register.d.ts +4 -0
- package/dist/esm/dataRetrieval/register.js +25 -0
- package/dist/esm/dataRetrieval/requestManager.d.ts +12 -0
- package/dist/esm/dataRetrieval/requestManager.js +65 -0
- package/dist/esm/dataRetrieval/scripts/filePartial.d.ts +18 -0
- package/dist/esm/dataRetrieval/scripts/filePartial.js +16 -0
- package/dist/{types/webWorker → esm/dataRetrieval}/scripts/fileStreaming.d.ts +7 -1
- package/dist/esm/dataRetrieval/scripts/fileStreaming.js +93 -0
- package/dist/esm/dataRetrieval/utils/environment.d.ts +1 -0
- package/dist/esm/dataRetrieval/utils/environment.js +3 -0
- package/dist/esm/dataRetrieval/workerManager.d.ts +10 -0
- package/dist/esm/dataRetrieval/workerManager.js +55 -0
- package/dist/esm/dataRetrieval/workers/filePartialWorker.js +7 -0
- package/dist/esm/dataRetrieval/workers/fileStreamingWorker.js +7 -0
- package/dist/{types → esm}/fileManager.d.ts +2 -2
- package/dist/esm/fileManager.js +52 -0
- package/dist/{types → esm}/index.d.ts +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/{types → esm}/metadataManager.d.ts +1 -0
- package/dist/esm/metadataManager.js +47 -0
- package/dist/esm/types/codDicomWebServerOptions.js +1 -0
- package/dist/{types → esm}/types/fileManagerOptions.d.ts +1 -1
- package/dist/esm/types/fileManagerOptions.js +1 -0
- package/dist/{types → esm}/types/index.d.ts +1 -1
- package/dist/esm/types/index.js +7 -0
- package/dist/{types → esm}/types/metadata.d.ts +1 -1
- package/dist/esm/types/metadata.js +1 -0
- package/dist/esm/types/metadataUrlCreationParams.js +1 -0
- package/dist/esm/types/parsedWadoRsUrlDetails.js +1 -0
- package/dist/esm/types/requestOptions.js +1 -0
- package/dist/esm/types/scriptObject.d.ts +4 -0
- package/dist/esm/types/scriptObject.js +1 -0
- package/dist/umd/614.js +19 -0
- package/dist/umd/614.js.map +1 -0
- package/dist/umd/66.js +19 -0
- package/dist/umd/66.js.map +1 -0
- package/dist/umd/main.js +21 -0
- package/dist/umd/main.js.map +1 -0
- package/package.json +18 -6
- package/dist/16.js +0 -19
- package/dist/16.js.map +0 -1
- package/dist/170.js +0 -19
- package/dist/170.js.map +0 -1
- package/dist/main.js +0 -21
- package/dist/main.js.map +0 -1
- package/dist/types/types/workerCustomMessageEvents.d.ts +0 -10
- package/dist/types/webWorker/registerWorkers.d.ts +0 -4
- package/dist/types/webWorker/scripts/filePartial.d.ts +0 -7
- package/dist/types/webWorker/workerManager.d.ts +0 -10
- /package/dist/{types → esm}/classes/utils.d.ts +0 -0
- /package/dist/{types/constants/worker.d.ts → esm/constants/dataRetrieval.d.ts} +0 -0
- /package/dist/{types → esm}/constants/url.d.ts +0 -0
- /package/dist/{types/webWorker → esm/dataRetrieval}/workers/filePartialWorker.d.ts +0 -0
- /package/dist/{types/webWorker → esm/dataRetrieval}/workers/fileStreamingWorker.d.ts +0 -0
- /package/dist/{types → esm}/types/codDicomWebServerOptions.d.ts +0 -0
- /package/dist/{types → esm}/types/metadataUrlCreationParams.d.ts +0 -0
- /package/dist/{types → esm}/types/parsedWadoRsUrlDetails.d.ts +0 -0
- /package/dist/{types → esm}/types/requestOptions.d.ts +0 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CustomError } from '../classes/customClasses';
|
|
2
|
+
class RequestManager {
|
|
3
|
+
loaderRegistry = {};
|
|
4
|
+
register(loaderName, loaderObject) {
|
|
5
|
+
try {
|
|
6
|
+
if (!loaderObject) {
|
|
7
|
+
throw new CustomError(`Loader object for ${loaderName} is not provided`);
|
|
8
|
+
}
|
|
9
|
+
this.loaderRegistry[loaderName] = {
|
|
10
|
+
loaderObject,
|
|
11
|
+
listeners: {}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
console.warn(error);
|
|
16
|
+
throw new CustomError('throws');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
listenerCallback = (loaderName, taskName, args) => {
|
|
20
|
+
const listeners = this.loaderRegistry[loaderName]?.listeners[taskName];
|
|
21
|
+
if (listeners) {
|
|
22
|
+
listeners.forEach((listener) => listener({ data: args }));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
async executeTask(loaderName, taskName, options) {
|
|
26
|
+
const loaderObject = this.loaderRegistry[loaderName]?.loaderObject;
|
|
27
|
+
if (!loaderObject) {
|
|
28
|
+
throw new CustomError(`Loader ${loaderName} not registered`);
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
return await loaderObject[taskName](options, (args) => this.listenerCallback(loaderName, 'message', args));
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error(`Error executing task "${taskName}" on "${loaderName}":`, error);
|
|
37
|
+
throw new CustomError(`Task "${taskName}" failed: ${error.message}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
addEventListener(workerName, eventType, listener) {
|
|
41
|
+
const loaderObject = this.loaderRegistry[workerName];
|
|
42
|
+
if (!loaderObject) {
|
|
43
|
+
console.error(`Loader '${workerName}' is not registered.`);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (!loaderObject.listeners[eventType]) {
|
|
47
|
+
loaderObject.listeners[eventType] = [listener];
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
loaderObject.listeners[eventType].push(listener);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
removeEventListener(workerName, eventType, listener) {
|
|
54
|
+
const loaderObject = this.loaderRegistry[workerName];
|
|
55
|
+
if (!loaderObject) {
|
|
56
|
+
console.error(`Loader '${workerName}' is not registered.`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
loaderObject.listeners[eventType] = (loaderObject.listeners[eventType] || []).filter((existingListener) => existingListener !== listener);
|
|
60
|
+
}
|
|
61
|
+
reset() {
|
|
62
|
+
this.loaderRegistry = {};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export default RequestManager;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const filePartial: {
|
|
2
|
+
partial(args: {
|
|
3
|
+
url: string;
|
|
4
|
+
offsets?: {
|
|
5
|
+
startByte: number;
|
|
6
|
+
endByte: number;
|
|
7
|
+
};
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
}, callBack: (data: {
|
|
10
|
+
url: string;
|
|
11
|
+
fileArraybuffer: Uint8Array;
|
|
12
|
+
offsets: {
|
|
13
|
+
startByte: number;
|
|
14
|
+
endByte: number;
|
|
15
|
+
};
|
|
16
|
+
}) => void): Promise<void | Error>;
|
|
17
|
+
};
|
|
18
|
+
export default filePartial;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CustomError } from '../../classes/customClasses';
|
|
2
|
+
const filePartial = {
|
|
3
|
+
async partial(args, callBack) {
|
|
4
|
+
const { url, offsets, headers } = args;
|
|
5
|
+
if (offsets?.startByte && offsets?.endByte) {
|
|
6
|
+
headers['Range'] = `bytes=${offsets.startByte}-${offsets.endByte - 1}`;
|
|
7
|
+
}
|
|
8
|
+
await fetch(url, { headers })
|
|
9
|
+
.then((response) => response.arrayBuffer())
|
|
10
|
+
.then((data) => callBack({ url, fileArraybuffer: new Uint8Array(data), offsets }))
|
|
11
|
+
.catch((error) => {
|
|
12
|
+
throw new CustomError('filePartial.ts: Error when fetching file: ' + error?.message);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export default filePartial;
|
|
@@ -7,6 +7,12 @@ declare const fileStreaming: {
|
|
|
7
7
|
url: string;
|
|
8
8
|
headers?: Record<string, string>;
|
|
9
9
|
useSharedArrayBuffer?: boolean;
|
|
10
|
-
}
|
|
10
|
+
}, callBack: (data: {
|
|
11
|
+
url: string;
|
|
12
|
+
position: number;
|
|
13
|
+
isAppending?: boolean;
|
|
14
|
+
fileArraybuffer?: Uint8Array;
|
|
15
|
+
chunk?: Uint8Array;
|
|
16
|
+
}) => void): Promise<Uint8Array | void>;
|
|
11
17
|
};
|
|
12
18
|
export default fileStreaming;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { CustomError } from '../../classes/customClasses';
|
|
2
|
+
const fileStreaming = {
|
|
3
|
+
maxFetchSize: 4 * 1024 * 1024 * 1024,
|
|
4
|
+
fetchedSize: 0,
|
|
5
|
+
setMaxFetchSize(size) {
|
|
6
|
+
if (size > 0) {
|
|
7
|
+
this.maxFetchSize = size;
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
decreaseFetchedSize(size) {
|
|
11
|
+
if (size > 0 && size <= this.fetchedSize) {
|
|
12
|
+
this.fetchedSize -= size;
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
async stream(args, callBack) {
|
|
16
|
+
const { url, headers, useSharedArrayBuffer } = args;
|
|
17
|
+
const controller = new AbortController();
|
|
18
|
+
let sharedArraybuffer = null;
|
|
19
|
+
let fileArraybuffer = null;
|
|
20
|
+
try {
|
|
21
|
+
const response = await fetch(url, {
|
|
22
|
+
headers: { ...headers },
|
|
23
|
+
signal: controller.signal
|
|
24
|
+
});
|
|
25
|
+
if (!response.ok) {
|
|
26
|
+
throw new CustomError(`HTTP error! status: ${response.status}`);
|
|
27
|
+
}
|
|
28
|
+
const reader = response.body?.getReader();
|
|
29
|
+
if (!reader) {
|
|
30
|
+
throw new CustomError('Failed to get reader from response body');
|
|
31
|
+
}
|
|
32
|
+
let result;
|
|
33
|
+
let completed = false;
|
|
34
|
+
const totalLength = parseInt(response.headers.get('Content-Length') || '0', 10);
|
|
35
|
+
const firstChunk = await reader.read();
|
|
36
|
+
completed = firstChunk.done;
|
|
37
|
+
if (!firstChunk.value) {
|
|
38
|
+
throw new CustomError('The fetched chunks does not have value');
|
|
39
|
+
}
|
|
40
|
+
if (!completed) {
|
|
41
|
+
let position = firstChunk.value.length;
|
|
42
|
+
if (this.fetchedSize + position > this.maxFetchSize) {
|
|
43
|
+
controller.abort();
|
|
44
|
+
throw new CustomError(`Maximum size(${this.maxFetchSize}) for fetching files reached`);
|
|
45
|
+
}
|
|
46
|
+
this.fetchedSize += position;
|
|
47
|
+
if (useSharedArrayBuffer) {
|
|
48
|
+
sharedArraybuffer = new SharedArrayBuffer(totalLength);
|
|
49
|
+
fileArraybuffer = new Uint8Array(sharedArraybuffer);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
fileArraybuffer = new Uint8Array(totalLength);
|
|
53
|
+
}
|
|
54
|
+
fileArraybuffer.set(firstChunk.value);
|
|
55
|
+
callBack({ url, position, fileArraybuffer });
|
|
56
|
+
while (!completed) {
|
|
57
|
+
result = await reader.read();
|
|
58
|
+
if (result.done) {
|
|
59
|
+
completed = true;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const chunk = result.value;
|
|
63
|
+
if (this.fetchedSize + chunk.length > this.maxFetchSize) {
|
|
64
|
+
sharedArraybuffer = null;
|
|
65
|
+
fileArraybuffer = null;
|
|
66
|
+
controller.abort();
|
|
67
|
+
throw new CustomError(`Maximum size(${this.maxFetchSize}) for fetching files reached`);
|
|
68
|
+
}
|
|
69
|
+
this.fetchedSize += chunk.length;
|
|
70
|
+
fileArraybuffer.set(chunk, position);
|
|
71
|
+
position += chunk.length;
|
|
72
|
+
callBack({
|
|
73
|
+
isAppending: true,
|
|
74
|
+
url,
|
|
75
|
+
position: position,
|
|
76
|
+
chunk: !useSharedArrayBuffer ? chunk : undefined
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
const streamingError = new CustomError('fileStreaming.ts: ' + error.message || 'An error occured when streaming');
|
|
83
|
+
console.error(streamingError.message, error);
|
|
84
|
+
throw streamingError;
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
sharedArraybuffer = null;
|
|
88
|
+
fileArraybuffer = null;
|
|
89
|
+
controller.abort();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
export default fileStreaming;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isNodeEnvironment(): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CustomErrorEvent, CustomMessageEvent } from '../classes/customClasses';
|
|
2
|
+
declare class WebWorkerManager {
|
|
3
|
+
private workerRegistry;
|
|
4
|
+
register(name: string, workerFn: () => Worker): void;
|
|
5
|
+
executeTask(workerName: string, taskName: string, options: Record<string, unknown> | unknown): Promise<void>;
|
|
6
|
+
addEventListener(workerName: string, eventType: keyof WorkerEventMap, listener: (evt: CustomMessageEvent | CustomErrorEvent) => unknown): void;
|
|
7
|
+
removeEventListener(workerName: string, eventType: keyof WorkerEventMap, listener: (evt: CustomMessageEvent | CustomErrorEvent) => unknown): void;
|
|
8
|
+
reset(): void;
|
|
9
|
+
}
|
|
10
|
+
export default WebWorkerManager;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { wrap } from 'comlink';
|
|
2
|
+
import { CustomError } from '../classes/customClasses';
|
|
3
|
+
class WebWorkerManager {
|
|
4
|
+
workerRegistry = {};
|
|
5
|
+
register(name, workerFn) {
|
|
6
|
+
try {
|
|
7
|
+
const worker = workerFn();
|
|
8
|
+
if (!worker) {
|
|
9
|
+
throw new CustomError(`WorkerFn of worker ${name} is not creating a worker`);
|
|
10
|
+
}
|
|
11
|
+
this.workerRegistry[name] = {
|
|
12
|
+
instance: wrap(worker),
|
|
13
|
+
nativeWorker: worker
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
console.warn(error);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async executeTask(workerName, taskName, options) {
|
|
21
|
+
const worker = this.workerRegistry[workerName]?.instance;
|
|
22
|
+
if (!worker) {
|
|
23
|
+
throw new CustomError(`Worker ${workerName} not registered`);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
return await worker[taskName](options);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
console.error(`Error executing task "${taskName}" on worker "${workerName}":`, error);
|
|
32
|
+
throw new CustomError(`Task "${taskName}" failed: ${error.message}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
addEventListener(workerName, eventType, listener) {
|
|
36
|
+
const worker = this.workerRegistry[workerName];
|
|
37
|
+
if (!worker) {
|
|
38
|
+
console.error(`Worker type '${workerName}' is not registered.`);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
worker.nativeWorker.addEventListener(eventType, listener);
|
|
42
|
+
}
|
|
43
|
+
removeEventListener(workerName, eventType, listener) {
|
|
44
|
+
const worker = this.workerRegistry[workerName];
|
|
45
|
+
if (!worker) {
|
|
46
|
+
console.error(`Worker type '${workerName}' is not registered.`);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
worker.nativeWorker.removeEventListener(eventType, listener);
|
|
50
|
+
}
|
|
51
|
+
reset() {
|
|
52
|
+
this.workerRegistry = {};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export default WebWorkerManager;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { FileManagerOptions } from './types';
|
|
2
2
|
declare class FileManager {
|
|
3
3
|
private files;
|
|
4
|
-
private
|
|
5
|
-
constructor({
|
|
4
|
+
private fileStreamingScriptName;
|
|
5
|
+
constructor({ fileStreamingScriptName }: FileManagerOptions);
|
|
6
6
|
set(url: string, file: {
|
|
7
7
|
data: Uint8Array;
|
|
8
8
|
position: number;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getDataRetrievalManager } from './dataRetrieval/dataRetrievalManager';
|
|
2
|
+
class FileManager {
|
|
3
|
+
files = {};
|
|
4
|
+
fileStreamingScriptName;
|
|
5
|
+
constructor({ fileStreamingScriptName }) {
|
|
6
|
+
this.fileStreamingScriptName = fileStreamingScriptName;
|
|
7
|
+
}
|
|
8
|
+
set(url, file) {
|
|
9
|
+
this.files[url] = file;
|
|
10
|
+
}
|
|
11
|
+
get(url, offsets) {
|
|
12
|
+
if (!this.files[url] || (offsets && this.files[url].position <= offsets.endByte)) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return offsets ? this.files[url].data.slice(offsets.startByte, offsets.endByte) : this.files[url].data;
|
|
16
|
+
}
|
|
17
|
+
setPosition(url, position) {
|
|
18
|
+
if (this.files[url]) {
|
|
19
|
+
this.files[url].position = position;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
getPosition(url) {
|
|
23
|
+
return this.files[url]?.position;
|
|
24
|
+
}
|
|
25
|
+
append(url, chunk, position) {
|
|
26
|
+
if (this.files[url] && position) {
|
|
27
|
+
this.files[url].data.set(chunk, position - chunk.length);
|
|
28
|
+
this.setPosition(url, position);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
getTotalSize() {
|
|
32
|
+
return Object.entries(this.files).reduce((total, [url, { position }]) => {
|
|
33
|
+
return url.includes('?bytes=') ? total : total + position;
|
|
34
|
+
}, 0);
|
|
35
|
+
}
|
|
36
|
+
remove(url) {
|
|
37
|
+
const removedSize = this.getPosition(url);
|
|
38
|
+
delete this.files[url];
|
|
39
|
+
if (url.includes('?bytes=')) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const retrievalManager = getDataRetrievalManager();
|
|
43
|
+
retrievalManager.executeTask(this.fileStreamingScriptName, 'decreaseFetchedSize', removedSize);
|
|
44
|
+
}
|
|
45
|
+
purge() {
|
|
46
|
+
const totalSize = this.getTotalSize();
|
|
47
|
+
this.files = {};
|
|
48
|
+
const retrievalManager = getDataRetrievalManager();
|
|
49
|
+
retrievalManager.executeTask(this.fileStreamingScriptName, 'decreaseFetchedSize', totalSize);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export default FileManager;
|
|
@@ -2,6 +2,7 @@ import type { JsonMetadata, MetadataUrlCreationParams } from './types';
|
|
|
2
2
|
declare class MetadataManager {
|
|
3
3
|
private metadata;
|
|
4
4
|
constructor();
|
|
5
|
+
addDeidMetadata(jsonMetadata: JsonMetadata): void;
|
|
5
6
|
getMetadataFromCache(url: string): JsonMetadata;
|
|
6
7
|
getMetadata(params: MetadataUrlCreationParams, headers: Record<string, string>): Promise<JsonMetadata | null>;
|
|
7
8
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CustomError } from './classes/customClasses';
|
|
2
|
+
import { createMetadataJsonUrl } from './classes/utils';
|
|
3
|
+
class MetadataManager {
|
|
4
|
+
metadata = {};
|
|
5
|
+
constructor() { }
|
|
6
|
+
addDeidMetadata(jsonMetadata) {
|
|
7
|
+
const { deid_study_uid, deid_series_uid, cod } = jsonMetadata;
|
|
8
|
+
if (!cod || !deid_study_uid || !deid_series_uid) {
|
|
9
|
+
console.warn('Missing required metadata properties: cod, deid_study_uid, or deid_series_uid');
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
for (const deid_sop_uid in cod.instances) {
|
|
13
|
+
const instance = cod.instances[deid_sop_uid];
|
|
14
|
+
instance.metadata.DeidStudyInstanceUID = { Value: [deid_study_uid] };
|
|
15
|
+
instance.metadata.DeidSeriesInstanceUID = { Value: [deid_series_uid] };
|
|
16
|
+
instance.metadata.DeidSopInstanceUID = { Value: [deid_sop_uid] };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
getMetadataFromCache(url) {
|
|
20
|
+
return this.metadata[url];
|
|
21
|
+
}
|
|
22
|
+
async getMetadata(params, headers) {
|
|
23
|
+
const url = createMetadataJsonUrl(params);
|
|
24
|
+
if (!url) {
|
|
25
|
+
throw new CustomError('Error creating metadata json url');
|
|
26
|
+
}
|
|
27
|
+
const cachedMetadata = this.getMetadataFromCache(url);
|
|
28
|
+
if (cachedMetadata) {
|
|
29
|
+
return cachedMetadata;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const response = await fetch(url, { headers });
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
throw new CustomError(`Failed to fetch metadata: ${response.statusText}`);
|
|
35
|
+
}
|
|
36
|
+
const data = await response.json();
|
|
37
|
+
this.addDeidMetadata(data);
|
|
38
|
+
this.metadata[url] = data;
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error(error);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export default MetadataManager;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './codDicomWebServerOptions';
|
|
2
|
+
export * from './fileManagerOptions';
|
|
3
|
+
export * from './metadata';
|
|
4
|
+
export * from './metadataUrlCreationParams';
|
|
5
|
+
export * from './parsedWadoRsUrlDetails';
|
|
6
|
+
export * from './requestOptions';
|
|
7
|
+
export * from './scriptObject';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/umd/614.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
*
|
|
3
|
+
* cod-dicomweb-server v1.2.4
|
|
4
|
+
* git+https://github.com/gradienthealth/cod-dicomweb-server.git
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Adithyan Dinesh and project contributors.
|
|
7
|
+
*
|
|
8
|
+
* This source code is licensed under the MIT license found in the
|
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var n in r)("object"==typeof exports?exports:t)[n]=r[n]}}(self,(()=>(()=>{"use strict";
|
|
13
|
+
/**
|
|
14
|
+
* @license
|
|
15
|
+
* Copyright 2019 Google LLC
|
|
16
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
*/
|
|
18
|
+
const t=Symbol("Comlink.proxy"),e=Symbol("Comlink.endpoint"),r=Symbol("Comlink.releaseProxy"),n=Symbol("Comlink.finalizer"),o=Symbol("Comlink.thrown"),i=t=>"object"==typeof t&&null!==t||"function"==typeof t,a={canHandle:e=>i(e)&&e[t],serialize(t){const{port1:e,port2:r}=new MessageChannel;return u(t,e),[r,[r]]},deserialize:t=>(t.start(),function(t,e){const r=new Map;return t.addEventListener("message",(function(t){const{data:e}=t;if(!e||!e.id)return;const n=r.get(e.id);if(n)try{n(e)}finally{r.delete(e.id)}})),h(t,r,[],e)}(t))},c=new Map([["proxy",a],["throw",{canHandle:t=>i(t)&&o in t,serialize({value:t}){let e;return e=t instanceof Error?{isError:!0,value:{message:t.message,name:t.name,stack:t.stack}}:{isError:!1,value:t},[e,[]]},deserialize(t){if(t.isError)throw Object.assign(new Error(t.value.message),t.value);throw t.value}}]]);function u(e,r=globalThis,i=["*"]){r.addEventListener("message",(function a(c){if(!c||!c.data)return;if(!function(t,e){for(const r of t){if(e===r||"*"===r)return!0;if(r instanceof RegExp&&r.test(e))return!0}return!1}(i,c.origin))return void console.warn(`Invalid origin '${c.origin}' for comlink proxy`);const{id:f,type:l,path:p}=Object.assign({path:[]},c.data),y=(c.data.argumentList||[]).map(d);let h;try{const r=p.slice(0,-1).reduce(((t,e)=>t[e]),e),n=p.reduce(((t,e)=>t[e]),e);switch(l){case"GET":h=n;break;case"SET":r[p.slice(-1)[0]]=d(c.data.value),h=!0;break;case"APPLY":h=n.apply(r,y);break;case"CONSTRUCT":h=function(e){return Object.assign(e,{[t]:!0})}(new n(...y));break;case"ENDPOINT":{const{port1:t,port2:r}=new MessageChannel;u(e,r),h=function(t,e){return b.set(t,e),t}(t,[t])}break;case"RELEASE":h=void 0;break;default:return}}catch(t){h={value:t,[o]:0}}Promise.resolve(h).catch((t=>({value:t,[o]:0}))).then((t=>{const[o,i]=m(t);r.postMessage(Object.assign(Object.assign({},o),{id:f}),i),"RELEASE"===l&&(r.removeEventListener("message",a),s(r),n in e&&"function"==typeof e[n]&&e[n]())})).catch((t=>{const[e,n]=m({value:new TypeError("Unserializable return value"),[o]:0});r.postMessage(Object.assign(Object.assign({},e),{id:f}),n)}))})),r.start&&r.start()}function s(t){(function(t){return"MessagePort"===t.constructor.name})(t)&&t.close()}function f(t){if(t)throw new Error("Proxy has been released and is not useable")}function l(t){return g(t,new Map,{type:"RELEASE"}).then((()=>{s(t)}))}const p=new WeakMap,y="FinalizationRegistry"in globalThis&&new FinalizationRegistry((t=>{const e=(p.get(t)||0)-1;p.set(t,e),0===e&&l(t)}));function h(t,n,o=[],i=function(){}){let a=!1;const c=new Proxy(i,{get(e,i){if(f(a),i===r)return()=>{!function(t){y&&y.unregister(t)}(c),l(t),n.clear(),a=!0};if("then"===i){if(0===o.length)return{then:()=>c};const e=g(t,n,{type:"GET",path:o.map((t=>t.toString()))}).then(d);return e.then.bind(e)}return h(t,n,[...o,i])},set(e,r,i){f(a);const[c,u]=m(i);return g(t,n,{type:"SET",path:[...o,r].map((t=>t.toString())),value:c},u).then(d)},apply(r,i,c){f(a);const u=o[o.length-1];if(u===e)return g(t,n,{type:"ENDPOINT"}).then(d);if("bind"===u)return h(t,n,o.slice(0,-1));const[s,l]=v(c);return g(t,n,{type:"APPLY",path:o.map((t=>t.toString())),argumentList:s},l).then(d)},construct(e,r){f(a);const[i,c]=v(r);return g(t,n,{type:"CONSTRUCT",path:o.map((t=>t.toString())),argumentList:i},c).then(d)}});return function(t,e){const r=(p.get(e)||0)+1;p.set(e,r),y&&y.register(t,e,t)}(c,t),c}function v(t){const e=t.map(m);return[e.map((t=>t[0])),(r=e.map((t=>t[1])),Array.prototype.concat.apply([],r))];var r}const b=new WeakMap;function m(t){for(const[e,r]of c)if(r.canHandle(t)){const[n,o]=r.serialize(t);return[{type:"HANDLER",name:e,value:n},o]}return[{type:"RAW",value:t},b.get(t)||[]]}function d(t){switch(t.type){case"HANDLER":return c.get(t.name).deserialize(t.value);case"RAW":return t.value}}function g(t,e,r,n){return new Promise((o=>{const i=new Array(4).fill(0).map((()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16))).join("-");e.set(i,o),t.start&&t.start(),t.postMessage(Object.assign({id:i},r),n)}))}function w(t){return w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},w(t)}function E(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,j(n.key),n)}}function O(t,e,r){return e&&E(t.prototype,e),r&&E(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function j(t){var e=function(t,e){if("object"!=w(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=w(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==w(e)?e:e+""}function S(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function P(t,e,r){return e=_(e),function(t,e){if(e&&("object"==w(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,k()?Reflect.construct(e,r||[],_(t).constructor):e.apply(t,r))}function x(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&T(t,e)}function L(t){var e="function"==typeof Map?new Map:void 0;return L=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return function(t,e,r){if(k())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,e);var o=new(t.bind.apply(t,n));return r&&T(o,r.prototype),o}(t,arguments,_(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),T(r,t)},L(t)}function k(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(k=function(){return!!t})()}function T(t,e){return T=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},T(t,e)}function _(t){return _=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},_(t)}var N=function(t){function e(){return S(this,e),P(this,e,arguments)}return x(e,t),O(e)}(L(Error));function A(t){return A="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},A(t)}function M(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */M=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var i=e&&e.prototype instanceof m?e:m,a=Object.create(i.prototype),c=new _(n||[]);return o(a,"_invoke",{value:x(t,r,c)}),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var p="suspendedStart",y="suspendedYield",h="executing",v="completed",b={};function m(){}function d(){}function g(){}var w={};s(w,a,(function(){return this}));var E=Object.getPrototypeOf,O=E&&E(E(N([])));O&&O!==r&&n.call(O,a)&&(w=O);var j=g.prototype=m.prototype=Object.create(w);function S(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function P(t,e){function r(o,i,a,c){var u=l(t[o],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==A(f)&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function x(e,r,n){var o=p;return function(i,a){if(o===h)throw Error("Generator is already running");if(o===v){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=L(c,n);if(u){if(u===b)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=v,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=h;var s=l(e,r,n);if("normal"===s.type){if(o=n.done?v:y,s.arg===b)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=v,n.method="throw",n.arg=s.arg)}}}function L(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,L(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),b;var i=l(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,b;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,b):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,b)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function N(e){if(e||""===e){var r=e[a];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(A(e)+" is not iterable")}return d.prototype=g,o(j,"constructor",{value:g,configurable:!0}),o(g,"constructor",{value:d,configurable:!0}),d.displayName=s(g,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,s(t,u,"GeneratorFunction")),t.prototype=Object.create(j),t},e.awrap=function(t){return{__await:t}},S(P.prototype),s(P.prototype,c,(function(){return this})),e.AsyncIterator=P,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new P(f(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},S(j),s(j,u,"Generator"),s(j,a,(function(){return this})),s(j,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=N,_.prototype={constructor:_,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(T),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,b):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),b},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),T(r),b}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;T(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:N(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),b}},e}function R(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}const C={partial:function(t,e){return(r=M().mark((function r(){var n,o;return M().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=t.url,o=t.headers,r.next=3,fetch(n,{headers:o}).then((function(t){return t.arrayBuffer()})).then((function(t){return e({url:n,fileArraybuffer:new Uint8Array(t)})})).catch((function(t){throw new N("filePartial.ts: Error when fetching file: "+(null==t?void 0:t.message))}));case 3:case"end":return r.stop()}}),r)})),function(){var t=this,e=arguments;return new Promise((function(n,o){var i=r.apply(t,e);function a(t){R(i,n,o,a,c,"next",t)}function c(t){R(i,n,o,a,c,"throw",t)}a(void 0)}))})();var r}};function G(t){return G="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},G(t)}function z(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function D(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?z(Object(r),!0).forEach((function(e){F(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):z(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function F(t,e,r){return(e=function(t){var e=function(t,e){if("object"!=G(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=G(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==G(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}return u(D(D({},C),{},{partial:function(t){return C.partial(t,postMessage)}})),{}})()));
|
|
19
|
+
//# sourceMappingURL=614.js.map
|