Новые таблицы миса
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Http\Resources\Mis\FormattedPatientResource;
|
||||
use App\Models\MetrikaGroup;
|
||||
use App\Models\MetrikaResult;
|
||||
use App\Models\MisMedicalHistory;
|
||||
use App\Models\MisStationarBranch;
|
||||
use App\Models\ObservationPatient;
|
||||
use App\Models\Report;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -102,30 +103,51 @@ class ReportController extends Controller
|
||||
|
||||
$status = $data['status'];
|
||||
|
||||
$startDate = Carbon::now()->addDays(-1)->format('Y-m-d');
|
||||
$endDate = Carbon::now()->format('Y-m-d');
|
||||
|
||||
$model = new MisMedicalHistory();
|
||||
$misDepartmentId = $request->user()->department->rf_mis_department_id;
|
||||
$misStationarBranchId = MisStationarBranch::where('rf_DepartmentID', $misDepartmentId)->first()->StationarBranchID;
|
||||
if ($status === 'plan') {
|
||||
$patients = MisMedicalHistory::select(
|
||||
[
|
||||
...$model->getFillable(),
|
||||
DB::raw('ROW_NUMBER() OVER (ORDER BY "DateRecipient" DESC) as num')
|
||||
])
|
||||
->where('rf_EmerSignID', 1)
|
||||
->whereDate('DateRecipient', '>=', Carbon::now()->format('Y-m-d'))
|
||||
->plan()
|
||||
->inDepartment($misDepartmentId, $startDate, $endDate)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->get();
|
||||
->get()
|
||||
->map(function ($item, $index) {
|
||||
$item->num = $index + 1;
|
||||
return $item;
|
||||
});;
|
||||
} else if ($status === 'emergency') {
|
||||
$patients = MisMedicalHistory::select(
|
||||
[
|
||||
...$model->getFillable(),
|
||||
DB::raw('ROW_NUMBER() OVER (ORDER BY "DateRecipient" DESC) as num')
|
||||
])
|
||||
->where('rf_EmerSignID', 2)
|
||||
->whereDate('DateRecipient', '>=', Carbon::now()->format('Y-m-d'))
|
||||
->emergency()
|
||||
->inDepartment($misDepartmentId, $startDate, $endDate)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->limit(20)
|
||||
->get();
|
||||
->get()
|
||||
->map(function ($item, $index) {
|
||||
$item->num = $index + 1;
|
||||
return $item;
|
||||
});;
|
||||
} else if ($status === 'deceased') {
|
||||
|
||||
}
|
||||
|
||||
$patients->load(['migrations' => function ($query) use ($startDate, $endDate, $misStationarBranchId) {
|
||||
$query->whereHas('diagnosis', function ($query) {
|
||||
$query->where('rf_DiagnosTypeID', 3);
|
||||
})->with('diagnosis.mkb')
|
||||
->where('rf_StationarBranchID', $misStationarBranchId);
|
||||
}]);
|
||||
|
||||
return response()->json(FormattedPatientResource::collection($patients));
|
||||
}
|
||||
|
||||
@@ -137,17 +159,21 @@ class ReportController extends Controller
|
||||
|
||||
$status = $data['status'];
|
||||
|
||||
$startDate = Carbon::now()->addDays(-1)->format('Y-m-d');
|
||||
$endDate = Carbon::now()->format('Y-m-d');
|
||||
|
||||
$model = new MisMedicalHistory();
|
||||
$misDepartmentId = $request->user()->department->rf_mis_department_id;
|
||||
if ($status === 'plan') {
|
||||
$count = MisMedicalHistory::select($model->getFillable())
|
||||
->where('rf_EmerSignID', 1)
|
||||
->whereDate('DateRecipient', '>=', Carbon::now()->format('Y-m-d'))
|
||||
->plan()
|
||||
->inDepartment($misDepartmentId, $startDate, $endDate)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->count();
|
||||
} else if ($status === 'emergency') {
|
||||
$count = MisMedicalHistory::select($model->getFillable())
|
||||
->where('rf_EmerSignID', 2)
|
||||
->whereDate('DateRecipient', '>=', Carbon::now()->format('Y-m-d'))
|
||||
->emergency()
|
||||
->inDepartment($misDepartmentId, $startDate, $endDate)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->count();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,12 @@ class FormattedPatientResource extends JsonResource
|
||||
return [
|
||||
'id' => $this->MedicalHistoryID,
|
||||
'num' => $this->num,
|
||||
'mkb' => $this->whenLoaded('migrations', function () {
|
||||
return [
|
||||
'ds' => $this->migrations()->first()->diagnosis()->first()->mkb()->first()->DS ?? null,
|
||||
'name' => $this->migrations()->first()->diagnosis()->first()->mkb()->first()->NAME ?? null,
|
||||
];
|
||||
}),
|
||||
'fullname' => Str::ucwords(Str::lower("$this->FAMILY $this->Name $this->OT")),
|
||||
'age' => Carbon::parse($this->BD)->diff(Carbon::now())->format('%y'),
|
||||
'birth_date' => Carbon::parse($this->BD)->format('d.m.Y'),
|
||||
|
||||
22
app/Models/MisDiagnos.php
Normal file
22
app/Models/MisDiagnos.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MisDiagnos extends Model
|
||||
{
|
||||
protected $table = 'stt_diagnos';
|
||||
protected $primaryKey = 'DiagnosID';
|
||||
|
||||
protected $fillable = [
|
||||
'rf_MedicalHistoryID',
|
||||
'rf_MigrationPatient',
|
||||
'rf_MKBID',
|
||||
];
|
||||
|
||||
public function mkb()
|
||||
{
|
||||
return $this->hasOne(MisMKB::class, 'MKBID', 'rf_MKBID');
|
||||
}
|
||||
}
|
||||
16
app/Models/MisMKB.php
Normal file
16
app/Models/MisMKB.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MisMKB extends Model
|
||||
{
|
||||
protected $table = 'oms_mkb';
|
||||
protected $primaryKey = 'MKBID';
|
||||
|
||||
protected $fillable = [
|
||||
'DS',
|
||||
'NAME'
|
||||
];
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MisMedicalHistory extends Model
|
||||
{
|
||||
@@ -18,4 +19,60 @@ class MisMedicalHistory extends Model
|
||||
'BD',
|
||||
'Address'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'DateRecipient' => 'datetime'
|
||||
];
|
||||
|
||||
/*
|
||||
* Истории со срочностью - Плановая
|
||||
*/
|
||||
public function scopePlan()
|
||||
{
|
||||
return $this->where('rf_EmerSignID', 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Истории со срочностью - Экстренная
|
||||
*/
|
||||
public function scopeEmergency()
|
||||
{
|
||||
return $this->where('rf_EmerSignID', 2);
|
||||
}
|
||||
|
||||
/*
|
||||
* Движения истории
|
||||
*/
|
||||
public function migrations()
|
||||
{
|
||||
return $this->hasMany(MisMigrationPatient::class, 'rf_MedicalHistoryID', 'MedicalHistoryID');
|
||||
}
|
||||
|
||||
/*
|
||||
* Движение по StationarBranch
|
||||
*/
|
||||
public function scopeInStationarBranch($query, $stationarBranchID)
|
||||
{
|
||||
return $this->whereHas('migrations', function ($query) use ($stationarBranchID) {
|
||||
$query->where('rf_StationarBranchID', $stationarBranchID);
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Истории в отделении ($departmentId)
|
||||
*/
|
||||
public function scopeInDepartment($query, $departmentId, $startDate, $endDate)
|
||||
{
|
||||
return $query->whereExists(function ($q) use ($departmentId, $startDate, $endDate) {
|
||||
$q->select(DB::raw(1))
|
||||
->from('stt_migrationpatient as mp')
|
||||
->join('stt_stationarbranch as sb', 'sb.StationarBranchID', '=', 'mp.rf_StationarBranchID')
|
||||
->whereColumn('mp.rf_MedicalHistoryID', 'stt_medicalhistory.MedicalHistoryID')
|
||||
->where('sb.rf_DepartmentID', $departmentId);
|
||||
|
||||
if ($startDate && $endDate) {
|
||||
$q->whereBetween('mp.DateIngoing', [$startDate, $endDate]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
26
app/Models/MisMigrationPatient.php
Normal file
26
app/Models/MisMigrationPatient.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
11
app/Models/MisStationarBranch.php
Normal file
11
app/Models/MisStationarBranch.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MisStationarBranch extends Model
|
||||
{
|
||||
protected $table = 'stt_stationarbranch';
|
||||
protected $primaryKey = 'StationarBranchID';
|
||||
}
|
||||
Reference in New Issue
Block a user