Commented a lot of functions. Tried to get jsDoc and/or docco to work

This commit is contained in:
Erik Ziegler committed 2015-11-16 17:49:35 +01:00
1 parent 14f47ad0e3
commit f349572d53
46 files changed
+654 -274

No files matched your search

@@ -1,19 +1,46 @@
Template.tabTitle.events({
/**
* Closes a tab when the close button is pressed in the title
* The next tab to the left is loaded if the current tab is closed
*
* @param e The click event used to close the tab
*/
'click .close': function(e) {
// Identify the tab title DOM node
var tab = $(e.currentTarget).parents('a[data-toggle="tab"]').eq(0);
// Get the relevent contentId that this tab title represents
// Replace any hash marks (#) that were required by Bootstrap's tab switching
var contentId = tab.data("target").replace("#", "");
// Check if we are closing the active tab. If we are, prepare to switch
// to the next tab to the left.
var activeContentId = Session.get('activeContentId');
if (activeContentId === contentId) {
// Find the index of the tab that is being closed
var tabIndex = tab.parent('li').index();
var tabIndex = tab.parent('li').index();
var newActiveTabIndex = Math.max(tabIndex - 1, 0);
var newActiveTab = $(".tabTitle").eq(newActiveTabIndex);
var newActiveTabLink = newActiveTab.find("a[data-toggle=tab]");
var newContentId = newActiveTabLink.data("target").replace("#", "");
// Find the index the tab to its left
var newActiveTabIndex = Math.max(tabIndex - 1, 0);
switchToTab(newContentId);
var tabObjectId = tabs.find({contentid: contentId}).fetch()[0]._id;
tabs.remove(tabObjectId);
// Find the DOM node of the tab that will be activated
var newActiveTab = $(".tabTitle").eq(newActiveTabIndex);
// Find the content ID of the tab that will be switched to
var newActiveTabLink = newActiveTab.find("a[data-toggle=tab]");
var newContentId = newActiveTabLink.data("target").replace("#", "");
// Switch to this tab
switchToTab(newContentId);
}
// Find the tab to be closed in the Tabs collection
var tabObjectId = WorklistTabs.findOne({contentid: contentId})._id;
// Remove this tab from the Tabs collection so it is no longer rendered
WorklistTabs.remove(tabObjectId);
// Remove any stored data related to this tab from the global ViewerData structure
delete ViewerData[contentId];
}
});
+2 -2
View File
@@ -3,7 +3,7 @@
<li role="presentation" class="tabTitle active">
<a data-target="#worklistTab" role="tab" data-toggle="tab">Study List</a>
</li>
{{ #each tabs }}
{{ #each worklistTabs }}
{{ >tabTitle }}
{{ /each }}
</ul>
@@ -14,7 +14,7 @@
{{> worklistResult }}
</div>
</div>
{{ #each tabs }}
{{ #each worklistTabs }}
{{ >tabContent }}
{{ /each }}
</div>
+97 -19
View File
@@ -1,31 +1,78 @@
ViewerData = Session.get('ViewerData') || {};
StudyMetaData = {};
/**
* Template: Worklist
*
* This is the main component of the Worklist package
*/
// Define the ViewerData global object
// If there is currently any Session data for this object,
// use this to repopulate the variable
ViewerData = Session.get('ViewerData') || {};
// Define the StudyMetaData object. This is used as a cache
// to store study meta data information to prevent unnecessary
// calls to the server
var StudyMetaData = {};
// Create the WorklistTabs collection
WorklistTabs = new Meteor.Collection(null);
/**
* Retrieves study metadata using a server call, and fires a callback
* when completed.
*
* @params {string} studyInstanceUid The UID of the Study to be retrieved
* @params {function} doneCallback The callback function to be executed when the study retrieval has finished
*/
getStudyMetadata = function(studyInstanceUid, doneCallback) {
log.info('worklistStudy getStudyMetadata');
if (StudyMetaData.hasOwnProperty(studyInstanceUid) && StudyMetaData[studyInstanceUid]) {
var study = StudyMetaData[studyInstanceUid];
// If the StudyMetaData cache already has data related to this
// studyInstanceUid, then we should fire the doneCallback with this data
// and stop here.
var study = StudyMetaData[studyInstanceUid];
if (study) {
doneCallback(study);
return;
}
// If no study metadata is in the cache variable, we need to retrieve it from
// the server with a call.
Meteor.call('GetStudyMetadata', studyInstanceUid, function(error, study) {
// Once we have retrieved the data, we sort the series' by series
// and instance number in ascending order
sortStudy(study);
// Then we store this data in the cache variable
StudyMetaData[studyInstanceUid] = study;
// Finally, we fire the doneCallback with this study meta data
doneCallback(study);
});
};
/**
* Switches to a new tab in the tabbed worklist container
* This function renders either the Worklist or the Viewer template with new data.
*
* @param contentId The unique ID of the tab to be switched to
*/
switchToTab = function(contentId) {
log.info("Switching to tab: " + contentId);
// Use Bootstrap's Tab JavaScript to show the contents of the current tab
// Unless it is the worklist, it is currently an empty div
$('.tabTitle a[data-target="#' + contentId + '"]').tab('show');
// Remove any previous Viewers from the DOM
$("#viewer").remove();
// Update the 'activeContentId' variable in Session
Session.set("activeContentId", contentId);
// If we are switching to the Worklist tab, reset any CSS styles
// that have been applied to prevent scrolling in the Viewer.
// Then stop here, since nothing needs to be re-rendered.
if (contentId === 'worklistTab') {
document.body.style.overflow = null;
document.body.style.height = null;
@@ -34,30 +81,44 @@ switchToTab = function(contentId) {
return;
}
// Set active tab
Session.set("activeContentId", contentId);
// Get tab content container
// Get tab content container given the contentId string
// If no such container exists, stop here because something is wrong
var container = $('.tab-content').find("#" + contentId).get(0);
if (!container) {
log.warn('No container present with the contentId: ' + contentId);
return;
}
// Use the stored ViewerData global object to retrieve the studyInstanceUid
// related to this tab
var studyInstanceUid = ViewerData[contentId].studyInstanceUid;
// Attempt to retrieve the meta data (it might be cached)
getStudyMetadata(studyInstanceUid, function(study) {
// Once we have the study data, store it in a structure with
// any other saved data about this tab (e.g. layout structure)
var data = {
viewportRows: ViewerData[contentId].viewportRows,
viewportColumns: ViewerData[contentId].viewportColumns,
contentId: contentId,
studies: [study],
studies: [study]
};
// Update the Session variable with the loaded studies
Session.set('studies', data.studies);
// Remove the loading text template that is inside by default
// Remove the loading text template that is inside the tab container by default
container.innerHTML = "";
// Use Blaze to render the Viewer Template into the container
UI.renderWithData(Template.viewer, data, container);
// Retrieve the DOM element of the viewer
var imageViewer = $("#viewer");
// If it is present in the DOM (it should be), then apply
// styles to prevent page scrolling and overscrolling on mobile devices
if (imageViewer) {
document.body.style.overflow = "hidden";
document.body.style.height = '100%';
@@ -68,20 +129,34 @@ switchToTab = function(contentId) {
});
};
/**
* Opens a new tab in the tabbed worklist environment using
* a given study and new tab title.
*
* @param studyInstanceUid The UID of the Study to be opened
* @param title The title to be used for the tab heading
*/
openNewTab = function(studyInstanceUid, title) {
// Generate a unique ID to represent this tab
// We can't just use the Mongo entry ID because
// then it will change after hot-reloading.
var contentid = generateUUID();
var data = {
// Create a new entry in the WorklistTabs Collection
WorklistTabs.insert({
title: title,
contentid: contentid,
};
tabs.insert(data);
active: false
});
// Update the ViewerData global object
ViewerData[contentid] = {
title: title,
contentid: contentid,
studyInstanceUid: studyInstanceUid
};
// Switch to the new tab
switchToTab(contentid);
};
@@ -96,9 +171,12 @@ Template.worklist.onRendered(function() {
Template.worklist.helpers({
'tabs': function() {
log.info('Updating tabs');
return tabs.find();
/**
* Returns the current set of Worklist Tabs
* @returns Meteor.Collection The current state of the WorklistTabs Collection
*/
'worklistTabs': function() {
return WorklistTabs.find();
}
});
@@ -1,6 +1,13 @@
// Define the Studies Collection
// This is a client-side only Collection which
// Stores the list of studies in the Worklist
Studies = new Mongo.Collection(null);
Template.worklistResult.helpers({
/**
* Returns a sorted instance of the Studies Collection
* by Patient name and Study Date in Ascending order.
*/
studies : function() {
return Studies.find({}, {sort: {patientName : 1, studyDate : 1}});
}
@@ -1,4 +1,4 @@
//Get all studies
// Retrieve all studies
search();
var studyDateFrom;
@@ -6,6 +6,13 @@ var studyDateTo;
var checkFrom = false;
var checkTo = false;
/**
* Transforms an input string into a search filter for
* the Worklist Search call
*
* @param filter The input string to be searched for
* @returns {*}
*/
function getFilter(filter) {
if(filter && filter.length && filter.substr(filter.length - 1) !== '*') {
filter += '*';
@@ -13,16 +20,19 @@ function getFilter(filter) {
return filter;
}
//Search value
/**
* Search for a value in a string
*/
function isIndexOf(mainVal, searchVal) {
if(mainVal === undefined || mainVal === '' || mainVal.indexOf(searchVal) > -1){
if (mainVal === undefined || mainVal === '' || mainVal.indexOf(searchVal) > -1){
return true;
}
return false;
}
//Replace object is undefined
/**
* Replace object if undefined
*/
function replaceUndefinedColumnValue (text) {
if (text == undefined || text === "undefined") {
return "";
@@ -31,94 +41,96 @@ function replaceUndefinedColumnValue (text) {
}
}
//Convert string to study date
/**
* Convert string to study date
*/
function convertStringToStudyDate (dateStr) {
var y = dateStr.substring(0,4);
var m = dateStr.substring(4,6);
var d = dateStr.substring(6,8);
var newDateStr = y+"/"+m+"/"+d;
var date_ = new Date(newDateStr);
return date_;
return new Date(newDateStr);
}
/**
* Runs a search for studies matching the worklist query parameters
* Inserts the identified studies into the Studies Collection
*/
function search() {
// Create the filters to be used for the Worklist Search
var filter = {
patientName: getFilter($('#patientName').val()),
patientId: getFilter($('#patientId').val()),
accessionNumber: getFilter($('#patientAccessionNumber').val())
};
// Make sure that modality has a reasonable value, since it is occasionally
// returned as 'undefined'
var modality = replaceUndefinedColumnValue($('#modality').val());
// Clear all current studies
Studies.remove({});
Meteor.call('WorklistSearch', filter, function(error, studies) {
if (studies) {
studies.forEach(function(study) {
if(isIndexOf(study.modalities, modality) &&
(new Date(studyDateFrom).setHours(0,0,0,0) <= convertStringToStudyDate(study.studyDate) || !checkFrom) &&
(convertStringToStudyDate(study.studyDate) <= new Date(studyDateTo).setHours(0,0,0,0) || !checkTo)) {
Studies.insert(study);
}
});
if (!studies) {
return;
}
// Loop through all identified studies
studies.forEach(function(study) {
// Search the rest of the parameters that aren't done via the server call
if(isIndexOf(study.modalities, modality) &&
(new Date(studyDateFrom).setHours(0,0,0,0) <= convertStringToStudyDate(study.studyDate) || !checkFrom) &&
(convertStringToStudyDate(study.studyDate) <= new Date(studyDateTo).setHours(0,0,0,0) || !checkTo)) {
// Insert any matching studies into the Studies Collection
Studies.insert(study);
}
});
});
}
Template.worklistSearch.events({
//Search
/**
* Searches for studies given the current state of the form controls
*/
'click button#btnSearch' :function(event) {
studyDateFrom = $('#studyDateFrom').val();
studyDateTo = $('#studyDateTo').val();
checkFrom = $('#checkFrom').is(':checked');
checkTo = $('#checkTo').is(':checked');
search();
return false;
},
//Today
/**
* Searches for studies with a study date equal to Today
*/
'click button#btnToday' :function(event) {
studyDateTo = new Date();
studyDateFrom = studyDateTo;
checkFrom = true;
checkTo = true;
search();
return false;
},
//Clear
'click button#btnClear' :function(event) {
$("#patientId").val("");
$("#patientName").val("");
$("#patientAccessionNumber").val("");
$("#studyDescription").val("");
$("#referringPhysician").val("");
$("#studyDateFrom").val("");
$("#studyDateTo").val("");
$("#modality").val("");
$('#checkFrom').prop('checked', false);
$('#checkTo').prop('checked', false);
},
//Last 7 Days
'click button#btnLastSevenDays' :function(event) {
/**
* Searches for studies in the Last 7 Days
*/
'click button#btnLastSevenDays' :function() {
studyDateTo = new Date();
studyDateFrom = new Date();
studyDateFrom.setDate(studyDateFrom.getDate()-7);
checkFrom = true;
checkTo = true;
search();
return false;
},
/**
* Clears all input data in the study search panel
*/
'click button#btnClear' :function(event) {
$("#searchPanel .form-control").val("");
$('#checkFrom').prop('checked', false);
$('#checkTo').prop('checked', false);
}
});