LT-350: remove measurements from the viewport
This commit is contained in:
1 parent
9a11dc1808
commit
98e8cf4eca
9 files changed
+165
-78
No files matched your search
@@ -37,13 +37,37 @@ class MeasurementApi {
|
||||
this.toolsGroupsMap[tool.id] = toolGroup.id;
|
||||
|
||||
const addedHandler = measurement => {
|
||||
let measurementNumber;
|
||||
|
||||
// Get the measurement number
|
||||
const timepoint = this.timepointApi.timepoints.findOne({
|
||||
studyInstanceUids: measurement.studyInstanceUid
|
||||
});
|
||||
const measurementNumber = groupCollection.find({
|
||||
studyInstanceUid: { $in: timepoint.studyInstanceUids }
|
||||
}).count() + 1;
|
||||
|
||||
const emptyItem = groupCollection.findOne({
|
||||
toolId: { $eq: null },
|
||||
timepointId: timepoint.timepointId
|
||||
});
|
||||
|
||||
if (emptyItem) {
|
||||
measurementNumber = emptyItem.measurementNumber;
|
||||
|
||||
groupCollection.update({
|
||||
timepointId: timepoint.timepointId,
|
||||
measurementNumber
|
||||
}, {
|
||||
$set: {
|
||||
toolId: tool.id,
|
||||
toolItemId: measurement._id,
|
||||
createdAt: measurement.createdAt
|
||||
}
|
||||
});
|
||||
} else {
|
||||
measurementNumber = groupCollection.find({
|
||||
studyInstanceUid: { $in: timepoint.studyInstanceUids }
|
||||
}).count() + 1;
|
||||
}
|
||||
|
||||
measurement.measurementNumber = measurementNumber;
|
||||
|
||||
// Get the current location (if already defined)
|
||||
@@ -60,16 +84,6 @@ class MeasurementApi {
|
||||
}
|
||||
}
|
||||
|
||||
// Reflect the entry in the tool group collection
|
||||
groupCollection.insert({
|
||||
toolId: tool.id,
|
||||
toolItemId: measurement._id,
|
||||
timepointId: timepoint.timepointId,
|
||||
studyInstanceUid: measurement.studyInstanceUid,
|
||||
createdAt: measurement.createdAt,
|
||||
measurementNumber
|
||||
});
|
||||
|
||||
// Set the timepoint ID, measurement number and location
|
||||
collection.update(measurement._id, {
|
||||
$set: {
|
||||
@@ -79,39 +93,74 @@ class MeasurementApi {
|
||||
}
|
||||
});
|
||||
|
||||
if (!emptyItem) {
|
||||
// Reflect the entry in the tool group collection
|
||||
groupCollection.insert({
|
||||
toolId: tool.id,
|
||||
toolItemId: measurement._id,
|
||||
timepointId: timepoint.timepointId,
|
||||
studyInstanceUid: measurement.studyInstanceUid,
|
||||
createdAt: measurement.createdAt,
|
||||
measurementNumber
|
||||
});
|
||||
}
|
||||
|
||||
// Enable reactivity
|
||||
this.changeObserver.changed();
|
||||
};
|
||||
|
||||
const removedHandler = measurement => {
|
||||
// Remove the record from the tools group collection too
|
||||
groupCollection.remove({
|
||||
const measurementNumber = measurement.measurementNumber;
|
||||
|
||||
groupCollection.update({
|
||||
toolItemId: measurement._id
|
||||
}, {
|
||||
$set: {
|
||||
toolId: null,
|
||||
toolItemId: null
|
||||
}
|
||||
});
|
||||
|
||||
// Update the measurement numbers only if it is last item
|
||||
const measurementNumber = measurement.measurementNumber;
|
||||
const timepoint = this.timepointApi.timepoints.findOne({
|
||||
timepointId: measurement.timepointId
|
||||
const nonEmptyItem = groupCollection.findOne({
|
||||
measurementNumber,
|
||||
toolId: { $not: null }
|
||||
});
|
||||
const filter = {
|
||||
studyInstanceUid: { $in: timepoint.studyInstanceUids },
|
||||
measurementNumber
|
||||
};
|
||||
const remainingItems = groupCollection.find(filter).count();
|
||||
if (!remainingItems) {
|
||||
filter.measurementNumber = { $gte: measurementNumber };
|
||||
const operator = {
|
||||
$inc: { measurementNumber: -1 }
|
||||
};
|
||||
const options = { multi: true };
|
||||
groupCollection.update(filter, operator, options);
|
||||
toolGroup.childTools.forEach(childTool => {
|
||||
const collection = this.tools[childTool.id];
|
||||
collection.update(filter, operator, options);
|
||||
});
|
||||
|
||||
if (nonEmptyItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
const groupItems = groupCollection.find({ measurementNumber }).fetch();
|
||||
|
||||
groupItems.forEach(groupItem => {
|
||||
// Remove the record from the tools group collection too
|
||||
groupCollection.remove({ _id: groupItem._id });
|
||||
|
||||
// Update the measurement numbers only if it is last item
|
||||
const timepoint = this.timepointApi.timepoints.findOne({
|
||||
timepointId: groupItem.timepointId
|
||||
});
|
||||
|
||||
const filter = {
|
||||
studyInstanceUid: { $in: timepoint.studyInstanceUids },
|
||||
measurementNumber
|
||||
};
|
||||
|
||||
const remainingItems = groupCollection.find(filter).count();
|
||||
if (!remainingItems) {
|
||||
filter.measurementNumber = { $gte: measurementNumber };
|
||||
const operator = {
|
||||
$inc: { measurementNumber: -1 }
|
||||
};
|
||||
const options = { multi: true };
|
||||
groupCollection.update(filter, operator, options);
|
||||
toolGroup.childTools.forEach(childTool => {
|
||||
const collection = this.tools[childTool.id];
|
||||
collection.update(filter, operator, options);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Enable reactivity
|
||||
this.changeObserver.changed();
|
||||
};
|
||||
@@ -258,6 +307,8 @@ class MeasurementApi {
|
||||
// Synchronize the updated measurements with Cornerstone Tools
|
||||
// toolData to make sure the displayed measurements show 'Target X' correctly
|
||||
const syncFilter = _.clone(filter);
|
||||
delete syncFilter.timepointId;
|
||||
|
||||
syncFilter.measurementNumber = {
|
||||
$gt: measurementNumber - 1
|
||||
};
|
||||
@@ -281,7 +332,12 @@ class MeasurementApi {
|
||||
const result = [];
|
||||
const items = this.toolGroups[toolGroupId].find(selector, options).fetch();
|
||||
items.forEach(item => {
|
||||
result.push(this.tools[item.toolId].findOne(item.toolItemId));
|
||||
if(item.toolId) {
|
||||
result.push(this.tools[item.toolId].findOne(item.toolItemId));
|
||||
} else {
|
||||
result.push({ measurementNumber: item.measurementNumber });
|
||||
}
|
||||
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -124,7 +124,6 @@ class TimepointApi {
|
||||
});
|
||||
}
|
||||
|
||||
// Return the prior timepoint
|
||||
lock() {
|
||||
const current = this.current();
|
||||
if (!current) {
|
||||
@@ -138,6 +137,7 @@ class TimepointApi {
|
||||
});
|
||||
}
|
||||
|
||||
// Return the prior timepoint
|
||||
prior() {
|
||||
const current = this.current();
|
||||
if (!current) {
|
||||
|
||||
Reference in new issue
Block a user