Measurements and Timepoint interaction in Lesion Table and tools
This commit is contained in:
1 parent
5363880e40
commit
b49c36493e
15 files changed
+300
-383
No files matched your search
@@ -1,203 +1,165 @@
|
||||
var measurementManagerDAL = (function () {
|
||||
var measurementManagerDAL = (function() {
|
||||
var trialPatientLocations = [];
|
||||
var timepoints = [];
|
||||
|
||||
// Returns trialPatientLocations array
|
||||
function getPatientLocations () {
|
||||
function getPatientLocations() {
|
||||
return trialPatientLocations;
|
||||
}
|
||||
|
||||
function getLocationName (locationUID) {
|
||||
for(var i = 0; i< trialPatientLocations.length; i++) {
|
||||
function getLocationName(locationUID) {
|
||||
for (var i = 0; i < trialPatientLocations.length; i++) {
|
||||
var locationObject = trialPatientLocations[i];
|
||||
if(locationObject.uid === locationUID) {
|
||||
if (locationObject.uid === locationUID) {
|
||||
return locationObject.location.location;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
function getTimepoints() {
|
||||
return timepoints;
|
||||
}
|
||||
|
||||
// Adds new location to trialPatientLocations array
|
||||
function addPatientLocation (location) {
|
||||
var contentId = getContentId();
|
||||
function addPatientLocation(location) {
|
||||
var locationUID = uuid.v4();
|
||||
var locationObject = {contentId: contentId, uid: locationUID, location: location};
|
||||
var locationObject = {
|
||||
uid: locationUID,
|
||||
location: location
|
||||
};
|
||||
trialPatientLocations.push(locationObject);
|
||||
|
||||
return locationUID;
|
||||
}
|
||||
|
||||
function getContentId () {
|
||||
return Session.get("activeContentId");
|
||||
}
|
||||
|
||||
function getTimepointsOfTab (){
|
||||
var contentId = getContentId();
|
||||
var tabData = TabsTimepoints.find({contentId: contentId}).fetch();
|
||||
return tabData[0].timepoints;
|
||||
}
|
||||
|
||||
// Add timepoint data to Measurements collection
|
||||
function addTimepointData(lesionData) {
|
||||
var timepoints = Timepoints.find().fetch();
|
||||
var timepointsObject = {};
|
||||
|
||||
var contentId = getContentId();
|
||||
var timepointsOfTab = getTimepointsOfTab();
|
||||
var timepointsArr = [];
|
||||
for(var i=0; i< timepointsOfTab.length; i++) {
|
||||
var timepointId = timepointsOfTab[i].timepointID;
|
||||
for (var i = 0; i < timepoints.length; i++) {
|
||||
var timepointId = timepoints[i].timepointID;
|
||||
var lesionTimepointId = lesionData.timepointID;
|
||||
|
||||
var timepointObject;
|
||||
if (timepointId === lesionTimepointId) {
|
||||
// Add real mesurement
|
||||
var timepointObject = {};
|
||||
timepointObject[timepointId] = {longestDiameter: lesionData.measurementText, imageId: lesionData.imageId};
|
||||
timepointsArr.push(timepointObject);
|
||||
timepointObject = {
|
||||
longestDiameter: lesionData.measurementText,
|
||||
imageId: lesionData.imageId
|
||||
};
|
||||
} else {
|
||||
// Add null measurement
|
||||
var timepointObject = {};
|
||||
timepointObject[timepointId] = {longestDiameter: "", imageId: ""};
|
||||
timepointsArr.push(timepointObject);
|
||||
|
||||
timepointObject = {
|
||||
longestDiameter: "",
|
||||
imageId: ""
|
||||
};
|
||||
}
|
||||
timepointsObject[timepointId] = timepointObject;
|
||||
}
|
||||
|
||||
var lesionDataCollectionObject = {
|
||||
var lesionDataObject = {
|
||||
lesionNumber: lesionData.lesionNumber,
|
||||
isTarget: true,
|
||||
locationUID: lesionData.locationUID,
|
||||
location: getLocationName(lesionData.locationUID),
|
||||
timepoints: timepointsArr
|
||||
timepoints: timepointsObject
|
||||
};
|
||||
|
||||
Measurements.insert({contentId: contentId, lesionData: lesionDataCollectionObject});
|
||||
Measurements.insert(lesionDataObject);
|
||||
}
|
||||
|
||||
// Update timepoint data in Measurements collection
|
||||
function updateTimepointData (lesionData) {
|
||||
var contentId = getContentId();
|
||||
var timepointID = lesionData.timepointID;
|
||||
var tabMeasurements = Measurements.find({contentId: contentId, "lesionData.lesionNumber": lesionData.lesionNumber}).fetch();
|
||||
var tabMeasurementsData = tabMeasurements[0];
|
||||
if (tabMeasurements != undefined && tabMeasurements.length > 0) {
|
||||
|
||||
// Update timepoint
|
||||
var timepointArr = tabMeasurementsData.lesionData.timepoints;
|
||||
for(var i=0; i< timepointArr.length; i++) {
|
||||
var timepoint = timepointArr[i];
|
||||
if(timepoint[timepointID] != undefined) {
|
||||
timepoint[timepointID].longestDiameter = lesionData.measurementText;
|
||||
timepoint[timepointID].imageId = lesionData.imageId;
|
||||
|
||||
}
|
||||
}
|
||||
Measurements.update(
|
||||
{ contentId: contentId, "lesionData.lesionNumber": lesionData.lesionNumber},
|
||||
{
|
||||
$set: {
|
||||
"lesionData.timepoints": timepointArr
|
||||
}
|
||||
}, {multi: true}
|
||||
);
|
||||
function updateTimepointData(lesionData) {
|
||||
// Find the specific lesion to be updated
|
||||
var measurement = Measurements.find({
|
||||
lesionNumber: lesionData.lesionNumber
|
||||
}).fetch()[0];
|
||||
|
||||
// If no such lesion exists, stop here
|
||||
if (!measurement) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update this specific lesion at the given timepoint
|
||||
var timepointID = lesionData.timepointID;
|
||||
|
||||
// Update timepoints from lesion data
|
||||
var timepoints = measurement.timepoints;
|
||||
timepoints[timepointID].longestDiameter = lesionData.measurementText;
|
||||
timepoints[timepointID].imageId = lesionData.imageId;
|
||||
|
||||
Measurements.update({
|
||||
lesionNumber: lesionData.lesionNumber
|
||||
}, {
|
||||
$set: {
|
||||
timepoints: timepoints
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Check timepointData is found in Measurements collection
|
||||
function timepointDataIsFound (lesionNumber) {
|
||||
var contentId = getContentId();
|
||||
var timepointData = Measurements.findOne({contentId: contentId, "lesionData.lesionNumber": lesionNumber});
|
||||
if (timepointData != undefined) {
|
||||
function timepointDataIsFound(lesionNumber) {
|
||||
var timepointData = Measurements.findOne({
|
||||
lesionNumber: lesionNumber
|
||||
});
|
||||
if (timepointData) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Adds new timepoint item to tiemepoints array
|
||||
function addLesionData (lesionData) {
|
||||
if(timepointDataIsFound(lesionData)) {
|
||||
function addLesionData(lesionData) {
|
||||
if (timepointDataIsFound(lesionData)) {
|
||||
// Update data
|
||||
updateTimepointData(lesionData);
|
||||
} else{
|
||||
} else {
|
||||
// Insert data
|
||||
addTimepointData(lesionData);
|
||||
}
|
||||
|
||||
// TODO: This code block will be removed
|
||||
// Populate timepoints array
|
||||
var roi = {
|
||||
uid: lesionData.uid,
|
||||
number: lesionData.lesionNumber,
|
||||
measurement: lesionData.measurementText,
|
||||
locationUID: lesionData.locationUID
|
||||
};
|
||||
if (timepoints.length) {
|
||||
timepoints.forEach(function(timepoint) {
|
||||
if(timepoint.timepointID === timepointID) {
|
||||
timepoint.rois.push(roi);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
timepoints.push({timepointID: timepointID, rois: [roi]});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Returns new lesion number according to timepointID
|
||||
function getNewLesionNumber (timepointID) {
|
||||
var contentId = getContentId();
|
||||
var lesionNumberCounter = 0;
|
||||
var timepointsData = Measurements.find({contentId: contentId}).fetch();
|
||||
if(timepointsData.length > 0) {
|
||||
for(var i=0; i< timepointsData.length; i++) {
|
||||
var timepointData = timepointsData[i];
|
||||
var timepoints = timepointData.lesionData.timepoints;
|
||||
for(var j=0; j< timepoints.length; j++) {
|
||||
var timepoint = timepoints[j];
|
||||
var key = Object.keys(timepoint);
|
||||
if(key == timepointID) {
|
||||
if (timepoint[key].longestDiameter === "") {
|
||||
return timepointData.lesionData.lesionNumber;
|
||||
function getNewLesionNumber(timepointID) {
|
||||
// Get all current lesion measurements
|
||||
var measurements = Measurements.find().fetch();
|
||||
|
||||
} else {
|
||||
lesionNumberCounter = lesionNumberCounter + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(lesionNumberCounter + 1);
|
||||
|
||||
return lesionNumberCounter + 1;
|
||||
// If no measurements exist yet, start at 1
|
||||
if (!measurements.length) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
// If measurements exist, find the last lesion number
|
||||
// from the given timepoint
|
||||
var lesionNumberCounter = 0;
|
||||
for (var i = 0; i < measurements.length; i++) {
|
||||
var measurement = measurements[i];
|
||||
var timepoints = measurement.timepoints;
|
||||
|
||||
if (timepoints[timepointID].longestDiameter === '') {
|
||||
return measurement.lesionNumber;
|
||||
} else {
|
||||
lesionNumberCounter = lesionNumberCounter + 1;
|
||||
}
|
||||
}
|
||||
console.log(lesionNumberCounter + 1);
|
||||
return lesionNumberCounter + 1;
|
||||
}
|
||||
|
||||
// If lesion number is added for any timepoint, returns lesion locationUID
|
||||
function isLesionNumberAdded (lesionNumber) {
|
||||
if (timepointDataIsFound(lesionNumber)){
|
||||
var contentId = getContentId();
|
||||
var timepointData = Measurements.find({contentId: contentId, "lesionData.lesionNumber": lesionNumber}).fetch();
|
||||
return timepointData[0].lesionData.locationUID;
|
||||
|
||||
function isLesionNumberAdded(lesionNumber) {
|
||||
if (!timepointDataIsFound(lesionNumber)) {
|
||||
return;
|
||||
}
|
||||
return null
|
||||
|
||||
var measurement = Measurements.find({
|
||||
lesionNumber: lesionNumber
|
||||
}).fetch()[0];
|
||||
|
||||
return measurement.locationUID;
|
||||
}
|
||||
|
||||
return {
|
||||
addNewLocation: addPatientLocation,
|
||||
getLocations: getPatientLocations,
|
||||
addLesionData: addLesionData,
|
||||
getLesionNumber: getNewLesionNumber,
|
||||
getNewLesionNumber: getNewLesionNumber,
|
||||
isLesionNumberAdded: isLesionNumberAdded,
|
||||
getTimepoints: getTimepoints,
|
||||
updateTimepointData: updateTimepointData
|
||||
|
||||
};
|
||||
})();
|
||||
Reference in new issue
Block a user