Update
This commit is contained in:
@@ -13,6 +13,7 @@ use App\Pasien;
|
||||
use App\Jadwalperiksa;
|
||||
use App\Riwayat;
|
||||
use App\RekapAntibiotik;
|
||||
use App\Organisms;
|
||||
use DateTime;
|
||||
use Carbon\Carbon;
|
||||
use Session;
|
||||
@@ -308,40 +309,62 @@ class ReportController extends Controller
|
||||
}
|
||||
echo json_encode($lists);
|
||||
} else {
|
||||
if ($bulan === 'pertanggal' || $bulan === 'terjadwal') {
|
||||
$results = DB::table($bulan === 'terjadwal' ? 'jadwalperiksan' : 'periksa')->when($bulan === 'terjadwal', function ($query) use ($tahun) {
|
||||
return $query->whereNull('jadwalperiksan.status')
|
||||
->where('jadwalperiksan.daftar', 'LIKE', "%$tahun%");
|
||||
}, function ($query) use ($tahun) {
|
||||
return $query->where('periksa.daftar', 'LIKE', "$tahun%");
|
||||
})->get();
|
||||
$totals = ['m' => 0, 'f' => 0, 'jkn' => 0, 'umum' => 0, 'tag' => 0, 'gcu' => 0, 'bill' => 0, 'swasta' => 0, 'electiv' => 0, 'cito' => 0];
|
||||
foreach ($results as $result) {
|
||||
$asuransi = $result->asuransi;
|
||||
$urgensi = $result->urgensi;
|
||||
$totals = self::updateTotals($totals, $asuransi, $urgensi, $result->jkpasien);
|
||||
$arraylist[] = self::mapResultToArray($result);
|
||||
}
|
||||
if ($bulan === 'pertanggal') {
|
||||
$arraylist[] = self::getTotalRow($totals);
|
||||
}
|
||||
echo json_encode($arraylist);
|
||||
} else {
|
||||
if ($bulan == 'ALL' || $bulan == 'Pick Month') {
|
||||
$results = DB::table('periksa')->where('daftar', 'LIKE', $tahun.'%')->get();
|
||||
$query = Periksa::select('*');
|
||||
if ($bulan !== 'ALL') {
|
||||
$query->whereMonth('mulai', $bulan);
|
||||
}
|
||||
$periksa = $query
|
||||
->whereYear('mulai', $tahun)
|
||||
->orderBy('mulai', 'ASC')
|
||||
->get();
|
||||
|
||||
if ($periksa->count() == 0) {
|
||||
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 {
|
||||
$tglcari = $tahun.'-'.$bulan;
|
||||
$results = DB::table('periksa')->where('daftar', 'LIKE', $tglcari.'%')->get();
|
||||
$row->selisih_hari = null;
|
||||
$row->status_target = "TIDAK ADA HASIL";
|
||||
}
|
||||
$totals = ['m' => 0, 'f' => 0, 'jkn' => 0, 'umum' => 0, 'tag' => 0, 'gcu' => 0, 'bill' => 0, 'swasta' => 0, 'electiv' => 0, 'cito' => 0];
|
||||
foreach ($results as $result) {
|
||||
$asuransi = $result->asuransi;
|
||||
$urgensi = $result->urgensi;
|
||||
$totals = self::updateTotals($totals, $asuransi, $urgensi, $result->jkpasien);
|
||||
$arraylist[] = self::mapResultToArray($result);
|
||||
}
|
||||
$arraylist[] = self::getTotalRow($totals);
|
||||
echo json_encode($arraylist);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -482,6 +505,7 @@ class ReportController extends Controller
|
||||
}
|
||||
return view('admin.glassreport', compact('orderbydate', 'jsonantibiotik', 'bulan', 'tahun'));
|
||||
}
|
||||
|
||||
public function genZNreport(Request $request) {
|
||||
$data = [];
|
||||
$bulan = $request->input('bulan');
|
||||
@@ -493,26 +517,155 @@ class ReportController extends Controller
|
||||
$bulan = str_replace('bulan=', '', $bulan);
|
||||
$tahun = str_replace('tahun=', '', $tahun);
|
||||
}
|
||||
if ($bulan == '' OR $bulan == 'ALL' OR $bulan == 'Pick Month') {
|
||||
$results = DB::table('periksa as p')
|
||||
->leftJoin('db_komponenjawaban', 'p.nofoto', 'db_komponenjawaban.accnumber')
|
||||
->whereMonth('daftar', $bulan)->whereYear('daftar', $tahun)
|
||||
->whereIn('db_komponenjawaban.komponen', ['lsg_pewarnaanziehlnielsen', 'id_pewarnaanziehlnielsen'])
|
||||
->select('db_komponenjawaban.komponen', DB::raw('COUNT(*) as jumlah'))
|
||||
->groupBy('db_komponenjawaban.komponen')
|
||||
->orderByDesc('jumlah')
|
||||
->get();
|
||||
|
||||
// komponen Ziehl yang mau dianalisa
|
||||
$komponenList = [
|
||||
'id_pewarnaanziehlnielsen',
|
||||
'id_pewarnaanziehlnielsensewaktu',
|
||||
'lsg_pewarnaanziehlnielsen',
|
||||
'lsg_pewarnaanziehlnielsensewaktu'
|
||||
];
|
||||
|
||||
// Nilai Ziehl yang ingin dihitung
|
||||
$nilaiList = Organisms::where('kelompok', 'Pewarnaan Ziehl Nielsen')->pluck('name')->toArray();
|
||||
// 1. Ambil periksa sesuai bulan & tahun
|
||||
if ($bulan == '' OR $bulan == 'ALL'){
|
||||
$periksa = Periksa::with(['komponen' => function($q) use ($komponenList){
|
||||
$q->whereIn('komponen', $komponenList);
|
||||
}])
|
||||
->whereYear('mulai', $tahun)
|
||||
->get();
|
||||
} else {
|
||||
$results = DB::table('periksa as p')
|
||||
->leftJoin('db_komponenjawaban', 'p.nofoto', 'db_komponenjawaban.accnumber')
|
||||
->whereMonth('daftar', $bulan)->whereYear('daftar', $tahun)
|
||||
->whereIn('db_komponenjawaban.komponen', ['lsg_pewarnaanziehlnielsen', 'id_pewarnaanziehlnielsen'])
|
||||
->select('db_komponenjawaban.komponen', DB::raw('COUNT(*) as jumlah'))
|
||||
->groupBy('db_komponenjawaban.komponen')
|
||||
->orderByDesc('jumlah')
|
||||
->get();
|
||||
$periksa = Periksa::with(['komponen' => function($q) use ($komponenList){
|
||||
$q->whereIn('komponen', $komponenList);
|
||||
}])
|
||||
->whereMonth('mulai', $bulan)
|
||||
->whereYear('mulai', $tahun)
|
||||
->get();
|
||||
}
|
||||
|
||||
return view('admin.znreport', compact('results', 'bulan', 'tahun'));
|
||||
|
||||
// 2. Ambil distinct kd_spesimen → ini akan jadi kolom
|
||||
$kdSpesimenList = $periksa
|
||||
->pluck('kd_spesimen')
|
||||
->unique()
|
||||
->values();
|
||||
|
||||
// 3. Bangun struktur perhitungan
|
||||
$rekapLaki = [];
|
||||
$rekapPerempuan = [];
|
||||
foreach ($nilaiList as $nilai) {
|
||||
foreach ($kdSpesimenList as $spesimen) {
|
||||
|
||||
// hitung laki-laki
|
||||
$rekapLaki[$nilai][$spesimen] = $periksa
|
||||
->where('kd_spesimen', $spesimen)
|
||||
->where('jkpasien', 'L')
|
||||
->filter(function($px) use ($nilai, $komponenList){
|
||||
return $px->komponen
|
||||
->whereIn('komponen', $komponenList)
|
||||
->where('isidata', $nilai)
|
||||
->count() > 0;
|
||||
})->count();
|
||||
|
||||
// hitung perempuan
|
||||
$rekapPerempuan[$nilai][$spesimen] = $periksa
|
||||
->where('kd_spesimen', $spesimen)
|
||||
->where('jkpasien', 'P')
|
||||
->filter(function($px) use ($nilai, $komponenList){
|
||||
return $px->komponen
|
||||
->whereIn('komponen', $komponenList)
|
||||
->where('isidata', $nilai)
|
||||
->count() > 0;
|
||||
})->count();
|
||||
}
|
||||
}
|
||||
$chartL = [];
|
||||
$chartP = [];
|
||||
|
||||
foreach ($nilaiList as $nilai) {
|
||||
$chartL[] = array_sum($rekapLaki[$nilai]);
|
||||
$chartP[] = array_sum($rekapPerempuan[$nilai]);
|
||||
}
|
||||
|
||||
return view('cetak.znreport', compact(
|
||||
'rekapLaki',
|
||||
'rekapPerempuan',
|
||||
'kdSpesimenList',
|
||||
'nilaiList',
|
||||
'bulan',
|
||||
'tahun',
|
||||
'chartL',
|
||||
'chartP'
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
public function genTATreport(Request $request) {
|
||||
$data = [];
|
||||
$bulan = $request->input('bulan');
|
||||
$tahun = $request->input('tahun');
|
||||
if ($tahun == '' OR is_null($tahun)){
|
||||
$getarray = explode('?', $bulan);
|
||||
$bulan = $getarray[0] ?? date('m');
|
||||
$tahun = $getarray[1] ?? date('Y');
|
||||
$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();
|
||||
|
||||
if ($periksa->count() == 0) {
|
||||
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();
|
||||
return view('cetak.tatreport', [
|
||||
'bulan' => $bulan,
|
||||
'tahun' => $tahun,
|
||||
'detail' => $hasil,
|
||||
'rekap' => $rekap
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user