Skip to content

Commit

Permalink
feat(mongodb): implement MWL delete API
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Dec 10, 2023
1 parent 3e022d1 commit 4c2c0bf
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 0 deletions.
38 changes: 38 additions & 0 deletions api/dicom-web/controller/MWL-RS/delete-mwlItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { ApiErrorArrayHandler } = require("@error/api-errors.handler");
const { Controller } = require("@root/api/controller.class");
const { ApiLogger } = require("@root/utils/logs/api-logger");
const { DeleteMwlItemService } = require("./service/delete-mwlItem.service");

class DeleteMwlItemCountController extends Controller {
constructor(req, res) {
super(req, res);
this.apiLogger = new ApiLogger(this.request, "MWL-RS");
}

async mainProcess() {
try {
let deleteMwlItemService = new DeleteMwlItemService(this.request, this.response);
await deleteMwlItemService.deleteMwlItem();

return this.response
.set("Content-Type", "application/dicom+json")
.status(200)
.send();

} catch (e) {
let apiErrorArrayHandler = new ApiErrorArrayHandler(this.response, this.apiLogger, e);
return apiErrorArrayHandler.doErrorResponse();
}
}
}

/**
*
* @param {import('express').Request} req
* @param {import('express').Response} res
*/
module.exports = async function (req, res) {
let controller = new DeleteMwlItemCountController(req, res);

await controller.doPipeline();
};
22 changes: 22 additions & 0 deletions api/dicom-web/controller/MWL-RS/service/delete-mwlItem.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { DicomWebServiceError, DicomWebStatusCodes } = require("@error/dicom-web-service");
const { MwlItemModel } = require("@models/mongodb/models/mwlitems.model");

class DeleteMwlItemService {
constructor(req, res) {
/** @type { import("express").Request } */
this.request = req;
/** @type { import("express").Response } */
this.response = res;
}

async deleteMwlItem() {
const { studyUID, spsID } = this.request.params;
let { deletedCount } = await MwlItemModel.deleteByStudyInstanceUIDAndSpsID(studyUID, spsID);

if (!deletedCount) {
throw new DicomWebServiceError(DicomWebStatusCodes.NoSuchSOPInstance, "Modality Worklist Item not found.", 404);
}
}
}

module.exports.DeleteMwlItemService = DeleteMwlItemService;
23 changes: 23 additions & 0 deletions api/dicom-web/mwl-rs.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,27 @@ router.get("/mwlitems",require("./controller/MWL-RS/get-mwlItem"));
*/
router.get("/mwlitems/count",require("./controller/MWL-RS/count-mwlItem"));

/**
* @openapi
* /dicom-web/mwlitems/{studyUID}/{spsID}:
* delete:
* tags:
* - MWL-RS
* description: >
* This transaction deletes a Modality WorkList item.
* requestBody:
* content:
* application/dicom+json:
* parameters:
* - $ref: "#/components/parameters/studyUID"
* - $ref: "#/components/parameters/spsID"
* responses:
* "204":
* description: Delete successfully
*/
router.delete("/mwlitems/:studyUID/:spsID", validateParams({
studyUID: Joi.string().required(),
spsID: Joi.string().required()
}, "params", undefined), require("./controller/MWL-RS/delete-mwlItem"));

module.exports = router;
1 change: 1 addition & 0 deletions docs/swagger/parameters/dicomweb-common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ components:
parameters:
"filter":
description: "{attributeID}={value}; {attributeID} = {dicomTag} | {dicomKeyword} | {dicomTag}.{attributeID} | {dicomKeyword}.{attributeID}"
in: query
schema:
type: array
items:
Expand Down
8 changes: 8 additions & 0 deletions docs/swagger/parameters/mwl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
components:
parameters:
spsID:
in: path
name: spsID
required: true
schema:
type: string
1 change: 1 addition & 0 deletions error/dicom-web-service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const DicomWebStatusCodes = {
"InvalidAttributeValue": "0106",
"DuplicateSOPinstance": "0111",
"NoSuchSOPInstance": "0112",
"InvalidArgumentValue": "0115",
"MissingAttribute": "0120",
"ProcessingFailure": "0272",
Expand Down
13 changes: 13 additions & 0 deletions models/mongodb/models/mwlitems.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const _ = require("lodash");
const { tagsNeedStore } = require("../../DICOM/dicom-tags-mapping");
const { getVRSchema } = require("../schema/dicomJsonAttribute");
const { IncludeFieldsFactory } = require("../service");
const { dictionary } = require("@models/DICOM/dicom-tags-dic");

let mwlItemSchema = new mongoose.Schema(
{},
Expand Down Expand Up @@ -50,6 +51,18 @@ let mwlItemSchema = new mongoose.Schema(
},
getCount: async function (query) {
return await mongoose.model("mwlItems").countDocuments(query);
},
deleteByStudyInstanceUIDAndSpsID: async function(studyUID, spsID) {
return await mongoose.model("mwlItems").deleteMany({
$and: [
{
[`${dictionary.keyword.StudyInstanceUID}.Value.0`]: studyUID
},
{
[`${dictionary.keyword.ScheduledProcedureStepSequence}.Value.0.${dictionary.keyword.ScheduledProcedureStepID}.Value.0`]: spsID
}
]
});
}
},
methods: {
Expand Down

0 comments on commit 4c2c0bf

Please sign in to comment.