reorganize packages, start converting overall app to react (very broken at the moment)

This commit is contained in:
Erik Ziegler committed 2018-12-12 18:06:25 +01:00
1 parent 024fe1a448
commit 5f30f7bd35
479 files changed
+5364 -11611

No files matched your search

@@ -0,0 +1,10 @@
<template name="dialogStudyAssociation">
{{#dialogForm (extend this
schema=instance.schema
dialogClass='modal-lg'
title='Study Association'
confirmLabel='Save'
)}}
{{>studyAssociationTable}}
{{/dialogForm}}
</template>
@@ -0,0 +1,147 @@
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { Blaze } from 'meteor/blaze';
import moment from 'moment';
import _ from 'underscore';
import { OHIF } from 'meteor/ohif:core';
Template.dialogStudyAssociation.onCreated(() => {
const instance = Template.instance();
instance.data.confirmCallback = formData => {
OHIF.log.info('Saving associations');
const Timepoints = OHIF.studylist.timepointApi.timepoints;
// Find the rows of the study association table
const $tableRows = instance.$('#studyAssociationTable table tbody tr');
// Create an empty object to group studies into
const studies = {};
// Loop through each row to parse the data
$tableRows.each(function() {
// Get a selector for this row
const $row = $(this);
// Check the includeStudy checkbox to see if we should parse this row
const includeStudy = $row.find('input.includeStudy[type="checkbox"]').eq(0).prop('checked');
if (!includeStudy) {
return;
}
// Find the selected timepoint option for this study
const $timepointInput = $row.find('input.timepointOption[type="radio"]:checked');
// Find the related label and trim it down to actual label (TODO: do this another way)
const timepointType = $timepointInput.val();
// Get the study metaData by checking the row with the template engine Blaze
const data = Blaze.getData(this);
// Concatenate the study data to an array, depending on whether is was marked as baseline
// or follow-up
if (!studies.hasOwnProperty(timepointType)) {
studies[timepointType] = [];
}
studies[timepointType].push(data);
});
const studiesKeys = Object.keys(studies);
// TODO: REMOVE - Temporary for RSNA
const hasBaseline = _.contains(studiesKeys, 'baseline');
if (hasBaseline) {
const patientId = studies[studiesKeys[0]][0].patientId;
Timepoints.remove({ patientId });
}
studiesKeys.forEach(timepointType => {
// Get the studies associated with this timepoint
const relatedStudies = studies[timepointType];
// Create an array of all the studyInstanceUids for storage in the Timepoint
const studyInstanceUids = relatedStudies.map(function(study) {
return study.studyInstanceUid;
});
// Create an array of all the studyDates for storage in the Timepoint
let studyDates = relatedStudies.map(study => moment(study.studyDate).toDate());
// Sort the study dates, so we can get a range for these values
studyDates = studyDates.sort();
// HipaaEventType to log changes in collections
let hipaaEventType;
let hipaaEvent;
// Check if these studies are already associated with an existing Timepoint
let 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
}
});
}
let 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
}
});
timepointId = existingTimepoint.timepointId;
hipaaEventType = 'modify';
} else {
// Create a new timepoint to represent the (baseline or follow-up) studies
let timepoint = {
timepointType: timepointType,
timepointId: OHIF.utils.guid(),
studyInstanceUids: studyInstanceUids,
patientId: relatedStudies[0].patientId,
earliestDate: studyDates[0],
latestDate: studyDates[studyDates.length - 1],
isLocked: false
};
// Insert this timepoint into the Timepoints Collection
Timepoints.insert(timepoint);
timepointId = timepoint.timepointId;
hipaaEventType = 'create';
}
// Log
hipaaEvent = {
eventType: hipaaEventType,
userId: OHIF.user.getUserId(),
userName: OHIF.user.getName(),
collectionName: 'Timepoints',
recordId: timepointId,
patientId: relatedStudies[0].patientId,
patientName: relatedStudies[0].patientName
};
});
OHIF.studylist.timepointApi.storeTimepoints();
return formData;
};
});
@@ -0,0 +1,67 @@
<template name="studyAssociationTable">
<div id="studyAssociationTable">
<div id="associationInstructions" class="row">
<div class="col-md-12">
<h5>Instructions</h5>
<p>Select the studies you would like to associate to a time point. Only one follow-up time point can be associated at the same time.</p>
<p>We have automatically retrieved all studies within 14 days ({{formatDA this.earliestDate}} to {{formatDA latestDate}}) of your selected studies, in case you forgot to select a study.</p>
</div>
</div>
<div class="tableHeaderBackground">
</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 class="{{#if autoselected}}disabled{{/if}}">
<td class="checkboxWrapper center">
<label>
<input type="checkbox" class="includeStudy" {{valueIf autoselected '' 'checked'}}/> <span></span>
</label>
</td>
<td class="center studyDataCell">
{{#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">
<p>{{formatPN patientName}}</p>
</td>
<td class="studyDataCell">
<p>{{studyDescription}}</p>
</td>
<td class="timepointOptions center studyDataCell noselect">
{{#each timepointOptions}}
<label class="noselect">
<input type="radio"
name="{{../_id}}"
value="{{value}}"
class="timepointOption"
{{valueIf checked 'checked' ''}}
{{valueIf ../autoselected 'disabled' ''}}>
<span></span>{{name}}
</label>
{{/each}}
</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</template>
@@ -0,0 +1,142 @@
import { Template } from 'meteor/templating';
import moment from 'moment';
import { OHIF } from 'meteor/ohif:core';
/**
* 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;
}
const earliestStudy = selectedStudies[0];
const latestStudy = selectedStudies[selectedStudies.length - 1];
const earliestDate = moment(earliestStudy.studyDate, 'YYYYMMDD');
earliestDate.subtract(range);
const 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;
}
const 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
const autoselected = OHIF.studylist.collections.Studies.find({
studyDate: {
$gte: range.earliestDate.format('YYYYMMDD'),
$lte: range.latestDate.format('YYYYMMDD')
}
}, {
sort: {
studyDate: 1
}
}).fetch();
// Make an array of studyInstanceUids in selectedStudies
const studyInstanceUids = selectedStudies.map(selectedStudy => selectedStudy.studyInstanceUid);
autoselected.forEach(study => {
const 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() {
const selectedStudies = OHIF.studylist.getSelectedStudies();
return autoSelectStudies(selectedStudies);
},
/**
* This helper returns the list of Timepoint types the user can set for this study
*
* @returns {Array.<T>}
*/
timepointOptions() {
return [{
value: 'baseline',
name: 'Baseline',
checked: true
}, {
value: 'followup',
name: 'Follow-up',
checked: false
}];
},
earliestDate() {
const selectedStudies = OHIF.studylist.getSelectedStudies();
const range = getDateRange(selectedStudies);
if (range) {
return range.earliestDate;
}
},
latestDate() {
const selectedStudies = OHIF.studylist.getSelectedStudies();
const range = getDateRange(selectedStudies);
if (range) {
return range.latestDate;
}
}
});
Template.studyAssociationTable.events({
'change input.includeStudy'(event, instance) {
const checkbox = event.currentTarget;
const studyRow = $(checkbox).closest('tr');
const studyDataCells = studyRow.find('td.studyDataCell');
if (checkbox.checked === true) {
studyRow.removeClass('disabled');
studyDataCells.find('input').attr('disabled', false);
} else {
studyRow.addClass('disabled');
studyDataCells.find('input').attr('disabled', true);
}
}
});
@@ -0,0 +1,188 @@
@import "{ohif:viewerbase}/app"
$tableHoverColor = #2c363f
$tableTextPrimaryColor = white
$tableHeaderHeight = 50px
$bodyCellHeight = 30px
#studyAssociationTable
color: #fff
.header
text-align: center
.center
text-align: center
#associationInstructions
theme('background', '$uiGrayDarker')
margin-bottom: 2px
padding: 0 15px
.tableHeaderBackground
theme('background-color', '$uiGrayDarker')
position: absolute
height: $tableHeaderHeight + 1px
left: 0
width: 100%
z-index: 1
border-bottom: solid 1px
theme('border-bottom-color', '$largeNumbersColor')
table
z-index: 2
position: relative
thead
tr
th
padding-bottom: 5px
border-bottom: solid 1px #6fbde2
height: $tableHeaderHeight
font-weight: normal
tbody
tr
padding: 5px
background-color: black
&:nth-child(even)
theme('background-color', '$uiGrayDarker')
td
position: relative
height: $bodyCellHeight
line-height: $bodyCellHeight
color: $tableTextPrimaryColor
border-top: 1px solid #436270
border-bottom: 1px solid #436270
vertical-align: middle
transition(all 0.1s ease)
p
margin: 0
&.timepointOptions
label
font-weight: 200
cursor: pointer
input
margin: 0 3px
&[type="radio"]
border: 0
clip: rect(0 0 0 0)
height: 1px
margin: -1px
overflow: hidden
padding: 0
position: absolute
width: 1px
& + span
display: block
position: absolute
border: 2px solid #c8c8c8
border-radius: 100%
height: 15px
width: 15px
top: 2px
left: 0
padding: 3px
z-index: 5
transition: border .25s linear
-webkit-transition: border .25s linear
& + span:before
display: block
content: ''
border-radius: 100%
height: 100%
width: 100%
transition: background 0.25s linear
-webkit-transition: background 0.25s linear
&:checked + span
theme('border-color', '$activeColor')
&:before
theme('background-color', '$activeColor')
&:disabled
& + span
border-color: #535960 !important
&:checked + span
border-color: #0D4256 !important
&:before
background-color: #0D4256 !important
label
padding: 0 5px
padding-left: 20px
display: inline-block
position: relative
line-height: initial
&.checkboxWrapper
label
display: block
margin: 0
input
margin: 0 3px
&[type="checkbox"]
border: 0
clip: rect(0 0 0 0)
height: 1px
margin: -1px
overflow: hidden
padding: 0
position: absolute
width: 1px
& + span
display: block
border: 1px solid #b6b6b6
background-color: white
border-radius: 2px
height: 16px
width: 16px
margin: 0 auto
z-index: 5
transition: border .25s linear
-webkit-transition: border .25s linear
& + span:before
display: block
position: relative
content: ''
font-size: 9px
top: -7px
color: white
background-color: transparent
transition: background 0.25s linear
-webkit-transition: background 0.25s linear
&:checked + span
theme('background-color', '$activeColor')
&:before
content: '\2713'
&.disabled
td
color: #535960
&:hover, &:active, &.active
background-color: $tableHoverColor
color: white
td
// This selector is necessary to override bootstrap's 'table' class
border-top: 1px solid #436270
border-bottom: 1px solid #436270
background-color: $tableHoverColor