Skip to content

Commit

Permalink
feat: get{level}DicomJson for storing into mongo
Browse files Browse the repository at this point in the history
- Use get{level}DicomJson to filter tag need to store in db
that speed up mongoose saving
- And refactor `getMediaStorageInfo` that should present in every level
  • Loading branch information
Chinlinlee committed Apr 19, 2023
1 parent 9eab50c commit 7ceb1bb
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 7 deletions.
74 changes: 68 additions & 6 deletions models/DICOM/dicom-json-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const shortHash = require("shorthash2");
const dicomBulkDataModel = require("../mongodb/models/dicomBulkData");
const { logger } = require("../../utils/logs/log");
const patientModel = require("../mongodb/models/patient");
const { tagsNeedStore } = require("./dicom-tags-mapping");

const { raccoonConfig } = require("../../config-class");

Expand Down Expand Up @@ -81,12 +82,14 @@ class DicomJsonModel {
async storeToDb(dicomFileSaveInfo) {
let dicomJsonClone = _.cloneDeep(this.dicomJson);
try {
let mediaStorage = this.getMediaStorageInfo();
_.merge(dicomJsonClone, this.uidObj);
_.merge(dicomJsonClone, {
studyPath: dicomFileSaveInfo.studyPath,
seriesPath: dicomFileSaveInfo.seriesPath,
instancePath: dicomFileSaveInfo.relativePath
});
_.merge(dicomJsonClone, mediaStorage);

delete dicomJsonClone.sopClass;
delete dicomJsonClone.sopInstanceUID;
Expand Down Expand Up @@ -128,7 +131,7 @@ class DicomJsonModel {
{
studyUID: this.uidObj.studyUID
},
dicomJson,
this.getStudyDicomJson(dicomJson),
{
upsert: true,
new: true
Expand All @@ -148,7 +151,7 @@ class DicomJsonModel {
}
]
},
dicomJson,
this.getSeriesDicomJson(dicomJson),
{
upsert: true,
new: true
Expand All @@ -157,15 +160,12 @@ class DicomJsonModel {
}

async storePatientCollection(dicomJson) {
let mediaStorage = this.getMediaStorageInfo();

await patientModel.findOneAndUpdate(
{
patientID: this.uidObj.patientID
},
{
...dicomJson,
...mediaStorage,
...this.getPatientDicomJson(dicomJson),
$addToSet: {
studyPaths: dicomJson.studyPath
}
Expand Down Expand Up @@ -258,6 +258,68 @@ class DicomJsonModel {
};
}

getPatientDicomJson(dicomJson=undefined) {
if (!dicomJson) dicomJson = this.dicomJson;

let patientDicomJson = {
patientID: dicomJson.patientID
};

for(let tag in tagsNeedStore.Patient) {
let value = _.get(dicomJson, tag);
if (value)
_.set(patientDicomJson, tag, value);
}

return patientDicomJson;
}

getStudyDicomJson(dicomJson=undefined) {

if (!dicomJson) dicomJson = this.dicomJson;

let studyDicomJson = {
studyUID: dicomJson.studyUID,
studyPath: dicomJson.studyPath
};

for(let tag in tagsNeedStore.Study) {
let value = _.get(dicomJson, tag);
if (value)
_.set(studyDicomJson, tag, value);
}

let patientDicomJson = this.getPatientDicomJson(dicomJson);

return {
...patientDicomJson,
...studyDicomJson
};
}

getSeriesDicomJson(dicomJson=undefined) {
if (!dicomJson) dicomJson = this.dicomJson;

let seriesDicomJson = {
studyUID: dicomJson.studyUID,
seriesUID: dicomJson.seriesUID,
seriesPath: dicomJson.seriesPath
};

for(let tag in tagsNeedStore.Series) {
let value = _.get(dicomJson, tag);
if(value)
_.set(seriesDicomJson, tag, value);
}

let studyDicomJson = this.getStudyDicomJson(dicomJson);

return {
...studyDicomJson,
...seriesDicomJson
};
}

}


Expand Down
5 changes: 4 additions & 1 deletion test/patient.mongo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ describe("Patient MongoDB and DicomJsonModel", async() => {
let dicomJsonModel = new DicomJsonModel(cloneFakePatientData);
dicomJsonModel.setUidObj();

await dicomJsonModel.storePatientCollection(cloneFakePatientData);
await dicomJsonModel.storePatientCollection({
...dicomJsonModel.getMediaStorageInfo(),
...cloneFakePatientData
});

let findDoc = await patientModel.findOne();
expect(findDoc).property("studyPaths").that.is.an("array").include("/foo/bar");
Expand Down

0 comments on commit 7ceb1bb

Please sign in to comment.