Форматирование

This commit is contained in:
brusnitsyn
2026-04-24 16:46:10 +09:00
parent fd0e6ee817
commit 63daa62888
87 changed files with 1380 additions and 791 deletions

View File

@@ -15,7 +15,7 @@ class Department extends Model
'name_full',
'name_short',
'rf_mis_department_id',
'rf_department_type'
'rf_department_type',
];
public function metrikaDefault()

View File

@@ -7,12 +7,13 @@ use Illuminate\Database\Eloquent\Model;
class DepartmentMetrikaDefault extends Model
{
protected $primaryKey = 'department_metrika_default_id';
public $timestamps = false;
protected $fillable = [
'rf_department_id',
'rf_metrika_item_id',
'value'
'value',
];
public function departments()

View File

@@ -7,10 +7,11 @@ use Illuminate\Database\Eloquent\Model;
class DepartmentType extends Model
{
protected $primaryKey = 'department_type_id';
public $timestamps = false;
protected $fillable = [
'name_full',
'name_short'
'name_short',
];
}

View File

@@ -9,6 +9,7 @@ use Illuminate\Support\Carbon;
class LifeMisMigrationPatient extends Model
{
protected $table = 'life_stt_migrationpatient';
protected $primaryKey = 'MigrationPatientID';
public function branch()
@@ -34,7 +35,7 @@ class LifeMisMigrationPatient extends Model
/**
* Находятся на лечении
*/
public function scopeCurrentlyInTreatment($query, $branchId = null, DateRange $dateRange = null)
public function scopeCurrentlyInTreatment($query, $branchId = null, ?DateRange $dateRange = null)
{
$query->where('rf_kl_VisitResultID', 0)
->where('rf_kl_StatCureResultID', 0)
@@ -49,7 +50,7 @@ class LifeMisMigrationPatient extends Model
}
if ($dateRange) {
// $query->whereBetween('DateIngoing', [$dateRange->startSql(), $dateRange->endSql()]);
// $query->whereBetween('DateIngoing', [$dateRange->startSql(), $dateRange->endSql()]);
$query->where('DateIngoing', '>=', $dateRange->startSql())
->where('DateIngoing', '<=', $dateRange->endSql());
}
@@ -71,7 +72,7 @@ class LifeMisMigrationPatient extends Model
/**
* Выбывшие пациенты (все исходы)
*/
public function scopeOutcomePatients($query, $branchId = null, DateRange $dateRange = null)
public function scopeOutcomePatients($query, $branchId = null, ?DateRange $dateRange = null)
{
$query->where('rf_MedicalHistoryID', '<>', 0);
@@ -94,7 +95,7 @@ class LifeMisMigrationPatient extends Model
/**
* Выписанные пациенты
*/
public function scopeOutcomeDischarged($query, $branchId = null, DateRange $dateRange = null)
public function scopeOutcomeDischarged($query, $branchId = null, ?DateRange $dateRange = null)
{
// По уточненному SQL: Выписано за период
$dischargeCodes = [1, 11, 2, 12, 7, 18, 48];
@@ -121,7 +122,7 @@ class LifeMisMigrationPatient extends Model
/**
* Перевод в другое отделение
*/
public function scopeOutcomeTransferred($query, $branchId = null, DateRange $dateRange = null)
public function scopeOutcomeTransferred($query, $branchId = null, ?DateRange $dateRange = null)
{
// По заданному SQL: только эти коды перевода
$transferCodes = [4, 14];
@@ -148,7 +149,7 @@ class LifeMisMigrationPatient extends Model
/**
* Умершие пациенты
*/
public function scopeDeceasedOutcome($query, $branchId = null, DateRange $dateRange = null)
public function scopeDeceasedOutcome($query, $branchId = null, ?DateRange $dateRange = null)
{
// ID умершего
$deceasedCodes = [5, 6, 15, 16];
@@ -172,7 +173,7 @@ class LifeMisMigrationPatient extends Model
return $query;
}
public function scopeOutcomeWithoutTransferred($query, $branchId = null, DateRange $dateRange = null)
public function scopeOutcomeWithoutTransferred($query, $branchId = null, ?DateRange $dateRange = null)
{
$query->whereNotIn('rf_kl_VisitResultID', [4, 14])
->where('rf_kl_VisitResultID', '<>', 0)
@@ -194,16 +195,17 @@ class LifeMisMigrationPatient extends Model
return $query;
}
public function scopeExtractedToday($query, $branchId = null, DateRange $dateRange = null)
public function scopeExtractedToday($query, $branchId = null, ?DateRange $dateRange = 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');
// 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($dateRange, function($query) use ($dateRange) {
->when($dateRange, function ($query) use ($dateRange) {
$startDate = Carbon::parse($dateRange->startSql())->toDateString();
$endDate = Carbon::parse($dateRange->endSql())->toDateString();
return $query->whereHas('medicalHistory', function ($mhQuery) use ($startDate, $endDate) {
$mhQuery->whereDate('DateExtract', '>', $startDate)
->whereDate('DateExtract', '<=', $endDate);

View File

@@ -37,6 +37,7 @@ class MedicalHistorySnapshot extends Model
* Типы пациентов
*/
const PATIENT_TYPE_DISCHARGED = 'discharged'; // Выписанные
const PATIENT_TYPE_CURRENT = 'current'; // Текущие
public function report()
@@ -67,7 +68,7 @@ class MedicalHistorySnapshot extends Model
public function scopeByDepartment($query, $departmentId)
{
return $query->whereHas('medicalHistory.migrations.branch', function($q) use ($departmentId) {
return $query->whereHas('medicalHistory.migrations.branch', function ($q) use ($departmentId) {
$q->where('rf_DepartmentID', $departmentId);
});
}

View File

@@ -7,12 +7,14 @@ use Illuminate\Database\Eloquent\Model;
class MetrikaForm extends Model
{
protected $table = 'metrika_group_items';
protected $primaryKey = 'metrika_group_item_id';
public $timestamps = false;
protected $fillable = [
'rf_metrika_group_id',
'rf_metrika_item_id'
'rf_metrika_item_id',
];
// Метод для получения данных формы
@@ -35,7 +37,7 @@ class MetrikaForm extends Model
'default_value' => $formItem->item->default_value,
'is_required' => $formItem->item->is_required ?? false,
'order' => $formItem->order ?? 0,
'section' => $formItem->section ?? 'general'
'section' => $formItem->section ?? 'general',
];
})
->sortBy('order')
@@ -105,13 +107,13 @@ class MetrikaForm extends Model
return [
'schema' => $schema,
'defaults' => $defaults,
'fields' => $formItems
'fields' => $formItems,
];
}
private static function getDefaultByType($dataType)
{
return match($dataType) {
return match ($dataType) {
'integer', 'float' => 0,
'string', 'text' => '',
'boolean' => false,

View File

@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
class MetrikaGroup extends Model
{
protected $primaryKey = 'metrika_group_id';
public $timestamps = false;
protected $fillable = [

View File

@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
class MetrikaGroupItem extends Model
{
protected $primaryKey = 'metrika_group_item_id';
public $timestamps = false;
protected $fillable = [

View File

@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
class MetrikaItem extends Model
{
protected $primaryKey = 'metrika_item_id';
public $timestamps = false;
protected $fillable = [

View File

@@ -8,12 +8,13 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
class MetrikaResult extends Model
{
protected $primaryKey = 'metrika_result_id';
public $timestamps = false;
protected $fillable = [
'rf_metrika_item_id',
'rf_report_id',
'value'
'value',
];
public function report(): \Illuminate\Database\Eloquent\Relations\BelongsTo
@@ -21,13 +22,13 @@ class MetrikaResult extends Model
return $this->belongsTo(Report::class, 'rf_report_id', 'report_id');
}
// public function group(): \Illuminate\Database\Eloquent\Relations\BelongsTo
// {
// return $this->belongsTo(MetrikaGroup::class, 'rf_metrika_group_id', 'metrika_group_id');
// }
// public function group(): \Illuminate\Database\Eloquent\Relations\BelongsTo
// {
// return $this->belongsTo(MetrikaGroup::class, 'rf_metrika_group_id', 'metrika_group_id');
// }
// public function values(): HasMany
// {
// return $this->hasMany(MetrikaResultValue::class, 'rf_metrika_result_id', 'metrika_result_id');
// }
// public function values(): HasMany
// {
// return $this->hasMany(MetrikaResultValue::class, 'rf_metrika_result_id', 'metrika_result_id');
// }
}

View File

@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
class MetrikaResultValue extends Model
{
protected $primaryKey = 'metrika_result_value_id';
public $timestamps = false;
protected $fillable = [

View File

@@ -7,7 +7,9 @@ use Illuminate\Database\Eloquent\Model;
class MisBed extends Model
{
protected $table = 'stt_Bed';
protected $primaryKey = 'BedID';
public $timestamps = false;
protected $fillable = [
@@ -24,14 +26,14 @@ class MisBed extends Model
'x_Edition',
'x_Status',
'ShiftNum',
'rf_PreviousBedID'
'rf_PreviousBedID',
];
protected $casts = [
'DateWorkB' => 'datetime',
'DateWorkE' => 'datetime',
'UGUID' => 'string',
'x_Status' => 'integer'
'x_Status' => 'integer',
];
public function bedActions()

View File

@@ -7,7 +7,9 @@ use Illuminate\Database\Eloquent\Model;
class MisBedAction extends Model
{
protected $table = 'stt_BedAction';
protected $primaryKey = 'BedActionID';
public $timestamps = false;
protected $fillable = [
@@ -24,20 +26,21 @@ class MisBedAction extends Model
'rf_DocPRVDID',
'rf_MedStageID',
'rf_BedProfileID',
'SystemDate'
'SystemDate',
];
protected $casts = [
'Date' => 'datetime',
'SystemDate' => 'datetime',
'UGUID' => 'string',
'x_Status' => 'integer'
'x_Status' => 'integer',
];
/**
* Типы действий с койками
*/
const ACTION_TYPE_OCCUPIED = 1; // Поступление
const ACTION_TYPE_FREE = 2; // Выписка
public function bed()
@@ -53,7 +56,7 @@ class MisBedAction extends Model
$query = self::where('rf_MigrationPatientID', $migrationPatientId)
->whereIn('rf_ActionTypeID', [
self::ACTION_TYPE_OCCUPIED,
self::ACTION_TYPE_FREE
self::ACTION_TYPE_FREE,
])
->orderBy('Date');

View File

@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
class MisDiagnos extends Model
{
protected $table = 'stt_diagnos';
protected $primaryKey = 'DiagnosID';
protected $fillable = [

View File

@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
class MisDocPrvd extends Model
{
protected $primaryKey = 'DocPRVDID';
protected $table = 'hlt_docprvd';
public function lpuDoctor()

View File

@@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Auth;
class MisLpuDoctor extends Model
{
public $table = 'hlt_lpudoctor';
protected $primaryKey = 'LPUDoctorID';
public function scopeActive($query)

View File

@@ -7,10 +7,11 @@ use Illuminate\Database\Eloquent\Model;
class MisMKB extends Model
{
protected $table = 'oms_mkb';
protected $primaryKey = 'MKBID';
protected $fillable = [
'DS',
'NAME'
'NAME',
];
}

View File

@@ -9,7 +9,9 @@ use Illuminate\Support\Facades\DB;
class MisMedicalHistory extends Model
{
protected $table = 'stt_medicalhistory';
protected $primaryKey = 'MedicalHistoryID';
public $timestamps = false;
protected $fillable = [
@@ -18,12 +20,12 @@ class MisMedicalHistory extends Model
'Name',
'OT',
'BD',
'Address'
'Address',
];
protected $casts = [
'DateRecipient' => 'datetime',
'DateExtract' => 'datetime'
'DateExtract' => 'datetime',
];
/**
@@ -45,7 +47,7 @@ class MisMedicalHistory extends Model
*/
public function getActualDischargeDate(): ?Carbon
{
if (!$this->DateExtract) {
if (! $this->DateExtract) {
return null;
}
@@ -62,7 +64,7 @@ class MisMedicalHistory extends Model
*/
public function getBedDays(): int
{
if (!$this->DateRecipient) {
if (! $this->DateRecipient) {
return 0;
}
@@ -106,15 +108,15 @@ class MisMedicalHistory extends Model
return $this->surgicalOperations()->where('rf_StationarBranchID', $branchId)
->where('Date', '>=', $startDate)
->where('Date', '<=', $endDate);
// ->whereBetween('Date', [$startDate, $endDate]);
// ->whereBetween('Date', [$startDate, $endDate]);
}
public function scopeCurrentlyHospitalized($query)
{
return $query->where(function ($builder) {
$builder->whereDate('DateExtract', '1900-01-01')
->orWhereDate('DateExtract', '2222-01-01');
})
$builder->whereDate('DateExtract', '1900-01-01')
->orWhereDate('DateExtract', '2222-01-01');
})
->where('MedicalHistoryID', '<>', 0);
}
@@ -188,7 +190,7 @@ class MisMedicalHistory extends Model
if ($startDate && $endDate) {
$q->where('mp.DateIngoing', '>=', $startDate)
->where('mp.DateIngoing', '<=', $endDate);
// $q->whereBetween('mp.DateIngoing', [$startDate, $endDate]);
// $q->whereBetween('mp.DateIngoing', [$startDate, $endDate]);
}
});
}

View File

@@ -9,6 +9,7 @@ use Illuminate\Support\Carbon;
class MisMigrationPatient extends Model
{
protected $table = 'stt_migrationpatient';
protected $primaryKey = 'MigrationPatientID';
protected $casts = [
@@ -43,10 +44,10 @@ class MisMigrationPatient extends Model
/**
* Находятся на лечении
*/
public function scopeCurrentlyInTreatment($query, $branchId = null, DateRange $dateRange = null)
public function scopeCurrentlyInTreatment($query, $branchId = null, ?DateRange $dateRange = null)
{
$query->whereNotIn('rf_kl_VisitResultID', [4])
->whereHas('medicalHistory', function ($query) use ($branchId, $dateRange) {
->whereHas('medicalHistory', function ($query) {
$query->whereDate('DateExtract', '1900-01-01');
})
->where('rf_MedicalHistoryID', '<>', 0);
@@ -56,7 +57,7 @@ class MisMigrationPatient extends Model
}
if ($dateRange) {
// $query->whereBetween('DateIngoing', [$dateRange->startSql(), $dateRange->endSql()]);
// $query->whereBetween('DateIngoing', [$dateRange->startSql(), $dateRange->endSql()]);
$query->where('DateIngoing', '>=', $dateRange->startSql())
->where('DateIngoing', '<=', $dateRange->endSql());
}
@@ -78,7 +79,7 @@ class MisMigrationPatient extends Model
/**
* Выбывшие пациенты (все исходы)
*/
public function scopeOutcomePatients($query, $branchId = null, DateRange $dateRange = null)
public function scopeOutcomePatients($query, $branchId = null, ?DateRange $dateRange = null)
{
$query->where('rf_MedicalHistoryID', '<>', 0);
@@ -101,7 +102,7 @@ class MisMigrationPatient extends Model
/**
* Выписанные пациенты
*/
public function scopeOutcomeDischarged($query, $branchId = null, DateRange $dateRange = null)
public function scopeOutcomeDischarged($query, $branchId = null, ?DateRange $dateRange = null)
{
// По уточненному SQL: Выписано за период
$dischargeCodes = [1, 11, 2, 12, 7, 18, 48];
@@ -128,7 +129,7 @@ class MisMigrationPatient extends Model
/**
* Перевод в другое отделение
*/
public function scopeOutcomeTransferred($query, $branchId = null, DateRange $dateRange = null)
public function scopeOutcomeTransferred($query, $branchId = null, ?DateRange $dateRange = null)
{
// По заданному SQL: только эти коды перевода
$transferCodes = [4, 14];
@@ -155,7 +156,7 @@ class MisMigrationPatient extends Model
/**
* Умершие пациенты
*/
public function scopeDeceasedOutcome($query, $branchId = null, DateRange $dateRange = null)
public function scopeDeceasedOutcome($query, $branchId = null, ?DateRange $dateRange = null)
{
// ID умершего
$deceasedCodes = [5, 6, 15, 16];
@@ -179,7 +180,7 @@ class MisMigrationPatient extends Model
return $query;
}
public function scopeOutcomeWithoutTransferred($query, $branchId = null, DateRange $dateRange = null)
public function scopeOutcomeWithoutTransferred($query, $branchId = null, ?DateRange $dateRange = null)
{
// По заданной логике переводы только 4 и 14, исключаем их
$query->whereNotIn('rf_kl_VisitResultID', [4, 14])
@@ -202,16 +203,17 @@ class MisMigrationPatient extends Model
return $query;
}
public function scopeExtractedToday($query, $branchId = null, DateRange $dateRange = null)
public function scopeExtractedToday($query, $branchId = null, ?DateRange $dateRange = 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');
// 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($dateRange, function($query) use ($dateRange) {
->when($dateRange, function ($query) use ($dateRange) {
$startDate = Carbon::parse($dateRange->startSql())->toDateString();
$endDate = Carbon::parse($dateRange->endSql())->toDateString();
return $query->whereHas('medicalHistory', function ($mhQuery) use ($startDate, $endDate) {
$mhQuery->whereDate('DateExtract', '>', $startDate)
->whereDate('DateExtract', '<=', $endDate);

View File

@@ -14,4 +14,4 @@ class MisOperationPurpose extends Model
{
return $this->belongsTo(MisSurgicalOperation::class, 'rf_SurgicalOperationID', 'SurgicalOperationID');
}
}
}

View File

@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
class MisServiceMedical extends Model
{
protected $table = 'oms_servicemedical';
protected $primaryKey = 'ServiceMedicalID';
public function surgicalOperations()

View File

@@ -7,5 +7,6 @@ use Illuminate\Database\Eloquent\Model;
class MisStationarBranch extends Model
{
protected $table = 'stt_stationarbranch';
protected $primaryKey = 'StationarBranchID';
}

View File

@@ -8,9 +8,11 @@ use LaravelIdea\Helper\App\Models\_IH_MisSurgicalOperation_QB;
class MisSurgicalOperation extends Model
{
private const COMPLETED_OPERATION_STATUS_ID = 3;
private const CANCELLED_OPERATION_STATUS_ID = 4;
protected $table = 'stt_surgicaloperation';
protected $primaryKey = 'SurgicalOperationID';
public function serviceMedical()
@@ -28,10 +30,9 @@ class MisSurgicalOperation extends Model
return $this->hasOne(MisOperationPurpose::class, 'rf_SurgicalOperationID', 'SurgicalOperationID');
}
/**
* Получить операции у которых исход <> 0
* @param $query
*
* @return _IH_MisSurgicalOperation_QB|_IH_MisSurgicalOperation_QB
*/
public function scopeCompleted($query)
@@ -41,7 +42,7 @@ class MisSurgicalOperation extends Model
/**
* Получить операции с благоприятным исходом
* @param $query
*
* @return _IH_MisSurgicalOperation_QB|_IH_MisSurgicalOperation_QB
*/
public function scopePositiveResult($query)
@@ -51,7 +52,7 @@ class MisSurgicalOperation extends Model
/**
* Получить операции с неблагоприятным исходом
* @param $query
*
* @return _IH_MisSurgicalOperation_QB|_IH_MisSurgicalOperation_QB
*/
public function scopeNotPositiveResult($query)
@@ -59,10 +60,9 @@ class MisSurgicalOperation extends Model
return $query->where('rf_OperationResultID', 2);
}
/**
* Получить отмененные операции через назначение
* @param $query
*
* @return _IH_MisSurgicalOperation_QB
*/
public function scopeCanceled($query)

View File

@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
class ObservationPatient extends Model
{
protected $primaryKey = 'observation_patient_id';
public $timestamps = false;
protected $fillable = [
@@ -15,7 +16,7 @@ class ObservationPatient extends Model
'rf_mkab_id',
'rf_department_id',
'rf_report_id',
'comment'
'comment',
];
public function history()

View File

@@ -14,6 +14,7 @@ class Report extends Model
const METRIC_BED_DAYS_ID = 18;
protected $primaryKey = 'report_id';
public $timestamps = false;
protected $fillable = [
@@ -137,9 +138,9 @@ class Report extends Model
// Сохраняем результат как метрику
MetrikaResult::updateOrCreate([
'rf_report_id' => $this->report_id,
'rf_metrika_item_id' => self::METRIC_BED_DAYS_ID,
],
'rf_report_id' => $this->report_id,
'rf_metrika_item_id' => self::METRIC_BED_DAYS_ID,
],
[
'value' => $avgBedDays,
]);

View File

@@ -5,7 +5,6 @@ namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Foundation\Auth\User as Authenticatable;
@@ -17,7 +16,7 @@ use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable, HasApiTokens;
use HasApiTokens, HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
@@ -30,7 +29,7 @@ class User extends Authenticatable
'password',
'rf_lpudoctor_id',
'rf_department_id',
'current_role_id'
'current_role_id',
];
/**
@@ -99,10 +98,10 @@ class User extends Authenticatable
$sessionId = session()->getId();
$token = Auth::user()->currentAccessToken();
// $sessionKey = 'user_' . $this->id . '_current_role';
// $roleId = $this->current_role_id ?? $defaultRoleId;
//
// $role = Role::where('role_id', $roleId)->first();
// $sessionKey = 'user_' . $this->id . '_current_role';
// $roleId = $this->current_role_id ?? $defaultRoleId;
//
// $role = Role::where('role_id', $roleId)->first();
if ($token) {
foreach ($token->abilities as $ability) {
@@ -121,7 +120,7 @@ class User extends Authenticatable
$sessionRoleId = DB::table('sessions')->where('id', $sessionId)->value('role_id');
$roleId = $sessionRoleId ?? $defaultRoleId;
// dd($sessionId);
// dd($sessionId);
$role = Role::where('role_id', $roleId)->first();
return $role;

View File

@@ -13,7 +13,7 @@ class UserDepartment extends Model
'rf_department_id',
'is_favorite',
'order',
'user_name'
'user_name',
];
protected $casts = [