Skip to content

Commit

Permalink
feat: add update event for subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Jun 2, 2023
1 parent f9fa5bd commit 35347fe
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class BaseWorkItemService {
return eventInformation;
}

progressReportOf(workItem) {
return {
"00741002": _.get(workItem.dicomJson, dictionary.keyword.ProcedureStepProgressInformationSequence)
};
}

async isAeTileSubscribed(aeTitle) {
let subscription = await subscriptionModel.findOne({
aeTitle: aeTitle
Expand Down Expand Up @@ -127,7 +133,7 @@ class BaseWorkItemService {
return hitSubscriptions;
}

async getAssignedEventInformationArray(workItem, stationNameUpdated, performerUpdated) {
getAssignedEventInformationArray(workItem, stationNameUpdated, performerUpdated) {
if (!performerUpdated) {
let scheduledStationCodeSeq = _.get(workItem.dicomJson, `${dictionary.keyword.ScheduledStationNameCodeSequence}.Value`);
return stationNameUpdated ? scheduledStationCodeSeq : [];
Expand Down
77 changes: 67 additions & 10 deletions api/dicom-web/controller/UPS-RS/service/update-workItem.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const {
DicomWebStatusCodes
} = require("@error/dicom-web-service");
const { DicomJsonModel } = require("@models/DICOM/dicom-json-model");
const { BaseWorkItemService } = require("./base-workItem.service");
const { dictionary } = require("@models/DICOM/dicom-tags-dic");
const { UPS_EVENT_TYPE } = require("./workItem-event");


const notAllowedAttributes = [
Expand All @@ -25,15 +28,14 @@ const notAllowedAttributes = [
"00741000"
];

class UpdateWorkItemService {
class UpdateWorkItemService 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.requestWorkItem = /** @type {Object[]} */(this.request.body).pop();
/** @type {DicomJsonModel} */
this.requestWorkItem = new DicomJsonModel(this.requestWorkItem);
Expand All @@ -46,14 +48,69 @@ class UpdateWorkItemService {
await this.findOneWorkItem();
await this.checkRequestUpsIsValid();
this.adjustRequestWorkItem();
await workItemModel.findOneAndUpdate({

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

let updateWorkItemDicomJson = new DicomJsonModel(updatedWorkItem);
let hitSubscriptions = await this.getHitSubscriptions(updateWorkItemDicomJson);
if (hitSubscriptions.length === 0) {
return updatedWorkItem;
}
let hitSubscriptionAeTitleArray = hitSubscriptions.map(sub => sub.aeTitle);


//Each time the SCP changes the Input Readiness State (0040,4041) Attribute for a UPS instance, the SCP shall send a UPS State Report Event to subscribed SCUs.
let modifiedInputReadLineState = this.requestWorkItem.getString(`${dictionary.keyword.InputReadinessState}`);
let originalInputReadLineState = this.workItem.getString(`${dictionary.keyword.InputReadinessState}`);
if (modifiedInputReadLineState && modifiedInputReadLineState !== originalInputReadLineState) {
this.addUpsEvent(
UPS_EVENT_TYPE.StateReport,
this.workItem.dicomJson.upsInstanceUID,
this.stateReportOf(updateWorkItemDicomJson),
hitSubscriptionAeTitleArray
);
}

this.addProgressInfoUpdatedEvent(updateWorkItemDicomJson, hitSubscriptionAeTitleArray);
this.addAssignedEvents(updateWorkItemDicomJson, hitSubscriptionAeTitleArray);

this.triggerUpsEvents();
}

addProgressInfoUpdatedEvent(workItemDicomJson, aeTitles) {
let modifiedProcedureStepProgressInfo = _.get(this.requestWorkItem.dicomJson, dictionary.keyword.ProcedureStepProgressInformationSequence);
let originalProcedureStepProgressInfo = _.get(this.workItem.dicomJson , dictionary.keyword.ProcedureStepProgressInformationSequence);
if (modifiedProcedureStepProgressInfo && !_.isEqual(modifiedProcedureStepProgressInfo, originalProcedureStepProgressInfo)) {
this.addUpsEvent(
UPS_EVENT_TYPE.ProgressReport,
this.workItem.dicomJson.upsInstanceUID,
this.progressReportOf(workItemDicomJson),
aeTitles
);
}
}

addAssignedEvents(workItemDicomJson, aeTitles) {
let modifiedPerformer = _.get(this.requestWorkItem.dicomJson, dictionary.keyword.ScheduledHumanPerformersSequence);
let originalPerformer = _.get(this.workItem.dicomJson, dictionary.keyword.ScheduledHumanPerformersSequence);
let performerUpdated = modifiedPerformer && !_.isEqual(modifiedPerformer, originalPerformer);

let modifiedStationName = _.get(this.requestWorkItem.dicomJson, dictionary.keyword.ScheduledStationNameCodeSequence);
let originalStationName = _.get(this.workItem.dicomJson, dictionary.keyword.ScheduledStationNameCodeSequence);
let stationNameUpdate = modifiedStationName && !_.isEqual(modifiedStationName, originalStationName);

let assignedEventInformationArray = this.getAssignedEventInformationArray(workItemDicomJson, performerUpdated, stationNameUpdate);
for(let assignedEventInfo of assignedEventInformationArray) {
this.addUpsEvent(UPS_EVENT_TYPE.Assigned, workItemDicomJson.dicomJson.upsInstanceUID, assignedEventInfo, aeTitles);
}
}

async findOneWorkItem() {

let workItem = await workItemModel.findOne({
Expand All @@ -67,9 +124,9 @@ class UpdateWorkItemService {
404
);
}
this.workItem = new DicomJsonModel(workItem);

this.workItem = new DicomJsonModel(workItem.toObject());

}

checkRequestUpsIsValid() {
Expand Down Expand Up @@ -114,15 +171,15 @@ class UpdateWorkItemService {
);
}
};

return mappingMethod[procedureState]() || true;
}

/**
* remove not allowed updating attribute in request work item
*/
adjustRequestWorkItem() {
for(let i = 0 ; i < notAllowedAttributes.length ; i++) {
for (let i = 0; i < notAllowedAttributes.length; i++) {
let notAllowedAttr = notAllowedAttributes[i];
_.unset(this.requestWorkItem.dicomJson, notAllowedAttr);
}
Expand Down

0 comments on commit 35347fe

Please sign in to comment.