Skip to content

Commit

Permalink
Add a DICOMweb proxy capability to the webserver
Browse files Browse the repository at this point in the history
  • Loading branch information
wayfarer3130 committed May 23, 2023
1 parent e1bca71 commit 31bedf8
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/static-wado-creator/lib/mkdicomwebConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { staticWadoConfig } = require("@radicalimaging/static-wado-util");
const createMain = require("./createMain");
const deleteMain = require("./deleteMain");
const rejectMain = require("./rejectMain");
const queryMain = require("./queryMain");
const instanceMain = require("./instanceMain");
const indexMain = require("./indexMain");
const groupMain = require("./groupMain");
Expand Down Expand Up @@ -58,6 +59,10 @@ const { mkdicomwebConfig } = ConfigPoint.register({
key: "-e, --no-encapsulated-image",
description: "Avoid encapsulating the image frame. Writes with the extension and without multipart",
},
{
key: "--singlepart-bulkdata",
description: "Store bulkdata as single part data",
},
{
key: "--single-part-image",
description: "Writes single part image data",
Expand Down Expand Up @@ -184,6 +189,11 @@ const { mkdicomwebConfig } = ConfigPoint.register({
main: rejectMain,
helpDescription: "Reject the specified series",
},
{
command: "query <url>",
main: queryMain,
helpDescription: "Performs DICOMweb query operations to update local deduplicated/metadata",
},
],
},
});
Expand Down
23 changes: 23 additions & 0 deletions packages/static-wado-creator/lib/query/retrieveJson.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const https = require("https");

/** Retrieve the given url fromm the back end, returning a JSON representation of the data */
module.exports = function retrieve(url, options) {
console.log("Requesting to retrieve", url);
const parsedUrl = new URL(url);
const req = https.request(parsedUrl, (res) => {
console.log(`STATUS: ${res.statusCode}`);
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log(`BODY: ${chunk}`);
});
res.on('end', () => {
console.log('No more data in response.');
});
});
req.on('error', (e) => {
console.error(`problem with request: ${e.message}`);
});

req.end();
}
57 changes: 57 additions & 0 deletions packages/static-wado-creator/lib/queryMain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const StaticWado = require("./StaticWado");
const adaptProgramOpts = require("./util/adaptProgramOpts");
const retrieveJson = require("./query/retrieveJson");

/**
* Queries the given URL instance.
* Options:
* * metadata
* Appends /series to the URL and tries to retrieve
* Stores the data in the `series` key
* Iterates over all series in the list and checks if the series is up to date
* For each series not up to date:
* * `series/<seriesInstanceUID>/metadata` stored to a key of the same name
* * Iterates over all instances in above and adds to `StudyData`
* Writes updated study data files (recreated from new deduplciated data)
* * cache - will cache all queried files
* * stream - will print the response directly to the standard output.
* * deduplicated
* Reads the /deduplicated path first
* If no object, and the `metadata` option is set, then runs that path
* If the object is found, then writes the deduplicated data to the deduplicated path
* Runs the regular metadata create path
*
* Retrieving individual instances for proxying cached data.
* Data can be read from disk once this is complete.
* `mkdicomweb query 1.2.3/series --cache`
* `mkdicomweb query 1.2.3/series/2.3.4/metadata --cache`
*
* Retrieving a study query for direct proxy:
* Data can be streamed directly from the command line.
* `mkdicomweb query 1.2.3?ModalitiesInStudy=CR --stream`
*
* Creates or Updates Deduplicated Metadata:
* This command should be used before receiving data against remote proxies NOT supporting deduplicated
* `mkdicomweb query 1.2.3 --metadata`
*
* Creates or Updates Deduplicated Metadata from Deduplicated Remote
* This command should be used before receiving data against remote proxies supporting deduplicated
* `mkdicomweb query 1.2.3 --deduplicated`
*
* @param {*} url to fetch
* @param {*} options
* @param {*} program
*/
module.exports = function queryMain(url, options) {
const finalOptions = adaptProgramOpts(options, {
...this,
isGroup: true,
isStudyData: true,
});
const importer = new StaticWado(finalOptions);
const useUrl = url.indexOf('http')===-1 ? `${this.dicomwebUrl}/studies/${url}` : url;
console.log("Import from", useUrl);
retrieveJson(url, options).then(json => {
console.log("Retrieved:", JSON.stringify(json,null,2));
});
};
3 changes: 2 additions & 1 deletion packages/static-wado-creator/lib/writer/HashDataWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const HashDataWriter =
(options) =>
async (id, key, data, additionalOptions = {}) => {
const isRaw = ArrayBuffer.isView(data);
const { singlepartBulkdata } = options;
const { mimeType } = additionalOptions;
// If the file has an extension, it should be directly accessible as that file type.
const gzip = !isRaw || (data.length > 1024 && !mimeType);
Expand All @@ -30,7 +31,7 @@ const HashDataWriter =
mkdir: true,
gzip,
});
if (isRaw) {
if (isRaw && !singlepartBulkdata) {
await WriteMultipart(writeStream, [new MultipartHeader("Content-Type", "application/octet-stream")], rawData);
} else {
await writeStream.write(rawData);
Expand Down
2 changes: 1 addition & 1 deletion packages/static-wado-deploy/lib/clientMain.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import uploadDeploy from "./uploadDeploy.mjs";

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

0 comments on commit 31bedf8

Please sign in to comment.