@include('header')
@php
$UserId = Session::get('UserId');
@endphp
<style type="text/css">
fieldset legend {
    background: inherit;
    font-family: "Lato", sans-serif;
    color: #650812;
    font-size: 15px;
    left: 10px;
    padding: 0 10px;
    position: absolute;
    top: -12px;
    font-weight: 400;
    width: auto !important;
    border: none !important;
}

fieldset {
    background: #ffffff;
    border: 1px solid #C43853;
    border-radius: 5px;
    margin: 20px 0 1px 0;
    padding: 25px;
    position: relative;
}

.form-control {
    min-height: 1px;
    height: 25px;
}

.table th,
.table td {
    padding: 0.325rem;
}

.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: 1px;
    padding-left: 6px;
}
</style>
<div class="container-fluid flex-grow-1 container-p-y">
    <!-- <h4 class="font-weight-bold py-3 mb-0">Add O.T. Notes</h4> --><br>
    <form id="validation-form" novalidate="novalidate" method="POST" enctype="multipart/form-data" autocomplete="off"
        action="">
        <input type="hidden" name="action" id="actionvalue" value="{{$actionval}}">
        <input type="hidden" name="saveid" id="saveid" value="{{$data[0]->id}}">
        <input type="hidden" name="CounselingId" id="CounselingId" value="{{$data[0]->CounselingId}}">
        <input type="hidden" name="IpdNo" id="IpdNo" value="{{$data[0]->IpdNo}}">
        
        @csrf

        <div class="row">

         

            <div class="col-md-12">
                <div class="card mb-12 mb-1">
                    <div class="card-body" style="padding: 12px;">
                        <table class="table table-bordered table-striped mb-0">
                            <thead>
                                <tr>
                                    
                                    <th>MrdNo</th>
                                    <th width="30" align="center" valign="top" colspan="2">Patient Name </th>
                                    <th width="30" align="center" valign="top">Age </th>
                                    <th width="30" align="center" valign="top">Gender </th>
                                    <th width="30" align="center" valign="top" colspan="2">Address</th>
                                    <th width="30" align="center" valign="top">Mobile No</th>

                                </tr>

                                <tr>

                                   
                                    <th width="50" align="center" valign="top"><input type="text" class="form-control"
                                            placeholder="" id="MrdNo" name="MrdNo" value="{{$data[0]->MrdNo}}" readonly>
                                        <div class="clearfix"></div>
                                    </th>

                                    <th width="150" align="center" valign="top" colspan="2"><input type="text" class="form-control"
                                            placeholder="" name="PatientName" id="PatientName" value="{{$data[0]->PatientName}}" required>
                                        <div class="clearfix"></div>
                                    </th>

                                    <th width="20" align="center" valign="top"><input type="text" class="form-control"
                                            placeholder="" id="Age" name="Age" value="{{$data[0]->Age}}" required>

                                    <th width="20" align="center" valign="top"><input type="text" class="form-control"
                                                placeholder="" id="Gender" name="Gender" value="{{$data[0]->Gender}}" required>    

                                    <th width="180" align="center" valign="top" colspan="2"><input type="text" class="form-control"
                                            placeholder="" id="Address" name="Address" value="{{$data[0]->Address}}">
                                        <div class="clearfix"></div>
                                    </th>
                                    <th width="80" align="center" valign="top"><input type="text" class="form-control"
                                            placeholder="" id="Phone" name="Phone" value="{{$data[0]->Phone}}">
                                        <div class="clearfix"></div>
                                    </th>
      
                                   
                                </tr>

                                <tr style="padding-top: 7px;">
                              
                                  
                                    <th width="50" align="center" valign="top">Date of Admission </th>
                                    <th width="50" align="center" valign="top"><input type="date" name="AdmissionDate"
                                            class="form-control" id="AdmissionDate" value="{{$data[0]->AdmissionDate}}">
                                    </th>

                                    <th width="20" align="center" valign="top">Date of Operation </th>
                                    <th width="50" align="center" valign="top"><input type="date" name="SurgeryDate"
                                            id="SurgeryDate" class="form-control" value="{{$data[0]->SurgeryDate}}">
                                    </th>
                                    <th width="20" align="center" valign="top">Date of Discharge </th>
                                    <th width="50" align="center" valign="top"><input type="date" name="DischargeDate"
                                            class="form-control" id="DischargeDate" value="{{$data[0]->DischargeDate}}">
                                    </th>

                                    {{-- <th width="20" align="center" valign="top">Site RE/LE/BE </th>
                                    <th width="50" align="center" valign="top">
                                        <select class="form-control" id="Eye" name="Eye" style="height:30px;">
                                            <option value="" selected>...</option>
                                            <option value="RE" <?php if($data[0]->Eye == 'RE'){?> selected <?php } ?>>RE</option>
                                            <option value="LE" <?php if($data[0]->Eye == 'LE'){?> selected <?php } ?>>LE</option>
                                            <option value="BE" <?php if($data[0]->Eye == 'BE'){?> selected <?php } ?>>BE</option>
                                        </select> 
                                      
                                    </th> --}}
                                   
                                </tr>

                            </thead>
                            <tbody>
                            </tbody>
                        </table>

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



        </div>

        <div class="row">
            <div class="col-md-12">
                <div class="row">
                    <div class="col-md-6">
                        <fieldset>
                            <legend>Diagnosis</legend>
                            <div class="row">
                                <div class="col-lg-11">
                                    <div class="form-group">
                                        <textarea class="form-control" placeholder="Search for..." name="Diagnosis"
                                            id="Diagnosis">{{$data[0]->Diagnosis}}</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('Diagnosis','Diagnosis')">...</button>
                                    </span>
                                </div>
                            </div>

                        </fieldset>
                    </div>

                    <div class="col-md-6">
                        <div class="col-md-12">
                            <fieldset>
                                <legend>Surgery</legend>
                                <div class="row">
                                    <div class="col-lg-11">
                                        <div class="form-group">
                                            <textarea class="form-control" placeholder="Search for..." name="Surgery"
                                                id="Surgery">{{$data[0]->Surgery}}</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('Surgery','Surgery')">...</button>
                                        </span>
                                    </div>
                                </div>
    


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

                <div class="row">
                    <div class="col-md-6">
                        <div class="col-md-12">
                            <fieldset style="height: 240px;">
                                <legend>Surgery Notes</legend>
                                <div class="row">
                                    <div class="col-lg-9">
                                        <select class="form-control" style="height: 35px;" id="CmbPlanOfMang" name="CmbPlanOfMang"
                                            onchange="getSpecInstDetails(this.value,'SurgeryNote')">
                                            <option value="">...</option>
                                            @foreach($pomspecinstList as $result)
                                            <option value="{{$result->Name}}">{{$result->Name}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                   
                                </div>
                                <div class="row" style="padding-top:10px;">
                                    <div class="col-lg-11"><textarea class="form-control" id="SurgeryNote" name="SurgeryNote"
                                            style="height: 160px;">{{$data[0]->SurgeryNote}}</textarea>
                                    </div>
                                     <div class="col-lg-1" style="padding-left: 20px;"><span class="input-group-append"><button class="btn btn-secondary"
                                                type="button" data-toggle="modal" data-target="#modal-report-inst"
                                                onclick="addNewSpecInst('CmbPlanOfMang','SurgeryNote')">+</button></span>
                                                </div>
                                                {{-- <div class="col-lg-1" style="padding-left: 1px;">
                                                <span class="input-group-append"><button class="btn btn-secondary"
                                                type="button" data-toggle="modal" data-target="#modal-report" id="add_button"
                                                onclick="getValue('SurgeryNote','SurgeryNote')">...</button></span>
                                    </div> --}}
                                    
                                </div>

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

                    <div class="col-md-6">
                        <fieldset>
                            <legend></legend>
                            <div class="col-sm-12">
                                <button class="btn btn-primary" id="submit" type="submit" name="submit">Save</button>
                               <button class="btn btn-success" onclick="printOt()" id="printbtn" type="button"
                                    >Print</button> 
                                
                            </div>
                        </fieldset>
                    </div>

                    
                    <div>
                        <div>


                        </div>

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

<input type="hidden" id="CurrDate" value="{{date('Y-m-d')}}">






</form>
</div>
</div>
</div>
<!-- [ Layout content ] Start -->

</div>
<!-- [ Layout container ] End -->

</div>
<!-- Overlay -->

<div class="layout-overlay layout-sidenav-toggle"></div>
</div>
<script src="{{url('assets/js/jquery-3.6.0.min.js')}}"></script>
@include('masters/inccommonmodal')
@include('masters/incspecinstmodal')
@include('footerscript')
<script>
$('.datalist').on('click', function() {
    $(this).val('');
});
function addNewSpecInst(idval, type) {
        $('#specinstaction').val('Save');
        $('#specinstid').val('');
        $('#SpecInstName').val('');
        $('#SpecInstDetails').val('');
        $('#specinstcmbid').val(idval);
        $('#SpecInstType').val(type).attr("selecetd", true);
        $('#specinstbtn').text("Save");
        $('#specinsttitle').html(
            "Add <span class='font-weight-light'>New</span>");
        specinstlists(idval, type);

    }
function specinstlists(idval, type) {
        $.ajax({
            url: "{{ url('viewSpecInstList') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}',
                Type: type
            },
            success: function(data) {
                //console.log(data);
                $('#specinstcustresult').html(data);
            }
        });
    }

    function saveSpecInst() {
        var SpecInstName = $('#SpecInstName').val();
        var SpecInstDetails = $('#SpecInstDetails').val();
        var SpecInstType = $('#SpecInstType').val();
        var action = $('#specinstaction').val();
        var id = $('#specinstid').val();
        $.ajax({
            url: "{{ url('saveSpecInst') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}',
                SpecInstName: SpecInstName,
                SpecInstDetails: SpecInstDetails,
                SpecInstType: SpecInstType,
                action: action,
                id: id
            },
            beforeSend: function() {
                $('#specinstbtn').attr('disabled', 'disabled');
                $('#specinstbtn').text('Please Wait...');
            },
            success: function(data) {

                $('#modal-report-inst').modal('hide');
                $('#specinstaction').val('Save');
                $('#specinstid').val('');
                $('#specinstbtn').attr('disabled', false);
                $('#specinstbtn').text('Submit');
                specInst_List();

                //window.location.href = "/{{projectUrl()}}optoform/" + MrdNo + "/" + VisitDate + "/" + VisitNo + "?page=consult";  

            }
        });
    }

    function specInst_List() {
        var idval = $('#specinstcmbid').val();
        var Type = $('#SpecInstType').val();
        $.ajax({
            url: "{{ url('saveSpecInstList') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}',
                Type: Type
            },
            success: function(data) {
                $('#' + idval).html(data);

            }
        });
    }

    function getSpecInstDetails(val, detailsid) {
       
       if (val == '') {
           $('#' + detailsid).val('');
       }
       $.ajax({
           url: "{{ url('getSpecInstDetails') }}",
           method: "POST",
           data: {
               _token: '{{csrf_token()}}',
               val: val
           },

           success: function(data) {
               //console.log(data);
               if (val != '') {
                   $('#' + detailsid).val(data);
               } else {
                   $('#' + detailsid).val('');
               }

           }
       });
   }
   
function printOt() {
    var id = $('#saveid').val();
    setTimeout(function() {
        window.open(
            '/{{projectUrl()}}printOtNotesOther/' + id, 'popUpWindow2',
            'height=1000,width=800,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
        );
    }, 1);
}

function getValue(val, idval) {
    $('#ModalValue').val(val);
    $('#ValueId').val(idval);
    $('#OldValue').val('');
    desc_lists(val);
}



function success_toast() {
    var isRtl = $('body').attr('dir') === 'rtl' || $('html').attr('dir') === 'rtl';
    $.growl.notice({
        title: 'Success',
        message: 'Record Saved Successfully!',
        location: isRtl ? 'tl' : 'tr'
    });
}
$(document).ready(function() {
    $('#validation-form').on('submit', function(e) {
        e.preventDefault();
        if ($('#validation-form').valid()) {
            $.ajax({
                url: "{{ url('saveOtNotesOther') }}",
                method: "POST",
                data: new FormData(this),
                contentType: false,
                processData: false,
                beforeSend: function() {
                    $('#submit').attr('disabled', 'disabled');
                    $('#submit').text('Please Wait...');
                },
                success: function(data) {
                    success_toast();
                    $('#actionvalue').val('Edit');
                    $('#saveid').val(data);
                    $('#printbtn').attr("disabled", false);
                    $('#discbtn').attr("disabled", false);
                    $('#billbtn').attr("disabled", false);
                    $('#receiptbtn').attr("disabled", false);
                    $('#submit').attr('disabled', false);
                    $('#submit').text('Submit');
                }
            });
        }

    });


    $(document).on("shown.bs.modal", "#modal-report", function() {
        $('#search_text77').focus();
    });

    $(document).on("click", ".updatespecinst", function(event) {
            event.preventDefault();
            event.stopPropagation();
            var id = $(this).attr("data-id");
            var action = "fetch_record";
            $.ajax({
                url: "{{ url('editSpecInst') }}",
                method: "POST",
                data: {
                    _token: '{{csrf_token()}}',
                    id: id
                },
                dataType: "json",
                success: function(data) {
                    //console.log(data);
                    $('#SpecInstName').val(data.Name);
                    $('#SpecInstType').val(data.Type).attr("selected", true);
                    $('#SpecInstDetails').val(data.Details)
                    $('#specinstaction').val('Edit');

                    $('#specinstid').val(id);
                    $('#specinstbtn').text("Update");
                    $('#modal-report-inst').modal('show');
                    $('.modal-title').html(
                        "Update <span class='font-weight-light'>Record</span>");

                }
            });
        });



        $(document).on("click", ".deletespecinst", function(event) {
            event.preventDefault();
            var id = $(this).attr("data-id");
            var action = "delete";
            var idval = $('#specinstcmbid').val();
            var type = $('#SpecInstType').val();
            //alert(id);
            swal({
                title: "Are you sure?",
                text: "You will not be able to recover this Record!",
                type: "warning",
                showCancelButton: true,
                confirmButtonClass: "btn-danger",
                confirmButtonText: "Yes, delete",
                cancelButtonText: "No, cancel",
                closeOnConfirm: false,
                closeOnCancel: false
            }, function(isConfirm) {
                if (isConfirm) {
                    $.ajax({
                        url: "{{ url('deleteSpecInst') }}",
                        method: "POST",
                        data: {
                            _token: '{{csrf_token()}}',
                            id: id
                        },

                        success: function(data) {
                            swal("Deleted!", "Record has been deleted.", "success");

                            addNewSpecInst(idval, type);
                            specInst_List();

                        }
                    });

                } else {
                    swal("Cancelled", "Record is safe :)", "error");
                }
            });


        });

});
</script>