<?php

$ruid = $_GET['ruid'];
$date = $_GET['date'];
$patid = $_GET['patid'];
$studyUID = $_GET['studyUID'];
$patage = $_GET['patage'];
$patsex = $_GET['patsex'];
$name = $_GET['name'];


?>
<!doctype html public "-//w3c//dtd html 3.2//ja">
<html>
<head>
<title>update report</title>
<meta http-equiv=content-type content="text/html; charset=x-euc-jp">

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin


<?php



?>

function send(flag) {
 sendCGI = "report_mode.php";
  if (flag == "main") sendCGI = "report_do.php";
  if (flag == "sub") sendCGI = "report_sub_do.php";
  if (flag == "trans") sendCGI = "report_trans_do.php";
  document.report_contents.action = sendCGI;
  document.report_contents.submit(); }

//END -->
</script>

<STYLE>
BR.page { page-break-after: always }
.main_font {font : 15pt serif ;}
</STYLE>

</head>
<body BACKGROUND="./img/yellow.jpg" >


<?php

//
//	2002.1.1
//	DICOM to WWW Gateway :PHP script
//	Made by Norya Yokohama % Medical Division @ WERC
//  2004.9.19
//  added by tadashi tsuchimoto @ MITT belong to yokohamazyuku
//  update report
//


  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);



  print("<table>");
  print("<TR><TH>Patient ID:</TH><tH ALIGN=RIGHT bgcolor=\"#ccffff\">$patid</TH><TH>Sex:</TH><tH ALIGN=RIGHT bgcolor=\"#ccffff\">$patsex</TH></TR>");
  print("<TR><TH>Patient Name:</TH><tH ALIGN=LEFT bgcolor=\"#ccd555\">$name</TH><TH>Age:</TH><tH ALIGN=RIGHT bgcolor=\"#ccffff\">$patage</TH></TR>");
  //$fdate=formatDate($date);
  print("<TR><TH>Study Date:</TH><tH ALIGN=LEFT bgcolor=\"#cccfff\">$date</TH>");

  print("</table>");



  $sql = "select 
  reportlevel.report AS report ,
  reportlevel.summary AS summary ,
  reportlevel.drname AS drname ,
  reportlevel.clinicalinfo as clinicalinfo,
  reportlevel.imagediag as imagediag,
  reportlevel.tequnitian as tequnitian,
  reportlevel.orderdr as orderdr,
  reportlevel.dept as dept,
  reportlevel.diagtime as diagtime,
  reportlevel.print as print,
  reportlevel.comment as comment,
  reportlevel.patparentrep as patparentrep,
  reportlevel.bookmark as bookmark,
  reportlevel.refimage2 as refimage2,
  reportlevel.refimage3 as refimage3,
  reportlevel.refimage4 as refimage4,
  reportlevel.refimage5 as refimage5,
  reportlevel.refimage6 as refimage6,
  reportlevel.refimage7 as refimage7,
  reportlevel.refimage8 as refimage8,
  reportlevel.refimage9 as refimage9,
  reportlevel.refimage10 as refimage10,
  reportlevel.refimage as refimage,
  reportlevel.ward as ward 
   from reportlevel
  where reportlevel.ruid ='$ruid'";

  $rtn_select = $db_handle->prepare($sql);
  $rtn_select->execute();
  
  
  $row_count = $rtn_select->rowCount();


  if ($row_count>=1){
	while ($rtn_select_row = $rtn_select->fetch(PDO::FETCH_ASSOC)) {
	
    $report = $rtn_select_row['report'] ;
    $summary = $rtn_select_row['summary'] ;
    $drname = $rtn_select_row['drname'] ;
    $clinicalinfo = $rtn_select_row['clinicalinfo'] ;
    $imagediag = $rtn_select_row['imagediag'] ;
    $tequnitian = $rtn_select_row['tequnitian'] ;
    $dept = $rtn_select_row['dept'] ;
    $orderdr = $rtn_select_row['orderdr'] ;
    $diagtime = $rtn_select_row['diagtime'] ;
    $print = $rtn_select_row['print'] ;
    $comment = $rtn_select_row['comment'] ;
    $refimage = $rtn_select_row['refimage'] ;
    $refimage2 = $rtn_select_row['refimage2'] ;
    $refimage3 = $rtn_select_row['refimage3'] ;
    $refimage4 = $rtn_select_row['refimage4'] ;
    $refimage5 = $rtn_select_row['refimage5'] ;
    $refimage6 = $rtn_select_row['refimage6'] ;
	$refimage7 = $rtn_select_row['refimage7'] ;
	$refimage8 = $rtn_select_row['refimage8'] ;
	$refimage9 = $rtn_select_row['refimage9'] ;
	$refimage10 = $rtn_select_row['refimage10'] ;
    $patparentrep = $rtn_select_row['patparentrep'] ;
    $bookmark = $rtn_select_row['bookmark'] ;
    $ward = $rtn_select_row['ward'] ;
	
	}

  }else{
  print("new report insert");
  $sql_insert = "insert into reportlevel (ruid) values ('$ruid')";
  $rtn_insert = $db_handle->prepare($sql_insert);
  $rtn_insert->execute();


  }




    $time = getdate();
	$aYear=$time['year'];
	$aMonth=$time['mon'];
	$aDay=$time['mday'];
	$diagtime2 = ( $aYear ."/".  $aMonth ."/".  $aDay  );



print("<form name=\"report_contents\" action=report_mode.php method=post>");


 print("Order Dr.");



 print("<select name=orderdr value='$orderdr'>");
 
if($orderdr){
 print("<option value='$orderdr' selected>$orderdr</option>");
}

 print("<option value=></option>");

 print("</select><br>");
 

print("Comment");
print("<input type=text name=comment size=50 value='$comment' class=\"main_font\"><br>");






print("Clinical Information:");
print("&nbsp&nbsp&nbsp&nbsp&nbsp Previous Examinations:");
print("<input type=text name=summary size=15 value='$summary' class=\"main_font\"><br>");
print("<textarea name=clinicalinfo rows=2 cols=75 wrap=physical class=\"main_font\">$clinicalinfo</textarea><br>");
print("Reamrk of Images:<br>");
print("<textarea name=report rows=8 cols=75 wrap=physical class=\"main_font\">$report</textarea><br>");
print("Impression<br>");
print("<textarea name=imagediag rows=2 cols=75 wrap=physical class=\"main_font\">$imagediag</textarea><br>");


//order radiologist
 print("Diagnostician:");


 print("<input type=text name=drname size=30 value='$drname'>");




if(!$diagtime){
print("Final Update:<input type=text name=diagtime_reg size=15 value='$diagtime2'>");
}
if($diagtime){
print("Final Update:<input type=text name=diagtime_reg size=15 value='$diagtime'>");
}


print("Renewable:<input type=text name=diagtime size=15 value='$diagtime2'>");

print("<input type=hidden name=patid value='$patid'>");
print("<input type=hidden name=studyUID value='$studyUID'>");
print("<input type=hidden name=ruid value='$ruid'>");


print("<p>");



print("</form>");

print("<div align=right>");
print("<input type=\"button\" value=\"Final Update\" onClick=\"send('main')\">");

print("</div>");

print("<p>");

print("<p>");

?>



</body>
</html>
