Skip to content

Commit

Permalink
feat: WADO-RS Retrieve Instance Resources APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Aug 11, 2023
1 parent 21750b6 commit eb26522
Show file tree
Hide file tree
Showing 10 changed files with 753 additions and 1 deletion.
84 changes: 84 additions & 0 deletions api-sql/dicom-web/controller/WADO-RS/retrieveInstance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const wadoService = require("./service/WADO-RS.service");
const { WADOZip } = require("./service/WADOZip");
const { ApiLogger } = require("@root/utils/logs/api-logger");
const { Controller } = require("@root/api/controller.class");
class RetrieveInstanceOfSeriesOfStudiesController extends Controller {
constructor(req, res) {
super(req, res);
}

async mainProcess() {
let apiLogger = new ApiLogger(this.request, "WADO-RS");
apiLogger.addTokenValue();

apiLogger.logger.info(`Get study's series' instances, study UID: ${this.request.params.studyUID}, series UID: ${this.request.params.seriesUID}`);
apiLogger.logger.info(`Request Accept: ${this.request.headers.accept}`);

try {

if (this.request.headers.accept.toLowerCase() === "application/zip") {
return await this.responseZip();
} else if (this.request.headers.accept.includes("multipart/related")) {
return await this.responseMultipartRelated();
} else if (this.request.headers.accept.includes("*")){
this.request.headers.accept = "multipart/related; type=\"application/dicom\"";
return await this.responseMultipartRelated();
}

return wadoService.sendNotSupportedMediaType(this.response, this.request.headers.accept);
} catch(e) {
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e));
apiLogger.logger.error(errorStr);

this.response.writeHead(500, {
"Content-Type": "application/dicom+json"
});
this.response.end(JSON.stringify({
code: 500,
message: "Server error occurred"
}));
}
}

async responseZip() {
let wadoZip = new WADOZip(this.request.params, this.response);
let zipResult = await wadoZip.getZipOfInstanceDICOMFile();
if (zipResult.status) {
return this.response.end();
} else {
this.response.writeHead(zipResult.code, {
"Content-Type": "application/dicom+json"
});
return this.response.end(JSON.stringify(zipResult));
}
}

async responseMultipartRelated() {
let type = wadoService.getAcceptType(this.request);
let isSupported = wadoService.supportInstanceMultipartType.indexOf(type) > -1;
if (!isSupported) {
return wadoService.sendNotSupportedMediaType(this.response, type);
}

let imageMultipartWriter = new wadoService.ImageMultipartWriter(
this.request,
this.response,
wadoService.InstanceImagePathFactory,
wadoService.multipartContentTypeWriter[type]
);

return await imageMultipartWriter.write();
}
}


/**
*
* @param {import("http").IncomingMessage} req
* @param {import("http").ServerResponse} res
*/
module.exports = async function(req, res) {
let controller = new RetrieveInstanceOfSeriesOfStudiesController(req, res);

await controller.doPipeline();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const { logger } = require("@root/utils/logs/log");
const wadoService = require("./service/WADO-RS.service");
const { WADOZip } = require("./service/WADOZip");
const errorResponse = require("@root/utils/errorResponse/errorResponseMessage");
const { Controller } = require("@root/api/controller.class");

class RetrieveInstancesOfSeries extends Controller {
constructor(req, res) {
super(req, res);
}

async mainProcess() {
try {
logger.info(`[WADO-RS] [Get study's series' instances, study UID: ${this.request.params.studyUID}, series UID: ${this.request.params.seriesUID}] [Request Accept: ${this.request.headers.accept}]`);

if (this.request.headers.accept.toLowerCase() === "application/zip") {
return await this.responseZip();
} else if (this.request.headers.accept.includes("multipart/related")) {
return await this.responseMultipartRelated();
} else if (this.request.headers.accept.includes("*")){
this.request.headers.accept = "multipart/related; type=\"application/dicom\"";
return await this.responseMultipartRelated();
}

return wadoService.sendNotSupportedMediaType(this.response, this.request.headers.accept);
} catch (e) {
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e));
logger.error(`[WADO-RS] [Error: ${errorStr}]`);

this.response.writeHead(500, {
"Content-Type": "application/dicom+json"
});
this.response.end(JSON.stringify({
code: 500,
message: "Server error occurred"
}));
}
}

async responseZip() {
let wadoZip = new WADOZip(this.request.params, this.response);
let zipResult = await wadoZip.getZipOfSeriesDICOMFiles();
if (zipResult.status) {
return this.response.end();
} else {
this.response.writeHead(zipResult.code, {
"Content-Type": "application/dicom+json"
});
return this.response.end(JSON.stringify(zipResult));
}
}

async responseMultipartRelated() {
let type = wadoService.getAcceptType(this.request);
let isSupported = wadoService.supportInstanceMultipartType.indexOf(type) > -1;
if (!isSupported) {
return wadoService.sendNotSupportedMediaType(this.response, type);
}

let imageMultipartWriter = new wadoService.ImageMultipartWriter(
this.request,
this.response,
wadoService.SeriesImagePathFactory,
wadoService.multipartContentTypeWriter[type]
);

return await imageMultipartWriter.write();
}
}

/**
*
* @param {import("http").IncomingMessage} req
* @param {import("http").ServerResponse} res
*/
module.exports = async function (req, res) {
let controller = new RetrieveInstancesOfSeries(req, res);

await controller.doPipeline();
};
80 changes: 80 additions & 0 deletions api-sql/dicom-web/controller/WADO-RS/retrieveStudyInstances.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const { logger } = require("@root/utils/logs/log");
const wadoService = require("./service/WADO-RS.service");
const { WADOZip } = require("./service/WADOZip");
const errorResponse = require("@root/utils/errorResponse/errorResponseMessage");
const { Controller } = require("@root/api/controller.class");

class RetrieveStudyInstancesController extends Controller {
constructor(req, res) {
super(req, res);
}

async mainProcess() {
try {
logger.info(`[WADO-RS] [Get study's instances, study UID: ${this.request.params.studyUID}] [Request Accept: ${this.request.headers.accept}]`);

if (this.request.headers.accept.toLowerCase() === "application/zip") {
return await this.responseZip();
} else if (this.request.headers.accept.includes("multipart/related")) {
return await this.responseMultipartRelated();
} else if (this.request.headers.accept.includes("*")) {
this.request.headers.accept = "multipart/related; type=\"application/dicom\"";
return await this.responseMultipartRelated();
}

return wadoService.sendNotSupportedMediaType(this.response, this.request.headers.accept);
} catch (e) {
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e));
logger.error(`[WADO-RS] [Error: ${errorStr}]`);

this.response.writeHead(500, {
"Content-Type": "application/dicom+json"
});
this.response.end(JSON.stringify({
code: 500,
message: "Server error occurred"
}));
}
}

async responseZip() {
let wadoZip = new WADOZip(this.request.params, this.response);
let zipResult = await wadoZip.getZipOfStudyDICOMFiles();
if (zipResult.status) {
return this.response.end();
} else {
this.response.writeHead(zipResult.code, {
"Content-Type": "application/dicom+json"
});
return this.response.end(JSON.stringify(zipResult));
}
}

async responseMultipartRelated() {
let type = wadoService.getAcceptType(this.request);
let isSupported = wadoService.supportInstanceMultipartType.indexOf(type) > -1;
if (!isSupported) {
return wadoService.sendNotSupportedMediaType(this.response, type);
}

let imageMultipartWriter = new wadoService.ImageMultipartWriter(
this.request,
this.response,
wadoService.StudyImagePathFactory,
wadoService.multipartContentTypeWriter[type]
);

return await imageMultipartWriter.write();
}
}

/**
*
* @param {import("http").IncomingMessage} req
* @param {import("http").ServerResponse} res
*/
module.exports = async function (req, res) {
let controller = new RetrieveStudyInstancesController(req, res);

await controller.doPipeline();
};
Loading

0 comments on commit eb26522

Please sign in to comment.