action-kelolapasien.js 10.3 KB
Newer Older
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
1
Loadpasien()
Indra Raja's avatar
Indra Raja committed
2
function Loadpasien() {
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
3

Indra Raja's avatar
Indra Raja committed
4 5 6
    $.ajax({
        type: 'POST',
        dataType: 'json',
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
7
        url: baseURL + '/api/loadkelolapasien',
Indra Raja's avatar
Indra Raja committed
8 9 10 11 12
        data: {

        },

        success: function (result) {
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
13
            // console.log(result);
Indra Raja's avatar
Indra Raja committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

            $('table.table-bordered > tbody').empty();
            // console.log(result);

            if (result.code == 0) {

                let data = result.data;
                // console.log(data);
                let counter = 1;

                for (x in data) {
                    var newRow = $("<tr>");
                    var cols = "";
                    // onClick="openmyprofile('+reg[x].userid+',\''+reg[x].named+'\')">
                    cols += '<td class="">' + counter + '</td>';
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
29 30
                    cols += '<td class="tdCenterText ">' + data[x].no_rekam_medis + '</td>';
                    cols += '<td class="tdCenterText">' + data[x].ktp + '</td>';
Indra Raja's avatar
Indra Raja committed
31
                    cols += '<td class="tdCenterText bgtd1 tdBorder-left">' + data[x].nama + '</td>';
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
32 33 34 35 36
                    cols += '<td class="tdCenterText bgtd1 tdBorder-left">' + data[x].tempat_lahir + '</td>';
                    cols += '<td class="tdCenterText bgtd1 tdBorder-left">' + data[x].tanggal_lahir + '</td>';
                    cols += '<td class="tdCenterText bgtd1 tdBorder-left">' + data[x].alamat + '</td>';
                    cols += '<td class="tdCenterText bgtd1 tdBorder-left">' + data[x].no_hp + '</td>';
                    cols += '<td class="tdCenterText bgtd1 tdBorder-left">' + data[x].create_date + '</td>';
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
37
                    cols += '<td class="tdCenterText bgtd1 "> <div class="text-center" ><span style="padding: 7px;" class="btn btn-success btn-xs" data-toggle="modal" data-target="#Editdata" onClick="loadedit(' + data[x].id_pasien + ')">Edit</span> <span style="padding: 7px;"class="btn btn-danger btn-xs"  onclick="Delete(' + data[x].id_pasien + ')">Hapus</span></div></td>';
Indra Raja's avatar
Indra Raja committed
38

Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
39
                    // console.log(data[x].id_pasien);
Indra Raja's avatar
Indra Raja committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
                    newRow.append(cols);
                    $("table.table-bordered").append(newRow);
                    counter++;

                    // $('.loaddata').append('' + x + '<span>' + data[x].nama + '</span>');
                }

            } else {
                bootbox.alert({ message: 'Data Antrian Kosong', centerVertical: true });
            }
            $('#dataTable').DataTable({
                "scrollY": '500px',
                "scrollX": true,
                fixedHeader: true,
                scrollCollapse: true,
                paging: true,
                columnDefs: [
                    { width: 30, targets: 0 },
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
58
                    { width: 80, targets: 1 },
Indra Raja's avatar
Indra Raja committed
59 60 61 62
                    { width: 130, targets: 2 },
                    { width: 130, targets: 3 },
                    { width: 130, targets: 4 },
                    { width: 130, targets: 5 },
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
63 64 65 66
                    { width: 130, targets: 6 },
                    { width: 130, targets: 7 },
                    { width: 110, targets: 8 },
                    { width: 100, targets: 9 },
Indra Raja's avatar
Indra Raja committed
67 68 69 70 71 72 73 74 75 76
                ],

            });
        },
        error: function (xhr) {
            alert(xhr.status + '-' + xhr.statusText);
        }
    });
}

Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 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

$('#edit').on('click', function () {
    let id_pasien = $('#id_pasien').val();
    let ktp = $('#ktp').val();
    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();

    if (nama == null || nama == "") {
        bootbox.alert({ message: 'Nama tidak boleh kosong', centerVertical: true });
        return false;
    }
    else if (ktp == null || ktp == "") {
        bootbox.alert({ message: 'No Induk Kependudukan (NIK) 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 (ktp.toString().length > 16) {
        bootbox.alert({ message: 'No Induk Kependudukan (NIK) tidak boleh lebih dari 16 angka', centerVertical: true });
        return false;
    } else if (ktp.toString().length < 16) {
        bootbox.alert({ message: 'No Induk Kependudukan (NIK) tidak boleh kurang dari 16 angka', centerVertical: true });
        return false;
    } else if (no_hp.toString().length > 13) {
        bootbox.alert({ message: 'No Induk Kependudukan (NIK) HP tidak boleh lebih dari 13 angka', centerVertical: true });
        return false;
    }
    else if (validasipasien(ktp) == 1) {
        bootbox.alert({ message: 'No Induk Kependudukan (NIK) Sudah Ada!', centerVertical: true });
    } else {
        editdatapasien(id_pasien)
    }



})

function editdatapasien(id_pasien) {
    let ktp = $('#ktp').val();
    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();

Indra Raja's avatar
Indra Raja committed
139 140 141
    $.ajax({
        type: 'POST',
        dataType: 'json',
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
142
        url: baseURL + '/api/editkelolapasien',
Indra Raja's avatar
Indra Raja committed
143
        data: {
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
144 145 146 147 148 149 150 151
            id_pasien: id_pasien,
            iktp: ktp,
            inama: nama,
            itempat_lahir: tempat_lahir,
            itanggal_lahir: tanggal_lahir,
            ialamat: alamat,
            ino_hp: no_hp,

Indra Raja's avatar
Indra Raja committed
152
        },
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
153 154 155 156 157

        success: function (response) {
            $('#Editdata').modal('hide');
            console.log(response);
            if (response['code'] == 0) {
Indra Raja's avatar
Indra Raja committed
158 159
                swal({
                    title: "",
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
160
                    text: "Data Berhasil DiUbah!",
Indra Raja's avatar
Indra Raja committed
161 162 163 164 165 166 167
                    icon: "succes",
                    button: "ok",
                }, function () {
                    location.reload();
                });

            } else {
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
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
                swal({
                    title: "",
                    text: "Data Gagal Ditambahkan!",
                    icon: "succes",
                    button: "ok",
                });

            }

        },
        error: function (xhr) {

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


    });
}


function validasipasien(ktp) {

    var exist = 0;

    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/api/loadkelolapasien',
        async: false,
        data: {
            id: null,
        },
        success: function (result) {
            console.log(result)
            var data = result.data;
            var ktpcounter = 0;

            for (x in data) {
                if (ktp == data[x]['ktp']) {
                    ktpcounter += 1;
                    if (ktpcounter > 1) {
                        exist = 1;
                    }
                }
            }


        },

        error: function (xhr) {
            //alert(xhr.status+'-'+xhr.statusText);
        }
    });
    return exist;

}


function loadedit(id_pasien) {

    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/api/loadkelolapasien',
        data: {
            id_pasien: id_pasien,
        },
        success: function (result) {
            // console.log(result);
            // $('.loaddata').empty();
            // console.log(result);

            if (result.code == 0) {

                let data = result.data;

                $('#id_pasien').val(data[0].id_pasien);
                $('#no_rekam_medis').val(data[0].no_rekam_medis);
                $('#ktp').val(data[0].ktp);
                $('#nama').val(data[0].nama);
                $('#tempat_lahir').val(data[0].tempat_lahir);
                $('#tanggal_lahir').val(data[0].tanggal_lahir);
                $('#alamat').val(data[0].alamat);
                $('#no_hp').val(data[0].no_hp);

            } else {
                alert(result.info);
Indra Raja's avatar
Indra Raja committed
259
            }
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
260 261 262
        },
        error: function (xhr) {
            alert(xhr.status + '-' + xhr.statusText);
Indra Raja's avatar
Indra Raja committed
263
        }
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
264 265
    });
}
Indra Raja's avatar
Indra Raja committed
266

Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
function Delete(id_pasien) {
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/api/loadkelolapasien',
        data: {
            id_pasien: id_pasien,
        },
        success: function (result) {
            console.log(result);
            let nama_pasien = result.data[0].nama;
            swal({
                title: "Apakah yakin mengahapus pasien '" + nama_pasien + "'? ",
                type: "error",
                confirmButtonClass: "btn-danger",
                confirmButtonText: "Yes!",
                showCancelButton: true,
            },
                function () {
                    $.ajax({
                        type: 'POST',
                        dataType: 'json',
                        url: baseURL + '/api/deletekelolapasien',
                        data: {
                            id_pasien: id_pasien,
                        },
                        success: function (result) {
                            // console.log(result)
                            if (result.code == 0) {
                                swal({
                                    title: "",
                                    text: "Data Berhasil Dihapus!",
                                    icon: "succes",
                                    button: "ok",
                                }, function () {
                                    location.reload();
                                });


                            } else {
                                alert('gagal');
                            }
                        },
                        error: function (xhr) {
                            alert(xhr.status + '-' + xhr.statusText);
                        }
                    });
                }
            );

        }
Indra Raja's avatar
Indra Raja committed
318
    });
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
319

Indra Raja's avatar
Indra Raja committed
320 321
}