action-antrian.js 15.1 KB
Newer Older
Indra Raja's avatar
Indra Raja committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

$(document).ready(function () {
    $("#tanggal_lahir").change(function () {
        //console.log("berubah nih!");
        var x = new Date($("#tanggal_lahir").val());
        var Cnow = new Date();
        if (Cnow.getFullYear() < x.getFullYear()) {
            bootbox.alert({
                title: "<span min-height='100px'></span>",
                message: "Tanggal Lahir tidak Boleh Melebihi Tanggal Hari ini!",
                callback: function () {
                    console.log('This was logged in the callback!');
                },
                centerVertical: true
            })
            //$("#tanggal_lahir").val('');
        }
    });
});



$('#cetak').on('click', function (e) {
    //alert("kepanggil");
    e.preventDefault();
    var w = window.open('', '', 'width=300,height=400');
    w.document.write('<html><body><table border="" >' +
        '<tr><th><h1>SELAMAT DATANG</h1><h2> Di Rumah Sakit</h2></th></tr></thead>' +
        '<tbody><tr>' +
        '<th><h2>ANTRIAN</h2>' +
        '<h1>' + kode_dokter_cetak + + no_antrian_cetak + '</h1>' +
        '<h3>Nama Pasien : ' + nama_pasien_cetak + '</h3>' +
        '<h3>Poli : ' + kode_poli_cetak + '</h3>' +
        '<h3>Nama Dokter : ' + nama_dokter_cetak + '</h3>' +
        '</th></tr></tbody></table></body></html>');
    w.window.print();
    w.document.close();
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
38 39 40 41 42 43
    w.window.onafterprint = function () {

        setTimeout(function () {
            w.close()
            window.location.href = baseURL + "/queue/beranda"
        }, 3000);
44
    }
Indra Raja's avatar
Indra Raja committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89

})




$('#tambah').on('click', function () {
    SaveDataAja();
})

function SaveDataAja(param) {
    let nama = $('#nama').val();
    let tempat_lahir = $('#tempat_lahir').val();
    let tanggal_lahir = $('#tanggal_lahir').val();
    let alamat = $('#alamat').val();
    let no_hp = $('#no_hp').val();
    let poli = $("#poli option:selected").attr("value");
    let dokter = $('#dokter option:selected').attr("value");
    let ktp = $('#ktp').val();
    let no_antrian = $("input[name=antrian]:checked").val();

    // console.log(no_antrian);

    /* save data */
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/api/savedata',
        data: {
            iktp: ktp,
            //id_pasien: param,
            inama: nama,
            itempat_lahir: tempat_lahir,
            itanggal_lahir: tanggal_lahir,
            ialamat: alamat,
            ino_hp: no_hp,
            ipoli: poli,
            idokter: dokter,
            ino_antrian: no_antrian,

        },

        success: function (response) {
            // alert("success");
            // response[data];
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
90

Indra Raja's avatar
Indra Raja committed
91
            if (response['code'] == 0) {
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
92
                let $id = response.data.id_pasien;
93
                console.log(response.data);
Indra Raja's avatar
Indra Raja committed
94 95
                // alert($id);
                let $encodedId = btoa($id);
Indra Raja's avatar
Indra Raja committed
96 97
                console.log($encodedId);
                window.location.href = ("cetakantrian/" + $encodedId);
Indra Raja's avatar
Indra Raja committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270

            } else {
                bootbox.alert({ message: ' gagal', centerVertical: true });
            }

        },
        error: function (xhr) {

            if (xhr.status != 200) {
                //bootbox.alert(xhr.status + "-" + xhr.statusText + " <br>Silahkan coba kembali :) ");
            } else {
                alert('dadas');
            }
        }
    });
}


loadpoli();
$('#poli').on('change', function () {
    var idpoli = $('#poli').val();
    console.log(idpoli);
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/api/loaddokter',
        data: {
            id_poli: idpoli
        },
        success: function (result) {

            if (result['code'] == 0) {

                var res = result['data'];
                optionseg = '';
                optionseg += '<option value="Pilih" disabled selected>Pilih</option>';
                for (var i = 0; i < res.length; i++) {
                    optionseg += '<option value="' + res[i].id_dokter + '">' + res[i].nama_dokter + '</option>';
                }
                $("select#dokter").removeAttr('disabled');
                $("select#dokter").html(optionseg);
            } else {
                bootbox.dialog({
                    message: "<span class='bigger-110'>" + result['info'] + "</span>",
                    buttons:
                    {
                        "OK":
                        {
                            "label": "<i class='icon-ok'></i> OK ",
                            "className": "btn-sm btn-danger",
                            "callback": function () {
                                notifyCancel('ERROR: ' + result['info'] + '. Bila ada kesulitan dimohon untuk menghubungi Admin terkait');
                            }
                        }
                    }
                });
            }
        }
    });
});

function loadpoli() {
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/api/loadpoli',

        success: function (result) {
            if (result['code'] == 0) {
                //console.log (result);
                var res = result['data'];

                optionseg = '';
                optionseg += '<option value="Pilih" disabled selected>Pilih</option>';
                for (var i = 0; i < res.length; i++) {
                    optionseg += '<option value="' + res[i].id_poli + '">' + res[i].nama_poli + '</option>';
                }

                $("select#poli").html(optionseg);
            } else {
                bootbox.dialog({
                    message: "<span class='bigger-110'>" + result['info'] + "</span>",
                    buttons:
                    {
                        "OK":
                        {
                            "label": "<i class='icon-ok'></i> OK ",
                            "className": "btn-sm btn-danger",
                            "callback": function () {
                                notifyCancel('ERROR: ' + result['info'] + '. Bila ada kesulitan dimohon untuk menghubungi Admin terkait');
                            }
                        }
                    }
                });
            }
        }
    });
}

$('#pilihno').on('click', function () {

    // let nama = $('#nama').val();
    // let tempat_lahir = $('#tempat_lahir').val();
    // let tanggal_lahir = $('#tanggal_lahir').val();
    // let alamat = $('#alamat').val();
    // let no_hp = $('#no_hp').val();
    // let poli = $("#poli option:selected").attr("value");
    // let dokter = $('#dokter option:selected').attr("value");
    // let ktp = $('#ktp').val();
    // //  let $kode_poli = $("#poli option:selected").attr("code");
    // let $no_antrian = $('#no_antrian').val();
    // // console.log(nama);


    // if (ktp == null || ktp == "") {
    //     bootbox.alert({ message: 'Ktp tidak boleh kosong', centerVertical: true });
    //     return false;
    // }
    // else if (nama == null || nama == "") {
    //     bootbox.alert({ message: 'Nama tidak boleh kosong', centerVertical: true });
    //     return false;
    // } else if (tempat_lahir == null || tempat_lahir == "") {
    //     bootbox.alert({ message: 'Tempat lahir tidak boleh kosong', centerVertical: true });
    //     return false;
    // } else if (tanggal_lahir == null || tanggal_lahir == "") {
    //     bootbox.alert({ message: 'Tanggal lahir tidak boleh kosong', centerVertical: true });
    //     return false;
    // } else if (alamat == null || alamat == "") {
    //     bootbox.alert({ message: 'Alamat tidak boleh kosong', centerVertical: true });
    //     return false;
    // } else if (no_hp == null || no_hp == "") {
    //     bootbox.alert({ message: 'No hp tidak boleh kosong', centerVertical: true });
    //     return false;
    // }
    // else if (poli == null || poli == "") {
    //     bootbox.alert({ message: 'Poli tidak boleh kosong', centerVertical: true });
    //     return false;
    // }
    // else if (dokter == null || dokter == "") {
    //     bootbox.alert({ message: 'Dokter tidak boleh kosong', centerVertical: true });
    //     return false;
    // } else if (ktp.toString().length > 16) {
    //     bootbox.alert({ message: 'KTP tidak boleh lebih dari 16 angka', centerVertical: true });
    //     return false;
    // } else if (ktp.toString().length < 16) {
    //     bootbox.alert({ message: 'KTP tidak boleh kurang dari 16 angka', centerVertical: true });
    //     return false;
    // } else if (no_hp.toString().length > 13) {
    //     bootbox.alert({ message: 'No HP tidak boleh lebih dari 13 angka', centerVertical: true });
    //     return false;
    // } else {
    pilihAntrian()
    // }



});



function pilihAntrian() {
    var $dokter = $('#dokter option:selected').attr("value");
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/api/loadPilihAntrian',
        data: {
            iddok: $dokter,
        },

        success: function (response) {
            console.log(response.data);
            var $antrian = (response.data);
271 272

            $('.antrian').empty();
Indra Raja's avatar
Indra Raja committed
273 274 275
            // console.log($antrian);
            // console.log(response);
            if ($antrian) {
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
276 277 278 279 280 281
                var hour = 0;;

                var splithour = [];
                splithour[0] = $antrian[0]['jam_mulai'].split(':');


Indra Raja's avatar
Indra Raja committed
282 283 284

                hour += parseInt(splithour[0][0]);
                minute = parseInt(splithour[0][1]);
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
285 286 287



Indra Raja's avatar
Indra Raja committed
288 289 290 291 292 293

                for (var i = 0; i < $antrian.length; i++) {
                    if ($antrian[i]['id_pasien'] === null) {
                        let y = '';


Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
294 295 296 297
                        var splittime = [];
                        splittime[i] = $antrian[i]['waktu_antrian'].split(':');


Indra Raja's avatar
Indra Raja committed
298 299

                        if (minute >= 60) {
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
300 301
                            hour += Math.floor(minute / 60);
                            minute = minute % 60;
Indra Raja's avatar
Indra Raja committed
302
                        }
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
303 304

                        if (minute.toString().length === 1) {
Indra Raja's avatar
Indra Raja committed
305 306 307 308
                            y += `<div class="col-lg-1">
                            <div class="buttons" >
                                        <input type="radio" name="antrian" value="` + $antrian[i]['no_antrian'] + `" id="antrian` + i + `" />
                                        <label for="antrian` + i + `">` + $antrian[i]['no_antrian'] + `</label>
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
309
                                        <label style="text-align:center` + i + `">` + hour + ':' + '0' + minute + `</label>
Indra Raja's avatar
Indra Raja committed
310 311 312
                                    </div>
                                </div > `;
                            $('.antrian').append(y);
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
313
                        } else {
Indra Raja's avatar
Indra Raja committed
314 315 316 317
                            y += `<div class="col-lg-1">
                            <div class="buttons" >
                                        <input type="radio" name="antrian" value="` + $antrian[i]['no_antrian'] + `" id="antrian` + i + `" />
                                        <label for="antrian` + i + `">` + $antrian[i]['no_antrian'] + `</label>
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
318
                                        <label style="text-align:center"` + i + `">` + hour + ':' + minute + `</label>
Indra Raja's avatar
Indra Raja committed
319 320 321 322
                                    </div>
                                </div > `;
                            $('.antrian').append(y);
                        }
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
323

Indra Raja's avatar
Indra Raja committed
324 325 326

                        minute += parseInt(splittime[i][1]);

Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
327 328 329
                    } else if ($antrian[i]['status_code'] == 10 || $antrian[i]['status_code'] == 20 || $antrian[i]['status_code'] == 30 || $antrian[i]['status_code'] == 40) {
                        var splittime = [];
                        splittime[i] = $antrian[i]['waktu_antrian'].split(':');
Indra Raja's avatar
Indra Raja committed
330
                        let y = '';
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
331 332 333



Indra Raja's avatar
Indra Raja committed
334 335

                        if (minute >= 60) {
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
336 337
                            hour += Math.floor(minute / 60);
                            minute = minute % 60;
Indra Raja's avatar
Indra Raja committed
338 339
                        }

Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
340
                        if (minute.toString().length === 1) {
Indra Raja's avatar
Indra Raja committed
341 342 343 344
                            y += `<div class="col-lg-1">
                            <div class="buttons" >
                                        <input type="picked" name="antrian" value="` + $antrian[i]['no_antrian'] + `" id="antrian` + i + `" />
                                        <label for="antrian` + i + `">` + $antrian[i]['no_antrian'] + `</label>
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
345
                                        <label for="antrian` + i + `">` + hour + ':' + '0' + minute + `</label>
Indra Raja's avatar
Indra Raja committed
346 347 348
                                    </div>
                                </div > `;
                            $('.antrian').append(y);
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
349
                        } else {
Indra Raja's avatar
Indra Raja committed
350 351 352 353
                            y += `<div class="col-lg-1">
                            <div class="buttons" >
                                        <input type="picked" name="antrian" value="` + $antrian[i]['no_antrian'] + `" id="antrian` + i + `" />
                                        <label for="antrian` + i + `">` + $antrian[i]['no_antrian'] + `</label>
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
354
                                        <label for="antrian` + i + `">` + hour + ':' + minute + `</label>
Indra Raja's avatar
Indra Raja committed
355 356 357 358
                                    </div>
                                </div > `;
                            $('.antrian').append(y);
                        }
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
359

Indra Raja's avatar
Indra Raja committed
360 361
                        minute += parseInt(splittime[i][1]);
                    }
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
362 363
                    else if ($antrian[i]['status_code'] == 60) {

Indra Raja's avatar
Indra Raja committed
364 365 366 367 368 369 370 371 372
                        let y = '';
                        y += `<div class="col-lg-1">
                                <div class="buttons" >
                                    <input type="done" name="antrian" value="` + $antrian[i] + `" id="antrian` + i + `" />
                                    <label for="antrian` + i + `">` + $antrian[i]['no_antrian'] + `</label>
                                  
                                </div>
                            </div > `;
                        $('.antrian').append(y);
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
373 374 375 376 377 378 379
                    } else if ($antrian[i]['status_code'] == 50) {

                        var splittime = [];
                        splittime[i] = $antrian[i]['waktu_antrian'].split(':');



Indra Raja's avatar
Indra Raja committed
380 381 382


                        if (minute >= 60) {
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
383 384
                            hour += Math.floor(minute / 60);
                            minute = minute % 60;
Indra Raja's avatar
Indra Raja committed
385
                        }
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
386

Indra Raja's avatar
Indra Raja committed
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
                        let y = '';
                        y += `<div class="col-lg-1">
                                <div class="buttons" >
                                    <input type="done" name="antrian" value="` + $antrian[i] + `" id="antrian` + i + `" />
                                    <label for="antrian` + i + `">` + $antrian[i]['no_antrian'] + `</label>
                                  
                                </div>
                            </div > `;
                        $('.antrian').append(y);

                        minute += parseInt(splittime[i][1]);
                    }


                }
            } else {
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
403

Indra Raja's avatar
Indra Raja committed
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
            }
        },
        error: function (xhr) {

            if (xhr.status != 200) {
                //bootbox.alert(xhr.status + "-" + xhr.statusText + " <br>Silahkan coba kembali :) ");
            } else {
                alert('Cannot load queue');
            }
        }
    });
}

$(document).ready(function () {
    $('#close').on('click', function () {
        document.getElementById("seat").innerHTML = "";
    })
});