Skip to content

Commit

Permalink
feat: store STOW result in variable for next usage
Browse files Browse the repository at this point in the history
- Use `res.locals` to store result in variable
- Add `next()` for plugin `after` use case
- Store `storeInstanceResult` in `storeInstanceResultList`
  • Loading branch information
Chinlinlee committed Nov 25, 2022
1 parent 035bb7e commit df6646d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"es6": true
},
"extends": ["eslint:recommended"],
"globals": {
"_": true
},
"rules": {
"semi": ["error", "always"],
"comma-dangle": ["error", "never"],
Expand Down
11 changes: 9 additions & 2 deletions api/dicom-web/stow/controller/postSTOW.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ function updateFailureMessage(stowMessage, sopSeq, iStoreInstanceResult) {
vr: "US",
Value: [iStoreInstanceResult.statusCode]
}
}
};

Object.assign(sopSeq, failureMessage);
stowMessage["00081198"].Value.push(sopSeq);
}

module.exports = async (req, res) => {
module.exports = async (req, res, next) => {
//store the successFiles;
let successFiles = [];
let successFHIR = [];
Expand Down Expand Up @@ -115,6 +116,8 @@ module.exports = async (req, res) => {
} else {
let fileField = Object.keys(files).pop();
let uploadedFiles = files[fileField];
let storeInstanceResultList = [];

if (!_.isArray(uploadedFiles)) uploadedFiles = [uploadedFiles];
try {
for (let i = 0; i < uploadedFiles.length; i++) {
Expand Down Expand Up @@ -175,6 +178,7 @@ module.exports = async (req, res) => {
let baseFileName = path.basename(uploadedFiles[i].name);
successFHIR.push(baseFileName);
successFiles.push(baseFileName);
storeInstanceResultList.push(storeInstanceResult);

}
}
Expand All @@ -190,11 +194,14 @@ module.exports = async (req, res) => {
logger.info(
`[STOW-RS] [Finished STOW-RS, elapsed time: ${elapsedTime} ms]`
);
res.locals.storeInstanceResultList = storeInstanceResultList;
next();
return res.status(retCode).send(resMessage);
} catch (err) {
let errMsg = err.message || err;
console.error('/dicom-web/studies "STOW Api" err, ', errMsg);
console.log(successFiles);
next();
return res.status(500).send(errMsg);
}
}
Expand Down
25 changes: 16 additions & 9 deletions api/dicom-web/stow/service/stow.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ function detachBigValuesDicomJson(dicomJson) {
* @param {Object} dicomJson
*/
function getStoreDest(dicomJson) {
let started_date = "";
started_date =
let startedDate = "";
startedDate =
dcm2jsonV8.dcmString(dicomJson, "00080020") +
dcm2jsonV8.dcmString(dicomJson, "00080030");
if (!started_date) started_date = Date.now();
started_date = moment(started_date, "YYYYMMDDhhmmss").toISOString();
let started_date_split = started_date.split("-");
let year = started_date_split[0];
let month = started_date_split[1];
if (!startedDate) startedDate = Date.now();
startedDate = moment(startedDate, "YYYYMMDDhhmmss").toISOString();
let startedDateSplit = startedDate.split("-");
let year = startedDateSplit[0];
let month = startedDateSplit[1];
let uid = dcm2jsonV8.dcmString(dicomJson, "0020000E");
let shortUID = sh.unique(uid);
let relativeStorePath = `files/${year}/${month}/${shortUID}/`;
Expand Down Expand Up @@ -528,6 +528,7 @@ async function stow(req, filename, originalFilename) {
}

let uidObj = getUidObj(dicomJson);
let storedFilesPath = [];
try {
let dicomJsonAndBigTags = detachBigValuesDicomJson(dicomJson);
let retrieveUrlObj = getRetrieveUrlObj(req, uidObj);
Expand Down Expand Up @@ -557,7 +558,7 @@ async function stow(req, filename, originalFilename) {

let { relativeStorePath, fullStorePath, metadataFullStorePath } =
getStoreDest(dicomJsonAndBigTags.dicomJson);
mkdirp.sync(fullStorePath, 0755);
mkdirp.sync(fullStorePath, 0x755);
storeMetadataToDisk(dicomJsonAndBigTags, metadataFullStorePath);


Expand All @@ -578,6 +579,11 @@ async function stow(req, filename, originalFilename) {
httpStatusCode: 500
};
}
storedFilesPath.push({
relativeStorePath,
fullStorePath,
metadataFullStorePath
});

// Pre-Process for generating Jpeg of DICOM first
// Many useful for WSI
Expand Down Expand Up @@ -684,7 +690,8 @@ async function stow(req, filename, originalFilename) {
message: `Store DICOM instance successful`,
uidObj: uidObj,
retrieveUrlObj: retrieveUrlObj,
httpStatusCode: 200
httpStatusCode: 200,
storedFilesPath
};
} catch (e) {
console.error(e);
Expand Down

0 comments on commit df6646d

Please sign in to comment.