Files
onboard/app/Models/MisMedicalHistory.php
brusnitsyn 87e21f0e08 * восстановление окна наблюдения
* добавил получение выбывших
* фильтрация выбывших по результатам лечения
* добавил подсказку при наведении на операции
* добавил вывод причины наблюдения
* добавил вкладки для выбывших
* изменил связь и сохранение пациентов на контроле
* добавил возможность редактирования причины контроля
* полное изменение окна с нежелательными событиями
* исправил просмотр причины контроля
* работа над окном редактирования причины контроля в таблице
* визуальное выделение умерших и проведенных операций
* добавил выбор даты для роли врач
* центрирование блоков статистики
* разделение выполненных операций на срочность
* поправил метод определения текущего дня для роли врач
* функция блокировки при выборе другой даты для роли врач
2026-01-29 16:42:42 +09:00

109 lines
3.0 KiB
PHP
Raw 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\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class MisMedicalHistory extends Model
{
protected $table = 'stt_medicalhistory';
protected $primaryKey = 'MedicalHistoryID';
protected $fillable = [
'MedicalHistoryID',
'FAMILY',
'Name',
'OT',
'BD',
'Address'
];
protected $casts = [
'DateRecipient' => 'datetime'
];
public function observationPatient()
{
return $this->hasMany(ObservationPatient::class, 'rf_medicalhistory_id', 'MedicalHistoryID');
}
public function surgicalOperations()
{
return $this->hasMany(MisSurgicalOperation::class, 'rf_MedicalHistoryID', 'MedicalHistoryID');
}
public function scopeOperationOnBranch($query, $branchId, $startDate, $endDate)
{
return $this->surgicalOperations()->where('rf_StationarBranchID', $branchId)
->whereBetween('Date', [$startDate, $endDate]);
}
public function scopeCurrentlyHospitalized($query)
{
return $query->whereDate('DateExtract', '1900-01-01')
->where('MedicalHistoryID', '<>', 0);
}
/*
* Истории со срочностью - Плановая
*/
public function scopePlan($query)
{
return $query->where('rf_EmerSignID', 1);
}
/*
* Истории со срочностью - Экстренная
*/
public function scopeEmergency($query)
{
return $query->where('rf_EmerSignID', 2);
}
/*
* Истории с результатом - Умер
*/
public function scopeDeceased($query)
{
return $query->where('rf_kl_VisitResultID', 5);
}
/*
* Движения истории
*/
public function migrations()
{
return $this->hasMany(MisMigrationPatient::class, 'rf_MedicalHistoryID', 'MedicalHistoryID');
}
/*
* Движение по StationarBranch
*/
public function scopeInStationarBranch($query, $stationarBranchID)
{
return $this->whereHas('migrations', function ($query) use ($stationarBranchID) {
$query->where('rf_StationarBranchID', $stationarBranchID);
});
}
/*
* Истории в отделении ($departmentId)
*/
public function scopeInDepartment($query, $departmentId, $startDate, $endDate)
{
return $query->whereExists(function ($q) use ($departmentId, $startDate, $endDate) {
$q->select(DB::raw(1))
->from('stt_migrationpatient as mp')
->join('stt_stationarbranch as sb', 'sb.StationarBranchID', '=', 'mp.rf_StationarBranchID')
->whereColumn('mp.rf_MedicalHistoryID', 'stt_medicalhistory.MedicalHistoryID')
->where('sb.rf_DepartmentID', $departmentId);
if ($startDate && $endDate) {
$q->whereBetween('mp.DateIngoing', [$startDate, $endDate]);
}
});
}
}