Work on refactoring measurements out of Lesion Tracker package

- Removed AssociatedStudies Collection
- Measurement API is generated from configuration files
- Data exchange methods are defined in configuration
This commit is contained in:
Erik Ziegler committed 2016-11-15 08:21:46 +01:00
1 parent c511edd419
commit ab4d4c9008
537 files changed
+5122 -3545

No files matched your search

@@ -0,0 +1,64 @@
<template name="studyAssociationTable">
<div id="studyAssociationTable">
<div class="row">
<div class="col-md-12">
<h4>Instructions</h4>
<p>Associate the selected studies with timepoints in the clinical trial. Only 1 follow-up time point can be associated at the same time.</p>
<p>We have automatically retrieved all studies within 14 days (<strong>{{formatDA earliestDate}}</strong> to <strong>{{formatDA latestDate}}</strong>) of your selected studies, in case you forgot to
select a study.</p>
</div>
</div>
<table class="table table-responsive">
<thead>
<tr>
<th class="center">Include Study?</th>
<th class="center">Study Date</th>
<th class="center">Patient Name</th>
<th class="center">Study Description</th>
<th class="center">Timepoint Type</th>
</tr>
</thead>
<tbody>
{{ #each relevantStudies }}
<tr>
<td class="center">
<input type="checkbox" class="includeStudy" {{valueIf autoselected '' 'checked'}}/>
</td>
<td class="center studyDataCell {{ #if autoselected }}disabled{{ /if }}">
{{ #if autoselected}}
<p class="studyDate autoselected"
data-toggle="tooltip"
title="This study was autoselected.">
{{formatDA studyDate}}
</p>
{{ else }}
<p class="studyDate">{{formatDA studyDate}}</p>
{{ /if }}
</td>
<td class="center studyDataCell {{ #if autoselected }}disabled{{ /if }}">
<p>{{formatPN patientName}}</p>
</td>
<td class="studyDataCell {{ #if autoselected }}disabled{{ /if }}">
<p>{{studyDescription}}</p>
</td>
<td class="timepointOptions center studyDataCell noselect {{ #if autoselected }}disabled{{ /if }}">
{{ #each timepointOptions }}
<label class="noselect">
<input type="radio"
name="{{../_id}}"
value="{{value}}"
class="timepointOption"
{{ valueIf checked 'checked' ''}}
{{ valueIf autoselected 'disabled' ''}}>
{{name}}
</label>
{{ /each }}
</td>
</tr>
{{ /each }}
</tbody>
</table>
</div>
</template>
@@ -0,0 +1,150 @@
/**
* Finds related studies within defined time window of =/- 14 days of selected studies
* @param selectedStudies
* @param range Object
*/
function getDateRange(selectedStudies, range) {
if (range === undefined) {
range = {
days: 14
};
}
if (!selectedStudies.length) {
return;
}
var earliestStudy = selectedStudies[0];
var latestStudy = selectedStudies[selectedStudies.length - 1];
var earliestDate = moment(earliestStudy.studyDate, 'YYYYMMDD');
earliestDate.subtract(range);
var latestDate = moment(latestStudy.studyDate, 'YYYYMMDD');
latestDate.add(range);
return {
earliestDate: earliestDate,
latestDate: latestDate
};
}
/**
* Selects all studies related to the currently input studies,
* based on various criteria. Returns the entire array of related studies.
*
* (at the moment, this is only the date range +/- 14 days, with a matching patientId)
*
* @param selectedStudies A user-selected list of studies
* @returns {*} The entire array of related studies
*/
function autoSelectStudies(selectedStudies) {
if (!selectedStudies.length) {
return;
}
var range = getDateRange(selectedStudies);
// Fetch autoselected studies based on the date range
// Note that we used MongoDB's fetch here so we have a mutable array,
// rather than a Cursor
var autoselected = StudyListStudies.find({
studyDate: {
$gte: range.earliestDate.format('YYYYMMDD'),
$lte: range.latestDate.format('YYYYMMDD')
}
}, {
sort: {
studyDate: 1
}
}).fetch();
// Make an array of studyInstanceUids in selectedStudies
var studyInstanceUids = selectedStudies.map(function(selectedStudy) {
return selectedStudy.studyInstanceUid;
});
autoselected.forEach(function(study) {
var exists = studyInstanceUids.indexOf(study.studyInstanceUid);
if (exists > -1) {
study.autoselected = false;
return;
}
study.autoselected = true;
});
return autoselected;
}
Template.studyAssociationTable.helpers({
/**
* This helpers includes the user-selected and autoselected studies
* to be associated.
*
* @returns {Array.<T>}
*/
relevantStudies: function() {
var selectedStudies = StudyListSelectedStudies.find({}, {
sort: {
studyDate: 1
}
}).fetch() || [];
return autoSelectStudies(selectedStudies);
},
/**
* This helper returns the list of Timepoint types the user can set for this study
*
* @returns {Array.<T>}
*/
timepointOptions: function() {
return [{
value: 'baseline',
name: 'Baseline',
checked: true
}, {
value: 'followup',
name: 'Follow-up',
checked: false
}];
},
earliestDate: function() {
var selectedStudies = StudyListSelectedStudies.find({}, {
sort: {
studyDate: 1
}
}).fetch();
var range = getDateRange(selectedStudies);
if (range) {
return range.earliestDate;
}
},
latestDate: function() {
var selectedStudies = StudyListSelectedStudies.find({}, {
sort: {
studyDate: 1
}
}).fetch();
var range = getDateRange(selectedStudies);
if (range) {
return range.latestDate;
}
}
});
Template.studyAssociationTable.events({
'change input.includeStudy': function(e) {
var checkbox = e.currentTarget;
var studyDataCells = $(checkbox).parents('tr').find('td.studyDataCell');
if (checkbox.checked === true) {
studyDataCells.removeClass('disabled');
studyDataCells.find('input').attr('disabled', false);
} else {
studyDataCells.addClass('disabled');
studyDataCells.find('input').attr('disabled', true);
}
}
});
@@ -0,0 +1,19 @@
#studyAssociationTable
.header
text-align: center
.center
text-align: center
table
tbody
tr
td.timepointOptions
input
margin: 0 3px
label
padding: 0 5px
td.disabled
opacity: 0.2