TIF_E41200599/resources/views/client-side/konsultasi/hasil-diagnosa.blade.php

198 lines
12 KiB
PHP

@extends('layouts.app')
@section('landingTitle', 'KlinikSapi.Go | Hasil Diagnosa Penyakit')
@section('content')
<section class="bg-white dark:bg-gray-900 pt-20">
<div class="py-8 px-4 mx-auto max-w-screen-xl text-center lg:py-16">
<h1 class="mb-4 text-4xl font-extrabold tracking-tight leading-none text-gray-900 md:text-4xl lg:text-5xl dark:text-white">Hasil Diagnosa Penyakit Sapi</h1>
<p class="text-lg font-normal text-gray-500 lg:text-xl sm:px-16 lg:px-48 dark:text-gray-400">Temukan hasil diagnosa penyakit sapi Anda di sini. Kami memberikan informasi detail untuk membantu Anda memahami kondisi kesehatan ternak Anda.</p>
</div>
</section>
<section class="flex px-44 pb-24">
<div class="relative overflow-x-auto shadow-md sm:rounded-lg w-full">
<form action="{{ route('diagnosa.post') }}" method="post" autocomplete="off">
@csrf
<h2 class="text-2xl text-blue-600 my-8 px-10">> Gejala yang Dipilih</h2>
<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
<tr>
<th scope="col" class="px-6 py-6 text-center" width="5%">#No</th>
{{-- <th scope="col" class="px-6 py-6 text-center" width="15%">Kode Gejala</th> --}}
<th scope="col" class="px-6 py-6 text-center" width="30%">Nama Gejala</th>
<th scope="col" class="px-6 py-6 text-center" width="20%">Penyakit Terkait</th>
{{-- <th scope="col" class="px-6 py-6 text-center" width="30%">Belief</th> --}}
</tr>
</thead>
<tbody>
@foreach ($groupedResults as $result)
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600 text-center">
<td class="px-6 py-4 text-center">{{ $firsttab++ }}</td>
{{-- <td class="px-6 py-4 text-center">
<strong class="text-blue-600">{{ $result['gejalaId'] }}</strong>
<input type="hidden" name="gejalaId[]" value="{{ $result['gejalaId'] }}">
</td> --}}
<td class="px-6 py-4 text-center">{{ $result['gejala'] }}</td>
<td class="px-6 py-4 text-center">
<strong>Total</strong> ({{ count($result['penyakitIds']) }} Penyakit)
</td>
{{-- <td class="px-6 py-4 text-center">
@foreach ($result['allbelief'] as $beliefs)
{{ $beliefs }}@if(!$loop->last), @endif
@endforeach
</td> --}}
</tr>
@endforeach
</tbody>
</table>
{{-- <h2 class="text-2xl text-blue-600 my-8 px-10">> Densitas (m) Awal</h2>
<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
<tr>
<th scope="col" class="px-6 py-6 text-center" width="5%">#No</th>
<th scope="col" class="px-6 py-6 text-center" width="15%">Kode Gejala</th>
<th scope="col" class="px-6 py-6 text-center" width="30%">Nama Gejala</th>
<th scope="col" class="px-6 py-6 text-center" width="30%">Penyakit Terkait</th>
<th scope="col" class="px-6 py-6 text-center" width="10%">Belief</th>
<th scope="col" class="px-6 py-6 text-center" width="10%">Plausibility</th>
</tr>
</thead>
<tbody>
@foreach ($groupedResults as $result)
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600 text-center">
<td class="px-6 py-4 text-center">{{ $secondtab++ }}</td>
<td class="px-6 py-4 text-center">
<strong class="text-blue-600">{{ $result['gejalaId'] }}</strong>
</td>
<td class="px-6 py-4 text-center">{{ $result['gejala'] }}</td>
<td class="px-6 py-4 text-center">
@foreach ($result['penyakitIds'] as $penyakitId)
<strong class="text-blue-600">{{ $penyakitId }}@if(!$loop->last), @endif</strong>
@endforeach
</td>
<td class="px-6 py-4 text-center">{{ $result['belief'] }}</td>
<td class="px-6 py-4 text-center">
{{ $result['plausibility'] == 0.00 || $result['plausibility'] == 1.00 ? round($result['plausibility']) : $result['plausibility'] }}
<input type="hidden" name="nilaiKeyakinan[]" value="{{ $result['plausibility'] }}">
</td>
</tr>
@endforeach
</tbody>
</table> --}}
@php
// Mencari probabilitas terbesar dan penyakit yang terkait
$maxProbabilitas = 0;
$penyakitTerdiagnosa = null;
foreach ($hasilPerhitungan as $penyakitId => $probabilitas) {
if ($probabilitas > $maxProbabilitas) {
$maxProbabilitas = $probabilitas;
$penyakitTerdiagnosa = $penyakitId;
}
}
// Menghitung persentase probabilitas
$persentaseProbabilitas = $maxProbabilitas * 100;
@endphp
{{-- <h2 class="text-2xl text-blue-600 my-8 px-10">> Hasil Perhitungan Dempster-Shafer</h2>
<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400 text-center">
<tr>
<th scope="col" class="px-6 py-6" width="10%">#No</th>
<th scope="col" class="px-6 py-6" width="30%">Kode Penyakit</th>
<th scope="col" class="px-6 py-6" width="50%">Penyakit</th>
<th scope="col" class="px-6 py-6" width="10%">Probabilitas</th>
</tr>
</thead>
<tbody>
@foreach ($hasilPerhitungan as $penyakitId => $probabilitas)
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600 text-center">
<td class="px-6 py-4">
{{ $thirdtab++ }}
</td>
<td class="px-6 py-4">
<strong class="text-blue-600">{{ $penyakitId }}</strong>
</td>
<td class="px-6 py-4">
@if ($penyakitId == 'THETA (ϴ)')
<strong>-</strong>
@else
@php
$penyakitIds = explode(',', $penyakitId);
$penyakitNames = [];
foreach ($penyakitIds as $id) {
$penyakit = \App\Models\Penyakit::find(trim($id));
if ($penyakit) {
$penyakitNames[] = $penyakit->penyakit;
} else {
$penyakitNames[] = "Penyakit ID $id tidak ditemukan";
}
}
@endphp
{{ implode(', ', $penyakitNames) }}
@endif
</td>
<td class="px-6 py-4">
{{ $probabilitas == 1.00 ? 1 : round($probabilitas, 2) }}
</td>
</tr>
@endforeach
</tbody>
</table> --}}
<h2 class="text-2xl text-blue-600 my-8 px-10">> Hasil Diagnosa Penyakit</h2>
<p class="px-10 text-xl text-justify">
@if ($penyakitTerdiagnosa === null || $penyakitTerdiagnosa === 0)
Berdasarkan perhitungan metode Dempster-Shafer, tidak ada penyakit yang ditemukan dengan nilai keyakinan lebih dari <strong>0</strong> atau bila dipersentasekan menjadi <strong>0%</strong>.
@else
Berdasarkan perhitungan metode Dempster-Shafer, penyakit yang paling mungkin adalah
<strong class="text-red-600">
@php
// Pecah ID penyakit menjadi array
$penyakitIDs = explode(',', $penyakitTerdiagnosa);
// Ambil data penyakit berdasarkan array ID
$penyakitList = \App\Models\Penyakit::whereIn('penyakitId', $penyakitIDs)->get();
// Jika penyakit ditemukan, gabungkan nama penyakit dengan koma
$namaPenyakit = $penyakitList->pluck('penyakit')->join(', ');
@endphp
{{ $namaPenyakit ?: "Penyakit dengan ID $penyakitTerdiagnosa tidak ditemukan" }}
</strong>
dengan nilai keyakinan sebesar <strong class="text-red-600">{{ round($maxProbabilitas, 2) }}</strong>
atau bila dipersentasekan menjadi <strong class="text-red-600">{{ round($persentaseProbabilitas) }}%</strong>.
@endif
</p>
<h2 class="text-2xl text-blue-600 my-8 px-10">> Solusi Pencegahan</h2>
<p class="px-10 text-xl text-justify">
@if ($penyakitTerdiagnosa === null || $penyakitTerdiagnosa === 0)
Tidak ada solusi pencegahan yang diperlukan.
@else
@if ($penyakitList)
@foreach ($penyakitList as $penyakit)
{{ $penyakit->deskripsi }} Solusi pencegahan dapat dilakukan dengan cara <strong class="lowercase">{{ $penyakit->solusi }}</strong>.
@endforeach
@else
Informasi deskripsi dan solusi untuk penyakit ID {{ $penyakitTerdiagnosa }} tidak ditemukan.
@endif
@endif
</p>
<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
<tfoot>
<tr>
<td colspan="4" class="text-right px-6 py-10">
<div class="flex gap-10">
<a href="{{ route('diagnosa.penyakit') }}" class="text-white {{ $penyakitTerdiagnosa == 'THETA (ϴ)' ? 'w-full' : 'w-1/2' }} bg-red-500 hover:bg-red-600 focus:ring-4 focus:outline-none focus:ring-red-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-red-600 dark:hover:bg-red-500 dark:focus:ring-red-600">Diagnosa Ulang</a>
<button type="submit" class="text-white w-1/2 bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" {{ $penyakitTerdiagnosa == 'THETA (ϴ)' ? 'hidden' : '' }}>Simpan Hasil Diagnosa</button>
</div>
</td>
</tr>
</tfoot>
</table>
<input type="hidden" name="diagnosaId" value="{{ $diagnosaId }}">
<input type="hidden" name="userId" value="{{ Auth::user()->id }}">
<input type="hidden" name="penyakitId" value="{{ $penyakitTerdiagnosa }}">
<input type="hidden" name="probabilitas" value="{{ $maxProbabilitas }}">
</form>
</div>
</section>
@endsection