function DisplayChart($data, $label, $height, $id) { $colors = GenerateColorGradient(); ?> <table class="grayrounded" width="100%"> <tr> <td class="title"><?php echo $label; ?> </td> </tr> <tr> <td class="body"> <script> $(function() { var data = [ { label: "<?php echo $label; ?> ", hoverable: true, clickable: true, data: [<? foreach ($data as $date => $item) { $value = $data[$date]['value']; $date = $date*1000; if (($date > 0) && ($value > 0)) { $jsonstrings[] .= "['$date', $value]"; #$jsonstrings[] .= "['$date', " . number_format($value,1,'.','') . "]"; } } ?><?php echo implode2(',', $jsonstrings); ?> ] } ]; var options = { series: { lines: { show: true, fill: false }, points: { show: true } }, legend: { noColumns: 6 }, xaxis: { mode: "time", timeformat: "%Y-%m-%d" }, yaxis: { min: 0, tickDecimals: 1 }, selection: { mode: "x" }, }; var placeholder = $("#placeholder<?php echo $id; ?> "); var plot = $.plot(placeholder, data, options); }); </script> <div id="placeholder<?php echo $id; ?> " style="height:<?php echo $height; ?> px;" align="center"></div> </td> </tr> <tr> <td class="body"> <table class="tinytable"> <thead> <th>Date</th> <th>Subject</th> <th>Study</th> <th>Value</th> </thead> <tbody> <? // get min, max $min = $data[0]; $max = $data[0]; foreach ($data as $date => $value) { $value = $data[$date]['value']; if ($value > $max) { $max = $value; } if ($value < $min) { $min = $value; } } $range = $max - $min; foreach ($data as $date => $value) { $value = $data[$date]['value']; $uid = $data[$date]['uid']; $studynum = $data[$date]['studynum']; $subjectid = $data[$date]['subjectid']; $studyid = $data[$date]['studyid']; if (($value > 0) && ($range > 0)) { $cindex = round((($value - $min)/$range)*100); if ($cindex > 100) { $cindex = 100; } } $date = $date; $date = date("D, d M Y", $date); ?> <tr> <td><?php echo $date; ?> </td> <td><a href="subjects.php?id=<?php echo $subjectid; ?> "><?php echo $uid; ?> </a></td> <td><a href="subjects.php?id=<?php echo $studyid; ?> "><?php echo $uid; echo $studynum; ?> </a></td> <td align="right" bgcolor="<?php echo $colors[$cindex]; ?> "><tt><?php echo $value; ?> <tt></td> </tr> <? } ?> </tbody> </table> </td> </tr> </table> <? }
function DisplayAnalysisList($id, $numperpage, $pagenum) { $sqlstring = "select pipeline_name, pipeline_level from pipelines where pipeline_id = {$id}"; $result = MySQLiQuery($sqlstring, __FILE__, __LINE__); $row = mysqli_fetch_array($result, MYSQLI_ASSOC); $pipeline_name = $row['pipeline_name']; $pipeline_level = $row['pipeline_level']; //$urllist['Analysis'] = "analysis.php"; $urllist['Pipelines'] = "pipelines.php"; $urllist["{$pipeline_name}"] = "pipelines.php?action=editpipeline&id={$id}"; $urllist["Analysis List"] = "pipelines.php?action=viewanalyses&id={$id}"; NavigationBar("Analysis", $urllist); /* prep the pagination */ if ($numperpage == "") { $numperpage = 500; } if ($pagenum == "" || $pagenum < 1) { $pagenum = 1; } $limitstart = ($pagenum - 1) * $numperpage; $limitcount = $numperpage; /* create the color lookup table */ $colors = GenerateColorGradient(); //echo "<pre>"; //print_r($colors); //echo "</pre>"; /* run the sql query here to get the row count */ $sqlstring = "select *, timediff(analysis_enddate, analysis_startdate) 'analysis_time', timediff(analysis_clusterenddate, analysis_clusterstartdate) 'cluster_time' from analysis a left join studies b on a.study_id = b.study_id left join enrollment c on b.enrollment_id = c.enrollment_id left join subjects d on c.subject_id = d.subject_id where a.pipeline_id = {$id} and analysis_status not in ('NoMatchingStudies','NoMatchingStudyDependency','IncompleteDependency','BadDependency')"; $result = MySQLiQuery($sqlstring, __FILE__, __LINE__); $numrows = mysqli_num_rows($result); $numpages = ceil($numrows / $numperpage); if ($pagenum > $numpages) { $pagenum = $numpages; } ?> <div id="dialogbox" title="Dialog Box" style="display:none;">Loading...</div> <script type="text/javascript"> //$(document).ready(function() { // $(".fancybox").fancybox(); //}); </script> <script type="text/javascript"> //$(document).ready(function() { $(function() { $("#studiesall").click(function() { var checked_status = this.checked; $(".allstudies").find("input[type='checkbox']").each(function() { this.checked = checked_status; }); }); $("#analysesall").click(function() { var checked_status = this.checked; $(".allanalyses").find("input[type='checkbox']").each(function() { this.checked = checked_status; }); }); $("a.viewlog").click(function(e) { var id = jQuery(this).attr("id"); e.preventDefault(); $("#dialogbox").load("viewanalysis.php?action=viewlogs&analysisid=" + id).dialog({height:800, width:1200}); }); $("a.viewfiles").click(function(e) { var id = jQuery(this).attr("id"); e.preventDefault(); $("#dialogbox").load("viewanalysis.php?action=viewfiles&analysisid=" + id).dialog({height:800, width:1200}); }); $("a.viewresults").click(function(e) { var id = jQuery(this).attr("id"); e.preventDefault(); $("#dialogbox").load("viewanalysis.php?action=viewresults&analysisid=" + id + "&studyid=<?php echo $study_id; ?> ").dialog({height:800, width:1200}); }); }); </script> <table width="100%" class="tablepage"> <form method="post" action="pipelines.php" id="numperpageform"> <input type="hidden" name="action" value="viewanalyses"> <input type="hidden" name="id" value="<?php echo $id; ?> "> <tr> <td class="label"><?php echo $numrows; ?> analyses</td> <td class="pagenum"> Page <?php echo $pagenum; ?> of <?php echo $numpages; ?> <span class="tiny">(<?php echo $numperpage; ?> /page)</span> <select name="numperpage" title="Change number per page" onChange="numperpageform.submit()"> <option value="100" <?php if ($numperpage == 100) { echo "selected"; } ?> >100 <option value="500" <?php if ($numperpage == 500) { echo "selected"; } ?> >500 <option value="1000" <?php if ($numperpage == 1000) { echo "selected"; } ?> >1,000 <option value="2000" <?php if ($numperpage == 2000) { echo "selected"; } ?> >2,000 <option value="5000" <?php if ($numperpage == 5000) { echo "selected"; } ?> >5,000 <option value="10000" <?php if ($numperpage == 10000) { echo "selected"; } ?> >10,000 <option value="50000" <?php if ($numperpage == 50000) { echo "selected"; } ?> >50,000 </select> </td> <td class="middle"> </td> <td class="firstpage" title="First page"><a href="pipelines.php?action=viewanalyses&id=<?php echo $id; ?> &numperpage=<?php echo $numperpage; ?> &pagenum=1">«</a></td> <td class="previouspage" title="Previous page"><a href="pipelines.php?action=viewanalyses&id=<?php echo $id; ?> &numperpage=<?php echo $numperpage; ?> &pagenum=<?php echo $pagenum - 1; ?> ">‹</a></td> <td title="Refresh page"><a href="" style="margin-left:20px; margin-right:20px; font-size:14pt">⟳</a></td> <td class="nextpage" title="Next page"><a href="pipelines.php?action=viewanalyses&id=<?php echo $id; ?> &numperpage=<?php echo $numperpage; ?> &pagenum=<?php echo $pagenum + 1; ?> ">›</a></td> <td class="lastpage" title="Last page"><a href="pipelines.php?action=viewanalyses&id=<?php echo $id; ?> &numperpage=<?php echo $numperpage; ?> &pagenum=<?php echo $numpages; ?> ">»</a></td> </tr> </form> </table> <form method="post" name="studieslist" action="pipelines.php"> <input type="hidden" name="action" value="deleteanalyses" id="studieslistaction"> <input type="hidden" name="destination" value="" id="studieslistdestination"> <input type="hidden" name="analysisnotes" value=""> <input type="hidden" name="analysisid" value=""> <input type="hidden" name="id" value="<?php echo $id; ?> "> <table id="analysistable" class="smallgraydisplaytable" width="100%"> <!--<table id="analysistable" class="tablesorter" width="100%">--> <thead> <tr> <th><input type="checkbox" id="studiesall"> Study</th> <th>Visit</th> <th>Pipeline<br>version</th> <?php if ($pipeline_level == 1) { ?> <th>Study date</th> <th># series</th> <?php } ?> <th>Status</th> <th>Successful</th> <th>Logs</th> <th>Files</th> <th>Results</th> <th>Notes</th> <th>Message</th> <th>Size<br><span class="tiny">bytes</span></th> <th>Hostname</th> <th>Setup time<br><span class="tiny">completed date</span></th> <th>Cluster time<br><span class="tiny">completed date</span></th> <th>Operations<br><input type="checkbox" id="analysesall"></th> </tr> </thead> <tbody> <?php $sqlstring = "select *, timediff(analysis_enddate, analysis_startdate) 'analysis_time', timediff(analysis_clusterenddate, analysis_clusterstartdate) 'cluster_time' from analysis a left join studies b on a.study_id = b.study_id left join enrollment c on b.enrollment_id = c.enrollment_id left join subjects d on c.subject_id = d.subject_id where a.pipeline_id = {$id} and a.analysis_status not in ('NoMatchingStudies','NoMatchingStudyDependency','IncompleteDependency','BadDependency') order by a.analysis_status desc, study_datetime desc limit {$limitstart}, {$limitcount}"; $result = MySQLiQuery($sqlstring, __FILE__, __LINE__); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $numcomplete += $row['analysis_iscomplete']; $analysistimes[] = $row['analysis_time']; $analysissizes[] = $row['analysis_disksize']; $clustertimes[] = $row['cluster_time']; } $minsize = min($analysissizes); $maxsize = max($analysissizes); $minanalysistime = min($analysistimes); $maxanalysistime = max($analysistimes); $minclustertime = min($clustertimes); $maxclustertime = max($clustertimes); /* rewind the result */ mysqli_data_seek($result, 0); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $analysis_id = $row['analysis_id']; $analysis_qsubid = $row['analysis_qsubid']; $analysis_status = $row['analysis_status']; $analysis_numseries = $row['analysis_numseries']; $analysis_statusmessage = $row['analysis_statusmessage']; $analysis_statusdatetime = $row['analysis_statusdatetime']; $analysis_swversion = $row['analysis_swversion']; $analysis_iscomplete = $row['analysis_iscomplete']; $analysis_time = $row['analysis_time']; $analysis_size = $row['analysis_disksize']; $analysis_isbad = $row['analysis_isbad']; $notes = $row['analysis_notes']; $analysis_hostname = $row['analysis_hostname']; $cluster_time = $row['cluster_time']; $analysis_enddate = date('Y-m-d H:i', strtotime($row['analysis_enddate'])); if ($row['analysis_clusterenddate'] == "") { $analysis_clusterenddate = "-"; } else { $analysis_clusterenddate = date('Y-m-d H:i', strtotime($row['analysis_clusterenddate'])); } $study_id = $row['study_id']; $study_num = $row['study_num']; $study_datetime = date('M j, Y H:i', strtotime($row['study_datetime'])); $uid = $row['uid']; $visittype = $row['study_type']; $pipeline_version = $row['pipeline_version']; $pipeline_dependency = $row['pipeline_dependency']; $sqlstringA = "select pipeline_submithost from pipelines where pipeline_id = {$id}"; //PrintSQL($sqlstringA); $resultA = MySQLiQuery($sqlstringA, __FILE__, __LINE__); $rowA = mysqli_fetch_array($resultA, MYSQLI_ASSOC); $pipeline_submithost = $rowA['pipeline_submithost']; if ($pipeline_submithost == "") { $pipeline_submithost = $GLOBALS['cfg']['clustersubmithost']; } $sqlstringA = "select pipeline_name, pipeline_submithost from pipelines where pipeline_id = {$pipeline_dependency}"; $resultA = MySQLiQuery($sqlstringA, __FILE__, __LINE__); $rowA = mysqli_fetch_array($resultA, MYSQLI_ASSOC); $pipeline_dep_name = $rowA['pipeline_name']; if ($notes == "") { $notestitle = "Click to create notes"; $notescolor = "#DDD"; } else { $notestitle = $notes; $notescolor = "C00"; } if ($analysis_isbad) { $rowcolor = "#f2d7d7"; } else { $rowcolor = ""; } /* get color index for the size */ $sizeindex = 0; if ($analysis_size > 0) { $sizeindex = round($analysis_size / ($maxsize - $minsize) * 100.0); if ($sizeindex > 100) { $sizeindex = 100; } $sizecolor = $colors[$sizeindex]; } else { $sizecolor = "#fff"; } //echo "$analysis_size, $sizeindex, $sizecolor, $maxsize<br>"; ?> <script> function GetAnalysisNotes<?php echo $analysis_id; ?> (){ var analysisnotes = prompt("Enter notes for this analysis","<?php echo $notestitle; ?> "); if (analysisnotes != null){ //$("#analysisnotes").attr("value", analysisnotes); document.studieslist.analysisnotes.value = analysisnotes; document.studieslist.action.value = 'setanalysisnotes'; document.studieslist.id.value = '<?php echo $id; ?> '; document.studieslist.analysisid.value = '<?php echo $analysis_id; ?> '; document.studieslist.submit(); } } </script> <tr bgcolor="<?php echo $rowcolor; ?> "> <td class="allstudies" style="text-align:left"><input type="checkbox" name="studyid[]" value="<?php echo $study_id; ?> "> <a href="studies.php?id=<?php echo $study_id; ?> "><?php echo $uid; echo $study_num; ?> </a></td> <td><?php echo $visittype; ?> </td> <td><?php echo $pipeline_version; ?> </td> <?php if ($pipeline_level == 1) { ?> <td class="tiny"><?php echo $study_datetime; ?> </td> <td><?php echo $analysis_numseries; ?> </td> <?php } ?> <td> <?php if ($analysis_status == 'processing' && $analysis_qsubid != 0) { //$systemstring = "SGE_ROOT=/sge/sge-root; export SGE_ROOT; SGE_CELL=nrccell; export SGE_CELL; cd /sge/sge-root/bin/lx24-amd64; ./qstat -j $analysis_qsubid"; $systemstring = "ssh {$pipeline_submithost} qstat -j {$analysis_qsubid}"; //echo "$systemstring"; //$out = shell_exec($systemstring); if (trim($out) == "hi") { ?> <img src="images/alert.png" title="Analysis is marked as running, but the cluster job is not.<br><br>This means the analysis is being setup and the data is being copied or the cluster job failed. Check log files for error"><?php } ?> <!--<a class="fancybox" title="SGE status" href="pipelines.php?action=viewjob&id=<?php echo $analysis_qsubid; ?> ">processing</a>--> <a href="<?php echo $GLOBALS['cfg']['siteurl']; ?> /pipelines.php?action=viewjob&id=<?php echo $analysis_qsubid; ?> ">processing</a> <?php } else { if ($analysis_qsubid == 0) { echo "Preparing data"; } else { echo $analysis_status; } } ?> </td> <td style="font-weight: bold; color: green"><?php if ($analysis_iscomplete) { echo "✓"; } ?> </td> <?php if ($analysis_status != "") { ?> <td><a href="#" class="viewlog" id="<?php echo $analysis_id; ?> "><img src="images/preview.gif"></a></td> <td><a href="#" class="viewfiles" id="<?php echo $analysis_id; ?> "><img src="images/folder.gif"></a></td> <td><a href="#" class="viewresults" id="<?php echo $analysis_id; ?> "><img src="images/chart-vertical.png"></a></td> <?php } else { ?> <td></td> <td></td> <?php } ?> <td> <span onClick="GetAnalysisNotes<?php echo $analysis_id; ?> ();" style="cursor:hand; font-size:14pt; color: <?php echo $notescolor; ?> " title="<?php echo $notestitle; ?> ">✎</span> </td> <td style="font-size:9pt; white-space:nowrap"> <?php echo $analysis_statusmessage; ?> <br> <?php if (strpos($analysis_statusmessage, "processing step") !== false) { $parts = explode(" ", $analysis_statusmessage); $stepnum = $parts[2]; $steptotal = $parts[4]; ?> <img src="horizontalchart.php?b=no&w=150&h=3&v=<?php echo $stepnum; ?> ,<?php echo $steptotal - $stepnum; ?> &c=666666,DDDDDD" style="margin:2px"><br> <?php } ?> <span class="tiny"><?php echo $analysis_statusdatetime; ?> </span> </td> <td align="right" style="font-size:8pt; border-bottom: 5px solid <?php echo $sizecolor; ?> ; margin-bottom:0px; padding-bottom:0px" valign="bottom"> <?php echo number_format($analysis_size, 0); ?> <table cellspacing="0" cellpadding="0" border="0" width="100%" height="5px" style="margin-top:5px"> <tr> <td width="100%" height="5px" style="background-color: <?php echo $sizecolor; ?> ; height:5px; font-size: 1pt; border: 0px"> </td> </tr> </table> </td> <td><?php echo $analysis_hostname; ?> </td> <td><?php echo $analysis_time; ?> <br><span class="tiny"><?php echo $analysis_enddate; ?> </span></td> <td><?php echo $cluster_time; ?> <br><span class="tiny"><?php echo $analysis_clusterenddate; ?> </span></td> <td class="allanalyses" ><input type="checkbox" name="analysisids[]" value="<?php echo $analysis_id; ?> "></td> </tr> <?php } ?> <script> function GetDestination(){ var destination = prompt("Please enter a valid destination for the selected analyses","/home/<?php echo $GLOBALS['username']; ?> /onrc/data"); if (destination != null){ //document.studieslist.destination.value = desination; document.studieslist.action='pipelines.php'; //document.studieslist.action.value='copyanalyses'; $("#studieslistaction").attr("value", "copyanalyses"); $("#studieslistdestination").attr("value", destination); document.studieslist.submit(); } } function GetDestination2(){ var destination = prompt("Please enter a valid directory in which to create the 'data' directory and links","/home/<?php echo $GLOBALS['username']; ?> /onrc/data"); if (destination != null){ document.studieslist.action='pipelines.php'; $("#studieslistaction").attr("value", "createlinks"); $("#studieslistdestination").attr("value", destination); document.studieslist.submit(); } } function MarkAnalysis(){ document.studieslist.action='pipelines.php'; document.studieslist.submit(); } </script> <tr style="color: #444; font-size:12pt; font-weight:bold"> <td colspan="8" valign="top" style="background-color: #fff"> <table> <tr> <td valign="top" style="color: #444; font-size:12pt; font-weight:bold; border-top:none"> Studies group </td> <td valign="top" style="border-top:none"> <select name="studygroupid" style="width:150px"> <?php $sqlstring = "select * from groups where group_type = 'study'"; $result = MySQLiQuery($sqlstring, __FILE__, __LINE__); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $groupid = $row['group_id']; $groupname = $row['group_name']; ?> <option value="<?php echo $groupid; ?> "><?php echo $groupname; ?> <?php } ?> </select> <input type="submit" name="addtogroup" value="Add" onclick="document.studieslist.action='groups.php';document.studieslist.action.value='addstudiestogroup'"> </td> </tr> </table> </td> <td colspan="8" align="right" style="background-color: #fff; font-size: 12pt"> With selected: <br><br> <input type="submit" value="Delete" style="border: 1px solid red; background-color: pink; width:150px; margin:4px" onclick="document.studieslist.action.value='deleteanalyses';return confirm('Are you absolutely sure you want to DELETE the selected analyses?')" title="<b style='color:pink'>Pipeline will be disabled. Wait until the deletions are compelte before reenabling the pipeline</b><Br> This will delete the selected analyses, which will be regenerated using the latest pipeline version"> <br><br><br> <input type="button" name="copyanalyses" value="Copy analyses to..." style="width: 150px; margin:4px" onclick="document.studieslist.action='pipelines.php';document.studieslist.action.value='copyanalyses';GetDestination()"> <br> <input type="button" name="createlinks" value="Create links..." style="width: 150px; margin:4px" onclick="document.studieslist.action='pipelines.php';document.studieslist.action.value='createlinks';GetDestination2()" title="Creates a directory called 'data' which contains links to all of the selected studies"> <br> <input type="button" name="rerunresults" value="Re-run results script" style="width: 150px; margin:4px" onclick="document.studieslist.action='pipelines.php';document.studieslist.action.value='rerunresults';document.studieslist.submit();" title="This will delete any existing results inserted into NiDB and re-run the results script"> <br> <input type="button" name="runsupplement" value="Run supplement script" style="width: 150px; margin:4px" onclick="document.studieslist.action='pipelines.php';document.studieslist.action.value='runsupplement';document.studieslist.submit();" title="Run the script specified in the supplemental command script. This will not download new data or re-download existing data. It will only perform commands on the existing files in the analysis directory"> <br> <input type="button" name="rechecksuccess" value="Re-check if successful" style="width: 150px; margin:4px" onclick="document.studieslist.action='pipelines.php';document.studieslist.action.value='rechecksuccess';document.studieslist.submit();" title="This option will check the selected analyses against the 'successfully completed files' field and mark them as successful if the file(s) exist"> <br><br> <input type="button" name="markasbad" value="Mark as bad" style="width: 150px; margin:4px" onclick="document.studieslist.action='pipelines.php';document.studieslist.action.value='markbad'; MarkAnalysis()" title="Mark the analyses as bad so they will not be used in dependent pipelines"> <br> <input type="button" name="markasgood" value="Mark as good" style="width: 150px; margin:4px" onclick="document.studieslist.action='pipelines.php';document.studieslist.action.value='markgood'; MarkAnalysis()" title="Unmark an analysis as bad"> </td> </tr> </tbody> </table> </form> <?php }
function DisplayMRSeries($id, $study_num, $uid, $audit, $fix) { $colors = GenerateColorGradient(); /* get the subject information */ $sqlstring = "select * from subjects a left join enrollment b on a.subject_id = b.subject_id left join studies c on b.enrollment_id = c.enrollment_id where c.study_id = $id"; $result = MySQLQuery($sqlstring, __FILE__, __LINE__); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result, MYSQL_ASSOC); $dbsubjectname = $row['name']; $dbsubjectdob = $row['birthdate']; $dbsubjectsex = $row['gender']; $dbstudydatetime = $row['study_datetime']; } else { echo "$sqlstring<br>"; } /* get the movement & SNR stats by sequence name */ $sqlstring2 = "SELECT b.series_sequencename, max(a.move_maxx) 'maxx', min(a.move_minx) 'minx', max(a.move_maxy) 'maxy', min(a.move_miny) 'miny', max(a.move_maxz) 'maxz', min(a.move_minz) 'minz', avg(a.pv_snr) 'avgpvsnr', avg(a.io_snr) 'avgiosnr', std(a.pv_snr) 'stdpvsnr', std(a.io_snr) 'stdiosnr', min(a.pv_snr) 'minpvsnr', min(a.io_snr) 'miniosnr', max(a.pv_snr) 'maxpvsnr', max(a.io_snr) 'maxiosnr', min(a.motion_rsq) 'minmotion', max(a.motion_rsq) 'maxmotion', avg(a.motion_rsq) 'avgmotion', std(a.motion_rsq) 'stdmotion' FROM mr_qa a left join mr_series b on a.mrseries_id = b.mrseries_id where a.io_snr > 0 group by b.series_sequencename"; //echo "$sqlstring2<br>"; $result2 = MySQLQuery($sqlstring2, __FILE__, __LINE__); while ($row2 = mysql_fetch_array($result2, MYSQL_ASSOC)) { $sequence = $row2['series_sequencename']; $pstats[$sequence]['rangex'] = abs($row2['minx']) + abs($row2['maxx']); $pstats[$sequence]['rangey'] = abs($row2['miny']) + abs($row2['maxy']); $pstats[$sequence]['rangez'] = abs($row2['minz']) + abs($row2['maxz']); $pstats[$sequence]['avgpvsnr'] = $row2['avgpvsnr']; $pstats[$sequence]['stdpvsnr'] = $row2['stdpvsnr']; $pstats[$sequence]['minpvsnr'] = $row2['minpvsnr']; $pstats[$sequence]['maxpvsnr'] = $row2['maxpvsnr']; $pstats[$sequence]['avgiosnr'] = $row2['avgiosnr']; $pstats[$sequence]['stdiosnr'] = $row2['stdiosnr']; $pstats[$sequence]['miniosnr'] = $row2['miniosnr']; $pstats[$sequence]['maxiosnr'] = $row2['maxiosnr']; $pstats[$sequence]['avgmotion'] = $row2['avgmotion']; $pstats[$sequence]['stdmotion'] = $row2['stdmotion']; $pstats[$sequence]['minmotion'] = $row2['minmotion']; $pstats[$sequence]['maxmotion'] = $row2['maxmotion']; if ($row2['stdiosnr'] != 0) { $pstats[$sequence]['maxstdiosnr'] = ($row2['avgiosnr'] - $row2['miniosnr'])/$row2['stdiosnr']; } else { $pstats[$sequence]['maxstdiosnr'] = 0; } if ($row2['stdpvsnr'] != 0) { $pstats[$sequence]['maxstdpvsnr'] = ($row2['avgpvsnr'] - $row2['minpvsnr'])/$row2['stdpvsnr']; } else { $pstats[$sequence]['maxstdpvsnr'] = 0; } if ($row2['stdmotion'] != 0) { $pstats[$sequence]['maxstdmotion'] = ($row2['avgmotion'] - $row2['minmotion'])/$row2['stdmotion']; } else { $pstats[$sequence]['maxstdmotion'] = 0; } } //print_r($pstats); ?> <script> $(document).ready(function() { $(".highlightblack").hide(); $(".highlightred").hide(); $(".highlightorange").hide(); $(".highlightyellow").hide(); $(".highlightgreen").hide(); $(".ratingdiv").hover( function() { $(this).children(".highlightblack").show(); }, function() { $(this).children(".highlightblack").hide(); } ); $(".ratingdiv").hover( function() { $(this).children(".highlightred").show(); }, function() { $(this).children(".highlightred").hide(); } ); $(".ratingdiv").hover( function() { $(this).children(".highlightorange").show(); }, function() { $(this).children(".highlightorange").hide(); } ); $(".ratingdiv").hover( function() { $(this).children(".highlightyellow").show(); }, function() { $(this).children(".highlightyellow").hide(); } ); $(".ratingdiv").hover( function() { $(this).children(".highlightgreen").show(); }, function() { $(this).children(".highlightgreen").hide(); } ); }); $(function() { $( document ).tooltip({show:{effect:'appear'}, hide:{duration:0}}); }); </script> <style type="text/css"> .edit_inline { background-color: lightyellow; padding-left: 2pt; padding-right: 2pt; } .edit_textarea { background-color: lightyellow; } textarea.inplace_field { background-color: white; font-family: courier new; font-size: 8pt; border: 1pt solid gray; width: 800px; } input.inplace_field { background-color: white; font-size: 8pt; border: 1pt solid gray; width: 200px; } </style> <table class="smallgraydisplaytable" width="100%"> <thead> <tr> <th>Series</th> <th>Upload Beh</th> <th>Protocol</th> <th title="Time of the start of the series acquisition">Time</th> <th>Notes</th> <th title="View movement graph and FFT">QA</th> <th title="Analyst ratings and notes">Ratings</th> <th title="Total displacement in X direction">X</th> <th title="Total displacement in Y direction">Y</th> <th title="Total displacement in Z direction">Z</th> <th title="Per Voxel SNR (timeseries) - Calculated from the fslstats command">PV<br>SNR</th> <th title="Inside-Outside SNR - This calculates the brain signal (center of brain-extracted volume) compared to the average of the volume corners">IO<br>SNR</th> <th>Motion R<sup>2</sup></th> <th>Sequence</th> <th>Length<br><span class="tiny">approx.</span></th> <th>TR<br><span class="tiny">ms</span></th> <th>Spacing <br><span class="tiny">(x y z)</span></th> <th>Image size <br><span class="tiny">(x y z)</span></th> <th>BOLD reps</th> <th># files</th> <th>Size</th> <th>Beh</th> <? if ($GLOBALS['issiteadmin']) { ?> <th>Hide</th> <th>Reset QA</th> <? } ?> </tr> </thead> <tbody> <? /* just get a list of MR series ids */ $sqlstring = "select mrseries_id from mr_series where study_id = $id order by series_num"; $result = MySQLQuery($sqlstring, __FILE__, __LINE__); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $mrseriesids[] = $row['mrseries_id']; } /* get the rating information */ if (count($mrseriesids) < 1) { ?> <tr> <td colspan="22" align="center">No series found for this study</td> </tr> <? } else { $sqlstring3 = "select * from ratings where rating_type = 'series' and data_modality = 'MR' and data_id in (" . implode(',',$mrseriesids) . ")"; $result3 = MySQLQuery($sqlstring3, __FILE__, __LINE__); while ($row3 = mysql_fetch_array($result3, MYSQL_ASSOC)) { $ratingseriesid = $row3['data_id']; $ratings[$ratingseriesid][] = $row3['rating_value']; } //print_r($ratings); /* get the actual MR series info */ mysql_data_seek($result,0); $sqlstring = "select * from mr_series where study_id = $id order by series_num"; $result = MySQLQuery($sqlstring, __FILE__, __LINE__); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $mrseries_id = $row['mrseries_id']; $series_datetime = date('g:ia',strtotime($row['series_datetime'])); $protocol = $row['series_protocol']; $series_desc = $row['series_desc']; $sequence = $row['series_sequencename']; $series_num = $row['series_num']; $series_tr = $row['series_tr']; $series_te = $row['series_te']; $series_flip = $row['series_flip']; $phasedir = $row['phaseencodedir']; $phaseangle = $row['phaseencodeangle']; $series_spacingx = $row['series_spacingx']; $series_spacingy = $row['series_spacingy']; $series_spacingz = $row['series_spacingz']; $series_fieldstrength = $row['series_fieldstrength']; $img_rows = $row['img_rows']; $img_cols = $row['img_cols']; $img_slices = $row['img_slices']; $bold_reps = $row['bold_reps']; $numfiles = $row['numfiles']; $series_size = $row['series_size']; $series_status = $row['series_status']; $series_notes = $row['series_notes']; $beh_size = $row['beh_size']; $numfiles_beh = $row['numfiles_beh']; $data_type = $row['data_type']; $lastupdate = $row['lastupdate']; $image_type = $row['image_type']; $image_comments = $row['image_comments']; $ishidden = $row['ishidden']; if (($numfiles_beh == '') || ($numfiles_beh == 0)) { /* get the number and size of the beh files */ $behs = glob($GLOBALS['cfg']['archivedir'] . "/$uid/$study_num/$series_num/beh/*"); //print_r($behs); $numfiles_beh = count($behs); $totalsize = 0; foreach ($behs as $behfile) { $beh_size += filesize($behfile); } if ($numfiles_beh > 0) { $sqlstring5 = "update mr_series set beh_size = '$beh_size', numfiles_beh = '$numfiles_beh' where mrseries_id = $mrseries_id"; $result5 = MySQLQuery($sqlstring5, __FILE__, __LINE__); } } if ($phasedir == "COL") { // A>>P or P>>A if ($phaseangle == 0) { $phase = "A >> P"; } elseif ((abs($phaseangle) > 3.1) && (abs($phaseangle) < 3.2)) { $phase = "P >> A"; } else { $phase = "COL"; } } else { // R>>L or L>>R if (($phaseangle > 1.5) && ($phaseangle < 1.6)) { $phase = "R >> L"; } elseif (($phaseangle < -1.5) && ($phaseangle > -1.6)) { $phase = "L >> R"; } else { $phase = "ROW"; } } $behdir = ""; if (trim($protocol) == "") { $protocol = "(blank)"; } $scanlengthsec = ($series_tr * $numfiles)/1000.0; //echo "[Secs: $scanlengthsecs]"; $scanlength = floor($scanlengthsec/60.0) . ":" . sprintf("%02d",round(fmod($scanlengthsec,60.0))); if ( (preg_match("/epfid2d1/i",$sequence)) && ($numfiles_beh < 1)) { $behcolor = "red"; } else { $behcolor = ""; } if ($numfiles_beh < 1) { $numfiles_beh = "-"; } $thumbpath = $GLOBALS['cfg']['archivedir'] . "/$uid/$study_num/$series_num/thumb.png"; $gifthumbpath = $GLOBALS['cfg']['archivedir'] . "/$uid/$study_num/$series_num/thumb.gif"; $realignpath = $GLOBALS['cfg']['archivedir'] . "/$uid/$study_num/$series_num/MotionCorrection.txt"; $sqlstring2 = "select * from mr_qa where mrseries_id = $mrseries_id"; $result2 = MySQLQuery($sqlstring2, __FILE__, __LINE__); $row2 = mysql_fetch_array($result2, MYSQL_ASSOC); $iosnr = $row2['io_snr']; $pvsnr = $row2['pv_snr']; $move_minx = $row2['move_minx']; $move_miny = $row2['move_miny']; $move_minz = $row2['move_minz']; $move_maxx = $row2['move_maxx']; $move_maxy = $row2['move_maxy']; $move_maxz = $row2['move_maxz']; $acc_minx = $row2['acc_minx']; $acc_miny = $row2['acc_miny']; $acc_minz = $row2['acc_minz']; $acc_maxx = $row2['acc_maxx']; $acc_maxy = $row2['acc_maxy']; $acc_maxz = $row2['acc_maxz']; $motion_rsq = $row2['motion_rsq']; $rangex = abs($move_minx) + abs($move_maxx); $rangey = abs($move_miny) + abs($move_maxy); $rangez = abs($move_minz) + abs($move_maxz); $rangex2 = abs($acc_minx) + abs($acc_maxx); $rangey2 = abs($acc_miny) + abs($acc_maxy); $rangez2 = abs($acc_minz) + abs($acc_maxz); $stdsmotion = 0; /* calculate color based on voxel size... red (100) means more than 1 voxel displacement in that direction */ if ($series_spacingx > 0) { $xindex = round(($rangex/$series_spacingx)*100); if ($xindex > 100) { $xindex = 100; } $xindex2 = round(($rangex2/$series_spacingx)*100); if ($xindex2 > 100) { $xindex2 = 100; } } if ($series_spacingy > 0) { $yindex = round(($rangey/$series_spacingy)*100); if ($yindex > 100) { $yindex = 100; } $yindex2 = round(($rangey2/$series_spacingy)*100); if ($yindex2 > 100) { $yindex2 = 100; } } if ($series_spacingz > 0) { $zindex = round(($rangez/$series_spacingz)*100); if ($zindex > 100) { $zindex = 100; } $zindex2 = round(($rangez2/$series_spacingz)*100); if ($zindex2 > 100) { $zindex2 = 100; } } /* get standard deviations from the mean for SNR */ if ($pstats[$sequence]['stdiosnr'] != 0) { if ($iosnr > $pstats[$sequence]['avgiosnr']) { $stdsiosnr = 0; } else { $stdsiosnr = (($iosnr - $pstats[$sequence]['avgiosnr'])/$pstats[$sequence]['stdiosnr']); } } if ($pstats[$sequence]['stdpvsnr'] != 0) { if ($pvsnr > $pstats[$sequence]['avgpvsnr']) { $stdspvsnr = 0; } else { $stdspvsnr = (($pvsnr - $pstats[$sequence]['avgpvsnr'])/$pstats[$sequence]['stdpvsnr']); } } if ($pstats[$sequence]['stdmotion'] != 0) { if ($motion_rsq > $pstats[$sequence]['avgmotion']) { $stdmotion = 0; } else { $stdmotion = (($motion_rsq - $pstats[$sequence]['avgmotion'])/$pstats[$sequence]['stdmotion']); } } if ($pstats[$sequence]['maxstdpvsnr'] == 0) { $pvindex = 100; } else { $pvindex = round(($stdspvsnr/$pstats[$sequence]['maxstdpvsnr'])*100); } $pvindex = 100 + $pvindex; if ($pvindex > 100) { $pvindex = 100; } if ($pstats[$sequence]['maxstdiosnr'] == 0) { $ioindex = 100; } else { $ioindex = round(($stdsiosnr/$pstats[$sequence]['maxstdiosnr'])*100); } $ioindex = 100 + $ioindex; if ($ioindex > 100) { $ioindex = 100; } if ($ioindex < 0) { $ioindex = 0; } if ($pstats[$sequence]['maxstdmotion'] == 0) { $motionindex = 100; } else { $motionindex = round(($stdmotion/$pstats[$sequence]['maxstdmotion'])*100); } $motionindex = 100 + $motionindex; if ($motionindex > 100) { $motionindex = 100; } if ($motionindex < 0) { $motionindex = 0; } //echo "[ioindex: $ioindex]"; $maxpvsnrcolor = $colors[100-$pvindex]; $maxiosnrcolor = $colors[100-$ioindex]; $maxmotioncolor = $colors[100-$motionindex]; if ($pvsnr <= 0.0001) { $pvsnr = "-"; $maxpvsnrcolor = ""; } else { $pvsnr = number_format($pvsnr,2); } if ($iosnr <= 0.0001) { $iosnr = "-"; $maxiosnrcolor = ""; } else { $iosnr = number_format($iosnr,2); } //if ($motion_rsq <= 0.0001) { $motion_rsq = "-"; $maxmotioncolor = ""; } //else { $motion_rsq = number_format($motion_rsq,2); } /* setup movement colors */ $maxxcolor = $colors[$xindex]; $maxycolor = $colors[$yindex]; $maxzcolor = $colors[$zindex]; if ($rangex <= 0.0001) { $rangex = "-"; $maxxcolor = ""; } else { $rangex = number_format($rangex,2); } if ($rangey <= 0.0001) { $rangey = "-"; $maxycolor = ""; } else { $rangey = number_format($rangey,2); } if ($rangez <= 0.0001) { $rangez = "-"; $maxzcolor = ""; } else { $rangez = number_format($rangez,2); } /* setup acceleration colors */ $maxxcolor2 = $colors[$xindex2]; $maxycolor2 = $colors[$yindex2]; $maxzcolor2 = $colors[$zindex2]; if ($rangex2 <= 0.0001) { $rangex2 = "-"; $maxxcolor2 = ""; } else { $rangex2 = number_format($rangex2,2); } if ($rangey2 <= 0.0001) { $rangey2 = "-"; $maxycolor2 = ""; } else { $rangey2 = number_format($rangey2,2); } if ($rangez2 <= 0.0001) { $rangez2 = "-"; $maxzcolor2 = ""; } else { $rangez2 = number_format($rangez2,2); } /* format the motion r^2 value */ if ($motion_rsq == 0) { $motion_rsq = '-'; $maxmotioncolor = ""; } else { $motion_rsq = number_format($motion_rsq,5); } /* get manually entered QA info */ $sqlstringC = "select avg(value) 'avgrating', count(value) 'count' from manual_qa where series_id = $mrseries_id and modality = 'MR'"; //PrintSQL($sqlstringC); $resultC = MySQLQuery($sqlstringC, __FILE__, __LINE__); $rowC = mysql_fetch_array($resultC, MYSQL_ASSOC); $avgrating = $rowC['avgrating']; $ratingcount = $rowC['count']; if ($avgrating < 0.5) { $manualqacolor = "black"; } if (($avgrating >= 0.5) && ($avgrating < 1.5)) { $manualqacolor = "#FF0000"; } if (($avgrating >= 1.5) && ($avgrating <= 3.0)) { $manualqacolor = "#00FF00"; } if ($ratingcount < 1) { $manualqacolor = "#EFEFEF"; } /* check if this is real data, or unusable data based on the ratings, and get rating counts */ $isbadseries = false; $istestseries = false; $ratingcount2 = ''; $hasratings = false; $rowcolor = ''; //print_r($ratings); if (isset($ratings)) { foreach ($ratings as $key => $ratingarray) { if ($key == $mrseries_id) { $hasratings = true; if (in_array(5,$ratingarray)) { $isbadseries = true; } if (in_array(6,$ratingarray)) { $istestseries = true; } $ratingcount2 = count($ratingarray); break; } } } if ($isbadseries) { $rowcolor = "red"; } if ($istestseries) { $rowcolor = "#AAAAAA"; } if ($ishidden) { $rowcolor = "AAA"; } /* --- audit the dicom files --- */ $dupes = null; $dcmcount = 0; if ($audit) { $dicoms = glob($GLOBALS['cfg']['archivedir'] . "/$uid/$study_num/$series_num/dicom/*.dcm"); //print_r($dicoms); $dcmcount = count($dicoms); if ($dcmcount > 0) { //$filename = $dicoms[0]; $mergeddcms = null; foreach ($dicoms as $dcmfile) { $dicom = Nanodicom::factory($dcmfile, 'simple'); $dicom->parse(array(array(0x0010, 0x0010), array(0x0010, 0x0030), array(0x0010, 0x0040), array(0x0018, 0x1030), array(0x0008, 0x103E), array(0x0010, 0x0020), array(0x0020, 0x0012), array(0x0020, 0x0013), array(0x0008, 0x0020), array(0x0008, 0x0030), array(0x0008, 0x0032))); $dicom->profiler_diff('parse'); $filesubjectname = trim($dicom->value(0x0010, 0x0010)); $filesubjectdob = trim($dicom->value(0x0010, 0x0030)); $filesubjectsex = trim($dicom->value(0x0010, 0x0040)); $fileprotocol = trim($dicom->value(0x0018, 0x1030)); $fileseriesdesc = trim($dicom->value(0x0008, 0x103E)); $fileseriesnum = trim($dicom->value(0x0020, 0x0011)); $filescanid = trim($dicom->value(0x0010, 0x0020)); $fileinstancenumber = trim($dicom->value(0x0020, 0x0013)); $fileslicenumber = trim($dicom->value(0x0020, 0x0012)); $fileacquisitiontime = trim($dicom->value(0x0008, 0x0032)); $filecontenttime = trim($dicom->value(0x0008, 0x0033)); $filestudydate = trim($dicom->value(0x0008, 0x0020)); $filestudytime = trim($dicom->value(0x0008, 0x0030)); unset($dicom); //echo "<pre>$fileprotocol, $protocol -- $fileslicenumber, $fileinstancenumber - [$filestudydate $filestudytime] - [$dbstudydatetime]</pre><br>"; $filestudydatetime = $filestudydate . substr($filestudytime,0,6); $dbstudydatetime = str_replace(array(":","-"," "),"",$dbstudydatetime); $dbsubjectdob = str_replace(array(":","-"," "),"",$dbsubjectdob); if ( ($fileprotocol != $protocol) || ($dbsubjectname != $filesubjectname) || ($dbsubjectdob != $filesubjectdob) || ($dbsubjectsex != $filesubjectsex) || ($series_num != $fileseriesnum) || ($filestudydatetime != $dbstudydatetime) ) { if ($fileprotocol != $protocol) { //echo "Protocol does not match (File: $fileprotocol DB: $protocol)<br>"; //echo "files don't match DB<br>"; $errantdcms[]{'filename'} = $dcmfile; $errantdcms[]{'error'} = "Protocol does not match (File: $fileprotocol DB: $protocol)"; } if (strcasecmp($dbsubjectname,$filesubjectname) != 0) { if (($dbsubjectname == "") && ($filesubjectname) != "") { //echo "Patient name does not match (File: $filesubjectname DB: $dbsubjectname)<br>"; $errantdcms[]{'filename'} = $dcmfile; $errantdcms[]{'error'} = "Patient name does not match (File: $filesubjectname DB: $dbsubjectname)"; } elseif (($filesubjectname == "") && ($dbsubjectname) != "") { //echo "Patient name does not match (File: $filesubjectname DB: $dbsubjectname)<br>"; $errantdcms[]{'filename'} = $dcmfile; $errantdcms[]{'error'} = "Patient name does not match (File: $filesubjectname DB: $dbsubjectname)"; } else { if ((stristr($dbsubjectname, $filesubjectname) === false) && (stristr($filesubjectname, $dbsubjectname) === false)) { //echo "Patient name does not match (File: $filesubjectname DB: $dbsubjectname)<br>"; $errantdcms[]{'filename'} = $dcmfile; $errantdcms[]{'error'} = "Patient name does not match (File: $filesubjectname DB: $dbsubjectname)"; } } } if ($dbsubjectdob != $filesubjectdob) { //echo "Patient DOB does not match (File: $filesubjectdob DB: $dbsubjectdob)<br>"; $errantdcms[]{'filename'} = $dcmfile; $errantdcms[]{'error'} = "Patient DOB does not match (File: $filesubjectdob DB: $dbsubjectdob)"; } if ($dbsubjectsex != $filesubjectsex) { //echo "Patient sex does not match (File: $filesubjectsex DB: $dbsubjectsex)<br>"; $errantdcms[]{'filename'} = $dcmfile; $errantdcms[]{'error'} = "Patient sex does not match (File: $filesubjectsex DB: $dbsubjectsex)"; } if ($series_num != $fileseriesnum) { //echo "Series number does not match (File: $fileseriesnum DB: $series_num)<br>"; $errantdcms[]{'filename'} = $dcmfile; $errantdcms[]{'error'} = "Series number does not match (File: $fileseriesnum DB: $series_num)"; } if ($filestudydatetime != $dbstudydatetime) { //echo "Study datetime does not match (File: $filestudydatetime DB: $dbstudydatetime)<br>"; $errantdcms[]{'filename'} = $dcmfile; $errantdcms[]{'error'} = "Study datetime does not match (File: $filestudydatetime DB: $dbstudydatetime)"; } } $mergeddcms{$filesubjectname}{$filesubjectdob}{$filesubjectsex}{$filestudydate}{$filestudytime}{$fileseriesnum}{$fileslicenumber}{$fileinstancenumber}{$fileacquisitiontime}{$filecontenttime}[] = $dcmfile; if (count($mergeddcms{$filesubjectname}{$filesubjectdob}{$filesubjectsex}{$filestudydate}{$filestudytime}{$fileseriesnum}{$fileslicenumber}{$fileinstancenumber}{$fileacquisitiontime}{$filecontenttime}) > 1) { /* check the MD5 hash to see if the files really are the same */ //$hash1 = md5_file( //echo "Series $fileseriesnum contains duplicate files<br>"; $dupes[$series_num] = 1; if ($fix) { /* move the duplicate file to the dicom/extra directory */ if (!file_exists($GLOBALS['cfg']['archivedir'] . "/$uid/$study_num/$series_num/dicom/duplicates")) { mkdir($GLOBALS['cfg']['archivedir'] . "/$uid/$study_num/$series_num/dicom/duplicates"); } echo "Moving [$dcmfile] -> [" . $GLOBALS['cfg']['archivedir'] . "/$uid/$study_num/$series_num/dicom/duplicates/" . GenerateRandomString(20) . ".dcm]<br>"; rename($dcmfile, $GLOBALS['cfg']['archivedir'] . "/$uid/$study_num/$series_num/dicom/duplicates/" . GenerateRandomString(20) . ".dcm"); } } } } /* move the errant files */ if ($fix) { for($i=0;$i<count($errantdcms);$i++) { echo "Moving [$errantdcms[$i]{'filename'}] -> [" . $GLOBALS['dicomincomingpath'] . "/" . GenerateRandomString(20) . ".dcm]<br>"; rename($errantdcms[$i]{'filename'},$GLOBALS['dicomincomingpath'] . "/" . GenerateRandomString(20) . ".dcm"); } /* rename the files in the directory */ $dicoms = glob($GLOBALS['cfg']['archivedir'] . "/$uid/$study_num/$series_num/dicom/*.dcm"); //print_r($dicoms); $dcmcount = count($dicoms); if ($dcmcount > 0) { $dcmsize = 0; foreach ($dicoms as $dcmfile) { $dicom = Nanodicom::factory($dcmfile, 'simple'); $dicom->parse(array(array(0x0010, 0x0010), array(0x0010, 0x0030), array(0x0010, 0x0040), array(0x0018, 0x1030), array(0x0008, 0x103E), array(0x0010, 0x0020), array(0x0020, 0x0012), array(0x0020, 0x0013), array(0x0008, 0x0020), array(0x0008, 0x0030), array(0x0008, 0x0032))); $dicom->profiler_diff('parse'); $fileseriesnum = trim($dicom->value(0x0020, 0x0011)); $fileinstancenumber = trim($dicom->value(0x0020, 0x0013)); $fileslicenumber = trim($dicom->value(0x0020, 0x0012)); $fileacquisitiontime = trim($dicom->value(0x0008, 0x0032)); unset($dicom); $dcmsize += filesize($dcmfile); $newdcmfile = $GLOBALS['cfg']['archivedir'] . "/$uid/$study_num/$series_num/dicom/$uid" . "_$study_num" . "_$series_num" . "_" . sprintf("%05d",$fileslicenumber) . "_" . sprintf("%05d",$fileinstancenumber) . "_$fileacquisitiontime.dcm"; //if (file_exists($newdcmfile)) { /* some DTI files are weird, so we'll append the aquisition time */ //} echo "$dcmfile --> $newdcmfile<br>"; rename($dcmfile, $newdcmfile); } /* update the database with the new info */ $sqlstring5 = "update mr_series set series_size = $dcmsize, numfiles = $dcmcount where mrseries_id = $mrseries_id"; $result5 = MySQLQuery($sqlstring5, __FILE__, __LINE__); } } } ?> <script type="text/javascript"> $(document).ready(function(){ $(".edit_inline<? echo $mrseries_id; ?>").editInPlace({ url: "series_inlineupdate.php", params: "action=editinplace&modality=MR&id=<? echo $mrseries_id; ?>", default_text: "<i style='color:#AAAAAA'>Add notes...</i>", bg_over: "white", bg_out: "lightyellow", }); }); </script> <script type="text/javascript"> // Popup window code function newPopup(url) { popupWindow = window.open( url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes') } </script> <style> .ui-tooltip { padding: 7px 7px; border-radius: 5px; font-size: 10px; border: 1px solid black; } </style> <tr style="color: <?php echo $rowcolor; ?> "> <td><?php echo $series_num; ?> <? if ($dupes[$series_num] == 1) { ?><span style="color: white; background-color: red; padding: 1px 5px; font-weight: bold; font-size: 8pt">Contains duplicates</span> <? } ?> </td> <td><span id="uploader<?php echo $mrseries_id; ?> "></span></td> <td title="<b>Series Description</b> <?php echo $series_desc; ?> <br><b>Protocol</b> <?php echo $protocol; ?> <br><b>Sequence Description</b> <?php echo $sequence; ?> <br><b>TE</b> <?php echo $series_te; ?> ms<br><b>Magnet</b> <?php echo $series_fieldstrength; ?> T<br><b>Flip angle</b> <?php echo $series_flip; ?> °<br><b>Image type</b> <?php echo $image_type; ?> <br><b>Image comment</b> <?php echo $image_comments; ?> <br><b>Phase encoding</b> <?php echo $phase; ?> "> <? if ($data_type == "dicom") { $dicoms = glob($GLOBALS['cfg']['archivedir'] . "/$uid/$study_num/$series_num/dicom/*.dcm"); $dcmfile = $dicoms[0]; if (file_exists($dcmfile)) { ?><a href="series.php?action=scanparams&dcmfile=<?php echo $dcmfile; ?> "><?php echo $series_desc; ?> </a><? } else { ?><span style="color: red" title="Files missing from disk"><?php echo $series_desc; ?> </span><? } } else { echo $series_desc; } ?> <br> <? if (file_exists($thumbpath)) { ?> <a href="preview.php?image=<?php echo $thumbpath; ?> " class="preview"><img src="images/preview.gif" border="0"></a> <? } ?> <? if (file_exists($gifthumbpath)) { ?> <a href="preview.php?image=<?php echo $gifthumbpath; ?> " class="preview"><img src="images/movie.png" border="0"></a> <? } ?> <? if ($bold_reps < 2) { ?> <a href="viewimage.php?modality=mr&type=dicom&seriesid=<?php echo $mrseries_id; ?> "><img src="images/colors.png" border="0"></a> <? } ?> </td> <td style="font-size:8pt"><?php echo $series_datetime; ?> </td> <td><span id="series_notes" class="edit_inline<? echo $mrseries_id; ?>" style="background-color: lightyellow; padding: 1px 3px; font-size: 8pt;"><? echo $series_notes; ?></span></td> <td class="seriesrow" style="padding: 0px 5px;"> <a href="JavaScript:newPopup('mrseriesqa.php?id=<?php echo $mrseries_id; ?> ');"><img src="images/chart.gif" border="0" title="View QA results, including movement correction"></a> </td> <td class="seriesrow" style="padding: 0px 5px;"> <span style="font-size:7pt"><?php echo $ratingcount2; ?> </span> <div id="popup" style="display:none; min-width:800px; min-height:400px"></div> <? if ($hasratings) { $image = "rating2.png"; } else { $image = "rating.png"; } ?> <a href="JavaScript:newPopup('ratings.php?id=<?php echo $mrseries_id; ?> &type=series&modality=mr');"><img src="images/<?php echo $image; ?> " border="0" title="View ratings"></a> </td> <td class="seriesrow" align="right" style="padding:0px"> <table cellspacing="0" cellpadding="1" height="100%" width="100%" class="movementsubtable" style="border-radius:0px"> <tr><td title="Total X displacement" class="mainval" style="background-color: <?php echo $maxxcolor; ?> ;"><?php echo $rangex; ?> </td></tr> <tr><td title="Total X acceleration" class="subval" style="background-color: <?php echo $maxxcolor2; ?> ;"><?php echo $rangex2; ?> </td></tr> </table> </td> <td class="seriesrow" align="right" style="padding:0px;margin:0px;height:100%"> <table cellspacing="0" cellpadding="0" height="100%" width="100%" class="movementsubtable"> <tr><td title="Total Y displacement" class="mainval" style="background-color: <?php echo $maxycolor; ?> ;height:100%"><?php echo $rangey; ?> </td></tr> <tr><td title="Total Y acceleration" class="subval" style="background-color: <?php echo $maxycolor2; ?> ;height:100%"><?php echo $rangey2; ?> </td></tr> </table> </td> <td class="seriesrow" align="right" style="padding:0px"> <table cellspacing="0" cellpadding="1" height="100%" width="100%" class="movementsubtable"> <tr><td title="Total Z displacement" class="mainval" style="background-color: <?php echo $maxzcolor; ?> ;"><?php echo $rangez; ?> </td></tr> <tr><td title="Total Z acceleration" class="subval" style="background-color: <?php echo $maxzcolor2; ?> ;"><?php echo $rangez2; ?> </td></tr> </table> </td> <td class="seriesrow" align="right" style="background-color: <?php echo $maxpvsnrcolor; ?> ; font-size:8pt"> <a href="stddevchart.php?h=40&w=450&min=<?php echo $pstats[$sequence]['minpvsnr']; ?> &max=<?php echo $pstats[$sequence]['maxpvsnr']; ?> &mean=<?php echo $pstats[$sequence]['avgpvsnr']; ?> &std=<?php echo $pstats[$sequence]['stdpvsnr']; ?> &i=<?php echo $pvsnr; ?> &b=yes" class="preview" style="color: black; text-decoration: none"><?php echo $pvsnr; ?> </a> </td> <td class="seriesrow" align="right" style="background-color: <?php echo $maxiosnrcolor; ?> ; font-size:8pt"> <a href="stddevchart.php?h=40&w=450&min=<?php echo $pstats[$sequence]['miniosnr']; ?> &max=<?php echo $pstats[$sequence]['maxiosnr']; ?> &mean=<?php echo $pstats[$sequence]['avgiosnr']; ?> &std=<?php echo $pstats[$sequence]['stdiosnr']; ?> &i=<?php echo $iosnr; ?> &b=yes" class="preview" style="color: black; text-decoration: none"><?php echo $iosnr; ?> </a> </td> <td class="seriesrow" align="right" style="background-color: <?php echo $maxmotioncolor; ?> ; font-size:8pt"> <a href="stddevchart.php?h=40&w=450&min=<?php echo $pstats[$sequence]['minmotion']; ?> &max=<?php echo $pstats[$sequence]['maxmotion']; ?> &mean=<?php echo $pstats[$sequence]['avgmotion']; ?> &std=<?php echo $pstats[$sequence]['stdmotion']; ?> &i=<?php echo $motion_rsq; ?> &b=yes" class="preview" style="color: black; text-decoration: none"><?php echo $motion_rsq; ?> </a> </td> <td><?php echo $sequence; ?> </td> <td style="font-size:8pt"><?php echo $scanlength; ?> </td> <td align="right" style="font-size:8pt"><?php echo $series_tr; ?> </td> <td style="font-size:8pt"><?php echo number_format($series_spacingx, 1); ?> × <?php echo number_format($series_spacingy, 1); ?> × <?php echo number_format($series_spacingz, 1); ?> </td> <td style="font-size:8pt"><?php echo $img_cols; ?> × <?php echo $img_rows; ?> × <?php echo $img_slices; ?> </td> <td style="font-size:8pt"><?php echo $bold_reps; ?> </td> <td style="font-size:8pt"> <?php echo $numfiles; ?> <? if (($dcmcount != $numfiles) && ($audit)) { ?><span style="color: white; background-color: red; padding: 1px 5px; font-weight: bold"><?php echo $dcmcount; ?> </span> <? } ?> </td> <td nowrap style="font-size:8pt"> <?php echo HumanReadableFilesize($series_size); ?> <a href="download.php?modality=mr&type=dicom&seriesid=<?php echo $mrseries_id; ?> " border="0"><img src="images/download16.png" title="Download <?php echo $data_type; ?> data"></a> </td> <td nowrap bgcolor="<?php echo $behcolor; ?> "> <? if ($numfiles_beh != "-") { ?> <a href="managefiles.php?seriesid=<?php echo $mrseries_id; ?> &modality=mr&datatype=beh"><?php echo $numfiles_beh; ?> </a> <? } else { ?> <?php echo $numfiles_beh; ?> <? } ?> <span class="tiny"> <? if ($numfiles_beh > 0) { echo "(" . HumanReadableFilesize($beh_size) . ")"; ?> <a href="download.php?modality=mr&type=beh&seriesid=<?php echo $mrseries_id; ?> " border="0"><img src="images/download16.png" title="Download behavioral data"></a> <? } ?> </span> </td> <? if ($GLOBALS['issiteadmin']) { if ($ishidden) { ?> <td><a href="studies.php?action=unhidemrseries&id=<?php echo $id; ?> &seriesid=<?php echo $mrseries_id; ?> " title="Un-hide this series from search results.">Unhide</a></td> <? } else { ?> <td><a href="studies.php?action=hidemrseries&id=<?php echo $id; ?> &seriesid=<?php echo $mrseries_id; ?> " title="Hide this series from search results. It will be visible on this page, but nowhere else on NiDB">Hide</a></td> <? } ?> <td><a href="studies.php?action=resetqa&seriesid=<?php echo $mrseries_id; ?> &id=<?php echo $id; ?> " color="red">X</a></td> <? } ?> </tr> <? } ?> <!-- uploader script for this series --> <script> function createUploaders(){ /* window.onload can only be called once, so make 1 function to create all uploaders */ <? mysql_data_seek($result,0); /* reset the sql result, so we can loop through it again */ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $mrseries_id = $row['mrseries_id']; ?> var uploader<?php echo $mrseries_id; ?> = new qq.FileUploader({ element: document.getElementById('uploader<?php echo $mrseries_id; ?> '), action: 'upload.php', params: {modality: 'MRBEH', studyid: '<?php echo $id; ?> ', seriesid: <?php echo $mrseries_id; ?> }, debug: true }); <? } ?> } // in your app create uploader as soon as the DOM is ready // don't wait for the window to load window.onload = createUploaders; </script> <? } ?> </tbody> </table> <? }
function Search($s) { //print_r($s); /* ***************** steps to searching ***************** 1) build the search string 2) run the query 3) depending on the query type, either... a) display the query, then end b) display the results */ /* --------- [1] get the SQL search string ---------- */ $sqlstring = BuildSQLString($s); if ($sqlstring == "") { return; } /* escape all the variables and put them back into meaningful variable names */ foreach ($s as $key => $value) { if (is_scalar($value)) { $$key = mysql_real_escape_string($s[$key]); } else { $$key = $s[$key]; } } /* make modality lower case to conform with table names... MySQL table names are case sensitive when using the 'show tables' command */ $s_studymodality = strtolower($s_studymodality); /* ---------- [2] run the query ----------- */ $starttime = microtime(true); $result = MySQLQuery($sqlstring, __FILE__, __LINE__); $querytime = microtime(true) - $starttime; if ($s_resultorder == "debug") { ?> <span class="sublabel">Query returned <?php echo mysql_num_rows($result); ?> rows in <?php echo number_format($querytime, 4); ?> sec</span> <div style="background-color: #EEEEEE"><?php echo $sqlstring; ?> </div><br> <div style="background-color: #EEEEEE"><?php echo getFormattedSQL($sqlstring); ?> </div> <br><br><br><br> <? return; } /* display the results */ if (mysql_num_rows($result) > 0) { if ((mysql_num_rows($result) > 100000) && ($s_resultorder != "pipelinecsv")) { ?> <div style="border: 2px solid darkred; background-color: #FFEEEE; text-align: left; padding:5px; border-radius: 5px"> <b>Your search returned <? echo number_format(mysql_num_rows($result),0); ?> results... which is a lot</b> <br> Try changing the search criteria to return fewer results or select a .csv format </div> <? return; } /* generate a color gradient in an array (green to yellow to red) */ $colors = GenerateColorGradient(); $colors2 = GenerateColorGradient2(); /* display the number of rows and the search time */ ?> <span class="sublabel">Query returned <? echo number_format(mysql_num_rows($result),0); ?> rows in <?php echo number_format($querytime, 4); ?> sec</span> <details> <summary style="font-size:9pt">View SQL query:</summary> <div style="background-color: #EEEEEE; font-family:courier new; font-size:10pt"><?php echo getFormattedSQL($sqlstring); ?> <br></div> </details> <style> #preview { position:absolute; border:1px solid #ccc; background:gray; padding:0px; display:none; color:#fff; } </style> <script type="text/javascript"> // Popup window code function newPopup(url) { popupWindow = window.open( url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=no') } </script> <? /* ---------- pipeline results ------------ */ if (($s_resultorder == "pipeline") || ($s_resultorder == "pipelinecsv")) { if ($s_pipelineresulttype == "i") { /* get the result names first (due to MySQL bug which prevents joining in this table in the main query) */ $sqlstringX = "select * from analysis_resultnames where result_name like '%$s_pipelineresultname%' "; $resultX = MySQLQuery($sqlstringX,__FILE__,__LINE__); while ($rowX = mysql_fetch_array($resultX, MYSQL_ASSOC)) { $resultnames[$rowX['resultname_id']] = $rowX['result_name']; } /* and get the result unit (due to the same MySQL bug) */ $sqlstringX = "select * from analysis_resultunit where result_unit like '%$s_pipelineresultunit%' "; $resultX = MySQLQuery($sqlstringX,__FILE__,__LINE__); while ($rowX = mysql_fetch_array($resultX, MYSQL_ASSOC)) { $resultunit[$rowX['resultunit_id']] = $rowX['result_unit']; } /* ---------------- pipeline results (images) --------------- */ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { //PrintVariable($row,'row'); $step = $row['analysis_step']; $pipelinename = $row['pipeline_name']; $uid = $row['uid']; $subject_id = $row['subject_id']; $gender = $row['gender']; $study_id = $row['study_id']; $study_num = $row['study_num']; $type = $row['result_type']; $size = $row['result_size']; //$name = $row['result_name']; $name = $resultnames[$row['result_nameid']]; $unit = $resultunit[$row['result_unitid']]; $filename = $row['result_filename']; $swversion = $row['result_softwareversion']; $important = $row['result_isimportant']; $lastupdate = $row['result_lastupdate']; switch($type) { case "v": $thevalue = $value; break; case "f": $thevalue = $filename; break; case "t": $thevalue = $text; break; case "h": $thevalue = $filename; break; case "i": $thevalue = $filename; break; } $tables["$uid$study_num"][$name] = $thevalue; $tables["$uid$study_num"]['subjectid'] = $subject_id; $tables["$uid$study_num"]['studyid'] = $study_id; $tables["$uid$study_num"]['studynum'] = $study_num; $names[$name] = "blah"; } //PrintVariable($tables,'Tables'); ?> <table cellspacing="0" class="multicoltable"> <thead> <tr> <th>UID</th> <? foreach ($names as $name => $blah) { ?> <th align="center" style="font-size:9pt"><?php echo $name; ?> </th> <? } ?> </tr> </thead> <? $maximgwidth = 1200/count($names); $maximgwidth -= ($maximgwidth*0.05); /* subtract 5% of image width to give a gap between them */ if ($maximgwidth < 100) { $maximgwidth = 100; } foreach ($tables as $uid => $valuepair) { ?> <tr style="font-weight: <?php echo $bold; ?> "> <td><a href="studies.php?id=<?php echo $tables[$uid]['studyid']; ?> "><b><?php echo $uid; ?> </b></a></td> <? foreach ($names as $name => $blah) { if ($tables[$uid][$name] == "") { $dispval = "-"; } else { $dispval = $tables[$uid][$name]; } list($width, $height, $type, $attr) = getimagesize("/mount$filename"); $filesize = number_format(filesize("/mount$filename")/1000) . " kB"; ?> <td style="padding:2px"><a href="preview.php?image=/mount<?php echo $dispval; ?> " class="preview"><img src="preview.php?image=/mount<?php echo $dispval; ?> " style="max-width: <?php echo $maximgwidth; ?> px"></a></td> <? } ?> </tr> <? } ?> </table> <br><br><br><br><br><br><br><br> <? } else { /* ---------------- pipeline results (values) --------------- */ /* get the result names first (due to MySQL bug which prevents joining in this table in the main query) */ $sqlstringX = "select * from analysis_resultnames where result_name like '%$s_pipelineresultname%' "; $resultX = MySQLQuery($sqlstringX,__FILE__,__LINE__); while ($rowX = mysql_fetch_array($resultX, MYSQL_ASSOC)) { $resultnames[$rowX['resultname_id']] = $rowX['result_name']; } /* and get the result unit (due to the same MySQL bug) */ $sqlstringX = "select * from analysis_resultunit where result_unit like '%$s_pipelineresultunit%' "; $resultX = MySQLQuery($sqlstringX,__FILE__,__LINE__); while ($rowX = mysql_fetch_array($resultX, MYSQL_ASSOC)) { $resultunit[$rowX['resultunit_id']] = $rowX['result_unit']; } /* load the data into a useful table */ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $step = $row['analysis_step']; $pipelinename = $row['pipeline_name']; $uid = $row['uid']; $subject_id = $row['subject_id']; $study_id = $row['study_id']; $study_num = $row['study_num']; $birthdate = $row['birthdate']; $gender = $row['gender']; $study_datetime = $row['study_datetime']; $type = $row['result_type']; $size = $row['result_size']; $name = $resultnames[$row['result_nameid']]; $name2 = $resultnames[$row['result_nameid']]; $unit = $resultunit[$row['result_unitid']]; $unit2 = $resultunit[$row['result_unitid']]; $text = $row['result_text']; $value = $row['result_value']; $filename = $row['result_filename']; $swversion = $row['result_softwareversion']; $important = $row['result_isimportant']; $lastupdate = $row['result_lastupdate']; /* calculate age at scan */ list($year, $month, $day) = explode("-", $birthdate); $d1 = mktime(0,0,0,$month,$day,$year); list($year, $month, $day, $extra) = explode("-", $study_datetime); $d2 = mktime(0,0,0,$month,$day,$year); $ageatscan = number_format((($d2-$d1)/31536000),1); if (strpos($unit,'^') !== false) { $unit = str_replace('^','<sup>',$unit); $unit .= '</sup>'; } switch($type) { case "v": $thevalue = $value; break; case "f": $thevalue = $filename; break; case "t": $thevalue = $text; break; case "h": $thevalue = $filename; break; case "i": ?> <a href="preview.php?image=/mount<?php echo $filename; ?> " class="preview"><img src="images/preview.gif" border="0"></a> <? break; } if (substr($name, -(strlen($unit))) != $unit) { $name .= " <b>$unit</b>"; $name2 .= " " . $row['result_unit']; } $tables[$uid][$name] = $thevalue; $tables[$uid][$name2] = $thevalue; $tables[$uid]['age'] = $ageatscan; $tables[$uid]['gender'] = $gender; $tables[$uid]['subjectid'] = $subject_id; $tables[$uid]['studyid'] = $study_id; $tables[$uid]['studynum'] = $study_num; //$names[$name] = "blah"; if (($thevalue > $names[$name]['max']) || ($names[$name]['max'] == "")) { $names[$name]['max'] = $thevalue; } if (($thevalue < $names[$name]['min']) || ($names[$name]['min'] == "")) { $names[$name]['min'] = $thevalue; } if (($thevalue > $names2[$name2]['max']) || ($names2[$name2]['max'] == "")) { $names2[$name2]['max'] = $thevalue; } if (($thevalue < $names2[$name2]['min']) || ($names2[$name2]['min'] == "")) { $names2[$name2]['min'] = $thevalue; } } if ($s_resultorder == "pipelinecsv") { $csv = "uid,studynum,sex,age"; foreach ($names2 as $name2 => $blah) { $csv .= ",$name2"; } $csv .= "\n"; foreach ($tables as $uid => $valuepair) { $csv .= $uid . ',' . $tables[$uid]['studynum'] . ',' . $tables[$uid]['gender'] . ',' . $tables[$uid]['age']; foreach ($names2 as $name2 => $blah) { $csv .= ',' . $tables[$uid][$name2]; } $csv .= "\n"; } $filename = "query" . GenerateRandomString(10) . ".csv"; file_put_contents("/tmp/" . $filename, $csv); ?> <br><br> <div width="50%" align="center" style="background-color: #FAF8CC; padding: 5px;"> Download .csv file <a href="download.php?type=file&filename=<?php echo "/tmp/{$filename}"; ?> "><img src="images/download16.png"></a> </div> <? } else { ?> <br><br><br><br><br> <br><br><br><br><br> <br><br><br><br><br> <style> tr.rowhover:hover { background-color: ffff96; } td.tdhover:hover { background-color: yellow; } </style> <table cellspacing="0"> <tr> <td>UID</td> <td>Sex</td> <td>Age</td> <? $csv = "studyid,sex,age"; foreach ($names as $name => $blah) { $csv .= ",$name"; ?> <td style="max-width:25px;"><span style="padding-left: 8px; font-size:10pt; white-space:nowrap; display: block; -webkit-transform: rotate(-70deg) translate3d(0,0,0); -moz-transform: rotate(-70deg);"><?php echo $name; ?> </span></td> <? } $csv .= "\n"; ?> </tr> <? foreach ($tables as $uid => $valuepair) { ?> <tr style="font-weight: <?php echo $bold; ?> " class="rowhover"> <td> <a href="studies.php?id=<?php echo $tables[$uid]['studyid']; ?> "><b><?php echo $uid; ?> </b><?php echo $tables[$uid]['studynum']; ?> </a> </td> <td style="border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:9pt; padding:2px;"><?php echo $tables[$uid]['gender']; ?> </td> <td style="border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:9pt; padding:2px;"><?php echo $tables[$uid]['age']; ?> </td> <? $stats[0][$tables[$uid]['gender']]++; $stats[1][] = $tables[$uid]['age']; $csv .= $tables[$uid]['studyid'] . ',' . $tables[$uid]['gender'] . ',' . $tables[$uid]['age']; $i=2; foreach ($names as $name => $blah) { $val = $tables[$uid][$name]; $range = $names[$name]['max'] - $names[$name]['min']; if (($val > 0) && ($range > 0)) { $cindex = round((($val - $names[$name]['min'])/$range)*100); //echo "[$val, $range, $cindex]<br>"; if ($cindex > 100) { $cindex = 100; } } if ($tables[$uid][$name] == "") { $dispval = "-"; } else { $dispval = $tables[$uid][$name]; $stats[$i][] = $val; //$stats[$i]['numintotal'] ++; } $csv .= ',' . $tables[$uid][$name]; if ($dispval != '-') { if (($dispval + 0) > 10000) { $dispval = number_format($dispval,0); } elseif (($dispval + 0) > 1000) { $dispval = number_format($dispval,2); } else { $dispval = number_format($dispval,4); } } ?> <td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px; background-color: <? if ($s_pipelinecolorize) { if (trim($dispval) == '-') { echo "#EEE"; } else { echo $colors[$cindex]; } } ?>"><?php echo $dispval; ?> </td> <? $i++; } $csv .= "\n"; ?> </tr> <? } if ($s_pipelineresultstats == 1) { ?> <tr class="rowhover"> <td align="right"><b>N</b></td> <td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"> <? foreach ($stats[0] as $key => $value) { echo "$key -> $value<br>"; } ?> </td> <? for($i=1;$i<count($stats);$i++) { $count = count($stats[$i]); ?><td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"><?php echo $count; ?> </td><? } ?> </tr> <tr class="rowhover"> <td align="right"><b>Min</b></td> <td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"></td> <? for($i=1;$i<count($stats);$i++) { $min = min($stats[$i]); ?><td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"><?php echo $min; ?> </td><? } ?> </tr> <tr class="rowhover"> <td align="right"><b>Max</b></td> <td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"></td> <? for($i=1;$i<count($stats);$i++) { $max = max($stats[$i]); ?><td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"><?php echo $max; ?> </td><? } ?> </tr> <tr class="rowhover"> <td align="right"><b>Mean</b></td> <td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"></td> <? for($i=1;$i<count($stats);$i++) { $avg = number_format(array_sum($stats[$i])/count($stats[$i]),2); ?><td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"><?php echo $avg; ?> </td><? } ?> </tr> <tr class="rowhover"> <td align="right"><b>Median</b></td> <td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"></td> <? for($i=1;$i<count($stats);$i++) { $median = number_format(median($stats[$i]),2); ?><td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"><?php echo $median; ?> </td><? } ?> </tr> <tr class="rowhover"> <td align="right"><b>Std Dev</b></td> <td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"></td> <? for($i=1;$i<count($stats);$i++) { $stdev = number_format(sd($stats[$i]),2); ?><td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"><?php echo $stdev; ?> </td><? } ?> </tr> <? } ?> </table> <? if ($s_pipelinecormatrix == 1) { ?> <br><br><br><br> <br><br><br><br> <b>Correlation Matrix (r)</b><br> <? foreach ($names as $name => $blah) { foreach ($tables as $uid => $valuepair) { $lists['age'][] = $tables[$uid]['age']; /* this loop gets the data into an array */ foreach ($names as $name => $blah) { $lists[$name][] = $tables[$uid][$name]; } } } ?> <table cellspacing="0"> <tr> <td> </td> <? foreach ($lists as $label => $vals1) { ?> <td style="max-width:25px;"><span style="padding-left: 8px; font-size:10pt; white-space:nowrap; display: block; -webkit-transform: rotate(-70deg) translate3d(0,0,0); -moz-transform: rotate(-70deg);"><?php echo $label; ?> </span></td> <? } ?> </tr> <? $kashi = new Kashi(); foreach ($lists as $label => $vals1) { for ($i=0;$i<count($vals1);$i++) { if ($vals1[$i] == 0) { $vals1[$i] = 0.000001; } } ?> <tr class="rowhover"> <td align="right" style="font-size:10pt"><?php echo $label; ?> </td> <? foreach ($lists as $label => $vals2) { $starttime1 = microtime(true); /* compare vals1 to vals2 */ //$coeff = Correlation($vals1,$vals2); for ($i=0;$i<count($vals2);$i++) { if ($vals2[$i] == 0) { $vals2[$i] = 0.000001; } } $coeff = $kashi->cor($vals1,$vals2); $coefftime = microtime(true) - $starttime1; $cindex = round((($coeff - (-1))/2)*100); //echo "[$val, $range, $cindex]<br>"; if ($cindex > 100) { $cindex = 100; } /* display correlation coefficient */ ?> <td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px; background-color: <?php echo $colors2[$cindex]; ?> "><?php echo number_format($coeff, 3); ?> </td> <? flush(); } ?> </tr> <? } ?> </table> <? } } } } elseif ($s_resultorder == 'subject') { /* display only subject data */ SearchStudy($result); } elseif ($s_resultorder == 'uniquesubject') { /* display only unique subject data */ SearchSubject($result); } elseif ($s_resultorder == 'long') { /* display longitudinal data */ SearchLongitudinal($result); } else { SearchDefault($result, $s, $colors, $colors2); } } else { ?> <span class="sublabel">Query returned <? echo number_format(mysql_num_rows($result),0); ?> rows in <?php echo number_format($querytime, 4); ?> sec</span> <details> <summary style="font-size:9pt">View SQL query:</summary> <div style="background-color: #EEEEEE; font-family:courier new; font-size:10pt"><?php echo getFormattedSQL($sqlstring); ?> <br></div> </details> <br> <? } }
function DisplayChart($data1, $data2, $data3, $title, $label1, $label2, $label3, $height, $id, $disptable) { $colors = GenerateColorGradient(); ksort($data1); ksort($data2); ksort($data3); ?> <table class="smallgrayrounded" width="100%"> <tr> <td class="title"><?php echo $title; ?> </td> </tr> <tr> <td class="body"> <script> $(function() { var data1 = [<?php foreach ($data1 as $date => $item) { $value = $data1[$date]['value']; $date = $date * 1000; if ($date > 0 && $value > 0) { $jsonstrings[] .= "['{$date}', {$value}]"; } } echo implode2(',', $jsonstrings); ?> ]; <?php if ($label2 != "") { ?> var data2 = [<?php $jsonstrings = ""; foreach ($data2 as $date => $item) { $value = $data2[$date]['value']; $date = $date * 1000; if ($date > 0 && $value > 0) { $jsonstrings[] .= "['{$date}', {$value}]"; } } echo implode2(',', $jsonstrings); ?> ]; <?php } ?> <?php if ($label3 != "") { ?> var data3 = [<?php $jsonstrings = ""; foreach ($data3 as $date => $item) { $value = $data3[$date]['value']; $date = $date * 1000; if ($date > 0 && $value > 0) { $jsonstrings[] .= "['{$date}', {$value}]"; } } echo implode2(',', $jsonstrings); ?> ]; <?php } ?> var options = { series: { lines: { show: true, fill: false }, points: { show: true } }, grid: { hoverable: true, clickable: true }, legend: { noColumns: 6 }, xaxis: { mode: "time", timeformat: "%Y-%m-%d" }, yaxis: { min: 0, tickDecimals: 1 }, selection: { mode: "x" }, }; var placeholder = $("#placeholder<?php echo $id; ?> "); var plot = $.plot(placeholder, [ { label: "<?php echo $label1; ?> ", color: '#F00', data: data1}<?php if ($label2 != "") { ?> , { label: "<?php echo $label2; ?> ", color: '#4B4', data: data2} <?php } if ($label3 != "") { ?> , { label: "<?php echo $label3; ?> ", color: '#00F', data: data3} <?php } ?> ],options); }); </script> <div id="placeholder<?php echo $id; ?> " style="height:<?php echo $height; ?> px;" align="center"></div> </td> </tr> <?php if ($disptable) { ?> <tr> <td class="body"> <table class="tinytable"> <thead> <th>Date</th> <th>Subject</th> <th>Study</th> <th>Value</th> </thead> <tbody> <?php // get min, max $min = $data[0]; $max = $data[0]; foreach ($data as $date => $value) { $value = $data[$date]['value']; if ($value > $max) { $max = $value; } if ($value < $min) { $min = $value; } } $range = $max - $min; foreach ($data as $date => $value) { $value = $data[$date]['value']; $uid = $data[$date]['uid']; $studynum = $data[$date]['studynum']; $subjectid = $data[$date]['subjectid']; $studyid = $data[$date]['studyid']; if ($value > 0 && $range > 0) { $cindex = round(($value - $min) / $range * 100); if ($cindex > 100) { $cindex = 100; } } $date = $date; $date = date("D, d M Y", $date); ?> <tr> <td><?php echo $date; ?> </td> <td><a href="subjects.php?id=<?php echo $subjectid; ?> "><?php echo $uid; ?> </a></td> <td><a href="subjects.php?id=<?php echo $studyid; ?> "><?php echo $uid; echo $studynum; ?> </a></td> <td align="right" bgcolor="<?php echo $colors[$cindex]; ?> "><tt><?php echo $value; ?> <tt></td> </tr> <?php } ?> </tbody> </table> </td> </tr> <?php } ?> </table> <?php }