diff --git a/api-sql/dicom-web/controller/QIDO-RS/allPatient.js b/api-sql/dicom-web/controller/QIDO-RS/allPatient.js deleted file mode 100644 index b2034f3e..00000000 --- a/api-sql/dicom-web/controller/QIDO-RS/allPatient.js +++ /dev/null @@ -1,46 +0,0 @@ -const { - SqlQidoRsService: QidoRsService -} = require("./service/QIDO-RS.service"); -const { ApiLogger } = require("@root/utils/logs/api-logger"); -const { Controller } = require("@root/api/controller.class"); - -class QueryAllPatientsController extends Controller { - constructor(req, res) { - super(req, res); - } - - async mainProcess() { - let apiLogger = new ApiLogger(this.request, "QIDO-RS"); - - apiLogger.addTokenValue(); - apiLogger.logger.info("Query all patients"); - - try { - let qidoRsService = new QidoRsService(this.request, this.response, "patient"); - - await qidoRsService.getAndResponseDicomJson(); - } catch (e) { - let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); - apiLogger.logger.error(errorStr); - - this.response.writeHead(500, { - "Content-Type": "application/dicom+json" - }); - this.response.end(JSON.stringify({ - code: 500, - message: "Server error occurred" - })); - } - } -} - -/** - * - * @param {import('express').Request} req - * @param {import('express').Response} res - */ -module.exports = async function (req, res) { - let controller = new QueryAllPatientsController(req, res); - - await controller.doPipeline(); -}; diff --git a/api-sql/dicom-web/controller/QIDO-RS/queryAllInstances.js b/api-sql/dicom-web/controller/QIDO-RS/queryAllInstances.js deleted file mode 100644 index cedf9169..00000000 --- a/api-sql/dicom-web/controller/QIDO-RS/queryAllInstances.js +++ /dev/null @@ -1,46 +0,0 @@ -const { - SqlQidoRsService: QidoRsService -} = require("./service/QIDO-RS.service"); -const { ApiLogger } = require("@root/utils/logs/api-logger"); -const { Controller } = require("@root/api/controller.class"); - -class QueryAllInstancesController extends Controller { - constructor(req, res) { - super(req, res); - } - - async mainProcess() { - let apiLogger = new ApiLogger(this.request, "QIDO-RS"); - - apiLogger.addTokenValue(); - apiLogger.logger.info("Query all instances"); - - try { - let qidoRsService = new QidoRsService(this.request, this.response, "instance"); - - await qidoRsService.getAndResponseDicomJson(); - } catch (e) { - let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); - apiLogger.logger.error(errorStr); - - this.response.writeHead(500, { - "Content-Type": "application/dicom+json" - }); - this.response.end(JSON.stringify({ - code: 500, - message: "Server error occurred" - })); - } - } -} - -/** - * - * @param {import('express').Request} req - * @param {import('express').Response} res - */ -module.exports = async function (req, res) { - let controller = new QueryAllInstancesController(req, res); - - await controller.doPipeline(); -}; diff --git a/api-sql/dicom-web/controller/QIDO-RS/queryAllSeries.js b/api-sql/dicom-web/controller/QIDO-RS/queryAllSeries.js deleted file mode 100644 index dcb9b3c9..00000000 --- a/api-sql/dicom-web/controller/QIDO-RS/queryAllSeries.js +++ /dev/null @@ -1,47 +0,0 @@ -const { - SqlQidoRsService: QidoRsService -} = require("./service/QIDO-RS.service"); -const { ApiLogger } = require("@root/utils/logs/api-logger"); -const { Controller } = require("@root/api/controller.class"); - -class QueryAllSeriesController extends Controller { - constructor(req, res) { - super(req, res); - } - - async mainProcess() { - let apiLogger = new ApiLogger(this.request, "QIDO-RS"); - - apiLogger.addTokenValue(); - apiLogger.logger.info("Query all series"); - - try { - - let qidoRsService = new QidoRsService(this.request, this.response, "series"); - - await qidoRsService.getAndResponseDicomJson(); - - } catch (e) { - let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); - apiLogger.logger.error(errorStr); - - this.response.writeHead(500, { - "Content-Type": "application/dicom+json" - }); - this.response.end(JSON.stringify({ - code: 500, - message: "Server error occurred" - })); - } - } -} -/** - * - * @param {import('express').Request} req - * @param {import('express').Response} res - */ -module.exports = async function (req, res) { - let controller = new QueryAllSeriesController(req, res); - - await controller.doPipeline(); -}; diff --git a/api-sql/dicom-web/controller/QIDO-RS/queryAllStudies.js b/api-sql/dicom-web/controller/QIDO-RS/queryAllStudies.js deleted file mode 100644 index ca2096ab..00000000 --- a/api-sql/dicom-web/controller/QIDO-RS/queryAllStudies.js +++ /dev/null @@ -1,49 +0,0 @@ -const { - SqlQidoRsService: QidoRsService -} = require("./service/QIDO-RS.service"); -const { ApiLogger } = require("@root/utils/logs/api-logger"); -const { Controller } = require("@root/api/controller.class"); - -class QueryAllStudiesController extends Controller { - constructor(req, res) { - super(req, res); - } - - async mainProcess() { - let apiLogger = new ApiLogger(this.request, "QIDO-RS"); - - apiLogger.addTokenValue(); - apiLogger.logger.info(`Query All Studies`); - - try { - - let qidoRsService = new QidoRsService(this.request, this.response, "study"); - - await qidoRsService.getAndResponseDicomJson(); - - } catch (e) { - let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); - apiLogger.logger.error(errorStr); - - this.response.writeHead(500, { - "Content-Type": "application/dicom+json" - }); - this.response.end(JSON.stringify({ - code: 500, - message: "Server error occurred" - })); - } - } -} - -/** - * - * @param {import('express').Request} req - * @param {import('express').Response} res - */ -module.exports = async function (req, res) { - let controller = new QueryAllStudiesController(req, res); - - await controller.doPipeline(); -}; - diff --git a/api-sql/dicom-web/controller/QIDO-RS/queryStudies-Instances.js b/api-sql/dicom-web/controller/QIDO-RS/queryStudies-Instances.js deleted file mode 100644 index 682913a4..00000000 --- a/api-sql/dicom-web/controller/QIDO-RS/queryStudies-Instances.js +++ /dev/null @@ -1,47 +0,0 @@ -const { - SqlQidoRsService: QidoRsService -} = require("./service/QIDO-RS.service"); -const { ApiLogger } = require("@root/utils/logs/api-logger"); -const { Controller } = require("@root/api/controller.class"); - -class QueryInstancesOfStudiesController extends Controller { - constructor(req, res) { - super(req, res); - } - - async mainProcess() { - let apiLogger = new ApiLogger(this.request, "QIDO-RS"); - - apiLogger.addTokenValue(); - apiLogger.logger.info(`Query instances in study, Study UID: ${this.request.params.studyUID}`); - - try { - - let qidoRsService = new QidoRsService(this.request, this.response, "instance"); - - await qidoRsService.getAndResponseDicomJson(); - } catch (e) { - let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); - apiLogger.logger.error(errorStr); - - this.response.writeHead(500, { - "Content-Type": "application/dicom+json" - }); - this.response.end(JSON.stringify({ - code: 500, - message: "Server error occurred" - })); - } - } -} - -/** - * - * @param {import('express').Request} req - * @param {import('express').Response} res - */ -module.exports = async function (req, res) { - let controller = new QueryInstancesOfStudiesController(req, res); - - await controller.doPipeline(); -}; \ No newline at end of file diff --git a/api-sql/dicom-web/controller/QIDO-RS/queryStudies-Series-Instance.js b/api-sql/dicom-web/controller/QIDO-RS/queryStudies-Series-Instance.js deleted file mode 100644 index 005a986d..00000000 --- a/api-sql/dicom-web/controller/QIDO-RS/queryStudies-Series-Instance.js +++ /dev/null @@ -1,49 +0,0 @@ -const _ = require("lodash"); -const { - SqlQidoRsService: QidoRsService -} = require("./service/QIDO-RS.service"); -const { ApiLogger } = require("@root/utils/logs/api-logger"); -const { Controller } = require("@root/api/controller.class"); - -class QueryInstancesOfSeriesOfStudiesController extends Controller { - constructor(req, res) { - super(req, res); - } - - async mainProcess() { - let apiLogger = new ApiLogger(this.request, "QIDO-RS"); - - apiLogger.addTokenValue(); - apiLogger.logger.info(`Query instance Level, Study UID: ${this.request.params.studyUID}, Series UID: ${this.request.params.seriesUID}`); - - try { - - let qidoRsService = new QidoRsService(this.request, this.response, "instance"); - - await qidoRsService.getAndResponseDicomJson(); - - } catch (e) { - let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); - apiLogger.logger.error(errorStr); - - this.response.writeHead(500, { - "Content-Type": "application/dicom+json" - }); - this.response.end(JSON.stringify({ - code: 500, - message: "Server error occurred" - })); - } - } -} - -/** - * - * @param {import('express').Request} req - * @param {import('express').Response} res - */ -module.exports = async function (req, res) { - let controller = new QueryInstancesOfSeriesOfStudiesController(req, res); - - await controller.doPipeline(); -}; diff --git a/api-sql/dicom-web/controller/QIDO-RS/queryStudies-Series.js b/api-sql/dicom-web/controller/QIDO-RS/queryStudies-Series.js deleted file mode 100644 index 0d6e8215..00000000 --- a/api-sql/dicom-web/controller/QIDO-RS/queryStudies-Series.js +++ /dev/null @@ -1,47 +0,0 @@ -const { - SqlQidoRsService: QidoRsService -} = require("./service/QIDO-RS.service"); -const { ApiLogger } = require("@root/utils/logs/api-logger"); -const { Controller } = require("@root/api/controller.class"); - -class QuerySeriesOfStudiesController extends Controller { - constructor(req, res) { - super(req, res); - } - - async mainProcess() { - let apiLogger = new ApiLogger(this.request, "QIDO-RS"); - - apiLogger.addTokenValue(); - apiLogger.logger.info(`Query series Level, Study UID: ${this.request.params.studyUID}`); - - try { - - let qidoRsService = new QidoRsService(this.request, this.response, "series"); - - await qidoRsService.getAndResponseDicomJson(); - - } catch (e) { - let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); - apiLogger.logger.error(errorStr); - - this.response.writeHead(500, { - "Content-Type": "application/dicom+json" - }); - this.response.end(JSON.stringify({ - code: 500, - message: "Server error occurred" - })); - } - } -} -/** - * - * @param {import('express').Request} req - * @param {import('express').Response} res - */ -module.exports = async function (req, res) { - let controller = new QuerySeriesOfStudiesController(req, res); - - await controller.doPipeline(); -}; diff --git a/api-sql/dicom-web/controller/QIDO-RS/service/QIDO-RS.service.js b/api-sql/dicom-web/controller/QIDO-RS/service/QIDO-RS.service.js index 0dfb8dfb..7f594750 100644 --- a/api-sql/dicom-web/controller/QIDO-RS/service/QIDO-RS.service.js +++ b/api-sql/dicom-web/controller/QIDO-RS/service/QIDO-RS.service.js @@ -1,143 +1,16 @@ const _ = require("lodash"); -const { QidoRsService } = require("@root/api/dicom-web/controller/QIDO-RS/service/QIDO-RS.service"); -const { DicomWebService } = require("@root/api/dicom-web/service/dicom-web.service"); -const { StudyQueryBuilder } = require("./querybuilder"); -const { dictionary } = require("@models/DICOM/dicom-tags-dic"); -const { - DicomWebServiceError, - DicomWebStatusCodes -} = require("@error/dicom-web-service"); -const { StudyModel } = require("@models/sql/models/study.model"); -const { SeriesModel } = require("@models/sql/models/series.model"); -const { InstanceModel } = require("@models/sql/models/instance.model"); -const { PatientModel } = require("@models/sql/models/patient.model"); - - -class SqlQidoRsService extends QidoRsService { - /** - * - * @param {import('express').Request} req - * @param {import('express').Response} res - * @param {"study" | "series" | "instance"} level - */ - constructor(req, res, level = "instance") { - super(req, res, level); +const { QidoRsService, convertAllQueryToDICOMTag } = require("@root/api/dicom-web/controller/QIDO-RS/service/QIDO-RS.service"); + +QidoRsService.prototype.initQuery_ = function () { + let query = _.cloneDeep(this.request.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]; } - async getAndResponseDicomJson() { - try { - - let dicomWebService = new DicomWebService(this.request, this.response); - - let queryOptions = { - query: this.query, - skip: this.skip_, - limit: this.limit_, - includeFields: this.includeFields_, - retrieveBaseUrl: `${dicomWebService.getBasicURL()}/studies`, - requestParams: this.request.params - }; - - let qidoDicomJsonFactory = new QidoDicomJsonFactory(queryOptions, this.level); - - let dicomJson = await qidoDicomJsonFactory.getDicomJson(); - - let dicomJsonLength = _.get(dicomJson, "length", 0); - if (dicomJsonLength > 0) { - this.response.writeHead(200, { - "Content-Type": "application/dicom+json" - }); - this.response.end(JSON.stringify(dicomJson)); - } else { - this.response.writeHead(204); - this.response.end(); - } - - } catch (e) { - throw e; - } - } - - /** - * @private - */ - initQuery_() { - let query = _.cloneDeep(this.request.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]; - } - - this.query = convertAllQueryToDicomTag(query); - } -} - -class QidoDicomJsonFactory { - - /** - * - * @param {import("../../../../../utils/typeDef/dicom").DicomJsonMongoQueryOptions} queryOptions - * @param {string} level - */ - constructor(queryOptions, level = "instance") { - this.level = level; - - this.getDicomJsonByLevel = { - "patient": async () => { - return await PatientModel.getDicomJson(queryOptions); - }, - "study": async () => { - return await StudyModel.getDicomJson(queryOptions); - }, - "series": async () => { - return await SeriesModel.getDicomJson(queryOptions); - }, - "instance": async () => { - return await InstanceModel.getDicomJson(queryOptions); - } - }; - } - - async getDicomJson() { - return await this.getDicomJsonByLevel[this.level](); - } -} - - -/** - * Convert All of name(tags, keyword) of queries to tags number - * @param {Object} iParam The request query. - * @returns - */ -function convertAllQueryToDicomTag(iParam) { - let keys = Object.keys(iParam); - let newQS = {}; - for (let i = 0; i < keys.length; i++) { - let keyName = keys[i]; - let keyNameSplit = keyName.split("."); - let newKeyNames = []; - for (let x = 0; x < keyNameSplit.length; x++) { - if (dictionary.keyword[keyNameSplit[x]]) { - newKeyNames.push(dictionary.keyword[keyNameSplit[x]]); - } else if (dictionary.tag[keyNameSplit[x]]) { - newKeyNames.push(keyNameSplit[x]); - } - } - if (newKeyNames.length === 0) { - throw new DicomWebServiceError( - DicomWebStatusCodes.InvalidArgumentValue, - `Invalid request query: ${keyNameSplit}`, - 400 - ); - } - - let retKeyName = newKeyNames.join("."); - newQS[retKeyName] = iParam[keyName]; - } - return newQS; -} + this.query = convertAllQueryToDICOMTag(query, false); +}; -module.exports.SqlQidoRsService = SqlQidoRsService; -module.exports.convertAllQueryToDicomTag = convertAllQueryToDicomTag; \ No newline at end of file +module.exports.QidoRsService = QidoRsService; \ No newline at end of file diff --git a/api-sql/dicom-web/controller/QIDO-RS/service/query-dicom-json-factory.js b/api-sql/dicom-web/controller/QIDO-RS/service/query-dicom-json-factory.js new file mode 100644 index 00000000..7921b927 --- /dev/null +++ b/api-sql/dicom-web/controller/QIDO-RS/service/query-dicom-json-factory.js @@ -0,0 +1,17 @@ +const { + QueryDicomJsonFactory, + QueryPatientDicomJsonFactory, + QueryStudyDicomJsonFactory, + QuerySeriesDicomJsonFactory, + QueryInstanceDicomJsonFactory +} = require("@root/api/dicom-web/controller/QIDO-RS/service/query-dicom-json-factory"); + +QueryDicomJsonFactory.prototype.getDicomJson = async function () { + return await this.model.getDicomJson(this.queryOptions); +}; + +module.exports.QueryDicomJsonFactory = QueryDicomJsonFactory; +module.exports.QueryPatientDicomJsonFactory = QueryPatientDicomJsonFactory; +module.exports.QueryStudyDicomJsonFactory = QueryStudyDicomJsonFactory; +module.exports.QuerySeriesDicomJsonFactory = QuerySeriesDicomJsonFactory; +module.exports.QueryInstanceDicomJsonFactory = QueryInstanceDicomJsonFactory; \ No newline at end of file diff --git a/api/dicom-web/controller/QIDO-RS/base.controller.js b/api/dicom-web/controller/QIDO-RS/base.controller.js index d94d85e1..ce69d448 100644 --- a/api/dicom-web/controller/QIDO-RS/base.controller.js +++ b/api/dicom-web/controller/QIDO-RS/base.controller.js @@ -1,6 +1,6 @@ const { Controller } = require("@root/api/controller.class"); const { ApiLogger } = require("@root/utils/logs/api-logger"); -const { QidoRsService } = require("./service/QIDO-RS.service"); +const { QidoRsService } = require("@qido-rs-service"); const { ApiErrorArrayHandler } = require("@error/api-errors.handler"); class BaseQueryController extends Controller { diff --git a/api/dicom-web/controller/QIDO-RS/service/QIDO-RS.service.js b/api/dicom-web/controller/QIDO-RS/service/QIDO-RS.service.js index 38f02d49..56d4acda 100644 --- a/api/dicom-web/controller/QIDO-RS/service/QIDO-RS.service.js +++ b/api/dicom-web/controller/QIDO-RS/service/QIDO-RS.service.js @@ -139,7 +139,7 @@ class QidoRsService { * @param {Object} iParam The request query. * @returns */ -function convertAllQueryToDICOMTag(iParam) { +function convertAllQueryToDICOMTag(iParam, pushSuffixValue=true) { let keys = Object.keys(iParam); let newQS = {}; for (let i = 0; i < keys.length; i++) { @@ -160,10 +160,16 @@ function convertAllQueryToDICOMTag(iParam) { `Invalid request query: ${keyNameSplit}`, 400 ); - } else if (newKeyNames.length >= 2) { - retKeyName = newKeyNames.map(v => v + ".Value").join("."); + } + + if (pushSuffixValue) { + if (newKeyNames.length >= 2) { + retKeyName = newKeyNames.map(v => v + ".Value").join("."); + } else { + newKeyNames.push("Value"); + retKeyName = newKeyNames.join("."); + } } else { - newKeyNames.push("Value"); retKeyName = newKeyNames.join("."); } diff --git a/api/dicom-web/controller/QIDO-RS/service/query-dicom-json-factory.js b/api/dicom-web/controller/QIDO-RS/service/query-dicom-json-factory.js index b123280c..3a020c86 100644 --- a/api/dicom-web/controller/QIDO-RS/service/query-dicom-json-factory.js +++ b/api/dicom-web/controller/QIDO-RS/service/query-dicom-json-factory.js @@ -204,6 +204,7 @@ class QueryInstanceDicomJsonFactory extends QueryDicomJsonFactory { } } +module.exports.QueryDicomJsonFactory = QueryDicomJsonFactory; module.exports.QueryPatientDicomJsonFactory = QueryPatientDicomJsonFactory; module.exports.QueryStudyDicomJsonFactory = QueryStudyDicomJsonFactory; module.exports.QuerySeriesDicomJsonFactory = QuerySeriesDicomJsonFactory; diff --git a/dimse-sql/queryBuilder.js b/dimse-sql/queryBuilder.js index 806f7178..65a4160e 100644 --- a/dimse-sql/queryBuilder.js +++ b/dimse-sql/queryBuilder.js @@ -1,7 +1,6 @@ const _ = require("lodash"); -const { convertRequestQueryToMongoQuery } = require("@root/api/dicom-web/controller/QIDO-RS/service/QIDO-RS.service"); -const { convertAllQueryToDicomTag } = require("@root/api-sql/dicom-web/controller/QIDO-RS/service/QIDO-RS.service"); +const { convertAllQueryToDicomTag } = require("@root/api/dicom-web/controller/QIDO-RS/service/QIDO-RS.service"); const { DimseQueryBuilder } = require("@root/dimse/queryBuilder"); diff --git a/routes.js b/routes.js index 437d2d00..ce52abc6 100644 --- a/routes.js +++ b/routes.js @@ -20,7 +20,7 @@ module.exports = function (app) { loadAllPlugin(); app.use("/dicom-web", require("./api/dicom-web/stow-rs.route")); - app.use("/dicom-web", require("./api-sql/dicom-web/qido-rs.route")); + app.use("/dicom-web", require("./api/dicom-web/qido-rs.route")); app.use("/dicom-web", require("./api-sql/dicom-web/wado-rs-instance.route")); app.use("/dicom-web", require("./api-sql/dicom-web/wado-rs-metadata.route")); app.use("/dicom-web", require("./api-sql/dicom-web/wado-rs-rendered.route"));