Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/iws8/html/icure/
Upload File :
Current File : /var/www/html/mmishra/iws8/html/icure/functions.inc

<?php

function list_tabledata($sql) {
        $rs = mysql_query($sql);

        if (mysql_num_rows($rs)) {
                $colHeads = mysql_num_fields($rs);

                $str = "<table border='1' width='90%'><tr><th>Sr</th>";
                for ($i=0; $i < $colHeads; $i++) { // Header
                        $str .= "<th>".ucwords(str_replace("_"," ",mysql_field_name($rs, $i)))."</th>";
                }
                $str .= "</tr>";
                        
                while ($row = mysql_fetch_row($rs)) { //data
                        $j++;
                        $str .= "<tr><td>$j</td><td>".implode($row,'</td><td>')."</td></tr>";
                }
                $str .= "</table>";
        } else {
                $str = "---";
        }
	
	return $str;
}

function get_email($patgroup, $patid) {
        if ($patgroup == 'Student')
	        return $patid.'@iiita.ac.in';
	else if ($patgroup == 'Employee') {
	        $rs = mysql_query("select email from employees where emp_no='$patid'");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
                	return $o->email;
        	} else
			return 'icure@iiita.ac.in';
        } else
		return 'rdayal@iiita.ac.in';
}

function is_student($patid) {
        $tbl = 'students';

        $rs = mysql_query("select * from $tbl where roll_no='$patid'");
        if (mysql_num_rows($rs)) return TRUE;
	else return FALSE;

}

function student_detail($rollno) {
        $tbl = 'students';

        $str = "<div>";
        $rs = mysql_query("select * from $tbl where roll_no='$rollno'");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "$o->name_eng ($o->dob)";
        }
        $str .= "</div>";

        return $str;
}

function is_employee($patid) {
        $tbl = 'employees';
        
        $rs = mysql_query("select * from $tbl where emp_no='$patid'");
        if (mysql_num_rows($rs)) return TRUE;
        else return FALSE;
        
}

function employee_detail($empno) {
        $tbl = 'employees';

        $str = "<div>";
        $rs = mysql_query("select * from $tbl where emp_no='$empno'");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "$o->emp_name ($o->designation)";
        }
        $str .= "</div>";

        return $str;
}

function employee_list($empno) {
        $tbl = 'employees';

        $str = "<select name='patid' style='width:230'><option value=''>Select Name</option>";
        $rs = mysql_query("select emp_no,emp_name,designation from $tbl order by emp_name");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->emp_no'".($empno == $o->emp_no ? ' selected' : '').">$o->emp_name</option>";
        }
        $str .= "</select>";

        return $str;
}

function agencystaff_list($empno) {
        $tbl = 'agencystaffs';

        $str = "<select name='patid' style='width:230'><option value=''>Select Name</option>";
        $rs = mysql_query("select staff_no as emp_no,concat(staff_name,' (',trim(staff_post),')') as emp_name from $tbl order by emp_name");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->emp_no'".($empno == $o->emp_no ? ' selected' : '').">$o->emp_name</option>";
        }
        $str .= "</select>";

        return $str;
}

function agencystaff_detail($staffnm) {
        $tbl = 'agencystaffs';

        $str = "<div>";
        $rs = mysql_query("select * from $tbl where staff_name='$staffnm'");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "$o->staff_name ($o->staff_post)";
        }
        $str .= "</div>";

        return $str;
}

function patient_name($regno) {
	$rs = mysql_query("select pat_group,pat_id,dependent from registrations where reg_no=$regno");
	if (mysql_num_rows($rs)) {
		$o = mysql_fetch_object($rs);
        	$patgroup = $o->pat_group;
        	$patid = $o->pat_id;
        	$dependent = $o->dependent;
        
		if ($patgroup == 'Student') $sql = "select name_eng as pname,gender as spec from students where roll_no='$patid'";
		else if ($patgroup == 'Employee') $sql = "select emp_name as pname,designation as spec from employees where emp_no='$patid'";
		//else if ($patgroup == 'AgencyStaff') $sql = "select staff_name as pname,staff_post as spec from agencystaffs where staff_no=$patid";
		else $sql = "select staff_name as pname,staff_post as spec from agencystaffs where staff_name='$patid'";

        	$rs = mysql_query($sql);
        	if (mysql_num_rows($rs)) {
        		$o = mysql_fetch_object($rs);
                	$str .= "[ $patgroup: ".strtoupper($patid)." ]<br>$o->pname ($o->spec)<br>";
			$str .= ($dependent == 'Dependent Name' || $dependent == 'Parent Name' || $dependent == 'Official Purpose' ? "Self" :"Dependent: $dependent");
        	} else {
                	$str .= "[ $patgroup: ".strtoupper($patid)." ]";
			$str .= "<br>$dependent";
		}
		//$str .= ($dependent ? "<br>Dependent: $dependent" : '<br>Self');
        }

        return $str;
}

function patient_detail($patid) {
        $str = "<div>";
	$rs = mysql_query("select pat_group,dependent from registrations where pat_id='$patid' order by reg_no desc");
	if (mysql_num_rows($rs)) {
		$o = mysql_fetch_object($rs);
        	$patgroup = $o->pat_group;
        	$dependent = $o->dependent;
		
		if ($patgroup == 'Student') $sql = "select name_eng as pname,gender as spec from students where roll_no='$patid'";
		else if ($patgroup == 'Employee') $sql = "select emp_name as pname,designation as spec from employees where emp_no='$patid'";
		else $sql = "select staff_name as pname,staff_post as spec from agencystaffs where staff_name='$patid'";

        	$rs = mysql_query($sql);
        	if (mysql_num_rows($rs)) {
        		$o = mysql_fetch_object($rs);
                	$str .= "[ $patgroup: ".strtoupper($patid)." ]<br>$o->pname ($o->spec)";
        	} else {
                	$str .= "[ $patgroup: ".strtoupper($patid)." ]";
		}
		//$str .= ($dependent ? "<br>Dependent: $dependent" : '<br>Self');
	} else {
                $str .= "[ New: ".strtoupper($patid)." ]";
        }
	$str .= "</div>";

        return $str;
}

function doctor_list($drid) {
	$str = "<select name='drid'><option value=''></option>";
	$rs = mysql_query("select * from doctors order by dr_name");
	while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->dr_id'";
		if ($drid == $o->dr_id) $str .= ' selected';
		$str .= ">$o->dr_name</option>";
        }
	$str .= '</select>';

        return $str;
}

function doctor_detail($drid) {
        //$str = "<div>";
        $rs = mysql_query("select * from doctors where dr_id='$drid'");
        while ($o = mysql_fetch_object($rs)) {
                //$str .= "$o->dr_name ($o->specialization)";
                $str .= "$o->dr_name ($o->designation)";
        }
        //$str .= "</div>";

        return $str;
}

function staff_list($phid) {
        $str = "<select name='phid'><option value=''></option>";
        $rs = mysql_query("select * from staffs order by ph_name");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->ph_id'";
                if ($phid == $o->ph_id) $str .= ' selected';
                $str .= ">$o->ph_name</option>";
        }
        $str .= '</select>';

        return $str;
}

function staffmulti_list($phid) {
        $str = "<select name='phid[]' size='7' multiple><option value=''></option>";
        $rs = mysql_query("select * from staffs order by ph_name");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->ph_id'";
                if ($phid == $o->ph_id) $str .= ' selected';
                $str .= ">$o->ph_name</option>";
        }
        $str .= '</select>';

        return $str;
}

function staffcheck_list($phid) {
        $rs = mysql_query("select * from staffs order by ph_name");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<input type='checkbox' name='phid[]' value='$o->ph_id'";
                if ($phid == $o->ph_id) $str .= ' checked';
                $str .= ">$o->ph_name";
        }

        return $str;
}

function staff_detail($phid) {
        $rs = mysql_query("select * from staffs where ph_id='$phid'");
        if (mysql_num_rows($rs)) {
		$o = mysql_fetch_object($rs);
                $str = "$o->ph_name ($o->specialization)";
        } else {
		$str = "X-staff";
	}

        return $str;
}

function medicine_list($medid, $plusminus) {
        $str = "<select name='medid'><option value=''></option>";
        if ($plusminus == '+')
		$rs = mysql_query("select * from medicines order by med_name");
        else { 
		//$rs = mysql_query("select * from medicines where qty_inhand>qty_critical order by med_name");
		$rs = mysql_query("select * from medicines where qty_inhand>0 order by med_name");
	}
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option style='color:".($o->qty_inhand <= $o->qty_critical ? 'red' : '')."' value='$o->med_id'";
                if ($medid == $o->med_id) $str .= ' selected';
                $str .= ">$o->med_name ($o->qty_inhand/$o->qty_critical)</option>";
        }
        $str .= '</select>';

        return $str;
}

function medicines_list($medid, $plusminus) {
        $str = "<select name='medid[]'><option value=''></option>";
        if ($plusminus == '+')
                $rs = mysql_query("select * from medicines order by med_name");
        else {
                //$rs = mysql_query("select * from medicines where qty_inhand>qty_critical order by med_name");
                $rs = mysql_query("select * from medicines where qty_inhand>0 order by med_name");
        }
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option style='color:".($o->qty_inhand <= $o->qty_critical ? 'red' : '')."' value='$o->med_id'";
                if ($medid == $o->med_id) $str .= ' selected';
                $str .= ">$o->med_name ($o->qty_inhand/$o->qty_critical)</option>";
        }
        $str .= '</select>';

        return $str;
}

function medicine_detail($medid) {
        $str = "<div>";
        $rs = mysql_query("select med_name from medicines where med_id=$medid");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "$o->med_name";
        }
	$str .= "</div>";

        return $str;
}

function material_list($medid,$plusminus) {
        $str = "<select name='medid'>";
        if ($plusminus == '+')
                $rs = mysql_query("select * from materials order by med_name");
        else {
                //$rs = mysql_query("select med_id,med_name from $tbl where qty_inhand>qty_critical order by med_name");
                $rs = mysql_query("select * from materials where qty_inhand>0 order by med_name");
        }
        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option style='color:".($o->qty_inhand <= $o->qty_critical ? 'red' : '')."' value='$o->med_id'";
                if ($medid == $o->med_id) $str .= ' selected';
                $str .= ">$o->med_name ($o->qty_inhand/$o->qty_critical/$o->qty_used)</option>";
        }
        $str .= '</select>';

        return $str;
}

function material_detail($medid) {
        $str = "<div>";
        $rs = mysql_query("select med_name from materials where med_id=$medid");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "$o->med_name";
        }
        $str .= "</div>";

        return $str;
}


function registration_detail($regno) {
        $rs = mysql_query("select * from registrations where reg_no=$regno");
        while ($o = mysql_fetch_object($rs)) {
                $str = "<table border='1' width='90%' style='border-collapse: collapse'>
                <tr><th>RegNo</th><th>Dated</th><th nowrap>Patient</th><th nowrap>Doctor</th></tr>
                <tr><td align='center'><font size='+1'>$regno</font></td>
		<td align='center'>$o->reg_date $o->reg_time</td>
                <td>".patient_detail($o->pat_id).($o->dependent ? 'Dependent: '.$o->dependent : '(Self)')."</td>
                <td align='center'>".doctor_detail($o->dr_id)."</td>
                </tr></table><br>";
        }

	return $str;
}

//multiple registrations
function list_registrations($patid) {
        $str = "[ $patid]".patient_detail($patid);
	$rs = mysql_query("select * from registrations where pat_id='$patid' order by reg_no desc");
        while ($o = mysql_fetch_object($rs)) {
		$i++;
		$str .= "$i) ".($o->dependent ? "Dependent: ".strtoupper($o->dependent) : "Self");
                $str .= "<table border='1' width='95%'>
                <tr><th>RegNo</th><th>Registration Date</th><th>Doctor</th><th>Staff</th></tr>
                <tr><td align='center'>$o->reg_no</td><td align='center'> $o->reg_date $o->reg_time</td>
                <td align='center'>".doctor_detail($o->dr_id)."</td>
		<td align='center'>".staff_detail($o->login_id)."</td>
                </tr></table><br>";
        }

        return $str;
}

function medications($regno) {
        $sql = "select med_name as medicine,qty,a.login_id as staff from medications as a, medicines as b where a.med_id=b.med_id and reg_no=$regno order by dis_id";

	$rs = mysql_query($sql);
        if (mysql_num_rows($rs)) {
        	$str = "<ol>";
		while ($o = mysql_fetch_object($rs)) {
			$staff = $o->staff;
                	$str .= "<li>$o->medicine ($o->qty)</li>";
        	}
		$str .= "</ol>By: ".staff_detail($staff);
	} else {
		$str = '--';
	}

        return $str;
}

function medication_detail($regno) {
	$str = "<table border='1'>
	<tr><th>Registration</th><th>Medication</th></tr>
	<tr><td>".registration_detail($regno) ."</td><td>".medications($regno)."</td></tr>
	</table>"; 
        
	return $str;
}

function is_registration($regno) {
        
        if (mysql_num_rows(mysql_query("select * from registrations where reg_no=$regno")))
                return TRUE;
        else    
                return FALSE;

}

function registrations($regno) {
        $sql = "select * from registrations where reg_no=$regno";

        $rs = mysql_query($sql);
        if (mysql_num_rows($rs)) {
                $o = mysql_fetch_object($rs);
                $str = 'RegNo.:'.$o->reg_no.'<br>'.
		'Dated: '.$o->reg_date.'<br>'.
                'Doctor: '.doctor_detail($o->dr_id).'<br>'.
                'Staff: '.staff_detail($o->login_id);
        } else {
                $str = '--';
        }

        return $str;
}

function admission_detail($regno) {
        $rs = mysql_query("select * from admissions where reg_no=$regno");
        while ($o = mysql_fetch_object($rs)) {
                $str = "<table border='1' width='50%'>
                <tr><th>Admission Date Time</th><th>Diagnosis</th></tr>
                <tr><td align='center'>$o->adm_datetime</td>
                <td>$o->diagnosis</td>
                </tr></table><br>";
        }

        return $str;
}

function is_admission($regno) {
        
        if (mysql_num_rows(mysql_query("select * from admissions where reg_no=$regno")))
                return TRUE;
        else    
                return FALSE;

}

function prescription_detail($regno) {
        $str = "<div align='left' border='1'><b>Rx-</b>";

        $rs = mysql_query("select * from prescriptions where reg_no=$regno order by pres_id");
        while ($o = mysql_fetch_object($rs)) {
                if (is_numeric($o->medicine))
			$str .= "<li>".phtest_detail($o->medicine)."</li>";
		else 
			$str .= "<li>$o->medicine ($o->dose, $o->frequency times, $o->course_days days)</li>";
        }
        $str .= "</ul></div>";

        return $str;
}

function is_prescription($regno) {

        if (mysql_num_rows(mysql_query("select * from prescriptions where reg_no=$regno")))
		return TRUE;
	else
		return FALSE;

}

function phtest_list($testgroup,$testid) {
        $tbl = 'phtests';

        $str = "<select name='testid'>";
        if ($testgroup)
		$rs = mysql_query("select test_id,test_group,test_name,test_range from $tbl where test_group='$testgroup' order by test_name");
	else 
		$rs = mysql_query("select test_id,test_group,test_name,test_range from $tbl order by test_group,test_name");

        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->test_id'";
                if ($testid == $o->test_id) $str .= ' selected';
                $str .= ">$o->test_group, $o->test_name ($o->test_range)</option>";
        }
        $str .= "</select>";

        return $str;
}

function phtest_detail($testid) {
        $str = "";
        $rs = mysql_query("select * from phtests where test_id=$testid");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "$o->test_group, $o->test_name ($o->test_range)";
        }
	$str .= "";

        return $str;
}

function phtest_group($testid) {
        $rs = mysql_query("select * from phtests where test_id=$testid");
        while ($o = mysql_fetch_object($rs)) {
                $str = $o->test_group;
        }
        return $str;
}

function hospital_list($hosid) {
        $tbl = 'hospitals';

        $str = "<select name='hosid'><option value=''></option>";
        $rs = mysql_query("select * from $tbl order by hos_name");

        while ($o = mysql_fetch_object($rs)) {
                $str .= "<option value='$o->hos_id'";
                if ($testid == $o->hos_id) $str .= ' selected';
                $str .= ">$o->hos_name</option>";
        }
        $str .= "</select>";

        return $str;
}

function hospital_detail($hosid) {
        $str = "";
        $rs = mysql_query("select * from hospitals where hos_id=$hosid");
        while ($o = mysql_fetch_object($rs)) {
                $str .= "$o->hos_name, $o->address";
        }
        $str .= "";

        return $str;
}

function previous_month() {
        $pmonth = (int)(date("n"));
        if ($pmonth == 0) {
                $pmonth = 12;
                $pyear = date("Y") - 1;
        } else
                $pyear = date("Y");

        return date("Y-m", mktime(0, 0, 0, $pmonth, 0, $pyear));
}

function next_month() {
        $nmonth = (int)(date("n"));
        if ($nmonth == 12) {
                $nmonth = 0;
                $nyear = date("Y") + 1;
        } else
                $nyear = date("Y");

        $nmonth = $nmonth + 1;

        return date("Y-m", mktime(0, 0, 0, $nmonth, 25, $nyear));
}

function DateAdd($days) {
        $curdate = getdate();
        $cday = $curdate['mday'] + $days;
        $cmonth = $curdate['mon'];
        $cyear = $curdate['year'];
        if ($cday > 31) {
                $cmonth = $cmonth + 1;
                $cday = $cday - 31;
                if ($cmonth == 13) {
                        $cyear = $cyear + 1;
                        $cmonth = 1;
                }
        }

        if ($cday < 10) $cday = "0$cday";
        if ($cmonth < 10) $cmonth = "0$cmonth";
        //$ourDate = array($cyear, $cmonth, $cday);
        $ourDate = "$cyear-$cmonth-$cday";

        return $ourDate;
}

function htmlsafe($str) {
	return trim(htmlspecialchars(stripslashes($str), ENT_QUOTES));
}

function htmlunsafe($str) {
	return trim(htmlspecialchars_decode($str, ENT_COMPAT));
}

?>