@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-2">
							<button type="button" class="btn btn-warning" id="btnviewcustom"><i class="fa fa-search"></i></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-12">
				<div class="card-box ribbon-box">
					<div class="ribbon ribbon-primary" id="judul">Queue</div>
					<p class="m-b-0"></p>
					<div id="gridpemeriksaan"></div>
				</div>
            </div>
        </div>
	</div>
</div>
<input type="hidden" name="_token" id="token" value="{{ csrf_token() }}">
<input type="hidden" id="master_set01" name="master_set01" value="ThisDay">
<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="">

@endsection
@push('script')
<script type="text/javascript">
	var start = new Date();
	CountDownTimer(start, 'timeremaining');
	function CountDownTimer(dt, id) {
		var end 	= new Date(dt.getTime() + 60000);
		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	= 'pengambilan';
		var poli	= '';
		var set06	= '';
		var token	= document.getElementById('token').value;
		var sourcepasiencari = {
			datatype: "json",
			datafields: [
				{ name: 'id'},
				{ name: 'mulai', type: 'text'},
				{ name: 'akhir', type: 'text'},
				{ name: 'nofoto', type: 'text'},
				{ name: 'noregister', type: 'text'},
				{ name: 'asalpasien', type: 'text'},
				{ name: 'nmrs', type: 'text'},
				{ name: 'pasien_id', type: 'text'},
				{ name: 'nama', type: 'text'},
				{ name: 'jkpasien', type: 'text'},
				{ name: 'tgllahirpasien', type: 'text'},
				{ name: 'tlppasien', type: 'text'},
				{ name: 'alamatpasien', 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_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: '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",
			altrows			: true,
			columns: [
				{ text: 'Result', 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 home 		= '{{URL::to("/")}}';
						var alamat		= home+'/hasil/'+dataRecord.nofoto;
						window.open(alamat,'_blank');
					}
				},
				{ text: 'Acc.No', datafield: 'nofoto', width: 100, cellsalign: 'left', align: 'center' },
				{ text: 'Status', datafield: 'tlsstatus', width: 75, 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: 'Analis', datafield: 'nmanalis', width: 120, cellsalign: 'left', align: 'center'  },
				{ text: 'PPDS', datafield: 'nmppdssenior', width: 120, cellsalign: 'left', align: 'center'  },
				{ text: 'SPV', datafield: 'nmdokter', width: 120, cellsalign: 'left', align: 'center'  },
			]
		});
	}
	$(window).on('load', function () {
		openedpage();
	});
    $(document).ready(function () {
		$("#mulai").datepicker({format: 'yyyy-mm-dd'});
		$("#akhir").datepicker({format: 'yyyy-mm-dd'});
		$("#btnviewcustom").click(function() {
			var mulai=document.getElementById('mulai').value;
			var akhir=document.getElementById('akhir').value;
			if (mulai == ''){
				$("#err_text").val('Start Date Cannot Empty'); 
				$("#modalerror").modal('show'); 
			} else if (akhir == ''){
				$("#err_text").val('End Date Cannot Empty'); 
				$("#modalerror").modal('show'); 
			} else {
				$("#master_set01").val('searchbydate');
				$("#valjenis").val('searchbydate');
				$("#valcari").val('');
				openedpage();
				var judul='Search Result 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('ThisDay');
			$("#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();
		});
    });
</script>
@endpush

