//var vitals_nodata_img = '<img src="/Content/img/vitals_nodata_img.png" class="img-responsive vitals_nodata_img" />';
var vitals_nodata_img = '<div class="well">No Recorded Value</div>';
$(document).ready(function () {
    loadvisit_type()
    $('#EditCaseSheet').hide();
    CheckAppointmnet();
    patient_select_new();
    loadwatch_parameter();
    
    show_preloader('vitals_');
    show_preloader('prescription_');
    show_preloader('lab_tests_');
});
var patient = $('#Hdnpatient_id').val();

function changedefault(e) {
    var photoSrc = "/Content/img/profile_icon.png";
    console.log("Image Error")
    $(e).attr("src", photoSrc)
}

function Patient_select() {
    var patient
    if ($('#Hdnpatient_id').val() == '') {
        patient = $('#EditVisitReportID').val();
        var patient_id = patient.split('-');
        patient = patient_id[0];
    }
    else {
        patient = $('#Hdnpatient_id').val()
    }

    var PatientData = {
        Patient_id: patient,
        Dml_Indicator: '1',
        Doctor_id: $('#doctorId').val()
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/CaseStudy/CaseStudy',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientData),
        success: function (data) {
            var data = JSON.parse(data);
            if (data.msg == "Success") {
                var data = data.data;
                if (jQuery.isEmptyObject((data))) {

                }
                else {
                    console.log(data);
                    if (data.length > 0) {
                        $('#noofvisit').html(data[0].visit_count);
                        if (data[0].created_on == '' || data[0].created_on == null) {
                            $('#firstvisit').html('');
                        }
                        else {
                            $('#firstvisit').html(data[0].created_on);
                        }
                        $('#moreinfovisit_date').html(data[0].visit_count + ' visits since ' + $('#firstvisit').html());
                        if (data.Table[0].type_of_diabetes == '' || data.Table[0].type_of_diabetes == null) {
                            $('#diab').html('Type of Diabetes');
                            $('.diab').html('Type of Diabetes');
                            $('body').removeClass('orange_bg1');
                            $('body').removeClass('orange_bg2');
                            $('body').removeClass('orange_bg3');
                            $('body').removeClass('orange_bg4');
                            $('body').removeClass('orange_bg5');
                            $('body').addClass('orange_bg');
                        }
                        else if (data.Table[0].type_of_diabetes == '0') {
                            $('#diab').html('Diabetes');
                            $('.diab').html('Diabetes');
                            $('#diabVal').val(data.Table[0].type_of_diabetes);
                            $('#diab').html('Type of Diabetes');
                            $('.diab').html('Type of Diabetes');
                            $('body').removeClass('orange_bg1');
                            $('body').removeClass('orange_bg2');
                            $('body').removeClass('orange_bg3');
                            $('body').removeClass('orange_bg4');
                            $('body').removeClass('orange_bg5');
                            $('body').addClass('orange_bg');

                        }
                        else if (data.Table[0].type_of_diabetes == '1') {
                            $('#diab').html('Type1');
                            $('.diab').html('Type1');
                            $('#diabVal').val(data.Table[0].type_of_diabetes);
                            $('body').removeClass('orange_bg');
                            $('body').removeClass('orange_bg1');
                            $('body').removeClass('orange_bg3');
                            $('body').removeClass('orange_bg4');
                            $('body').removeClass('orange_bg5');
                            $('body').addClass('orange_bg2');
                        }
                        else if (data.Table[0].type_of_diabetes == '2') {
                            $('#diab').html('Type2');
                            $('.diab').html('Type2');
                            $('#diabVal').val(data.Table[0].type_of_diabetes);

                            $('body').removeClass('orange_bg');
                            $('body').removeClass('orange_bg1');
                            $('body').removeClass('orange_bg2');
                            $('body').removeClass('orange_bg3');
                            $('body').removeClass('orange_bg4');
                            $('body').addClass('orange_bg5');

                        }
                        else if (data.Table[0].type_of_diabetes == '3') {
                            $('#diab').html('MODY');
                            $('.diab').html('MODY');
                            $('#diabVal').val(data.Table[0].type_of_diabetes);
                            $('body').removeClass('orange_bg');
                            $('body').removeClass('orange_bg1');
                            $('body').removeClass('orange_bg2');
                            $('body').removeClass('orange_bg3');
                            $('body').removeClass('orange_bg5');
                            $('body').addClass('orange_bg4');
                        }
                        else if (data.Table[0].type_of_diabetes == '4') {
                            $('#diab').html('LADA');
                            $('.diab').html('LADA');
                            $('#diabVal').val(data.Table[0].type_of_diabetes);
                            $('body').removeClass('orange_bg');
                            $('body').removeClass('orange_bg1');
                            $('body').removeClass('orange_bg2');
                            $('body').removeClass('orange_bg3');
                            $('body').removeClass('orange_bg5');
                            $('body').addClass('orange_bg4');
                        }
                        else if (data.Table[0].type_of_diabetes == '5') {
                            $('#diab').html('GDM');
                            $('.diab').html('GDM');
                            $('#diabVal').val(data.Table[0].type_of_diabetes);
                            $('body').removeClass('orange_bg');
                            $('body').removeClass('orange_bg1');
                            $('body').removeClass('orange_bg2');
                            $('body').removeClass('orange_bg4');
                            $('body').removeClass('orange_bg5');
                            $('body').addClass('orange_bg3');


                        }
                        else if (data.Table[0].type_of_diabetes == '6') {
                            $('#diab').html('Other');
                            $('.diab').html('Other');
                            $('#diabVal').val(data.Table[0].type_of_diabetes);
                            $('body').removeClass('orange_bg');
                            $('body').removeClass('orange_bg1');
                            $('body').removeClass('orange_bg2');
                            $('body').removeClass('orange_bg3');
                            $('body').removeClass('orange_bg5');
                            $('body').addClass('orange_bg4');
                        }

                        $('#smoking').val(data[0].patient_smoking_habit);
                        var image = (data[0].photo);
                        var PatientPhoto = $('#ChdnPatientPhoto').val();
                        if ($.trim(image) == "" || image == null) {
                            photoSrc = "/Content/img/profile_icon.png";
                        }
                        else {
                            photoSrc = PatientPhoto + image;
                        }

                        $('.imgphoto').attr('src', photoSrc);


                        var first_name = (data[0].first_name)
                        var last_name = (data[0].last_name)
                        if (last_name == '' || last_name == null) {
                            last_name = '';
                        }
                        first_name = first_name + ' ' + last_name;
                        $("#PatientName").attr('title', data[0].patient_id);
                        $('.PatientName').html(first_name);
                        $('.Patientpno').html('<i class="fa fa-phone" aria-hidden="true"></i> ' + data[0].phone_number_1);

                        $('#PatientId').html(data[0].patient_id);
                        if (data[0].DOB == '' || data[0].DOB == null) {
                            if (data[0].age_registered_date == "" || data[0].age_registered_date == null) {
                                if (data[0].gender == '' || data[0].gender == null) {
                                    $('.age').html('-');
                                }
                                else if (age == "" || age == null) {
                                    $('.age').html('-');
                                }
                                else {
                                    $('.age').html('-');
                                }
                            }
                            else {
                                var dob = (data[0].age_registered_date);
                                dob = new Date(dob);
                                var today = new Date();
                                age = Math.floor((today - dob) / (365.25 * 24 * 60 * 60 * 1000));
                            }

                            //$('#hndage').val(age);
                            $('#gender').val(data[0].gender);

                            var gender;
                            if (data[0].gender == '1') {
                                gender = ' - 1'
                                $('#Male').prop('checked', true);
                            }
                            if (data[0].gender == '2') {
                                gender = ' - 2'
                                $('#Female').prop('checked', true);
                            }
                            if (data[0].gender == '3') {
                                gender = ' - 3'
                                $('#Male').prop('checked', true);

                            }
                            var genders = data[0].gender;
                            if (genders == 1) {
                                genders = 'Male';
                            }
                            else if (genders == 2) {
                                genders = 'Female';
                            }
                            else if (genders == 3) {
                                genders = 'Others';
                            }
                            else {
                                genders = 'Gender';
                            }
                            var age = '';
                            if (data[0].age == '' || data[0].age == null) {
                                age = 'Age';
                            }
                            else {
                                age = data[0].age + ' years ';
                            }
                            $('#hndage').val(age);
                            $('#AAge').val(age);
                            $('.Age').html(age + genders);

                        }
                        else {
                            var gender, age, dob;
                            if (data[0].gender == '1') {
                                gender = ' - 1'
                                $('#Male').prop('checked', true);
                            }
                            if (data[0].gender == '2') {
                                gender = ' - 2'
                                $('#Female').prop('checked', true);
                            }
                            if (data[0].gender == '3') {
                                gender = ' - 3'
                                $('#Male').prop('checked', true);

                            }

                            //var dob = (data[0].DOB);
                            //dob = new Date(dob);
                            //var today = new Date();
                            //var age = Math.floor((today - dob) / (365.25 * 24 * 60 * 60 * 1000));

                            dob = (data[0].DOB);
                            dob = new Date(dob);
                            var today = new Date();
                            age = Math.floor((today - dob) / (365.25 * 24 * 60 * 60 * 1000));

                            $('#gender').val(gender);
                            $('#hndage').val(age);
                            var genders = data[0].gender;
                            if (genders == 1) {
                                genders = 'Male';
                            }
                            else if (genders == 2) {
                                genders = 'Female';
                            }
                            else if (genders == 3) {
                                genders = 'Others';
                            }
                            else {
                                genders = 'Gender';
                            }

                            $('#gender').val(data[0].gender);
                            var sex = data[0].gender;
                            if (sex == 1) {
                                $("#Male").prop('checked', true);
                            }
                            if (sex == 2) {
                                $("#Female").prop('checked', true);
                            }
                            //$('#AAge').val(age);
                            $('.Age').html(age + ' ' + 'years ' + genders);
                        }
                        if (data[0].diabetes_of_year == '' || data[0].diabetes_of_year == null) {
                            $('#diabetes').html('Histroy in years');
                        }
                        else {

                            $('#diabetes').html(data[0].diabetes_of_year + ' Years');
                            $('#txtCHDiabetes').val(data[0].diabetes_of_year);
                            $('#yearDia').html(data[0].diabetes_of_year);
                        }
                        if (data[0].patient_height == '' || data[0].patient_height == null) {
                            $('#hieght').html('-');
                        }
                        else {
                            //var hieghtdb = data[0].patient_height + '.' + data[0].patient_height_metric;
                            //var hieghtout = Math.round(hieghtdb / 0.032808);

                            var hieghtdb = parseInt(data[0].patient_height * 12) + parseInt(data[0].patient_height_metric);
                            var hieghtout = Math.round(hieghtdb * 2.54);
                            $('#hieght').html(hieghtout);
                            $('#hidhieghtFt').val(data[0].patient_height);
                            $('#hidhieghtIn').val(data[0].patient_height_metric);
                        }
                        if (data[0].patient_weight == '' || data[0].patient_weight == null) {
                            $('#wight').html('-');
                        }
                        else {
                            $('#wight').html(data[0].patient_weight);
                            $('#hidwight').val(data[0].patient_weight);
                        }

                        var heightFt = (data[0].patient_height),
                        heightIn = (data[0].patient_height_metric),
                        height = parseFloat(heightFt * 12) + parseFloat(heightIn);
                        var weight = (data[0].patient_weight);
                        weight = (weight * 2.20462)
                        BMI = calculateBMI(height, weight);

                        $('#bmi').text(isNaN(BMI) ? '-' : BMI);

                        var BmiFlags = $('#bmi').text();
                        if (BmiFlags <= 18.5) {
                            $('#BMI').html('Underweight');
                            //$('.BMI_head > i').addClass('above_average');
                            $('#BMI_head').addClass('dash-notify-above');
                        }
                        else if (BmiFlags > 18.5 && BmiFlags <= 24.9) {
                            $('#BMI').html('Normal');
                            //$('.BMI_head > i').addClass('hide');
                            $('#BMI_head').addClass('dash-notify-normal');
                        }
                        else if (BmiFlags > 25.0 && BmiFlags <= 29.9) {
                            $('#BMI').html('Overweight');
                            //$('.BMI_head > i').addClass('above_average');
                            $('#BMI_head').addClass('dash-notify-above');
                        }
                        else if (BmiFlags >= 30.0) {
                            $('#BMI').html('Obese');
                            //$('.BMI_head > i').addClass('below_average');
                            $('#BMI_head').addClass('dash-notify-above');

                        }

                        $('#ChkAlcohol').val(data[0].patient_alcohol_consumption);
                        $('a[data-toggle=ChkAlcohol][data-title="' + data[0].patient_alcohol_consumption + '"]').removeClass('not-active');
                        $('a[data-toggle=ChkAlcohol][data-title="' + data[0].patient_alcohol_consumption + '"]').addClass('active');
                        var ls = data[0].patient_alcohol_consumption;
                        var lsTxt;
                        if (ls == 1) {
                            lsTxt = "Non Drinker";
                        } else if (ls == 2) {
                            lsTxt = "Rare";
                        } else if (ls == 3) {
                            lsTxt = "Social";
                        } else if (ls == 4) {
                            lsTxt = "Regular";
                        } else if (ls == 5) {
                            lsTxt = "Heavy";
                        }
                        else {
                            lsTxt = "Select";
                        }
                        $('#AlcText_1>span').text(lsTxt);

                        $('#ChkFood').val(data[0].patient_food_perference);
                        $('a[data-toggle=ChkFood][data-title="' + data[0].patient_food_perference + '"]').removeClass('not-active');
                        $('a[data-toggle=ChkFood][data-title="' + data[0].patient_food_perference + '"]').addClass('active');
                        var ls = data[0].patient_food_perference;
                        var lsTxt;
                        if (ls == 1) {
                            lsTxt = "Vegetarian";
                        } else if (ls == 2) {
                            lsTxt = "Non-Vegetarian";
                        } else if (ls == 3) {
                            lsTxt = "Eggetarian";
                        } else if (ls == 4) {
                            lsTxt = "Vegan";
                        }
                        else {
                            lsTxt = "Select";
                        }
                        $('#ChkFoodText_1>span').text(lsTxt);

                        $('#ChkSmoking').val(data[0].patient_smoking_habit);
                        $('a[data-toggle=ChkSmoking][data-title="' + data[0].patient_smoking_habit + '"]').removeClass('not-active');
                        $('a[data-toggle=ChkSmoking][data-title="' + data[0].patient_smoking_habit + '"]').addClass('active');

                        var ls = data[0].patient_smoking_habit;
                        var lsTxt;
                        if (ls == "8517006") {
                            lsTxt = "Iv'e quit";
                        } else if (ls == "266919005") {
                            lsTxt = "Don't Smoke";
                        } else if (ls == "4.28061E+14") {
                            lsTxt = "1-2/day";
                        } else if (ls == "4.28041E+14") {
                            lsTxt = "3-5/day";
                        } else if (ls == "4.28071E+14") {
                            lsTxt = "5-10/day";
                        } else if (ls == "449868002") {
                            lsTxt = "10/day";
                        }
                        else {
                            lsTxt = "Select";
                        }
                        $('#smkText_1>span').text(lsTxt);

                        $('#ChkActivity').val(data[0].patient_activity_level);
                        $('a[data-toggle=ChkActivity][data-title="' + data[0].patient_activity_level + '"]').removeClass('not-active');
                        $('a[data-toggle=ChkActivity][data-title="' + data[0].patient_activity_level + '"]').addClass('active');
                        var ls = data[0].patient_activity_level;
                        var lsTxt;
                        if (ls == 1) {
                            lsTxt = "Sedentary(low)";
                        } else if (ls == 2) {
                            lsTxt = "Moderate(normal)";
                        } else if (ls == 3) {
                            lsTxt = "Active(high)";
                        } else if (ls == 4) {
                            lsTxt = "Athletic(Very high)";
                        }
                        else {
                            lsTxt = "Select";
                        }
                        $('#ChkActText_1>span').text(lsTxt);
                    }

                }

                falgsType();
                loadpatient_history();
                weightlist();
            }
            else {
                console.log(data);
            }
        }

    });
}

function patient_select_new() {
    debugger;
    var patient
    if ($('#Hdnpatient_id').val() == '') {
        patient = $('#EditVisitReportID').val();
        var patient_id = patient.split('-');
        patient = patient_id[0];
    }
    else {
        patient = $('#Hdnpatient_id').val()
    }

    var PatientData = {
        Patient_id: patient,
        Dml_Indicator: '1',
        Doctor_id: $('#doctorId').val()
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/CaseStudy/CaseStudy',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientData),
        success: function (data) {
           
            debugger;
            var data = JSON.parse(data);
            console.log(data);
            if (data.msg == "Success") {
                var data = data.data;
                if (jQuery.isEmptyObject((data))) {

                }
                else {
                    if (data.Table.length > 0) {

                        //Added by Antony
                        //$('#Hpatientid').val(data.Table[0].patientid)
                        //$('#Hvisit_reportid').val(data.Table[0].Visit_Reportid) //

                        $('#noofvisit').html(data.Table[0].visit_count);
                        if (data.Table[0].created_on == '' || data.Table[0].created_on == null) {
                            $('#firstvisit').html('');
                        }
                        else {
                            $('#firstvisit').html(data.Table[0].created_on);
                        }

                        $('#moreinfovisit_date').html(data.Table[0].visit_count + ' visits since ' + $('#firstvisit').html());

                        $('#Selbloodgroup').val(data.Table[0].patient_blood_group);
                        if (data.Table[0].type_of_diabetes == '' || data.Table[0].type_of_diabetes == null) {
                            $('#diab').html('Type of Diabetes');
                            $('.diab').html('Type of Diabetes');
                            $('body').removeClass('orange_bg1');
                            $('body').removeClass('orange_bg2');
                            $('body').removeClass('orange_bg3');
                            $('body').removeClass('orange_bg4');
                            $('body').removeClass('orange_bg5');
                            $('body').addClass('orange_bg');
                        }
                        else if (data.Table[0].type_of_diabetes == '0') {
                            $('#diab').html('Diabetes');
                            $('.diab').html('Diabetes');
                            $('#diabVal').val(data.Table[0].type_of_diabetes);
                            $('#diab').html('Type of Diabetes');
                            $('.diab').html('Type of Diabetes');
                            $('body').removeClass('orange_bg1');
                            $('body').removeClass('orange_bg2');
                            $('body').removeClass('orange_bg3');
                            $('body').removeClass('orange_bg4');
                            $('body').removeClass('orange_bg5');
                            $('body').addClass('orange_bg');

                        }
                        else if (data.Table[0].type_of_diabetes == '1') {
                            $('#diab').html('Type1');
                            $('.diab').html('Type1');
                            $('#diabVal').val(data.Table[0].type_of_diabetes);
                            $('body').removeClass('orange_bg');
                            $('body').removeClass('orange_bg1');
                            $('body').removeClass('orange_bg3');
                            $('body').removeClass('orange_bg4');
                            $('body').removeClass('orange_bg5');
                            $('body').addClass('orange_bg2');
                        }
                        else if (data.Table[0].type_of_diabetes == '2') {
                            $('#diab').html('Type2');
                            $('.diab').html('Type2');
                            $('#diabVal').val(data.Table[0].type_of_diabetes);

                            $('body').removeClass('orange_bg');
                            $('body').removeClass('orange_bg1');
                            $('body').removeClass('orange_bg2');
                            $('body').removeClass('orange_bg3');
                            $('body').removeClass('orange_bg4');
                            $('body').addClass('orange_bg5');

                        }
                        else if (data.Table[0].type_of_diabetes == '3') {
                            $('#diab').html('MODY');
                            $('.diab').html('MODY');
                            $('#diabVal').val(data.Table[0].type_of_diabetes);
                            $('body').removeClass('orange_bg');
                            $('body').removeClass('orange_bg1');
                            $('body').removeClass('orange_bg2');
                            $('body').removeClass('orange_bg3');
                            $('body').removeClass('orange_bg5');
                            $('body').addClass('orange_bg4');
                        }
                        else if (data.Table[0].type_of_diabetes == '4') {
                            $('#diab').html('LADA');
                            $('.diab').html('LADA');
                            $('#diabVal').val(data.Table[0].type_of_diabetes);
                            $('body').removeClass('orange_bg');
                            $('body').removeClass('orange_bg1');
                            $('body').removeClass('orange_bg2');
                            $('body').removeClass('orange_bg3');
                            $('body').removeClass('orange_bg5');
                            $('body').addClass('orange_bg4');
                        }
                        else if (data.Table[0].type_of_diabetes == '5') {
                            $('#diab').html('GDM');
                            $('.diab').html('GDM');
                            $('#diabVal').val(data.Table[0].type_of_diabetes);
                            $('body').removeClass('orange_bg');
                            $('body').removeClass('orange_bg1');
                            $('body').removeClass('orange_bg2');
                            $('body').removeClass('orange_bg4');
                            $('body').removeClass('orange_bg5');
                            $('body').addClass('orange_bg3');


                        }
                        else if (data.Table[0].type_of_diabetes == '6') {
                            $('#diab').html('Other');
                            $('.diab').html('Other');
                            $('#diabVal').val(data.Table[0].type_of_diabetes);
                            $('body').removeClass('orange_bg');
                            $('body').removeClass('orange_bg1');
                            $('body').removeClass('orange_bg2');
                            $('body').removeClass('orange_bg3');
                            $('body').removeClass('orange_bg5');
                            $('body').addClass('orange_bg4');
                        }

                        $('#smoking').val(data.Table[0].patient_smoking_habit);
                        var image = (data.Table[0].photo);
                        var PatientPhoto = $('#ChdnPatientPhoto').val();
                        if ($.trim(image) == "" || image == null) {
                            photoSrc = "/Content/img/profile_icon.png";
                        }
                        else {
                            photoSrc = PatientPhoto + image;
                        }

                        $('.imgphoto').attr('src', photoSrc);


                        var first_name = (data.Table[0].first_name)
                        var last_name = (data.Table[0].last_name)
                        if (last_name == '' || last_name == null) {
                            last_name = '';
                        }
                        first_name = first_name + ' ' + last_name;
                        $("#PatientName").attr('title', data.Table[0].patient_id);
                        $('.PatientName').html(first_name);
                        $('.Patientpno').html('<i class="fa fa-phone" aria-hidden="true"></i> ' + data.Table[0].phone_number_1);

                        $('#PatientId').html(data.Table[0].patient_id);
                        $('.PatientId').html('<i class="fa fa-credit-card"></i> ' + data.Table[0].patient_id);
                        debugger;
                        var r_age;
                        if (data.Table[0].DOB == '' || data.Table[0].DOB == null) {
                            if (data.Table[0].age_registered_date == "" || data.Table[0].age_registered_date == null) {
                                if (data.Table[0].gender == '' || data.Table[0].gender == null) {
                                    $('.age').html('-');
                                }
                                else if (data.Table[0].age == "" || data.Table[0].age == null) {
                                    $('.age').html('-');
                                }
                                else {
                                    $('.age').html('-');
                                }
                            }
                            else {
                                var dob = (data.Table[0].age_registered_date);
                                dob = new Date(dob);
                                var today = new Date();
                                r_age = Math.floor((today - dob) / (365.25 * 24 * 60 * 60 * 1000));
                            }

                            //$('#hndage').val(age);
                            $('#gender').val(data.Table[0].gender);

                            var gender;
                            if (data.Table[0].gender == '1') {
                                gender = ' - 1'
                                $('#Male').prop('checked', true);
                            }
                            if (data.Table[0].gender == '2') {
                                gender = ' - 2'
                                $('#Female').prop('checked', true);
                            }
                            if (data.Table[0].gender == '3') {
                                gender = ' - 3'
                                $('#Male').prop('checked', true);

                            }
                            var genders = data.Table[0].gender;

                            $('#Csex').val(genders);
                            $('a[data-toggle=Csex][data-title="' + genders + '"]').removeClass('not-active');
                            $('a[data-toggle=Csex][data-title="' + genders + '"]').addClass('active');

                            if (genders == 1) {
                                genders = 'Male';
                            }
                            else if (genders == 2) {
                                genders = 'Female';
                            }
                            else if (genders == 3) {
                                genders = 'Others';
                            }
                            else {
                                genders = 'Gender';
                            }

                            var age = '', ageC = '';
                            if (data.Table[0].age_registered_date == '' || data.Table[0].age_registered_date == null) {
                                if (data.Table[0].age == '' || data.Table[0].age == null) {
                                    age = 'Age / ';
                                }
                                else {
                                    ageC = data.Table[0].age;
                                    age = data.Table[0].age + ' years ';
                                }
                            }
                            else {
                                ageC = r_age;
                                age = r_age + ' years ';
                            }
                            $('#hndage').val(ageC);
                            $('#AAge').val(ageC);
                            $('.Age').html(age + genders);

                        }
                        else {
                            var gender;

                            $('#Csex').val(data.Table[0].gender);
                            $('a[data-toggle=Csex][data-title="' + data.Table[0].gender + '"]').removeClass('not-active');
                            $('a[data-toggle=Csex][data-title="' + data.Table[0].gender + '"]').addClass('active');
                            if (data.Table[0].gender == '1') {
                                gender = ' - 1'
                                $('#Male').prop('checked', true);
                            }
                            if (data.Table[0].gender == '2') {
                                gender = ' - 2'
                                $('#Female').prop('checked', true);
                            }
                            if (data.Table[0].gender == '3') {
                                gender = ' - 3'
                                $('#Male').prop('checked', true);

                            }

                            var dob = (data.Table[0].DOB);
                            dob = new Date(dob);
                            var today = new Date();
                            var age = Math.floor((today - dob) / (365.25 * 24 * 60 * 60 * 1000));

                            $('#gender').val(gender);
                            $('#hndage').val(age);
                            $('#AAge').val(age);
                            var genders = data.Table[0].gender;
                            if (genders == 1) {
                                genders = 'Male';
                            }
                            else if (genders == 2) {
                                genders = 'Female';
                            }
                            else if (genders == 3) {
                                genders = 'Others';
                            }
                            else {
                                genders = 'Gender';
                            }

                            $('#gender').val(data.Table[0].gender);
                            var sex = data.Table[0].gender;
                            if (sex == 1) {
                                $("#Male").prop('checked', true);
                            }
                            if (sex == 2) {
                                $("#Female").prop('checked', true);
                            }
                            //$('#AAge').val(age);
                            $('.Age').html(age + ' ' + 'years ' + genders);
                        }
                        if (data.Table[0].diabetes_of_year == '' || data.Table[0].diabetes_of_year == null) {
                            $('#diabetes').html('History in years');
                            $('.diabetes').html('History in years');
                        }
                        else {

                            $('#diabetes').html(data.Table[0].diabetes_of_year + ' Years');
                            $('.diabetes').html(data.Table[0].diabetes_of_year + ' Years');
                            $('#txtCHDiabetes').val(data.Table[0].diabetes_of_year);
                            $('#yearDia').html(data.Table[0].diabetes_of_year);
                        }
                        if (data.Table[0].patient_height == '' || data.Table[0].patient_height == null) {
                            $('#hieght').html('-');
                        }
                        else {
                            //var hieghtdb = data.Table[0].patient_height + '.' + data.Table[0].patient_height_metric;
                            //var hieghtout = Math.round(hieghtdb / 0.032808);

                            var hieghtdb = parseInt(data.Table[0].patient_height * 12) + parseInt(data.Table[0].patient_height_metric);
                            var hieghtout = Math.round(hieghtdb * 2.54);

                            $('#hieght').html(hieghtout);
                            $('#hidhieghtFt').val(data.Table[0].patient_height);
                            $('#hidhieghtIn').val(data.Table[0].patient_height_metric);
                        }
                        if (data.Table[0].patient_weight == '' || data.Table[0].patient_weight == null) {
                            $('.wight').html('-');
                        }
                        else {
                            $('.wight').html(data.Table[0].patient_weight);
                            $('#hidwight').val(data.Table[0].patient_weight);
                        }

                        var heightFt = (data.Table[0].patient_height),
                        heightIn = (data.Table[0].patient_height_metric),
                        height = parseFloat(heightFt * 12) + parseFloat(heightIn);
                        var weight = (data.Table[0].patient_weight);
                        weight = (weight * 2.20462)
                        BMI = calculateBMI(height, weight);

                        $('#bmi').text(isNaN(BMI) ? '-' : BMI);

                        var BmiFlags = $('#bmi').text();
                        if (BmiFlags <= 18.5) {
                            $('#BMI').html('Underweight');
                            $('#BMI_head').addClass('dash-notify-above');
                        }
                        else if (BmiFlags > 18.5 && BmiFlags <= 24.9) {
                            $('#BMI').html('Normal');
                            $('#BMI_head').addClass('dash-notify-normal');
                        }
                        else if (BmiFlags > 25.0 && BmiFlags <= 29.9) {
                            $('#BMI').html('Overweight');
                            $('#BMI_head').addClass('dash-notify-above');
                        }
                        else if (BmiFlags >= 30.0) {
                            $('#BMI').html('Obese');
                            $('#BMI_head').addClass('dash-notify-above');
                        }

                        $('#ChkAlcohol').val(data.Table[0].patient_alcohol_consumption);
                        $('a[data-toggle=ChkAlcohol][data-title="' + data.Table[0].patient_alcohol_consumption + '"]').removeClass('not-active');
                        $('a[data-toggle=ChkAlcohol][data-title="' + data.Table[0].patient_alcohol_consumption + '"]').addClass('active');
                        var ls = data.Table[0].patient_alcohol_consumption;
                        var lsTxt;
                        if (ls == 1) {
                            lsTxt = "Non Drinker";
                        } else if (ls == 2) {
                            lsTxt = "Rare";
                        } else if (ls == 3) {
                            lsTxt = "Social";
                        } else if (ls == 4) {
                            lsTxt = "Regular";
                        } else if (ls == 5) {
                            lsTxt = "Heavy";
                        }
                        else {
                            lsTxt = "Select";
                        }
                        $('#AlcText_1>span').text(lsTxt);

                        $('#ChkFood').val(data.Table[0].patient_food_perference);
                        $('a[data-toggle=ChkFood][data-title="' + data.Table[0].patient_food_perference + '"]').removeClass('not-active');
                        $('a[data-toggle=ChkFood][data-title="' + data.Table[0].patient_food_perference + '"]').addClass('active');
                        var ls = data.Table[0].patient_food_perference;
                        var lsTxt;
                        if (ls == 1) {
                            lsTxt = "Vegetarian";
                        } else if (ls == 2) {
                            lsTxt = "Non-Vegetarian";
                        } else if (ls == 3) {
                            lsTxt = "Eggetarian";
                        } else if (ls == 4) {
                            lsTxt = "Vegan";
                        }
                        else {
                            lsTxt = "Select";
                        }
                        $('#ChkFoodText_1>span').text(lsTxt);

                        $('#ChkSmoking').val(data.Table[0].patient_smoking_habit);
                        $('a[data-toggle=ChkSmoking][data-title="' + data.Table[0].patient_smoking_habit + '"]').removeClass('not-active');
                        $('a[data-toggle=ChkSmoking][data-title="' + data.Table[0].patient_smoking_habit + '"]').addClass('active');

                        var ls = data.Table[0].patient_smoking_habit;
                        var lsTxt;
                        if (ls == "8517006") {
                            lsTxt = "Iv'e quit";
                        } else if (ls == "266919005") {
                            lsTxt = "Don't Smoke";
                        } else if (ls == "4.28061E+14") {
                            lsTxt = "1-2/day";
                        } else if (ls == "4.28041E+14") {
                            lsTxt = "3-5/day";
                        } else if (ls == "4.28071E+14") {
                            lsTxt = "5-10/day";
                        } else if (ls == "449868002") {
                            lsTxt = "10/day";
                        }
                        else {
                            lsTxt = "Select";
                        }
                        $('#smkText_1>span').text(lsTxt);

                        $('#ChkActivity').val(data.Table[0].patient_activity_level);
                        $('a[data-toggle=ChkActivity][data-title="' + data.Table[0].patient_activity_level + '"]').removeClass('not-active');
                        $('a[data-toggle=ChkActivity][data-title="' + data.Table[0].patient_activity_level + '"]').addClass('active');
                        var ls = data.Table[0].patient_activity_level;
                        var lsTxt;
                        if (ls == 1) {
                            lsTxt = "Sedentary(low)";
                        } else if (ls == 2) {
                            lsTxt = "Moderate(normal)";
                        } else if (ls == 3) {
                            lsTxt = "Active(high)";
                        } else if (ls == 4) {
                            lsTxt = "Athletic(Very high)";
                        }
                        else {
                            lsTxt = "Select";
                        }
                        $('#ChkActText_1>span').text(lsTxt);

                    }

                    if (data.Table1.length > 0) {

                        if (data.Table1[0].bp_flag_type == '' || data.Table1[0].bp_flag_type == null) {
                            $('#BP').html('-');
                            $('#BP_head_1').addClass('dash-notify-normal');

                        }
                        else if (data.Table1[0].bp_flag_type == '0') {
                            $('#BP').html('Normal');
                            $('#BP_head').addClass('dash-notify-normal');
                        }
                            //low bp
                        else if (data.Table1[0].bp_flag_type == '1') {
                            $('#BP').html('Low BP');
                            $('#BP_head').addClass('dash-notify-above');
                        }
                            //low bp
                        else if (data.Table1[0].bp_flag_type == '2') {
                            $('#BP').html('Low BP');
                            $('#BP_head').addClass('dash-notify-below');
                        }
                        else if (data.Table1[0].bp_flag_type == '3') {
                            $('#BP').html('Normal');
                            $('#BP_head').addClass('dash-notify-normal');
                        }
                        else if (data.Table1[0].bp_flag_type == '4') {
                            $('#BP').html('Prehypertension');
                            $('#BP_head').addClass('dash-notify-above');
                        }
                        else if (data.Table1[0].bp_flag_type == '5') {
                            $('#BP').html('Hypertension Stage 1');
                            $('#BP_head').addClass('dash-notify-above');
                        }
                        else if (data.Table1[0].bp_flag_type == '6') {
                            $('#BP').html('Hypertension Stage 2');
                            $('#BP_head').addClass('dash-notify-above');
                        }
                        else if (data.Table1[0].bp_flag_type == '7') {
                            $('#BP').html('Hypertension Crisis');
                            $('#BP_head').addClass('dash-notify-above');
                        }
                        var DDietBP = $('#BP').html();
                        $('#DBP').html(DDietBP);

                        if (data.Table1[0].dyslipedemia1 == '' || data.Table1[0].dyslipedemia1 == null) {
                            $('#Dyslipidimea').html('-');
                            $('.Dyslipidimea_head > i').addClass('dash-notify-normal');
                        }
                        else if (data.Table1[0].dyslipedemia1 == '0') {
                            $('#Dyslipidimea').html('No');
                            $('#Dyslipidimea_head').addClass('dash-notify-normal');
                        }
                        else if (data.Table1[0].dyslipedemia1 == '1') {
                            $('#Dyslipidimea').html('Yes');
                            $('#Dyslipidimea_head').addClass('dash-notify-below');
                        }

                        if (data.Table1[0].pdr == '' || data.Table1[0].pdr == null) {
                            $('#PDR').html('-');
                            $('#PDR_head').addClass('dash-notify-normal');
                        }
                        else if (data.Table1[0].pdr == '0') {
                            $('#PDR').html('-');
                            $('#PDR_head').addClass('dash-notify-normal');
                        }
                        else if (data.Table1[0].pdr == '1') {
                            $('#PDR').html('None');
                            $('#PDR_head').addClass('dash-notify-normal');
                        }
                        else if (data.Table1[0].pdr == '2') {
                            $('#PDR').html('Mild');
                            $('#PDR_head').addClass('dash-notify-above');
                        }
                        else if (data.Table1[0].pdr == '3') {
                            $('#PDR').html('Moderate');
                            $('#PDR_head').addClass('dash-notify-above');
                        }
                        else if (data.Table1[0].pdr == '4') {
                            $('#PDR').html('Severe');
                            $('#PDR_head').addClass('dash-notify-below');
                        }


                        if (data.Table1[0].npdr == '' || data.Table1[0].npdr == null) {
                            $('#NPDR').html('-');
                            $('#NPDR_head').addClass('dash-notify-normal');
                        }
                        else if (data.Table1[0].npdr == '0') {
                            $('#NPDR').html('-');
                            $('#NPDR_head').addClass('dash-notify-normal');
                        }
                        else if (data.Table1[0].npdr == '1') {
                            $('#NPDR').html('None');
                            $('#NPDR_head').addClass('dash-notify-normal');
                        }
                        else if (data.Table1[0].npdr == '2') {
                            $('#NPDR').html('Mild');
                            $('#NPDR_head').addClass('dash-notify-above');
                        }
                        else if (data.Table1[0].npdr == '3') {
                            $('#NPDR').html('Moderate');
                            $('#NPDR_head').addClass('dash-notify-above');
                        }
                        else if (data.Table1[0].npdr == '4') {
                            $('#NPDR').html('Severe');
                            $('#NPDR_head').addClass('dash-notify-below');
                        }

                        if (data.Table1[0].neuropathy_flag == '' || data.Table1[0].npdr == null || data.Table1[0].npdr == 0) {
                            $('#PNeuropathy').html('-');
                            $('#PNeuropathy_head').addClass('dash-notify-normal');
                        }
                        else if (data.Table1[0].neuropathy_flag == '1') {
                            $('#PNeuropathy').html('Normal');
                            $('#PNeuropathy_head').addClass('dash-notify-normal');
                        }
                        else if (data.Table1[0].neuropathy_flag == '2') {
                            $('#PNeuropathy').html('Mild');
                            $('#PNeuropathy_head').addClass('dash-notify-above');
                        }
                        else if (data.Table1[0].neuropathy_flag == '3') {
                            $('#PNeuropathy').html('Moderate');
                            $('#PNeuropathy_head').addClass('dash-notify-above');
                        }
                        else if (data.Table1[0].neuropathy_flag == '4') {
                            $('#PNeuropathy').html('Severe');
                            $('#PNeuropathy_head').addClass('dash-notify-below');
                        }

                        if (data.Table1[0].autonomic_neuropathy == '' || data.Table1[0].autonomic_neuropathy == null) {
                            $('#ANeuropathy').html('-');
                            $('#ANeuropathy_head').addClass('dash-notify-normal');
                        }
                        else if (data.Table1[0].autonomic_neuropathy == '0') {
                            $('#ANeuropathy').html('Absent');
                            $('#ANeuropathy_head').addClass('dash-notify-normal');
                        }
                        else if (data.Table1[0].autonomic_neuropathy == '1') {
                            $('#ANeuropathy').html('Present');
                            $('#ANeuropathy_head').addClass('dash-notify-below');
                        }




                    }

                    if (data.Table2.length > 0) {
                        if (data.Table2[0].treatment_history_notes == '' || data.Table2[0].treatment_history_notes == null) {
                            $('#THistory').html('');
                        }
                        else {
                            $('#THistory').html(data.Table2[0].treatment_history_notes);
                        }
                        if (data.Table2[0].surgery_history_notes == '' || data.Table2[0].surgery_history_notes == null) {
                            $('#SHistory').html('');
                        }
                        else {
                            $('#SHistory').html(data.Table2[0].surgery_history_notes);
                        }
                    }

                    if (data.Table3.length > 0) {
                        var Angina = data.Table3[0].history_angina;
                        var CHD = data.Table3[0].coronary_heart_disease;
                        var CVA = data.Table3[0].CVA;
                        var PAD = data.Table3[0].history_pad;

                        if (Angina == 1) {
                            $('#Angina').prop('checked', true);
                        }
                        if (CHD == 1) {
                            $('#CoronaryHeart').prop('checked', true);
                        }
                        if (CVA == 1) {
                            $('#CVA').prop('checked', true);
                        }
                        if (PAD == 1) {
                            $('#PAD').prop('checked', true);
                        }
                        if (data.Table3[0].personal_history == '' || data.Table3[0].personal_history == null) {
                            $('#PHistory').html('');
                        }
                        else {
                            $('#PHistory').html(data.Table3[0].personal_history);
                        }
                    }
                    if (data.Table4.length > 0) {
                        $('#lab_id').val(data.Table4[0].lab_id);
                    }

                    if (data.Table5.length > 0) {
                        for (var i = 0; i < data.Table5.length; i++) {
                            var relationship = '';
                            var disease = '';
                            if (data.Table5[i].relationship == 1) {
                                relationship = 'Father';
                            }
                            else if (data.Table5[i].relationship == 2) {
                                relationship = 'Mother';
                            }
                            else if (data.Table5[i].relationship == 3) {
                                relationship = 'Brother';
                            }
                            else if (data.Table5[i].relationship == 4) {
                                relationship = 'Sister';
                            }
                            else if (data.Table5[i].relationship == 5) {
                                relationship = 'Paternal GrandFather';
                            }
                            else if (data.Table5[i].relationship == 6) {
                                relationship = 'Paternal GrandMother';
                            }
                            else if (data.Table5[i].relationship == 7) {
                                relationship = 'Maternal GrandFather';
                            }
                            else if (data.Table5[i].relationship == 8) {
                                relationship = 'Maternal GrandMother';
                            }
                            else {
                                relationship = '';
                            }
                            if (data.Table5[i].disease == 1) {
                                disease = 'CVA';
                            }
                            else if (data.Table5[i].disease == 2) {
                                disease = 'Thyroid';
                            }
                            else if (data.Table5[i].disease == 3) {
                                disease = 'Hypertension';
                            }
                            else if (data.Table5[i].disease == 4) {
                                disease = 'Diabetes';
                            }
                            else {
                                disease = '';
                            }
                            tr = tr + '<tr><td>' + relationship + '</td><td>' + disease + '</td><td>' + data.Table5[i].no_of_years + '</td><td>' + data.Table5[i].name + '</td></tr>';
                        }
                        $('#tbl_family_body').html(tr);
                    }

                    if (data.Table6.length > 0) {
                        var date = '';
                        var trr = ''
                        for (var i = 0; i < data.Table6.length ; i++) {
                            if (data.Table6[i].weight_date != '' && data.Table6[i].weight_date != null && data.Table6[i].patient_weight != null && data.Table6[i].patient_weight != '') {
                                date = data.Table6[i].weight_date;
                                trr = trr + '<a href="#"><div class="pull-left">' + data.Table6[i].patient_weight + 'kg (' + date + ')' + '</div><div class="clearfix"></div></a>';
                            }
                        }
                        $('#weightlist').html(trr);
                    }

                    if (data.Table7.length > 0) {
                        $('.divallergies').empty();
                        $('.divallergiess').empty();
                        var tr = '', li = '';
                        if (data.Table7.length > 0) {

                            for (var i = 0; i < data.Table7.length; i++) {
                                /* tr = tr + '<span class="btn btn-default  btn-sm btn-primary-bordered">' + data[i].allergy_display + '</span>'*/
                                tr = tr + '<span class="btn btn-default  btn-xs btn-primary-bordered floated_close">' + data.Table7[i].allergy_display + '<span class="float_close_icon" onclick=delallergy("' + data.Table7[i].allergy_id + '")><i class="fa fa-times" aria-hidden="true"></i></span></span>';
                                if (i == 0) {
                                    li = li + '<li>' + data.Table7[i].allergy_display + '</li>';
                                }
                                else {
                                    li = li + '<li> | ' + data.Table7[i].allergy_display + '</li>';
                                }

                            }
                            $('.divallergies').append(tr);
                            $('.divallergiess').append(li);
                        }
                    }


                    bp_blood_step_chart();
                    //BPChart();
                    //BloodSugarChart();
                    //StepChart();
                }

                //-----------> want to check<--------------------------


            }
            else {
                console.log(data);
            }
        }

    });

}

function bp_blood_step_chart() {
    var patient
    if ($('#Hdnpatient_id').val() == '') {
        patient = $('#EditVisitReportID').val();
        var patient_id = patient.split('-');
        patient = patient_id[0];
    }
    else {
        patient = $('#Hdnpatient_id').val()
    }

    var PatientData = {
        Patient_id: patient,
        Dml_Indicator: '2',
        Doctor_id: $('#doctorId').val()
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/CaseStudy/CaseStudy',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientData),
        success: function (data) {
            var data = JSON.parse(data);
            if (data.msg == "Success") {
                var data = data.data;
                if (jQuery.isEmptyObject((data))) {

                }
                else {
                    var BPMin = [], BPMax = [], BPlabel = [], FBS = [], PBS = [], FBSlabel = [], stepVal = [], stepDate = [];
                    if (data.Table.length > 0) {
                        for (var i = 0; i < data.Table.length; i++) {
                            BPMin.push(data.Table[i].patient_bp_min);
                            BPlabel.push(data.Table[i].Pdate);
                        }
                    }
                    if (data.Table1.length > 0) {
                        for (var i = 0; i < data.Table1.length; i++) {
                            BPMax.push(data.Table1[i].patient_bp_max);
                        }
                    }
                    if (data.Table2.length > 0) {
                        for (var i = 0; i < data.Table2.length; i++) {
                            FBS.push(data.Table2[i].patient_blood_sugar_value);
                            FBSlabel.push(data.Table2[i].Pdate)
                        }
                    }
                    if (data.Table3.length > 0) {
                        for (var i = 0; i < data.Table3.length; i++) {
                            PBS.push(data.Table3[i].patient_blood_sugar_value);
                        }
                    }
                    if (data.Table4.length > 0) {
                        for (var i = 0; i < data.Table4.length; i++) {
                            stepVal.push(data.Table4[i].patient_step_record_achieved);
                            stepDate.push(data.Table4[i].Pdate)
                        }
                    }
                }
                graph2(BPMin, BPMax, BPlabel, 'chartBP', 'Systolic', 'Diastolic');
                graph2(FBS, PBS, FBSlabel, 'chartsugar', 'Fasting blood sugar', 'Postponed blood sugar');
                graph1(stepVal, stepDate, 'chartstep', 'Date');
                $('.da-load-casestudy').hide();

                MA_QA_HF_chart_overall();

            }
            else {
                console.log(data);
            }
        }
    });
}

$('#chartBP,#chartstep,#chartsugar').click(function (e) {
    bp_blood_step_chart_overall(e.target.id);
});

function MA_QA_HF_chart_overall() {
    //$('.da-load-casestudy').show();
    var patient
    if ($('#Hdnpatient_id').val() == '') {
        patient = $('#EditVisitReportID').val();
        var patient_id = patient.split('-');
        patient = patient_id[0];
    }
    else {
        patient = $('#Hdnpatient_id').val()
    }

    var PatientData = {
        Patient_id: patient,
        Dml_Indicator: '101',
        Doctor_id: $('#doctorId').val()
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/CaseStudy/CaseStudy',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientData),
        success: function (data) {
            var data = JSON.parse(data);
            if (data.msg == "Success") {
                var data = data.data;
                if (jQuery.isEmptyObject((data))) {
                    $('.da-load-casestudy').hide();
                }
                else {
                    var QL = [], HF = [], QLlabel = [], MA = [], MAlabel = [], HFlabel = [];
                    if (data.Table.length > 0) {
                        for (var i = 0; i < data.Table.length; i++) {
                            HF.push(data.Table[i].score);
                            HFlabel.push(data.Table[i].date);
                        }
                    }

                    if (data.Table1.length > 0) {
                        for (var i = 0; i < data.Table1.length; i++) {
                            QL.push(data.Table1[i].score);
                            QLlabel.push(data.Table1[i].date)
                        }
                    }

                    if (data.Table2.length > 0) {
                        for (var i = 0; i < data.Table2.length; i++) {
                            MA.push(data.Table2[i].score);
                            MAlabel.push(data.Table2[i].date)
                        }
                    }
                }
                graph3_ws(HF, HFlabel, 'charthf');
                graph3_ws(QL, QLlabel, 'chartqa');
                graph3_ws(MA, MAlabel, 'chartm');
                $('.da-load-casestudy').hide();
                if ($('#EditVisitReportID').val() != '') {

                }
                else {
                    //$('.da-load-casestudy').hide();
                }
            }
            else {
                console.log(data);
            }
        }
    });
}

//function bp_blood_step_chart_overall(domid) {
//    var patient
//    if ($('#Hdnpatient_id').val() == '') {
//        patient = $('#EditVisitReportID').val();
//        var patient_id = patient.split('-');
//        patient = patient_id[0];
//    }
//    else {
//        patient = $('#Hdnpatient_id').val()
//    }
//    var PatientData = {
//        Patient_id: patient,
//        Dml_Indicator: '100',
//        Doctor_id: $('#doctorId').val()
//    }
//    $.ajax({
//        async: true,
//        type: 'POST',
//        url: '/CaseStudy/CaseStudy',
//        contentType: 'application/json; charset=UTF-8',
//        data: JSON.stringify(PatientData),
//        success: function (data) {
//            if (jQuery.isEmptyObject((data))) {
//            }
//            else {
//                var data = JSON.parse(data);
//                var BPMin = [], BPMax = [], BPlabel = [], FBS = [], PBS = [], FBSlabel = [], stepVal = [], stepDate = [];
//                if (data.Table.length > 0) {
//                    for (var i = 0; i < data.Table.length; i++) {
//                        BPMin.push(data.Table[i].patient_bp_min);
//                        BPlabel.push(data.Table[i].Pdate);
//                    }
//                }
//                if (data.Table1.length > 0) {
//                    for (var i = 0; i < data.Table1.length; i++) {
//                        BPMax.push(data.Table1[i].patient_bp_max);
//                    }
//                }
//                if (data.Table2.length > 0) {
//                    for (var i = 0; i < data.Table2.length; i++) {
//                        FBS.push(data.Table2[i].patient_blood_sugar_value);
//                        FBSlabel.push(data.Table2[i].Pdate)
//                    }
//                }
//                if (data.Table3.length > 0) {
//                    for (var i = 0; i < data.Table3.length; i++) {
//                        PBS.push(data.Table3[i].patient_blood_sugar_value);
//                    }
//                }
//                if (data.Table4.length > 0) {
//                    for (var i = 0; i < data.Table4.length; i++) {
//                        stepVal.push(data.Table4[i].patient_step_record_achieved);
//                        stepDate.push(data.Table4[i].Pdate)
//                    }
//                }
//            }     
//            if (domid === "chartBP") graph2_bpbsall(BPMin, BPMax, BPlabel, 'chartBP1','Systolic', 'Diastolic');
//            if (domid === "chartsugar") graph2_bpbsall(FBS, PBS, FBSlabel, 'chartsugar1','Fasting blood sugar', 'Postponed blood sugar');
//            if (domid === "chartstep") graph1_bpbsall(stepVal, stepDate, 'chartstep1', 'Date');
//            if ($('#EditVisitReportID').val() != '') {
//            }
//            else {
//                //$('.da-load-casestudy').hide();
//            }
//        }
//    });
//}

function bp_blood_step_chart_overall(domid) {
    $('.da-load-casestudy').show();
    var patient
    if ($('#Hdnpatient_id').val() == '') {
        patient = $('#EditVisitReportID').val();
        var patient_id = patient.split('-');
        patient = patient_id[0];
    }
    else {
        patient = $('#Hdnpatient_id').val()
    }
    var PatientData = {
        Patient_id: patient,
        Dml_Indicator: '100',
        Doctor_id: $('#doctorId').val()
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/CaseStudy/CaseStudy',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientData),
        success: function (data) {
            var data = JSON.parse(data);
            if (data.msg == "Success") {
                var data = data.data;
                if (jQuery.isEmptyObject((data))) {
                    $('.da-load-casestudy').hide();
                }
                else {
                    var BPMin = [], BPMax = [], BPlabel = [], FBS = [], PBS = [], FBSlabel = [], stepVal = [], stepDate = [];
                    if (data.Table.length > 0) {
                        for (var i = 0; i < data.Table.length; i++) {
                            BPMin.push(data.Table[i].patient_bp_min);
                            BPlabel.push(data.Table[i].Pdate);
                        }
                    }
                    if (data.Table1.length > 0) {
                        for (var i = 0; i < data.Table1.length; i++) {
                            BPMax.push(data.Table1[i].patient_bp_max);
                        }
                    }
                    if (data.Table2.length > 0) {
                        for (var i = 0; i < data.Table2.length; i++) {
                            FBS.push(data.Table2[i].patient_blood_sugar_value);
                            FBSlabel.push(data.Table2[i].Pdate)
                        }
                    }
                    if (data.Table3.length > 0) {
                        for (var i = 0; i < data.Table3.length; i++) {
                            PBS.push(data.Table3[i].patient_blood_sugar_value);
                        }
                    }
                    if (data.Table4.length > 0) {
                        for (var i = 0; i < data.Table4.length; i++) {
                            stepVal.push(data.Table4[i].patient_step_record_achieved);
                            stepDate.push(data.Table4[i].Pdate)
                        }
                    }
                }
                if (domid === "chartBP") {
                    $('#bptablevalues').empty();
                    graph2_bpbsall(BPMin, BPMax, BPlabel, 'chartBP1', 'Systolic', 'Diastolic');
                    if (data.Table5.length > 0) {
                        var j = 0, bp_data_table;
                        var bp_data_table = data.Table5;
                        tr = $('<table class="table table-condensed body-borderless table_borderless m5" id="bp_table" />');
                        tr.append("<thead><tr><th>S No</th><th>Systolic Value</th><th>Diastolic Value</th><th>Updated Date</th></tr></thead><tbody>");
                        $.each(bp_data_table, function (i, emp) {
                            j++;
                            row_data = "<tr><td>" + j + "</td><td>" + emp.patient_bp_max + "</td><td>" + emp.patient_bp_min + "</td><td>" + emp.updated_date + "</td></tr>";
                            tr.append(row_data);
                        });
                        tr.append("</tbody>");
                        $.when($('#bptablevalues').append(tr)).then($('#bp_table').DataTable({
                            "columnDefs": [{
                                "orderable": false,
                            }]
                        }));
                    }
                    else {
                        tr = $('<table class="table table-condensed body-borderless table_borderless m5" id="bp_table" />');
                        tr.append("<thead><tr><th>S No</th><th>Systolic Value</th><th>Diastolic Value</th><th>Updated Date</th></tr></thead><tbody>");
                        tr.append("</tbody>");
                    }
                }
                if (domid === "chartsugar") {
                    graph2_bpbsall(FBS, PBS, FBSlabel, 'chartsugar1', 'Fasting blood sugar', 'Postponed blood sugar');
                    $('#bsvaluetable').empty();
                    if (data.Table6.length > 0) {
                        var j = 0, bs_data_table, fbs = '-', pps = '-', k = 0;
                        var bs_data_table = data.Table6;
                        var bs_data_table_1 = data.Table7;
                        tr = $('<table class="table table-condensed body-borderless table_borderless m5" id="bs_table" />');
                        tr.append("<thead><tr><th>S No</th><th>Fasting Blood Sugar</th><th>Postprandial Blood Sugar</th><th>Updated Date</th></tr></thead><tbody>");
                        for (var i = 0; i < bs_data_table.length; i++) {
                            if (k < bs_data_table_1.length) {
                                if (bs_data_table[i]["updated_date"] == bs_data_table_1[k]["updated_date"]) {
                                    fbs = bs_data_table[i]["patient_blood_sugar_value"];
                                    pps = bs_data_table_1[k]["patient_blood_sugar_value"];
                                    j++;
                                    row_data = "<tr><td>" + j + "</td><td>" + fbs + "</td><td>" + pps + "</td><td>" + bs_data_table[i]["updated_date"] + "</td></tr>";
                                    tr.append(row_data);
                                    k = k + 1;
                                }
                                else {
                                    fbs = bs_data_table[i]["patient_blood_sugar_value"];
                                    pps = '-'
                                    j++;
                                    row_data = "<tr><td>" + j + "</td><td>" + fbs + "</td><td>" + pps + "</td><td>" + bs_data_table[i]["updated_date"] + "</td></tr>";
                                    tr.append(row_data);
                                    fbs = '-'
                                    pps = bs_data_table_1[k]["patient_blood_sugar_value"];
                                    j++;
                                    row_data = "<tr><td>" + j + "</td><td>" + fbs + "</td><td>" + pps + "</td><td>" + bs_data_table_1[k]["updated_date"] + "</td></tr>";
                                    tr.append(row_data);
                                    k = k + 1;
                                }
                            }
                            else {
                                fbs = bs_data_table[i]["patient_blood_sugar_value"];
                                pps = '-'
                                j++;
                                row_data = "<tr><td>" + j + "</td><td>" + fbs + "</td><td>" + pps + "</td><td>" + bs_data_table[i]["updated_date"] + "</td></tr>";
                                tr.append(row_data);
                                k = k + 1;
                            }
                        }
                        tr.append("</tbody>");
                        $.when($('#bsvaluetable').append(tr)).then($('#bs_table').DataTable({
                            "columnDefs": [{
                                "orderable": false,
                            }]
                        }));
                    }
                    else {
                        tr = $('<table class="table table-condensed body-borderless table_borderless m5" id="bs_table" />');
                        tr.append("<thead><tr><th>S No</th><th>Fasting Blood Sugar</th><th>Postprandial Blood Sugar</th><th>Updated Date</th></tr></thead><tbody>");
                        tr.append("</tbody>");
                    }
                }
                if (domid === "chartstep") {
                    graph1_bpbsall(stepVal, stepDate, 'chartstep1', 'Date');
                    $('#setpvaluetable').empty();
                    if (data.Table8.length > 0) {
                        var j = 0, step_data_table;
                        var step_data_table = data.Table8;
                        tr = $('<table class="table table-condensed body-borderless table_borderless m5" id="step_table" />');
                        tr.append("<thead><tr><th>S No</th><th>Steps Count</th><th>Updated Date</th></tr></thead><tbody>");
                        $.each(step_data_table, function (i, emp) {
                            j++;
                            row_data = "<tr><td>" + j + "</td><td>" + emp.patient_step_record_achieved + "</td><td>" + emp.updated_date + "</td></tr>";
                            tr.append(row_data);
                        });
                        tr.append("</tbody>");
                        $.when($('#setpvaluetable').append(tr)).then($('#step_table').DataTable({
                            "columnDefs": [{
                                "orderable": false,
                            }]
                        }));
                    }
                    else {
                        tr = $('<table class="table table-condensed body-borderless table_borderless m5" id="step_table" />');
                        tr.append("<thead><tr><th>S No</th><th>Systolic Value</th><th>Diastolic Value</th><th>Updated Date</th></tr></thead><tbody>");
                        tr.append("</tbody>");
                    }
                }
                $('.da-load-casestudy').hide();
                if ($('#EditVisitReportID').val() != '') {
                }
                else {
                }
            }
            else {
                console.log(data);
            }
        }
    });
}


function graph1(dataValue, lablevalue, id, labletext) {
    var chartColors = {
        green: 'rgb(75, 192, 192)',
        blue: 'rgb(54, 162, 235)',
        greenfade: 'rgba(75, 192, 192,0.8)',
        bluefade: 'rgba(54, 162, 235,0.4)',
        white: 'rgb(255, 255, 255)',
        whitefade: 'rgba(255, 255, 255,0.7)',
        newgreen: '#94fc13',
        neworange: '#ff502f',
        darkblue: '#36a2eb',
        darkpink: '#ff6b8b',
        lightwhite: '#fff'
    };

    var config = {
        type: 'line',
        data: {
            labels: lablevalue,
            datasets: [{
                label: labletext,
                backgroundColor: chartColors.lightwhite,
                borderColor: chartColors.darkblue,
                data: dataValue,

            }]
        },
        options: {
            responsive: true,
            tooltips: {
                mode: 'label',
            },
            legend: {
                display: false,
            },
            scales: {
                xAxes: [{
                    display: true,
                    scaleLabel: {
                        display: true,
                        labelString: labletext,
                        fontSize: 9
                    },
                    ticks: {
                        fontSize: 9,
                        //    fontColor: "#222"
                    },
                    gridLines: {
                        display: false,
                        //   color: '#aaa'
                    }
                }],
                yAxes: [{
                    display: true,
                    scaleLabel: {
                        display: false,
                        labelString: 'Value',
                        fontSize: 9
                    },
                    ticks: {
                        fontSize: 9,
                        beginAtZero: true,
                        //   fontColor: "#222"
                    },
                    gridLines: {
                        display: false,
                        //    color: '#aaa'
                    }
                }]
            }
        }
    };

    var ctx = document.getElementById(id).getContext("2d");
    window.myLine = new Chart(ctx, config);
}


function graph2(dataValue1, dataValue2, lablevalue, id, label1, label2) {
    var chartColors = {
        green: 'rgb(75, 192, 192)',
        blue: 'rgb(54, 162, 235)',
        greenfade: 'rgba(75, 192, 192,0.8)',
        bluefade: 'rgba(54, 162, 235,0.4)',
        white: 'rgb(255, 255, 255)',
        whitefade: 'rgba(255, 255, 255,0.7)',
        newgreen: '#94fc13',
        neworange: '#ff502f',
        darkblue: '#36a2eb',
        darkpink: '#ff6b8b',
        lightwhite: '#fff'
    };
    var config = {
        type: 'line',
        data: {
            labels: lablevalue,
            datasets: [{
                label: label1,
                backgroundColor: chartColors.lightwhite,
                borderColor: chartColors.darkblue,
                data: dataValue1,

            }, {
                label: label2,
                    backgroundColor: chartColors.lightwhite,
                    borderColor: chartColors.darkpink,
                data: dataValue2,
            }]
        },
        options: {
            responsive: true,
            tooltips: {
                mode: 'label',
            },
            legend: {
                display: false,
            },
            scales: {
                xAxes: [{
                    display: true,
                    scaleLabel: {
                        display: true,
                        labelString: 'Date',
                        fontSize: 9
                    },
                    ticks: {
                        fontSize: 9,
                    },
                    gridLines: {
                        display: false,
                    }
                }],
                yAxes: [{
                    display: true,
                    scaleLabel: {
                        display: false,
                        labelString: 'Value',
                        fontSize: 9
                    },
                    ticks: {
                        fontSize: 9,
                        beginAtZero: true,
                    },
                    gridLines: {
                        display: false,
                    }
                }]
            }
        }
    };

    var ctx = document.getElementById(id).getContext("2d");
    window.myLine = new Chart(ctx, config);
}

function weightlist() {
    var d = new Date();

    var month = d.getMonth() + 1;
    var day = d.getDate();

    var output = d.getFullYear() + '-' +
        (month < 10 ? '0' : '') + month + '-' +
        (day < 10 ? '0' : '') + day;

    var PatientData = {
        patient_id: patient,
        indicator_id: 'W',
        date: output
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/CaseStudy/weightlist',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientData),
        success: function (data) {
            var data = JSON.parse(data);
            if (data.msg == "Success") {
                //var data = data.data;
                if (jQuery.isEmptyObject((data))) {

                }
                else {
                    var tr = '';
                    if (data.weight.length > 0) {
                        for (var i = 0; i < data.weight.length; i++) {
                            //'latest_weight';
                            var date = '';
                            if (data.weight[i].updated_date != '' && data.weight[i].updated_date != null && data.weight[i].weight_value != null && data.weight[i].weight_value != '') {
                                date = data.weight[i].updated_date;
                                //if (date.length > 0) {
                                //    date = date[2] + '/' + date[1] + '/' + date[0];
                                //}
                                tr = tr + '<a href="#"><div class="pull-left">' + data.weight[i].weight_value + 'kg (' + date + ')' + '</div><div class="clearfix"></div></a>';
                            }
                            //tr = tr + '<span>' + data.weight[i].weight_value + '</span>'
                        }
                        $('#weightlist').html(tr);

                    }
                }
            }
            else {
                console.log(data);
            }
        }
    });

}

function bmi(heightft, heightin, Weight) {
    var heightFt = (heightft),
                    heightIn = (heightin),
                    height = parseFloat(heightft * 12) + parseFloat(heightin);
    var weight = (Weight),
    BMI = calculateBMI(height, weight);
    //$('#bmi').text(BMI);
    $('#bmi').text(isNaN(BMI) ? '-' : BMI);
}
function calculateBMI(height, weight) {
    var BMI = (weight / (height * height)) * 703

    return Math.round(BMI * Math.pow(10, 2)) / Math.pow(10, 2);
}
function falgsType() {
    var patient
    if ($('#Hdnpatient_id').val() == '') {
        patient = $('#EditVisitReportID').val();
        var patient_id = patient.split('-');
        patient = patient_id[0];
    }
    else {
        patient = $('#Hdnpatient_id').val()
    }


    var PatientData = {
        Patient_id: patient,
        Doctor_id: $('#doctorId').val(),
        Dml_Indicator: '2'
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/CaseStudy/CaseStudy',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientData),
        success: function (data) {
            var data = JSON.parse(data);
            if (data.msg == "Success") {
                var data = data.data;
                if (jQuery.isEmptyObject((data))) {

                }
                else {
                    if (data.length > 0) {
                        console.log(data);

                        if (data[0].stage_diabetes == '' || data[0].stage_diabetes == null) {
                            $('#StageDiabetes').html('-');

                        }
                        else if (data[0].stage_diabetes == '0') {
                            $('#StageDiabetes').html('Hypo Glycaemic');
                        }
                        else if (data[0].stage_diabetes == '1') {
                            $('#StageDiabetes').html('Normal');
                        }
                        else if (data[0].stage_diabetes == '2') {
                            $('#StageDiabetes').html('Pre-Diatetic');
                        }
                        else if (data[0].stage_diabetes == '3') {
                            $('#StageDiabetes').html('Diabetic');
                        }

                        if (data[0].type_of_diabetes == '' || data[0].type_of_diabetes == null) {
                            $('#TypeDiabetes').html('-');
                        }
                        else if (data[0].type_of_diabetes == '0') {
                            $('#TypeDiabetes').html('Type1');
                        }
                        else if (data[0].type_of_diabetes == '1') {
                            $('#TypeDiabetes').html('Type2');
                        }
                        else if (data[0].type_of_diabetes == '2') {
                            $('#TypeDiabetes').html('MODY');
                        }
                        else if (data[0].type_of_diabetes == '3') {
                            $('#TypeDiabetes').html('LADA');

                        }
                        else if (data[0].type_of_diabetes == '4') {
                            $('#TypeDiabetes').html('GAD Other');
                        }
                        if (data[0].bp_flag_type == '' || data[0].bp_flag_type == null) {
                            $('#BP').html('-');
                            $('#BP_head_1').addClass('dash-notify-normal');

                        }
                        else if (data[0].bp_flag_type == '0') {
                            $('#BP').html('Normal');
                            $('#BP_head').addClass('dash-notify-normal');
                        }
                            //low bp
                        else if (data[0].bp_flag_type == '1') {
                            $('#BP').html('Low BP');
                            $('#BP_head').addClass('dash-notify-above');
                        }
                            //low bp
                        else if (data[0].bp_flag_type == '2') {
                            $('#BP').html('Low BP');
                            $('#BP_head').addClass('dash-notify-below');
                        }
                        else if (data[0].bp_flag_type == '3') {
                            $('#BP').html('Normal');
                            $('#BP_head').addClass('dash-notify-normal');
                        }
                        else if (data[0].bp_flag_type == '4') {
                            $('#BP').html('Prehypertension');
                            $('#BP_head').addClass('dash-notify-above');
                        }
                        else if (data[0].bp_flag_type == '5') {
                            $('#BP').html('Hypertension Stage 1');
                            $('#BP_head').addClass('dash-notify-above');
                        }
                        else if (data[0].bp_flag_type == '6') {
                            $('#BP').html('Hypertension Stage 2');
                            $('#BP_head').addClass('dash-notify-above');
                        }
                        else if (data[0].bp_flag_type == '7') {
                            $('#BP').html('Hypertension Crisis');
                            $('#BP_head').addClass('dash-notify-above');
                        }
                        var DDietBP = $('#BP').html();
                        $('#DBP').html(DDietBP);

                        if (data[0].dyslipedemia1 == '' || data[0].dyslipedemia1 == null) {
                            $('#Dyslipidimea').html('-');
                            //$('.Dyslipidimea_head > i').addClass('hide');
                            $('.Dyslipidimea_head > i').addClass('dash-notify-normal');
                        }
                        else if (data[0].dyslipedemia1 == '0') {
                            $('#Dyslipidimea').html('No');
                            //$('.Dyslipidimea_head > i').addClass('hide');
                            $('#Dyslipidimea_head').addClass('dash-notify-normal');
                        }
                        else if (data[0].dyslipedemia1 == '1') {
                            $('#Dyslipidimea').html('Yes');
                            //$('.Dyslipidimea_head > i').addClass('below_average');
                            $('#Dyslipidimea_head').addClass('dash-notify-below');
                        }


                        if (data[0].pdr == '' || data[0].pdr == null) {
                            $('#PDR').html('-');
                            // $('.PDR_head > i').addClass('hide');
                            $('#PDR_head').addClass('dash-notify-normal');
                        }
                        else if (data[0].pdr == '0') {
                            $('#PDR').html('-');
                            //$('.PDR_head > i').addClass('hide');
                            $('#PDR_head').addClass('dash-notify-normal');
                        }
                        else if (data[0].pdr == '1') {
                            $('#PDR').html('None');
                            //$('.PDR_head > i').addClass('hide');
                            $('#PDR_head').addClass('dash-notify-normal');
                        }
                        else if (data[0].pdr == '2') {
                            $('#PDR').html('Mild');
                            //$('.PDR_head > i').addClass('above_average');
                            $('#PDR_head').addClass('dash-notify-above');
                        }
                        else if (data[0].pdr == '3') {
                            $('#PDR').html('Moderate');
                            //$('.PDR_head > i').addClass('above_average');
                            $('#PDR_head').addClass('dash-notify-above');
                        }
                        else if (data[0].pdr == '4') {
                            $('#PDR').html('Severe');
                            //$('.PDR_head > i').addClass('below_average');
                            $('#PDR_head').addClass('dash-notify-below');
                        }


                        if (data[0].npdr == '' || data[0].npdr == null) {
                            $('#NPDR').html('-');
                            //$('.NPDR_head > i').addClass('hide');
                            $('#NPDR_head').addClass('dash-notify-normal');
                        }
                        else if (data[0].npdr == '0') {
                            $('#NPDR').html('-');
                            //$('.NPDR_head > i').addClass('hide');
                            $('#NPDR_head').addClass('dash-notify-normal');
                        }
                        else if (data[0].npdr == '1') {
                            $('#NPDR').html('None');
                            //$('.NPDR_head > i').addClass('hide');
                            $('#NPDR_head').addClass('dash-notify-normal');
                        }
                        else if (data[0].npdr == '2') {
                            $('#NPDR').html('Mild');
                            //$('.NPDR_head > i').addClass('above_average');
                            $('#NPDR_head').addClass('dash-notify-above');

                        }
                        else if (data[0].npdr == '3') {
                            $('#NPDR').html('Moderate');
                            //$('.NPDR_head > i').addClass('above_average');
                            $('#NPDR_head').addClass('dash-notify-above');
                        }
                        else if (data[0].npdr == '4') {
                            $('#NPDR').html('Severe');
                            //$('.NPDR_head > i').addClass('below_average');
                            $('#NPDR_head').addClass('dash-notify-below');
                        }


                        if (data[0].neuropathy_flag == '' || data[0].npdr == null || data[0].npdr == 0) {
                            $('#PNeuropathy').html('-');
                            //$('.PNeuropathy_head > i').addClass('hide');
                            $('#PNeuropathy_head').addClass('dash-notify-normal');
                        }
                        else if (data[0].neuropathy_flag == '1') {
                            $('#PNeuropathy').html('Normal');
                            //$('.PNeuropathy_head > i').addClass('hide');
                            $('#PNeuropathy_head').addClass('dash-notify-normal');
                        }
                        else if (data[0].neuropathy_flag == '2') {
                            $('#PNeuropathy').html('Mild');
                            //$('.PNeuropathy_head > i').addClass('above_average');
                            $('#PNeuropathy_head').addClass('dash-notify-above');
                        }
                        else if (data[0].neuropathy_flag == '3') {
                            $('#PNeuropathy').html('Moderate');
                            //$('.PNeuropathy_head > i').addClass('above_average');
                            $('#PNeuropathy_head').addClass('dash-notify-above');
                        }
                        else if (data[0].neuropathy_flag == '4') {
                            $('#PNeuropathy').html('Severe');
                            //$('.PNeuropathy_head > i').addClass('below_average');
                            $('#PNeuropathy_head').addClass('dash-notify-below');
                        }

                        if (data[0].autonomic_neuropathy == '' || data[0].autonomic_neuropathy == null) {
                            $('#ANeuropathy').html('-');
                            //$('.ANeuropathy_head > i').addClass('hide');
                            $('#ANeuropathy_head').addClass('dash-notify-normal');
                        }
                        else if (data[0].autonomic_neuropathy == '0') {
                            $('#ANeuropathy').html('Absent');
                            //$('.ANeuropathy_head > i').addClass('hide');
                            $('#ANeuropathy_head').addClass('dash-notify-normal');
                        }
                        else if (data[0].autonomic_neuropathy == '1') {
                            $('#ANeuropathy').html('Present');
                            //$('.ANeuropathy_head > i').addClass('below_average');
                            $('#ANeuropathy_head').addClass('dash-notify-below');
                        }

                    }
                }
                Histroy();
                Cardiac_History();
            }
            else {
                console.log(data);
            }
        }
    });
}


function Histroy() {
    var PatientData = {
        Patient_id: $('#Hdnpatient_id').val(),
        Dml_Indicator: '3'
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/CaseStudy/CaseStudy',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientData),
        success: function (data) {
            var data = JSON.parse(data);
            if (data.msg == "Success") {
                var data = data.data;
                if (jQuery.isEmptyObject((data))) {

                }
                else {

                    if (data.length > 0) {
                        if (data[0].treatment_history_notes == '' || data[0].treatment_history_notes == null) {
                            $('#THistory').html('');
                        }
                        else {
                            $('#THistory').html(data[0].treatment_history_notes);
                        }
                        if (data[0].surgery_history_notes == '' || data[0].surgery_history_notes == null) {
                            $('#SHistory').html('');
                        }
                        else {
                            $('#SHistory').html(data[0].surgery_history_notes);
                        }
                    }
                }
            }
            else {
                console.log(data);
            }
        }
    });
}
function Cardiac_History()
{
    var PatientData = {
        Patient_id: $('#Hdnpatient_id').val(),
        Dml_Indicator: '4'
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/CaseStudy/CaseStudy',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientData),
        success: function (data) {
            var data = JSON.parse(data);
            if (data.msg == "Success") {
                var data = data.data;
                if (jQuery.isEmptyObject((data))) {

                }
                else {
                    if (data.length > 0) {
                        var Angina = data[0].history_angina;
                        var CHD = data[0].coronary_heart_disease;
                        var CVA = data[0].CVA;
                        var PAD = data[0].history_pad;

                        if (Angina == 1) {
                            $('#Angina').prop('checked', true);
                        }
                        if (CHD == 1) {
                            $('#CoronaryHeart').prop('checked', true);
                        }
                        if (CVA == 1) {
                            $('#CVA').prop('checked', true);
                        }
                        if (PAD == 1) {
                            $('#PAD').prop('checked', true);
                        }
                        if (data[0].personal_history == '' || data[0].personal_history == null) {
                            $('#PHistory').html('');
                        }
                        else {
                            $('#PHistory').html(data[0].personal_history);
                        }
                    }
                }
                BPChart();
                BloodSugarChart();
                StepChart();

            }
            else {
                console.log(data);
            }
        }
    });
}

function BloodSugarChart() {
    var BPTrend = {
        patient_id: $('#Hdnpatient_id').val(),
        Dml_Indicator: 'B'
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/PatientDashboard/BloodSugarChart',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(BPTrend),
        success: function (datas) {
            var data1 = JSON.parse(datas);
            if (data1.msg == "Success") {
                var data1 = data1.data;
                if (jQuery.isEmptyObject(data1)) {

                    var chartColors = {
                        red: 'rgb(255, 99, 132)',
                        redfade: 'rgba(255, 99, 132,0.5)',
                        orange: 'rgb(255, 159, 64)',
                        yellow: 'rgb(255, 205, 86)',
                        green: 'rgb(75, 192, 192)',
                        blue: 'rgb(54, 162, 235)',
                        greenfade: 'rgba(75, 192, 192,0.4)',
                        bluefade: 'rgba(54, 162, 235,0.4)',
                        purple: 'rgb(153, 102, 255)',
                        grey: 'rgb(231,233,237)',
                        greyfade: 'rgba(231,233,237,0.7)',
                        violet: 'rgb(76, 68, 255)',
                        white: 'rgb(255, 255, 255)',
                        whitefade: 'rgba(255, 255, 255,0.7)',
                        darkblue: '#36a2eb',
                        darkpink: '#ff6b8b',
                        lightwhite: '#fff'
                    };


                    var chartColors = {
                        red: 'rgb(255, 99, 132)',
                        orange: 'rgb(255, 159, 64)',
                        yellow: 'rgb(255, 205, 86)',
                        green: 'rgb(75, 192, 192)',
                        blue: 'rgb(54, 162, 235)',
                        greenfade: 'rgba(75, 192, 192,0.4)',
                        bluefade: 'rgba(54, 162, 235,0.4)',
                        purple: 'rgb(153, 102, 255)',
                        grey: 'rgb(231,233,237)',
                        violet: 'rgb(76, 68, 255)',
                        darkblue: '#36a2eb',
                        darkpink: '#ff6b8b',
                        lightwhite: '#fff'
                    };

                    var ctx = document.getElementById('chartsugar').getContext('2d');
                    // ctx.fill = 'rgb(124, 89, 254)';
                    var chart = new Chart(ctx, {
                        type: 'line',
                        data: {
                            datasets: [{
                                label: 'Fasting blood sugar',
                                data: ["0", "0", "0", "0", "0", "0", "0"],
                                borderWidth: 1,

                                backgroundColor: chartColors.lightwhite,
                                borderColor: chartColors.darkblue,

                                backgroundColor: chartColors.lightwhite,
                                borderColor: chartColors.darkpink,

                            }, {
                                label: 'Postprandial blood sugar',
                                data: ["0", "0", "0", "0", "0", "0", "0"],
                                borderWidth: 1,

                                backgroundColor: chartColors.lightwhite,
                                borderColor: chartColors.darkblue,

                                backgroundColor: chartColors.lightwhite,
                                borderColor: chartColors.darkpink,

                            }],
                            labels: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
                        },
                        options: {
                            legend: {
                                display: false,
                            },
                            scales: {

                                xAxes: [{
                                    ticks: {
                                        //  fontColor: "#fff"
                                    },
                                    gridLines: {
                                        display: false,
                                        //   color: '#fff'
                                    }
                                }],

                                xAxes: [{
                                    ticks: {
                                        // fontColor: "#222"
                                    },
                                    gridLines: {
                                        display: false,
                                        //  color: '#aaa'
                                    }
                                }],

                                yAxes: [{
                                    ticks: {

                                        reverse: false,
                                        //   fontColor: "#fff"
                                    },
                                    gridLines: {
                                        display: false,
                                        //  color: '#fff',

                                        reverse: false,
                                        //   fontColor: "#222"
                                    },
                                    gridLines: {
                                        display: false,
                                        //  color: '#aaa'

                                    }
                                }]
                            }
                        }
                    });

                }



                    //datavalue
                else {
                    var sugarMin = [], sugarMax = [], label = [];
                    var BPTrend = {
                        doctor_id: $('#HiddenDoctorID').val(),
                        patient_id: $('#Hdnpatient_id').val(),
                        Dml_Indicator: 'A'
                    }


                    for (var i = 0; i < data1.length; i++) {
                        sugarMin.push(data1[i].patient_blood_sugar_value);
                        label.push(data1[i].Pdate);
                    }

                    $.ajax({
                        async: true,
                        type: 'POST',
                        url: '/PatientDashboard/BloodSugarChart',
                        contentType: 'application/json; charset=UTF-8',
                        data: JSON.stringify(BPTrend),
                        success: function (datass) {
                            var data22 = JSON.parse(datass);
                            if (data22.msg == "Success") {
                                var data22 = data22.data;
                                console.log(data22);
                                if (jQuery.isEmptyObject(data22)) {

                                }
                                else {
                                    console.log(data22);
                                    for (var i = 0; i < data22.length; i++) {
                                        sugarMax.push(data22[i].patient_blood_sugar_value);
                                    }
                                }
                                var chartColors = {
                                    red: 'rgb(255, 99, 132)',
                                    redfade: 'rgba(255, 99, 132,0.5)',
                                    orange: 'rgb(255, 159, 64)',
                                    yellow: 'rgb(255, 205, 86)',
                                    green: 'rgb(75, 192, 192)',
                                    blue: 'rgb(54, 162, 235)',
                                    greenfade: 'rgba(75, 192, 192,0.4)',
                                    bluefade: 'rgba(54, 162, 235,0.4)',
                                    purple: 'rgb(153, 102, 255)',
                                    grey: 'rgb(231,233,237)',
                                    greyfade: 'rgba(231,233,237,0.7)',
                                    violet: 'rgb(76, 68, 255)',
                                    white: 'rgb(255, 255, 255)',
                                    whitefade: 'rgba(255, 255, 255,0.7)',
                                    darkblue: '#36a2eb',
                                    darkpink: '#ff6b8b',
                                    lightwhite: '#fff'
                                };


                                var chartColors = {
                                    red: 'rgb(255, 99, 132)',
                                    orange: 'rgb(255, 159, 64)',
                                    yellow: 'rgb(255, 205, 86)',
                                    green: 'rgb(75, 192, 192)',
                                    blue: 'rgb(54, 162, 235)',
                                    greenfade: 'rgba(75, 192, 192,0.4)',
                                    bluefade: 'rgba(54, 162, 235,0.4)',
                                    purple: 'rgb(153, 102, 255)',
                                    grey: 'rgb(231,233,237)',
                                    violet: 'rgb(76, 68, 255)',
                                    darkblue: '#36a2eb',
                                    darkpink: '#ff6b8b',
                                    lightwhite: '#fff'
                                };

                                sugarMin = sugarMin.reverse();
                                sugarMax = sugarMax.reverse();
                                label = label.reverse();
                                var ctx = document.getElementById('chartsugar').getContext('2d');
                                // ctx.fill = 'rgb(124, 89, 254)';
                                var chart = new Chart(ctx, {
                                    type: 'line',
                                    data: {
                                        datasets: [{
                                            label: 'Fasting blood sugar',
                                            data: sugarMin,
                                            borderWidth: 1,

                                            backgroundColor: chartColors.lightwhite,
                                            borderColor: chartColors.darkblue,

                                            backgroundColor: chartColors.lightwhite,
                                            borderColor: chartColors.darkpink,

                                        }, {
                                            label: 'Postprandial blood sugar',
                                            data: sugarMax,
                                            borderWidth: 1,

                                            backgroundColor: chartColors.lightwhite,
                                            borderColor: chartColors.darkblue,

                                            backgroundColor: chartColors.lightwhite,
                                            borderColor: chartColors.darkpink,

                                        }],
                                        labels: label
                                    },
                                    options: {
                                        legend: {
                                            display: false,
                                        },
                                        scales: {

                                            xAxes: [{
                                                ticks: {
                                                    //  fontColor: "#fff"
                                                },
                                                gridLines: {
                                                    display: false,
                                                    //   color: '#fff'
                                                }
                                            }],

                                            xAxes: [{
                                                ticks: {
                                                    // fontColor: "#222"
                                                },
                                                gridLines: {
                                                    display: false,
                                                    //  color: '#aaa'
                                                }
                                            }],

                                            yAxes: [{
                                                ticks: {

                                                    reverse: false,
                                                    //   fontColor: "#fff"
                                                },
                                                gridLines: {
                                                    display: false,
                                                    //  color: '#fff',

                                                    reverse: false,
                                                    //   fontColor: "#222"
                                                },
                                                gridLines: {
                                                    display: false,
                                                    //  color: '#aaa'

                                                }
                                            }]
                                        }
                                    }
                                });
                            }
                            else {
                                console.log(data22)
                            }
                        }
                    });

                }
            }
            else {
                console.log(data1);
            }
        }

    });
}

function BPChart() {
    var BPTrend = {
        patient_id: $('#Hdnpatient_id').val(),
        Dml_Indicator: 'B'
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/PatientDashboard/BPChart',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(BPTrend),
        success: function (datas) {
            var data1 = JSON.parse(datas);
            if (data1.msg == "Success") {
                var data1 = data1.data;
                if (jQuery.isEmptyObject(data1)) {
                    var chartColors = {
                        red: 'rgb(255, 99, 132)',
                        redfade: 'rgba(255, 99, 132,0.5)',
                        orange: 'rgb(255, 159, 64)',
                        yellow: 'rgb(255, 205, 86)',
                        green: 'rgb(75, 192, 192)',
                        blue: 'rgb(54, 162, 235)',
                        greenfade: 'rgba(75, 192, 192,0.8)',
                        bluefade: 'rgba(54, 162, 235,0.4)',
                        purple: 'rgb(153, 102, 255)',
                        grey: 'rgb(231,233,237)',
                        greyfade: 'rgba(231,233,237,0.7)',
                        violet: 'rgb(76, 68, 255)',
                        white: 'rgb(255, 255, 255)',
                        whitefade: 'rgba(255, 255, 255,0.7)',
                        darkblue: '#36a2eb',
                        darkpink: '#ff6b8b',
                        lightwhite: '#fff'
                    };

                    var chartColors = {
                        red: 'rgb(255, 99, 132)',
                        orange: 'rgb(255, 159, 64)',
                        yellow: 'rgb(255, 205, 86)',
                        green: 'rgb(75, 192, 192)',
                        blue: 'rgb(54, 162, 235)',
                        greenfade: 'rgba(75, 192, 192,0.4)',
                        bluefade: 'rgba(54, 162, 235,0.4)',
                        purple: 'rgb(153, 102, 255)',
                        grey: 'rgb(231,233,237)',
                        violet: 'rgb(76, 68, 255)',
                        darkblue: '#36a2eb',
                        darkpink: '#ff6b8b',
                        lightwhite: '#fff'
                    };

                    var ctx = document.getElementById('chartBP').getContext('2d');
                    var chart = new Chart(ctx, {
                        type: 'line',
                        data: {
                            datasets: [{
                                label: 'BP Min',
                                data: ["0", "0", "0", "0", "0", "0", "0"],
                                borderWidth: 1,

                                backgroundColor: chartColors.lightwhite,
                                borderColor: chartColors.darkblue,

                                backgroundColor: chartColors.lightwhite,
                                borderColor: chartColors.darkpink,

                            }, {
                                label: 'BP Max',
                                data: ["0", "0", "0", "0", "0", "0", "0"],
                                borderWidth: 1,

                                backgroundColor: chartColors.lightwhite,
                                borderColor: chartColors.darkblue,

                                backgroundColor: chartColors.lightwhite,
                                borderColor: chartColors.darkpink,

                            }],
                            labels: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
                        },
                        options: {
                            legend: {
                                display: false,
                            },
                            scales: {

                                xAxes: [{
                                    ticks: {
                                        fontColor: "#fff"
                                    },
                                    gridLines: {
                                        display: false,
                                        color: '#fff'
                                    }
                                }],

                                xAxes: [{
                                    ticks: {
                                        //  fontColor: "#222"
                                    },
                                    gridLines: {
                                        display: false,
                                        //   color: '#aaa'
                                    }
                                }],

                                yAxes: [{
                                    ticks: {

                                        reverse: false,
                                        //   fontColor: "#fff",
                                    },
                                    gridLines: {
                                        display: false,
                                        //  color: '#fff',

                                        reverse: false,
                                        //  fontColor: "#222"
                                    },
                                    gridLines: {
                                        display: false,
                                        // color: '#aaa'

                                    }
                                }]
                            }
                        }
                    });

                }
                else {
                    var BPMin = [], BPMax = [], label = [];
                    var BPTrend = {
                        patient_id: $('#Hdnpatient_id').val(),
                        Dml_Indicator: 'A'
                    }


                    for (var i = 0; i < data1.length; i++) {
                        BPMin.push(data1[i].patient_bp_min);
                        label.push(data1[i].Pdate);
                    }

                    $.ajax({
                        async: true,
                        type: 'POST',
                        url: '/PatientDashboard/BPChart',
                        contentType: 'application/json; charset=UTF-8',
                        data: JSON.stringify(BPTrend),
                        success: function (datass) {
                            var data22 = JSON.parse(datass);
                            if (data22.msg == "Success") {
                                var data22 = data22.data;
                                if (jQuery.isEmptyObject(datas)) {

                                }
                                else {
                                    for (var i = 0; i < data22.length; i++) {
                                        BPMax.push(data22[i].patient_bp_max);
                                    }
                                    var chartColors = {
                                        red: 'rgb(255, 99, 132)',
                                        redfade: 'rgba(255, 99, 132,0.5)',
                                        orange: 'rgb(255, 159, 64)',
                                        yellow: 'rgb(255, 205, 86)',
                                        green: 'rgb(75, 192, 192)',
                                        blue: 'rgb(54, 162, 235)',
                                        greenfade: 'rgba(75, 192, 192,0.8)',
                                        bluefade: 'rgba(54, 162, 235,0.4)',
                                        purple: 'rgb(153, 102, 255)',
                                        grey: 'rgb(231,233,237)',
                                        greyfade: 'rgba(231,233,237,0.7)',
                                        violet: 'rgb(76, 68, 255)',
                                        white: 'rgb(255, 255, 255)',
                                        whitefade: 'rgba(255, 255, 255,0.7)',
                                        darkblue: '#36a2eb',
                                        darkpink: '#ff6b8b',
                                        lightwhite: '#fff'
                                    };

                                    var chartColors = {
                                        red: 'rgb(255, 99, 132)',
                                        orange: 'rgb(255, 159, 64)',
                                        yellow: 'rgb(255, 205, 86)',
                                        green: 'rgb(75, 192, 192)',
                                        blue: 'rgb(54, 162, 235)',
                                        greenfade: 'rgba(75, 192, 192,0.4)',
                                        bluefade: 'rgba(54, 162, 235,0.4)',
                                        purple: 'rgb(153, 102, 255)',
                                        grey: 'rgb(231,233,237)',
                                        violet: 'rgb(76, 68, 255)',
                                        darkblue: '#36a2eb',
                                        darkpink: '#ff6b8b',
                                        lightwhite: '#fff'
                                    };

                                    BPMin = BPMin.reverse();
                                    BPMax = BPMax.reverse();
                                    label = label.reverse();
                                    var ctx = document.getElementById('chartBP').getContext('2d');
                                    var chart = new Chart(ctx, {
                                        type: 'line',
                                        data: {
                                            datasets: [{
                                                label: 'BP Min',
                                                data: BPMin,
                                                borderWidth: 1,

                                                backgroundColor: chartColors.lightwhite,
                                                borderColor: chartColors.darkblue,

                                                backgroundColor: chartColors.lightwhite,
                                                borderColor: chartColors.darkpink,

                                            }, {
                                                label: 'BP Max',
                                                data: BPMax,
                                                borderWidth: 1,

                                                backgroundColor: chartColors.lightwhite,
                                                borderColor: chartColors.darkblue,

                                                backgroundColor: chartColors.lightwhite,
                                                borderColor: chartColors.darkpink,

                                            }],
                                            labels: label
                                        },
                                        options: {
                                            legend: {
                                                display: false,
                                            },
                                            scales: {

                                                xAxes: [{
                                                    ticks: {
                                                        fontColor: "#fff"
                                                    },
                                                    gridLines: {
                                                        display: false,
                                                        color: '#fff'
                                                    }
                                                }],

                                                xAxes: [{
                                                    ticks: {
                                                        //  fontColor: "#222"
                                                    },
                                                    gridLines: {
                                                        display: false,
                                                        //   color: '#aaa'
                                                    }
                                                }],

                                                yAxes: [{
                                                    ticks: {

                                                        reverse: false,
                                                        //   fontColor: "#fff",
                                                    },
                                                    gridLines: {
                                                        display: false,
                                                        //  color: '#fff',

                                                        reverse: false,
                                                        //  fontColor: "#222"
                                                    },
                                                    gridLines: {
                                                        display: false,
                                                        // color: '#aaa'

                                                    }
                                                }]
                                            }
                                        }
                                    });
                                }
                            }
                            else {
                                console.log(data22)
                            }
                        }
                    });

                }
            }
            else {
                console.log(data1)
            }
        }

    });
}

function StepChart() {
    var BPTrend = {
        patient_id: $('#Hdnpatient_id').val(),
        Dml_Indicator: ''
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/PatientDashboard/StepChart',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(BPTrend),
        success: function (datas) {
            var data1 = JSON.parse(datas);
            if (data1.msg == "Success") {
                var data1 = data1.data;
                if (jQuery.isEmptyObject(data1)) {
                    var chartColors = {
                        red: 'rgb(255, 99, 132)',
                        orange: 'rgb(255, 159, 64)',
                        yellow: 'rgb(255, 205, 86)',
                        green: 'rgb(75, 192, 192)',
                        blue: 'rgb(54, 162, 235)',
                        greenfade: 'rgba(75, 192, 192,0.4)',
                        bluefade: 'rgba(54, 162, 235,0.4)',
                        purple: 'rgb(153, 102, 255)',
                        grey: 'rgb(231,233,237)',
                        greyfade: 'rgba(231,233,237,0.7)',
                        violet: 'rgb(76, 68, 255)',
                        white: 'rgb(255, 255, 255)',
                        whitefade: 'rgba(255, 255, 255,0.7)',
                        darkblue: '#36a2eb',
                        darkpink: '#ff6b8b',
                        lightwhite: '#fff'
                    };

                    var chartColors = {
                        red: 'rgb(255, 99, 132)',
                        orange: 'rgb(255, 159, 64)',
                        yellow: 'rgb(255, 205, 86)',
                        green: 'rgb(75, 192, 192)',
                        blue: 'rgb(54, 162, 235)',
                        greenfade: 'rgba(75, 192, 192,0.4)',
                        bluefade: 'rgba(54, 162, 235,0.4)',
                        purple: 'rgb(153, 102, 255)',
                        grey: 'rgb(231,233,237)',
                        violet: 'rgb(76, 68, 255)',
                        darkblue: '#36a2eb',
                        darkpink: '#ff6b8b',
                        lightwhite: '#fff'
                    };

                    var ctx = document.getElementById('chartstep').getContext('2d');
                    var chart = new Chart(ctx, {
                        type: 'line',
                        data: {
                            datasets: [{
                                label: 'Step Count',
                                data: ["0", "0", "0", "0", "0", "0", "0"],
                                borderWidth: 1,

                                backgroundColor: chartColors.lightwhite,
                                borderColor: chartColors.darkblue,

                                backgroundColor: chartColors.lightwhite,
                                borderColor: chartColors.darkpink,

                            }],
                            labels: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
                        },
                        options: {
                            legend: {
                                display: false,
                            },
                            scales: {

                                xAxes: [{
                                    ticks: {
                                        //    fontColor: "#fff"
                                    },
                                    gridLines: {
                                        display: false,
                                        //   color: '#fff'
                                    }
                                }],

                                xAxes: [{
                                    ticks: {
                                        //  fontColor: "#222"
                                    },
                                    gridLines: {
                                        display: false,
                                        //  color: '#aaa'
                                    }
                                }],

                                yAxes: [{
                                    ticks: {

                                        reverse: false,
                                        //    fontColor: "#fff",
                                    },
                                    gridLines: {
                                        display: false,
                                        //  color: '#fff',

                                        reverse: false,
                                        //  fontColor: "#222"
                                    },
                                    gridLines: {
                                        display: false,
                                        //   color: '#aaa'

                                    }
                                }]
                            }
                        }
                    });
                }
                else {
                    var StepCount = [], label = [];

                    for (var i = 0; i < data1.length; i++) {
                        StepCount.push(data1[i].patient_step_record_achieved);
                        label.push(data1[i].Pdate);
                    }

                    var chartColors = {
                        red: 'rgb(255, 99, 132)',
                        orange: 'rgb(255, 159, 64)',
                        yellow: 'rgb(255, 205, 86)',
                        green: 'rgb(75, 192, 192)',
                        blue: 'rgb(54, 162, 235)',
                        greenfade: 'rgba(75, 192, 192,0.4)',
                        bluefade: 'rgba(54, 162, 235,0.4)',
                        purple: 'rgb(153, 102, 255)',
                        grey: 'rgb(231,233,237)',
                        greyfade: 'rgba(231,233,237,0.7)',
                        violet: 'rgb(76, 68, 255)',
                        white: 'rgb(255, 255, 255)',
                        whitefade: 'rgba(255, 255, 255,0.7)',
                        darkblue: '#36a2eb',
                        darkpink: '#ff6b8b',
                        lightwhite: '#fff'
                    };

                    var chartColors = {
                        red: 'rgb(255, 99, 132)',
                        orange: 'rgb(255, 159, 64)',
                        yellow: 'rgb(255, 205, 86)',
                        green: 'rgb(75, 192, 192)',
                        blue: 'rgb(54, 162, 235)',
                        greenfade: 'rgba(75, 192, 192,0.4)',
                        bluefade: 'rgba(54, 162, 235,0.4)',
                        purple: 'rgb(153, 102, 255)',
                        grey: 'rgb(231,233,237)',
                        violet: 'rgb(76, 68, 255)',
                        darkblue: '#36a2eb',
                        darkpink: '#ff6b8b',
                        lightwhite: '#fff'
                    };
                    StepCount = StepCount.reverse();
                    label = label.reverse();
                    var ctx = document.getElementById('chartstep').getContext('2d');
                    var chart = new Chart(ctx, {
                        type: 'line',
                        data: {
                            datasets: [{
                                label: 'Step Count',
                                data: StepCount,
                                borderWidth: 1,

                                backgroundColor: chartColors.lightwhite,
                                borderColor: chartColors.darkblue,

                                backgroundColor: chartColors.lightwhite,
                                borderColor: chartColors.darkpink,

                            }],
                            labels: label
                        },
                        options: {
                            legend: {
                                display: false,
                            },
                            scales: {

                                xAxes: [{
                                    ticks: {
                                        //    fontColor: "#fff"
                                    },
                                    gridLines: {
                                        display: false,
                                        //   color: '#fff'
                                    }
                                }],

                                xAxes: [{
                                    ticks: {
                                        //  fontColor: "#222"
                                    },
                                    gridLines: {
                                        display: false,
                                        //  color: '#aaa'
                                    }
                                }],

                                yAxes: [{
                                    ticks: {

                                        reverse: false,
                                        //    fontColor: "#fff",
                                    },
                                    gridLines: {
                                        display: false,
                                        //  color: '#fff',

                                        reverse: false,
                                        //  fontColor: "#222"
                                    },
                                    gridLines: {
                                        display: false,
                                        //   color: '#aaa'

                                    }
                                }]
                            }
                        }
                    });

                }
                Allergies();
            }
            else {
                console.log(data1);
            }
        }

    });
}



function Allergies() {
    var PatientData = {
        Patient_id: $('#Hdnpatient_id').val(),
        Dml_Indicator: 'DS'
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/CaseStudy/Allergy_Ins_Sel',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientData),
        success: function (data) {
            var data = JSON.parse(data);
            if (data.msg == "Success") {
                var data = data.data;
                if (jQuery.isEmptyObject((data))) {

                }
                else {
                    $('#allergies').empty();
                    var tr = '';
                    if (data.length > 0) {

                        for (var i = 0; i < data.length; i++) {
                            tr = tr + '<span class="btn btn-default  btn-sm btn-primary-bordered">' + data[i].allergy_display + '</span>'
                        }
                        $('#allergies').append(tr);
                    }
                }
            }
            else {
                console.log(data);
            }
        }
    });
}


function TreamentSurgery()
{
    var PatientData = {
        Patient_id: $('#Hdnpatient_id').val(),
        treatment_history_notes: $('#THistory').html(),
        surgery_history_notes: $('#SHistory').html(),
        Dml_Indicator: '5'
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/CaseStudy/CaseStudy',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientData),
        success: function (data) {
            if (jQuery.isEmptyObject((data))) {

            }
            else {
            }
        }
    });
}



$("#btnPsubmit").click(function () {
    history_angina=0,CoronaryHeart=0,CVA=0;
    if ($('#Angina').prop("checked") == true)
    {
        history_angina=1;
    }
    if ($('#CoronaryHeart').prop("checked")==true) {
        CoronaryHeart=1;
    }
    if ($('#CVA').prop("checked")==true) {
        CVA=1;
    }
    if ($('#PAD').prop("checked")==true) {
        PAD=1;
    }
    var PatientData = {
        Patient_id: $('#Hdnpatient_id').val(),
        history_angina:history_angina,
        coronary_heart_disease:CoronaryHeart,
        CVA :CVA,
        history_pad:PAD,
        Dml_Indicator: '6'
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/CaseStudy/CaseStudy',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientData),
        success: function (data) {
            if (jQuery.isEmptyObject((data))) {

            }
            else {
            }
        }
    });
});


function CheckAppointmnet() {
    var PatientData = {
        Patient_id: $('#Hdnpatient_id').val(),
        Dml_Indicator: 'CH',
        doctor_id: $('#doctorId').val()
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/CaseStudy/CheckAppointment',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientData),
        success: function (data) {
            var data = JSON.parse(data);
            if (data.msg == "Success") {
                var data = data.data;
                if (jQuery.isEmptyObject((data))) {
                    $('#CheckAppointment').html('Book Appointment');
                }
                else {

                    if (data.length > 0) {
                        if (data[0].visit_report_id == '' || data[0].visit_report_id == null) {
                            $('#CheckAppointment').html('Create CaseSheet');
                        }
                        else {
                            $('#CheckAppointment').html('Book Appointment');
                        }
                        $('#Hdnappointment_date').val(data[0].slot_start_time);
                        $('#appointment_type').val(data[0].appointment_type);
                    }
                    else {
                        $('#CheckAppointment').html('Book Appointment');
                    }


                }
            }
            else {
                console.log(data);
            }
        }
    });
    EditCaseStudy();

}

function EditCaseStudy() {
    var PatientData = {
        Patient_id: $('#Hdnpatient_id').val(),
        Dml_Indicator: 'ECH',
        doctor_id: $('#doctorId').val()
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/CaseStudy/CheckAppointment',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(PatientData),
        success: function (data) {
            var data = JSON.parse(data);
            if (data.msg == "Success") {
                var data = data.data;
                debugger;
                if (jQuery.isEmptyObject((data))) {
                    $('#EditCaseSheet').hide();
                }
                else {

                    if (data.length > 0) {
                        $('#EditCaseSheet').show();
                        $('#VisitReportID').val(data[0].visit_report_id);
                        $('#appointment_type').val(data[0].appointment_type);
                    }
                    else {
                        $('#EditCaseSheet').hide();
                    }


                }
            }
            else {
                console.log(data);
            }
        }
    });

}

$('#CheckAppointment').click(function () {
    if ($('#CheckAppointment').html() == 'Create CaseSheet') {

        var RightData = {
            doctor_user_module_id: "CAS_AF",
            Stringtype: "role_rights_function",
            Dml_Indicator: "RB"
        }
        $.ajax({
            async: true,
            type: 'POST',
            url: '/UserRight/User_rights_privileges',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(RightData),
            success: function (data) {
                debugger;
                var data1 = JSON.parse(data);
                if (data1.msg == "Success") {
                    var data1 = data1.data;
                    if (jQuery.isEmptyObject((data1))) {

                    }
                    else {

                        status = data1.Table[0].role_rights_add
                        if (status == 0) {
                            toastr.warning("you have No rights to this page");
                            return;
                        }
                        else {
                            window.location.href = '/Casestudy/Indexformbuilder?patient_id=' + $('#Hdnpatient_id').val() + '&slotdate=' + $('#Hdnappointment_date').val() + '&Did=' + $('#doctorId').val() + '&appointment_type=' + $('#appointment_type').val() + '&PharmacyID=' + $('#txtPharmacyID').val();
                        }
                    }
                    
                }
                else {
                    console.log(data);
                }
            }
        });       
    }
    else {
        window.location.href = '/DirectPatientEnroll/AppointmentSlot?patient_id=' + $('#Hdnpatient_id').val() + '&PName=' + $('#PatientName').html();
    }

});

$('#EditCaseSheet').click(function () {

    var RightData = {
        doctor_user_module_id: "CAS_AF",
        Stringtype: "role_rights_function",
        Dml_Indicator: "RB"
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/UserRight/User_rights_privileges',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(RightData),
        success: function (data) {
            debugger;
            var data1 = JSON.parse(data);
            if (data1.msg == "Success") {
                var data1 = data1.data;
                if (jQuery.isEmptyObject((data1))) {

                }
                else {

                    status = data1.Table[0].role_rights_add
                    if (status == 0) {
                        toastr.warning("you have No rights to this page");
                        return;
                    }
                    else {
                    
                        window.location.href = '/Casestudy/Indexformbuilder?VisitReport=' + $('#VisitReportID').val() + '&patient_id=' + $('#Hdnpatient_id').val() + '&Did=' + $('#doctorId').val() + '&appointment_type=' + $('#appointment_type').val() + '&PharmacyID=' + $('#txtPharmacyID').val();
                    }
                }
            }
            else {
                console.log(data);
            }
        }
    });
    
});



//first screen Completed point

//MoreInfomations

var more = 0;
 $('#view_more_1').click(function () {
    more++;
    if (more==1) {
        load_patient_summary_visit_report();
    }
});


    function printPrescription(val) {
        window.open('/PatientDashboard/PPDF?visitreportid=' + val + '&lantype=' + $('#sellang').val(), "_blank");
    }



    function loadwatch_parameter() {
        var PrescriptionVisitId = {
            Dml_Indicator: 'P',
            patient_id: patient,
            doctor_id: $('#doctor_Id').val()
        }
        $.ajax({
            async: true,
            type: 'POST',
            url: '/CaseStudy/Watchlist',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(PrescriptionVisitId),
            success: function (data) {
                var data = JSON.parse(data);
                if (data.msg == "Success") {
                    var data = data.data;
                    if (jQuery.isEmptyObject((data))) {

                    }
                    else {

                        var op = '';
                        var sel = '<option value="0">--select--</option>';
                        for (var i = 0; i < data.length; i++) {
                            op = op + '<option value=' + data[i].watch_parameter_id + '>' + data[i].description + '</option>';
                        }
                        $('#SelParameter').append(sel + op);
                    }
                }
                else {
                    console.log(data);
                }
            }
        });
        loadfrequency_parameter();
    }

    function loadfrequency_parameter() {
        var PrescriptionVisitId = {
            Dml_Indicator: 'F',
            patient_id: patient,
            doctor_id: $('#doctor_Id').val()
        }
        $.ajax({
            async: true,
            type: 'POST',
            url: '/CaseStudy/Watchlist',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(PrescriptionVisitId),
            success: function (data) {
                var data = JSON.parse(data);
                if (data.msg == "Success") {
                    var data = data.data;
                    if (jQuery.isEmptyObject((data))) {

                    }
                    else {
                        var op = '';
                        var sel = '<option value="0">--select--</option>';
                        for (var i = 0; i < data.length; i++) {
                            op = op + '<option value=' + data[i].watch_frequency_id + '>' + data[i].description + '</option>';
                        }
                        $('#SelFrequency').append(sel + op);
                    }
                }
                else {
                    console.log(data);
                }
            }
        });
        loadwatch_list();
    }


    function loadwatch_list() {
        var loadwatchlist = {
            Dml_Indicator: 'S',
            patient_id: patient,
            doctor_id: $('#doctorId').val()
        }
        $.ajax({
            async: true,
            type: 'POST',
            url: '/CaseStudy/Watchlist',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(loadwatchlist),
            success: function (data) {
                var data = JSON.parse(data);
                if (data.msg == "Success") {
                    var data = data.data;
                    if (jQuery.isEmptyObject((data))) {

                    }
                    else {

                        for (var i = 0; i < data.length; i++) {
                            var SelPriority = data[0].priority;

                            $('#Chknepropathy').val(SelPriority);
                            $('a[data-toggle=SelPriority][data-title="' + SelPriority + '"]').addClass('active');

                            $('#endDate').val(data[0].end_date);
                            $('#watch_id').val(data[0].watch_id);
                            var rowcount = $.trim($('#WatchTableRowCount').val());
                            var tot_row = (Number(rowcount) + 1);
                            var ikey = '';
                            var sess_data = data[i].ParameterDescription + "," + data[i].watch_parameter_id + "," + data[i].FrequencyDescription + "," + data[i].watch_frequency_id + "," + data[i].target_1 + "," + data[i].target_2;
                            ikey = 'row' + tot_row;
                            sessionStorage.setItem(ikey, sess_data);

                            var value = "<tr id='t_" + ikey + "'><td>" + data[i].ParameterDescription + "</td><td>" + data[i].FrequencyDescription + "</td><td>" + data[i].target_1 + "</td><td>" + data[i].target_2 + "</td><td><button class='edit btn btn-default  btn-sm btn-add' onclick='watchlistedit(\"" + ikey + "\")'><i class='fa fa-pencil' aria-hidden='true'></i></button><button class='edit btn btn-default  btn-sm btn-add' onclick='watchlistdelete(\"" + ikey + "\")'><i class='fa fa-trash' aria-hidden='true'></i></button></td></tr>";

                            $('#WatchTable > tbody:last').append(value);
                            $('#WatchTableRowCount').val(tot_row);
                            if (tot_row > 0) {

                                $('#mWatchlist').prop('checked', true);
                                $('#mWatchSection').show();
                            }
                        }
                    }
                }
                else {
                    console.log(data);
                }
            }
        });
        loadViplist();
    }
    function loadViplist() {
        var loadViplist = {
            Dml_Indicator: 'S',
            patient_id: patient,
            doctor_id: $('#doctorId').val()
        }
        $.ajax({
            async: true,
            type: 'POST',
            url: '/CaseStudy/Viplist',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(loadViplist),
            success: function (data) {
                var data = JSON.parse(data);
                if (data.msg == "Success") {
                    var data = data.data;
                    if (jQuery.isEmptyObject((data))) {

                    }
                    else {

                        var status = '';
                        for (var i = 0; i < data.length; i++) {
                            status = data[i].status;
                            if (status == 1) {
                                $('#modalVIP').prop('checked', true);
                                $('#mVIPSection').show();
                                $('#txtVipDetails').val(data[i].description);
                            }
                        }
                    }
                }
                else {
                    console.log(data);
                }
            }
        });
    }

    $('#SelParameter').change(function () {
        if ($('#SelParameter').val() == 1) {
            $('#lbltarget1').html('SYS');
            $('#lbltarget2').html('DIA');
            $('#lbltarget1').show();
            $('#lbltarget2').show();
            $('#txttarget2').show();
            $('#txttarget1').show();
        }
        else if ($('#SelParameter').val() == 2) {
            $('#lbltarget1').html('FBS');
            $('#lbltarget1').show();
            $('#txttarget1').show();
            $('#lbltarget2').hide();
            $('#txttarget2').hide();
        }
        else if ($('#SelParameter').val() == 3) {
            $('#lbltarget1').html('PBS');
            $('#lbltarget1').show();
            $('#txttarget1').show();
            $('#lbltarget2').hide();
            $('#txttarget2').hide();
        }
        else {
            $('#lbltarget1').html('Target 1');
            $('#lbltarget2').html('Target 2');
            $('#lbltarget1').show();
            $('#lbltarget2').show();
            $('#txttarget2').show();
            $('#txttarget1').show();
        }
    });

    $('#addwatchlist').click(function () {
        if ($.trim($('#SelParameter :selected').val()) == "" || $('#SelParameter :selected').val() == "0") {
            $('#PSelParameter').show();
            $('#PSelParameter').fadeOut(8000);
            $('#PSelParameter').html('Select Parameter');
            $('#SelParameter').focus();
            $('#SelParameter :selected').val('0');
            return false;
        }
        if ($.trim($('#SelFrequency :selected').val()) == "" || $('#SelFrequency :selected').val() == "0") {
            $('#PSelFrequency').show();
            $('#PSelFrequency').fadeOut(8000);
            $('#PSelFrequency').html('Select Frequency');
            $('#SelFrequency').focus();
            $('#SelFrequency :selected').val('0');
            return false;
        }
        if ($.trim($('#txttarget1').val()) == "") {
            $('#Ptxttarget1').show();
            $('#Ptxttarget1').fadeOut(8000);
            $('#Ptxttarget1').html('Enter the value');
            $('#txttarget1').focus();
            $('#txttarget1').val('');
            return false;
        }
        if ($('#SelParameter').val() == 1) {
            if ($.trim($('#txttarget2').val()) == "") {
                $('#Ptxttarget2').show();
                $('#Ptxttarget2').fadeOut(8000);
                $('#Ptxttarget2').html('Enter the value');
                $('#txttarget2').focus();
                $('#txttarget2').val('');
                return false;
            }
        }

        var sess_key;
        var rowcount = $.trim($('#WatchTableRowCount').val());
        var tot_row = (Number(rowcount) + 1);
        var ikey = '';
        var sess_data = $('#SelParameter :selected').text() + "," + $('#SelParameter').val() + "," + $('#SelFrequency :selected').text() + "," + $('#SelFrequency').val() + "," + $('#txttarget1').val() + "," + $('#txttarget2').val();

        if (rowcount >= 1) {
            var getEid = $('#WatchTable  tr').last();
            var actId = getEid.prop('id');
            var afterSplit = actId.split('row');
            afterInc = parseInt(afterSplit[1]) + 1;
            console.log(afterInc);
            ikey = 'row' + afterInc;
        }
        else {

            ikey = 'row' + tot_row;
        }
        sessionStorage.setItem(ikey, sess_data);

        var value = "<tr id='t_" + ikey + "'><td>" + $('#SelParameter :selected').text() + "</td><td>" + $('#SelFrequency :selected').text() + "</td><td>" + $('#txttarget1').val() + "</td><td>" + $('#txttarget2').val() + "</td><td><button class='edit btn btn-default  btn-sm btn-add' onclick='watchlistedit(\"" + ikey + "\")'><i class='fa fa-pencil' aria-hidden='true'></i></button><button class='edit btn btn-default  btn-sm btn-add' onclick='watchlistdelete(\"" + ikey + "\")'><i class='fa fa-trash' aria-hidden='true'></i></button></td></tr>";

        $('#WatchTable > tbody:last').append(value);
        $('#WatchTableRowCount').val(tot_row);
        $('#SelParameter').val(0);
        $('#SelFrequency').val(0);
        $('#txttarget1').val('');
        $('#txttarget2').val('');

    });

    function watchlistedit(val) {

        $('#addwatchlist').hide();
        $('#updatewatchlist').show();
        $('#hnd_watchlist').val(val);

        var gkey = val;
        var row_data = sessionStorage.getItem(gkey);
        var row_data_split = row_data.split(',');
        $('#SelParameter').val(row_data_split[1]);
        $('#SelFrequency').val(row_data_split[3]);
        $('#txttarget1').val(row_data_split[4]);
        $('#txttarget2').val(row_data_split[5]);


        if (row_data_split[1] == 1) {
            $('#lbltarget1').html('SYS');
            $('#lbltarget2').html('DIA');
            $('#lbltarget1').show();
            $('#lbltarget2').show();
            $('#txttarget2').show();
            $('#txttarget1').show();
        }
        else if (row_data_split[1] == 2) {
            $('#lbltarget1').html('FBS');
            $('#lbltarget1').show();
            $('#txttarget1').show();
            $('#lbltarget2').hide();
            $('#txttarget2').hide();
        }
        else if (row_data_split[1] == 3) {
            $('#lbltarget1').html('PBS');
            $('#lbltarget1').show();
            $('#txttarget1').show();
            $('#lbltarget2').hide();
            $('#txttarget2').hide();
        }
        else {
            $('#lbltarget1').html('Target 1');
            $('#lbltarget2').html('Target 2');
            $('#lbltarget1').show();
            $('#lbltarget2').show();
            $('#txttarget2').show();
            $('#txttarget1').show();
        }

    }
    function watchlistdelete(val) {
        sessionStorage.removeItem(val);
        $('#t_' + val).remove();
        var a = $.trim($('#WatchTableRowCount').val());
        var a = (a) - (1);
        $('#WatchTableRowCount').val(a);
    }

    $('#updatewatchlist').click(function () {

        var table_id = $('#hnd_watchlist').val();


        if ($.trim($('#SelParameter :selected').val()) == "" || $('#SelParameter :selected').val() == "0") {
            $('#PSelParameter').show();
            $('#PSelParameter').fadeOut(8000);
            $('#PSelParameter').html('Select Parameter');
            $('#SelParameter').focus();
            $('#SelParameter :selected').val('0');
            return false;
        }
        if ($.trim($('#SelFrequency :selected').val()) == "" || $('#SelFrequency :selected').val() == "0") {
            $('#PSelFrequency').show();
            $('#PSelFrequency').fadeOut(8000);
            $('#PSelFrequency').html('Select Frequency');
            $('#SelFrequency').focus();
            $('#SelFrequency :selected').val('0');
            return false;
        }
        if ($.trim($('#txttarget1').val()) == "") {
            $('#Ptxttarget1').show();
            $('#Ptxttarget1').fadeOut(8000);
            $('#Ptxttarget1').html('Select Types');
            $('#txttarget1').focus();
            $('#txttarget1').val('');
            return false;
        }

        if ($('#SelParameter').val() == 1) {
            if ($.trim($('#txttarget2').val()) == "") {
                $('#Ptxttarget2').show();
                $('#Ptxttarget2').fadeOut(8000);
                $('#Ptxttarget2').html('Enter the value');
                $('#txttarget2').focus();
                $('#txttarget2').val('');
                return false;
            }
        }
        $('#addwatchlist').show();
        $('#updatewatchlist').hide();





        var sess_data = $('#SelParameter :selected').text() + "," + $('#SelParameter').val() + "," + $('#SelFrequency :selected').text() + "," + $('#SelFrequency').val() + "," + $('#txttarget1').val() + "," + $('#txttarget2').val();
        var ikey = table_id;
        sessionStorage.setItem(ikey, sess_data);

        $('#WatchTable > tbody:last').empty();


        var tot_row = $.trim($('#WatchTableRowCount').val());
        var i, j;


        for (i = 1; i <= tot_row; i++) {
            var gkey = 'row' + i;
            console.log(sessionStorage.getItem(gkey));
            var row_data = sessionStorage.getItem(gkey);

            if (row_data == null) {
                console.log(gkey + '--------->' + row_data);
            }
            if (row_data != null) {
                row_data = row_data.split(',');



                // var value = "<tr id='t_" + ikey + "'><td>" + $('#SelParameter :selected').text() + "</td><td>" + $('#SelFrequency :selected').text() + "</td><td>" + $('#txttarget1').val() + "</td><td>" + $('#txttarget2').val() + "</td><td><button class='edit btn btn-default  btn-sm btn-add' onclick='watchlistedit(\"" + ikey + "\")'><i class='fa fa-pencil' aria-hidden='true'></i></button><button class='edit btn btn-default  btn-sm btn-add' onclick='watchlistdelete(\"" + ikey + "\")'><i class='fa fa-trash' aria-hidden='true'></i></button></td></tr>";
                var value = "<tr id='t_" + gkey + "'><td>" + row_data[0] + "</td><td>" + row_data[2] + "</td><td>" + row_data[4] + "</td><td>" + row_data[5] + "</td><td><button class='edit btn btn-default  btn-sm btn-add' onclick='watchlistedit(\"" + gkey + "\")'><i class='fa fa-pencil' aria-hidden='true'></i></button><button class='edit btn btn-default  btn-sm btn-add' onclick='watchlistdelete(\"" + gkey + "\")'><i class='fa fa-trash' aria-hidden='true'></i></button></td></tr>";

                $('#WatchTable > tbody:last').append(value);
            }
        }

        $('#SelParameter').val(0);
        $('#SelFrequency').val(0);
        $('#txttarget1').val('');
        $('#txttarget2').val('');


    });


    $('#btnwatchlist').click(function () {
        if ($('#SelPriority').val() == "") {
            $('#PSelPriority').show();
            $('#PSelPriority').fadeOut(8000);
            $('#PSelPriority').html('Select Priority');
            $('#SelPriority').focus();
            $('#SelPriority').val('');
            return false;
        }
        if ($.trim($('#endDate').val()) == "") {
            $('#PendDate').show();
            $('#PendDate').fadeOut(8000);
            $('#PendDate').html('End Date');
            $('#endDate').focus();
            $('#endDate').val('');
            return false;
        }
        var Notesdata = {
            watch_id: $('#watch_id').val(),
            Dml_Indicator: 'D'
        }
        $('#myPatientCsviewModal').modal('toggle');
        $.ajax({
            async: true,
            type: 'POST',
            url: '/caseStudy/Watchlist',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(Notesdata),
            success: function (data) {
                Addwatchlist();
                if (jQuery.isEmptyObject((data))) {
                }
                else {
                }
            }
        });

    });


    function Addwatchlist() {
    
        var enddate = $('#endDate').val();
        enddate = enddate.split('/');
        var End_Date = enddate[2] + "-" + enddate[1] + "-" + enddate[0];
        var Notesdata = {
            patient_id: $('#Hdnpatient_id').val(),
            created_by: $('#doctorId').val(),
            removed_on: '',
            removed_by: $('#doctorId').val(),
            doctor_id: $('#doctorId').val(),
            priority: $('#SelPriority').val(),
            end_date: End_Date,
            Dml_Indicator: 'I'
        }

        $.ajax({
            async: true,
            type: 'POST',
            url: '/caseStudy/Watchlist',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(Notesdata),
            success: function (data) {
                var data1 = JSON.parse(data);
                if (data1.msg == "Success") {
                    var data1 = data1.data;
                    if (jQuery.isEmptyObject((data))) {
                    }
                    else {
                        var watch_id = '';
                        if (data.length > 2) {


                            $.each(data1, function (i, emp) {

                                watch_id = emp.watch_id;

                            });
                            var tot_rowM = $.trim($('#WatchTableRowCount').val());
                            $("#BtnLabSubmit").html('Update changes');
                            if (tot_rowM > 0) {
                                var L = 0;
                                for (j = 1; j <= tot_rowM; j++) {
                                    var a = $('#WatchTable_body').children('tr').eq(L);
                                    //var a = $('#WatchTable').closest('table').attr('id');
                                    //var b = a;
                                    var b = a.prop('id');
                                    L++;
                                    var C = b.split('_');
                                    var gkey = C[1];

                                    var row_data = sessionStorage.getItem(gkey);
                                    var K = 0;
                                    if (row_data == "") {
                                        console.log(gkey + '--------->' + row_data);
                                    }
                                    if (row_data != "" && row_data != null) {
                                        console.log(gkey + '-------' + row_data);
                                        row_data = row_data.split(',');

                                        var sms = {
                                            Dml_Indicator: 'DI',
                                            watch_parameter_id: row_data[1],
                                            watch_id: watch_id,
                                            watch_frequency_id: row_data[3],
                                            target_1: row_data[4],
                                            target_2: row_data[5],
                                        }
                                        $.ajax({
                                            async: true,
                                            type: 'POST',
                                            url: '/CaseStudy/Watchlist',
                                            contentType: 'application/json; charset=UTF-8',
                                            data: JSON.stringify(sms),
                                            success: function (data) {
                                            }
                                        });
                                    }
                                }
                            }
                        }
                    }

                    AddVip();

                }
                else {
                    console.log(data1);
                }
            }
        });
    }

    function AddVip() {
        var description = $.trim($('#txtVipDetails').val());
        var status = "1";
        if (description == '') {
            status = "0";
        }
        var vipdata = {
            patient_id: $('#Hdnpatient_id').val(),
            doctor_id: $('#doctorId').val(),
            description: description,
            status: status,
            created_by: $('#doctorId').val(),
            Dml_Indicator: 'I'
        }
        $.ajax({
            async: true,
            type: 'POST',
            url: '/caseStudy/Viplist',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(vipdata),
            success: function (data) {
                var data = JSON.parse(data);
                if (data.msg == "Success") {
                    var data = data.data;
                    if (jQuery.isEmptyObject((data))) {
                    }
                    else {

                    }

                    popclear();
                }
                else {
                    console.log(data);
                }
            }
        });
    }


function popclear() {
    $('a[data-toggle="SelPriority"]').not('[data-title="' + 1 + '"]').removeClass('active').addClass('not-active');
    $('a[data-toggle="SelPriority"]').not('[data-title="' + 2 + '"]').removeClass('active').addClass('not-active');
    $('a[data-toggle="SelPriority"]').not('[data-title="' + 3 + '"]').removeClass('active').addClass('not-active');
    $('#WatchTable tbody').empty();
    $('#endDate').val('');
    $('#SelParameter').empty();
    $('#SelFrequency').empty();
    $('#txttarget1').val('');
    $('#txttarget2').val('');

    $('#txtVipDetails').val('');
}

$('#btnclose').click(function () {
    popclear();
});

$('#btncloseX').click(function () {
    popclear();
});


  $('#btnContact').click(function () {

        window.location.href = '/DirectPatientEnroll?patient_id=' + $('#Hdnpatient_id').val() ;
    });


  function loadpatient_history() {
      var familydetails = {
          Dml_Indicator: 'S',
          patient_id: $('#Hdnpatient_id').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/caseStudy/patient_family_history',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(familydetails),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  if (jQuery.isEmptyObject((data))) {
                  }
                  else {
                      var tr = '';
                      if (data.length > 0) {
                          for (var i = 0; i < data.length; i++) {
                              var relationship = '';
                              var disease = '';
                              if (data[i].relationship == 1) {
                                  relationship = 'Father';
                              }
                              else if (data[i].relationship == 2) {
                                  relationship = 'Mother';
                              }
                              else if (data[i].relationship == 3) {
                                  relationship = 'Brother';
                              }
                              else if (data[i].relationship == 4) {
                                  relationship = 'Sister';
                              }
                              else if (data[i].relationship == 5) {
                                  relationship = 'Paternal GrandFather';
                              }
                              else if (data[i].relationship == 6) {
                                  relationship = 'Paternal GrandMother';
                              }
                              else if (data[i].relationship == 7) {
                                  relationship = 'Maternal GrandFather';
                              }
                              else if (data[i].relationship == 8) {
                                  relationship = 'Maternal GrandMother';
                              }
                              else if (data[i].relationship == 9) {
                                  relationship = 'Both Parents';
                              }
                              else if (data[i].relationship == 10) {
                                  relationship = 'All Family number';
                              }
                              else {
                                  relationship = '';
                              }

                              if (data[i].disease == 1) {
                                  disease = 'CVA';
                              }
                              else if (data[i].disease == 2) {
                                  disease = 'Thyroid';
                              }
                              else if (data[i].disease == 3) {
                                  disease = 'Hypertension';
                              }
                              else if (data[i].disease == 4) {
                                  disease = 'Diabetes';
                              }
                              else if (data[i].disease == 5) {
                                  disease = 'Cardiac Diseases';
                              }
                              else if (data[i].disease == 6) {
                                  disease = 'Cancer';
                              }
                              else if (data[i].disease == 7) {
                                  disease = 'Renal Diseases';
                              }
                              else {
                                  disease = '';
                              }
                              tr = tr + '<tr><td>' + relationship + '</td><td>' + disease + '</td><td>' + data[i].no_of_years + '</td><td>' + data[i].name + '</td></tr>';
                          }
                          $('#tbl_family_body').html(tr);
                      }
                  }
              }
              else {
                  console.log(data);
              }
          }
      });
  }




  //summary patient details visit_report start

  function patient_summary_visit_report(visitReportId) {
      debugger;
      var userid = '';
      var MedicinePrescriptiondate = {
          visit_report_id: visitReportId,
          patient_id: $('#Hdnpatient_id').val(),
          Userid: $('#doctorId').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/caseStudy/Patient_Summary_details',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(MedicinePrescriptiondate),
          success: function (data) {
              
              debugger;
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  $('.tbl_patient_summary_details').html('');
                  if (jQuery.isEmptyObject((data))) {

                  }
                  else {
                      if (Object.keys(data).length > 2) {
                          console.log(data);
                          var div = "", divtr = '';
                          var j = 1;

                          //loadvisit_selection
                          if (data.Table20.length > 0) {
                              //for (var i = 0; i < data.Table20.length; i++) {
                              //    var expanded_status = 'false', expanded_in = '';
                              //    if (i < 1) {
                              //        expanded_status = 'True';
                              //        expanded_in = 'in';
                              //    }
                              //    divtr = divtr + '<div class="panel panel-primary" onclick=patient_summary_visit_report("' + data.Table20[i].visit_report_id + '")><div class="panel-heading clearfix" role="button" data-toggle="collapse" data-parent="#accordion" href="#PatientVisitSummary-section' + data.Table20[i].visit_report_id + '" aria-expanded="' + expanded_status + '" aria-controls="PatientVisitSummary-section' + data.Table20[i].visit_report_id + '"><i class="icon-calendar"></i>'
                              //    divtr = divtr + '<h3 class="panel-title"><span class="pull-left">' + data.Table20[i].visit_date + '</span><span class="pull-right"><a href="javascript:void(0);" onclick=printpdf("' + data.Table20[i].visit_report_id + '")><i class="fa fa-print "></i>print prescription</a>&nbsp;&nbsp;&nbsp;&nbsp;<i class="fa fa-angle-double-down"></i></span></h3></div><div id="PatientVisitSummary-section' + data.Table20[i].visit_report_id + '" class="panel-collapse collapse ' + expanded_in + '" role="tabpanel" aria-labelledby="headingOne">'
                              //    divtr = divtr + '<div class="panel-body"><div id="summary_div_' + data.Table20[i].visit_report_id + '"><div style="padding:0px;" class="col-md-12" id="summarydiv_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock">Summary</div><div class="col-md-12" id="tbl_patient_summary_details_' + data.Table20[i].visit_report_id + '"></div></div>'
                              //    divtr = divtr + '<div id="Prescription_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock">Prescription</div><div class="presc_table_block"><div id="tbl-medicine_' + data.Table20[i].visit_report_id + '"></div></div></div>'
                              //    divtr = divtr + '<div id="lab_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock">lab Tests</div><div class=""><div id="Lab-table_' + data.Table20[i].visit_report_id + '" ></div></div></div>'
                              //    divtr = divtr + '<div id="file_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock">Files</div><div class="col-xs-12 presc_table_block" id="tbl-fileupload_' + data.Table20[i].visit_report_id + '"></div></div>'
                              //    divtr = divtr + '<div id="next_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock">Next Appointment</div><div class="col-md-6 padding0 "><div class="col-md-6 disp_table_cell"><div class="form-group label_center"><label class="control-label">Next Appointment Date</label></div></div><div class="col-md-6 disp_table_cell"><div class="form-group label_center"><label class="control-label next_appoinment_date_label_1" id="lblNextApp_' + data.Table20[i].visit_report_id + '"></label></div></div></div></div></div></div></div></div>';
                              //}
                              //$('.loadvisit_selection').html(divtr);

                          }

                          div = div + '<div class="col-md-12"><h5><b>Doctor Name :  ' + data.Table24[0].doctor_name + '</b></h5></div>';

                          // vitals section
                          if (data.Table.length > 0 && ((data.Table[0].pulse_rate != null && data.Table[0].pulse_rate != '') || (data.Table[0].spo2 != null && data.Table[0].spo2 != '') || (data.Table[0].temperature != null && data.Table[0].temperature != ''))) {
                              div = div + '<div class="col-md-12"><h5><b>Vitals</b></h5></div>';
                          }
                          else if (data.Table17.length > 0 && ((data.Table17[0].weight != null && data.Table17[0].weight != '') || (data.Table17[0].patient_height != null && data.Table17[0].patient_height != ''))) {
                              div = div + '<div class="col-md-12"><h5><b>Vitals</b></h5></div>';
                          }
                          else if (data.Table1.length > 0 && (data.Table1[0].patient_bp_max != null && data.Table1[0].patient_bp_max != '')) {
                              div = div + '<div class="col-md-12"><h5><b>Vitals</b></h5></div>';
                          }

                          if (data.Table17.length > 0) {
                              if (data.Table17[0].weight != null && data.Table17[0].weight != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Weight</label> : <span>' + data.Table17[0].weight + ' Kg </span></div>';
                              }
                              if (data.Table17[0].patient_height != null && data.Table17[0].patient_height != '') {
                                  var hieghtdb = parseInt(data.Table17[0].patient_height * 12) + parseInt(data.Table17[0].patient_height_metric);
                                  var hieghtout = Math.round(hieghtdb * 2.54);
                                  $('#hieght').html(hieghtout);
                                  var hieght = hieghtout;

                                  div = div + '<div class="col-md-4"><label class="control-label">Height</label> : <span>' + hieght + ' cm </span></div>';
                              }
                          }

                          if (data.Table1.length > 0) {
                              if (data.Table1[0].patient_bp_max != null && data.Table1[0].patient_bp_max != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Sys/Dia</label> : <span>' + data.Table1[0].patient_bp_max + '</span>/<span>' + data.Table1[0].patient_bp_min + '</span></div>';
                              }
                          }

                          if (data.Table.length > 0) {
                              if (data.Table[0].pulse_rate != null && data.Table[0].pulse_rate != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Pulse Rate</label> : <span>' + data.Table[0].pulse_rate + '</span></div>';
                              }
                              if (data.Table[0].spo2 != null && data.Table[0].spo2 != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">SpO2</label> : <span>' + data.Table[0].spo2 + '</span></div>';
                              }
                              if (data.Table[0].temperature != null && data.Table[0].temperature != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Temperature</label> : <span>' + data.Table[0].temperature + '</span></div>';
                              }
                          }

                          if (data.Table.length > 0 && data.Table[0].observation_primary != null) {
                              div = div + '<div class="col-md-12"><h5><b>OBSERVATION</b></h5></div>';
                          }
                          else if (data.Table17.length > 0 && data.Table17.length > 0) {
                              div = div + '<div class="col-md-12"><h5><b>OBSERVATION</b></h5></div>';
                          }
                          else if (data.Table1.length > 0 && data.Table1[0].patient_bp_record_id != null) {
                              div = div + '<div class="col-md-12"><h5><b>OBSERVATION</b></h5></div>';
                          }
                          else {

                          }

                          if (data.Table24.length > 0) {
                              if (data.Table24[0].diagnosis != null && data.Table24[0].diagnosis != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Diagnosis</label> : <span>' + data.Table24[0].diagnosis + ' </span></div>';
                              }
                              if (data.Table24[0].notes != null && data.Table24[0].notes != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Notes</label> : <span>' + data.Table24[0].notes + ' </span></div>';
                              }
                              if (data.Table24[0].investigation != null && data.Table24[0].investigation != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Investigation</label> : <span>' + data.Table24[0].investigation + ' </span></div>';
                              }
                              if (data.Table24[0].observation != null && data.Table24[0].observation != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Observation</label> : <span>' + data.Table24[0].observation + ' </span></div>';
                              }
                              if (data.Table24[0].treatment_procedure != null && data.Table24[0].treatment_procedure != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Treatment Procedure</label> : <span>' + data.Table24[0].treatment_procedure + ' </span></div>';
                              }
                              if (data.Table24[0].instruction != null && data.Table24[0].instruction != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Instruction</label> : <span>' + data.Table24[0].instruction + ' </span></div>';
                              }
                              if (data.Table24[0].xray_findings != null && data.Table24[0].xray_findings != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Examination Findings</label> : <span>' + data.Table24[0].xray_findings + ' </span></div>';
                              }
                              if (data.Table24[0].advice != null && data.Table24[0].advice != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Advice</label> : <span>' + data.Table24[0].advice + ' </span></div>';
                              }
                              if (data.Table24[0].counselling != null && data.Table24[0].counselling != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Counselling</label> : <span>' + data.Table24[0].counselling + ' </span></div>';
                              }
                              if (data.Table24[0].xray_findings_new != null && data.Table24[0].xray_findings_new != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Xray Finding</label> : <span>' + data.Table24[0].xray_findings_new + ' </span></div>';
                              }
                              if (data.Table24[0].lab_findings != null && data.Table24[0].lab_findings != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Lab Findings</label> : <span>' + data.Table24[0].lab_findings + ' </span></div>';
                              }
                              if (data.Table24[0].review_notes != null && data.Table24[0].review_notes != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Review Notes</label> : <span>' + data.Table24[0].review_notes + ' </span></div>';
                              }
                          }

                          if (data.Table.length > 0) {

                              if (data.Table[0].current_complaints != null && data.Table[0].current_complaints != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Complaints</label> : <span>' + data.Table[0].current_complaints + '</span></div>';
                              }
                              if (data.Table[0].note != null && data.Table[0].note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Notes </label> : <span>' + data.Table[0].note + '</span></div>';
                              }
                              
                              if (data.Table[0].hypoglycemia_episodes != null && data.Table[0].hypoglycemia_episodes != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Hypoglycemic Episodes</label> : <span>' + data.Table[0].hypoglycemia_episodes + '</span></div>';
                              }

                              debugger;
                              if (data.Table28[0].vas != null && data.Table28[0].vas != '') {
                                  if (data.Table28[0].vas == '0') {
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Visual Analogue Scale(VAS)</b></h5></label> : <span> No Pain</span></div>';
                                  }
                                  else if (data.Table28[0].vas == '1' || data.Table28[0].vas == '2' || data.Table28[0].vas == '3') {
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Visual Analogue Scale(VAS)</b></h5></label> : <span> Mild</span></div>';
                                  }
                                  else if (data.Table28[0].vas == '4' || data.Table28[0].vas == '5' || data.Table28[0].vas == '6') {
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Visual Analogue Scale(VAS)</b></h5></label> : <span> Moderate </span></div>';
                                  }
                                  else if (data.Table28[0].vas == '7' || data.Table28[0].vas == '8' || data.Table28[0].vas == '9') {
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Visual Analogue Scale(VAS)</b></h5></label> : <span> Severe</span></div>';
                                  }
                                  if (data.Table28[0].vas == '10') {
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Visual Analogue Scale(VAS)</b></h5></label> : <span> Worst Pain </span></div>';
                                  }
                                  if (data.Table28[0].vasduration != null) {
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Vas Duration</b></h5></label> : <span> ' + data.Table28[0].vasduration + ' </span></div>';
                                  }

                                  if (data.Table28[0].vaslocation != null) {
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Vas Location</b></h5></label> : <span> ' + data.Table28[0].vaslocation + ' </span></div>';
                                  }

                                  if (data.Table28[0].followup != null) {
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Follow Up/Admission Plan</b></h5></label> : <span> ' + data.Table28[0].followup + ' </span></div>';
                                  }

                                  if (data.Table28[0].vaspaincharacter != null) {
                                      var paincharacter = data.Table28[0].vaspaincharacter;

                                      if (paincharacter != null && paincharacter != "") {

                                          var paincharactersplit = paincharacter.split(',');
                                          var paincharacter_disp = [];
                                          for (i = 0; i < paincharactersplit.length; i++) {

                                              if (paincharactersplit[i] == 0) {
                                                  var paincharacter_view = "Dull"
                                              }
                                              else if (paincharactersplit[i] == 1) {
                                                  var paincharacter_view = "Aching"
                                              }
                                              else if (paincharactersplit[i] == 2) {
                                                  var paincharacter_view = "Sharp"
                                              }
                                              else if (paincharactersplit[i] == 3) {
                                                  var paincharacter_view = "Stabbing"
                                              }
                                              else if (paincharactersplit[i] == 4) {
                                                  var paincharacter_view = "Shooting"
                                              }
                                              else if (paincharactersplit[i] == 5) {
                                                  var paincharacter_view = "Burning"
                                              }
                                              else if (paincharactersplit[i] == 6) {
                                                  var paincharacter_view = "Referred/Radiant Plain"
                                              }
                                              paincharacter_disp.push(paincharacter_view)

                                          }

                                      }
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Pain Character</b></h5></label> : <span> ' + paincharacter_disp + ' </span></div>';
                                  }
                                  if (data.Table28[0].vasfullrisk != null) {
                                      var frsfa = data.Table28[0].vasfullrisk;
                                      var frsfa_disp = [];
                                      if (frsfa != null && frsfa != "") {

                                          var frsfasplit = frsfa.split(',');

                                          for (i = 0; i < frsfasplit.length; i++) {
                                              if (frsfasplit[i] == 0) {
                                                  var frsfa_view = "No risk"
                                              }
                                              else if (frsfasplit[i] == 1) {
                                                  var frsfa_view = "Age More than 65 years"
                                              }
                                              else if (frsfasplit[i] == 2) {
                                                  var frsfa_view = "History of fall in last 3 Months"
                                              }
                                              else if (frsfasplit[i] == 3) {
                                                  var frsfa_view = "Walks with assistance"
                                              }
                                              else if (frsfasplit[i] == 4) {
                                                  var frsfa_view = "Any Neurological Problem"
                                              }

                                              frsfa_disp.push(frsfa_view)


                                          }

                                      }
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Full Risk Screening for Adults</b></h5></label> : <span> ' + frsfa_disp + ' </span></div>';
                                  }
                              }



                              if (data.Table[0].glycemic_variability != null && data.Table[0].glycemic_variability != '') {
                                  var glycemic_variability = data.Table[0].glycemic_variability;
                                  if (glycemic_variability == 1) {
                                      glycemic_variability = "Present";
                                  }
                                  else {
                                      glycemic_variability = "Absent";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Glycemic Variability</label> : <span>' + glycemic_variability + '</span></div>';
                              }
                              if (data.Table[0].cvs != null && data.Table[0].cvs != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">CVS</label> : <span>' + data.Table[0].cvs + '</span></div>';
                              }
                              if (data.Table[0].ABS != null && data.Table[0].ABS != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">ABD</label> : <span>' + data.Table[0].ABS + '</span></div>';
                              }
                              if (data.Table[0].rs != null && data.Table[0].rs != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">RS</label> : <span>' + data.Table[0].rs + '</span></div>';
                              }
                              if (data.Table[0].CNS != null && data.Table[0].CNS != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">CNS</label> : <span>' + data.Table[0].CNS + '</span></div>';
                              }

                              if (data.Table[0].heart_sound != null && data.Table[0].heart_sound != '') {
                                  var heart_sound = data.Table[0].heart_sound;
                                  if (heart_sound == 1) {
                                      heart_sound = "True";
                                  }
                                  else {
                                      heart_sound = "False";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Abnormal Heart Sound</label> : <span>' + heart_sound + '</span></div>';
                              }

                              if (data.Table[0].murmurs != null && data.Table[0].murmurs != '') {
                                  var murmurs = data.Table[0].murmurs;
                                  if (murmurs == 1) {
                                      murmurs = "Present";
                                  }
                                  else {
                                      murmurs = "Absent";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Murmurs</label> : <span>' + murmurs + '</span></div>';
                              }

                              if (data.Table[0].reduce_air_entry != null && data.Table[0].reduce_air_entry != '') {
                                  var reduce_air_entry = data.Table[0].reduce_air_entry;
                                  if (reduce_air_entry == 1) {
                                      reduce_air_entry = "Present";
                                  }
                                  else {
                                      reduce_air_entry = "Absent";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Reduced Air Entry</label> : <span>' + reduce_air_entry + '</span></div>';
                              }

                              if (data.Table[0].crackles != null && data.Table[0].crackles != '') {
                                  var crackles = data.Table[0].crackles;
                                  if (crackles == 1) {
                                      crackles = "Present";
                                  }
                                  else {
                                      crackles = "Absent";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Crackles</label> : <span>' + crackles + '</span></div>';
                              }
                              if (data.Table[0].bowel_sounds != null && data.Table[0].bowel_sounds != '') {
                                  var bowel_sounds = data.Table[0].bowel_sounds;
                                  if (bowel_sounds == 1) {
                                      bowel_sounds = "Present";
                                  }
                                  else {
                                      bowel_sounds = "Absent";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Abnormal Bowel Sounds</label> : <span>' + bowel_sounds + '</span></div>';
                              }
                              if (data.Table[0].organomeglay != null && data.Table[0].organomeglay != '') {
                                  var organomeglay = data.Table[0].organomeglay;
                                  if (organomeglay == 1) {
                                      organomeglay = "Present";
                                  }
                                  else {
                                      organomeglay = "Absent";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Organomeglay</label> : <span>' + organomeglay + '</span></div>';
                              }
                              if (data.Table[0].tremors_weakness != null && data.Table[0].tremors_weakness != '') {
                                  var tremors_weakness = data.Table[0].tremors_weakness;
                                  if (tremors_weakness == 1) {
                                      tremors_weakness = "Present";
                                  }
                                  else {
                                      tremors_weakness = "Absent";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Tremors Weakness</label> : <span>' + tremors_weakness + '</span></div>';
                              }
                              if (data.Table[0].cognitive_imparement != null && data.Table[0].cognitive_imparement != '') {
                                  var cognitive_imparement = data.Table[0].cognitive_imparement;
                                  if (cognitive_imparement == 1) {
                                      cognitive_imparement = "Present";
                                  }
                                  else {
                                      cognitive_imparement = "Absent";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Cognitive Imparement</label> : <span>' + cognitive_imparement + '</span></div>';
                              }
                          }
                          
                          //dental
                          if (data.Table28.length > 0 && (data.Table28[0].dental_procedure_done != null || data.Table28[0].dental_procedure_remaining != null || data.Table28[0].dental_type != null)) {
                              div = div + '<div class="col-md-12"><h5><b>Dental</h5></b></div>';
                          }
                          if (data.Table28.length > 0) {
                              if (data.Table28[0].dental_type != null && data.Table28[0].dental_type != '') {
                                  div = div + '<div class="col-md-12"><label class="control-label">Type of Dental Appointment</label> : <span>' + (data.Table28[0].dental_type == 1 ? "Cosmetic" : data.Table28[0].dental_type == 2 ? "Dental" : "Surgical") + '</span></div>';
                              }
                              if (data.Table28[0].dental_procedure_done != null && data.Table28[0].dental_procedure_done != '') {
                                  div = div + '<div class="col-md-12"><label class="control-label">Procedure Done</label> : <span>' + data.Table28[0].dental_procedure_done + '</span></div>';
                              }
                              if (data.Table28[0].dental_procedure_remaining != null && data.Table28[0].dental_procedure_remaining != '') {
                                  div = div + '<div class="col-md-12"><label class="control-label">Procedure Remaining</label> : <span>' + data.Table28[0].dental_procedure_remaining + '</span></div>';
                              }
                          }

                          if (data.Table2.length > 0 && data.Table2[0].glycemic_parameters_basic_id != null) {
                              div = div + '<div class="col-md-12"><h5><b>Glycemic</b></h5></div>';
                          }
                          else if (data.Table3.length > 0 && data.Table3[0].patient_hbac_record_id != null) {
                              div = div + '<div class="col-md-12"><h5><b>Glycemic</b></h5></div>';
                          }
                          else if (data.Table4.length > 0 && data.Table4[0].patient_blood_sugar_record_id != null) {
                              div = div + '<div class="col-md-12"><h5><b>Glycemic</b></h5></div>';
                          }
                          else {

                          }
                          if (data.Table2.length > 0) {
                              if (data.Table2[0].fasting_insulin != null && data.Table2[0].fasting_insulin != '') {
                                  var fasting_inslin_unit = 'mlU/L';
                                  if (data.Table2[0].fasting_inslin_unit == 2) {
                                      fasting_inslin_unit = 'pmol/L'
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Fasting Insulin</label> : <span>' + data.Table2[0].fasting_insulin + ' ' + fasting_inslin_unit + '</span></div>';
                              }
                              if (data.Table2[0].hemoglobin != null && data.Table2[0].hemoglobin != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">HB</label> : <span>' + data.Table2[0].hemoglobin + ' gms</span></div>';
                              }
                              if (data.Table2[0].note != null && data.Table2[0].note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Glycemic Notes</label> : <span>' + data.Table2[0].note + '</span></div>';
                              }
                              if (data.Table2[0].WBC != null && data.Table2[0].WBC != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">WBC</label> : <span>' + data.Table2[0].WBC + ' cells per cubic millimeter</span></div>';
                              }
                              if (data.Table2[0].platelet != null && data.Table2[0].platelet != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Platelet</label> : <span>' + data.Table2[0].platelet + ' per microliter</span></div>';
                              }
                              if (data.Table2[0].se_ketones != null && data.Table2[0].se_ketones != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Se_ketones</label> : <span>' + data.Table2[0].se_ketones + ' mmol/L</span></div>';
                              }

                          }

                          //if (data.Table3.length > 0 || data.Table4.length > 0) {
                          //    div = div + '<br/><div class="col-md-12"><h4>Glycemic</h4></div>';
                          //}

                          if (data.Table3.length > 0) {
                              if (data.Table3[0].patient_hbac_record_value != null && data.Table3[0].patient_hbac_record_value != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">HBA1C</label> : <span>' + data.Table3[0].patient_hbac_record_value + ' %</span></div>';
                              }
                          }

                          if (data.Table4.length > 0) {
                              for (var i = 0; i < data.Table4.length; i++) {
                                  if (data.Table4[i].patient_blood_sugar_value != null && data.Table4[i].patient_blood_sugar_value != '' && data.Table4[i].patient_blood_sugar_type == 1) {
                                      var unit = 'mg/dL';
                                      if (data.Table4[i].patient_blood_sugar_unit == 1) {
                                          unit = 'mmol/L';
                                      }
                                      div = div + '<div class="col-md-4"><label class="control-label">Fasting blood sugar</label> : <span>' + data.Table4[i].patient_blood_sugar_value + ' ' + unit + '</span></div>';
                                  }
                                  if (data.Table4[i].patient_blood_sugar_value != null && data.Table4[i].patient_blood_sugar_value != '' && data.Table4[i].patient_blood_sugar_type == 2) {
                                      var unit = 'mg/dL';
                                      if (data.Table4[i].patient_blood_sugar_unit == 1) {
                                          unit = 'mmol/L';
                                      }
                                      div = div + '<div class="col-md-4"><label class="control-label">Postprandial blood sugar</label> : <span>' + data.Table4[i].patient_blood_sugar_value + ' ' + unit + '</span></div>';
                                  }
                                  if (data.Table4[i].patient_blood_sugar_value != null && data.Table4[i].patient_blood_sugar_value != '' && data.Table4[i].patient_blood_sugar_type == 3) {
                                      var unit = 'mg/dL';
                                      if (data.Table4[i].patient_blood_sugar_unit == 1) {
                                          unit = 'mmol/L';
                                      }
                                      div = div + '<div class="col-md-4"><label class="control-label">Random blood sugar</label> : <span>' + data.Table4[i].patient_blood_sugar_value + ' ' + unit + '</span></div>';
                                  }
                                  if (data.Table4[i].patient_blood_sugar_value != null && data.Table4[i].patient_blood_sugar_value != '' && data.Table4[i].patient_blood_sugar_type == 4) {
                                      var unit = 'mg/dL';
                                      if (data.Table4[i].patient_blood_sugar_unit == 1) {
                                          unit = 'mmol/L';
                                      }
                                      div = div + '<div class="col-md-4"><label class="control-label">Before Lunch BS</label> : <span>' + data.Table4[i].patient_blood_sugar_value + ' ' + unit + '</span></div>';
                                  }
                                  if (data.Table4[i].patient_blood_sugar_value != null && data.Table4[i].patient_blood_sugar_value != '' && data.Table4[i].patient_blood_sugar_type == 5) {
                                      var unit = 'mg/dL';
                                      if (data.Table4[i].patient_blood_sugar_unit == 1) {
                                          unit = 'mmol/L';
                                      }
                                      div = div + '<div class="col-md-4"><label class="control-label">After Lunch BS</label> : <span>' + data.Table4[i].patient_blood_sugar_value + ' ' + unit + '</span></div>';
                                  }
                                  if (data.Table4[i].patient_blood_sugar_value != null && data.Table4[i].patient_blood_sugar_value != '' && data.Table4[i].patient_blood_sugar_type == 6) {
                                      var unit = 'mg/dL';
                                      if (data.Table4[i].patient_blood_sugar_unit == 1) {
                                          unit = 'mmol/L';
                                      }
                                      div = div + '<div class="col-md-4"><label class="control-label">Before Dinner BS</label> : <span>' + data.Table4[i].patient_blood_sugar_value + ' ' + unit + '</span></div>';
                                  }
                                  if (data.Table4[i].patient_blood_sugar_value != null && data.Table4[i].patient_blood_sugar_value != '' && data.Table4[i].patient_blood_sugar_type == 7) {
                                      var unit = 'mg/dL';
                                      if (data.Table4[i].patient_blood_sugar_unit == 1) {
                                          unit = 'mmol/L';
                                      }
                                      div = div + '<div class="col-md-4"><label class="control-label">After Dinner BS</label> : <span>' + data.Table4[i].patient_blood_sugar_value + ' ' + unit + '</span></div>';
                                  }
                                  if (data.Table4[i].patient_blood_sugar_value != null && data.Table4[i].patient_blood_sugar_value != '' && data.Table4[i].patient_blood_sugar_type == 8) {
                                      var unit = 'mg/dL';
                                      if (data.Table4[i].patient_blood_sugar_unit == 1) {
                                          unit = 'mmol/L';
                                      }
                                      div = div + '<div class="col-md-4"><label class="control-label">3 Am BS</label> : <span>' + data.Table4[i].patient_blood_sugar_value + ' ' + unit + '</span></div>';
                                  }
                              }

                          }
                          //want to write code
                          if (data.Table5.length > 0) {
                              //if (data.Table3[0].patient_hbac_record_value != null && data.Table3[0].patient_hbac_record_value != '') {
                              //    div = div + '<div class="col-md-4"><label class="control-label">Platelet</label> : <span>' + data.Table3[0].patient_hbac_record_value + ' %</span></div>';
                              //}
                          }

                          if (data.Table6.length > 0) {
                              if (data.Table6[0].renal_function_test_id != null) {
                                  div = div + '<div class="col-md-12"><h5><b>RENAL</b></h5></div>';
                              }
                          }
                          else {
                              if (data.Table7.length > 0) {
                                  if ((data.Table7[0].ACR != null && data.Table7[0].ACR != '') || (data.Table7[0].nephropathy != null && data.Table7[0].nephropathy != '')) {
                                      div = div + '<div class="col-md-12"><h5><b>RENAL</b></h5></div>';
                                  }
                              }
                          }

                          if (data.Table6.length > 0) {
                              if (data.Table6[0].Urea != null && data.Table6[0].Urea != '') {
                                  var unit = 'mg/dL';
                                  if (data.Table6[0].urea_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Urea</label> : <span>' + data.Table6[0].Urea + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].creatinine != null && data.Table6[0].creatinine != '') {
                                  var unit = 'mg/dL';
                                  if (data.Table6[0].Creatinine_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Creatinine</label> : <span>' + data.Table6[0].creatinine + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].egfr_value != null && data.Table6[0].egfr_value != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">EGFR ( Calculated )</label> : <span>' + data.Table6[0].egfr_value + ' ml/min/1.73m2</span></div>';
                              }
                              if (data.Table6[0].Sodium != null && data.Table6[0].Sodium != '') {
                                  var unit = 'mEq/L';
                                  if (data.Table6[0].sodium_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Sodium</label> : <span>' + data.Table6[0].Sodium + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].Potassium != null && data.Table6[0].Potassium != '') {
                                  var unit = 'mEq/L';
                                  if (data.Table6[0].potassium_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Potassium</label> : <span>' + data.Table6[0].Potassium + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].Chlorine != null && data.Table6[0].Chlorine != '') {
                                  var unit = 'mEq/L';
                                  if (data.Table6[0].chlorine_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Chlorine</label> : <span>' + data.Table6[0].Chlorine + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].BiCarbonate != null && data.Table6[0].BiCarbonate != '') {
                                  var unit = 'mEq/L';
                                  if (data.Table6[0].Bicarbonate_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">BiCarbonate</label> : <span>' + data.Table6[0].BiCarbonate + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].serium_calcium != null && data.Table6[0].serium_calcium != '') {
                                  var unit = 'mEq/L';
                                  if (data.Table6[0].Calcium_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Calcium</label> : <span>' + data.Table6[0].serium_calcium + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].serium_phosphorous != null && data.Table6[0].serium_phosphorous != '') {
                                  var unit = 'mEq/L';
                                  if (data.Table6[0].Phosphorus_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Phosphorous</label> : <span>' + data.Table6[0].serium_phosphorous + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].serium_magnesium != null && data.Table6[0].serium_magnesium != '') {
                                  var unit = 'mEq/L';
                                  if (data.Table6[0].Magnesium_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Magnesium</label> : <span>' + data.Table6[0].serium_magnesium + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].note != null && data.Table6[0].note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Renal Notes</label> : <span>' + data.Table6[0].note + ' </span></div>';
                              }
                              if (data.Table6[0].ASD != null && data.Table6[0].ASD != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">ASD</label> : <span>' + data.Table6[0].ASD + ' </span></div>';
                              }
                              if (data.Table6[0].VSD != null && data.Table6[0].VSD != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">VSD</label> : <span>' + data.Table6[0].VSD + ' </span></div>';
                              }
                              if (data.Table6[0].C_value != null && data.Table6[0].C_value != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Valve Notes</label> : <span>' + data.Table6[0].C_value + ' </span></div>';
                              }
                              if (data.Table6[0].fraction != null && data.Table6[0].fraction != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Fraction</label> : <span>' + data.Table6[0].fraction + ' </span></div>';
                              }
                              if (data.Table6[0].mitral_value != null && data.Table6[0].mitral_value != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Mitral Value</label> : <span>' + data.Table6[0].mitral_value + ' </span></div>';
                              }
                              if (data.Table6[0].lotic_value != null && data.Table6[0].lotic_value != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Aortic Valve</label> : <span>' + data.Table6[0].lotic_value + ' </span></div>';
                              }
                              if (data.Table6[0].tricuspid != null && data.Table6[0].tricuspid != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Tricuspid</label> : <span>' + data.Table6[0].tricuspid + ' </span></div>';
                              }
                              if (data.Table6[0].pulmonary != null && data.Table6[0].pulmonary != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Pulmonary</label> : <span>' + data.Table6[0].pulmonary + ' </span></div>';
                              }

                          }

                          if (data.Table7.length > 0) {
                              if (data.Table7[0].ACR != null && data.Table7[0].ACR != '') {
                                  var ACR = '';
                                  if (data.Table7[0].ACR == 1) {
                                      ACR = '< 30 mg/dL - Normal';
                                  }
                                  if (data.Table7[0].ACR == 2) {
                                      ACR = '30 to 300 mg/dL - Microalbuminuria';
                                  }
                                  if (data.Table7[0].ACR == 3) {
                                      ACR = '  > 300 mg/dL - Proteinuria';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">ACR</label> : <span>' + ACR + '</span></div>';
                              }
                              if (data.Table7[0].nephropathy != null && data.Table7[0].nephropathy != '') {
                                  var nephropathy = '';
                                  if (data.Table7[0].nephropathy == 1) {
                                      nephropathy = 'Yes';
                                  }
                                  if (data.Table7[0].nephropathy == 2) {
                                      nephropathy = 'No';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Nephropathy</label> : <span>' + nephropathy + '</span></div>';
                              }
                          }



                          if (data.Table8.length > 0) {
                              if (data.Table8[0].cholestrol_id != null) {
                                  div = div + '<div class="col-md-12"><h5><b>CHOLESTEROL</b></h5></div>';
                              }

                          }
                          else {
                              if (data.Table9.length > 0) {
                                  if (data.Table9[0].dyslipedemia != null && data.Table9[0].dyslipedemia != '') {
                                      div = div + '<div class="col-md-12"><h5><b>CHOLESTEROL</b></h5></div>';
                                  }
                              }
                          }

                          if (data.Table8.length > 0) {
                              if (data.Table8[0].Total_Cholestrol != null && data.Table8[0].Total_Cholestrol != '') {
                                  var unit = 'mmol/L';
                                  if (data.Table8[0].Total_cholestrol_unit == 1) {
                                      unit = 'mg/dL';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Total Cholesterol</label> : <span>' + data.Table8[0].Total_Cholestrol + '' + unit + ' </span></div>';
                              }

                              if (data.Table8[0].LDL != null && data.Table8[0].LDL != '') {
                                  var unit = 'mmol/L';
                                  if (data.Table8[0].LDL_unit == 1) {
                                      unit = 'mg/dL';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">LDL</label> : <span>' + data.Table8[0].LDL + '' + unit + ' </span></div>';
                              }

                              if (data.Table8[0].HDL != null && data.Table8[0].HDL != '') {
                                  var unit = 'mmol/L';
                                  if (data.Table8[0].HDL_unit == 1) {
                                      unit = 'mg/dL';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">HDL</label> : <span>' + data.Table8[0].HDL + '' + unit + ' </span></div>';
                              }

                              if (data.Table8[0].VLDL != null && data.Table8[0].VLDL != '') {
                                  var unit = 'mmol/L';
                                  if (data.Table8[0].VLDL_unit == 1) {
                                      unit = 'mg/dL';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">VLDL</label> : <span>' + data.Table8[0].VLDL + '' + unit + ' </span></div>';
                              }
                              if (data.Table8[0].Triglycerides != null && data.Table8[0].Triglycerides != '') {
                                  var unit = 'mmol/L';
                                  if (data.Table8[0].Triglycerides_unit == 1) {
                                      unit = 'mg/dL';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Triglycerides</label> : <span>' + data.Table8[0].Triglycerides + '' + unit + ' </span></div>';
                              }
                              if (data.Table8[0].T_cholestrol_Hdl_ratio != null && data.Table8[0].T_cholestrol_Hdl_ratio != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Total Cholesterol : HDL Ratio</label> : <span>' + data.Table8[0].T_cholestrol_Hdl_ratio + ' </span></div>';
                              }
                              if (data.Table8[0].note != null && data.Table8[0].note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Cholestrol Notes</label> : <span>' + data.Table8[0].note + ' </span></div>';
                              }
                          }
                          if (data.Table9.length > 0) {
                              if (data.Table9[0].dyslipedemia != null && data.Table9[0].dyslipedemia != '') {
                                  var unit = '';
                                  if (data.Table9[0].dyslipedemia == 1) {
                                      unit = 'yes';
                                  }
                                  else {
                                      unit = 'No';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Dyslipidemia</label> : <span>' + unit + ' </span></div>';
                              }
                          }

                          if (data.Table10.length > 0 && ((data.Table10[0].last_observation_date != null && data.Table10[0].last_observation_date != '') || (data.Table10[0].next_suggested_appointment != null && data.Table10[0].next_suggested_appointment != '') || (data.Table10[0].note != null && data.Table10[0].note != ''))) {
                              div = div + '<div class="col-md-12"><h5><b>OPTHAL</b></h5></div>';
                          }
                          else if (data.Table11.length > 0 && data.Table11[0].patient_level_flag_id != null && ((data.Table11[0].pdr != null && data.Table11[0].pdr != '') || (data.Table11[0].npdr != null && data.Table11[0].npdr != '') || (data.Table11[0].viterous_hemorage != null && data.Table11[0].viterous_hemorage != '') || (data.Table11[0].retinal_detachment != null && data.Table11[0].retinal_detachment != '') || (data.Table11[0].retinopathy != null && data.Table11[0].retinopathy != ''))) {
                              div = div + '<div class="col-md-12"><h5><b>OPTHAL</b></h5></div>';
                          }
                          if (data.Table10.length > 0) {

                              if (data.Table10[0].last_observation_date != null && data.Table10[0].last_observation_date != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Last Observation Date</label> : <span>' + data.Table10[0].last_observation_date + ' </span></div>';
                              }
                              if (data.Table10[0].next_suggested_appointment != null && data.Table10[0].next_suggested_appointment != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Next Suggested Opthal Appointment</label> : <span>' + data.Table10[0].next_suggested_appointment + ' </span></div>';
                              }
                              if (data.Table10[0].note != null && data.Table10[0].note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Opthal Notes</label> : <span>' + data.Table10[0].note + ' </span></div>';
                              }
                          }

                          if (data.Table11.length > 0) {
                              if (data.Table11[0].pdr != null && data.Table11[0].pdr != '') {
                                  var val = '';
                                  if (data.Table11[0].pdr == 1) {
                                      val = 'None';
                                  }
                                  else if (data.Table11[0].pdr == 2) {
                                      val = 'Mild';
                                  }
                                  else if (data.Table11[0].pdr == 3) {
                                      val = 'Moderate';
                                  }
                                  else if (data.Table11[0].pdr == 4) {
                                      val = 'Severe';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">PDR</label> : <span>' + val + ' </span></div>';
                              }
                              if (data.Table11[0].npdr != null && data.Table11[0].npdr != '') {
                                  var val = '';
                                  if (data.Table11[0].npdr == 1) {
                                      val = 'None';
                                  }
                                  else if (data.Table11[0].npdr == 2) {
                                      val = 'Mild';
                                  }
                                  else if (data.Table11[0].npdr == 3) {
                                      val = 'Moderate';
                                  }
                                  else if (data.Table11[0].npdr == 4) {
                                      val = 'Severe';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">NPDR</label> : <span>' + val + ' </span></div>';
                              }
                              if (data.Table11[0].viterous_hemorage != null && data.Table11[0].viterous_hemorage != '') {
                                  var val = '';
                                  if (data.Table11[0].viterous_hemorage == 1) {
                                      val = 'Yes';
                                  }
                                  else if (data.Table11[0].viterous_hemorage == 2) {
                                      val = 'No';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Vitreous Hemorrhage</label> : <span>' + val + ' </span></div>';
                              }
                              if (data.Table11[0].retinal_detachment != null && data.Table11[0].retinal_detachment != '') {
                                  var val = '';
                                  if (data.Table11[0].retinal_detachment == 1) {
                                      val = 'Yes';
                                  }
                                  else if (data.Table11[0].retinal_detachment == 2) {
                                      val = 'No';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Retinal Detachment</label> : <span>' + val + ' </span></div>';
                              }
                              if (data.Table11[0].retinopathy != null && data.Table11[0].retinopathy != '') {
                                  var val = '';
                                  if (data.Table11[0].retinopathy == 1) {
                                      val = 'Yes';
                                  }
                                  else if (data.Table11[0].retinopathy == 2) {
                                      val = 'No';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Retinopathy</label> : <span>' + val + ' </span></div>';
                              }
                          }

                          if (data.Table19.length > 0 && data.Table19[0].patient_level_cardiac_id != null && (data.Table19[0].L_LAD != null || data.Table19[0].L_LAD_type != null || data.Table19[0].L_LCX != null ||
                               data.Table19[0].L_LCX_type != null || data.Table19[0].L_RCA != null || data.Table19[0].L_RCA_type != null || data.Table19[0].R_LAD != null || data.Table19[0].R_LAD_type != null
                               || data.Table19[0].R_LCX != null || data.Table19[0].R_LCX_type != null || data.Table19[0].R_RCA != null || data.Table19[0].R_RCA_type != null)) {
                              div = div + '<div class="col-md-12"><h5>CARDIAC</h5></div>';
                          }
                          else if (data.Table12.length > 0 && data.Table12[0].cardiac_profile_id != null && (data.Table12[0].ECG != null || data.Table12[0].ECHO != null
                          || (data.Table12[0].ecg_abnormal != null && data.Table12[0].ecg_abnormal != 0) || (data.Table12[0].echo_abnormal != null && data.Table12[0].echo_abnormal != 0) || data.Table12[0].TMT_test != null || data.Table12[0].note != null)) {
                              div = div + '<div class="col-md-12"><h5>CARDIAC</h5></div>';
                          }
                          else { }
                          if (data.Table19.length > 0) {
                              if (data.Table19[0].L_LAD != null && data.Table19[0].L_LAD != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">LCA</label> : <span>' + data.Table19[0].L_LAD + ' %</span></div>';
                              }
                              if (data.Table19[0].L_LAD_type != null && data.Table19[0].L_LAD_type != '' && data.Table19[0].L_LAD_type != 0) {
                                  var type = '';
                                  if (data.Table19[0].L_LAD_type == 1) {
                                      type = 'Proximal';
                                  }
                                  else if (data.Table19[0].L_LAD_type == 2) {
                                      type = 'Mid';
                                  }
                                  else if (data.Table19[0].L_LAD_type == 3) {
                                      type = 'Distal';
                                  }

                                  div = div + '<div class="col-md-4"><label class="control-label">LCA Type</label> : <span>' + type + ' </span></div>';
                              }

                              if (data.Table19[0].L_LCX != null && data.Table19[0].L_LCX != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">LCX</label> : <span>' + data.Table19[0].L_LCX + ' %</span></div>';
                              }
                              if (data.Table19[0].L_LCX_type != null && data.Table19[0].L_LCX_type != '' && data.Table19[0].L_LCX_type != 0) {
                                  var type = '';
                                  if (data.Table19[0].L_LCX_type == 1) {
                                      type = 'Proximal';
                                  }
                                  else if (data.Table19[0].L_LCX_type == 2) {
                                      type = 'Mid';
                                  }
                                  else if (data.Table19[0].L_LCX_type == 3) {
                                      type = 'Distal';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">LCX Type</label> : <span>' + type + ' </span></div>';
                              }


                              if (data.Table19[0].L_RCA != null && data.Table19[0].L_RCA != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">LAD</label> : <span>' + data.Table19[0].L_RCA + ' %</span></div>';
                              }
                              if (data.Table19[0].L_RCA_type != null && data.Table19[0].L_RCA_type != '' && data.Table19[0].L_RCA_type != 0) {
                                  var type = '';
                                  if (data.Table19[0].L_RCA_type == 1) {
                                      type = 'Proximal';
                                  }
                                  else if (data.Table19[0].L_RCA_type == 2) {
                                      type = 'Mid';
                                  }
                                  else if (data.Table19[0].L_RCA_type == 3) {
                                      type = 'Distal';
                                  }

                                  div = div + '<div class="col-md-4"><label class="control-label">LAD Type</label> : <span>' + type + ' </span></div>';
                              }


                              if (data.Table19[0].R_LAD != null && data.Table19[0].R_LAD != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">RCA</label> : <span>' + data.Table19[0].R_LAD + ' %</span></div>';
                              }
                              if (data.Table19[0].R_LAD_type != null && data.Table19[0].R_LAD_type != '' && data.Table19[0].R_LAD_type != 0) {
                                  var type = '';
                                  if (data.Table19[0].R_LAD_type == 1) {
                                      type = 'Proximal';
                                  }
                                  else if (data.Table19[0].R_LAD_type == 2) {
                                      type = 'Mid';
                                  }
                                  else if (data.Table19[0].R_LAD_type == 3) {
                                      type = 'Distal';
                                  }

                                  div = div + '<div class="col-md-4"><label class="control-label">RCA Type</label> : <span>' + type + ' </span></div>';
                              }


                              if (data.Table19[0].R_LCX != null && data.Table19[0].R_LCX != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">R-PLB</label> : <span>' + data.Table19[0].R_LCX + ' %</span></div>';
                              }
                              if (data.Table19[0].R_LCX_type != null && data.Table19[0].R_LCX_type != '' && data.Table19[0].R_LCX_type != 0) {
                                  var type = '';
                                  if (data.Table19[0].R_LCX_type == 1) {
                                      type = 'Proximal';
                                  }
                                  else if (data.Table19[0].R_LCX_type == 2) {
                                      type = 'Mid';
                                  }
                                  else if (data.Table19[0].R_LCX_type == 3) {
                                      type = 'Distal';
                                  }

                                  div = div + '<div class="col-md-4"><label class="control-label">R-PLB Type</label> : <span>' + type + ' </span></div>';
                              }


                              if (data.Table19[0].R_RCA != null && data.Table19[0].R_RCA != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">R-PDA</label> : <span>' + data.Table19[0].R_RCA + ' %</span></div>';
                              }
                              if (data.Table19[0].R_RCA_type != null && data.Table19[0].R_RCA_type != '' && data.Table19[0].R_RCA_type != 0) {
                                  var type = '';
                                  if (data.Table19[0].R_RCA_type == 1) {
                                      type = 'Proximal';
                                  }
                                  else if (data.Table19[0].R_RCA_type == 2) {
                                      type = 'Mid';
                                  }
                                  else if (data.Table19[0].R_RCA_type == 3) {
                                      type = 'Distal';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">R-PDA Type</label> : <span>' + type + ' </span></div>';
                              }



                          }

                          if (data.Table12.length > 0) {
                              if (data.Table12[0].ECG != null && data.Table12[0].ECG != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">ECG</label> : <span>' + data.Table12[0].ECG + ' </span></div>';
                              }
                              if (data.Table12[0].ECHO != null && data.Table12[0].ECHO != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">ECHO</label> : <span>' + data.Table12[0].ECHO + ' </span></div>';
                              }
                              if (data.Table12[0].ecg_abnormal != null && data.Table12[0].ecg_abnormal != '') {
                                  if (data.Table12[0].ecg_abnormal == 1) {
                                      div = div + '<div class="col-md-4"><label class="control-label">ECG Abnormal</label> : <span>True</span></div>';
                                  }
                              }
                              if (data.Table12[0].echo_abnormal != null && data.Table12[0].echo_abnormal != '') {
                                  if (data.Table12[0].echo_abnormal == 1) {
                                      div = div + '<div class="col-md-4"><label class="control-label">ECHO Abnormal</label> : <span>True</span></div>';
                                  }
                              }
                              if (data.Table12[0].TMT_test != null && data.Table12[0].TMT_test != '') {
                                  if (data.Table12[0].TMT_test == 1) {
                                      div = div + '<div class="col-md-4"><label class="control-label">TMT</label> : <span>Positive</span></div>';
                                  }
                                  else {
                                      div = div + '<div class="col-md-4"><label class="control-label">TMT</label> : <span>Negative</span></div>';
                                  }
                              }
                              if (data.Table12[0].note != null && data.Table12[0].note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Cardiac Notes</label> : <span>' + data.Table12[0].note + '</span></div>';
                              }
                          }


                          if (data.Table13.length > 0 && (data.Table13[0].autonomic_neuropathy != null && data.Table13[0].autonomic_neuropathy != '')) {
                              div = div + '<div class="col-md-12"><h5>NEUROPATHY</h5></div>';
                          }
                          else if (data.Table14.length > 0 && ((data.Table14[0].peripharal_neuhropathy != null && data.Table14[0].peripharal_neuhropathy != '') || (data.Table14[0].AB_index != null && data.Table14[0].AB_index != '') || (data.Table14[0].doppler_note != null && data.Table14[0].doppler_note != '') || (data.Table14[0].note != null && data.Table14[0].note != ''))) {
                              div = div + '<div class="col-md-12"><h5>NEUROPATHY</h5></div>';
                          }
                          else {

                          }
                          if (data.Table13.length > 0) {
                              if (data.Table13[0].autonomic_neuropathy != null && data.Table13[0].autonomic_neuropathy != '') {
                                  if (data.Table13[0].autonomic_neuropathy == 1) {
                                      div = div + '<div class="col-md-4"><label class="control-label">Autonomic Neuropathy</label> : <span>Yes</span></div>';
                                  }
                                  else {
                                      div = div + '<div class="col-md-4"><label class="control-label">Autonomic Neuropathy</label> : <span>No</span></div>';
                                  }
                              }
                          }
                          if (data.Table14.length > 0) {
                              if (data.Table14[0].peripharal_neuhropathy != null && data.Table14[0].peripharal_neuhropathy != '') {
                                  var val = '';
                                  if (data.Table14[0].peripharal_neuhropathy == 1) {
                                      val = 'None';
                                  }
                                  else if (data.Table14[0].peripharal_neuhropathy == 2) {
                                      val = 'Mild';
                                  }
                                  else if (data.Table14[0].peripharal_neuhropathy == 3) {
                                      val = 'Moderate';
                                  }
                                  else if (data.Table14[0].peripharal_neuhropathy == 4) {
                                      val = 'Severe';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Peripheral Neuhropathy</label> : <span>' + val + ' </span></div>';
                              }
                              if (data.Table14[0].AB_index != null && data.Table14[0].AB_index != '') {
                                  var val = '';
                                  if (data.Table14[0].AB_index == 1) {
                                      val = 'None';
                                  }
                                  else if (data.Table14[0].AB_index == 2) {
                                      val = 'Mild';
                                  }
                                  else if (data.Table14[0].AB_index == 3) {
                                      val = 'Moderate';
                                  }
                                  else if (data.Table14[0].AB_index == 4) {
                                      val = 'Severe';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">AB Index</label> : <span>' + val + ' </span></div>';
                              }
                              if (data.Table14[0].doppler_note != null && data.Table14[0].doppler_note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Doppler</label> : <span>' + data.Table14[0].doppler_note + ' </span></div>';
                              }
                              if (data.Table14[0].note != null && data.Table14[0].note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Neuropthy Note</label> : <span>' + data.Table14[0].note + ' </span></div>';
                              }
                          }

                          if (data.Table15.length > 0) {
                              if (data.Table15[0].thyroid_id != null) {
                                  div = div + '<div class="col-md-12"><h5><b>THYROID</b></h5></div>';
                              }
                          }

                          if (data.Table15.length > 0) {
                              if (data.Table15[0].Free_T3 != null && data.Table15[0].Free_T3 != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Free T3</label> : <span>' + data.Table15[0].Free_T3 + ' Pg/dl </span></div>';
                              }
                              if (data.Table15[0].Free_T4 != null && data.Table15[0].Free_T4 != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Free T4</label> : <span>' + data.Table15[0].Free_T4 + ' ng/dl </span></div>';
                              }
                              if (data.Table15[0].Free_T4 != null && data.Table15[0].Free_T4 != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">TSH</label> : <span>' + data.Table15[0].TSH + ' mlU/m </span></div>';
                              }
                              if (data.Table15[0].note != null && data.Table15[0].note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Thyroid Notes</label> : <span>' + data.Table15[0].note + '</span></div>';
                              }
                          }

                          if (data.Table16.length > 0) {
                              if (data.Table16[0].sheet_chest_xray_id != null) {
                                  div = div + '<div class="col-md-12"><h5><b>ULTRASOUND / X-RAY</b></h5></div>';
                              }
                          }
                          if (data.Table16.length > 0) {
                              if (data.Table16[0].notes != null && data.Table16[0].notes != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Chest X-Ray Notes</label> : <span>' + data.Table16[0].notes + ' Pg/dl </span></div>';
                              }
                              if (data.Table16[0].USNotes != null && data.Table16[0].USNotes != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Ultrasound Notes</label> : <span>' + data.Table16[0].USNotes + ' ng/dl </span></div>';
                              }
                              if (data.Table16[0].fatty_lives != null && data.Table16[0].fatty_lives != '') {
                                  var val = '';
                                  if (data.Table16[0].fatty_lives == 1) {
                                      val = 'Yes';
                                  }
                                  else if (data.Table16[0].fatty_lives == 2) {
                                      val = 'No';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Fatty Liver</label> : <span>' + val + ' </span></div>';
                              }
                              if (data.Table16[0].GS_Calculus != null && data.Table16[0].GS_Calculus != '') {
                                  var val = '';
                                  if (data.Table16[0].GS_Calculus == 1) {
                                      val = 'Yes';
                                  }
                                  else if (data.Table16[0].GS_Calculus == 2) {
                                      val = 'No';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">GB Calculas</label> : <span>' + val + ' </span></div>';
                              }
                          }
                          if (data.Table18.length > 0) {
                              //$('#moreinfovisit_date').html(data.Table18[0].c_date);
                          }

                          if (data.Table26.length > 0) {
                              if (data.Table26[0].liver_function_test_id != null && (data.Table26[0].serum_bilirubin_total != null || data.Table26[0].serum_bilirubin_direct != null
                                                    || data.Table26[0].bilirubin_indirect != null || data.Table26[0].serum_protein_total != null || data.Table26[0].serum_protein_albumin != null || data.Table26[0].serumproteinglibulin != null
                                                    || data.Table26[0].SGOT != null || data.Table26[0].SGPT != null || data.Table26[0].serum_alkaline_phosphatase != null || data.Table26[0].gamma_glutamyl_transpeptidase != null || data.Table26[0].serum_magnesium != null)) {
                                  div = div + '<div class="col-md-12"><h5><b>LIVER FUNCTION TEST</b></h5></div>';
                              }
                          }

                          if (data.Table26.length > 0) {
                              if (data.Table26[0].serum_bilirubin_total != null && data.Table26[0].serum_bilirubin_total != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Serum Bilirubin Total</label> : <span>' + data.Table26[0].serum_bilirubin_total + ' mg/dl </span></div>';
                              }
                              if (data.Table26[0].serum_bilirubin_direct != null && data.Table26[0].serum_bilirubin_direct != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Serum Bilirubin Direct</label> : <span>' + data.Table26[0].serum_bilirubin_direct + ' mg/dl </span></div>';
                              }

                              if (data.Table26[0].bilirubin_indirect != null && data.Table26[0].bilirubin_indirect != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Bilirubin Indirect</label> : <span>' + data.Table26[0].bilirubin_indirect + ' mg/dl </span></div>';
                              }
                              if (data.Table26[0].serum_protein_total != null && data.Table26[0].serum_protein_total != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Serum Protein -Total</label> : <span>' + data.Table26[0].serum_protein_total + ' g/dl </span></div>';
                              }
                              if (data.Table26[0].serum_protein_albumin != null && data.Table26[0].serum_protein_albumin != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Serum Protein - Albumin</label> : <span>' + data.Table26[0].serum_protein_albumin + ' g/dl</span></div>';
                              }
                              if (data.Table26[0].serumproteinglibulin != null && data.Table26[0].serumproteinglibulin != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Serum Protein - Glibulin</label> : <span>' + data.Table26[0].serumproteinglibulin + ' g/dl </span></div>';
                              }
                              if (data.Table26[0].SGOT != null && data.Table26[0].SGOT != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">SGOT (AST)</label> : <span>' + data.Table26[0].SGOT + ' IU/l </span></div>';
                              }
                              if (data.Table26[0].SGPT != null && data.Table26[0].SGPT != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">SGPT (AST)</label> : <span>' + data.Table26[0].SGPT + ' IU/l </span></div>';
                              }
                              if (data.Table26[0].serum_alkaline_phosphatase != null && data.Table26[0].serum_alkaline_phosphatase != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Serum Alkaline Phosphatase</label> : <span>' + data.Table26[0].serum_alkaline_phosphatase + ' IU/l </span></div>';
                              }
                              if (data.Table26[0].gamma_glutamyl_transpeptidase != null && data.Table26[0].gamma_glutamyl_transpeptidase != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Serum Alkaline Phosphatase</label> : <span>' + data.Table26[0].gamma_glutamyl_transpeptidase + ' IU/l </span></div>';
                              }
                              if (data.Table26[0].serum_magnesium != null && data.Table26[0].serum_magnesium != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Gamma Glutamyl Transpeptidase (GGT)</label> : <span>' + data.Table26[0].serum_magnesium + ' IU/l </span></div>';
                              }

                          }

                          //cbc and urine routine
                          if (data.Table29.length > 0) {
                              if (data.Table29[0].visit_report_id != null) {
                                  div = div + '<div class="col-md-12"><h5><b>CBC</b></h5></div>';
                              }
                          }

                          if (data.Table29.length > 0) {
                              for (var i = 0; i < data.Table29.length; i++) {
                                  if (data.Table29[0].hemoglobin != null && data.Table29[0].hemoglobin != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">HEMOGLOBIN</label> : <span>' + data.Table29[0].hemoglobin + " " + ((data.Table29[0].hemoglobin_unit == null || data.Table29[0].hemoglobin_unit == "") ? "" : data.Table29[0].hemoglobin_unit) + ' </span></div>';
                                  }
                                  if (data.Table29[0].platelet_count != null && data.Table29[0].platelet_count != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">PLATELET COUNT</label> : <span>' + data.Table29[0].platelet_count + " " + ((data.Table29[0].platelet_count_unit == null || data.Table29[0].platelet_count_unit == "") ? "" : data.Table29[0].platelet_count_unit) + ' </span></div>';
                                  }
                                  if (data.Table29[0].nucleated_red_blood_cells != null && data.Table29[0].nucleated_red_blood_cells != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">NUCLEATED RED BLOOD CELLS</label> : <span>' + data.Table29[0].nucleated_red_blood_cells + ' </span></div>';
                                  }
                                  if (data.Table29[0].nucleated_red_blood_cells_percent != null && data.Table29[0].nucleated_red_blood_cells_percent != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">NUCLEATED RED BLOOD CELLS %</label> : <span>' + data.Table29[0].nucleated_red_blood_cells_percent + ' </span></div>';
                                  }
                                  if (data.Table29[0].hematocrit != null && data.Table29[0].hematocrit != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">HEMATOCRIT(PCV)</label> : <span>' + data.Table29[0].hematocrit + ' </span></div>';
                                  }
                                  if (data.Table29[0].lymphocyte_percent != null && data.Table29[0].lymphocyte_percent != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">LYMPHOCYTE PERCENTAGE</label> : <span>' + data.Table29[0].lymphocyte_percent + ' </span></div>';
                                  }
                                  if (data.Table29[0].total_leucocytes_count != null && data.Table29[0].total_leucocytes_count != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">TOTAL LEUCOCYTES COUNT</label> : <span>' + data.Table29[0].total_leucocytes_count + ' </span></div>';
                                  }
                                  if (data.Table29[0].mean_corpuscular_hemoglobin != null && data.Table29[0].mean_corpuscular_hemoglobin != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">MEAN CORPUSCULAR HEMOGLOBIN(MCH)</label> : <span>' + data.Table29[0].mean_corpuscular_hemoglobin + ' </span></div>';
                                  }
                                  if (data.Table29[0].mean_corp_hemo_conc != null && data.Table29[0].mean_corp_hemo_conc != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">MEAN CORP.HEMO.CONC(MCHC)</label> : <span>' + data.Table29[0].mean_corp_hemo_conc + ' </span></div>';
                                  }
                                  if (data.Table29[0].mean_corpuscular_volume != null && data.Table29[0].mean_corpuscular_volume != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">MEAN CORPUSCULAR VOLUME(MCV)</label> : <span>' + data.Table29[0].mean_corpuscular_volume + ' </span></div>';
                                  }
                                  if (data.Table29[0].monocytes != null && data.Table29[0].monocytes != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">MONOCYTES</label> : <span>' + data.Table29[0].monocytes + ' </span></div>';
                                  }
                                  if (data.Table29[0].neutrophils != null && data.Table29[0].neutrophils != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">NEUTROPHILS</label> : <span>' + data.Table29[0].neutrophils + ' </span></div>';
                                  }
                                  if (data.Table29[0].eosinophils_absolute_count != null && data.Table29[0].eosinophils_absolute_count != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">EOSINOPHILS - ABSOLUTE COUNT</label> : <span>' + data.Table29[0].eosinophils_absolute_count + ' </span></div>';
                                  }
                                  if (data.Table29[0].basophils_absolute_count != null && data.Table29[0].basophils_absolute_count != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">BASOPHILS - ABSOLUTE COUNT</label> : <span>' + data.Table29[0].basophils_absolute_count + ' </span></div>';
                                  }
                                  if (data.Table29[0].lymphocytes_absolute_count != null && data.Table29[0].lymphocytes_absolute_count != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">LYMPHOCYTES - ABSOLUTE COUNT</label> : <span>' + data.Table29[0].lymphocytes_absolute_count + ' </span></div>';
                                  }
                                  if (data.Table29[0].monocytes_absolute_count != null && data.Table29[0].monocytes_absolute_count != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">MONOCYTES - ABSOLUTE COUNT</label> : <span>' + data.Table29[0].monocytes_absolute_count + ' </span></div>';
                                  }
                                  if (data.Table29[0].neutrophils_absolute_count != null && data.Table29[0].neutrophils_absolute_count != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">NEUTROPHILS - ABSOLUTE COUNT</label> : <span>' + data.Table29[0].neutrophils_absolute_count + ' </span></div>';
                                  }
                                  if (data.Table29[0].basophils != null && data.Table29[0].basophils != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">BASOPHILS</label> : <span>' + data.Table29[0].basophils + ' </span></div>';
                                  }

                                  if (data.Table29[0].eosinophils != null && data.Table29[0].eosinophils != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">EOSINOPHILS</label> : <span>' + data.Table29[0].eosinophils + ' </span></div>';
                                  }

                                  if (data.Table29[0].immature_granulocytes != null && data.Table29[0].immature_granulocytes != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">IMMATURE GRANULOCYTES(IG)</label> : <span>' + data.Table29[0].immature_granulocytes + ' </span></div>';
                                  }
                                  if (data.Table29[0].immature_granulocytes_percent != null && data.Table29[0].immature_granulocytes_percent != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">IMMATURE GRANULOCYTE PERCENTAGE(IG%)</label> : <span>' + data.Table29[0].immature_granulocytes_percent + ' </span></div>';
                                  }
                                  if (data.Table29[0].total_rbc != null && data.Table29[0].total_rbc != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">TOTAL RBC</label> : <span>' + data.Table29[0].total_rbc + ' </span></div>';
                                  }
                                  if (data.Table29[0].redcell_distribution_width != null && data.Table29[0].redcell_distribution_width != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">RED CELL DISTRIBUTION WIDTH (RDW-CV)</label> : <span>' + data.Table29[0].redcell_distribution_width + ' </span></div>';
                                  }
                                  if (data.Table29[0].redcell_distribution_width_sd != null && data.Table29[0].redcell_distribution_width_sd != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">RED CELL DISTRIBUTION WIDTH - SD(RDW-SD)</label> : <span>' + data.Table29[0].redcell_distribution_width_sd + ' </span></div>';
                                  }
                              }
                          }

                          if (data.Table30.length > 0) {
                              if (data.Table30[0].visit_report_id != null) {
                                  div = div + '<div class="col-md-12"><h5><b>Urine Routine</b></h5></div>';
                              }
                          }
                          if (data.Table30.length > 0) {
                              for (var i = 0; i < data.Table30.length; i++) {
                                  if (data.Table30[0].specific_gravity != null && data.Table30[0].specific_gravity != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">SPECIFIC GRAVITY</label> : <span>' + data.Table30[0].specific_gravity + " " + ((data.Table30[0].specific_gravity_unit == null || data.Table30[0].specific_gravity_unit == "") ? "" : data.Table30[0].specific_gravity_unit) + ' </span></div>';
                                  }
                                  if (data.Table30[0].urinary_bilirubin != null && data.Table30[0].urinary_bilirubin != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">URINARY BILIRUBIN</label> : <span>' + data.Table30[0].urinary_bilirubin + " " + ((data.Table30[0].urinary_bilirubin_unit == null || data.Table30[0].urinary_bilirubin_unit == "") ? "" : data.Table30[0].urinary_bilirubin_unit) + ' </span></div>';
                                  }
                                  if (data.Table30[0].urine_blood != null && data.Table30[0].urine_blood != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">URINE BLOOD</label> : <span>' + data.Table30[0].urine_blood + ' </span></div>';
                                  }
                                  if (data.Table30[0].urobilinogen != null && data.Table30[0].urobilinogen != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">UROBILINOGEN</label> : <span>' + data.Table30[0].urobilinogen + " " + ((data.Table30[0].urobilinogen_unit == null || data.Table30[0].urobilinogen_unit == "") ? "" : data.Table30[0].urobilinogen_unit) + ' </span></div>';
                                  }
                                  if (data.Table30[0].urinary_glucose != null && data.Table30[0].urinary_glucose != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">URINARY GLUCOSE</label> : <span>' + data.Table30[0].urinary_glucose + ' </span></div>';
                                  }
                                  if (data.Table30[0].urine_ketone != null && data.Table30[0].urine_ketone != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">URINE KETONE</label> : <span>' + data.Table30[0].urine_ketone + " " + ((data.Table30[0].urine_ketone_unit == null || data.Table30[0].urine_ketone_unit == "") ? "" : data.Table30[0].urine_ketone_unit) + ' </span></div>';
                                  }
                                  if (data.Table30[0].urinary_leucocytes != null && data.Table30[0].urinary_leucocytes != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">URINARY LEUCOCYTES</label> : <span>' + data.Table30[0].urinary_leucocytes + ' </span></div>';
                                  }
                                  if (data.Table30[0].nitrite != null && data.Table30[0].nitrite != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">NITRITE</label> : <span>' + data.Table30[0].nitrite + " " + ((data.Table30[0].nitrite_unit == null || data.Table30[0].nitrite_unit == "") ? "" : data.Table30[0].nitrite_unit) + ' </span></div>';
                                  }
                                  if (data.Table30[0].ph != null && data.Table30[0].ph != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">PH</label> : <span>' + data.Table30[0].ph + ' </span></div>';
                                  }
                                  if (data.Table30[0].urinary_protein != null && data.Table30[0].urinary_protein != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">URINARY PROTEIN</label> : <span>' + data.Table30[0].urinary_protein + ' </span></div>';
                                  }
                              }
                          }

                          if (data.Table25.length > 0) {
                              for (var i = 0; i < data.Table25.length; i++) {
                                  if (data.Table25[i].parameter_value != null && data.Table25[i].parameter_value != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">' + data.Table25[i].parameter_name + '</label> : <span>' + data.Table25[i].parameter_value + " " + data.Table25[i].unit + '</span></div>';
                                  }
                              }
                          }

                          if (data.Table27.length > 0) {
                              if (data.Table27[0].master_labtest_visit_report_id != null) {
                                  div = div + '<div class="col-md-12"><h5><b>Master Lab Test</b></h5></div>';
                              }
                          }


                          if (data.Table27.length > 0) {
                              for (var i = 0; i < data.Table27.length; i++) {
                                  if (data.Table27[0].parameter_name != null && data.Table27[0].parameter_name != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">' + data.Table27[i].parameter_name + '</label> : <span>' + data.Table27[i].parameter_value + '  ' + data.Table27[i].reference_value + ' ' + data.Table27[i].unit + '</span></div>';
                                  }
                              }
                          }
                          //Dynamic Binding
                          var divtr = ''

                          if (data.Table43.length > 0) {
                              // EXTRACT VALUE FOR HTML HEADER.
                              var col = [];
                              for (var i = 0; i < data.Table43.length; i++) {
                                  for (var key in data.Table43[i]) {
                                      if (col.indexOf(key) === -1 && key !== "formid") {
                                          col.push(key);
                                      }
                                  }
                              }

                              // Add an "Actions" column to the headers.
                              col.push("Actions");

                              // CREATE HTML TABLE MARKUP.
                              var tableHTML = '<table id="DynamicTable_' + i + '" class="table table-bordered table-striped no-footer dataTable">';

                              // CREATE HTML TABLE HEADER ROW USING THE EXTRACTED HEADERS ABOVE.
                              tableHTML += '<thead><tr>';
                              for (var i = 0; i < col.length; i++) {
                                  tableHTML += '<th>' + col[i] + '</th>';
                              }
                              tableHTML += '</tr></thead>';

                              // ADD JSON DATA TO THE TABLE AS ROWS.
                              tableHTML += '<tbody>';
                              for (var i = 0; i < data.Table43.length; i++) {
                                  tableHTML += '<tr>';
                                  for (var j = 0; j < col.length; j++) {
                                      if (col[j] === "Actions") {
                                          // Add "Edit" and "Delete" actions to the Actions column.
                                          var print = '<a  data-toggle="tooltip" title="Print"  id="" class="btn btn-edit btn-xs"  data-id="" data-type="role_rights_function" data-nav="sp_div" data-name="c_details_form"  href="javascript:void(0);" onclick= formprint("' + data.Table43[i].formid + '")><i class="fa fa-print printcolor" aria-hidden="true"></i></a>';
                                          tableHTML += '<td>' + print + '</td>';
                                      } else {
                                          tableHTML += '<td>' + data.Table43[i][col[j]] + '</td>';
                                      }
                                  }
                                  tableHTML += '</tr>';
                              }
                              tableHTML += '</tbody></table>';

                              // UPDATE THE CONTAINER WITH THE NEWLY CREATED TABLE HTML.
                              //var divContainer = document.getElementById("ShowDataTable");
                              //divContainer.innerHTML = tableHTML;

                              // APPEND TO THE VARIABLE div
                              div = div + tableHTML;
                          }



                          $('#tbl_patient_summary_details_' + data.Table18[0].visit_report_id).html('');
                          $('#tbl_patient_summary_details_' + data.Table18[0].visit_report_id).html(div);

                          if (data.Table21.length > 0) {
                              tr = '';
                              for (var i = 0; i < data.Table21.length; i++) {
                                  var session = '';
                                  visit_report_id = data.Table21[i].visit_report_id;
                                  if (data.Table21[i].evening == 1) {
                                      session = data.Table21[i].morning + ' - ' + data.Table21[i].afternoon + ' - ' + data.Table21[i].evening + ' - ' + data.Table21[i].night;
                                  }
                                  else {
                                      session = data.Table21[i].morning + ' - ' + data.Table21[i].afternoon + ' - ' + data.Table21[i].night;
                                  }
                                  var color = '';
                                  if (data.Table21[i].priority == 1) {
                                      color = '<i class=" fa fa-circle" style="color:green"></i>&nbsp;';
                                  }
                                  else if (data.Table21[i].priority == 2) {
                                      color = '<i class=" fa fa-circle" style="color:orange"></i>&nbsp;';
                                  }
                                  else if (data.Table21[i].priority == 3) {
                                      color = '<i class=" fa fa-circle" style="color:#418bfe"></i>&nbsp;';
                                  }
                                  else {
                                      color = '<i class=" fa fa-circle" style="color:#ffffff"></i>&nbsp;';
                                  }
                                  var instructions = '';
                                  if (data.Table21[i].instructions == '' || data.Table21[i].instructions == null) {
                                      instructions = '';
                                  }
                                  else {
                                      instructions = data.Table21[i].instructions;
                                  }
                                  if (data.Table21[i].days_to_take == '' || data.Table21[i].days_to_take == null) {
                                      days_to_take = '';
                                  }
                                  else if (data.Table21[i].days_to_take == '9999') {
                                      days_to_take = 'Daily';
                                  }
                                  else {
                                      days_to_take = data.Table21[i].days_to_take;
                                  }
                                  var generic_name = '';
                                  if (data.Table21[i].generic_name == '' || data.Table21[i].generic_name == null) {
                                      generic_name = '';
                                  }
                                  else {
                                      generic_name = '<span style=font-size:11px;><i>(' + data.Table21[i].generic_name + ')</i></span>';
                                  }

                                  //tr = tr + '<div class="col-md-12 presc_table_row"><div class="col-md-4"><span style="text-transform:capitalize;">' + data[i].medicine_name + '</div><div class="col-md-2 red">' + data[i].medicine_type + '</div><div class="col-md-2 red">' + data[i].when_to_eat_value + '</div><div class="col-md-3"> &nbsp; ' + data[i].morning + ' &nbsp;&nbsp;&nbsp;&nbsp; - &nbsp;&nbsp;&nbsp;&nbsp; ' + data[i].afternoon + '&nbsp;&nbsp;&nbsp;&nbsp; - &nbsp;&nbsp;&nbsp;&nbsp; ' + data[i].evening + ' &nbsp;&nbsp;&nbsp;&nbsp; - &nbsp;&nbsp;&nbsp;&nbsp; ' + data[i].night + ' &nbsp;&nbsp;&nbsp;&nbsp;</div><div class="col-md-1 red">' + data[i].days_to_take + '</div><div class="clearfix"></div></div>';
                                  tr = tr + '<tr><td>' + data.Table21[i].medicine_type + '</td><td style="text-transform:capitalize;">' + color + data.Table21[i].medicine_name + generic_name + '</td><td>' + data.Table21[i].when_to_eat_value + '</td><td>' + days_to_take + '</td><td>' + instructions + '</td><td>' + session + '</td></tr>';
                              }

                              var pdf = '<a href="javascript:void(0);" class="pull-right btn_cpy_prescription" onclick=printPrescription("' + visit_report_id + '")><i class="fa fa-clipboard " aria-hidden="true"></i> Print </a>'
                              var table = '<div class="table-responsive"><table class="table table-condensed body-borderless table_borderless">';
                              var tableend = '</table></div>';
                              var headTable = '<thead style="background: grey;"><tr><th>Type</th><th>Medicine & Generic</th><th>When to take</th><th>Duration(Days)</th><th>Notes</th><th>Frequency</th></tr></thead>';

                              $('#tbl-medicine_' + visit_report_id).html('');
                              $('#tbl-medicine_' + visit_report_id).append(table + headTable + tr + tableend);
                              //$('.prescription_print').html(pdf);
                          }
                          else {
                              $('#Prescription_div_' + data.Table18[0].visit_report_id).hide();
                          }


                          if (data.Table22.length > 0) {
                              j = 0;
                              var labtr = '';
                              var SuggestedDate = '';
                              var thead = '<table class="table table-condensed table_bordered"><th>S.No</th><th>Service Name</th><th>Service Code</th><th>Quantity</th><th>Date</th><th>Action</th>';
                              var theadend = '</table>';


                              for (var i = 0; i < data.Table22.length; i++) {
                                  var action = "-";
                                  var payment = '';
                                  if (data.Table22[i].is_lab == 1 || data.Table22[i].is_appointment == 1) {
                                      var lab_document = '';
                                      //if (data.Table22[i].document_path != null && data.Table22[i].document_path != "") {
                                      //    lab_document = '<a href="' + $('#hdngetlabfilepath').val() + $('#HdnHospitalid').val() + "/" + $('#HBranchID').val() + "/Lab_Documents/" + data.Table22[i].document_path + '" target="_blank" style="margin-right: 10px;">View Lab Document</a>';
                                      //}
                                      if (data.Table22[i].document_path != null && data.Table22[i].document_path != "") {
                                          var str = data.Table22[i].document_path;
                                          var temp = new Array();
                                          temp = str.split(",");
                                          var strarray = str.split(',');
                                          for (var k = 0; k < strarray.length; k++) {
                                              lab_document = lab_document + '<a href="' + $('#hdngetlabfilepath').val() + $('#HdnHospitalid').val() + "/" + $('#HBranchID').val() + "/Lab_Documents/" + strarray[k] + '" target="_blank" style="margin-right: 10px;">Lab Document ' + (k + 1) + '</a>' + "/";
                                          }
                                      }
                                      action = ((data.Table22[i].flag == 3 || data.Table22[i].flag == 4) || (data.Table22[i].aflag == 3 || data.Table22[i].aflag == 4)) ? lab_document + '<button type="button" class="btn btn-primaryuse btn-xs mr-5" style="margin-right: 10px;" onclick=jobprint("' + data.Table22[i].work_order_id + '","' + data.Table22[i].hospitalid + '","' + data.Table22[i].patientid + '","' + data.Table22[i].branchid + '","' + data.Table22[i].master_service_id + '","' + data.Table22[i].barcodeid + '")><i class="fa fa fa-print" aria-hidden="true"></i></button>' : (data.Table22[i].flag == 2) ? lab_document + " Result Pending" : "Result Pending";
                                      payment = (data.Table22[i].is_bill == 1 || data.Table22[i].is_bill == "1") ? '<a><span class="label label-success" style="background-color: green !important;">PAID</span></a>' : '<a><span class="label label-danger">PENDING</span></a>';
                                  }

                                  labtr = labtr + '<tr><td>' + (i + 1) + '</td><td>' + payment + data.Table22[i].service_name + '</td><td>' + data.Table22[i].service_code + '</td><td>' + data.Table22[i].quantity + '</td><td>' + data.Table22[i].service_date + '</td><td>' + action + '</td></tr>';
                              }


                              $('#Lab-table_' + data.Table22[0].visit_report_id).html('');
                              $('#Lab-table_' + data.Table22[0].visit_report_id).append(thead + labtr + theadend);
                              $('#lab_div_' + data.Table18[0].visit_report_id).show();

                          }
                          else {
                              $('#lab_div_' + data.Table18[0].visit_report_id).hide();
                          }

                          if (data.Table31.length > 0) { //Exercise Summary
                              var exercisetable = '<>'
                              var tr = '';
                              for (var i = 0; i < data.Table31.length; i++) {

                                  var monday = data.Table31[i].monday_flag;
                                  var tuesday = data.Table31[i].tuesday_flag;
                                  var wednesday = data.Table31[i].wednesday_flag;
                                  var thusday = data.Table31[i].thursday_flag;
                                  var friday = data.Table31[i].friday_flag;
                                  var saturday = data.Table31[i].saturday_flag;
                                  var sunday = data.Table31[i].sunday_flag;

                                  var SuggestedDays = ''; var suggestedDaysCount = 0;
                                  if (monday == 1) {

                                      SuggestedDays = 'Mon';
                                      suggestedDaysCount = suggestedDaysCount + 1;
                                  }
                                  if (tuesday == 1) {
                                      if (SuggestedDays == '') {
                                          SuggestedDays = '  Tue';
                                      }
                                      else {
                                          SuggestedDays = SuggestedDays + ',  Tue';
                                      }
                                      suggestedDaysCount = suggestedDaysCount + 1;
                                  }
                                  if (wednesday == 1) {
                                      if (SuggestedDays == '') {
                                          SuggestedDays = '  Wed';
                                      }
                                      else {
                                          SuggestedDays = SuggestedDays + ',  Wed';
                                      }
                                      suggestedDaysCount = suggestedDaysCount + 1;
                                  }
                                  if (thusday == 1) {
                                      if (SuggestedDays == '') {
                                          SuggestedDays = '  Thu';
                                      }
                                      else {
                                          SuggestedDays = SuggestedDays + ',  Thu';
                                      }
                                      suggestedDaysCount = suggestedDaysCount + 1;
                                  }
                                  if (friday == 1) {
                                      if (SuggestedDays == '') {
                                          SuggestedDays = '  Fri';
                                      }
                                      else {
                                          SuggestedDays = SuggestedDays + ',  Fri';
                                      }
                                      suggestedDaysCount = suggestedDaysCount + 1;
                                  }
                                  if (saturday == 1) {
                                      if (SuggestedDays == '') {
                                          SuggestedDays = '  Sat';
                                      }
                                      else {
                                          SuggestedDays = SuggestedDays + ',  Sat';
                                      }
                                      suggestedDaysCount = suggestedDaysCount + 1;
                                  }
                                  if (sunday == 1) {
                                      if (SuggestedDays == '') {
                                          SuggestedDays = '  Sun';
                                      }
                                      else {
                                          SuggestedDays = SuggestedDays + '  Sun';
                                      }
                                      suggestedDaysCount = suggestedDaysCount + 1;
                                  }
                                  var treatment_description = [];
                                  var t = data.Table31[i].treatment.split(",");
                                  var j = 0;
                                  for (var k = 0; k < t.length; k++) {
                                      if (t[k] == 1) {
                                          treatment_description[j] = "IFT"
                                      }
                                      else if (t[k] == 2) {
                                          treatment_description[j] = "UST"
                                      }
                                      else if (t[k] == 3) {
                                          treatment_description[j] = "CCT"
                                      }
                                      else if (t[k] == 4) {
                                          treatment_description[j] = "WAX"
                                      }
                                      else if (t[k] == 5) {
                                          treatment_description[j] = "ES"
                                      }
                                      else if (t[k] == 6) {
                                          treatment_description[j] = "LASER"
                                      }
                                      else if (t[k] == 7) {
                                          treatment_description[j] = "ICT"
                                      }
                                      else if (t[k] == 8) {
                                          treatment_description[j] = "IPT"
                                      }
                                      else if (t[k] == 9) {
                                          treatment_description[j] = "CPM"
                                      }
                                      else if (t[k] == 10) {
                                          treatment_description[j] = "CPT"
                                      }
                                      else {

                                      }
                                      j++;
                                  }
                                  var treatment_description_1 = treatment_description.toString();

                                  var choose_region_desc = [];
                                  if (data.Table31[i].choose_region != null && data.Table31[i].choose_region != "") {
                                      var r = data.Table31[i].choose_region.split(",");
                                      var p = 0;
                                      for (var k = 0; k < r.length; k++) {
                                          if (r[k] == 1) {
                                              choose_region_desc[p] = "SHOULDER REHAB"
                                          }
                                          else if (r[k] == 2) {
                                              choose_region_desc[p] = "ELBOW REHAB"
                                          }
                                          else if (r[k] == 3) {
                                              choose_region_desc[p] = "WRIST & HAND REHAB"
                                          }
                                          else if (r[k] == 4) {
                                              choose_region_desc[p] = "SPINE REHAB"
                                          }
                                          else if (r[k] == 5) {
                                              choose_region_desc[p] = "PELVIC & CORE REHAB"
                                          }
                                          else if (r[k] == 6) {
                                              choose_region_desc[p] = "HIP REHAB"
                                          }
                                          else if (r[k] == 7) {
                                              choose_region_desc[p] = "KNEE REHAB"
                                          }
                                          else if (r[k] == 8) {
                                              choose_region_desc[p] = "ANKLE & FOOT REHAB"
                                          }
                                          else if (r[k] == 9) {
                                              choose_region_desc[p] = "LIBERATORY MANEUVER"
                                          }
                                          else {

                                          }
                                          p++;

                                      }
                                  }
                                  var choose_region_1 = choose_region_desc.toString();


                                  tr = tr + "<tr><td>" + choose_region_1 + "</td><td>" + data.Table31[i].op_type + "</td><td>" + data.Table31[i].excercise_description + "</td><td>" + SuggestedDays + "</td><td>" + data.Table31[i].days_to_take + "</td><td>" + data.Table31[i].excercise_duration_per_day + "</td><td>" + data.Table31[i].sitting + "</td><td>" + data.Table31[i].instruction + "</td><td>" + treatment_description_1 + "</td></tr>";
                              }
                              var table = '<div class="table-responsive"><table class="table table-condensed body-borderless table_borderless">';
                              var tableend = '</table></div>';
                              var headTable = '<thead style="background: grey;"><tr><th>Region</th><th>Pre/Post OP</th><th>Type of Exercise</th><th>Suggested Days</th><th>Number of Days</th><th>Duration</th><th>Sitting</th><th>Exercise Instruction</th><th>Treatment</th></tr></thead>';

                              $('#Exercise-table_' + data.Table18[0].visit_report_id).html('');
                              $('#Exercise-table_' + data.Table18[0].visit_report_id).append(table + headTable + tr + tableend);
                          }
                          else {
                              $('#exercise_div_' + data.Table18[0].visit_report_id).hide();
                          }
                          //diet summary
                          if (data.Table33.length > 0) {
                              var tr = "";
                              for (var i = 0; i < data.Table33.length; i++) {
                                  j++;
                                  tr = tr + "<tr><td>" + data.Table33[i].time + "</td>";
                                  tr = tr + " <td>" + data.Table33[i].type_of_food + "</td>";
                                  tr = tr + " <td>" + data.Table33[i].no_of_servings + ' Per day' + "</td>";
                                  tr = tr + " <td>" + data.Table33[i].instructions + "</td>";
                                  tr = tr + "</tr>";

                              }
                              var dietplan = '<div><p>Plan Duration: <span>' + ((data.Table33[0].diet_goal_duration == null) ? '-' : data.Table33[0].diet_goal_duration + ' days') + '</span></p></div><div><p>Suggested Kcal Intake: <span>' + data.Table33[0].kcal + '</span></p></div>';
                              var table = '<div class="table-responsive"><table class="table table-condensed body-borderless table_borderless">';
                              var tableend = '</table></div>';
                              var headTable = '<thead style="background: grey;"><tr><th>Time</th><th>Food</th><th>Serving</th><th>Instruction</th></tr></thead>';

                              $('#Diet_table_' + data.Table18[0].visit_report_id).html('');
                              $('#Diet_table_' + data.Table18[0].visit_report_id).append(dietplan);
                              $('#Diet_table_' + data.Table18[0].visit_report_id).append(table + headTable + tr + tableend);
                          }
                          else {
                              $('#diet_div_' + data.Table18[0].visit_report_id).hide();
                          }

                          //observed nutrition

                          if (data.Table34.length > 0) {

                              var tr = '';
                              for (var i = 0; i < data.Table34.length; i++) {
                                  j++;
                                  tr = tr + "<tr><td>" + data.Table34[i].type + "</td><td>" + data.Table34[i].type_name + "</td></tr>";

                              }

                              var table = '<div class="table-responsive"><table class="table table-condensed body-borderless table_borderless">';
                              var tableend = '</table></div>';
                              var headTable = '<thead style="background: grey;"><tr><th>Type</th><th>Observed Value</th></tr></thead>';

                              $('#observed_nutrition_table_' + data.Table18[0].visit_report_id).html('');
                              $('#observed_nutrition_table_' + data.Table18[0].visit_report_id).append(table + headTable + tr + tableend);
                          }
                          else {
                              $('#observed_nutrition_div_' + data.Table18[0].visit_report_id).hide();
                          }

                          //future services
                          if (data.Table35.length > 0) {

                              var tr = '';
                              for (var i = 0; i < data.Table35.length; i++) {
                                  j++;
                                  if (data.Table35[i].base_amount_type == 4) {
                                      var date_time = data.Table35[i].service_date + " " + data.Table35[i].service_time + " - " + data.Table35[i].service_end_date + " " + data.Table35[i].service_end_time;
                                      tr = tr + '<tr><td>' + (i + 1) + '</td><td>' + data.Table35[i].service_name + '</td><td>' + data.Table35[i].service_code + '</td><td>' + data.Table35[i].quantity + '</td><td>' + date_time + '</td><td>' + ((data.Table35[i].remarks == '') ? '-' : data.Table35[i].remarks) + '</td></tr>'
                                  }
                                  else {
                                      var date_time = data.Table35[i].service_date + " " + data.Table35[i].service_time;
                                      tr = tr + '<tr><td>' + (i + 1) + '</td><td>' + data.Table35[i].service_name + '</td><td>' + data.Table35[i].service_code + '</td><td>' + data.Table35[i].quantity + '</td><td>' + date_time + '</td><td>' + ((data.Table35[i].remarks == '') ? '-' : data.Table35[i].remarks) + '</td></tr>'
                                  }

                              }

                              var table = '<div class="table-responsive"><table class="table table-condensed body-borderless table_borderless">';
                              var tableend = '</table></div>';
                              var headTable = '<thead style="background: grey;"><tr><th>S.NO</th><th>Service Name</th><th>Service Code</th><th>Quantity</th><th>Date & Time</th><th>Description</th></tr></thead>';

                              $('#future_services_table_' + data.Table18[0].visit_report_id).html('');
                              $('#future_services_table_' + data.Table18[0].visit_report_id).append(table + headTable + tr + tableend);
                          }
                          else {
                              $('#future_services_div_' + data.Table18[0].visit_report_id).hide();
                          }

                          if (data.Table23.length > 0) {
                              var imgtr = '';
                              for (var i = 0; i < data.Table23.length; i++) {
                                  var img = '';
                                  if (data.Table23[i].patient_lab_record_path == '' || data.Table23[i].patient_lab_record_path == null) {
                                      img = '-';
                                  }
                                  else {
                                      if (data.Table23[i].record_type == 3) {
                                          img = '<img src=' + $("#hdngetlabfilepath").val() + data.Table23[i].doctor_id + "/PrescriptionWritingPad/" + data.Table23[i].patient_lab_record_path + ' class="img-responsive" style="height: 50px;width: 50px;">';
                                          img = '<a href="' + $('#hdngetlabfilepath').val() + data.Table23[i].doctor_id + "/PrescriptionWritingPad/" + data.Table23[i].patient_lab_record_path + '" target="_blank">' + img + '</a>'
                                      }
                                      else {
                                          img = '<img src=' + $("#hdngetlabfilepath").val() + data.Table23[i].patient_lab_record_path + ' class="img-responsive" style="height: 50px;width: 50px;">';
                                          img = '<a href="' + $('#hdngetlabfilepath').val() + data.Table23[i].patient_lab_record_path + '" target="_blank">' + img + '</a>'
                                      }
                                      }
                                  debugger;
                                  imgtr = imgtr + '<div class="col-xs-3">' + img + '<br/><span style="text-transform:capitalize;">' + ((data.Table23[i].patient_testname != '' && data.Table23[i].patient_testname != null) ? data.Table23[i].patient_testname : 'No file name') + '</span></div>';
                              }
                              $('#tbl-fileupload_' + data.Table23[0].visit_report_id).html('');
                              $('#tbl-fileupload_' + data.Table23[0].visit_report_id).append(imgtr);
                          }
                          else {
                              $('#file_div_' + data.Table18[0].visit_report_id).hide();
                          }

                          if (data.Table24.length > 0) {
                              if (data.Table24[0].NextAppointment != '' && data.Table24[0].NextAppointment != null) {
                                  $('#lblNextApp_' + data.Table24[0].visit_report_id).html(data.Table24[0].NextAppointment);
                              }
                              else {
                                  $('#divNextApp_' + data.Table18[0].visit_report_id).hide();
                              }

                              if (data.Table24[0].next_appointment_notes != '' && data.Table24[0].next_appointment_notes != null) {
                                  $('#lblNextAppNotes_' + data.Table24[0].visit_report_id).html(data.Table24[0].next_appointment_notes);
                              }
                              else {
                                  $('#divNextAppNotes_' + data.Table18[0].visit_report_id).hide();
                              }

                              if ((data.Table24[0].NextAppointment == '' || data.Table24[0].NextAppointment == null) && (data.Table24[0].next_appointment_notes == '' || data.Table24[0].next_appointment_notes == null)) {
                                  $('#next_div_' + data.Table18[0].visit_report_id).hide();
                              }
                          }
                          else {
                              $('#next_div_' + data.Table18[0].visit_report_id).hide();
                          }

                          $('#summary_div_' + visitReportId).removeClass('us-db-case-loader');
                      }
                      else {
                          $('.tbl_patient_summary_details').html('');
                          $('#summary_div_' + visitReportId).removeClass('us-db-case-loader');
                      }
                  }
              }
              else {
                  console.log(data);
              }
          }
      });
  }


  function load_patient_summary_visit_report() {
      debugger;
      //$('.patient_summary_details_').show();
      var MedicinePrescriptiondate = {
          visit_report_id: $('#VisitReportID').val(),
          patient_id: $('#Hdnpatient_id').val(),
          doctor_id: $('#doctorId').val(),
          type: "1"
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/caseStudy/Patient_Summary_details',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(MedicinePrescriptiondate),
          success: function (data) {

              var data = JSON.parse(data);
              console.log(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  $('.tbl_patient_summary_details').html();
                  if (jQuery.isEmptyObject((data))) {

                  }
                  else {
                      debugger;
                      if (Object.keys(data).length > 2) {
                          console.log(data);
                          var div = "", divtr = '';
                          var j = 1;
                          //loadvisit_selection
                          //if (data.Table20.length > 0) {
                          //    for (var i = 0; i < data.Table20.length; i++) {
                          //        var expanded_status = 'false', expanded_in = '';
                          //        if (i < 1) {
                          //            expanded_status = 'True';
                          //            expanded_in = 'in';
                          //        }
                          //        divtr = divtr + '<div class="panel panel-primary" onclick=patient_summary_visit_report("' + data.Table20[i].visit_report_id + '")><div class="panel-heading clearfix" role="button" data-toggle="collapse" data-parent="#accordion" href="#PatientVisitSummary-section' + data.Table20[i].visit_report_id + '" aria-expanded="' + expanded_status + '" aria-controls="PatientVisitSummary-section' + data.Table20[i].visit_report_id + '"><i class="icon-calendar"></i>'
                          //        divtr = divtr + '<h3 class="panel-title"><span class="pull-left">' + data.Table20[i].visit_date + '</span><span class="pull-right"><a href="javascript:void(0);" onclick=printpdf("' + data.Table20[i].visit_report_id + '")><i class="fa fa-print "></i> print </a>&nbsp;&nbsp;&nbsp;&nbsp;<i class="fa fa-angle-double-down"></i></span></h3></div><div id="PatientVisitSummary-section' + data.Table20[i].visit_report_id + '" class="panel-collapse collapse ' + expanded_in + '" role="tabpanel" aria-labelledby="headingOne">'
                          //        divtr = divtr + '<div class="panel-body"><div class="us-db-case-loader" id="summary_div_' + data.Table20[i].visit_report_id + '"><div style="padding:0px;" class="col-md-12" id="summarydiv_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock">Summary</div><div class="col-md-12" id="tbl_patient_summary_details_' + data.Table20[i].visit_report_id + '"></div></div>'
                          //        divtr = divtr + '<div id="Prescription_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock"><h5><b>Prescription</b></h5></div><div class="presc_table_block"><div id="tbl-medicine_' + data.Table20[i].visit_report_id + '"></div></div></div>'
                          //        divtr = divtr + '<div id="lab_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock"><h5><b>lab Tests</b></h5></div><div class=""><div id="Lab-table_' + data.Table20[i].visit_report_id + '" ></div></div></div>'
                          //        divtr = divtr + '<div id="exercise_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock"><h5><b>Exercise/Physiotherapy</b></h5></div><div class=""><div id="Exercise-table_' + data.Table20[i].visit_report_id + '" ></div></div></div>'
                          //        divtr = divtr + '<div id="file_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock"><h5><b>Files</b></h5></div><div class="col-xs-12 presc_table_block" id="tbl-fileupload_' + data.Table20[i].visit_report_id + '"></div></div>'
                          //        divtr = divtr + '<div id="next_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock"><h5><b>Next Appointment</b></h5></div><div class="col-md-6 padding0 "><div class="col-md-6 disp_table_cell"><div class="form-group label_center"><label class="control-label">Next Appointment Date</label></div></div><div class="col-md-6 disp_table_cell"><div class="form-group label_center"><label class="control-label next_appoinment_date_label_1" id="lblNextApp_' + data.Table20[i].visit_report_id + '"></label></div></div></div></div></div></div></div></div>';
                          //    }
                          //    $('.loadvisit_selection').html(divtr);

                          //}
                          if (data.Table20.length > 0) {
                              for (var i = 0; i < data.Table20.length; i++) {
                                  var expanded_status = 'false', expanded_in = '';
                                  //if (i < 1) {
                                  //    expanded_status = 'True';
                                  //    expanded_in = 'in';
                                  //}
                                  divtr = divtr + '<div class="panel panel-primary" onclick=patient_summary_visit_report("' + data.Table20[i].visit_report_id + '")><div class="panel-heading clearfix" role="button" data-toggle="collapse" data-parent="#accordion" href="#PatientVisitSummary-section' + data.Table20[i].visit_report_id + '" aria-expanded="' + expanded_status + '" aria-controls="PatientVisitSummary-section' + data.Table20[i].visit_report_id + '"><i class="icon-calendar"></i>'
                                  divtr = divtr + '<h3 class="panel-title"><span class="pull-left">' + data.Table20[i].visit_date + '</span><span class="pull-right"><a href="javascript:void(0);" onclick=printpdf("' + data.Table20[i].visit_report_id + '","' + data.Table20[i].visit_reportid + '","' + data.Table20[i].patientid + '","' + data.Table20[i].hospitalid + '","' + data.Table20[i].branch_id + '")><i class="fa fa-print "></i> print </a>&nbsp;&nbsp;&nbsp;&nbsp;<i class="fa fa-angle-double-down"></i></span></h3></div><div id="PatientVisitSummary-section' + data.Table20[i].visit_report_id + '" class="panel-collapse collapse ' + expanded_in + '" role="tabpanel" aria-labelledby="headingOne">'
                                  divtr = divtr + '<div class="panel-body"><div class="us-db-case-loader" id="summary_div_' + data.Table20[i].visit_report_id + '"><div style="padding:0px;" class="col-md-12" id="summarydiv_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock">Summary</div><div class="col-md-12" id="tbl_patient_summary_details_' + data.Table20[i].visit_report_id + '"></div></div>'
                                  divtr = divtr + '<div id="Prescription_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock"><h5><b>Prescription</b></h5></div><div class="presc_table_block"><div id="tbl-medicine_' + data.Table20[i].visit_report_id + '"></div></div></div>'
                                  divtr = divtr + '<div id="lab_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock"><h5><b>Investigations</b></h5></div><div class=""><div id="Lab-table_' + data.Table20[i].visit_report_id + '" ></div></div></div>'
                                  divtr = divtr + '<div id="exercise_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock"><h5><b>Exercise/Physiotherapy</b></h5></div><div class=""><div id="Exercise-table_' + data.Table20[i].visit_report_id + '" ></div></div></div>'
                                  divtr = divtr + '<div id="diet_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock"><h5><b>Diet</b></h5></div><div class=""><div id="Diet_table_' + data.Table20[i].visit_report_id + '" ></div></div></div>'
                                  divtr = divtr + '<div id="observed_nutrition_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock"><h5><b>Observed Nutrition</b></h5></div><div class=""><div id="observed_nutrition_table_' + data.Table20[i].visit_report_id + '" ></div></div></div>'
                                  divtr = divtr + '<div id="file_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock"><h5><b>Files</b></h5></div><div class="col-xs-12 presc_table_block" id="tbl-fileupload_' + data.Table20[i].visit_report_id + '"></div></div>'
                                  divtr = divtr + '<div id="next_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock"><h5><b>Next Appointment</b></h5></div><div class="col-md-12 padding0 " id="divNextApp_' + data.Table20[i].visit_report_id + '"><div class="col-md-6 disp_table_cell"><div class="form-group label_center"><label class="control-label">Next Appointment Date</label></div></div><div class="col-md-6 disp_table_cell"><div class="form-group label_center"><label class="control-label next_appoinment_date_label_1" id="lblNextApp_' + data.Table20[i].visit_report_id + '"></label></div></div></div><div class="col-md-12 padding0 " id="divNextAppNotes_' + data.Table20[i].visit_report_id + '"><div class="col-md-6 disp_table_cell"><div class="form-group label_center"><label class="control-label">Next Appointment Notes</label> : <span id="lblNextAppNotes_' + data.Table20[i].visit_report_id + '"></span></div></div></div></div>'
                                  divtr = divtr + '<div id="future_services_div_' + data.Table20[i].visit_report_id + '"><div class="label_center summaryblock"><h5><b>Future Investigations</b></h5></div><div class=""><div id="future_services_table_' + data.Table20[i].visit_report_id + '" ></div></div></div></div></div></div></div>';
                              }                            
                              $('#cs_op_history_data').html(divtr);

                          }

                          if (data.Table32.length > 0) {
                              divtr = '';
                              for (var i = 0; i < data.Table32.length; i++) {
                                  var expanded_status = 'false', expanded_in = '';
                                  //if (i < 1) {
                                  //    expanded_status = 'True';
                                  //    expanded_in = 'in';
                                  //}
                                  divtr = divtr + '<div class="panel panel-primary" onclick=patient_summary_visit_report("' + data.Table32[i].visit_report_id + '")><div class="panel-heading clearfix" role="button" data-toggle="collapse" data-parent="#accordion" href="#PatientVisitSummary-section' + data.Table32[i].visit_report_id + '" aria-expanded="' + expanded_status + '" aria-controls="PatientVisitSummary-section' + data.Table32[i].visit_report_id + '"><i class="icon-calendar"></i>'
                                  divtr = divtr + '<h3 class="panel-title"><span class="pull-left">' + data.Table32[i].visit_date + '</span><span class="pull-right"><a href="javascript:void(0);" onclick=Discharge_report("' + data.Table32[i].branch_id + '","' + data.Table32[i].hospitalid + '","' + data.Table32[i].patientid + '","' + data.Table32[i].visit_reportid + '")><i class="fa fa-print "></i> print </a>&nbsp;&nbsp;&nbsp;&nbsp;<i class="fa fa-angle-double-down"></i></span></h3></div><div id="PatientVisitSummary-section' + data.Table32[i].visit_report_id + '" class="panel-collapse collapse ' + expanded_in + '" role="tabpanel" aria-labelledby="headingOne">'
                                  divtr = divtr + '<div class="panel-body"><div class="us-db-case-loader" id="summary_div_' + data.Table32[i].visit_report_id + '"><div style="padding:0px;" class="col-md-12" id="summarydiv_' + data.Table32[i].visit_report_id + '"><div class="label_center summaryblock">Summary</div><div class="col-md-12" id="tbl_patient_summary_details_' + data.Table32[i].visit_report_id + '"></div></div>'
                                  divtr = divtr + '<div id="Prescription_div_' + data.Table32[i].visit_report_id + '"><div class="label_center summaryblock"><h5><b>Prescription</b></h5></div><div class="presc_table_block"><div id="tbl-medicine_' + data.Table32[i].visit_report_id + '"></div></div></div>'
                                  divtr = divtr + '<div id="lab_div_' + data.Table32[i].visit_report_id + '"><div class="label_center summaryblock"><h5><b>Investigations</b></h5></div><div class=""><div id="Lab-table_' + data.Table32[i].visit_report_id + '" ></div></div></div>'
                                
                                  divtr = divtr + '</div></div></div></div>';
                              }
                              $('#cs_ip_history').html(divtr);                             

                          }
                          else {
                              $('#cs_ip_history').html('<div class="img-center"><img src="/Content/img/no_record.png" class="img-resposive no_record_img" style="height: 200px;width: 500px;" ><br><div class="no_data_content">No data found.</div></div>');
                          }


                          div = div + '<div class="col-md-12"><h5><b>Doctor Name :  ' + data.Table24[0].doctor_name + '</b></h5></div>';

                          // vitals section
                          if (data.Table.length > 0 && ((data.Table[0].pulse_rate != null && data.Table[0].pulse_rate != '') || (data.Table[0].spo2 != null && data.Table[0].spo2 != '') || (data.Table[0].temperature != null && data.Table[0].temperature != ''))) {
                              div = div + '<div class="col-md-12"><h5><b>Vitals</b></h5></div>';
                          }
                          else if (data.Table17.length > 0 && ((data.Table17[0].weight != null && data.Table17[0].weight != '') || (data.Table17[0].patient_height != null && data.Table17[0].patient_height != ''))) {
                              div = div + '<div class="col-md-12"><h5><b>Vitals</b></h5></div>';
                          }
                          else if (data.Table1.length > 0 && (data.Table1[0].patient_bp_max != null && data.Table1[0].patient_bp_max != '')) {
                              div = div + '<div class="col-md-12"><h5><b>Vitals</b></h5></div>';
                          }

                          if (data.Table17.length > 0) {
                              if (data.Table17[0].weight != null && data.Table17[0].weight != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Weight</label> : <span>' + data.Table17[0].weight + ' Kg </span></div>';
                              }
                              if (data.Table17[0].patient_height != null && data.Table17[0].patient_height != '') {
                                  var hieghtdb = parseInt(data.Table17[0].patient_height * 12) + parseInt(data.Table17[0].patient_height_metric);
                                  var hieghtout = Math.round(hieghtdb * 2.54);
                                  $('#hieght').html(hieghtout);
                                  var hieght = hieghtout;

                                  div = div + '<div class="col-md-4"><label class="control-label">Height</label> : <span>' + hieght + ' cm </span></div>';
                              }
                          }

                          if (data.Table1.length > 0) {
                              if (data.Table1[0].patient_bp_max != null && data.Table1[0].patient_bp_max != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Sys/Dia</label> : <span>' + data.Table1[0].patient_bp_max + '</span>/<span>' + data.Table1[0].patient_bp_min + '</span></div>';
                              }
                          }

                          if (data.Table.length > 0) {
                              if (data.Table[0].pulse_rate != null && data.Table[0].pulse_rate != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Pulse Rate</label> : <span>' + data.Table[0].pulse_rate + '</span></div>';
                              }
                              if (data.Table[0].spo2 != null && data.Table[0].spo2 != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">SpO2</label> : <span>' + data.Table[0].spo2 + '</span></div>';
                              }
                              if (data.Table[0].temperature != null && data.Table[0].temperature != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Temperature</label> : <span>' + data.Table[0].temperature + '</span></div>';
                              }
                          }

                          if (data.Table.length > 0 && data.Table[0].observation_primary != null) {
                              div = div + '<div class="col-md-12"><h5><b>OBSERVATION</b></h5></div>';
                          }
                          else if (data.Table17.length > 0 && data.Table17.length > 0) {
                              div = div + '<div class="col-md-12"><h5><b>OBSERVATION</b></h5></div>';
                          }
                          else if (data.Table1.length > 0 && data.Table1[0].patient_bp_record_id != null) {
                              div = div + '<div class="col-md-12"><h5><b>OBSERVATION</b></h5></div>';
                          }
                          else {

                          }

                          if (data.Table24.length > 0) {
                              if (data.Table24[0].diagnosis != null && data.Table24[0].diagnosis != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Diagnosis</label> : <span>' + data.Table24[0].diagnosis + ' </span></div>';
                              }
                              if (data.Table24[0].notes != null && data.Table24[0].notes != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Notes</label> : <span>' + data.Table24[0].notes + ' </span></div>';
                              }
                              if (data.Table24[0].investigation != null && data.Table24[0].investigation != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Investigation</label> : <span>' + data.Table24[0].investigation + ' </span></div>';
                              }
                              if (data.Table24[0].observation != null && data.Table24[0].observation != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Observation</label> : <span>' + data.Table24[0].observation + ' </span></div>';
                              }
                              if (data.Table24[0].treatment_procedure != null && data.Table24[0].treatment_procedure != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Treatment Procedure</label> : <span>' + data.Table24[0].treatment_procedure + ' </span></div>';
                              }
                              if (data.Table24[0].instruction != null && data.Table24[0].instruction != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Instruction</label> : <span>' + data.Table24[0].instruction + ' </span></div>';
                              }
                              if (data.Table24[0].xray_findings != null && data.Table24[0].xray_findings != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Examination Findings</label> : <span>' + data.Table24[0].xray_findings + ' </span></div>';
                              }
                              if (data.Table24[0].advice != null && data.Table24[0].advice != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Advice</label> : <span>' + data.Table24[0].advice + ' </span></div>';
                              }
                              if (data.Table24[0].counselling != null && data.Table24[0].counselling != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Counselling</label> : <span>' + data.Table24[0].counselling + ' </span></div>';
                              }
                              if (data.Table24[0].xray_findings_new != null && data.Table24[0].xray_findings_new != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Xray Finding</label> : <span>' + data.Table24[0].xray_findings_new + ' </span></div>';
                              }
                              if (data.Table24[0].lab_findings != null && data.Table24[0].lab_findings != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Lab Findings</label> : <span>' + data.Table24[0].lab_findings + ' </span></div>';
                              }
                              if (data.Table24[0].review_notes != null && data.Table24[0].review_notes != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Review Notes</label> : <span>' + data.Table24[0].review_notes + ' </span></div>';
                              }
                          }

                          if (data.Table.length > 0) {

                              if (data.Table[0].current_complaints != null && data.Table[0].current_complaints != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Complaints</label> : <span>' + data.Table[0].current_complaints + '</span></div>';
                              }
                              if (data.Table[0].note != null && data.Table[0].note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Notes </label> : <span>' + data.Table[0].note + '</span></div>';
                              }
                             
                              if (data.Table[0].hypoglycemia_episodes != null && data.Table[0].hypoglycemia_episodes != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Hypoglycemic Episodes</label> : <span>' + data.Table[0].hypoglycemia_episodes + '</span></div>';
                              }
                              debugger;
                              if (data.Table[0].vas != null && data.Table[0].vas != '') {
                                  if (data.Table28[0].vas == '0') {
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Visual Analogue Scale(VAS)</b></h5></label> : <span> No Pain</span></div>';
                                  }
                                  else if (data.Table28[0].vas == '1' || data.Table28[0].vas == '2' || data.Table28[0].vas == '3') {
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Visual Analogue Scale(VAS)</b></h5></label> : <span> Mild</span></div>';
                                  }
                                  else if (data.Table28[0].vas == '4' || data.Table28[0].vas == '5' || data.Table28[0].vas == '6') {
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Visual Analogue Scale(VAS)</b></h5></label> : <span> Moderate </span></div>';
                                  }
                                  else if (data.Table28[0].vas == '7' || data.Table28[0].vas == '8' || data.Table28[0].vas == '9') {
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Visual Analogue Scale(VAS)</b></h5></label> : <span> Severe</span></div>';
                                  }
                                  if (data.Table28[0].vas == '10') {
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Visual Analogue Scale(VAS)</b></h5></label> : <span> Worst Pain </span></div>';
                                  }
                                  if (data.Table28[0].vasduration != null) {
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Vas Duration</b></h5></label> : <span> ' + data.Table28[0].vasduration + ' </span></div>';
                                  }

                                  if (data.Table28[0].vaslocation != null) {
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Vas Location</b></h5></label> : <span> ' + data.Table28[0].vaslocation + ' </span></div>';
                                  }

                                  if (data.Table28[0].followup != null) {
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Follow Up/Admission Plan</b></h5></label> : <span> ' + data.Table28[0].followup + ' </span></div>';
                                  }

                                  if (data.Table28[0].vaspaincharacter != null) {
                                      var paincharacter = data.Table28[0].vaspaincharacter;

                                      if (paincharacter != null && paincharacter != "") {

                                          var paincharactersplit = paincharacter.split(',');
                                          var paincharacter_disp = [];
                                          for (i = 0; i < paincharactersplit.length; i++) {

                                              if (paincharactersplit[i] == 0) {
                                                  var paincharacter_view = "Dull"
                                              }
                                              else if (paincharactersplit[i] == 1) {
                                                  var paincharacter_view = "Aching"
                                              }
                                              else if (paincharactersplit[i] == 2) {
                                                  var paincharacter_view = "Sharp"
                                              }
                                              else if (paincharactersplit[i] == 3) {
                                                  var paincharacter_view = "Stabbing"
                                              }
                                              else if (paincharactersplit[i] == 4) {
                                                  var paincharacter_view = "Shooting"
                                              }
                                              else if (paincharactersplit[i] == 5) {
                                                  var paincharacter_view = "Burning"
                                              }
                                              else if (paincharactersplit[i] == 6) {
                                                  var paincharacter_view = "Referred/Radiant Plain"
                                              }
                                              paincharacter_disp.push(paincharacter_view)

                                          }

                                      }
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Pain Character</b></h5></label> : <span> ' + paincharacter_disp + ' </span></div>';
                                  }
                                  if (data.Table28[0].vasfullrisk != null) {
                                      var frsfa = data.Table28[0].vasfullrisk;
                                      var frsfa_disp = [];
                                      if (frsfa != null && frsfa != "") {

                                          var frsfasplit = frsfa.split(',');

                                          for (i = 0; i < frsfasplit.length; i++) {
                                              if (frsfasplit[i] == 0) {
                                                  var frsfa_view = "No risk"
                                              }
                                              else if (frsfasplit[i] == 1) {
                                                  var frsfa_view = "Age More than 65 years"
                                              }
                                              else if (frsfasplit[i] == 2) {
                                                  var frsfa_view = "History of fall in last 3 Months"
                                              }
                                              else if (frsfasplit[i] == 3) {
                                                  var frsfa_view = "Walks with assistance"
                                              }
                                              else if (frsfasplit[i] == 4) {
                                                  var frsfa_view = "Any Neurological Problem"
                                              }

                                              frsfa_disp.push(frsfa_view)


                                          }

                                      }
                                      div = div + '<div class="col-md-12"><label class="control-label"><h5><b>Full Risk Screening for Adults</b></h5></label> : <span> ' + frsfa_disp + ' </span></div>';
                                  }
                              }
                              if (data.Table[0].glycemic_variability != null && data.Table[0].glycemic_variability != '') {
                                  var glycemic_variability = data.Table[0].glycemic_variability;
                                  if (glycemic_variability == 1) {
                                      glycemic_variability = "Present";
                                  }
                                  else {
                                      glycemic_variability = "Absent";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Glycemic Variability</label> : <span>' + glycemic_variability + '</span></div>';
                              }
                              if (data.Table[0].cvs != null && data.Table[0].cvs != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">CVS</label> : <span>' + data.Table[0].cvs + '</span></div>';
                              }
                              if (data.Table[0].ABS != null && data.Table[0].ABS != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">ABD</label> : <span>' + data.Table[0].ABS + '</span></div>';
                              }
                              if (data.Table[0].rs != null && data.Table[0].rs != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">RS</label> : <span>' + data.Table[0].rs + '</span></div>';
                              }
                              if (data.Table[0].CNS != null && data.Table[0].CNS != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">CNS</label> : <span>' + data.Table[0].CNS + '</span></div>';
                              }

                              if (data.Table[0].heart_sound != null && data.Table[0].heart_sound != '') {
                                  var heart_sound = data.Table[0].heart_sound;
                                  if (heart_sound == 1) {
                                      heart_sound = "True";
                                  }
                                  else {
                                      heart_sound = "False";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Abnormal Heart Sound</label> : <span>' + heart_sound + '</span></div>';
                              }

                              if (data.Table[0].murmurs != null && data.Table[0].murmurs != '') {
                                  var murmurs = data.Table[0].murmurs;
                                  if (murmurs == 1) {
                                      murmurs = "Present";
                                  }
                                  else {
                                      murmurs = "Absent";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Murmurs</label> : <span>' + murmurs + '</span></div>';
                              }

                              if (data.Table[0].reduce_air_entry != null && data.Table[0].reduce_air_entry != '') {
                                  var reduce_air_entry = data.Table[0].reduce_air_entry;
                                  if (reduce_air_entry == 1) {
                                      reduce_air_entry = "Present";
                                  }
                                  else {
                                      reduce_air_entry = "Absent";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Reduced Air Entry</label> : <span>' + reduce_air_entry + '</span></div>';
                              }

                              if (data.Table[0].crackles != null && data.Table[0].crackles != '') {
                                  var crackles = data.Table[0].crackles;
                                  if (crackles == 1) {
                                      crackles = "Present";
                                  }
                                  else {
                                      crackles = "Absent";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Crackles</label> : <span>' + crackles + '</span></div>';
                              }
                              if (data.Table[0].bowel_sounds != null && data.Table[0].bowel_sounds != '') {
                                  var bowel_sounds = data.Table[0].bowel_sounds;
                                  if (bowel_sounds == 1) {
                                      bowel_sounds = "Present";
                                  }
                                  else {
                                      bowel_sounds = "Absent";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Abnormal Bowel Sounds</label> : <span>' + bowel_sounds + '</span></div>';
                              }
                              if (data.Table[0].organomeglay != null && data.Table[0].organomeglay != '') {
                                  var organomeglay = data.Table[0].organomeglay;
                                  if (organomeglay == 1) {
                                      organomeglay = "Present";
                                  }
                                  else {
                                      organomeglay = "Absent";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Organomeglay</label> : <span>' + organomeglay + '</span></div>';
                              }
                              if (data.Table[0].tremors_weakness != null && data.Table[0].tremors_weakness != '') {
                                  var tremors_weakness = data.Table[0].tremors_weakness;
                                  if (tremors_weakness == 1) {
                                      tremors_weakness = "Present";
                                  }
                                  else {
                                      tremors_weakness = "Absent";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Tremors Weakness</label> : <span>' + tremors_weakness + '</span></div>';
                              }
                              if (data.Table[0].cognitive_imparement != null && data.Table[0].cognitive_imparement != '') {
                                  var cognitive_imparement = data.Table[0].cognitive_imparement;
                                  if (cognitive_imparement == 1) {
                                      cognitive_imparement = "Present";
                                  }
                                  else {
                                      cognitive_imparement = "Absent";
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Cognitive Imparement</label> : <span>' + cognitive_imparement + '</span></div>';
                              }
                          }
                         
                          //dental
                          if (data.Table28.length > 0 && (data.Table28[0].dental_procedure_done != null || data.Table28[0].dental_procedure_remaining != null || data.Table28[0].dental_type != null)) {
                              div = div + '<div class="col-md-12"><h5><b>Dental</h5></b></div>';
                          }
                          if (data.Table28.length > 0) {
                              if (data.Table28[0].dental_type != null && data.Table28[0].dental_type != '') {
                                  div = div + '<div class="col-md-12"><label class="control-label">Type of Dental Appointment</label> : <span>' + (data.Table28[0].dental_type == 1 ? "Cosmetic" : data.Table28[0].dental_type == 2 ? "Dental" : "Surgical") + '</span></div>';
                              }
                              if (data.Table28[0].dental_procedure_done != null && data.Table28[0].dental_procedure_done != '') {
                                  div = div + '<div class="col-md-12"><label class="control-label">Procedure Done</label> : <span>' + data.Table28[0].dental_procedure_done + '</span></div>';
                              }
                              if (data.Table28[0].dental_procedure_remaining != null && data.Table28[0].dental_procedure_remaining != '') {
                                  div = div + '<div class="col-md-12"><label class="control-label">Procedure Remaining</label> : <span>' + data.Table28[0].dental_procedure_remaining + '</span></div>';
                              }
                          }
                          if (data.Table2.length > 0 && data.Table2[0].glycemic_parameters_basic_id != null) {
                              div = div + '<div class="col-md-12"><h5><b>Glycemic</b></h5></div>';
                          }
                          else if (data.Table3.length > 0 && data.Table3[0].patient_hbac_record_id != null) {
                              div = div + '<div class="col-md-12"><h5><b>Glycemic</b></h5></div>';
                          }
                          else if (data.Table4.length > 0 && data.Table4[0].patient_blood_sugar_record_id != null) {
                              div = div + '<div class="col-md-12"><h5><b>Glycemic</b></h5></div>';
                          }
                          else {

                          }
                          if (data.Table2.length > 0) {
                              if (data.Table2[0].fasting_insulin != null && data.Table2[0].fasting_insulin != '') {
                                  var fasting_inslin_unit = 'mlU/L';
                                  if (data.Table2[0].fasting_inslin_unit == 2) {
                                      fasting_inslin_unit = 'pmol/L'
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Fasting Insulin</label> : <span>' + data.Table2[0].fasting_insulin + ' ' + fasting_inslin_unit + '</span></div>';
                              }
                              if (data.Table2[0].hemoglobin != null && data.Table2[0].hemoglobin != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">HB</label> : <span>' + data.Table2[0].hemoglobin + ' gms</span></div>';
                              }
                              if (data.Table2[0].note != null && data.Table2[0].note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Glycemic Notes</label> : <span>' + data.Table2[0].note + '</span></div>';
                              }
                              if (data.Table2[0].WBC != null && data.Table2[0].WBC != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">WBC</label> : <span>' + data.Table2[0].WBC + ' cells per cubic millimeter</span></div>';
                              }
                              if (data.Table2[0].platelet != null && data.Table2[0].platelet != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Platelet</label> : <span>' + data.Table2[0].platelet + ' per microliter</span></div>';
                              }
                              if (data.Table2[0].se_ketones != null && data.Table2[0].se_ketones != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Se_ketones</label> : <span>' + data.Table2[0].se_ketones + ' mmol/L</span></div>';
                              }

                          }

                          //if (data.Table3.length > 0 || data.Table4.length > 0) {
                          //    div = div + '<br/><div class="col-md-12"><h4>Glycemic</h4></div>';
                          //}

                          if (data.Table3.length > 0) {
                              if (data.Table3[0].patient_hbac_record_value != null && data.Table3[0].patient_hbac_record_value != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">HBA1C</label> : <span>' + data.Table3[0].patient_hbac_record_value + ' %</span></div>';
                              }
                          }

                          if (data.Table4.length > 0) {
                              for (var i = 0; i < data.Table4.length; i++) {
                                  if (data.Table4[i].patient_blood_sugar_value != null && data.Table4[i].patient_blood_sugar_value != '' && data.Table4[i].patient_blood_sugar_type == 1) {
                                      var unit = 'mg/dL';
                                      if (data.Table4[i].patient_blood_sugar_unit == 1) {
                                          unit = 'mmol/L';
                                      }
                                      div = div + '<div class="col-md-4"><label class="control-label">Fasting blood sugar</label> : <span>' + data.Table4[i].patient_blood_sugar_value + ' ' + unit + '</span></div>';
                                  }
                                  if (data.Table4[i].patient_blood_sugar_value != null && data.Table4[i].patient_blood_sugar_value != '' && data.Table4[i].patient_blood_sugar_type == 2) {
                                      var unit = 'mg/dL';
                                      if (data.Table4[i].patient_blood_sugar_unit == 1) {
                                          unit = 'mmol/L';
                                      }
                                      div = div + '<div class="col-md-4"><label class="control-label">Postprandial blood sugar</label> : <span>' + data.Table4[i].patient_blood_sugar_value + ' ' + unit + '</span></div>';
                                  }
                                  if (data.Table4[i].patient_blood_sugar_value != null && data.Table4[i].patient_blood_sugar_value != '' && data.Table4[i].patient_blood_sugar_type == 3) {
                                      var unit = 'mg/dL';
                                      if (data.Table4[i].patient_blood_sugar_unit == 1) {
                                          unit = 'mmol/L';
                                      }
                                      div = div + '<div class="col-md-4"><label class="control-label">Random blood sugar</label> : <span>' + data.Table4[i].patient_blood_sugar_value + ' ' + unit + '</span></div>';
                                  }
                                  if (data.Table4[i].patient_blood_sugar_value != null && data.Table4[i].patient_blood_sugar_value != '' && data.Table4[i].patient_blood_sugar_type == 4) {
                                      var unit = 'mg/dL';
                                      if (data.Table4[i].patient_blood_sugar_unit == 1) {
                                          unit = 'mmol/L';
                                      }
                                      div = div + '<div class="col-md-4"><label class="control-label">Before Lunch BS</label> : <span>' + data.Table4[i].patient_blood_sugar_value + ' ' + unit + '</span></div>';
                                  }
                                  if (data.Table4[i].patient_blood_sugar_value != null && data.Table4[i].patient_blood_sugar_value != '' && data.Table4[i].patient_blood_sugar_type == 5) {
                                      var unit = 'mg/dL';
                                      if (data.Table4[i].patient_blood_sugar_unit == 1) {
                                          unit = 'mmol/L';
                                      }
                                      div = div + '<div class="col-md-4"><label class="control-label">After Lunch BS</label> : <span>' + data.Table4[i].patient_blood_sugar_value + ' ' + unit + '</span></div>';
                                  }
                                  if (data.Table4[i].patient_blood_sugar_value != null && data.Table4[i].patient_blood_sugar_value != '' && data.Table4[i].patient_blood_sugar_type == 6) {
                                      var unit = 'mg/dL';
                                      if (data.Table4[i].patient_blood_sugar_unit == 1) {
                                          unit = 'mmol/L';
                                      }
                                      div = div + '<div class="col-md-4"><label class="control-label">Before Dinner BS</label> : <span>' + data.Table4[i].patient_blood_sugar_value + ' ' + unit + '</span></div>';
                                  }
                                  if (data.Table4[i].patient_blood_sugar_value != null && data.Table4[i].patient_blood_sugar_value != '' && data.Table4[i].patient_blood_sugar_type == 7) {
                                      var unit = 'mg/dL';
                                      if (data.Table4[i].patient_blood_sugar_unit == 1) {
                                          unit = 'mmol/L';
                                      }
                                      div = div + '<div class="col-md-4"><label class="control-label">After Dinner BS</label> : <span>' + data.Table4[i].patient_blood_sugar_value + ' ' + unit + '</span></div>';
                                  }
                                  if (data.Table4[i].patient_blood_sugar_value != null && data.Table4[i].patient_blood_sugar_value != '' && data.Table4[i].patient_blood_sugar_type == 8) {
                                      var unit = 'mg/dL';
                                      if (data.Table4[i].patient_blood_sugar_unit == 1) {
                                          unit = 'mmol/L';
                                      }
                                      div = div + '<div class="col-md-4"><label class="control-label">3 Am BS</label> : <span>' + data.Table4[i].patient_blood_sugar_value + ' ' + unit + '</span></div>';
                                  }
                              }

                          }
                          //want to write code
                          if (data.Table5.length > 0) {
                              //if (data.Table3[0].patient_hbac_record_value != null && data.Table3[0].patient_hbac_record_value != '') {
                              //    div = div + '<div class="col-md-4"><label class="control-label">Platelet</label> : <span>' + data.Table3[0].patient_hbac_record_value + ' %</span></div>';
                              //}
                          }

                          if (data.Table6.length > 0) {
                              if (data.Table6[0].renal_function_test_id != null) {
                                  div = div + '<div class="col-md-12"><h5><b>RENAL</b></h5></div>';
                              }
                          }
                          else {
                              if (data.Table7.length > 0) {
                                  if ((data.Table7[0].ACR != null && data.Table7[0].ACR != '') || (data.Table7[0].nephropathy != null && data.Table7[0].nephropathy != '')) {
                                      div = div + '<div class="col-md-12"><h5><b>RENAL</b></h5></div>';
                                  }
                              }
                          }

                          if (data.Table6.length > 0) {
                              if (data.Table6[0].Urea != null && data.Table6[0].Urea != '') {
                                  var unit = 'mg/dL';
                                  if (data.Table6[0].urea_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Urea</label> : <span>' + data.Table6[0].Urea + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].creatinine != null && data.Table6[0].creatinine != '') {
                                  var unit = 'mg/dL';
                                  if (data.Table6[0].Creatinine_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Creatinine</label> : <span>' + data.Table6[0].creatinine + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].egfr_value != null && data.Table6[0].egfr_value != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">EGFR ( Calculated )</label> : <span>' + data.Table6[0].egfr_value + ' ml/min/1.73m2</span></div>';
                              }
                              if (data.Table6[0].Sodium != null && data.Table6[0].Sodium != '') {
                                  var unit = 'mEq/L';
                                  if (data.Table6[0].sodium_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Sodium</label> : <span>' + data.Table6[0].Sodium + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].Potassium != null && data.Table6[0].Potassium != '') {
                                  var unit = 'mEq/L';
                                  if (data.Table6[0].potassium_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Potassium</label> : <span>' + data.Table6[0].Potassium + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].Chlorine != null && data.Table6[0].Chlorine != '') {
                                  var unit = 'mEq/L';
                                  if (data.Table6[0].chlorine_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Chlorine</label> : <span>' + data.Table6[0].Chlorine + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].BiCarbonate != null && data.Table6[0].BiCarbonate != '') {
                                  var unit = 'mEq/L';
                                  if (data.Table6[0].Bicarbonate_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">BiCarbonate</label> : <span>' + data.Table6[0].BiCarbonate + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].serium_calcium != null && data.Table6[0].serium_calcium != '') {
                                  var unit = 'mEq/L';
                                  if (data.Table6[0].Calcium_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Calcium</label> : <span>' + data.Table6[0].serium_calcium + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].serium_phosphorous != null && data.Table6[0].serium_phosphorous != '') {
                                  var unit = 'mEq/L';
                                  if (data.Table6[0].Phosphorus_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Phosphorous</label> : <span>' + data.Table6[0].serium_phosphorous + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].serium_magnesium != null && data.Table6[0].serium_magnesium != '') {
                                  var unit = 'mEq/L';
                                  if (data.Table6[0].Magnesium_unit == 1) {
                                      unit = 'mmol/L';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Magnesium</label> : <span>' + data.Table6[0].serium_magnesium + '' + unit + ' </span></div>';
                              }
                              if (data.Table6[0].note != null && data.Table6[0].note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Renal Notes</label> : <span>' + data.Table6[0].note + ' </span></div>';
                              }
                              if (data.Table6[0].ASD != null && data.Table6[0].ASD != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">ASD</label> : <span>' + data.Table6[0].ASD + ' </span></div>';
                              }
                              if (data.Table6[0].VSD != null && data.Table6[0].VSD != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">VSD</label> : <span>' + data.Table6[0].VSD + ' </span></div>';
                              }
                              if (data.Table6[0].C_value != null && data.Table6[0].C_value != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Valve Notes</label> : <span>' + data.Table6[0].C_value + ' </span></div>';
                              }
                              if (data.Table6[0].fraction != null && data.Table6[0].fraction != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Fraction</label> : <span>' + data.Table6[0].fraction + ' </span></div>';
                              }
                              if (data.Table6[0].mitral_value != null && data.Table6[0].mitral_value != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Mitral Value</label> : <span>' + data.Table6[0].mitral_value + ' </span></div>';
                              }
                              if (data.Table6[0].lotic_value != null && data.Table6[0].lotic_value != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Aortic Valve</label> : <span>' + data.Table6[0].lotic_value + ' </span></div>';
                              }
                              if (data.Table6[0].tricuspid != null && data.Table6[0].tricuspid != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Tricuspid</label> : <span>' + data.Table6[0].tricuspid + ' </span></div>';
                              }
                              if (data.Table6[0].pulmonary != null && data.Table6[0].pulmonary != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Pulmonary</label> : <span>' + data.Table6[0].pulmonary + ' </span></div>';
                              }

                          }

                          if (data.Table7.length > 0) {
                              if (data.Table7[0].ACR != null && data.Table7[0].ACR != '') {
                                  var ACR = '';
                                  if (data.Table7[0].ACR == 1) {
                                      ACR = '< 30 mg/dL - Normal';
                                  }
                                  if (data.Table7[0].ACR == 2) {
                                      ACR = '30 to 300 mg/dL - Microalbuminuria';
                                  }
                                  if (data.Table7[0].ACR == 3) {
                                      ACR = '  > 300 mg/dL - Proteinuria';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">ACR</label> : <span>' + ACR + '</span></div>';
                              }
                              if (data.Table7[0].nephropathy != null && data.Table7[0].nephropathy != '') {
                                  var nephropathy = '';
                                  if (data.Table7[0].nephropathy == 1) {
                                      nephropathy = 'Yes';
                                  }
                                  if (data.Table7[0].nephropathy == 2) {
                                      nephropathy = 'No';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Nephropathy</label> : <span>' + nephropathy + '</span></div>';
                              }
                          }



                          if (data.Table8.length > 0) {
                              if (data.Table8[0].cholestrol_id != null) {
                                  div = div + '<div class="col-md-12"><h5><b>CHOLESTEROL</b></h5></div>';
                              }

                          }
                          else {
                              if (data.Table9.length > 0) {
                                  if (data.Table9[0].dyslipedemia != null && data.Table9[0].dyslipedemia != '') {
                                      div = div + '<div class="col-md-12"><h5><b>CHOLESTEROL</b></h5></div>';
                                  }
                              }
                          }

                          if (data.Table8.length > 0) {
                              if (data.Table8[0].Total_Cholestrol != null && data.Table8[0].Total_Cholestrol != '') {
                                  var unit = 'mmol/L';
                                  if (data.Table8[0].Total_cholestrol_unit == 1) {
                                      unit = 'mg/dL';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Total Cholesterol</label> : <span>' + data.Table8[0].Total_Cholestrol + '' + unit + ' </span></div>';
                              }

                              if (data.Table8[0].LDL != null && data.Table8[0].LDL != '') {
                                  var unit = 'mmol/L';
                                  if (data.Table8[0].LDL_unit == 1) {
                                      unit = 'mg/dL';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">LDL</label> : <span>' + data.Table8[0].LDL + '' + unit + ' </span></div>';
                              }

                              if (data.Table8[0].HDL != null && data.Table8[0].HDL != '') {
                                  var unit = 'mmol/L';
                                  if (data.Table8[0].HDL_unit == 1) {
                                      unit = 'mg/dL';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">HDL</label> : <span>' + data.Table8[0].HDL + '' + unit + ' </span></div>';
                              }

                              if (data.Table8[0].VLDL != null && data.Table8[0].VLDL != '') {
                                  var unit = 'mmol/L';
                                  if (data.Table8[0].VLDL_unit == 1) {
                                      unit = 'mg/dL';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">VLDL</label> : <span>' + data.Table8[0].VLDL + '' + unit + ' </span></div>';
                              }
                              if (data.Table8[0].Triglycerides != null && data.Table8[0].Triglycerides != '') {
                                  var unit = 'mmol/L';
                                  if (data.Table8[0].Triglycerides_unit == 1) {
                                      unit = 'mg/dL';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Triglycerides</label> : <span>' + data.Table8[0].Triglycerides + '' + unit + ' </span></div>';
                              }
                              if (data.Table8[0].T_cholestrol_Hdl_ratio != null && data.Table8[0].T_cholestrol_Hdl_ratio != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Total Cholesterol : HDL Ratio</label> : <span>' + data.Table8[0].T_cholestrol_Hdl_ratio + ' </span></div>';
                              }
                              if (data.Table8[0].note != null && data.Table8[0].note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Cholestrol Notes</label> : <span>' + data.Table8[0].note + ' </span></div>';
                              }
                          }
                          if (data.Table9.length > 0) {
                              if (data.Table9[0].dyslipedemia != null && data.Table9[0].dyslipedemia != '') {
                                  var unit = '';
                                  if (data.Table9[0].dyslipedemia == 1) {
                                      unit = 'yes';
                                  }
                                  else {
                                      unit = 'No';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Dyslipidemia</label> : <span>' + unit + ' </span></div>';
                              }
                          }

                          if (data.Table10.length > 0 && ((data.Table10[0].last_observation_date != null && data.Table10[0].last_observation_date != '') || (data.Table10[0].next_suggested_appointment != null && data.Table10[0].next_suggested_appointment != '') || (data.Table10[0].note != null && data.Table10[0].note != ''))) {
                              div = div + '<div class="col-md-12"><h5><b>OPTHAL</b></h5></div>';
                          }
                          else if (data.Table11.length > 0 && data.Table11[0].patient_level_flag_id != null && ((data.Table11[0].pdr != null && data.Table11[0].pdr != '') || (data.Table11[0].npdr != null && data.Table11[0].npdr != '') || (data.Table11[0].viterous_hemorage != null && data.Table11[0].viterous_hemorage != '') || (data.Table11[0].retinal_detachment != null && data.Table11[0].retinal_detachment != '') || (data.Table11[0].retinopathy != null && data.Table11[0].retinopathy != ''))) {
                              div = div + '<div class="col-md-12"><h5><b>OPTHAL</b></h5></div>';
                          }
                          if (data.Table10.length > 0) {

                              if (data.Table10[0].last_observation_date != null && data.Table10[0].last_observation_date != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Last Observation Date</label> : <span>' + data.Table10[0].last_observation_date + ' </span></div>';
                              }
                              if (data.Table10[0].next_suggested_appointment != null && data.Table10[0].next_suggested_appointment != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Next Suggested Opthal Appointment</label> : <span>' + data.Table10[0].next_suggested_appointment + ' </span></div>';
                              }
                              if (data.Table10[0].note != null && data.Table10[0].note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Opthal Notes</label> : <span>' + data.Table10[0].note + ' </span></div>';
                              }
                          }

                          if (data.Table11.length > 0) {
                              if (data.Table11[0].pdr != null && data.Table11[0].pdr != '') {
                                  var val = '';
                                  if (data.Table11[0].pdr == 1) {
                                      val = 'None';
                                  }
                                  else if (data.Table11[0].pdr == 2) {
                                      val = 'Mild';
                                  }
                                  else if (data.Table11[0].pdr == 3) {
                                      val = 'Moderate';
                                  }
                                  else if (data.Table11[0].pdr == 4) {
                                      val = 'Severe';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">PDR</label> : <span>' + val + ' </span></div>';
                              }
                              if (data.Table11[0].npdr != null && data.Table11[0].npdr != '') {
                                  var val = '';
                                  if (data.Table11[0].npdr == 1) {
                                      val = 'None';
                                  }
                                  else if (data.Table11[0].npdr == 2) {
                                      val = 'Mild';
                                  }
                                  else if (data.Table11[0].npdr == 3) {
                                      val = 'Moderate';
                                  }
                                  else if (data.Table11[0].npdr == 4) {
                                      val = 'Severe';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">NPDR</label> : <span>' + val + ' </span></div>';
                              }
                              if (data.Table11[0].viterous_hemorage != null && data.Table11[0].viterous_hemorage != '') {
                                  var val = '';
                                  if (data.Table11[0].viterous_hemorage == 1) {
                                      val = 'Yes';
                                  }
                                  else if (data.Table11[0].viterous_hemorage == 2) {
                                      val = 'No';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Vitreous Hemorrhage</label> : <span>' + val + ' </span></div>';
                              }
                              if (data.Table11[0].retinal_detachment != null && data.Table11[0].retinal_detachment != '') {
                                  var val = '';
                                  if (data.Table11[0].retinal_detachment == 1) {
                                      val = 'Yes';
                                  }
                                  else if (data.Table11[0].retinal_detachment == 2) {
                                      val = 'No';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Retinal Detachment</label> : <span>' + val + ' </span></div>';
                              }
                              if (data.Table11[0].retinopathy != null && data.Table11[0].retinopathy != '') {
                                  var val = '';
                                  if (data.Table11[0].retinopathy == 1) {
                                      val = 'Yes';
                                  }
                                  else if (data.Table11[0].retinopathy == 2) {
                                      val = 'No';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Retinopathy</label> : <span>' + val + ' </span></div>';
                              }
                          }

                          if (data.Table19.length > 0 && data.Table19[0].patient_level_cardiac_id != null && (data.Table19[0].L_LAD != null || data.Table19[0].L_LAD_type != null || data.Table19[0].L_LCX != null ||
                               data.Table19[0].L_LCX_type != null || data.Table19[0].L_RCA != null || data.Table19[0].L_RCA_type != null || data.Table19[0].R_LAD != null || data.Table19[0].R_LAD_type != null
                               || data.Table19[0].R_LCX != null || data.Table19[0].R_LCX_type != null || data.Table19[0].R_RCA != null || data.Table19[0].R_RCA_type != null)) {
                              div = div + '<div class="col-md-12"><h5>CARDIAC</h5></div>';
                          }
                          else if (data.Table12.length > 0 && data.Table12[0].cardiac_profile_id != null && (data.Table12[0].ECG != null || data.Table12[0].ECHO != null
                          || (data.Table12[0].ecg_abnormal != null && data.Table12[0].ecg_abnormal != 0) || (data.Table12[0].echo_abnormal != null && data.Table12[0].echo_abnormal != 0) || data.Table12[0].TMT_test != null || data.Table12[0].note != null)) {
                              div = div + '<div class="col-md-12"><h5>CARDIAC</h5></div>';
                          }
                          else { }
                          if (data.Table19.length > 0) {
                              if (data.Table19[0].L_LAD != null && data.Table19[0].L_LAD != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">LCA</label> : <span>' + data.Table19[0].L_LAD + ' %</span></div>';
                              }
                              if (data.Table19[0].L_LAD_type != null && data.Table19[0].L_LAD_type != '' && data.Table19[0].L_LAD_type != 0) {
                                  var type = '';
                                  if (data.Table19[0].L_LAD_type == 1) {
                                      type = 'Proximal';
                                  }
                                  else if (data.Table19[0].L_LAD_type == 2) {
                                      type = 'Mid';
                                  }
                                  else if (data.Table19[0].L_LAD_type == 3) {
                                      type = 'Distal';
                                  }

                                  div = div + '<div class="col-md-4"><label class="control-label">LCA Type</label> : <span>' + type + ' </span></div>';
                              }

                              if (data.Table19[0].L_LCX != null && data.Table19[0].L_LCX != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">LCX</label> : <span>' + data.Table19[0].L_LCX + ' %</span></div>';
                              }
                              if (data.Table19[0].L_LCX_type != null && data.Table19[0].L_LCX_type != '' && data.Table19[0].L_LCX_type != 0) {
                                  var type = '';
                                  if (data.Table19[0].L_LCX_type == 1) {
                                      type = 'Proximal';
                                  }
                                  else if (data.Table19[0].L_LCX_type == 2) {
                                      type = 'Mid';
                                  }
                                  else if (data.Table19[0].L_LCX_type == 3) {
                                      type = 'Distal';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">LCX Type</label> : <span>' + type + ' </span></div>';
                              }


                              if (data.Table19[0].L_RCA != null && data.Table19[0].L_RCA != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">LAD</label> : <span>' + data.Table19[0].L_RCA + ' %</span></div>';
                              }
                              if (data.Table19[0].L_RCA_type != null && data.Table19[0].L_RCA_type != '' && data.Table19[0].L_RCA_type != 0) {
                                  var type = '';
                                  if (data.Table19[0].L_RCA_type == 1) {
                                      type = 'Proximal';
                                  }
                                  else if (data.Table19[0].L_RCA_type == 2) {
                                      type = 'Mid';
                                  }
                                  else if (data.Table19[0].L_RCA_type == 3) {
                                      type = 'Distal';
                                  }

                                  div = div + '<div class="col-md-4"><label class="control-label">LAD Type</label> : <span>' + type + ' </span></div>';
                              }


                              if (data.Table19[0].R_LAD != null && data.Table19[0].R_LAD != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">RCA</label> : <span>' + data.Table19[0].R_LAD + ' %</span></div>';
                              }
                              if (data.Table19[0].R_LAD_type != null && data.Table19[0].R_LAD_type != '' && data.Table19[0].R_LAD_type != 0) {
                                  var type = '';
                                  if (data.Table19[0].R_LAD_type == 1) {
                                      type = 'Proximal';
                                  }
                                  else if (data.Table19[0].R_LAD_type == 2) {
                                      type = 'Mid';
                                  }
                                  else if (data.Table19[0].R_LAD_type == 3) {
                                      type = 'Distal';
                                  }

                                  div = div + '<div class="col-md-4"><label class="control-label">RCA Type</label> : <span>' + type + ' </span></div>';
                              }


                              if (data.Table19[0].R_LCX != null && data.Table19[0].R_LCX != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">R-PLB</label> : <span>' + data.Table19[0].R_LCX + ' %</span></div>';
                              }
                              if (data.Table19[0].R_LCX_type != null && data.Table19[0].R_LCX_type != '' && data.Table19[0].R_LCX_type != 0) {
                                  var type = '';
                                  if (data.Table19[0].R_LCX_type == 1) {
                                      type = 'Proximal';
                                  }
                                  else if (data.Table19[0].R_LCX_type == 2) {
                                      type = 'Mid';
                                  }
                                  else if (data.Table19[0].R_LCX_type == 3) {
                                      type = 'Distal';
                                  }

                                  div = div + '<div class="col-md-4"><label class="control-label">R-PLB Type</label> : <span>' + type + ' </span></div>';
                              }


                              if (data.Table19[0].R_RCA != null && data.Table19[0].R_RCA != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">R-PDA</label> : <span>' + data.Table19[0].R_RCA + ' %</span></div>';
                              }
                              if (data.Table19[0].R_RCA_type != null && data.Table19[0].R_RCA_type != '' && data.Table19[0].R_RCA_type != 0) {
                                  var type = '';
                                  if (data.Table19[0].R_RCA_type == 1) {
                                      type = 'Proximal';
                                  }
                                  else if (data.Table19[0].R_RCA_type == 2) {
                                      type = 'Mid';
                                  }
                                  else if (data.Table19[0].R_RCA_type == 3) {
                                      type = 'Distal';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">R-PDA Type</label> : <span>' + type + ' </span></div>';
                              }



                          }

                          if (data.Table12.length > 0) {
                              if (data.Table12[0].ECG != null && data.Table12[0].ECG != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">ECG</label> : <span>' + data.Table12[0].ECG + ' </span></div>';
                              }
                              if (data.Table12[0].ECHO != null && data.Table12[0].ECHO != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">ECHO</label> : <span>' + data.Table12[0].ECHO + ' </span></div>';
                              }
                              if (data.Table12[0].ecg_abnormal != null && data.Table12[0].ecg_abnormal != '') {
                                  if (data.Table12[0].ecg_abnormal == 1) {
                                      div = div + '<div class="col-md-4"><label class="control-label">ECG Abnormal</label> : <span>True</span></div>';
                                  }
                              }
                              if (data.Table12[0].echo_abnormal != null && data.Table12[0].echo_abnormal != '') {
                                  if (data.Table12[0].echo_abnormal == 1) {
                                      div = div + '<div class="col-md-4"><label class="control-label">ECHO Abnormal</label> : <span>True</span></div>';
                                  }
                              }
                              if (data.Table12[0].TMT_test != null && data.Table12[0].TMT_test != '') {
                                  if (data.Table12[0].TMT_test == 1) {
                                      div = div + '<div class="col-md-4"><label class="control-label">TMT</label> : <span>Positive</span></div>';
                                  }
                                  else {
                                      div = div + '<div class="col-md-4"><label class="control-label">TMT</label> : <span>Negative</span></div>';
                                  }
                              }
                              if (data.Table12[0].note != null && data.Table12[0].note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Cardiac Notes</label> : <span>' + data.Table12[0].note + '</span></div>';
                              }
                          }


                          if (data.Table13.length > 0 && (data.Table13[0].autonomic_neuropathy != null && data.Table13[0].autonomic_neuropathy != '')) {
                              div = div + '<div class="col-md-12"><h5>NEUROPATHY</h5></div>';
                          }
                          else if (data.Table14.length > 0 && ((data.Table14[0].peripharal_neuhropathy != null && data.Table14[0].peripharal_neuhropathy != '') || (data.Table14[0].AB_index != null && data.Table14[0].AB_index != '') || (data.Table14[0].doppler_note != null && data.Table14[0].doppler_note != '') || (data.Table14[0].note != null && data.Table14[0].note != ''))) {
                              div = div + '<div class="col-md-12"><h5>NEUROPATHY</h5></div>';
                          }
                          else {

                          }
                          if (data.Table13.length > 0) {
                              if (data.Table13[0].autonomic_neuropathy != null && data.Table13[0].autonomic_neuropathy != '') {
                                  if (data.Table13[0].autonomic_neuropathy == 1) {
                                      div = div + '<div class="col-md-4"><label class="control-label">Autonomic Neuropathy</label> : <span>Yes</span></div>';
                                  }
                                  else {
                                      div = div + '<div class="col-md-4"><label class="control-label">Autonomic Neuropathy</label> : <span>No</span></div>';
                                  }
                              }
                          }
                          if (data.Table14.length > 0) {
                              if (data.Table14[0].peripharal_neuhropathy != null && data.Table14[0].peripharal_neuhropathy != '') {
                                  var val = '';
                                  if (data.Table14[0].peripharal_neuhropathy == 1) {
                                      val = 'None';
                                  }
                                  else if (data.Table14[0].peripharal_neuhropathy == 2) {
                                      val = 'Mild';
                                  }
                                  else if (data.Table14[0].peripharal_neuhropathy == 3) {
                                      val = 'Moderate';
                                  }
                                  else if (data.Table14[0].peripharal_neuhropathy == 4) {
                                      val = 'Severe';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Peripheral Neuhropathy</label> : <span>' + val + ' </span></div>';
                              }
                              if (data.Table14[0].AB_index != null && data.Table14[0].AB_index != '') {
                                  var val = '';
                                  if (data.Table14[0].AB_index == 1) {
                                      val = 'None';
                                  }
                                  else if (data.Table14[0].AB_index == 2) {
                                      val = 'Mild';
                                  }
                                  else if (data.Table14[0].AB_index == 3) {
                                      val = 'Moderate';
                                  }
                                  else if (data.Table14[0].AB_index == 4) {
                                      val = 'Severe';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">AB Index</label> : <span>' + val + ' </span></div>';
                              }
                              if (data.Table14[0].doppler_note != null && data.Table14[0].doppler_note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Doppler</label> : <span>' + data.Table14[0].doppler_note + ' </span></div>';
                              }
                              if (data.Table14[0].note != null && data.Table14[0].note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Neuropthy Note</label> : <span>' + data.Table14[0].note + ' </span></div>';
                              }
                          }

                          if (data.Table15.length > 0) {
                              if (data.Table15[0].thyroid_id != null) {
                                  div = div + '<div class="col-md-12"><h5><b>THYROID</b></h5></div>';
                              }
                          }

                          if (data.Table15.length > 0) {
                              if (data.Table15[0].Free_T3 != null && data.Table15[0].Free_T3 != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Free T3</label> : <span>' + data.Table15[0].Free_T3 + ' Pg/dl </span></div>';
                              }
                              if (data.Table15[0].Free_T4 != null && data.Table15[0].Free_T4 != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Free T4</label> : <span>' + data.Table15[0].Free_T4 + ' ng/dl </span></div>';
                              }
                              if (data.Table15[0].Free_T4 != null && data.Table15[0].Free_T4 != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">TSH</label> : <span>' + data.Table15[0].TSH + ' mlU/m </span></div>';
                              }
                              if (data.Table15[0].note != null && data.Table15[0].note != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Thyroid Notes</label> : <span>' + data.Table15[0].note + '</span></div>';
                              }
                          }

                          if (data.Table16.length > 0) {
                              if (data.Table16[0].sheet_chest_xray_id != null) {
                                  div = div + '<div class="col-md-12"><h5><b>ULTRASOUND / X-RAY</b></h5></div>';
                              }
                          }
                          if (data.Table16.length > 0) {
                              if (data.Table16[0].notes != null && data.Table16[0].notes != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Chest X-Ray Notes</label> : <span>' + data.Table16[0].notes + ' Pg/dl </span></div>';
                              }
                              if (data.Table16[0].USNotes != null && data.Table16[0].USNotes != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Ultrasound Notes</label> : <span>' + data.Table16[0].USNotes + ' ng/dl </span></div>';
                              }
                              if (data.Table16[0].fatty_lives != null && data.Table16[0].fatty_lives != '') {
                                  var val = '';
                                  if (data.Table16[0].fatty_lives == 1) {
                                      val = 'Yes';
                                  }
                                  else if (data.Table16[0].fatty_lives == 2) {
                                      val = 'No';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">Fatty Liver</label> : <span>' + val + ' </span></div>';
                              }
                              if (data.Table16[0].GS_Calculus != null && data.Table16[0].GS_Calculus != '') {
                                  var val = '';
                                  if (data.Table16[0].GS_Calculus == 1) {
                                      val = 'Yes';
                                  }
                                  else if (data.Table16[0].GS_Calculus == 2) {
                                      val = 'No';
                                  }
                                  div = div + '<div class="col-md-4"><label class="control-label">GB Calculas</label> : <span>' + val + ' </span></div>';
                              }
                          }
                          if (data.Table18.length > 0) {
                              //$('#moreinfovisit_date').html(data.Table18[0].c_date);
                          }

                          if (data.Table26.length > 0) {
                              if (data.Table26[0].liver_function_test_id != null && (data.Table26[0].serum_bilirubin_total != null || data.Table26[0].serum_bilirubin_direct != null
                                                    || data.Table26[0].bilirubin_indirect != null || data.Table26[0].serum_protein_total != null || data.Table26[0].serum_protein_albumin != null || data.Table26[0].serumproteinglibulin != null
                                                    || data.Table26[0].SGOT != null || data.Table26[0].SGPT != null || data.Table26[0].serum_alkaline_phosphatase != null || data.Table26[0].gamma_glutamyl_transpeptidase != null || data.Table26[0].serum_magnesium != null)) {
                                  div = div + '<div class="col-md-12"><b><h5><b>LIVER FUNCTION TEST</b></h5></div>';
                              }
                          }
                          if (data.Table26.length > 0) {
                              if (data.Table26[0].serum_bilirubin_total != null && data.Table26[0].serum_bilirubin_total != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Serum Bilirubin Total</label> : <span>' + data.Table26[0].serum_bilirubin_total + ' mg/dl </span></div>';
                              }
                              if (data.Table26[0].serum_bilirubin_direct != null && data.Table26[0].serum_bilirubin_direct != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Serum Bilirubin Direct</label> : <span>' + data.Table26[0].serum_bilirubin_direct + ' mg/dl </span></div>';
                              }

                              if (data.Table26[0].bilirubin_indirect != null && data.Table26[0].bilirubin_indirect != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Bilirubin Indirect</label> : <span>' + data.Table26[0].bilirubin_indirect + ' mg/dl </span></div>';
                              }
                              if (data.Table26[0].serum_protein_total != null && data.Table26[0].serum_protein_total != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Serum Protein -Total</label> : <span>' + data.Table26[0].serum_protein_total + ' g/dl </span></div>';
                              }
                              if (data.Table26[0].serum_protein_albumin != null && data.Table26[0].serum_protein_albumin != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Serum Protein - Albumin</label> : <span>' + data.Table26[0].serum_protein_albumin + ' g/dl</span></div>';
                              }
                              if (data.Table26[0].serumproteinglibulin != null && data.Table26[0].serumproteinglibulin != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Serum Protein - Glibulin</label> : <span>' + data.Table26[0].serumproteinglibulin + ' g/dl </span></div>';
                              }
                              if (data.Table26[0].SGOT != null && data.Table26[0].SGOT != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">SGOT (AST)</label> : <span>' + data.Table26[0].SGOT + ' IU/l </span></div>';
                              }
                              if (data.Table26[0].SGPT != null && data.Table26[0].SGPT != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">SGPT (AST)</label> : <span>' + data.Table26[0].SGPT + ' IU/l </span></div>';
                              }
                              if (data.Table26[0].serum_alkaline_phosphatase != null && data.Table26[0].serum_alkaline_phosphatase != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Serum Alkaline Phosphatase</label> : <span>' + data.Table26[0].serum_alkaline_phosphatase + ' IU/l </span></div>';
                              }
                              if (data.Table26[0].gamma_glutamyl_transpeptidase != null && data.Table26[0].gamma_glutamyl_transpeptidase != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Serum Alkaline Phosphatase</label> : <span>' + data.Table26[0].gamma_glutamyl_transpeptidase + ' IU/l </span></div>';
                              }
                              if (data.Table26[0].serum_magnesium != null && data.Table26[0].serum_magnesium != '') {
                                  div = div + '<div class="col-md-4"><label class="control-label">Gamma Glutamyl Transpeptidase (GGT)</label> : <span>' + data.Table26[0].serum_magnesium + ' IU/l </span></div>';
                              }

                          }
                          //cbc and urine routine
                          if (data.Table29.length > 0) {
                              if (data.Table29[0].visit_report_id != null) {
                                  div = div + '<div class="col-md-12"><h5><b>CBC</b></h5></div>';
                              }
                          }

                          if (data.Table29.length > 0) {
                              for (var i = 0; i < data.Table29.length; i++) {
                                  if (data.Table29[0].hemoglobin != null && data.Table29[0].hemoglobin != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">HEMOGLOBIN</label> : <span>' + data.Table29[0].hemoglobin + " " + ((data.Table29[0].hemoglobin_unit == null || data.Table29[0].hemoglobin_unit == "") ? "" : data.Table29[0].hemoglobin_unit) + ' </span></div>';
                                  }
                                  if (data.Table29[0].platelet_count != null && data.Table29[0].platelet_count != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">PLATELET COUNT</label> : <span>' + data.Table29[0].platelet_count + " " + ((data.Table29[0].platelet_count_unit == null || data.Table29[0].platelet_count_unit == "") ? "" : data.Table29[0].platelet_count_unit) + ' </span></div>';
                                  }
                                  if (data.Table29[0].nucleated_red_blood_cells != null && data.Table29[0].nucleated_red_blood_cells != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">NUCLEATED RED BLOOD CELLS</label> : <span>' + data.Table29[0].nucleated_red_blood_cells + ' </span></div>';
                                  }
                                  if (data.Table29[0].nucleated_red_blood_cells_percent != null && data.Table29[0].nucleated_red_blood_cells_percent != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">NUCLEATED RED BLOOD CELLS %</label> : <span>' + data.Table29[0].nucleated_red_blood_cells_percent + ' </span></div>';
                                  }
                                  if (data.Table29[0].hematocrit != null && data.Table29[0].hematocrit != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">HEMATOCRIT(PCV)</label> : <span>' + data.Table29[0].hematocrit + ' </span></div>';
                                  }
                                  if (data.Table29[0].lymphocyte_percent != null && data.Table29[0].lymphocyte_percent != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">LYMPHOCYTE PERCENTAGE</label> : <span>' + data.Table29[0].lymphocyte_percent + ' </span></div>';
                                  }
                                  if (data.Table29[0].total_leucocytes_count != null && data.Table29[0].total_leucocytes_count != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">TOTAL LEUCOCYTES COUNT</label> : <span>' + data.Table29[0].total_leucocytes_count + ' </span></div>';
                                  }
                                  if (data.Table29[0].mean_corpuscular_hemoglobin != null && data.Table29[0].mean_corpuscular_hemoglobin != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">MEAN CORPUSCULAR HEMOGLOBIN(MCH)</label> : <span>' + data.Table29[0].mean_corpuscular_hemoglobin + ' </span></div>';
                                  }
                                  if (data.Table29[0].mean_corp_hemo_conc != null && data.Table29[0].mean_corp_hemo_conc != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">MEAN CORP.HEMO.CONC(MCHC)</label> : <span>' + data.Table29[0].mean_corp_hemo_conc + ' </span></div>';
                                  }
                                  if (data.Table29[0].mean_corpuscular_volume != null && data.Table29[0].mean_corpuscular_volume != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">MEAN CORPUSCULAR VOLUME(MCV)</label> : <span>' + data.Table29[0].mean_corpuscular_volume + ' </span></div>';
                                  }
                                  if (data.Table29[0].monocytes != null && data.Table29[0].monocytes != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">MONOCYTES</label> : <span>' + data.Table29[0].monocytes + ' </span></div>';
                                  }
                                  if (data.Table29[0].neutrophils != null && data.Table29[0].neutrophils != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">NEUTROPHILS</label> : <span>' + data.Table29[0].neutrophils + ' </span></div>';
                                  }
                                  if (data.Table29[0].eosinophils_absolute_count != null && data.Table29[0].eosinophils_absolute_count != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">EOSINOPHILS - ABSOLUTE COUNT</label> : <span>' + data.Table29[0].eosinophils_absolute_count + ' </span></div>';
                                  }
                                  if (data.Table29[0].basophils_absolute_count != null && data.Table29[0].basophils_absolute_count != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">BASOPHILS - ABSOLUTE COUNT</label> : <span>' + data.Table29[0].basophils_absolute_count + ' </span></div>';
                                  }
                                  if (data.Table29[0].lymphocytes_absolute_count != null && data.Table29[0].lymphocytes_absolute_count != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">LYMPHOCYTES - ABSOLUTE COUNT</label> : <span>' + data.Table29[0].lymphocytes_absolute_count + ' </span></div>';
                                  }
                                  if (data.Table29[0].monocytes_absolute_count != null && data.Table29[0].monocytes_absolute_count != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">MONOCYTES - ABSOLUTE COUNT</label> : <span>' + data.Table29[0].monocytes_absolute_count + ' </span></div>';
                                  }
                                  if (data.Table29[0].neutrophils_absolute_count != null && data.Table29[0].neutrophils_absolute_count != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">NEUTROPHILS - ABSOLUTE COUNT</label> : <span>' + data.Table29[0].neutrophils_absolute_count + ' </span></div>';
                                  }
                                  if (data.Table29[0].basophils != null && data.Table29[0].basophils != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">BASOPHILS</label> : <span>' + data.Table29[0].basophils + ' </span></div>';
                                  }

                                  if (data.Table29[0].eosinophils != null && data.Table29[0].eosinophils != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">EOSINOPHILS</label> : <span>' + data.Table29[0].eosinophils + ' </span></div>';
                                  }

                                  if (data.Table29[0].immature_granulocytes != null && data.Table29[0].immature_granulocytes != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">IMMATURE GRANULOCYTES(IG)</label> : <span>' + data.Table29[0].immature_granulocytes + ' </span></div>';
                                  }
                                  if (data.Table29[0].immature_granulocytes_percent != null && data.Table29[0].immature_granulocytes_percent != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">IMMATURE GRANULOCYTE PERCENTAGE(IG%)</label> : <span>' + data.Table29[0].immature_granulocytes_percent + ' </span></div>';
                                  }
                                  if (data.Table29[0].total_rbc != null && data.Table29[0].total_rbc != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">TOTAL RBC</label> : <span>' + data.Table29[0].total_rbc + ' </span></div>';
                                  }
                                  if (data.Table29[0].redcell_distribution_width != null && data.Table29[0].redcell_distribution_width != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">RED CELL DISTRIBUTION WIDTH (RDW-CV)</label> : <span>' + data.Table29[0].redcell_distribution_width + ' </span></div>';
                                  }
                                  if (data.Table29[0].redcell_distribution_width_sd != null && data.Table29[0].redcell_distribution_width_sd != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">RED CELL DISTRIBUTION WIDTH - SD(RDW-SD)</label> : <span>' + data.Table29[0].redcell_distribution_width_sd + ' </span></div>';
                                  }
                              }
                          }

                          if (data.Table30.length > 0) {
                              if (data.Table30[0].visit_report_id != null) {
                                  div = div + '<div class="col-md-12"><h5><b>Urine Routine</b></h5></div>';
                              }
                          }
                          if (data.Table30.length > 0) {
                              for (var i = 0; i < data.Table30.length; i++) {
                                  if (data.Table30[0].specific_gravity != null && data.Table30[0].specific_gravity != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">SPECIFIC GRAVITY</label> : <span>' + data.Table30[0].specific_gravity + " " + ((data.Table30[0].specific_gravity_unit == null || data.Table30[0].specific_gravity_unit == "") ? "" : data.Table30[0].specific_gravity_unit) + ' </span></div>';
                                  }
                                  if (data.Table30[0].urinary_bilirubin != null && data.Table30[0].urinary_bilirubin != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">URINARY BILIRUBIN</label> : <span>' + data.Table30[0].urinary_bilirubin + " " + ((data.Table30[0].urinary_bilirubin_unit == null || data.Table30[0].urinary_bilirubin_unit == "") ? "" : data.Table30[0].urinary_bilirubin_unit) + ' </span></div>';
                                  }
                                  if (data.Table30[0].urine_blood != null && data.Table30[0].urine_blood != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">URINE BLOOD</label> : <span>' + data.Table30[0].urine_blood + ' </span></div>';
                                  }
                                  if (data.Table30[0].urobilinogen != null && data.Table30[0].urobilinogen != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">UROBILINOGEN</label> : <span>' + data.Table30[0].urobilinogen + " " + ((data.Table30[0].urobilinogen_unit == null || data.Table30[0].urobilinogen_unit == "") ? "" : data.Table30[0].urobilinogen_unit) + ' </span></div>';
                                  }
                                  if (data.Table30[0].urinary_glucose != null && data.Table30[0].urinary_glucose != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">URINARY GLUCOSE</label> : <span>' + data.Table30[0].urinary_glucose + ' </span></div>';
                                  }
                                  if (data.Table30[0].urine_ketone != null && data.Table30[0].urine_ketone != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">URINE KETONE</label> : <span>' + data.Table30[0].urine_ketone + " " + ((data.Table30[0].urine_ketone_unit == null || data.Table30[0].urine_ketone_unit == "") ? "" : data.Table30[0].urine_ketone_unit) + ' </span></div>';
                                  }
                                  if (data.Table30[0].urinary_leucocytes != null && data.Table30[0].urinary_leucocytes != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">URINARY LEUCOCYTES</label> : <span>' + data.Table30[0].urinary_leucocytes + ' </span></div>';
                                  }
                                  if (data.Table30[0].nitrite != null && data.Table30[0].nitrite != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">NITRITE</label> : <span>' + data.Table30[0].nitrite + " " + ((data.Table30[0].nitrite_unit == null || data.Table30[0].nitrite_unit == "") ? "" : data.Table30[0].nitrite_unit) + ' </span></div>';
                                  }
                                  if (data.Table30[0].ph != null && data.Table30[0].ph != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">PH</label> : <span>' + data.Table30[0].ph + ' </span></div>';
                                  }
                                  if (data.Table30[0].urinary_protein != null && data.Table30[0].urinary_protein != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">URINARY PROTEIN</label> : <span>' + data.Table30[0].urinary_protein + ' </span></div>';
                                  }
                              }
                          }

                          if (data.Table25.length > 0) {
                              for (var i = 0; i < data.Table25.length; i++) {
                                  if (data.Table25[i].parameter_value != null && data.Table25[i].parameter_value != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">' + data.Table25[i].parameter_name + '</label> : <span>' + data.Table25[i].parameter_value + " " + data.Table25[i].unit + '</span></div>';
                                  }
                              }
                          }

                          if (data.Table27.length > 0) {
                              if (data.Table27[0].master_labtest_visit_report_id != null) {
                                  div = div + '<div class="col-md-12"><h5><b>Master Lab Test</b></h5></div>';
                              }
                          }


                          if (data.Table27.length > 0) {
                              for (var i = 0; i < data.Table27.length; i++) {
                                  if (data.Table27[0].parameter_name != null && data.Table27[0].parameter_name != '') {
                                      div = div + '<div class="col-md-4"><label class="control-label">' + data.Table27[i].parameter_name + '</label> : <span>' + data.Table27[i].parameter_value + '  ' + data.Table27[i].reference_value + ' ' + data.Table27[i].unit + '</span></div>';
                                  }
                              }
                          }



                          $('#tbl_patient_summary_details_' + data.Table18[0].visit_report_id).html('');
                          $('#tbl_patient_summary_details_' + data.Table18[0].visit_report_id).html(div);

                          if (data.Table21.length > 0) {
                              tr = '';
                              for (var i = 0; i < data.Table21.length; i++) {
                                  var session = '';
                                  visit_report_id = data.Table21[i].visit_report_id;
                                  if (data.Table21[i].evening == 1) {
                                      session = data.Table21[i].morning + ' - ' + data.Table21[i].afternoon + ' - ' + data.Table21[i].evening + ' - ' + data.Table21[i].night;
                                  }
                                  else {
                                      session = data.Table21[i].morning + ' - ' + data.Table21[i].afternoon + ' - ' + data.Table21[i].night;
                                  }
                                  var color = '';
                                  if (data.Table21[i].priority == 1) {
                                      color = '<i class=" fa fa-circle" style="color:green"></i>&nbsp;';
                                  }
                                  else if (data.Table21[i].priority == 2) {
                                      color = '<i class=" fa fa-circle" style="color:orange"></i>&nbsp;';
                                  }
                                  else if (data.Table21[i].priority == 3) {
                                      color = '<i class=" fa fa-circle" style="color:#418bfe"></i>&nbsp;';
                                  }
                                  else {
                                      color = '<i class=" fa fa-circle" style="color:#ffffff"></i>&nbsp;';
                                  }
                                  var instructions = '';
                                  if (data.Table21[i].instructions == '' || data.Table21[i].instructions == null) {
                                      instructions = '';
                                  }
                                  else {
                                      instructions = data.Table21[i].instructions;
                                  }
                                  if (data.Table21[i].days_to_take == '' || data.Table21[i].days_to_take == null) {
                                      days_to_take = '';
                                  }
                                  else if (data.Table21[i].days_to_take == '9999') {
                                      days_to_take = 'Daily';
                                  }
                                  else {
                                      days_to_take = data.Table21[i].days_to_take;
                                  }
                                  var generic_name = '';
                                  if (data.Table21[i].generic_name == '' || data.Table21[i].generic_name == null) {
                                      generic_name = '';
                                  }
                                  else {
                                      generic_name = '<span style=font-size:11px;><i>(' + data.Table21[i].generic_name + ')</i></span>';
                                  }

                                  //tr = tr + '<div class="col-md-12 presc_table_row"><div class="col-md-4"><span style="text-transform:capitalize;">' + data[i].medicine_name + '</div><div class="col-md-2 red">' + data[i].medicine_type + '</div><div class="col-md-2 red">' + data[i].when_to_eat_value + '</div><div class="col-md-3"> &nbsp; ' + data[i].morning + ' &nbsp;&nbsp;&nbsp;&nbsp; - &nbsp;&nbsp;&nbsp;&nbsp; ' + data[i].afternoon + '&nbsp;&nbsp;&nbsp;&nbsp; - &nbsp;&nbsp;&nbsp;&nbsp; ' + data[i].evening + ' &nbsp;&nbsp;&nbsp;&nbsp; - &nbsp;&nbsp;&nbsp;&nbsp; ' + data[i].night + ' &nbsp;&nbsp;&nbsp;&nbsp;</div><div class="col-md-1 red">' + data[i].days_to_take + '</div><div class="clearfix"></div></div>';
                                  tr = tr + '<tr><td>' + data.Table21[i].medicine_type + '</td><td style="text-transform:capitalize;">' + color + data.Table21[i].medicine_name + generic_name + '</td><td>' + data.Table21[i].when_to_eat_value + '</td><td>' + days_to_take + '</td><td>' + instructions + '</td><td>' + session + '</td></tr>';
                              }

                              var pdf = '<a href="javascript:void(0);" class="pull-right btn_cpy_prescription" onclick=printPrescription("' + visit_report_id + '")><i class="fa fa-clipboard " aria-hidden="true"></i> Print </a>'
                              var table = '<div class="table-responsive"><table class="table table-condensed body-borderless table_borderless">';
                              var tableend = '</table></div>';
                              var headTable = '<thead style="background: grey;"><tr><th>Type</th><th>Medicine & Generic</th><th>When to take</th><th>Duration(Days)</th><th>Notes</th><th>Frequency</th></tr></thead>';

                              $('#tbl-medicine_' + visit_report_id).html('');
                              $('#tbl-medicine_' + visit_report_id).append(table + headTable + tr + tableend);
                              //$('.prescription_print').html(pdf);
                          }
                          else {
                              $('#Prescription_div_' + data.Table18[0].visit_report_id).hide();
                          }


                          //if (data.Table22.length > 0) {
                          //    j = 0;
                          //    var labtr = '';
                          //    var SuggestedDate = '';
                          //    for (var i = 0; i < data.Table22.length; i++) {
                          //        //labtr = labtr + '<tr><td>' + data.Table2[i].lab_prescription + '</td><td>' + data.Table2[i].lab_type_name + '</td><td style="text-align:center;">' + data.Table2[i].suggested_date + '</td></tr>'
                          //        if (i == 0) {
                          //            labtr = labtr + '<tr><td><p><span>' + data.Table22[i].suggested_date + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td><td><span>' + data.Table22[i].lab_prescription + '</span>';
                          //            SuggestedDate = data.Table22[i].suggested_date;
                          //        }
                          //        else {
                          //            if (data.Table22[i].suggested_date == SuggestedDate) {
                          //                SuggestedDate = data.Table22[i].suggested_date;
                          //                labtr = labtr + '<span>,</span><span>' + data.Table22[i].lab_prescription + '</span>';
                          //            }
                          //            else {
                          //                SuggestedDate = data.Table22[i].suggested_date;
                          //                labtr = labtr + '</td></tr><tr><td></p><p><span>' + SuggestedDate + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td><td><span>' + data.Table22[i].lab_prescription + '</span>';
                          //            }
                          //        }

                          //    }
                          //    var cls = '</td></tr></p>';
                          //    $('#Lab-table_' + data.Table22[0].visit_report_id).html('');
                          //    $('#Lab-table_' + data.Table22[0].visit_report_id).append(labtr + cls);

                          //}
                         
                              if (data.Table22.length > 0) {
                                  j = 0;
                                  var labtr = '';
                                  var SuggestedDate = '';
                                  var thead = '<table class="table table-condensed table_bordered"><th>S.No</th><th>Service Name</th><th>Service Code</th><th>Quantity</th><th>Date</th><th>Action</th>';
                                  var theadend = '</table>';

                                  
                                  for (var i = 0; i < data.Table22.length; i++) {
                                      var action = "-";
                                      var payment = '';
                                      if (data.Table22[i].is_lab == 1 || data.Table22[i].is_appointment == 1) {
                                          var lab_document = '';
                                          if (data.Table22[i].document_path != null && data.Table22[i].document_path != "") {
                                              var str = data.Table22[i].document_path;
                                              var temp = new Array();
                                              temp = str.split(",");
                                              var strarray = str.split(',');
                                              for (var k = 0; k < strarray.length; k++) {
                                                  lab_document = lab_document + '<a href="' + $('#hdngetlabfilepath').val() + $('#HdnHospitalid').val() + "/" + $('#HBranchID').val() + "/Lab_Documents/" + strarray[k] + '" target="_blank" style="margin-right: 10px;">Lab Document ' + (k + 1) + '</a>' + "/";
                                              }
                                          }
                                          action = ((data.Table22[i].flag == 3 || data.Table22[i].flag == 4) || (data.Table22[i].aflag == 3 || data.Table22[i].aflag == 4)) ? lab_document + '<button type="button" class="btn btn-primaryuse btn-xs mr-5" style="margin-right: 10px;" onclick=jobprint("' + data.Table22[i].work_order_id + '","' + data.Table22[i].hospitalid + '","' + data.Table22[i].patientid + '","' + data.Table22[i].branchid + '","' + data.Table22[i].master_service_id + '","' + data.Table22[i].barcodeid + '")><i class="fa fa fa-print" aria-hidden="true"></i></button>' : (data.Table22[i].flag == 2) ? lab_document + " Result Pending" : "Result Pending";
                                          payment = (data.Table22[i].is_bill == 1 || data.Table22[i].is_bill == "1") ? '<a><span class="label label-success" style="background-color: green !important;">PAID</span></a>' : '<a><span class="label label-danger">PENDING</span></a>';
                                      }

                                      labtr = labtr + '<tr><td>' + (i + 1) + '</td><td>' + payment + data.Table22[i].service_name + '</td><td>' + data.Table22[i].service_code + '</td><td>' + data.Table22[i].quantity + '</td><td>' + data.Table22[i].service_date + '</td><td>' + action + '</td></tr>';
                                  }


                                  $('#Lab-table_' + data.Table22[0].visit_report_id).html('');
                                  $('#Lab-table_' + data.Table22[0].visit_report_id).append(thead + labtr + theadend);
                                  $('#lab_div_' + data.Table18[0].visit_report_id).show();

                              }
                              else {
                                  $('#lab_div_' + data.Table18[0].visit_report_id).hide();
                              }

                          if (data.Table31.length > 0) { //Exercise Summary
                              var exercisetable = '<>'
                              var tr = '';
                              for (var i = 0; i < data.Table31.length; i++) {

                                  var monday = data.Table31[i].monday_flag;
                                  var tuesday = data.Table31[i].tuesday_flag;
                                  var wednesday = data.Table31[i].wednesday_flag;
                                  var thusday = data.Table31[i].thursday_flag;
                                  var friday = data.Table31[i].friday_flag;
                                  var saturday = data.Table31[i].saturday_flag;
                                  var sunday = data.Table31[i].sunday_flag;

                                  var SuggestedDays = ''; var suggestedDaysCount = 0;
                                  if (monday == 1) {

                                      SuggestedDays = 'Mon';
                                      suggestedDaysCount = suggestedDaysCount + 1;
                                  }
                                  if (tuesday == 1) {
                                      if (SuggestedDays == '') {
                                          SuggestedDays = '  Tue';
                                      }
                                      else {
                                          SuggestedDays = SuggestedDays + ',  Tue';
                                      }
                                      suggestedDaysCount = suggestedDaysCount + 1;
                                  }
                                  if (wednesday == 1) {
                                      if (SuggestedDays == '') {
                                          SuggestedDays = '  Wed';
                                      }
                                      else {
                                          SuggestedDays = SuggestedDays + ',  Wed';
                                      }
                                      suggestedDaysCount = suggestedDaysCount + 1;
                                  }
                                  if (thusday == 1) {
                                      if (SuggestedDays == '') {
                                          SuggestedDays = '  Thu';
                                      }
                                      else {
                                          SuggestedDays = SuggestedDays + ',  Thu';
                                      }
                                      suggestedDaysCount = suggestedDaysCount + 1;
                                  }
                                  if (friday == 1) {
                                      if (SuggestedDays == '') {
                                          SuggestedDays = '  Fri';
                                      }
                                      else {
                                          SuggestedDays = SuggestedDays + ',  Fri';
                                      }
                                      suggestedDaysCount = suggestedDaysCount + 1;
                                  }
                                  if (saturday == 1) {
                                      if (SuggestedDays == '') {
                                          SuggestedDays = '  Sat';
                                      }
                                      else {
                                          SuggestedDays = SuggestedDays + ',  Sat';
                                      }
                                      suggestedDaysCount = suggestedDaysCount + 1;
                                  }
                                  if (sunday == 1) {
                                      if (SuggestedDays == '') {
                                          SuggestedDays = '  Sun';
                                      }
                                      else {
                                          SuggestedDays = SuggestedDays + '  Sun';
                                      }
                                      suggestedDaysCount = suggestedDaysCount + 1;
                                  }
                                  var treatment_description = [];
                                  var t = data.Table31[i].treatment.split(",");
                                  var j = 0;
                                  for (var k = 0; k < t.length; k++) {
                                      if (t[k] == 1) {
                                          treatment_description[j] = "IFT"
                                      }
                                      else if (t[k] == 2) {
                                          treatment_description[j] = "UST"
                                      }
                                      else if (t[k] == 3) {
                                          treatment_description[j] = "CCT"
                                      }
                                      else if (t[k] == 4) {
                                          treatment_description[j] = "WAX"
                                      }
                                      else if (t[k] == 5) {
                                          treatment_description[j] = "ES"
                                      }
                                      else if (t[k] == 6) {
                                          treatment_description[j] = "LASER"
                                      }
                                      else if (t[k] == 7) {
                                          treatment_description[j] = "ICT"
                                      }
                                      else if (t[k] == 8) {
                                          treatment_description[j] = "IPT"
                                      }
                                      else if (t[k] == 9) {
                                          treatment_description[j] = "CPM"
                                      }
                                      else if (t[k] == 10) {
                                          treatment_description[j] = "CPT"
                                      }
                                      else {

                                      }
                                      j++;
                                  }
                                  var treatment_description_1 = treatment_description.toString();

                                  var choose_region_desc = [];
                                  if (data.Table31[i].choose_region != null && data.Table31[i].choose_region != "") {
                                      var r = data.Table31[i].choose_region.split(",");
                                      var p = 0;
                                      for (var k = 0; k < r.length; k++) {
                                          if (r[k] == 1) {
                                              choose_region_desc[p] = "SHOULDER REHAB"
                                          }
                                          else if (r[k] == 2) {
                                              choose_region_desc[p] = "ELBOW REHAB"
                                          }
                                          else if (r[k] == 3) {
                                              choose_region_desc[p] = "WRIST & HAND REHAB"
                                          }
                                          else if (r[k] == 4) {
                                              choose_region_desc[p] = "SPINE REHAB"
                                          }
                                          else if (r[k] == 5) {
                                              choose_region_desc[p] = "PELVIC & CORE REHAB"
                                          }
                                          else if (r[k] == 6) {
                                              choose_region_desc[p] = "HIP REHAB"
                                          }
                                          else if (r[k] == 7) {
                                              choose_region_desc[p] = "KNEE REHAB"
                                          }
                                          else if (r[k] == 8) {
                                              choose_region_desc[p] = "ANKLE & FOOT REHAB"
                                          }
                                          else if (r[k] == 9) {
                                              choose_region_desc[p] = "LIBERATORY MANEUVER"
                                          }
                                          else {

                                          }
                                          p++;

                                      }
                                  }
                                  var choose_region_1 = choose_region_desc.toString();


                                  tr = tr + "<tr><td>" + choose_region_1 + "</td><td>" + data.Table31[i].op_type + "</td><td>" + data.Table31[i].excercise_description + "</td><td>" + SuggestedDays + "</td><td>" + data.Table31[i].days_to_take + "</td><td>" + data.Table31[i].excercise_duration_per_day + "</td><td>" + data.Table31[i].sitting + "</td><td>" + data.Table31[i].instruction + "</td><td>" + treatment_description_1 + "</td></tr>";
                              }
                              var table = '<div class="table-responsive"><table class="table table-condensed body-borderless table_borderless">';
                              var tableend = '</table></div>';
                              var headTable = '<thead style="background: grey;"><tr><th>Region</th><th>Pre/Post OP</th><th>Type of Exercise</th><th>Suggested Days</th><th>Number of Days</th><th>Duration</th><th>Sitting</th><th>Exercise Instruction</th><th>Treatment</th></tr></thead>';

                              $('#Exercise-table_' + data.Table18[0].visit_report_id).html('');
                              $('#Exercise-table_' + data.Table18[0].visit_report_id).append(table + headTable + tr + tableend);
                          }
                          else {
                              $('#exercise_div_' + data.Table18[0].visit_report_id).hide();
                          }

                          //diet summary
                          if (data.Table33.length > 0) {
                              var tr = "";
                              for (var i = 0; i < data.Table33.length; i++) {
                                  j++;
                                  tr = tr + "<tr><td>" + data.Table33[i].time + "</td>";
                                  tr = tr + " <td>" + data.Table33[i].type_of_food + "</td>";
                                  tr = tr + " <td>" + data.Table33[i].no_of_servings + ' Per day' + "</td>";
                                  tr = tr + " <td>" + data.Table33[i].instructions + "</td>";
                                  tr = tr + "</tr>";

                              }
                              var dietplan = '<div><p>Plan Duration: <span>' + ((data.Table33[0].diet_goal_duration == null) ? '-' : data.Table33[0].diet_goal_duration + ' days') + '</span></p></div><div><p>Suggested Kcal Intake: <span>' + data.Table33[0].kcal + '</span></p></div>';
                              var table = '<div class="table-responsive"><table class="table table-condensed body-borderless table_borderless">';
                              var tableend = '</table></div>';
                              var headTable = '<thead style="background: grey;"><tr><th>Time</th><th>Food</th><th>Serving</th><th>Instruction</th></tr></thead>';

                              $('#Diet_table_' + data.Table18[0].visit_report_id).html('');
                              $('#Diet_table_' + data.Table18[0].visit_report_id).append(dietplan);
                              $('#Diet_table_' + data.Table18[0].visit_report_id).append(table + headTable + tr + tableend);
                          }
                          else {
                              $('#diet_div_' + data.Table18[0].visit_report_id).hide();
                          }

                          //observed nutrition

                          if (data.Table34.length > 0) {

                              var tr = '';
                              for (var i = 0; i < data.Table34.length; i++) {
                                  j++;
                                  tr = tr + "<tr><td>" + data.Table34[i].type + "</td><td>" + data.Table34[i].type_name + "</td></tr>";

                              }

                              var table = '<div class="table-responsive"><table class="table table-condensed body-borderless table_borderless">';
                              var tableend = '</table></div>';
                              var headTable = '<thead style="background: grey;"><tr><th>Type</th><th>Observed Value</th></tr></thead>';

                              $('#observed_nutrition_table_' + data.Table18[0].visit_report_id).html('');
                              $('#observed_nutrition_table_' + data.Table18[0].visit_report_id).append(table + headTable + tr + tableend);
                          }
                          else {
                              $('#observed_nutrition_div_' + data.Table18[0].visit_report_id).hide();
                          }

                          //future services
                          if (data.Table35.length > 0) {

                              var tr = '';
                              for (var i = 0; i < data.Table35.length; i++) {
                                  j++;
                                  if (data.Table35[i].base_amount_type == 4) {
                                      var date_time = data.Table35[i].service_date + " " + data.Table35[i].service_time + " - " + data.Table35[i].service_end_date + " " + data.Table35[i].service_end_time;
                                      tr = tr + '<tr><td>' + (i + 1) + '</td><td>' + data.Table35[i].service_name + '</td><td>' + data.Table35[i].service_code + '</td><td>' + data.Table35[i].quantity + '</td><td>' + date_time + '</td><td>' + ((data.Table35[i].remarks == '') ? '-' : data.Table35[i].remarks) + '</td></tr>'
                                  }
                                  else {
                                      var date_time = data.Table35[i].service_date + " " + data.Table35[i].service_time;
                                      tr = tr + '<tr><td>' + (i + 1) + '</td><td>' + data.Table35[i].service_name + '</td><td>' + data.Table35[i].service_code + '</td><td>' + data.Table35[i].quantity + '</td><td>' + date_time + '</td><td>' + ((data.Table35[i].remarks == '') ? '-' : data.Table35[i].remarks) + '</td></tr>'
                                  }

                              }

                              var table = '<div class="table-responsive"><table class="table table-condensed body-borderless table_borderless">';
                              var tableend = '</table></div>';
                              var headTable = '<thead style="background: grey;"><tr><th>S.NO</th><th>Service Name</th><th>Service Code</th><th>Quantity</th><th>Date & Time</th><th>Description</th></tr></thead>';

                              $('#future_services_table_' + data.Table18[0].visit_report_id).html('');
                              $('#future_services_table_' + data.Table18[0].visit_report_id).append(table + headTable + tr + tableend);
                          }
                          else {
                              $('#future_services_div_' + data.Table18[0].visit_report_id).hide();
                          }

                          if (data.Table23.length > 0) {
                              var imgtr = '';
                              for (var i = 0; i < data.Table23.length; i++) {
                                  var img = '';
                                  if (data.Table23[i].patient_lab_record_path == '' || data.Table23[i].patient_lab_record_path == null) {
                                      img = '-';
                                  }
                                  else {
                                      if (data.Table23[i].record_type == 3) {
                                          img = '<img src=' + $("#hdngetlabfilepath").val() + data.Table23[i].doctor_id + "/PrescriptionWritingPad/" + data.Table23[i].patient_lab_record_path + ' class="img-responsive" style="height: 50px;width: 50px;">';
                                          img = '<a href="' + $('#hdngetlabfilepath').val() + data.Table23[i].doctor_id + "/PrescriptionWritingPad/" + data.Table23[i].patient_lab_record_path + '" target="_blank">' + img + '</a>'
                                      }
                                      else {
                                          img = '<img src=' + $("#hdngetlabfilepath").val() + data.Table23[i].patient_lab_record_path + ' class="img-responsive" style="height: 50px;width: 50px;">';
                                          img = '<a href="' + $('#hdngetlabfilepath').val() + data.Table23[i].patient_lab_record_path + '" target="_blank">' + img + '</a>'
                                      }
                                      }
                                  imgtr = imgtr + '<div class="col-xs-3">' + img + '<br/><span style="text-transform:capitalize;">' + ((data.Table23[i].patient_testname != '' && data.Table23[i].patient_testname != null) ? data.Table23[i].patient_testname : 'No file name') + '</span></div>';
                              }
                              $('#tbl-fileupload_' + data.Table23[0].visit_report_id).html('');
                              $('#tbl-fileupload_' + data.Table23[0].visit_report_id).append(imgtr);
                          }
                          else {
                              $('#file_div_' + data.Table18[0].visit_report_id).hide();
                          }

                          if (data.Table24.length > 0) {
                              if (data.Table24[0].NextAppointment != '' && data.Table24[0].NextAppointment != null) {
                                  $('#lblNextApp_' + data.Table24[0].visit_report_id).html(data.Table24[0].NextAppointment);
                              }
                              else {
                                  $('#divNextApp_' + data.Table18[0].visit_report_id).hide();
                              }

                              if (data.Table24[0].next_appointment_notes != '' && data.Table24[0].next_appointment_notes != null) {
                                  $('#lblNextAppNotes_' + data.Table24[0].visit_report_id).html(data.Table24[0].next_appointment_notes);
                              }
                              else {
                                  $('#divNextAppNotes_' + data.Table18[0].visit_report_id).hide();
                              }

                              if ((data.Table24[0].NextAppointment == '' || data.Table24[0].NextAppointment == null) && (data.Table24[0].next_appointment_notes == '' || data.Table24[0].next_appointment_notes == null)) {
                                  $('#next_div_' + data.Table18[0].visit_report_id).hide();
                              }
                          }
                          else {
                              $('#next_div_' + data.Table18[0].visit_report_id).hide();
                          }

                          $('#summary_div_' + data.Table20[0].visit_report_id).removeClass('us-db-case-loader');
                      }
                      else {
                          $('.tbl_patient_summary_details').html('');
                      }
                  }
              }
              else {
                  console.log(data);
              }
          }
      });
  }

  function printpdf(VisitReportID, visitid, patientid, hospitalid, branchid) {
      if ($('#HCasesheetPrintType').val() == 0) {
          window.open('/PatientDashboard/PPDF?visitreportid=' + VisitReportID + '&lantype=' + $('#sellang').val() + '&btnval=1', "_blank");
      }
      else {
          var load_data = {
              formid: "137",
              branchid: branchid,
              hospitalid: hospitalid,
              patientid: patientid,
              visit_reportid: visitid
          }
          $.ajax({
              async: true,
              type: 'POST',
              url: '/reports/PrintCrystalReport',
              contentType: 'application/json; charset=UTF-8',
              data: JSON.stringify(load_data),
              success: function (data) {
                  debugger;

                  var byteArray = new Uint8Array(data);
                  var blob = new Blob([byteArray], { type: "application/pdf" });
                  var link = window.URL.createObjectURL(blob);
                  window.open(link, '_blank');

              }
          });
      }
  }


  //print lab result
  function jobprint(work_order_id, hospitalid, patientid, branchid, master_service_id, barcodeid) {

      var load_data = {
          formid: "108",
          branchid: branchid,
          hospitalid: hospitalid,
          work_order_id: work_order_id,
          patientid: patientid,
          barcodeid: barcodeid,
          masterserviceid: master_service_id

      }

      $.ajax({
          async: true,
          type: 'POST',
          url: '/reports/PrintCrystalReport',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(load_data),
          success: function (data) {
              var byteArray = new Uint8Array(data);
              var blob = new Blob([byteArray], { type: "application/pdf" });
              var link = window.URL.createObjectURL(blob);
              window.open(link, '_blank');

          }
      });

  }

  //function printpdf(VisitReportID) {  //Added By Antony
  //    debugger;

  //    var Hpatientid = $('#Hpatientid').val();
  //    var Hvisit_reportid = $('#Hvisit_reportid').val();

  //    var load_data = {
  //        // hospitalid,branchid,patientid,dmlindicator,fromdate,todate,visit_reportid

  //        formid: "80",
  //        branchid: $('#HBranchID').val(),
  //        patientid: Hpatientid,
  //        visit_reportid: Hvisit_reportid,
  //    }

  //    $.ajax({
  //        async: true,
  //        type: 'POST',
  //        url: '/reports/PrintCrystalReport',
  //        contentType: 'application/json; charset=UTF-8',
  //        data: JSON.stringify(load_data),
  //        success: function (data) {
  //            debugger;
  //            var byteArray = new Uint8Array(data);
  //            var blob = new Blob([byteArray], { type: "application/pdf" });
  //            var link = window.URL.createObjectURL(blob);
  //            window.open(link, '_blank');

  //        }
  //    });

  //}


  var graph = 1;
  function GraphSectionshow() {
      $('#graphdiv').show();
      $('#Ghide').show();
      $('#Gshow').hide();
      if (graph==1) {
          observationgraph();
          graph++;
      }

  }
  function GraphSectionhide() {
      $('#graphdiv').hide();
      $('#Ghide').hide();
      $('#Gshow').show();
  }

 

  function observationgraph() {

      var PaitentsTrend = {
          Dml_Indicator: 'OB',
          doctor_id: $('#doctorId').val(),
          Patient_id: $('#Hdnpatient_id').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/CaseStudy/Graph_Section',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(PaitentsTrend),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  if (jQuery.isEmptyObject((data))) {

                  }
                  else {
                      debugger;
                      if (Object.keys(data).length > 0) {
                          var bp_max = '<th>diastolic</th>', bp_min = '<th>systolic</th>', Parameters = '<th>Parameters</th>', Hpulse_rate = '<th>Pulse</th>', Hspo2 = '<th>SPO2</th>', Hhypoglycemia_episodes = '<th>Hypoglycemic Episodes</th>';
                          if (data.Table.length > 0) {
                              var datalength = 10;
                              if (data.Table.length < 10) {
                                  datalength = data.Table.length;
                              }
                              for (var i = 0; i < datalength; i++) {
                                  Parameters = Parameters + '<th>' + data.Table[i].VDate + '</th>'
                                  var patient_bp_max = '-', patient_bp_min = '-', pulse_rate = '-', spo2 = '-', hypoglycemia_episodes = '-';
                                  if (data.Table[i].patient_bp_max != null && data.Table[i].patient_bp_max != '') {
                                      patient_bp_max = data.Table[i].patient_bp_max + ' mmHg';
                                  }
                                  if (data.Table[i].patient_bp_min != null && data.Table[i].patient_bp_min != '') {
                                      patient_bp_min = data.Table[i].patient_bp_min + ' mmHg';
                                  }
                                  if (data.Table[i].pulse_rate != null && data.Table[i].pulse_rate != '') {
                                      pulse_rate = data.Table[i].pulse_rate + ' /min';
                                  }
                                  if (data.Table[i].spo2 != null && data.Table[i].spo2 != '') {
                                      spo2 = data.Table[i].spo2 + ' %';
                                  }
                                  if (data.Table[i].hypoglycemia_episodes != null && data.Table[i].hypoglycemia_episodes != '') {
                                      hypoglycemia_episodes = data.Table[i].hypoglycemia_episodes + ' /week';
                                  }
                                  bp_max = bp_max + '<td>' + patient_bp_max + '</td>';
                                  bp_min = bp_min + '<td>' + patient_bp_min + '</td>';
                                  Hpulse_rate = Hpulse_rate + '<td>' + pulse_rate + '</td>';
                                  Hspo2 = Hspo2 + '<td>' + spo2 + '</td>';
                                  Hhypoglycemia_episodes = Hhypoglycemia_episodes + '<td>' + hypoglycemia_episodes + '</td>';
                              }


                              var theadstart = '<thead><tr>'
                              var theadend = '</tr></thead>'
                              var tbodystart = '<tbody>'
                              var tbodyend = '</tbody>'
                              var trstart = '<tr>';
                              var trend = '</tr>';
                              var result = theadstart + Parameters + theadend + tbodystart + trstart + bp_max + trend + trstart + bp_min + trend + trstart + Hpulse_rate + trend + trstart + Hspo2 + trend + trstart + Hhypoglycemia_episodes + trend + tbodyend
                              $('#tbl_observation').html(result);
                          }
                          if (data.Table.length > 0) {
                              var bp_max = [], bp_min = [], pulse_rate = [], spo2 = [], hypoglycemia_episodes = [], maxDate = [], minDate = [], pulseDate = [], spo2Date = [], hypoglycemiaDate = [];
                              for (var i = 0; i < data.Table.length; i++) {
                                  if (data.Table[i].patient_bp_max != '' && data.Table[i].patient_bp_max != null && data.Table[i].patient_bp_max != 0) {
                                      bp_max.push(data.Table[i].patient_bp_max);
                                      maxDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].patient_bp_min != '' && data.Table[i].patient_bp_min != null && data.Table[i].patient_bp_min != 0) {
                                      bp_min.push(data.Table[i].patient_bp_min);
                                      minDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].pulse_rate != '' && data.Table[i].pulse_rate != null && data.Table[i].pulse_rate != 0) {
                                      pulse_rate.push(data.Table[i].pulse_rate);
                                      pulseDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].spo2 != '' && data.Table[i].spo2 != null && data.Table[i].spo2 != 0) {
                                      spo2.push(data.Table[i].spo2);
                                      spo2Date.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].hypoglycemia_episodes != '' && data.Table[i].hypoglycemia_episodes != null && data.Table[i].hypoglycemia_episodes != 0) {
                                      hypoglycemia_episodes.push(data.Table[i].hypoglycemia_episodes);
                                      hypoglycemiaDate.push(data.Table[i].VDate);
                                  }
                              }
                              bp_max = bp_max.reverse();
                              bp_min = bp_min.reverse();
                              maxDate = maxDate.reverse();
                              pulse_rate = pulse_rate.reverse();
                              pulseDate = pulseDate.reverse();
                              spo2 = spo2.reverse();
                              spo2Date = spo2Date.reverse();
                              hypoglycemia_episodes = hypoglycemia_episodes.reverse();
                              hypoglycemiaDate = hypoglycemiaDate.reverse();
                              if (bp_max.length > 0 || bp_min > 0) {
                                  graph2(bp_max, bp_min, maxDate, 'ghydiastolic', 'Systolic', 'Diastolic');
                              }
                              else {
                                  $('#divghydiastolic').hide();
                              }
                              if (pulse_rate.length > 0) {
                                  graph1(pulse_rate, pulseDate, 'ghyPulse', 'Pulse');
                              }
                              else {
                                  $('#divghyPulse').hide();
                              }
                              if (spo2.length > 0) {
                                  graph1(spo2, spo2Date, 'ghySPO2', 'SPO2');
                              }
                              else {
                                  $('#divghySPO2').hide();
                              }
                              if (hypoglycemia_episodes.length > 0) {
                                  graph1(hypoglycemia_episodes, hypoglycemiaDate, 'ghyhypoglycemicepisodes', 'hypoglycemia Episodes');
                              }
                              else {
                                  $('#divghyhypoglycemicepisodes').hide();
                              }
                          }
                      }

                      Glycemicgraph();
                  }
              }
              else {
                  console.log(data);
              }
          }
      });
  }



  function Glycemicgraph() {

      var PaitentsTrend = {
          Dml_Indicator: 'GL',
          doctor_id: $('#doctorId').val(),
          Patient_id: $('#Hdnpatient_id').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/CaseStudy/Graph_Section',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(PaitentsTrend),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  if (jQuery.isEmptyObject((data))) {

                  }
                  else {
                      if (Object.keys(data).length > 0) {
                          var Parameters = '<th>Parameters</th>', HHbA1c = '<th>HbA1c</th>', HFastingInsulin = '<th>Fasting Insulin</th>', HHB = '<th>HB</th>';
                          if (data.Table.length > 0) {
                              var datalength = 10;
                              if (data.Table.length < 10) {
                                  datalength = data.Table.length;
                              }
                              for (var i = 0; i < datalength; i++) {
                                  Parameters = Parameters + '<th>' + data.Table[i].VDate + '</th>'
                                  var patient_hbac_record_value = '-', fasting_insulin = '-', hemoglobin = '-';
                                  if (data.Table[i].patient_hbac_record_value != null && data.Table[i].patient_hbac_record_value != '') {
                                      patient_hbac_record_value = data.Table[i].patient_hbac_record_value + ' %';
                                  }
                                  if (data.Table[i].fasting_insulin != null && data.Table[i].fasting_insulin != '') {
                                      var unit = ' mlU/L';
                                      if (data.Table[i].fasting_inslin_unit == 2) {
                                          unit = ' pmol/L'
                                      }
                                      fasting_insulin = data.Table[i].fasting_insulin + unit;
                                  }
                                  if (data.Table[i].hemoglobin != null && data.Table[i].hemoglobin != '') {
                                      hemoglobin = data.Table[i].hemoglobin + ' gms';
                                  }

                                  HHbA1c = HHbA1c + '<td>' + patient_hbac_record_value + '</td>';
                                  HFastingInsulin = HFastingInsulin + '<td>' + fasting_insulin + '</td>';
                                  HHB = HHB + '<td>' + hemoglobin + '</td>';
                              }
                              //for (var i = 0; i < 30; i++) {
                              //    if (data.Table[i].patient_blood_sugar_value != null && data.Table[i].patient_blood_sugar_value != '' && data.Table[i].) {
                              //        var unit = ' mg/dL';
                              //        if (data.Table[i].patient_blood_sugar_value == 2) {
                              //            unit = ' mmol/L'
                              //        }
                              //        fasting_insulin = data.Table[i].fasting_insulin + unit;
                              //    }
                              //}

                              var theadstart = '<thead><tr>'
                              var theadend = '</tr></thead>'
                              var tbodystart = '<tbody>'
                              var tbodyend = '</tbody>'
                              var trstart = '<tr>';
                              var trend = '</tr>';
                              var result = theadstart + Parameters + theadend + tbodystart + trstart + HHbA1c + trend + trstart + HFastingInsulin + trend + trstart + HHB + trend + tbodyend;
                              $('#tbl_Glycemic').html(result);
                          }
                          if (data.Table.length > 0) {
                              var HbA1c = [], fasting_insulin = [], hemoglobin = [], HbA1cDate = [], fasting_insulinDate = [], hemoglobinDate = [];
                              for (var i = 0; i < data.Table.length; i++) {
                                  if (data.Table[i].patient_hbac_record_value != '' && data.Table[i].patient_hbac_record_value != null && data.Table[i].patient_hbac_record_value != 0) {
                                      HbA1c.push(data.Table[i].patient_hbac_record_value);
                                      HbA1cDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].fasting_insulin != '' && data.Table[i].fasting_insulin != null && data.Table[i].fasting_insulin != 0) {
                                      fasting_insulin.push(data.Table[i].fasting_insulin);
                                      fasting_insulinDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].hemoglobin != '' && data.Table[i].hemoglobin != null && data.Table[i].hemoglobin != 0) {
                                      hemoglobin.push(data.Table[i].hemoglobin);
                                      hemoglobinDate.push(data.Table[i].VDate);
                                  }
                              }
                              HbA1c = HbA1c.reverse();
                              HbA1cDate = HbA1cDate.reverse();
                              fasting_insulin = fasting_insulin.reverse();
                              fasting_insulinDate = fasting_insulinDate.reverse();
                              hemoglobin = hemoglobin.reverse();
                              hemoglobinDate = hemoglobinDate.reverse();

                              if (HbA1c.length > 0) {
                                  graph1(HbA1c, HbA1cDate, 'ghyHbA1c', 'HbA1c');
                              }
                              else {
                                  $('#divghyHbA1c').hide();
                              }
                              if (fasting_insulin.length > 0) {
                                  graph1(fasting_insulin, fasting_insulinDate, 'ghyfasting_insulinDate', 'Fasting Insulin');
                              }
                              else {
                                  $('#divghyfasting_insulinDate').hide();
                              }
                              if (hemoglobin.length > 0) {
                                  graph1(hemoglobin, hemoglobinDate, 'ghyHB', 'HB');
                              }
                              else {
                                  $('#divghyHB').hide();
                              }
                          }
                      }
                      bloodgraph();
                  }
              }
              else {
                  console.log(data);
              }
          }
      });
  }


  function bloodgraph() {
      var PaitentsTrend = {
          Dml_Indicator: 'SU',
          doctor_id: $('#doctorId').val(),
          Patient_id: $('#Hdnpatient_id').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/CaseStudy/Graph_Section',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(PaitentsTrend),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  if (jQuery.isEmptyObject((data))) {

                  }
                  else {
                      if (Object.keys(data).length > 0) {

                          if (data.Table.length > 0) {
                              var su1 = [], su1Date = [], su2 = [], su2Date = [], su3 = [], su3Date = [], su4 = [], su4Date = [], su5 = [], su5Date = [], su6 = [], su6Date = [], su7 = [], su7Date = [], su8 = [], su8Date = [];
                              for (var i = 0; i < data.Table.length; i++) {
                                  if (data.Table[i].patient_blood_sugar_value != '' && data.Table[i].patient_blood_sugar_value != null && data.Table[i].patient_blood_sugar_value != 0 && data.Table[i].patient_blood_sugar_type == 1) {
                                      su1.push(data.Table[i].patient_blood_sugar_value);
                                      su1Date.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].patient_blood_sugar_value != '' && data.Table[i].patient_blood_sugar_value != null && data.Table[i].patient_blood_sugar_value != 0 && data.Table[i].patient_blood_sugar_type == 2) {
                                      su2.push(data.Table[i].patient_blood_sugar_value);
                                      su2Date.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].patient_blood_sugar_value != '' && data.Table[i].patient_blood_sugar_value != null && data.Table[i].patient_blood_sugar_value != 0 && data.Table[i].patient_blood_sugar_type == 3) {
                                      su3.push(data.Table[i].patient_blood_sugar_value);
                                      su3Date.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].patient_blood_sugar_value != '' && data.Table[i].patient_blood_sugar_value != null && data.Table[i].patient_blood_sugar_value != 0 && data.Table[i].patient_blood_sugar_type == 4) {
                                      su4.push(data.Table[i].patient_blood_sugar_value);
                                      su4Date.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].patient_blood_sugar_value != '' && data.Table[i].patient_blood_sugar_value != null && data.Table[i].patient_blood_sugar_value != 0 && data.Table[i].patient_blood_sugar_type == 5) {
                                      su5.push(data.Table[i].patient_blood_sugar_value);
                                      su5Date.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].patient_blood_sugar_value != '' && data.Table[i].patient_blood_sugar_value != null && data.Table[i].patient_blood_sugar_value != 0 && data.Table[i].patient_blood_sugar_type == 6) {
                                      su6.push(data.Table[i].patient_blood_sugar_value);
                                      su6Date.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].patient_blood_sugar_value != '' && data.Table[i].patient_blood_sugar_value != null && data.Table[i].patient_blood_sugar_value != 0 && data.Table[i].patient_blood_sugar_type == 7) {
                                      su7.push(data.Table[i].patient_blood_sugar_value);
                                      su7Date.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].patient_blood_sugar_value != '' && data.Table[i].patient_blood_sugar_value != null && data.Table[i].patient_blood_sugar_value != 0 && data.Table[i].patient_blood_sugar_type == 8) {
                                      su8.push(data.Table[i].patient_blood_sugar_value);
                                      su8Date.push(data.Table[i].VDate);
                                  }
                              }
                              if (su1.length > 0) {
                                  graph1(su1, su1Date, 'ghybs1', 'Fasting blood sugar');
                              }
                              else {
                                  $('#divghybs1').hide();
                              }
                              if (su2.length > 0) {
                                  graph1(su2, su2Date, 'ghybs2', 'Postprandial blood sugar');
                              }
                              else {
                                  $('#divghybs2').hide();
                              }
                              if (su3.length > 0) {
                                  graph1(su3, su3Date, 'ghybs3', 'Random blood sugar');
                              }
                              else {
                                  $('#divghybs3').hide();
                              }
                              if (su4.length > 0) {
                                  graph1(su4, su4Date, 'ghybs4', 'Before Lunch BS');
                              }
                              else {
                                  $('#divghybs4').hide();
                              }
                              if (su5.length > 0) {
                                  graph1(su5, su5Date, 'ghybs5', 'Before Dinner BS');
                              }
                              else {
                                  $('#divghybs5').hide();
                              }
                              if (su6.length > 0) {
                                  graph1(su6, su6Date, 'ghybs6', '3 Am BS');
                              }
                              else {
                                  $('#divghybs6').hide();
                              }
                              if (su7.length > 0) {
                                  graph1(su7, su7Date, 'ghybs7', 'After Lunch BS');
                              }
                              else {
                                  $('#divghybs7').hide();
                              }
                              if (su8.length > 0) {
                                  graph1(su8, su8Date, 'ghybs8', 'After Dinner BS');
                              }
                              else {
                                  $('#divghybs8').hide();
                              }
                          }
                      }
                      renalgraph();
                  }
              }
              else {
                  console.log(data);
              }
          }
      });
  }

  function renalgraph() {
      var PaitentsTrend = {
          Dml_Indicator: 'RE',
          doctor_id: $('#doctorId').val(),
          Patient_id: $('#Hdnpatient_id').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/CaseStudy/Graph_Section',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(PaitentsTrend),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  if (jQuery.isEmptyObject((data))) {

                  }
                  else {
                      if (Object.keys(data).length > 0) {
                          var Parameters = '<th>Parameters</th>', HUrea = '<th>Urea</th>', HCreatinine = '<th>Creatinine</th>', HEGFR = '<th>EGFR</th>', HSodium = '<th>Sodium( Na )</th>',
                              HPotassium = '<th>Potassium( k )</th>', HChlorine = '<th>Chloride( Cl )</th>', HBiCarbonate = '<th>BiCarbonate( HCO3 )</th>', HCalcium = '<th>Calcium( Ca )</th>',
                              HPhosphorus = '<th>Phosphorus( P )</th>', HMagnesium = '<th>Magnesium( Mg )</th>';
                          if (data.Table.length > 0) {
                              var datalength = 10;
                              if (data.Table.length < 10) {
                                  datalength = data.Table.length;
                              }
                              for (var i = 0; i < datalength; i++) {
                                  Parameters = Parameters + '<th>' + data.Table[i].VDate + '</th>'
                                  var Urea = '-', Creatinine = '-', EGFR = '-', Sodium = '-', Potassium = '-', Chlorine = '-', BiCarbonate = '-', Calcium = '-', Phosphorus = '-', Magnesium = '-';

                                  if (data.Table[i].Urea != null && data.Table[i].Urea != '') {
                                      var Unit = ' mmol/L';
                                      if (data.Table[i].urea_unit == 2) {
                                          Unit = ' mg/dL';
                                      }
                                      Urea = data.Table[i].Urea + Unit;
                                  }
                                  if (data.Table[i].creatinine != null && data.Table[i].creatinine != '') {
                                      var unit = ' µmol/L';
                                      if (data.Table[i].Creatinine == 2) {
                                          unit = ' mg/dL'
                                      }
                                      Creatinine = data.Table[i].creatinine + unit;
                                  }
                                  if (data.Table[i].egfr_value != null && data.Table[i].egfr_value != '') {
                                      EGFR = data.Table[i].egfr_value + ' gms';
                                  }
                                  if (data.Table[i].Sodium != null && data.Table[i].Sodium != '') {
                                      var Unit = ' mmol/L';
                                      if (data.Table[i].sodium_unit == 2) {
                                          Unit = ' mEq/L';
                                      }
                                      Sodium = data.Table[i].Sodium + Unit;
                                  }
                                  if (data.Table[i].Potassium != null && data.Table[i].Potassium != '') {
                                      var Unit = ' mmol/L';
                                      if (data.Table[i].potassium_unit == 2) {
                                          Unit = ' mEq/L';
                                      }
                                      Potassium = data.Table[i].Potassium + Unit;
                                  }

                                  if (data.Table[i].Chlorine != null && data.Table[i].Chlorine != '') {
                                      var Unit = ' mmol/L';
                                      if (data.Table[i].chlorine_unit == 2) {
                                          Unit = ' mEq/L';
                                      }
                                      Chlorine = data.Table[i].Chlorine + Unit;
                                  }

                                  if (data.Table[i].BiCarbonate != null && data.Table[i].BiCarbonate != '') {
                                      var Unit = ' mmol/L';
                                      if (data.Table[i].Bicarbonate_unit == 2) {
                                          Unit = ' mEq/L';
                                      }
                                      BiCarbonate = data.Table[i].BiCarbonate + Unit;
                                  }

                                  if (data.Table[i].serium_calcium != null && data.Table[i].serium_calcium != '') {
                                      var Unit = ' mmol/L';
                                      if (data.Table[i].Calcium_unit == 2) {
                                          Unit = ' mEq/L';
                                      }
                                      Calcium = data.Table[i].serium_calcium + Unit;
                                  }

                                  if (data.Table[i].serium_phosphorous != null && data.Table[i].serium_phosphorous != '') {
                                      var Unit = ' mmol/L';
                                      if (data.Table[i].Phosphorus_unit == 2) {
                                          Unit = ' mEq/L';
                                      }
                                      Phosphorus = data.Table[i].serium_phosphorous + Unit;
                                  }

                                  if (data.Table[i].serium_magnesium != null && data.Table[i].serium_magnesium != '') {
                                      var Unit = ' mmol/L';
                                      if (data.Table[i].Magnesium_unit == 2) {
                                          Unit = ' mEq/L';
                                      }
                                      Magnesium = data.Table[i].serium_magnesium + Unit;
                                  }



                                  HUrea = HUrea + '<td>' + Urea + '</td>';
                                  HCreatinine = HCreatinine + '<td>' + Creatinine + '</td>';
                                  HEGFR = HEGFR + '<td>' + EGFR + '</td>';
                                  HSodium = HSodium + '<td>' + Sodium + '</td>';
                                  HPotassium = HPotassium + '<td>' + Potassium + '</td>';
                                  HChlorine = HChlorine + '<td>' + Chlorine + '</td>';
                                  HBiCarbonate = HBiCarbonate + '<td>' + BiCarbonate + '</td>';
                                  HCalcium = HCalcium + '<td>' + Calcium + '</td>';
                                  HPhosphorus = HPhosphorus + '<td>' + Phosphorus + '</td>';
                                  HMagnesium = HMagnesium + '<td>' + Magnesium + '</td>';
                              }

                              var theadstart = '<thead><tr>'
                              var theadend = '</tr></thead>'
                              var tbodystart = '<tbody>'
                              var tbodyend = '</tbody>'
                              var trstart = '<tr>';
                              var trend = '</tr>';
                              var result = theadstart + Parameters + theadend + tbodystart + trstart + HUrea + trend + trstart + HCreatinine + trend + trstart + HEGFR + trend
                                  + trstart + HSodium + trend + trstart + HPotassium + trend + trstart + HChlorine + trend + trstart + HBiCarbonate + trend
                                  + trstart + HCalcium + trend + trstart + HPhosphorus + trend + trstart + HMagnesium + trend + tbodyend;
                              $('#tbl_renal').html(result);
                          }
                          if (data.Table.length > 0) {
                              var Urea = [], UreaDate = [], creatinine = [], creatinineDate = [], EGFR = [], EGFRDate = [], Sodium = [], SodiumDate = [],
                              Potassium = [], PotassiumDate = [], Chlorine = [], ChlorineDate = [], BiCarbonate = [], BiCarbonateDate = [], Calcium = [], CalciumDate = []
                              Phosphorus = [], PhosphorusDate = [], Magnesium = [], MagnesiumDate = [];
                              for (var i = 0; i < data.Table.length; i++) {
                                  if (data.Table[i].Urea != '' && data.Table[i].Urea != null && data.Table[i].Urea != 0) {
                                      Urea.push(data.Table[i].Urea);
                                      UreaDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].creatinine != '' && data.Table[i].creatinine != null && data.Table[i].creatinine != 0) {
                                      creatinine.push(data.Table[i].creatinine);
                                      creatinineDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].egfr_value != '' && data.Table[i].egfr_value != null && data.Table[i].egfr_value != 0) {
                                      EGFR.push(data.Table[i].egfr_value);
                                      EGFRDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].Sodium != '' && data.Table[i].Sodium != null && data.Table[i].Sodium != 0) {
                                      Sodium.push(data.Table[i].Sodium);
                                      SodiumDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].Potassium != '' && data.Table[i].Potassium != null && data.Table[i].Potassium != 0) {
                                      Potassium.push(data.Table[i].Potassium);
                                      PotassiumDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].Chlorine != '' && data.Table[i].Chlorine != null && data.Table[i].Chlorine != 0) {
                                      Chlorine.push(data.Table[i].Chlorine);
                                      ChlorineDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].BiCarbonate != '' && data.Table[i].BiCarbonate != null && data.Table[i].BiCarbonate != 0) {
                                      BiCarbonate.push(data.Table[i].BiCarbonate);
                                      BiCarbonateDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].serium_calcium != '' && data.Table[i].serium_calcium != null && data.Table[i].serium_calcium != 0) {
                                      Calcium.push(data.Table[i].serium_calcium);
                                      CalciumDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].serium_phosphorous != '' && data.Table[i].serium_phosphorous != null && data.Table[i].serium_phosphorous != 0) {
                                      Phosphorus.push(data.Table[i].serium_phosphorous);
                                      PhosphorusDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].serium_magnesium != '' && data.Table[i].serium_magnesium != null && data.Table[i].serium_magnesium != 0) {
                                      Magnesium.push(data.Table[i].serium_magnesium);
                                      MagnesiumDate.push(data.Table[i].VDate);
                                  }
                              }
                              Urea = Urea.reverse();
                              UreaDate = UreaDate.reverse();
                              creatinine = creatinine.reverse();
                              creatinineDate = creatinineDate.reverse();
                              EGFR = EGFR.reverse();
                              EGFRDate = EGFRDate.reverse();
                              Sodium = Sodium.reverse();
                              SodiumDate = SodiumDate.reverse();
                              Potassium = Potassium.reverse();
                              PotassiumDate = PotassiumDate.reverse();
                              Chlorine = Chlorine.reverse();
                              ChlorineDate = ChlorineDate.reverse();
                              BiCarbonate = BiCarbonate.reverse();
                              BiCarbonateDate = BiCarbonateDate.reverse();
                              Calcium = Calcium.reverse();
                              CalciumDate = CalciumDate.reverse();
                              Phosphorus = Phosphorus.reverse();
                              PhosphorusDate = PhosphorusDate.reverse();
                              Magnesium = Magnesium.reverse();
                              MagnesiumDate = MagnesiumDate.reverse();

                              if (Urea.length > 0) {
                                  graph1(Urea, UreaDate, 'ghyUrea', 'Urea');
                              }
                              else {
                                  $('#divghyUrea').hide();
                              }
                              if (creatinine.length > 0) {
                                  graph1(creatinine, creatinineDate, 'ghyCreatinine', 'Creatinine');
                              }
                              else {
                                  $('#divghyCreatinine').hide();
                              }
                              if (EGFR.length > 0) {
                                  graph1(EGFR, EGFRDate, 'ghyEGFR', 'EGFR ( Calculated )');
                              }
                              else {
                                  $('#divghyEGFR').hide();
                              }
                              if (Sodium.length > 0) {
                                  graph1(Sodium, SodiumDate, 'ghySodium', 'Sodium( Na )');
                              }
                              else {
                                  $('#divghySodium').hide();
                              }
                              if (Potassium.length > 0) {
                                  graph1(Potassium, PotassiumDate, 'ghyPotassium', 'Potassium( k )');
                              }
                              else {
                                  $('#divghyPotassium').hide();
                              }
                              if (Chlorine.length > 0) {
                                  graph1(Chlorine, ChlorineDate, 'ghyChloride', 'Chloride( Cl )');
                              }
                              else {
                                  $('#divghyChloride').hide();
                              }
                              if (BiCarbonate.length > 0) {
                                  graph1(BiCarbonate, BiCarbonateDate, 'ghyBiCarbonate', 'BiCarbonate( HCO3 )');
                              }
                              else {
                                  $('#divghyBiCarbonate').hide();
                              }
                              if (Calcium.length > 0) {
                                  graph1(Calcium, CalciumDate, 'ghyCalcium', 'Calcium( Ca )');
                              }
                              else {
                                  $('#divghyCalcium').hide();
                              }
                              if (Phosphorus.length > 0) {
                                  graph1(Phosphorus, PhosphorusDate, 'ghyPhosphorus', 'Phosphorus( P )');
                              }
                              else {
                                  $('#divghyPhosphorus').hide();
                              }
                              if (Magnesium.length > 0) {
                                  graph1(Magnesium, MagnesiumDate, 'ghyMagnesium', 'Magnesium( Mg )');
                              }
                              else {
                                  $('#divghyMagnesium').hide();
                              }
                          }
                      }
                      cholesterolgraph();

                  }
              }
              else {
                  console.log(data);
              }
          }
      });
  }


  function cholesterolgraph() {

      var PaitentsTrend = {
          Dml_Indicator: 'CH',
          doctor_id: $('#doctorId').val(),
          Patient_id: $('#Hdnpatient_id').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/CaseStudy/Graph_Section',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(PaitentsTrend),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  if (jQuery.isEmptyObject((data))) {

                  }
                  else {
                      if (Object.keys(data).length > 0) {
                          var Parameters = '<th>Parameters</th>', HTotalCholesterol = '<th>Total Cholesterol</th>', HLDL = '<th>LDL (Low Density Lipoproteins)</th>', HHDL = '<th>HDL (High Density Lipoproteins)</th>',
                              HVLDL = '<th>VLDL</th>', HTriglycerides = '<th>Triglycerides</th>', HHDLRatio = '<th>Total Cholesterol : HDL Ratio</th>';
                          if (data.Table.length > 0) {
                              var datalength = 10;
                              if (data.Table.length < 10) {
                                  datalength = data.Table.length;
                              }
                              for (var i = 0; i < datalength; i++) {
                                  Parameters = Parameters + '<th>' + data.Table[i].VDate + '</th>'
                                  var TotalCholesterol = '-', LDL = '-', HDL = '-', VLDL = '-', Triglycerides = '-', HDLRatio = '-';
                                  if (data.Table[i].Total_Cholestrol != null && data.Table[i].Total_Cholestrol != '') {
                                      var unit = ' mg/dL';
                                      if (data.Table[i].Total_cholestrol_unit == 2) {
                                          unit = ' mmol/L'
                                      }
                                      TotalCholesterol = data.Table[i].Total_Cholestrol + unit;
                                  }

                                  if (data.Table[i].LDL != null && data.Table[i].LDL != '') {
                                      var unit = ' mg/dL';
                                      if (data.Table[i].LDL_unit == 2) {
                                          unit = ' mmol/L'
                                      }
                                      LDL = data.Table[i].LDL + unit;
                                  }

                                  if (data.Table[i].HDL != null && data.Table[i].HDL != '') {
                                      var unit = ' mg/dL';
                                      if (data.Table[i].HDL_unit == 2) {
                                          unit = ' mmol/L'
                                      }
                                      HDL = data.Table[i].HDL + unit;
                                  }

                                  if (data.Table[i].VLDL != null && data.Table[i].VLDL != '') {
                                      var unit = ' mg/dL';
                                      if (data.Table[i].VLDL_unit == 2) {
                                          unit = ' mmol/L'
                                      }
                                      VLDL = data.Table[i].VLDL + unit;
                                  }

                                  if (data.Table[i].Triglycerides != null && data.Table[i].Triglycerides != '') {
                                      var unit = ' mg/dL';
                                      if (data.Table[i].Triglycerides_unit == 2) {
                                          unit = ' mmol/L'
                                      }
                                      Triglycerides = data.Table[i].Triglycerides + unit;
                                  }

                                  if (data.Table[i].T_cholestrol_Hdl_ratio != null && data.Table[i].T_cholestrol_Hdl_ratio != '') {

                                      HDLRatio = data.Table[i].T_cholestrol_Hdl_ratio;
                                  }

                                  HTotalCholesterol = HTotalCholesterol + '<td>' + TotalCholesterol + '</td>';
                                  HLDL = HLDL + '<td>' + LDL + '</td>';
                                  HHDL = HHDL + '<td>' + HDL + '</td>';
                                  HVLDL = HVLDL + '<td>' + VLDL + '</td>';
                                  HTriglycerides = HTriglycerides + '<td>' + Triglycerides + '</td>';
                                  HHDLRatio = HHDLRatio + '<td>' + HDLRatio + '</td>';
                              }

                              var theadstart = '<thead><tr>'
                              var theadend = '</tr></thead>'
                              var tbodystart = '<tbody>'
                              var tbodyend = '</tbody>'
                              var trstart = '<tr>';
                              var trend = '</tr>';
                              var result = theadstart + Parameters + theadend + tbodystart + trstart + HTotalCholesterol + trend + trstart + HLDL + trend + trstart + HHDL + trend +
                                  trstart + HVLDL + trend + trstart + HTriglycerides + trend + trstart + HHDLRatio + trend + tbodyend;
                              $('#tbl_cholestrol').html(result);
                          }
                          if (data.Table.length > 0) {
                              var TotalCholesterol = [], TotalCholesterolDate = [], LDL = [], LDLDate = [], HDL = [], HDLDate = []
                              VLDL = [], VLDLDate = [], Triglycerides = [], TriglyceridesDate = [], HDLRatio = [], HDLRatioDate = [];

                              for (var i = 0; i < data.Table.length; i++) {
                                  if (data.Table[i].patient_hbac_record_value != '' && data.Table[i].patient_hbac_record_value != null && data.Table[i].patient_hbac_record_value != 0) {
                                      TotalCholesterol.push(data.Table[i].Total_Cholestrol);
                                      TotalCholesterolDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].LDL != '' && data.Table[i].LDL != null && data.Table[i].LDL != 0) {
                                      LDL.push(data.Table[i].LDL);
                                      LDLDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].HDL != '' && data.Table[i].HDL != null && data.Table[i].HDL != 0) {
                                      HDL.push(data.Table[i].HDL);
                                      HDLDate.push(data.Table[i].VDate);
                                  }

                                  if (data.Table[i].VLDL != '' && data.Table[i].VLDL != null && data.Table[i].VLDL != 0) {
                                      VLDL.push(data.Table[i].VLDL);
                                      VLDLDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].Triglycerides != '' && data.Table[i].Triglycerides != null && data.Table[i].Triglycerides != 0) {
                                      Triglycerides.push(data.Table[i].Triglycerides);
                                      TriglyceridesDate.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].T_cholestrol_Hdl_ratio != '' && data.Table[i].T_cholestrol_Hdl_ratio != null && data.Table[i].T_cholestrol_Hdl_ratio != 0) {
                                      HDLRatio.push(data.Table[i].T_cholestrol_Hdl_ratio);
                                      HDLRatioDate.push(data.Table[i].VDate);
                                  }
                              }
                              TotalCholesterol = TotalCholesterol.reverse();
                              TotalCholesterolDate = TotalCholesterolDate.reverse();
                              LDL = LDL.reverse();
                              LDLDate = LDLDate.reverse();
                              HDL = HDL.reverse();
                              HDLDate = HDLDate.reverse();
                              VLDL = VLDL.reverse();
                              VLDLDate = VLDLDate.reverse();
                              Triglycerides = Triglycerides.reverse();
                              TriglyceridesDate = TriglyceridesDate.reverse();
                              HDLRatio = HDLRatio.reverse();
                              HDLRatioDate = HDLRatioDate.reverse();

                              if (TotalCholesterol.length > 0) {
                                  graph1(TotalCholesterol, TotalCholesterolDate, 'ghyTotalCholesterol', 'Total Cholesterol');
                              }
                              else {
                                  $('#divghyTotalCholesterol').hide();
                              }
                              if (LDL.length > 0) {
                                  graph1(LDL, LDLDate, 'ghyLDL', 'LDL (Low Density Lipoproteins)');
                              }
                              else {
                                  $('#divghyLDL').hide();
                              }
                              if (HDL.length > 0) {
                                  graph1(HDL, HDLDate, 'ghyHDL', 'HDL (High Density Lipoproteins)');
                              }
                              else {
                                  $('#divghyHDL').hide();
                              }
                              if (VLDL.length > 0) {
                                  graph1(VLDL, VLDLDate, 'ghyVLDL', 'VLDL');
                              }
                              else {
                                  $('#divghyVLDL').hide();
                              }
                              if (Triglycerides.length > 0) {
                                  graph1(Triglycerides, TriglyceridesDate, 'ghyTriglycerides', 'Triglycerides');
                              }
                              else {
                                  $('#divghyTriglycerides').hide();
                              }
                              if (HDLRatio.length > 0) {
                                  graph1(HDLRatio, HDLRatioDate, 'ghyHDLRatio', 'Total Cholesterol : HDL Ratio');
                              }
                              else {
                                  $('#divghyHDLRatio').hide();
                              }
                          }
                      }
                      Cardiacgraph();

                  }
              }
              else {
                  console.log(data);
              }
          }
      });
  }


  function Cardiacgraph() {
      var PaitentsTrend = {
          Dml_Indicator: 'CA',
          doctor_id: $('#doctorId').val(),
          Patient_id: $('#Hdnpatient_id').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/CaseStudy/Graph_Section',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(PaitentsTrend),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  if (jQuery.isEmptyObject((data))) {

                  }
                  else {
                      if (Object.keys(data).length > 0) {
                          var Parameters = '<th>Parameters</th>', HEjectionFraction = '<th>Ejection Fraction</th>';
                          if (data.Table.length > 0) {
                              var datalength = 10;
                              if (data.Table.length < 10) {
                                  datalength = data.Table.length;
                              }
                              for (var i = 0; i < datalength; i++) {
                                  Parameters = Parameters + '<th>' + data.Table[i].VDate + '</th>'
                                  var EjectionFraction = '-';
                                  if (data.Table[i].fraction != null && data.Table[i].fraction != '') {
                                      EjectionFraction = data.Table[i].fraction;
                                  }
                                  HEjectionFraction = HEjectionFraction + '<td>' + EjectionFraction + '</td>';
                              }

                              var theadstart = '<thead><tr>'
                              var theadend = '</tr></thead>'
                              var tbodystart = '<tbody>'
                              var tbodyend = '</tbody>'
                              var trstart = '<tr>';
                              var trend = '</tr>';
                              var result = theadstart + Parameters + theadend + tbodystart + trstart + HEjectionFraction + trend + tbodyend;
                              $('#tbl_cardiac').html(result);
                          }
                          if (data.Table.length > 0) {
                              var EjectionFraction = [], EjectionFractionDate = [];
                              for (var i = 0; i < data.Table.length; i++) {
                                  if (data.Table[i].fraction != '' && data.Table[i].fraction != null && data.Table[i].fraction != 0) {
                                      EjectionFraction.push(data.Table[i].fraction);
                                      EjectionFractionDate.push(data.Table[i].VDate);
                                  }
                              }
                              EjectionFraction = EjectionFraction.reverse();
                              EjectionFractionDate = EjectionFractionDate.reverse();
                              if (EjectionFraction.length > 0) {
                                  graph1(EjectionFraction, EjectionFractionDate, 'ghyEjectionFraction', 'Ejection Fraction');
                              }
                              else {
                                  $('#divghyEjectionFraction').hide();
                              }
                          }
                      }
                      Thyroidgraph();
                  }
              }
              else {
                  console.log(data);
              }
          }
      });
  }

  function Thyroidgraph() {
      var PaitentsTrend = {
          Dml_Indicator: 'TH',
          doctor_id: $('#doctorId').val(),
          Patient_id: $('#Hdnpatient_id').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/CaseStudy/Graph_Section',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(PaitentsTrend),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  if (jQuery.isEmptyObject((data))) {

                  }
                  else {
                      if (Object.keys(data).length > 0) {
                          var Parameters = '<th>Parameters</th>', HT3 = '<th>Free T3</th>', HT4 = '<th>Free T4</th>', HTSH = '<th>TSH</th>', HN_T3 = '<th>T3</th>', HN_T4 = '<th>T4</th>';
                          if (data.Table.length > 0) {
                              var datalength = 10;
                              if (data.Table.length < 10) {
                                  datalength = data.Table.length;
                              }
                              for (var i = 0; i < datalength; i++) {
                                  Parameters = Parameters + '<th>' + data.Table[i].VDate + '</th>'
                                  var T3 = '-', T4 = '-', TSH = '-', N_T3 = '-', N_T4 = '-';
                                  if (data.Table[i].Free_T3 != null && data.Table[i].Free_T3 != '') {
                                      T3 = data.Table[i].Free_T3 + ' Pg/dL';
                                  }
                                  if (data.Table[i].Free_T4 != null && data.Table[i].Free_T4 != '') {
                                      T4 = data.Table[i].Free_T4 + ' ng/dL';
                                  }
                                  if (data.Table[i].TSH != null && data.Table[i].TSH != '') {
                                      TSH = data.Table[i].TSH + ' mIU/mL';
                                  }
                                  if (data.Table[i].T3 != null && data.Table[i].T3 != '') {
                                      N_T3 = data.Table[i].T3 + ' Pg/dL';
                                  }
                                  if (data.Table[i].T4 != null && data.Table[i].T4 != '') {
                                      N_T4 = data.Table[i].T4 + ' ng/dL';
                                  }

                                  HT3 = HT3 + '<td>' + T3 + '</td>';
                                  HT4 = HT4 + '<td>' + T4 + '</td>';
                                  HN_T3 = HN_T3 + '<td>' + N_T3 + '</td>';
                                  HN_T4 = HN_T4 + '<td>' + N_T4 + '</td>';
                                  HTSH = HTSH + '<td>' + TSH + '</td>';
                              }

                              var theadstart = '<thead><tr>'
                              var theadend = '</tr></thead>'
                              var tbodystart = '<tbody>'
                              var tbodyend = '</tbody>'
                              var trstart = '<tr>';
                              var trend = '</tr>';
                              var result = theadstart + Parameters + theadend + tbodystart + trstart + HT3 + trend + trstart + HT4 + trend + trstart + HN_T3 + trend + trstart + HN_T4 + trend + trstart + HTSH + trend + tbodyend;
                              $('#tbl_thyroid').html(result);
                          }
                          if (data.Table.length > 0) {
                              var T3 = [], T3Date = [], T4 = [], T4Date = [], TSH = [], TSHDate = [], N_T3 = [], N_T3Date = [], N_T4 = [], N_T4Date = [];
                              for (var i = 0; i < data.Table.length; i++) {
                                  if (data.Table[i].Free_T3 != '' && data.Table[i].Free_T3 != null && data.Table[i].Free_T3 != 0) {
                                      T3.push(data.Table[i].Free_T3);
                                      T3Date.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].Free_T4 != '' && data.Table[i].Free_T4 != null && data.Table[i].Free_T4 != 0) {
                                      T4.push(data.Table[i].Free_T4);
                                      T4Date.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].T3 != '' && data.Table[i].T3 != null && data.Table[i].T3 != 0) {
                                      N_T3.push(data.Table[i].T3);
                                      N_T3Date.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].T4 != '' && data.Table[i].T4 != null && data.Table[i].T4 != 0) {
                                      N_T4.push(data.Table[i].T4);
                                      N_T4Date.push(data.Table[i].VDate);
                                  }
                                  if (data.Table[i].TSH != '' && data.Table[i].TSH != null && data.Table[i].TSH != 0) {
                                      TSH.push(data.Table[i].TSH);
                                      TSHDate.push(data.Table[i].VDate);
                                  }
                              }
                              T3 = T3.reverse();
                              T3Date = T3Date.reverse();
                              T4 = T4.reverse();
                              T4Date = T4Date.reverse();
                              N_T3 = N_T3.reverse();
                              N_T3Date = N_T3Date.reverse();
                              N_T4 = N_T4.reverse();
                              N_T4Date = N_T4Date.reverse();
                              TSH = TSH.reverse();
                              TSHDate = TSHDate.reverse();

                              if (T3.length > 0) {
                                  graph1(T3, T3Date, 'ghyT3', 'Free T3');
                              }
                              else {
                                  $('#divghyT3').hide();
                              }
                              if (T4.length > 0) {
                                  graph1(T4, T4Date, 'ghyT4', 'Free T4');
                              }
                              else {
                                  $('#divghyT4').hide();
                              }
                              if (N_T3.length > 0) {
                                  graph1(N_T3, T3Date, 'ghyNT3', 'T3');
                              }
                              else {
                                  $('#divghyNT3').hide();
                              }
                              if (N_T4.length > 0) {
                                  graph1(N_T4, T4Date, 'ghyNT4', 'T4');
                              }
                              else {
                                  $('#divghyNT4').hide();
                              }
                              if (TSH.length > 0) {
                                  graph1(TSH, TSHDate, 'ghyTSH', 'TSH');
                              }
                              else {
                                  $('#divghyTSH').hide();
                              }
                          }
                      }
                  }
                  CBCGraph();
              }
              else {
                  console.log(data);
              }
          }
      });
  }
  //load cbc graph
  function CBCGraph() {
      var PaitentsTrend = {
          Dml_Indicator: 'CS',
          doctor_id: $('#doctorId').val(),
          Patient_id: $('#Hdnpatient_id').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/CaseStudy/Graph_Section',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(PaitentsTrend),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  if (jQuery.isEmptyObject((data))) {

                  }
                  else {
                      if (Object.keys(data).length > 0) {

                          var Parameters = '<th>Parameters</th>', hemoglobin = '<th>HEMOGLOBIN</th>', plateletCount = '<th>PLATELET COUNT</th>',
                              nucleatedRedBlood = '<th>NUCLEATED RED BLOOD CELLS</th>', nucleatedBloodCellPercent = '<th>NUCLEATED RED BLOOD CELLS (%)</th>', hematocrit = '<th>HEMATOCRIT(PCV)</th>',
                              lympocytePercent = '<th>LYMPHOCYTE PERCENTAGE</th>', totalLeucocytes = '<th>TOTAL LEUCOCYTES COUNT</th>', meanCorpuscular = '<th>MEAN CORPUSCULAR HEMOGLOBIN(MCH)</th>', meanCorpHemo = '<th>MEAN CORP.HEMO.CONC(MCHC)</th>', meanCorpuscularVolume = '<th>MEAN CORPUSCULAR VOLUME(MCV)</th>',
                              monocytes = '<th>MONOCYTES</th>', neutrophils = '<th>NEUTROPHILS</th>', eosinophilsCount = '<th>EOSINOPHILS - ABSOLUTE COUNT</th>',
                              basophilsCount = '<th>BASOPHILS - ABSOLUTE COUNT</th>', lymphocytesCount = '<th>LYMPHOCYTES - ABSOLUTE COUNT</th>', monocytesCount = '<th>MONOCYTES - ABSOLUTE COUNT</th>',
                              neutrophilsCount = '<th>NEUTROPHILS - ABSOLUTE COUNT</th>', basophils = '<th>BASOPHILS</th>', eosinophils = '<th>EOSINOPHILS</th>', immaturegranulo = '<th>IMMATURE GRANULOCYTES(IG)</th>',
                              immatureGranuloPercent = '<th>IMMATURE GRANULOCYTE PERCENTAGE(IG%)</th>', totalRBC = '<th>TOTAL RBC</th>', redCell = '<th>RED CELL DISTRIBUTION WIDTH (RDW-CV)</th>', redCellDistribution = '<th>RED CELL DISTRIBUTION WIDTH - SD(RDW-SD)</th>';

                          if (data.Table.length > 0) {
                              var datalength = 10;
                              if (data.Table.length < 10) {
                                  datalength = data.Table.length;
                              }
                              for (var i = 0; i < datalength; i++) {
                                  Parameters = Parameters + '<th>' + data.Table[i].VDate + '</th>';

                                  var hemoglobinValue = '-', plateletCountValue = '-', nucleatedRedBloodValue = '-', nucleatedBloodCellPercentValue = '-',
                                      hematocritValue = '-', lympocytePercentValue = '-', totalLeucocytesValue = '-', meanCorpuscularValue = '-', meanCorpHemoValue = '-', meanCorpuscularVolumeValue = '-',
                                      monocytesValue = '-', neutrophilsValue = '-', eosinophilsCountValue = '-', basophilsCountValue = '-', lymphocytesCountValue = '-',
                                      monocytesCountValue = '-', neutrophilsCountValue = '-', basophilsValue = '-', eosinophilsValue = '-', immaturegranuloValue = '-',
                                      immatureGranuloPercentValue = '-', totalRBCValue = '-', redCellValue = '-', redCellDistributionValue = '-';


                                  if (data.Table[i].hemoglobin != null && data.Table[i].hemoglobin != '') {
                                      hemoglobinValue = data.Table[i].hemoglobin + ' ' + (data.Table[i].hemoglobin_unit == null || data.Table[i].hemoglobin_unit == "" ? "" : data.Table[i].hemoglobin_unit);
                                  }
                                  if (data.Table[i].platelet_count != null && data.Table[i].platelet_count != '') {
                                      plateletCountValue = data.Table[i].platelet_count + ' ' + (data.Table[i].platelet_count_unit == null || data.Table[i].platelet_count_unit == "" ? "" : data.Table[i].platelet_count_unit);
                                  }
                                  if (data.Table[i].nucleated_red_blood_cells != null && data.Table[i].nucleated_red_blood_cells != '') {
                                      nucleatedRedBloodValue = data.Table[i].nucleated_red_blood_cells;
                                  }
                                  if (data.Table[i].nucleated_red_blood_cells_percent != null && data.Table[i].nucleated_red_blood_cells_percent != '') {
                                      nucleatedBloodCellPercentValue = data.Table[i].nucleated_red_blood_cells_percent;
                                  }
                                  if (data.Table[i].hematocrit != null && data.Table[i].hematocrit != '') {
                                      hematocritValue = data.Table[i].hematocrit;
                                  }
                                  if (data.Table[i].lymphocyte_percent != null && data.Table[i].lymphocyte_percent != '') {
                                      lympocytePercentValue = data.Table[i].lymphocyte_percent;
                                  }

                                  if (data.Table[i].total_leucocytes_count != null && data.Table[i].total_leucocytes_count != '') {
                                      totalLeucocytesValue = data.Table[i].total_leucocytes_count;
                                  }
                                  if (data.Table[i].mean_corpuscular_hemoglobin != null && data.Table[i].mean_corpuscular_hemoglobin != '') {
                                      meanCorpuscularValue = data.Table[i].mean_corpuscular_hemoglobin;
                                  }
                                  if (data.Table[i].mean_corp_hemo_conc != null && data.Table[i].mean_corp_hemo_conc != '') {
                                      meanCorpHemoValue = data.Table[i].mean_corp_hemo_conc;
                                  }
                                  if (data.Table[i].mean_corpuscular_volume != null && data.Table[i].mean_corpuscular_volume != '') {
                                      meanCorpuscularVolumeValue = data.Table[i].mean_corpuscular_volume;
                                  }
                                  if (data.Table[i].monocytes != null && data.Table[i].monocytes != '') {
                                      monocytesValue = data.Table[i].monocytes;
                                  }
                                  if (data.Table[i].neutrophils != null && data.Table[i].neutrophils != '') {
                                      neutrophilsValue = data.Table[i].neutrophils;
                                  }
                                  if (data.Table[i].eosinophils_absolute_count != null && data.Table[i].eosinophils_absolute_count != '') {
                                      eosinophilsCountValue = data.Table[i].eosinophils_absolute_count;
                                  }
                                  if (data.Table[i].basophils_absolute_count != null && data.Table[i].basophils_absolute_count != '') {
                                      basophilsCountValue = data.Table[i].basophils_absolute_count;
                                  }
                                  if (data.Table[i].lymphocytes_absolute_count != null && data.Table[i].lymphocytes_absolute_count != '') {
                                      lymphocytesCountValue = data.Table[i].lymphocytes_absolute_count;
                                  }
                                  if (data.Table[i].monocytes_absolute_count != null && data.Table[i].monocytes_absolute_count != '') {
                                      monocytesCountValue = data.Table[i].monocytes_absolute_count;
                                  }
                                  if (data.Table[i].neutrophils_absolute_count != null && data.Table[i].neutrophils_absolute_count != '') {
                                      neutrophilsCountValue = data.Table[i].neutrophils_absolute_count;
                                  }
                                  if (data.Table[i].basophils != null && data.Table[i].basophils != '') {
                                      basophilsValue = data.Table[i].basophils;
                                  }
                                  if (data.Table[i].eosinophils != null && data.Table[i].eosinophils != '') {
                                      eosinophilsValue = data.Table[i].eosinophils;
                                  }
                                  if (data.Table[i].immature_granulocytes != null && data.Table[i].immature_granulocytes != '') {
                                      immaturegranuloValue = data.Table[i].immature_granulocytes;
                                  }
                                  if (data.Table[i].immature_granulocytes_percent != null && data.Table[i].immature_granulocytes_percent != '') {
                                      immatureGranuloPercentValue = data.Table[i].immature_granulocytes_percent;
                                  }
                                  if (data.Table[i].total_rbc != null && data.Table[i].total_rbc != '') {
                                      totalRBCValue = data.Table[i].total_rbc;
                                  }
                                  if (data.Table[i].redcell_distribution_width != null && data.Table[i].redcell_distribution_width != '') {
                                      redCellValue = data.Table[i].redcell_distribution_width;
                                  }
                                  if (data.Table[i].redcell_distribution_width_sd != null && data.Table[i].redcell_distribution_width_sd != '') {
                                      redCellDistributionValue = data.Table[i].redcell_distribution_width_sd;
                                  }


                                  hemoglobin = hemoglobin + '<td>' + hemoglobinValue + '</td>';
                                  plateletCount = plateletCount + '<td>' + plateletCountValue + '</td>';
                                  nucleatedRedBlood = nucleatedRedBlood + '<td>' + nucleatedRedBloodValue + '</td>';
                                  nucleatedBloodCellPercent = nucleatedBloodCellPercent + '<td>' + nucleatedBloodCellPercentValue + '</td>';
                                  hematocrit = hematocrit + '<td>' + hematocritValue + '</td>';
                                  lympocytePercent = lympocytePercent + '<td>' + lympocytePercentValue + '</td>';
                                  totalLeucocytes = totalLeucocytes + '<td>' + totalLeucocytesValue + '</td>';
                                  meanCorpuscular = meanCorpuscular + '<td>' + meanCorpuscularValue + '</td>';
                                  meanCorpHemo = meanCorpHemo + '<td>' + meanCorpHemoValue + '</td>';
                                  meanCorpuscularVolume = meanCorpuscularVolume + '<td>' + meanCorpuscularVolumeValue + '</td>';
                                  monocytes = monocytes + '<td>' + monocytesValue + '</td>';
                                  neutrophils = neutrophils + '<td>' + neutrophilsValue + '</td>';
                                  eosinophilsCount = eosinophilsCount + '<td>' + eosinophilsCountValue + '</td>';
                                  basophilsCount = basophilsCount + '<td>' + basophilsCountValue + '</td>';
                                  lymphocytesCount = lymphocytesCount + '<td>' + lymphocytesCountValue + '</td>';
                                  monocytesCount = monocytesCount + '<td>' + monocytesCountValue + '</td>';
                                  neutrophilsCount = neutrophilsCount + '<td>' + neutrophilsCountValue + '</td>';
                                  basophils = basophils + '<td>' + basophilsValue + '</td>';
                                  eosinophils = eosinophils + '<td>' + eosinophilsValue + '</td>';
                                  immaturegranulo = immaturegranulo + '<td>' + immaturegranuloValue + '</td>';
                                  immatureGranuloPercent = immatureGranuloPercent + '<td>' + immatureGranuloPercentValue + '</td>';
                                  totalRBC = totalRBC + '<td>' + totalRBCValue + '</td>';
                                  redCell = redCell + '<td>' + redCellValue + '</td>';
                                  redCellDistribution = redCellDistribution + '<td>' + redCellDistributionValue + '</td>';

                              }

                              var theadstart = '<thead><tr>'
                              var theadend = '</tr></thead>'
                              var tbodystart = '<tbody>'
                              var tbodyend = '</tbody>'
                              var trstart = '<tr>';
                              var trend = '</tr>';
                              var result = theadstart + Parameters + theadend + tbodystart + trstart + hemoglobin + trend + trstart + plateletCount + trend + trstart + nucleatedRedBlood +
                                  trend + trstart + nucleatedBloodCellPercent + trend + trstart + hematocrit + trend + trstart + lympocytePercent + trend + trstart + totalLeucocytes + trend + trstart + meanCorpuscular + trend + trstart + meanCorpHemo + trend +
                                  trstart + meanCorpuscularVolume + trend + trstart + monocytes + trend + trstart + neutrophils + trend + trstart + eosinophilsCount + trend +
                                  trstart + basophilsCount + trend + trstart + lymphocytesCount + trend + trstart + monocytesCount + trend +
                                  trstart + neutrophilsCount + trend + trstart + basophils + trend + trstart + eosinophils + trend + trstart + immaturegranulo + trend +
                                  trstart + immatureGranuloPercent + trend + trstart + totalRBC + trend + trstart + redCell + trend + trstart + redCellDistribution + trend + tbodyend;

                              $('#tbl_cbc').html(result);
                          }
                      }
                  }

                  UrineRoutineGraph();
              }
              else {
                  console.log(data);
              }
          }
      });
  }

  //urine routine graph
  function UrineRoutineGraph() {
      var PaitentsTrend = {
          Dml_Indicator: 'US',
          doctor_id: $('#doctorId').val(),
          Patient_id: $('#Hdnpatient_id').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/CaseStudy/Graph_Section',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(PaitentsTrend),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  if (jQuery.isEmptyObject((data))) {

                  }
                  else {
                      if (Object.keys(data).length > 0) {

                          var Parameters = '<th>Parameters</th>', specificgravity = '<th>SPECIFIC GRAVITY</th>', urinarybilirubin = '<th>URINARY BILIRUBIN</th>',
                              urineblood = '<th>URINE BLOOD</th>', urobiligen = '<th>UROBILINOGEN</th>', urinaryglucose = '<th>URINARY GLUCOSE</th>',
                              urinaryketone = '<th>URINE KETONE</th>', leucocytes = '<th>URINARY LEUCOCYTES</th>', nitrite = '<th>NITRITE</th>', ph = '<th>PH</th>', urinaryprotein = '<th>URINARY PROTEIN</th>';

                          if (data.Table.length > 0) {
                              var datalength = 10;
                              if (data.Table.length < 10) {
                                  datalength = data.Table.length;
                              }
                              for (var i = 0; i < datalength; i++) {
                                  Parameters = Parameters + '<th>' + data.Table[i].VDate + '</th>';

                                  var specificgravityValue = '-', urinarybilirubinValue = '-', urinebloodValues = '-', urobiligenValue = '-',
                                      urinaryglucoseValue = '-'; urinaryketoneValue = '-'; leucocytesValue = '-'; nitriteValue = '-'; phValue = '-'; urinaryproteinValue = '-';

                                  if (data.Table[i].specific_gravity != null && data.Table[i].specific_gravity != '') {
                                      specificgravityValue = data.Table[i].specific_gravity + ' ' + (data.Table[i].specific_gravity_unit == null || data.Table[i].specific_gravity_unit == "" ? "" : data.Table[i].specific_gravity_unit);
                                  }
                                  if (data.Table[i].urinary_bilirubin != null && data.Table[i].urinary_bilirubin != '') {
                                      urinarybilirubinValue = data.Table[i].urinary_bilirubin + ' ' + (data.Table[i].urinary_bilirubin_unit == null || data.Table[i].urinary_bilirubin_unit == "" ? "" : data.Table[i].urinary_bilirubin_unit);
                                  }
                                  if (data.Table[i].urine_blood != null && data.Table[i].urine_blood != '') {
                                      urinebloodValues = data.Table[i].urine_blood;
                                  }
                                  if (data.Table[i].urobilinogen != null && data.Table[i].urobilinogen != '') {
                                      urobiligenValue = data.Table[i].urobilinogen + ' ' + (data.Table[i].urobilinogen_unit == null || data.Table[i].urobilinogen_unit == "" ? "" : data.Table[i].urobilinogen_unit);
                                  }
                                  if (data.Table[i].urinary_glucose != null && data.Table[i].urinary_glucose != '') {
                                      urinaryglucoseValue = data.Table[i].urinary_glucose;
                                  }
                                  if (data.Table[i].urine_ketone != null && data.Table[i].urine_ketone != '') {
                                      urinaryketoneValue = data.Table[i].urine_ketone + ' ' + (data.Table[i].urine_ketone_unit == null || data.Table[i].urine_ketone_unit == "" ? "" : data.Table[i].urine_ketone_unit);
                                  }

                                  if (data.Table[i].urinary_leucocytes != null && data.Table[i].urinary_leucocytes != '') {
                                      leucocytesValue = data.Table[i].urinary_leucocytes;
                                  }
                                  if (data.Table[i].nitrite != null && data.Table[i].nitrite != '') {
                                      nitriteValue = data.Table[i].nitrite + ' ' + (data.Table[i].nitrite_unit == null || data.Table[i].nitrite_unit == "" ? "" : data.Table[i].nitrite_unit);
                                  }
                                  if (data.Table[i].ph != null && data.Table[i].ph != '') {
                                      phValue = data.Table[i].ph;
                                  }
                                  if (data.Table[i].urinary_protein != null && data.Table[i].urinary_protein != '') {
                                      urinaryproteinValue = data.Table[i].urinary_protein;
                                  }


                                  specificgravity = specificgravity + '<td>' + specificgravityValue + '</td>';
                                  urinarybilirubin = urinarybilirubin + '<td>' + urinarybilirubinValue + '</td>';
                                  urineblood = urineblood + '<td>' + urinebloodValues + '</td>';
                                  urobiligen = urobiligen + '<td>' + urobiligenValue + '</td>';
                                  urinaryglucose = urinaryglucose + '<td>' + urinaryglucoseValue + '</td>';
                                  urinaryketone = urinaryketone + '<td>' + urinaryketoneValue + '</td>';
                                  leucocytes = leucocytes + '<td>' + leucocytesValue + '</td>';
                                  nitrite = nitrite + '<td>' + nitriteValue + '</td>';
                                  ph = ph + '<td>' + phValue + '</td>';
                                  urinaryprotein = urinaryprotein + '<td>' + urinaryproteinValue + '</td>';

                              }

                              var theadstart = '<thead><tr>'
                              var theadend = '</tr></thead>'
                              var tbodystart = '<tbody>'
                              var tbodyend = '</tbody>'
                              var trstart = '<tr>';
                              var trend = '</tr>';
                              var result = theadstart + Parameters + theadend + tbodystart + trstart + specificgravity + trend + trstart + urinarybilirubin + trend + trstart + urineblood +
                                  trend + trstart + urobiligen + trend + trstart + urinaryglucose + trend + trstart + urinaryketone + trend + trstart + leucocytes + trend + trstart + nitrite + trend + trstart + ph + trend +
                                  trstart + urinaryprotein + trend + tbodyend;
                              $('#tbl_urineroutine').html(result);
                          }
                      }
                      observed_nutrition_graph();
                  }
              }
              else {
                  console.log(data);
              }
          }
      });
  }
  function observed_nutrition_graph() {
      var doctorData = {
          Dml_Indicator: 'GS',
          Patient_id: $('#Hdnpatient_id').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/CaseStudy/Patient_Observed_Nutrition',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(doctorData),
          success: function (data) {
              var data1 = JSON.parse(data);
              if (data1.msg == "Success") {
                  var data1 = data1.data;
                  if (jQuery.isEmptyObject((data1))) {

                  }
                  else {
                      var row = '';
                      var theadStart = '<thead><tr><th>Type</th>';
                      var theadEnd = '</tr></thead>';
                      var tbodyStart = '<tbody>';
                      var tbodyEnd = '</tbody>';
                      var thead = '';
                      var trow = '';
                      var j = 0;

                      $('#tbl_observed_nutrition').empty();
                      if (Object.keys(data1).length > 0) {
                          for (var i = 0; i < data1.Table.length; i++) {
                              j++;
                              thead = thead + '<th>' + data1.Table[i].date + '</th>';
                          }
                          if (data1.Table1.length > 0) {

                              while (j > 0) {
                                  trow = trow + '<td></td>';
                                  j--;
                              }

                              for (var i = 0; i < data1.Table1.length; i++) {
                                  row = row + '<tr><td>' + data1.Table1[i].Type + '</td>' + trow + '</tr>';
                              }
                          }


                          $('#tbl_observed_nutrition').append(theadStart + thead + theadEnd + tbodyStart + row + tbodyEnd);

                          if (data1.Table2.length > 0) {

                              var refTab = document.getElementById("tbl_observed_nutrition");
                              // Loop through all rows and columns of the table and popup alert with the value
                              // /content of each cell.
                              for (var k = 0; k < data1.Table2.length; k++) {
                                  for (var i = 1; row = refTab.rows[i]; i++) {
                                      row = refTab.rows[0];
                                      for (var j = 0; col = row.cells[j]; j++) {
                                          if (refTab.rows[0].cells[j].innerHTML == data1.Table2[k].date && refTab.rows[i].cells[0].innerHTML == data1.Table2[k].Type) {
                                              refTab.rows[i].cells[j].innerHTML = data1.Table2[k].TypeValue;
                                          }
                                          console.log(col.firstChild.nodeValue);
                                      }
                                  }
                              }
                          }
                      }

                  }
              }
              else {
                  console.log(data1);
              }
          }
      });
  }

 


  function graph1(dataValue, lablevalue, id, labletext) {
      var chartColors = {
          green: 'rgb(75, 192, 192)',
          blue: 'rgb(54, 162, 235)',
          greenfade: 'rgba(75, 192, 192,0.8)',
          bluefade: 'rgba(54, 162, 235,0.4)',
          white: 'rgb(255, 255, 255)',
          whitefade: 'rgba(255, 255, 255,0.7)',
          newgreen: '#94fc13',
          neworange: '#ff502f',
          darkblue: '#36a2eb',
          darkpink: '#ff6b8b',
          lightwhite: '#fff'
      };

      var config = {
          type: 'line',
          data: {
              labels: lablevalue,
              datasets: [{
                  label: labletext,
                  backgroundColor: chartColors.lightwhite,
                  borderColor: chartColors.darkblue,
                  data: dataValue,

              }]
          },
          options: {
              responsive: true,
              tooltips: {
                  mode: 'label',
              },
              legend: {
                  display: false,
              },
              scales: {
                  xAxes: [{
                      display: true,
                      scaleLabel: {
                          display: true,
                          labelString: labletext,
                          fontSize: 9
                      },
                      ticks: {
                          fontSize: 9,
                          //    fontColor: "#222"
                      },
                      gridLines: {
                          display: false,
                          //   color: '#aaa'
                      }
                  }],
                  yAxes: [{
                      display: true,
                      scaleLabel: {
                          display: false,
                          labelString: 'Value',
                          fontSize: 9
                      },
                      ticks: {
                          fontSize: 9,
                          beginAtZero: true,
                          //   fontColor: "#222"
                      },
                      gridLines: {
                          display: false,
                          //    color: '#aaa'
                      }
                  }]
              }
          }
      };

      var ctx = document.getElementById(id).getContext("2d");
      window.myLine = new Chart(ctx, config);
  }


  function graph2(dataValue1, dataValue2, lablevalue, id, label1, label2) {
      var chartColors = {
          green: 'rgb(75, 192, 192)',
          blue: 'rgb(54, 162, 235)',
          greenfade: 'rgba(75, 192, 192,0.8)',
          bluefade: 'rgba(54, 162, 235,0.4)',
          white: 'rgb(255, 255, 255)',
          whitefade: 'rgba(255, 255, 255,0.7)',
          newgreen: '#94fc13',
          neworange:'#ff502f',
          darkblue: '#36a2eb',
          darkpink: '#ff6b8b',
          lightwhite: '#fff'
      };
      var config = {
          type: 'line',
          data: {
              labels: lablevalue,
              datasets: [{
                  label: label1,
                  backgroundColor: chartColors.lightwhite,
                  borderColor: chartColors.darkblue,
                  data: dataValue1,

              }, {
                  label: label2,
                      backgroundColor: chartColors.lightwhite,
                      borderColor: chartColors.darkpink,
                  data: dataValue2,
              }]
          },
          options: {
              responsive: true,
              tooltips: {
                  mode: 'label',
              },
              legend: {
                  display: false,
              },
              scales: {
                  xAxes: [{
                      display: true,
                      scaleLabel: {
                          display: true,
                          labelString: 'Date',
                          fontSize: 9
                      },
                      ticks: {
                          fontSize: 9,
                      },
                      gridLines: {
                          display: false,
                      }
                  }],
                  yAxes: [{
                      display: true,
                      scaleLabel: {
                          display: false,
                          labelString: 'Value',
                          fontSize: 9
                      },
                      ticks: {
                          fontSize: 9,
                          beginAtZero: true,
                      },
                      gridLines: {
                          display: false,
                      }
                  }]
              }
          }
      };

      var ctx = document.getElementById(id).getContext("2d");
      window.myLine = new Chart(ctx, config);
  }




//summary patient details visit_report_end


  //view chart(health and fitness,medication,quality assurance)
  function graph1_bpbsall(dataValue, lablevalue, id, labletext) {
      var chartColors = {
          green: 'rgb(75, 192, 192)',
          blue: 'rgb(54, 162, 235)',
          greenfade: 'rgba(75, 192, 192,0.8)',
          bluefade: 'rgba(54, 162, 235,0.4)',
          white: 'rgb(255, 255, 255)',
          whitefade: 'rgba(255, 255, 255,0.7)',
          newgreen: '#94fc13',
          neworange: '#ff502f',
          darkblue: '#36a2eb',
          darkpink: '#ff6b8b',
          lightwhite: '#fff'
      };

      var config = {
          type: 'line',
          data: {
              labels: lablevalue,
              datasets: [{
                  label: labletext,
                  backgroundColor: chartColors.lightwhite,
                  borderColor: chartColors.darkblue,
                  data: dataValue,

              }]
          },
          options: {
              responsive: true,
              tooltips: {
                  mode: 'label',
              },
              legend: {
                  display: false,
              },
              scales: {
                  xAxes: [{
                      display: true,
                      scaleLabel: {
                          display: true,
                          labelString: labletext,
                          fontSize: 9
                      },
                      ticks: {
                          fontSize: 9,
                          //    fontColor: "#222"
                      },
                      gridLines: {
                          display: false,
                          //   color: '#aaa'
                      }
                  }],
                  yAxes: [{
                      display: true,
                      scaleLabel: {
                          display: false,
                          labelString: 'Value',
                          fontSize: 9
                      },
                      ticks: {
                          fontSize: 9,
                          beginAtZero: true,
                          //   fontColor: "#222"
                      },
                      gridLines: {
                          display: false,
                          //    color: '#aaa'
                      }
                  }]
              }
          }
      };

      var ctx = document.getElementById(id).getContext("2d");
      window.myLine1 = new Chart(ctx, config);
  }


  function graph2_bpbsall(dataValue1, dataValue2, lablevalue, id, label1, label2) {
      var chartColors = {
          green: 'rgb(75, 192, 192)',
          blue: 'rgb(54, 162, 235)',
          greenfade: 'rgba(75, 192, 192,0.8)',
          bluefade: 'rgba(54, 162, 235,0.4)',
          white: 'rgb(255, 255, 255)',
          whitefade: 'rgba(255, 255, 255,0.7)',
          newgreen: '#94fc13',
          neworange: '#ff502f', darkblue: '#36a2eb',
          darkpink: '#ff6b8b',
          lightwhite: '#fff'
      };
      var config = {
          type: 'line',
          data: {
              labels: lablevalue,
              datasets: [{
                  label: label1,
                  backgroundColor: chartColors.lightwhite,
                  borderColor: chartColors.darkblue,
                  data: dataValue1,

              }, {
                  label: label2,
                      backgroundColor: chartColors.lightwhite,
                      borderColor: chartColors.darkpink,
                  data: dataValue2,
              }]
          },
          options: {
              responsive: true,
              tooltips: {
                  mode: 'label',
              },
              legend: {
                  display: false,
              },
              scales: {
                  xAxes: [{
                      display: true,
                      scaleLabel: {
                          display: true,
                          labelString: 'Date',
                          fontSize: 9
                      },
                      ticks: {
                          fontSize: 9,
                      },
                      gridLines: {
                          display: false,
                      }
                  }],
                  yAxes: [{
                      display: true,
                      scaleLabel: {
                          display: false,
                          labelString: 'Value',
                          fontSize: 9
                      },
                      ticks: {
                          fontSize: 9,
                          beginAtZero: true,
                      },
                      gridLines: {
                          display: false,
                      }
                  }]
              }
          }
      };

      var ctx = document.getElementById(id).getContext("2d");
      window.myLine1 = new Chart(ctx, config);
  }


  function graph3_ws(dataValue1, lablevalue, id) {
      var chartColors = {
          green: 'rgb(75, 192, 192)',
          blue: 'rgb(54, 162, 235)',
          greenfade: 'rgba(75, 192, 192,0.8)',
          bluefade: 'rgba(54, 162, 235,0.4)',
          white: 'rgb(255, 255, 255)',
          whitefade: 'rgba(255, 255, 255,0.7)',
          newgreen: '#94fc13',
          neworange: '#ff502f',
          darkblue: '#36a2eb',
          darkpink: '#ff6b8b',
          lightwhite: '#fff'
      };
      var config = {
          type: 'line',
          data: {
              labels: lablevalue,
              datasets: [{
                  label: "score",
                  backgroundColor: chartColors.lightwhite,
                  borderColor: chartColors.darkblue,
                  data: dataValue1,
              }]
          },
          options: {
              responsive: true,
              tooltips: {
                  mode: 'label',
              },
              legend: {
                  display: false,
              },
              scales: {
                  xAxes: [{
                      display: true,
                      scaleLabel: {
                          display: true,
                          labelString: 'Date',
                          fontSize: 9
                      },
                      ticks: {
                          fontSize: 9,
                      },
                      gridLines: {
                          display: false,
                      }
                  }],
                  yAxes: [{
                      display: true,
                      scaleLabel: {
                          display: false,
                          labelString: 'Value',
                          fontSize: 9
                      },
                      ticks: {
                          fontSize: 9,
                          beginAtZero: true,
                      },
                      gridLines: {
                          display: false,
                      }
                  }]
              }
          }
      };

      var ctx = document.getElementById(id).getContext("2d");
      window.myLine = new Chart(ctx, config);
  }


//view chart end


//payment start -- old

  function ActiveInvoice() {
      $('#cpi_activeInvoice_table').addClass('us-db-loader-active-inv');
      var InvoiceId = {
          doctor_id: $('#doctorId').val(),
          Dml_Indicator: 'AI',
          patient_id: $('#Hdnpatient_id').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/caseStudy/invoice_payment',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(InvoiceId),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  var tr = '';
                  $('#cpi_activeInvoice_body').empty();
                  if (jQuery.isEmptyObject((data))) {
                  }
                  else {
                      if (data.length > 0) {

                          for (var i = 0; i < data.length; i++) {
                              //tr = tr + '<tr data-invoice="' + data[i].invoice_id + "," + data[i].invoice_amount + '"><td>' + data[i].invoice_id + '</td><td>' + data[i].invoice_date + '</td><td><i class="fa fa-print" onclick=Invoice_lab_print(\"' + data[i].lab_order_id + '\",\"' + data[i].visit_report_id + '\") ></i>' + data[i].invoice_description + '</td><td>' + data[i].invoice_amount + '</td><td><a href="javascript:void(0);" onclick=Delete_Active_invoice(\"' + data[i].invoice_id + '\",\"' + data[i].lab_order_id + '\")><i class="fa fa-trash" aria-hidden="true"></i>Delete</a></td><td><a href="javascript:void(0);" data-toggle="modal" data-target="#modal_collectpayment_inner" data-backdrop="static" data-keyboard="true">+ Payment</a></td></tr>';
                              tr = tr + '<tr data-invoice="' + data[i].invoice_id + "," + data[i].invoice_amount + '"><td><input style="display:none" type="checkbox" id="' + data[i].invoice_id + '" name="checkbox1" value="' + data[i].balance_amount + '" onclick=\'checkval(\"' + data[i].balance_amount + '\",\"' + data[i].invoice_id + '\")\';></td><td>' + data[i].invoice_id + '</td><td>' + data[i].invoice_date + '</td><td><span class="print btn btn-default  btn-sm"><i class="fa fa-print" onclick=\'Invoice_lab_print(\"' + data[i].lab_order_id + '\",\"' + data[i].visit_report_id + '\",\"' + data[i].invoice_id + '\", \"' + data[i].invoice_description + '\")\'; ></i></span>' + data[i].invoice_description + '</td><td>' + data[i].invoice_amount + '</td><td>' + data[i].balance_amount + '</td><td><a class="payment btn btn-default  btn-sm" href="javascript:void(0);"  data-backdrop="static" data-keyboard="true" onclick =\'fullpayment(\"' + data[i].balance_amount + '\",\"' + 1 + '\",\"' + data[i].invoice_id + '\", \"' + data[i].lab_order_id + '\")\';><i class="fa fa-money" area-hidden="true"></i></a><a class="payment btn btn-default  btn-sm" href="javascript:void(0);" data-backdrop="static" data-keyboard="true" onclick=\'fullpayment(\"' + data[i].balance_amount + '\",\"' + 2 + '\",\"' + data[i].invoice_id + '\", \"' + data[i].lab_order_id + '\")\';><i class="fa fa-credit-card" area-hidden="true"></i><a class="part-payment btn btn-default  btn-sm" href="javascript:void(0);" data-backdrop="static" data-keyboard="true" onclick=add_payment1(\"' + data[i].lab_order_id + '\");><i class="fa fa-hourglass-half" area-hidden="true"></i></a></td><td><a class="delete btn btn-default  btn-sm" href="javascript:void(0);" onclick=Delete_Active_invoice(\"' + data[i].invoice_id + '\",\"' + data[i].lab_order_id + '\")><i class="fa fa-trash" aria-hidden="true"></i></a></td></tr>';
                          }
                          $('#cpi_activeInvoice_body').html(tr);
                          $('#CpiInvoiceTotal').html((parseFloat(data[0].invoice_total) - parseFloat(data[0].invoice_payment)).toFixed(2));
                          $('#CpiInvoicePayment').html(data[0].invoice_payment);
                          $('#CpiInvoiceTotal_amt').html(data[0].invoice_total);
                      }
                      else {
                          //$('#CpiInvoiceTotal').html('-');
                          //$('#CpiInvoicePayment').html('-');
                          //$('#CpiInvoiceTotal_amt').html('-');
                      }
                  }
                  $('#cpi_activeInvoice_table').removeClass('us-db-loader-active-inv');
              }
              else {
                  console.log(data);
              }
          }
      });
  }


  $('#cpHistoryInvoiceId').click(function () {
      HistroyInvoice();
  });

  function HistroyInvoice() {
      $('.cpi_historyInvoice_table').addClass('us-db-loader-history-inv');
      var InvoiceId = {
          doctor_id: $('#doctorId').val(),
          Dml_Indicator: 'HS',
          patient_id: $('#Hdnpatient_id').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/caseStudy/invoice_payment',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(InvoiceId),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  var tr = '';
                  $('#cpi_historyInvoice_body').empty();
                  if (jQuery.isEmptyObject((data))) {
                  }
                  else {
                      if (data.length > 0) {
                          var tr1 = '', tr2 = '', tr3 = '', j = 1;
                          var invoice_id = '';
                          var a = data.length;
                          for (var i = 0; i < data.length; i++) {

                              //if (i==0) {
                              //    tr1 = '<tr><td>' + data[i].invoice_id + '</td><td>' + data[i].invoice_date + '</td><td>' + data[i].invoice_description + '</td><td>' + data[i].invoice_amount + '</td><td class="ptr"><a tabindex="0" class="" data-html="true" data-toggle="popover" data-placement="top" data-trigger="click" title="<table class=\'table\'><tbody>';
                              //    invoice_id = data[i].invoice_id;
                              //}
                              var payment_type = '';
                              if (data[i].payment_type == 1) {
                                  payment_type = 'Cash';
                              }
                              else if (data[i].payment_type == 2) {
                                  payment_type = 'Card';
                              }
                              else if (data[i].payment_type == 3) {
                                  payment_type = 'Payment Gateway';
                              }
                              else {
                                  payment_type = '';
                              }
                              if (a == j) {

                                  if (data[i].invoice_id == data[i].invoice_id) {
                                      tr2 = tr2 + '<tr><td>' + data[i].paid_date + '</td><td>' + data[i].payment_amount + '</td><td>' + payment_type + '</td></tr>';
                                      tr = tr + '<tr><td>' + data[i].invoice_id + '</td><td>' + data[i].invoice_date + '</td><td><i class="fa fa-print" onclick=\'Invoice_lab_print(\"' + data[i].lab_order_id + '\",\"' + data[i].visit_report_id + '\",\"' + data[i].invoice_id + '\", \"' + data[i].invoice_description + '\")\';  ></i>' + data[i].invoice_description + '</td><td>' + data[i].invoice_amount + '</td><td class="ptr"><a tabindex="0" class="" data-html="true" data-toggle="popover" data-placement="top" data-trigger="click" title="<span class=\'cpPopClose pull-right\'><i class=\'fa fa-times\' aria-hidden=\'true\'></i></span><table class=\'table\'><thead><tr><th>Pay date</th><th>Amt</th><th>Pay Type</th></tr></thead><tbody>' + tr2 + '</tbody></table>">History</a></td></tr>';
                                      tr2 = '';
                                  }
                              }
                              else {
                                  if (data[i].invoice_id != data[j].invoice_id) {
                                      tr2 = tr2 + '<tr><td>' + data[i].paid_date + '</td><td>' + data[i].payment_amount + '</td><td>' + payment_type + '</td></tr>';
                                      tr = tr + '<tr><td>' + data[i].invoice_id + '</td><td>' + data[i].invoice_date + '</td><td><i class="fa fa-print" onclick=\'Invoice_lab_print(\"' + data[i].lab_order_id + '\",\"' + data[i].visit_report_id + '\",\"' + data[i].invoice_id + '\", \"' + data[i].invoice_description + '\")\'; ></i>' + data[i].invoice_description + '</td><td>' + data[i].invoice_amount + '</td><td class="ptr"><a tabindex="0" class="" data-html="true" data-toggle="popover" data-placement="top" data-trigger="click" title="<span class=\'cpPopClose pull-right\'><i class=\'fa fa-times\' aria-hidden=\'true\'></i></span><table class=\'table\'><thead><tr><th>Pay date</th><th>Amt</th><th>Pay Type</th></tr></thead><tbody>' + tr2 + '</tbody></table>">History</a></td></tr>';
                                      tr2 = '';
                                  }
                                  else {
                                      tr2 = tr2 + '<tr><td>' + data[i].paid_date + '</td><td>' + data[i].payment_amount + '</td><td>' + payment_type + '</td></tr>';
                                  }
                              }

                              j++;

                              // tr = tr + '<tr><td>' + data[i].invoice_id + '</td><td>' + data[i].invoice_date + '</td><td>' + data[i].invoice_description + '</td><td>' + data[i].invoice_amount + '</td><td class="ptr"><a tabindex="0" class="" data-html="true" data-toggle="popover" data-placement="top" data-trigger="click" title="<table class=\'table\'><tbody><td>col1</td><td>col1</td><td>col1</td></tr><tr><td>col1</td><td>col1</td><td>col1</td></tr></tbody></table>">History</a></td></tr>';
                          }
                          tr = tr
                          $('#cpi_historyInvoice_body').html(tr);
                          $("[data-toggle=popover]").popover();
                      }
                  }
                  $('.cpi_historyInvoice_table').removeClass('us-db-loader-history-inv');
              }
              else {
                  console.log(data);
              }
          }
      });
  }

//payment end -- old


  //invoice payment
  function collectpayment() {
      var InvoiceId = {
            Patient_id: $('#Hdnpatient_id').val(),
            doctor_id: $('#doctorId').val(),
            Dml_Indicator: 'IS'
        }
        $.ajax({
            async: true,
            type: 'POST',
            url: '/caseStudy/invoice_payment',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(InvoiceId),
            success: function (data) {
                var data = JSON.parse(data);
                if (data.msg == "Success") {
                    var data = data.data;
                    if (jQuery.isEmptyObject((data))) {
                    }
                    else {
                        if (data.length > 0) {
                            $('#InvoiceId').val(data[0].InvoiceId);
                            $('#CpiInvoiceTotal').html(parseFloat(data[0].invoice_total) - parseFloat(data[0].invoice_payment));
                            $('#CpiInvoicePayment').html(data[0].invoice_payment);
                            $('#CpiInvoiceTotal_amt').html(data[0].invoice_total);
                        }
                    }
                    invoice_quickSelect();
                    ActiveInvoice();
                }
                else {
                    console.log(data);
                }
            }
        });
    }



  function invoice_quickSelect() {
      var familydetails = {
          doctor_id: $('#doctorId').val(),
          Dml_Indicator: 'PS'
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/caseStudy/doctor_consultation_fees_details_amt',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(familydetails),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  if (jQuery.isEmptyObject((data))) {
                  }
                  else {
                      var tr = '', quickSelect = ''
                      $('#invoice_quickSelect').empty();
                      if (data.length > 0) {
                          for (var i = 0; i < data.length; i++) {
                              quickSelect = quickSelect + '<li onclick=\'addinvoice(\"' + data[i].consultation_name + '\")\'>' + data[i].consultation_name + '</li>';
                          }
                          $('#invoice_quickSelect').html(quickSelect);
                      }
                  }
              }
              else {
                  console.log(data);
              }
          }
      });
  }

  function addinvoice(InvoiceName) {
      var InvoiceNames = InvoiceName;

      var invoice = {}
      invoice.invoice_id = $('#InvoiceId').val(),
      invoice.Patient_id = $('#Hdnpatient_id').val(),
       invoice.doctor_id = $('#doctorId').val(),
       invoice.invoice_description = InvoiceNames,
       invoice.invoice_date = '',
       invoice.invoice_amount = $('#InvoiceAmount').val(),
       invoice.invoice_status = 1,
       invoice.balance_amount = $('#InvoiceAmount').val(),
       invoice.Dml_Indicator = 'QI',
       invoice.visit_report_id = $('#VisitReportID').val(),

   $.ajax({
       async: true,
       type: 'POST',
       url: '/caseStudy/invoice_payment',
       contentType: 'application/json; charset=UTF-8',
       data: JSON.stringify(invoice),
       success: function (data) {
           var data = JSON.parse(data);
           if (data.msg == "Success") {
               collectpayment();
           }
           else {
               console.log(data);
           }
       }
   });

  }


  $('#btnAddInvoice').click(function () {
      var InvoiceDate = $('#InvoiceDate').val();
      var InvoiceName = $('#InvoiceName').val();
      var InvoiceAmount = $('#InvoiceAmount').val();
      if ($.trim(InvoiceDate) == '') {
          $('#PInvoiceDate').show();
          $('#PInvoiceDate').fadeOut(8000);
          $('#PInvoiceDate').html('Select the invoice date');
          $('#InvoiceDate').focus();
          $('#InvoiceDate').val('');
          return false;
      }
      if ($.trim(InvoiceName) == '') {
          $('#PInvoiceName').show();
          $('#PInvoiceName').fadeOut(8000);
          $('#PInvoiceName').html('Enter the invoice name');
          $('#InvoiceName').focus();
          $('#InvoiceName').val('');
          return false;
      }
      if ($.trim(InvoiceAmount) == '') {
          $('#PInvoiceAmount').show();
          $('#PInvoiceAmount').fadeOut(8000);
          $('#PInvoiceAmount').html('Enter the invoice amount');
          $('#InvoiceAmount').focus();
          $('#InvoiceAmount').val('');
          return false;
      }

      var InvoiceDates = InvoiceDate.split('/');
      InvoiceDate = InvoiceDates[2] + "-" + InvoiceDates[1] + "-" + InvoiceDates[0];
      var invoice = {
          invoice_id: $('#InvoiceId').val(),
          Patient_id: $('#Hdnpatient_id').val(),
          doctor_id: $('#doctorId').val(),
          invoice_description: $('#InvoiceName').val(),
          invoice_date: InvoiceDate,
          invoice_amount: $('#InvoiceAmount').val(),
          invoice_status: 1,
          balance_amount: $('#InvoiceAmount').val(),
          Dml_Indicator: 'I',
          visit_report_id: $('#VisitReportID').val(),
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/caseStudy/invoice_payment',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(invoice),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  $('#InvoiceDate').val('');
                  $('#InvoiceName').val('');
                  $('#InvoiceAmount').val('');
                  collectpayment();
              }
              else {
                  console.log(data);
              }
          }
      });
  });

  $('#cpi_activeInvoice_body').on('click', 'tr', function () {
      $('#cpi_activeInvoice_body > tr').removeClass('active');
      $('#cpi_activeInvoice_body > tr').css('fontSize', '12px');
      $(this).addClass('active');
      var id = $(this).attr('data-invoice');
      var val = id.split(',');


      var GetRight = {
          Dml_Indicator: 'RS',
          doctor_user_role_id: $('#hiddenRole_id').val(),
          doctor_user_module_id: '17'
      }

      $.ajax({
          async: true,
          type: 'POST',
          url: '/UserRight/DoctorRight',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(GetRight),
          success: function (data) {
              var data1 = JSON.parse(data);
              if (data1.msg == "Success") {
                  if (jQuery.isEmptyObject((data1))) {
                  }
                  else {
                      var roleRight = '';
                      $.each(data1, function (i, emp) {
                          roleRight = emp.doctor_user_role_rights;
                      });
                      if (roleRight == 1) {
                          ActiveInvoiceDetails(val[0], val[1]);
                          $("#cpiActiveDetails").show();
                      }
                      else {
                          toastr.warning('You have no right to access page contact administrator');
                      }
                  }
              }
              else {
                  console.log(data);
              }
          }
      });

  });

  $('#cpiDetailToggle').click(function () {
      $('#cpi_activeInvoice_body > tr').removeClass('active');
      $('#cpi_activeInvoice_body > tr').css('fontSize', '14px');
      $("#cpiActiveDetails").hide();
      $('#cpi_activeInvoice_sec').removeClass().addClass('col-md-12 padding0');
  });


  function ActiveInvoice() {
      $('#cpi_activeInvoice_table').addClass('us-db-loader-active-inv');
      var InvoiceId = {
          doctor_id: $('#doctorId').val(),
          Dml_Indicator: 'AI',
          patient_id: $('#Hdnpatient_id').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/caseStudy/invoice_payment',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(InvoiceId),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  var tr = '';
                  $('#cpi_activeInvoice_body').empty();
                  if (jQuery.isEmptyObject((data))) {
                  }
                  else {
                      if (data.length > 0) {
                          for (var i = 0; i < data.length; i++) {
                              //tr = tr + '<tr data-invoice="' + data[i].invoice_id + "," + data[i].invoice_amount + '"><td>' + data[i].invoice_id + '</td><td>' + data[i].invoice_date + '</td><td><i class="fa fa-print" onclick=Invoice_lab_print(\"' + data[i].lab_order_id + '\",\"' + data[i].visit_report_id + '\") ></i>' + data[i].invoice_description + '</td><td>' + data[i].invoice_amount + '</td><td><a href="javascript:void(0);" onclick=Delete_Active_invoice(\"' + data[i].invoice_id + '\",\"' + data[i].lab_order_id + '\")><i class="fa fa-trash" aria-hidden="true"></i>Delete</a></td><td><a href="javascript:void(0);" data-toggle="modal" data-target="#modal_collectpayment_inner" data-backdrop="static" data-keyboard="true">+ Payment</a></td></tr>';
                              tr = tr + '<tr data-invoice="' + data[i].invoice_id + "," + data[i].invoice_amount + '"><td><input style="display:none" type="checkbox" id="' + data[i].invoice_id + '" name="checkbox1" value="' + data[i].balance_amount + '" onclick=\'checkval(\"' + data[i].balance_amount + '\",\"' + data[i].invoice_id + '\")\';></td><td>' + data[i].invoice_id + '</td><td>' + data[i].invoice_date + '</td><td><span class="print btn btn-default  btn-sm"><i class="fa fa-print" onclick=\'Invoice_lab_print(\"' + data[i].lab_order_id + '\",\"' + data[i].visit_report_id + '\",\"' + data[i].invoice_id + '\", \"' + data[i].invoice_description + '\")\'; ></i></span>' + data[i].invoice_description + '</td><td>' + data[i].invoice_amount + '</td><td>' + data[i].balance_amount + '</td><td><a class="payment btn btn-default  btn-sm" href="javascript:void(0);"  data-backdrop="static" data-keyboard="true" onclick =\'fullpayment(\"' + data[i].balance_amount + '\",\"' + 1 + '\",\"' + data[i].invoice_id + '\", \"' + data[i].lab_order_id + '\")\';><i class="fa fa-money" area-hidden="true"></i></a><a class="payment btn btn-default  btn-sm" href="javascript:void(0);" data-backdrop="static" data-keyboard="true" onclick=\'fullpayment(\"' + data[i].balance_amount + '\",\"' + 2 + '\",\"' + data[i].invoice_id + '\", \"' + data[i].lab_order_id + '\")\';><i class="fa fa-credit-card" area-hidden="true"></i><a class="part-payment btn btn-default  btn-sm" href="javascript:void(0);" data-backdrop="static" data-keyboard="true" onclick=add_payment1(\"' + data[i].lab_order_id + '\");><i class="fa fa-hourglass-half" area-hidden="true"></i></a></td><td><a class="delete btn btn-default  btn-sm" href="javascript:void(0);" onclick=Delete_Active_invoice(\"' + data[i].invoice_id + '\",\"' + data[i].lab_order_id + '\")><i class="fa fa-trash" aria-hidden="true"></i></a></td></tr>';
                          }
                          $('#cpi_activeInvoice_body').html(tr);
                          //$('#CpiInvoiceTotal').html(data[0].invoice_total);
                          //$('#CpiInvoicePayment').html(data[0].invoice_payment);

                          $('#CpiInvoiceTotal').html(parseFloat(data[0].invoice_total) - parseFloat(data[0].invoice_payment));
                          $('#CpiInvoicePayment').html(data[0].invoice_payment);
                          $('#CpiInvoiceTotal_amt').html(data[0].invoice_total);
                      }
                      else {
                          //$('#CpiInvoiceTotal').html('-');
                          //$('#CpiInvoicePayment').html('-');
                          //$('#CpiInvoiceTotal_amt').html('-');
                      }
                  }
                  $('#cpi_activeInvoice_table').removeClass('us-db-loader-active-inv');

              }
              else {
                  console.log(data);
              }
          }
      });
  }

  function add_payment1(labid) {
      $('#pack_id').val(labid);
      $('#Selpaymenttype').val('1');
      $('#modal_collectpayment_inner').modal('toggle');
  }

  function fullpayment(balance_amount, payment_type, invoice_id, lab_order_id) {

      var GetRight = {
          Dml_Indicator: 'RS',
          doctor_user_role_id: '@Session["RoleId"]',
          doctor_user_module_id: '17'
      }

      $.ajax({
          async: true,
          type: 'POST',
          url: '/UserRight/DoctorRight',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(GetRight),
          success: function (data) {
              var data1 = JSON.parse(data);
              if (data1.msg == "Success") {
                  var data1 = data1.data;
                  if (jQuery.isEmptyObject((data))) {

                  }
                  else {
                      var roleRight = '';
                      $.each(data1, function (i, emp) {
                          roleRight = emp.doctor_user_role_rights;
                      });
                      if (roleRight == 1) {
                          //ActiveInvoiceDetails(val[0], val[1]);
                          //$("#cpiActiveDetails").show();
                          var invoice_status = 3;
                          var patient_id, doc_id;
                          patient_id = $('#Hdnpatient_id').val();
                          if (lab_order_id.length > 3) {
                              doc_id = lab_order_id.split('-')[0];
                              if (doc_id == ($('#doctorId').val())) {
                                  get_package_details(lab_order_id, invoice_id, patient_id);
                              }
                          }

                          var InvoiceId = {
                              doctor_id: $('#doctorId').val(),
                              patient_id: $('#Hdnpatient_id').val(),
                              payment_amount: balance_amount,
                              payment_type: payment_type,
                              invoice_id: invoice_id,
                              invoice_status: invoice_status,
                              balance_amount: 0,
                              Dml_Indicator: 'PI'
                          }
                          $.ajax({
                              async: true,
                              type: 'POST',
                              url: '/caseStudy/invoice_payment',
                              contentType: 'application/json; charset=UTF-8',
                              data: JSON.stringify(InvoiceId),
                              success: function (data) {
                                  var data = JSON.parse(data);
                                  if (data.msg == "Success") {
                                      var data = data.data;
                                      if (jQuery.isEmptyObject((data))) {
                                      }
                                      else {
                                      }
                                      $('#paymentamount').val('');
                                      //$("#cpiActiveDetails").hide();
                                      doc_id = lab_order_id.split('-')[0];
                                      if (doc_id == ($('#doctorId').val())) {
                                          get_package_details(lab_order_id, invoice_id, $('#Hdnpatient_id').val());
                                      }
                                      ActiveInvoice();
                                      HistroyInvoice();
                                      toastr.success("Full Payment added successfully !!!");
                                      $('.paymentclose').click();
                                      //ActiveInvoiceDetails($('#curinvoiceid').val(), $('#curamount').val())
                                  }
                                  else {
                                      console.log(data);
                                  }
                              }
                          });
                      }
                      else {
                          toastr.warning('You have no right to access page contact administrator');
                      }
                  }
              }
              else {
                  console.log(data1);
              }
          }
      });

  }


  function Delete_Active_invoice(invoice_id, lab_id) {
      var txt;
      var r = confirm("Are you sure you want to delete the Invoice: " + invoice_id + " ?");
      if (r == true) {
          $('#tblDoctorUser1').modal('toggle');
          $('#hndinvoiceId').val(invoice_id);
      } else {

      }
  }

  $('#mpinsubmit').click(function () {
      var InvoiceId = {
          doctor_id: $('#doctorId').val(),
          Dml_Indicator: 'D',
          invoice_id: $('#hndinvoiceId').val(),
          MPIN: $('#mpinnum').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/caseStudy/invoice_payment',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(InvoiceId),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  if (jQuery.isEmptyObject((data))) {
                  }
                  else {
                      if (data.length > 0) {
                          if (data[0].StringMsg == 'Success') {
                              ActiveInvoice();
                          }
                          else if (data[0].StringMsg == 'Cannot able to delete') {
                              toastr.warning('Payment Received - Unable to delete Invoice');
                          }
                          else {
                              toastr.warning('MPIN is wrong !!!');
                          }
                      }
                  }

              }
              else {
                  console.log(data);
              }
          }
      });
  });


  function ActiveInvoiceDetails(id, amount) {
      $('#curinvoiceid').val(id);
      $('#curamount').val(amount);
      var invoice = {
          invoice_id: $('#curinvoiceid').val(),
          Patient_id: $('#Hdnpatient_id').val(),
          doctor_id: $('#doctorId').val(),
          Dml_Indicator: 'PD',
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/caseStudy/invoice_payment',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(invoice),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  $('#tblinvoiceamtdetails_body').empty();
                  var tr = '';
                  if (jQuery.isEmptyObject((data))) {
                  }
                  else {
                      debugger;
                      if (data.length > 0) {
                          for (var i = 0; i < data.length; i++) {
                              var paymenttype = '';
                              if (data[i].payment_type == 1) {
                                  paymenttype = 'Cash';
                              }
                              else if (data[i].payment_type == 2) {
                                  paymenttype = 'Card';
                              }
                              else {
                                  paymenttype = 'Payment Gateway';
                              }
                              tr = tr + '<tr><td>' + data[i].payment_id + '</td><td>' + paymenttype + '</td><td>' + data[i].payment_amount + '</td></tr>';
                          }
                      }
                      $('#tblinvoiceamtdetails_body').html(tr);
                  }
              }
              else {
                  console.log(data);
              }
          }
      });
  }

  $('#add_cpi_invoice').click(function () {
      if ($.trim($('#paymentamount').val()) == '') {
          $('#Ppaymentamount').show();
          $('#Ppaymentamount').fadeOut(8000);
          $('#Ppaymentamount').html('enter the invoice amount');
          $('#paymentamount').focus();
          $('#paymentamount').val('');
          return false;
      }
      var previousval = 0;
      $('#tblinvoiceamtdetails > tbody  > tr').each(function () {
          $(this).find("td:gt(1)").each(function () {
              var temp = $(this).html();
              previousval = parseFloat(previousval) + parseFloat(temp);
          });
      });
      previousval = parseFloat(previousval) + parseFloat($('#paymentamount').val());
      var invoice_status = '', balance_amount = '', patient_id = '', invoice_id = '', doc_id = '', package_id = '';
      if (previousval > parseFloat($('#curamount').val())) {
          $('#Ppaymentamount').show();
          $('#Ppaymentamount').fadeOut(8000);
          $('#Ppaymentamount').html('Check amount');
          $('#paymentamount').focus();
          $('#paymentamount').val('');
          return false;
      }
      else if (previousval < parseFloat($('#curamount').val())) {
          invoice_status = 2;
          balance_amount = parseFloat($('#curamount').val()) - parseFloat(previousval);
      }
      else {
          invoice_status = 3;
          balance_amount = 0;
          patient_id = $('#Hdnpatient_id').val();
          invoice_id = $('#curinvoiceid').val();
          package_id = $('#pack_id').val();
          if (package_id != null || package_id != ""){
              if (package_id.length > 3) {
                  doc_id = $('#pack_id').val().split('-')[0];
                  if (doc_id == ($('#doctorId').val())) {
                      get_package_details(package_id, invoice_id, patient_id);
                  }
              }
         }
      }
      var InvoiceId = {
          doctor_id: $('#doctorId').val(),
          patient_id: $('#Hdnpatient_id').val(),
          payment_amount: $('#paymentamount').val(),
          payment_type: $('#Selpaymenttype').val(),
          invoice_id: $('#curinvoiceid').val(),
          invoice_status: invoice_status,
          balance_amount: balance_amount,
          Dml_Indicator: 'PI'
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/caseStudy/invoice_payment',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(InvoiceId),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  if (jQuery.isEmptyObject((data))) {
                  }
                  else {
                  }
                  $('#paymentamount').val('');
                  //$("#cpiActiveDetails").hide();
                  ActiveInvoice();
                  HistroyInvoice();
                  ActiveInvoiceDetails($('#curinvoiceid').val(), $('#curamount').val());
                  $('#add_cpi_invoice').prop('disabled', false);
                  $('#Selpaymenttype').val('1');
              }
              else {
                  console.log(data);
              }
          }
      });
      //tblinvoiceamtdetails
  });

  $('#cpHistoryInvoiceId').click(function () {
      HistroyInvoice();

  });

  function HistroyInvoice() {
      $('.cpi_historyInvoice_table').addClass('us-db-loader-history-inv');
      var InvoiceId = {
          doctor_id: $('#doctorId').val(),
          Dml_Indicator: 'HS',
          patient_id: $('#Hdnpatient_id').val()
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/caseStudy/invoice_payment',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(InvoiceId),
          success: function (data) {
              var data = JSON.parse(data);
              if (data.msg == "Success") {
                  var data = data.data;
                  var tr = '';
                  $('#cpi_historyInvoice_body').empty();
                  if (jQuery.isEmptyObject((data))) {
                  }
                  else {
                      if (data.length > 0) {
                          var tr1 = '', tr2 = '', tr3 = '', j = 1;
                          var invoice_id = '';
                          var a = data.length;
                          for (var i = 0; i < data.length; i++) {
                              var payment_type = '';
                              if (data[i].payment_type == 1) {
                                  payment_type = 'Cash';
                              }
                              else if (data[i].payment_type == 2) {
                                  payment_type = 'Card';
                              }
                              else if (data[i].payment_type == 3) {
                                  payment_type = 'Payment Gateway';
                              }
                              else {
                                  payment_type = '';
                              }
                              if (a == j) {
                                  if (data[i].invoice_id == data[i].invoice_id) {
                                      tr2 = tr2 + '<tr><td>' + data[i].paid_date + '</td><td>' + data[i].payment_amount + '</td><td>' + payment_type + '</td></tr>';
                                      tr = tr + '<tr><td>' + data[i].invoice_id + '</td><td>' + data[i].invoice_date + '</td><td><i class="fa fa-print" onclick=\'Invoice_lab_print(\"' + data[i].lab_order_id + '\",\"' + data[i].visit_report_id + '\",\"' + data[i].invoice_id + '\", \"' + data[i].invoice_description + '\")\';  ></i>' + data[i].invoice_description + '</td><td>' + data[i].invoice_amount + '</td><td class="ptr"><a tabindex="0" class="" data-html="true" data-toggle="popover" data-placement="top" data-trigger="click" title="<span class=\'cpPopClose pull-right\'><i class=\'fa fa-times\' aria-hidden=\'true\'></i></span><table class=\'table\'><thead><tr><th>Pay date</th><th>Amt</th><th>Pay Type</th></tr></thead><tbody>' + tr2 + '</tbody></table>">History</a></td></tr>';
                                      tr2 = '';
                                  }
                              }
                              else {
                                  if (data[i].invoice_id != data[j].invoice_id) {
                                      tr2 = tr2 + '<tr><td>' + data[i].paid_date + '</td><td>' + data[i].payment_amount + '</td><td>' + payment_type + '</td></tr>';
                                      tr = tr + '<tr><td>' + data[i].invoice_id + '</td><td>' + data[i].invoice_date + '</td><td><i class="fa fa-print" onclick=\'Invoice_lab_print(\"' + data[i].lab_order_id + '\",\"' + data[i].visit_report_id + '\",\"' + data[i].invoice_id + '\", \"' + data[i].invoice_description + '\")\'; ></i>' + data[i].invoice_description + '</td><td>' + data[i].invoice_amount + '</td><td class="ptr"><a tabindex="0" class="" data-html="true" data-toggle="popover" data-placement="top" data-trigger="click" title="<span class=\'cpPopClose pull-right\'><i class=\'fa fa-times\' aria-hidden=\'true\'></i></span><table class=\'table\'><thead><tr><th>Pay date</th><th>Amt</th><th>Pay Type</th></tr></thead><tbody>' + tr2 + '</tbody></table>">History</a></td></tr>';
                                      tr2 = '';
                                  }
                                  else {
                                      tr2 = tr2 + '<tr><td>' + data[i].paid_date + '</td><td>' + data[i].payment_amount + '</td><td>' + payment_type + '</td></tr>';
                                  }
                              }
                              j++;
                              // tr = tr + '<tr><td>' + data[i].invoice_id + '</td><td>' + data[i].invoice_date + '</td><td>' + data[i].invoice_description + '</td><td>' + data[i].invoice_amount + '</td><td class="ptr"><a tabindex="0" class="" data-html="true" data-toggle="popover" data-placement="top" data-trigger="click" title="<table class=\'table\'><tbody><td>col1</td><td>col1</td><td>col1</td></tr><tr><td>col1</td><td>col1</td><td>col1</td></tr></tbody></table>">History</a></td></tr>';
                          }
                          tr = tr
                          $('#cpi_historyInvoice_body').html(tr);
                          $("[data-toggle=popover]").popover();
                      }
                  }
                  $('.cpi_historyInvoice_table').removeClass('us-db-loader-history-inv');
              }
              else {
                  console.log(data);
              }
          }
      });
  }


  $('#cpHistoryInvoiceId').click(function () {

      if ($("#cpHistoryInvoice-section").hasClass("in")) {
          $('.paymentcollection').animate({ scrollTop: 600 }, 'slow');
      }
      else {
          $('.paymentcollection').animate({ scrollTop: 600 }, 'slow');
      }

  });

  function historydetails() {
      '<td>col1</td><td>col1</td><td>col1</td></tr><tr><td>col1</td><td>col1</td><td>col1</td></tr>';
  }
  //function yourfunction() { alert('test'); }

  function Invoice_lab_print(order_id, visit_report_id, invoice_id, invoice_description) {
      debugger;
      var dml_indicatr = '', invoice_details = invoice_description.split('-');
      var dml_indicatr = '', invoice_details = invoice_description.split('-');
      if (invoice_details[0] == "package") {
          dml_indicatr = "PP";  //package print
          window.open('/PatientDashboard/doctorfees?visitreportid=' + visit_report_id + '&invoice_id=' + invoice_id + '&indicator=' + dml_indicatr + '&doctorId=' + $('#doctorId').val() + '&btnval=1', "_blank");
      }
      else {
          dml_indicatr = "NP"; //normal invoice print
          var invoice = invoice_description.split(' ');
          if (invoice[0] == "LabOrder") {
              if (order_id != '' && order_id != "null") {
                  window.open('/PatientDashboard/labinvoice?orderid=' + invoice_id + '&doctorId=' + $('#doctorId').val());
              }
          }
          else {
              if (visit_report_id == null || visit_report_id == "" || visit_report_id == "null") {
                  dml_indicatr = "PP";
              }
              window.open('/PatientDashboard/doctorfees?visitreportid=' + visit_report_id + '&invoice_id=' + invoice_id + '&indicator=' + dml_indicatr + '&doctorId=' + $('#doctorId').val() + '&btnval=1', "_blank");
          }
      }
  }


//invoice payment end 


  //load visit type
  function loadvisit_type() {
      debugger;
      var data = {
          P_Dml_Indicator: 'DVT'
      }
      $.ajax({
          async: true,
          type: 'POST',
          url: '/Billing/Service_Master_Ins_upd_sel',
          contentType: 'application/json; charset=UTF-8',
          data: JSON.stringify(data),
          success: function (data) {
              debugger;

              var data1 = JSON.parse(data);

              if (jQuery.isEmptyObject((data1.data))) {

              }
              else {

                  if (data1.msg == "Success") {
                      var data2 = data1.data;

                      if (data2[1].status == 1) {
                          $('#ip_history_tab').removeClass('hidden')
                          //$('#trs_ip_btn').removeClass('hidden')
                      }
                      else {
                          $('#ip_history_tab').addClass('hidden')
                          //$('#trs_ip_btn').addClass('hidden')
                      }
                  }
              }
          }
      })
  }
