Работа над журналом для ст. мед сестер
This commit is contained in:
22
app/Models/MaterializedViewModel.php
Normal file
22
app/Models/MaterializedViewModel.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MaterializedViewModel extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
public $incrementing = false;
|
||||
protected $guarded = [];
|
||||
|
||||
public function save(array $options = [])
|
||||
{
|
||||
throw new \BadMethodCallException('Materialized view is read-only. Use REFRESH MATERIALIZED VIEW instead.');
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot delete from materialized view.');
|
||||
}
|
||||
}
|
||||
49
app/Models/MedicalHistory.php
Normal file
49
app/Models/MedicalHistory.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string|null $medical_card_number
|
||||
* @property string|null $full_name
|
||||
* @property \Carbon\Carbon|null $birth_date
|
||||
* @property \Carbon\Carbon|null $recipient_date
|
||||
* @property \Carbon\Carbon|null $extract_date
|
||||
* @property \Carbon\Carbon|null $death_date
|
||||
* @property int|null $male
|
||||
* @property int|null $hospital_result_id
|
||||
* @property int|null $visit_result_id
|
||||
* @property int|null $latest_migration_id
|
||||
*/
|
||||
class MedicalHistory extends MaterializedViewModel
|
||||
{
|
||||
protected $table = 'mv_medicalhistory_summary';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
public function migrations(): \Illuminate\Database\Eloquent\Relations\HasMany|MedicalHistory
|
||||
{
|
||||
return $this->hasMany(MigrationPatient::class, 'medical_history_id', 'id');
|
||||
}
|
||||
|
||||
public function operations(): \Illuminate\Database\Eloquent\Relations\HasMany|MedicalHistory
|
||||
{
|
||||
return $this->hasMany(SurgicalOperation::class, 'medical_history_id', 'id');
|
||||
}
|
||||
|
||||
public function latestMigration()
|
||||
{
|
||||
return $this->hasOne(MigrationPatient::class, 'medical_history_id', 'id')
|
||||
->latest('ingoing_date');
|
||||
}
|
||||
|
||||
public function operationsInDepartment($query, $departmentId)
|
||||
{
|
||||
return $this->operations()->where('department_id', $departmentId);
|
||||
}
|
||||
|
||||
// Скоупы
|
||||
public function scopeUrgency($query, $typeId) // 1 = Экстренно, 2 = Планово
|
||||
{
|
||||
return $query->where('urgency_id', $typeId);
|
||||
}
|
||||
}
|
||||
34
app/Models/MedicalHistoryCorrection.php
Normal file
34
app/Models/MedicalHistoryCorrection.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MedicalHistoryCorrection extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'medical_history_id',
|
||||
'medical_card_number',
|
||||
'full_name',
|
||||
'birth_date',
|
||||
'recipient_date',
|
||||
'extract_date',
|
||||
'death_date',
|
||||
'male',
|
||||
'urgency_id',
|
||||
'hospital_result_id',
|
||||
'visit_result_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'birth_date' => 'datetime',
|
||||
'recipient_date' => 'datetime',
|
||||
'extract_date' => 'datetime',
|
||||
'death_date' => 'datetime',
|
||||
];
|
||||
|
||||
public function medicalHistory()
|
||||
{
|
||||
return $this->belongsTo(MedicalHistory::class);
|
||||
}
|
||||
}
|
||||
30
app/Models/MedicalHistoryNurse.php
Normal file
30
app/Models/MedicalHistoryNurse.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MedicalHistoryNurse extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'source_type',
|
||||
'medical_card_number',
|
||||
'full_name',
|
||||
'birth_date',
|
||||
'recipient_date',
|
||||
'extract_date',
|
||||
'death_date',
|
||||
'male',
|
||||
'urgency_id',
|
||||
'hospital_result_id',
|
||||
'visit_result_id',
|
||||
'user_id',
|
||||
'mis_user_id',
|
||||
'comment',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,9 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\Sluggable\Attributes\Sluggable;
|
||||
|
||||
#[Sluggable(from: 'name', to: 'code')]
|
||||
class MetrikaItem extends Model
|
||||
{
|
||||
protected $primaryKey = 'metrika_item_id';
|
||||
@@ -16,5 +18,6 @@ class MetrikaItem extends Model
|
||||
'description',
|
||||
'data_type',
|
||||
'is_active',
|
||||
'code'
|
||||
];
|
||||
}
|
||||
|
||||
105
app/Models/MigrationPatient.php
Normal file
105
app/Models/MigrationPatient.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\DateRange;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigrationPatient extends MaterializedViewModel
|
||||
{
|
||||
protected $table = 'mv_migrationpatient_details';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
public function medicalHistory()
|
||||
{
|
||||
return $this->belongsTo(MedicalHistory::class, 'medical_history_id', 'id');
|
||||
}
|
||||
|
||||
public function operations()
|
||||
{
|
||||
return $this->hasMany(SurgicalOperation::class, 'migration_patient_id', 'id');
|
||||
}
|
||||
|
||||
// Пересечение с отчетным периодом
|
||||
public function scopeDateRange($query, string $from, string $to)
|
||||
{
|
||||
return $query->where('ingoing_date', '<=', $to)
|
||||
->where(function ($q) use ($from) {
|
||||
$q->whereNull('out_date')->orWhere('out_date', '>=', $from);
|
||||
});
|
||||
}
|
||||
|
||||
// Фильтр по подразделению (получает ID отделений)
|
||||
public function scopeDepartment($query, int $departmentId)
|
||||
{
|
||||
$branchIds = DB::table('stt_stationarbranch')
|
||||
->where('rf_DepartmentID', $departmentId)
|
||||
->pluck('StationarBranchID');
|
||||
|
||||
return $query->whereIn('stationar_branch_id', $branchIds);
|
||||
}
|
||||
|
||||
// Добавляет вычисляемый столбец `category` (только для отображения)
|
||||
public function scopeWithCategory($query, string $from, string $to)
|
||||
{
|
||||
$sql = "CASE
|
||||
WHEN ingoing_date BETWEEN ? AND ? THEN 'admitted'
|
||||
WHEN out_date BETWEEN ? AND ? THEN
|
||||
CASE
|
||||
WHEN death_date IS NOT NULL AND death_date BETWEEN ? AND ? THEN 'deceased'
|
||||
WHEN stat_cure_result_id IN (3,4,7) THEN 'transferred'
|
||||
ELSE 'discharged'
|
||||
END
|
||||
WHEN ingoing_date < ? AND (out_date IS NULL OR out_date > ?) THEN 'current'
|
||||
ELSE 'historical'
|
||||
END as category";
|
||||
|
||||
return $query->selectRaw($sql, [$from, $to, $from, $to, $from, $to, $to, $to]);
|
||||
}
|
||||
|
||||
// Быстрые фильтры по статусам (используют индексы MV, а не computed column)
|
||||
public function scopeAdmitted($query, string $from, string $to)
|
||||
{
|
||||
return $query->where('ingoing_date', '>', $from)
|
||||
->where('ingoing_date', '<=', $to);
|
||||
}
|
||||
|
||||
public function scopeDischarged($query, string $from, string $to)
|
||||
{
|
||||
return $query->where('out_date', '>', $from)
|
||||
->where('out_date', '<=', $to)
|
||||
->whereNotIn('stat_cure_result_id', [3, 4, 7])
|
||||
->whereNull('death_date'); // умершие не считаются "выбывшими домой"
|
||||
}
|
||||
|
||||
public function scopeTransferred($query, string $from, string $to)
|
||||
{
|
||||
return $query->where('out_date', '>', $from)
|
||||
->where('out_date', '<=', $to)
|
||||
->whereIn('stat_cure_result_id', [3, 4, 7]);
|
||||
}
|
||||
|
||||
public function scopeDeceased($query, string $from, string $to)
|
||||
{
|
||||
return $query->whereNotNull('death_date')
|
||||
->where('death_date', '>', $from)
|
||||
->where('death_date', '<=', $to);
|
||||
}
|
||||
|
||||
public function scopeCurrent($query, DateRange $dateRange)
|
||||
{
|
||||
// return $query->where('ingoing_date', '<', $dateRange->startSql())
|
||||
// ->where(function ($q) use ($dateRange) {
|
||||
// $q->whereNull('out_date')->orWhere('out_date', '>', $dateRange->endSql());
|
||||
// });
|
||||
// return $query->where('ingoing_date', '<=', $dateRange->endSql())
|
||||
// ->has('medicalHistory')
|
||||
// ->where(function ($q) use ($dateRange) {
|
||||
// $q->whereNull('out_date')
|
||||
// ->orWhere('out_date', '>=', $dateRange->startSql())
|
||||
// ->where('out_date', '<=', $dateRange->endSql());
|
||||
// });
|
||||
return $query->where('is_actually_current', true);
|
||||
}
|
||||
}
|
||||
27
app/Models/ReportNurse.php
Normal file
27
app/Models/ReportNurse.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ReportNurse extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'date_report',
|
||||
'sent_at',
|
||||
'period_type',
|
||||
'period_start',
|
||||
'period_end',
|
||||
'status_id'
|
||||
];
|
||||
|
||||
public function patients()
|
||||
{
|
||||
return $this->hasMany(ReportNursePatient::class, 'report_nurse_id');
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
return $this->belongsTo(ReportStatus::class);
|
||||
}
|
||||
}
|
||||
19
app/Models/ReportPatientStatus.php
Normal file
19
app/Models/ReportPatientStatus.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\Sluggable\Attributes\Sluggable;
|
||||
|
||||
|
||||
/**
|
||||
* Статус пациента (состоит, поступил, умер, выписан, переведен)
|
||||
*/
|
||||
#[Sluggable(from: 'name', to: 'code')]
|
||||
class ReportPatientStatus extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'code'
|
||||
];
|
||||
}
|
||||
18
app/Models/ReportPatientType.php
Normal file
18
app/Models/ReportPatientType.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\Sluggable\Attributes\Sluggable;
|
||||
|
||||
/**
|
||||
* Тип пациента (экстренный, плановый)
|
||||
*/
|
||||
#[Sluggable(from: 'name', to: 'code')]
|
||||
class ReportPatientType extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'code'
|
||||
];
|
||||
}
|
||||
18
app/Models/ReportStatus.php
Normal file
18
app/Models/ReportStatus.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\Sluggable\Attributes\Sluggable;
|
||||
|
||||
/**
|
||||
* Статус отчета (1 - черновик; 2 - опубликован)
|
||||
*/
|
||||
#[Sluggable(from: 'name', to: 'code')]
|
||||
class ReportStatus extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'code'
|
||||
];
|
||||
}
|
||||
21
app/Models/SurgicalOperation.php
Normal file
21
app/Models/SurgicalOperation.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SurgicalOperation extends Model
|
||||
{
|
||||
protected $table = 'mv_surgical_operations';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
public function medicalHistory(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(MedicalHistory::class, 'medical_history_id', 'id');
|
||||
}
|
||||
|
||||
public function migration(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(MigrationPatient::class, 'migration_patient_id', 'id');
|
||||
}
|
||||
}
|
||||
19
app/Models/UnifiedMedicalHistory.php
Normal file
19
app/Models/UnifiedMedicalHistory.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UnifiedMedicalHistory extends MaterializedViewModel
|
||||
{
|
||||
protected $table = 'v_unified_medical_history';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $casts = [
|
||||
'birth_date' => 'date',
|
||||
'recipient_date' => 'datetime',
|
||||
'extract_date' => 'datetime',
|
||||
'death_date' => 'datetime',
|
||||
'male' => 'boolean',
|
||||
];
|
||||
}
|
||||
@@ -12,11 +12,12 @@ use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
use HasApiTokens, HasFactory, Notifiable, HasRoles;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
|
||||
Reference in New Issue
Block a user