This commit is contained in:
31
api/app/Rules/Sigtap/ProcedimentoRequireCid.php
Normal file
31
api/app/Rules/Sigtap/ProcedimentoRequireCid.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules\Sigtap;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ProcedimentoRequireCid implements Rule
|
||||
{
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
return self::isValid($value);
|
||||
}
|
||||
|
||||
public static function isValid($value)
|
||||
{
|
||||
return !DB::table('sigtap.procedimento')->where('id', $value)
|
||||
->whereExists(function ($query) {
|
||||
|
||||
$query->select(DB::raw(1))
|
||||
->from('sigtap.procedimento_cid')
|
||||
->whereColumn('sigtap.procedimento_cid.procedimento_id', 'sigtap.procedimento.id')
|
||||
->where('principal', 'S');
|
||||
})->exists();
|
||||
}
|
||||
|
||||
public function message()
|
||||
{
|
||||
return "Procedimento exige CID.";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user