$(document).ready(function () {
    $('#Back_href').attr('href', '/Ipmanagement/ippatientdetails?Patient_Id=' + $('#IPPatient_Id').val() + '&IPVisitReport_Id=' + $('#IPVisitReport_Id').val() + '&IPDischarge_Id=' + $('#IPDischarge_Id').val() + '&branch_id=' + $('#branch_id').val() + '');
    $('#Screen_Heading').html('OT Schedule');
    LoadOT_Schedule();
    LoadOT_Patient();
});


function LoadOT_Schedule() {

    var ScheduleData = {
        Dml_Indicator: "OTSHN",
        IP_visit_report_id: $('#IPVisitReport_Id').val()
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/Ipmanagement/AdmitPatient_Ins_Upd_Sel',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(ScheduleData),
        success: function (data) {
            debugger;
            $('#dd_shedule').empty();
            var data2 = JSON.parse(data);
            if (jQuery.isEmptyObject((data2.data))) {

            }
            else {

                if (data2.msg == "Success") {

                    var data1 = data2.data;

                    var shedule;

                    var default_opt = '<option value="0">--Select--</option>';
                    $.each(data1, function (i, emp) {

                        shedule = shedule + '<option value="' + emp.id + '">' + emp.ip_operation_name + '</option>';

                    });
                    $('#dd_shedule').append(default_opt + shedule);
                }
                else {
                    console.log(data);
                }
            }
        }
    });
}

function LoadOT_Patient() {

    var ScheduleData = {
        Dml_Indicator: "OTPV",
        IP_visit_report_id: $('#IPVisitReport_Id').val()
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/Ipmanagement/AdmitPatient_Ins_Upd_Sel',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(ScheduleData),
        success: function (data) {
            debugger;
            $('#dd_shedule').empty();
            var data2 = JSON.parse(data);
            if (jQuery.isEmptyObject((data2.data))) {

            }
            else {

                if (data2.msg == "Success") {

                    var data1 = data2.data;
                    if (data1.length > 0) {

                        $('#PaitentSearch').val(data1[0].PatientName);
                        $('#hdpat_id').val(data1[0].patient_id);
                        $('#HdnVisitId').val(data1[0].visit_reportid);
                        $('#HdnPatientId').val(data1[0].patientid);
                        $('#PaitentSearch').attr('disabled', true);
                        Load_OTSurgery(data1[0].visit_reportid);
                    }
                }
                else {
                    console.log(data);
                }
            }
        }
    });
}