Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/icure/admin/
Upload File :
Current File : /var/www/html/mmishra/icure/admin/medication.inc

<h3 align='left'>Medication</h3>
<center>
<?php

$tbl = 'medications';

$regno = $_REQUEST["regno"];
$disids = $_REQUEST["disid"];

$medid = $_POST["medid"];
$batchID = $_REQUEST["batchID"];
$qty = ($_POST["qty"] ? $_POST["qty"] : 0);
$xqty = ($_POST["xqty"] ? $_POST["xqty"] : 0);
$sqty = 0;
$j = 0;

if ($_POST["submit"] == 'SAVE') {
	foreach ($disids as $disid) {
		//check dis qty, should not be more than the stock qty
		$rs = mysql_query("select * from medicines where med_id=$medid[$j]");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
			$sqty = $o->qty_inhand;
			if ($qty[$j] > $sqty) $qty[$j] = $sqty;
		}
		//maitain medication record	
		if (mysql_num_rows(mysql_query("select * from $tbl where dis_id=$disid"))) {
			mysql_query("update $tbl set reg_no=$regno,med_id=$medid[$j],qty=$qty[$j],dis_datetime=now(),
			login_id='$user' where dis_id=$disid");
			//update medicine inventory
			mysql_query("update medicines set qty_inhand=qty_inhand-$qty[$j]+$xqty[$j],qty_used=qty_used+$qty[$j]-$xqty[$j]
			where med_id=$medid[$j]");
		} else if($medid[$j]) {
			mysql_query("insert into $tbl(reg_no,med_id,qty,dis_datetime,login_id) 
			values($regno,$medid[$j],$qty[$j],now(),'$user')");
			//update medicine inventory
			mysql_query("update medicines set qty_inhand=qty_inhand-$qty[$j],qty_used=qty_used+$qty[$j]
			where med_id=$medid[$j]");
		}
		$j++;
	}
       $rs = mysql_query("select * from registrations where reg_no=$regno");
       if (mysql_num_rows($rs)) {
		$o = mysql_fetch_object($rs);
		$patgroup = $o->pat_group;
		$patid = $o->pat_id;
		$email = get_email($patgroup, $patid);
		//$email = 'mmishra@iiita.ac.in';
	}
	$str = medication_detail($regno);
	if ($email) echo automailer($email, "iCure@IIITA - Medication", $str);
} else if ($_POST["submit"] == 'DELETE') {
        foreach ($disids as $disid) {
		mysql_query("delete from $tbl where dis_id=$disid");
		//update medicine inventory
		mysql_query("update medicines set qty_inhand=qty_inhand+$xqty[$j],qty_used=qty_used-$xqty[$j]
		where med_id=$medid[$j]");
		$j++;
	}
}

?>

Registration No. <input type='text' name='regno' value='<?php echo $regno; ?>' size='10'>
<input type='submit' name='submit' value='OK'>
<br>

<?php

if ($regno) {
	if (is_registration($regno)) {
		echo registration_detail($regno);
	
		//if (is_prescription($regno)) {
		//	echo prescription_detail($regno);
		
			echo "<font color='red'>
			<b>Stocks of red marked medicines are under critical level. Quantity shown as (inhand/critical).</b>
			<br>
			Issued quantity cannot exceed stock quantity.</font> 
			<table border='1' width='70%'>
			<tr><th>Sr</th><th>Medicine Name</th><th>Qty</th><th>Date Time</th><th>Staff</th></tr>";

			$ddt 	= new datetime(date("Y-m-d"));
			$dd 	= $ddt->format('Y-m-d');
			$rs 	= mysql_query("select * from $tbl where reg_no=$regno order by med_id");
			while ($o = mysql_fetch_object($rs)) {
				$i++;
				$ddt1 	= $o->dis_datetime;
				$ddt 	= new datetime($ddt1);
				$dd 	= $ddt->format('Y-m-d');
				$lid 	= $o->login_id;
		
				echo "<tr><td>$i</td>";
        			
				if ($dd == date("Y-m-d")) {
					echo "<td><input type='hidden' name='disid[]' value='$o->dis_id'>
	   				".medicines_list($o->med_id,'-')."<input type='hidden' name='xqty[]' value='$o->qty'></td>
					<td align='center'><input type='text' name='qty[]' value='$o->qty' size='3' maxlength='2'></td>";
				} else {
					echo "<td>".medicine_detail($o->med_id)."</td>
					<td align='center'>$o->qty</td>";
				}
				echo "<td align='center'>$o->dis_datetime</td><td>".staff_detail($o->login_id)."</td></tr>";
				$ddt1 = $o->dis_datetime;
			}
			if (is_admission($regno)) $mno = 20; else $mno = 8;
			if ($dd == date("Y-m-d")) {
				while ($i < $mno) {
					$i++;
					echo "<tr><td>$i</td>
					<td><input type='hidden' name='disid[]' value='0'>
					".medicines_list('','-')."<input type='hidden' name='xqty[]' value='0'></td>
					<td align='center'><input type='text' name='qty[]' value='' size='3' maxlength='2'></td>
					<td align='center'>".date("Y-m-d H:i:s")."</td>
					<td>$user</td></tr>";
				}
				
				while ($i >= $mno && $i < $mno + 7) {
					$i++;
					echo "<tr><td>$i</td>
					<td><input type='hidden' name='disid[]' value='0'>
					".medicines_list('','-')."<input type='hidden' name='xqty[]' value='0'></td>
					<td align='center'><input type='text' name='qty[]' value='' size='3' maxlength='2'></td>
					<td align='center'>".date("Y-m-d H:i:s")."</td>
					<td>$user</td></tr>";
				}
				
				echo "<tr><th colspan='3'><input type='submit' name='submit' value='SAVE'></th>
				<th colspan='2'><input type='submit' name='submit' value='DELETE'></th></tr>";
			}
			echo "</table>";
		//} else
		//	echo "No prescription";
	} else
		echo "No registration";
}

?>
</center>