@extends('base.layout')

@section('content')
<div class="wrapper">
	<div class="container-fluid">
		<div class="row">
			<div class="col-lg-5">
				<div class="card-box ribbon-box">
					<div class="ribbon ribbon-warning">Search by Date Range</div>
					<p class="m-b-0"></p>
					<div class="form-row">
						<div class="form-group col-lg-4">
							<input type="text" name="mulai" id="mulai" class="form-control" placeholder="Start Date" data-mask="9999-99-99">
						</div>
						<div class="form-group col-lg-4">
							<input type="text" name="akhir" id="akhir" class="form-control" placeholder="End Date" data-mask="9999-99-99">
						</div>
						<div class="form-group col-lg-6 btn-group">
							<button type="button" class="btn btn-warning" id="btnviewcustom"><i class="fa fa-search"></i></button>
							<button type="button" class="btn btn-danger" id="btnviewmanual"><i class="fa fa-user-md"></i> View Manual Only</button>
						</div>
					</div>
				</div>
			</div>
			<div class="col-lg-5">
				<div class="card-box ribbon-box">
					<div class="ribbon ribbon-success">Search by ?</div>
					<p class="m-b-0"></p>
					<div class="form-row">
						<div class="form-group col-lg-4">
							<input type="text" name="valcari" id="valcari" class="form-control" placeholder="Key">
						</div>
						<div class="form-group col-lg-4">
							<select class="form-control" id="valjenis" name="valjenis">
								<option value="norm">No.RM</option>
								<option value="nofoto">No.Foto</option>
							</select>
						</div>
						<div class="form-group col-lg-4">
							<button type="button" class="btn btn-success" id="btnpencarian"><i class="fa fa-search"></i></button>
						</div>
					</div>
				</div>
			</div>
			<div class="col-lg-2">
				<button type="button" class="btn btn-block btn-primary" id="timeremaining">0</button>
				<button type="button" class="btn btn-block btn-danger" id="btnhariinidoank">This Day Only</button>
				<button type="button" class="btn btn-block btn-info" id="btnmundur2">Last 2 Days</button>
				<button type="button" class="btn btn-block btn-warning" id="btnmundur3">Last 3 Days</button>
			</div>
		</div>
		<div class="row">
			<div class="col-lg-4" id="modalkirimkealat">
				<div class="card-box ribbon-box">
					<div class="ribbon ribbon-primary">Cetak BarCode</div>
					<p class="m-b-0"></p>
						<div class="form-group m-b-25">
							<div class="col-12">
								<div class="form-row">
									<div class="form-group col-lg-8">
										<label for="view_nama" class="text-primary">Nama<span class="text-danger">*</span></label>
										<input type="text" name="view_nama" id="view_nama" class="form-control" readonly>
									</div>
									<div class="form-group col-lg-2">
										<label for="view_tanggal" class="text-primary">Tanggal</label>
										<input type="text" class="form-control" id="view_tanggal" name="view_tanggal" readonly>
										<input type="hidden" class="form-control" id="view_tahun" name="view_tahun" readonly>
										<input type="hidden" class="form-control" id="view_noloket" name="view_noloket" readonly>
									</div>
									<div class="form-group col-lg-2">
										<label for="view_noregister" class="text-primary">No.Register</label>
										<input type="text" class="form-control" id="view_noregister" name="view_noregister" readonly>
									</div>
								</div>
								<div class="form-row">
									<div class="form-group col-lg-6">
										<label for="view_klinisi" class="text-primary">Dokter Pengirim</label>
										<input type="text" id="view_klinisi" name="view_klinisi" class="form-control" readonly>
									</div>
									<div class="form-group col-lg-6">
										<label for="view_klinis" class="text-primary">Klinis</label>
										<input type="text" id="view_klinis" name="view_klinis" class="form-control" readonly>
									</div>
								</div>
								<div class="form-row">
									<div class="form-group col-lg-6">
										<label for="view_kd_spesimen" class="text-primary">Code</label>
										<input type="text" id="view_kd_spesimen" name="view_kd_spesimen" class="form-control" readonly>
									</div>
									<div class="form-group col-lg-6">
										<label for="view_nm_spesimen" class="text-primary">Spesimen</label>
										<input type="text" id="view_nm_spesimen" name="view_nm_spesimen" class="form-control" readonly>
									</div>
								</div>
								<div class="form-group">
									<label for="view_modality" class="text-primary">Alat yang di tuju</label>
									<select class="form-control select2" id="view_modality" name="view_modality[]" style="width: 100%;" multiple="multiple">
										<option>Pilih</option>                               
										<option value="Vitek 1">Vitek 01</option>
										<option value="Vitek 2">Vitek 02</option>
										<option value="genexpert01">GeneXpert 01</option>
										<option value="genexpert02">GeneXpert 02</option>
										<option value="genexpert03">GeneXpert 03</option>
										<option value="abbotm2000">Abbot M2000</option>
										<option value="abbotm2000rt">Abbot M2000rt</option>
										<option value="BD Bachtect">BD Bachtect</option>
										<option value="BD MGIT">BD MGIT</option>
									</select>
								</div>
								<div class="form-group">
									<table id="tableModality" class="table">
										<thead>
											<tr>
												<th>No</th>
												<th>Device</th>
												<th>Barcode</th>
												<th>Action</th>
											</tr>
										</thead>
										<tbody>
										</tbody>
									</table>
								</div>
							</div>
						</div>
						<div class="form-group account-btn text-center m-t-10">
							<div class="col-12">
								<input type="hidden" id="view_idne">
								<button class="btn w-lg btn-custom waves-effect waves-light" id="btnkirimkealat" type="button">Save</button>
							</div>
						</div>
				</div>
            </div>
			<div class="col-lg-4" id="modalbaru">
				<div class="card-box ribbon-box">
					<div class="ribbon ribbon-success">Pendaftaran Baru</div>
					<p class="m-b-0"></p>
					<div class="form-group m-b-25">
						<div class="col-12">
							<div class="form-row">
								<div class="form-group col-lg-4">
									<label for="noregister" class="text-primary">No. RM</label>
									<input type="text" class="form-control" id="noregister" name="noregister" placeholder="Silahkan diisi kalau ada">
								</div>
								<div class="form-group col-lg-4">
									<label for="nik" class="text-primary">No. KTP</label>
									<input type="text" id="nik" name="nik" class="form-control">
								</div>
								<div class="form-group col-lg-4">
									<label for="bpjs" class="text-primary">No. BPJS</label>
									<input type="text" id="bpjs" name="bpjs" class="form-control">
								</div>
							</div>
							<div class="form-group">
								<label for="nama" class="text-primary">Nama<span class="text-danger">*</span></label>
								<input type="text" name="nama" id="nama" class="form-control">
							</div>
							<div class="form-row">
								<div class="form-group col-lg-6">
									<label for="tgl" class="text-primary">Tanggal Lahir</label>
									<input type="text" id="tgl" name="tgl_lahir" placeholder="" data-mask="9999-99-99" class="form-control">
								</div>
								<div class="form-group col-lg-6">
									<label for="berat" class="text-primary">Berat Badan (Kg)</label>
									<input type="text" id="berat" name="berat" class="form-control" value="50">
								</div>
							</div>
							<div class="form-group">
								<label for="radio" class="text-primary">Kelamin<span class="text-danger">*</span></label>
								<div class="radio">
									<input type="radio" name="jk" id="radio1" value="L">
									<label for="radio1">Laki-laki</label>&ensp;&ensp;
									<input type="radio" name="jk" id="radio2" value="P">
									<label for="radio2">Perempuan</label>
								</div>
							</div>
							<div class="form-group">
								<label for="alamat" class="text-primary">Alamat</label>
								<input type="text" id="alamat" name="alamat" class="form-control">
							</div>
							<div class="form-group">
								<label for="telpon" class="text-primary">No.HP</label>
								<input type="text" id="telpon" name="telpon" class="form-control" placeholder="Telpon Yang bisa dihubungi">
							</div>
							<div class="form-group">
								<label for="radio" class="text-primary">Asuransi<span class="text-danger">*</span></label>
								<div class="radio">
									<input type="radio" name="insurance" id="radio3" value="UMM">
									<label for="radio3">Umum</label>&ensp;&ensp;
									<input type="radio" name="insurance" id="radio4" value="JKN">
									<label for="radio4">JKN</label>&ensp;&ensp;
									<input type="radio" name="insurance" id="radio5" value="SWASTA">
									<label for="radio5">SWASTA</label>
									<input type="radio" name="insurance" id="radio8" value="TAG">
									<label for="radio8">TAG</label>
									<input type="radio" name="insurance" id="radio9" value="GCU">
									<label for="radio9">GCU</label>
									<input type="radio" name="insurance" id="radio10" value="Billing">
									<label for="radio10">Billing</label>
								</div>
							</div>
							<div class="form-group">
								<label for="radio" class="text-primary">Urgensi<span class="text-danger">*</span></label>
								<div class="radio">
									<input type="radio" name="urgensi" id="radio6" value="Elective">
									<label for="radio6">Elective</label>&ensp;&ensp;
									<input type="radio" name="urgensi" id="radio7" value="CITO">
									<label for="radio7">CITO</label>
								</div>
							</div>
							<div class="form-group">
								<label for="pilihanasal" class="text-primary">Asal Pasien</label>
								<select class="form-control" id="pilihanasal" name="pilihanasal">
									<option value="">Pilih Salah Satu</option>
									<option value="Klinik">Klinik</option>
									<option value="Ruangan">Ruangan</option>
									<option value="Lainnya">Lainnya</option>
								</select>
							</div>
							<div class="form-group" id="viewteksklinik">
								<label for="nmpoli" class="text-primary">Nama Klinik</label>
								<input type="text" id="nmpoli" name="nmpoli" class="form-control" Placeholder="Ketik Nama Klinik">
							</div>
							<div class="form-group" id="viewteksruangan">
								<label for="nmruangan" class="text-primary">Ruangan</label>
								<input type="text" id="nmruangan" name="nmruangan" class="form-control" Placeholder="Ketika Poli / Ruangan Asal Pasien">
							</div>
							<div class="form-group" id="viewtekslainnya">
								<label for="lainlain" class="text-primary">Lain-Lain</label>
								<input type="text" id="lainlain" name="lainlain" class="form-control">
							</div>
							<div class="form-group">
								<label for="klinisi" class="text-primary">Dokter Pengirim</label>
								<input type="text" id="klinisi" name="klinisi" class="form-control">
							</div>
							<div class="form-group">
								<label for="klinis" class="text-primary">Klinis/Diagnosa</label>
								<input type="text" id="klinis" name="klinis" class="form-control">
							</div>
							<div class="form-group">
								<label for="poli" class="text-primary">Permintaan</label>
								<select class="form-control select2" id="poli" name="poli">
									<option value="0">Pilih</option>
									@if(isset($polis) && !empty($polis))
										@foreach($polis as $rpoli)
											<option value="{{ $rpoli->id }}">
												@php
													if ($rpoli->subsubpoli){
														echo $rpoli->subpoli.' ( '.$rpoli->subsubpoli.' )';
													} else {
														echo $rpoli->subpoli;
													}
												@endphp
											</option>
										@endforeach
									@endif
								</select>
							</div>
							<div class="form-group">
								<label for="ruangan" class="text-primary">Jenis Spesimen</label>
								<select class="form-control" id="ruangan" name="ruangan">
									<option value="">Pilih</option>
									@if(isset($lisspesimen) && !empty($lisspesimen))
										@foreach($lisspesimen as $rspesimen)
											<option value="{{ $rspesimen->id }}" valkode="{{ $rspesimen->category }}" valnama="{{ $rspesimen->name }}">{{ $rspesimen->name }} ( {{ $rspesimen->category }} )</option>
										@endforeach
									@endif
								</select>
							</div>
							<div class="form-group m-b-0">
								<p class="mb-2 mt-4 font-weight-bold">Scan Permintaan</p>
								<input type="file" class="filestyle" data-placeholder="No file" data-btnClass="btn-light" id="upload_file" name="upload_file">
							</div>
						</div>
					</div>
					<div class="form-group account-btn text-center m-t-10">
						<div class="col-12">
							<input type="hidden" name="pasien_id" id="pasien_id">
							<input type="hidden" name="supervisor" id="supervisor">
							<input type="hidden" name="jeniskerja" id="jeniskerja">
							<input type="hidden" id="nmrs" name="nmrs" value="RSSA Malang" class="form-control">
							<button type="button" class="btn btn-danger waves-effect waves-light pull-left" id="btnkembali">Kembali</button>
							<button type="button" class="btn btn-success waves-effect waves-light pull-right" id="btnsimpan">Daftar</button>
						</div>
					</div>
					<div class="form-group account-btn text-center m-t-10" id="divpembatalan">
						<div class="col-12">
							<input type="text" id="alasan" name="alasan" placeholder="Tulis Alasan Pembatalannya di Sini" class="form-control">
							<button type="button" class="btn btn-success waves-effect waves-light pull-right" id="btnbatalkan">Batalkan</button>
						</div>
					</div>
				</div>
            </div>
            <div class="col-lg-12" id="modalawal">
				<div class="card-box ribbon-box">
					<div class="ribbon ribbon-primary" id="judul">Queue</div>
					<p class="m-b-0"></p>
					<div class="form-row">
						<div class="form-group col-lg-2">
							<button type="button" class="btn btn-primary" id="btndaftarbaru"><i class="fa fa-plus"></i></button>
						</div>
						<div class="form-group col-lg-2">
							<button type="button" class="btn btn-success" id="btntandaterima"><i class="fa fa-print"></i> Cetak Form Tanda Terima</button>
						</div>
						<div class="form-group col-lg-3">
						</div>
						<div class="form-group col-lg-4 btn-group">
						</div>
					</div>
					<div id="gridpemeriksaan"></div>
				</div>
            </div>
        </div>
	</div>
</div>
<div id="modalhapus" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h4 class="modal-title" id="myModalLabel">Alasan Pembatalan</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal">
					<div class="form-group m-b-25">
						<div class="col-12">
							<label>Tulis alasan pembatalan</label>
							<input type="text" class="form-control" id="id_alasan">							
						</div>
					</div>
					<div class="form-group account-btn text-center m-t-10">
						<div class="col-12">
							<input type="hidden" id="id_pemeriksaan">
							<button class="btn w-lg btn-custom waves-effect waves-light" id="btnpembatalan" type="button">Save</button>
						</div>
					</div>
				</form>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div>
<div id="modalarsip" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h4 class="modal-title" id="myModalLabel">Apakah Anda Yakin Ingin Mengarsipkan ini.?</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal">
					<div class="form-group m-b-25">
						<div class="col-12">
							Data Yang telah diarsipkan akan hilang di tampilan ini, namun bisa di lihat kembali di halaman laporan.						
						</div>
					</div>
					<div class="form-group account-btn text-center m-t-10">
						<div class="col-12">
							<input type="hidden" id="id_arsip">
							<button class="btn w-lg btn-custom waves-effect waves-light" id="btnpengarsipan" type="button">Arsipkan</button>
						</div>
					</div>
				</form>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div>
<input type="hidden" name="_token" id="token" value="{{ csrf_token() }}">
<input type="hidden" id="master_set01" name="master_set01" value="ThisDayPendaftaran">
<input type="hidden" id="master_set02" name="master_set02" value="{{ Session('previlage') }}">
<input type="hidden" id="master_set03" name="master_set03" value="">
<input type="hidden" id="master_set04" name="master_set04" value="">
<input type="hidden" id="getgambar" name="getgambar" value="">
<input type="hidden" id="getjenisgambar" name="getjenisgambar" value="">
<input type="hidden" id="kd_spesimen" name="kd_spesimen" value="">
<input type="hidden" id="nm_spesimen" name="nm_spesimen" value="">
<input type="hidden" id="nofoto" name="nofoto" value="">
<div style="overflow: hidden; display: none;">
	<label for="jadwal" class="text-primary">Dijadwalkan Tanggal, Jam Mulai dan Jam Selesai</label>
	<div class="form-row">
		<div class="form-group col-lg-4">
			<input type="text" class="form-control" id="jadwal" value="{{ date('Y-m-d') }}">
		</div>
		<div class="form-group col-lg-4">
			<div class="input-group clockpicker" data-placement="top" data-align="top" data-autoclose="true" > 
				<input type="text" class="form-control" id="jammulai" placeholder="Now">
				<div class="input-group-append">
					<span class="input-group-text"><i class="mdi mdi-clock"></i></span>
				</div>
			</div>
		</div>
		<div class="form-group col-lg-4">
			<div class="input-group clockpicker" data-placement="top" data-align="top" data-autoclose="true" > 
				<input type="text" class="form-control" id="jamselesai" placeholder="Sampai?">
				<div class="input-group-append">
					<span class="input-group-text"><i class="mdi mdi-clock"></i></span>
				</div>
			</div>
		</div>
	</div>
</div>
@endsection
@push('script')
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script type="text/javascript">
	$("#noregister").on('change', function () {
		var val01	= document.getElementById('noregister').value;
        if (val01 == '') {
            document.getElementById("radio1").checked = false;
            document.getElementById("radio2").checked = false;
            $("#tgl").val("");
            $("#alamat").val("");
            $("#nama").val("");
			$("#pasien_id").val("");
			$("#telpon").val("");
			$("#nik").val("");
			$("#bpjs").val("");
        } else {
			$.post('{{ route("getnamebyrm") }}', { id: val01, _token: "{{ csrf_token() }}" },
			function(data){
				var jk  	= data.jk;
				if (jk == 'L') {
					document.getElementById("radio1").checked = true;
				} else {
					document.getElementById("radio2").checked = true;
				}
				$("#pasien_id").val(data.id);
				$("#telpon").val(data.telpon);
				$("#nama").val(data.nama);
				$("#tgl").val(data.tgl_lahir);
				$("#alamat").val(data.alamat);
				$("#nik").val(data.nik);
				$("#bpjs").val(data.bpjs);
				return false;
			});
            
        }
    });
	var start = new Date();
	CountDownTimer(start, 'timeremaining');
	function CountDownTimer(dt, id) {
		var end 	= new Date(dt.getTime() + 1500000);
		var _second = 1000;
		var _minute = _second * 60;
		var _hour 	= _minute * 60;
		var _day 	= _hour * 24;
		var timer;
		function showRemaining() {
			var now = new Date();
			var distance = end - now;
			if (distance < 0) {
				clearInterval(timer);
				var start = new Date();
				CountDownTimer(start, 'timeremaining');
				$("#gridpemeriksaan").jqxGrid('updatebounddata','filter');
				return;
			}
			var days = Math.floor(distance / _day);
			var hours = Math.floor((distance % _day) / _hour);
			var minutes = Math.floor((distance % _hour) / _minute);
			var seconds = Math.floor((distance % _minute) / _second);
			document.getElementById(id).innerHTML ='Refresh in ';
			document.getElementById(id).innerHTML += seconds + 'secs';
		}
		timer = setInterval(showRemaining, 1000);
	}
	function openedpage( jQuery ){
		var jenis	= document.getElementById('master_set01').value;
		var mulai	= document.getElementById('mulai').value;
		var akhir	= document.getElementById('akhir').value;
		var valcari	= document.getElementById('valcari').value;
		var master	= 'mikro';
		var poli	= 'pendaftaran';
		var set06	= '';
		var token	= document.getElementById('token').value;
		var sourcepasiencari = {
			datatype: "json",
			datafields: [
				{ name: 'id'},
				{ name: 'mulai', type: 'text'},
				{ name: 'akhir', type: 'text'},
				{ name: 'noloket', type: 'text'},
				{ name: 'nofoto', type: 'text'},
				{ name: 'noregister', type: 'text'},
				{ name: 'asalpasien', type: 'text'},
				{ name: 'nmrs', type: 'text'},
				{ name: 'idpasien', type: 'text'},
				{ name: 'nama', type: 'text'},
				{ name: 'jk', type: 'text'},
				{ name: 'tgllahir', type: 'text'},
				{ name: 'telpon', type: 'text'},
				{ name: 'alamat', type: 'text'},
				{ name: 'reques', type: 'text'},
				{ name: 'usia', type: 'text'},
				{ name: 'berat', type: 'text'},
				{ name: 'ruangan_id', type: 'text'},
				{ name: 'ruangan', type: 'text'},
				{ name: 'dokter_id', type: 'text'},
				{ name: 'ppdssenior', type: 'text'},
				{ name: 'middleppds', type: 'text'},
				{ name: 'ppdsjunior', type: 'text'},
				{ name: 'ppdsmiddle2', type: 'text'},
				{ name: 'ppdsjunior2', type: 'text'},
				{ name: 'analis', type: 'text'},
				{ name: 'excutor', type: 'text'},
				{ name: 'nmdokter', type: 'text'},
				{ name: 'nmppdssenior', type: 'text'},
				{ name: 'nmmiddleppds', type: 'text'},
				{ name: 'nmppdsjunior', type: 'text'},
				{ name: 'nmppdsmiddle2', type: 'text'},
				{ name: 'nmppdsjunior2', type: 'text'},
				{ name: 'nmanalis', type: 'text'},
				{ name: 'nmexcutor', type: 'text'},
				{ name: 'klinisi', type: 'text'},
				{ name: 'klinis', type: 'text'},
				{ name: 'poli', type: 'text'},
				{ name: 'poli_id', type: 'text'},
				{ name: 'keterangan', type: 'text'},
				{ name: 'kesimpulan', type: 'text'},
				{ name: 'asuransi', type: 'text'},
				{ name: 'urgensi', type: 'text'},
				{ name: 'diagnosa', type: 'text'},
				{ name: 'diagnosa2', type: 'text'},
				{ name: 'modality', type: 'text'},
				{ name: 'kd_spesimen', type: 'text'},
				{ name: 'nm_spesimen', type: 'text'},
				{ name: 'dlp', type: 'text'},
				{ name: 'daftar', type: 'text'},
				{ name: 'foto', type: 'text'},
				{ name: 'tgldraft', type: 'text'},
				{ name: 'nmdrafter', type: 'text'},
				{ name: 'baca', type: 'text'},
				{ name: 'nmpembaca', type: 'text'},
				{ name: 'verifikasi', type: 'text'},
				{ name: 'export', type: 'text'},
				{ name: 'tgladendum', type: 'text'},
				{ name: 'nmadendum', type: 'text'},
				{ name: 'filefoto', type: 'text'},
				{ name: 'status', type: 'text'},
				{ name: 'tandatangan', type: 'text'},
				{ name: 'jenisfont', type: 'text'},
				{ name: 'jumlah', type: 'text'},
				{ name: 'ktp', type: 'text'},
				{ name: 'bpjs', type: 'text'},
				{ name: 'tlsstatus'},
				{ name: 'tlsnoregister'},
				{ name: 'tlsnama'},
				{ name: 'tlsjk'},
				{ name: 'daftartgl'},
				{ name: 'daftarjam'},
				{ name: 'tlsreques'}
			],
			type		: 'GET',
			cache		: false,
			data		: {jenis:jenis, mulai:mulai, akhir:akhir, valcari:valcari, poli:poli, master:master, _token: token},
			url			: '{{ route("getList") }}',
		};
		var getTanggalDaftar = function (row, column, value) {
			var mulai 	= $('#gridpemeriksaan').jqxGrid('getrowdata', row).daftar;
			var mulai 	= row ? row.mulai : null;
			if (mulai) {
				var arrmulai = mulai.split(' ');
				return arrmulai.length > 1 ? arrmulai[0] : null;
			}
			return null;
		}
		var getJamDaftar = function (row, column, value) {
			var mulai 	= $('#gridpemeriksaan').jqxGrid('getrowdata', row).daftar;
			var mulai 	= row ? row.mulai : null;
			if (mulai) {
				var arrmulai = mulai.split(' ');
				return arrmulai.length > 1 ? arrmulai[1] : null;
			}
			return null;
		}
        var dataAdapter = new $.jqx.dataAdapter(sourcepasiencari, { async: false, loadError: function (xhr, status, error) { console.log('Error loading "' + sourcepasiencari.url + '" : ' + error); } });
    	$("#gridpemeriksaan").jqxGrid({
			width			: '100%',
        	filterable		: true,
			showfilterrow	: true,
			columnsresize	: true,
			pageable		: true,
			sortable		: true,
			autoheight		: true,
			source			: dataAdapter,
			theme			: "energyblue",
			selectionmode	: 'checkbox',
			altrows			: true,
			ready: function ()
			{
				// called when the Grid is loaded. Call methods or set properties here.         
			},
			columns: [
				{ text: 'Form', filterable: false, columntype: 'button', align: 'center', width: 50, cellsrenderer: function () {
					return "Print";
					}, buttonclick: function (row) {        
						editrowjabatan 	= row;   
						var offset      = $("#gridpemeriksaan").offset();       
						var dataRecord  = $("#gridpemeriksaan").jqxGrid('getrowdata', editrowjabatan);
						var selectedRecords = new Array();
						selectedRecords.push(dataRecord.id);
						var token       = document.getElementById('token').value;
						$.post('{{ route("exprintformSIMRS") }}', { set01: selectedRecords,  _token: token },
						function(data){
							var newWindow = window.open('', '', 'width=800, height=500'),
								document = newWindow.document.open(),
								pageContent =
									'<!DOCTYPE html>\n' +
									'<html>\n' +
									'<head>\n' +
									'<meta charset="utf-8" />\n' +
									'<title>Print Form</title>\n' +
									'</head>\n' +
									'<body>' + data + '</body>\n</html>';
								document.write(pageContent);
								document.close();
								newWindow.print();
								return false;
						});
					}
				},
				{ text: 'Edit', filterable: false, columntype: 'button', align: 'center', width: 50, cellsrenderer: function () {
					return "Edit";
					}, buttonclick: function (row) {        
						editrowjabatan 	= row;   
						var offset      = $("#gridpemeriksaan").offset();       
						var dataRecord  = $("#gridpemeriksaan").jqxGrid('getrowdata', editrowjabatan);
						var daftar 		= dataRecord.daftar;
						var arrdaftar 	= daftar.split(' ');
						document.getElementById("radio1").checked = false;
						document.getElementById("radio2").checked = false;
						document.getElementById("radio3").checked = false;
						document.getElementById("radio4").checked = false;
						document.getElementById("radio5").checked = false;
						document.getElementById("radio6").checked = false;
						document.getElementById("radio7").checked = false;
						document.getElementById("radio8").checked = false;
						document.getElementById("radio9").checked = false;
						document.getElementById("radio10").checked = false;
						if (dataRecord.jk == 'L') {
							document.getElementById("radio1").checked = true;
						} else {
							document.getElementById("radio2").checked = true;
						}
						if (dataRecord.urgensi == 'CITO') {
							document.getElementById("radio7").checked = true;
						} else {
							document.getElementById("radio6").checked = true;
						}
						if (dataRecord.asuransi == 'UMM') {
							document.getElementById("radio3").checked = true;
						} else if (dataRecord.asuransi == 'JKN') {
							document.getElementById("radio4").checked = true;
						} else if (dataRecord.asuransi == 'SWASTA') {
							document.getElementById("radio5").checked = true;
						} else if (dataRecord.asuransi == 'TAG') {
							document.getElementById("radio8").checked = true;
						} else if (dataRecord.asuransi == 'GCU') {
							document.getElementById("radio9").checked = true;
						} else {
							document.getElementById("radio10").checked = true;
						}
						$("#kd_spesimen").val(dataRecord.kd_spesimen);
						$("#nm_spesimen").val(dataRecord.nm_spesimen);
						$("#ruangan").val(dataRecord.ruangan_id);
						$("#getgambar").val("");
						$("#upload_file").val("");
						$("#berat").val(dataRecord.berat);
						$("#tgl").val(dataRecord.tgllahir);
						$("#alamat").val(dataRecord.alamat);
						$("#nama").val(dataRecord.nama);
						$("#pasien_id").val(dataRecord.idpasien);
						$("#telpon").val(dataRecord.telpon);
						$("#noregister").val(dataRecord.noregister);
						$("#nmpoli").val(dataRecord.asalpasien);
						$("#nmruangan").val(dataRecord.asalpasien);
						$("#lainlain").val(dataRecord.asalpasien);
						$("#nik").val(dataRecord.ktp);
						$("#bpjs").val(dataRecord.bpjs);
						$("#klinisi").val(dataRecord.klinisi);
						$("#klinis").val(dataRecord.klinis);
						$("#ruangan").val(dataRecord.ruangan_id);
						$("#poli").val(dataRecord.poli_id).select2().trigger('change');
						$("#alasan").val("");
						$("#pilihanasal").val("Ruangan");
						$("#viewteksklinik").hide();
						$("#viewteksruangan").show();
						$("#viewtekslainnya").hide();
						$("#jadwal").val(arrdaftar[0]);
						$("#jeniskerja").val(dataRecord.id);
						$('#modalbaru').show();
						$('#divpembatalan').show();
						$('#modalawal').removeClass('col-lg-12').addClass('col-lg-8');
					}
				},
				{ text: 'Stiker', filterable: false, columntype: 'button', align: 'center', width: 50, cellsrenderer: function () {
					return "Print";
					}, buttonclick: function (row) {        
						editrowjabatan 	= row;   
						var offset      = $("#gridpemeriksaan").offset();       
						var dataRecord  = $("#gridpemeriksaan").jqxGrid('getrowdata', editrowjabatan);
						var token       = document.getElementById('token').value;
						$.post('{{ route("exCekAksess") }}', { nofoto: 'stiker', noregister: dataRecord.noregister, daftartgl: dataRecord.daftartgl, nm_spesimen: dataRecord.nm_spesimen, _token: token },
						function(data){
							jQueryOpenBarCode(data.item, data.nofoto);
						});
						
					}
				},
				{ text: 'Ulang', filterable: false, columntype: 'button', align: 'center', width: 50, cellsrenderer: function () {
					return "Ulang";
					}, buttonclick: function (row) {        
						editrowjabatan 	= row;   
						var offset      = $("#gridpemeriksaan").offset();       
						var dataRecord  = $("#gridpemeriksaan").jqxGrid('getrowdata', editrowjabatan);
						swal({
							title: 'Apakah anda yakin ?',
							text: 'Data Pemeriksaan '+dataRecord.tlsreques+' an '+dataRecord.tlsnama+' akan kami buatkan order baru di LIS.?',
							type: 'warning',
							showCancelButton: true,
							confirmButtonClass: 'btn btn-confirm mt-2',
							cancelButtonClass: 'btn btn-cancel ml-2 mt-2',
							confirmButtonText: 'Yes, Buatkan Ulang'
						}).then(function () {
							$.post('{{ route("deleteList") }}', { val01: 'buatulang', val02: dataRecord.id, val03: '', _token: '{{csrf_token()}}' },
							function(data){
								var status  = data.status;
								var message = data.message;
								$.toast({
									heading: status,
									text: message,
									position: 'top-right',
									loaderBg: '#bf441d',
									icon: 'info',
									hideAfter: 5000,
									stack: 1
								});
								openedpage();
								return false;
							});
						});
					}
				},
				{ text: 'No', filterable: false, datafield: 'noloket', width: 70, cellsalign: 'center', align: 'center' },
				{ text: 'Status', filtertype: 'checkedlist', datafield: 'tlsstatus', width: 75, cellsalign: 'left', align: 'center' },
				{ text: 'AccNumber', datafield: 'nofoto', width: 100, cellsalign: 'left', align: 'center' },
				{ text: 'No.RM', datafield: 'tlsnoregister', width: 100, cellsalign: 'left', align: 'center' },
				{ text: 'Name', datafield: 'tlsnama', width: 150, cellsalign: 'left', align: 'center'  },
				{ text: 'Gender', datafield: 'tlsjk', width: 50, cellsalign: 'left', align: 'center'  },
				{ text: 'Date', datafield: 'daftartgl', width: 80, cellsalign: 'center', align: 'center'  },
				{ text: 'Time', datafield: 'daftarjam', width: 80, cellsalign: 'center', align: 'center'  },
				{ text: 'Urgensi', filtertype: 'checkedlist', datafield: 'urgensi', width: 110, cellsalign: 'left', align: 'center'  },
				{ text: 'Comming From', filtertype: 'checkedlist', datafield: 'asalpasien', width: 120, cellsalign: 'left', align: 'center'  },
				{ text: 'Code', datafield: 'kd_spesimen', width: 80, cellsalign: 'left', align: 'center'  },
				{ text: 'Spesimen', datafield: 'nm_spesimen', width: 120, cellsalign: 'left', align: 'center'  },
				{ text: 'Order', datafield: 'tlsreques', width: 300, cellsalign: 'left', align: 'center'  },
			]
		});
	}
	$('#upload_file').change(function () {
        var imgPath = this.value;
        var ext = imgPath.substring(imgPath.lastIndexOf('.') + 1).toLowerCase();
        if(ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "pdf") {
			$('#getjenisgambar').val(ext);
            readURL(this);
        } else {
            swal({
				title: 'Stop',
				text: 'Please select image file (jpg, jpeg, png or pdf).',
				type: 'warning',
			})
        }
    });
    function readURL(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function (e) {
                //$('#preview').attr('src', e.target.result);
                $('#getgambar').val(e.target.result);
            };
            reader.readAsDataURL(input.files[0]);
        }
    }
	function HTMLOpenBarCode(item, nofoto) {
		var itemParts = item.split('<>');
		var asalpasien = itemParts[0]?.trim() || "xx";
		var kd_spesimen = itemParts[1]?.trim() || "xx";
		var noregister = itemParts[2]?.trim() || "xx";
		var nama = itemParts[3]?.trim() || "xx";
		var tgllahir = itemParts[4]?.trim() || "0000-00-00";
		var reques = itemParts[5]?.trim() || "xx";
		var daftartgl = itemParts[6]?.trim() || "xx";

		var printWindow = window.open('', '', 'width=1000,height=700,scrollbars=yes,resizable=yes');

		var style = `
			<style>
				@page {
					size: 5cm 3.5cm landscape;
					margin: 0;
				}
				@media print {
					body {
						width: 5cm;
						height: 3.5cm;
						margin: 0;
						top: 0mm;
						padding: 0mm;
						font-family: Tahoma, Arial, sans-serif;
					}
				}
				body {
					width: 5cm;
					height: 3.5cm;
					margin: 0;
					padding: 0mm;
					font-family: Tahoma, Arial, sans-serif;
					
				}
				table {
					width: 100%;
					border-collapse: collapse;
					table-layout: fixed;
				}
				svg {
					width: 70%;
					height: 35px;
				}
				td {
					padding: 0;
					margin: 0;
					font-size: 8pt;
					font-weight: bold;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			</style>
		`;

		var html = `
			<html>
			<head>
				<title>Print Barcode</title>
				${style}
			</head>
			<body>
				<table>
					<tr>
						<td>&nbsp;</td><td>${kd_spesimen} / ${asalpasien}</td>
					</tr>
					<tr>
						<td>&nbsp;</td><td><svg id="barcode"></svg></td>
					</tr>
					<tr>
						<td>&nbsp;</td><td>${noregister} / ${nama} / ${tgllahir}</td>
					</tr>
					<tr>
						<td>&nbsp;</td><td>${reques} ( ${daftartgl} )</td>
					</tr>
				</table>
			</body>
			</html>
		`;

		printWindow.document.write(html);
		printWindow.document.close();

		printWindow.onload = function () {
			var barcodeElement = printWindow.document.getElementById('barcode');
			if (barcodeElement) {
				JsBarcode(barcodeElement, nofoto, {
					format: "CODE128",
					displayValue: true,
					height: 25,
					margin: 0
				});

				// Tunggu render selesai, baru print
				setTimeout(() => {
					printWindow.focus();
					printWindow.print();
					printWindow.onafterprint = function () {
						printWindow.close();
					};
				}, 500);
			} else {
				console.error("Element #barcode tidak ditemukan di dalam jendela print.");
			}
		};
	}
	function jQueryOpenBarCode(item, nofoto) {
		if (typeof window.jspdf === 'undefined' || typeof JsBarcode === 'undefined') {
			alert('Kesalahan: Library jsPDF atau JsBarcode belum dimuat.');
			return;
		}
		const itemParts = item.split('<>');
		const asalpasien = itemParts[0]?.trim() || "xx";
		const kd_spesimen = itemParts[1]?.trim() || "xx";
		const noregister = itemParts[2]?.trim() || "xx";
		let nama = itemParts[3]?.trim() || "xx";
		const tgllahir = itemParts[4]?.trim() || "0000-00-00";
		const reques = itemParts[5]?.trim() || "xx";
		const daftartgl = itemParts[6]?.trim() || "xx";
		const kelamin = itemParts[7]?.trim() || "x";
		if (nama.length > 10) {
			nama = nama.substring(0, 10) + ".";
		}
		const { jsPDF } = window.jspdf;
		const doc = new jsPDF({
			orientation: 'landscape',
			unit: 'mm',
			format: [50, 35]
		});
		const leftMargin = 2;
		const contentWidth = 50 - (leftMargin * 2);
		let yPosition = 4;

		doc.setFont('helvetica', 'bold');
		doc.setFontSize(7);
		doc.text(`${kd_spesimen} / ${asalpasien}`, leftMargin, yPosition, {
			maxWidth: contentWidth,
		});
		yPosition += 4;
		try {
			const canvas = document.createElement('canvas');
			JsBarcode(canvas, nofoto, {
				format: "CODE128",
				displayValue: false,
				height: 40,
				width: 1.5,
				margin: 5
			});
			const barcodeDataUrl = canvas.toDataURL('image/png');
			const barcodeHeight = 10;
			doc.addImage(barcodeDataUrl, 'PNG', leftMargin, yPosition, contentWidth, barcodeHeight);
			yPosition += barcodeHeight + 3; 
			doc.setFont('helvetica', 'bold');
			doc.setFontSize(9);
			const centerX = 50 / 2;
			doc.text(nofoto, centerX, yPosition, { align: 'center' });
			yPosition += 4;

		} catch (e) {
			console.error("Gagal membuat barcode:", e);
			doc.text("Error Barcode", leftMargin, yPosition);
			yPosition += 12;
		}
		doc.setFont('helvetica', 'bold');
		doc.setFontSize(6.5);
		doc.text(`${noregister} / ${nama} / ${tgllahir} / ${kelamin}`, leftMargin, yPosition, {
			maxWidth: contentWidth,
		});
		yPosition += 4;
		doc.text(`${reques} ( ${daftartgl} )`, leftMargin, yPosition, {
			maxWidth: contentWidth,
		});
		doc.output('dataurlnewwindow');
	}
	$(window).on('load', function () {
		openedpage();
	});
    $(document).ready(function () {
		
		$("#view_modality").on('change', function() {
			var komponen 	= 'view_modality';
			var isi 		= $(this).val();
			var nofoto 		= document.getElementById('nofoto').value;
			var noregister 	= document.getElementById('view_noregister').value;
			var noloket 	= document.getElementById('view_noloket').value;
			var tahunpendek = document.getElementById('view_tahun').value;
			var kode 		= document.getElementById('view_kd_spesimen').value;
			var nama 		= document.getElementById('view_nama').value;
			var jenis 		= 'mappingalat';
			if (!isi || isi.length === 0) {
				console.log("Tidak ada nilai yang dipilih.");
				return;
			}
			var form_data 	= new FormData();
				form_data.append('nofoto', nofoto);
				form_data.append('komponen', komponen);
				form_data.append('jenis', jenis);
				form_data.append('isi', JSON.stringify(isi));
				form_data.append('keterangan', 'mappingalat');
				form_data.append('_token', '{{csrf_token()}}');
			$.ajax({
				url			: '{{ route("getResult") }}',
				data		: form_data,
				type		: 'POST',
				contentType	: false,
				processData	: false,
				success		: function (data) {
					var tanggal 		= document.getElementById('view_tanggal').value;
					var itemPartsThn 	= tanggal.split('-');
					var tahun 			= itemPartsThn[0].trim();
					var bulan 			= itemPartsThn.length > 1 ? itemPartsThn[1].trim() : "00";
					var tanggal 		= itemPartsThn.length > 2 ? itemPartsThn[2].trim() : "00";
					var tableBody 	= $("#tableModality tbody");
						tableBody.empty();
						isi.forEach(function (item, index) {
							if (item == 'Vitek 1' || item == 'Vitek 2'){
								var barcodeunik = tanggal+bulan+tahun+'-'+noloket;
							} else if (item == 'BD Bachtect' || item == 'BD MGIT'){
								var barcodeunik = tahunpendek+'-'+noloket;
							} else if (item == 'abbotm2000' || item == 'abbotm2000rt'){
								var barcodeunik = tahun+bulan+tanggal+'-'+noloket;
							} else {
								var barcodeunik = nofoto;
							}
							var row = `<tr>
										<td>${index + 1}</td>
										<td>${item}</td>
										<td>${barcodeunik}</td>
										<td><button class="btn btn-primary btn-sm" onClick="jQueryOpenBarCode('${item}<>${tahunpendek}<>${noloket}<>${tanggal}<>${nofoto}<>${noregister}<>${kode}<>${nama}')">Print Barcode</button></td></tr>`;
							tableBody.append(row);
						});
					return false;
				},
				error: function (xhr, status, error) {
					var response 	= xhr.responseJSON || {};
					var traceText 	= response.trace ? JSON.stringify(response.trace) : null;
					console.log(traceText || xhr.responseText);
				}
			});
		});
		$("#tgl").datepicker({format: 'yyyy-mm-dd'});
		$("#mulai").datepicker({format: 'yyyy-mm-dd'});
		$("#akhir").datepicker({format: 'yyyy-mm-dd'});
		$('#modalbaru').hide();
		$('#modalkirimkealat').hide();
		$("#jadwal").datepicker({format: 'yyyy-mm-dd'});
		$("#btnviewcustom").click(function() {
			var mulai=document.getElementById('mulai').value;
			var akhir=document.getElementById('akhir').value;
			if (mulai == ''){
				swal({
					title	: 'Stop',
					text	: 'Start Date Cannot Empty',
					type	: 'warning',
				})
			} else if (akhir == ''){
				swal({
					title	: 'Stop',
					text	: 'End Date Cannot Empty',
					type	: 'warning',
				})
			} else {
				$("#master_set01").val('searchbydate');
				$("#valjenis").val('searchbydate');
				$("#valcari").val('');
				openedpage();
				var judul='Search Result by date Between '+mulai+' and '+akhir;
				$("#judul").html(judul);
			}
		});
		$("#btnviewmanual").click(function() {
			var mulai=document.getElementById('mulai').value;
			var akhir=document.getElementById('akhir').value;
			if (mulai == ''){
				swal({
					title	: 'Stop',
					text	: 'Start Date Cannot Empty',
					type	: 'warning',
				})
			} else if (akhir == ''){
				swal({
					title	: 'Stop',
					text	: 'End Date Cannot Empty',
					type	: 'warning',
				})
			} else {
				$("#master_set01").val('searchbydatemanual');
				$("#valjenis").val('searchbydatemanual');
				$("#valcari").val('');
				openedpage();
				var judul='Search Data Manual by date Between '+mulai+' and '+akhir;
				$("#judul").html(judul);
			}
		});
		$("#btnpencarian").click(function() {
			var set01=document.getElementById('valcari').value;
			var set02=document.getElementById('valjenis').value;
			var set03='inisaja';
			var judul='Search Result by key: '+set01;
			$("#valjenis").val(set02);
			$("#master_set01").val(set02);
			$("#judul").html(judul);
			openedpage();
		});
		$("#btnhariinidoank").click(function() {
			$("#master_set01").val('ThisDayPendaftaran');
			$("#master_set02").val('');
			$("#master_set03").val('');
			$("#master_set04").val('');
			var judul='Patient Queue This Day only';
			$("#judul").html(judul);
			$("#valcari").val('');
			$("#mulai").val('');
			$("#akhir").val('');
			$("#valjenis").val('searchbydate');
			openedpage();
		});
		$("#btnmundur2").click(function() {
			$("#master_set01").val('mundur2');
			$("#master_set02").val('');
			$("#master_set03").val('');
			$("#master_set04").val('');
			$("#valcari").val('');
			$("#mulai").val('');
			$("#akhir").val('');
			$("#valjenis").val('searchbydate');
			var judul='Patient Queue Past 2 Days';
			$("#judul").html(judul);
			openedpage();
		});
		$("#btnmundur3").click(function() {
			$("#master_set01").val('mundur3');
			$("#master_set02").val('');
			$("#master_set03").val('');
			$("#master_set04").val('');
			$("#valcari").val('');
			$("#mulai").val('');
			$("#akhir").val('');
			$("#valjenis").val('searchbydate');
			var judul='Patient Queue Past 3 Days';
			$("#judul").html(judul);
			openedpage();
		});
		$("#btndaftarbaru").click(function(){
			document.getElementById("radio1").checked = false;
            document.getElementById("radio2").checked = false;
            $("#kd_spesimen").val("");
			$("#nm_spesimen").val("");
			$("#ruangan").val("");
			$("#getgambar").val("");
			$("#upload_file").val("");
			$("#tgl").val("");
            $("#alamat").val("");
            $("#nama").val("");
			$("#pasien_id").val("");
			$("#telpon").val("");
			$("#noregister").val("");
			$("#nmpoli").val("");
			$("#nmruangan").val("");
			$("#lainlain").val("");
			$("#pilihanasal").val("");
			$("#viewteksklinik").hide();
			$("#viewteksruangan").hide();
			$("#viewtekslainnya").hide();
			$("#jadwal").val("{{ date('Y-m-d') }}");
			$("#jeniskerja").val("tambahbaru");
			$('#modalbaru').show();
			$('#divpembatalan').hide();
			$('#modalawal').removeClass('col-lg-12').addClass('col-lg-8');
		});
		$("#pilihanasal").on('change', function () {
			var pilihan = this.value;
			if (pilihan == 'Klinik'){
				$("#viewteksklinik").show();
				$("#viewteksruangan").hide();
				$("#viewtekslainnya").hide();
			} else if (pilihan == 'Ruangan'){
				$("#viewteksklinik").hide();
				$("#viewteksruangan").show();
				$("#viewtekslainnya").hide();
			} else if (pilihan == 'Lainnya'){
				$("#viewteksklinik").hide();
				$("#viewteksruangan").hide();
				$("#viewtekslainnya").show();
			} else {
				$("#viewteksklinik").hide();
				$("#viewteksruangan").hide();
				$("#viewtekslainnya").hide();
			}
		});
		$("#ruangan").on('change', function () {
			var valkode 	= $(this).attr('valkode');
			var valnama 	= $(this).attr('valnama');
			$("#kd_spesimen").val(valkode);
			$("#nm_spesimen").val(valnama);
		});
		$("#btnsimpan").click(function(){
			if($('#radio1').is(':checked')) {
				var jk  =   'L';
			} else if($('#radio2').is(':checked')) {
				var jk  =   'P';
			}
			if ($('#radio3').is(':checked')) {
				var insurance	=   'Umum';
			} else if ($('#radio4').is(':checked')) {
				var insurance	=   'JKN';
			} else if ($('#radio8').is(':checked')) {
				var insurance	=   'TAG';
			} else if ($('#radio9').is(':checked')) {
				var insurance	=   'GCU';
			} else if ($('#radio10').is(':checked')) {
				var insurance	=   'Billing';
			} else {
				var insurance   =   'SWASTA';
			}
			if ($('#radio6').is(':checked')) {
				var urgensi     =   'Elective';
			} else {
				var urgensi     =   'CITO';
			}
			var pasien_id   =   document.getElementById('pasien_id').value;
			var nama        =   document.getElementById('nama').value;
			var tgl         =   document.getElementById('tgl').value;
			var alamat      =   document.getElementById('alamat').value;
			var nmruangan   =   document.getElementById('nmruangan').value;
			var nmpoli   	=   document.getElementById('nmpoli').value;
			var lainlain   	=   document.getElementById('lainlain').value;
			var noregister  =   document.getElementById('noregister').value;
			var ruangan     =   document.getElementById('ruangan').value;
			var berat  		=   document.getElementById('berat').value;
			var nmrs  		=   document.getElementById('nmrs').value;
			var klinisi  	=   document.getElementById('klinisi').value;
			var klinis  	=   document.getElementById('klinis').value;
			var jadwal  	=   document.getElementById('jadwal').value;
			var jammulai  	=   document.getElementById('jammulai').value;
			var jamselesai 	=   document.getElementById('jamselesai').value;
			var telpon 		=   document.getElementById('telpon').value;
			var filegambar 	= 	document.getElementById('getgambar').value;
			var jeniskerja 	= 	document.getElementById('jeniskerja').value;
			var supervisor 	= 	document.getElementById('supervisor').value;
			var jenisgambar	= 	document.getElementById('getjenisgambar').value;
			var nik			= 	document.getElementById('nik').value;
			var bpjs		= 	document.getElementById('bpjs').value;
			var token   	=   document.getElementById('token').value;
			var form_data 	= 	new FormData();
				form_data.append('file', filegambar);
				form_data.append('jenisgambar', jenisgambar);
				form_data.append('pasien_id', pasien_id);
				form_data.append('nama', nama);
				form_data.append('tgl', tgl);
				form_data.append('alamat', alamat);
				form_data.append('ruangan', ruangan);
				form_data.append('kd_spesimen', document.getElementById('kd_spesimen').value);
				form_data.append('nm_spesimen', document.getElementById('nm_spesimen').value);
				form_data.append('jk', jk);
				form_data.append('insurance', insurance);
				form_data.append('urgensi', urgensi);
				form_data.append('nmpoli', nmpoli);
				form_data.append('nmruangan', nmruangan);
				form_data.append('lainlain', lainlain);
				form_data.append('noregister', noregister);
				form_data.append('val01', berat);
				form_data.append('val02', nmrs);
				form_data.append('val03', klinisi);
				form_data.append('val04', jadwal);
				form_data.append('val05', jammulai);
				form_data.append('val06', jamselesai);
				form_data.append('val07', telpon);
				form_data.append('val08', jeniskerja);
				form_data.append('val09', supervisor);
				form_data.append('val10', klinis);
				form_data.append('nik', nik);
				form_data.append('bpjs', bpjs);
				form_data.append('poli_id', document.getElementById('poli').value);
				form_data.append('_token', '{{csrf_token()}}');
			$("html, body").animate({ scrollTop: 0 }, "slow");
			$('#modalbaru').hide();
			$('#modalawal').removeClass('col-lg-8').addClass('col-lg-12');
			$.ajax({
				url			: '{{ url("register") }}',
				data		: form_data,
				type		: 'POST',
				contentType	: false,
				processData	: false,
				success		: function (data) {
					var status  = data.status;
					var message = data.message;
					if (status == 'Failed'){
						swal({
							title	: status,
							text	: message,
							type	: 'warning',
						})
					}else {
						$.toast({
							heading		: status,
							text		: message,
							position	: 'top-right',
							loaderBg	: '#5ba035',
							icon		: 'success',
							hideAfter	: 15000,
							stack		: 1
						});
						openedpage();
					}
					return false;
				},
				error: function (xhr, status, error) {
					swal({
						title	: status,
						text	: xhr.responseText,
						type	: 'error',
					})
				}
			});
		});
		$("#btnbatalkan").click(function(){
			var periksa_id  =   document.getElementById('jeniskerja').value;
			var alasan      =   document.getElementById('alasan').value;       
			var tabel       =   'aktif';
			if (periksa_id == '' || alasan == ''){
				swal({
					title	: 'Info',
					text	: 'Alasan tidak boleh dikosongi',
					type	: 'warning',
				})
			} else {
				swal({
					title: 'Apakah anda yakin ?',
					text: 'Data Yang sudah dibatalkan tidak bisa dikembalikan lagi, apakah anda yakin.!',
					type: 'warning',
					showCancelButton: true,
					confirmButtonClass: 'btn btn-confirm mt-2',
					cancelButtonClass: 'btn btn-cancel ml-2 mt-2',
					confirmButtonText: 'Yes'
				}).then(function () {
					$("html, body").animate({ scrollTop: 0 }, "slow");
					$('#modalbaru').hide();
					$('#modalawal').removeClass('col-lg-8').addClass('col-lg-12');
					$.post('{{ route("deleteList") }}', { val01: periksa_id, val02: alasan, val03: tabel, _token: '{{csrf_token()}}' },
					function(data){
						var status  = data.status;
						var message = data.message;
						$.toast({
							heading: status,
							text: message,
							position: 'top-right',
							loaderBg: '#bf441d',
							icon: 'info',
							hideAfter: 5000,
							stack: 1
						});
						openedpage();
						return false;
					});
				});
			}
		});
		$("#btnkirimkealat").click(function(){
			$('#modalawal').removeClass('col-lg-8').addClass('col-lg-12');
			$('#modalkirimkealat').hide();
		});
		$("#btnkembali").click(function(){
			$('#modalawal').removeClass('col-lg-8').addClass('col-lg-12');
			$('#modalbaru').hide();
			openedpage();
		});
		$("#btntandaterima").click(function(){
			var rowsgridcetak = $("#gridpemeriksaan").jqxGrid('selectedrowindexes');
			var selectedRecords = new Array();
			for (var m = 0; m < rowsgridcetak.length; m++) {
				var row = $("#gridpemeriksaan").jqxGrid('getrowdata', rowsgridcetak[m]);
				selectedRecords.push(row.id);
			}
			var token	= document.getElementById('token').value;
			if (m == '0'){
				swal({
					title: 'Stop',
					text: 'Please Select / Checkist First',
					type: 'warning',
				})
			} else {
				$.post('{{ route("exTandaTerima") }}', { set01: selectedRecords,  _token: token },
				function(data){
					var newWindow = window.open('', '', 'width=1024, height=640'),
						document = newWindow.document.open(),
						pageContent =
							'<!DOCTYPE html>\n' +
							'<html>\n' +
							'<head>\n' +
							'<meta charset="utf-8" />\n' +
							'<title>Tanda Terima Sample</title>\n' +
							'</head>\n' +
							'<body>' + data + '</body>\n</html>';
						document.write(pageContent);
						document.close();
						newWindow.print();
					openedpage();
					return false;
				});
			}
		});
    });
</script>
@endpush

