diff --git a/app/Http/Controllers/Api/ReportController.php b/app/Http/Controllers/Api/ReportController.php index bb4b121..7371c22 100644 --- a/app/Http/Controllers/Api/ReportController.php +++ b/app/Http/Controllers/Api/ReportController.php @@ -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(); } diff --git a/app/Http/Resources/Mis/FormattedPatientResource.php b/app/Http/Resources/Mis/FormattedPatientResource.php index 58ffa8d..402ebaf 100644 --- a/app/Http/Resources/Mis/FormattedPatientResource.php +++ b/app/Http/Resources/Mis/FormattedPatientResource.php @@ -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'), diff --git a/app/Models/MisDiagnos.php b/app/Models/MisDiagnos.php new file mode 100644 index 0000000..2c307fb --- /dev/null +++ b/app/Models/MisDiagnos.php @@ -0,0 +1,22 @@ +hasOne(MisMKB::class, 'MKBID', 'rf_MKBID'); + } +} diff --git a/app/Models/MisMKB.php b/app/Models/MisMKB.php new file mode 100644 index 0000000..36e2bef --- /dev/null +++ b/app/Models/MisMKB.php @@ -0,0 +1,16 @@ + '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]); + } + }); + } } diff --git a/app/Models/MisMigrationPatient.php b/app/Models/MisMigrationPatient.php new file mode 100644 index 0000000..fc96b93 --- /dev/null +++ b/app/Models/MisMigrationPatient.php @@ -0,0 +1,26 @@ +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'); + } +} diff --git a/app/Models/MisStationarBranch.php b/app/Models/MisStationarBranch.php new file mode 100644 index 0000000..42cd632 --- /dev/null +++ b/app/Models/MisStationarBranch.php @@ -0,0 +1,11 @@ + 'Гинекологическое отделение', 'name_short' => 'Гинекологическое', - 'rf_department_type' => 1 + 'rf_department_type' => 1, + 'rf_mis_department_id' => 1054 ]); Department::create([ 'name_full' => 'Нейрохирургическое отделение', 'name_short' => 'Нейрохирургическое', - 'rf_department_type' => 1 + 'rf_department_type' => 1, + 'rf_mis_department_id' => 1049 ]); Department::create([ 'name_full' => 'Отделение термических поражений', 'name_short' => 'Термических поражений', - 'rf_department_type' => 1 + 'rf_department_type' => 1, + 'rf_mis_department_id' => 1059 ]); Department::create([ 'name_full' => 'Отоларингологическое отделение', 'name_short' => 'Отоларингологическое', - 'rf_department_type' => 1 + 'rf_department_type' => 1, + 'rf_mis_department_id' => 1061 ]); Department::create([ 'name_full' => 'Проктологическое отделение', 'name_short' => 'Проктологическое', - 'rf_department_type' => 1 + 'rf_department_type' => 1, + 'rf_mis_department_id' => 1065 ]); Department::create([ 'name_full' => 'Отделение сосудистой хирургии', 'name_short' => 'Сосудистой хирургии', - 'rf_department_type' => 1 + 'rf_department_type' => 1, + 'rf_mis_department_id' => 1050 ]); Department::create([ 'name_full' => 'Отделение торакальной хирургии', 'name_short' => 'Торакальной хирургии', - 'rf_department_type' => 1 + 'rf_department_type' => 1, + 'rf_mis_department_id' => 1069 ]); Department::create([ 'name_full' => 'Травматологическое отделение', 'name_short' => 'Травматологическое', - 'rf_department_type' => 1 + 'rf_department_type' => 1, + 'rf_mis_department_id' => 1070 ]); Department::create([ 'name_full' => 'Урологическое отделение', 'name_short' => 'Урологическое', - 'rf_department_type' => 1 + 'rf_department_type' => 1, + 'rf_mis_department_id' => 1071 ]); Department::create([ 'name_full' => 'Хирургическое отделение', 'name_short' => 'Хирургическое', - 'rf_department_type' => 1 + 'rf_department_type' => 1, + 'rf_mis_department_id' => 1072 ]); Department::create([ 'name_full' => 'Отделение ЧЛХ', 'name_short' => 'ЧЛХ', - 'rf_department_type' => 1 + 'rf_department_type' => 1, + 'rf_mis_department_id' => 1073 ]); DepartmentMetrikaDefault::create([ diff --git a/package-lock.json b/package-lock.json index c44ce52..cd160c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2017,7 +2017,6 @@ "integrity": "sha512-9nF4PdUle+5ta4W5SyZdLCCmFd37uVimSjg1evcTqKJCyvCEEj12WKzOSBNak6r4im4J4iYXKH1OWpUV5LBYFg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@emotion/hash": "~0.8.0", "csstype": "~3.0.5" @@ -2093,7 +2092,6 @@ "resolved": "https://registry.npmjs.org/d3-selection/-/d3-selection-3.0.0.tgz", "integrity": "sha512-fmTRWbNMmsmWq6xJV8D19U/gw/bwrHfNXxrIN+HfZgnzqTHp9jOmKMhsTUjXOJnZOdZY9Q28y4yebKzqDKlxlQ==", "license": "ISC", - "peer": true, "engines": { "node": ">=12" } @@ -2147,7 +2145,6 @@ "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-4.1.0.tgz", "integrity": "sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==", "license": "MIT", - "peer": true, "funding": { "type": "github", "url": "https://github.com/sponsors/kossnocorp" @@ -3570,7 +3567,6 @@ "resolved": "https://registry.npmjs.org/vite/-/vite-7.3.0.tgz", "integrity": "sha512-dZwN5L1VlUBewiP6H9s2+B3e3Jg96D0vzN+Ry73sOefebhYr9f94wwkMNN/9ouoU8pV1BqA1d1zGk8928cx0rg==", "license": "MIT", - "peer": true, "dependencies": { "esbuild": "^0.27.0", "fdir": "^6.5.0", @@ -3928,7 +3924,6 @@ "resolved": "https://registry.npmjs.org/vue/-/vue-3.5.26.tgz", "integrity": "sha512-SJ/NTccVyAoNUJmkM9KUqPcYlY+u8OVL1X5EW9RIs3ch5H2uERxyyIUI4MRxVCSOiEcupX9xNGde1tL9ZKpimA==", "license": "MIT", - "peer": true, "dependencies": { "@vue/compiler-dom": "3.5.26", "@vue/compiler-sfc": "3.5.26", diff --git a/resources/js/Pages/Report/Components/ReportSectionItem.vue b/resources/js/Pages/Report/Components/ReportSectionItem.vue index 0d56af7..b779a55 100644 --- a/resources/js/Pages/Report/Components/ReportSectionItem.vue +++ b/resources/js/Pages/Report/Components/ReportSectionItem.vue @@ -1,9 +1,10 @@