<?php echo $__env->make('header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<div class="container-fluid flex-grow-1 container-p-y">
    <h4 class="font-weight-bold py-3 mb-0">Disease Wise Treatment</h4>
    <?php
    if(file_exists('json_files/json-file.json')){
    $json = file_get_contents('json_files/json-file.json');
    //Decode JSON
    $json_data = json_decode($json,true);
    $results = array();
    }

    if(file_exists('json_files/timetables_date.json')){ 
        $json2 = file_get_contents('json_files/timetables_date.json');
        //Decode JSON
        $json_data2 = json_decode($json2,true);
        $results2 = array();
        }
    ?>

    <form method="post" action="/<?php echo e(projectUrl()); ?>saveTreatments">
        <div class="row">
            <div class="col-md-12 mb-4">

                <div id="accordion">
                    <div class="card mb-2">

                        <div id="accordion-1" class="collapse show" data-parent="#accordion">
                            <div class="card-body demo-vertical-spacing">


                                <div class="table-responsive" style="overflow-x:auto;">
                                    <input type="hidden" name="action" value="Save">
                                    <?php echo csrf_field(); ?>
                                    <table id="" class="table table-bordered table-striped mb-0">
                                        <thead>
                                            <tr>
                                                <th colspan="1" align="left" valign="top">
                        <button class="btn btn-secondary" type="button" data-toggle="modal" data-target="#modal-report656"
                             id="add-drugs" onclick="addNewDrug()">+</button>
                    </th>

                    <th colspan="1" align="left" valign="top">

                      <select class="form-control" name="TreatRoll" id="TreatRoll" onchange="getTreatments(this.value)">
                        <option value="Opd" <?php if($val == 'Opd'){?> selected <?php } ?>>OPD</option>
                        <option value="Ipd" <?php if($val == 'Ipd'){?> selected <?php } ?>>IPD/Discharge Card</option>
                      </select>
                    </th>
                                                <th colspan="5" align="left" valign="top">

                                                    <input class="form-control" type="text" list="emails2"
                                                        style="overflow-x:auto;" id="Treatment" name="Treatment" required
                                                        oninput="getRecords(this.value)" autocomplete="off">
                                                    <datalist id="emails2">
                                                    <?php
        foreach($json_data2['items'] as $result) {?>
                            <option value="<?php echo $result['Treatment']; ?>">
                                <?php } ?>
                                                    </datalist>
                                                </th>
                                                
                                            </tr>

                                </div>

                                <tr>
                                    <!--  <th width="20" align="center" valign="top">Select</th> -->
                                    <th width="70"> Type </th>
                                    <th width="150"> Name </th>
                                    <th width="90">Dose</th>
                                    <th width="90">Freq.</th>
                                    <th width="90">Duration</th>
                                    <th width="20">Eye </th>
                                    <th width="20">&nbsp; </th>
                                </tr>
                                </thead>
                                <tbody class="prevdata">

                                </tbody>
                                <tbody id="dynamic_field">

                                    <tr>
                                        <!--  <td align="center" valign="top"><input class="form-check-input" type="checkbox" value="1" name="TreatChk1">
                                                           </td> -->
                                        <td>
                                            <select class="form-control" name="TreatType1[]"  id="TreatType1" onchange="getDrugByType(this.value,1)">
                                            <option value="" selected>...</option>
                                            <?php
        foreach($json_data['JsonData']['TreatType'] as $result) {?>
                                                <option value="<?php echo e($result['Values']); ?>"><?php echo e($result['Values']); ?></option>
                                                    <?php } ?>

                                            </select>
                                            <!-- <input class="form-control" type="text" list="Treat_Type1"
                                                name="TreatType1[]"  id="TreatType1">
                                            <datalist id="Treat_Type1">

                                                <?php
        foreach($json_data['JsonData']['TreatType'] as $result) {?>
                                                <option value="<?php echo e($result['Values']); ?>">
                                                    <?php } ?>
                                            </datalist> -->
                                        </td>
                                        <td>
                                           
                                                <input class="form-control" type="text" name="TreatName1[]"  list="Treat_Name1" id="TreatName1"
                          onClick="this.select();"
                            oninput="getTreatNameDetails('TreatName1','TreatDose1','TreatFreq1')">
                        <datalist id="Treat_Name1" class="treatments">
                            <?php $__currentLoopData = $drugList; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $drugdata): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($drugdata->Name); ?>">
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </datalist>

                                        </td>
                                        <td>
                                            <!-- <input class="form-control" type="text" list="Treat_Dose1"
                                                name="TreatDose1[]"  id="TreatDose1">
                                            <datalist id="Treat_Dose1">

                                                <?php
        foreach($json_data['JsonData']['TreatDose'] as $result) {?>
                                                <option value="<?php echo e($result['Values']); ?>">
                                                    <?php } ?>
                                            </datalist> -->

                                            <select class="form-control" name="TreatDose1[]"  id="TreatDose1">
                                            <option value="" selected>...</option>
                                            <?php
        foreach($json_data['JsonData']['TreatDose'] as $result) {?>
                                                <option value="<?php echo e($result['Values']); ?>"><?php echo e($result['Values']); ?></option>
                                                    <?php } ?>

                                            </select>

                                        </td>
                                        <td>
                                            <!-- <input class="form-control" type="text" list="Treat_Freq1"
                                                name="TreatFreq1[]"  id="TreatFreq1">
                                            <datalist id="Treat_Freq1">

                                                <?php
        foreach($json_data['JsonData']['TreatFreq'] as $result) {?>
                                                <option value="<?php echo e($result['Values']); ?>">
                                                    <?php } ?>
                                            </datalist> -->

                                            <select class="form-control" name="TreatFreq1[]"  id="TreatFreq1">
                                            <option value="" selected>...</option>
                                            <?php
        foreach($json_data['JsonData']['TreatFreq'] as $result) {?>
                                                <option value="<?php echo e($result['Values']); ?>"><?php echo e($result['Values']); ?></option>
                                                    <?php } ?>

                                            </select>
                                        </td>
                                        <td>
                                            <!-- <input class="form-control" type="text" list="Treat_Dur1" name="TreatDur1[]"
                                                 id="TreatDur1">
                                            <datalist id="Treat_Dur1">

                                                <?php
        foreach($json_data['JsonData']['TreatDur'] as $result) {?>
                                                <option value="<?php echo e($result['Values']); ?>">
                                                    <?php } ?>
                                            </datalist> -->

                                            <select class="form-control" name="TreatDur1[]"  id="TreatDur1">
                                            <option value="" selected>...</option>
                                            <?php
        foreach($json_data['JsonData']['TreatDur'] as $result) {?>
                                                <option value="<?php echo e($result['Values']); ?>"><?php echo e($result['Values']); ?></option>
                                                    <?php } ?>

                                            </select>

                                        </td>
                                        <td>
                                            <!-- <input class="form-control" type="text" list="Treat_Eye1" name="TreatEye1[]"
                                                id="TreatEye1">
                                            <datalist id="Treat_Eye1">

                                                <?php
        foreach($json_data['JsonData']['TreatEye'] as $result) {?>
                                                <option value="<?php echo e($result['Values']); ?>">
                                                    <?php } ?>
                                            </datalist> -->

                                            <select class="form-control" name="TreatEye1[]"  id="TreatEye1">
                                            <option value="" selected>...</option>
                                            <?php
        foreach($json_data['JsonData']['TreatEye'] as $result) {?>
                                                <option value="<?php echo e($result['Values']); ?>"><?php echo e($result['Values']); ?></option>
                                                    <?php } ?>

                                            </select>

                                        </td>

                                        <td align="center" valign="top"> <button class="btn btn-primary" type="button"
                                                id="add_more"><i class="feather icon-plus"></i></button>
                                        </td>

                                    </tr>

                                </tbody>
                                </table>

                            </div>

                            <div class="row">
                             <div class="col-lg-12">
                                <label class="floating-label" for="Name" style="font-size: 20px;font-weight: bold;">Advice <span
                                            class="text-danger">*</span></label>
                    <textarea class="form-control" id="Advice" name="Advice" style="height: 160px;"></textarea>
                </div>
                </div>



                            <div class="col-sm-12">
                                <button class="btn btn-primary" name="submit" type="submit">Submit</button>
                                <button class="btn btn-info" type="reset">Clear</button>
                                <button class="btn btn-danger" type="button" id="delete" onclick="deleteTreatment()" style="display:none;">Delete</button>
                            </div>
                        </div>

                    </div>


                </div>



            </div>
        </div>


</div>





</form>
</div>
<?php echo $__env->make('masters/incdrugmodal', \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>
    function getDrugByType(val,srno){
            $.ajax({
        url: "<?php echo e(url('getDrugByType')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            val:val
        },
        success: function(data) {
            console.log(data);
            $('#Treat_Name' + srno).html(data);
        }
    });
    }
    function getTreatments(val){
        window.location.href="/treatmentmaster/"+val;
    }
    function addNewDrug(){
    $('#drugaction').val('Save');
           $('#drugid').val('');
           $('#DrugName').val('');
                $('#DrugType').val('').attr("selected",true);
                $('#DrugDose').val('').attr("selected",true);
                $('#DrugFreq').val('').attr("selected",true);
                $('#drugbtn').text("Save");
                $('.modal-title').html(
                    "Add <span class='font-weight-light'>Drug</span>");
    procedure_lists();

}
        function procedure_lists() {
    $.ajax({
        url: "<?php echo e(url('viewDrugList')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>'
        },
        success: function(data) {
            console.log(data);
            $('#drugcustresult').html(data);
        }
    });
}

        function drugList(){
            $.ajax({
            url: "<?php echo e(url('saveDrugList')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>'
            },
            success: function(data) {
                $('.treatments').html(data);
            
            }
        });
        }
        function saveDrug(){
            var Type = $('#DrugType').val();
            var Name = $('#DrugName').val();
            var Dose = $('#DrugDose').val();
            var Freq = $('#DrugFreq').val();
            var MrdNo = $('#MrdNo').val();
            var VisitDate = $('#VisitDate').val();
            var VisitNo = $('#VisitNo').val();
            var action = $('#drugaction').val();
            var id = $('#drugid').val();
            $.ajax({
            url: "<?php echo e(url('saveDrug')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                Type: Type,
                Name:Name,
                Dose:Dose,
                Freq:Freq,
                action:action,
                id:id
            },
            beforeSend: function() {
                    $('#drugbtn').attr('disabled', 'disabled');
                    $('#drugbtn').text('Please Wait...');
                },
            success: function(data) {

                $('#modal-report656').modal('hide');
                $('#drugaction').val('Save');
           $('#drugid').val('');
                    $('#drugbtn').attr('disabled', false);
                    $('#drugbtn').text('Submit');
                    drugList();
                    //window.location.href = "/<?php echo e(projectUrl()); ?>optoform/" + MrdNo + "/" + VisitDate + "/" + VisitNo + "?page=consult";  
               
            }
        });
        }

        // function getTreatNameDetails(name,dose,freq){
        //     var treatname = $('#'+name).val();
        //     $.ajax({
        //     url: "<?php echo e(url('getTreatNameDetails')); ?>",
        //     method: "POST",
        //     data: {
        //         _token: '<?php echo e(csrf_token()); ?>',
        //         name: treatname
        //     },
        //     dataType: "json",
        //     success: function(data) {
        //        console.log(data);
        //         $('#'+dose).val(data.Dose);
        //         $('#'+freq).val(data.Freq);
        //         $('#Sv'+dose).val(data.Dose);
        //         $('#Sv'+freq).val(data.Freq);
                
        //     }
        // });
        // }

        function removeTreatment(val){
           $('#SvTreatType'+val).val('');
           $('#SvTreatName'+val).val('');
           $('#SvTreatDose'+val).val('');
           $('#SvTreatFreq'+val).val('');
           $('#SvTreatDur'+val).val('');
           $('#SvTreatEye'+val).val('');
        }
$(document).ready(function() {
    $(document).on("click", ".updatedrug", function(event) {
        event.preventDefault();
        event.stopPropagation();
        var id = $(this).attr("data-id");
        var action = "fetch_record";
        $.ajax({
            url: "<?php echo e(url('editDrug')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                id: id
            },
            dataType: "json",
            success: function(data) {
                $('#DrugName').val(data.Name);
                $('#DrugType').val(data.Type).attr("selected",true);
                $('#DrugDose').val(data.Dose).attr("selected",true);
                $('#DrugFreq').val(data.Freq).attr("selected",true);
                $('#drugaction').val('Edit');

                $('#drugid').val(id);
                $('#drugbtn').text("Update");
                $('#modal-report656').modal('show');
                $('.modal-title').html(
                    "Update <span class='font-weight-light'>Drug</span>");

            }
        });
    });



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

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

                        procedure_lists();

                    }
                });

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


    });
    $('#add_more').click(function() {
        var action = 'addMore';
        $.ajax({
            url: "<?php echo e(url('getMoreTreatments')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>'
            },
            success: function(data) {
                $('#dynamic_field').append(data);
            }
        });
    });

    $(document).on('click', '.btn_remove', function() {
        var button_id = $(this).attr("id");
        if (confirm("Are you sure you want to delete?")) {
            $('#row' + button_id + '').remove();
        }
    });
});

function getRecords(val){
        var action = 'getRecords';
      $.ajax({
        url: "<?php echo e(url('getSaveTreatments')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                Treatment: val
            }, 
  success: function(data){
    console.log(data);
         $('.prevdata').html(data.html);   // Inject HTML content
            $('#Advice').val(data.advice);    // Set Advice input
            $('#delete').show();
        
  }
  });
    }

    function deleteTreatment(){
        if(confirm("Are you sure you want to delete This Record?"))  
           {
        var Treatment = $('#Treatment').val();
         var TreatRoll = $('#TreatRoll').val();
      $.ajax({
        url: "<?php echo e(url('deleteTreatment')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                Treatment: Treatment,
                TreatRoll:TreatRoll
            }, 
   success: function(data){
    alert(data);
    window.location.href="/treatmentmaster/"+TreatRoll;
   }
});
  }
    }
</script>
<?php /**PATH C:\laragon\www\parijathosp\resources\views/masters/treatmentmaster.blade.php ENDPATH**/ ?>