LT-115: Fixing indexing issues for different tools at same measurement number
This commit is contained in:
parent
0fccb48271
commit
6be83653f8
@ -1,6 +1,5 @@
|
|||||||
import { Mongo } from 'meteor/mongo';
|
import { Mongo } from 'meteor/mongo';
|
||||||
import { _ } from 'meteor/underscore';
|
import { _ } from 'meteor/underscore';
|
||||||
|
|
||||||
import { OHIF } from 'meteor/ohif:core';
|
import { OHIF } from 'meteor/ohif:core';
|
||||||
|
|
||||||
let configuration = {};
|
let configuration = {};
|
||||||
@ -34,15 +33,12 @@ class MeasurementApi {
|
|||||||
collection.attachSchema(tool.schema);
|
collection.attachSchema(tool.schema);
|
||||||
this.tools[tool.id] = collection;
|
this.tools[tool.id] = collection;
|
||||||
|
|
||||||
collection.find().observe({
|
const addedHandler = measurement => {
|
||||||
added: measurement => {
|
|
||||||
const timepoint = this.timepointApi.timepoints.findOne({
|
const timepoint = this.timepointApi.timepoints.findOne({
|
||||||
studyInstanceUids: measurement.studyInstanceUid
|
studyInstanceUids: measurement.studyInstanceUid
|
||||||
});
|
});
|
||||||
const measurementNumber = groupCollection.find({
|
const measurementNumber = groupCollection.find({
|
||||||
studyInstanceUid: {
|
studyInstanceUid: { $in: timepoint.studyInstanceUids }
|
||||||
$in: timepoint.studyInstanceUids
|
|
||||||
}
|
|
||||||
}).count() + 1;
|
}).count() + 1;
|
||||||
measurement.measurementNumber = measurementNumber;
|
measurement.measurementNumber = measurementNumber;
|
||||||
|
|
||||||
@ -61,39 +57,41 @@ class MeasurementApi {
|
|||||||
timepointId: timepoint.timepointId
|
timepointId: timepoint.timepointId
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
removedAt: (measurement, atIndex) => {
|
const removedHandler = measurement => {
|
||||||
|
// Remove the record from the tools group collection too
|
||||||
groupCollection.remove({
|
groupCollection.remove({
|
||||||
toolItemId: measurement._id
|
toolItemId: measurement._id
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Update the measurement numbers only if it is last item
|
||||||
|
const measurementNumber = measurement.measurementNumber;
|
||||||
const timepoint = this.timepointApi.timepoints.findOne({
|
const timepoint = this.timepointApi.timepoints.findOne({
|
||||||
timepointId: measurement.timepointId
|
timepointId: measurement.timepointId
|
||||||
});
|
});
|
||||||
const filter = {
|
const filter = {
|
||||||
studyInstanceUid: {
|
studyInstanceUid: { $in: timepoint.studyInstanceUids },
|
||||||
$in: timepoint.studyInstanceUids
|
measurementNumber
|
||||||
},
|
|
||||||
measurementNumber: {
|
|
||||||
$gt: atIndex
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
const remainingItems = groupCollection.find(filter).count();
|
||||||
|
if (!remainingItems) {
|
||||||
|
filter.measurementNumber = { $gte: measurementNumber };
|
||||||
const operator = {
|
const operator = {
|
||||||
$inc: {
|
$inc: { measurementNumber: -1 }
|
||||||
measurementNumber: -1
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
const options = {
|
const options = { multi: true };
|
||||||
multi: true
|
|
||||||
};
|
|
||||||
|
|
||||||
groupCollection.update(filter, operator, options);
|
groupCollection.update(filter, operator, options);
|
||||||
toolGroup.childTools.forEach(childTool => {
|
toolGroup.childTools.forEach(childTool => {
|
||||||
const collection = this.tools[childTool.id];
|
const collection = this.tools[childTool.id];
|
||||||
collection.update(filter, operator, options);
|
collection.update(filter, operator, options);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
collection.find().observe({
|
||||||
|
added: addedHandler,
|
||||||
|
removed: removedHandler
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user