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,66 +33,65 @@ 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: { $in: timepoint.studyInstanceUids }
|
||||||
studyInstanceUid: {
|
}).count() + 1;
|
||||||
$in: timepoint.studyInstanceUids
|
measurement.measurementNumber = measurementNumber;
|
||||||
}
|
|
||||||
}).count() + 1;
|
|
||||||
measurement.measurementNumber = measurementNumber;
|
|
||||||
|
|
||||||
groupCollection.insert({
|
groupCollection.insert({
|
||||||
toolId: tool.id,
|
toolId: tool.id,
|
||||||
toolItemId: measurement._id,
|
toolItemId: measurement._id,
|
||||||
timepointId: timepoint.timepointId,
|
timepointId: timepoint.timepointId,
|
||||||
studyInstanceUid: measurement.studyInstanceUid,
|
studyInstanceUid: measurement.studyInstanceUid,
|
||||||
createdAt: measurement.createdAt,
|
createdAt: measurement.createdAt,
|
||||||
measurementNumber
|
measurementNumber
|
||||||
});
|
});
|
||||||
|
|
||||||
collection.update(measurement._id, {
|
collection.update(measurement._id, {
|
||||||
$set: {
|
$set: {
|
||||||
measurementNumber,
|
measurementNumber,
|
||||||
timepointId: timepoint.timepointId
|
timepointId: timepoint.timepointId
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
removedAt: (measurement, atIndex) => {
|
const removedHandler = measurement => {
|
||||||
groupCollection.remove({
|
// Remove the record from the tools group collection too
|
||||||
toolItemId: measurement._id
|
groupCollection.remove({
|
||||||
});
|
toolItemId: measurement._id
|
||||||
|
});
|
||||||
|
|
||||||
const timepoint = this.timepointApi.timepoints.findOne({
|
// Update the measurement numbers only if it is last item
|
||||||
timepointId: measurement.timepointId
|
const measurementNumber = measurement.measurementNumber;
|
||||||
});
|
const timepoint = this.timepointApi.timepoints.findOne({
|
||||||
const filter = {
|
timepointId: measurement.timepointId
|
||||||
studyInstanceUid: {
|
});
|
||||||
$in: timepoint.studyInstanceUids
|
const filter = {
|
||||||
},
|
studyInstanceUid: { $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