function PatientSearch(patient_id, type, branch_id, visit_id) {
   
    debugger;
    var PatientSearchData = {
        visit_type: type,
        Dml_Indicator: 'LP',
        patient_id: patient_id,
        branch_id: branch_id,
        visit_report_id: visit_id
    }
   return $.ajax({
        async: true,
        type: 'POST',
        url: '/Billing/IP_OP_Request',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientSearchData),
        success: function (data) {
            console.log(data);
            debugger;
            var data1 = JSON.parse(data);
            if (data1.msg == "Success") {
                console.log(data1);
                var data1 = data1.data;
                if (jQuery.isEmptyObject((data1))) {
                    $('#txtPaitentSearch_1').val('');
                    toastr.warning('Something went wrong. Please try after sometime');
                }
                else {

                    if (data1.length > 0) {
                        $('.pat-strip').show();
                        if (data1[0].visit_type == 2) {
                            $('.ip-strip').show();
                            $('.op-strip').hide();
                            $('#DOA,.DOA1').show();
                            $('#billing_class,.billing_class1').show()
                            $('#ward_id,.ward_id1').show();
                            $('#bed_id,.bed_id1').show();
                            $('#div_ipoperation,.div_ipoperation').show();
                            $('#visit_name,.visit_name').html('IP Admission No : ' + data1[0].display_visit_report);
                        }
                        else {
                            $('#DOA,.DOA1').hide();
                            $('#ward_id,.ward_id1').hide();
                            $('#billing_class,.billing_class1').hide();
                            $('#bed_id,.bed_id1').hide();
                            $('.ip-strip').hide();
                            $('#div_ipoperation,.div_ipoperation').hide();
                            $('#visit_name,.visit_name').html('Visit No : ' + data1[0].display_visit_report);
                        }
                        $('#PatName').val(data1[0].patient_name);
                        $('.pat-stripe-user-name').html('<a data-toggle="modal" style="cursor: pointer;" onclick=\'billing_details(\"' + data1[0].patient_id + '\",\"' + data1[0].patient_name + '\",\"' + data1[0].phone_number_1 + '\",\"' + data1[0].Due_Status + '\",this)\'>' + data1[0].patient_name);
                        $('.pat_contact').html(data1[0].phone_number_1);
                        $('.pat_id').html(data1[0].patient_id1);
                        $('.billing_class').html(data1[0].master_service_name);
                        $('#Hpatientid').val(data1[0].patient_id);
                        //data1[0].is_entity == 1 ? $('#entity').show() : $('#entity').hide();
                        if (data1[0].is_entity == 1) {
                            $('#entity').show()
                            $('.diventity').show()
                        } else {
                            $('#entity').hide();
                            $('.diventity').hide();
                        }
                        if ((data1[0].is_insurance == 1 ||data1[0].is_insurance == 2)  && data1[0].is_MultiPay==1) {
                            $('#div_tpa').show();
                            $('.div_tpa').show();
                            var h1 = (data1[0].is_insurance == 1)?'TPA : ':'Insurance Name : '
                            $('#tpa_insurance').html(h1 + '<span>' + data1[0].TPA_Insurance_Name + '</span>');
                            $('.tpa_insurance').html(h1 + '<span>' + data1[0].TPA_Insurance_Name + '</span>');
                        }
                       
                        //$('#Hpatientid').change();
                        $('.age').html(data1[0].age + ' Yrs /' + data1[0].gender);
                        if (data1[0].patient_height == '' || data1[0].patient_height == null) {
                            $('.height').html('-');
                        }
                        else {
                            var hieghtdb = parseInt(data1[0].patient_height * 12) + parseInt(data1[0].patient_height_metric);
                            var hieghtout = Math.round(hieghtdb * 2.54);
                            $('.height').html(hieghtout + 'cm');

                        }
                        if (data1[0].patient_weight == '' || data1[0].patient_weight == null) {
                            $('.weight').html('-');
                        }
                        else {
                            $('.weight').html(data1[0].patient_weight + 'kg');

                        }
                        $('#hdn_visit_doctorid').val(data1[0].last_visit_doctor_id_var);
                        $('#hdn_visit_doctorname').val(data1[0].last_docname);
                        $('.DOA').html(data1[0].ip_patient_admitdate);
                        $('.entity').html(data1[0].insurance_id);
                        $('.visit').html(data1[0].visit_count);
                        $('.visit_date').html(data1[0].created_on);
                        //$('.visit_id').html(data1[0].display_visit_report);
                        $('#Hvisitid').val(data1[0].visit_report_id);
                        $('#Vvisit_reportid').val(data1[0].visit_reportid);
                        $('.pat_address').html(data1[0].address_line_1 + ',<p class="mar0 mt5 ml-10">' + data1[0].address_line_2 + ',</p><p class="mar0 mt5 ml-10">' + data1[0].city + ', ' + data1[0].place + ',</p><p class="mar0 mt5 ml-10">' + data1[0].state + '-' + data1[0].pincode) + ', ' + data1[0].country + '</p>';
                        $('.doc_name').html(data1[0].doctor_name);
                        $('.ward_id').html(data1[0].ward_code);
                        $('#Hwardid').val(data1[0].wardid);
                        $('.bed_id').html(data1[0].bed_code);
                        $('#Hbedid').val(data1[0].bed_id);
                       // LoadVisitDoctor();
                     //   $('#VisitDoctor').append('<option value="' + data1[0].doctor_id + '">' + data1[0].doctor_name + '</option>');
                      //  $('#VisitDoctor').val(data1[0].doctor_name);
                        $('.visit_type').html(data1[0].visit_type_name);
                        $('#OperationName').html(data1[0].ip_operation_name);
                        $('.OperationName').html(data1[0].ip_operation_name);
                        $('#Hbilling_class').val(data1[0].billing_class);
                        $('#VBranch_id').val(data1[0].branch_id);
                        $('.IPpatblood,#IPpatblood').html(data1[0].patient_blood_group);
                        $('#firstvisit,.firstvisit').html(data1[0].first_visit);
                        $('#opdvisit,.opdvisit').html(data1[0].opd_number);
                        if (data1[0].is_app_installed == null || data1[0].is_app_installed != 1) {
                            $('#app_no').show();
                            $('#app_yes').hide();
                        }

                        if (data1[0].PatientImage == null || $.trim(data1[0].PatientImage) == "") {
                            $("#CardPatientImage").attr("src", "/Content/img/profile_icon.png");
                        }
                        else {
                            var PtImage = $('#hdnfilepath1').val() + $('#HospitalId').val() + '/PatientImage/' + data1[0].PatientImage;
                            $("#CardPatientImage").attr("src", PtImage);
                        }

                    }
                    else {
                        $('.pat-strip').hide();
                        var msg = '';
                        if (type == 1 || type == 3 || type == 4) {
                            msg = 'No Visit for the Patient'
                        }
                        else {
                            msg = 'No IP Visit for the Patient'
                        }
                        toastr.warning(msg,
                   {
                       closeButton: false,
                       progressBar: true,
                       allowHtml: true,
                       timeOut: 0,
                   })
                        setTimeout(function () {
                            $('#txtPaitentSearch_1').val('')
                            $('#txtPaitentSearch_1').attr('disabled', false);
                        }, 2000);

                    }
                }
            }
            else {
                console.log(data1);
            }
        }
    })
}
// For IP in request page
function PatientSearchrequest(patient_id, type, branch_id, visit_id) {
    var PatientSearchData = {
        visit_type: type,
        Dml_Indicator: 'LPR',
        patient_id: patient_id,
        branch_id: branch_id,
        visit_id: visit_id
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Billing/IP_OP_Request',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientSearchData),
        success: function (data) {
            console.log(data);
            debugger;
            var data1 = JSON.parse(data);
            if (data1.msg == "Success") {
                console.log(data1);
                var data1 = data1.data;
                if (jQuery.isEmptyObject((data1))) {
                    $('#txtPaitentSearch_1').val('');
                    toastr.warning('Something went wrong. Please try after sometime');
                }
                else {

                    if (data1.length > 0) {

                        if (data1[0].ip_visit_report_status == 2) {
                            msg = 'No ' + $('#visit_type option:selected').text() + ' Visit for the Patient'
                            toastr.warning(msg,
                           {
                               closeButton: false,
                               progressBar: true,
                               allowHtml: true,
                               timeOut: 0,
                           })
                            setTimeout(function () {
                                $('#txtPaitentSearch_1').val('')
                                $('#txtPaitentSearch_1').attr('disabled', false);
                            }, 2000);
                        }
                        else if (data1[0].ip_nursing_discharge == 1) {
                            msg = 'Patient Discharged'
                            toastr.warning(msg,
                        {
                            closeButton: false,
                            progressBar: true,
                            allowHtml: true,
                            timeOut: 0,
                        })
                            setTimeout(function () {
                                $('#txtPaitentSearch_1').val('')
                                $('#txtPaitentSearch_1').attr('disabled', false);
                            }, 2000);
                        }
                        else {
                            $('.pat-strip').show();
                            if (data1[0].visit_type == 2) {
                                $('.ip-strip').show();
                                $('.op-strip').hide();
                                $('#DOA').show();
                            
                                $('#ward_id').show();
                                $('#bed_id').show();
                            }
                            else {

                                $('#DOA').hide();
                               
                                $('#ward_id').hide();
                                $('#bed_id').hide();
                                $('.ip-strip').hide();
                            }
                            $('.pat-stripe-user-name').html(data1[0].patient_name);
                            $('.pat_contact').html(data1[0].phone_number_1);
                            $('.pat_id').html(data1[0].patient_id1);
                            $('.billing_class').html(data1[0].master_service_name);
                            $('#Hpatientid').val(data1[0].patient_id);
                            $('.age').html(data1[0].age + ' Yrs /' + data1[0].gender);
                            if (data1[0].patient_height == '' || data1[0].patient_height == null) {
                                $('.height').html('-');
                            }
                            else {
                                var hieghtdb = parseInt(data1[0].patient_height * 12) + parseInt(data1[0].patient_height_metric);
                                var hieghtout = Math.round(hieghtdb * 2.54);
                                $('.height').html(hieghtout + 'cm');

                            }
                            if (data1[0].patient_weight == '' || data1[0].patient_weight == null) {
                                $('.weight').html('-');
                            }
                            else {
                                $('.weight').html(data1[0].patient_weight + 'kg');

                            }
                            if (data1[0].is_entity == 1) {
                                $('#entity').show()
                                $('.diventity').show()
                            } else {
                                $('#entity').hide();
                                $('.diventity').hide();
                            }
                            if ((data1[0].is_insurance == 1 || data1[0].is_insurance == 2) && data1[0].is_MultiPay == 1) {
                                $('#div_tpa').show();
                                $('.div_tpa').show();
                                var h1 = (data1[0].is_insurance == 1) ? 'TPA : ' : 'Insurance Name : '
                                $('#tpa_insurance').html(h1 + '<span>' + data1[0].TPA_Insurance_Name + '</span>');
                                $('.tpa_insurance').html(h1 + '<span>' + data1[0].TPA_Insurance_Name + '</span>');
                            }
                            $('#hdn_visit_doctorid').val(data1[0].last_visit_doctor_id_var);
                            $('#hdn_visit_doctorname').val(data1[0].last_docname);
                            $('.DOA').html(data1[0].ip_patient_admitdate);
                            $('.entity').html(data1[0].insurance_id);
                            $('.visit').html(data1[0].visit_count);
                            $('.visit_date').html(data1[0].created_on);
                            $('.visit_id').html(data1[0].display_visit_report);
                            $('#Hvisitid').val(data1[0].visit_report_id);
                            $('.pat_address').html(data1[0].address_line_1 + ',<p class="mar0 mt5 ml-10">' + data1[0].address_line_2 + ',</p><p class="mar0 mt5 ml-10">' + data1[0].city + ', ' + data1[0].place + ',</p><p class="mar0 mt5 ml-10">' + data1[0].state + '-' + data1[0].pincode) + ', ' + data1[0].country + '</p>';
                            $('.doc_name').html(data1[0].doctor_name);
                            $('.ward_id').html(data1[0].ward_code);
                            $('#Hwardid').val(data1[0].wardid);
                            $('.bed_id').html(data1[0].bed_code);
                            $('#Hbedid').val(data1[0].bed_id);
                            $('.visit_type').html(data1[0].visit_type_name);
                            $('#IPpatblood,.IPpatblood').html(data1[0].patient_blood_group);
                            $('#firstvisit,.firstvisit').html(data1[0].first_visit);
                            $('#Hbilling_class').val(data1[0].billing_class);
                            $('#VBranch_id').val(data1[0].branch_id);
                            if (data1[0].is_app_installed == null || data1[0].is_app_installed != 1) {
                                $('#app_no').show();
                                $('#app_yes').hide();
                            }

                            if (data1[0].PatientImage == null || $.trim(data1[0].PatientImage) == "") {
                                $("#CardPatientImage").attr("src", "/Content/img/profile_icon.png");
                            }
                            else {
                                var PtImage = $('#hdnfilepath1').val() + $('#HospitalId').val() + '/PatientImage/' + data1[0].PatientImage;
                                $("#CardPatientImage").attr("src", PtImage);
                            }

                        }
                    }
                    else {
                        //$('.pat-strip').hide();
                        //var msg = '';
                        //if (data1[0].ip_visit_report_status==2) {
                        msg = 'No ' + $('#visit_type option:selected').text() + ' Visit for the Patient'
                        //}
                        //else {
                        //    msg = 'Patient Discharged..'
                        //}
                        toastr.warning(msg,
                   {
                       closeButton: false,
                       progressBar: true,
                       allowHtml: true,
                       timeOut: 0,
                   })
                        setTimeout(function () {
                            $('#txtPaitentSearch_1').val('')
                            $('#txtPaitentSearch_1').attr('disabled', false);
                        }, 2000);

                    }
                }
            }
            else {
                console.log(data1);
            }
        }
    })
}
//Package purchase details card binding
function package_details_card(package_name, cost_of_package, expire_date) {
    debugger;
    $('.packname').html(package_name);
    $('.packcost').html(cost_of_package);
    $('.packexdate').html(expire_date);
    $('.pack_card').show();
}



function PatientGeneralDetails(patient_id, branch_id) {

    var PatientSearchData = {        
        Dml_Indicator: 'GP',
        patient_id: patient_id,
        branch_id: branch_id        
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Billing/IP_OP_Request',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientSearchData),
        success: function (data) {
            console.log(data);
            debugger;
            var data1 = JSON.parse(data);
            if (data1.msg == "Success") {
                console.log(data1);
                var data1 = data1.data;
                if (jQuery.isEmptyObject((data1))) {                   
                    toastr.warning('Something went wrong. Please try after sometime');
                }
                else {

                    if (data1.length > 0) {
                        $('.pat-strip').show();
                    
                       
                        $('#DOA').hide();
                        $('#entity').hide();
                        $('#ward_id').hide();
                        $('#billing_class').hide();
                        $('#bed_id').hide();
                        $('.ip-strip').hide();
                        $('#doctorName').hide();
                        $('#visitNo').hide();
                        $('#patientType').hide();
                      

                        $('.pat-stripe-user-name').html(data1[0].patient_name);
                        $('.pat_contact').html(data1[0].phone_number_1);
                        $('.pat_id').html(data1[0].patient_id1);                       
                        $('#Hpatientid').val(data1[0].patient_id);
                        $('.age').html(data1[0].age + ' Yrs /' + data1[0].gender);
                        if (data1[0].patient_height == '' || data1[0].patient_height == null) {
                            $('.height').html('-');
                        }
                        else {
                            var hieghtdb = parseInt(data1[0].patient_height * 12) + parseInt(data1[0].patient_height_metric);
                            var hieghtout = Math.round(hieghtdb * 2.54);
                            $('.height').html(hieghtout + 'cm');

                        }
                        if (data1[0].patient_weight == '' || data1[0].patient_weight == null) {
                            $('.weight').html('-');
                        }
                        else {
                            $('.weight').html(data1[0].patient_weight + 'kg');

                        }                        
                        $('.visit').html(data1[0].visit_count);
                        $('.visit_date').html(data1[0].created_on);
                        $('#IPpatblood,.IPpatblood').html(data1[0].patient_blood_group);
                        $('#firstvisit,.firstvisit').html(data1[0].first_visit);
                        $('.pat_address').html(data1[0].address_line_1 + ',<p class="mar0 mt5 ml-10">' + data1[0].address_line_2 + ',</p><p class="mar0 mt5 ml-10">' + data1[0].city + ', ' + data1[0].place + ',</p><p class="mar0 mt5 ml-10">' + data1[0].state + '-' + data1[0].pincode) + ', ' + data1[0].country + '</p>';

                        if (data1[0].is_app_installed == null || data1[0].is_app_installed != 1) {
                            $('#app_no').show();
                            $('#app_yes').hide();
                        }

                        if (data1[0].PatientImage == null || $.trim(data1[0].PatientImage) == "") {
                            $("#CardPatientImage").attr("src", "/Content/img/profile_icon.png");
                        }
                        else {
                            var PtImage = $('#hdnfilepath1').val() + $('#HospitalId').val() + '/PatientImage/' + data1[0].PatientImage;
                            $("#CardPatientImage").attr("src", PtImage);
                        }
                    }
                    else {
                        $('.pat-strip').hide();                      
                    }
                }
            }
            else {
                console.log(data1);
            }
        }
    })

}

function IP_PatientGeneralDetails(patient_id, branch_id) {

    var PatientSearchData = {
        Dml_Indicator: 'IPGP',
        patient_id: patient_id,
        branch_id: branch_id
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Billing/IP_OP_Request',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientSearchData),
        success: function (data) {
            console.log(data);
            debugger;
            var data1 = JSON.parse(data);
            if (data1.msg == "Success") {
                console.log(data1);
                var data1 = data1.data;
                if (jQuery.isEmptyObject((data1))) {
                    toastr.warning('Something went wrong. Please try after sometime');
                }
                else {

                    if (data1.length > 0) {
                        $('.pat-strip').show();


                        $('#DOA').hide();
                        $('#entity').hide();
                        $('#ward_id').hide();
                        $('#billing_class').hide();
                        $('#bed_id').hide();
                        $('.ip-strip').hide();
                        $('#doctorName').hide();
                        $('#visitNo').hide();
                        $('#patientType').hide();


                     //   $('.pat-stripe-user-name').html(data1[0].patient_name);
                        $('.pat-stripe-user-name').html('<a data-toggle="modal" style="cursor: pointer;" onclick=\'billing_details(\"' + data1[0].patient_id + '\",\"' + data1[0].patient_name + '\",\"' + data1[0].phone_number_1 + '\",\"' + data1[0].Due_Status + '\",this)\'>' + data1[0].patient_name);

                        $('.pat_contact').html(data1[0].phone_number_1);
                        $('.pat_id').html(data1[0].patient_id1);
                        $('#Hpatientid').val(data1[0].patient_id);
                        $('.age').html(data1[0].age + ' Yrs /' + data1[0].gender);
                        if (data1[0].patient_height == '' || data1[0].patient_height == null) {
                            $('.height').html('-');
                        }
                        else {
                            var hieghtdb = parseInt(data1[0].patient_height * 12) + parseInt(data1[0].patient_height_metric);
                            var hieghtout = Math.round(hieghtdb * 2.54);
                            $('.height').html(hieghtout + 'cm');

                        }
                        if (data1[0].patient_weight == '' || data1[0].patient_weight == null) {
                            $('.weight').html('-');
                        }
                        else {
                            $('.weight').html(data1[0].patient_weight + 'kg');

                        }
                        $('.visit').html(data1[0].visit_count);
                        $('.visit_date').html(data1[0].created_on);
                        $('#IPpatblood,.IPpatblood').html(data1[0].patient_blood_group);
                        $('#firstvisit,.firstvisit').html(data1[0].first_visit);
                        $('.pat_address').html(data1[0].address_line_1 + ',<p class="mar0 mt5 ml-10">' + data1[0].address_line_2 + ',</p><p class="mar0 mt5 ml-10">' + data1[0].city + ', ' + data1[0].place + ',</p><p class="mar0 mt5 ml-10">' + data1[0].state + '-' + data1[0].pincode) + ', ' + data1[0].country + '</p>';

                        if (data1[0].is_app_installed == null || data1[0].is_app_installed != 1) {
                            $('#app_no').show();
                            $('#app_yes').hide();
                        }

                        if (data1[0].PatientImage == null || $.trim(data1[0].PatientImage) == "") {
                            $("#CardPatientImage").attr("src", "/Content/img/profile_icon.png");
                        }
                        else {
                            var PtImage = $('#hdnfilepath1').val() + $('#HospitalId').val() + '/PatientImage/' + data1[0].PatientImage;
                            $("#CardPatientImage").attr("src", PtImage);
                        }
                    }
                    else {
                        $('.pat-strip').hide();
                    }
                }
            }
            else {
                console.log(data1);
            }
        }
    })

}


