Skip to content

Commit

Permalink
feat: change state event
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Jun 3, 2023
1 parent 35347fe commit 08ae3f2
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ const {
DicomWebServiceError,
DicomWebStatusCodes
} = require("@error/dicom-web-service");
const { BaseWorkItemService } = require("./base-workItem.service");
const { UPS_EVENT_TYPE } = require("./workItem-event");

class ChangeWorkItemStateService {
class ChangeWorkItemStateService extends BaseWorkItemService {
/**
*
* @param {import('express').Request} req
* @param {import('express').Response} res
*/
constructor(req, res) {
this.request = req;
this.response = res;
super(req, res);
this.requestState = /** @type {Object[]} */(this.request.body).pop();
/** @type {DicomJsonModel} */
this.requestState = new DicomJsonModel(this.requestState);
Expand Down Expand Up @@ -50,11 +51,24 @@ class ChangeWorkItemStateService {
this.completeChange();
}

await workItemModel.findOneAndUpdate({
let updatedWorkItem = await workItemModel.findOneAndUpdate({
upsInstanceUID: this.request.params.workItem
}, {
...this.requestState.dicomJson
}, {
new: true
});

let updatedWorkItemDicomJson = new DicomJsonModel(updatedWorkItem.toObject());

let hitSubscriptions = await this.getHitSubscriptions(updatedWorkItemDicomJson);

if (hitSubscriptions.length === 0) return;

let hitSubscriptionAeTitleArray = hitSubscriptions.map(sub => sub.aeTitle);

this.addUpsEvent(UPS_EVENT_TYPE.StateReport, updatedWorkItemDicomJson.dicomJson.upsInstanceUID, this.stateReportOf(updatedWorkItemDicomJson), hitSubscriptionAeTitleArray);
this.triggerUpsEvents();
}

async findOneWorkItem() {
Expand Down

0 comments on commit 08ae3f2

Please sign in to comment.