modified: .gitignore
This commit is contained in:
55
app/Models/DepartmentPatient.php
Normal file
55
app/Models/DepartmentPatient.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DepartmentPatient extends Model
|
||||
{
|
||||
protected $primaryKey = 'department_patient_id';
|
||||
|
||||
protected $fillable = [
|
||||
'rf_department_id',
|
||||
'source_type',
|
||||
'rf_medicalhistory_id',
|
||||
'full_name',
|
||||
'birth_date',
|
||||
'patient_kind',
|
||||
'diagnosis_code',
|
||||
'diagnosis_name',
|
||||
'admitted_at',
|
||||
'is_current',
|
||||
'outcome_type',
|
||||
'outcome_at',
|
||||
'created_by',
|
||||
'linked_to_mis_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'birth_date' => 'date',
|
||||
'admitted_at' => 'datetime',
|
||||
'is_current' => 'boolean',
|
||||
'outcome_at' => 'datetime',
|
||||
'linked_to_mis_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function scopeCurrent($query)
|
||||
{
|
||||
return $query->where('is_current', true);
|
||||
}
|
||||
|
||||
public function scopeManual($query)
|
||||
{
|
||||
return $query->where('source_type', 'manual');
|
||||
}
|
||||
|
||||
public function observationPatients()
|
||||
{
|
||||
return $this->hasMany(ObservationPatient::class, 'rf_department_patient_id', 'department_patient_id');
|
||||
}
|
||||
|
||||
public function operations()
|
||||
{
|
||||
return $this->hasMany(DepartmentPatientOperation::class, 'rf_department_patient_id', 'department_patient_id');
|
||||
}
|
||||
}
|
||||
36
app/Models/DepartmentPatientOperation.php
Normal file
36
app/Models/DepartmentPatientOperation.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DepartmentPatientOperation extends Model
|
||||
{
|
||||
protected $primaryKey = 'department_patient_operation_id';
|
||||
|
||||
protected $fillable = [
|
||||
'rf_department_patient_id',
|
||||
'rf_kl_service_medical_id',
|
||||
'service_code',
|
||||
'service_name',
|
||||
'urgency',
|
||||
'started_at',
|
||||
'ended_at',
|
||||
'created_by',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'started_at' => 'datetime',
|
||||
'ended_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function patient()
|
||||
{
|
||||
return $this->belongsTo(DepartmentPatient::class, 'rf_department_patient_id', 'department_patient_id');
|
||||
}
|
||||
|
||||
public function serviceMedical()
|
||||
{
|
||||
return $this->belongsTo(MisServiceMedical::class, 'rf_kl_service_medical_id', 'ServiceMedicalID');
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
use App\Services\DateRange;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class LifeMisMigrationPatient extends Model
|
||||
{
|
||||
@@ -72,18 +73,19 @@ class LifeMisMigrationPatient extends Model
|
||||
*/
|
||||
public function scopeOutcomePatients($query, $branchId = null, DateRange $dateRange = null)
|
||||
{
|
||||
$query->where('rf_kl_VisitResultID', '<>', 0) // не активное лечение
|
||||
->whereDate('DateOut', '<>', '1900-01-01') // есть дата выбытия
|
||||
->where('rf_MedicalHistoryID', '<>', 0);
|
||||
$query->where('rf_MedicalHistoryID', '<>', 0);
|
||||
|
||||
if ($branchId) {
|
||||
$query->where('rf_StationarBranchID', $branchId);
|
||||
}
|
||||
|
||||
if ($dateRange) {
|
||||
// $query->whereBetween('DateOut', [$dateRange->startSql(), $dateRange->endSql()]);
|
||||
$query->where('DateOut', '>=', $dateRange->startSql())
|
||||
->where('DateOut', '<=', $dateRange->endSql());
|
||||
$startDate = Carbon::parse($dateRange->startSql())->toDateString();
|
||||
$endDate = Carbon::parse($dateRange->endSql())->toDateString();
|
||||
$query->whereHas('medicalHistory', function ($mhQuery) use ($startDate, $endDate) {
|
||||
$mhQuery->whereDate('DateExtract', '>', $startDate)
|
||||
->whereDate('DateExtract', '<=', $endDate);
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
@@ -94,11 +96,10 @@ class LifeMisMigrationPatient extends Model
|
||||
*/
|
||||
public function scopeOutcomeDischarged($query, $branchId = null, DateRange $dateRange = null)
|
||||
{
|
||||
// ID выписки
|
||||
$dischargeCodes = [1, 7, 8, 9, 10, 11, 48, 49, 124];
|
||||
// По уточненному SQL: Выписано за период
|
||||
$dischargeCodes = [1, 11, 2, 12, 7, 18, 48];
|
||||
|
||||
$query->whereIn('rf_kl_VisitResultID', $dischargeCodes)
|
||||
->whereDate('DateOut', '<>', '1900-01-01')
|
||||
->where('rf_MedicalHistoryID', '<>', 0);
|
||||
|
||||
if ($branchId) {
|
||||
@@ -106,9 +107,12 @@ class LifeMisMigrationPatient extends Model
|
||||
}
|
||||
|
||||
if ($dateRange) {
|
||||
// $query->whereBetween('DateOut', [$dateRange->startSql(), $dateRange->endSql()]);
|
||||
$query->where('DateOut', '>=', $dateRange->startSql())
|
||||
->where('DateOut', '<=', $dateRange->endSql());
|
||||
$startDate = Carbon::parse($dateRange->startSql())->toDateString();
|
||||
$endDate = Carbon::parse($dateRange->endSql())->toDateString();
|
||||
$query->whereHas('medicalHistory', function ($mhQuery) use ($startDate, $endDate) {
|
||||
$mhQuery->whereDate('DateExtract', '>', $startDate)
|
||||
->whereDate('DateExtract', '<=', $endDate);
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
@@ -119,11 +123,10 @@ class LifeMisMigrationPatient extends Model
|
||||
*/
|
||||
public function scopeOutcomeTransferred($query, $branchId = null, DateRange $dateRange = null)
|
||||
{
|
||||
// ID перевода
|
||||
$transferCodes = [2, 3, 4, 12, 13, 14];
|
||||
// По заданному SQL: только эти коды перевода
|
||||
$transferCodes = [4, 14];
|
||||
|
||||
$query->whereIn('rf_kl_VisitResultID', $transferCodes)
|
||||
->whereDate('DateOut', '<>', '1900-01-01')
|
||||
->where('rf_MedicalHistoryID', '<>', 0);
|
||||
|
||||
if ($branchId) {
|
||||
@@ -131,9 +134,12 @@ class LifeMisMigrationPatient extends Model
|
||||
}
|
||||
|
||||
if ($dateRange) {
|
||||
// $query->whereBetween('DateOut', [$dateRange->startSql(), $dateRange->endSql()]);
|
||||
$query->where('DateOut', '>=', $dateRange->startSql())
|
||||
->where('DateOut', '<=', $dateRange->endSql());
|
||||
$startDate = Carbon::parse($dateRange->startSql())->toDateString();
|
||||
$endDate = Carbon::parse($dateRange->endSql())->toDateString();
|
||||
$query->whereHas('medicalHistory', function ($mhQuery) use ($startDate, $endDate) {
|
||||
$mhQuery->whereDate('DateExtract', '>', $startDate)
|
||||
->whereDate('DateExtract', '<=', $endDate);
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
@@ -148,7 +154,6 @@ class LifeMisMigrationPatient extends Model
|
||||
$deceasedCodes = [5, 6, 15, 16];
|
||||
|
||||
$query->whereIn('rf_kl_VisitResultID', $deceasedCodes)
|
||||
->whereDate('DateOut', '<>', '1900-01-01')
|
||||
->where('rf_MedicalHistoryID', '<>', 0);
|
||||
|
||||
if ($branchId) {
|
||||
@@ -156,9 +161,12 @@ class LifeMisMigrationPatient extends Model
|
||||
}
|
||||
|
||||
if ($dateRange) {
|
||||
// $query->whereBetween('DateOut', [$dateRange->startSql(), $dateRange->endSql()]);
|
||||
$query->where('DateOut', '>=', $dateRange->startSql())
|
||||
->where('DateOut', '<=', $dateRange->endSql());
|
||||
$startDate = Carbon::parse($dateRange->startSql())->toDateString();
|
||||
$endDate = Carbon::parse($dateRange->endSql())->toDateString();
|
||||
$query->whereHas('medicalHistory', function ($mhQuery) use ($startDate, $endDate) {
|
||||
$mhQuery->whereDate('DateExtract', '>', $startDate)
|
||||
->whereDate('DateExtract', '<=', $endDate);
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
@@ -166,11 +174,8 @@ class LifeMisMigrationPatient extends Model
|
||||
|
||||
public function scopeOutcomeWithoutTransferred($query, $branchId = null, DateRange $dateRange = null)
|
||||
{
|
||||
// ID выписанных, без переводных
|
||||
$outcomeWithoutTransferredIds = [5, 6, 15, 16, 1, 7, 8, 9, 10, 11, 48, 49, 124];
|
||||
|
||||
$query->whereIn('rf_kl_VisitResultID', $outcomeWithoutTransferredIds)
|
||||
->whereDate('DateOut', '<>', '1900-01-01')
|
||||
$query->whereNotIn('rf_kl_VisitResultID', [4, 14])
|
||||
->where('rf_kl_VisitResultID', '<>', 0)
|
||||
->where('rf_MedicalHistoryID', '<>', 0);
|
||||
|
||||
if ($branchId) {
|
||||
@@ -178,9 +183,12 @@ class LifeMisMigrationPatient extends Model
|
||||
}
|
||||
|
||||
if ($dateRange) {
|
||||
// $query->whereBetween('DateOut', [$dateRange->startSql(), $dateRange->endSql()]);
|
||||
$query->where('DateOut', '>=', $dateRange->startSql())
|
||||
->where('DateOut', '<=', $dateRange->endSql());
|
||||
$startDate = Carbon::parse($dateRange->startSql())->toDateString();
|
||||
$endDate = Carbon::parse($dateRange->endSql())->toDateString();
|
||||
$query->whereHas('medicalHistory', function ($mhQuery) use ($startDate, $endDate) {
|
||||
$mhQuery->whereDate('DateExtract', '>', $startDate)
|
||||
->whereDate('DateExtract', '<=', $endDate);
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
@@ -194,9 +202,12 @@ class LifeMisMigrationPatient extends Model
|
||||
$query->where('rf_kl_VisitResultID', '<>', 0)
|
||||
->where('rf_MedicalHistoryID', '<>', 0)
|
||||
->when($dateRange, function($query) use ($dateRange) {
|
||||
// return $query->whereBetween('DateOut', [$dateRange->startSql(), $dateRange->endSql()]);
|
||||
return $query->where('DateOut', '>=', $dateRange->startSql())
|
||||
->where('DateOut', '<=', $dateRange->endSql());
|
||||
$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);
|
||||
});
|
||||
});
|
||||
|
||||
if ($branchId) {
|
||||
|
||||
@@ -11,7 +11,26 @@ class MedicalHistorySnapshot extends Model
|
||||
protected $fillable = [
|
||||
'rf_report_id',
|
||||
'rf_medicalhistory_id',
|
||||
'rf_department_patient_id',
|
||||
'patient_type',
|
||||
'patient_uid',
|
||||
'patient_source_type',
|
||||
'patient_kind',
|
||||
'full_name',
|
||||
'birth_date',
|
||||
'diagnosis_code',
|
||||
'diagnosis_name',
|
||||
'admitted_at',
|
||||
'outcome_type',
|
||||
'outcome_at',
|
||||
'is_manual',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'birth_date' => 'date',
|
||||
'admitted_at' => 'datetime',
|
||||
'outcome_at' => 'datetime',
|
||||
'is_manual' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -30,6 +49,11 @@ class MedicalHistorySnapshot extends Model
|
||||
return $this->belongsTo(MisMedicalHistory::class, 'rf_medicalhistory_id', 'MedicalHistoryID');
|
||||
}
|
||||
|
||||
public function departmentPatient()
|
||||
{
|
||||
return $this->belongsTo(DepartmentPatient::class, 'rf_department_patient_id', 'department_patient_id');
|
||||
}
|
||||
|
||||
// Скоупы для фильтрации
|
||||
public function scopeForReport($query, $reportId)
|
||||
{
|
||||
|
||||
@@ -87,13 +87,15 @@ class MisMedicalHistory extends Model
|
||||
|
||||
public function surgicalOperations()
|
||||
{
|
||||
return $this->hasMany(MisSurgicalOperation::class, 'rf_MedicalHistoryID', 'MedicalHistoryID');
|
||||
return $this->hasMany(MisSurgicalOperation::class, 'rf_MedicalHistoryID', 'MedicalHistoryID')
|
||||
->completed();
|
||||
}
|
||||
|
||||
public function surgicalOperationsInBranch($branchId)
|
||||
{
|
||||
$operations = MisSurgicalOperation::where('rf_MedicalHistoryID', $this->MedicalHistoryID)
|
||||
->where('rf_StationarBranchID', $branchId)
|
||||
->completed()
|
||||
->get();
|
||||
|
||||
return $operations;
|
||||
@@ -109,7 +111,10 @@ class MisMedicalHistory extends Model
|
||||
|
||||
public function scopeCurrentlyHospitalized($query)
|
||||
{
|
||||
return $query->whereDate('DateExtract', '1900-01-01')
|
||||
return $query->where(function ($builder) {
|
||||
$builder->whereDate('DateExtract', '1900-01-01')
|
||||
->orWhereDate('DateExtract', '2222-01-01');
|
||||
})
|
||||
->where('MedicalHistoryID', '<>', 0);
|
||||
}
|
||||
|
||||
@@ -126,7 +131,7 @@ class MisMedicalHistory extends Model
|
||||
*/
|
||||
public function scopeEmergency($query)
|
||||
{
|
||||
return $query->where('rf_EmerSignID', 2);
|
||||
return $query->whereIn('rf_EmerSignID', [2, 4]);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -152,6 +157,12 @@ class MisMedicalHistory extends Model
|
||||
->orderBy('DateOut', 'desc');
|
||||
}
|
||||
|
||||
public function latestMigration()
|
||||
{
|
||||
return $this->hasOne(MisMigrationPatient::class, 'rf_MedicalHistoryID', 'MedicalHistoryID')
|
||||
->ofMany('DateOut', 'max');
|
||||
}
|
||||
|
||||
/*
|
||||
* Движение по StationarBranch
|
||||
*/
|
||||
@@ -181,4 +192,9 @@ class MisMedicalHistory extends Model
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function operationPurpose()
|
||||
{
|
||||
return $this->belongsTo(MisOperationPurpose::class, 'MedicalHistoryID', 'rf_MedicalHistoryID');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,11 @@ class MisMigrationPatient extends Model
|
||||
protected $table = 'stt_migrationpatient';
|
||||
protected $primaryKey = 'MigrationPatientID';
|
||||
|
||||
protected $casts = [
|
||||
'DateIngoing' => 'datetime:Y-m-d H:i:s',
|
||||
'DateOut' => 'datetime:Y-m-d H:i:s',
|
||||
];
|
||||
|
||||
public function branch()
|
||||
{
|
||||
return $this->hasOne(MisStationarBranch::class, 'StationarBranchID', 'rf_StationarBranchID');
|
||||
@@ -31,18 +36,12 @@ class MisMigrationPatient extends Model
|
||||
return $this->hasOne(MisMKB::class, 'MKBID', 'rf_MKBID');
|
||||
}
|
||||
|
||||
public function medicalHistory()
|
||||
{
|
||||
return $this->belongsTo(MisMedicalHistory::class, 'rf_MedicalHistoryID', 'MedicalHistoryID');
|
||||
}
|
||||
|
||||
/**
|
||||
* Находятся на лечении
|
||||
*/
|
||||
public function scopeCurrentlyInTreatment($query, $branchId = null, DateRange $dateRange = null)
|
||||
{
|
||||
$query->where('rf_kl_VisitResultID', 0)
|
||||
->where('rf_kl_StatCureResultID', 0)
|
||||
$query->whereNotIn('rf_kl_VisitResultID', [4])
|
||||
->whereHas('medicalHistory', function ($query) use ($branchId, $dateRange) {
|
||||
$query->whereDate('DateExtract', '1900-01-01');
|
||||
})
|
||||
@@ -77,18 +76,19 @@ class MisMigrationPatient extends Model
|
||||
*/
|
||||
public function scopeOutcomePatients($query, $branchId = null, DateRange $dateRange = null)
|
||||
{
|
||||
$query->where('rf_kl_VisitResultID', '<>', 0) // не активное лечение
|
||||
->whereDate('DateOut', '<>', '1900-01-01') // есть дата выбытия
|
||||
->where('rf_MedicalHistoryID', '<>', 0);
|
||||
$query->where('rf_MedicalHistoryID', '<>', 0);
|
||||
|
||||
if ($branchId) {
|
||||
$query->where('rf_StationarBranchID', $branchId);
|
||||
}
|
||||
|
||||
if ($dateRange) {
|
||||
$query->where('DateOut', '>=', $dateRange->startSql())
|
||||
->where('DateOut', '<=', $dateRange->endSql());
|
||||
// $query->whereBetween('DateOut', [$dateRange->startSql(), $dateRange->endSql()]);
|
||||
$startDate = Carbon::parse($dateRange->startSql())->toDateString();
|
||||
$endDate = Carbon::parse($dateRange->endSql())->toDateString();
|
||||
$query->whereHas('medicalHistory', function ($mhQuery) use ($startDate, $endDate) {
|
||||
$mhQuery->whereDate('DateExtract', '>', $startDate)
|
||||
->whereDate('DateExtract', '<=', $endDate);
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
@@ -99,11 +99,10 @@ class MisMigrationPatient extends Model
|
||||
*/
|
||||
public function scopeOutcomeDischarged($query, $branchId = null, DateRange $dateRange = null)
|
||||
{
|
||||
// ID выписки
|
||||
$dischargeCodes = [1, 7, 8, 9, 10, 11, 48, 49, 124];
|
||||
// По уточненному SQL: Выписано за период
|
||||
$dischargeCodes = [1, 11, 2, 12, 7, 18, 48];
|
||||
|
||||
$query->whereIn('rf_kl_VisitResultID', $dischargeCodes)
|
||||
->whereDate('DateOut', '<>', '1900-01-01')
|
||||
->where('rf_MedicalHistoryID', '<>', 0);
|
||||
|
||||
if ($branchId) {
|
||||
@@ -111,8 +110,12 @@ class MisMigrationPatient extends Model
|
||||
}
|
||||
|
||||
if ($dateRange) {
|
||||
$query->where('DateOut', '>=', $dateRange->startSql())
|
||||
->where('DateOut', '<=', $dateRange->endSql());
|
||||
$startDate = Carbon::parse($dateRange->startSql())->toDateString();
|
||||
$endDate = Carbon::parse($dateRange->endSql())->toDateString();
|
||||
$query->whereHas('medicalHistory', function ($mhQuery) use ($startDate, $endDate) {
|
||||
$mhQuery->whereDate('DateExtract', '>', $startDate)
|
||||
->whereDate('DateExtract', '<=', $endDate);
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
@@ -123,11 +126,10 @@ class MisMigrationPatient extends Model
|
||||
*/
|
||||
public function scopeOutcomeTransferred($query, $branchId = null, DateRange $dateRange = null)
|
||||
{
|
||||
// ID перевода
|
||||
$transferCodes = [2, 3, 4, 12, 13, 14];
|
||||
// По заданному SQL: только эти коды перевода
|
||||
$transferCodes = [4, 14];
|
||||
|
||||
$query->whereIn('rf_kl_VisitResultID', $transferCodes)
|
||||
->whereDate('DateOut', '<>', '1900-01-01')
|
||||
->where('rf_MedicalHistoryID', '<>', 0);
|
||||
|
||||
if ($branchId) {
|
||||
@@ -135,8 +137,12 @@ class MisMigrationPatient extends Model
|
||||
}
|
||||
|
||||
if ($dateRange) {
|
||||
$query->where('DateOut', '>=', $dateRange->startSql())
|
||||
->where('DateOut', '<=', $dateRange->endSql());
|
||||
$startDate = Carbon::parse($dateRange->startSql())->toDateString();
|
||||
$endDate = Carbon::parse($dateRange->endSql())->toDateString();
|
||||
$query->whereHas('medicalHistory', function ($mhQuery) use ($startDate, $endDate) {
|
||||
$mhQuery->whereDate('DateExtract', '>', $startDate)
|
||||
->whereDate('DateExtract', '<=', $endDate);
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
@@ -151,7 +157,6 @@ class MisMigrationPatient extends Model
|
||||
$deceasedCodes = [5, 6, 15, 16];
|
||||
|
||||
$query->whereIn('rf_kl_VisitResultID', $deceasedCodes)
|
||||
->whereDate('DateOut', '<>', '1900-01-01')
|
||||
->where('rf_MedicalHistoryID', '<>', 0);
|
||||
|
||||
if ($branchId) {
|
||||
@@ -159,8 +164,12 @@ class MisMigrationPatient extends Model
|
||||
}
|
||||
|
||||
if ($dateRange) {
|
||||
$query->where('DateOut', '>=', $dateRange->startSql())
|
||||
->where('DateOut', '<=', $dateRange->endSql());
|
||||
$startDate = Carbon::parse($dateRange->startSql())->toDateString();
|
||||
$endDate = Carbon::parse($dateRange->endSql())->toDateString();
|
||||
$query->whereHas('medicalHistory', function ($mhQuery) use ($startDate, $endDate) {
|
||||
$mhQuery->whereDate('DateExtract', '>', $startDate)
|
||||
->whereDate('DateExtract', '<=', $endDate);
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
@@ -168,11 +177,9 @@ class MisMigrationPatient extends Model
|
||||
|
||||
public function scopeOutcomeWithoutTransferred($query, $branchId = null, DateRange $dateRange = null)
|
||||
{
|
||||
// ID выписанных, без переводных
|
||||
$outcomeWithoutTransferredIds = [5, 6, 15, 16, 1, 7, 8, 9, 10, 11, 48, 49, 124];
|
||||
|
||||
$query->whereIn('rf_kl_VisitResultID', $outcomeWithoutTransferredIds)
|
||||
->whereDate('DateOut', '<>', '1900-01-01')
|
||||
// По заданной логике переводы только 4 и 14, исключаем их
|
||||
$query->whereNotIn('rf_kl_VisitResultID', [4, 14])
|
||||
->where('rf_kl_VisitResultID', '<>', 0)
|
||||
->where('rf_MedicalHistoryID', '<>', 0);
|
||||
|
||||
if ($branchId) {
|
||||
@@ -180,8 +187,12 @@ class MisMigrationPatient extends Model
|
||||
}
|
||||
|
||||
if ($dateRange) {
|
||||
$query->where('DateOut', '>=', $dateRange->startSql())
|
||||
->where('DateOut', '<=', $dateRange->endSql());
|
||||
$startDate = Carbon::parse($dateRange->startSql())->toDateString();
|
||||
$endDate = Carbon::parse($dateRange->endSql())->toDateString();
|
||||
$query->whereHas('medicalHistory', function ($mhQuery) use ($startDate, $endDate) {
|
||||
$mhQuery->whereDate('DateExtract', '>', $startDate)
|
||||
->whereDate('DateExtract', '<=', $endDate);
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
@@ -195,8 +206,12 @@ class MisMigrationPatient extends Model
|
||||
$query->where('rf_kl_VisitResultID', '<>', 0)
|
||||
->where('rf_MedicalHistoryID', '<>', 0)
|
||||
->when($dateRange, function($query) use ($dateRange) {
|
||||
return $query->where('DateOut', '>=', $dateRange->startSql())
|
||||
->where('DateOut', '<=', $dateRange->endSql());
|
||||
$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);
|
||||
});
|
||||
});
|
||||
|
||||
if ($branchId) {
|
||||
@@ -205,4 +220,9 @@ class MisMigrationPatient extends Model
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function medicalHistory()
|
||||
{
|
||||
return $this->belongsTo(MisMedicalHistory::class, 'rf_MedicalHistoryID', 'MedicalHistoryID');
|
||||
}
|
||||
}
|
||||
|
||||
17
app/Models/MisOperationPurpose.php
Normal file
17
app/Models/MisOperationPurpose.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MisOperationPurpose extends Model
|
||||
{
|
||||
protected $table = 'stt_operationpurpose';
|
||||
|
||||
protected $primaryKey = 'OperationPurposeID';
|
||||
|
||||
public function surgicalOperation()
|
||||
{
|
||||
return $this->belongsTo(MisSurgicalOperation::class, 'rf_SurgicalOperationID', 'SurgicalOperationID');
|
||||
}
|
||||
}
|
||||
17
app/Models/MisReanimation.php
Normal file
17
app/Models/MisReanimation.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MisReanimation extends Model
|
||||
{
|
||||
protected $table = 'stt_reanimation';
|
||||
|
||||
protected $primaryKey = 'ReanimationID';
|
||||
|
||||
public function migrationPatient()
|
||||
{
|
||||
return $this->belongsTo(MisMigrationPatient::class, 'rf_MigrationPatientID', 'MigrationPatientID');
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MisSurgicalOperation extends Model
|
||||
{
|
||||
private const COMPLETED_OPERATION_STATUS_ID = 3;
|
||||
|
||||
protected $table = 'stt_surgicaloperation';
|
||||
protected $primaryKey = 'SurgicalOperationID';
|
||||
|
||||
@@ -18,4 +20,16 @@ class MisSurgicalOperation extends Model
|
||||
{
|
||||
return $this->belongsTo(MisMedicalHistory::class, 'rf_MedicalHistoryID', 'MedicalHistoryID');
|
||||
}
|
||||
|
||||
public function operationPurpose()
|
||||
{
|
||||
return $this->hasOne(MisOperationPurpose::class, 'rf_SurgicalOperationID', 'SurgicalOperationID');
|
||||
}
|
||||
|
||||
public function scopeCompleted($query)
|
||||
{
|
||||
return $query->whereHas('operationPurpose', function ($purposeQuery) {
|
||||
$purposeQuery->where('rf_OperationStatusID', self::COMPLETED_OPERATION_STATUS_ID);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ class ObservationPatient extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'rf_medicalhistory_id',
|
||||
'rf_department_patient_id',
|
||||
'rf_mkab_id',
|
||||
'rf_department_id',
|
||||
'rf_report_id',
|
||||
@@ -21,4 +22,9 @@ class ObservationPatient extends Model
|
||||
{
|
||||
return $this->belongsTo(MisMedicalHistory::class, 'rf_medicalhistory_id', 'MedicalHistoryID');
|
||||
}
|
||||
|
||||
public function departmentPatient()
|
||||
{
|
||||
return $this->belongsTo(DepartmentPatient::class, 'rf_department_patient_id', 'department_patient_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,13 @@ class Report extends Model
|
||||
'sent_at',
|
||||
'rf_department_id',
|
||||
'rf_user_id',
|
||||
'rf_lpudoctor_id'
|
||||
'rf_lpudoctor_id',
|
||||
'period_type',
|
||||
'period_start',
|
||||
'period_end',
|
||||
'report_month',
|
||||
'report_year',
|
||||
'status',
|
||||
];
|
||||
|
||||
public function metrikaResults(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
|
||||
Reference in New Issue
Block a user