Example #1
0
	function SearchStudy(&$result) {
		//PrintSQLTable(&$result);
		?>
		<form name="subjectlist" method="post" action="search.php">
		<input type="hidden" name="modality" value="">
		<input type="hidden" name="action" value="submit">
		<table class="graydisplaytable" width="100%">
			<thead>
				<tr>
					<th>&nbsp;</th>
					<th>UID</th>
					<th>Project<br><span class="tiny">Enroll dates</span></th>
					<th>DOB</th>
					<th>Gender</th>
					<th>Ethnicities</th>
					<th>Education</th>
					<th>Handedness</th>
					<th>uuid</th>
					<th>Alt UIDs</th>
				</tr>
			</thead>
		<?
		while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
			$uid = $row['uid'];
			$subject_id = $row['subject_id'];
			$enrollment_id = $row['enrollment_id'];
			$project_name = $row['project_name'];
			$enroll_startdate = $row['enroll_startdate'];
			$enroll_enddate = $row['enroll_enddate'];
			$birthdate = $row['birthdate'];
			$gender = $row['gender'];
			$ethnicity1 = $row['ethnicity1'];
			$ethnicity2 = $row['ethnicity2'];
			$weight = $row['weight'];
			$handedness = $row['handedness'];
			$education = $row['education'];
			$uid = $row['uid'];
			$uuid = strtoupper($row['uuid']);

			/* get list of alternate subject UIDs */
			$altuids = GetAlternateUIDs($subject_id);
			
			$enroll_startdate = date("Y-m-d",strtotime($enroll_startdate));
			if ($enroll_enddate = '0000-00-00 00:00:00') {
				$enroll_enddate = 'present';
			}
			else {
				$enroll_enddate = date("Y-m-d",strtotime($enroll_enddate));
			}
			
			if ($gender == '') { $gender = '-'; }
			if (($ethnicity1 == '') && ($ethnicity2 == '')) { $ethnicity = '-'; }
			else { $ethnicity = "$ethnicity $ethnicity2"; }
			if ($gender == '') { $gender = '-'; }
			//if ($handedness == '') { $handedness = '-'; }
			?>
			<tr>
				<td><input type="checkbox" name="enrollmentid[]" value="<?php 
echo $enrollment_id;
?>
"></td>
				<td><a href="subjects.php?id=<?php 
echo $subject_id;
?>
"><?php 
echo $uid;
?>
</a></td>
				<td><?php 
echo $project_name;
?>
<br><span class="tiny"><?php 
echo $enroll_startdate;
?>
 - <?php 
echo $enroll_enddate;
?>
</span></td>
				<td><?php 
echo $birthdate;
?>
</td>
				<td><?php 
echo $gender;
?>
</td>
				<td><?php 
echo $ethnicity1;
?>
 <?php 
echo $ethnicity2;
?>
</td>
				<td><?php 
echo $education;
?>
</td>
				<td><?php 
echo $handedness;
?>
</td>
				<td class="tiny"><?php 
echo $uuid;
?>
</td>
				<td><?php 
echo implode2(', ', $altuids);
?>
</td>
			</tr>
			<?
		}
		?>
		</table>
		<?
		DisplayDownloadBox('', 'subject');
	}
Example #2
0
	function ViewGroup($id, $measures, $columns, $groupmeasures) {
	
		$urllist['Group List'] = "groups.php";
		NavigationBar("Groups", $urllist,0,'','','','');
		
		/* get the general group information */
		$sqlstring = "select * from groups where group_id = $id";
		$result = mysql_query($sqlstring) or die("Query failed: " . mysql_error() . "<br><i>$sqlstring</i><br>");
		$row = mysql_fetch_array($result, MYSQL_ASSOC);
		$groupname = $row['group_name'];
		$grouptype = $row['group_type'];

		?>
		<script>
			$(document).ready(function()
				{
					$("#studytable").tablesorter();
				}
			); 
		</script>
		
		<div align="center"><span style="color:darkblue;font-size:15pt;font-weight:bold"><?php 
echo $groupname;
?>
</span> - <i><?php 
echo $grouptype;
?>
</i> level group</div>
		<br><br>
		<?
		/* (subject level) group statistics */
		$totalage = 0;
		$numage = 0;
		$totalweight = 0;
		$numweight = 0;
		$n = 0;
		
		//print_r(get_defined_vars());
		
		/* ------------------ subject group type ------------------- */
		if ($grouptype == "subject") {
			/* get the actual group data (subject level) */
			$sqlstring = "select a.subjectgroup_id, b.*, (datediff(now(), birthdate)/365.25) 'age' from group_data a left join subjects b on a.data_id = b.subject_id where a.group_id = $id";
			$result = mysql_query($sqlstring) or die("Query failed: " . mysql_error() . "<br><i>$sqlstring</i><br>");
			while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
				$subjectid = $row['subject_id'];
				$name = $row['name'];
				$birthdate = $row['birthdate'];
				$age = $row['age'];
				$gender = $row['gender'];
				$ethnicity1 = $row['ethnicity1'];
				$ethnicity2 = $row['ethnicity2'];
				$weight = $row['weight'];
				$handedness = $row['handedness'];
				$education = $row['education'];
				$uid = $row['uid'];
				
				/* do some demographics calculations */
				$n++;
				if ($age > 0) {
					$totalage += $age;
					$numage++;
					$ages[] = $age;
				}
				if ($weight > 0) {
					$totalweight += $weight;
					$numweight++;
					$weights[] = $weight;
				}
				$genders{$gender}++;
				$educations{$education}++;
				$ethnicity1s{$ethnicity1}++;
				$ethnicity2s{$ethnicity2}++;
				$handednesses{$handedness}++;
			}
			if ($numage > 0) { $avgage = $totalage/$numage; } else { $avgage = 0; }
			if (count($ages) > 0) { $varage = sd($ages); } else { $varage = 0; }
			if ($numweight > 0) { $avgweight = $totalweight/$numweight; } else { $avgweight = 0; }
			if (count($weights) > 0) { $varweight = sd($weights); } else { $varweight = 0; }
			
			?>
			<table>
				<tr>
					<td valign="top" style="padding-right:20px">
						<?
						DisplayDemographicsTable($n,$avgage,$varage,$genders,$ethnicity1s,$ethnicity2s,$educations,$handednesses,$avgweight,$varweight);
						?>
					</td>
				</tr>
				<tr>
					<td valign="top" style="padding-right:20px">
						<details>
						<summary>SQL</summary>
						<?php 
echo PrintSQL($sqlstring);
?>
						</details>
					</td>
				</tr>
				<tr>
					<td valign="top">
						<form action="groups.php" method="post">
						<input type="hidden" name="id" value="<?php 
echo $id;
?>
">
						<input type="hidden" name="action" value="removegroupitem">
						<table class="smallgraydisplaytable">
							<th>Initials</th>
							<th>UID</th>
							<th>Age<br><span class="tiny">current</span></th>
							<th>Sex</th>
							<th>Ethnicity 1</th>
							<th>Ethnicity 2</th>
							<th>Weight</th>
							<th>Handedness</th>
							<th>Education</th>
							<th>Alt UIDs</th>
							<th>Remove<br>from group</th>
						<?
						/* reset the result pointer to 0 to iterate through the results again */
						mysql_data_seek($result,0);
						while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
							$itemid = $row['subjectgroup_id'];
							$subjectid = $row['subject_id'];
							$name = $row['name'];
							$birthdate = $row['birthdate'];
							$age = $row['age'];
							$gender = $row['gender'];
							$ethnicity1 = $row['ethnicity1'];
							$ethnicity2 = $row['ethnicity2'];
							$weight = $row['weight'];
							$handedness = $row['handedness'];
							$education = $row['education'];
							$uid = $row['uid'];
							
							/* get list of alternate subject UIDs */
							$altuids = GetAlternateUIDs($subjectid);
							
							$parts = explode("^",$name);
							$name = substr($parts[1],0,1) . substr($parts[0],0,1);
							?>
							<tr>
								<td><?php 
echo $name;
?>
</td>
								<td><a href="subjects.php?id=<?php 
echo $subjectid;
?>
"><?php 
echo $uid;
?>
</a></td>
								<? if ($age <= 0) {$color = "red";} else {$color="black";} ?>
								<td style="color:<?php 
echo $color;
?>
"><?php 
echo number_format($age, 1);
?>
Y</td>
								<? if (!in_array(strtoupper($gender),array('M','F','O'))) {$color = "red";} else {$color="black";} ?>
								<td style="color:<?php 
echo $color;
?>
"><?php 
echo $gender;
?>
</td>
								<td><?php 
echo $ethnicitiy1;
?>
</td>
								<td><?php 
echo $ethnicitiy1;
?>
</td>
								<td><?php 
echo number_format($weight, 1);
?>
kg</td>
								<td><?php 
echo $handedness;
?>
</td>
								<td><?php 
echo $education;
?>
</td>
								<td><?php 
echo implode(', ', $altuids);
?>
</td>
								<!--<td><a href="groups.php?action=removegroupitem&itemid=<?php 
echo $itemid;
?>
&id=<?php 
echo $id;
?>
" style="color:red">X</a></td>-->
								<td><input type="checkbox" name="itemid[]" value="<?php 
echo $itemid;
?>
"></td>
							</tr>
							<?
						}
						?>
							<tr>
								<td colspan="100" align="right">
									<input type="submit" value="Remove">
									</form>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			<?
		}
		
		/* ------------------ study group type ------------------- */
		if ($grouptype == "study") {
			$csv = "";
			
			/* get the demographics (study level) */
			$sqlstring = "select c.enroll_subgroup,d.*, (datediff(b.study_datetime, d.birthdate)/365.25) 'age' from group_data a left join studies b on a.data_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.group_id = $id group by d.uid order by d.uid,b.study_num";
			$result = mysql_query($sqlstring) or die("Query failed: " . mysql_error() . "<br><i>$sqlstring</i><br>");
			while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
				$studyid = $row['study_id'];
				$studynum = $row['study_num'];
				$studydesc = $row['study_desc'];
				$studyalternateid = $row['study_alternateid'];
				$studymodality = $row['study_modality'];
				$studydatetime = $row['study_datetime'];
				$studyoperator = $row['study_operator'];
				$studyperformingphysician = $row['study_performingphysician'];
				$studysite = $row['study_site'];
				$studyinstitution = $row['study_institution'];
				$studynotes = $row['study_notes'];
				$subgroup = $row['enroll_subgroup'];

				$subjectid = $row['subject_id'];
				$name = $row['name'];
				$birthdate = $row['birthdate'];
				$age = $row['age'];
				$gender = $row['gender'];
				$ethnicity1 = $row['ethnicity1'];
				$ethnicity2 = $row['ethnicity2'];
				$weight = $row['weight'];
				$handedness = $row['handedness'];
				$education = $row['education'];
				$uid = $row['uid'];

				$subjectids[] = $subjectid;
				/* do some demographics calculations */
				$n++;
				if ($age > 0) {
					$totalage += $age;
					$numage++;
					$ages[] = $age;
				}
				if ($weight > 0) {
					$totalweight += $weight;
					$numweight++;
					$weights[] = $weight;
				}
				$genders{$gender}++;
				$educations{$education}++;
				$ethnicity1s{$ethnicity1}++;
				$ethnicity2s{$ethnicity2}++;
				$handednesses{$handedness}++;
			}
			if ($numage > 0) { $avgage = $totalage/$numage; } else { $avgage = 0; }
			if (count($ages) > 0) { $varage = sd($ages); } else { $varage = 0; }
			if ($numweight > 0) { $avgweight = $totalweight/$numweight; } else { $avgweight = 0; }
			if (count($weights) > 0) { $varweight = sd($weights); } else { $varweight = 0; }
			
			if ($measures == "all") {
				$sqlstringD = "select a.subject_id, b.enrollment_id, c.*, d.measure_name from measures c join measurenames d on c.measurename_id = d.measurename_id left join enrollment b on c.enrollment_id = b.enrollment_id join subjects a on a.subject_id = b.subject_id where a.subject_id in (" . implode2(",", $subjectids) . ")";
				//PrintSQL($sqlstringD);
				$resultD = MySQLQuery($sqlstringD,__FILE__,__LINE__);
				
				if ($groupmeasures == "byvalue") {
					$mnames = array('ANTDX','AVDDX','AX1Com1_Code','AX1Com2_Code','AX1Com3_Code','AX1Com4_Code','AX1Com5_Code','AX1Com6_Code','AX1Com7_Code','AX1Pri_Code','AXIIDX','BRDDX','DPNDX','DSM-Axis','DSM-Axis1','DSM-Axis2','DSM-Axis295.3','DSM-Axis304.3','DSM-AxisV71.09','DSM_IV_TR','DXGROUP_1','DX_GROUP','MiniDxn','MiniDxnFollowUp','NARDX','OBCDX','PARDX','ProbandGroup','Psychosis','relnm1','SAsubtype','SCZDX','status','SubjectType','SZTDX');
					while ($rowD = mysql_fetch_array($resultD, MYSQL_ASSOC)) {
						$subjectid = $rowD['subject_id'];
						$measurename = $rowD['measure_name'];

						if (in_array($measurename,$mnames)) {
							if ($rowD['measure_type'] == 's') {
								$value = strtolower(trim($rowD['measure_valuestring']));
							}
							else {
								$value = strtolower(trim($rowD['measure_valuenum']));
							}
							
							if (is_numeric(substr($value,0,6))) {
								//echo "$value --6--> ";
								$value = substr($value,0,6);
								//echo "$value<br>";
							}
							elseif (is_numeric(substr($value,0,5))) {
								//echo "$value --5--> ";
								$value = substr($value,0,5);
								//echo "$value<br>";
							}
							elseif (is_numeric(substr($value,0,4))) {
								$value = substr($value,0,4);
							}
							elseif (is_numeric(substr($value,0,3))) {
								$value = substr($value,0,3);
							}
							elseif (is_numeric(substr($value,1,5))) {
								$value = substr($value,1,5);
							}
							elseif (substr($value,0,3) == "xxx") {
								$value = "xxx";
							}
							
							$measuredata[$subjectid][$value] = 1;
							$measurenames[] = $value;
						}
					}
					$measurenames = array_unique($measurenames);
					natsort($measurenames);
				}
				else {
					while ($rowD = mysql_fetch_array($resultD, MYSQL_ASSOC)) {
						if ($rowD['measure_type'] == 's') {
							$measuredata[$rowD['subject_id']][$rowD['measure_name']]['value'][] = $rowD['measure_valuestring'];
						}
						else {
							$measuredata[$rowD['subject_id']][$rowD['measure_name']]['value'][] = $rowD['measure_valuenum'];
						}
						$measuredata[$rowD['subject_id']][$rowD['measure_name']]['notes'][] = $rowD['measure_notes'];
						$measurenames[] = $rowD['measure_name'];
						//$i++;
					}
					$measurenames = array_unique($measurenames);
					natcasesort($measurenames);
				}
				//PrintVariable($measurenames, 'MeasureNames');
				//PrintVariable($measuredata, 'MeasureData');
			}
			
			/* setup the CSV header */
			if ($columns == "min") {
				$csv = "UID";
			}
			else {
				$csv = "Initials,UID,AgeAtStudy,Sex,Ethnicity,Race,SubGroup,Weight,Handedness,Education,AltUIDs,StudyID,Description,AltStudyID,Modality,StudyDate,Operator,Physician,Site";
			}
			
			?>
			<table>
				<tr>
					<td valign="top" style="padding-right:20px">
						<?
						DisplayDemographicsTable($n,$avgage,$varage,$genders,$ethnicity1s,$ethnicity2s,$educations,$handednesses,$avgweight,$varweight);
						?>
					</td>
				</tr>
				<tr>
					<td valign="top" style="padding-right:20px">
						<details>
						<summary>SQL</summary>
						<?php 
echo PrintSQL($sqlstring);
?>
						</details>
					</td>
				</tr>
				<tr>
					<td valign="top">
						<a href="groups.php?action=viewgroup&id=<?php 
echo $id;
?>
&measures=all">Include measures</a><br>
						<a href="groups.php?action=viewgroup&id=<?php 
echo $id;
?>
&measures=all&columns=min">Include measures and only UID</a><br>
						<a href="groups.php?action=viewgroup&id=<?php 
echo $id;
?>
&measures=all&columns=min&groupmeasures=byvalue">Include measures and only UID and group measures by value</a>
						<br><br>
						<span class="tiny">Click columns to sort. May be slow for large tables</span>

						<form action="groups.php" method="post">
						<input type="hidden" name="id" value="<?php 
echo $id;
?>
">
						<input type="hidden" name="action" value="removegroupitem">
						
						<table id="studytable" class="tablesorter">
							<thead>
								<tr>
									<? if ($columns != "min") { ?>
									<th>Initials</th>
									<? } ?>
									<th>UID</th>
									<? if ($columns != "min") { ?>
									<th>Age<br><span class="tiny">at study</span></th>
									<th>Sex</th>
									<th>Ethnicities</th>
									<th>SubGroup</th>
									<th>Weight</th>
									<th>Handedness</th>
									<th>Education</th>
									<th>Alt UIDs</th>
									<th>Study ID</th>
									<th>Description</th>
									<th>Alternate Study ID</th>
									<th>Modality</th>
									<th>Date/time</th>
									<th>Operator</th>
									<th>Physician</th>
									<th>Site</th>
									<? } ?>
									<?
										if (count($measurenames) > 0) {
											foreach ($measurenames as $measurename) {
												echo "<th>$measurename</th>";
												$csv .= ",\"$measurename\"";
											}
										}
									?>
									<th>Remove<br>from group</th>
								</tr>
							</thead>
							<tbody>
						<?

						/* reset the result pointer to 0 to iterate through the results again */
						$sqlstring = "select a.subjectgroup_id, c.enroll_subgroup, b.*, d.*, (datediff(b.study_datetime, d.birthdate)/365.25) 'age' from group_data a left join studies b on a.data_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.group_id = $id order by d.uid,b.study_num";
						$result = mysql_query($sqlstring) or die("Query failed: " . mysql_error() . "<br><i>$sqlstring</i><br>");
						//mysql_data_seek($result,0);
						while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
							$studyid = $row['study_id'];
							$studynum = $row['study_num'];
							$studydesc = $row['study_desc'];
							$studyalternateid = $row['study_alternateid'];
							$studymodality = $row['study_modality'];
							$studydatetime = $row['study_datetime'];
							$studyoperator = $row['study_operator'];
							$studyperformingphysician = $row['study_performingphysician'];
							$studysite = $row['study_site'];
							$studyinstitution = $row['study_institution'];
							$studynotes = $row['study_notes'];
							$subgroup = $row['enroll_subgroup'];
							
							$itemid = $row['subjectgroup_id'];
							$subjectid = $row['subject_id'];
							$name = $row['name'];
							$birthdate = $row['birthdate'];
							$age = $row['age'];
							$gender = $row['gender'];
							$ethnicity1 = $row['ethnicity1'];
							$ethnicity2 = $row['ethnicity2'];
							$weight = $row['weight'];
							$handedness = $row['handedness'];
							$education = $row['education'];
							$uid = $row['uid'];

							/* get list of alternate subject UIDs */
							$altuids = GetAlternateUIDs($subjectid);
							
							$parts = explode("^",$name);
							$name = substr($parts[1],0,1) . substr($parts[0],0,1);
							
							if ($columns == "min") {
								$csv .= "\n\"$uid\"";
							}
							else {
								$csv .= "\n\"$name\",\"$uid\",\"$age\",\"$gender\",\"$ethnicity1\",\"$ethnicity2\",\"$subgroup\",\"$weight\",\"$handedness\",\"$education\",\"" . implode2(', ',$altuids) . "\",\"$uid$studynum\",\"$studydesc\",\"$studyalternateid\",\"$studymodality\",\"$studydatetime\",\"$studyoperator\",\"$studyperformingphysician\",\"$studysite\"";
							}
							?>
							<tr>
								<? if ($columns != "min") { ?>
								<td><?php 
echo $name;
?>
</td>
								<? } ?>
								<td><a href="subjects.php?id=<?php 
echo $subjectid;
?>
"><?php 
echo $uid;
?>
</a></td>
								<? if ($columns != "min") { ?>
								<? if ($age <= 0) {$color = "red";} else {$color="black";} ?>
								<td style="color:<?php 
echo $color;
?>
"><?php 
echo number_format($age, 1);
?>
Y</td>
								<? if (!in_array(strtoupper($gender),array('M','F','O'))) {$color = "red";} else {$color="black";} ?>
								<td style="color:<?php 
echo $color;
?>
"><?php 
echo $gender;
?>
</td>
								<td style="font-size:8pt"><?php 
echo $ethnicity1;
?>
 <?php 
echo $ethnicity2;
?>
</td>
								<td style="font-size:8pt"><?php 
echo $subgroup;
?>
</td>
								<? if ($weight <= 0) {$color = "red";} else {$color="black";} ?>
								<td style="color:<?php 
echo $color;
?>
"><?php 
echo number_format($weight, 1);
?>
kg</td>
								<td><?php 
echo $handedness;
?>
</td>
								<td><?php 
echo $education;
?>
</td>
								<td style="font-size:8pt"><?php 
echo implode2(', ', $altuids);
?>
</td>
								<td><a href="studies.php?id=<?php 
echo $studyid;
?>
"><?php 
echo $uid;
echo $studynum;
?>
</a></td>
								<td style="font-size:8pt"><?php 
echo $studydesc;
?>
</td>
								<td><?php 
echo $studyalternateid;
?>
</td>
								<td><?php 
echo $studymodality;
?>
</td>
								<td><?php 
echo $studydatetime;
?>
</td>
								<td><?php 
echo $studyoperator;
?>
</td>
								<td><?php 
echo $studyperformingphysician;
?>
</td>
								<td style="font-size:8pt"><?php 
echo $studysite;
?>
</td>
								<? } ?>
								<?
									if (count($measurenames) > 0) {
										if ($groupmeasures == "byvalue") {
											foreach ($measurenames as $measurename) {
												$csv .= ",\"" . $measuredata[$subjectid][$measurename] . "\"";
											?>
											<td class="seriesrow">
												<?
													if (isset($measuredata[$subjectid][$measurename])) {
														echo $measuredata[$subjectid][$measurename];
													}
												?>
											</td>
											<?
											}
										}
										else {
											foreach ($measurenames as $measure) {
												$csv .= ",\"" . $measuredata[$subjectid][$measure]['value'] . "\"";
												?>
												<td class="seriesrow">
													<?
														if (isset($measuredata[$subjectid][$measure]['value'])) {
															foreach ($measuredata[$subjectid][$measure]['value'] as $value) {
																echo "$value<br>";
															}
														}
													?>
												</td>
												<?
											}
										}
									}
								?>
								<!--<td><a href="groups.php?action=removegroupitem&itemid=<?php 
echo $itemid;
?>
&id=<?php 
echo $id;
?>
" style="color:red">X</a></td>-->
								<td><input type="checkbox" name="itemid[]" value="<?php 
echo $itemid;
?>
"></td>
							</tr>
							<?
						}
						?>
							<tr>
								<td colspan="100" align="right">
									<input type="submit" value="Remove">
									</form>
								</td>
							</tr>
							</tbody>
						</table>
					</td>
				</tr>
			</table>
			<?
			
				/* ---------- generate csv file ---------- */
				$filename = $groupname . "_" . GenerateRandomString(10) . ".csv";
				file_put_contents("/tmp/" . $filename, $csv);
				?>
				<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>
				<?
		}
		
		/* ------------------ series group type ------------------- */
		if ($grouptype == "series") {
			/* get a distinct list of modalities... then get a list of series for each modality */
			$sqlstring = "select distinct(modality) from group_data where group_id = $id order by modality";
			$result = mysql_query($sqlstring) or die("Query failed: " . mysql_error() . "<br><i>$sqlstring</i><br>");
			while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
				$modalities[] = $row['modality'];
			}
			
			foreach ($modalities as $modality) {
				$modality = strtolower($modality);
				/* get the demographics (series level) */
				$sqlstring = "select b.*,c.enroll_subgroup, e.*, (datediff(b.series_datetime, e.birthdate)/365.25) 'age' from group_data a left join ".$modality."_series b on a.data_id = b.".$modality."series_id left join studies c on b.study_id = c.study_id left join enrollment d on c.enrollment_id = d.enrollment_id left join subjects e on d.subject_id = e.subject_id where a.group_id = 3 and a.modality = '".$modality."' and e.subject_id is not null group by e.uid";
				$result = mysql_query($sqlstring) or die("Query failed: " . mysql_error() . "<br><i>$sqlstring</i><br>");
				while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
					$studyid = $row['study_id'];
					$studynum = $row['study_num'];
					$studydesc = $row['study_desc'];
					$studyalternateid = $row['study_alternateid'];
					$studymodality = $row['study_modality'];
					$studydatetime = $row['study_datetime'];
					$studyoperator = $row['study_operator'];
					$studyperformingphysician = $row['study_performingphysician'];
					$studysite = $row['study_site'];
					$studyinstitution = $row['study_institution'];
					$studynotes = $row['study_notes'];

					$subgroup = $row['enroll_subgroup'];
					
					$subjectid = $row['subject_id'];
					$name = $row['name'];
					$birthdate = $row['birthdate'];
					$age = $row['age'];
					$gender = $row['gender'];
					$ethnicity1 = $row['ethnicity1'];
					$ethnicity2 = $row['ethnicity2'];
					$weight = $row['weight'];
					$handedness = $row['handedness'];
					$education = $row['education'];
					$uid = $row['uid'];
					
					/* do some demographics calculations */
					$n++;
					if ($age > 0) {
						$totalage += $age;
						$numage++;
						$ages[] = $age;
					}
					if ($weight > 0) {
						$totalweight += $weight;
						$numweight++;
						$weights[] = $weight;
					}
					$genders{$gender}++;
					$educations{$education}++;
					$ethnicity1s{$ethnicity1}++;
					$ethnicity2s{$ethnicity2}++;
					$handednesses{$handedness}++;
				}
			}
			/* calculate some stats */
			if ($numage > 0) { $avgage = $totalage/$numage; } else { $avgage = 0; }
			if (count($ages) > 0) { $varage = sd($ages); } else { $varage = 0; }
			if ($numweight > 0) { $avgweight = $totalweight/$numweight; } else { $avgweight = 0; }
			if (count($weights) > 0) { $varweight = sd($weights); } else { $varweight = 0; }
			
			?>
			<table>
				<tr>
					<td valign="top" style="padding-right:20px">
						<?
						DisplayDemographicsTable($n,$avgage,$varage,$genders,$ethnicity1s,$ethnicity2s,$educations,$handednesses,$avgweight,$varweight);
						?>
					</td>
					<td valign="top" style="padding-right:20px">
						<details>
						<summary>SQL</summary>
						<?php 
echo PrintSQL($sqlstring);
?>
						</details>
					</td>
					<td valign="top">
						<table class="smallgraydisplaytable">
							<th>Initials</th>
							<th>UID</th>
							<th>Age<br><span class="tiny">at study</span></th>
							<th>Sex</th>
							<th>Ethnicities</th>
							<th>SubGroup</th>
							<th>Weight</th>
							<th>Handedness</th>
							<th>Education</th>
							<th>Alt UIDs</th>
							<th>Study ID</th>
							<th>Description/Protocol</th>
							<th>Modality</th>
							<th>Date/time</th>
							<th>Series #</th>
							<th>Remove<br>from group</th>
						<?
						/* get a distinct list of modalities... then get a list of series for each modality */
						
						/* reset the result pointer to 0 to iterate through the results again */
						foreach ($modalities as $modality) {
							$modality = strtolower($modality);
							/* get the demographics (series level) */
							$sqlstring = "select b.*, c.study_num, e.*, (datediff(b.series_datetime, e.birthdate)/365.25) 'age' from group_data a left join ".$modality."_series b on a.data_id = b.".$modality."series_id left join studies c on b.study_id = c.study_id left join enrollment d on c.enrollment_id = d.enrollment_id left join subjects e on d.subject_id = e.subject_id where a.group_id = 3 and a.modality = '".$modality."' and e.subject_id is not null";
							//print "[$sqlstring]<br>";
							$result = mysql_query($sqlstring) or die("Query failed: " . mysql_error() . "<br><i>$sqlstring</i><br>");
							mysql_data_seek($result,0);
							while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
								$seriesdesc = $row['series_desc'];
								$seriesprotocol = $row['series_protocol'];
								$seriesdatetime = $row['series_datetime'];
								$seriesnum = $row['series_num'];
								$studynum = $row['study_num'];
								$seriesmodality = strtoupper($modality);
								
								$itemid = $row['subjectgroup_id'];
								$subjectid = $row['subject_id'];
								$name = $row['name'];
								$birthdate = $row['birthdate'];
								$age = $row['age'];
								$gender = $row['gender'];
								$ethnicity1 = $row['ethnicity1'];
								$ethnicity2 = $row['ethnicity2'];
								$weight = $row['weight'];
								$handedness = $row['handedness'];
								$education = $row['education'];
								$uid = $row['uid'];

								/* get list of alternate subject UIDs */
								$altuids = GetAlternateUIDs($subjectid);
								
								$parts = explode("^",$name);
								$name = substr($parts[1],0,1) . substr($parts[0],0,1);
								?>
								<tr>
									<td><?php 
echo $name;
?>
</td>
									<td><a href="subjects.php?id=<?php 
echo $subjectid;
?>
"><?php 
echo $uid;
?>
</a></td>
									<? if ($age <= 0) {$color = "red";} else {$color="black";} ?>
									<td style="color:<?php 
echo $color;
?>
"><?php 
echo number_format($age, 1);
?>
Y</td>
									<? if (!in_array(strtoupper($gender),array('M','F','O'))) {$color = "red";} else {$color="black";} ?>
									<td style="color:<?php 
echo $color;
?>
"><?php 
echo $gender;
?>
</td>
									<td style="font-size:8pt"><?php 
echo $ethnicitiy1;
?>
 <?php 
echo $ethnicitiy1;
?>
</td>
									<td style="font-size:8pt"><?php 
echo $subgroup;
?>
</td>
									<? if ($weight <= 0) {$color = "red";} else {$color="black";} ?>
									<td style="color:<?php 
echo $color;
?>
"><?php 
echo number_format($weight, 1);
?>
kg</td>
									<td><?php 
echo $handedness;
?>
</td>
									<td><?php 
echo $education;
?>
</td>
									<td style="font-size:8pt"><?php 
echo implode2(', ', $altuids);
?>
</td>
									<td><a href="studies.php?id=<?php 
echo $studyid;
?>
"><?php 
echo $uid;
echo $studynum;
?>
</a></td>
									<td style="font-size:8pt"><?php 
echo $seriesdesc;
?>
 <?php 
echo $seriesprotocol;
?>
</td>
									<td><?php 
echo $seriesmodality;
?>
</td>
									<td style="font-size:8pt"><?php 
echo $seriesdatetime;
?>
</td>
									<td><?php 
echo $seriesnum;
?>
</td>
									<td><a href="groups.php?action=removegroupitem&itemid=<?php 
echo $itemid;
?>
&id=<?php 
echo $id;
?>
" style="color:red">X</a></td>
								</tr>
								<?
							}
						}
						?>
						</table>
					</td>
				</tr>
			</table>
			<?
		}
	}
Example #3
0
	function DisplaySubjectList($searchuid, $searchaltuid, $searchname, $searchgender, $searchdob, $searchactive) {
	
		$searchuid = mysql_real_escape_string($searchuid);
		$searchaltuid = mysql_real_escape_string($searchaltuid);
		$searchname = mysql_real_escape_string($searchname);
		$searchgender = mysql_real_escape_string($searchgender);
		$searchdob = mysql_real_escape_string($searchdob);
		$searchactive = mysql_real_escape_string($searchactive);
	?>
	<script>
		$(document).ready(function() {
			$('#newsubjecttext').hide();
			
			$('#newsubject').hover(
				function () { $('#newsubjecttext').show(); }, 
				function () { $('#newsubjecttext').hide(); }
			);
		});
	</script>
	
	<table width="100%" cellspacing="0" class="headertable">
		<tbody>
			<tr>
				<td class="header1">Subjects</td>
				<td class="header2" align="right">
					<a href="subjects.php">Subject List</a> &gt; 
					<a href="subjects.php?action=addform" id="newsubject"> New Subject </a><br>
					<div align="right" id="newsubjecttext" style="color:darkred; background-color: yellow; font-size:9pt; border: 1px solid red; padding:5px; border-radius:5px"><b>Search on this page before creating a new subject</b><br>to make sure they do not already exist!</div>
				</td>
			</tr>
		</tbody>
	</table>

	<br><bR>
	<script>
	$(function() {
		$( "#searchuid" ).autocomplete({
			source: "autocomplete_uid.php",
			minLength: 2,
			autoFocus: true
		});
	});
	</script>
	<style>
	.ui-autocomplete {
		max-height: 150px;
		overflow-y: auto;
		/* prevent horizontal scrollbar */
		overflow-x: hidden;
		/* add padding to account for vertical scrollbar */
		padding-right: 25px;
	}
	/* IE 6 doesn't support max-height
	 * we use height instead, but this forces the menu to always be this tall
	 */
	* html .ui-autocomplete {
		height: 150px;
	}
	</style>
	
	<table class="graydisplaytable" width="100%">
		<thead>
			<tr>
				<th align="left">&nbsp;</th>
				<th>UID<br><span class="tiny">S1234ABC</span></th>
				<th>Alternate UID</th>
				<th>Name</th>
				<th>Sex<br><span class="tiny">M,F,O,U</span></th>
				<th>DOB<br><span class="tiny">YYYY-MM-DD</span></th>
				<th>Projects</th>
				<th>Active?</th>
				<th>Activity date</th>
				<? if ($GLOBALS['isadmin']) { ?>
				<!--<th>Delete</td>-->
				<? } ?>
				<th>&nbsp;</th>
				<th>&nbsp;</th>
			</tr>
		</thead>
		<script type="text/javascript">
		$(document).ready(function() {
			$("#rightcheckall").click(function() {
				var checked_status = this.checked;
				$(".rightcheck").find("input[type='checkbox']").each(function() {
					this.checked = checked_status;
				});
			});
		});
		</script>
		<tbody>
			<form method="post" action="subjects.php">
			<input type="hidden" name="action" value="search">
			<tr>
				<td>&nbsp;</td>
				<td align="left"><input type="text" placeholder="UID" name="searchuid" id="searchuid" value="<?php 
echo $searchuid;
?>
" size="15" autofocus="autofocus"></td>
				<td align="left"><input type="text" placeholder="Alternate UID" name="searchaltuid" value="<?php 
echo $searchaltuid;
?>
" size="20"></td>
				<td align="left"><input type="text" placeholder="Name" name="searchname" value="<?php 
echo $searchname;
?>
" size="40"></td>
				<td align="left"><input type="text" placeholder="Sex" name="searchgender" value="<?php 
echo $searchgender;
?>
" size="2" maxlength="2"></td>
				<td align="left"><input type="text" placeholder="YYYY-MM-DD" name="searchdob" value="<?php 
echo $searchdob;
?>
" size="10"></td>
				<td> - </td>
				<td align="left"><input type="checkbox" name="searchactive" <? if ($searchactive == '1') { echo "checked"; } ?> value="1"></td>
				<td> - </td>
				<td align="left"><input type="submit" value="Search"></td>
				<? if ($GLOBALS['isadmin']) { ?>
				<td><input type="checkbox" id="rightcheckall"></td>
				<? } ?>
			</tr>
			</form>
			
			<form method="post" name="subjectlist" action="subjects.php">
			<input type="hidden" name="action" value="merge">
			<?
				$subjectsfound = 0;
				/* if all the fields are blank, only display the most recent subjects */
				if ( ($searchuid == "") && ($searchaltuid == "") && ($searchname == "") && ($searchgender == "") && ($searchdob == "") ) {
					$sqlstring = "select a.* from subjects a left join enrollment b on a.subject_id = b.subject_id left join user_project c on b.project_id = c.project_id left join projects d on c.project_id = d.project_id where a.isactive = 1 group by a.uid order by a.lastupdate desc limit 0,25";
					//PrintSQL($sqlstring);
					?>
						<tr>
							<td colspan="11" align="center" style="color: #555555; padding:8px; font-size:10pt">
								No search criteria specified
							</td>
						</tr>
					<?
				}
				else {
					$sqlstring = "select a.*, b.altuid, d.view_phi from subjects a left join subject_altuid b on a.subject_id = b.subject_id left join enrollment c on a.subject_id = c.subject_id left join user_project d on c.project_id = d.project_id left join projects e on c.project_id = e.project_id left join studies f on c.enrollment_id = f.enrollment_id where a.uid like '%$searchuid%'";
					if ($searchaltuid != "") { $sqlstring .= " and (b.altuid like '%$searchaltuid%' or b.altuid = sha1('$searchaltuid') or b.altuid = sha1(upper('$searchaltuid')) or b.altuid = sha1(lower('$searchaltuid')) or f.study_alternateid = '$searchaltuid' or f.study_alternateid like '%$searchaltuid%' or f.study_alternateid = sha1('$searchaltuid') or f.study_alternateid = sha1(upper('$searchaltuid')) or f.study_alternateid = sha1(lower('$searchaltuid')) )"; }
					if ($searchname != "") { $sqlstring .= " and (a." . MakeSQLorList($searchname,'name') . ")"; }
					if ($searchgender != "") { $sqlstring .= " and a.`gender` like '%$searchgender%'"; }
					if ($searchdob != "") { $sqlstring .= " and a.`birthdate` like '%$searchdob%'"; }
					$sqlstring .= "and a.isactive = '$searchactive' group by a.uid order by a.name asc";
					//PrintSQL($sqlstring);
					$result = MySQLQuery($sqlstring, __FILE__, __LINE__);
					if (mysql_num_rows($result) > 0) {
						while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
							$id = $row['subject_id'];
							$name = $row['name'];
							$dob = $row['birthdate'];
							$gender = $row['gender'];
							$uid = $row['uid'];
							$isactive = $row['isactive'];
							$lastupdate = date('M j, Y g:ia',strtotime($row['lastupdate']));
							$viewphi = $row['view_phi'];

							if (!$viewphi) {
								$dob = substr($dob,0,4) . "-00-00";
							}
							if ($isactive) { $isactivecheck = "&#x2713;"; }
							else { $isactivecheck = ""; }
							
							$altuids = GetAlternateUIDs($id);
							
							if (strpos($name,'^') !== false) {
								list($lname, $fname) = explode("^",$name);
								$name = strtoupper(substr($fname,0,1)) . strtoupper(substr($lname,0,1));
							}
							
							/* get project enrollment list */
							$sqlstringA = "SELECT d.*, e.* FROM subjects a LEFT JOIN enrollment b on a.subject_id = b.subject_id LEFT JOIN projects d on d.project_id = b.project_id LEFT JOIN instance e on d.instance_id = e.instance_id WHERE a.subject_id = '$id' GROUP BY d.project_id";
							//PrintSQL($sqlstringA);
							unset($enrolllist);
							$resultA = MySQLQuery($sqlstringA, __FILE__, __LINE__);
							if (mysql_num_rows($resultA) > 0) {
								while ($rowA = mysql_fetch_array($resultA, MYSQL_ASSOC)) {
									$projectid = $rowA['project_id'];
									$projectname = $rowA['project_name'];
									$projectcostcenter = $rowA['project_costcenter'];
									if ($projectid != "") {
										$enrolllist[$projectid] = "$projectname ($projectcostcenter)";
									}
								}
							}
							
							if ($isactive == 0) { ?><tr style="background-image:url('images/deleted.png')"><? } else { ?><tr><? } ?>
							
								<td><input type="checkbox" name="uids[]" value="<?php 
echo $uid;
?>
"></td>
								<!--<input type="hidden" name="uidids[]" value="<?php 
echo $id;
?>
">-->
								<td><a href="subjects.php?action=display&id=<?php 
echo $id;
?>
"><?php 
echo FormatUID($uid);
?>
</a></td>
								<td><?php 
echo implode2(', ', $altuids);
?>
</td>
								<td><?php 
echo $name;
?>
</td>
								<td><?php 
echo $gender;
?>
</td>
								<td><?php 
echo $dob;
?>
</td>
								<td>
									<? if (count($enrolllist) > 0) { ?>
									<details style="font-size:8pt; color: gray">
									<summary>Enrolled projects</summary>
									<?
										//PrintVariable($enrolllist);
										foreach ($enrolllist as $projectid => $val) {
											$sqlstringA = "select * from user_project where project_id = '$projectid' and user_id = (select user_id from users where username = '******'username'] . "')";
											$resultA = MySQLQuery($sqlstringA, __FILE__, __LINE__);
											$viewphi = 0;
											if (mysql_num_rows($resultA) > 0) {
												$rowA = mysql_fetch_array($resultA, MYSQL_ASSOC);
												$viewphi = $rowA['view_phi'];
											}
											if ($viewphi) {
												?><span style="color:#238217; white-space:nowrap;" title="You have access to <?php 
echo $val;
?>
">&#8226; <?php 
echo $val;
?>
</span><br><?
											}
											else {
												?><span style="color:#8b0000; white-space:nowrap;" title="You <b>do not</b> have access to <?php 
echo $val;
?>
">&#8226; <?php 
echo $val;
?>
</span><br><?
											}
										}
									?>
									</details>
									<?
									}
									else {
										?><span style="font-size:8pt; color: darkred">Not enrolled</span><?
									}
									?>
								</td>
								<td><?php 
echo $isactivecheck;
?>
</td>
								<td><?php 
echo $lastupdate;
?>
</td>
								<? if ($GLOBALS['isadmin']) { ?>
								<!--<td><a href="subjects.php?action=deleteconfirm&id=<?php 
echo $id;
?>
"><div class="adminbutton" style="padding: 0px; margin; 0px;">X</div></a></td>-->
								<? } ?>
								<td></td>
								<? if ($GLOBALS['issiteadmin']) { ?>
								<td class="rightcheck"><input type="checkbox" name="ids[]" value="<?php 
echo $id;
?>
"></td>
								<? } ?>
							</tr>
							<? 
						}
						$subjectsfound = 1;
					}
				?>
				<tr>
					<td colspan="8">
						<? if ($GLOBALS['issiteadmin']) {?>
						<input type="submit" name="merge" value="Merge selected subjects" style="border: 1px solid red; background-color: pink; width:150px; margin:4px" onclick="document.subjectlist.action='subjects.php';document.subjectlist.action.value='merge'" title="Merges all studies from the selected subjects">
						<? } ?>
						<br><br>
						<select name="subjectgroupid">
							<?
								$sqlstring = "select user_id from users where username = '******'username'] . "'";
								$result = MySQLQuery($sqlstring, __FILE__, __LINE__);
								$row = mysql_fetch_array($result, MYSQL_ASSOC);
								$userid = $row['user_id'];
							
								$sqlstring = "select * from groups where group_type = 'subject' and group_owner = '$userid'";
								$result = MySQLQuery($sqlstring, __FILE__, __LINE__);
								while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
									$groupid = $row['group_id'];
									$groupname = $row['group_name'];
									?>
									<option value="<?php 
echo $groupid;
?>
"><?php 
echo $groupname;
?>
									<?
								}
							?>
						</select>
						<input type="submit" name="addtogroup" value="Add to group" onclick="document.subjectlist.action='groups.php';document.subjectlist.action.value='addsubjectstogroup'">
					</td>
					<td colspan="3" align="right">
						<? if ($GLOBALS['issiteadmin']) {?>
						<input type="submit" style="border: 1px solid red; background-color: pink; width:150px; margin:4px" name="obliterate" value="Obliterate subjects" title="Remove all database entries for the subject and move their data to a /deleted directory" onclick="document.subjectlist.action='subjects.php';document.subjectlist.action.value='obliterate'"><br>
						<? } ?>
					</td>
				</tr>
				<?
				}
				?>
			</table>
			</form>
		</tbody>
	</table>
	<?
	}