private function process($tanggal, $tanggal2, $departemen_id, $jenis_kunjungan, $jenis_pembayaran_id, $jenis_kelamin, $jenis_laporan, $klinik, $wilayah) { $reportName = "laporan_kunjungan_loket_harian"; $tanggal = $this->reverseDate($tanggal); $tanggal2 = $this->reverseDate($tanggal2); $objPHPExcel = $this->loadPHPExcelLib($reportName); $rekapArray = array(); foreach (JenisPembayaran::model()->findAll("status = '1'") as $jp) { $rekapArray[$jp->nama] = array(); foreach (Poli::model()->findAllByAttributes(array("jenis" => 1, "status" => 1)) as $poli) { $rekapArray[$jp->nama][$poli->nama] = array("L" => 0, "P" => 0); } } $objPHPExcel->setActiveSheetIndex(0); $activeSheet = $objPHPExcel->getActiveSheet(); //judul $activeSheet->getCell("B4")->setValue("Tanggal : " . $tanggal); $filter = ""; if (substr("" . $departemen_id, 0, 4) == "wil_") { $puskesmas = Puskesmas::model()->findByPk(substr("" . $departemen_id, 4)); $departemen = NULL; $activeSheet->getCell("B3")->setValue("Wilayah Puskesmas " . ucwords(strtolower($puskesmas->nama))); } else { $departemen = Departemen::model()->findByPk($departemen_id); $puskesmas = Puskesmas::model()->findByPk($departemen->puskesmas_id); $activeSheet->getCell("B3")->setValue($departemen->nama); $filter = " AND departemen_id = '" . $departemen->id . "'"; } if ($jenis_kunjungan != "") { $filter .= " AND jenis_kunjungan = '" . $jenis_kunjungan . "' "; } if ($jenis_pembayaran_id != "") { $filter .= " AND jenis_pembayaran_id = '" . $jenis_pembayaran_id . "' "; } if ($jenis_laporan != "") { $arrayDiagnosaKhusus = array(); foreach (Lb1JenisLaporanDetail::model()->findAllByAttributes(array("jenis_id" => $jenis_laporan)) as $data) { $arrayDiagnosaKhusus[] = $data->penyakit_id; } } //header $baris = 8; $no = 1; $transaksiArray = TransaksiKunjungan::model()->findAll("waktu between '{$tanggal} 00:00:00' AND '{$tanggal2} 23:59:00' AND puskesmas_id = '" . $puskesmas->id . "'" . $filter); foreach ($transaksiArray as $kunjungan) { $pasien = Pasien::model()->findByPk($kunjungan->pasien_id); if ($jenis_kelamin != "" && $pasien->jenis_kelamin != $jenis_kelamin) { continue; } if ($wilayah != "" && $pasien->dalam_wilayah != $wilayah) { continue; } $ada = FALSE; $kosong = TRUE; $jenis_pembayaran = JenisPembayaran::model()->findByPk($kunjungan->jenis_pembayaran_id); $poli = Poli::model()->findByPk($kunjungan->poli_tujuan); $diagnosaArray = array(); $idDiagnosaArray = array(); $meds = TransaksiMedicalRecord::model()->findAllByAttributes(array("kunjungan_id" => $kunjungan->id)); foreach ($meds as $med) { $diags = TransaksiDiagnosa::model()->findAllByAttributes(array("medical_record_id" => $med->id)); foreach ($diags as $diag) { $kosong = FALSE; $ada = TRUE; /* if($jenis_laporan != "" && !in_array($diag->penyakit_id, $arrayDiagnosaKhusus)){ }else{ $ada = TRUE; }*/ $penyakit = Penyakit::model()->findByAttributes(array("id" => $diag->penyakit_id)); $diagnosaArray[] = "[" . $penyakit->kode . "/" . $diag->jenis_kasus . "] " . ($penyakit->nama_indonesia == "" ? $penyakit->nama : $penyakit->nama_indonesia); } } $ada2 = FALSE; $kosong2 = TRUE; $bpArray = array(); $ants = TransaksiAntrian::model()->findAllByAttributes(array("kunjungan_id" => $kunjungan->id)); foreach ($ants as $ant) { $kosong2 = FALSE; if ($klinik != "" && $ant->poli_tujuan != $klinik) { } else { $ada2 = TRUE; } $polie = Poli::model()->findByPk($ant->poli_tujuan); $rekapArray[$jenis_pembayaran->nama][$polie->nama][$pasien->jenis_kelamin] += 1; $bpArray[] = $polie->nama; } if ($kosong || $kosong2 || $ada && $ada2) { } else { continue; } $activeSheet->getCellByColumnAndRow(1, $baris)->setValue($no . "."); $activeSheet->getCellByColumnAndRow(2, $baris)->setValue(date("d-m-Y", strtotime($kunjungan->waktu))); $activeSheet->getCellByColumnAndRow(3, $baris)->setValueExplicit($pasien->kode, PHPExcel_Cell_DataType::TYPE_STRING); $activeSheet->getCellByColumnAndRow(4, $baris)->setValue($pasien->nama); $age = date_diff(date_create($pasien->tanggal_lahir), date_create($kunjungan->waktu))->y; if ($age > 200) { $age = 0; } $activeSheet->getCellByColumnAndRow(5, $baris)->setValue($age); $activeSheet->getCellByColumnAndRow(6, $baris)->setValue($pasien->jenis_kelamin); $activeSheet->getCellByColumnAndRow(7, $baris)->setValue($pasien->alamat); $activeSheet->getCellByColumnAndRow(8, $baris)->setValue($pasien->nama_kepala_keluarga); $activeSheet->getCellByColumnAndRow(9, $baris)->setValueExplicit($pasien->no_ktp, PHPExcel_Cell_DataType::TYPE_STRING); $activeSheet->getCellByColumnAndRow(10, $baris)->setValue($jenis_pembayaran->nama); $activeSheet->getCellByColumnAndRow(11, $baris)->setValueExplicit($kunjungan->kode_asuransi, PHPExcel_Cell_DataType::TYPE_STRING); $activeSheet->getCellByColumnAndRow(12, $baris)->setValue($kunjungan->jenis_kunjungan == "B" ? "Baru" : "Lama"); $activeSheet->getCellByColumnAndRow(13, $baris)->setValue(implode(", ", $diagnosaArray)); //diagnosa $activeSheet->getCellByColumnAndRow(14, $baris)->setValue(implode(", ", $bpArray)); //bp $tujuan = $poli->nama . " : " . ucwords(strtolower(Departemen::model()->findByPk($kunjungan->departemen_id)->nama)); $activeSheet->getCellByColumnAndRow(15, $baris)->setValue($tujuan); $baris++; $no++; } $activeSheet->getStyle("B8:P" . ($baris - 1))->applyFromArray(array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN)))); //Pindah ke sheet 2 $objPHPExcel->setActiveSheetIndex(1); $activeSheet = $objPHPExcel->getActiveSheet(); $smbaris = 4; foreach ($rekapArray as $key => $rekap) { $num = 2; $activeSheet->getCellByColumnAndRow(1, $smbaris)->setValue($key); foreach (Poli::model()->findAllByAttributes(array("jenis" => 1, "status" => 1)) as $poli) { if ($smbaris == 4) { //set judul $activeSheet->getCellByColumnAndRow($num, 2)->setValue($poli->nama); $activeSheet->getCellByColumnAndRow($num, 3)->setValue("Lk"); $activeSheet->getCellByColumnAndRow($num + 1, 3)->setValue("Pr"); $activeSheet->getCellByColumnAndRow($num + 2, 3)->setValue("Total"); $activeSheet->mergeCellsByColumnAndRow($num, 2, $num + 2, 2); } $activeSheet->getCellByColumnAndRow($num, $smbaris)->setValue($rekap[$poli->nama]["L"]); $activeSheet->getCellByColumnAndRow($num + 1, $smbaris)->setValue($rekap[$poli->nama]["P"]); $activeSheet->getCellByColumnAndRow($num + 2, $smbaris)->setValue($rekap[$poli->nama]["L"] + $rekap[$poli->nama]["P"]); $num += 3; } if ($smbaris == 4) { $activeSheet->getStyle("B2:" . $this->get_col_letter($num - 1) . "3")->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => '8B0000')), 'font' => array('color' => array('rgb' => 'FFFFFF')))); } $smbaris++; } $this->fillBorder($activeSheet, "B2:" . $this->get_col_letter($num - 1) . ($smbaris - 1)); $activeSheet->getStyle("B4:" . $this->get_col_letter($num - 1) . ($smbaris - 1))->applyFromArray(array('font' => array('color' => array('rgb' => '000000'), 'size' => 13, 'name' => 'Calibri'))); $activeSheet->getStyle("C4:" . $this->get_col_letter($num - 1) . ($smbaris - 1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); return array("phpexcel" => $objPHPExcel, "name" => $reportName . "_" . $tanggal); }
private function process($month, $year, $departemen_id, $kategori_penyakit) { $reportName = "laporan_lb1"; $objPHPExcel = $this->loadPHPExcelLib($reportName); $objPHPExcel->setActiveSheetIndex(0); $activeSheet = $objPHPExcel->getActiveSheet(); $namaBulan = array("1" => "Januari", "2" => "Februari", "3" => "Maret", "4" => "April", "5" => "Mei", "6" => "Juni", "7" => "Juli", "8" => "Agustus", "9" => "September", "10" => "Oktober", "11" => "November", "12" => "Desember"); //judul $activeSheet->getCell("B3")->setValue(": " . Setting::getNamaPuskesmas()); $activeSheet->getCell("B4")->setValue(": " . Setting::getKodePuskesmas()); $activeSheet->getCell("B5")->setValue(": " . CHtml::value(WilayahKabupaten::model()->findByPk(Setting::getKabupaten()), "nama")); $activeSheet->getCell("AW4")->setValue($namaBulan[$month]); $activeSheet->getCell("AW5")->setValue($year); $filter = ""; if (substr("" . $departemen_id, 0, 4) == "wil_") { $puskesmas = Puskesmas::model()->findByPk(substr("" . $departemen_id, 4)); $departemen = NULL; } else { $departemen = Departemen::model()->findByPk($departemen_id); $puskesmas = Puskesmas::model()->findByPk($departemen->puskesmas_id); $filter = " AND departemen_id = '" . $departemen->id . "'"; } $kodePusk = Setting::getKodePuskesmas(); //konten $globaldata = array(); $baris = 11; $trs = array(); if ($kategori_penyakit == "") { //$trs = Penyakit::model()->findAll("lb1_status = '1'"); foreach (Penyakit::model()->findAll("lb1_status = '1'") as $p) { $trs[] = $p->id; } } else { foreach (Lb1JenisLaporanDetail::model()->findAllByAttributes(array("jenis_id" => $kategori_penyakit)) as $detail) { //$penyakit = Penyakit::model()->findByAttributes(array("id" => $detail->penyakit_id)); $trs[] = $detail->penyakit_id; } } $jumlahData = 0; foreach ($trs as $p) { $activeSheet->getCellByColumnAndRow(0, $baris)->setValue($kodePusk); $activeSheet->getCellByColumnAndRow(1, $baris)->setValue($namaBulan[$month]); $activeSheet->getCellByColumnAndRow(2, $baris)->setValue($year); $activeSheet->getCellByColumnAndRow(3, $baris)->setValue($p->kode); $activeSheet->getCellByColumnAndRow(4, $baris)->setValue($p->nama_indonesia); //$activeSheet->getCell("CE".$baris)->setValue($p->id); $output = array(); for ($i = 0; $i < 18; $i++) { $output[$i . "_L_B"] = 0; $output[$i . "_L_L"] = 0; $output[$i . "_P_B"] = 0; $output[$i . "_P_L"] = 0; } $globaldata[$p] = $output; $baris++; $jumlahData++; } $diags = TransaksiDiagnosa::model()->findAll("puskesmas_id = '" . $puskesmas->id . "' AND year(waktu) = '{$year}' AND month(waktu) = '{$month}'" . $filter); foreach ($diags as $diag) { $med = TransaksiMedicalRecord::model()->findByPk($diag->medical_record_id); $pasien = Pasien::model()->findByPk($med->pasien_id); $jenis_kelamin = $pasien->jenis_kelamin; $kategoriUmur = $this->getKategoriUmur($pasien); if (in_array($diag->penyakit_id, $trs)) { $globaldata[$diag->penyakit_id][$kategoriUmur . "_" . $jenis_kelamin . "_" . $diag->jenis_kasus] += 1; } } $jumlahIsi = 0; $baris = 11; foreach ($globaldata as $penyakit_id => $output) { /* $kunjungans = TransaksiKunjungan::model()->findAll("puskesmas_id = '{$puskemas_id}' AND year(waktu) = '{$year}' AND month(waktu) = '{$month}'"); foreach($kunjungans as $kunjungan){ $pasien = Pasien::model()->findByPk($kunjungan->pasien_id); $jenis_kelamin = $pasien->jenis_kelamin; //get kategori umur $kategoriUmur = $this->getKategoriUmur($pasien); $medRecArray = array(); $antrians = TransaksiAntrian::model()->findAll("kunjungan_id = '{$kunjungan->id}'"); foreach($antrians as $antrian){ $medRecArray[$antrian->medical_record_id] = 1; } foreach($medRecArray as $key => $val){ $diags = TransaksiDiagnosa::model()->findAll("puskesmas_id = '{$puskemas_id}' AND medical_record_id = '{$key}' AND penyakit_id = '{$p->id}'"); foreach($diags as $diag){ $output[$kategoriUmur."_".$jenis_kelamin."_".$diag->jenis_kasus] += 1; } } } */ $jml = array(); $jml["L_B"] = 0; $jml["L_L"] = 0; $jml["P_B"] = 0; $jml["P_L"] = 0; for ($kat = 0; $kat <= 17; $kat++) { $kolom = 10 + $kat * 4; $activeSheet->getCellByColumnAndRow($kolom, $baris)->setValue($output[$kat . "_L_B"]); $activeSheet->getCellByColumnAndRow($kolom + 1, $baris)->setValue($output[$kat . "_L_L"]); $activeSheet->getCellByColumnAndRow($kolom + 2, $baris)->setValue($output[$kat . "_P_B"]); $activeSheet->getCellByColumnAndRow($kolom + 3, $baris)->setValue($output[$kat . "_P_L"]); $jml["L_B"] += $output[$kat . "_L_B"]; $jml["L_L"] += $output[$kat . "_L_L"]; $jml["P_B"] += $output[$kat . "_P_B"]; $jml["P_L"] += $output[$kat . "_P_L"]; } $p = Penyakit::model()->findByAttributes(array("id" => $penyakit_id)); $activeSheet->getCellByColumnAndRow(0, $baris)->setValue($kodePusk); $activeSheet->getCellByColumnAndRow(1, $baris)->setValue($namaBulan[$month]); $activeSheet->getCellByColumnAndRow(2, $baris)->setValue($year); $activeSheet->getCellByColumnAndRow(3, $baris)->setValue($p->kode); $nama = $p->nama_indonesia; if ($nama == "") { $nama = $p->nama; } $activeSheet->getCellByColumnAndRow(4, $baris)->setValue($nama); $activeSheet->getCellByColumnAndRow(5, $baris)->setValue("=SUM(G" . $baris . ":J" . $baris . ")"); $activeSheet->getCellByColumnAndRow(6, $baris)->setValue($jml["L_B"]); $activeSheet->getCellByColumnAndRow(7, $baris)->setValue($jml["L_L"]); $activeSheet->getCellByColumnAndRow(8, $baris)->setValue($jml["P_B"]); $activeSheet->getCellByColumnAndRow(9, $baris)->setValue($jml["P_L"]); /* if($jumlahIsi>$jumlahData){ $p = Penyakit::model()->findByAttributes(array("id"=>$penyakit_id)); $activeSheet->getCellByColumnAndRow(0, $baris)->setValue($kodePusk); $activeSheet->getCellByColumnAndRow(1, $baris)->setValue($namaBulan[$month]); $activeSheet->getCellByColumnAndRow(2, $baris)->setValue($year); $activeSheet->getCellByColumnAndRow(3, $baris)->setValue($p->kode); $nama = $p->nama_indonesia; if($nama == ""){ $nama = $p->nama; } $activeSheet->getCellByColumnAndRow(4, $baris)->setValue($nama); $this->fillBorder($activeSheet, "A".$baris.":CD".$baris); }*/ //$activeSheet->getCell("CF".$baris)->setValue($penyakit_id); $baris++; $jumlahIsi++; } $this->fillBorder($activeSheet, "A11:CD" . ($baris - 1)); return array("phpexcel" => $objPHPExcel, "name" => $reportName . "_" . $namaBulan[$month] . "_" . $year); }