-
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: add retrieve series's instances metadata
- Add retrieve study's series's instances metadata
- Loading branch information
1 parent
5a01d9d
commit 77aec48
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
api/dicom-web/controller/WADO-RS/retrieveSeriesMetadata.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,50 @@ | ||
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' Instances Metadata] [series UID: ${req.params.seriesUID}, study UID: ${req.params.studyUID}]`); | ||
try { | ||
let responseMetadata = []; | ||
let imagesPathList = await wadoService.getSeriesImagesPath(req.params); | ||
if (imagesPathList) { | ||
for (let imagePathObj of imagesPathList) { | ||
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 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(); | ||
} | ||
}; |
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