-
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 API of query for series in a study
- Add `/dicom-web/studies/{studyUID}/series` QIDO-RS # API Docs - API Docs add tags - API Docs add `/dicom-web/studies/{studyUID}/series` of QIDO-RS
- Loading branch information
1 parent
c80d5d0
commit a2eb251
Showing
5 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
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
113 changes: 113 additions & 0 deletions
113
api/dicom-web/controller/QIDO-RS/queryStudies-Series.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,113 @@ | ||
const _ = require('lodash'); | ||
const mongoose = require('mongoose'); | ||
const moment = require('moment'); | ||
const { | ||
convertAllQueryToDICOMTag, | ||
convertRequestQueryToMongoQuery, | ||
getStudyLevelFields, | ||
getSeriesLevelFields | ||
} = require('./service/QIDO-RS.service'); | ||
const { | ||
logger | ||
} = require('../../../../utils/log'); | ||
|
||
/** | ||
* @openapi | ||
* /dicom-web/studies/{studyUID}/series: | ||
* get: | ||
* tags: | ||
* - QIDO-RS | ||
* description: Query for studies | ||
* parameters: | ||
* - $ref: "#/components/parameters/studyUID" | ||
* - $ref: "#/components/parameters/StudyDate" | ||
* - $ref: "#/components/parameters/StudyTime" | ||
* - $ref: "#/components/parameters/AccessionNumber" | ||
* - $ref: "#/components/parameters/ModalitiesInStudy" | ||
* - $ref: "#/components/parameters/ReferringPhysicianName" | ||
* - $ref: "#/components/parameters/PatientName" | ||
* - $ref: "#/components/parameters/PatientID" | ||
* - $ref: "#/components/parameters/StudyID" | ||
* - $ref: "#/components/parameters/Modality" | ||
* - $ref: "#/components/parameters/SeriesNumber" | ||
* responses: | ||
* 200: | ||
* description: Query successfully | ||
*/ | ||
|
||
/** | ||
* | ||
* @param {import('http').IncomingMessage} req | ||
* @param {import('http').ServerResponse} res | ||
*/ | ||
module.exports = async function (req, res) { | ||
try { | ||
let limit = req.query.limit || 100; | ||
let skip = req.query.offset || 0; | ||
delete req.query["limit"]; | ||
delete req.query["offset"]; | ||
let query = _.cloneDeep(req.query); | ||
let queryKeys = Object.keys(query).sort(); | ||
for (let i = 0; i < queryKeys.length; i++) { | ||
let queryKey = queryKeys[i]; | ||
if (!query[queryKey]) delete query[queryKey]; | ||
} | ||
|
||
let dicomTagQuery = convertAllQueryToDICOMTag(query); | ||
let studiesJson = await getStudyDicomJson(dicomTagQuery, limit, skip, req); | ||
res.writeHead(200, { | ||
"Content-Type": "application/dicom+json" | ||
}); | ||
res.end(JSON.stringify(studiesJson.data)); | ||
} catch (e) { | ||
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); | ||
logger.error(`[QIDO-RS] [Error: ${errorStr}]`); | ||
} | ||
} | ||
|
||
async function getStudyDicomJson(iQuery, limit, skip, req) { | ||
logger.info(`[QIDO-RS] [Query series Level, Study UID: ${req.params.studyUID}]`); | ||
let result = { | ||
data: '', | ||
status: false | ||
}; | ||
let protocol = req.secure ? "https" : "http"; | ||
let retrieveUrl = `${protocol}://${req.headers.host}/${process.env.DICOMWEB_API}/studies`; | ||
try { | ||
iQuery = await convertRequestQueryToMongoQuery(iQuery); | ||
let query = { | ||
...req.params, | ||
...iQuery.$match | ||
} | ||
logger.info(`[QIDO-RS] [Query for MongoDB: ${JSON.stringify(query)}]`); | ||
let studyFields = getStudyLevelFields(); | ||
let seriesFields = getSeriesLevelFields(); | ||
let docs = await mongoose.model("dicomSeries") | ||
.find(query, { | ||
...studyFields, | ||
...seriesFields | ||
}) | ||
.limit(limit) | ||
.skip(skip) | ||
.exec(); | ||
result.data = docs.map(v => { | ||
let obj = v.toObject(); | ||
delete obj._id; | ||
delete obj.id; | ||
obj["00801190"] = { | ||
vr: "UR", | ||
Value: [ | ||
`${retrieveUrl}/${obj["0020000D"]["Value"][0]}/series/${obj["0020000E"]["Value"][0]}` | ||
] | ||
}; | ||
return obj; | ||
}); | ||
result.status = true; | ||
return result; | ||
} catch (e) { | ||
console.error("get Series DICOM error", e); | ||
result.data = e; | ||
result.status = false; | ||
return result; | ||
} | ||
} |
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,18 @@ | ||
components: | ||
parameters: | ||
"studyUID": | ||
name: "studyUID" | ||
in: path | ||
required: true | ||
schema: | ||
type: string | ||
"Modality": | ||
name: "00080060" | ||
in: query | ||
schema: | ||
type: string | ||
"SeriesNumber": | ||
name: "00200011" | ||
in: query | ||
schema: | ||
type: string |