* поправил поле выбора даты * добавил индикатор в контроле * окно выбора пользователя для сводной * привязка окна для ввода причины контроля * добавил привязку историй пациентов для просмотра статистики по дням * поправил фиксацию фио ответственного, убрал при диапазоне * отключение ролей адм и зав от реплики
165 lines
4.7 KiB
PHP
165 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class MisMigrationPatient extends Model
|
|
{
|
|
protected $table = 'stt_migrationpatient';
|
|
protected $primaryKey = 'MigrationPatientID';
|
|
|
|
public function branch()
|
|
{
|
|
return $this->hasOne(MisStationarBranch::class, 'StationarBranchID', 'rf_StationarBranchID');
|
|
}
|
|
|
|
public function diagnosis()
|
|
{
|
|
return $this->hasMany(MisDiagnos::class, 'rf_MigrationPatientID', 'MigrationPatientID');
|
|
}
|
|
|
|
public function mkb()
|
|
{
|
|
return $this->hasOne(MisMKB::class, 'MKBID', 'rf_MKBID');
|
|
}
|
|
|
|
/**
|
|
* Находятся на лечении
|
|
*/
|
|
public function scopeCurrentlyInTreatment($query, $branchId = null, $startDate = null, $endDate = null)
|
|
{
|
|
$query->where('rf_kl_VisitResultID', 0)
|
|
->where('rf_MedicalHistoryID', '<>', 0);
|
|
|
|
if ($branchId) {
|
|
$query->where('rf_StationarBranchID', $branchId);
|
|
}
|
|
|
|
if ($startDate && $endDate) {
|
|
$query->whereBetween('DateIngoing', [$startDate, $endDate]);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
public function scopeWhereInDepartment($query, $branchId = null)
|
|
{
|
|
$query->where('rf_MedicalHistoryID', '<>', 0);
|
|
|
|
if ($branchId) {
|
|
$query->where('rf_StationarBranchID', $branchId);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
/**
|
|
* Выбывшие пациенты (все исходы)
|
|
*/
|
|
public function scopeOutcomePatients($query, $branchId = null, $startDate = null, $endDate = null)
|
|
{
|
|
$query->where('rf_kl_VisitResultID', '<>', 0) // не активное лечение
|
|
->whereDate('DateOut', '<>', '1900-01-01') // есть дата выбытия
|
|
->where('rf_MedicalHistoryID', '<>', 0);
|
|
|
|
if ($branchId) {
|
|
$query->where('rf_StationarBranchID', $branchId);
|
|
}
|
|
|
|
if ($startDate && $endDate) {
|
|
$query->whereBetween('DateOut', [$startDate, $endDate]);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
/**
|
|
* Выписанные пациенты
|
|
*/
|
|
public function scopeDischarged($query, $branchId = null, $startDate = null, $endDate = null)
|
|
{
|
|
// ID выписки
|
|
$dischargeCodes = [1, 7, 8, 9, 10, 11, 48, 49, 124];
|
|
|
|
$query->whereIn('rf_kl_VisitResultID', $dischargeCodes)
|
|
->whereDate('DateOut', '<>', '1900-01-01')
|
|
->where('rf_MedicalHistoryID', '<>', 0);
|
|
|
|
if ($branchId) {
|
|
$query->where('rf_StationarBranchID', $branchId);
|
|
}
|
|
|
|
if ($startDate && $endDate) {
|
|
$query->whereBetween('DateOut', [$startDate, $endDate]);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
/**
|
|
* Перевод в другое отделение
|
|
*/
|
|
public function scopeTransferred($query, $branchId = null, $startDate = null, $endDate = null)
|
|
{
|
|
// ID перевода
|
|
$transferCodes = [2, 3, 4, 12, 13, 14];
|
|
|
|
$query->whereIn('rf_kl_VisitResultID', $transferCodes)
|
|
->whereDate('DateOut', '<>', '1900-01-01')
|
|
->where('rf_MedicalHistoryID', '<>', 0);
|
|
|
|
if ($branchId) {
|
|
$query->where('rf_StationarBranchID', $branchId);
|
|
}
|
|
|
|
if ($startDate && $endDate) {
|
|
$query->whereBetween('DateOut', [$startDate, $endDate]);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
/**
|
|
* Умершие пациенты
|
|
*/
|
|
public function scopeDeceasedOutcome($query, $branchId = null, $startDate = null, $endDate = null)
|
|
{
|
|
// ID умершего
|
|
$deceasedCodes = [5, 6, 15, 16];
|
|
|
|
$query->whereIn('rf_kl_VisitResultID', $deceasedCodes)
|
|
->whereDate('DateOut', '<>', '1900-01-01')
|
|
->where('rf_MedicalHistoryID', '<>', 0);
|
|
|
|
if ($branchId) {
|
|
$query->where('rf_StationarBranchID', $branchId);
|
|
}
|
|
|
|
if ($startDate && $endDate) {
|
|
$query->whereBetween('DateOut', [$startDate, $endDate]);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
public function scopeExtractedToday($query, $branchId = null, $startDate = null, $endDate = null)
|
|
{
|
|
if (is_null($startDate)) $startDate = Carbon::now()->addDays(-1)->format('Y-m-d');
|
|
if (is_null($endDate)) $endDate = Carbon::now()->format('Y-m-d');
|
|
|
|
$query->where('rf_kl_VisitResultID', '<>', 0)
|
|
->where('rf_MedicalHistoryID', '<>', 0)
|
|
->when($startDate && $endDate, function($query) use ($startDate, $endDate) {
|
|
return $query->whereBetween('DateOut', [$startDate, $endDate]);
|
|
});
|
|
|
|
if ($branchId) {
|
|
$query->where('rf_StationarBranchID', $branchId);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
}
|