<?php 
require_once("Connections/courier.php");
require_once("functions/functions.php");
list($id, $process_claim_no) = explode("@@@", $_POST['id']);
$query_rsodest_patient = "SELECT *, DATE_FORMAT(dateofbirth, '%D %b %Y') as datenew, (DATE_FORMAT(current_date, '%Y') - DATE_FORMAT(dateofbirth, '%Y') - (DATE_FORMAT(current_date, '00-%m-%d') < DATE_FORMAT(dateofbirth, '00-%m-%d'))) AS age FROM patient_information where id='$id'";
$rsodest_patient = mysql_query($query_rsodest_patient, $courier) or die(mysql_error());
$row_rsodest_patient = mysql_fetch_assoc($rsodest_patient);

$MEMBERSHIPID=$row_rsodest_patient['id'];
$patient_no=$row_rsodest_patient['card_number'];
$PROVIDERID=$_SESSION['provider_id'];
$type_of_client=$row_rsodest_patient['type_of_client'];
$_SESSION['client_type']=$type_of_client;

$query_rsodest_claim_no = "select * from process_claim_no where process_claim_no='$process_claim_no'";
$rsodest_claim_no = mysql_query($query_rsodest_claim_no, $courier) or die(mysql_error());
$row_rsodest_claim_no = mysql_fetch_assoc($rsodest_claim_no);
$totalRows_rsodest_claim_no = mysql_num_rows($rsodest_claim_no);
$mode_of_payment = $row_rsodest_claim_no['mode_of_payment'];
$visit_status = $row_rsodest_claim_no['patient_status'];

$patient_lens_type = mysql_fetch_assoc(mysql_query("SELECT lens_type FROM patient_lens_type WHERE process_claim_no='$process_claim_no'"));
$optical_info_query = mysql_query("SELECT * FROM optical_examination WHERE process_claim_no ='$process_claim_no'", $courier);
$optical_info_query_2 = mysql_query("SELECT * FROM optical_examination WHERE process_claim_no <> '$process_claim_no' AND patient_id='$id'", $courier);
// echo $process_claim_no;
?>

<form name="form" role="form">
    <div class="portlet light bordered">
<div class="portlet-title">
            <div style="cursor:pointer;" class="caption" onclick="$('#click_show_diagnostics').trigger('click');">
                <span class="caption-subject font-blue-madison bold uppercase"> <i class="fa fa-dollar"></i> Client Bills - <?php echo $process_claim_no; ?> <?php if($row_rsodest_claim_no['insurance_claim_no']){ ?>&nbsp;|&nbsp;Claim No: <?php echo $row_rsodest_claim_no['insurance_claim_no']; } ?> </span>
            </div>
            <div class="tools">
                <a id="click_show_diagnostics" href="" class="collapse" data-original-title="" title=""> </a>
            </div>
        </div>
        <div class="portlet-body">
            <div class="row">
             <?php if($visit_status=='In Use'){ ?>   
                <div class="col-md-4 ">
                    <div class="portlet light bordered">
                        <div class="portlet-title">
                            <div class="caption">
                               <div class="row">
                                           <div class="col-md-12">
                                               <div class="col-md-7 col-sm-8 col-xs-12">
            <input type="text" name="searchtext_query_item_name" id="searchtext_query_item_name" onkeyup=" MainsearchItemsName('search_view_items_added','#view_items_response_wrapper',this.value);" class="form-control input-circle" placeholder="Item Name" autofocus>
                                               </div>
                                               <div class="col-md-5 col-sm-4 col-xs-12">
                                                    <input type="hidden" id="replacement_item_id" name="replacement_item_id">
                                                   <input type="hidden" name="mode_of_payment" id="mode_of_payment" value="<?php echo $mode_of_payment; ?>"> 
                                                   <input type="hidden" name="process_claim_no" id="mode_of_payment" value="<?php echo $process_claim_no; ?>"> 
                                                   <select name="mode_of_payment_all" id="mode_of_payment_all" class="form-control input-circle" onchange="MainsearchItemsName('search_view_items_added','#view_items_response_wrapper',this.value);">
                                                        <option value="cash" <?php if($mode_of_payment=='CASH' || $mode_of_payment){echo "selected";}?>>CASH</option>
                                                       <?php if($mode_of_payment=='insurance'){?>
                                                        <option value="insurance" <?php if($mode_of_payment=='insurance'){echo "selected";}?>>INSURANCE</option>
                                                        <?php }?>
                                                        <?php if($mode_of_payment=='company'){?>
                                                        <option value="company" <?php if($mode_of_payment=='company'){echo "selected";}?>>COMPANY</option>
                                                        <?php }?>
                                                        <?php if($mode_of_payment=='staff'){?>
                                                        <option value="staff" <?php if($mode_of_payment=='staff'){echo "selected";}?>>STAFF</option>
                                                        <?php }?>
                                                        <option value="gratis" <?php if($mode_of_payment=='GRATIS'){echo "selected";}?>>GRATIS</option>
                                                        <option value="credit sales" <?php if($mode_of_payment=='GRATIS'){echo "selected";}?>>CREDIT SALES</option>
                                                        <option value="replacement" <?php if($mode_of_payment=='REPLACEMENT'){echo "selected";}?>>REPLACEMENT</option>
                                                        <option value="frame reserve" <?php if($mode_of_payment=='FRAME RESERVE'){echo "selected";}?>>FRAME RESERVE</option>
                                                    </select>
                                               </div>
                                           </div>
                              </div>
                            </div>
                        </div>
                        <div class="portlet-body" id="">
                            <div class="slimScrollDiv" style="height: 300px;overflow-y: scroll;overflow-x: hidden;">
                                <div class="" id="view_items_response_wrapper">                       
                                     <?php include('view_items_administrative.php'); ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

<?php } ?>

                <div class="col-md-<?php if($visit_status=='In Use'){ echo 8; }else{ echo 12; } ?> ">
                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a href="#tab_1_1" data-toggle="tab" aria-expanded="true"> CLIENT BILLING </a>
                        </li>
                        <li class="">
                            <a href="#tab_1_3" data-toggle="tab" aria-expanded="false">  LENS PRESCRIPTION </a>
                        </li>
                        <li class="">
                            <a href="#tab_1_5" data-toggle="tab" aria-expanded="false">  DR'S COMMENTS </a>
                        </li>
                        <li class="">
                            <a href="#tab_1_4" data-toggle="tab" aria-expanded="false">  FRAMES RESERVED </a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab_1_1">
                            <div class="portlet light bordered" style="min-height:194px;" id="view_items_response_wrapper_2">
                                <?php include ('view_items_claims_administrative.php'); ?>
                            </div>
                        </div>
                        <div class="tab-pane" id="tab_1_5">
                            <div class="portlet light bordered" style="min-height:194px;" id="">
                            <?php if($row_rsodest_claim_no['additional_note']!= ''){ ?>
                                        <?php echo $row_rsodest_claim_no['additional_note']; ?>
                                        <hr>
                            <?php } ?>
                                        <div class="row">
                                        <div class="demo-gallery">
                                            <ul id="lightgallery" class="list-unstyled row">
                                                <?php
                                                $all_drawings = mysql_query("SELECT * FROM consultation_drawings WHERE process_claim_no = '$process_claim_no' AND type='additional_comment' ORDER BY id ASC", $courier);
                                                $i = 1;
                                                while ($row = mysql_fetch_assoc($all_drawings)) {
                                                    ?>
                                                    <li class="col-xs-6 col-sm-4 col-md-3" data-responsive="consultation/<?php echo $row['drawing_name']; ?> 375, consultation/<?php echo $row['drawing_name']; ?> 480, consultation/<?php echo $row['drawing_name']; ?> 800" data-src="consultation/<?php echo $row['drawing_name']; ?>" data-sub-html="<h4>Consultation Note <?php echo $i; ?></h4><p>Attached Consultation Note</p>">
                                                        <a href="">
                                                            <img style="height:120px" class="img-responsive" src="consultation/<?php echo $row['drawing_name']; ?>">
                                                        </a>
                                                    </li>
                                                    <?php
                                                    $i++;
                                                }
                                                ?>
                                            </ul>
                                        </div>
                                    </div>
                            </div>
                        </div>

                            <div class="tab-pane" id="tab_1_3">
                                    <div class="row">
                                        <div class="col-md-12" id="all_prescription_wrapper">

                                <?php if($visit_status == 'In Use'){ ?>
                                        <div class="btn-group btn-group-devided pull-right" data-toggle="buttons">                             
                                    <label data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');" class="btn green btn-outline btn-circle btn-sm active">
                                            <input type="radio" name="options" class="toggle" id="option2"> Add Lens Prescription <i class="fa fa-plus"></i>
                                        </label>

                                    <label id="refresh_tn_lens_presc" onclick="getSimpleData('fetch_all_lens_prescription_front_desk', '<?php echo $_POST['id'];?>', '#all_prescription_wrapper_2');" class="btn red btn-outline btn-circle btn-sm active">
                                            <input type="radio" name="options" class="toggle" id="option2"> Refresh <i class="fa fa-refresh"></i>
                                        </label>
                                        <br>
                                </div>
                        <?php } ?>

<div id="all_prescription_wrapper_2">
                                         <?php if(mysql_num_rows($optical_info_query) > 0){ ?>
                                            <table class="table table-bordered">
                <tr>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                    <th style="text-align:center;"> Sphere </th>
                    <th style="text-align:center;"> Cylinder </th>
                    <th style="text-align:center;"> Axis </th>
                    <th style="text-align:center;"> VA </th>
                    <th style="text-align:center;"> Add </th>
                    <th style="text-align:center;"> VA </th>
                    <th style="text-align:center;"> PD </th>
                    <th style="text-align:center;"> TYPE </th>
                    <th style="text-align:center;"> LENS </th>
                    <th colspan="2" style="text-align:center;"> </th>
                </tr>
                <tbody>
                        <?php
                        $i=1;
                        while($optical_info = mysql_fetch_assoc($optical_info_query)){
                            $patient_lens_type = mysql_fetch_assoc(mysql_query("SELECT lens_type FROM patient_lens_type WHERE process_claim_no='".$optical_info['process_claim_no']."' AND lens_id_count='".$optical_info['lens_id_count']."'"));
                            ?>
                            <tr>
                                                                <td rowspan="2" data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php echo $i; ?></td>
                                                                <td data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');">RIGHT</td>
                                                                <td data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php echo $optical_info['od_sphere']; ?></td>
                                                                <td data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php echo $optical_info['od_cylinder']; ?></td>
                                                                <td data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php echo $optical_info['od_axis']; ?></td>
                                                                <td data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php echo $optical_info['od_va']; ?></td>
                                                                <td data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php echo $optical_info['od_add']; ?></td>
                                                                <td data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php echo $optical_info['od_va2']; ?></td>
                                                                <td data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php echo $optical_info['od_pd']; ?></td>
                                                                <td rowspan="2" style="text-align:center;" data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php getSightRead($process_claim_no,$optical_info['lens_id_count']); ?></td>
                                                                <td rowspan="2" data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');">
                                                                <div class="alert bold" id="">
                                                                    <span id="lens_description_wrapper"> </span>
                                                                    <span style="font-size:12px;font-weight:normal"> <?php
                                                                        $lens_addition = PatientLensAddition($process_claim_no,$optical_info['lens_id_count']);
                                                                        echo $patient_lens_type['lens_type']; echo ' '.$optical_info['lens_type'].' '; if(!empty($optical_info['lens_index'])){ echo '('.$optical_info['lens_index'].')';} if(!empty($lens_addition)){ ?> - Additions (<span id="lens_description_wrapper2"><?php echo $lens_addition; ?></span>) <?php } ?> </span>
                                                                 </div>
                                                                </td>
                                                                <td rowspan="2" data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');" style="text-align:center;"><i class="fa fa-pencil"></i></td>
                                                                <td rowspan="2" onclick="if(confirm('Delete this Lens Prescription?')){getSimpleData('delete_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');}" style="text-align:center;color:red;cursor:pointer"><i class="fa fa-trash"></i></td>
                                                            </tr>
                                                            <tr data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');">
                                                                <td>LEFT</td>
                                                                <td><?php echo $optical_info['os_sphere']; ?></td>
                                                                <td><?php echo $optical_info['os_cylinder']; ?></td>
                                                                <td><?php echo $optical_info['os_axis']; ?></td>
                                                                <td><?php echo $optical_info['os_va']; ?></td>
                                                                <td><?php echo $optical_info['os_add']; ?></td>
                                                                <td><?php echo $optical_info['os_va2']; ?></td>
                                                                <td><?php echo $optical_info['os_pd']; ?></td>
                                                            </tr>
                       <?php $i++; } ?>
                </tbody>
                </table>
                                         <?php } ?> 
                                        
                                         <?php if(mysql_num_rows($optical_info_query_2) > 0){ ?>
                                            <table class="table table-bordered">
                                            <tr>
                                                    <th colspan="20" style="text-align:center;">Lens Prescription History</th>
                                                </tr>
                <tr>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                    <th style="text-align:center;"> Sphere </th>
                    <th style="text-align:center;"> Cylinder </th>
                    <th style="text-align:center;"> Axis </th>
                    <th style="text-align:center;"> VA </th>
                    <th style="text-align:center;"> Add </th>
                    <th style="text-align:center;"> VA </th>
                    <th style="text-align:center;"> PD </th>
                    <th style="text-align:center;"> TYPE </th>
                    <th style="text-align:center;"> LENS </th>
                    <th colspan="2" style="text-align:center;"> </th>
                </tr>
                <tbody>
                        <?php
                        $i=1;
                        while($optical_info = mysql_fetch_assoc($optical_info_query_2)){
                            $patient_lens_type = mysql_fetch_assoc(mysql_query("SELECT lens_type FROM patient_lens_type WHERE process_claim_no='".$optical_info['process_claim_no']."' AND lens_id_count='".$optical_info['lens_id_count']."'"));
                            ?>
                            <tr>
                                                                <td rowspan="2" data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php echo $i; ?></td>
                                                                <td data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');">RIGHT</td>
                                                                <td data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php echo $optical_info['od_sphere']; ?></td>
                                                                <td data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php echo $optical_info['od_cylinder']; ?></td>
                                                                <td data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php echo $optical_info['od_axis']; ?></td>
                                                                <td data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php echo $optical_info['od_va']; ?></td>
                                                                <td data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php echo $optical_info['od_add']; ?></td>
                                                                <td data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php echo $optical_info['od_va2']; ?></td>
                                                                <td data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');"><?php echo $optical_info['od_pd']; ?></td>
                                                                <td rowspan="2" style="text-align:center;"><?php getSightRead($optical_info['process_claim_no'],$optical_info['lens_id_count']); ?></td>
                                                                <td rowspan="2" data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');">
                                                                <div class="alert bold" id="">
                                                                    <span id="lens_description_wrapper"> </span>
                                                                    <span style="font-size:12px;font-weight:normal"> <?php
                                                                        $lens_addition = PatientLensAddition($optical_info['process_claim_no'],$optical_info['lens_id_count']);
                                                                        echo $patient_lens_type['lens_type']; echo ' '.$optical_info['lens_type'].' '; if(!empty($optical_info['lens_index'])){ echo '('.$optical_info['lens_index'].')';} if(!empty($lens_addition)){ ?> - Additions (<span id="lens_description_wrapper2"><?php echo $lens_addition; ?></span>) <?php } ?> </span>
                                                                 </div>
                                                                </td>
                                                                <td rowspan="2" data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $optical_info['process_claim_no'].'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');" style="text-align:center;"><i class="fa fa-pencil"></i></td>
                                                                <td rowspan="2" onclick="if(confirm('Delete this Lens Prescription?')){getSimpleData('delete_lens_prescription', '<?php echo $optical_info['process_claim_no'].'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');}" style="text-align:center;color:red;cursor:pointer"><i class="fa fa-trash"></i></td>
                                                            </tr>
                                                            <tr data-toggle="modal" href="#large_lens" onclick="getSimpleData('get_lens_prescription', '<?php echo $process_claim_no.'_'.$optical_info['lens_id_count'] ?>', '#lens_prescription_wrapper');">
                                                                <td>LEFT</td>
                                                                <td><?php echo $optical_info['os_sphere']; ?></td>
                                                                <td><?php echo $optical_info['os_cylinder']; ?></td>
                                                                <td><?php echo $optical_info['os_axis']; ?></td>
                                                                <td><?php echo $optical_info['os_va']; ?></td>
                                                                <td><?php echo $optical_info['os_add']; ?></td>
                                                                <td><?php echo $optical_info['os_va2']; ?></td>
                                                                <td><?php echo $optical_info['os_pd']; ?></td>
                                                            </tr>
                       <?php $i++; } ?>
                </tbody>
                </table>
                                         <?php } ?> 
</div>

                                        </div>
                                    </div>
                            </div>

                                            <div class="tab-pane" id="tab_1_4">
                                                <?php include('patient_reserve_frames_list.php'); ?>
                                            </div>
                            </div>
                    </div>
                </div> 
        </div>
    </div>


<!-- /.modal -->
<div class="modal fade bs-modal-lg" id="large_lens" tabindex="-1" role="dialog" aria-hidden="true">
                                            <div class="modal-dialog modal-lg">
                                                <div class="modal-content" id="lens_prescription_wrapper">
                                                    
                                                   
                                                    <div class="modal-header">
                                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                                                        <!-- <h4 class="modal-title">Lens Prescription</h4> -->
                                                    </div>

                                                    <div class="modal-body"> </div>
                                                    

                                                </div>
                                            </div>
                                        </div>

</form>


<script type="text/javascript">
     $(document).ready(function(){
         $('#lightgallery').lightGallery({
             cssEasing: 'cubic-bezier(0.680, -0.550, 0.265, 1.550)'
           });
    });
</script>