<?php 
   session_start();
   require_once 'config.php';
   require_once 'auth.php';
   $MainPage="OPD";
   $Page = "Queue-Management";
   ?>
<!DOCTYPE html>
<html lang="en" class="default-style">
   <head>
      <title><?php echo $Proj_Title; ?></title>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge" />
      <meta name="viewport"
         content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
      <meta name="description" content="" />
      <meta name="keywords" content="">
      <meta name="author" content="Codedthemes" />
      <?php include_once 'header_script.php'; ?>
   </head>
   <body>
      <div class="layout-wrapper layout-1 layout-without-sidenav">
         <div class="layout-inner">
            <?php //include 'sidenavi.php'; ?>
            <div class="layout-container">
               <!-- [ Layout content ] Start -->
               <div class="container-fluid flex-grow-1">
                  <!-- <h4 class="font-weight-bold py-3 mb-0">Optometrist Form
                     <span><button type="button" class="btn btn-success" data-toggle="modal" data-target="#modal-report22"  id="add_button">OPD Summary</button></span>
                     
                     
                     </h4>
                     -->
                  <div class="modal fade" id="modal-report22" tabindex="-1" role="dialog"
                     aria-labelledby="myExtraLargeModalLabel" aria-hidden="true">
                     <div class="modal-dialog" style="max-width: 57%; ">
                        <div class="modal-content">
                           <div class="modal-header">
                              <h5 class="modal-title">OPD Summary</h5>
                              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                              <span aria-hidden="true">&times;</span>
                              </button>
                           </div>
                           <div class="modal-body">
                              <?php //include 'opd-patient-summary.php';?>
                           </div>
                        </div>
                     </div>
                  </div>
                  <style type="text/css">
                     .col-1,.col-2,.col-3,.col-4,.col-5,.col-6,.col-7,.col-8,.col-9,.col-10,.col-11, .col-12,.col, .col-auto, .col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12, .col-sm, .col-sm-auto, .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12, .col-md, .col-md-auto, .col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12, .col-lg, .col-lg-auto, .col-xl-1, .col-xl-2, .col-xl-3, .col-xl-4, .col-xl-5, .col-xl-6, .col-xl-7, .col-xl-8, .col-xl-9, .col-xl-10, .col-xl-11, .col-xl-12, .col-xl, .col-xl-auto {
                     position: relative;
                     width: 100%;
                     padding-right: 7px;
                     padding-left: 7px;
                     }
                     #myBtn {
                     display: none;
                     position: fixed;
                     bottom: 20px;
                     right: 30px;
                     z-index: 99;
                     font-size: 18px;
                     border: none;
                     outline: none;
                     background-color: red;
                     color: white;
                     cursor: pointer;
                     padding: 15px;
                     border-radius: 4px;
                     }
                     #myBtn:hover {
                     background-color: #555;
                     }
                  </style>
                  <?php 
                    
                     
                     if($_REQUEST['visitdate']){
                     $VisitDate = $_REQUEST['visitdate'];
                     }
                     else{
                     $VisitDate = date('Y-m-d');    
                     }
                     
                     if($_REQUEST['mrd'] == ''){
                     $sql = "SELECT MAX(MrdNo) As MrdNo FROM tbl_patients";
                     $row = getRecord($sql);
                     if($row['MrdNo'] == ''){
                         $MrdNo = 1;
                     }
                     else if($_GET['val'] == 'new'){
                        $MrdNo = $row['MrdNo']+1;
                     }
                     else{
                         $MrdNo = $row['MrdNo']+1;
                     }
                     }
                     else{
                         $MrdNo = $_REQUEST['mrd'];
                     }
                     
                     if($_REQUEST['visitdate'] == ''){
                     $sql4 = "SELECT MAX(VisitNo) As VisitNo FROM tbl_visits WHERE MrdNo='$MrdNo'";
                     $row4 = getRecord($sql4);
                     $VisitNo = $row4['VisitNo']+1;
                     }
                     else{
                      $sql4 = "SELECT * FROM tbl_visits WHERE MrdNo='$MrdNo' AND VisitDate='".$_REQUEST['visitdate']."'";
                      $rnct4 = getRow($sql4);
                     $row4 = getRecord($sql4);
                     if($rnct4 > 0){
                     $VisitNo = $row4['VisitNo'];   
                     }
                     else{
                         $sql4 = "SELECT MAX(VisitNo) As VisitNo FROM tbl_visits WHERE MrdNo='$MrdNo'";
                     $row4 = getRecord($sql4);
                       $VisitNo = $row4['VisitNo']+1;  
                     }
                     }
                     
                     
                     /*$sql6 ="SELECT * FROM tbl_visits WHERE MrdNo='$MrdNo'AND VisitDate='$VisitDate'";
                     $rncnt4 = getRow($sql6);
                     if($rncnt4 > 0){}
                     else{    
                         try{
                         $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();
                     }
                     }*/
                     
                     $sql2 = "SELECT * FROM tbl_visits WHERE MrdNo='$MrdNo'";
                     $rncnt2 = getRow($sql2);
                     
                     $sql7 = "SELECT * FROM tbl_consultant WHERE MrdNo='$MrdNo' AND VisitDate='$VisitDate'";
                     $row7 = getRecord($sql7);
                     $rncnt7 = getRow($sql7);
                     
                     if($rncnt7 > 0){
                          $VisitTime =   $row7['VisitTime'];
                       $RefBy = $row7['RefBy'];
                       $Patient_Name = $row7['PatientName'];
                     $Gender = $row7['Gender'];
                     $Age = $row7['Age'];
                     $EmailId = $row7['EmailId'];
                     $Phone = $row7['Phone'];
                     $MarritalStatus = $row7['MarritalStatus'];
                     $Address = $row7['Address'];
                     $Duration = $row7['Duration'];
                     }
                     else{
                      $VisitTime = date('h:i');
                     
                      $sql66 = "SELECT RefBy FROM tbl_consultant WHERE id=(SELECT MAX(id) FROM `tbl_consultant` WHERE RefBy!='')";
                      $row66 = getRecord($sql66);
                         $RefBy = $row66['RefBy'];
                     $sql8 = "SELECT * FROM tbl_patients WHERE MrdNo='$MrdNo'";
                     $row8 = getRecord($sql8);
                     $Patient_Name = $row8['PatientName'];
                     $Gender = $row8['Gender'];
                     $Age = $row8['Age'];
                     $EmailId = $row8['EmailId'];
                     $Phone = $row8['Phone'];
                     $MarritalStatus = $row8['MarritalStatus'];
                     $Address = $row8['Address'];
                     $Duration = 0;
                     }
                     
                     $sql8 = "SELECT ptnotes FROM tbl_patients WHERE MrdNo='$MrdNo'";
                     $row8 = getRecord($sql8);
                     
                      ?>
                  <style type="text/css">
                     .form-control {
                     min-height: 1px;
                     height: 25px;
                     font-size: 17px;
                     }
                  </style>
                  <button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
                  <form method="post" action="ajax_files/ajax_opto_form.php" autocomplete="off">
                     <input type="hidden" id="CurrDate" value="<?php echo date('Y-m-d');?>">
                     <input type="hidden" name="action" id="action" value="Save">
                     <input type="hidden" name="id" id="id" value="">
                     <?php
                        if(file_exists('json_files/json-file.json')){ 
                         $json = file_get_contents('json_files/json-file.json');
                         //Decode JSON
                         $json_data = json_decode($json,true);
                         $results = array();
                         }
                         ?>
                     <style type="text/css">
                        .table th,
                        .table td {
                        padding: 0.325rem;
                        font-size: 17px;
                        }
                     </style>
                     <div class="row">
                        <div class="col-md-12">
                           <div class="card mb-2">
                              <div class="card-body"
                                 style="padding: 1px;padding-left: 6px;padding-right: 6px;padding-bottom: 30px;background-color: cadetblue;">
                                 <div class="card-header" style="padding-top: 5px;">
                                    <ul class="nav nav-tabs card-header-tabs nav-responsive-md">
                                       <li class="nav-item">
                                          <a class="nav-link active" data-toggle="tab" href="#navs-wc-home"
                                             onclick="pressTab(1)" style="color: black;">Patient Info</a>
                                       </li>
                                       <!--<li class="nav-item">
                                          <a class="nav-link" data-toggle="tab" href="#navs-wc-profile" onclick="pressTab(2)">Patient Detail</a>
                                          </li>-->
                                       <li class="nav-item">
                                          <a class="nav-link" onclick="patientSummary()" href="javascript:void(0)" style="color: black;">Patient Summary</a>
                                       </li>
                                       <?php if($_SESSION['CopyPaste'] == 'copy'){?>
                                       <li class="nav-item" style="float:right">
                                          <a href="<?php echo $_SERVER['PHP_SELF']; ?>?mrd=<?php echo $_REQUEST['mrd']; ?>&visitdate=<?php echo $_REQUEST['visitdate'];?>&action=paste"
                                             class="btn btn-info">Paste</a>
                                       </li>
                                       <?php } ?>
                                       <li class="nav-item pastebtn" style="float:right;display:none;">
                                          <a href="<?php echo $_SERVER['PHP_SELF']; ?>?mrd=<?php echo $_REQUEST['mrd']; ?>&visitdate=<?php echo $_REQUEST['visitdate'];?>&action=paste"
                                             class="btn btn-info">Paste</a>
                                       </li>
                                       &nbsp;&nbsp;
                                       <!--    <li class="nav-item" style="float:right">
                                          <a href="javascript:void(0)" onclick="copyRecord()" id="copybtn" class="btn btn-primary">Copy</a>
                                          </li> -->
                                       &nbsp;&nbsp;
                                       <li class="nav-item" style="float:right">
                                          <a href="dashboard.php" class="btn btn-success">Back To Home</a>
                                       </li>&nbsp;&nbsp;
                                       <li class="nav-item" style="float:right">
                                          <button class="btn btn-info" type="button" onclick="printOpd()"
                                             id="print">Print</button>
                                       </li>&nbsp;&nbsp;
                                        <li class="nav-item" style="float:right">
                                          <button class="btn btn-danger" type="button"
                                             onclick="deletePatient()">Delete Patient</button>
                                       </li>&nbsp;&nbsp;
                                       <!-- <li class="nav-item" style="float:right">
                                          <button class="btn btn-danger" type="button"
                                             onclick="deletedPatients()">Deleted Patients List</button>
                                       </li> -->
                                    </ul>
                                 </div>
                                 <div class="tab-content">
                                    <div class="tab-pane fade show active" id="navs-wc-home">
                                       <div class="form-row">
                                          <div class="form-group col-md-12" style="margin-bottom: 0rem;">
                                             <fieldset>
                                                <legend>Search Patient</legend>
                                                <div class="table-responsive" style="overflow-x:auto;">
                                                   <table class="table table-bordered table-striped mb-0">
                                                      <thead>
                                                         <tr>
                                                            <th width="20">MRD NO</th>
                                                            <th width="200">Add Search Criteria</th>
                                                            <th width="50">Visit Date</th>
                                                            <th width="130">Visit Date</th>
                                                            <th width="20"></th>
                                                            <!--<th width="200">Visit Time</th>-->
                                                         </tr>
                                                      </thead>
                                                      <tbody>
                                                         <tr>
                                                            <td width="90">
                                                               <input type="hidden" id="newmrdno"
                                                                  value="<?php echo $MrdNo; ?>">
                                                               <div class="input-group">
                                                                  <input type="text" name="MrdNo"
                                                                     id="MrdNo" class="form-control"
                                                                     placeholder=""
                                                                     value="<?php echo $MrdNo; ?>"
                                                                     onClick="this.select();"
                                                                     oninput="getPatientDetails()"
                                                                     style="background-color: chartreuse;font-size: 25px;"
                                                                     value="<?php echo $_REQUEST['mrd'];?>">
                                                                  <span class="input-group-append">
                                                                     <button
                                                                        class="btn btn-secondary"
                                                                        type="button"
                                                                        style="height: 26px;    line-height: 0.47;"
                                                                        onclick="getNewMrdNo()">New</button>
                                                                     <!-- <div class="input-group-text">
                                                                        <input type="checkbox" id="getNewMrdNo" onclick="getNewMrdNo2()">
                                                                        <div class="clearfix"></div>
                                                                        </div> -->
                                                                  </span>
                                                               </div>
                                                               <input type="hidden" name="VisitNo"
                                                                  id="VisitNo"
                                                                  value="<?php echo $VisitNo;?>">
                                                            </td>
                                                            <td>
                                                               <input class="form-control datalist"
                                                                  list="DataList2" name="PatientId"
                                                                  id="PatientId"
                                                                  onchange="getPatientDetails2(this.value)"
                                                                  value="<?php echo $row7['PatientId'];?>"
                                                                  <?php if($row8['ptnotes'] != ''){?>
                                                                  style="background-color: red;"
                                                                  <?php } else {?>
                                                                  style="background-color: chartreuse;"
                                                                  <?php } ?>>
                                                               <datalist id="DataList2">
                                                                  <?php 
                                                                     $CreatedDate = 'all';
                                                                       //$sql4 = "CALL patient_read('$CreatedDate')";
                                                                      $sql4 = "SELECT MrdNo,PatientName,ConsultantName,Phone FROM tbl_patients";
                                                                      $row4 = getList($sql4);
                                                                      foreach($row4 as $result){
                                                                          if($result['Phone'] == ''){
                                                                              $PatientName = $result['MrdNo']." / ".$result['PatientName'];
                                                                          }
                                                                          else{
                                                                              $PatientName = $result['MrdNo']." / ".$result['PatientName']."/".$result['Phone'];
                                                                          }
                                                                     ?>
                                                                  <option
                                                                     value="<?php echo $PatientName; ?>">
                                                                  </option>
                                                                  <?php } ?>
                                                               </datalist>
                                                            </td>
                                                            <td>
                                                               <input type="date" class="form-control"
                                                                  name="VisitDate2" id="VisitDate2"
                                                                  value="<?php echo $VisitDate;?>"
                                                                  onchange="checkVisitDate(this.value)">
                                                            </td>
                                                            <?php 
                                                               $CurrDate = date('Y-m-d');
                                                               $sql5 = "SELECT * FROM tbl_visits WHERE MrdNo='$MrdNo' AND VisitDate='$CurrDate' ORDER BY VisitDate DESC";
                                                               $rncnt55 = getRow($sql5);
                                                               $sql4 = "SELECT MAX(VisitNo) As VisitNo FROM tbl_visits WHERE MrdNo='$MrdNo'";
                                                               $row4 = getRecord($sql4);
                                                               $VisitNo22 = $row4['VisitNo']+1;
                                                               ?>
                                                            <td>
                                                               <select class="form-control"
                                                                  onchange="getConsultRec(this.value)"
                                                                  name="VisitDate" id="VisitDate"
                                                                  style="height: 35px;">
                                                                  <?php if($rncnt55>0){} else{?>
                                                                  <option selected=""
                                                                     value="<?php echo $CurrDate;?>">
                                                                     <?php echo $VisitNo22." / ".date("d/m/Y", strtotime(str_replace('-', '/',$CurrDate)));?>
                                                                  </option>
                                                                  <?php } ?>
                                                                  <?php 
                                                                     $sql5 = "SELECT * FROM tbl_visits WHERE MrdNo='$MrdNo' AND DeleteFlag=0 ORDER BY VisitDate DESC";
                                                                     $row5 = getList($sql5);
                                                                     foreach($row5 as $result){
                                                                     ?>
                                                                  <option
                                                                     value="<?php echo $result['VisitDate'];?>"
                                                                     <?php if($result['VisitDate'] == $VisitDate) {?>
                                                                     selected <?php } ?>>
                                                                     <?php echo $result['VisitNo']." / ".date("d/m/Y", strtotime(str_replace('-', '/',$result['VisitDate']))); ?>
                                                                  </option>
                                                                  <?php } ?>
                                                               </select>
                                                            </td>
                                                            <input type="hidden" name="VisitTime"
                                                               id="VisitTime" class="form-control"
                                                               placeholder=""
                                                               value="<?php echo $VisitTime; ?>">
                                                            <td> <button class="btn btn-danger"
                                                               type="button" style="height: 30px;"
                                                               data-toggle="modal"
                                                               data-target="#myModal"></button>
                                                            </td>
                                                            <!--  <td> 
                                                               </td>-->
                                                </div>
                                                <div id="myModal" class="modal fade" role="dialog">
                                                <div class="modal-dialog">
                                                <!-- Modal content-->
                                                <div class="modal-content">
                                                <div class="modal-header">
                                                <h4 class="modal-title">Patient Note</h4>
                                                </div>
                                                <div class="modal-body">
                                                <input type="hidden" name="ptmrdno"
                                                   id="ptmrdno"
                                                   value="<?php echo $MrdNo; ?>">
                                                <input type="hidden" name="ptvisitdate"
                                                   id="ptvisitdate"
                                                   value="<?php echo $VisitDate; ?>">
                                                <textarea class="form-control" id="ptnotes"
                                                   name="ptnotes" rows="3"
                                                   style="height: 100px;"><?php echo $row8['ptnotes'];?></textarea>
                                                </div>
                                                <div class="modal-footer">
                                                <!-- <button type="button" class="btn btn-info" onclick="savePtNotes()">Save</button> -->
                                                <button type="button"
                                                   class="btn btn-default"
                                                   data-dismiss="modal">Close</button>
                                                </div>
                                                </div>
                                                </div>
                                                </div>
                                                </tr>
                                                </tbody>
                                                </table>
                                          </div>
                                          </fieldset>
                                       </div>
                                       <script>
                                          function patientSummary(){
                                             var MrdNo = $('#MrdNo').val();
                                             setTimeout(function() {
                                                  window.open(
                                                      'view-patient-summary.php?mrdno='+MrdNo, 'PatientSummary',
                                                      'toolbar=1, scrollbars=1, location=1,statusbar=0, menubar=1, resizable=1, width=1500, height=1000'
                                                  );
                                              }, 1);
                                          }
                                          function deletedPatients() {
                                              setTimeout(function() {
                                                  window.open(
                                                      'view-deleted-patients.php', 'deletedPatients',
                                                      'toolbar=1, scrollbars=1, location=1,statusbar=0, menubar=1, resizable=1, width=1500, height=1000'
                                                  );
                                              }, 1);
                                          }
                                          
                                          function deletePatient(){
                                             var action = "deletePatient";
                                             var MrdNo = $('#MrdNo').val();
                                             if(confirm("Are you sure?")){
                                              $.ajax({
                                                  type: "POST",
                                                  url: "ajax_files/ajax_patients.php",
                                                  data: {
                                                      action: action,
                                                      
                                                      MrdNo: MrdNo
                                                  },
                                                  success: function(data) {
                                                      alert("Patient Record Deleted!");
                                                      window.location.href ="patientdetailform.php";
                                                  }
                                              });
                                           }
                                          }
                                          function checkVisitDate(val) {
                                              var action = "checkVisitDate";
                                              var MrdNo = $('#MrdNo').val();
                                              $.ajax({
                                                  type: "POST",
                                                  url: "ajax_files/ajax_patients.php",
                                                  data: {
                                                      action: action,
                                                      val: val,
                                                      MrdNo: MrdNo
                                                  },
                                                  success: function(data) {
                                                      $('#VisitNo').val(data);
                                                      window.location.href =
                                                          "patientdetailform.php?mrd=" + MrdNo +
                                                          "&visitdate=" + val;
                                                  }
                                              });
                                          }
                                          
                                          function checkShortKey(id) {
                                              var ShortKey = $('#ShortKey' + id).val();
                                              var action = "checkShortKey";
                                              $.ajax({
                                                  type: "POST",
                                                  url: "ajax_files/ajax_patients.php",
                                                  data: {
                                                      action: action,
                                                      TreatName: ShortKey
                                                  },
                                                  success: function(data) {
                                                      var res = JSON.parse(data);
                                                      var Status = res.Status;
                                                      var TreatName = res.TreatName;
                                                      if (Status == 1) {
                                                          $('#TreatName' + id).val(TreatName);
                                                      } else {
                                          
                                                      }
                                          
                                                  }
                                              });
                                          }
                                          
                                          function checkShortKey2(id) {
                                              var ShortKey = $('#ShortKeysv' + id).val();
                                              var action = "checkShortKey";
                                              $.ajax({
                                                  type: "POST",
                                                  url: "ajax_files/ajax_patients.php",
                                                  data: {
                                                      action: action,
                                                      TreatName: ShortKey
                                                  },
                                                  success: function(data) {
                                                      var res = JSON.parse(data);
                                                      var Status = res.Status;
                                                      var TreatName = res.TreatName;
                                                      if (Status == 1) {
                                                          $('#TreatNamesv' + id).val(TreatName);
                                                      } else {
                                          
                                                      }
                                          
                                                  }
                                              });
                                          }
                                          
                                          
                                          function checkShortKey3(id) {
                                              var ShortKey = $('#ShortKeynv' + id).val();
                                              var action = "checkShortKey";
                                              $.ajax({
                                                  type: "POST",
                                                  url: "ajax_files/ajax_patients.php",
                                                  data: {
                                                      action: action,
                                                      TreatName: ShortKey
                                                  },
                                                  success: function(data) {
                                                      var res = JSON.parse(data);
                                                      var Status = res.Status;
                                                      var TreatName = res.TreatName;
                                                      if (Status == 1) {
                                                          $('#TreatNamenv' + id).val(TreatName);
                                                      } else {
                                          
                                                      }
                                          
                                                  }
                                              });
                                          }
                                          
                                          function savePtNotes() {
                                              var ptmrdno = $('#ptmrdno').val();
                                              var ptvisitdate = $('#ptvisitdate').val();
                                              var ptnotes = $('#ptnotes').val();
                                              var action = "savePtNotes";
                                              $.ajax({
                                                  type: "POST",
                                                  url: "ajax_files/ajax_patients.php",
                                                  data: {
                                                      action: action,
                                                      MrdNo: ptmrdno,
                                                      VisitDate: ptvisitdate,
                                                      ptnotes: ptnotes
                                                  },
                                                  success: function(data) {
                                                      if (data == 1) {
                                                          $('#myModal').modal('hide');
                                                      }
                                                  }
                                              });
                                          }
                                          
                                          function getNewMrdNo2() {
                                              if ($('#getNewMrdNo').prop('checked') == true) {
                                                  var newmrdno = $('#newmrdno').val();
                                                  $('#MrdNo').val(newmrdno);
                                              } else {
                                                  $('#MrdNo').val('');
                                              }
                                          }
                                          
                                          function pasteRecord() {
                                          
                                          }
                                          
                                          function copyRecord() {
                                              var MrdNo = $('#MrdNo').val();
                                              var VisitDate = $('#VisitDate').val();
                                              //alert(MrdNo);alert(VisitDate);
                                              var action = 'copyRecord';
                                              $.ajax({
                                                  type: "POST",
                                                  url: "ajax_files/ajax_patients.php",
                                                  data: {
                                                      action: action,
                                                      MrdNo: MrdNo,
                                                      VisitDate: VisitDate
                                                  },
                                                  beforeSend: function() {
                                                      $('#copybtn').attr('disabled', 'disabled');
                                                      $('#copybtn').text('Copied...');
                                                  },
                                                  success: function(data) {
                                                      //alert("Record Copied");
                                                      $('.pastebtn').show();
                                                      $('#copybtn').attr('disabled', false);
                                                      $('#copybtn').text('Copy');
                                                  }
                                              });
                                          }
                                          
                                          function getPatientSummary(MrdNo) {
                                              //var MrdNo = $('#MrdNo').val();
                                              var action = 'getPatientSummary';
                                              $.ajax({
                                                  type: "POST",
                                                  url: "ajax_files/ajax_patients.php",
                                                  data: {
                                                      action: action,
                                                      id: MrdNo
                                                  },
                                                  success: function(data) {
                                                      console.log(data);
                                                      $('#navs-wc-summary').html(data);
                                                  }
                                              });
                                          }
                                          
                                          function getPatientDetails() {
                                          
                                              var MrdNo = $('#MrdNo').val();
                                              var action = 'getPatientDetails';
                                              $('#PatientId').val('');
                                              $.ajax({
                                                  type: "POST",
                                                  url: "ajax_files/ajax_patients.php",
                                                  data: {
                                                      action: action,
                                                      id: MrdNo
                                                  },
                                                  dataType: "json",
                                                  success: function(data) {
                                                      $('#PatientName').val(data.PatientName);
                                                      $('#Fname').val(data.Fname);
                                                      $('#Mname').val(data.Mname);
                                                      $('#Lname').val(data.Lname);
                                                      $('#Gender').val(data.Gender).attr('selected',
                                                          true);
                                                      $('#Age').val(data.Age);
                                                      $('#Phone').val(data.Phone);
                                                      $('#Address').val(data.Address);
                                                      $('#Notes').val(data.History);
                                                      $('#Remark').val(data.Stressor);
                                                      $('#City').val(data.City);
                                                      //alert(data.ptnotes);
                                                      if(data.ptnotes == undefined || data.ptnotes == ''){
                                                         $('#PatientId').css("background-color","chartreuse");
                                                         $('#myModal').modal("hide");
                                                         $('#ptnotes').val('');
                                                      }
                                                      else{
                                                         $('#PatientId').css("background-color","red");
                                                         $('#myModal').modal("show");
                                                         $('#ptnotes').val(data.ptnotes);
                                                      }
                                                  }
                                              });
                                              getVisitDate(MrdNo);
                                              getPatientSummary(MrdNo);
                                              $('#ptmrdno').val(MrdNo);
                                              getMaxMrdno(MrdNo);
                                              blankPrevDate();
                                          }
                                          
                                          function checkCounsultant(MrdNo) {
                                              var action = 'checkCounsultant';
                                              $.ajax({
                                                  type: "POST",
                                                  url: "ajax_files/ajax_patients.php",
                                                  data: {
                                                      action: action,
                                                      id: MrdNo
                                                  },
                                                  success: function(data) {
                                                      console.log(data);
                                                      var res = JSON.parse(data);
                                                      var History = res.History;
                                                      var Stressor = res.Stressor;
                                                      $('#Notes').val(History);
                                                      $('#Remark').val(Stressor);
                                          
                                                  }
                                              });
                                          }
                                          
                                          function getMaxMrdno(MrdNo) {
                                              var action = 'getMaxMrdno';
                                              var VisitDate = $('#VisitDate2').val();
                                              $.ajax({
                                                  type: "POST",
                                                  url: "ajax_files/ajax_patients.php",
                                                  data: {
                                                      action: action,
                                                      MrdNo: MrdNo,
                                                      VisitDate: VisitDate
                                                  },
                                                  success: function(data) {
                                                      $('#VisitNo').val(data);
                                          
                                                  }
                                              });
                                          }
                                          
                                          function blankPrevDate() {
                                              var CurrDate = $('#CurrDate').val();
                                              $("input[name='Telugu']").val(0).attr('checked', false);
                                              $("input[name='DM']").val(0).attr('checked', false);
                                              $("input[name='HT']").val(0).attr('checked', false);
                                              $("input[name='IHD']").val(0).attr('checked', false);
                                              $("input[name='PILES']").val(0).attr('checked', false);
                                              $("input[name='Thyroid']").val(0).attr('checked', false);
                                              $("input[name='Other']").val(0).attr('checked', false);
                                              $("input[name='OtherTxt']").val('');
                                              $("input[name='Prognosis']").val(0).attr('checked', false);
                                              $("input[name='DSH']").val(0).attr('checked', false);
                                              $("input[name='FollowUp']").val(0).attr('checked', false);
                                              $("input[name='Irregular']").val(0).attr('checked', false);
                                              $("input[name='Medication']").val(0).attr('checked', false);
                                              $("input[name='StrictSupervision']").val(0).attr('checked', false);
                                              $("input[name='Admission']").val(0).attr('checked', false);
                                              $("input[name='ChkBlood']").val(0).attr('checked', false);
                                              $("input[name='Eeg']").val(0).attr('checked', false);
                                              $("input[name='ChkCT']").val(0).attr('checked', false);
                                              $("input[name='ChkMRI']").val(0).attr('checked', false);
                                              $("input[name='ChkUSG']").val(0).attr('checked', false);
                                              $("input[name='ChkOthers']").val(0).attr('checked', false);
                                              $("input[name='TxtBlood']").val('');
                                              $("input[name='TxtEeg']").val('');
                                              $("input[name='TxtCT']").val('');
                                              $("input[name='TxtMRI']").val('');
                                              $("input[name='TxtUSG']").val('');
                                              $("input[name='TxtOthers']").val('');
                                              $('#Diagnosis').val('');
                                              $('#SpecialNote').val('');
                                              $('#Duration').val(0);
                                              $('#FollowUpDate').val(CurrDate);
                                              //$("input[name='Language']").val('E').attr('checked', true);
                                              $('#prevtreatments').html('');
                                              $('#PrevTreatment').val('');
                                          
                                          
                                          }
                                          
                                          function getPatientDetails2(MrdNo) {
                                              //var MrdNo = $('#MrdNo').val(); 
                                          
                                              var action = 'getPatientDetails';
                                              $.ajax({
                                                  type: "POST",
                                                  url: "ajax_files/ajax_patients.php",
                                                  data: {
                                                      action: action,
                                                      id: MrdNo
                                                  },
                                                  dataType: "json",
                                                  success: function(data) {
                                                      $('#PatientName').val(data.PatientName);
                                                      $('#MrdNo').val(data.MrdNo);
                                                      $('#Fname').val(data.Fname);
                                                      $('#Mname').val(data.Mname);
                                                      $('#Lname').val(data.Lname);
                                                      $('#Gender').val(data.Gender).attr('selected',
                                                          true);
                                                      $('#Age').val(data.Age);
                                                      $('#Phone').val(data.Phone);
                                                      $('#Address').val(data.Address);
                                                      //$('#Notes').val(data.History);
                                                      //$('#Remark').val(data.Stressor);
                                                      $('#City').val(data.City);
                                                      getVisitDate(data.MrdNo);
                                                      getPatientSummary(data.MrdNo);
                                                      checkCounsultant(data.MrdNo);
                                                      $('#ptmrdno').val(data.MrdNo);
                                                      getMaxMrdno(data.MrdNo);
                                                      blankPrevDate();

                                                      if(data.ptnotes == undefined || data.ptnotes == ''){
                                                         $('#PatientId').css("background-color","chartreuse");
                                                         $('#myModal').modal("hide");
                                                         $('#ptnotes').val('');
                                                      }
                                                      else{
                                                         $('#PatientId').css("background-color","red");
                                                         $('#myModal').modal("show");
                                                         $('#ptnotes').val(data.ptnotes);
                                                      }
                                                  }
                                              });
                                          }
                                          
                                          function getNewMrdNo() {
                                              window.location.href = 'patientdetailform.php?val=new';
                                              /*var action = 'getNewMrdNo';
                                          $.ajax({
                                          type: "POST",
                                          url: "ajax_files/ajax_patients.php", 
                                          data:{action:action},    
                                          success: function(data){
                                          $('#MrdNo').val(data);
                                          $('#Fname').val('');
                                          $('#Mname').val('');
                                          $('#Lname').val('');
                                          $('#Gender').val('').attr('selected',true);
                                          $('#Age').val('');
                                          $('#Phone').val('');
                                          $('#Address').val('');
                                          $('#City').val('');
                                          $('#prevtreatments').hide();
                                          }  
                                          });*/
                                          }
                                          
                                          
                                          function getVisitDate(MrdNo) {
                                              //var MrdNo = $('#MrdNo').val();
                                              var action = 'getVisitDate';
                                              $.ajax({
                                                  type: "POST",
                                                  url: "ajax_files/ajax_patients.php",
                                                  data: {
                                                      action: action,
                                                      MrdNo: MrdNo
                                                  },
                                                  success: function(data) {
                                                      //alert(data);
                                                      $('#VisitDate').html(data);
                                                  }
                                              });
                                          }
                                          
                                          function getUpRecordList() {
                                              var MrdNo = $('#MrdNo').val();
                                              var action = 'getUpRecordList';
                                              $.ajax({
                                                  type: "POST",
                                                  url: "ajax_files/ajax_opto_form.php",
                                                  data: {
                                                      action: action,
                                                      MrdNo: MrdNo
                                                  },
                                                  success: function(data) {
                                                      $('#customers').html(data);
                                                      $('#myModal22').modal("show");
                                                  }
                                              });
                                          }
                                          
                                          function chkInvst(chk, val) {
                                              //var chk = $("input[name="+chk+"]").val();
                                              var val = $("input[name=" + val + "]").val();
                                              if (val == '') {
                                                  $("input[name=" + chk + "]").val(0).attr('checked', false);
                                              } else {
                                                  $("input[name=" + chk + "]").val(1).attr('checked', true);
                                              }
                                          }
                                       </script>
                                       <style>
                                          .form-control {
                                          background-color: bisque;
                                          }
                                       </style>
                                       <div class="form-group col-md-12" style="margin-bottom: 0rem;">
                                          <fieldset>
                                             <legend>Patient General Info</legend>
                                             <div class="table-responsive" style="overflow-x:auto;">
                                                <table class="table table-bordered table-striped mb-0">
                                                   <thead>
                                                      <tr>
                                                         <th width="100">Full Name</th>
                                                         <th width="100">New Name</th>
                                                         <th width="10" style="width: 13%;">Sex</th>
                                                         <th width="20" style="width: 7%;">Age</th>
                                                         <th width="50">Email</th>
                                                      </tr>
                                                   </thead>
                                                   <tbody>
                                                      <tr>
                                                         <td>
                                                            <div class="input-group">
                                                               <!--  <input class="form-control" name="ShortPtName" id="ShortPtName" value="" style="max-width: 20%;" placeholder="Sht Key" oninput="ShortPtName33()"> -->
                                                               <input type="text" class="form-control"
                                                                  list="Dllname" id="PatientName"
                                                                  name="PatientName" placeholder="Patient Name"
                                                                  value="<?php echo $Patient_Name;?>"
                                                                  oninput="getFnameCap2('PatientName'),ShortPtName33('PatientName')">
                                                               <datalist id="Dllname">
                                                                  <?php 
                                                                     $sql4 = "SELECT DISTINCT(PatientName) As PatientName FROM tbl_patients";
                                                                     $row4 = getList($sql4);
                                                                     foreach($row4 as $result){
                                                                     ?>
                                                                  <option
                                                                     value="<?php echo $result['PatientName']; ?>">
                                                                     <?php } ?>
                                                               </datalist>
                                                               <span class="input-group-append">
                                                               <button class="btn btn-secondary"
                                                                  type="button"
                                                                  style="height: 26px;"
                                                                  onclick="getUpRecordList()">...</button>
                                                               </span>
                                                            </div>
                                                            <div id="myModal22" class="modal fade"
                                                               role="dialog">
                                                            <div class="modal-dialog">
                                                            <!-- Modal content-->
                                                            <div class="modal-content">
                                                            <div class="modal-header">
                                                            <h4 class="modal-title">
                                                            Patient Updated Record
                                                            History</h4>
                                                            </div>
                                                            <div class="modal-body">
                                                            <style type="text/css">
                                                            #customers {
                                                            font-family: Arial, Helvetica, sans-serif;
                                                            border-collapse: collapse;
                                                            width: 100%;
                                                            }
                                                            #customers td,
                                                            #customers th {
                                                            border: 1px solid #ddd;
                                                            padding: 8px;
                                                            }
                                                            #customers tr:nth-child(even) {
                                                            background-color: #f2f2f2;
                                                            }
                                                            #customers tr:hover {
                                                            background-color: #ddd;
                                                            }
                                                            #customers th {
                                                            padding-top: 12px;
                                                            padding-bottom: 12px;
                                                            text-align: left;
                                                            background-color: #04AA6D;
                                                            color: white;
                                                            }
                                                            </style>
                                                            <table id="customers">
                                                            </table>
                                                            </div>
                                                            <div class="modal-footer">
                                                            <button type="button"
                                                               class="btn btn-default"
                                                               data-dismiss="modal">Close</button>
                                                            </div>
                                                            </div>
                                                            </div>
                                                            </div>
                                                         </td>
                                                         <td> <input type="text" class="form-control"
                                                            list="Dllname" id="NewName"
                                                            name="NewName" placeholder="" value=""
                                                            oninput="getFnameCap2('PatientName')">
                                                         </datalist>
                                                         </td>
                                                         <td><select class="form-control" id="Gender"
                                                            name="Gender" required
                                                            style="height: 34px;">
                                                        
                                                         <option value="Male"
                                                            <?php if($Gender == 'Male'){?>
                                                            selected <?php } ?>>Male</option>
                                                         <option value="Female"
                                                            <?php if($Gender == 'Female'){?>
                                                            selected <?php } ?>>Female</option>
                                                         </select> </td>
                                                         <td> <input type="text" class="form-control"
                                                            id="Age" name="Age" placeholder=""
                                                            required
                                                            onKeyPress="return isNumberKey(event)"
                                                            value="<?php echo $Age;?>"></td>
                                                         <td> <input type="email" class="form-control"
                                                            id="EmailId" name="EmailId"
                                                            placeholder=""
                                                            value="<?php echo $EmailId;?>"></td>
                                                      </tr>
                                                   </tbody>
                                                   <thead>
                                                      <tr>
                                                         <th width="20">Mobile No</th>
                                                         <th width="20">New Mobile No</th>
                                                         <th width="20">Marital Status</th>
                                                         <th width="120" colspan="2">Address</th>
                                                      </tr>
                                                   </thead>
                                                   <tbody>
                                                      <tr>
                                                         <td> <input type="text" class="form-control"
                                                            id="Phone" name="Phone" placeholder=""
                                                            onKeyPress="return isNumberKey(event)"
                                                            value="<?php echo $Phone;?>"></td>
                                                         <td> <input type="text" class="form-control"
                                                            id="NewPhone" name="NewPhone"
                                                            placeholder=""
                                                            onKeyPress="return isNumberKey(event)">
                                                         </td>
                                                         <td>
                                                            <select class="form-control" name="MarritalStatus"
                                                               id="MarritalStatus" style="height: 35px;">
                                                               <option <?php if($MarritalStatus == 'M'){ ?> selected <?php } ?> value="M">Married</option>
                                                               <option <?php if($MarritalStatus == 'UN'){ ?> selected <?php } ?> value="UN">Unmarried</option>
                                                               <option <?php if($MarritalStatus == 'D'){ ?> selected <?php } ?> value="D">Divorce</option>
                                                               <option <?php if($MarritalStatus == 'W'){ ?> selected <?php } ?> value="W">Widow</option>
                                                               <option <?php if($MarritalStatus == 'Disputed'){ ?> selected <?php } ?> value="Disputed">Disputed</option>
                                                            </select>
                                                           <!--  <input class="form-control"
                                                               list="Marrital_Status"
                                                               name="MarritalStatus"
                                                               id="MarritalStatus"
                                                               value="<?php echo $MarritalStatus;?>"
                                                               
                                                               oninput="getFnameCap('Address')">
                                                            <datalist id="Marrital_Status">
                                                               <option value="M">
                                                               <option value="UN">
                                                               <option value="D">
                                                               <option value="W">
                                                                  <?php 
                                                                     $sql = "SELECT DISTINCT(MarritalStatus) As MarritalStatus FROM tbl_patients WHERE MarritalStatus NOT IN ('M','UN','D','W')";
                                                                     $row = getList($sql);
                                                                     foreach($row as $result){
                                                                      ?>
                                                               <option
                                                                  value="<?php echo $result['MarritalStatus']; ?>">
                                                                  <?php } ?>
                                                            </datalist> -->
                                                            <!-- <select class="form-control" id="MarritalStatus" name="MarritalStatus" style="height: 34px;">
                                                               <option value="" disabled="" selected="">...</option>
                                                               <option value="M" <?php if($MarritalStatus == 'M'){?> selected <?php } ?>>M</option>
                                                               <option value="UN" <?php if($MarritalStatus == 'UN'){?> selected <?php } ?>>UN</option>
                                                               <option value="D" <?php if($MarritalStatus == 'D'){?> selected <?php } ?>>D</option>
                                                               <option value="W" <?php if($MarritalStatus == 'W'){?> selected <?php } ?>>W</option>
                                                               <option value="Other" <?php if($MarritalStatus == 'Other'){?> selected <?php } ?>>Other</option>
                                                               </select> -->
                                                         </td>
                                                         <td colspan="2">
                                                         <input class="form-control" list="Cities"
                                                            name="Address" id="Address"
                                                            value="<?php echo $Address;?>"
                                                            
                                                            oninput="getFnameCap('Address')">
                                                         <datalist id="Cities">
                                                         <?php 
                                                            $sql = "SELECT DISTINCT(Address) As Address FROM tbl_patients";
                                                            $row = getList($sql);
                                                            foreach($row as $result){
                                                             ?>
                                                         <option
                                                            value="<?php echo $result['Address']; ?>">
                                                         <?php } ?>
                                                         </datalist>
                                                         <!--  <textarea class="form-control" id="Address" name="Address" rows="3" style="height: 36px;"><?php echo $Address;?></textarea> -->
                                                         </td>
                                                         <!--   <td>  <input class="form-control" list="Cities" name="City" id="City" value="<?php echo $row7['City'];?>">
                                                            <datalist id="Cities">
                                                              <?php 
                                                               $sql = "SELECT DISTINCT(City) As City FROM tbl_patients";
                                                               $row = getList($sql);
                                                               foreach($row as $result){
                                                                ?>    
                                                              <option value="<?php echo $result['City']; ?>">
                                                              <?php } ?>
                                                             
                                                            </datalist></td>            
                                                                             <td> <input type="text" class="form-control" id="RelativeComes" name="RelativeComes" placeholder="" value="<?php echo $row7['RelativeComes'];?>"></td> -->
                                                         <!--   
                                                            <td colspan="2"> <input type="text" class="form-control" id="RelativeName" name="RelativeName" placeholder="" value="<?php echo $row7['RelativeName'];?>"></td>    -->
                                                         <!--<td><input class="form-control" name="PatientWilling" id="PatientWilling"  value="<?php echo $row7['PatientWilling'];?>"> </td>                                                                                                                               <td> </td>-->
                                                         <!--<td> </td>-->
                                                         <!--<td> </td>-->
                                                         <!--<td> </td><td> </td>                                                                                                  -->
                                                      </tr>
                                                   </tbody>
                                                   <thead>
                                                   <tr>
                                                   <th width="50">Name of Objective Data</th>
                                                   <th width="20">Foot Note</th>
                                                   <th width="20" colspan="2">&nbsp;Comorbities:
                                                   known case of</th>
                                                   <th width="20"><input type="checkbox" value="1"
                                                      name="Telugu"
                                                      <?php if($row7['Telugu'] == '1'){?>
                                                      checked <?php } ?>>&nbsp;Telugu</th>
                                                   </tr>
                                                   </thead>
                                                   <tbody>
                                                   <tr>
                                                   <td>
                                                      <div class="input-group">
                                                      <input class="form-control"
                                                      list="relation_ship" name="Relationship"
                                                      id="Relationship"
                                                      value="<?php echo $row7['Relationship'];?>"
                                                      style="max-width: 35%;"
                                                      >
                                                      <datalist id="relation_ship">
                                                   
                                                  <?php 
                                                      $sql4 = "SELECT DISTINCT(Relationship) As Relationship FROM tbl_consultant";
                                                      $row4 = getList($sql4);
                                                      foreach($row4 as $result){
                                                      ?>
                                                   <option
                                                      value="<?php echo $result['Relationship']; ?>">
                                                   <?php } ?>                                                   
                                                   </datalist>
                                                   <input type="text" class="form-control" placeholder="Relative Name" oninput="getFnameCap('RelativeName')" name="RelativeName"
                                                      id="RelativeName">
                                  
                                                </div>
                                                   
                                                   </td>
                                                   <td>
                                                   <input type="text" class="form-control"
                                                      list="FootNote" id="RefBy" name="RefBy"
                                                      placeholder=""
                                                      value="<?php echo $RefBy;?>">
                                                   <datalist id="FootNote">
                                                   <?php 
                                                      $sql4 = "SELECT DISTINCT(RefBy) As RefBy FROM tbl_consultant";
                                                      $row4 = getList($sql4);
                                                      foreach($row4 as $result){
                                                      ?>
                                                   <option
                                                      value="<?php echo $result['RefBy']; ?>">
                                                   <?php } ?>
                                                   </datalist>
                                                   </td>
                                                   <td colspan="3"><input type="checkbox" name="DM"
                                                      value="1"
                                                      <?php if($row7['DM'] == '1'){?> checked
                                                      <?php } ?> />
                                                   DM &nbsp;&nbsp;
                                                   <input type="checkbox" name="HT" value="1"
                                                      <?php if($row7['HT'] == '1'){?> checked
                                                      <?php } ?> />
                                                   HT &nbsp;&nbsp;
                                                   <input type="checkbox" name="IHD" value="1"
                                                      <?php if($row7['IHD'] == '1'){?> checked
                                                      <?php } ?> />
                                                   IHD &nbsp;&nbsp;
                                                   <input type="checkbox" name="PILES"
                                                      value="1"
                                                      <?php if($row7['PILES'] == '1'){?>
                                                      checked <?php } ?> />
                                                   PILES &nbsp;&nbsp;
                                                   <input type="checkbox" name="Thyroid"
                                                      value="1"
                                                      <?php if($row7['Thyroid'] == '1'){?>
                                                      checked <?php } ?> />
                                                   Thyroid&nbsp;&nbsp;
                                                   <input type="checkbox" name="Other"
                                                      value="1"
                                                      <?php if($row7['Other'] == '1'){?>
                                                      checked <?php } ?> />
                                                   Other
                                                   <input type="text" name="OtherTxt"
                                                      value="<?php echo $row7['OtherTxt'];?>"
                                                      class="form-control" />
                                                   </td>
                                                   </tr>
                                                   </tbody>
                                                </table>
                                             </div>
                                          </fieldset>
                                       </div>
                                    </div>
                                    <div class="row">
                                    <div class="col-lg-8">
                                    <div class="form-group col-md-12" style="margin-bottom: 0rem;">
                                    <fieldset>
                                    <legend>Detail Notes</legend>
                                    <div class="row">
                                    <div class="col-lg-11">
                                    <div class="form-group">
                                    <textarea class="form-control" id="Notes"
                                       rows="10" name="Notes"
                                       style="height: 146px;"><?php echo $row7['Notes'];?></textarea>
                                    </div>
                                    </div>
                                    <div class="col-lg-1">
                                    <span class="input-group-append">
                                    <button class="btn btn-secondary" type="button"
                                       data-toggle="modal"
                                       data-target="#modal-report" id="add_button"
                                       onclick="getValue('Notes','Notes')">...</button>
                                    </span>
                                    </div>
                                    </div>
                                    </fieldset>
                                    </div>
                                    <div class="form-group col-md-12" style="margin-bottom: 0rem;">
                                    <fieldset>
                                    <div id="accordion2">
                                    <div class="card mb-2">
                                    <div class="card-header">
                                    <a class="collapsed d-flex justify-content-between text-dark"
                                       data-toggle="collapse"
                                       href="#accordion2-2">Investigation<div
                                       class="collapse-icon"></div></a>
                                    </div>
                                    <div id="accordion2-2" class="collapse"
                                       data-parent="#accordion2">
                                    <div class="card-body">
                                    <table id="report-table"
                                       class="table table-bordered table-striped mb-0">
                                    <tbody>
                                    <tr>
                                    <th width="10">
                                    <input type="checkbox"
                                       name="ChkBlood"
                                       value="1"
                                       <?php if($row7['ChkBlood'] == '1'){?>
                                       checked <?php } ?>
                                       style="transform: scale(2);margin-left: 10px;margin-right: 10px;" />
                                    Blood &nbsp;&nbsp;
                                    </th>
                                    <th width="500"><input
                                       type="text"
                                       class="form-control"
                                       name="TxtBlood"
                                       value="<?php echo $row7['TxtBlood'];?>"
                                       oninput="chkInvst('ChkBlood','TxtBlood')">
                                    </th>
                                    </tr>
                                    <tr>
                                    <th>
                                    <input type="checkbox"
                                       name="Eeg" value="1"
                                       <?php if($row7['Eeg'] == '1'){?>
                                       checked <?php } ?>
                                       style="transform: scale(2);margin-left: 10px;margin-right: 10px;" />
                                    EEG &nbsp;&nbsp;
                                    </th>
                                    <th width="200"><input
                                       type="text"
                                       class="form-control"
                                       name="TxtEeg"
                                       value="<?php echo $row7['TxtEeg'];?>"
                                       oninput="chkInvst('Eeg','TxtEeg')">
                                    </th>
                                    </tr>
                                    <tr>
                                    <th>
                                    <input type="checkbox"
                                       name="ChkCT" value="1"
                                       <?php if($row7['ChkCT'] == '1'){?>
                                       checked <?php } ?>
                                       style="transform: scale(2);margin-left: 10px;margin-right: 10px;" />
                                    CT Brain &nbsp;&nbsp;
                                    </th>
                                    <th width="200"><input
                                       type="text"
                                       class="form-control"
                                       name="TxtCT"
                                       value="<?php echo $row7['TxtCT'];?>"
                                       oninput="chkInvst('ChkCT','TxtCT')">
                                    </th>
                                    </tr>
                                    <tr>
                                    <th>
                                    <input type="checkbox"
                                       name="ChkMRI" value="1"
                                       <?php if($row7['ChkMRI'] == '1'){?>
                                       checked <?php } ?>
                                       style="transform: scale(2);margin-left: 10px;margin-right: 10px;" />
                                    MRI Brain &nbsp;&nbsp;
                                    </th>
                                    <th width="200"><input
                                       type="text"
                                       class="form-control"
                                       name="TxtMRI"
                                       value="<?php echo $row7['TxtMRI'];?>"
                                       oninput="chkInvst('ChkMRI','TxtMRI')">
                                    </th>
                                    </tr>
                                    <tr>
                                    <th>
                                    <input type="checkbox"
                                       name="ChkUSG" value="1"
                                       <?php if($row7['ChkUSG'] == '1'){?>
                                       checked <?php } ?>
                                       style="transform: scale(2);margin-left: 10px;margin-right: 10px;" />
                                    USG &nbsp;&nbsp;
                                    </th>
                                    <th width="200"><input
                                       type="text"
                                       class="form-control"
                                       name="TxtUSG"
                                       value="<?php echo $row7['TxtUSG'];?>"
                                       oninput="chkInvst('ChkUSG','TxtUSG')">
                                    </th>
                                    </tr>
                                    <tr>
                                    <th>
                                    <input type="checkbox"
                                       name="ChkOthers"
                                       value="1"
                                       <?php if($row7['ChkOthers'] == '1'){?>
                                       checked <?php } ?>
                                       style="transform: scale(2);margin-left: 10px;margin-right: 10px;" />
                                    Others &nbsp;&nbsp;
                                    </th>
                                    <th width="200"><input
                                       type="text"
                                       class="form-control"
                                       name="TxtOthers"
                                       value="<?php echo $row7['TxtOthers'];?>"
                                       oninput="chkInvst('ChkOthers','TxtOthers')">
                                    </th>
                                    </tr>
                                    </tbody>
                                    </table>
                                    </div>
                                    </div>
                                    </div>
                                    </div>
                                    </fieldset>
                                    </div>
                                    <div class="form-group col-md-12" style="margin-bottom: 0rem;">
                                    <fieldset>
                                    <legend>Treatment</legend>
                                    <div class="table-responsive">
                                    <?php include 'inctreatments.php'; ?>
                                    </div>
                                    </fieldset>
                                    </div>
                                    <div class="form-group col-md-12" style="margin-bottom: 0rem;">
                                    <fieldset>
                                    <legend>Language</legend>
                                    <table id="report-table"
                                       class="table table-bordered table-striped mb-0">
                                    <?php if($rncnt7 > 0){?>   
                                    <tbody>
                                    <tr>
                                    <th width="10">
                                    <input type="radio" name="Language"
                                       value="M"
                                       <?php if($row7['Language'] == 'M'){?>
                                       checked <?php } else {?>
                                       <?php } ?>
                                       style="transform: scale(2);margin-left: 10px;margin-right: 10px;" />
                                    Marathi &nbsp;&nbsp;
                                    </th>
                                    <th width="10">
                                    <input type="radio" name="Language"
                                       value="E"
                                       <?php if($row7['Language'] == 'E'){?>
                                       checked <?php } ?>
                                       style="transform: scale(2);margin-left: 10px;margin-right: 10px;" />
                                    English &nbsp;&nbsp;
                                    </th>
                                    <th width="10">
                                    <input type="radio" name="Language"
                                       value="H"
                                       <?php if($row7['Language'] == 'H'){?>
                                       checked <?php } ?>
                                       style="transform: scale(2);margin-left: 10px;margin-right: 10px;" />
                                    Hindi &nbsp;&nbsp;
                                    </th>
                                    </tr>
                                    </tbody>
                                 <?php } else {?>
<tbody>
                                    <tr>
                                    <th width="10">
                                    <input type="radio" name="Language"
                                       value="M" checked style="transform: scale(2);margin-left: 10px;margin-right: 10px;" />
                                    Marathi &nbsp;&nbsp;
                                    </th>
                                    <th width="10">
                                    <input type="radio" name="Language"
                                       value="E"
                                      
                                       style="transform: scale(2);margin-left: 10px;margin-right: 10px;" />
                                    English &nbsp;&nbsp;
                                    </th>
                                    <th width="10">
                                    <input type="radio" name="Language"
                                       value="H"
                                       
                                       style="transform: scale(2);margin-left: 10px;margin-right: 10px;" />
                                    Hindi &nbsp;&nbsp;
                                    </th>
                                    </tr>
                                    </tbody>


                                 <?php } ?>
                                    </table>
                                    </fieldset>
                                    </div>
                                    
                                    </div>
                                    <div class="col-lg-4">
                                    <div class="form-group col-md-12" style="margin-bottom: 0rem;">
                                    <fieldset>
                                    <legend>Instructions</legend>
                                    <div class="table-responsive" style="overflow-x:auto;">
                                    <table id="report-table"
                                       class="table table-bordered table-striped mb-0"
                                       width="100%">
                                    <tbody>
                                    <tr>
                                    <th width="113" style="font-size: 15px;">
                                    <input type="checkbox" name="Prognosis"
                                       value="1"
                                       <?php if($row7['Prognosis'] == '1'){?>
                                       checked <?php } ?> />
                                    Poor Prognosis &nbsp;&nbsp;
                                 <input type="checkbox" name="DSH"
                                       value="1"
                                       <?php if($row7['DSH'] == '1'){?>
                                       checked <?php } ?> />
                                    DSH Risk Informed to OD</th>
                                    </tr>
                                   
                                    <tr>
                                    <th width="146" style="font-size: 15px;">
                                    <input type="checkbox" name="FollowUp"
                                       value="1"
                                       <?php if($row7['FollowUp'] == '1'){?>
                                       checked <?php } ?> />
                                    Follow up with responsible relative</th>
                                    </tr>
                                    <tr>
                                    <th width="88" style="font-size: 15px;">
                                    <input type="checkbox" name="Irregular"
                                       value="1"
                                       <?php if($row7['Irregular'] == '1'){?>
                                       checked <?php } ?> />
                                    Irregular Treatment
                                    &nbsp;&nbsp;
                                     <input type="checkbox" name="Medication"
                                       value="1"
                                       <?php if($row7['Medication'] == '1'){?>
                                       checked <?php } ?> />
                                    Self Medication

                                 </th>
                                    </tr>
                                    
                                    <tr>
                                    <th width="111" style="font-size: 15px;">
                                    <input type="checkbox"
                                       name="StrictSupervision" value="1"
                                       <?php if($row7['StrictSupervision'] == '1'){?>
                                       checked <?php } ?> /> Maintain
                                    strict supervision on patients</th>
                                    </tr>
                                    <tr>
                                    <th width="300" style="font-size: 15px;">
                                    <input type="checkbox" name="Admission"
                                       value="1"
                                       <?php if($row7['Admission'] == '1'){?>
                                       checked <?php } ?> />
                                    Admission / Relatives not willing at
                                    present</th>
                                    </tr>
                                    </tbody>
                                    </table>
                                    </div>
                                    </fieldset>
                                    </div>
                                    <div class="form-group col-md-12" style="margin-bottom: 0rem;">
                                      <fieldset>
                                    <div class="table-responsive">
                                    <table id="report-table"
                                       class="table table-bordered table-striped mb-0">
                                    <tbody>
                                    <tr>
                                    <th width="113">
                                    <input type="checkbox" value="1"
                                       name="ChkPrevTreat"
                                       <?php if($row7['ChkPrevTreat'] == '1'){?>
                                       checked <?php } ?>> Previous
                                    Treatment
                                    </th>
                                    </tr>
                                    <tr>
                                    <th width="113">
                                    <!-- <textarea class="form-control"
                                       id="PrevTreatment"
                                       name="PrevTreatment"
                                       style="height: 65px;"><?php echo $row7['PrevTreatment'];?></textarea> -->
                                       <input type="text" id="PrevTreatment"
                                       name="PrevTreatment" value="<?php echo $row7['PrevTreatment'];?>" list="prevtreat" class="form-control" oninput="ShortPtName33('PrevTreatment')">
                                       <!-- <datalist id="prevtreat">
                                          <?php 
                                          $sql_11 = "SELECT DISTINCT(PrevTreatment) AS PrevTreatment FROM tbl_consultant";
                                          $row_11 = getList($sql_11);
                                          foreach($row_11 as $result){?>
                                          <option value="<?php echo $result['PrevTreatment'];?>">
                                          <?php } ?>
                                       </datalist> -->
                                    </th>
                                    </tr>
                                    </tbody>
                                    </table>
                                    </div>
                                    </fieldset> 
                                     <fieldset>
                                    <div class="table-responsive">
                                    <table id="report-table"
                                       class="table table-bordered table-striped mb-0">
                                    <tbody>
                                    <tr>
                                    <th width="113">
                                     <input type="checkbox" value="1"
                                       name="ChkSpecialNote"
                                       <?php if($row7['ChkSpecialNote'] == '1'){?>
                                       checked <?php } ?>> Special Note</th>
                                    </tr>
                                    <tr>
                                    <th width="113">
                                    <textarea class="form-control"
                                       id="SpecialNote"
                                       name="SpecialNote" oninput="ShortPtName33('SpecialNote')"><?php echo $row7['SpecialNote'];?></textarea> 

                                       <!--  <input type="text" id="SpecialNote"
                                       name="SpecialNote" value="<?php echo $row7['SpecialNote'];?>" list="spnote" class="form-control">
                                       <datalist id="spnote">
                                          <?php 
                                          $sql_12 = "SELECT DISTINCT(SpecialNote) AS SpecialNote FROM tbl_consultant";
                                          $row_12 = getList($sql_12);
                                          foreach($row_12 as $result){?>
                                          <option value="<?php echo $result['SpecialNote'];?>">
                                          <?php } ?>
                                       </datalist> -->
                                    </th>
                                    </tr>
                                    </tbody>
                                    </table>
                                    </div>
                                   
                                    <div class="table-responsive">
                                    <table id="report-table"
                                       class="table table-bordered table-striped mb-0">
                                    <tbody>
                                    <tr>
                                       <th style="width: 115px;">Duration</th>
                                    <th>
                                    Follow up Date</th>
                                    </tr>
                                    <tr>
                                       <th><input type="number" class="form-control" id="Duration"
                                       name="Duration" placeholder=""
                                       value="<?php echo $Duration;?>"
                                       oninput="findFollowDate()" required></th>
                                    <th>
                                    <input
                                       onchange="checkFollowDate(this.value)"
                                       type="date" class="form-control"
                                       name="FollowUpDate"
                                       id="FollowUpDate"
                                       value="<?php echo $row7['FollowUpDate'];?>"
                                       required>
                                    
                                    </th>
                                    </tr>
                                    <tr>
                                       <th colspan="2">
                                    <span id="followcheck"
                                       style="color:red;"></span>
                                    </th>
                                 </tr>
                                    </tbody>
                                    </table>
                                    </div>
                                    </fieldset>
                                    <fieldset>
                                    <div class="table-responsive">
                                    <table id="report-table"
                                       class="table table-bordered table-striped mb-0">
                                    <tbody>
                                    <tr>
                                    <th width="113" colspan="2">
                                    <input type="checkbox" value="1"
                                       name="ChkDiagnosis"
                                       <?php if($row7['ChkDiagnosis'] == '1'){?>
                                       checked <?php } ?>> Diagnosis</th>
                                    </tr>
                                    <tr>
                                    <th width="350" colspan="1">
                                        <input type="text" id="Diagnosis"
                                       name="Diagnosis" value="<?php echo $row7['Diagnosis'];?>" list="diagnosislist" class="form-control">
                                       <datalist id="diagnosislist">
                                          <?php 
                                          $sql_11 = "SELECT DISTINCT(Diagnosis) AS Diagnosis FROM tbl_consultant";
                                          $row_11 = getList($sql_11);
                                          foreach($row_11 as $result){?>
                                          <option value="<?php echo $result['Diagnosis'];?>">
                                          <?php } ?>
                                       </datalist> 
                                 <!--    <textarea class="form-control"
                                       id="Diagnosis"
                                       name="Diagnosis"><?php echo $row7['Diagnosis'];?></textarea> -->
                                    </th>
                                  <!--   <th>
                                    <span class="input-group-append">
                                    <button class="btn btn-secondary"
                                       type="button"
                                       data-toggle="modal"
                                       data-target="#modal-report"
                                       id="add_button"
                                       onclick="getValue('Diagnosis','Diagnosis')">...</button>
                                    </span>
                                    </th> -->
                                    </tr>
                                    </tbody>
                                    </table>
                                    </div>
                                    </fieldset>
                                    <fieldset>
                                    <div class="table-responsive">
                                    <table id="report-table"
                                       class="table table-bordered table-striped mb-0">
                                    <tbody>
                                    <tr>
                                    <th width="113">
                                    <input type="checkbox" value="1"
                                       name="ChkAdvice"
                                       <?php if($row7['ChkAdvice'] == '1'){?>
                                       checked <?php } ?>> Advised</th>
                                    </tr>
                                    <tr>
                                    <th width="113">
                                   <!--  <textarea class="form-control"
                                       id="Remark" name="Remark"
                                       style="height: 76px;"><?php echo $row7['Remark'];?></textarea> -->

                                       <input type="text" id="Remark"
                                       name="Remark" value="<?php echo $row7['Remark'];?>" list="rmk" class="form-control" oninput="ShortPtName33('Remark')">
                                       <!-- <datalist id="rmk">
                                          <?php 
                                          $sql_12 = "SELECT DISTINCT(Remark) AS Remark FROM tbl_consultant";
                                          $row_12 = getList($sql_12);
                                          foreach($row_12 as $result){?>
                                          <option value="<?php echo $result['Remark'];?>">
                                          <?php } ?>
                                       </datalist> -->

                                    </th>
                                    </tr>
                                    </tbody>
                                    </table>
                                    </div>
                                    </fieldset>
                                    
                                    <fieldset>
                                    <div class="col-sm-12 sub_btn" style="padding-top:10px;">
                                        <input type="checkbox" value="1"
                                       name="NameUnder"
                                       <?php if($row7['NameUnder'] == '1'){?>
                                       checked <?php } ?>> PNB<br><br>
                                    <button class="btn btn-success" type="submit" name="submit"
                                       id="submit">Save </button>
                                    <button class="btn btn-danger" type="button"
                                       onclick="deleteRecord()">Delete</button>
                                    <button class="btn btn-info" type="button" onclick="printOpd()"
                                       id="print">Print</button>
                                    </div>
                                    </fieldset>
                                   
                                    </div>
                                    </div>
                                    </div>
                                 </div>
                                 <!-- Close Tab 1-->
                                 <div class="tab-pane fade" id="navs-wc-summary">
                                 <?php include 'opd-patient-summary.php';?>
                                 </div>
                                 <!-- Open Tab 2 -->
                              </div>
                           </div>
                        </div>
                     </div>
               </div>
            </div>
            </form>
            
         </div>
      </div>
      </div>
      <!-- [ Layout content ] Start -->
      </div>
      <!-- [ Layout container ] End -->
      </div>
      <!-- Overlay -->
      <div class="layout-overlay layout-sidenav-toggle"></div>
      </div>
      <!-- [ Layout wrapper] End -->
      <!-- Modal -->
      <?php include_once 'footer_script.php';include 'inccommonmodal.php';?>
      <script>
            function ShortPtName33(val){
            var ShortKey = $('#'+val).val();
              var action = "checkShortKey";
                  $.ajax({
                     type: "POST",
                     url: "ajax_files/ajax_patients.php",
                     data: {
                        action: action,
                        TreatName: ShortKey
                     },
                     success: function(data) {
                        var res = JSON.parse(data);
                        var Status = res.Status;
                        var TreatName = res.TreatName;
                        if (Status == 1) {
                           $('#'+val).val(TreatName);
                        } else {}
                    }
              });
         }
         $('.datalist').on('click', function() {
             $(this).val('');
         });
         

         function deleteRecord() {
             var MrdNo = $('#MrdNo').val();
             var VisitDate = $('#VisitDate2').val();
             var action = 'deleteRecord';
               if(confirm("Are you sure?")){
             $.ajax({
                 type: "POST",
                 url: "ajax_files/ajax_opto_form.php",
                 data: {
                     action: action,
                     MrdNo: MrdNo,
                     VisitDate: VisitDate
                 },
                 success: function(data) {
                  //alert(data);exit();
                     alert('Record Deleted!');
                     window.location.href = 'patientdetailform.php';
                 }
             });
          }
         
         }
         
         function removeTreatment(name, freq) {
             $('#' + name).val('');
             $('#' + freq).val('');
         }
         
         function getValue(val, idval) {
             $('#ModalValue').val(val);
             $('#ValueId').val(idval);
             $('#OldValue').val('');
             desc_lists(val);
         }
         
         function checkFollowDate(val) {
             var action = 'checkFollowDate';
             $.ajax({
                 type: "POST",
                 url: "ajax_files/ajax_follow_date.php",
                 data: {
                     action: action,
                     val: val
                 },
                 success: function(data) {
                     if (data == '') {
                         $('#submit').attr("disabled", false);
                         $('#print').attr("disabled", false);
                         $('#followcheck').html(data);
                     } else {
                         $('#submit').attr("disabled", true);
                         $('#print').attr("disabled", true);
                         $('#followcheck').html(data);
                     }
         
                 }
             });
         }
         
         function getFnameCap(val) {
             const str = $('#' + val).val();
             const str2 = str.charAt(0).toUpperCase() + str.slice(1);
             $('#' + val).val(str2);
         }

         function getFnameCap2(val) {
             const str = $('#' + val).val();
             const str2 = str.toUpperCase();
             $('#' + val).val(str2);
         }
         
         
         function printOpd() {
             var MrdNo = $('#MrdNo').val();
             var VisitDate = $('#VisitDate').val();
         
             window.open(
                 'opd-print.php?mrd=' + MrdNo + '&visitdate=' + VisitDate, 'name',
                 'toolbar=1, scrollbars=1, location=1,statusbar=0, menubar=1, resizable=1, width=800, height=600'
             );
         }
         
         function pressTab(val) {
             if (val == 3) {
                 $('.sub_btn').hide();
             } else {
                 $('.sub_btn').show();
             }
         }
         
         function getConsultRec(val) {
             var MrdNo = $('#MrdNo').val();
             window.location.href = "patientdetailform.php?mrd=" + MrdNo + "&visitdate=" + val;
         }
         
         function findFollowDate() {
             var action = 'findFollowDate';
             var Duration = $('#Duration').val();
         
             $.ajax({
                 type: "POST",
                 url: "ajax_files/ajax_opto_form.php",
                 data: {
                     action: action,
                     Duration: Duration
                 },
                 success: function(data) {
                     //alert(data);
                     var res = JSON.parse(data);
                     var Status = res.Status;
                     var Followdate = res.FollowDate;
                     if (Status == 0) {
                         $('#submit').attr("disabled", true);
                         $('#print').attr("disabled", true);
                         $('#followcheck').html('Sunday Holiday');
                         $('#FollowUpDate').val(Followdate);
                     } else {
                         $('#FollowUpDate').val(Followdate);
                         checkFollowDate(Followdate);
                         $('#submit').attr("disabled", false);
                         $('#print').attr("disabled", false);
         
         
                     }
         
         
                 }
             });
         }
         $(document).ready(function() {
            $('#MrdNo').focus();
            $('#MrdNo').select();
             $('#add_more').click(function() {
                 var action = 'addMore';
                 $.ajax({
                     type: "POST",
                     url: "ajax_files/ajax_treatments.php",
                     data: {
                         action: action
                     },
                     success: function(data) {
                         $('#dynamic_field').append(data);
                     }
                 });
             });
         
             $(document).on('click', '.btn_remove', function() {
                 var button_id = $(this).attr("id");
         
                 $('#row' + button_id + '').remove();
         
             });
         });
      </script>
      <script>
         //Get the button
         var mybutton = document.getElementById("myBtn");
         
         // When the user scrolls down 20px from the top of the document, show the button
         window.onscroll = function() {
             scrollFunction()
         };
         
         function scrollFunction() {
             if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
                 mybutton.style.display = "block";
             } else {
                 mybutton.style.display = "none";
             }
         }
         
         // When the user clicks on the button, scroll to the top of the document
         function topFunction() {
             document.body.scrollTop = 0;
             document.documentElement.scrollTop = 0;
         }
      </script>
   </body>
</html>