diff --git a/api-sql/dicom-web/controller/UPS-RS/service/update-workItem.service.js b/api-sql/dicom-web/controller/UPS-RS/service/update-workItem.service.js new file mode 100644 index 00000000..6787d9d3 --- /dev/null +++ b/api-sql/dicom-web/controller/UPS-RS/service/update-workItem.service.js @@ -0,0 +1,40 @@ +const { WorkItemModel } = require("@dbModels/workItems.model"); +const { DicomWebServiceError, DicomWebStatusCodes } = require("@error/dicom-web-service"); +const { DicomJsonModel } = require("@dicom-json-model"); +const { UpdateWorkItemService } = require("@root/api/dicom-web/controller/UPS-RS/service/update-workItem.service"); +const { UpsWorkItemPersistentObject } = require("@models/sql/po/upsWorkItem.po"); +const { set, get } = require("lodash"); +const { CreateWorkItemService } = require("./create-workItem.service"); + +class SqlUpdateWorkItemService extends UpdateWorkItemService { + constructor(req, res) { + super(req, res); + this.transactionUID = this.requestWorkItem.getString("00081195"); + set(this.requestWorkItem.dicomJson, "upsInstanceUID", this.request.params.workItem); + } + + async updateUps() { + this.workItem = await WorkItemModel.findOneWorkItemDicomJsonModel(this.request.params.workItem); + await this.checkRequestUpsIsValid(); + this.adjustRequestWorkItem(); + + let createService = new CreateWorkItemService(this.request, this.response); + let patient = await createService.findOneOrCreatePatient(); + let workItem = new UpsWorkItemPersistentObject(this.requestWorkItem.dicomJson, patient); + let savedWorkItem = await workItem.save(); + //TODO: update UPS event + } + + /** + * replace not allowed updating attribute in request work item + */ + adjustRequestWorkItem() { + for (let i = 0; i < UpdateWorkItemService.notAllowedAttributes.length; i++) { + let notAllowedAttr = UpdateWorkItemService.notAllowedAttributes[i]; + let originalValueOfNotAllowedAttr = get(this.workItem.dicomJson, notAllowedAttr); + set(this.requestWorkItem.dicomJson, originalValueOfNotAllowedAttr); + } + } +} + +module.exports.UpdateWorkItemService = SqlUpdateWorkItemService; \ No newline at end of file diff --git a/api/dicom-web/controller/UPS-RS/update-workItem.js b/api/dicom-web/controller/UPS-RS/update-workItem.js index f1c77d2b..267ccfbb 100644 --- a/api/dicom-web/controller/UPS-RS/update-workItem.js +++ b/api/dicom-web/controller/UPS-RS/update-workItem.js @@ -1,6 +1,6 @@ const { UpdateWorkItemService -} = require("./service/update-workItem.service"); +} = require("@ups-service/update-workItem.service"); const { ApiLogger } = require("../../../../utils/logs/api-logger"); const { Controller } = require("../../../controller.class"); const { DicomWebServiceError } = require("@error/dicom-web-service"); diff --git a/models/sql/models/workitems.model.js b/models/sql/models/workitems.model.js index fd800623..0c7875f2 100644 --- a/models/sql/models/workitems.model.js +++ b/models/sql/models/workitems.model.js @@ -4,6 +4,8 @@ const { vrTypeMapping } = require("../vrTypeMapping"); const { raccoonConfig } = require("@root/config-class"); const { SUBSCRIPTION_STATE } = require("@models/DICOM/ups"); const { UpsQueryBuilder } = require("@root/api-sql/dicom-web/controller/UPS-RS/service/query/upsQueryBuilder"); +const { DicomJsonModel } = require("../dicom-json-model"); +const { DicomWebServiceError, DicomWebStatusCodes } = require("@error/dicom-web-service"); let Common; if (raccoonConfig.dicomDimseConfig.enableDimse) { @@ -36,6 +38,24 @@ class WorkItemModel extends Model { return json; })); } + + static async findOneWorkItemDicomJsonModel(upsInstanceUID) { + let workItemObj = await WorkItemModel.findOne({ + where: { + upsInstanceUID: upsInstanceUID + } + }); + if (workItemObj) { + let {json} = workItemObj.toJSON(); + return new DicomJsonModel(json); + } else { + throw new DicomWebServiceError( + DicomWebStatusCodes.UPSDoesNotExist, + "The UPS instance not exist", + 404 + ); + } + } }; /** @type { import("sequelize").ModelAttributes } */