184 lines
5.5 KiB
PHP
184 lines
5.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use DB;
|
|
|
|
class RequestDailyMonitoring extends Model
|
|
{
|
|
use HasFactory;
|
|
use SoftDeletes;
|
|
protected $table = "request_log_daily_monitorings";
|
|
|
|
protected $fillable = [
|
|
'request_log_id',
|
|
'subject',
|
|
'object',
|
|
'submission_date',
|
|
'body_temperature',
|
|
'respiration_rate',
|
|
'sistole',
|
|
'diastole',
|
|
'analysis',
|
|
'lab_date',
|
|
'provider',
|
|
'examination',
|
|
'created_by',
|
|
'updated_by',
|
|
'deleted_by',
|
|
'reason',
|
|
'deleted_at'
|
|
];
|
|
|
|
protected $appends = ['medical_plan', 'non_medikamentosa_plan', 'document', 'discharge_date', 'confirmation_medical_leter', 'medical_action_letter', 'laboratorium_result'];
|
|
|
|
// public function getBodyTemperatureAttribute()
|
|
// {
|
|
// return round($this->attributes['body_temperature'], 0);
|
|
// }
|
|
|
|
// public function getSistoleAttribute()
|
|
// {
|
|
// return round($this->attributes['sistole'], 0);
|
|
// }
|
|
|
|
// public function getDiastoleAttribute()
|
|
// {
|
|
// return round($this->attributes['diastole'], 0);
|
|
// }
|
|
|
|
// public function getRespirationRateAttribute()
|
|
// {
|
|
// return round($this->attributes['respiration_rate'], 0);
|
|
// }
|
|
|
|
protected static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
// Event handling untuk deleting
|
|
static::deleting(function ($model) {
|
|
// Set nilai deleted_by dengan ID pengguna yang melakukan penghapusan (jika ada)
|
|
$model->deleted_by = Auth::id();
|
|
$model->save();
|
|
});
|
|
}
|
|
|
|
public function getMedicalPlanAttribute()
|
|
{
|
|
$arr_medical_plan = [];
|
|
$medical_plan = DB::table('request_log_medical_plan')->where(['request_log_daily_monitoring_id' => $this->attributes['id'], 'type' => 1])->get();
|
|
|
|
foreach ($medical_plan as $row) {
|
|
$arr_medical_plan[] = [
|
|
'medical_plan_str' => $row->plan
|
|
];
|
|
}
|
|
|
|
return $arr_medical_plan;
|
|
}
|
|
|
|
public function getNonMedikamentosaPlanAttribute()
|
|
{
|
|
$arr_non_medikamentosa_plan = [];
|
|
$non_medikamentosa_plan = DB::table('request_log_medical_plan')->where(['request_log_daily_monitoring_id' => $this->attributes['id'], 'type' => 2])->get();
|
|
|
|
foreach ($non_medikamentosa_plan as $row) {
|
|
$arr_non_medikamentosa_plan[] = [
|
|
'non_medikamentosa_plan_str' => $row->plan
|
|
];
|
|
}
|
|
|
|
return $arr_non_medikamentosa_plan;
|
|
}
|
|
|
|
public function getDocumentAttribute()
|
|
{
|
|
$arr_document = [];
|
|
$document = DB::table('files')->where([
|
|
'fileable_type' => 'App\Models\LaboratoriumResult',
|
|
'fileable_id' => $this->attributes['id'],
|
|
'deleted_at' => null,
|
|
])->get();
|
|
|
|
foreach ($document as $row) {
|
|
$arr_document[] = [
|
|
'id' => $row->id,
|
|
'file_name' => $row->original_name,
|
|
'path' => env('APP_URL') . '/storage/lab_result/' . $row->name .'.'. $row->extension,
|
|
'type' => $row->type,
|
|
];
|
|
}
|
|
|
|
return $arr_document;
|
|
}
|
|
|
|
public function getDischargeDateAttribute()
|
|
{
|
|
return $discharge_date = DB::table('request_logs')->where('id', $this->attributes['request_log_id'])->select('discharge_date')->first();
|
|
}
|
|
|
|
public function getConfirmationMedicalLeterAttribute()
|
|
{
|
|
$arr_document = [];
|
|
$document = DB::table('files')->where([
|
|
'fileable_type' => 'App\Models\LaboratoriumResult',
|
|
'type' => 'confirmation-medical-letter',
|
|
'fileable_id' => $this->attributes['id'],
|
|
])->get();
|
|
|
|
foreach ($document as $row) {
|
|
$arr_document[] = [
|
|
'name' => $row->original_name,
|
|
'path' => env('APP_URL') . '/storage/lab_result/' . $row->name .'.'. $row->extension,
|
|
'type' => $row->type,
|
|
];
|
|
}
|
|
|
|
return $arr_document;
|
|
}
|
|
public function getMedicalActionLetterAttribute()
|
|
{
|
|
$arr_document = [];
|
|
$document = DB::table('files')->where([
|
|
'fileable_type' => 'App\Models\LaboratoriumResult',
|
|
'type' => 'medical-action-letter',
|
|
'fileable_id' => $this->attributes['id'],
|
|
])->get();
|
|
|
|
foreach ($document as $row) {
|
|
$arr_document[] = [
|
|
'name' => $row->original_name,
|
|
'path' => env('APP_URL') . '/storage/lab_result/' . $row->name .'.'. $row->extension,
|
|
'type' => $row->type,
|
|
];
|
|
}
|
|
|
|
return $arr_document;
|
|
}
|
|
public function getLaboratoriumResultAttribute()
|
|
{
|
|
$arr_document = [];
|
|
$document = DB::table('files')->where([
|
|
'fileable_type' => 'App\Models\LaboratoriumResult',
|
|
'type' => 'laboratorium-result',
|
|
'fileable_id' => $this->attributes['id'],
|
|
])->get();
|
|
|
|
foreach ($document as $row) {
|
|
$arr_document[] = [
|
|
'name' => $row->original_name,
|
|
'path' => env('APP_URL') . '/storage/lab_result/' . $row->name .'.'. $row->extension,
|
|
'type' => $row->type,
|
|
];
|
|
}
|
|
|
|
return $arr_document;
|
|
}
|
|
|
|
}
|