Skip to content

Commit

Permalink
feat(mongodb): implement change status of mwl item
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Dec 16, 2023
1 parent 4c2c0bf commit 302b2bd
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
39 changes: 39 additions & 0 deletions api/dicom-web/controller/MWL-RS/change-mwlItem-status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const { ApiErrorArrayHandler } = require("@error/api-errors.handler");
const { Controller } = require("@root/api/controller.class");
const { ApiLogger } = require("@root/utils/logs/api-logger");
const { GetMwlItemCountService } = require("./service/count-mwlItem.service");
const { ChangeMwlItemStatusService } = require("./service/change-mwlItem-status");

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

async mainProcess() {
try {
let changeMwlItemService = new ChangeMwlItemStatusService(this.request, this.response);
let changedMwlItems = await changeMwlItemService.changeMwlItemsStatus();

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

} 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 ChangeMwlItemStatusCountController(req, res);

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

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

async changeMwlItemsStatus() {
let { status } = this.request.params;
let mwlItem = await this.getMwlItemByStudyUIDAndSpsID();
if (!mwlItem) {
throw new DicomWebServiceError(DicomWebStatusCodes.NoSuchObjectInstance, "No such object instance", 404);
}

_.set(mwlItem, `${dictionary.keyword.ScheduledProcedureStepSequence}.Value.0.${dictionary.keyword.ScheduledProcedureStepStatus}.Value.0`, status);
await mwlItem.save();

return mwlItem.toDicomJson();
}

async getMwlItemByStudyUIDAndSpsID() {
return await MwlItemModel.findOne({
$and: [
{
"00400100.Value.0.00400009.Value.0": this.request.params.spsID
},
{
"0020000D.Value.0": this.request.params.studyUID
}
]
});
}
}

module.exports.ChangeMwlItemStatusService = ChangeMwlItemStatusService;
30 changes: 30 additions & 0 deletions api/dicom-web/mwl-rs.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,34 @@ router.delete("/mwlitems/:studyUID/:spsID", validateParams({
spsID: Joi.string().required()
}, "params", undefined), require("./controller/MWL-RS/delete-mwlItem"));


/**
* @openapi
* /dicom-web/mwlitems/{studyUID}/{spsID}/status/{spsStatus}:
* post:
* tags:
* - MWL-RS
* description: >
* This transaction create or update a Modality WorkList item.
* requestBody:
* content:
* application/dicom+json:
* parameters:
* - $ref: "#/components/parameters/studyUID"
* - $ref: "#/components/parameters/spsID"
* - $ref: "#/components/parameters/spsStatus"
* responses:
* "200":
* description: change status of mwl item successfully
*/
router.post("/mwlitems/:studyUID/:spsID/status/:status",
validateByJoi(
Joi.object({
studyUID: Joi.string().required(),
spsID: Joi.string().required(),
status: Joi.string().valid("SCHEDULED", "ARRIVED", "READY", "STARTED", "DEPARTED", "CANCELED", "DISCONTINUED", "COMPLETED").required()
}), "params", {allowUnknown: false}),
require("./controller/MWL-RS/change-mwlItem-status")
);

module.exports = router;
15 changes: 15 additions & 0 deletions docs/swagger/parameters/mwl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,20 @@ components:
in: path
name: spsID
required: true
schema:
type: string
spsStatus:
in: path
name: spsStatus
required: true
enum:
- SCHEDULED
- ARRIVED
- READY
- STARTED
- DEPARTED
- CANCELED
- DISCONTINUED
- COMPLETED
schema:
type: string

0 comments on commit 302b2bd

Please sign in to comment.