Добавил ограничение по отказникам
This commit is contained in:
@@ -72,4 +72,25 @@ class MedicalHistorySnapshot extends Model
|
||||
$q->department($departmentId);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Исключить из снимка карты, по которым в МИС оформлен отказ от госпитализации.
|
||||
* Снимок остаётся неизменным (immutable) — отсекаем только при чтении.
|
||||
* Безопасно: пока таблицы отказов нет в реплике — no-op (см. MisDenial::tableAvailable()).
|
||||
*/
|
||||
public function scopeWithoutDenials($query)
|
||||
{
|
||||
if (! MisDenial::tableAvailable()) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
$denialTable = (new MisDenial)->getTable();
|
||||
$snapshotTable = $this->getTable();
|
||||
|
||||
return $query->whereNotExists(function ($sub) use ($denialTable, $snapshotTable) {
|
||||
$sub->selectRaw('1')
|
||||
->from($denialTable)
|
||||
->whereColumn("{$denialTable}.rf_MedicalHistoryID", "{$snapshotTable}.rf_medicalhistory_id");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user