This commit is contained in:
Duidev Software House
2025-12-05 19:38:39 +07:00
parent fdbe9c2522
commit e63353db3d
6 changed files with 231 additions and 156 deletions
@@ -32,6 +32,47 @@ use Session;
class Controller extends BaseController
{
use AuthorizesRequests, ValidatesRequests;
private function cekBatasAtas($value, $rule) {
if (!$rule || !str_contains($rule, '>')) return false;
$angka = (int) filter_var($rule, FILTER_SANITIZE_NUMBER_INT);
return $value > $angka;
}
private function cekMidRange($value, $rule) {
if (!$rule) return false;
$rule = trim($rule);
if ($rule === '-' || $rule === '') return false;
if (!str_contains($rule, '-')) return false;
[$min, $max] = array_map('trim', explode('-', $rule));
if (!is_numeric($min) || !is_numeric($max)) return false;
return $value >= (int)$min && $value <= (int)$max;
}
private function cekBatasBawah($value, $rule) {
if (!$rule || !str_contains($rule, '<')) return false;
$angka = (int) filter_var($rule, FILTER_SANITIZE_NUMBER_INT);
return $value < $angka;
}
protected function cekInterpretasi($value, $data) {
if ($this->cekBatasAtas($value, $data->batasatas)) {
return "S";
}
if ($this->cekMidRange($value, $data->midrange)) {
return "I";
}
if ($this->cekBatasBawah($value, $data->batasbawah)) {
return "R";
}
return null;
}
protected function getStyledValue($value, $color, $strong = false) {
return $strong ? "<strong><font color=\"$color\">$value</font></strong>" : "<font color=\"$color\">$value</font>";
}
@@ -1677,9 +1677,14 @@ class DokterController extends Controller
]);
}
if ($request->input('isi') == 'updatevaluemic'){
RekapAntibiotik::where('id', $nofoto)->update([
'value' => $request->input('komponen')
$value = (int) $request->input('komponen');
$data = RekapAntibiotik::findOrFail($nofoto);
$interpretation = $this->cekInterpretasi($value, $data);
$data->update([
'value' => $value,
'interpretation' => $interpretation
]);
$pesan = $interpretation;
}
if ($request->input('isi') == 'updateinterpretationmic'){
RekapAntibiotik::where('id', $nofoto)->update([
@@ -2118,8 +2123,8 @@ class DokterController extends Controller
}
}
public function getAdendum(Request $request) {
$nofoto = $request->input('val01');
$arrayfiles = [];
$nofoto = $request->input('val01');
$arrayfiles = [];
$files = Riwayat::where('nofoto', $nofoto)->orderBy('created_at', 'ASC')->get();
foreach ($files as $file) {
$arrayfiles[] = array(
@@ -40,7 +40,6 @@ use Carbon\Carbon;
class FrontpageController extends Controller
{
protected $lisServiceUrl;
public function __construct() {
$this->lisServiceUrl = env('LIS_SERVICE_URL', 'http://10.10.120.72:5000');
}
@@ -309,65 +309,108 @@ class ReportController extends Controller
}
echo json_encode($lists);
} else {
$query = Periksa::select('*');
$query = Periksa::select('id', 'nofoto', 'noregister', 'nmpasien', 'tlppasien', 'tgllahirpasien', 'usia', 'alamatpasien', 'ktp', 'bpjs', 'asuransi', 'urgensi', 'asalpasien', 'klinisi', 'klinis', 'nmanalis', 'nmppdssenior', 'kd_spesimen', 'nm_spesimen', 'dlp', 'diagnosa2', 'mulai', 'verifikasi', 'status')->whereYear('mulai', $tahun);
if ($bulan !== 'ALL') {
$query->whereMonth('mulai', $bulan);
}
$periksa = $query
->whereYear('mulai', $tahun)
->orderBy('mulai', 'ASC')
->get();
if ($periksa->count() == 0) {
/**
* CURSOR Streaming data, tidak boros memori
*/
$periksaCursor = $query->orderBy('mulai', 'ASC')->cursor();
$hasil = [];
/**
* Karena cursor tidak bisa pluck di awal,
* kita kumpulkan accnumber & poli_id sambil streaming
*/
$acc = [];
$poli_ids = [];
foreach ($periksaCursor as $r) {
$acc[] = $r->nofoto;
$poli_ids[] = $r->poli_id;
$hasil[] = $r; // simpan pointer row
}
/** Jika tidak ada data */
if (empty($hasil)) {
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;
/**
* Ambil komponen terkait (1 query saja)
*/
$komponen = DB::table('db_komponenjawaban')
->select('accnumber','komponen','isidata')
->whereIn('accnumber', array_unique($acc))
->whereIn('komponen', [
'id_bakteri01','id_bakteri02','id_mikroorganisme'
])
->get()
->groupBy('accnumber');
/**
* Ambil poli terkait (1 query)
*/
$poli = DB::table('poli')
->select('id','subpoli','modaliti2')
->whereIn('id', array_unique($poli_ids))
->get()
->keyBy('id');
/**
* Proses setiap row tidak ada map() untuk hemat memori
*/
foreach ($hasil as $row) {
$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;
$row->modaliti2 = $p->modaliti2 ?? '1';
// Hitung status 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";
}
$selisih = Carbon::parse($row->mulai)->diffInDays($row->verifikasi);
$row->selisih_hari = $selisih;
$row->status_target = ($selisih <= intval($row->modaliti2))
? "MEMENUHI TARGET"
: "TIDAK MEMENUHI TARGET";
} else {
$row->selisih_hari = null;
$row->selisih_hari = null;
$row->status_target = "TIDAK ADA HASIL";
}
return $row;
});
if ($jenisreport == 'rekaptat'){
$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();
return response()->json($rekap);
} else {
return response()->json($hasil);
}
/**
* Return untuk dua mode (rekaptat / data penuh)
*/
if ($jenisreport == 'rekaptat') {
$rekap = collect($hasil)->groupBy('kd_spesimen')->map(function($g){
return [
'jenis_pemeriksaan' => $g->first()->kd_spesimen,
'memenuhi' => $g->where('status_target','MEMENUHI TARGET')->count(),
'tidak_memenuhi' => $g->where('status_target','TIDAK MEMENUHI TARGET')->count(),
'tidak_ada_hasil' => $g->where('status_target','TIDAK ADA HASIL')->count(),
'total' => $g->count(),
];
})->values();
return response()->json($rekap);
}
return response()->json($hasil);
}
}
public function genRekapAntibiotik(Request $request) {
$data = [];