Skip to content

Commit

Permalink
feat: implement update workitem API
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Nov 26, 2023
1 parent 0277aba commit de32f10
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion api/dicom-web/controller/UPS-RS/update-workItem.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
20 changes: 20 additions & 0 deletions models/sql/models/workitems.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 } */
Expand Down

0 comments on commit de32f10

Please sign in to comment.