36 lines
907 B
PHP
36 lines
907 B
PHP
<?php
|
|
|
|
namespace App\Rules\Sigtap;
|
|
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class CidSecundarioIsValidForProcedimento implements Rule
|
|
{
|
|
private $procedimentoId;
|
|
|
|
public function __construct($procedimentoId)
|
|
{
|
|
$this->procedimentoId = $procedimentoId;
|
|
}
|
|
|
|
public function passes($attribute, $value)
|
|
{
|
|
return self::isValid($this->procedimentoId, $value);
|
|
}
|
|
|
|
public static function isValid($procedimentoId, $cidId)
|
|
{
|
|
return DB::table('sigtap.procedimento_cid as procedimento_cid')
|
|
->where('procedimento_cid.procedimento_id', $procedimentoId)
|
|
->where('procedimento_cid.cid_id', $cidId)
|
|
->where('procedimento_cid.principal', 'N')
|
|
->exists();
|
|
}
|
|
|
|
public function message()
|
|
{
|
|
return 'CID secundário inválido para o procedimento informado.';
|
|
}
|
|
}
|