<?php include ('techsyn_header.php'); ?>
<!-- Main Content Container for side bar and body-->
<div class="main-container ace-save-state" id="main-container">
    <?php include ('techsyn_sidebar.php'); ?>
    <!--breadcrumb-->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="breadcrumbs ace-save-state" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li class="#">Patient Management</li>
                    <li class="active">OPD List</li>
                </ul>
            </div>
            <!-- End of breadcrumb -->
            <div class="page-content">
                <form name="f1" method="post" id="flex_form_opd" action="">
                    <div id="flex1" style="width: 100%">
                    </div>
                    <input type="hidden" name="appointment_id_pdf" id="appointment_id_pdf" />
                </form>
                <form name="export_form" method="post" id="export_form" action="">
                    <input type="hidden" name="flex_employee_appointment_id" id="flex_employee_appointment_id" /> <input
                        type="hidden" name="pdf_action" id="pdf_action" value="pdf_emp_appointment_list.php" /> <input
                        type="hidden" name="excel_action" id="excel_action" value="excel_emp_appointment_list.php" />
                </form>
                <form name="flex_appointment_form" method="post" id="flex_appointment_form" action="">
                    <input type="hidden" name="appointmentId" id="appointmentId" /> <input type="hidden"
                        name="flex_opd_id" id="flex_opd_id" /> <input type="hidden" name="returnPage" id="returnPage" />
                </form>
            </div>
        </div>
        <!-- /.page-content -->
    </div>
</div>
<!-- /.main-content -->
<link rel="stylesheet" href="assets/font-awesome/4.5.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="assets/css/jquery-ui.custom.min.css" />
<link rel="stylesheet" href="assets/css/chosen.min.css" />
<link rel="stylesheet" href="assets/css/bootstrap-datepicker3.min.css" />
<link rel="stylesheet" href="assets/css/bootstrap-timepicker.min.css" />
<link rel="stylesheet" href="assets/css/daterangepicker.min.css" />
<link rel="stylesheet" href="assets/css/bootstrap-datetimepicker.min.css" />
<link rel="stylesheet" href="assets/css/bootstrap-colorpicker.min.css" />
<script type="text/javascript" src="js/typeahead.bundle.js"></script>
<script src="assets/js/jquery-ui.custom.min.js" type="text/javascript"></script>
<script src="assets/js/jquery.ui.touch-punch.min.js" type="text/javascript"></script>
<script src="assets/js/chosen.jquery.min.js" type="text/javascript"></script>
<script src="assets/js/spinbox.min.js" type="text/javascript"></script>
<script src="assets/js/bootstrap-datepicker.min.js" type="text/javascript"></script>
<script src="assets/js/bootstrap-timepicker.min.js" type="text/javascript"></script>
<script src="assets/js/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="assets/js/jquery.dataTables.bootstrap.min.js" type="text/javascript"></script>
<script src="assets/js/dataTables.buttons.min.js" type="text/javascript"></script>
<script src="assets/js/buttons.flash.min.js" type="text/javascript"></script>
<script src="assets/js/buttons.html5.min.js" type="text/javascript"></script>
<script src="assets/js/buttons.print.min.js" type="text/javascript"></script>
<script src="assets/js/buttons.colVis.min.js" type="text/javascript"></script>
<script src="assets/js/dataTables.select.min.js" type="text/javascript"></script>
<script src="assets/js/moment.min.js" type="text/javascript"></script>
<script src="assets/js/daterangepicker.min.js" type="text/javascript"></script>
<script src="assets/js/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
<script src="assets/js/bootstrap-colorpicker.min.js" type="text/javascript"></script>
<script src="assets/js/jquery.knob.min.js" type="text/javascript"></script>
<script src="assets/js/autosize.min.js" type="text/javascript"></script>
<script src="assets/js/jquery.inputlimiter.min.js" type="text/javascript"></script>
<script src="assets/js/jquery.maskedinput.min.js" type="text/javascript"></script>
<script src="assets/js/bootstrap-tag.min.js" type="text/javascript"></script>
<script src="assets/js/ace-elements.min.js" type="text/javascript"></script>
<style type="text/css">
    /* .emergency {
        background-color: red;
    } */

    .injury {
        background-color: red;
    }
</style>
<script type="text/javascript">
    $(function () {
        var w = screen.width * .90;
        var h = 0;
        h = (window.innerHeight - ($("#navbar").height() + $(".breadcrumbs").height())) * .75;
        $("#flex1").flexigrid({
            url: 'opd_list_script.php',
            dataType: 'json',
            colModel: [{
                display: 'Sr',
                name: 'count',
                width: w * .02,
                sortable: false,
                align: 'left'
            },
            {
                display: '',
                name: 'link',
                width: w * .13,
                sortable: false,
                align: 'left'
            },
            {
                display: 'Reporting OHC',
                name: 'ohc_type_id',
                width: w * .1,
                sortable: true,
                align: 'left'
            },

            {
                display: 'Date',
                name: 'appointment_date',
                width: w * .11,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Ticket No',
                name: 'appointment_id',
                width: w * .07,
                sortable: true,
                align: 'left'
            }, {
                display: 'Follow-ups',
                name: 'followup_id',
                width: w * .09,
                sortable: true,
                align: 'left'
            },
            {
                display: 'ECode/G.Pass',
                name: 'emp_code',
                width: w * .08,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Patient Name',
                name: 'patient_name',
                width: w * .1,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Is Hospitalized',
                name: 'is_hospitalized',
                width: w * .1,
                sortable: true,
                align: 'left'
            },
            // {
            //     display: 'Followup Remarks',
            //     name: 'followup_remarks',
            //     width: w * .1,
            //     sortable: true,
            //     align: 'left'
            // },
            // {
            //     display: 'Emergency',
            //     name: 'IsEmergency',
            //     width: w * .07,
            //     sortable: true,
            //     align: 'left'
            // },
            // {
            //     display: 'Injury',
            //     name: 'appointment_type',
            //     width: w * .07,
            //     sortable: true,
            //     align: 'left'
            // },
            {
                display: 'Detention',
                name: 'detention',
                width: w * .07,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Doctor Consulted',
                name: 'doctor_attended_flag',
                width: w * .07,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Medicine Given By',
                name: 'doctor_attended_flag',
                width: w * .1,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Complaints',
                name: 'complaints',
                width: w * .1,
                sortable: true,
                align: 'left'
            },
            // {
            //     display: 'Examination Findings',
            //     name: 'examination_remarks',
            //     width: w * .1,
            //     sortable: true,
            //     align: 'left'
            // },
            {
                display: 'Diagnosis',
                name: 'injury_types_new',
                width: w * .1,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Treatments',
                name: 'hospital_treatment',
                width: w * .15,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Treatment given by',
                name: 'doctor_last_attended',
                width: w * .05,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Referral',
                name: 'referral',
                width: w * .05,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Follow-up',
                name: 'followup',
                width: w * .05,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Vitals',
                name: 'bp_sbp',
                width: w * .17,
                sortable: true,
                align: 'left'
            }
            ],
            buttons: [{
                name: 'PDF',
                bclass: 'print',
                onpress: pdf
            },
            {
                separator: true
            },
            {
                name: 'Excel',
                bclass: 'print_excel',
                onpress: excel
            },
            {
                separator: true
            }
            ],
            searchitems: [{
                display: 'Emp Code',
                name: 'emp_code',
                isdefault: true
            },
            {
                display: 'Patient Name',
                name: 'patient_name'
            },
            {
                display: 'Case type',
                name: 'case_type'
            },
            {
                display: 'Followup Remarks',
                name: 'followup_remarks'
            },
            {
                display: 'Doctor Consulted(Y/N)',
                name: 'doctor_attended_flag'
            },
            {
                display: 'Ticket No',
                name: 'ticket_no',
            },
            {
                display: 'Appointment Date (dd/mm/yyyy)',
                name: 'appointment_date'
            },
            {
                display: 'Appointment Date Between (dd/mm/yyyy-dd/mm/yyyy)',
                name: 'appointment_date_between'
            },
            {
                display: 'Complaints',
                name: 'complaints',
            },
            {
                display: 'Examination Findings',
                name: 'examination_remarks'
            },
            //                 {
            //                     display: 'Diagnosis',
            //                     name: 'ailment_name'
            //                 },
            //                 {
            //                     display: 'Treatments',
            //                     name: 'hospital_treatment'
            //                 },
            {
                display: 'Treatment given by',
                name: 'doctor_last_attended'
            },
            // {
            //     display: 'Emergency(Y/N)',
            //     name: 'IsEmergency'
            // },
            // {
            //     display: 'Injury Only(I)',
            //     name: 'appointment_type'
            // },
            {
                display: 'Detention',
                name: 'detention'
            },
            // {
            //     display: 'OPD Only(O)',
            //     name: 'appointment_type'
            // },
            {
                display: 'Remarks',
                name: 'remarks'
            },
            ],
            sortname: "appointment_date",
            sortorder: "desc",
            usepager: true, //pagination
            //title:"Employee OPD",
            useRp: true,
            rp: 50, //records per page
            showTableToggleBtn: false, //toggle button for the whole table
            resizable: true,
            //	width: w, 
            height: h,
            singleSelect: true
        });
    });

    function pdf() {
        window.open('ajax_pdf.php', 'OPD-Injury List');
    }

    function excel() {
        window.open('ajax_excel.php', 'OPD-Injury List');
    }


    function open_dashboard(emp_id) {

        if (emp_id != null && emp_id != '') {
            $("#flex_opd_id").val(emp_id);

            $("#flex_form_opd").attr('method', 'POST');
            $("#flex_form_opd").attr('action', 'emp_dashboard.php');
            $("#flex_form_opd").submit();

        }
    }
    function open_form_24(appointmentId) {
        $("#appointment_id_pdf").val(appointmentId);
        $("#flex_form_opd").attr('target', '_blank');
        $("#flex_form_opd").attr('method', 'POST');
        $("#flex_form_opd").attr('action', 'form24_incident_report.php');
        $("#flex_form_opd").submit();
    }


    


    function delete_employee_appointment_history(appointmnentId) {
        //$("#flex_employee_appointment_id").val(appointmnentId);
        BootstrapDialog.confirm('Are you sure to delete?', function (result) {
            if (result) {
                $.ajax({
                    url: 'delete_appointment_emp.php',
                    type: "POST",
                    data: {
                        'flex_employee_appointment_id': appointmnentId
                    },
                    success: function (data) {
                        if (data.indexOf("SUCCESS") != -1) {
                            BootstrapDialog.alert('Deleted Successfully.');
                            $("#flex1").flexReload();
                            //loadAppointmentHistory('<?php echo $_REQUEST['flex_opd_id'] ?>');
                        } else {
                            BootstrapDialog.alert('Error Deleting');
                        }
                        return;
                    },
                    error: function (data) {
                        BootstrapDialog.alert('Error Deleting');
                        return;
                    }
                });
            }
        });
    }
    var appointment_id = "";

    function send_email(appointmentId, appointment_type, emp_id, action) {
        if (appointment_type == "O") {
            document.forms['flex_appointment_form'].action = "send_email.php";
        }

    }
    var appointment_id = "";


    // function open_employee_appointment(appointmentId, appointment_type, emp_id, action) {
    //     if (appointment_type == "O") {
    //         if (action == 'V') {
    //             document.forms['flex_appointment_form'].action = "view_opd.php";
    //         } else if (action == 'E') {
    //             document.forms["flex_appointment_form"].action = "edit_opd.php";
    //         }
    //     } else if (appointment_type == "I") {
    //         if (action == 'V') {
    //             document.forms['flex_appointment_form'].action = "view_injury.php";
    //         } else if (action == 'E') {
    //             document.forms['flex_appointment_form'].action = "edit_injury.php";
    //         }
    //     }
    //     $("#flex_appointment_form").method = "post";
    //     $("#flex_appointment_form").find("#appointmentId").val(appointmentId);
    //     $("#flex_appointment_form").find("#flex_opd_id").val(emp_id);
    //     $("#flex_appointment_form").find("#returnPage").val("appointment_list.php");
    //     $("#flex_appointment_form").submit();
    // }

    function add_hospitalization_data(appointmentId) {
        $(".save_button").show();
        $("#appointment_id").val(appointmentId);
        $("#hos-remark").val("");
        $("#entry_time").val("");
        $('#modal-add-hos-details').modal("show");
    }

    function save_hos_details() {
        $.ajax({
            type: 'Post',
            url: 'save_additional_hos_data.php',
            data: $("#hos_form").serialize(),
            success: function (data) {
                data = JSON.parse(data);
                console.log("Parsed data:", data);
                if (data.status == '200') {
                    $('#modal-add-hos-details').modal("hide");
                    BootstrapDialog.alert({
                        title: 'Success',
                        message: data.message,
                        type: BootstrapDialog.TYPE_SUCCESS
                    });
                } else if (data.status == '500') {
                    $('#modal-add-hos-details').modal("hide");
                    BootstrapDialog.alert({
                        title: 'Error',
                        message: data.message,
                        type: BootstrapDialog.TYPE_DANGER
                    });
                }
            }, error: function (data) {
                BootstrapDialog.alert("Something went wrong");
            }

        })
    }

    function open_employee_appointment(appointmentId, appointment_type, emp_id, action, follow_up) {
        if (appointment_type == "O") {
            if (action == 'V') {
                document.forms['task_form'].action = "view_opd.php";
            } else if (action == 'E' || action == 'F') {
                document.forms["task_form"].action = "edit_opd.php";
            }
        } else if (appointment_type == "I") {
            if (action == 'V') {
                document.forms['task_form'].action = "view_injury.php";
            } else if (action == 'E' || action == 'F') {
                document.forms['task_form'].action = "edit_injury.php";
            }
        }
        $("#task_form").method = "post";
        if (action == 'F') {
            $("#task_form").append(jQuery('<input>', {
                'name': 'followup_to_opd',
                'id': 'followup_to_opd',
                'value': appointmentId,
                'type': 'hidden'
            }));
            $("#task_form").append(jQuery('<input>', {
                'name': 'followup_id',
                'id': 'followup_id',
                'value': follow_up,
                'type': 'hidden'
            }));
        } else {
            $("#task_form").append(jQuery('<input>', {
                'name': 'appointmentId',
                'id': 'appointmentId',
                'value': appointmentId,
                'type': 'hidden'
            }));
        }
        $("#task_form").append(jQuery('<input>', {
            'name': 'followup_id',
            'id': 'followup_id',
            'value': follow_up,
            'type': 'hidden'
        }));
        $("#task_form").append(jQuery('<input>', {
            'name': 'emp_id',
            'id': 'emp_id',
            'value': emp_id,
            'type': 'hidden'
        }));

        $("#task_form").append(jQuery('<input>', {
            'name': 'flex_opd_id',
            'id': 'flex_opd_id',
            'value': emp_id,
            'type': 'hidden'
        }));
        $("#task_form").append(jQuery('<input>', {
            'name': 'returnPage',
            'id': 'returnPage',
            'value': "appointment_list.php",
            'type': 'hidden'
        }));
        $("#task_form").submit();
    }
</script>
<?php  include('open_item_function.php');?>

<script type="text/javascript">
    jQuery(function ($) {
        var myTable =
            $('#dynamic-table')
                //.wrap("<div class='dataTables_borderWrap' />")   //if you are applying horizontal scrolling (sScrollX)
                .DataTable({
                    bAutoWidth: false,
                    "aoColumns": [{
                        "bSortable": false
                    },
                        null, null, null, null, null,
                    {
                        "bSortable": false
                    }
                    ],
                    "aaSorting": [],
                    select: {
                        style: 'multi'
                    }
                });
        //style the message box
        var defaultCopyAction = myTable.button(1).action();
        myTable.button(1).action(function (e, dt, button, config) {
            defaultCopyAction(e, dt, button, config);
            $('.dt-button-info').addClass('gritter-item-wrapper gritter-info gritter-center white');
        });
        var defaultColvisAction = myTable.button(0).action();
        myTable.button(0).action(function (e, dt, button, config) {
            defaultColvisAction(e, dt, button, config);
            if ($('.dt-button-collection > .dropdown-menu').length == 0) {
                $('.dt-button-collection')
                    .wrapInner('<ul class="dropdown-menu dropdown-light dropdown-caret dropdown-caret" />')
                    .find('a').attr('href', '#').wrap("<li />")
            }
            $('.dt-button-collection').appendTo('.tableTools-container .dt-buttons')
        });
        ////
        setTimeout(function () {
            $($('.tableTools-container')).find('a.dt-button').each(function () {
                var div = $(this).find(' > div').first();
                if (div.length == 1) div.tooltip({
                    container: 'body',
                    title: div.parent().text()
                });
                else $(this).tooltip({
                    container: 'body',
                    title: $(this).text()
                });
            });
        }, 500);
        myTable.on('select', function (e, dt, type, index) {
            if (type === 'row') {
                $(myTable.row(index).node()).find('input:checkbox').prop('checked', true);
            }
        });
        myTable.on('deselect', function (e, dt, type, index) {
            if (type === 'row') {
                $(myTable.row(index).node()).find('input:checkbox').prop('checked', false);
            }
        });
        /////////////////////////////////
        //table checkboxes
        $('th input[type=checkbox], td input[type=checkbox]').prop('checked', false);
        //select/deselect all rows according to table header checkbox
        $('#dynamic-table > thead > tr > th input[type=checkbox], #dynamic-table_wrapper input[type=checkbox]').eq(
            0).on('click', function () {
                var th_checked = this.checked; //checkbox inside "TH" table header
                $('#dynamic-table').find('tbody > tr').each(function () {
                    var row = this;
                    if (th_checked) myTable.row(row).select();
                    else myTable.row(row).deselect();
                });
            });
        //select/deselect a row when the checkbox is checked/unchecked
        $('#dynamic-table').on('click', 'td input[type=checkbox]', function () {
            var row = $(this).closest('tr').get(0);
            if (this.checked) myTable.row(row).deselect();
            else myTable.row(row).select();
        });
        $(document).on('click', '#dynamic-table .dropdown-toggle', function (e) {
            e.stopImmediatePropagation();
            e.stopPropagation();
            e.preventDefault();
        });
        //And for the first simple table, which doesn't have TableTools or dataTables
        //select/deselect all rows according to table header checkbox
        var active_class = 'active';
        $('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function () {
            var th_checked = this.checked; //checkbox inside "TH" table header
            $(this).closest('table').find('tbody > tr').each(function () {
                var row = this;
                if (th_checked) $(row).addClass(active_class).find('input[type=checkbox]').eq(0)
                    .prop('checked', true);
                else $(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop(
                    'checked', false);
            });
        });
        //select/deselect a row when the checkbox is checked/unchecked
        $('#simple-table').on('click', 'td input[type=checkbox]', function () {
            var $row = $(this).closest('tr');
            if ($row.is('.detail-row ')) return;
            if (this.checked) $row.addClass(active_class);
            else $row.removeClass(active_class);
        });
        /********************************/
        //add tooltip for small view action buttons in dropdown menu
        $('[data-rel="tooltip"]').tooltip({
            placement: tooltip_placement
        });
        //tooltip placement on right or left
        function tooltip_placement(context, source) {
            var $source = $(source);
            var $parent = $source.closest('table')
            var off1 = $parent.offset();
            var w1 = $parent.width();
            var off2 = $source.offset();
            //var w2 = $source.width();
            if (parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2)) return 'right';
            return 'left';
        }
        /***************/
        $('.show-details-btn').on('click', function (e) {
            e.preventDefault();
            $(this).closest('tr').next().toggleClass('open');
            $(this).find(ace.vars['.icon']).toggleClass('fa-angle-double-down').toggleClass(
                'fa-angle-double-up');
        });
        /***************/
        /**
        //add horizontal scrollbars to a simple table
        $('#simple-table').css({'width':'2000px', 'max-width': 'none'}).wrap('<div style="width: 1000px;" />').parent().ace_scroll(
          {
            horizontal: true,
            styleClass: 'scroll-top scroll-dark scroll-visible',//show the scrollbars on top(default is bottom)
            size: 2000,
            mouseWheelLock: true
          }
        ).css('padding-top', '12px');
        */
    })
    $('#doj').datepicker({
        autoclose: true,
        format: 'dd/mm/yyyy',
        startDate: '1d/1m/2000y',
        endDate: 'current',
        todayHighlight: true
    }).next().on(ace.click_event, function () {
        $(this).prev().focus();
    });
    $('#dob').datepicker({
        autoclose: true,
        format: 'dd/mm/yyyy',
        startDate: '1d/1m/1970y',
    }).next().on(ace.click_event, function () {
        $(this).prev().focus();
    });

    function send_email() {
        var appointment_id;

        $("#message").val($("#email_form").find("#email_content").html());
        $.ajax({
            url: 'send_email.php',
            type: 'POST',
            data: $("#email_form").serialize(),
            success: function (data) {
                BootstrapDialog.alert('Mail send Successfully');
                $("#flex1").flexReload();
                return;
            },
            error: function (data) {
                BootstrapDialog.alert('Error in sending mail');
                return;
            }
        });
        $('.close').click();
    }
</script>
<?php include ('form/add_hospitalization_modal.php') ?>
<?php include ('common_list.php'); ?>
<?php include ('form/send_mail.php'); ?>
<?php include ('techsyn_footer.php'); ?>
<?php include ('common_ace.php'); ?>