-
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.
- Loading branch information
1 parent
7952464
commit 1d2c07a
Showing
7 changed files
with
237 additions
and
3 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
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,64 @@ | ||
/** | ||
* @description | ||
* https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.12 | ||
* This transaction is used to stop the origin server from automatically subscribing the User-Agent to new Workitems. This does not delete any existing subscriptions to specific Workitems. | ||
*/ | ||
|
||
const { | ||
CancelWorkItemService | ||
} = require("./service/cancel.service"); | ||
const { ApiLogger } = require("../../../../utils/logs/api-logger"); | ||
const { Controller } = require("../../../controller.class"); | ||
const { DicomWebServiceError } = require("@error/dicom-web-service"); | ||
|
||
class CancelWorkItemController extends Controller { | ||
constructor(req, res) { | ||
super(req, res); | ||
} | ||
|
||
async mainProcess() { | ||
let apiLogger = new ApiLogger(this.request, "UPS-RS"); | ||
|
||
apiLogger.addTokenValue(); | ||
apiLogger.logger.info(`Cancel Work Item, params: ${this.paramsToString()}`); | ||
|
||
try { | ||
let service = new CancelWorkItemService(this.request, this.response); | ||
await service.cancel(); | ||
|
||
return this.response | ||
.set("Content-Type", "application/dicom+json") | ||
.status(202) | ||
.end(); | ||
} catch (e) { | ||
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); | ||
apiLogger.logger.error(errorStr); | ||
|
||
if (e instanceof DicomWebServiceError) { | ||
return this.response.status(e.code).json({ | ||
status: e.status, | ||
message: e.message | ||
}); | ||
} | ||
|
||
this.response.writeHead(500, { | ||
"Content-Type": "application/dicom+json" | ||
}); | ||
this.response.end(JSON.stringify({ | ||
code: 500, | ||
message: "An Server Exception Occurred" | ||
})); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param {import('express').Request} req | ||
* @param {import('express').Response} res | ||
*/ | ||
module.exports = async function (req, res) { | ||
let controller = new CancelWorkItemController(req, res); | ||
|
||
await controller.doPipeline(); | ||
}; |
108 changes: 108 additions & 0 deletions
108
api/dicom-web/controller/UPS-RS/service/cancel.service.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,108 @@ | ||
const _ = require("lodash"); | ||
const workItemModel = require("@models/mongodb/models/workItems"); | ||
const { DicomJsonModel, BaseDicomJson } = require("@models/DICOM/dicom-json-model"); | ||
const globalSubscriptionModel = require("@models/mongodb/models/upsGlobalSubscription"); | ||
const { | ||
DicomWebServiceError, | ||
DicomWebStatusCodes | ||
} = require("@error/dicom-web-service"); | ||
const { BaseWorkItemService } = require("./base-workItem.service"); | ||
const { dictionary } = require("@models/DICOM/dicom-tags-dic"); | ||
const { UPS_EVENT_TYPE } = require("./workItem-event"); | ||
const { raccoonConfig } = require("@root/config-class"); | ||
|
||
class CancelWorkItemService extends BaseWorkItemService { | ||
|
||
/** | ||
* | ||
* @param {import("express").Request} req | ||
* @param {import("express").Response} res | ||
*/ | ||
constructor(req, res) { | ||
super(req, res); | ||
this.upsInstanceUID = this.request.params.workItem; | ||
this.workItem = null; | ||
this.requestWorkItem = /** @type {Object[]} */(this.request.body).pop(); | ||
} | ||
|
||
async cancel() { | ||
|
||
this.workItem = await this.findOneWorkItem(this.upsInstanceUID); | ||
let procedureStepState = this.workItem.getString(dictionary.keyword.ProcedureStepState); | ||
|
||
if (procedureStepState === "IN PROGRESS") { | ||
//Only send cancel info event now, IMO | ||
//User need to watch for cancel event and use change state API to cancel | ||
await this.addCancelEvent(); | ||
await this.triggerUpsEvents(); | ||
return; | ||
} else if (procedureStepState === "CANCELED") { | ||
this.response.set("Warning", "299 <service>: The UPS is already in the requested state of CANCELED."); | ||
return this.response.status(200).json({ | ||
status: DicomWebStatusCodes.UPSAlreadyInRequestedStateOfCanceled, | ||
message: "UPS Already In Requested State Of Canceled" | ||
}); | ||
} else if (procedureStepState === "COMPLETED") { | ||
throw new DicomWebServiceError( | ||
DicomWebStatusCodes.UPSAlreadyCompleted, | ||
"The request is inconsistent with the current state of the Target Workitem. The Target Workitem is in the COMPLETED state.", | ||
409 | ||
); | ||
} else if (procedureStepState === "SCHEDULED") { | ||
throw new DicomWebServiceError( | ||
DicomWebStatusCodes.UPSNotYetInProgress, | ||
"The request is inconsistent with the current state of the Target Workitem. The Target Workitem is in the SCHEDULED state.", | ||
409 | ||
); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* | ||
* @param {string} upsInstanceUID | ||
* @returns | ||
*/ | ||
async findOneWorkItem(upsInstanceUID) { | ||
|
||
let workItem = await workItemModel.findOne({ | ||
upsInstanceUID: upsInstanceUID | ||
}); | ||
|
||
if (!workItem) { | ||
throw new DicomWebServiceError( | ||
DicomWebStatusCodes.UPSDoesNotExist, | ||
"The UPS instance not exist", | ||
404 | ||
); | ||
} | ||
|
||
return new DicomJsonModel(workItem); | ||
|
||
} | ||
|
||
async addCancelEvent() { | ||
let hitSubscriptions = await this.getHitSubscriptions(this.workItem); | ||
let aeTitles = hitSubscriptions.map(v => v.aeTitle); | ||
|
||
this.addUpsEvent(UPS_EVENT_TYPE.CancelRequested, this.upsInstanceUID, this.cancelRequestBy(), aeTitles); | ||
} | ||
|
||
cancelRequestBy() { | ||
let eventInfo = new BaseDicomJson( | ||
this.requestWorkItem, | ||
dictionary.keyword.ReasonForCancellation, | ||
dictionary.keyword.ProcedureStepDiscontinuationReasonCodeSequence, | ||
dictionary.keyword.ContactURI, | ||
dictionary.keyword.ContactDisplayName | ||
); | ||
|
||
eventInfo.setValue(dictionary.keyword.RequestingAE, raccoonConfig.dicomWebConfig.aeTitle); | ||
|
||
return eventInfo.dicomJson; | ||
} | ||
|
||
} | ||
|
||
|
||
module.exports.CancelWorkItemService = CancelWorkItemService; |
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
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