

    @include('modal.preview_result_forms.preview_result'. $preview_form_id)



    @include('layout.common_script')
    <script src="https://labonak.com/labonak/public/storage/assets/js/admin/preview_result_forms/preview_result_{{$preview_form_id}}.js"></script>

    <script>


        var patient_base_url = "{{url('patient')}}";


        var get_refs_base_url = "{{url('shared')}}";
        var sample_base_url = "{{url('sample')}}"
        var is_auto_generate_sample_number = 0;
        let sample_id = {{\Route::current()->parameter('id')}};
        let invoice_id = "{{($sample->invoice) ? $sample->invoice->id : 0}}";
        let invoice_code = "{{($sample->invoice) ? $sample->invoice->invoice_code : 0}}";

        let first_prev_sample_id = {{$firstPrvSampleId}};
        let previous_sample_date = "{{$firstPrvSampleDate}}";

        let testSamples = [];

    $.ajax({
        url: get_refs_base_url + '/test-items/' + sample_id +'/'+first_prev_sample_id,
        type: "GET",
        dataType: "json",
        success: function (response) {
            if(response.success){
                $('#sample-result-print').empty()
                let res = response.data
                antibiotic_results = res.antibiotic_results
                for (var i in res.sample_tests){
                    let heading = {"sample": res.sample, "department": res.sample_tests[i].department_name}
                    let samples_list = res.sample_tests[i].samples;
                    for(var j in samples_list){
                        renderPrintTestItemDepartmentRow(samples_list[j], heading,'sample-result-print')
                        var tests = samples_list[j].tests
                        var sampleTest = list_to_tree(tests)
                        sampleTest.map(parent => {
                            renderPrintTestItemRow(parent, '0' ,'test-dep-'+samples_list[j].sample_type_id,' sample-result-print')
                            if(parent.children.length){
                                var children = parent.children
                                children.map(function (child) {
                                    renderPrintTestItemRow(child, '1' ,'test-dep-'+samples_list[j].sample_type_id,' sample-result-print')
                                    if(child.children.length){
                                        var grandchildren = child.children
                                        grandchildren.map(function (grandchild) {
                                            renderPrintTestItemRow(grandchild, '1' ,'test-dep-'+samples_list[j].sample_type_id,' sample-result-print')
                                        })
                                    }
                                });
                            }
                        })
                    }
                }

            } else{
                antibiotic_results = []
            }
        }
    });

    </script>


