Skip to content

Commit

Permalink
feat: series sql model, and store series
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Aug 1, 2023
1 parent c95f379 commit d16c095
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 4 deletions.
10 changes: 6 additions & 4 deletions models/sql/dicom-json-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const _ = require("lodash");
const { DicomJsonModel } = require("@models/DICOM/dicom-json-model");
const { PatientPersistentObject } = require("./po/patient.po");
const { StudyPersistentObject } = require("./po/study.po");
const { SeriesPersistentObject } = require("./po/series.po");


class SqlDicomJsonModel extends DicomJsonModel {
Expand All @@ -27,7 +28,7 @@ class SqlDicomJsonModel extends DicomJsonModel {

let storedPatient = await this.storePatientCollection(dicomJsonClone);
let storedStudy = await this.storeStudyCollection(dicomJsonClone, storedPatient);
this.storeSeriesCollection(dicomJsonClone);
await this.storeSeriesCollection(dicomJsonClone, storedStudy);
this.storeInstanceCollection(dicomJsonClone);
} catch(e) {
throw e;
Expand All @@ -41,14 +42,15 @@ class SqlDicomJsonModel extends DicomJsonModel {
}

async storeStudyCollection(dicomJson, patient) {
// TODO
let studyPo = new StudyPersistentObject(dicomJson, patient);
let study = await studyPo.createStudy();
return study;
}

async storeSeriesCollection(dicomJson) {
// TODO
async storeSeriesCollection(dicomJson, study) {
let seriesPo = new SeriesPersistentObject(dicomJson, study);
let series = await seriesPo.createSeries();
return series;
}

async storeInstanceCollection(dicomJson) {
Expand Down
69 changes: 69 additions & 0 deletions models/sql/models/series.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const { Sequelize, DataTypes, Model } = require("sequelize");
const sequelizeInstance = require("@models/sql/instance");
const { vrTypeMapping } = require("../vrTypeMapping");

class SeriesModel extends Model { };

SeriesModel.init({
"x0020000D": {
type: vrTypeMapping.UI,
allowNull: false
},
"x0020000E": {
type: vrTypeMapping.UI,
allowNull: false,
unique: true
},
"x00080021": {
type: vrTypeMapping.DA
},
"x00080060": {
type: vrTypeMapping.CS
},
"x0008103E": {
type: vrTypeMapping.LO
},
"x0008103F": {
type: DataTypes.JSON
},
"x00081050": { // 1-n
type: DataTypes.JSON
},
"x00081052": {
type: DataTypes.JSON
},
"x00081070": { // 1-n
type: DataTypes.JSON
},
"x00081072": {
type: DataTypes.JSON
},
"x00081250": {
type: DataTypes.JSON
},
"x00200011": {
type: vrTypeMapping.IS
},
"x00400244": {
type: vrTypeMapping.DA
},
"x00400245": {
type: vrTypeMapping.TM
},
"x00400275": {
type: DataTypes.JSON
},
"x00080031": {
type: vrTypeMapping.TM
},
"json": {
type: DataTypes.JSON
}
}, {
sequelize: sequelizeInstance,
modelName: "Series",
tableName: "Series",
freezeTableName: true
});

module.exports.SeriesModel = SeriesModel;
79 changes: 79 additions & 0 deletions models/sql/po/series.po.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const moment = require("moment");
const _ = require("lodash");
const { PersonNameModel } = require("../models/personName.model");
const { SeriesModel } = require("../models/series.model");

const { tagsNeedStore } = require("@models/DICOM/dicom-tags-mapping");

class SeriesPersistentObject {
constructor(dicomJson, study) {

this.json = {};
Object.keys(tagsNeedStore.Study).forEach(key => {
let value = _.get(dicomJson, key);
value ? _.set(this.json, key, value) : undefined;
});
this.study = study;

this.x0020000D = this.study.x0020000D;
this.x0020000E = _.get(dicomJson, "0020000E.Value.0", "");
this.x00080021 = _.get(dicomJson, "00080021.Value.0", undefined);
this.x00080060 = _.get(dicomJson, "00080060.Value.0", "");
this.x0008103E = _.get(dicomJson, "0008103E.Value.0", "");
this.x0008103F = _.get(dicomJson, "0008103F.Value", undefined);
this.x00081050 = _.get(dicomJson, "00081050.Value", "");
this.x00081052 = _.get(dicomJson, "00081052.Value", "");
this.x00081070 = _.get(dicomJson, "00081070.Value", "");
this.x00081072 = _.get(dicomJson, "00081072.Value", "");
this.x00081250 = _.get(dicomJson, "00081250.Value", "");
this.x00200011 = _.get(dicomJson, "00200011.Value.0", "");
this.x00400244 = _.get(dicomJson, "00400244.Value.0", undefined);
this.x00400245 = _.get(dicomJson, "00400245.Value.0", "");
this.x00400275 = _.get(dicomJson, "00400275.Value", "");
this.x00080031 = _.get(dicomJson, "00080031.Value.0", "");
}

async createReferringPhysicianName() {
if (this.x00080090) {
return await PersonNameModel.create({
alphabetic: _.get(this.x00080090, "Alphabetic", undefined),
ideographic: _.get(this.x00080090, "Ideographic", undefined),
phonetic: _.get(this.x00080090, "Phonetic", undefined)
});
}
return undefined;
}

async createSeries() {
let [series, created] = await SeriesModel.findOrCreate({
where: {
x0020000D: this.x0020000D,
x0020000E: this.x0020000E
},
defaults: {
json: this.json,
x0020000D: this.x0020000D,
x0020000E: this.x0020000E,
x00080021: this.x00080021,
x00080060: this.x00080060,
x0008103E: this.x0008103E,
x0008103F: this.x0008103F,
x00081050: this.x00081050,
x00081052: this.x00081052,
x00081070: this.x00081070,
x00081072: this.x00081072,
x00081250: this.x00081250,
x00200011: this.x00200011,
x00400244: this.x00400244,
x00400245: this.x00400245 ? Number(this.x00400245) : undefined,
x00400275: this.x00400275,
x00080031: this.x00080031 ? Number(this.x00080031) : undefined
}
});

return series;
}

}

module.exports.SeriesPersistentObject = SeriesPersistentObject;

0 comments on commit d16c095

Please sign in to comment.