diff --git a/Packages/ohif-hanging-protocols/client/components/protocolEditor/protocolEditor.js b/Packages/ohif-hanging-protocols/client/components/protocolEditor/protocolEditor.js index fb137cbd0..b49446c10 100644 --- a/Packages/ohif-hanging-protocols/client/components/protocolEditor/protocolEditor.js +++ b/Packages/ohif-hanging-protocols/client/components/protocolEditor/protocolEditor.js @@ -107,7 +107,7 @@ Template.protocolEditor.helpers({ } // Retrieve the Stage Model for the current Protocol's active Stage - const stage = ProtocolEngine.getCurrentStageModel(); + var stage = ProtocolEngine.getCurrentStageModel(); if (!stage) { return; } @@ -123,14 +123,14 @@ Template.protocolEditor.helpers({ // by removing or adding Viewports to the stage // // First, calculate the difference, if any exists - const difference = stage.viewportStructure.getNumViewports() - stage.viewports.length; + var difference = stage.viewportStructure.getNumViewports() - stage.viewports.length; if (difference < 0) { // Make the viewport difference into a positive value - const absDifference = Math.abs(difference); + var absDifference = Math.abs(difference); // If there are more Viewports defined than necessary, remove the extraneous Viewports - const position = stage.viewports.length - absDifference; + var position = stage.viewports.length - absDifference; // Splice extra viewports from the Stage's viewports array stage.viewports.splice(position, absDifference); @@ -139,9 +139,9 @@ Template.protocolEditor.helpers({ // required amount // Count up until the difference in number of Viewports - for (let i = 0; i < difference; i++) { + for (var i = 0; i < difference; i++) { // Instantiate a new Viewport Model - const viewport = new HP.Viewport(); + var viewport = new HP.Viewport(); // Add new Viewports to the Stage's viewports array stage.viewports.push(viewport); @@ -163,7 +163,7 @@ Template.protocolEditor.events({ */ 'click #newProtocol'() { // Clone the default Protocol - const protocol = HP.defaultProtocol.createClone(); + var protocol = HP.defaultProtocol.createClone(); // Change the Protocol name to state that it is New, and give it a timestamp protocol.name = 'New (created ' + moment().format('h:mm:ss a') + ')'; @@ -184,19 +184,19 @@ Template.protocolEditor.events({ * Rename the current Protocol */ 'click #renameProtocol'() { - const selectedProtocol = this; + var selectedProtocol = this; if (selectedProtocol.locked) { return; } // Define some details for the text entry dialog - const title = 'Rename Protocol'; - const instructions = 'Enter a new name'; - const currentValue = selectedProtocol.name; + var title = 'Rename Protocol'; + var instructions = 'Enter a new name'; + var currentValue = selectedProtocol.name; // Open the text entry dialog with the details above // and fire the callback function when finished. - openTextEntryDialog(title, instructions, currentValue, value => { + openTextEntryDialog(title, instructions, currentValue, function(value) { // Update the name with the entered text selectedProtocol.name = value; @@ -220,17 +220,17 @@ Template.protocolEditor.events({ * * @param event The Change event for the input */ - 'change .btn-file :file'(event) { + 'change .btn-file :file': function(event) { // http://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-bootstrap-3/ // Find the Input in the DOM - const input = $(event.currentTarget); + var input = $(event.currentTarget); // Get the number of selected files - const numFiles = input.get(0).files ? input.get(0).files.length : 1; + var numFiles = input.get(0).files ? input.get(0).files.length : 1; // Get the label of the file - const label = input.val().replace(/\\/g, '/').replace(/.*\//, ''); + var label = input.val().replace(/\\/g, '/').replace(/.*\//, ''); // Trigger our custom event with the number of files and label input.trigger('fileselect', [numFiles, label]); @@ -240,15 +240,15 @@ Template.protocolEditor.events({ * * @param event The custom fileselect event */ - 'fileselect .btn-file :file'(event) { + 'fileselect .btn-file :file': function(event) { // Retreieve the FileList - const files = event.target.files; + var files = event.target.files; // Create an HTML5 File Reader - const reader = new FileReader(); + var reader = new FileReader(); reader.onload = () => { - const protocolToImport = JSON.parse(reader.result); + var protocolToImport = JSON.parse(reader.result); // Insert the protocol HP.ProtocolStore.addProtocol(protocolToImport); @@ -266,14 +266,12 @@ Template.protocolEditor.events({ * * @param event The select2:select event */ - 'select2:select #protocolSelect'(event) { + 'select2:select #protocolSelect': function(event) { // Retrieve the protocolId - const protocolId = event.params.data.id; + var protocolId = event.params.data.id; - // Retrieve the Protocol from the HangingProtocols Collection - const selectedProtocol = HangingProtocols.findOne({ - id: protocolId - }); + // Retrieve the protocol from the protocol store + var selectedProtocol = HP.ProtocolStore.getProtocol(protocolId); // If it doesn't exist, stop here if (!selectedProtocol) { @@ -291,85 +289,92 @@ Template.protocolEditor.events({ $(this).addClass('active').siblings().removeClass('active'); }, /** - * Update the HangingProtocols Collection with the latest changes to the current Protocol + * Update the protocol with the latest changes to the current Protocol */ 'click #saveProtocol'() { - const selectedProtocol = this; + var selectedProtocol = this; if (selectedProtocol.locked) { return; } - // Store the ID for the update call - const id = selectedProtocol._id; - - // Remove the MongoDB _id property so that we can - // simplify the $set value - delete selectedProtocol._id; - // Update the Protocol's modifiedDate and modifiedBy User details selectedProtocol.protocolWasModified(); // Update the current Protocol in the database with the latest changes - HangingProtocols.update(id, { - $set: selectedProtocol - }); + HP.ProtocolStore.updateProtocol(selectedProtocol.id, selectedProtocol); }, /** - * Save the current Protocol as a new document in the HangingProtocols Collection + * Save the current Protocol as a new document */ 'click #saveAsProtocol'() { - const selectedProtocol = this; + var selectedProtocol = this; + + // Clone the selected Protocol + var protocol = selectedProtocol.createClone(); // Define some details for the text entry dialog - const title = 'Save Protocol As'; - const instructions = 'Enter a new name'; - const currentValue = selectedProtocol.name; + var title = 'Save Protocol As'; + var instructions = 'Enter a new name'; + var currentValue = protocol.name; // Open the text entry dialog with the details above // and fire the callback function when finished. - openTextEntryDialog(title, instructions, currentValue, value => { - // Erase the MongoDB _id - delete selectedProtocol._id; - + openTextEntryDialog(title, instructions, currentValue, function(value) { // Create a new ID for the protocol - selectedProtocol.id = Random.id(); + protocol.id = Random.id(); // Update the name with the entered text - selectedProtocol.name = value; + protocol.name = value; + + // Unlock the protocol + protocol.locked = false; // Update the Protocol's modifiedDate and modifiedBy User details - selectedProtocol.protocolWasModified(); + protocol.protocolWasModified(); // Insert the new Protocol - HangingProtocols.insert(selectedProtocol); + HP.ProtocolStore.addProtocol(protocol); + + // Activate the new Protocol using the ProtocolEngine + ProtocolEngine.setHangingProtocol(protocol); + + // Update the protocol selector to display the new Protocols + updateProtocolSelect(); }); }, /** * Export the currently selected Protocol as a JSON file */ 'click #exportJSON'() { - // Tell the User's Browser to download the JSON file by routing a hidden iframe to our - // protocol-export Route. This prevents the tab from changing its current content. - const selectedProtocol = this; - document.getElementById('download_iframe').src = '/protocol-export/' + selectedProtocol.id; + var selectedProtocol = this; + + var protocolJSON = JSON.stringify(selectedProtocol, null, 2), + currentDate = new Date(), + filename = selectedProtocol.name + '-' + (currentDate.getTime().toString()) + '.json', + protocolBlob = new Blob([protocolJSON], { type: 'application/json' }); + + var downloadElement = document.getElementById('downloadElement'); + downloadElement.href = URL.createObjectURL(protocolBlob); + downloadElement.download = filename; + downloadElement.click(); }, /** * Delete the currently selected Protocol */ 'click #deleteProtocol'() { - const selectedProtocol = this; + var selectedProtocol = this; if (selectedProtocol.locked) { return; } - const options = { + var options = { title: 'Delete Protocol', text: 'Are you sure you would like to remove this Protocol? This cannot be reversed.' }; OHIF.viewerbase.showConfirmDialog(() => { - // Send a call to remove the Protocol from the HangingProtocols Collection on the server - Meteor.call('removeHangingProtocol', selectedProtocol._id); + // Remove the Protocol + HP.ProtocolStore.removeProtocol(selectedProtocol.id); // Reset the ProtocolEngine to the next best match ProtocolEngine.reset(); diff --git a/Packages/ohif-hanging-protocols/client/components/ruleEntryDialog/ruleEntryDialog.js b/Packages/ohif-hanging-protocols/client/components/ruleEntryDialog/ruleEntryDialog.js index 49f2b334e..640afd0a5 100644 --- a/Packages/ohif-hanging-protocols/client/components/ruleEntryDialog/ruleEntryDialog.js +++ b/Packages/ohif-hanging-protocols/client/components/ruleEntryDialog/ruleEntryDialog.js @@ -17,7 +17,7 @@ const keys = { * * @param dialog The DOM element of the dialog to close */ -const closeHandler = dialog => { +function closeHandler(dialog) { // Hide the lesion dialog $(dialog).css('display', 'none'); @@ -26,7 +26,7 @@ const closeHandler = dialog => { // Restore the focus to the active viewport Viewerbase.setFocusToActiveViewport(); -}; +} /** * Displays and updates the UI of the Rule Entry Dialog given a new set of @@ -39,10 +39,10 @@ const closeHandler = dialog => { */ openRuleEntryDialog = function(attributes, level, rule) { // Get the lesion location dialog - const dialog = $('.ruleEntryDialog'); + var dialog = $('.ruleEntryDialog'); // Clear any input that is still on the page - const currentValueInput = dialog.find('input.currentValue'); + var currentValueInput = dialog.find('input.currentValue'); currentValueInput.val(''); // Store the Dialog DOM data, rule level and rule in the template data @@ -51,7 +51,7 @@ openRuleEntryDialog = function(attributes, level, rule) { Template.ruleEntryDialog.rule = rule; // Initialize the Select2 search box for the attribute list - const attributeSelect = dialog.find('.attributes'); + var attributeSelect = dialog.find('.attributes'); attributeSelect.html('').select2({ data: attributes, placeholder: 'Select an attribute', @@ -70,15 +70,15 @@ openRuleEntryDialog = function(attributes, level, rule) { // If a rule has been provided, use its constraint to find the relevant Comparator if (rule && rule.constraint) { - const validator = Object.keys(rule.constraint)[0]; - const validatorOption = Object.keys(rule.constraint[validator])[0]; - const comparator = Comparators.findOne({ + var validator = Object.keys(rule.constraint)[0]; + var validatorOption = Object.keys(rule.constraint[validator])[0]; + var comparator = Comparators.findOne({ validator: validator, validatorOption: validatorOption }); // Set the current value input based on the rule constraint - const currentValue = rule.constraint[validator][validatorOption]; + var currentValue = rule.constraint[validator][validatorOption]; currentValueInput.val(currentValue); } @@ -93,10 +93,10 @@ openRuleEntryDialog = function(attributes, level, rule) { dialog.css('display', 'block'); // Show the backdrop - Blaze.render(Template.removableBackdrop, document.body); + UI.render(Template.removableBackdrop, document.body); // Make sure the context menu is closed when the user clicks away - $('.removableBackdrop').one('mousedown touchstart', () => { + $('.removableBackdrop').one('mousedown touchstart', function() { closeHandler(dialog); }); }; @@ -106,23 +106,23 @@ openRuleEntryDialog = function(attributes, level, rule) { */ function getActiveViewportImageId() { // Retrieve the active viewport index from the Session - const activeViewport = Session.get('activeViewport'); + var activeViewport = Session.get('activeViewport'); if (activeViewport === undefined) { return; } // Obtain the list of all Viewports on the page - const viewports = $('.imageViewerViewport'); + var viewports = $('.imageViewerViewport'); // Retrieve the active viewport element - const element = viewports.get(activeViewport); + var element = viewports.get(activeViewport); if (!element) { return; } // Obtain the enabled element from Cornerstone try { - const enabledElement = cornerstone.getEnabledElement(element); + var enabledElement = cornerstone.getEnabledElement(element); if (!enabledElement) { return; } @@ -143,6 +143,10 @@ function getAbstractPriorValue(imageId) { sort: [ ['studyDate', 'desc'] ] }); + if (!currentStudy) { + return; + } + const priorStudy = cornerstoneTools.metaData.get('study', imageId); if (!priorStudy) { return; @@ -180,7 +184,7 @@ function getAbstractPriorValue(imageId) { */ function getCurrentAttributeValue(attribute, level) { // Retrieve the active viewport's imageId. If none exists, stop here - const imageId = getActiveViewportImageId(); + var imageId = getActiveViewportImageId(); if (!imageId) { return; } @@ -197,7 +201,7 @@ function getCurrentAttributeValue(attribute, level) { // Retrieve the metadata values for the specified level from // the Cornerstone Tools metaData provider - const metadata = cornerstoneTools.metaData.get(level, imageId); + var metadata = cornerstoneTools.metaData.get(level, imageId); if (metadata[attribute] === undefined) { return HP.attributeDefaults[attribute]; @@ -208,7 +212,7 @@ function getCurrentAttributeValue(attribute, level) { Template.ruleEntryDialog.onCreated(function() { // Define the ReactiveVars that will be used to link aspects of the UI - const template = this; + var template = this; // Note: currentValue's initial value must be a string so the template renders properly template.currentValue = new ReactiveVar(''); template.attribute = new ReactiveVar(); @@ -217,12 +221,12 @@ Template.ruleEntryDialog.onCreated(function() { Template.ruleEntryDialog.onRendered(function() { // Initialize the Comparators Select2 box - const template = Template.instance(); + var template = Template.instance(); template.$('.comparators').select2(); // Get the default Comparator from the Select2 box and use it to // initialize the comparatorId ReactiveVar - const comparatorId = template.$('.comparators').val(); + var comparatorId = template.$('.comparators').val(); template.comparatorId.set(comparatorId); const dialog = template.$('.ruleEntryDialog'); @@ -233,7 +237,7 @@ Template.ruleEntryDialog.helpers({ /** * Returns the Comparators Collection to the Template with reactive rerendering */ - comparators() { + comparators: function() { return Comparators.find(); }, /** @@ -241,7 +245,7 @@ Template.ruleEntryDialog.helpers({ * * @returns {*} Attribute value for the active image */ - currentValue() { + currentValue: function() { return Template.instance().currentValue.get(); } }); @@ -253,15 +257,15 @@ Template.ruleEntryDialog.events({ * @param event the Click event * @param template The template context */ - 'click #save'(event, template) { + 'click #save': function(event, template) { // Retrieve the input properties to the template - const dialog = Template.ruleEntryDialog.dialog; - const level = Template.ruleEntryDialog.level; + var dialog = Template.ruleEntryDialog.dialog; + var level = Template.ruleEntryDialog.level; // Retrieve the current values for the attribute value and comparatorId - const attribute = template.attribute.get(); - const comparatorId = template.comparatorId.get(); - const currentValue = template.currentValue.get(); + var attribute = template.attribute.get(); + var comparatorId = template.comparatorId.get(); + var currentValue = template.currentValue.get(); // If currentValue input is undefined, prevent saving this rule if (currentValue === undefined) { @@ -269,14 +273,14 @@ Template.ruleEntryDialog.events({ } // Check if we are editing a rule or creating a new one - let rule; + var rule; if (Template.ruleEntryDialog.rule) { // If we are editing a rule, change the rule data rule = Template.ruleEntryDialog.rule; } else { // If we are creating a rule, obtain the active Viewport model // from the Protocol and Stage - const viewport = getActiveViewportModel(); + var viewport = getActiveViewportModel(); // Create a rule depending on the level property of this dialog switch (level) { @@ -300,12 +304,12 @@ Template.ruleEntryDialog.events({ } // Find the Comparator from the Comparators Collection given its ID - const comparator = Comparators.findOne({ + var comparator = Comparators.findOne({ id: comparatorId }); // Create a new constraint to add to the rule - const constraint = {}; + var constraint = {}; constraint[comparator.validator] = {}; constraint[comparator.validator][comparator.validatorOption] = currentValue; @@ -314,7 +318,7 @@ Template.ruleEntryDialog.events({ rule.constraint = constraint; // Instruct the Protocol Engine to update the Layout Manager with new data - const viewportIndex = Session.get('activeViewport'); + var viewportIndex = Session.get('activeViewport'); ProtocolEngine.updateViewports(viewportIndex); // Close the dialog @@ -323,8 +327,8 @@ Template.ruleEntryDialog.events({ /** * Allow the user to click the Cancel button to close the dialog */ - 'click #cancel'() { - const dialog = Template.ruleEntryDialog.dialog; + 'click #cancel': function() { + var dialog = Template.ruleEntryDialog.dialog; closeHandler(dialog); }, /** @@ -333,8 +337,8 @@ Template.ruleEntryDialog.events({ * @param event The Keydown event details * @returns {boolean} Return false to prevent bubbling of the event */ - 'keydown .ruleEntryDialog'(event) { - const dialog = Template.ruleEntryDialog.dialog; + 'keydown .ruleEntryDialog': function(event) { + var dialog = Template.ruleEntryDialog.dialog; // If Esc key is pressed, close the dialog if (event.which === keys.ESC) { @@ -348,9 +352,9 @@ Template.ruleEntryDialog.events({ * @param event The Change event for the select box * @param template The current template context */ - 'change select.attributes'(event, template) { + 'change select.attributes': function(event, template) { // Obtain the user-specified attribute to test against - const attribute = $(event.currentTarget).val(); + var attribute = $(event.currentTarget).val(); // Store it in the ReactiveVar template.attribute.set(attribute); @@ -359,10 +363,10 @@ Template.ruleEntryDialog.events({ Template.ruleEntryDialog.selectedAttribute = attribute; // Get the level of this dialog - const level = Template.ruleEntryDialog.level; + var level = Template.ruleEntryDialog.level; // Retrieve the current value of the attribute for the active viewport model - const value = getCurrentAttributeValue(attribute, level); + var value = getCurrentAttributeValue(attribute, level); // Update the ReactiveVar with the user-specified value template.currentValue.set(value); @@ -373,12 +377,12 @@ Template.ruleEntryDialog.events({ * @param event The Change event for the input * @param template The current template context */ - 'change input.currentValue'(event, template) { + 'change input.currentValue': function(event, template) { // Get the DOM element representing the input box - const input = $(event.currentTarget); + var input = $(event.currentTarget); // Get the current value of the input - let value = input.val(); + var value = input.val(); // If the input is of type 'number', parse it as a Float if (input.attr('type') === 'number') { @@ -394,9 +398,9 @@ Template.ruleEntryDialog.events({ * @param event The Change event for the select box * @param template The current template context */ - 'change select.comparators'(event, template) { + 'change select.comparators': function(event, template) { // Get the current value of the select box - const comparatorId = $(event.currentTarget).val(); + var comparatorId = $(event.currentTarget).val(); // Update the ReactiveVar with the value of the Comparators select box template.comparatorId.set(comparatorId); diff --git a/Packages/ohif-hanging-protocols/client/components/settingEntryDialog/settingEntryDialog.js b/Packages/ohif-hanging-protocols/client/components/settingEntryDialog/settingEntryDialog.js index 4a16bb26e..fb91b4e8b 100644 --- a/Packages/ohif-hanging-protocols/client/components/settingEntryDialog/settingEntryDialog.js +++ b/Packages/ohif-hanging-protocols/client/components/settingEntryDialog/settingEntryDialog.js @@ -16,7 +16,7 @@ const keys = { * * @param dialog The DOM element of the dialog to close */ -const closeHandler = dialog => { +function closeHandler(dialog) { // Hide the lesion dialog $(dialog).css('display', 'none'); @@ -25,7 +25,7 @@ const closeHandler = dialog => { // Restore the focus to the active viewport Viewerbase.setFocusToActiveViewport(); -}; +} /** * Displays and updates the UI of the Setting Entry Dialog given an @@ -35,40 +35,40 @@ const closeHandler = dialog => { */ openSettingEntryDialog = function(settingObject) { // Get the lesion location dialog - const dialog = $('.settingEntryDialog'); + var dialog = $('.settingEntryDialog'); // Store the Dialog DOM data, setting level and setting in the template data Template.settingEntryDialog.dialog = dialog; Template.settingEntryDialog.settingObject = settingObject; // Initialize the Select2 search box for the attribute list - const settings = Object.keys(HP.displaySettings); + var settings = Object.keys(HP.displaySettings); settings.concat(Object.keys(HP.CustomViewportSettings)); - const displaySettingsOptions = Object.keys(HP.displaySettings).map(key => { + var displaySettingsOptions = Object.keys(HP.displaySettings).map(key => { return { id: key, text: HP.displaySettings[key].text }; }); - const customSettingsOptions = Object.keys(HP.CustomViewportSettings).map(key => { + var customSettingsOptions = Object.keys(HP.CustomViewportSettings).map(key => { return { id: key, text: HP.CustomViewportSettings[key].text }; }); - const settingsOptions = displaySettingsOptions.concat(customSettingsOptions); + var settingsOptions = displaySettingsOptions.concat(customSettingsOptions); - const settingSelect = dialog.find('.settings'); + var settingSelect = dialog.find('.settings'); settingSelect.html('').select2({ data: settingsOptions, placeholder: 'Select a setting', allowClear: true }); - let settingDetails = { + var settingDetails = { options: [] }; @@ -78,7 +78,7 @@ openSettingEntryDialog = function(settingObject) { settingDetails = HP.CustomViewportSettings[settingObject.id]; } - const valueSelect = dialog.find('.currentValue'); + var valueSelect = dialog.find('.currentValue'); valueSelect.html('').select2({ data: settingDetails.options, placeholder: 'Select a value', @@ -107,14 +107,14 @@ openSettingEntryDialog = function(settingObject) { Blaze.render(Template.removableBackdrop, document.body); // Make sure the context menu is closed when the user clicks away - $('.removableBackdrop').one('mousedown touchstart', () => { + $('.removableBackdrop').one('mousedown touchstart', function() { closeHandler(dialog); }); }; Template.settingEntryDialog.onCreated(function() { // Define the ReactiveVars that will be used to link aspects of the UI - const template = this; + var template = this; // Note: currentValue's initial value must be a string so the template renders properly template.currentValue = new ReactiveVar(''); @@ -134,29 +134,29 @@ Template.settingEntryDialog.events({ * @param event the Click event * @param template The template context */ - 'click #save'(event, template) { + 'click #save': function(event, template) { // Retrieve the input properties to the template - const dialog = Template.settingEntryDialog.dialog; + var dialog = Template.settingEntryDialog.dialog; // Retrieve the current values for the id and current value - const setting = template.setting.get(); - const currentValue = template.currentValue.get(); + var setting = template.setting.get(); + var currentValue = template.currentValue.get(); // If currentValue input is undefined, prevent saving this setting if (currentValue === undefined) { return; } - const viewportSetting = { + var viewportSetting = { id: setting, value: currentValue }; // Obtain the active Viewport model from the Protocol and Stage - const viewport = getActiveViewportModel(); + var viewport = getActiveViewportModel(); // Remove any old rules if the ID has been changes - const originalSettingObject = Template.settingEntryDialog.settingObject; + var originalSettingObject = Template.settingEntryDialog.settingObject; if (originalSettingObject && originalSettingObject.id) { delete viewport.viewportSettings[originalSettingObject.id]; } @@ -165,7 +165,7 @@ Template.settingEntryDialog.events({ viewport.viewportSettings[viewportSetting.id] = viewportSetting.value; // Instruct the Protocol Engine to update the Layout Manager with new data - const viewportIndex = Session.get('activeViewport'); + var viewportIndex = Session.get('activeViewport'); ProtocolEngine.updateViewports(viewportIndex); // Close the dialog @@ -174,8 +174,8 @@ Template.settingEntryDialog.events({ /** * Allow the user to click the Cancel button to close the dialog */ - 'click #cancel'() { - const dialog = Template.settingEntryDialog.dialog; + 'click #cancel': function() { + var dialog = Template.settingEntryDialog.dialog; closeHandler(dialog); }, /** @@ -184,8 +184,8 @@ Template.settingEntryDialog.events({ * @param event The Keydown event details * @returns {boolean} Return false to prevent bubbling of the event */ - 'keydown .settingEntryDialog'(event) { - const dialog = Template.settingEntryDialog.dialog; + 'keydown .settingEntryDialog': function(event) { + var dialog = Template.settingEntryDialog.dialog; // If Esc key is pressed, close the dialog if (event.which === keys.ESC) { @@ -199,15 +199,15 @@ Template.settingEntryDialog.events({ * @param event The Change event for the select box * @param template The current template context */ - 'change select.settings'(event, template) { + 'change select.settings': function(event, template) { // Obtain the user-specified attribute to test against - const settingId = $(event.currentTarget).val(); + var settingId = $(event.currentTarget).val(); // Store it in the ReactiveVar template.setting.set(settingId); // Retrieve the current value from the attribute - let settingDetails = { + var settingDetails = { options: [] }; if (settingId && HP.displaySettings[settingId]) { @@ -216,8 +216,8 @@ Template.settingEntryDialog.events({ settingDetails = HP.CustomViewportSettings[settingId]; } - const dialog = Template.settingEntryDialog.dialog; - const valueSelect = dialog.find('.currentValue'); + var dialog = Template.settingEntryDialog.dialog; + var valueSelect = dialog.find('.currentValue'); valueSelect.html('').select2({ data: settingDetails.options, placeholder: 'Select a value', @@ -236,9 +236,9 @@ Template.settingEntryDialog.events({ * @param event The Change event for the input * @param template The current template context */ - 'change select.currentValue'(event, template) { + 'change select.currentValue': function(event, template) { // Get the current value of the select box - const value = $(event.currentTarget).val(); + var value = $(event.currentTarget).val(); // Update the ReactiveVar with the user-specified value template.currentValue.set(value); diff --git a/Packages/ohif-hanging-protocols/client/components/stageSortable/stageSortable.js b/Packages/ohif-hanging-protocols/client/components/stageSortable/stageSortable.js index 6caa9ac5e..7b3c32ebc 100644 --- a/Packages/ohif-hanging-protocols/client/components/stageSortable/stageSortable.js +++ b/Packages/ohif-hanging-protocols/client/components/stageSortable/stageSortable.js @@ -10,7 +10,7 @@ import 'meteor/ohif:viewerbase'; * so we can swap stages more easily */ Array.prototype.move = function(oldIndex, newIndex) { - const value = this[oldIndex]; + var value = this[oldIndex]; newIndex = Math.max(0, newIndex); newIndex = Math.min(this.length, newIndex); @@ -29,13 +29,13 @@ Array.prototype.move = function(oldIndex, newIndex) { * @returns {number} The index of the specified stage within the Protocol, * or undefined if it is not present. */ -const getStageIndex = (protocol, id) => { - let stageIndex; +function getStageIndex(protocol, id) { + var stageIndex; if (!protocol || !protocol.stages) { return; } - protocol.stages.forEach((stage, index) => { + protocol.stages.forEach(function(stage, index) { if (stage.id === id) { stageIndex = index; return false; @@ -43,7 +43,7 @@ const getStageIndex = (protocol, id) => { }); return stageIndex; -}; +} Template.stageSortable.helpers({ /** @@ -51,7 +51,7 @@ Template.stageSortable.helpers({ * * @returns {boolean} Whether or not the stage is currently being displayed */ - isActiveStage() { + isActiveStage: function() { // Rerun this function every time the layout manager has been updated Session.get('LayoutManagerUpdated'); @@ -60,7 +60,7 @@ Template.stageSortable.helpers({ return; } - const currentStage = ProtocolEngine.getCurrentStageModel(); + var currentStage = ProtocolEngine.getCurrentStageModel(); if (!currentStage) { return false; } @@ -73,8 +73,8 @@ Template.stageSortable.helpers({ * * @returns {number|*} */ - stageLabel() { - const stage = this; + stageLabel: function() { + var stage = this; // If no Protocol Engine has been defined yet, stop here to prevent errors if (!ProtocolEngine) { @@ -82,10 +82,10 @@ Template.stageSortable.helpers({ } // Retrieve the last saved copy of the current protocol - const lastSavedCopy = HangingProtocols.findOne(ProtocolEngine.protocol._id); + var lastSavedCopy = HP.ProtocolStore.getProtocol(ProtocolEngine.protocol.id); // Try to find the index of this stage in the previously saved copy - let stageIndex = getStageIndex(lastSavedCopy, stage.id); + var stageIndex = getStageIndex(lastSavedCopy, stage.id); // If the stage is new, and therefore wasn't present in the last save, // retrieve it's index in the array of new stage ids and use that for @@ -95,11 +95,11 @@ Template.stageSortable.helpers({ Session.get('timeAgoVariable'); // Find the index of the stage in the array of newly created stage IDs - const newStageNumber = ProtocolEngine.newStageIds.indexOf(stage.id) + 1; + var newStageNumber = ProtocolEngine.newStageIds.indexOf(stage.id) + 1; // Use Moment.js to format the createdDate of this stage relative to the // current time - const dateCreatedFromNow = moment(stage.createdDate).fromNow(); + var dateCreatedFromNow = moment(stage.createdDate).fromNow(); // Return the label for the new stage, // e.g. "New Stage 1 (created a few seconds ago)" @@ -115,7 +115,7 @@ Template.stageSortable.helpers({ * * @returns {boolean} Whether or not a later stage exists */ - isNextAvailable() { + isNextAvailable: function() { // Run this helper whenever the ProtocolEngine / LayoutManager has changed Session.get('LayoutManagerUpdated'); @@ -132,7 +132,7 @@ Template.stageSortable.helpers({ * * @returns {boolean} Whether or not an earlier stage exists */ - isPreviousAvailable() { + isPreviousAvailable: function() { // Run this helper whenever the ProtocolEngine / LayoutManager has changed Session.get('LayoutManagerUpdated'); @@ -150,9 +150,9 @@ Template.stageSortable.events({ /** * Displays a stage when its title is clicked */ - 'click .sortable-item span'() { + 'click .sortable-item span': function() { // Retrieve the index of this stage in the display set sequences - const stageIndex = getStageIndex(ProtocolEngine.protocol, this.id); + var stageIndex = getStageIndex(ProtocolEngine.protocol, this.id); // Display the selected stage ProtocolEngine.setCurrentProtocolStage(stageIndex); @@ -161,12 +161,12 @@ Template.stageSortable.events({ * Creates a new stage and adds it to the currently loaded Protocol at * the end of the display set sequence */ - 'click #addStage'() { + 'click #addStage': function() { // Retrieve the model describing the current stage - const stage = ProtocolEngine.getCurrentStageModel(); + var stage = ProtocolEngine.getCurrentStageModel(); // Clone this stage to create a new stage - const newStage = stage.createClone(); + var newStage = stage.createClone(); // Remove the stage's name if it has one delete newStage.name; @@ -178,7 +178,7 @@ Template.stageSortable.events({ ProtocolEngine.newStageIds.push(newStage.id); // Calculate the index of the last stage in the display set sequence - const stageIndex = ProtocolEngine.protocol.stages.length - 1; + var stageIndex = ProtocolEngine.protocol.stages.length - 1; // Switch to the last stage in the display set sequence ProtocolEngine.setCurrentProtocolStage(stageIndex); @@ -188,22 +188,22 @@ Template.stageSortable.events({ * the stages array. If it is the currently active stage, the current stage is * set to one stage earlier in the display set sequence. */ - 'click .deleteStage'() { + 'click .deleteStage': function() { // If this is the only stage in the Protocol, stop here if (ProtocolEngine.protocol.stages.length === 1) { return; } - const stageId = this.id; + var stageId = this.id; - const options = { + var options = { title: 'Remove Protocol Stage', text: 'Are you sure you would like to remove this Protocol Stage? This cannot be reversed.' }; - OHIF.viewerbase.showConfirmDialog(() => { + showConfirmDialog(function() { // Retrieve the index of this stage in the display set sequences - const stageIndex = getStageIndex(ProtocolEngine.protocol, stageId); + var stageIndex = getStageIndex(ProtocolEngine.protocol, stageId); // Remove it from the display set sequence ProtocolEngine.protocol.stages.splice(stageIndex, 1); @@ -211,7 +211,7 @@ Template.stageSortable.events({ // If we have removed the currently active stage, switch to the one before it if (ProtocolEngine.stage === stageIndex) { // Make sure we don't try to switch to a stage index below zero - const newStageIndex = Math.max(stageIndex - 1, 0); + var newStageIndex = Math.max(stageIndex - 1, 0); // Display the new stage ProtocolEngine.setCurrentProtocolStage(newStageIndex); @@ -222,10 +222,10 @@ Template.stageSortable.events({ }, options); }, - 'click .moveStageUp'() { + 'click .moveStageUp': function() { // Get the old and new indices following a 'sort' event - const oldIndex = ProtocolEngine.stage; - const newIndex = Math.max(ProtocolEngine.stage - 1, 0); + var oldIndex = ProtocolEngine.stage; + var newIndex = Math.max(ProtocolEngine.stage - 1, 0); if (oldIndex === newIndex) { return; @@ -242,10 +242,10 @@ Template.stageSortable.events({ // Update the Session variable to the UI re-renders Session.set('LayoutManagerUpdated', Random.id()); }, - 'click .moveStageDown'() { + 'click .moveStageDown': function() { // Get the old and new indices following a 'sort' event - const oldIndex = ProtocolEngine.stage; - const newIndex = Math.min(ProtocolEngine.stage + 1, ProtocolEngine.protocol.stages.length - 1); + var oldIndex = ProtocolEngine.stage; + var newIndex = Math.min(ProtocolEngine.stage + 1, ProtocolEngine.protocol.stages.length - 1); if (oldIndex === newIndex) { return; diff --git a/Packages/ohif-hanging-protocols/client/components/textEntryDialog/textEntryDialog.js b/Packages/ohif-hanging-protocols/client/components/textEntryDialog/textEntryDialog.js index a36251feb..6a0e2909b 100644 --- a/Packages/ohif-hanging-protocols/client/components/textEntryDialog/textEntryDialog.js +++ b/Packages/ohif-hanging-protocols/client/components/textEntryDialog/textEntryDialog.js @@ -15,7 +15,7 @@ const keys = { * * @param dialog The DOM element of the dialog to close */ -const closeHandler = dialog => { +function closeHandler(dialog) { // Hide the lesion dialog $(dialog).css('display', 'none'); @@ -24,7 +24,7 @@ const closeHandler = dialog => { // Restore the focus to the active viewport Viewerbase.setFocusToActiveViewport(); -}; +} /** * Displays and updates the UI of the Text Entry Dialog given a new title, @@ -36,10 +36,10 @@ const closeHandler = dialog => { */ openTextEntryDialog = function(title, instructions, currentValue, doneCallback) { // Get the lesion location dialog - const dialog = $('.textEntryDialog'); + var dialog = $('.textEntryDialog'); // Clear any input that is still on the page - const currentValueInput = dialog.find('input.currentValue'); + var currentValueInput = dialog.find('input.currentValue'); currentValueInput.val(currentValue); // Store the Dialog DOM data, rule level and rule in the template data @@ -55,10 +55,10 @@ openTextEntryDialog = function(title, instructions, currentValue, doneCallback) dialog.css('display', 'block'); // Show the backdrop - Blaze.render(Template.removableBackdrop, document.body); + UI.render(Template.removableBackdrop, document.body); // Make sure the context menu is closed when the user clicks away - $('.removableBackdrop').one('mousedown touchstart', () => { + $('.removableBackdrop').one('mousedown touchstart', function() { closeHandler(dialog); }); }; @@ -74,17 +74,17 @@ Template.textEntryDialog.events({ * Save the user-specified text * */ - 'click .save'() { + 'click .save': function() { // Retrieve the input properties to the template - const dialog = Template.textEntryDialog.dialog; - const currentValue = dialog.find('input.currentValue').val(); + var dialog = Template.textEntryDialog.dialog; + var currentValue = dialog.find('input.currentValue').val(); // If currentValue input is undefined, prevent saving this rule if (currentValue === undefined) { return; } - const doneCallback = Template.textEntryDialog.doneCallback; + var doneCallback = Template.textEntryDialog.doneCallback; if (doneCallback) { doneCallback(currentValue); } @@ -95,7 +95,7 @@ Template.textEntryDialog.events({ /** * Allow the user to click the Cancel button to close the dialog */ - 'click .cancel'() { + 'click .cancel': function() { closeHandler(Template.textEntryDialog.dialog); }, /** @@ -104,22 +104,22 @@ Template.textEntryDialog.events({ * @param event The Keydown event details * @returns {boolean} Return false to prevent bubbling of the event */ - 'keydown .textEntryDialog'(event) { - const dialog = Template.textEntryDialog.dialog; + 'keydown .textEntryDialog': function(event) { + var dialog = Template.textEntryDialog.dialog; // If Esc key is pressed, close the dialog if (event.which === keys.ESC) { closeHandler(dialog); return false; } else if (event.which === keys.ENTER) { - const currentValue = dialog.find('input.currentValue').val(); + var currentValue = dialog.find('input.currentValue').val(); // If currentValue input is undefined, prevent saving this rule if (currentValue === undefined) { return; } - const doneCallback = Template.textEntryDialog.doneCallback; + var doneCallback = Template.textEntryDialog.doneCallback; if (doneCallback) { doneCallback(currentValue); } @@ -134,9 +134,9 @@ Template.textEntryDialog.events({ * @param event The Change event for the input * @param template The current template context */ - 'change input.currentValue'(event, template) { + 'change input.currentValue': function(event, template) { // Get the DOM element representing the input box - const input = $(event.currentTarget); + var input = $(event.currentTarget); // Update the template data with the current value Template.textEntryDialog.currentValue = input.val(); diff --git a/Packages/ohif-hanging-protocols/client/protocolEngine.js b/Packages/ohif-hanging-protocols/client/protocolEngine.js index 1a00d23ce..c893b050a 100644 --- a/Packages/ohif-hanging-protocols/client/protocolEngine.js +++ b/Packages/ohif-hanging-protocols/client/protocolEngine.js @@ -196,7 +196,7 @@ HP.ProtocolEngine = class ProtocolEngine { findMatchByStudy(study) { var matched = []; - HangingProtocols.find().forEach(protocol => { + HP.ProtocolStore.getProtocol().forEach(protocol => { // Clone the protocol's protocolMatchingRules array // We clone it so that we don't accidentally add the // numberOfPriorsReferenced rule to the Protocol itself. @@ -225,9 +225,7 @@ HP.ProtocolEngine = class ProtocolEngine { }); if (!matched.length) { - var defaultProtocol = HangingProtocols.findOne({ - id: 'defaultProtocol' - }); + var defaultProtocol = HP.ProtocolStore.getProtocol('defaultProtocol'); return [{ score: 1, @@ -422,7 +420,7 @@ HP.ProtocolEngine = class ProtocolEngine { // TODO: Add relative Date / time }); - this.studies.forEach(study => { + this.studies.forEach(function(study) { const studyMatchDetails = HP.match(study, studyMatchingRules); if ((studyMatchingRules.length && !studyMatchDetails.score) || studyMatchDetails.score < highestStudyMatchingScore) { @@ -440,7 +438,7 @@ HP.ProtocolEngine = class ProtocolEngine { highestSeriesMatchingScore = seriesMatchDetails.score; - series.instances.forEach((instance, index) => { + series.instances.forEach(function(instance, index) { // This tests to make sure there is actually image data in this instance // TODO: Change this when we add PDF and MPEG support // See https://ohiforg.atlassian.net/browse/LT-227