96 lines
2.2 KiB
PHP
96 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Farmacia;
|
|
|
|
use App\Models\Cadastro\Material\Material;
|
|
use App\Models\Farmacia\Receita;
|
|
use App\Models\Farmacia\ReceitaItemEntrega;
|
|
use App\Models\Geral\MedidaTempo;
|
|
use App\Models\Model;
|
|
use Illuminate\Support\Str;
|
|
|
|
class ReceitaItem extends Model
|
|
{
|
|
protected $table = 'farmacia_receita_item';
|
|
|
|
protected $casts = [
|
|
'proxima_retirada' => 'datetime:Y-m-d',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'receita_id',
|
|
'material_id',
|
|
'quantidade',
|
|
'intervalo_tempo',
|
|
'intervalo_medida_tempo_id',
|
|
'durante_tempo',
|
|
'prescrito',
|
|
'proxima_retirada',
|
|
'observacao',
|
|
'supervisor_id',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'created_at',
|
|
'created_lotacao_id',
|
|
'created_centro_custo_id',
|
|
'updated_at',
|
|
'updated_lotacao_id',
|
|
'updated_centro_custo_id',
|
|
];
|
|
|
|
public function getPosologiaAttribute()
|
|
{
|
|
$posologia = '';
|
|
|
|
if (!is_null($this->quantidade)) {
|
|
|
|
$quantidade = (float) $this->quantidade;
|
|
|
|
$posologia .= fmod($quantidade, 1) == 0 ? (int) $quantidade : number_format($quantidade, 2, ',', '.');
|
|
|
|
if (!is_null($this->material->apresentacaoUnidadeMedida)) {
|
|
|
|
$posologia .= ' ' . Str::lower($this->material->apresentacaoUnidadeMedida->nome);
|
|
}
|
|
}
|
|
|
|
if (!is_null($this->intervalo_tempo)) {
|
|
|
|
$posologia .= " a cada {$this->intervalo_tempo}";
|
|
|
|
if (!is_null($this->intervaloMedidaTempo)) {
|
|
|
|
$posologia .= ' ' . Str::lower($this->intervaloMedidaTempo->nome);
|
|
}
|
|
}
|
|
|
|
if (!is_null($this->durante_tempo)) {
|
|
|
|
$posologia .= " durante {$this->durante_tempo} dia(s)";
|
|
}
|
|
|
|
return empty($posologia) ? null : $posologia;
|
|
}
|
|
|
|
public function receita()
|
|
{
|
|
return $this->belongsTo(Receita::class);
|
|
}
|
|
|
|
public function material()
|
|
{
|
|
return $this->belongsTo(Material::class);
|
|
}
|
|
|
|
public function intervaloMedidaTempo()
|
|
{
|
|
return $this->belongsTo(MedidaTempo::class);
|
|
}
|
|
|
|
public function entregas()
|
|
{
|
|
return $this->hasMany(ReceitaItemEntrega::class);
|
|
}
|
|
}
|