227 lines
6.0 KiB
PHP
227 lines
6.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Ambulatorio;
|
|
|
|
use App\Enums\Ambulatorio\PrescricaoFrequenciaDose;
|
|
use App\Enums\Geral\MedidaTempo as MedidaTempoEnum;
|
|
use App\Models\Cadastro\Material\Material;
|
|
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
|
use App\Models\Cadastro\UnidadeMedida;
|
|
use App\Models\Geral\MedidaTempo;
|
|
use App\Models\Geral\Turno;
|
|
use App\Models\Model;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Str;
|
|
|
|
class AtendimentoSoapPrescricaoMedicamentoItem extends Model
|
|
{
|
|
protected $table = 'ambulatorio_atendimento_soap_prescricao_medicamento_item';
|
|
|
|
protected $casts = [
|
|
'inicio' => 'datetime:d/m/Y',
|
|
'tratamento_interrompido_em' => 'datetime:d/m/Y',
|
|
'is_dose_unica' => 'boolean',
|
|
'is_uso_continuo' => 'boolean',
|
|
'is_imprimir_separado' => 'boolean',
|
|
'is_remover_impressao' => 'boolean',
|
|
'tratamento_interrompido_from_rascunho' => 'boolean',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'prescricao_medicamento_id',
|
|
'receita_tipo_id',
|
|
'descricao',
|
|
'justificativa',
|
|
'material_id',
|
|
'dose',
|
|
'unidade_medida_id',
|
|
'is_dose_unica',
|
|
'is_uso_continuo',
|
|
'is_imprimir_separado',
|
|
'is_remover_impressao',
|
|
'frequencia_vezes',
|
|
'turno_id',
|
|
'intervalo',
|
|
'intervalo_medida_tempo_id',
|
|
'inicio',
|
|
'duracao',
|
|
'duracao_medida_tempo_id',
|
|
'recomendacoes',
|
|
'tratamento_interrompido_from_rascunho',
|
|
'tratamento_interrompido_em',
|
|
'tratamento_interrompido_justificativa',
|
|
'tratamento_interrompido_soap_id',
|
|
'prescricao_medicamento_item_anterior_id',
|
|
];
|
|
|
|
protected $appends = [
|
|
'conclusao'
|
|
];
|
|
|
|
protected $hidden = [
|
|
'created_at',
|
|
'created_lotacao_id',
|
|
'created_centro_custo_id',
|
|
'updated_at',
|
|
'updated_lotacao_id',
|
|
'updated_centro_custo_id',
|
|
];
|
|
|
|
public function getIsManualAttribute()
|
|
{
|
|
return !is_null($this->descricao);
|
|
}
|
|
|
|
public function getIsTratamentoConcluidoAttribute()
|
|
{
|
|
return !$this->is_tratamento_interrompido
|
|
&& !is_null($this->conclusao)
|
|
&& Carbon::today()->isAfter($this->conclusao);
|
|
}
|
|
|
|
public function getIsTratamentoInterrompidoAttribute()
|
|
{
|
|
return !$this->tratamento_interrompido_from_rascunho && !is_null($this->tratamento_interrompido_em);
|
|
}
|
|
|
|
public function getPosologiaAttribute()
|
|
{
|
|
if ($this->is_manual) {
|
|
|
|
return null;
|
|
}
|
|
|
|
$posologia = '';
|
|
|
|
if ($this->is_dose_unica) {
|
|
|
|
$posologia .= ", dose única";
|
|
}
|
|
else {
|
|
|
|
$posologia .= $this->unidadeMedida ? " {$this->unidadeMedida->nome}" : " (dose)";
|
|
|
|
if (!is_null($this->frequencia_vezes)) {
|
|
|
|
$posologia .= ", {$this->frequencia_vezes} vez(es)";
|
|
|
|
if ($this->intervalo === 1 && $this->intervaloMedidaTempo->id === MedidaTempoEnum::DIAS) {
|
|
|
|
$posologia .= ' ao dia';
|
|
}
|
|
else {
|
|
|
|
$posologia .= " a cada {$this->intervalo} {$this->intervaloMedidaTempo->nome}";
|
|
}
|
|
}
|
|
else if (!is_null($this->turno_id)) {
|
|
|
|
$posologia .= ", pela {$this->turno->nome}";
|
|
|
|
if (!($this->intervalo === 1 && $this->intervaloMedidaTempo->id === MedidaTempoEnum::DIAS)) {
|
|
|
|
$posologia .= " a cada {$this->intervalo} {$this->intervaloMedidaTempo->nome}";
|
|
}
|
|
}
|
|
else {
|
|
|
|
$intervaloDescricao = $this->intervaloMedidaTempo->id === MedidaTempoEnum::HORAS
|
|
? ($this->intervalo > 1 ? "{$this->intervalo} {$this->intervaloMedidaTempo->nome}" : ' hora')
|
|
: "{$this->intervalo} {$this->intervaloMedidaTempo->nome}";
|
|
|
|
$posologia .= ", a cada {$intervaloDescricao}";
|
|
}
|
|
}
|
|
|
|
return "{$this->dose}" . Str::lower($posologia);
|
|
}
|
|
|
|
public function getFrequenciaDoseAttribute()
|
|
{
|
|
if (!is_null($this->frequencia_vezes)) {
|
|
|
|
return PrescricaoFrequenciaDose::FREQUENCIA;
|
|
}
|
|
else if (!is_null($this->turno_id)) {
|
|
|
|
return PrescricaoFrequenciaDose::TURNO;
|
|
}
|
|
else {
|
|
|
|
return PrescricaoFrequenciaDose::INTERVALO;
|
|
}
|
|
}
|
|
|
|
public function getConclusaoAttribute()
|
|
{
|
|
if ($this->is_dose_unica) {
|
|
|
|
return $this->inicio->copy();
|
|
}
|
|
|
|
switch ($this->duracao_medida_tempo_id) {
|
|
|
|
case MedidaTempoEnum::DIAS: {
|
|
|
|
return $this->inicio->copy()->addDays($this->duracao);
|
|
}
|
|
case MedidaTempoEnum::SEMANAS: {
|
|
|
|
return $this->inicio->copy()->addWeeks($this->duracao);
|
|
}
|
|
case MedidaTempoEnum::MESES: {
|
|
|
|
return $this->inicio->copy()->addMonths($this->duracao);
|
|
}
|
|
default: {
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function prescricaoMedicamento()
|
|
{
|
|
return $this->belongsTo(AtendimentoSoapPrescricaoMedicamento::class);
|
|
}
|
|
|
|
public function material()
|
|
{
|
|
return $this->belongsTo(Material::class);
|
|
}
|
|
|
|
public function turno()
|
|
{
|
|
return $this->belongsTo(Turno::class);
|
|
}
|
|
public function unidadeMedida()
|
|
{
|
|
return $this->belongsTo(UnidadeMedida::class);
|
|
}
|
|
|
|
public function intervaloMedidaTempo()
|
|
{
|
|
return $this->belongsTo(MedidaTempo::class);
|
|
}
|
|
|
|
public function duracaoMedidaTempo()
|
|
{
|
|
return $this->belongsTo(MedidaTempo::class);
|
|
}
|
|
|
|
public function tratamentoInterrompidoSoap()
|
|
{
|
|
return $this->belongsTo(AtendimentoSoap::class);
|
|
}
|
|
|
|
public function prescricaoMedicamentoItemAnterior()
|
|
{
|
|
return $this->belongsTo(AtendimentoSoapPrescricaoMedicamentoItem::class);
|
|
}
|
|
|
|
public function lotacao()
|
|
{
|
|
return $this->belongsTo(lotacao::class, 'created_lotacao_id');
|
|
}
|
|
}
|