This commit is contained in:
Dwi Swandhana
2026-07-03 20:48:38 +07:00
parent ed92325536
commit f857eec85c
11 changed files with 1820 additions and 1142 deletions
@@ -1136,7 +1136,6 @@ class ReportController extends Controller
}
public function genTATreport(Request $request) {
$data = [];
$bulan = $request->input('bulan');
$tahun = $request->input('tahun');
if ($tahun == '' OR is_null($tahun)){
@@ -1146,59 +1145,55 @@ class ReportController extends Controller
$bulan = str_replace('bulan=', '', $bulan);
$tahun = str_replace('tahun=', '', $tahun);
}
$query = Periksa::select('*');
if ($bulan !== 'ALL') {
$query->whereMonth('mulai', $bulan);
}
$periksa = $query->whereYear('mulai', $tahun)->orderBy('mulai', 'ASC')->get();
$startDate = $bulan === 'ALL'
? Carbon::createFromDate((int) $tahun, 1, 1)->startOfYear()
: Carbon::createFromDate((int) $tahun, (int) $bulan, 1)->startOfMonth();
$endDate = $bulan === 'ALL'
? Carbon::createFromDate((int) $tahun, 1, 1)->endOfYear()
: Carbon::createFromDate((int) $tahun, (int) $bulan, 1)->endOfMonth();
if ($periksa->count() == 0) {
$query = DB::table('periksa')
->leftJoin('poli', 'poli.id', '=', 'periksa.poli_id')
->select('periksa.id', 'periksa.kd_spesimen', 'periksa.mulai', 'periksa.verifikasi', 'poli.modaliti2')
->whereBetween('periksa.mulai', [$startDate->toDateTimeString(), $endDate->toDateTimeString()]);
$rekapRows = [];
$query->chunkById(1000, function ($rows) use (&$rekapRows) {
foreach ($rows as $row) {
$key = $row->kd_spesimen ?: '-';
if (!isset($rekapRows[$key])) {
$rekapRows[$key] = [
'jenis_pemeriksaan' => $key,
'memenuhi' => 0,
'tidak_memenuhi' => 0,
'tidak_ada_hasil' => 0,
'total' => 0,
];
}
if (empty($row->verifikasi)) {
$rekapRows[$key]['tidak_ada_hasil']++;
} else {
$target = $this->resolveTatTargetDays($row->modaliti2 ?? '1');
$status = $this->resolveTatStatus($row->mulai, $row->verifikasi, $target);
if ($status === 'MEMENUHI TARGET') {
$rekapRows[$key]['memenuhi']++;
} else {
$rekapRows[$key]['tidak_memenuhi']++;
}
}
$rekapRows[$key]['total']++;
}
}, 'periksa.id', 'id');
if (empty($rekapRows)) {
return response()->json([]);
}
$accnumbers = $periksa->pluck('nofoto')->toArray();
$komponen = DB::table('db_komponenjawaban')->whereIn('accnumber', $accnumbers)->whereIn('komponen', ['id_bakteri01','id_bakteri02','id_mikroorganisme'])->get()->groupBy('accnumber');
$poli = DB::table('poli')->whereIn('id', $periksa->pluck('poli_id'))->get()->keyBy('id');
$hasil = $periksa->map(function($row) use ($komponen, $poli){
$k = $komponen[$row->nofoto] ?? collect([]);
$row->id_bakteri01 = optional($k->firstWhere('komponen', 'id_bakteri01'))->isidata;
$row->id_bakteri02 = optional($k->firstWhere('komponen', 'id_bakteri02'))->isidata;
$row->bakteri = optional($k->firstWhere('komponen', 'bakteri'))->isidata;
$row->filefoto = "<a href='".url('/hasil/'.$row->nofoto)."'>$row->nofoto</a>";
$p = $poli[$row->poli_id] ?? null;
$row->subpoli = $p->subpoli ?? null;
$target = $p->modaliti2 ?? '1';
$row->modaliti2 = $target;
if (!empty($row->verifikasi)) {
$selisih_hari = Carbon::parse($row->mulai)->diffInDays(Carbon::parse($row->verifikasi));
$target = intval($target);
$hari = intval($selisih_hari);
$row->selisih_hari = $selisih_hari;
if ($hari <= $target) {
$row->status_target = "MEMENUHI TARGET";
} else {
$row->status_target = "TIDAK MEMENUHI TARGET";
}
} else {
$row->selisih_hari = null;
$row->status_target = "TIDAK ADA HASIL";
}
return $row;
});
$rekap = $hasil->groupBy('kd_spesimen')->map(function($group){
return [
'jenis_pemeriksaan' => $group->first()->kd_spesimen,
'memenuhi' => $group->where('status_target', 'MEMENUHI TARGET')->count(),
'tidak_memenuhi' => $group->where('status_target', 'TIDAK MEMENUHI TARGET')->count(),
'tidak_ada_hasil' => $group->where('status_target', 'TIDAK ADA HASIL')->count(),
'total' => $group->count()
];
})->values();
$rekap = collect(array_values($rekapRows));
return view('cetak.tatreport', [
'bulan' => $bulan,
'tahun' => $tahun,
'detail' => $hasil,
'rekap' => $rekap
]);
}