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

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

@@ -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);