LT-293: send proper timepoint id to server when removing an association and update the view, removing this associations

This commit is contained in:
Eloízio Salgado 2016-11-10 16:49:20 -02:00 committed by Erik Ziegler
parent 998cdce9fb
commit 987be26047
5 changed files with 90 additions and 23 deletions

View File

@ -1,7 +1,7 @@
import { OHIF } from 'meteor/ohif:core';
import { measurementTools } from './measurementTools';
import { retrieveMeasurements, storeMeasurements, retrieveTimepoints, storeTimepoints } from './dataExchange';
import { retrieveMeasurements, storeMeasurements, retrieveTimepoints, storeTimepoints, removeTimepoint, updateTimepoint } from './dataExchange';
import { validateMeasurements } from './dataValidation';
console.log('OHIF-LesionTracker: Defining Configuration for Measurements');
@ -26,6 +26,8 @@ OHIF.measurements.MeasurementApi.setConfiguration({
OHIF.measurements.TimepointApi.setConfiguration({
dataExchange: {
retrieve: retrieveTimepoints,
store: storeTimepoints
store: storeTimepoints,
remove: removeTimepoint,
update: updateTimepoint
}
});

View File

@ -64,3 +64,34 @@ export const storeTimepoints = (timepointData) => {
});
});
};
export const updateTimepoint = (timepointData, query) => {
console.log('updateTimepoint');
console.log(timepointData);
console.log(query);
return new Promise((resolve, reject) => {
Meteor.call('updateTimepoint', timepointData, query, (error, response) => {
if (error) {
reject(error);
} else {
resolve(response);
}
});
});
};
export const removeTimepoint = timepointData => {
console.log('removeTimepoint');
console.log(timepointData);
return new Promise((resolve, reject) => {
Meteor.call('removeTimepoint', timepointData, (error, response) => {
if (error) {
reject(error);
} else {
resolve(response);
}
});
});
};

View File

@ -37,6 +37,19 @@ Meteor.methods({
});
},
removeTimepoint(timepointData) {
OHIF.log.info('Removing Timepoint off the Server');
OHIF.log.info(JSON.stringify(timepointData, null, 2));
Timepoints.remove(timepointData);
},
updateTimepoint(timepointData, query) {
OHIF.log.info('Updating Timepoint on the Server');
OHIF.log.info(JSON.stringify(timepointData, null, 2));
OHIF.log.info(JSON.stringify(query, null, 2));
Timepoints.update(timepointData, query);
},
retrieveTimepoints(filter) {
OHIF.log.info('Retrieving Timepoints from the Server');
return Timepoints.find(filter || {}).fetch();

View File

@ -59,6 +59,45 @@ class TimepointApi {
storeFn(timepointData).then(() => OHIF.log.info('Timepoint storage completed'));
}
removeTimepoint(timepointId) {
const removeFn = configuration.dataExchange.remove;
if (!_.isFunction(removeFn)) {
return;
}
const timepointData = {
timepointId
};
OHIF.log.info('Preparing to remove timepoint');
OHIF.log.info(JSON.stringify(timepointData, null, 2));
removeFn(timepointData).then(() => {
OHIF.log.info('Timepoint removal completed');
this.timepoints.remove(timepointData);
});
}
updateTimepoint(timepointId, query) {
const updateFn = configuration.dataExchange.update;
if (!_.isFunction(updateFn)) {
return;
}
const timepointData = {
timepointId
};
OHIF.log.info('Preparing to update timepoint');
OHIF.log.info(JSON.stringify(timepointData, null, 2));
OHIF.log.info(JSON.stringify(query, null, 2));
updateFn(timepointData, query).then(() => {
OHIF.log.info('Timepoint updated completed');
this.timepoints.update(timepointData, query);
});
}
// Return all timepoints
all() {
return this.timepoints.find().fetch();

View File

@ -25,7 +25,7 @@ function removeTimepointAssociations() {
// Loop through the Cursor of Selected Studies
selectedStudies.forEach(function(selectedStudy) {
// Find the Timepoint that was previously referenced
const timepointApi = Template.instance().timepointApi;
const timepointApi = StudyList.timepointApi;
if (!timepointApi) {
return;
}
@ -49,7 +49,7 @@ function removeTimepointAssociations() {
if (timepoint.studyInstanceUids.length) {
// Update the Timepoints Collection with this modified array for the
// studyInstanceUids attribute
Timepoints.update(timepoint._id, {
timepointApi.updateTimepoint(timepoint.timepointId, {
$set: {
studyInstanceUids: timepoint.studyInstanceUids
}
@ -68,25 +68,7 @@ function removeTimepointAssociations() {
HipaaLogger.logEvent(hipaaEvent);
} else {
// If no more Studies are associated with this Timepoint, we should remove it
// from the Timepoints Collection via a server call
Meteor.call('removeTimepoint', timepoint._id, function(error) {
if (error) {
OHIF.log.warn(error);
return;
}
// Log
const hipaaEvent = {
eventType: 'delete',
userId: Meteor.userId(),
userName: Meteor.user().profile.fullName,
collectionName: 'Timepoints',
recordId: selectedStudy.timepointId,
patientId: selectedStudy.patientId,
patientName: selectedStudy.patientName
};
HipaaLogger.logEvent(hipaaEvent);
});
timepointApi.removeTimepoint(timepoint.timepointId);
}
});
}