Skip to content

Commit

Permalink
feat: add Rendered Instance
Browse files Browse the repository at this point in the history
- Remove useless comment
  • Loading branch information
Chinlinlee committed Nov 21, 2022
1 parent 629e221 commit 0f40a33
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
44 changes: 44 additions & 0 deletions api/dicom-web/controller/WADO-RS/retrieveRenderedInstances.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const _ = require("lodash");
const wadoService = require("./service/WADO-RS.service");
const renderedService = require("./service/rendered.service");
const { MultipartWriter } = require("../../../../utils/multipartWriter");
const errorResponse = require("../../../../utils/errorResponse/errorResponseMessage");
const { logger, apiInfoLog } = require("../../../../utils/log");

/**
*
* @param {import("http").IncomingMessage} req
* @param {import("http").ServerResponse} res
* @returns
*/
module.exports = async function(req, res) {
let headerAccept = _.get(req.headers, "accept", "");
apiInfoLog("WADO-RS", req.originalUrl, `[Get study's series' rendered instances, study UID: ${req.params.studyUID}, series UID: ${req.params.seriesUID}]`);
if (!headerAccept == `multipart/related; type="image/jpeg"`) {
let badRequestMessage = errorResponse.getBadRequestErrorMessage(`header accept only allow \`multipart/related; type="image/jpeg"\`, exception : ${headerAccept}`);
res.writeHead(badRequestMessage.HttpStatus, {
"Content-Type": "application/dicom+json"
});
return res.end(JSON.stringify(badRequestMessage));
}

try {
let imagePathObj = await wadoService.getInstanceImagePath(req.params);

if (imagePathObj) {
let multipartWriter = new MultipartWriter([], res, req);
let instanceFramesObj = await renderedService.getInstanceFrameObj(imagePathObj);
let dicomNumberOfFrames = _.get(instanceFramesObj, "00280008.Value.0", 1);
dicomNumberOfFrames = parseInt(dicomNumberOfFrames);
await renderedService.writeRenderedImages(req, dicomNumberOfFrames, instanceFramesObj, multipartWriter);
multipartWriter.writeFinalBoundary();
}
apiInfoLog("WADO-RS", req.originalUrl, `[Write Multipart Successfully, study's series' instances' rendered images, study UID: ${req.params.studyUID}, series UID: ${req.params.seriesUID}, instance UID: ${req.params.instanceUID}]`);
return res.end();
} catch(e) {
res.writeHead(500, {
"Content-Type": "application/dicom+json"
});
res.end(JSON.stringify(e));
}
};
8 changes: 6 additions & 2 deletions api/dicom-web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,16 @@ app.get(
require("./controller/WADO-RS/retrieveRenderedSeries")
);


app.get(
"/studies/:studyUID/series/:seriesUID/instances/:instanceUID/rendered",
validateParams(renderedQueryValidation, "query", { allowUnknown: false }),
require("./controller/WADO-RS/retrieveRenderedInstances")
);

app.get(
"/studies/:studyUID/series/:seriesUID/instances/:instanceUID/frames/:frameNumber/rendered",
validateParams({
frameNumber : intArrayJoi.intArray().items(Joi.number().integer().min(1)).single()//Joi.number().integer().min(1)
frameNumber : intArrayJoi.intArray().items(Joi.number().integer().min(1)).single()
} , "params" , {allowUnknown : true}),
validateParams(renderedQueryValidation, "query", { allowUnknown: false }),
require("./controller/WADO-RS/retrieveRenderedInstanceFrames")
Expand Down

0 comments on commit 0f40a33

Please sign in to comment.