Files
onboard/app/Models/MisDenial.php

42 lines
1.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models;
use Illuminate\Support\Facades\Schema;
/**
* Отказ от госпитализации (МИС).
*
* ВНИМАНИЕ: ЗАГЛУШКА. На момент написания таблицы отказов ещё нет в реплике.
* Когда репликатор её добавит — поменять $table на реальное имя.
* Пока таблицы нет, MisDenial::tableAvailable() === false и вся
* фильтрация отказников превращается в no-op (отчёты не ломаются).
*
* Структура в МИС:
* DenialID (PK), rf_MedicalHistoryID -> mv_medicalhistory_summary.id,
* rf_kl_HospRefusalID, DateTime, FAM/Name/OT, rf_StationarTypeID, ...
* Признак отказа = сам факт наличия строки с rf_MedicalHistoryID
* (по причинам/типам не фильтруем).
*/
class MisDenial extends MaterializedViewModel
{
protected $table = 'stt_denial'; // TODO: подставить реальное имя таблицы в реплике
protected $primaryKey = 'DenialID';
private static ?bool $tableExists = null;
public function medicalHistory()
{
return $this->belongsTo(MedicalHistory::class, 'rf_MedicalHistoryID', 'id');
}
/**
* Доступна ли таблица отказов в текущей БД (реплике).
* Мемоизируем на процесс, чтобы не дёргать information_schema на каждый запрос.
*/
public static function tableAvailable(): bool
{
return self::$tableExists ??= Schema::hasTable((new self)->getTable());
}
}