Skip to content

Commit

Permalink
feat: suspend subscription and add API docs
Browse files Browse the repository at this point in the history
# open api docs
- Subscribe Transaction
- Unsubscribe Transaction
- Suspend Global Subscription Transaction

# New API
- Suspend Global Subscription Transaction
  • Loading branch information
Chinlinlee committed Jun 3, 2023
1 parent 28e35f4 commit 7952464
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 13 deletions.
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;
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class UnSubscribeService extends BaseWorkItemService {
this.upsInstanceUID = this.request.params.workItem;
this.workItem = null;
this.subscriberAeTitle = this.request.params.subscriberAeTitle;
this.deletionLock = _.clone(this.request.query.deletionlock);
delete this.request.query["deletionlock"];
}

async delete() {
Expand Down
64 changes: 64 additions & 0 deletions api/dicom-web/controller/UPS-RS/suspend-subscription.js
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();
};
66 changes: 61 additions & 5 deletions api/dicom-web/ups-rs.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const { SUBSCRIPTION_FIXED_UIDS } = require("@models/DICOM/ups");
* tags:
* - UPS-RS
* description: >
* This transaction creates a Workitem on the target Worklist. It corresponds to the UPS DIMSE N-CREATE operation.
* This transaction creates a Workitem on the target Worklist. It corresponds to the UPS DIMSE N-CREATE operation.<br/><br/>
* See [Create Workitem Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.4)
* parameters:
* - $ref: "#/components/parameters/workitem"
Expand All @@ -44,7 +44,7 @@ router.post("/workitems",
* tags:
* - UPS-RS
* description: >
* This transaction retrieves a Workitem. It corresponds to the UPS DIMSE N-GET operation.
* This transaction retrieves a Workitem. It corresponds to the UPS DIMSE N-GET operation.<br/><br/>
* See [Retrieve Workitem Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.5)
* responses:
* "200":
Expand All @@ -65,7 +65,7 @@ router.get("/workitems",
* tags:
* - UPS-RS
* description: >
* This transaction retrieves a Workitem. It corresponds to the UPS DIMSE N-GET operation.
* This transaction retrieves a Workitem. It corresponds to the UPS DIMSE N-GET operation.<br/><br/>
* See [Retrieve Workitem Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.5)
* parameters:
* - $ref: "#/components/parameters/workitemUID"
Expand All @@ -88,7 +88,7 @@ router.get("/workitems/:workItem",
* tags:
* - UPS-RS
* description: >
* This transaction modifies Attributes of an existing Workitem. It corresponds to the UPS DIMSE N-SET operation.
* This transaction modifies Attributes of an existing Workitem. It corresponds to the UPS DIMSE N-SET operation.<br/><br/>
* See [Update Workitem Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.6)
* parameters:
* - $ref: "#/components/parameters/workitemUID"
Expand All @@ -108,7 +108,7 @@ router.post("/workitems/:workItem",
* - UPS-RS
* description: >
* This transaction is used to change the state of a Workitem. It corresponds to the UPS DIMSE N-ACTION operation "Change UPS State".<br/>
* State changes are used to claim ownership, complete, or cancel a Workitem.<br/>
* State changes are used to claim ownership, complete, or cancel a Workitem.<br/><br/>
* See [Change Workitem State](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.7)
* parameters:
* - $ref: "#/components/parameters/workitemUID"
Expand All @@ -132,17 +132,73 @@ router.put("/workitems/:workItem/state",
require("./controller/UPS-RS/change-workItem-state")
);

/**
* @openapi
* /dicom-web/workitems/{workitemUID}/subscribers/{aeTitle}:
* post:
* tags:
* - UPS-RS
* description: >
* This transaction creates a Subscription to a Worklist or Workitem resource. It corresponds to the UPS DIMSE N-ACTION operation "Subscribe to Receive UPS Event Reports".<br/><br/>
* See [Subscribe Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.10)
* parameters:
* - $ref: "#/components/parameters/workitemUID"
* - $ref: "#/components/parameters/aeTitle"
* responses:
* "201":
* description: The Subscription was created.
*/
router.post("/workitems/:workItem/subscribers/:subscriberAeTitle",
validateParams({
deletionlock: Joi.boolean().default(false)
}, "query", { allowUnknown: true }),
require("./controller/UPS-RS/subscribe")
);

/**
* @openapi
* /dicom-web/workitems/{workitemUID}/subscribers/{aeTitle}:
* delete:
* tags:
* - UPS-RS
* description: >
* This transaction is used to stop the origin server from sending new Event Reports to the user agent and may also stop the origin server from subscribing the user agent to new Workitems.<br/><br/>
* See [Unsubscribe Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.11)
* parameters:
* - $ref: "#/components/parameters/workitemUID"
* - $ref: "#/components/parameters/aeTitle"
* responses:
* "200":
* description: The Subscription(s) were removed.
*/
router.delete("/workitems/:workItem/subscribers/:subscriberAeTitle",
require("./controller/UPS-RS/unsubscribe")
);

/**
* @openapi
* /dicom-web/workitems/{workitemUID}/subscribers/{aeTitle}/suspend:
* post:
* tags:
* - UPS-RS
* description: >
* 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.<br/>
* See [Suspend Global Subscription Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.12)
* parameters:
* - $ref: "#/components/parameters/workitemUID"
* - $ref: "#/components/parameters/aeTitle"
* responses:
* "200":
* description: The Subscription(s) were removed.
*/
router.post("/workitems/:workItem/subscribers/:subscriberAeTitle/suspend",
validateParams({
workItem: Joi.string().valid(SUBSCRIPTION_FIXED_UIDS.GlobalUID, SUBSCRIPTION_FIXED_UIDS.FilteredGlobalUID),
subscriberAeTitle: Joi.string()
}, "params"),
require("./controller/UPS-RS/suspend-subscription")
);

//#endregion

module.exports = router;
80 changes: 75 additions & 5 deletions docs/swagger/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@
"tags": [
"UPS-RS"
],
"description": "This transaction creates a Workitem on the target Worklist. It corresponds to the UPS DIMSE N-CREATE operation. See [Create Workitem Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.4)\n",
"description": "This transaction creates a Workitem on the target Worklist. It corresponds to the UPS DIMSE N-CREATE operation.<br/><br/> See [Create Workitem Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.4)\n",
"parameters": [
{
"$ref": "#/components/parameters/workitem"
Expand All @@ -501,7 +501,7 @@
"tags": [
"UPS-RS"
],
"description": "This transaction retrieves a Workitem. It corresponds to the UPS DIMSE N-GET operation. See [Retrieve Workitem Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.5)\n",
"description": "This transaction retrieves a Workitem. It corresponds to the UPS DIMSE N-GET operation.<br/><br/> See [Retrieve Workitem Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.5)\n",
"responses": {
"200": {
"description": "Query successfully",
Expand All @@ -521,7 +521,7 @@
"tags": [
"UPS-RS"
],
"description": "This transaction retrieves a Workitem. It corresponds to the UPS DIMSE N-GET operation. See [Retrieve Workitem Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.5)\n",
"description": "This transaction retrieves a Workitem. It corresponds to the UPS DIMSE N-GET operation.<br/><br/> See [Retrieve Workitem Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.5)\n",
"parameters": [
{
"$ref": "#/components/parameters/workitemUID"
Expand All @@ -544,7 +544,7 @@
"tags": [
"UPS-RS"
],
"description": "This transaction modifies Attributes of an existing Workitem. It corresponds to the UPS DIMSE N-SET operation. See [Update Workitem Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.6)\n",
"description": "This transaction modifies Attributes of an existing Workitem. It corresponds to the UPS DIMSE N-SET operation.<br/><br/> See [Update Workitem Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.6)\n",
"parameters": [
{
"$ref": "#/components/parameters/workitemUID"
Expand All @@ -562,7 +562,7 @@
"tags": [
"UPS-RS"
],
"description": "This transaction is used to change the state of a Workitem. It corresponds to the UPS DIMSE N-ACTION operation \"Change UPS State\".<br/> State changes are used to claim ownership, complete, or cancel a Workitem.<br/> See [Change Workitem State](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.7)\n",
"description": "This transaction is used to change the state of a Workitem. It corresponds to the UPS DIMSE N-ACTION operation \"Change UPS State\".<br/> State changes are used to claim ownership, complete, or cancel a Workitem.<br/><br/> See [Change Workitem State](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.7)\n",
"parameters": [
{
"$ref": "#/components/parameters/workitemUID"
Expand All @@ -575,6 +575,67 @@
}
}
},
"/dicom-web/workitems/{workitemUID}/subscribers/{aeTitle}": {
"post": {
"tags": [
"UPS-RS"
],
"description": "This transaction creates a Subscription to a Worklist or Workitem resource. It corresponds to the UPS DIMSE N-ACTION operation \"Subscribe to Receive UPS Event Reports\".<br/><br/> See [Subscribe Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.10)\n",
"parameters": [
{
"$ref": "#/components/parameters/workitemUID"
},
{
"$ref": "#/components/parameters/aeTitle"
}
],
"responses": {
"201": {
"description": "The Subscription was created."
}
}
},
"delete": {
"tags": [
"UPS-RS"
],
"description": "This transaction is used to stop the origin server from sending new Event Reports to the user agent and may also stop the origin server from subscribing the user agent to new Workitems.<br/><br/> See [Unsubscribe Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.11)\n",
"parameters": [
{
"$ref": "#/components/parameters/workitemUID"
},
{
"$ref": "#/components/parameters/aeTitle"
}
],
"responses": {
"200": {
"description": "The Subscription(s) were removed."
}
}
}
},
"/dicom-web/workitems/{workitemUID}/subscribers/{aeTitle}/suspend": {
"post": {
"tags": [
"UPS-RS"
],
"description": "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.<br/> See [Suspend Global Subscription Transaction](https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_11.12)\n",
"parameters": [
{
"$ref": "#/components/parameters/workitemUID"
},
{
"$ref": "#/components/parameters/aeTitle"
}
],
"responses": {
"200": {
"description": "The Subscription(s) were removed."
}
}
}
},
"/dicom-web/studies/{studyUID}/bulkdata": {
"get": {
"tags": [
Expand Down Expand Up @@ -1331,6 +1392,15 @@
"type": "string"
}
},
"aeTitle": {
"name": "aeTitle",
"description": "The Application Entity Title of a Subscriber.",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
},
"frameNumbers": {
"name": "frameNumbers",
"description": "comma separated list of one or more non duplicate frame numbers",
Expand Down
9 changes: 8 additions & 1 deletion docs/swagger/parameters/ups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ components:
in: path
required: true
schema:
type: string
type: string
"aeTitle":
name: "aeTitle"
description: The Application Entity Title of a Subscriber.
in: path
required: true
schema:
type: string

0 comments on commit 7952464

Please sign in to comment.