-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: WADO-RS Retrieve Instance Resources APIs
- Loading branch information
1 parent
21750b6
commit eb26522
Showing
10 changed files
with
753 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; |
80 changes: 80 additions & 0 deletions
80
api-sql/dicom-web/controller/WADO-RS/retrieveStudy-Series-Instances.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
80
api-sql/dicom-web/controller/WADO-RS/retrieveStudyInstances.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; |
Oops, something went wrong.