<div class="container mt-3" style="margin-top:2px;">
  <?php
  require_once"labClass.php";
  $con=new labClass();
  $patientID= $_POST['patientID'];
  $pn= $con->getThisPatientD($patientID);
if($pn->rowCount()>0){
   $n=$pn->fetch();
      ?> 
   <small>PATIENT NAME:<h6 class="text-primary"><?php echo $n['fname']." ". $n['mname']." ".$n['lname'];?></h6></small>
   <sup id="tr"></sup>
  <h6>Medical recommendation:</h6> 
<table class="table" width="80%">
<tr>
<td height="50px">
   <label for="drug" class="form-label">Choose drug from the list:</label>
<input class="form-control" list="drugs" name="drug" id="drug" onchange="processData();">
<datalist id="drugs">
    <?php
     $Q= $con->getDrugList();
     if ($Q->rowCount()>0) {
     $lb=
     $Q->fetchAll();
     foreach ($lb as $key => $l) {
      
      ?>
      <option value="<?php echo  $l["iname"];?>">  
             <?php
            
           }
           }
 
      ?>
      </datalist>
      <sup class="text-danger" id="ro"> </sup>  
</td> 
</tr> 
     <tr>
    <td height="120px">
    <small>Treatment description:</small><br/>  
      <textarea  id="dosage" style="height:120px; width:100%;"  name="dosage" required></textarea>
      <sup class="text-danger" id="co"> </sup>
        
    
</td> 
</tr>
 
 
<tr>
<td align="right">
  <div class="form-floating mb-3 mt-3"> 
  <button type="submit" class="btn btn-primary" id="submit" value="Submit" name="submit"  style="height:60px;" onclick="saveData()">Submit</button>

</td>
</tr>
</table>
<?php 
}
else {
  echo "Invalid patientID!..";
}
?>
</div>
<div id="dispR"></div>
 

 
<script>
function saveData(){ 
var ecc=0; 
var iname =document.getElementById('drug').value; 
$.trim(iname);
var patientID =document.getElementById('pID').value; 
$.trim(patientID);
var dosage =document.getElementById('dosage').value; 
$.trim(dosage);
var user =document.getElementById('user').value; 
$.trim(user);
var sdate =document.getElementById('sdate').value; 
$.trim(sdate);
  //FIRST NAME VALIDATION
  
if(iname==""){ 

         ecc++;
         document.getElementById('tr').innerHTML="Item name is required!..";

             }
else{

document.getElementById('tr').innerHTML="";
    }
  if(dosage==""){ 

         ecc++;
         document.getElementById('co').innerHTML="Dosage required!..";

             }
else{

document.getElementById('co').innerHTML="";
    }
if(patientID==""){ 

         ecc++;
         document.getElementById('tr').innerHTML="Date is required!..";

             }
else{

document.getElementById('tr').innerHTML="";
    }
  if(sdate==""){ 

         ecc++;
         document.getElementById('tr').innerHTML="Date is required!..";

             }
else{

document.getElementById('tr').innerHTML="";
    }
    if(user==""){ 

         ecc++;
         document.getElementById('tr').innerHTML="User name is required!..";

             }
else{

document.getElementById('tr').innerHTML="";
    }
    if(ecc==0)
    { 
    $.post("pharmTreatPro.php",
    {iname:iname,user:user,sdate:sdate,dosage:dosage,patientID:patientID},
          function(data){
      $('#tr').html(data).show();
      document.getElementById('drug').value=null;
      document.getElementById('dosage').value=null;  
 
    });
    }
 
} 
 
function processData(){ 
var ecc=0; 
var iname =document.getElementById('drug').value; 
$.trim(iname);
  //FIRST NAME VALIDATION
  
if(iname==""){ 

         ecc++;
         document.getElementById('tr').innerHTML="Item name is required!..";

             }
else{

document.getElementById('tr').innerHTML="";
    }
  
    if(ecc==0)
    { 
        $.post("pharmRetrieveQ.php",
          {iname:iname},
          function(data){
      $('#tr').html(data).show();

    });
    }
 
} 
 
 
</script>
 

   
