168 lines
4.4 KiB
PHP
168 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models\ProntoAtendimento\Atendimento\Medico;
|
|
|
|
use App\Enums\Cadastro\MedidaTempo as CadastroMedidaTempo;
|
|
use App\Models\Cadastro\Medicamento\FormaFarmaceutica;
|
|
use App\Models\Cadastro\Medicamento\Medicamento;
|
|
use App\Models\Cadastro\Medicamento\ViaAdministracao;
|
|
use App\Models\Geral\MedidaTempo;
|
|
use App\Models\Geral\Turno;
|
|
use App\Models\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class ReceitaMedicamento extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'pronto_atendimento_atendimento_medico_receita_medicamento';
|
|
|
|
protected $fillable = [
|
|
'medicamento_id',
|
|
'via_administracao_outras',
|
|
'quantidade',
|
|
'intervalo_tempo',
|
|
'intervalo_medida_tempo_id',
|
|
'turno_id',
|
|
'durante_tempo',
|
|
'durante_medida_tempo_id',
|
|
'recomendacoes',
|
|
'descricao',
|
|
'medicamento_manual',
|
|
'prescricao_manual',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'created_at',
|
|
'created_lotacao_id',
|
|
'created_centro_custo_id',
|
|
'updated_at',
|
|
'updated_lotacao_id',
|
|
'updated_centro_custo_id',
|
|
'deleted_at',
|
|
'deleted_lotacao_id',
|
|
'deleted_centro_custo_id',
|
|
];
|
|
|
|
protected $appends = [
|
|
'dose_unica',
|
|
'posologia_por_frequencia',
|
|
'posologia_por_turno',
|
|
'posologia',
|
|
'uso_continuo',
|
|
'livre',
|
|
];
|
|
|
|
public function receita()
|
|
{
|
|
return $this->belongsTo(Receita::class);
|
|
}
|
|
|
|
public function medicamento()
|
|
{
|
|
return $this->belongsTo(Medicamento::class)->withTrashed();
|
|
}
|
|
|
|
public function viaAdministracao()
|
|
{
|
|
return $this->belongsTo(ViaAdministracao::class);
|
|
}
|
|
|
|
public function formaFarmaceutica()
|
|
{
|
|
return $this->belongsTo(FormaFarmaceutica::class);
|
|
}
|
|
|
|
public function intervaloMedidaTempo()
|
|
{
|
|
return $this->belongsTo(MedidaTempo::class);
|
|
}
|
|
|
|
public function turno()
|
|
{
|
|
return $this->belongsTo(Turno::class);
|
|
}
|
|
|
|
public function duranteMedidaTempo()
|
|
{
|
|
return $this->belongsTo(MedidaTempo::class);
|
|
}
|
|
|
|
public function getLivreAttribute()
|
|
{
|
|
return !is_null($this->descricao);
|
|
}
|
|
|
|
public function getDoseUnicaAttribute()
|
|
{
|
|
return !$this->livre
|
|
&& !$this->posologia_por_frequencia
|
|
&& !$this->posologia_por_turno
|
|
&& is_null($this->durante_tempo)
|
|
&& is_null($this->durante_medida_tempo_id);
|
|
}
|
|
|
|
public function getPosologiaPorFrequenciaAttribute()
|
|
{
|
|
return !is_null($this->intervalo_tempo)
|
|
&& !is_null($this->intervalo_medida_tempo_id);
|
|
}
|
|
|
|
public function getPosologiaPorTurnoAttribute()
|
|
{
|
|
return !is_null($this->turno_id);
|
|
}
|
|
|
|
public function getUsoContinuoAttribute()
|
|
{
|
|
return !$this->livre
|
|
&& !$this->dose_unica
|
|
&& is_null($this->durante_tempo)
|
|
&& is_null($this->durante_medida_tempo_id);
|
|
}
|
|
|
|
public function getQuantidadeAttribute($value)
|
|
{
|
|
return str_replace('.', ',', $value);
|
|
}
|
|
|
|
public function getPosologiaAttribute()
|
|
{
|
|
$unidadeMedida = $this->medicamento ? $this->medicamento->unidadeMedida->nome : null;
|
|
$posologia = "{$this->quantidade} {$unidadeMedida}";
|
|
|
|
if ($this->dose_unica) {
|
|
|
|
return $posologia;
|
|
}
|
|
|
|
if ($this->posologia_por_frequencia) {
|
|
|
|
if ($this->intervaloMedidaTempo->id === CadastroMedidaTempo::MINUTOS || $this->intervaloMedidaTempo->id === CadastroMedidaTempo::HORAS) {
|
|
|
|
$posologia .= " a cada {$this->intervalo_tempo} {$this->intervaloMedidaTempo->nome}";
|
|
}
|
|
else if ($this->intervaloMedidaTempo->id === CadastroMedidaTempo::DIAS || $this->intervaloMedidaTempo->id === CadastroMedidaTempo::SEMANAS || $this->intervaloMedidaTempo->id === CadastroMedidaTempo::MESES) {
|
|
|
|
$posologia .= " {$this->intervalo_tempo} vez(es) ao {$this->intervaloMedidaTempo->nome}";
|
|
}
|
|
}
|
|
else if ($this->posologia_por_turno) {
|
|
|
|
$posologia .= " pela {$this->turno->nome}";
|
|
}
|
|
|
|
if (!$this->uso_continuo && !$this->livre && is_object($this->duranteMedidaTempo)) {
|
|
$posologia .= " durante {$this->durante_tempo} {$this->duranteMedidaTempo->nome}";
|
|
}
|
|
|
|
|
|
return $posologia;
|
|
}
|
|
|
|
public function getIsAllowedToDeleteAttribute()
|
|
{
|
|
return true;
|
|
}
|
|
}
|