<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>Dicom</title>
    <link href="{{ url('assets/css/bootstrap.min.css') }}" rel="stylesheet" type="text/css" />
</head>

<body>
    <div class="container mt-5">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h4>รายการเคส</h4>

                        <form action="{{ url('printpdf') }}" method="post">
                            @csrf
                            <input type="hidden" name="department" value="{{ @$department }}">
                            <input type="hidden" name="event" value="exportpdf">
                            <button type="submit" class="btn btn-primary btn-sm">export pdf</button>
                            <button type="button" class="btn btn-primary btn-sm" id="export_dicom">export dicom</button>
                        </form>
                    </div>
                    <div class="card-body">
                        <button id="checkall" class="btn btn-primary btn-sm mb-2">checkall</button>
                        <div class="table-responsive">
                            <table class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>HN</th>
                                        <th>ชื่อ-นามสกุล</th>
                                        <th>วันที่</th>
                                        <th>แพทย์</th>
                                        <th>สถานะ</th>
                                        <th>จัดการ</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach ($tb_case as $case)
                                        <tr>
                                                <td ><input type="checkbox" name="cid[]" value="{{ $case['_id'] }}"></td>
                                            <td>{{ $case['case_hn'] }}</td>
                                            <td>{{ $case['patientname'] }}</td>
                                            <td>{{ $case['appointment_date'] }}</td>
                                            <td>{{ $case['doctorname'] }}</td>
                                            <td>{{ $case['statusjob'] }}</td>
                                            <td>
                                                <a cid="{{ $case['_id'] }}"
                                                    class="btn btn-primary btn-sm dicom_create">Dicom</a>
                                                {{-- <button class="btn btn-primary btn-sm">พิมพ์</button> --}}
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            {{ $tb_case->links() }}
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-12 mt-4">
                <div class="card">
                    <div class="card-header">
                        <h4>รายการที่พิมพ์แล้ว {{ count($tb_caseyet) }}</h4>
                    </div>
                    <div class="card-body">

                        <div class="table-responsive">
                            <table class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>HN</th>
                                        <th>ชื่อ-นามสกุล</th>
                                        <th>วันที่</th>
                                        <th>แพทย์</th>
                                        <th>สถานะ</th>
                                        <th>จัดการ</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @php
                                        $i = 0;
                                    @endphp

                                    @foreach ($tb_caseyet as $case)
                                        <tr>
                                            <td>{{ $i++ }}</td>
                                            <td>{{ $case['case_hn'] }}</td>
                                            <td>{{ $case['patientname'] }}</td>
                                            <td>{{ $case['appointment_date'] }}</td>
                                            <td>{{ $case['doctorname'] }}</td>
                                            <td>{{ $case['statusjob'] }}</td>
                                            <td>
                                                <a target="_blank" href="{{ url('printpdf/' . $case['_id']) }}"
                                                    class="btn btn-success btn-sm">พิมพ์อีกครั้ง</a>
                                                {{-- <button class="btn btn-success btn-sm">พิมพ์อีกครั้ง</button> --}}
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>


        </div>
    </div>


    <script></script>


    <script src="{{ url('public/js/jquery-3.6.0.min.js') }}"></script>
</body>

</html>

<script>
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
</script>

<script>
    $(document).ready(function() {
        $('.dicom_create').click(function() {
            var cid = $(this).attr('cid');
            $.post("{{ url('dicom') }}", {
                event: "dicom_create",
                cid: cid
            }, function(d,s) {
                let obj = JSON.parse(d);
                if(obj.status == "success"){
                    // alert(obj.dicomname);
                    window.open("http://localhost/dicom/"+obj.dicomname, '_blank');
                }else{
                    alert("ไม่สำเร็จ");
                }
            });
        });

        $("#export_dicom").click(function() {
            var cid = $('input[name="cid[]"]:checked').map(function() {
                return $(this).val();
            }).get();
            $.post("{{ url('dicom') }}", {
                event: "export_dicom",
                cid: cid
            }, function(d,s) {
                console.log(d);
            });
        });

        $("#checkall").click(function() {
            $('input[name="cid[]"]:checkbox').prop('checked', true);
        });

    });
</script>



