Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat: Add a DICOMweb proxy capability to the webserver #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -4,6 +4,7 @@ const createMain = require("./createMain");
const createPart10 = require("./createPart10");
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 @@ -83,6 +84,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 @@ -234,6 +239,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 @@ -33,6 +33,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 @@ -43,7 +44,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