<?php 
session_start();
include_once '../config.php';
$user_id = $_SESSION['Admin']['id'];
$CurrDate = date('dmY');
if($_REQUEST['action'] == 'Save'){
$MrdNo = addslashes(trim($_REQUEST['MrdNo']));
$PatientId = addslashes(trim($_REQUEST['PatientId']));
// if($_REQUEST['VisitDate'] == ''){
//    $VisitDate =  addslashes(trim($_REQUEST['VisitDate2']));
// }
// else{
//   $VisitDate = addslashes(trim($_REQUEST['VisitDate']));  
// }
$VisitDate =  addslashes(trim($_REQUEST['VisitDate2']));
$VisitTime = addslashes(trim($_REQUEST['VisitTime']));  
//echo  $VisitDate;exit();
$Fname = addslashes(trim($_REQUEST['Fname']));
$Mname = addslashes(trim($_REQUEST['Mname']));
$Lname = addslashes(trim($_REQUEST['Lname']));
$Age = addslashes(trim($_REQUEST['Age']));
$Gender = addslashes(trim($_REQUEST['Gender']));
$Phone = addslashes(trim($_REQUEST['Phone']));
$EmailId = addslashes(trim($_REQUEST['EmailId']));
$Address = addslashes(trim($_REQUEST['Address']));
$City = addslashes(trim($_REQUEST['City']));
$RelativeComes = addslashes(trim($_REQUEST['RelativeComes']));
$RelativeName = addslashes(trim($_REQUEST['RelativeName']));
$Relationship = addslashes(trim($_REQUEST['Relationship']));
$PatientWilling = addslashes(trim($_REQUEST['PatientWilling']));
$Prognosis = addslashes(trim($_REQUEST['Prognosis']));
$DSH = addslashes(trim($_REQUEST['DSH']));
$Admission = addslashes(trim($_REQUEST['Admission']));
$FollowUp = addslashes(trim($_REQUEST['FollowUp']));
$Irregular = addslashes(trim($_REQUEST['Irregular']));
$Medication = addslashes(trim($_REQUEST['Medication']));
$Notes = addslashes(trim($_REQUEST['Notes']));
$Notorious = addslashes(trim($_REQUEST['Notorious']));
$NotoriousChk = addslashes(trim($_REQUEST['NotoriousChk']));
$FollowUpDate = addslashes(trim($_REQUEST['FollowUpDate']));
$Remark = addslashes(trim($_REQUEST['Remark']));
$SpecialNote = addslashes(trim($_REQUEST['SpecialNote']));
$RefBy = addslashes(trim($_REQUEST['RefBy']));
$MarritalStatus = addslashes(trim($_REQUEST['MarritalStatus']));
$StrictSupervision = addslashes(trim($_REQUEST['StrictSupervision']));
$Diagnosis = addslashes(trim($_REQUEST['Diagnosis']));
$CreatedDate = date('Y-m-d');
$CreatedTime = date('h:i a');
$PatientName = addslashes(trim($_REQUEST['PatientName']));
$NewPhone = addslashes(trim($_REQUEST['NewPhone']));
$NewName = addslashes(trim($_REQUEST['NewName']));
$number = count($_POST["TreatName1"]);

//$VisitNo = addslashes(trim($_POST['VisitNo']));
$Duration = $_POST['Duration'];
$Comorbities = addslashes(trim($_POST['Comorbities']));
$DM = addslashes(trim($_POST['DM']));
$HT = addslashes(trim($_POST['HT']));
$IHD = addslashes(trim($_POST['IHD']));
$PILES = addslashes(trim($_POST['PILES']));
$Thyroid = addslashes(trim($_POST['Thyroid']));
$Telugu = addslashes(trim($_POST['Telugu']));
$ChkBlood = addslashes(trim($_POST['ChkBlood']));
$TxtBlood = addslashes(trim($_POST['TxtBlood']));
$ChkCT = addslashes(trim($_POST['ChkCT']));
$TxtCT = addslashes(trim($_POST['TxtCT']));
$ChkMRI = addslashes(trim($_POST['ChkMRI']));
$TxtMRI = addslashes(trim($_POST['TxtMRI']));
$ChkUSG = addslashes(trim($_POST['ChkUSG']));
$TxtUSG = addslashes(trim($_POST['TxtUSG']));
$ChkOthers = addslashes(trim($_POST['ChkOthers']));
$TxtOthers = addslashes(trim($_POST['TxtOthers']));
 $ptnotes = addslashes(trim($_REQUEST['ptnotes']));
 $Other = addslashes(trim($_REQUEST['Other']));
 $PrevTreatment = addslashes(trim($_REQUEST['PrevTreatment']));
 $Eeg = addslashes(trim($_REQUEST['Eeg']));
 $TxtEeg = addslashes(trim($_REQUEST['TxtEeg']));
 $OtherTxt = addslashes(trim($_REQUEST['OtherTxt']));
 $Language = addslashes(trim($_REQUEST['Language']));
 $ChkPrevTreat = addslashes(trim($_REQUEST['ChkPrevTreat']));
 $ChkDiagnosis = addslashes(trim($_REQUEST['ChkDiagnosis']));
 $ChkAdvice = addslashes(trim($_REQUEST['ChkAdvice']));
 $ChkSpecialNote = addslashes(trim($_REQUEST['ChkSpecialNote']));
 $NameUnder = $_REQUEST['NameUnder'];
    $ptnotesdate = date('Y-m-d');
$Consultant = 1;
$Status = 1;
$ModifiedBy = 1;
$ModifiedDate = null;
$sql2 = "SELECT * FROM tbl_patients WHERE MrdNo='$MrdNo'";
$rncnt2 = getRow($sql2);
if($rncnt2 > 0){
     $sql = "UPDATE tbl_patients SET ptnotes='$ptnotes',ptnotesdate='$ptnotesdate',Age='$Age',Phone='$Phone',EmailId='$EmailId' WHERE MrdNo='$MrdNo'";
    $conn->query($sql);
if($NewName != ''){
    $sql = "UPDATE tbl_patients SET PatientName='$NewName' WHERE MrdNo='$MrdNo'";
    $conn->query($sql);
    $sql2 = "INSERT INTO tbl_patient_new_records SET MrdNo='$MrdNo',OldName='$PatientName',Name='$NewName',CreatedDate='$CreatedDate',CreatedTime='$CreatedTime'";
    $conn->query($sql2);
}
if($NewPhone != ''){
    $sql = "UPDATE tbl_patients SET Phone='$NewPhone' WHERE MrdNo='$MrdNo'";
    $conn->query($sql);
    $sql2 = "INSERT INTO tbl_patient_new_records SET MrdNo='$MrdNo',OldPhone='$Phone',Phone='$NewPhone',CreatedDate='$CreatedDate',CreatedTime='$CreatedTime'";
    $conn->query($sql2);
}
}
    else{
        try{
        $sql = "INSERT INTO tbl_patients (ptnotes,ptnotesdate,MarritalStatus,srno,MrdNo,PatientName,Suffix,Fname,Mname,Lname,Gender,Dob,Age,Phone,Phone2,EmailId,City,State,Address,Consultant,ConsultantName,Fees,PayMode,RefBy,Status,CreatedBy,CreatedDate,ModifiedBy,ModifiedDate) 
        VALUES (:ptnotes,:ptnotesdate,:MarritalStatus,:srno,:MrdNo,:PatientName,:Suffix,:Fname,:Mname,:Lname,:Gender,:Dob,:Age,:Phone,:Phone2,:EmailId,:City,:State,:Address,:Consultant,:ConsultantName,:Fees,:PayMode,:RefBy,:Status,:CreatedBy,:CreatedDate,:ModifiedBy,:ModifiedDate)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':ptnotes', $ptnotes);
$stmt->bindParam(':ptnotesdate', $ptnotesdate);
$stmt->bindParam(':MarritalStatus', $MarritalStatus);
$stmt->bindParam(':srno', $MrdNo);
$stmt->bindParam(':MrdNo', $MrdNo);
$stmt->bindParam(':PatientName', $PatientName);
$stmt->bindParam(':Suffix', $Suffix);
$stmt->bindParam(':Fname', $Fname);
$stmt->bindParam(':Mname', $Mname);
$stmt->bindParam(':Lname', $Lname);
$stmt->bindParam(':Gender', $Gender);
$stmt->bindParam(':Dob', $Dob);
$stmt->bindParam(':Age', $Age);
$stmt->bindParam(':Phone', $Phone);
$stmt->bindParam(':Phone2', $Phone2);
$stmt->bindParam(':EmailId', $EmailId);
$stmt->bindParam(':City', $City);
$stmt->bindParam(':State', $State);
$stmt->bindParam(':Address', $Address);
$stmt->bindParam(':Consultant', $Consultant);
$stmt->bindParam(':ConsultantName', $ConsultantName);
$stmt->bindParam(':Fees', $Fees);
$stmt->bindParam(':PayMode', $PayMode);
$stmt->bindParam(':RefBy', $RefBy);
$stmt->bindParam(':Status', $Status);
$stmt->bindParam(':CreatedBy', $user_id);
$stmt->bindParam(':CreatedDate', $CreatedDate);
$stmt->bindParam(':ModifiedBy', $ModifiedBy);
$stmt->bindParam(':ModifiedDate', $ModifiedDate);
if ($stmt->execute()) {}
}
catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}
}


$sql6 ="SELECT * FROM tbl_visits WHERE MrdNo='$MrdNo'AND VisitDate='$VisitDate'";
$rncnt4 = getRow($sql6);
if($rncnt4 > 0){}
else{    
    try{
        $sql4 = "SELECT MAX(VisitNo) As VisitNo FROM tbl_visits WHERE MrdNo='$MrdNo'";
$row4 = getRecord($sql4);
$VisitNo = $row4['VisitNo']+1;
    $sql = "INSERT INTO tbl_visits (MrdNo,PatientName,VisitDate,VisitNo) VALUES (:MrdNo,:PatientName,:VisitDate,:VisitNo)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':MrdNo', $MrdNo);
$stmt->bindParam(':PatientName', $PatientName);
$stmt->bindParam(':VisitDate', $VisitDate);
$stmt->bindParam(':VisitNo', $VisitNo);
if ($stmt->execute()) {

}}
catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}
}


$sql3 = "SELECT * FROM tbl_consultant WHERE MrdNo='$MrdNo' AND VisitDate='$VisitDate'";
$rncnt3 = getRow($sql3);
$row3 = getRecord($sql3);
if($rncnt3 > 0){
    $sql = "UPDATE tbl_consultant SET NameUnder='$NameUnder',Diagnosis='$Diagnosis',StrictSupervision='$StrictSupervision',Duration='$Duration',MarritalStatus='$MarritalStatus',RefBy='$RefBy',Fname='$Fname',Mname='$Mname',Lname='$Lname',PatientName='$PatientName',Age='$Age',Gender='$Gender',Phone='$Phone',EmailId='$EmailId',Address='$Address',City='$City',RelativeComes='$RelativeComes',RelativeName='$RelativeName',Relationship='$Relationship',PatientWilling='$PatientWilling',Prognosis='$Prognosis',DSH='$DSH',Admission='$Admission',FollowUp='$FollowUp',Irregular='$Irregular',Medication='$Medication',Notes='$Notes',NotoriousChk='$NotoriousChk',Notorious='$Notorious',FollowUpDate='$FollowUpDate',Remark='$Remark',SpecialNote='$SpecialNote',Status='1',Comorbities='$Comorbities',DM='$DM',HT='$HT',IHD='$IHD'
    ,PILES='$PILES',Thyroid='$Thyroid',Telugu='$Telugu',ChkBlood='$ChkBlood'
    ,TxtBlood='$TxtBlood',ChkCT='$ChkCT',TxtCT='$TxtCT',ChkMRI='$ChkMRI'
    ,TxtMRI='$TxtMRI',ChkUSG='$ChkUSG',TxtUSG='$TxtUSG',ChkOthers='$ChkOthers'
,TxtOthers='$TxtOthers',Other='$Other',PrevTreatment='$PrevTreatment',Eeg='$Eeg',TxtEeg='$TxtEeg',OtherTxt='$OtherTxt',Language='$Language',ChkPrevTreat='$ChkPrevTreat',ChkDiagnosis='$ChkDiagnosis',ChkAdvice='$ChkAdvice',ChkSpecialNote='$ChkSpecialNote'

    WHERE MrdNo='$MrdNo' AND VisitDate='$VisitDate'";
    $conn->query($sql);
    $PostId = $row3['id'];
    try {
  $sql2 = "DELETE FROM tbl_consultant_treatments WHERE VisitDate='$VisitDate' AND MrdNo='$MrdNo'";
  $conn->query($sql2);
  if($number > 0)  
            {  
                for($i=0; $i<$number; $i++)  
                {  
                     if(trim($_POST["TreatName1"][$i] != ''))  
                     {
                        $TreatType1 = addslashes($_POST['TreatType1'][$i]);
                        $TreatName1 = addslashes($_POST['TreatName1'][$i]);
                        $TreatDose1 = addslashes($_POST['TreatDose1'][$i]);
                        $TreatFreq1 = addslashes($_POST['TreatFreq1'][$i]);
                        $TreatDur1 = addslashes($_POST['TreatDur1'][$i]);
                        $TreatEye1 = addslashes($_POST['TreatEye1'][$i]);
                        $sql33 = "INSERT INTO tbl_consultant_treatments (PostId,MrdNo,VisitDate,TreatType1,TreatName1,TreatDose1,TreatFreq1,TreatDur1,TreatEye1) VALUES (:PostId,:MrdNo,:VisitDate,:TreatType1,:TreatName1,:TreatDose1,:TreatFreq1,:TreatDur1,:TreatEye1)";
$stmt = $conn->prepare($sql33);
$stmt->bindParam(':PostId', $PostId);
$stmt->bindParam(':MrdNo', $MrdNo);
$stmt->bindParam(':VisitDate', $VisitDate);
$stmt->bindParam(':TreatType1', $TreatType1);
$stmt->bindParam(':TreatName1', $TreatName1);
$stmt->bindParam(':TreatDose1', $TreatDose1);
$stmt->bindParam(':TreatFreq1', $TreatFreq1);
$stmt->bindParam(':TreatDur1', $TreatDur1);
$stmt->bindParam(':TreatEye1', $TreatEye1);
if ($stmt->execute()) {?>
 <script>
    window.location.href="../patientdetailform.php?mrd=<?php echo $MrdNo;?>&visitdate=<?php echo $VisitDate;?>";
    //  setTimeout(function() {
    //     window.open(
    //         '../opd-print.php?mrd=<?php echo $MrdNo;?>&visitdate=<?php echo $VisitDate;?>', 'opdqueue',
    //         'toolbar=1, scrollbars=1, location=1,statusbar=0, menubar=1, resizable=1, width=1500, height=1000'
    //     );
    // }, 1);
</script>
<?php
}
} 
else{?>
 <script>
    window.location.href="../patientdetailform.php?mrd=<?php echo $MrdNo;?>&visitdate=<?php echo $VisitDate;?>";
</script>
<?php

}

}
                     }
                }//try

catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}
}
else{
 try{
    $sql = "INSERT INTO tbl_consultant (Diagnosis,StrictSupervision,Duration,MarritalStatus,RefBy,MrdNo,PatientId,VisitDate,VisitTime,Fname,Mname,Lname,PatientName,Age,Gender,Phone,EmailId,Address,City,RelativeComes,RelativeName,Relationship,PatientWilling,Prognosis,DSH,Admission,FollowUp,Irregular,Medication,Notes,NotoriousChk,Notorious,FollowUpDate,Remark,SpecialNote,CreatedDate,CreatedTime,Status) 
    VALUES (:Diagnosis,:StrictSupervision,:Duration,:MarritalStatus,:RefBy,:MrdNo,:PatientId,:VisitDate,:VisitTime,:Fname,:Mname,:Lname,:PatientName,:Age,:Gender,:Phone,:EmailId,:Address,:City,:RelativeComes,:RelativeName,:Relationship,:PatientWilling,:Prognosis,:DSH,:Admission,:FollowUp,:Irregular,:Medication,:Notes,:NotoriousChk,:Notorious,:FollowUpDate,:Remark,:SpecialNote,:CreatedDate,:CreatedTime,:Status)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':Diagnosis', $Diagnosis);
$stmt->bindParam(':StrictSupervision', $StrictSupervision);
$stmt->bindParam(':Duration', $Duration);
$stmt->bindParam(':MarritalStatus', $MarritalStatus);
$stmt->bindParam(':RefBy', $RefBy);
$stmt->bindParam(':MrdNo', $MrdNo);
$stmt->bindParam(':PatientId', $PatientId);
$stmt->bindParam(':VisitDate', $VisitDate);
$stmt->bindParam(':VisitTime', $VisitTime);
$stmt->bindParam(':Fname', $Fname);
$stmt->bindParam(':Gender', $Gender);
$stmt->bindParam(':Age', $Age);
$stmt->bindParam(':Mname', $Mname);
$stmt->bindParam(':Lname', $Lname);
$stmt->bindParam(':PatientName', $PatientName);
$stmt->bindParam(':Phone', $Phone);
$stmt->bindParam(':EmailId', $EmailId);
$stmt->bindParam(':Address', $Address);
$stmt->bindParam(':City', $City);
$stmt->bindParam(':RelativeComes', $RelativeComes);
$stmt->bindParam(':RelativeName', $RelativeName);
$stmt->bindParam(':Relationship', $Relationship);
$stmt->bindParam(':PatientWilling', $PatientWilling);
$stmt->bindParam(':Prognosis', $Prognosis);
$stmt->bindParam(':DSH', $DSH);
$stmt->bindParam(':Admission', $Admission);
$stmt->bindParam(':FollowUp', $FollowUp);
$stmt->bindParam(':Irregular', $Irregular);
$stmt->bindParam(':Medication', $Medication);
$stmt->bindParam(':Notes', $Notes);
$stmt->bindParam(':NotoriousChk', $NotoriousChk);
$stmt->bindParam(':Notorious', $Notorious);
$stmt->bindParam(':FollowUpDate', $FollowUpDate);
$stmt->bindParam(':Remark', $Remark);
$stmt->bindParam(':SpecialNote', $SpecialNote);
$stmt->bindParam(':CreatedDate', $CreatedDate);
$stmt->bindParam(':CreatedTime', $CreatedTime);
$stmt->bindParam(':Status', $Status);
if ($stmt->execute()) {
$PostId = $conn->lastInsertId();

  $sql = "UPDATE tbl_consultant SET Comorbities='$Comorbities',DM='$DM',HT='$HT',IHD='$IHD'
    ,PILES='$PILES',Thyroid='$Thyroid',Telugu='$Telugu',ChkBlood='$ChkBlood'
    ,TxtBlood='$TxtBlood',ChkCT='$ChkCT',TxtCT='$TxtCT',ChkMRI='$ChkMRI'
    ,TxtMRI='$TxtMRI',ChkUSG='$ChkUSG',TxtUSG='$TxtUSG',ChkOthers='$ChkOthers'
,TxtOthers='$TxtOthers',Other='$Other',PrevTreatment='$PrevTreatment',Eeg='$Eeg',TxtEeg='$TxtEeg',OtherTxt='$OtherTxt',Language='$Language',ChkPrevTreat='$ChkPrevTreat',ChkDiagnosis='$ChkDiagnosis',ChkAdvice='$ChkAdvice',ChkSpecialNote='$ChkSpecialNote',NameUnder='$NameUnder' WHERE id='$PostId'";
    $conn->query($sql);
        
    try {
  $sql2 = "DELETE FROM tbl_consultant_treatments WHERE VisitDate='$VisitDate' AND MrdNo='$MrdNo'";
  $conn->query($sql2);
  if($number > 0)  
            {  
                for($i=0; $i<$number; $i++)  
                {  
                     if(trim($_POST["TreatName1"][$i] != ''))  
                     {
                        $TreatType1 = addslashes($_POST['TreatType1'][$i]);
                        $TreatName1 = addslashes($_POST['TreatName1'][$i]);
                        $TreatDose1 = addslashes($_POST['TreatDose1'][$i]);
                        $TreatFreq1 = addslashes($_POST['TreatFreq1'][$i]);
                        $TreatDur1 = addslashes($_POST['TreatDur1'][$i]);
                        $TreatEye1 = addslashes($_POST['TreatEye1'][$i]);
                        $sql33 = "INSERT INTO tbl_consultant_treatments (PostId,MrdNo,VisitDate,TreatType1,TreatName1,TreatDose1,TreatFreq1,TreatDur1,TreatEye1,Status) VALUES (:PostId,:MrdNo,:VisitDate,:TreatType1,:TreatName1,:TreatDose1,:TreatFreq1,:TreatDur1,:TreatEye1,:Status)";
$stmt = $conn->prepare($sql33);
$stmt->bindParam(':PostId', $PostId);
$stmt->bindParam(':MrdNo', $MrdNo);
$stmt->bindParam(':VisitDate', $VisitDate);
$stmt->bindParam(':TreatType1', $TreatType1);
$stmt->bindParam(':TreatName1', $TreatName1);
$stmt->bindParam(':TreatDose1', $TreatDose1);
$stmt->bindParam(':TreatFreq1', $TreatFreq1);
$stmt->bindParam(':TreatDur1', $TreatDur1);
$stmt->bindParam(':TreatEye1', $TreatEye1);
$stmt->bindParam(':Status', $Status);
if ($stmt->execute()) {?>
    <script>
    window.location.href="../patientdetailform.php?mrd=<?php echo $MrdNo;?>&visitdate=<?php echo $VisitDate;?>";
    //  setTimeout(function() {
    //     window.open(
    //         '../opd-print.php?mrd=<?php echo $MrdNo;?>&visitdate=<?php echo $VisitDate;?>', 'opdqueue',
    //         'toolbar=1, scrollbars=1, location=1,statusbar=0, menubar=1, resizable=1, width=1500, height=1000'
    //     );
    // }, 1);
</script>
   <?php 
}
else{?>
 <script>
    window.location.href="../patientdetailform.php?mrd=<?php echo $MrdNo;?>&visitdate=<?php echo $VisitDate;?>";
</script>
<?php

}
} 
else{?>
 <script>
    window.location.href="../patientdetailform.php?mrd=<?php echo $MrdNo;?>&visitdate=<?php echo $VisitDate;?>";
</script>
<?php

}

}
                     }
                }//try

catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}

 }
}
catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}
}
}

if($_REQUEST['action'] == 'findFollowDate'){
    $Duration = $_REQUEST['Duration'];
    $CurrDate = date('Y-m-d');
    $date=date_create($CurrDate);
date_add($date,date_interval_create_from_date_string("$Duration days"));
$followdt =  date_format($date,"Y-m-d");
$dayname = date('D', strtotime($followdt));
if($dayname == 'Sun'){
    echo json_encode(array('Status'=>0,'FollowDate'=>$followdt));
}
else{
    echo json_encode(array('Status'=>1,'FollowDate'=>$followdt));
}
}

if($_REQUEST['action'] == 'getUpRecordList'){
    $MrdNo = $_REQUEST['MrdNo'];
  $sql63 = "SELECT * FROM tbl_patient_new_records WHERE MrdNo='$MrdNo'";
  $rncnt = getRow($sql63);
  if($rncnt > 0){
    ?>
  <tr>
    <th>Name</th>
    <th>Contact</th>
    <th>Date</th>
  </tr>
  <?php
  $row63 = getList($sql63);
  foreach($row63 as $result){
  ?>
  <tr>
    <td><?php echo $result['Name'];?></td>
    <td><?php echo $result['Phone'];?></td>
    <td><?php echo date("d/m/Y", strtotime(str_replace('-', '/',$result['CreatedDate'])));?></td>
  </tr>
<?php } } else { ?>
    <h4 style="color:red;">No Record Found!</h4>
<?php } }

if($_REQUEST['action'] == 'deleteRecord'){
    $MrdNo = $_REQUEST['MrdNo'];
    $VisitDate = $_REQUEST['VisitDate'];
    $sql = "INSERT INTO tbl_consultant_delete SELECT * FROM tbl_consultant WHERE MrdNo='$MrdNo' AND VisitDate='$VisitDate'";
    $conn->query($sql);

    $sql2 = "INSERT INTO tbl_consultant_treatments_delete SELECT * FROM tbl_consultant_treatments WHERE MrdNo='$MrdNo' AND VisitDate='$VisitDate'";
    $conn->query($sql2);
    
    $sql3 = "DELETE FROM tbl_consultant WHERE MrdNo='$MrdNo' AND VisitDate='$VisitDate'";
    $conn->query($sql3);

    $sql4 = "DELETE FROM tbl_consultant_treatments WHERE MrdNo='$MrdNo' AND VisitDate='$VisitDate'";
    $conn->query($sql4);

    $sql5 = "DELETE FROM tbl_visits WHERE MrdNo='$MrdNo' AND VisitDate='$VisitDate'";
    $conn->query($sql5);
    // $sql = "UPDATE tbl_consultant SET DeleteFlag=1 WHERE MrdNo='$MrdNo' AND VisitDate='$VisitDate'";
    // $conn->query($sql);
    // $sql = "UPDATE tbl_consultant_treatments SET DeleteFlag=1 WHERE MrdNo='$MrdNo' AND VisitDate='$VisitDate'";
    // $conn->query($sql);
    // $sql = "UPDATE tbl_visits SET DeleteFlag=1 WHERE MrdNo='$MrdNo' AND VisitDate='$VisitDate'";
    // $conn->query($sql);
    }
?>