| Current Path : /var/www/html/mmishra/icure/staff/ |
| Current File : /var/www/html/mmishra/icure/staff/medication1.inc |
<h3 align='left'>Medication</h3>
<center>
<?php
$tbl = 'medications';
$regno = $_REQUEST["regno"];
$disid = $_REQUEST["disid"];
$medid = $_REQUEST["medid"];
$batchID = $_POST["batchID"];
$qty = ($_POST["qty"] ? $_POST["qty"] : 0);
$xqty = ($_POST["xqty"] ? $_POST["xqty"] : 0);
$sqty = 0;
if ($_POST["submit"] == 'SAVE') {
//check dis qty, should not be more than the stock qty
$rs = mysql_query("select * from medicines where med_id=$medid and qty_inhand>=$qty");
if (mysql_num_rows($rs)) {
//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,batchID=$batchID,qty=$qty,dis_datetime=now(),
login_id='$user' where dis_id=$disid");
//update medicine inventory
mysql_query("update medicines set qty_inhand=qty_inhand-$qty+$xqty,qty_used=qty_used+$qty-$xqty
where med_id=$medid");
} else if($medid[$j]) {
mysql_query("insert into $tbl(reg_no,med_id,batchID,qty,dis_datetime,login_id)
values($regno,$medid,$batchID,$qty,now(),'$user')");
//update medicine inventory
mysql_query("update medicines set qty_inhand=qty_inhand-$qty,qty_used=qty_used+$qty
where med_id=$medid]");
}
}
} else if ($_POST['submit'] == 'DONE') {
if (medications($regno) != "--") {
$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 ($_REQUEST['del'] == 1) {
mysql_query("delete from $tbl where dis_id=$disid");
//update medicine inventory
mysql_query("update medicines set qty_inhand=qty_inhand+$xqty,qty_used=qty_used-$xqty
where med_id=$medid");
}
echo "Registration No. <input type='text' name='regno' value='$regno' size='10' onchange=\"javascript: document.location.href='?pg=$pg®no='+this.value\"> <input type='submit' name='submit' value='OK'><br>";
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. Add medicines one by one and click 'DONE' at the end.
</font>
<table border='1' width='90%'>
<tr><th>Sr</th><th>Medicine Name</th><th>Batch No.</th><th>Qty</th>
<th>Date Time</th><th>Staff</th><td>Action</td></tr>";
if (!$disid) {
echo "<tr><td>New</td><td>".select_medicine($regno, $medid, $pg)."</td>
<td>".select_batch($medid, $batchID)."</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>
<td><input type='submit' name='submit' value='SAVE'></td></tr>";
} else {
echo "<tr><td colspan='7'><a href='?pg=$pg®no=$regno&disid=0'>+</a></td></tr>";
}
$rs = mysql_query("select * from $tbl where reg_no=$regno order by med_id");
while ($o = mysql_fetch_object($rs)) {
$i++;
if ($disid == $o->dis_id) {
//editing of past medication
echo "<tr><th>$i</th><td>".select_medicine($regno, $o->med_id, $pg)."
<input type='hidden' name='xqty' value='$o->qty'></td>
<td>".select_batch($o->med_id, $o-batchID)."</td>
<td align='center'><input type='text' name='qty' value='$o->qty' size='3' maxlength='2'></td>
<td align='center'>$o->dis_datetime</td><td>$user</td>
<td><input type='submit' name='submit' value='SAVE'>
<a href='?pg=$pg$regno=$regno&del=1&disid=$o->dis_id'>x</a></tr>";
} else {
//list past medication
echo "<tr><th><a href='?pg=$pg®no=$regno&disid=$o->dis_id'>$i</a></th>";
echo "<td>".medicine_detail($o->med_id)."</td><td>".batch_detail($o->batchID)."</td>
<td>$o->qty</td><td>$o->dis_datetime</td><td>$o->login_id</td></tr>";
}
}
echo "</table><input type='hidden' name='disid' value='$disid'>
<input type='submit' name='submit' value='DONE'>";
//} else
// echo "No prescription";
} else
echo "No registration.";
}
?>
</center>