intial commit
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class Anak extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'data_anak';
|
||||
|
||||
protected $fillable = [
|
||||
'nama',
|
||||
'panggilan',
|
||||
'tanggal_lahir',
|
||||
'alamat',
|
||||
'nama_orang_tua',
|
||||
'gender',
|
||||
'image',
|
||||
'berat_terakhir',
|
||||
'tinggi_terakhir',
|
||||
'lingkar_kepala_terakhir',
|
||||
'id_orang_tua',
|
||||
'id_posyandu',
|
||||
'id_desa',
|
||||
'status'
|
||||
];
|
||||
|
||||
public function umur($date)
|
||||
{
|
||||
$tanggalLahir = Carbon::createFromFormat("Y-m-d", $this->tanggal_lahir);
|
||||
$carbonDate = Carbon::make($date);
|
||||
$umurInBulan = $carbonDate->diffInMonths($tanggalLahir);
|
||||
return $umurInBulan;
|
||||
}
|
||||
|
||||
public function updateStatistikTerakhir()
|
||||
{
|
||||
$statistik = $this->statistik()->orderBy('created_at', 'desc')->first();
|
||||
$this->berat_terakhir = $statistik->kategoriBerat();
|
||||
$this->tinggi_terakhir = $statistik->kategoriTinggi();
|
||||
$this->lingkar_kepala_terakhir = $statistik->kategoriLingkarKepala();
|
||||
$this->update();
|
||||
}
|
||||
|
||||
|
||||
public function statistikTerakhir()
|
||||
{
|
||||
$statistik = $this->statistik()->orderBy('created_at', 'desc')->first();
|
||||
return $statistik;
|
||||
}
|
||||
|
||||
public function beratTerakhir()
|
||||
{
|
||||
$statistik = $this->statistik()->orderBy('created_at', 'desc')->first();
|
||||
if (empty($statistik)) {
|
||||
return null;
|
||||
}
|
||||
return $statistik->berat;
|
||||
}
|
||||
|
||||
public function tinggiTerakhir()
|
||||
{
|
||||
$statistik = $this->statistik()->orderBy('created_at', 'desc')->first();
|
||||
if (empty($statistik)) {
|
||||
return null;
|
||||
}
|
||||
return $statistik->tinggi;
|
||||
}
|
||||
public function lingkarKepalaTerakhir()
|
||||
{
|
||||
$statistik = $this->statistik()->orderBy('created_at', 'desc')->first();
|
||||
if (empty($statistik)) {
|
||||
return null;
|
||||
}
|
||||
return $statistik->lingkar_kepala;
|
||||
}
|
||||
|
||||
public function statistik()
|
||||
{
|
||||
return $this->hasMany(StatistikAnak::class, 'id_anak', 'id');
|
||||
}
|
||||
|
||||
public function orangTua()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'id_orang_tua', 'id');
|
||||
}
|
||||
|
||||
public function desa()
|
||||
{
|
||||
return $this->belongsTo(Desa::class, 'id_desa', 'id');
|
||||
}
|
||||
|
||||
public function posyandu()
|
||||
{
|
||||
return $this->belongsTo(Posyandu::class, 'id_posyandu', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Artikel extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'artikel';
|
||||
|
||||
protected $fillable = [
|
||||
'judul',
|
||||
'kategori',
|
||||
'image',
|
||||
'penulis',
|
||||
'content',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id', 'post_id', 'content'
|
||||
];
|
||||
|
||||
public function post()
|
||||
{
|
||||
return $this->belongsTo(Post::class);
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Desa extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $table = 'data_desa';
|
||||
|
||||
protected $fillable = [
|
||||
'name'
|
||||
];
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
public function posyandu()
|
||||
{
|
||||
return $this->hasMany(Posyandu::class, 'id_desa', 'id');
|
||||
}
|
||||
|
||||
public function anak()
|
||||
{
|
||||
return $this->hasMany(Anak::class, 'id_desa', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Kategori extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'kategori';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Post extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id', 'title', 'content','read'
|
||||
];
|
||||
|
||||
public function comments()
|
||||
{
|
||||
return $this->hasMany(Comment::class, 'post_id', 'id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Posyandu extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $table = "data_posyandu";
|
||||
|
||||
protected $fillable = [
|
||||
'nama',
|
||||
'alamat',
|
||||
'latitude',
|
||||
'longitude',
|
||||
];
|
||||
|
||||
public function desa()
|
||||
{
|
||||
return $this->belongsTo(Desa::class, 'id_desa', 'id');
|
||||
}
|
||||
|
||||
public function anak()
|
||||
{
|
||||
return $this->hasMany(Anak::class, 'id_posyandu', 'id');
|
||||
}
|
||||
|
||||
public function jumlahAnak()
|
||||
{
|
||||
return $this->anak()->count();
|
||||
}
|
||||
|
||||
public function laporanBerat($allLatsStatistik)
|
||||
{
|
||||
$obesitas = 0;
|
||||
$gemuk = 0;
|
||||
$normal = 0;
|
||||
$kurus = 0;
|
||||
$sangatKurus = 0;
|
||||
|
||||
if($allLatsStatistik != NULL){
|
||||
foreach ($allLatsStatistik as $latestStatistik){
|
||||
if($latestStatistik != NULL){
|
||||
if ($latestStatistik->status_berat_badan == 'Gemuk') {
|
||||
$gemuk++;
|
||||
} else if ($latestStatistik->status_berat_badan == 'Normal') {
|
||||
$normal++;
|
||||
} else if ($latestStatistik->status_berat_badan == 'Kurus') {
|
||||
$kurus++;
|
||||
} else if ($latestStatistik->status_berat_badan == 'Sangat Kurus') {
|
||||
$sangatKurus++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'gemuk' => $gemuk,
|
||||
'normal' => $normal,
|
||||
'kurus' => $kurus,
|
||||
'sangat_kurus' => $sangatKurus,
|
||||
];
|
||||
}
|
||||
|
||||
public function laporanTinggi($allLatsStatistik)
|
||||
{
|
||||
|
||||
$tinggi = 0;
|
||||
$normal = 0;
|
||||
$pendek = 0;
|
||||
$sangatPendek = 0;
|
||||
|
||||
if($allLatsStatistik != NULL){
|
||||
foreach ($allLatsStatistik as $latestStatistik){
|
||||
if($latestStatistik != NULL){
|
||||
if ($latestStatistik->status_tinggi_badan == 'Tinggi') {
|
||||
$tinggi++;
|
||||
} else if ($latestStatistik->status_tinggi_badan == 'Normal') {
|
||||
$normal++;
|
||||
} else if ($latestStatistik->status_tinggi_badan == 'Pendek') {
|
||||
$pendek++;
|
||||
} else if ($latestStatistik->status_tinggi_badan == 'Sangat Pendek') {
|
||||
$sangatPendek++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'tinggi' => $tinggi,
|
||||
'normal' => $normal,
|
||||
'pendek' => $pendek,
|
||||
'sangat_pendek' => $sangatPendek,
|
||||
];
|
||||
}
|
||||
|
||||
public function laporanLingkarKepala($allLatsStatistik)
|
||||
{
|
||||
$makrosefali = 0;
|
||||
$normal = 0;
|
||||
$mikrosefali = 0;
|
||||
|
||||
if($allLatsStatistik != NULL){
|
||||
foreach ($allLatsStatistik as $latestStatistik){
|
||||
if($latestStatistik != NULL){
|
||||
if ($latestStatistik->status_lingkar_kepala == 'Makrosefali') {
|
||||
$makrosefali++;
|
||||
} else if ($latestStatistik->status_lingkar_kepala == 'Normal') {
|
||||
$normal++;
|
||||
} else if ($latestStatistik->status_lingkar_kepala == 'Mikrosefali') {
|
||||
$mikrosefali++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'makrosefali' => $makrosefali,
|
||||
'normal' => $normal,
|
||||
'mikrosefali' => $mikrosefali,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Reminder extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'reminders';
|
||||
|
||||
protected $fillable = [
|
||||
'judul',
|
||||
'deskripsi',
|
||||
'tanggal_reminder',
|
||||
'id_desa',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Role extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = "role";
|
||||
|
||||
protected $fillable = [
|
||||
'role'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class StatistikAnak extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'data_statistik_anak';
|
||||
|
||||
protected $fillable = [
|
||||
'tinggi',
|
||||
'berat',
|
||||
'lingkar_kepala',
|
||||
'date',
|
||||
'z_score_tinggi',
|
||||
'z_score_berat',
|
||||
'z_score_lingkar_kepala',
|
||||
'date',
|
||||
'id_anak',
|
||||
"status_berat_badan",
|
||||
"status_tinggi_badan",
|
||||
"status_lingkar_kepala",
|
||||
"z_score_gizi",
|
||||
"status_gizi"
|
||||
];
|
||||
|
||||
public function anak()
|
||||
{
|
||||
return $this->belongsTo(Anak::class, 'id_anak', 'id');
|
||||
}
|
||||
|
||||
public function kategoriBerat()
|
||||
{
|
||||
$berat = '';
|
||||
$zscore = $this->z_score_berat;
|
||||
if ($zscore > 2) {
|
||||
$berat = 'Gemuk';
|
||||
} elseif ($zscore > -2 && $zscore <= 2) {
|
||||
$berat = 'Normal';
|
||||
} elseif ($zscore > -3 && $zscore <= -2) {
|
||||
$berat = 'Kurus';
|
||||
} elseif ($zscore < -3) {
|
||||
$berat = 'Sangat Kurus';
|
||||
}
|
||||
|
||||
if (empty($this->z_score_berat)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $berat;
|
||||
}
|
||||
|
||||
public function kategoriTinggi()
|
||||
{
|
||||
$zscore = $this->z_score_tinggi;
|
||||
if ($zscore > 2) {
|
||||
$tinggi = 'Tinggi';
|
||||
} elseif ($zscore > -2 && $zscore <= 2) {
|
||||
$tinggi = 'Normal';
|
||||
} elseif ($zscore > -3 && $zscore <= -2) {
|
||||
$tinggi = 'Pendek';
|
||||
} elseif ($zscore <= -3) {
|
||||
$tinggi = 'Sangat Pendek';
|
||||
}
|
||||
|
||||
if (empty($this->z_score_tinggi)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $tinggi;
|
||||
}
|
||||
|
||||
public function kategoriLingkarKepala()
|
||||
{
|
||||
$zscore = $this->z_score_lingkar_kepala;
|
||||
if ($zscore > 2) {
|
||||
$lingkarKepala = 'Makrosefali';
|
||||
} elseif ($zscore > -2 && $zscore <= 2) {
|
||||
$lingkarKepala = 'Normal';
|
||||
} elseif ($zscore < -2) {
|
||||
$lingkarKepala = 'Mikrosefali';
|
||||
}
|
||||
|
||||
if (empty($this->z_score_lingkar_kepala)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $lingkarKepala;
|
||||
}
|
||||
|
||||
public function kategoriGizi()
|
||||
{
|
||||
$zscore = $this->z_score_gizi;
|
||||
if ($zscore > 3) {
|
||||
$gizi = 'Obesitas';
|
||||
} elseif ($zscore > 2 && $zscore <= 3) {
|
||||
$gizi = 'Gizi Lebih';
|
||||
} elseif ($zscore > 1 && $zscore <= 2) {
|
||||
$gizi = 'Beresiko Gizi Lebih';
|
||||
} elseif ($zscore >= -2 && $zscore <= 1) {
|
||||
$gizi = 'Gizi Baik';
|
||||
} elseif ($zscore >= -3 && $zscore < -2) {
|
||||
$gizi = 'Gizi Kurang';
|
||||
} elseif ($zscore < -3) {
|
||||
$gizi = 'Gizi Buruk';
|
||||
}
|
||||
|
||||
if (empty($this->z_score_gizi)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $gizi;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'nama',
|
||||
'email',
|
||||
'alamat',
|
||||
'password',
|
||||
'id_desa',
|
||||
'id_posyandu',
|
||||
'status',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function role()
|
||||
{
|
||||
return $this->belongsTo(Role::class, 'id_role', 'id');
|
||||
}
|
||||
|
||||
public function desa()
|
||||
{
|
||||
return $this->belongsTo(Desa::class, 'id_desa', 'id');
|
||||
}
|
||||
|
||||
public function posyandu()
|
||||
{
|
||||
return $this->belongsTo(Posyandu::class, 'id_posyandu', 'id');
|
||||
}
|
||||
|
||||
public function anak()
|
||||
{
|
||||
return $this->hasMany(Anak::class, 'id_orang_tua', 'id');
|
||||
}
|
||||
|
||||
public function post()
|
||||
{
|
||||
return $this->hasMany(Post::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
public function comments()
|
||||
{
|
||||
return $this->hasMany(Comment::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Contracts\Auth\Authenticatable $auth
|
||||
* @return User
|
||||
*/
|
||||
public static function getUser($user): User
|
||||
{
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user