Skip to content

Commit

Permalink
feat(stow-rs): calc and store additional tag
Browse files Browse the repository at this point in the history
- Store `Number of Study Related Series (0020,1206)`
to `dicomStudy` when post `findOneAndUpdate` of `dicom` schema
- Store `Number of Study Related Instances (0020,1208)` to `dicomStudy` when post
`findOneAndUpdate` of `dicom` schema
- Store `Modalities in Study (0008,0061)` to
`dicomStudy` when post `findOneAndUpdate` of `dicom` schema
- Store `SOP Classes in Study (0008,0062)` to
`dicomStudy` when post `findOneAndUpdate` of `dicom` schema
  • Loading branch information
Chinlinlee committed May 2, 2022
1 parent cf44360 commit 4ae378c
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 10 deletions.
3 changes: 3 additions & 0 deletions models/DICOM/dicom-tags-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ module.exports.tagsNeedStore = {
"00080061": {
vr: "CS"
},
"00080062": {
vr: "UI"
},
"00080090": {
vr: "PN"
},
Expand Down
200 changes: 190 additions & 10 deletions models/mongodb/models/dicom.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
const mongoose = require('mongoose');
const {
dicomJsonAttributeSchema,
dicomJsonAttributePNSchema,
dicomJsonAttributeDASchema
const {
dicomJsonAttributeSchema,
dicomJsonAttributePNSchema,
dicomJsonAttributeDASchema
} = require('../schema/dicomJsonAttribute');
const {
logger
} = require('../../../utils/log');

let dicomModelSchema = new mongoose.Schema({
let dicomModelSchema = new mongoose.Schema({
studyUID: {
type: String,
default: void 0,
Expand All @@ -24,7 +27,7 @@ let dicomModelSchema = new mongoose.Schema({
index: true,
required: true
},
"00080020" : dicomJsonAttributeDASchema,
"00080020": dicomJsonAttributeDASchema,
"00080030": {
...dicomJsonAttributeSchema,
Value: [mongoose.SchemaTypes.Number]
Expand Down Expand Up @@ -57,7 +60,7 @@ let dicomModelSchema = new mongoose.Schema({
...dicomJsonAttributeSchema,
Value: [mongoose.SchemaTypes.String]
},
"00080060" : {
"00080060": {
...dicomJsonAttributeSchema,
Value: [mongoose.SchemaTypes.String]
},
Expand All @@ -83,7 +86,7 @@ let dicomModelSchema = new mongoose.Schema({
...dicomJsonAttributeSchema,
Value: [mongoose.SchemaTypes.String]
}
}, {
}, {
strict: false,
versionKey: false,
toObject: {
Expand All @@ -102,12 +105,189 @@ dicomModelSchema.index({
});

dicomModelSchema.methods.getDICOMJson = function () {
let obj = this.toObject();
let obj = this.toObject();
delete obj._id;
delete obj.studyUID;
delete obj.seriesUID;
delete obj.instanceUID;
}

dicomModelSchema.post("findOneAndUpdate", async function (doc) {
updateStudyModalitiesInStudy(doc).catch(e => {
logger.error(`[STOW-RS] [update study modalities] [${e}]`);
});
updateStudySOPClassesInStudy(doc).catch(e => {
logger.error(`[STOW-RS] [update study sop classes in study] [${e}]`);
});
updateStudyNumberOfStudyRelatedSeries(doc).catch(e => {
logger.error(`[STOW-RS] [update study number of study related series] [${e}]`);
});
updateStudyNumberOfStudyRelatedInstance(doc).catch(e => {
logger.error(`[STOW-RS] [update study number of study related instances] [${e}]`);
});
});

async function updateStudyModalitiesInStudy(doc) {
try {
let modalitiesInStudy = await mongoose.model("dicom").aggregate([{
$match: {
studyUID: doc.studyUID
}
},
{
$group: {
_id: "$studyUID",
modalitiesInStudy: {
"$addToSet": "$00080060.Value"
}
}
},
{
"$project": {
"00080061": {
"vr": "CS",
"Value": {
"$reduce": {
"input": "$modalitiesInStudy",
"initialValue": [],
"in": {
"$concatArrays": [
"$$value",
"$$this"
]
}
}
}
}
}
}
]);
await mongoose.model("dicomStudy").findOneAndUpdate({
studyUID: doc.studyUID
}, {
$set: {
"00080061": modalitiesInStudy[0]["00080061"]
}
});
} catch (e) {
throw e;
}
}

async function updateStudySOPClassesInStudy(doc) {
try {
let sopClassesInStudy = await mongoose.model("dicom").aggregate([{
$match: {
studyUID: doc.studyUID
}
},
{
$group: {
_id: "$studyUID",
sopClassesInStudy: {
"$addToSet": "$00080016.Value"
}
}
},
{
"$project": {
"00080062": {
"vr": "CS",
"Value": {
"$reduce": {
"input": "$sopClassesInStudy",
"initialValue": [],
"in": {
"$concatArrays": [
"$$value",
"$$this"
]
}
}
}
}
}
}
]);
await mongoose.model("dicomStudy").findOneAndUpdate({
studyUID: doc.studyUID
}, {
$set: {
"00080062": sopClassesInStudy[0]["00080062"]
}
});
} catch (e) {
throw e;
}
}

async function updateStudyNumberOfStudyRelatedSeries(doc) {
try {
let numberOfStudyRelatedSeries = await mongoose.model("dicomSeries").aggregate([{
$match: {
studyUID: doc.studyUID
}
},
{
$group: {
_id: "$studyUID",
"count": {
"$sum": 1
}
}
}
]);
let numberOfStudyRelatedSeriesObj = {
"vr": "IS",
"Value": [
numberOfStudyRelatedSeries[0]["count"]
]
};
await mongoose.model("dicomStudy").findOneAndUpdate({
studyUID: doc.studyUID
}, {
$set: {
"00201206": numberOfStudyRelatedSeriesObj
}
});
} catch (e) {
throw e;
}
}

async function updateStudyNumberOfStudyRelatedInstance(doc) {
try {
let numberOfStudyRelatedInstance = await mongoose.model("dicom").aggregate([{
$match: {
studyUID: doc.studyUID
}
},
{
$group: {
_id: "$studyUID",
"count": {
"$sum": 1
}
}
}
]);
let numberOfStudyRelatedInstanceObj = {
"vr": "IS",
"Value": [
numberOfStudyRelatedInstance[0]["count"]
]
};
await mongoose.model("dicomStudy").findOneAndUpdate({
studyUID: doc.studyUID
}, {
$set: {
"00201208": numberOfStudyRelatedInstanceObj
}
});
} catch (e) {
throw e;
}
}

let dicomModel = mongoose.model('dicom', dicomModelSchema, 'dicom');
module.exports = dicomModel;
module.exports = dicomModel;

0 comments on commit 4ae378c

Please sign in to comment.