<?php echo $__env->make('header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php
    $UserId = Session::get('UserId');
?>
<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: 10px 0 1px 0;
        padding: 7px;
        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;
    }

    .autocomplete-list {
        border: 1px solid #ccc;
        max-height: 150px;
        overflow-y: auto;
        position: absolute;
        background-color: white;
        z-index: 1000;
        width: 100%;
    }

    .autocomplete-item {
        padding: 8px;
        cursor: pointer;
    }

    .autocomplete-item:hover,
    .autocomplete-item.active {
        background-color: #98e6ed;
    }
</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="Save">
        <input type="hidden" name="saveid" id="saveid" value="">
        <?php echo csrf_field(); ?>

        <div class="row">

            <div class="col-md-3">
                <div class="card mb-12 mb-1">
                    <div class="card-body" style="padding: 21px;">
                        <label>Counselling Lists</label>
                        <input class="form-control" list="OtDataList" name="OtPatientId" id="OtPatientId"
                            onClick="this.select();">
                        <div id="autocomplete-list" class="autocomplete-list"
                            style="display: none; position: absolute;"></div>
                    </div>

                </div>
            </div>

            <div class="col-md-9">
                <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>OT Sch Id</th>-->
                                    <th>MrdNo</th>
                                    <th width="30" align="center" valign="top">Patient Name </th>
                                    <th width="30" align="center" valign="top">Age </th>
                                    <th width="30" align="center" valign="top">Phone</th>
                                    <th width="30" align="center" valign="top">Address</th>
                                    <!-- <th width="30" align="center" valign="top">OT Date</th>
                                    <th width="30" align="center" valign="top">Time</th>-->

                                </tr>

                                <tr>

                                    <!--<th width="50" align="center" valign="top"><input type="text" class="form-control"
                                            placeholder="" id="OTSchId" name="OtPatientId" value=""
                                            oninput="getPatientDetails()">
                                        <div class="clearfix"></div>
                                    </th>-->

                                    <th width="50" align="center" valign="top"><input type="text"
                                            class="form-control" placeholder="" id="MrdNo" name="MrdNo"
                                            value="" required oninput="getPatientDetails()">
                                        <div class="clearfix"></div>
                                    </th>

                                    <th width="80" align="center" valign="top"><input type="text"
                                            class="form-control" placeholder="" name="PatientName" id="PatientName"
                                            value="" readonly>
                                        <div class="clearfix"></div>
                                    </th>

                                    <th width="80" align="center" valign="top"><input type="text"
                                            class="form-control" placeholder="" id="Age" name="Age"
                                            value="" readonly>

                                    <th width="80" align="center" valign="top"><input type="text"
                                            class="form-control" placeholder="" id="Phone" name="Phone"
                                            value="" readonly>

                                    <th width="180" align="center" valign="top"><input type="text"
                                            class="form-control" placeholder="" id="Address" name="Address"
                                            value="" readonly>
                                        <div class="clearfix"></div>
                                    </th>
                                    <!-- <th width="80" align="center" valign="top"><input type="date" class="form-control"
                                            placeholder="" id="CreatedDate" name="CreatedDate" value="" required>
                                        <div class="clearfix"></div>
                                    </th>
                                    <th width="80" align="center" valign="top"><input type="text" class="form-control"
                                            placeholder="" id="CreatedTime" name="CreatedTime" value="" required>
                                        <div class="clearfix"></div>
                                    </th>-->
                                    <input type="hidden" name="Gender" id="Gender" value="">


                                </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></legend>
                            <div class="row">
                                <div class="col-sm-3">
                                    <div class="form-group">
                                        <label class="form-label" for="Name">Admission Dt<span
                                                class="text-danger">*</span></label>
                                        <input type="date" class="form-control" id="AdmissionDate"
                                            name="AdmissionDate" value="<?php echo e(date('Y-m-d')); ?>" placeholder=""
                                            required="">
                                    </div>
                                </div>

                                <div class="col-sm-3">
                                    <div class="form-group">
                                        <label class="form-label" for="Name">Counselling Dt <span
                                                class="text-danger">*</span></label>
                                        <input type="date" class="form-control" id="CounsellingDate"
                                            name="CounsellingDate" value="<?php echo e(date('Y-m-d')); ?>" placeholder=""
                                            required="">
                                    </div>
                                </div>

                                <div class="col-sm-3">
                                    <div class="form-group">
                                        <label class="form-label" for="Name">Surgery Dt <span
                                                class="text-danger">*</span></label>
                                        <input type="date" class="form-control" id="SurgeryDate"
                                            name="SurgeryDate" value="<?php echo e(date('Y-m-d')); ?>" placeholder=""
                                            required="">
                                    </div>
                                </div>

                                <div class="col-sm-3">
                                    <div class="form-group">
                                        <label class="form-label" for="Name">Eye <span
                                                class="text-danger">*</span></label>
                                        <select required class="form-control" id="Eye" name="Eye"
                                            style="height:30px;" onchange="addEye(this.value)">
                                            <option value="" selected>...</option>
                                            <option value="RE">RE</option>
                                            <option value="LE">LE</option>
                                            <option value="BE">BE</option>
                                        </select>

                                    </div>
                                </div>

                                <div class="col-sm-10">
                                    <div class="form-group">
                                        <label class="form-label" for="Name">Diagnosis <span
                                                class="text-danger">*</span></label>
                                        <textarea class="form-control" placeholder="Search for..." name="Diagnosis" id="Diagnosis"></textarea>

                                    </div>
                                </div>
                                <div class="col-sm-2">
                                    <span class="input-group-append">
                                        <button class="btn btn-secondary" type="button" data-toggle="modal"
                                            data-target="#modal-report" id="add_button"
                                            onclick="getValue('IpdDiagnosis','Diagnosis')">...</button>
                                    </span>
                                </div>

                                <div class="col-sm-10">
                                    <div class="form-group">
                                        <label class="form-label" for="Name">Surgery Name <span
                                                class="text-danger">*</span></label>
                                        <input type="text" class="form-control" style="width: 100%;height:35px;"
                                            id="SurgeryName" name="SurgeryName" placeholder="" required="">
                                    </div>
                                </div>
                                <div class="col-sm-2">
                                    <span class="input-group-append">
                                        <button class="btn btn-secondary" type="button" data-toggle="modal"
                                            data-target="#modal-report" id="add_button"
                                            onclick="getValue('SurgeryName','SurgeryName')">...</button>
                                    </span>
                                </div>



                                <div class="col-sm-4">
                                    <div class="form-group">
                                        <label class="form-label" for="Name">Surgeon Name <span
                                                class="text-danger">*</span></label>
                                        <select class="form-control txtbold" style="width: 100%;height:35px;"
                                            data-allow-clear="true" name="SurgeonName" id="SurgeonName">
                                            <option value="" selected>...</option>
                                            <?php $__currentLoopData = $consultantList; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $result): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($result->id); ?>"><?php echo e($result->Name); ?></option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </div>
                                </div>

                                <div class="col-sm-4">
                                    <div class="form-group">
                                        <label class="form-label" for="Name">Anaesthetist </label>

                                        <select class="form-control" id="Anaesthetist" name="Anaesthetist"
                                            style="height: 30px;">
                                            <option value="" selected>...</option>
                                            <option value="Yes">Yes</option>
                                            <option value="No">No</option>
                                            <!-- <option value="Dr. Sunil Patki">Dr. Sunil Patki</option>
                                            <option value="Dr. Ravi Khetan">Dr. Ravi Khetan</option> -->


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

                                

                                <div class="col-sm-3">
                                    <div class="form-group">
                                        <label class="form-label" for="Name">LA/GA <span
                                                class="text-danger">*</span></label>
                                        <select class="form-control" id="LaGa" name="LaGa"
                                            style="height: 30px;" required>
                                            <option value="" selected>...</option>
                                            <option value="LA">LA</option>
                                            <option value="GA">GA</option>

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

                                <div class="col-sm-3">
                                    <div class="form-group">
                                        <label class="form-label" for="Name">Counselling Done By <span
                                                class="text-danger">*</span></label>
                                        <input type="text" required class="form-control" id="CounsellingDoneBy"
                                            name="CounsellingDoneBy" placeholder="" required="">
                                    </div>
                                </div>

                                <div class="col-sm-3">
                                    <div class="form-group">
                                        <label class="form-label" for="Name">IOL </label>
                                        <input type="text" class="form-control" id="Iol" name="Iol"
                                            placeholder="">
                                    </div>
                                </div>

                                <div class="col-sm-3">
                                    <div class="form-group">
                                        <label class="form-label" for="Name">Diopter </label>
                                        <input type="text" class="form-control" id="Diopter" name="Diopter"
                                            placeholder="">
                                    </div>
                                </div>

                                <div class="col-sm-4">
                                    <div class="form-group">
                                        <label class="form-label" for="Name">IPD No </label>
                                        <input type="text" class="form-control" id="IpdNo" name="IpdNo"
                                            placeholder="" style="height: 30px;">
                                    </div>
                                </div>

                                <div class="col-sm-4">
                                    <div class="form-group">
                                        <label class="form-label" for="Name">Confirm for Surgery <span
                                                class="text-danger">*</span></label>
                                        <select required class="form-control" id="ConfirmSurgery"
                                            name="ConfirmSurgery" style="height: 30px;">
                                            <option value="" selected>...</option>
                                            <option value="Yes">Yes</option>
                                            <option value="No">No</option>

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

                                <div class="col-sm-4">
                                    <div class="form-group">
                                        <label class="form-label" for="Name">Surgery Charges <span
                                                class="text-danger">*</span></label>
                                        <input type="text" class="form-control" id="SurgeryCharges"
                                            name="SurgeryCharges" placeholder="" required=""
                                            style="height: 30px;">
                                    </div>
                                </div>

                                <!-- <div class="col-sm-4">
                            <div class="form-group">
                                <label class="form-label" for="Name">Notes  <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="Fname" name="Fname" placeholder="" required="">
                            </div>
                        </div>-->

                            </div>

                        </fieldset>
                    </div>

                    <div class="col-md-6">
                        <div class="col-md-12">
                            <fieldset>
                                <legend></legend>
                                <div class="row">


                                    <div class="col-sm-3">
                                        <div class="form-group">
                                            <label class="form-label" for="Name">Payment 1 </label>
                                            <input type="text" list="PaymentList" class="form-control"
                                                id="Payment1" name="Payment1" placeholder="">
                                            <datalist id="PaymentList">
                                                <option value="Cashless">
                                                <option value="MJPJAY">
                                                <option value="ECHS">
                                                <option value="BSNL">
                                                <option value="FCI">
                                            </datalist>
                                        </div>
                                    </div>

                                    <div class="col-sm-3">
                                        <div class="form-group">
                                            <label class="form-label" for="Name">Amount </label>
                                            <input type="text" class="form-control" id="Amount1" name="Amount1"
                                                placeholder="">
                                        </div>
                                    </div>

                                    <div class="col-sm-3">
                                        <div class="form-group">
                                            <label class="form-label" for="Name">Payment 2 </label>
                                            <input type="text" list="PaymentList" class="form-control"
                                                id="Payment2" name="Payment2" placeholder="">
                                        </div>
                                    </div>

                                    <div class="col-sm-3">
                                        <div class="form-group">
                                            <label class="form-label" for="Name">Amount </label>
                                            <input type="text" class="form-control" id="Amount2" name="Amount2"
                                                placeholder="">
                                        </div>
                                    </div>

                                    <div class="col-sm-3">
                                        <div class="form-group">
                                            <label class="form-label" for="Name">Payment 3 </label>
                                            <input type="text" list="PaymentList" class="form-control"
                                                id="Payment3" name="Payment3" placeholder="">
                                        </div>
                                    </div>

                                    <div class="col-sm-3">
                                        <div class="form-group">
                                            <label class="form-label" for="Name">Amount </label>
                                            <input type="text" class="form-control" id="Amount3" name="Amount3"
                                                placeholder="">
                                        </div>
                                    </div>

                                    <div class="col-sm-3">
                                        <div class="form-group">
                                            <label class="form-label" for="Name">NEFT </label>
                                            <input type="text" class="form-control" id="Payment4"
                                                name="Payment4" placeholder="">
                                        </div>
                                    </div>

                                    <div class="col-sm-3">
                                        <div class="form-group">
                                            <label class="form-label" for="Name">Amount </label>
                                            <input type="text" class="form-control" id="Amount4" name="Amount4"
                                                placeholder="">
                                        </div>
                                    </div>

                                    <div class="col-sm-12" style="padding-left: 20px;">
                                        <div class="form-group">
                                            <label class="form-check-inline">
                                                <input type="checkbox" class="form-check-input" name="payment_type1" id="payment_type1"
                                                    value="Cashless"> Cashless
                                            </label>
                                            <label class="form-check-inline">
                                                <input type="checkbox" class="form-check-input" name="payment_type2" id="payment_type2"
                                                    value="MJPJAY"> MJPJAY
                                            </label>
                                            <label class="form-check-inline">
                                                <input type="checkbox" class="form-check-input" name="payment_type3" id="payment_type3"
                                                    value="ECHS"> ECHS
                                            </label>
                                            <label class="form-check-inline">
                                                <input type="checkbox" class="form-check-input" name="payment_type4" id="payment_type4"
                                                    value="BSNL"> BSNL
                                            </label>
                                            <label class="form-check-inline">
                                                <input type="checkbox" class="form-check-input" name="payment_type5" id="payment_type5"
                                                    value="FCI"> FCI
                                            </label>
                                        </div>
                                    </div>



                                    <div class="col-lg-12" style="padding-right: 7px;padding-left: 11px;">
                                        <div class="form-group">
                                            <label class="form-label" for="Name">Remark / Special Instruction
                                            </label>
                                            <textarea class="form-control" placeholder="" name="Remarks" id="Remarks" style="height: 126px;"></textarea>

                                        </div>
                                    </div>


                                    <div class="col-sm-4">
                                        <div class="form-group">
                                            <label class="form-label" for="Name">Relative Name 1 <span
                                                    class="text-danger">*</span></label>
                                            <input required type="text" class="form-control" id="RelativeName1"
                                                name="RelativeName1" placeholder="">
                                        </div>
                                    </div>

                                    <div class="col-sm-4">
                                        <div class="form-group">
                                            <label class="form-label" for="Name">Relation <span
                                                    class="text-danger">*</span></label>
                                            <input required type="text" class="form-control" id="Relation1"
                                                name="Relation1" placeholder="">
                                        </div>
                                    </div>

                                    <div class="col-sm-4">
                                        <div class="form-group">
                                            <label class="form-label" for="Name">Contact No <span
                                                    class="text-danger">*</span> </label>
                                            <input required type="text" class="form-control" id="ContactNo1"
                                                name="ContactNo1" placeholder="">
                                        </div>
                                    </div>

                                    <div class="col-sm-4">
                                        <div class="form-group">
                                            <label class="form-label" for="Name">Relative Name 2 </label>
                                            <input type="text" class="form-control" id="RelativeName2"
                                                name="RelativeName2" placeholder="">
                                        </div>
                                    </div>

                                    <div class="col-sm-4">
                                        <div class="form-group">
                                            <label class="form-label" for="Name">Relation </label>
                                            <input type="text" class="form-control" id="Relation2"
                                                name="Relation2" placeholder="">
                                        </div>
                                    </div>

                                    <div class="col-sm-4">
                                        <div class="form-group">
                                            <label class="form-label" for="Name">Contact No </label>
                                            <input type="text" class="form-control" id="ContactNo2"
                                                name="ContactNo2" placeholder="">
                                        </div>
                                    </div>
                                    <div class="col-sm-12" style="padding-right: 7px;padding-left: 11px;">
                                        <div class="form-group">
                                            <label class="form-label" for="Name">Consent <span
                                                    class="text-danger">*</span></label>
                                            <select class="form-control" id="ConsentId" name="ConsentId"
                                                style="height: 30px;">
                                                <option value="0" selected>...</option>
                                                <?php $__currentLoopData = $consentList; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $result): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option value="<?php echo e($result->id); ?>"><?php echo e($result->Name); ?>

                                                        <?php echo e($result->Language); ?></option>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

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





                                </div>


                            </fieldset>


                        </div>
                    </div>

                    <div class="col-md-12">

                        <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-danger" id="delete" type="button" disabled
                                    onclick="deleteRecord()">Delete</button>
                                <button class="btn btn-success" onclick="ipdPaper()" id="printbtn" type="button"
                                    disabled>IPD Paper</button>
                                <button class="btn btn-danger" type="button" onclick="ipdSticker()" id="ipdsticker"
                                    disabled>IPD Sticker</button>
                                <button class="btn btn-danger" type="button" onclick="consentPrint()"
                                    id="consentbtn" disabled>Consent
                                </button>
                                <button class="btn btn-danger" type="button" onclick="otNotes()" id="otnotebtn"
                                    disabled>OT Notes
                                </button>
                                <button class="btn btn-danger" type="button" onclick="dischargeCard()"
                                    id="discbtn" disabled>Discharge
                                    Card</button>
                                <button class="btn btn-secondary" type="button" onclick="ipdBill()" id="billbtn"
                                    disabled>IPD Bill
                                </button>
                                <button class="btn btn-secondary" type="button" onclick="ipdReceipt()"
                                    id="receiptbtn" disabled>IPD Receipt
                                </button>
                                <button class="btn btn-secondary" type="button" onclick="otList()">OT List
                                </button>
                                <button class="btn btn-danger" type="button" onclick="counsellingList()">Counselling
                                    List</button>

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


            </div>
        </div>

        <input type="hidden" id="CurrDate" value="<?php echo e(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="<?php echo e(url('assets/js/jquery-3.6.0.min.js')); ?>"></script>
<?php echo $__env->make('masters/inccommonmodal', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php echo $__env->make('footerscript', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<script>
    let currentFocus = -1;

    $(document).ready(function() {
        $("#OtPatientId").on("input", function() {
            let RefBy = $(this).val();

            if (RefBy.length === 0) {
                $("#autocomplete-list").hide();
                return;
            }

            $.ajax({
                url: "<?php echo e(url('getCounsellingList')); ?>",
                method: "POST",
                data: {
                    _token: '<?php echo e(csrf_token()); ?>',
                    RefBy: RefBy
                },
                success: function(data) {
                    $("#autocomplete-list").empty().show();
                    currentFocus = -1;

                    if (data.length === 0) {
                        $("#autocomplete-list").hide();
                        return;
                    }

                    data.forEach(function(item) {
                        $("#autocomplete-list").append(
                            `<div class="autocomplete-item" onclick="getOtDetails('${item.PatientNameFull}')">${item.PatientNameFull}</div>`
                            );
                    });

                    $(".autocomplete-item").on("click", function() {
                        $("#OtPatientId").val($(this).text());
                        $("#autocomplete-list").hide();
                    });
                }
            });
        });

        $("#OtPatientId").on("keydown", function(e) {
            let items = $(".autocomplete-item");

            if (e.key === "ArrowDown") {
                currentFocus++;
                if (currentFocus >= items.length) currentFocus = 0;
                setActive(items);
                e.preventDefault();
            } else if (e.key === "ArrowUp") {
                currentFocus--;
                if (currentFocus < 0) currentFocus = items.length - 1;
                setActive(items);
                e.preventDefault();
            } else if (e.key === "Enter") {
                e.preventDefault();
                if (currentFocus > -1 && items[currentFocus]) {
                    items.eq(currentFocus).click();
                }
            }
        });

        function setActive(items) {
            items.removeClass("active");
            if (currentFocus >= 0 && currentFocus < items.length) {
                items.eq(currentFocus).addClass("active");
                items.eq(currentFocus)[0].scrollIntoView({
                    block: "nearest"
                });
            }
        }

        $(document).click(function(e) {
            if (!$(e.target).closest("#OtPatientId, #autocomplete-list").length) {
                $("#autocomplete-list").hide();
            }
        });
    });


    function addEye(value) {
        if (!value) return;

        var diagnosis = $('#Diagnosis').val().trim();
        // Remove any existing eye prefixes at the beginning
        diagnosis = diagnosis.replace(/^(RE|LE|BE)\s*/i, ':');
        // Remove leading slash if present
        diagnosis = diagnosis.replace(/^\/\s*/, ':');
        // Prepend the selected eye prefix
        $('#Diagnosis').val(value + ' ' + diagnosis);


        var surgery_name = $('#SurgeryName').val().trim();
        // Remove any existing eye prefixes at the beginning
        surgery_name = surgery_name.replace(/^(RE|LE|BE)\s*/i, ':');
        // Remove leading slash if present
        surgery_name = surgery_name.replace(/^\/\s*/, ':');
        // Prepend the selected eye prefix
        $('#SurgeryName').val(value + ' ' + surgery_name);
    }

    function ipdPaper() {
        var id = $('#saveid').val();
        var consentid = $('#ConsentId').val();
        setTimeout(function() {
            window.open(
                '/<?php echo e(projectUrl()); ?>ipdPaper/' + id, 'popUpWindow66',
                'height=1000,width=1500,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
            );
        }, 1);
    }

    function otList() {
        setTimeout(function() {
            window.open(
                '/<?php echo e(projectUrl()); ?>searchOtList', 'popUpWindo8',
                'height=1000,width=1500,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
            );
        }, 1);
    }

    function counsellingList() {
        setTimeout(function() {
            window.open(
                '/<?php echo e(projectUrl()); ?>searchCounsellingList', 'popUpWindo8',
                'height=1000,width=1500,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
            );
        }, 1);
    }
    $('.datalist').on('click', function() {
        $(this).val('');
    });

    function otNotes() {
        var id = $('#saveid').val();
        setTimeout(function() {
            window.open(
                '/<?php echo e(projectUrl()); ?>addOtNotesOther/' + id, 'popUpWindow7',
                'height=1000,width=1500,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
            );
        }, 1);
    }



    function consentPrint() {
        var id = $('#saveid').val();
        var consentid = $('#ConsentId').val();
        if (consentid == '0') {
            alert('Please Select Consent');
        } else {
            setTimeout(function() {
                window.open(
                    '/<?php echo e(projectUrl()); ?>consentPrint/' + id + '/' + consentid, 'popUpWindow6',
                    'height=1000,width=1500,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
                );
            }, 1);
        }
    }

    function dischargeCard() {
        var otid = $('#saveid').val();
        var mrdno = $('#MrdNo').val();
        setTimeout(function() {
            window.open(
                '/<?php echo e(projectUrl()); ?>addDischargeCard2/' + mrdno + '/' + otid, 'popUpWindow3',
                'height=1000,width=1500,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
            );
        }, 1);
    }

    function ipdBill() {
        var otid = $('#saveid').val();
        var mrdno = $('#MrdNo').val();
        setTimeout(function() {
            window.open(
                '/<?php echo e(projectUrl()); ?>addIpdBill2/' + mrdno + '/' + otid, 'popUpWindow4',
                'height=1000,width=1500,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
            );
        }, 1);
    }

    function ipdReceipt() {
        var otid = $('#saveid').val();
        var mrdno = $('#MrdNo').val();
        setTimeout(function() {
            window.open(
                '/<?php echo e(projectUrl()); ?>addIpdReceipt/' + mrdno + '/' + otid, 'popUpWindow5',
                'height=1000,width=1500,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
            );
        }, 1);
    }

    function printOt() {
        var id = $('#saveid').val();
        setTimeout(function() {
            window.open(
                '/<?php echo e(projectUrl()); ?>printOtNotes/' + 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 ipdSticker() {
        var id = $('#saveid').val();
        setTimeout(function() {
            window.open(
                '/<?php echo e(projectUrl()); ?>printIpdSticker/' + id, 'popUpWindowIpdSticker',
                '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 deleteRecord() {
        if (!confirm("Are you sure you want to delete this record?")) {
            return; // Exit if user cancels
        }

        var id = $('#saveid').val();
        var $button = $('#delete');

        // Show loading state
        $button.prop('disabled', true).html('Deleting...');

        $.ajax({
            url: "<?php echo e(url('deleteCounsellingRecord')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                id: id
            },
            success: function(data) {
                // Redirect after successful deletion
                window.location.href = "/<?php echo e(projectUrl()); ?>addOtNotes";
            },
            error: function() {
                alert("Something went wrong. Please try again.");
                $button.prop('disabled', false).html('Delete');
            }
        });
    }

    function getPatientDetails() {
        var val = $('#MrdNo').val();
        $.ajax({
            url: "<?php echo e(url('getPatientDetails')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                id: val
            },
            dataType: "json",
            success: function(data) {
                $('#PatientName').val(data.PatientName);
                $('#Phone').val(data.Phone);
                $('#Age').val(data.Age);
                $('#Address').val(data.Address);
                $('#Gender').val(data.Gender);
            }
        });
    }

    function blankField() {
        $('#actionvalue').val('Save');
        $('#saveid').val('');
        $('#delete').attr("disabled", true);
        $('#printbtn').attr("disabled", true);
        $('#discbtn').attr("disabled", true);
        $('#billbtn').attr("disabled", true);
        $('#receiptbtn').attr("disabled", true);

        $('#consentbtn').attr("disabled", true);

        $('#otnotebtn').attr("disabled", true);
        $('#ipdsticker').attr("disabled", true);

        //$('#cmbtreateye').val('').attr("selected",true);
        $('#MrdNo').val('');
        $('#PatientName').val('');
        $('#Age').val('');
        $('#Phone').val('');
        $('#Address').val('');
        $('#Gender').val('');
        $('#Eye').val('');
        $('#Diagnosis').val('');
        $('#Bs').val('');
        $('#Bp').val('');
        $('#IopRe').val('');
        $('#IopLe').val('');
        $('#Other').val('');
        $('#Category').val('').attr("selected", true);
        $('#K1Re').val('');
        $('#K1Le').val('');
        $('#K2Re').val('');
        $('#K2Le').val('');
        $('#AL').val('');
        $('#Acd').val('');
        $('#IolPower').val('').attr("selected", true);
        $('#Formula').val('');
        $('#Aconstant').val('');
        $('#Surgeon').val('');
        $('#Assistant').val('');
        $('#Anaethetist').val('');
        $('#Package').val('');
        $('#SurgeryPerformed').val('');
        $('#DilatedBy').val('Tropicamet Plus');
        $('#AnesthesiaType').val('Topical');
        $('#Draping').val('Eyedrape');
        $('#Speculum').val('Screw Speculum');
        $('#ConjunctivalWash').val('Apidine Eyedrop');
        $('#SideportIncision').val('MVR Blade');
        $('#Viscoelastic').val('Appovisc/Intavisc');
        $('#ccc').val('Yes');
        $('#CapStaining').val('No');
        $('#IrrigationSol').val('Intasol');
        $('#Hydroscetion').val('Yes');
        $('#Nucleus').val('Direct Chop');
        $('#CorticalWash').val('Yes');
        $('#Lri').val('');
        $('#WoundHydration').val('');
        $('#Intracameral').val('Vigamax');
        $('#PkgAmt').val('');
        $('#InsComp').val('');
        $('#ReqAmt').val('');
        $('#SanctAmt').val('');
        $('#AddAmt').val('');
        $('#SettleAmt').val('');
        $('#SettleDate').val(CurrDate);
        $('#RefundAmt').val('');
        $('#RefundDate').val('');
        $('#UtrNo').val('');
        $('#ProcedureComments').val('');
        $('#Remarks').val('');
        $('#IolName').val('').attr("selected", true);
        $('#IolType').val('').attr("selected", true);
        $('#StudyPatient').val('');
        $('#IolType').val('');
        $('#Cyl').val('');
        $('#NearAdd').val('');
        $('#PackageAmount').val('');

        $('#Payment1').val('');
        $('#Payment2').val('');
        $('#Payment3').val('');
        $('#Payment4').val('');
        $('#Amount1').val('');
        $('#Amount2').val('');
        $('#Amount3').val('');
        $('#Amount4').val('');
        $('#payment_type1').prop("checked", false);
        $('#payment_type2').prop("checked", false);
        $('#payment_type3').prop("checked", false);
        $('#payment_type4').prop("checked", false);
        $('#payment_type5').prop("checked", false);
        $('#ConfirmOpto').val('').attr("selected", true);
        $('#CreatedDate').val(CurrDate);
        $('#CreatedTime').val('');
        $('#Project').val('');

    }

    function checkOtPatient(val) {
        var CurrDate = $('#CurrDate').val();
        $.ajax({
            url: "<?php echo e(url('checkOtPatient')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                id: val
            },
            success: function(data) {
                console.log(data);
                var res = JSON.parse(data);
                var Status = res.Status;
                var result = res.result;
                if (Status == 0) {
                    blankField();
                    getPatientDetails();

                } else {
                    $('#actionvalue').val('Edit');
                    $('#delete').attr("disabled", false);
                    $('#printbtn').attr("disabled", false);
                    $('#discbtn').attr("disabled", false);
                    $('#billbtn').attr("disabled", false);
                    $('#consentbtn').attr("disabled", false);
                    $('#receiptbtn').attr("disabled", false);
                    // $('#otbtn').attr("disabled", false);
                    // $('#counsellingbtn').attr("disabled", false);
                    $('#otnotebtn').attr("disabled", false);
                    $('#ipdsticker').attr("disabled", false);



                    $('#saveid').val(result.id);
                    $('#MrdNo').val(result.MrdNo);
                    $('#PatientName').val(result.PatientName);
                    $('#Age').val(result.Age);
                    $('#Phone').val(result.Phone);
                    $('#Address').val(result.Address);
                    $('#Gender').val(result.Gender);
                    $('#Eye').val(result.Eye).attr("selected", true);
                    $('#Diagnosis').val(result.Diagnosis);
                    $('#AdmissionDate').val(result.AdmissionDate);
                    $('#CounsellingDate').val(result.CounsellingDate);
                    $('#SurgeryDate').val(result.SurgeryDate);
                    $('#SurgeryName').val(result.SurgeryName);
                    $('#Anaesthetist').val(result.Anaesthetist);
                    $('#SurgeonName').val(result.SurgeonName).attr("selected", true);
                    $('#SurgeryPkg').val(result.SurgeryPkg);
                    $('#LaGa').val(result.LaGa).attr("selected", true);
                    $('#CounsellingDoneBy').val(result.CounsellingDoneBy);
                    $('#Iol').val(result.Iol);
                    $('#Diopter').val(result.Diopter);
                    $('#IpdNo').val(result.IpdNo);

                    $('#ConfirmSurgery').val(result.ConfirmSurgery).attr("selected", true);
                    $('#SurgeryCharges').val(result.SurgeryCharges);
                    $('#Payment1').val(result.Payment1);
                    $('#Amount1').val(result.Amount1);
                    $('#Payment2').val(result.Payment2);
                    $('#Amount2').val(result.Amount2);
                    $('#Payment3').val(result.Payment3);
                    $('#Amount3').val(result.Amount3);
                    $('#Payment4').val(result.Payment4);
                    $('#Amount4').val(result.Amount4);
                    if (result.payment_type1 == 'Cashless') {
                        $('#payment_type1').prop("checked", true);
                    } else {
                        $('#payment_type1').prop("checked", false);
                    }

                    if (result.payment_type2 == 'MJPJAY') {
                        $('#payment_type2').prop("checked", true);
                    } else {
                        $('#payment_type2').prop("checked", false);
                    }

                    if (result.payment_type3 == 'ECHS') {
                        $('#payment_type3').prop("checked", true);
                    } else {
                        $('#payment_type3').prop("checked", false);
                    }

                    if (result.payment_type4 == 'BSNL') {
                        $('#payment_type4').prop("checked", true);
                    } else {
                        $('#payment_type4').prop("checked", false);
                    }

                    if (result.payment_type5 == 'FCI') {
                        $('#payment_type5').prop("checked", true);
                    } else {
                        $('#payment_type5').prop("checked", false);
                    }

                    $('#Remarks').val(result.Remarks);
                    $('#RelativeName1').val(result.RelativeName1);
                    $('#Relation1').val(result.Relation1);
                    $('#ContactNo1').val(result.ContactNo1);
                    $('#RelativeName2').val(result.RelativeName2);
                    $('#Relation2').val(result.Relation2);
                    $('#ContactNo2').val(result.ContactNo2);
                    $('#ConsentId').val(result.ConsentId).attr("selected", true);

                }
            }
        });
    }


    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: "<?php echo e(url('saveOtNotes')); ?>",
                    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);
                        $('#delete').attr("disabled", false);
                        $('#printbtn').attr("disabled", false);
                        $('#discbtn').attr("disabled", false);
                        $('#billbtn').attr("disabled", false);
                        $('#receiptbtn').attr("disabled", false);
                        $('#consentbtn').attr("disabled", false);
                        $('#otnotebtn').attr("disabled", false);
                        $('#ipdsticker').attr("disabled", false);
                        $('#submit').attr('disabled', false);
                        $('#submit').text('Submit');



                    }
                });
            }

        });


        $(document).on("change", "#OtPatientId", function(event) {
            var val = this.value;
            checkOtPatient(val);
            $('#PatientId').val('');

        });



    });

    function getOtDetails(val) {
        //alert(val);
        checkOtPatient(val);
        $('#PatientId').val('');

    }
</script>
<?php /**PATH /home/gssnagpu/public_html/hospsoft.in/deshmukh_hosp/resources/views//ipd/add-otnotes.blade.php ENDPATH**/ ?>