-
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 instance's metadata
- Chore, Add typedef for get{Level}ImagesPath - Fix, missing series UID in not found message of retrieve series's metadata
- Loading branch information
1 parent
77aec48
commit b0f9b09
Showing
5 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
api/dicom-web/controller/WADO-RS/retrieveInstanceMetadata.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,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(); | ||
} | ||
}; |
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
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
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
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,9 @@ | ||
/** | ||
* @typedef { Object } ImagePathObj | ||
* @property { string } studyUID | ||
* @property { string } seriesUID | ||
* @property { string } instanceUID | ||
* @property { string } instancePath | ||
*/ | ||
|
||
module.exports.unUse = {}; |