Remove some subscription / reactivity / caching bugs and the unnecessary PatientLocations collection

This commit is contained in:
Erik Ziegler committed 2016-02-10 16:38:49 +01:00
1 parent 7d42456f57
commit 9cde04bcfe
43 files changed
+321 -234

No files matched your search

@@ -59,18 +59,53 @@ Template.associationModal.events({
// Sort the study dates, so we can get a range for these values
studyDates = studyDates.sort();
// Create a new timepoint to represent the (baseline or follow-up) studies
var timepoint = {
timepointType: timepointType,
timepointId: uuid.new(),
studyInstanceUids: studyInstanceUids,
patientId: relatedStudies[0].patientId, // TODO: Revisit this (Should timepoints be related to patientId?)
earliestDate: studyDates[0].format('YYYYMMDD'),
latestDate: studyDates[studyDates.length - 1].format('YYYYMMDD')
};
// Check if these studies are already associated with an existing Timepoint
var existingTimepoint;
if (timepointType === 'baseline') {
// If we're trying to associate them to the Baseline, we don't need to
// check if the studyInstanceUids are already associated with anything else
existingTimepoint = Timepoints.findOne({
patientId: relatedStudies[0].patientId,
timepointType: 'baseline'
});
} else {
// If we're trying to associate them to a Follow-up, we should check if any
// of them are already part of a Follow-up (e.g. Follow-up 1), so that
// the rest will also be associated with Follow-up 1.
existingTimepoint = Timepoints.findOne({
patientId: relatedStudies[0].patientId,
studyInstanceUids: {
$in: studyInstanceUids
}
});
}
// Insert this timepoint into the Timepoints Collection
Timepoints.insert(timepoint);
var timepointId;
if (existingTimepoint) {
// If these studies are already associated with an existing Timepoint,
// and the desired timepoint type is the same (e.g. Follow-up), update
// this Timepoint instead of creating a new one
Timepoints.update(existingTimepoint._id, {
$set: {
studyInstanceUids: studyInstanceUids
}
});
timepointId = existingTimepoint.timepointId;
} else {
// Create a new timepoint to represent the (baseline or follow-up) studies
var timepoint = {
timepointType: timepointType,
timepointId: uuid.new(),
studyInstanceUids: studyInstanceUids,
patientId: relatedStudies[0].patientId,
earliestDate: studyDates[0].format('YYYYMMDD'),
latestDate: studyDates[studyDates.length - 1].format('YYYYMMDD')
};
// Insert this timepoint into the Timepoints Collection
Timepoints.insert(timepoint);
timepointId = timepoint.timepointId;
}
// Loop through these studies to associate them with the newly created timepoint
relatedStudies.forEach(function(study) {
@@ -83,7 +118,7 @@ Template.associationModal.events({
// If a study already exists, update the entry with the new timepointId
Studies.update(existingStudy._id, {
$set: {
timepointId: timepoint.timepointId
timepointId: timepointId
}
});
} else {
@@ -93,7 +128,7 @@ Template.associationModal.events({
delete study._id;
// Attach the timepointId and insert it into the Studies Collection
study.timepointId = timepoint.timepointId;
study.timepointId = timepointId;
Studies.insert(study);
}
});
@@ -205,20 +205,6 @@ Template.lesionLocationDialog.events({
_id: selectedOptionId
});
var id;
var existingLocation = PatientLocations.findOne({
location: locationObj.location
});
if (existingLocation) {
id = existingLocation._id;
} else {
// Adds location data to PatientLocation and retrieve the location ID
id = PatientLocations.insert({
location: locationObj.location,
locationId: locationObj._id
});
}
// Add an ID value to the tool data to link it to the Measurements collection
if (!measurementData.id) {
measurementData.id = 'notready';
@@ -226,7 +212,6 @@ Template.lesionLocationDialog.events({
// Link locationUID with active lesion measurementData
measurementData.location = locationObj.location;
measurementData.locationId = locationObj.id;
measurementData.locationUID = id;
/// Set the isTarget value to true, since this is the target-lesion dialog callback
measurementData.isTarget = true;
@@ -241,8 +226,7 @@ Template.lesionLocationDialog.events({
$set: {
location: locationObj.location,
locationId: locationObj.id,
isNodal: locationObj.isNodal,
locationUID: id
isNodal: locationObj.isNodal
}
});
}
@@ -31,10 +31,10 @@ function removeTimepointAssociations() {
return;
}
// Update the Studies Collection to remove the link to this Timepoint
Studies.update(study._id, {
unset: {
timepointId: ''
// Remove this entry from the Studies Collection
Meteor.call('removeAssociatedStudy', study._id, function(error) {
if (error) {
log.warn(error);
}
});
@@ -70,27 +70,28 @@ function getLesionLocationCallback(measurementData, eventData) {
// Find out if this lesion number is already added in the lesion manager for another timepoint
// If it is, disable selector location
var locationUID = LesionManager.lesionNumberExists(measurementData);
if (locationUID) {
var locationId = LesionManager.lesionNumberExists(measurementData);
if (locationId) {
// Add an ID value to the tool data to link it to the Measurements collection
measurementData.id = 'notready';
measurementData.locationUID = locationUID;
measurementData.locationId = locationId;
// Disable the selection of a new location
disableLocationSelection(measurementData.locationUID);
disableLocationSelection(measurementData.locationId);
}
// Disable selector location to prevent selecting a new location
function disableLocationSelection(locationUID) {
var locationName = LesionManager.getLocationName(locationUID);
selectorLocation.find('option').each(function() {
if ($(this).text() === locationName) {
// Select location in locations dropdown list
selectorLocation.find('option').eq($(this).index()).prop('selected', true);
}
});
function disableLocationSelection(locationId) {
var locationObject = LesionLocations.findOne({
id: locationId
});
if (!locationObject) {
return;
}
selectorLocation.find('option[value="' + locationObject._id + '"]').prop('selected', true);
selectorLocation.prop('disabled', true);
}
@@ -273,26 +274,12 @@ Template.nonTargetLesionDialog.events({
_id: selectedOptionId
});
var id;
var existingLocation = PatientLocations.findOne({
location: locationObj.location
});
if (existingLocation) {
id = existingLocation._id;
} else {
// Adds location data to PatientLocation and retrieve the location ID
id = PatientLocations.insert({
location: locationObj.location
});
}
if (measurementData.id) {
// Update the location data
Measurements.update(measurementData.id, {
$set: {
location: locationObj.location,
locationId: locationObj.id,
locationUID: id
}
});
} else {
@@ -300,9 +287,6 @@ Template.nonTargetLesionDialog.events({
measurementData.id = 'notready';
}
// Link locationUID with active lesion measurementData
measurementData.locationUID = id;
/// Set the isTarget value to true, since this is the target-lesion dialog callback
measurementData.isTarget = false;
@@ -76,12 +76,7 @@ Template.studyDateList.events({
var loadingIndicator = selectBox.siblings('.loading');
loadingIndicator.css('display', 'block');
Meteor.call('GetStudyMetadata', studyInstanceUid, function(error, study) {
if (error) {
log.warn(error);
return;
}
getStudyMetadata(studyInstanceUid, function(study) {
sortStudy(study);
// Hide the loading indicator
@@ -1,12 +0,0 @@
<template name="timepointTextDialog">
<div id="timepointTextDialog">
<div class="timepointDialogContentWrapper">
<div class="dialogContent">
<div class="timepointContent">
<input type="checkbox" id="checkBoxBaseline" value="ok">
<label for="checkBoxBaseline">Baseline</label>
</div>
</div>
</div>
</div>
</template>
@@ -1,25 +0,0 @@
#timepointTextDialog
display: none
position: absolute
z-index: 99
.timepointDialogContentWrapper
position: absolute
width: 100px
height: 30px
padding: 5px
background-color: rgba(255,255,255,1)
border-top-left-radius: 5px
border-top-right-radius: 5px
.dialogContent
margin: 0 auto
float: none
padding: 0
.timepointContent
font-size: 16px
#checkBoxBaseline
height: 16px
width: 16px