<commit_before><!--  TODO
deal with error if page is navigated without ID's
change hdnCmd and txtEdit names
error check for unique key error
-->
<!-- 
	Selects and renders an image from passed recordID and associated imageID
	Variables passed by URL: 
		$recordID, primary key ID
		$imageID, unique image identifier for associated recordID
		$imageType, image size option (THUMBNAIL, REGULAR_SIZE, FULL_SIZE)	
		Author: <NAME>
 -->
<html>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head><link href="base.css" rel="stylesheet" type="text/css"></head>
<h2>Image Upload</h2>
<a href="manageRadiologyRecords.php"> Radiology Record Module</a><p>
<?php
	include("PHPconnectionDB.php");
	include("imageMultipleView.php");
	include("imageResize.php");
	
	// Function: uploads/inserts an image to the pacs_images table
	// Parameters:
	//		$imgfile, image to be stored
	// 		$recordID, primary key ID
	//		$imageID, unique identifier for image associated with recordID
	//		$imageType, image size option (THUMBNAIL, REGULAR_SIZE, FULL_SIZE)
	function uploadImage($imgfile, $recordID, $imageID, $imageType){
		$conn = connect();
		$lob = oci_new_descriptor($conn, OCI_D_LOB);
		//$lob2 = oci_new_descriptor($conn, OCI_D_LOB);
		//$query = "SELECT ".$imageType." FROM PACS_I
		/*
		$query = "insert into pacs_images (record_id, image_id, ".$imageType.") "
			."values(:recordID, :imageID, empty_blob()) returning ".$imageType." into :blobdata "
			."on duplicate key update ".$imageType." = empty_blob() returning ".$imageType." into :blobdata";
		*/
		//update pacs_images set ".$imageType." = empty_blob() where record_id = :recordID and image_id = :imageID returning ".$imageType." into :blobdata";
		/*
		begin 
		insert into t (mykey, mystuff)
		values ('X', 123);
		exception
		when dup_val_on_index then
		update t
		set    mystuff = 123
		where  mykey = 'X';
		end;
		*/
		
		//$query = "begin "
		/*
		$query = "delete from pacs_images where record_id = :recordID and image_id = :imageID";
		//echo $query;
		$stmt = oci_parse ($conn, $query);
		oci_bind_by_name($stmt, ':recordID', $recordID);
		oci_bind_by_name($stmt, ':imageID', $imageID);
		$e = oci_execute($stmt);
		oci_free_statement($stmt);
		*/

		/*
		$query = "insert into pacs_images (record_id, image_id, ".$imageType.") "
		."values(:recordID, :imageID, empty_blob()) "		
		."returning ".$imageType." into :blobdata;"
		."exception "
		."when dup_val_on_index then "
		."update pacs_images set ".$imageType." = empty_blob() "
		."where record_id = :recordID and image_id = :imageID "
		."returning ".$imageType." into :blobdata; ";
		*/
		
		/* Merge does not work with 'returning'
		 * this was the last query that I tried
		 */
		$query = "merge into pacs_images "
		."using dual on (record_id = :recordID and image_id = :imageID) "
		."when matched then "
		."update set ".$imageType." = empty_blob() "
		//."where record_id = :recordID and image_id = :imageID "
		."returning ".$imageType." into :blobdata "
		."when not matched then "		
		."insert (record_id, image_id, ".$imageType.") "
		."values (:recordID, :imageID, empty_blob()) "
		."returning ".$imageType." into :blobdata;";

		//."end;";
		
		
		
		echo $query;
		$stmt = oci_parse($conn, $query);
		oci_bind_by_name($stmt, ':recordID', $recordID);
		oci_bind_by_name($stmt, ':imageID', $imageID);
		oci_bind_by_name($stmt, ':blobdata', $lob, -1, OCI_B_BLOB);
		//oci_bind_by_name($stmt, ':blobdata2', $lob2, -1, OCI_B_BLOB);
		oci_execute($stmt, OCI_DEFAULT);  // Note OCI_DEFAULT

		
		if ($lob->save($imgfile)) {
			oci_commit($conn);
			echo "BLOB uploaded";
		}
		else {
			echo "Couldn't upload BLOB\n";
			echo "<h1>Record ID is: " . $recordID . "</h1>";
			echo "<h1>Image ID is: " . $imageID . "</h1>";
		}

		$lob->free();
		oci_close($conn);
		return;
	}
		
	// Display upload form if upload has not occurred
	if (!isset($_FILES['image'])) {
		$recordID = $_GET["recordID"];
		
		// Display thumbnail list
		// Must be all-caps for imageResize and imageView queries
		multi_image($recordID, 'REGULAR_SIZE'); 
?>		<commit_msg>Fixes to images insertion (in progress)<commit_after><!--  TODO
deal with error if page is navigated without ID's
change hdnCmd and txtEdit names
error check for unique key error
-->
<!-- 
	Selects and renders an image from passed recordID and associated imageID
	Variables passed by URL: 
		$recordID, primary key ID
		$imageID, unique image identifier for associated recordID
		$imageType, image size option (THUMBNAIL, REGULAR_SIZE, FULL_SIZE)	
		Author: <NAME>
 -->
<html>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head><link href="base.css" rel="stylesheet" type="text/css"></head>
<h2>Image Upload</h2>
<a href="manageRadiologyRecords.php"> Radiology Record Module</a><p>
<?php
	include("PHPconnectionDB.php");
	include("imageMultipleView.php");
	include("imageResize.php");
	
	// Function: uploads/inserts an image to the pacs_images table
	// Parameters:
	//		$imgfile, image to be stored
	// 		$recordID, primary key ID
	//		$imageID, unique identifier for image associated with recordID
	//		$imageType, image size option (THUMBNAIL, REGULAR_SIZE, FULL_SIZE)
	function uploadImage($imgfile, $recordID, $imageID, $imageType){
		$conn = connect();
		$lob = oci_new_descriptor($conn, OCI_D_LOB);
		//$lob2 = oci_new_descriptor($conn, OCI_D_LOB);
		//$query = "SELECT ".$imageType." FROM PACS_I
		/*
		$query = "insert into pacs_images (record_id, image_id, ".$imageType.") "
			."values(:recordID, :imageID, empty_blob()) returning ".$imageType." into :blobdata "
			."on duplicate key update ".$imageType." = empty_blob() returning ".$imageType." into :blobdata";
		*/
		//update pacs_images set ".$imageType." = empty_blob() where record_id = :recordID and image_id = :imageID returning ".$imageType." into :blobdata";
		/*
		begin 
		insert into t (mykey, mystuff)
		values ('X', 123);
		exception
		when dup_val_on_index then
		update t
		set    mystuff = 123
		where  mykey = 'X';
		end;
		*/
		
		//$query = "begin "
		/*
		$query = "delete from pacs_images where record_id = :recordID and image_id = :imageID";
		//echo $query;
		$stmt = oci_parse ($conn, $query);
		oci_bind_by_name($stmt, ':recordID', $recordID);
		oci_bind_by_name($stmt, ':imageID', $imageID);
		$e = oci_execute($stmt);
		oci_free_statement($stmt);
		*/

		/*
		$query = "insert into pacs_images (record_id, image_id, ".$imageType.") "
		."values(:recordID, :imageID, empty_blob()) "		
		."returning ".$imageType." into :blobdata;"
		."exception "
		."when dup_val_on_index then "
		."update pacs_images set ".$imageType." = empty_blob() "
		."where record_id = :recordID and image_id = :imageID "
		."returning ".$imageType." into :blobdata; ";
		*/
		
		/* Merge does not work with 'returning'
		 * this was the last query that I tried
		 */
		/*
		$query = "merge into pacs_images "
		."using dual on (record_id = :recordID and image_id = :imageID) "
		."when matched then "
		."update set ".$imageType." = empty_blob() "
		//."where record_id = :recordID and image_id = :imageID "
		."returning ".$imageType." into :blobdata "
		."when not matched then "		
		."insert (record_id, image_id, ".$imageType.") "
		."values (:recordID, :imageID, empty_blob()) "
		."returning ".$imageType." into :blobdata;";
		*/
		//."end;";
		$query = "update pacs_images set ".$imageType." = empty_blob() "
		."where record_id = :recordID and image_id = :imageID;";	
		echo $query;
		$query = oci_parse($conn, $query);
		oci_bind_by_name($query, ':recordID', $recordID);
		oci_bind_by_name($query, ':imageID', $imageID);
		oci_bind_by_name($query, ':blobdata', $lob, -1, OCI_B_BLOB);
		//oci_bind_by_name($stmt, ':blobdata2', $lob2, -1, OCI_B_BLOB);
		oci_execute($query, OCI_DEFAULT);  // Note OCI_DEFAULT
		
		if ($lob->save($imgfile)) {
			oci_commit($conn);
			echo "BLOB uploaded";
		}
		else {
			echo "Couldn't upload BLOB\n";
			echo "<h1>Record ID is: " . $recordID . "</h1>";
			echo "<h1>Image ID is: " . $imageID . "</h1>";
		}

		$lob->free();
		oci_close($conn);
		return;
	}
		
	// Display upload form if upload has not occurred
	if (!isset($_FILES['image'])) {
		$recordID = $_GET["recordID"];
		
		// Display thumbnail list
		// Must be all-caps for imageResize and imageView queries
		multi_image($recordID, 'REGULAR_SIZE'); 
?>		
{'fraction_non_alphanumeric': 0.16089613034623218, 'fraction_numerical': 0.005271354977836348, 'mean_word_length': 3.8875878220140514, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4707212', 'n_tokens_mistral': 3216, 'n_tokens_neox': 2928, 'n_words': 787}