diff --git a/models/sql/models/baseDicom.model.js b/models/sql/models/baseDicom.model.js new file mode 100644 index 00000000..19243f84 --- /dev/null +++ b/models/sql/models/baseDicom.model.js @@ -0,0 +1,27 @@ +const { raccoonConfig } = require("@root/config-class"); +const { Model } = require("sequelize"); + +let Common; +if (raccoonConfig.dicomDimseConfig.enableDimse) { + require("@models/DICOM/dcm4che/java-instance"); + Common = require("@java-wrapper/org/github/chinlinlee/dcm777/net/common/Common").Common; +} +class BaseDicomModel extends Model { + async getAttributes() { + let obj = this.toJSON(); + let jsonStr = JSON.stringify(obj.json); + return await Common.getAttributesFromJsonString(jsonStr); + } + + async incrementDeleteStatus() { + let deleteStatus = this.getDataValue("deleteStatus"); + this.setDataValue("deleteStatus", deleteStatus + 1); + await this.save(); + } + + toDicomJson() { + return this.json; + } +}; + +module.exports.BaseDicomModel = BaseDicomModel; \ No newline at end of file diff --git a/models/sql/models/instance.model.js b/models/sql/models/instance.model.js index 251bf99f..11711d46 100644 --- a/models/sql/models/instance.model.js +++ b/models/sql/models/instance.model.js @@ -9,19 +9,9 @@ const { dictionary } = require("@models/DICOM/dicom-tags-dic"); const { getStoreDicomFullPath } = require("@models/mongodb/service"); const { logger } = require("@root/utils/logs/log"); const { raccoonConfig } = require("@root/config-class"); +const { BaseDicomModel } = require("./baseDicom.model"); -let Common; -if (raccoonConfig.dicomDimseConfig.enableDimse) { - require("@models/DICOM/dcm4che/java-instance"); - Common = require("@java-wrapper/org/github/chinlinlee/dcm777/net/common/Common").Common; -} - -class InstanceModel extends Model { - async incrementDeleteStatus() { - let deleteStatus = this.getDataValue("deleteStatus"); - this.setDataValue("deleteStatus", deleteStatus + 1); - await this.save(); - } +class InstanceModel extends BaseDicomModel { async deleteInstance() { let instancePath = this.getDataValue("instancePath"); @@ -247,11 +237,4 @@ InstanceModel.getInstanceOfMedianIndex = async function (query) { return instance; }; -InstanceModel.prototype.getAttributes = async function () { - let seriesObj = this.toJSON(); - - let jsonStr = JSON.stringify(seriesObj.json); - return await Common.getAttributesFromJsonString(jsonStr); -}; - module.exports.InstanceModel = InstanceModel; diff --git a/models/sql/models/patient.model.js b/models/sql/models/patient.model.js index 32bb66c5..a6d54bc2 100644 --- a/models/sql/models/patient.model.js +++ b/models/sql/models/patient.model.js @@ -3,14 +3,9 @@ const sequelizeInstance = require("@models/sql/instance"); const { vrTypeMapping } = require("../vrTypeMapping"); const { PatientQueryBuilder } = require("@root/api-sql/dicom-web/controller/QIDO-RS/service/patientQueryBuilder"); const { raccoonConfig } = require("@root/config-class"); +const { BaseDicomModel } = require("./baseDicom.model"); -let Common; -if (raccoonConfig.dicomDimseConfig.enableDimse) { - require("@models/DICOM/dcm4che/java-instance"); - Common = require("@java-wrapper/org/github/chinlinlee/dcm777/net/common/Common").Common; -} - -class PatientModel extends Model { +class PatientModel extends BaseDicomModel { static async updateOrCreatePatient(patient) { /** @type {PatientModel | null} */ const { PatientPersistentObject } = require("../po/patient.po"); @@ -19,16 +14,6 @@ class PatientModel extends Model { return bringPatient; } - - async incrementDeleteStatus() { - let deleteStatus = this.getDataValue("deleteStatus"); - this.setDataValue("deleteStatus", deleteStatus + 1); - await this.save(); - } - - toDicomJson() { - return this.json; - } }; PatientModel.init({ @@ -95,11 +80,4 @@ PatientModel.getDicomJson = async function (queryOptions) { })); }; -PatientModel.prototype.getAttributes = async function () { - let patientObj = this.toJSON(); - - let jsonStr = JSON.stringify(patientObj.json); - return await Common.getAttributesFromJsonString(jsonStr); -}; - module.exports.PatientModel = PatientModel; diff --git a/models/sql/models/series.model.js b/models/sql/models/series.model.js index fcb74252..406d0424 100644 --- a/models/sql/models/series.model.js +++ b/models/sql/models/series.model.js @@ -9,24 +9,13 @@ const { dictionary } = require("@models/DICOM/dicom-tags-dic"); const { getStoreDicomFullPathGroup } = require("@models/mongodb/service"); const { logger } = require("@root/utils/logs/log"); const { raccoonConfig } = require("@root/config-class"); +const { BaseDicomModel } = require("./baseDicom.model"); -let Common; -if (raccoonConfig.dicomDimseConfig.enableDimse) { - require("@models/DICOM/dcm4che/java-instance"); - Common = require("@java-wrapper/org/github/chinlinlee/dcm777/net/common/Common").Common; -} - -class SeriesModel extends Model { +class SeriesModel extends BaseDicomModel { getSeriesPath() { return this.getDataValue("seriesPath"); } - async incrementDeleteStatus() { - let deleteStatus = this.getDataValue("deleteStatus"); - this.setDataValue("deleteStatus", deleteStatus + 1); - await this.save(); - } - async deleteSeriesFolder() { let seriesPath = this.getDataValue("seriesPath"); logger.warn("Permanently delete series folder: " + seriesPath); @@ -175,11 +164,4 @@ SeriesModel.getPathGroupOfInstances = async function(iParam) { } }; -SeriesModel.prototype.getAttributes = async function () { - let seriesObj = this.toJSON(); - - let jsonStr = JSON.stringify(seriesObj.json); - return await Common.getAttributesFromJsonString(jsonStr); -}; - module.exports.SeriesModel = SeriesModel; diff --git a/models/sql/models/study.model.js b/models/sql/models/study.model.js index 62c623d1..1478f0dd 100644 --- a/models/sql/models/study.model.js +++ b/models/sql/models/study.model.js @@ -11,14 +11,9 @@ const { dictionary } = require("@models/DICOM/dicom-tags-dic"); const { getStoreDicomFullPathGroup } = require("@models/mongodb/service"); const { logger } = require("@root/utils/logs/log"); const { raccoonConfig } = require("@root/config-class"); +const { BaseDicomModel } = require("./baseDicom.model"); -let Common; -if (raccoonConfig.dicomDimseConfig.enableDimse) { - require("@models/DICOM/dcm4che/java-instance"); - Common = require("@java-wrapper/org/github/chinlinlee/dcm777/net/common/Common").Common; -} - -class StudyModel extends Model { +class StudyModel extends BaseDicomModel { async getNumberOfStudyRelatedSeries() { let count = await SeriesModel.count({ where: { @@ -37,12 +32,6 @@ class StudyModel extends Model { return count; } - async incrementDeleteStatus() { - let deleteStatus = this.getDataValue("deleteStatus"); - this.setDataValue("deleteStatus", deleteStatus + 1); - await this.save(); - } - async deleteStudyFolder() { let studyPath = this.getDataValue("studyPath"); logger.warn("Permanently delete study folder: " + studyPath); @@ -218,11 +207,4 @@ StudyModel.getPathGroupOfInstances = async function (iParam) { } }; -StudyModel.prototype.getAttributes = async function () { - let studyObj = this.toJSON(); - - let jsonStr = JSON.stringify(studyObj.json); - return await Common.getAttributesFromJsonString(jsonStr); -}; - module.exports.StudyModel = StudyModel;