<?php
//mysql_connect("localhost","root","") or die("Error1:".mysql_error());
//mysql_select_db("buda_hotel_dbms") or die("Error2:".mysql_error());
class labClass{

     public  $dbcon;
     public  $host="localhost";
     public  $dbname="budacotz_labdb";
     public  $user="budacotz_bundaTZ";
     public  $pwd="Bunda@2025";
     //public  $user="root";
    // public  $pwd="";
    // public  $port="3308";


                                      //FUNCTION FOR DATABASE CONNECTION GOES HERE
 
function __construct(){
	
			 //  $this->dbcon = new PDO("mysql:dbname=$this->dbname;host=$this->host;$this->port",$this->user,$this->pwd);
            $this->dbcon = new PDO("mysql:dbname=$this->dbname;host=$this->host;",$this->user,$this->pwd);
          
}

function getDrTech(){
  try{
    $depart="Doctor";
    $ownerH=$this->dbcon->prepare("select * from users where department=:em"); 
    $ownerH->bindParam(":em",$depart); 
    $ownerH->execute(); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getPatientCheckUpReportsBydate($patientID,$dat1,$dat2){
  try{  

 
    $pStatus="Not yet";
     
    $data= array($patientID, $pStatus,$dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  testrecords where patientID=? and pStatus!=? and  tDate between ? and ?"); 

     
    $ownerH->execute($data); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getPatientsRecordByDate($dat1,$dat2){
  try{
    
    $data= array($dat1,$dat2);

    $ownerH=$this->dbcon->prepare("select * from patientdetail where regdate between ? and ?");  
      
    $ownerH->execute($data); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getLabToolKitUsedRecordsBydate($dat1,$dat2){
  try{  

    $data= array($dat1,$dat2);

    $ownerH=$this->dbcon->prepare("select * from  toolkitused where dateEntry between ? and ?"); 

     
    $ownerH->execute($data); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getLabToolKitRecordsBydate($dat1,$dat2){
  try{  

    $data= array($dat1,$dat2);

    $ownerH=$this->dbcon->prepare("select * from  toolkitentry where dateEntry between ? and ?"); 

     
    $ownerH->execute($data); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getPatientsCheckUpBillRecordsBydate($dat1,$dat2){
  try{  

 
    $pStatus="PAID";
     
    $data= array($pStatus,$dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  testrecords where pStatus=? and  tDate between ? and ?"); 

     
    $ownerH->execute($data); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getPatientsCheckUpRecordsBydate($dat1,$dat2){
  try{  

  
     
    $data= array($dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  testrecords where  tDate between ? and ?"); 

     
    $ownerH->execute($data); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getExpensesR(){
  try{
    $ownerH=$this->dbcon->prepare("select * from expenditure");

    $ownerH->execute(); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


///----------------REGISTRATION FORM VALIDATION---------------------
function registerEx($tname, $tPrice,$exDate){
  

   $regdate=Date("Y-m-d");$time=Date("h:i:sa");

   $data=array($tname, $tPrice,$exDate);
        
   try{   

      $Qr=$this->dbcon->prepare("insert into expenditure(exReason,exAmount,exDate) values(?,?,?)");
      
      $Qr->execute($data); 

      if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
   

}
catch(PDOException $ex){
  $ex->getMessage();
}
}


///////////////////////////


function addUsers($password,$depart,$email,$fname,$mname,$lname,$gender,$occupation,$phoneno,$country,$address,$dob,$empDate){
  
 try{
   $regdate=Date("Y-m-d");$time=Date("h:i:sa");

   //$data=array($password,$depart,$email,$fname,$mname,$lname,$gender,$occupation,$phoneno,$country,$address,$dob,$empDate);
  
//fname mname lname email phone dob department  citizen address gender  pwd empDate 
  $Q=$this->dbcon->prepare("insert into users(pwd,department,email,fname,mname,lname,gender,occupation,phoneno,citizen,address,dob,dhired)values(?,?,?,?,?,?,?,?,?,?,?,?,?)");

  $Q->execute(array($password,$depart,$email,$fname,$mname,$lname,$gender,$occupation,$phoneno,$country,$address,$dob,$empDate)); 

   if($Q->rowCount()>0)
   {
     return $Q;  
    }
   else
   {   
   return $Q->ErrorInfo(); 
   }
    
}
catch(PDOException $ex){
  $ex->getMessage();
}
}


function getUsersRecord(){
  try{
    $ownerH=$this->dbcon->prepare("select * from users");  
      $ownerH->execute(); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getLabTech(){
  try{
    $depart="Lab";
    $ownerH=$this->dbcon->prepare("select * from users where department=:em"); 
    $ownerH->bindParam(":em",$depart); 
    $ownerH->execute(); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function updateMtestResultD($pStatus,$user,$recordID,$patientID,$tname,$rDescrip,$rStatus,$Checkedby){
  try{
         $checkingStatus="Checked";

         $data=array($rDescrip,$user,$Checkedby,$checkingStatus,$rStatus, $recordID,$patientID,$pStatus,$tname);

         $ownerH=$this->dbcon->prepare("update testrecords set rDescrip=?,postedBy=?,checkedBy=?, checkingStatus=?, status=?  where recordID=? and patientID=?and pStatus!=? and mTest=?"); 
     
         $ownerH->execute($data); 
        
        return $ownerH;
   
 
     }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

 function login($username,$password){
  try{

    $Rs=$this->dbcon->prepare("select * from users where email=:em and pwd=:psd");
    $Rs->bindParam(":em",$username);
    $Rs->bindParam(":psd",$password);
    $Rs->execute(); 
    
     return $Rs;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getPatientCheckUpForupdateD($patientID,$tDate){
  try{
    $pStatus="Not yet"; 

    $ownerH=$this->dbcon->prepare("select * from  testrecords where patientID=:Id and pStatus !=:tId and tDate =:bId and rDescrip =:rId"); 

    //$ownerH->bindParam(":Id",$recordID);
    $ownerH->bindParam(":Id",$patientID);  
    $ownerH->bindParam(":tId",$pStatus);
    $ownerH->bindParam(":bId",$tDate); 
    $ownerH->bindParam(":rId",$pStatus);
   // $ownerH->bindParam(":tId",$tname);

    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}


function updateMtestBillD($sID,$pStatus,$recordID,$patientID,$tname,$tPrice){
  try{
         $data=array($tPrice,$sID,$pStatus,$recordID,$patientID,$tname);

         $ownerH=$this->dbcon->prepare("update testrecords set billAmount=?,sID=?, pStatus=? where recordID=? and patientID=? and mTest=?"); 
     
         $ownerH->execute($data); 
        
        return $ownerH;
      
     }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getLabToolKitUsedRecords(){
  try{  

    $ownerH=$this->dbcon->prepare("select * from  toolkitused"); 

     
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}




function getLabToolKitRecords(){
  try{  

    $ownerH=$this->dbcon->prepare("select * from  toolkitentry"); 

     
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}


function getPatientCheckUpReports($patientID,$tDate){
  try{  

   $pStatus="Not yet";
    
   $ownerH=$this->dbcon->prepare("select * from  testrecords where patientID=:pid and tDate=:td and pStatus!=:id"); 

  $ownerH->bindParam(":pid",$patientID);
  $ownerH->bindParam(":td",$tDate);
  $ownerH->bindParam(":id",$pStatus);
 
     
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getCrrReports($patientID,$sdate){
  try{  
   $ownerH=$this->dbcon->prepare("select distinct dateB  from  billrecord where patientID=:pid and dateB=:td order by dateB desc"); 
  $ownerH->bindParam(":pid",$patientID);
  $ownerH->bindParam(":td",$sdate);
  //$ownerH->bindParam(":id",$pStatus);
    $ownerH->execute();  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getPDReports($patientID){
  try{  
   $ownerH=$this->dbcon->prepare("select distinct dateB  from  billrecord where patientID=:pid order by dateB desc"); 
  $ownerH->bindParam(":pid",$patientID);
  //$ownerH->bindParam(":td",$tDate);
  //$ownerH->bindParam(":id",$pStatus);
    $ownerH->execute();  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getCodeReports($patientID,$dateB){
  try{   
   $ownerH=$this->dbcon->prepare("select * from  pdiagnosis where patientID=:pid and dateAt=:td"); 
  $ownerH->bindParam(":pid",$patientID);
  $ownerH->bindParam(":td",$dateB);
  $ownerH->execute();   
  return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getRosReports($patientID,$dateB){
  try{   
   $ownerH=$this->dbcon->prepare("select * from  ros where patientID=:pid and dateAt=:td"); 
  $ownerH->bindParam(":pid",$patientID);
  $ownerH->bindParam(":td",$dateB);
  $ownerH->execute();   
  return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getMTReports($patientID,$dateB){
  try{   
   $ownerH=$this->dbcon->prepare("select * from  testrecords where patientID=:pid and tDate=:td"); 
  $ownerH->bindParam(":pid",$patientID);
  $ownerH->bindParam(":td",$dateB);
  $ownerH->execute();   
  return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getDrugReports($patientID,$dateB){
  try{   
   $ownerH=$this->dbcon->prepare("select * from  drugdispenses where patientID=:pid and dateAt=:td"); 
  $ownerH->bindParam(":pid",$patientID);
  $ownerH->bindParam(":td",$dateB);
  $ownerH->execute();   
  return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getCompReports($patientID,$dateB){
  try{   
   $ownerH=$this->dbcon->prepare("select * from  complainhpi where patientID=:pid and dateAt=:td"); 
  $ownerH->bindParam(":pid",$patientID);
  $ownerH->bindParam(":td",$dateB);
  $ownerH->execute();   
  return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getPurchaseRBydate($dat1,$dat2){
  try{   
    $data= array($dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  purchaserecord where  entryD between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


function getServiceRBydate($dat1,$dat2){
  try{   
    $data= array($dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  billrecord where  dateB between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getDispenseRBydate($dat1,$dat2){
  try{  
    $pStatus="Not yet";
    $data= array($pStatus,$dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  drugdispenses where payStatus!=? and  dateAt between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getPurchaseR($sdate){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from  purchaserecord where  entryD=:dt"); 
    $ownerH->bindParam(":dt",$sdate);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getDispenseR($sdate){
  try{  

    $pStatus="Not yet";
    
    $ownerH=$this->dbcon->prepare("select * from  drugdispenses where payStatus!=:id and dateAt=:dt"); 
    $ownerH->bindParam(":id",$pStatus);
    $ownerH->bindParam(":dt",$sdate);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getPatientsCheckUpBillRecords(){
  try{  

    $pStatus="Not yet";
    
    $ownerH=$this->dbcon->prepare("select * from  testrecords where pStatus!=:id"); 

    $ownerH->bindParam(":id",$pStatus);
     
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getServiceBillRecords($sdate){
  try{  
    //$data=array($sdate);
    $ownerH=$this->dbcon->prepare("select * from  billrecord where dateB=:id"); 
    $ownerH->bindParam(":id",$sdate);
    $ownerH->execute();  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getDrConsult($sdate,$user){
  try{  
    $data=array($sdate,'%'.$user.'%');
    $ownerH=$this->dbcon->prepare("select * from  billrecord where dateB=? and descript like ?"); 
    //$ownerH->bindParam(":id",$sdate);
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}



function getPvitalS($sdate,$patientID){
  try{  
    //$data=array($sdate,'%'.$user.'%');
    $ownerH=$this->dbcon->prepare("select * from  vitalsign where dateT=:dt and patientID=:Id"); 
    $ownerH->bindParam(":dt",$sdate);
    $ownerH->bindParam(":Id",$patientID);
    $ownerH->execute();  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


function getDrConsultByDate($dat1,$dat2,$user){
  try{  
    $data=array('%'.$user.'%',$dat1,$dat2);
    $ownerH=$this->dbcon->prepare("select * from  billrecord where descript like ? and dateB between ? and ?"); 
    //$ownerH->bindParam(":id",$sdate);
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}


function getPatientsCheckUpRecords(){
  try{  
 

    $ownerH=$this->dbcon->prepare("select * from  testrecords");  
     
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getPatientCheckUpByDate($patientID,$tDate){
  try{
    $pStatus="Not yet"; 

    $ownerH=$this->dbcon->prepare("select * from  testrecords where patientID=:Id and pStatus=:tId and tDate =:bId"); 

    //$ownerH->bindParam(":Id",$recordID);
    $ownerH->bindParam(":Id",$patientID);  
    $ownerH->bindParam(":tId",$pStatus);
    $ownerH->bindParam(":bId",$tDate); 
   // $ownerH->bindParam(":tId",$tname);

    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}


function addMedicalTestDisc($patientID,$tname,$st,$rDescrip,$checkingStatus,$pAge,$checkedBy,$postedBy,$tPrice,$pStatus){
  
 
   $regdate=Date("Y-m-d");$time=Date("H:i:sa");
   $data=array($patientID,$tname,$st,$rDescrip,$checkingStatus,$pAge,$regdate,$checkedBy,$postedBy,$tPrice,$pStatus,$time);
try{ 

  $Qr=$this->dbcon->prepare("insert into testrecords (patientID,mTest,status,rDescrip,checkingStatus,pAge,tDate,checkedBy,postedBy,billAmount,  pStatus,timeAt) values(?,?,?,?,?,?,?,?,?,?,?,?)");
  $Qr->execute($data); 

   if($Qr->rowCount()>0)
   {
     return $Qr;  
    }
   else
   {   
   return $Qr; 
   }
    
}
catch(PDOException $ex){
  $ex->getMessage();
}
}


function addMedicalTest($patientID,$tname,$st,$rDescrip,$checkingStatus,$pAge,$checkedBy,$postedBy,$tPrice,$pStatus){
  
 
   $regdate=Date("Y-m-d");$time=Date("h:i:sa");
   $data=array($patientID,$tname,$st,$rDescrip,$checkingStatus,$pAge,$regdate,$checkedBy,$postedBy,$tPrice,$pStatus);
try{ 

  $Qr=$this->dbcon->prepare("insert into testrecords (patientID,mTest,status,rDescrip,checkingStatus,pAge,tDate,checkedBy,postedBy,billAmount,  pStatus) values(?,?,?,?,?,?,?,?,?,?,?)");
  $Qr->execute($data); 

   if($Qr->rowCount()>0)
   {
     return $Qr;  
    }
   else
   {   
   return $Qr; 
   }
    
}
catch(PDOException $ex){
  $ex->getMessage();
}
}

function getBillID(){
  try{
    $ownerH=$this->dbcon->prepare("select * from  billrecord");   
    $ownerH->execute(); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getServExist($patientID,$regDate,$drCat){
  try{
    $day1=$regDate;
   $day2=date('Y-m-d',strtotime($regDate.'-7 days'));
    $data=array($patientID,'%'.$drCat.'%',$day2,$day1);
    $ownerH=$this->dbcon->prepare("select * from  billrecord where  patientID=? and descript like ? and  dateB between ? and ?"); 
    //$ownerH->bindParam(":Id",$patientID);
    //$ownerH->bindParam(":dt",$regDate);   
    $ownerH->execute($data); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
   // $xc->getMessage();
    return $ownerH;
  }

}

function getServID($patientID,$regDate){
  try{
    $ownerH=$this->dbcon->prepare("select * from  billrecord where  patientID=:Id and dateB=:dt"); 
    $ownerH->bindParam(":Id",$patientID);
    $ownerH->bindParam(":dt",$regDate);   
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getThisCodeByRecID($recID){
  try{
    $ownerH=$this->dbcon->prepare("select * from  codedisease where  recID=:Id "); 
    $ownerH->bindParam(":Id",$recID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getThisCodeExist($patientID,$code,$disease,$sID,$sdate){
  try{

    $ownerH=$this->dbcon->prepare("select * from  pdiagnosis where patientID=:pd and sID=:sd and dateAt=:tr and  (pcode=:Id or proviD=:dt) ");
    $ownerH->bindParam(":pd",$patientID); 
    $ownerH->bindParam(":sd",$sID);
    $ownerH->bindParam(":tr",$sdate);
    $ownerH->bindParam(":Id",$code);
    $ownerH->bindParam(":dt",$disease);   
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
     return $ownerH;
  }

}

function getThisfCodeExistS($patientID,$code,$disease,$sID,$sdate){
  try{
    $cs="";
    $ownerH=$this->dbcon->prepare("select * from  pdiagnosis where patientID=:pd and sID=:sd and dateAt=:tr and  (pcode=:Id or proviD=:dt) and  (fcode=:fc or finalD=:fd)");
    $ownerH->bindParam(":pd",$patientID); 
    $ownerH->bindParam(":sd",$sID);
    $ownerH->bindParam(":tr",$sdate);
    $ownerH->bindParam(":Id",$code);
    $ownerH->bindParam(":dt",$disease);
    $ownerH->bindParam(":fc",$cs);
    $ownerH->bindParam(":fd",$fd);   
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
     return $ownerH;
  }

}
function getThisCode($code,$disease){
  try{
    $ownerH=$this->dbcon->prepare("select * from  codedisease where  code=:Id or disease=:dt"); 
    $ownerH->bindParam(":Id",$code);
    $ownerH->bindParam(":dt",$disease);   
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function updateItemD($iname,$icat,$ipprice,$isprice,$itemID,$expd){
  try{
      $data=array($iname,$icat,$ipprice,$isprice,$expd,$itemID);
        $ownerH=$this->dbcon->prepare("update iteminfo set iname=?,icat=?,ipprice=?,isprice=?,expd=?  where itemID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) {
            
       
           return $ownerH;
      } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function DosageDispensed($user,$iQty,$iname,$recID,$patientID){
  try{
      $bill="Billed by: ".$user;
      $data=array($iQty,$bill,$iname,$recID,$patientID);
        $ownerH=$this->dbcon->prepare("update drugdispenses set qty=?,payStatus=?  where drugname=? and recID=? and patientID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) {
            
       
           return $ownerH;
      } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}
function updateDosageQ($iname,$iQty,$recID,$patientID){
  try{
      $data=array($iQty,$iname,$recID,$patientID);
        $ownerH=$this->dbcon->prepare("update drugdispenses set qty=?  where drugname=? and recID=? and patientID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) {
            
       
           return $ownerH;
      } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}
function updateItemQ($iname,$tQty,$itemID){
  try{
      $data=array($tQty,$iname,$itemID);
        $ownerH=$this->dbcon->prepare("update iteminfo set iqty=?  where iname=? and itemID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) {
            
       
           return $ownerH;
      } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function itemReg($iname,$icat,$ipprice,$isprice,$iQty,$expd)
{
$data=array($iname,$icat,$ipprice,$isprice,$iQty,$expd);
try{    
$Qr=$this->dbcon->prepare("insert into iteminfo(iname,icat,ipprice,isprice,iqty,expd) values(?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
}
}

function dosageReg($patientID,$iname,$dosage,$isprice,$iQty,$sdate,$user)
{
//recID patientID drugname  dosage  dprice  qty dateAt  timeAt  drN 
$time=Date("H:i:sa");
$data=array($patientID,$iname,$dosage,$isprice,$iQty,$sdate,$time,$user);
try{    
$Qr=$this->dbcon->prepare("insert into drugdispenses(patientID,drugname,dosage,dprice,qty,dateAt,timeAt,drN) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
}
}

function itemPurchaseEntry($itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$user)
{
  $time=Date("H:i:sa").": By ".$user;
$data=array($itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$time);
try{    
$Qr=$this->dbcon->prepare("insert into purchaserecord(itemID,  iname,ipprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}
function getThisItem($iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from  iteminfo where  iname=:Id"); 
    $ownerH->bindParam(":Id",$iname);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getPatientDosFB($patientID,$sdate){
  try{
    $iQty=0;
    $ps="Not yet";
    $ownerH=$this->dbcon->prepare("select * from  drugdispenses where patientID=:id and dateAt=:dt and qty>:q and payStatus=:p"); 
    $ownerH->bindParam(":id",$patientID); 
    $ownerH->bindParam(":dt",$sdate);
    $ownerH->bindParam(":q",$iQty);
    $ownerH->bindParam(":p",$ps);      
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getPatientDos($patientID,$sdate){
  try{
    $iQty=0;
    $ownerH=$this->dbcon->prepare("select * from  drugdispenses where patientID=:id and dateAt=:dt and qty=:q"); 
    $ownerH->bindParam(":id",$patientID); 
    $ownerH->bindParam(":dt",$sdate);
    $ownerH->bindParam(":q",$iQty);     
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}


function getThisDosage($patientID,$iname,$sdate){
  try{
    $ownerH=$this->dbcon->prepare("select * from  drugdispenses where patientID=:id and  drugname=:nm and dateAt=:dt"); 
    $ownerH->bindParam(":id",$patientID);
    $ownerH->bindParam(":nm",$iname);
    $ownerH->bindParam(":dt",$sdate);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getThisROS($patientID,$ros,$sdate){
  try{
    $ownerH=$this->dbcon->prepare("select * from  ros where patientID=:id and  ros=:nm and dateAt=:dt"); 
    $ownerH->bindParam(":id",$patientID);
    $ownerH->bindParam(":nm",$ros);
    $ownerH->bindParam(":dt",$sdate);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
//
function getItemBySearch($searchValue){
  try{
    $ownerH=$this->dbcon->prepare("select * from  iteminfo where  iname like ?");
  
     $ownerH->execute(array('%'.$searchValue.'%')); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getDrugList(){
  try{
    $ownerH=$this->dbcon->prepare("select * from  iteminfo");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisDosEX($recID,$iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from  drugdispenses where   drugname=:nm and recID=:Id");
    $ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$recID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getThisItemBID($itemID,$iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from  iteminfo where   iname=:nm and itemID=:Id");
    $ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$itemID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getThisPatientD($patientID){
  try{
    $ownerH=$this->dbcon->prepare("select * from  patientdetail where  patientID=:Id"); 
    $ownerH->bindParam(":Id",$patientID);   
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getToolKitBySearch($searchValue){
  try{
    $ownerH=$this->dbcon->prepare("select * from  toolkit where  tName like ?");
  
     $ownerH->execute(array('%'.$searchValue.'%')); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getConsltntOpBySearch($searchValue){
  try{
    $ownerH=$this->dbcon->prepare("select * from  consultantdr where  drCategory like ?");
  
     $ownerH->execute(array('%'.$searchValue.'%')); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getMtestBySearch($searchValue){
  try{
    $ownerH=$this->dbcon->prepare("select * from  mtest where  mName like ?");
  
     $ownerH->execute(array('%'.$searchValue.'%')); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getConsultantBySearch($searchValue){
  try{
    $ownerH=$this->dbcon->prepare("select * from  consultantdr where  drCategory like ?");
  
     $ownerH->execute(array('%'.$searchValue.'%')); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function updateToolKitD($iname,$toolID){
  try{
      $data=array($iname,$toolID);
      $ownerH=$this->dbcon->prepare("update toolkit set tName=? where toolID=?"); 
     
         $ownerH->execute($data); 
        
         return $ownerH;
      
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function updateToolKitQty($tQty,$toolID){
  try{
      $data=array($tQty,$toolID);
      $ownerH=$this->dbcon->prepare("update toolkit set tQty=? where toolID=?"); 
     
         $ownerH->execute($data); 
         return $ownerH;
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}


function updateMtestD($cat,$tname,$tPrice,$testID){
  try{
      $data=array($cat,$tname,$tPrice,$testID);
        $ownerH=$this->dbcon->prepare("update mtest set cat=?, mName=?, tPrice=?  where testID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) {
            
       
           return $ownerH;
      } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getToolKitList(){
  try{
    $ownerH=$this->dbcon->prepare("select * from toolkit");  
      $ownerH->execute(); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisCodeDisease($searchValue){
  try{
    $ownerH=$this->dbcon->prepare("select * from codedisease where code like ? or disease like ?");  
    $ownerH->execute(array('%'.$searchValue.'%','%'.$searchValue.'%')); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getCodeDiseaseList(){
  try{
    $ownerH=$this->dbcon->prepare("select * from codedisease");  
    $ownerH->execute(); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getConsulttList(){
  try{
    $ownerH=$this->dbcon->prepare("select * from consultantdr");  
      $ownerH->execute(); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisConsultant($searchValue){
  try{
    $ownerH=$this->dbcon->prepare("select * from consultantdr where drCategory like ?");  
      $ownerH->execute(array('%'.$searchValue.'%')); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getPatientsRecord(){
  try{
    $ownerH=$this->dbcon->prepare("select * from patientdetail");  
      $ownerH->execute(); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisMT($tname){
  try{
    $ownerH=$this->dbcon->prepare("select * from mtest where mName=:nm");
     $ownerH->bindParam(":nm",$tname);   
      $ownerH->execute(); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getMedicalTestList(){
  try{
    $ownerH=$this->dbcon->prepare("select * from mtest");  
      $ownerH->execute(); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

///ROW  CUONTER
function getRowCount(){
  try{
    $ownerH=$this->dbcon->prepare("select * from patientdetail");  
      $ownerH->execute(); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
///----------------REGISTRATION FORM VALIDATION---------------------
function registerMtest($cat,$tname, $tPrice){
   $regdate=Date("Y-m-d");$time=Date("h:i:sa");
   $data=array($cat,$tname, $tPrice);
   try{   
      $Qr=$this->dbcon->prepare("insert into mtest(cat,mName,tPrice) values(?,?,?)");
      $Qr->execute($data); 
      if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
   

}
catch(PDOException $ex){
  $ex->getMessage();
}
}


///////////////////////////
function registerTk($iname, $iQty){
  

   $regdate=Date("Y-m-d");$time=Date("h:i:sa");

   $data=array($iname, $iQty, $regdate);

   try{  
       
      $Qr=$this->dbcon->prepare("insert into toolkit (tName,tQty,regDate) values(?,?,?)");
      
      $Qr->execute($data); 

      if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
   

}
catch(PDOException $ex){
  $ex->getMessage();
}
}

function updateConsultant($cDr, $nhifP,$cashP,$recID){
  

   $regdate=Date("Y-m-d");$time=Date("h:i:sa");

   $data=array($cDr, $nhifP,$cashP, $recID);

   try{  
       
      $Qr=$this->dbcon->prepare("update consultantdr set drCategory=?, nhifPrice=?,cashPrice=? where recID=?");
        
      $Qr->execute($data); 

      if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
   

}
catch(PDOException $ex){
  $ex->getMessage();
}
}


function pROS($sID,$sdate,$ros,$user,$desC,$patientID){
   $time=Date("H:i:sa");
   $data=array($patientID,$ros,$desC,$user,$sdate,$time,$sID);
   try{  
    $Qr=$this->dbcon->prepare("insert into ros(patientID,ros,descrip,drN,dateAt,timeAt,sID) values(?,?,?,?,?,?,?)");
        
      $Qr->execute($data); 
      if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
}
}



function pComplain($sID,$sdate,$comp,$user, $gExam, $hpi,$patientID){
  
   
  $time=Date("H:i:sa");

   $data=array($patientID,$gExam,$comp,$hpi,$user,$sID,$sdate,$time);

   try{  
       
    $Qr=$this->dbcon->prepare("insert into complainhpi(patientID, gExam, comlain, hpi, drN, sID, dateAt,timeAt  
      ) values(?,?,?,?,?,?,?,?)");
        
      $Qr->execute($data); 

      if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
   

}
catch(PDOException $ex){
  $ex->getMessage();
}
}


function codeUpdate($recID,$code,$disease)
{
$data=array($disease,$code,$recID);
try{    
$Qr=$this->dbcon->prepare("update codedisease set disease=?,code=? where recID=?");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
}
}

function vitalS($patientID,$user,$sdate,$vital,$unit)
{
$data=array($patientID,$user,$sdate,$vital,$unit);
try{    
$Qr=$this->dbcon->prepare("insert into vitalsign(patientID,testBy,dateT,vital,unit) values(?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
}
}

function codeReg($code,$disease)
{
$data=array($disease,$code);
try{    
$Qr=$this->dbcon->prepare("insert into codedisease(disease,code) values(?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
}
}

function addCodeD($patientID,$code,$disease,$user,$sdate,$sID)
{
$time=Date("H:i:sa");
$data=array($patientID,$code,$disease,$user,$sdate,$time,$sID);
try{    
$Qr=$this->dbcon->prepare("insert into pdiagnosis(patientID, pcode, proviD, drN, dateAt,timeAt,sID) values(?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
}
}

function updateCodeD($patientID,$code,$disease,$sdate,$sID)
{
$time=Date("H:i:sa");
$data=array($code,$disease,$patientID,$code,$disease,$sdate,$sID);
try{    
$Qr=$this->dbcon->prepare("update pdiagnosis set fcode=?, finalD=? where patientID=? and pcode=? and proviD=? and dateAt=? and sID=?");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
}
}
function billInvestigation($sCat,$sID,$sdate,$iname,$user, $billOp,$amount,$patientID){
    
  //$regdate=Date("Y-m-d");
  $time=Date("H:i:sa");

   $data=array($sID,$patientID,$sCat,$iname,$billOp,$amount,$user,$sdate,$time);

   try{  
       
      $Qr=$this->dbcon->prepare("insert into billrecord(sID,patientID,sCategory,descript,paymtOp,amount,billBy,dateB,timeB) values(?,?,?,?,?,?,?,?,?)");
        
      $Qr->execute($data); 

      if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
   

}
catch(PDOException $ex){
  $ex->getMessage();
}
}
function billMedical($sID,$sdate,$iname,$user, $billOp,$amount,$patientID){
  
  $sCat="Drug"; 
  //$regdate=Date("Y-m-d");
  $time=Date("H:i:sa");

   $data=array($sID,$patientID,$sCat,$iname,$billOp,$amount,$user,$sdate,$time);

   try{  
       
      $Qr=$this->dbcon->prepare("insert into billrecord(sID,patientID,sCategory,descript,paymtOp,amount,billBy,dateB,timeB) values(?,?,?,?,?,?,?,?,?)");
        
      $Qr->execute($data); 

      if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
   

}
catch(PDOException $ex){
  $ex->getMessage();
}
}
function billConsultantFee($sID,$regDate,$drCat,$user, $drN, $billOp,$amount,$patientID){
  
  $sCat="Consultation";
  $sDescrip="Consultation:By (".$drCat.":".$drN.")";
  //$regdate=Date("Y-m-d");
  $time=Date("H:i:sa");

   $data=array($sID,$patientID,$sCat,$sDescrip,$billOp,$amount,$user,$regDate,$time);

   try{  
       
      $Qr=$this->dbcon->prepare("insert into billrecord(sID,patientID,sCategory,descript,paymtOp,amount,billBy,dateB,timeB) values(?,?,?,?,?,?,?,?,?)");
        
      $Qr->execute($data); 

      if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
   

}
catch(PDOException $ex){
  $ex->getMessage();
}
}
function getThisItemFED($itemID,$iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from  iteminfo where   iname=:nm and itemID!=:Id");
    $ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$itemID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function registerConsultant($cDr, $nhifP,$cashP){
  

   $regdate=Date("Y-m-d");$time=Date("h:i:sa");

   $data=array($cDr, $nhifP,$cashP, $regdate);

   try{  
       
      $Qr=$this->dbcon->prepare("insert into consultantdr (drCategory,nhifPrice,cashPrice,regDate) values(?,?,?,?)");
        
      $Qr->execute($data); 

      if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
   

}
catch(PDOException $ex){
  $ex->getMessage();
}
}
function toolkitDismis($iname, $iQty){
  

   $regdate=Date("Y-m-d");$time=Date("h:i:sa");

   $dt=array($iname, $iQty, $regdate);

   try{  
        //tName iQty   
      $rQ=$this->dbcon->prepare("insert into toolkitused(tName,iQty,dateEntry) values(?,?,?)");
      
      $rQ->execute($dt); 

      if($rQ->rowCount()>0)
       {

        return $rQ;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $rQ->ErrorInfo(); 
      }
   

}
catch(PDOException $ex){
  $ex->getMessage();
}
}

function toolkitEntry($iname, $iQty){
  

   $regdate=Date("Y-m-d");$time=Date("h:i:sa");

   $dt=array($iname, $iQty, $regdate);

   try{  
        //tName iQty   
      $rQ=$this->dbcon->prepare("insert into toolkitentry(tName,iQty,dateEntry) values(?,?,?)");
      
      $rQ->execute($dt); 

      if($rQ->rowCount()>0)
       {

        return $rQ;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $rQ->ErrorInfo(); 
      }
   

}
catch(PDOException $ex){
  $ex->getMessage();
}
}

                                                         // REGISTRATION FUNCTION ENDS
function vtname($tname) {
   
  
    if( $tname!=""){
      return  $tname;
    } 
     else{
      return false;
     }
} 

function etname($tname) {
   if($iname=="")
                 {

           return $iname="Test name required!..";
                 }
   
   else         {
                return;
                }
   

} 

function etPrice($tPrice) {
   if($tPrice=="")
                 {

           return $tPrice="Item quantity required!..";
                 }
   
   else         {
                return;
                }
   

} 

function vtPrice($tPrice) {
   
  
    if( $tPrice!=""){
      return  $tPrice;
    } 
     else{
      return false;
     }
}



function vIname($iname) {
   
  
    if( $iname!=""){
      return  $iname;
    } 
     else{
      return false;
     }
}  
function vcDr($cDr) {
   
  
    if( $cDr!=""){
      return  $cDr;
    } 
     else{
      return false;
     }
} 
function vcashP($cashP) {
   
  
    if( $cashP!=""){
      return  $cashP;
    } 
     else{
      return false;
     }
} 
function vnhifP($nhifP) {
   
  
    if( $nhifP!=""){
      return  $nhifP;
    } 
     else{
      return false;
     }
} 
function vIqty($iQty) {
   
  
    if( $iQty!=""){
      return  $iQty;
    } 
     else{
      return false;
     }
}

function eIname($iname) {
   if($iname=="")
                 {

           return $iname="Item name required!..";
                 }
   
   else         {
                return;
                }
   

}    

function eIqty($iQty) {
   if($iQty=="")
                 {

           return $iQty="Item quantity required!..";
                 }
   
   else         {
                return;
                }
   

} 

                              //VALIDATE FIRST NAME








function vFname($fname) {
   
  
    if(preg_match("/^[A-Za-z]+$/",$fname)  && $fname!=""){
      return  $fname;
    } 
     else{
      return false;
     }
}  


function eFname($fname) {
   if($fname=="")
                 {

    return $mname="First name required!..";
                 }
  
   else if(!preg_match("/^[A-Za-z]+$/",$fname))
                {
     
        return $fname= "Invalid name!";
              }
   else         {
                return;
              }
   

}                           


                                      //MIDDLE NAME VALIDATION

function vMname($mname) {
   
  
    if(preg_match("/^[A-Za-z]+$/",$mname)  && $mname!=""){
      return  $mname;
    } 
     else{
      return false;
     }
}  


function eMname($mname) {
   if($mname=="")
                 {

    return $mname="Middle name required!..";
                 }
  
   else if(!preg_match("/^[A-Za-z]+$/",$mname))
                {
     
        return $mname= "Invalid name!";
              }
   else         {
                return;
              }
   

}     





                                      //LAST NAME VALIDATION

function vLname($lname) {
   
  
    if(preg_match("/^[A-Za-z]+$/",$lname)  && $lname!=""){
      return  $lname;
    } 
     else{
      return false;
     }
}  


function eLname($lname) {
   if($lname=="")
                 {

    return $lname="Last name required!..";
                 }
  
   else if(!preg_match("/^[A-Za-z]+$/",$lname))
                {
     
        return $lname= "Invalid name!";
              }
   else         {
                return;
              }
   

}




                                      //STREET VALIDATION

function vAddress($address) {
   
  
    if(preg_match("/^[\sA-Za-z]+$/",$address)  && $address!=""){
      return  $address;
    } 
     else{
      return false;
     }
}  


function eAddress($address) {
   if($address=="")
                 {

    return $address="Address required!..";
                 }
  
   else if(!preg_match("/^[\sA-Za-z]+$/",$address))
                {
     
        return $addrss= "Invalid address  name!";
              }
   else         {
                return;
              }
   

}




                                      //EMAIL VALIDATION

function vEmail($email) {
   
  
    if(preg_match("/\b[(A-Za-z)][\w.]\w+@\w+\.(net|com|edu)\b/",$email)  && $email!=""){
      return  $email;
    } 
     else{
      return false;
     }
}  


function eEmail($email) {
   if($email=="")
                 {

    return $email="Email required!..";
                 }
  
   else if(!preg_match("/\b[\(A-Za-z)][\w.]\w+@\w+\.(net|com|edu)\b/",$email))
                {
     
        return $email= "Invalid email address!";
              }
   else         {
                return;
              }
   

}               




                            //DATE OF BIRTH VALIDATION

function vDate($dob) {
   
  
    if($dob!=""){
      return  $dob;
    } 
     else{
      return false;
     }
}  



function eDate($dob) {
   if($dob=="")
                 {

    return $dob="Date of birth required!..";
                 }

    
   else         {
                return;
              }
   

}



   //OCCUPATION VALIDATION

function vOccupation($occupation) {
   
  
    if(preg_match("/^[\sA-Za-z]+$/",$occupation)  && $occupation!=""){
      return  $occupation;
    } 
     else{
      return false;
     }
} 

function vCountry($country) {
   
  
    if(preg_match("/^[\sA-Za-z]+$/",$country)  && $country!=""){
      return  $country;
    } 
     else{
      return false;
     }
}  


function eCountry($country) {
   if($country=="")
                 {

    return $region="Country required!..";
                 }
  
   else if(!preg_match("/^[\sA-Za-z]+$/",$country))
                {
     
        return $district= "Invalid country name!";
              }
   else         {
                return;
              }
   

}

   //OCCUPATION VALIDATION

 



function eOccupation($occupation) {
   if($occupation=="")
                 {

    return $occupation="Occupation required!..";
                 }
  
   else if(!preg_match("/^[\sA-Za-z]+$/",$occupation))
                {
     
        return $district= "Invalid occupation name!";
              }
   else         {
                return;
              }
   

}


function vCategory($category) {
   
  
    if(preg_match("/^[\sA-Za-z]+$/",$category)  && $category!=""){
      return  $category;
    } 
     else{
      return false;
     }
} 


function eCategory($category) {
   if($category=="")
                 {

    return $category="category required!..";
                 }
  
   else if(!preg_match("/^[\sA-Za-z]+$/",$category))
                {
     
        return $category= "Invalid category name!";
              }
   else         {
                return;
              }
   

}
//PASSWORD VALIDATION

function vPassword($password) {
   
  
    if(preg_match("/\w{8,25}/",$password)  && $password!=""){
      return  $password;
    } 
     else{
      return false;
     }
}  


function ePassword($password) {
   if($password=="")
                 {

    return $password="password required!..";
                 }

   
   else if(!preg_match("/\w{8,25}/",$password))
                {
     
        return $password= "Strong password with mixed numeric, upper and lower case required!";
              }
   else         {
                return;
              }
   

}

//PASSWORD VALIDATION

function vNpassword($npassword) {
   
  
    if(preg_match("/\w{8,25}/",$npassword)  && $npassword!=""){
      return  $npassword;
    } 
     else{
      return false;
     }
}  


function eNpassword($npassword) {
   if($npassword=="")
                 {

    return $npassword="password required!..";
                 }

   
   else if(!preg_match("/\w{8,25}/",$npassword))
                {
     
        return $npassword= "Strong password with mixed numeric, upper and lower case required!";
              }
   else         {
                return;
              }
   

}


 

function vNcpassword($npassword,$cpassword) {
   
  
    if($npassword== $cpassword){
      return  $npassword;
    } 
     else{
      return false;
     }
}  



function eNcpassword($npassword,$cpassword) {
   if($npassword!=$cpassword )
                 {

    return $npassword="Password mismatch!..";
                 }

    
   else         {
                return;
              }
   

}


                             //PASSWORD CONFIRMATION

function vCPassword($password,$cpassword) {
   
  
    if($password== $cpassword){
      return  $password;
    } 
     else{
      return false;
     }
}  



function eCPassword($password,$cpassword) {
   if($password!=$cpassword )
                 {

    return $password="Password mismatch!..";
                 }

    
   else         {
                return;
              }
   

}


//PHONE NUMBER VALIDATION

function vPatientID($patientID) {
   
  
    if(preg_match("/\d{1,12}/",$patientID)  && $patientID!=""){
      return  $patientID;
    } 
     else{
      return false;
     }
}  


function ePatientID($patientID) {
   if($patientID=="")
                 {

    return $patientID="Phone number required!..";
                 }

   
   else if(!preg_match("/\d{1,12}/",$patientID))
                {
     
        return $patientID= "Invalid patientID number!..";
              }
   else         {
                return;
              }
   

}
//PHONE NUMBER VALIDATION

function vPhoneno($phoneno) {
   
  
    if(preg_match("/\d{10,12}/",$phoneno)  && $phoneno!=""){
      return  $phoneno;
    } 
     else{
      return false;
     }
}  


function ePhoneno($phoneno) {
   if($phoneno=="")
                 {

    return $phoneno="Phone number required!..";
                 }

   
   else if(!preg_match("/\d{10,12}/",$phoneno))
                {
     
        return $phoneno= "Invalid phone number!..";
              }
   else         {
                return;
              }
   

}


                             //GENDER CONFIRMATION

function vGender($gender) {
   
  
    if($gender!=""){
      return  $gender;
    } 
     else{
      return false;
     }
}  



function eGender($gender) {

   if($gender=="")

                 {

    return $gender="Gender required!..";
                 }

    
   else         {
                return;
              }
   

}

/////////////////////////// 
function addEmployee($password,$depart,$email,$fname,$mname,$lname,$gender,$occupation,$phoneno,$country,$address,$dob,$empDate){
  
 try{
   $regdate=Date("Y-m-d");$time=Date("h:i:sa");

   //$data=array($password,$depart,$email,$fname,$mname,$lname,$gender,$occupation,$phoneno,$country,$address,$dob,$empDate);
  
//fname mname lname email phone dob department  citizen address gender  pwd empDate 
  $Q=$this->dbcon->prepare("insert into users(pwd,department,email,fname,mname,lname,gender,occupation,phoneno,citizen,address,dob,dhired)values(?,?,?,?,?,?,?,?,?,?,?,?,?..)");

  $Q->execute(array($password,$depart,$email,$fname,$mname,$lname,$gender,$occupation,$phoneno,$country,$address,$dob,$empDate)); 

   if($Q->rowCount()>0)
   {
     return $Q;  
    }
   else
   {   
   return $Q->ErrorInfo(); 
   }
    
}
catch(PDOException $ex){
  $ex->getMessage();
}
}
                                                            // REGISTRATION FUNCTION ENDS

/*if(isset($_POST['phoneno']) && isset($_POST['dob'])  && isset($_POST['fname']) && isset($_POST['mname']) && isset($_POST['lname']) && isset($_POST['email']) &&isset($_POST['ward']) && isset($_POST['gender']) && isset($_POST['district']) && isset($_POST['street']) && isset($_POST['country']) && isset($_POST['genger']) && isset($_POST['rcity']) && isset($_POST['password']) && isset($_POST['pobox'])){
 
*/

function registerP($patientID,$phoneno,$fname, $mname, $lname, $gender, $occupation,$country, $address , $dob){
  
 
   $regdate=Date("Y-m-d");$time=Date("h:i:sa");
   $data=array($patientID,$fname,$mname,$lname,$gender,$occupation,$phoneno,$country,$address,$dob,$regdate);
try{ 
 

  $Qr=$this->dbcon->prepare("insert into patientdetail(patientID,fname,mname,lname,gender,occupation,phoneno,citizen,address,dob,regdate) values(?,?,?,?,?,?,?,?,?,?,?)");
  $Qr->execute($data); 

   if($Qr->rowCount()>0)
   {
     return $Qr;  
    }
   else
   {   
   return $Qr; 
   }
    
}
catch(PDOException $ex){
  $ex->getMessage();
}
}

}                                                            // REGISTRATION FUNCTION ENDS

////////////////////////////////
        

?>