From ebefd6acef226c522f91f5c56b68052cf159377d Mon Sep 17 00:00:00 2001 From: chinlinlee Date: Sun, 19 Nov 2023 13:09:24 +0800 Subject: [PATCH] refactor: Use module alias for WADO-URI service --- .../WADO-URI/controller/retrieveInstance.js | 55 ------------------- api-sql/WADO-URI/index.js | 45 --------------- api/WADO-URI/controller/retrieveInstance.js | 2 +- config/jsconfig.sql.json | 1 + config/modula-alias/sql/package.json | 4 +- routes.js | 2 +- 6 files changed, 6 insertions(+), 103 deletions(-) delete mode 100644 api-sql/WADO-URI/controller/retrieveInstance.js delete mode 100644 api-sql/WADO-URI/index.js diff --git a/api-sql/WADO-URI/controller/retrieveInstance.js b/api-sql/WADO-URI/controller/retrieveInstance.js deleted file mode 100644 index 5224425d..00000000 --- a/api-sql/WADO-URI/controller/retrieveInstance.js +++ /dev/null @@ -1,55 +0,0 @@ -const { WadoUriService, NotFoundInstanceError } = require("../service/WADO-URI.service"); -const { Controller } = require("@root/api/controller.class"); -const { ApiLogger } = require("@root/utils/logs/api-logger"); - -class RetrieveSingleInstanceController extends Controller { - constructor(req, res) { - super(req, res); - this.logger = new ApiLogger(this.request, "WADO-URI"); - this.service = new WadoUriService(req, res, this.logger); - } - - async mainProcess() { - let { - contentType - } = this.request.query; - - if (!contentType) contentType = this.request.headers.accept; - - try { - - if (contentType === "application/dicom") { - this.service.getAndResponseDicomInstance(); - } else if (contentType === "image/jpeg") { - this.service.getAndResponseJpeg(); - } else if (!contentType) { - this.service.getAndResponseDicomInstance(); - } - - } catch(e) { - let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); - this.logger.error(errorStr); - - this.response.writeHead(500, { - "Content-Type": "application/dicom+json" - }); - this.response.end(JSON.stringify({ - code: 500, - message: errorStr - })); - } - - } - -} - -/** - * - * @param {import("http").IncomingMessage} req - * @param {import("http").ServerResponse} res - */ -module.exports = async function(req, res) { - let controller = new RetrieveSingleInstanceController(req, res); - - await controller.doPipeline(); -}; \ No newline at end of file diff --git a/api-sql/WADO-URI/index.js b/api-sql/WADO-URI/index.js deleted file mode 100644 index 11330b89..00000000 --- a/api-sql/WADO-URI/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Route - * Implement https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_9.4 - * WADO-URI - * @author Chin-Lin Lee - */ - -const { wadoUriValidationSchema } = require("@root/api/WADO-URI/middleware/validation-schema"); -const { defaultContentType } = require("@root/api/WADO-URI/middleware/default-contentType"); -const { validateByJoi} = require("@root/api/validator"); -const express = require("express"); -const router = express.Router(); - -/** - * @openapi - * /wado: - * get: - * tags: - * - WADO-URI - * description: Retrieve instance's metadata - * parameters: - * - $ref: "#/components/parameters/requestType" - * - $ref: "#/components/parameters/queryStudyUID" - * - $ref: "#/components/parameters/querySeriesUID" - * - $ref: "#/components/parameters/queryInstanceUID" - * - $ref: "#/components/parameters/contentType" - * - $ref: "#/components/parameters/frameNumber" - * - $ref: "#/components/parameters/imageQuality" - * - $ref: "#/components/parameters/region" - * - $ref: "#/components/parameters/rows" - * - $ref: "#/components/parameters/columns" - * - $ref: "#/components/parameters/windowCenter" - * - $ref: "#/components/parameters/windowWidth" - * - $ref: "#/components/parameters/iccprofile" - * responses: - * 200: - * $ref: "#/components/responses/WadoUriData" - * - */ -router.get("/", defaultContentType, validateByJoi(wadoUriValidationSchema, "query", { - allowUnknown: false -}), require("./controller/retrieveInstance")); - - -module.exports = router; \ No newline at end of file diff --git a/api/WADO-URI/controller/retrieveInstance.js b/api/WADO-URI/controller/retrieveInstance.js index efb12700..4af01fba 100644 --- a/api/WADO-URI/controller/retrieveInstance.js +++ b/api/WADO-URI/controller/retrieveInstance.js @@ -1,4 +1,4 @@ -const { WadoUriService, NotFoundInstanceError } = require("../service/WADO-URI.service"); +const { WadoUriService, NotFoundInstanceError } = require("@wado-uri-service"); const { Controller } = require("../../controller.class"); const { ApiLogger } = require("../../../utils/logs/api-logger"); const { ApiErrorArrayHandler } = require("@error/api-errors.handler"); diff --git a/config/jsconfig.sql.json b/config/jsconfig.sql.json index a8d0a396..e5a230d8 100644 --- a/config/jsconfig.sql.json +++ b/config/jsconfig.sql.json @@ -14,6 +14,7 @@ "@stow-rs-service": ["./api/dicom-web/controller/STOW-RS/service/stow-rs.service.js"], "@qido-rs-service": ["./api-sql/dicom-web/controller/QIDO-RS/service/QIDO-RS.service.js"], "@wado-rs-service": ["./api-sql/dicom-web/controller/WADO-RS/service/WADO-RS.service.js"], + "@wado-uri-service": ["./api-sql/WADO-URI/service/WADO-URI.service.js"], "@bulkdata-service": ["./api-sql/dicom-web/controller/WADO-RS/bulkdata/service/bulkdata.js"], "@delete-service": ["./api-sql/dicom-web/controller/WADO-RS/deletion/service/delete.js"], "@rendered-service": ["./api-sql/dicom-web/controller/WADO-RS/service/rendered.service.js"], diff --git a/config/modula-alias/sql/package.json b/config/modula-alias/sql/package.json index 52a9b3cb..7aa0693e 100644 --- a/config/modula-alias/sql/package.json +++ b/config/modula-alias/sql/package.json @@ -13,6 +13,7 @@ "@stow-rs-service": "../../../api/dicom-web/controller/STOW-RS/service/stow-rs.service.js", "@qido-rs-service": "../../../api-sql/dicom-web/controller/QIDO-RS/service/QIDO-RS.service.js", "@wado-rs-service": "../../../api-sql/dicom-web/controller/WADO-RS/service/WADO-RS.service.js", + "@wado-uri-service": "../../../api-sql/WADO-URI/service/WADO-URI.service.js", "@bulkdata-service": "../../../api-sql/dicom-web/controller/WADO-RS/bulkdata/service/bulkdata.js", "@delete-service": "../../../api-sql/dicom-web/controller/WADO-RS/deletion/service/delete.js", "@rendered-service": "../../../api-sql/dicom-web/controller/WADO-RS/service/rendered.service.js", @@ -22,6 +23,7 @@ "@dimse-study-query-task": "../../../dimse-sql/studyQueryTask.js", "@dimse-series-query-task": "../../../dimse-sql/seriesQueryTask.js", "@dimse-instance-query-task": "../../../dimse-sql/instanceQueryTask.js", - "@dimse-utils": "../../../dimse-sql/utils.js" + "@dimse-utils": "../../../dimse-sql/utils.js", + "@dimse": "../../../dimse-sql" } } \ No newline at end of file diff --git a/routes.js b/routes.js index 926f1329..ee4626ba 100644 --- a/routes.js +++ b/routes.js @@ -29,5 +29,5 @@ module.exports = function (app) { app.use("/dicom-web", require("./api/dicom-web/delete.route")); // app.use("/dicom-web", require("./api/dicom-web/ups-rs.route")); - app.use("/wado", require("./api-sql/WADO-URI")); + app.use("/wado", require("./api/WADO-URI")); };