Skip to content

Commit

Permalink
refactor: thumbnail process flow
Browse files Browse the repository at this point in the history
- I think we can just use `dicom` schema
to get median instance
- So I remove `getSeriesOfMedianIndex`
- and replace `getInstanceOfMedianIndex`'s args to query object
- that you can pass studyUID, or (studyUID, seriesUID)
- and use sort to make same UID together to get current median instance
  • Loading branch information
Chinlinlee committed May 9, 2023
1 parent c19d8b0 commit dd407c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 35 deletions.
14 changes: 8 additions & 6 deletions api/dicom-web/controller/WADO-RS/service/thumbnail.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,14 @@ class StudyThumbnailFactory extends ThumbnailFactory {
* @param {import("../../../../../utils/typeDef/dicom").Uids} uids
*/
async getThumbnailInstance() {
let medianSeries = await dicomSeriesModel.getSeriesOfMedianIndex(this.uids.studyUID);
if (!medianSeries) return undefined;

let medianInstance = await dicomModel.getInstanceOfMedianIndex(this.uids.studyUID, medianSeries.seriesUID);
let medianInstance = await dicomModel.getInstanceOfMedianIndex({
studyUID: this.uids.studyUID
});
if (!medianInstance) return undefined;

let instanceFramesObj = await renderedService.getInstanceFrameObj({
studyUID: this.uids.studyUID,
seriesUID: medianSeries.seriesUID,
seriesUID: medianInstance.seriesUID,
instanceUID: medianInstance.instanceUID
});

Expand All @@ -131,7 +130,10 @@ class SeriesThumbnailFactory extends ThumbnailFactory {
* @param {import("../../../../../utils/typeDef/dicom").Uids} uids
*/
async getThumbnailInstance() {
let medianInstance = await dicomModel.getInstanceOfMedianIndex(this.uids.studyUID, this.uids.seriesUID);
let medianInstance = await dicomModel.getInstanceOfMedianIndex({
studyUID: this.uids.studyUID,
seriesUID: this.uids.seriesUID
});
if (!medianInstance) return undefined;

let instanceFramesObj = await renderedService.getInstanceFrameObj({
Expand Down
17 changes: 9 additions & 8 deletions models/mongodb/models/dicom.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,21 +402,22 @@ dicomModelSchema.statics.getPathOfInstance = async function(iParam) {
* @param {string} studyUID
* @param {string} seriesUID
*/
dicomModelSchema.statics.getInstanceOfMedianIndex = async function (studyUID, seriesUID) {
let instanceCountOfSeries = await mongoose.model("dicomSeries").countDocuments({
studyUID,
seriesUID
dicomModelSchema.statics.getInstanceOfMedianIndex = async function (query) {
let instanceCountOfStudy = await mongoose.model("dicom").countDocuments({
studyUID: query.studyUID
});

return await mongoose.model("dicom").findOne({
studyUID
}, {
return await mongoose.model("dicom").findOne(query, {
studyUID: 1,
seriesUID: 1,
instanceUID: 1,
instancePath: 1
})
.skip(instanceCountOfSeries >> 1)
.sort({
studyUID: 1,
seriesUID: 1
})
.skip(instanceCountOfStudy >> 1)
.limit(1)
.exec();
};
Expand Down
21 changes: 0 additions & 21 deletions models/mongodb/models/dicomSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,26 +152,6 @@ dicomSeriesSchema.statics.getPathGroupOfInstances = async function(iParam) {
}
};

/**
*
* @param {string} studyUID
*/
dicomSeriesSchema.statics.getSeriesOfMedianIndex = async function (studyUID) {
let seriesCountOfStudy = await mongoose.model("dicomSeries").countDocuments({
studyUID
});

return await mongoose.model("dicomSeries").findOne({
studyUID
}, {
studyUID: 1,
seriesUID: 1
})
.skip(seriesCountOfStudy >> 1)
.limit(1)
.exec();
};


/**
* @typedef { mongoose.Model<dicomSeriesSchema> & {
Expand All @@ -180,7 +160,6 @@ dicomSeriesSchema.statics.getSeriesOfMedianIndex = async function (studyUID) {
* seriesUID: string
* }): Promise<import("../../../utils/typeDef/WADO-RS/WADO-RS.def").ImagePathObj[]>;
* getDicomJson: function(queryOptions: import("../../../utils/typeDef/dicom").DicomJsonMongoQueryOptions): Promise<JSON[]>;
* getSeriesOfMedianIndex: function(studyUID: string): Promise<any>
* }} DicomSeriesModel
*/

Expand Down

0 comments on commit dd407c9

Please sign in to comment.