Skip to content

Commit

Permalink
feat: add retrieve instance's metadata
Browse files Browse the repository at this point in the history
- Chore, Add typedef for get{Level}ImagesPath
- Fix, missing series UID  in not found message of
retrieve series's metadata
  • Loading branch information
Chinlinlee committed May 15, 2022
1 parent 77aec48 commit b0f9b09
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
48 changes: 48 additions & 0 deletions api/dicom-web/controller/WADO-RS/retrieveInstanceMetadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const mongoose = require("mongoose");
const _ = require("lodash");
const fs = require("fs");
const path = require("path");
const fileExist = require("../../../../utils/file/fileExist");
const wadoService = require("./service/WADO-RS.service");
const errorResponse = require("../../../../utils/errorResponse/errorResponseMessage");
const { logger } = require("../../../../utils/log");

/**
*
* @param {import("http").IncomingMessage} req
* @param {import("http").ServerResponse} res
*/
module.exports = async function(req, res) {
logger.info(`[WADO-RS] [Get Study's Series' Instance Metadata] [instance UID: ${req.params.instanceUID}, series UID: ${req.params.seriesUID}, study UID: ${req.params.studyUID}]`);
try {
let responseMetadata = [];
let imagePathObj = await wadoService.getInstanceImagePath(req.params);
if (imagePathObj) {
let instanceDir = path.dirname(imagePathObj.instancePath);
let metadataPath = path.join(instanceDir, `${imagePathObj.instanceUID}.metadata.json`);
if (await fileExist(metadataPath)) {
let metadataJsonStr = fs.readFileSync(metadataPath, { encoding: "utf-8" });
let metadataJson = JSON.parse(metadataJsonStr);
wadoService.addHostnameOfBulkDataUrl(metadataJson, req);
responseMetadata.push(metadataJson);
}
res.writeHead(200, {
"Content-Type": "application/dicom+json"
});
return res.end(JSON.stringify(responseMetadata));
}
res.writeHead(404);
return res.end(JSON.stringify(
errorResponse.getNotFoundErrorMessage(
`Not found metadata of instance UID: ${req.params.instanceUID}, series UID: ${req.params.seriesUID}, study UID: ${req.params.studyUID}`
)
));
} catch(e) {
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e));
console.error(errorStr);
res.writeHead(500, {
"Content-Type": "application/dicom+json"
});
return res.end();
}
};
2 changes: 1 addition & 1 deletion api/dicom-web/controller/WADO-RS/retrieveSeriesMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = async function(req, res) {
res.writeHead(404);
return res.end(JSON.stringify(
errorResponse.getNotFoundErrorMessage(
`Not found metadata of study UID: ${req.params.studyUID}`
`Not found metadata of series UID:${req.params.seriesUID} study UID: ${req.params.studyUID}`
)
));
} catch(e) {
Expand Down
4 changes: 4 additions & 0 deletions api/dicom-web/controller/WADO-RS/service/WADO-RS.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const flatten = require("flat");
/**
*
* @param {import("http").IncomingMessage} req
* @return { string }
*/
function getAcceptType(req) {
return req.headers.accept
Expand All @@ -19,6 +20,7 @@ function getAcceptType(req) {
/**
* Get path list of all study's instances with specific study UID
* @param {Object} iParam
* @return { Promise<import("../../../../../utils/typeDef/WADO-RS/WADO-RS.def").ImagePathObj[]> | undefined }
*/
async function getStudyImagesPath(iParam) {
let { studyUID } = iParam;
Expand Down Expand Up @@ -63,6 +65,7 @@ async function getStudyImagesPath(iParam) {
/**
* Get path list of all study's series' instances with specific study UID
* @param {Object} iParam
* @return { Promise<import("../../../../../utils/typeDef/WADO-RS/WADO-RS.def").ImagePathObj[]> | undefined }
* @returns
*/
async function getSeriesImagesPath(iParam) {
Expand Down Expand Up @@ -115,6 +118,7 @@ async function getSeriesImagesPath(iParam) {
/**
* Get path
* @param {Object} iParam
* @return { Promise<import("../../../../../utils/typeDef/WADO-RS/WADO-RS.def").ImagePathObj> | undefined }
*/
async function getInstanceImagePath(iParam) {
let { studyUID, seriesUID, instanceUID } = iParam;
Expand Down
4 changes: 4 additions & 0 deletions api/dicom-web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ app.get(
"/studies/:studyUID/series/:seriesUID/metadata",
require("./controller/WADO-RS/retrieveSeriesMetadata")
);
app.get(
"/studies/:studyUID/series/:seriesUID/instances/:instanceUID/metadata",
require("./controller/WADO-RS/retrieveInstanceMetadata")
);

//#endregion

Expand Down
9 changes: 9 additions & 0 deletions utils/typeDef/WADO-RS/WADO-RS.def.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @typedef { Object } ImagePathObj
* @property { string } studyUID
* @property { string } seriesUID
* @property { string } instanceUID
* @property { string } instancePath
*/

module.exports.unUse = {};

0 comments on commit b0f9b09

Please sign in to comment.