0% found this document useful (0 votes)
2 views6 pages

Puskesmas Data Analysis Functions

The document contains code for several backend functions for an application: 1. A function to retrieve data from multiple puskesmas (community health centers) for specified categories, months, and years. 2. A function to generate charts displaying the retrieved puskesmas data. 3. Functions for creating new user accounts for puskesmas administrators and exporting data to Excel format.

Uploaded by

idolla nikmatul
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Puskesmas Data Analysis Functions

The document contains code for several backend functions for an application: 1. A function to retrieve data from multiple puskesmas (community health centers) for specified categories, months, and years. 2. A function to generate charts displaying the retrieved puskesmas data. 3. Functions for creating new user accounts for puskesmas administrators and exporting data to Excel format.

Uploaded by

idolla nikmatul
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Input data puskesmas

private function getPwsData($puskesmas, $categories, $selectedMonth, $selectedYear)

$data = [];

$prosentase = [];

foreach ($puskesmas as $item) {

$s = $item->sasaranTahun($selectedYear);

$k = [];

foreach ($categories as $category) {

$p = $item->dataPws()->where('id_kategori', $category->id)->where('tahun', $selectedYear)

->where('bulan', '<=', $selectedMonth)->orderBy('bulan', 'desc')->get();

$d = $p->where('bulan', $selectedMonth);

$bd = ($d->count() == 0) ? 0 : $d->first()->pencapaian;

$ud = ($d->count() == 0) ? 0 : $d->first()->unit_lain;

$rsd = ($d->count() == 0) ? 0 : $d->first()->rumah_sakit;

$kd = ($d->count() == 0) ? 0 : $d->first()->kab;

$lkd = ($d->count() == 0) ? 0 : $d->first()->luar_kab;

$pd = ($d->count() == 0) ? 0 : $d->first()->polindes;


$l = $p->where('bulan', $selectedMonth - 1);

$bl = ($l->count() == 0) ? 0 : $l->first()->pencapaian;

$ul = ($l->count() == 0) ? 0 : $l->first()->unit_lain;

$rsl = ($l->count() == 0) ? 0 : $l->first()->rumah_sakit;

$kl = ($l->count() == 0) ? 0 : $l->first()->kab;

$lkl = ($l->count() == 0) ? 0 : $l->first()->luar_kab;

$pl = ($l->count() == 0) ? 0 : $l->first()->polindes;

$j = ($p->count() > 0) ? $p->sum('pencapaian') : 0;

$uj = ($p->count() > 0) ? $p->sum('unit_lain') : 0;

$rsj = ($p->count() > 0) ? $p->sum('rumah_sakit') : 0;

$kj = ($p->count() > 0) ? $p->sum('kab') : 0;

$lkj = ($p->count() > 0) ? $p->sum('luar_kab') : 0;

$pj = ($p->count() > 0) ? $p->sum('polindes') : 0;

$x = (Object)[

"bulan_lalu" => $bl,


"bulan_ini" => $bd,

"jumlah" => $j,

"prosentase" => ($j / $s->bumil) * 100,

"rank" => 0,

"unit_lain_lalu" => $ul,

"unit_lain_ini" => $ud,

"unit_lain_jumlah" => $uj,

"rs_lalu" => $rsl,

"rs_ini" => $rsd,

"rs_jumlah" => $rsj,

"kab_lalu" => $kl,

"kab_ini" => $kd,

"kab_jumlah" => $kj,

"luar_kab_lalu" => $lkl,

"luar_kab_ini" => $lkd,

"luar_kab_jumlah" => $lkj,

"polindes_lalu" => $pl,

"polindes_ini" => $pd,


"polindes_jumlah" => $pj,

];

$prosentase[$category->id - 1][] = ($j / $s->bumil) * 100;

$k[] = $x;

$data[] = $k;

for ($i = 0; $i < count($puskesmas); $i++) {

for ($j = 0; $j < count($categories); $j++) {

$data[$i][$j]->rank = $this->getRank($prosentase[$j], $data[$i][$j]->prosentase);

return $data;

Grafik

public function chart(Request $request)

$years = DataPWS::select('tahun')->distinct()->pluck('tahun', 'tahun');

if ($years->count() == 0)
$years = [date('Y') => date('Y')];

$months = DataPWS::$months;

$categories = Kategori::all();

$selectedMonth = $request->input('month', date('n'));

$selectedYear = $request->input('year', end($years));

$puskesmas = Puskesmas::all();

$puskesmasLabel = Puskesmas::select('nama')->pluck('nama');

$kumulatif = $this->getKumulatif($puskesmas, $categories, $selectedMonth, $selectedYear);

$naik = $this->getNaik($kumulatif);

$turun = $this->getTurun($kumulatif);

return view('[Link]', compact('months', 'years', 'selectedYear',

'selectedMonth', 'puskesmas', 'puskesmasLabel', 'naik', 'turun', 'categories'));

Membuat user puskesmas

public function create()

$roles = Role::pluck('name','id')->all();
$puskesmas = Puskesmas::pluck('nama','id')->all();

return view($this->view . '.create',compact('puskesmas','roles'));

Cetak excel

public function create()

$roles = Role::pluck('name','id')->all();

$puskesmas = Puskesmas::pluck('nama','id')->all();

return view($this->view . '.create',compact('puskesmas','roles'));

You might also like