$(document).ready(function () {
    $('.ip_fields').show();
    if ($("#IPPatient_Id").val() != "" || $("#IPPatient_Id").val() != null) {
        if ($("#IPReportId").val() == "" || $("#IPReportId").val() == null) {
            //loadpatientdetails();
        }
    }

    if ($("#IPDischarge_Id").val() == "2") {
        $('#HeaderEdit').hide();
        $('.disable').prop('readonly', true);
        $(':input[type="checkbox"]').prop('disabled', true);
        $('.disable').attr("disabled", true);
        $('.btndisable').removeAttr('id');
        $('.btndisable').attr("disabled", true);
    }

    if ($('#OPVisitReport_Id').val() == "" || $('#OPVisitReport_Id').val() == null)
    {
        var data= PatientSearch($('#IPPatient_Id').val(), "2", $('#hBranch_Id').val(), $('#IPVisitReport_Id').val());
        debugger;
        $.when(data)
            .then(function (data3) {
                debugger;
                //var dbDate = "02-03-2023";
                //var date2 = new Date("dbDate");
                //alert($('.DOA').html());
                var date = $('.DOA').html().split('-');
                date = date[2] + '-' + date[1] + '-' + date[0];
                
                $('#txtTransferdate').datepicker("destroy");
                $('#txtTransferdate').datepicker({
                    autoclose: true,
                    todayHighlight: true,
                    format: "dd/mm/yyyy",
                    startDate: new Date(date),
                    endDate: "today"
                    //endDate: new Date()
                })


            });

        
    }

    if($('#IPDischarge_Id').val()!=0)
    {
        $('#IP_EditBtn').hide();
    }

    
  
});

function loadpatientdetails() {
    var Fetchdata = {
        Dml_Indicator: "PD",
        patient_ID: $("#IPPatient_Id").val(),
        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(Fetchdata),
        success: function (data) {
            var data1 = JSON.parse(data);
            if (data1.msg == "Success") {
                var data1 = data1.data;
                if (jQuery.isEmptyObject((data1))) {

                }
                else {
                    $.each(data1, function (i, emp) {
                        $("#IPpatientid").html(emp.ip_patient_id + " | " + emp.ip_doctor_name),
                        $("#IPpatiendname").html(emp.PatientName),
                        $("#IPpatiendage").html(emp.age + " years | " + emp.gender),
                        $("#IPpatblood").html(emp.patient_blood_group),
                        $("#IPdate").html(emp.ip_patient_admitdate),
                        $("#IPBed").html(emp.Bed_Name),
                        $("#IPWard").html(emp.ward_name),
                        $("#IPReportId").val(emp.ip_visit_report_id),
                        $("#OperationName").html(emp.ip_operation_name),
                        $("#IPInsurance").html(emp.Insurance_Name),
                        $("#IPBilling").html(emp.BillingName),
                        $('#IPwardcategory').val(emp.wardid),
                        $('#IPpatiendphone').html(emp.patient_phone_number)

                        if (emp.type_of_admition == 1)
                        {
                            $('#div_ipoperation').hide();
                        }
                        else {
                            $('#div_ipoperation').show();
                        }
                    });
                }
            }
            else {
                console.log(data1);
            }
        }
    });
}