Skip to content

Commit 928a144

Browse files
committed
Add a DICOMweb proxy capability to the webserver
1 parent 717d0f2 commit 928a144

5 files changed

Lines changed: 93 additions & 2 deletions

File tree

packages/static-wado-creator/lib/mkdicomwebConfig.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { staticWadoConfig } = require("@radicalimaging/static-wado-util");
33
const createMain = require("./createMain");
44
const deleteMain = require("./deleteMain");
55
const rejectMain = require("./rejectMain");
6+
const queryMain = require("./queryMain");
67
const instanceMain = require("./instanceMain");
78
const indexMain = require("./indexMain");
89
const groupMain = require("./groupMain");
@@ -58,6 +59,10 @@ const { mkdicomwebConfig } = ConfigPoint.register({
5859
key: "-e, --no-encapsulated-image",
5960
description: "Avoid encapsulating the image frame. Writes with the extension and without multipart",
6061
},
62+
{
63+
key: "--singlepart-bulkdata",
64+
description: "Store bulkdata as single part data",
65+
},
6166
{
6267
key: "--single-part-image",
6368
description: "Writes single part image data",
@@ -184,6 +189,11 @@ const { mkdicomwebConfig } = ConfigPoint.register({
184189
main: rejectMain,
185190
helpDescription: "Reject the specified series",
186191
},
192+
{
193+
command: "query <url>",
194+
main: queryMain,
195+
helpDescription: "Performs DICOMweb query operations to update local deduplicated/metadata",
196+
},
187197
],
188198
},
189199
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const https = require("https");
2+
3+
/** Retrieve the given url fromm the back end, returning a JSON representation of the data */
4+
module.exports = function retrieve(url, options) {
5+
console.log("Requesting to retrieve", url);
6+
const parsedUrl = new URL(url);
7+
const req = https.request(parsedUrl, (res) => {
8+
console.log(`STATUS: ${res.statusCode}`);
9+
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
10+
res.setEncoding('utf8');
11+
res.on('data', (chunk) => {
12+
console.log(`BODY: ${chunk}`);
13+
});
14+
res.on('end', () => {
15+
console.log('No more data in response.');
16+
});
17+
});
18+
req.on('error', (e) => {
19+
console.error(`problem with request: ${e.message}`);
20+
});
21+
22+
req.end();
23+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const StaticWado = require("./StaticWado");
2+
const adaptProgramOpts = require("./util/adaptProgramOpts");
3+
const retrieveJson = require("./query/retrieveJson");
4+
5+
/**
6+
* Queries the given URL instance.
7+
* Options:
8+
* * metadata
9+
* Appends /series to the URL and tries to retrieve
10+
* Stores the data in the `series` key
11+
* Iterates over all series in the list and checks if the series is up to date
12+
* For each series not up to date:
13+
* * `series/<seriesInstanceUID>/metadata` stored to a key of the same name
14+
* * Iterates over all instances in above and adds to `StudyData`
15+
* Writes updated study data files (recreated from new deduplciated data)
16+
* * cache - will cache all queried files
17+
* * stream - will print the response directly to the standard output.
18+
* * deduplicated
19+
* Reads the /deduplicated path first
20+
* If no object, and the `metadata` option is set, then runs that path
21+
* If the object is found, then writes the deduplicated data to the deduplicated path
22+
* Runs the regular metadata create path
23+
*
24+
* Retrieving individual instances for proxying cached data.
25+
* Data can be read from disk once this is complete.
26+
* `mkdicomweb query 1.2.3/series --cache`
27+
* `mkdicomweb query 1.2.3/series/2.3.4/metadata --cache`
28+
*
29+
* Retrieving a study query for direct proxy:
30+
* Data can be streamed directly from the command line.
31+
* `mkdicomweb query 1.2.3?ModalitiesInStudy=CR --stream`
32+
*
33+
* Creates or Updates Deduplicated Metadata:
34+
* This command should be used before receiving data against remote proxies NOT supporting deduplicated
35+
* `mkdicomweb query 1.2.3 --metadata`
36+
*
37+
* Creates or Updates Deduplicated Metadata from Deduplicated Remote
38+
* This command should be used before receiving data against remote proxies supporting deduplicated
39+
* `mkdicomweb query 1.2.3 --deduplicated`
40+
*
41+
* @param {*} url to fetch
42+
* @param {*} options
43+
* @param {*} program
44+
*/
45+
module.exports = function queryMain(url, options) {
46+
const finalOptions = adaptProgramOpts(options, {
47+
...this,
48+
isGroup: true,
49+
isStudyData: true,
50+
});
51+
const importer = new StaticWado(finalOptions);
52+
const useUrl = url.indexOf('http')===-1 ? `${this.dicomwebUrl}/studies/${url}` : url;
53+
console.log("Import from", useUrl);
54+
retrieveJson(url, options).then(json => {
55+
console.log("Retrieved:", JSON.stringify(json,null,2));
56+
});
57+
};

packages/static-wado-creator/lib/writer/HashDataWriter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const HashDataWriter =
2020
(options) =>
2121
async (id, key, data, additionalOptions = {}) => {
2222
const isRaw = ArrayBuffer.isView(data);
23+
const { singlepartBulkdata } = options;
2324
const { mimeType } = additionalOptions;
2425
// If the file has an extension, it should be directly accessible as that file type.
2526
const gzip = !isRaw || (data.length > 1024 && !mimeType);
@@ -30,7 +31,7 @@ const HashDataWriter =
3031
mkdir: true,
3132
gzip,
3233
});
33-
if (isRaw) {
34+
if (isRaw && !singlepartBulkdata) {
3435
await WriteMultipart(writeStream, [new MultipartHeader("Content-Type", "application/octet-stream")], rawData);
3536
} else {
3637
await writeStream.write(rawData);

packages/static-wado-deploy/lib/clientMain.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import uploadDeploy from "./uploadDeploy.mjs";
33

44
export default async function (options) {
55
if (options.retrieve) throw new Error("Retrieve unsupported for client files");
6-
await commonMain(this, "client", options, uploadDeploy.bind(null, undefined));
6+
await commonMain(this, "client", options, uploadDeploy.bind(null, ""));
77
}

0 commit comments

Comments
 (0)