<!doctype html public "-//w3c//dtd html 3.2//ja">
<html>
<head>
<title>select series for volume rendering</title>

<script type="text/javascript"><!--
function win(src) {
window.open(src, '', ' menubar=no, toolbar=no,resizable = yes, scrollbars=yes');
}
// --></script>

<meta http-equiv=content-type content="text/html; charset=x-euc-jp">
</head>
<body BACKGROUND="./img/yellow.jpg">

<?php


// parameter

$patid = $_GET['patid'];
$patname_mod = $_GET['patname_mod'];
$size = $_GET['size'];
$browser = $_GET['browser'];
$scwidth = $_GET['scwidth'];
$scheight = $_GET['scheight'];
$userid = $_GET['userid'];
$permission = $_GET['permission'];
$study_uid = $_GET['study_uid'];
$date = $_GET['date'];







  include "init.inc";
  include "param_setting.ini";
  include "sql_generator.ini";
  include "file_mod.inc";
  $include_path=".";
  require("$include_path/dbconnect.ini");




//DB query

$db_handle = db_contact_start($db_type,$target_host,$target_db);


$sql = sql_generator("show_study_seriesUID");


$rtn_seriesUID = $db_handle->prepare($sql);

$rtn_seriesUID->execute(array($study_uid));


  $patid=chop($patid);

  print("<center><H1><B>Packed JPEG</B></H1>\n");
  print("<table>");
  print("<TR><TH>Patient ID:</TH><tH  ALIGN=RIGHT bgcolor=\"#ccffff\" >$patid</TH></TR>");
  print("<TR><TH>Patient Name:</TH><tH ALIGN=LEFT bgcolor=\"#ccd555\">$patname_mod</TH></TR>");
  print("</table>");




print("<table>");




$rtn_seriesUID->execute(array($study_uid));
	while ($seriesUID_row = $rtn_seriesUID->fetch(PDO::FETCH_ASSOC)) {
	$series_uid = $seriesUID_row['seriesuid'] ;
	$numserrelima = $seriesUID_row['sernum'] ;
	$serdes = $seriesUID_row['mod'] ;
	

	
	
	



//make sumnail images

$series_uid = chop($series_uid);

$sql = sql_generator("show_study_sumnail");
$rtn_sumnail = $db_handle->prepare($sql);
$rtn_sumnail->execute(array($series_uid));
	while ($sumnail_row = $rtn_sumnail->fetch(PDO::FETCH_ASSOC)) {
	$path = $sumnail_row['path'] ;
	}


$path = $file_root_path . $path;



	

// touch dir prepare procedure
$patid=trim($patid);
$date=trim($date);
$date=str_replace(" ", "",$date);
@$studyUID=trim($studyUID);
@$seriesUID=trim($seriesUID);	
if(!@$wl){
@$target_dir=touch_dir($patid,$date,$studyUID,$seriesUID,"default");
}else{
$wlww_con = $wl . $ww;
@$target_dir=touch_dir($patid,$date,$studyUID,$seriesUID,$wlww_con);
}
$target_path=($target_dir . "/" );
$file_name=basename($path);//print("path: $path\n");
$target_file_path=$target_path . $file_name . ".dcm";




//Symbolic link original file to target files.

$jpg_file_name = $target_file_path . "-sum_w.jpg";
if(!file_exists($jpg_file_name)){

	if(is_link($target_file_path)){
	if($path != linkinfo($target_file_path)){
	system("rm -f $target_file_path");
	symlink($path,$target_file_path);
	}
	}
	else{
	symlink($path,$target_file_path);
	}

	@$wl_from_dicomtag = get_dicom_value("0028,1050",$path);
	@$ww_from_dicomtag = get_dicom_value("0028,1051",$path);
	@$patposition_from_dicomtag = get_dicom_value("0018,5100",$path);



	$wl_from_dicomtag = trim(floor($wl_from_dicomtag));
	$ww_from_dicomtag = trim(floor($ww_from_dicomtag));
	$patposition_from_dicomtag = trim(floor($patposition_from_dicomtag));
	
	if($wl_from_dicomtag){
	$wl = $wl_from_dicomtag;
	$ww = $ww_from_dicomtag;
	}

if($wl){
$jpg_file_name=dcmtojpg_sum1_w($target_file_path,$wl,$ww);
}else{
$jpg_file_name=dcmtojpg_sum1($target_file_path);
}
}

print("<tr>");
print("<td>");

print("<img src=$jpg_file_name width=128>");

print("</td>");

print("<td valign=\"top\"> image number : $numserrelima <br>");
print("$serdes <br>");

if($numserrelima < 300){
print("<font color=red>This series do not have much images. <br>So it may not be suitable for 3D viewing . <br></font>");

}else{
print("<font color=blue>This series have enough images. <br>It may be suitable for 3D viewing . <br></font>");

}


//if($numserrelima > 300){
print("<button onclick=\"win('make_volume.php?patid=$patid&date=$date&study_uid=$study_uid&series_uid=$series_uid');\">crate 3D volume and boot Viewer</button>");
//}


print("</td>");





print("</tr>");

}


print("</table>");







?>

<br><br>

<?

print("<form action=\"show_study.php\" target=\"_self\">");
print("<input type=hidden name=date value=$date>");
print("<input type=hidden name=patid value=$patid>");
print("<input type=hidden name=size value=$size>");
print("<input type=hidden name=browser value=$browser>");
print("<input type=hidden name=scwidth value=$scwidth>");
print("<input type=hidden name=scheight value=$scheight>");
print("<input type=hidden name=userid value=$userid>");
print("<input type=hidden name=permission value=$permission>");
print("<input type=\"submit\" value=\"return to study list\">");
print("</form>");
?>

<form action="main_menu.php" method="post">
<input type=hidden name=size value="<? echo$size; ?>">
<input type=hidden name=browser value="<? echo$browser; ?>">
<input type=hidden name=scwidth value="<? echo$scwidth; ?>">
<input type=hidden name=scheight value="<? echo$scheight; ?>">
<input type=hidden name=userid value="<? echo $userid; ?>">
<input type=hidden name=permission value="<? echo $permission; ?>">
<input type="submit" value="back to main manu">


<br>


</CENTER>





</body>
</html>
