{% extends 'template.html' %}
{% block style %}
	<link href="{% nav public %}css/infomodal.css" rel="stylesheet">
{% endblock %}
{% block subcontent %}
<div style="margin-left:10px;">
	<h2>Kunjungan {{ data.tanggal }} {{ data.jam }}</h2>
	<h3 style="margin:5px 0px;">-- Data Pasien --</h3>
	<table class="data" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td style="width:90px;">No. RM</td>
			<td style="width:492px;">{{ pasien.no_rekmed }}</td>
		</tr>
		<tr>
			<td><b>Nama</b></td>
			<td><b>{{ pasien.nama }}</b>
			</td>
		</tr>
		<tr>
			<td>Alamat</td>
			<td>{{ pasien.alamat }}</td>
		</tr>
		<tr>
			<td>Usia</td>
			<td>{{ pasien.usia }} Tahun</td>
		</tr>
		<tr>
			<td>Jns Kel.</td>
			<td>{{ pasien.sex }}</td>
		</tr>
		<tr>
			<td>Golongan</td>
			<td>{{ data.golongan }}</td>
		</tr>
		<tr>
			<td>Baru/Lama</td>
			<td>{% if data.baru == 'y' %}Baru{% else %}Lama{% endif %}</td>
		</tr>
		<tr>
			<td>List Kunjungan</td>
			<td>
				{% if histori != null %}
					{% for h in histori %}
						<div class="btn-info btn btnModal" style="margin-bottom:5px" onclick="loadHistori({{h.id}})">{{h.tglh}}</div>
					{% endfor %}
				{% else %}
					Tidak Ada
				{% endif %}
			</td>
		</tr>
	</table>
	<br/><br/>
	<form class="items"  method="post">
		{% if session.flash.error != "" %}
			<div class="error">
				<b>Ada Kesalahan:</b><br/> 
				{{ session.flash.error | safe }}
			</div>
		{% endif %}
		<h3 style="margin:5px 0px;">-- Data Poli --</h3>
		<table class="data" cellpadding="0" cellspacing="0" border="0">
			<tr>
				<td style="width:90px;">Poli</td>
				<td style="width:492px;"><b>{{ poli.nama }}</b></td>
			</tr>
			<tr>
				<td>Dokter</td>
				<td>
					<select id="listDokter" name="dokter">
						{% for d in dokter %}
						<option value='{{d.id}}' {% if data.id_dokter == d.id %}selected="selected"{% endif %}>{{d.nama}}</option>
						{% endfor %}
					</select>
				</td>
			</tr>
		</table>
		<br/><br/>
		<h3 style="margin:5px 0px;">-- TTV --</h3>
		<table class="data" cellpadding="0" cellspacing="0" border="0">
			<tr>
				<td style="width:90px;">Suhu</td>
				<td style="width:492px;"><input type="text" name="suhu" value="{{ ttv.suhu }}"/> &deg;C</td>
			</tr>
			<tr>
				<td>Nadi</td>
				<td><input type="text" name="denyut" value="{{ ttv.denyut }}"/> bpm</td>
			</tr>
			<tr>
				<td>Tekanan Darah</td>
				<td><input type="text" name="tekanan_darah" value="{{ ttv.tekanan_darah }}"/> mmHg</td>
			</tr>
			<tr>
				<td>Pernapasan</td>
				<td><input type="text" name="pernapasan" value="{{ ttv.pernapasan }}"/> napas/menit</td>
			</tr>
			<tr>
				<td>Berat Badan</td>
				<td><input type="text" name="berat" value="{{ ttv.berat }}"/> kg</td>
			</tr>
			<tr>
				<td>Tinggi Badan</td>
				<td><input type="text" name="tinggi" value="{{ ttv.tinggi }}"/> cm</td>
			</tr>
		</table>
		<br/><br/>
		<h3 style="margin:5px 0px;">-- Pemeriksaan --</h3>
		<table cellpadding="5">
			<tr valign="top">
				<td style="width:90px;">Keluhan</td>
				<td><textarea name="keluhan" style="width:300px;height:100px">{{ data.keluhan }}</textarea></td>
			</tr>
			<tr valign="top">
				<td>Diagnosa</td>
				<td><textarea name="diagnosis" style="width:300px;height:60px">{{ data.diagnosis }}</textarea></td>
			</tr>
			<tr valign="top">
				<td>Keterangan</td>
				<td><textarea name="keterangan" style="width:300px;height:60px">{{ data.keterangan }}</textarea></td>
			</tr>
		</table>
		<br/>
		<h3 style="margin:5px 0px;">-- Registrasi --</h3>
		<table>
			<tr>
				<td style="width:160px;">Registrasi Pasien Baru</td>
				<td style="width:120px;font-size:16px">Rp {% if data.baru == 'y' %}10.000{% else %} 0{% endif %}</td>
			</tr>
		</table>
		<br/>
		<h3 style="margin:5px 0px;">-- Tindakan --</h3>
		<div class="tindakan">
			<div class="clearfix"></div>
			{% for tk in tindakank %}
				<div class="tindakan_item">
					<div class="option">
						<div class="minus minust btn-danger"><i class="fas fa-minus"></i></div>
					</div>
					<table style="margin-left:30px;width:600px;">
						<tr>
							<td>
								<select class="menu1" name="tindakan[]">
								{% for t in tindakan %}
									<option {%if tk.id_tindakan == t.id%}selected="selected"{%endif%} kode="{{t.kode}}" id_tindakan="{{t.id}}" value="{{t.id}};{{t.harga_jual}}">{{t.kode}} - {{t.nama | safe}}</option>
								{% endfor %}
								</select>
							</td>
							<td style="padding-left:10px;">
								Jml: <input class="jml" value="{{tk.jumlah}}" name="jmlt[]" type="text" style="width:50px;" />
							</td>
							<td>
								<span class="total" style="width:100%;">Rp <span class="total_price">0</span></span>
							</td>
						</tr>
					</table>
				</div>
			{% endfor %}
			<div class="plus plust btn-success"><i class="fas fa-plus"></i></div>
		</div>
		<br/><br/><br/>
		<h3 style="margin:5px 0px;">-- Obat --</h3>
		<div class="obat">
			<div class="clearfix"></div>
			{% for ok in obatk %}
				<div class="obat_item">
					<div class="option">
						<div class="minus minuso btn-danger"><i class="fas fa-minus"></i></div>
					</div>
					<table style="margin-left:30px;width:600px;">
						<tr>
							<td>
								<select class="menu1" name="obat[]">
								{% for o in obat %}
									<option {%if ok.id_obat == o.id%}selected="selected"{%endif%} kode="{{o.kode}}" id_tindakan="{{o.id}}" value="{{o.id}};{{o.harga_jual}}">{{o.nama | safe}}</option>
								{% endfor %}
								</select>
							</td>
							<td style="padding-left:10px;">
								Jml: <input class="jml" value="{{ok.jumlah}}" name="jmlo[]" type="text" style="width:50px;" />
							</td>
							<td>
								<span class="total" style="width:100%;">Rp <span class="total_price">0</span></span>
							</td>
						</tr>
					</table>
				</div>
			{% endfor %}
			<div class="plus pluso btn-success"><i class="fas fa-plus"></i></div>
		</div>
		<br/><br/><br/>
		<table>
			<tr>
				<td style="width:60px;"><h2>Total </h2></td>
				<td style="width:20px;padding-left:10px;color:#666;"></td>
				<td style="width:120px;"><h2>Rp  <span class="total_sum">0</span></h2></td>
			</tr>
		</table>
		<br/><br/><br/>
		<button class="submit btn btn-primary" type="submit" >Selesai</button>
		<div class="batal btn btn-danger" style="margin-left:15px">Batal</div>
		<br/><br/>
	</form>
</div>
<div class="tindakan_item_master" style="display:none">
	<div class="option">
		<div class="minus minust btn-danger"><i class="fas fa-minus"></i></div>
	</div>
	<table style="margin-left:30px;width:600px;">
		<tr>
			<td>
				<select class="menu1" name="tindakan[]">
				{% for t in tindakan %}
					<option kode="{{t.kode}}" id_tindakan="{{t.id}}" value="{{t.id}};{{t.harga_jual}}">{{t.kode}} - {{t.nama | safe}}</option>
				{% endfor %}
				</select>
			</td>
			<td style="padding-left:10px;">
				Jml: <input class="jml" value="1" name="jmlt[]" type="text" style="width:50px;" />
			</td>
			<td>
				<span class="total" style="width:100%;">Rp <span class="total_price">0</span></span>
			</td>
		</tr>
	</table>
</div>
<div class="obat_item_master" style="display:none">
	<div class="option">
		<div class="minus btn-danger"><i class="fas fa-minus"></i></div>
	</div>
	<table style="margin-left:30px;width:600px;">
		<tr>
			<td>
				<select class="menu1" name="obat[]">
				{% for o in obat %}
					<option kode="{{o.kode}}" id_obat="{{o.id}}" value="{{o.id}};{{o.harga_jual}}">{{o.nama | safe}}</option>
				{% endfor %}
				</select>
			</td>
			<td style="padding-left:10px;">
				Jml: <input class="jml" value="1" name="jmlo[]" type="text" style="width:50px;" />
			</td>
			<td>
				<span class="total" style="width:100%;">Rp <span class="total_price">0</span></span>
			</td>
		</tr>
	</table>
</div>
<!-- iModal -->
<div id="infoModal" class="imodal" style="display:none">
  <!-- iModal content -->
	<div class="imodal-content">
		<span class="close">&times;</span>
		<div class="detail-content">
		</div>
	</div>
</div>
{% endblock %}
{% block script %}
<script type="text/javascript">
	var reg = 0;
	var baru = "{{ data.baru }}";
	$(document).ready(function() {
		if (baru == 'y') {
			reg = 10000;
			$(".total_sum").text((reg).formatMoney(0,',','.'));
		}
		$(".plust").on("click",function() {
			newItemT();
		});
		$(".pluso").on("click",function() {
			newItemO();
		});
		$(".minus").on("click",function() {
			$(this).parent().parent().remove();
			hitungTotal();
		});
		$(".batal").on("click",function() {
			location.href = "{% nav perawat_kunjungan %}";
		});
		$(".menu1").on('change',function() {
			$menu = $(this).parent().parent();
			$menu.find('.jml').keyup();
		});
		$(".jml").on("keyup",function() {
			$parent = $(this).parent().parent()
			$super_parent = $parent.parent().parent().parent();
			jml =  $super_parent.find('.jml').val();
			total_price = parseInt(jml * $super_parent.find('select').val().split(';')[1]).formatMoney(0,',','.');
			$super_parent.find('.total_price').text(total_price);
			hitungTotal();
		});
		$(".items").submit(function() {
			$(".submit").attr('disabled','disabled');
		});
		$(".tindakan center").remove();
		$(".obat center").remove();
		$(".tindakan_item .jml").keyup();
		$(".obat_item .jml").keyup();
	});
	<!-- newItemT(); -->
	<!-- newItemO(); -->
	function newItemT() {
		$menu = $(".tindakan_item_master").clone(true).removeClass("tindakan_item_master").addClass("tindakan_item").show();
		$menu.insertBefore($('.plust')).find('.jml').keyup();
	}
	function newItemO() {
		$menu = $(".obat_item_master").clone(true).removeClass("obat_item_master").addClass("obat_item").show();
		$menu.insertBefore($('.pluso')).find('.jml').keyup();
	}
	function loadHistori(id) {
		modal.style.display = "block";
		$('.detail-content').html('Sedang memproses...');
		$('.detail-content').load('{% nav perawat_histori %}?idk='+id);
	}
	function hitungTotal() {
		var total = 0;
		$(".total_price").each(function() {
			total += $(this).text().replace(/\./g,'') *1;
		});
		$(".total_sum").text((total + reg).formatMoney(0,',','.'));
	}
</script>
<script src="{% nav public %}js/infomodal.js" type="text/javascript"></script>
{% endblock %}