-
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.
feat: suspend subscription and add API docs
# open api docs - Subscribe Transaction - Unsubscribe Transaction - Suspend Global Subscription Transaction # New API - Suspend Global Subscription Transaction
- Loading branch information
1 parent
28e35f4
commit 7952464
Showing
6 changed files
with
262 additions
and
13 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
api/dicom-web/controller/UPS-RS/service/suspend-subscription.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,54 @@ | ||
const _ = require("lodash"); | ||
const globalSubscriptionModel = require("@models/mongodb/models/upsGlobalSubscription"); | ||
const { | ||
DicomWebServiceError, | ||
DicomWebStatusCodes | ||
} = require("@error/dicom-web-service"); | ||
const { BaseWorkItemService } = require("./base-workItem.service"); | ||
|
||
class SuspendSubscribeService 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.subscriberAeTitle = this.request.params.subscriberAeTitle; | ||
} | ||
|
||
async delete() { | ||
|
||
if (!(await this.isGlobalSubscriptionExist())) { | ||
throw new DicomWebServiceError( | ||
DicomWebStatusCodes.ProcessingFailure, | ||
"The target Subscription was not found.", | ||
404 | ||
); | ||
} | ||
|
||
await this.deleteGlobalSubscription(); | ||
|
||
} | ||
|
||
async deleteGlobalSubscription() { | ||
|
||
await globalSubscriptionModel.findOneAndDelete({ | ||
aeTitle: this.subscriberAeTitle | ||
}); | ||
|
||
} | ||
|
||
async isGlobalSubscriptionExist() { | ||
return await globalSubscriptionModel.countDocuments({ | ||
aeTitle: this.subscriberAeTitle | ||
}) > 0; | ||
} | ||
|
||
} | ||
|
||
|
||
module.exports.SuspendSubscribeService = SuspendSubscribeService; |
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 { | ||
SuspendSubscribeService | ||
} = require("./service/suspend-subscription.service"); | ||
const { ApiLogger } = require("../../../../utils/logs/api-logger"); | ||
const { Controller } = require("../../../controller.class"); | ||
const { DicomWebServiceError } = require("@error/dicom-web-service"); | ||
|
||
class SuspendSubscribeWorkItemController extends Controller { | ||
constructor(req, res) { | ||
super(req, res); | ||
} | ||
|
||
async mainProcess() { | ||
let apiLogger = new ApiLogger(this.request, "UPS-RS"); | ||
|
||
apiLogger.addTokenValue(); | ||
apiLogger.logger.info(`Suspend Subscription, params: ${this.paramsToString()}`); | ||
|
||
try { | ||
let service = new SuspendSubscribeService(this.request, this.response); | ||
await service.delete(); | ||
|
||
return this.response | ||
.set("Content-Type", "application/dicom+json") | ||
.status(200) | ||
.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 SuspendSubscribeWorkItemController(req, res); | ||
|
||
await controller.doPipeline(); | ||
}; |
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