<?php
	//debug($exams);
?>

<?php if (!empty($registry)): ?>
	<div class="text-right"><span class="badge badge-secondary">ID: <?php echo $registry['idCartella']; ?></span></div>

	<h4><?php echo _('Registry'); ?></h4>
	<div class="table-overflow table-overflow-popup">
		<table class="table table-hover">
			<thead class="thead-light">
				<tr>
					<th><?php echo _('Age');  ?></th>
					<th><?php echo _('Sex');  ?></th>
					<th><?php echo _('HIV-positive');  ?></th>
					<th><?php echo _('AIDS Stage');  ?></th>
					<th><?php echo _('ART');  ?></th>
				</tr>
			</thead>
			
			<tbody>
				<tr>
					<td><?php echo $registry['age'];  ?></td>
					<td><?php echo $registry['sesso'];  ?></td>
					<td>
						<?php 
							if (isset($HivTestHistory['HIV_Stato'])) {
								echo $HivTestHistory['HIV_Stato']=='HIV_YES' ? _('Yes') : _('No');
							}
						?>
					</td>
					<td>
						<?php 
							if (isset($HivStages['StadioSida'])) {
								echo $HivStages['StadioSida'];
							}
						?>
					</td>
					<td>
						<?php 
							if (isset($TarvHistory['StatoTerapia'])) {
								echo $TarvHistory['StatoTerapia']=='TARV_SI' ? _('Yes') : _('No');
							}
						?>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
<?php endif; ?>

<?php if (!empty($exams)): ?>
	<h4><?php echo _('Examen'); ?></h4>
	<div class="table-overflow table-overflow-popup">
		<table class="table table-hover">
			<thead class="thead-light">
				<tr>
					<th><?php echo _('Date'); ?></th>
					<?php foreach($examsAcr as $label): ?>
						<th><?php echo $label; ?></th>
					<?php endforeach; ?>
				</tr>
			</thead>
			
			<tbody>
				<?php foreach($exams as $exam): ?>
					<tr>
						<td><?php echo $this->helper->getDateString($exam['Data'], false) ?? ''; ?></td>
						<?php foreach($examsAcr as $label): ?>
							<td><?php echo $exam[$label] ?? ''; ?></td>
						<?php endforeach; ?>
					</tr>
				<?php endforeach; ?>
			</tbody>
		</table>
	</div>
<?php endif; ?>

<?php if (!empty($dailyData)): ?>
	<h4><?php echo _('Daily'); ?></h4>
		
		<div class="row margin-bottom-10">
			<?php foreach($examStats as $year => $stat): ?>
				<div class="col-lg-4 col-xl-4"><canvas id="daily-chart-values-<?php echo $year; ?>"></canvas></div>
			<?php endforeach; ?>
		</div>
		
		
		<div class="table-overflow table-overflow-popup">
			<table class="table table-hover">
				<thead class="thead-light">
					<tr>
						<th><?php echo _('Date'); ?></th>
						<th>BMI</th>
						<th>TAmax</th>
						<th>TAmin</th>
						<th>FC</th>
						<th>FR</th>
						<th>TC</th>
						<th><?php echo _('Notes'); ?></th>
						<th><?php echo _('Diagnosis'); ?></th>
						<th><?php echo _('Symptoms'); ?></th>
					</tr>
				</thead>
				
				<tbody>
					<?php foreach($dailyData as $idDiaria => $diariaData): ?>
						<tr>
							<td><?php echo $this->helper->getDateString($diariaData['Diaria']['Data'], false) ?? ''; ?></td>
							<td><?php echo $diariaData['Diaria']['BMI'] ?? ''; ?></td>
							<td><?php echo $diariaData['Diaria']['TAmax'] ?? ''; ?></td>
							<td><?php echo $diariaData['Diaria']['TAmin'] ?? ''; ?></td>
							<td><?php echo $diariaData['Diaria']['FC'] ?? ''; ?></td>
							<td><?php echo $diariaData['Diaria']['FR'] ?? ''; ?></td>
							<td><?php echo $diariaData['Diaria']['TC'] ?? ''; ?></td>
							<td><?php echo $diariaData['Diaria']['Note'] ?? ''; ?></td>
							<td>
								<?php if(isset($diariaData['Sintomi']) && is_array($diariaData['Sintomi'])): ?>
									<ul>
										<?php foreach($diariaData['Sintomi'] as $symptoms): ?>
											<li><?php echo $symptoms['Sintomi']; ?></li>
										<?php endforeach; ?>
									</ul>
								<?php endif; ?>
							</td>
							<td>
								<?php if(isset($diariaData['Diagnosi']) && is_array($diariaData['Diagnosi'])): ?>
									<ul>
										<?php foreach($diariaData['Diagnosi'] as $symptoms): ?>
											<li><?php echo $symptoms['Diagnosi']; ?></li>
										<?php endforeach; ?>
									</ul>
								<?php endif; ?>
							</td>
						</tr>
					<?php endforeach; ?>
				</tbody>
			</table>
		</div>
<?php endif; ?>

<?php if (!empty($TarvHistory)): ?>
	<h4><?php echo _('TARV'); ?></h4>
	<div class="table-overflow table-overflow-popup">
		<table class="table table-hover">
			<thead class="thead-light">
				<tr>
					<th><?php echo _('Date'); ?></th>
					<th><?php echo _('Status'); ?></th>
					<th><?php echo _('Reason'); ?></th>
					<th><?php echo _('Line Description'); ?></th>
					<th><?php echo _('Therapy Description'); ?></th>
				</tr>
			</thead>
			<tbody>
				<?php foreach($TarvHistory as $tHistory): ?>
					<tr>
						<td><?php echo $this->helper->getDateString($tHistory['DataInizio'], false) ?? ''; ?></td>
						<td><?php echo $tHistory['StatoTerapia'] == 'TARV_SI' ? _('Yes') : _('No'); ?></td>
						<td><?php echo $tHistory['Motivo'] ?? ''; ?></td>
						<td><?php echo $tHistory['Descrizione_Linea'] ?? ''; ?></td>
						<td><?php echo $tHistory['Descrizione_Terapia'] ?? ''; ?></td>
					</tr>
				<?php endforeach; ?>
			</tbody>
		</table>
	</div>
<?php endif; ?>

<?php if (!empty($ListaFarmaci)): ?>
	<h4><?php echo _('Available drugs'); ?></h4>
	<div class="table-overflow table-overflow-popup">
		<table class="table table-hover">
			<thead class="thead-light">
				<tr>
					<th><?php echo _('Commercial name'); ?></th>
					<th><?php echo _('Active substance name'); ?></th>
					<th><?php echo _('Dosage'); ?></th>
					<th><?php echo _('Quantity'); ?></th>
				</tr>
			</thead>
			<tbody>
				<?php foreach($ListaFarmaci as $lFarmaci): ?>
					<tr>
						<td><?php echo $lFarmaci['NomeCommerciale'] ?? ''; ?></td>
						<td><?php echo $lFarmaci['NomeComposto'] ?? ''; ?></td>
						<td><?php echo $lFarmaci['Posologia'] ?? ''; ?></td>
						<td><?php echo $lFarmaci['Quantita'] ?? ''; ?></td>
					</tr>
				<?php endforeach; ?>
			</tbody>
		</table>
	</div>
<?php endif; ?>