diff --git a/app/Http/Controllers/Api/NurseController.php b/app/Http/Controllers/Api/NurseController.php index ee516fa..af60a59 100644 --- a/app/Http/Controllers/Api/NurseController.php +++ b/app/Http/Controllers/Api/NurseController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; +use App\Models\Department; use App\Models\MedicalHistory; use App\Models\MedicalHistoryCorrection; use App\Models\MedicalHistoryNurse; @@ -10,6 +11,7 @@ use App\Models\MigrationPatient; use App\Models\MigrationPatientCorrection; use App\Models\MigrationPatientNurse; use App\Models\MisMKSB; +use App\Models\MisMKSBMigration; use App\Models\MisStationarBranch; use App\Models\ReportNurse; use App\Models\ReportNurseMigrationPatient; @@ -55,8 +57,14 @@ class NurseController extends Controller public function storePatient(Request $request) { $user = auth()->user(); - $department = auth()->user()->department; - $misUserId = $user->rf_lpudoctor_id; + $misUserId = $request->query('userId') ? (int) $request->query('userId') : null; + $departmentId = $request->query('departmentId') ? (int) $request->query('departmentId') : null; + $sourceType = $request->query('sourceType', 'manual'); + + $departmentCacheKey = 'app:department:' . $departmentId; + $department = Cache::remember($departmentCacheKey, 21600, function () use ($departmentId) { + return Department::find($departmentId); + }); $data = $request->validate([ 'source_type' => 'nullable', @@ -72,22 +80,49 @@ class NurseController extends Controller 'visit_result_id' => 'required', 'mis_user_id' => 'nullable', 'comment' => 'nullable', + 'mis_id' => 'nullable' ]); + $data['mis_user_id'] = $misUserId; $data['user_id'] = $user->id; - $branch = MisStationarBranch::where('rf_DepartmentID', $department->rf_mis_department_id) - ->first(); + $branchCacheKey = 'app:department:' . $departmentId . ':branch'; + $branch = Cache::remember($branchCacheKey, 21600, function () use ($department) { + return MisStationarBranch::where('rf_DepartmentID', $department->rf_mis_department_id) + ->first(); + }); - $migrationData = [ - 'ingoing_date' => $data['recipient_date'], - 'out_date' => $data['extract_date'], - 'department_id' => $department->rf_mis_department_id, - 'stationar_branch_id' => $branch->StationarBranchID, - 'visit_result_id' => $data['visit_result_id'], - 'user_id' => $data['user_id'], - 'mis_user_id' => $misUserId - ]; + if ($sourceType === 'mis') { + $migrationMisQuery = MisMKSBMigration::query(); + $cacheKey = "mis:migration:patient:" . $data['mis_id'] . ':branch:' . $branch->StationarBranchID; + $migration = Cache::remember($cacheKey, 300, function () use ($migrationMisQuery, $data, $branch) { + return $migrationMisQuery->select(MisMKSBMigration::workColumns()) + ->where('rf_MedicalHistoryID', $data['mis_id']) + ->where('rf_StationarBranchID', $branch->StationarBranchID) + ->orderBy('DateIngoing', 'desc') + ->first()->toArray(); + }); + $migrationData = [ + 'ingoing_date' => $data['recipient_date'], + 'out_date' => $data['extract_date'], + 'department_id' => $department->rf_mis_department_id, + 'stationar_branch_id' => $branch->StationarBranchID, + 'visit_result_id' => $data['visit_result_id'], + 'user_id' => $data['user_id'], + 'mis_user_id' => $misUserId, + 'mis_id' => $migration['id'] + ]; + } else { + $migrationData = [ + 'ingoing_date' => $data['recipient_date'], + 'out_date' => $data['extract_date'], + 'department_id' => $department->rf_mis_department_id, + 'stationar_branch_id' => $branch->StationarBranchID, + 'visit_result_id' => $data['visit_result_id'], + 'user_id' => $data['user_id'], + 'mis_user_id' => $misUserId + ]; + } DB::beginTransaction(); diff --git a/app/Http/Controllers/Web/NurseReportController.php b/app/Http/Controllers/Web/NurseReportController.php index 40fb5f7..e12ccde 100644 --- a/app/Http/Controllers/Web/NurseReportController.php +++ b/app/Http/Controllers/Web/NurseReportController.php @@ -32,7 +32,7 @@ class NurseReportController extends Controller { $user = Auth::user(); $selectedUserId = $request->query('userId') ? (int) $request->query('userId') : null; - $departmentId = $request->query('departmentId', $user->department->department_id); + $departmentId = $request->query('departmentId') ? (int) $request->query('departmentId') : null; $department = Department::where('department_id', $departmentId)->firstOrFail(); $dateRange = $this->dateRangeService->getDateRangeFromRequest($request, $user); @@ -45,26 +45,6 @@ class NurseReportController extends Controller $hasReport = $existsReport && $isPastPeriod; -// if ($hasReport) { -// $inDepartmentHistories = $this->nurseMedicalHistoryService->getDepartmentHistories($dateRange, $department->rf_mis_department_id); -// $recipientHistories = $this->nurseMedicalHistoryService->getRecipientHistories($dateRange, $department->rf_mis_department_id); -// $dischargedHistories = $this->nurseMedicalHistoryService->getDischargedHistories($dateRange, $department->rf_mis_department_id); -// $deceasedHistories = $this->nurseMedicalHistoryService->getDeceasedHistories($dateRange, $department->rf_mis_department_id); -// $transferredHistories = $this->nurseMedicalHistoryService->getTransferredHistories($dateRange, $department->rf_mis_department_id); -// } else if ($this->dateRangeService->isPastPeriod($dateRange)) { -// $inDepartmentHistories = collect([]); -// $recipientHistories = collect([]); -// $dischargedHistories = collect([]); -// $deceasedHistories = collect([]); -// $transferredHistories = collect([]); -// } else { -// $inDepartmentHistories = $this->unifiedMedicalHistoryService->getDepartmentHistories($dateRange, $department->rf_mis_department_id); -// $recipientHistories = $this->unifiedMedicalHistoryService->getRecipientHistories($dateRange, $department->rf_mis_department_id); -// $dischargedHistories = $this->unifiedMedicalHistoryService->getDischargedHistories($dateRange, $department->rf_mis_department_id); -// $deceasedHistories = $this->unifiedMedicalHistoryService->getDeceasedHistories($dateRange, $department->rf_mis_department_id); -// $transferredHistories = $this->unifiedMedicalHistoryService->getTransferredHistories($dateRange, $department->rf_mis_department_id); -// } - $data = $this->unifiedMedicalHistoryService->getGroupedHistories($dateRange, $department->rf_mis_department_id); $currentReport = ReportNurse::where('rf_department_id', $departmentId) @@ -82,7 +62,7 @@ class NurseReportController extends Controller 'canEditPastReport' => $user->currentRoleCan('nurse.report.edit.past'), 'department' => $department, 'selectedUserId' => $selectedUserId, - 'selectedDepartmentId' => (int) $departmentId, + 'selectedDepartmentId' => $departmentId, 'dates' => [ $dateRange->startDate->getTimestampMs(), $dateRange->endDate->getTimestampMs(), diff --git a/app/Models/MedicalHistoryNurse.php b/app/Models/MedicalHistoryNurse.php index 7733e2f..76b7fc3 100644 --- a/app/Models/MedicalHistoryNurse.php +++ b/app/Models/MedicalHistoryNurse.php @@ -21,7 +21,8 @@ class MedicalHistoryNurse extends Model 'user_id', 'mis_user_id', 'comment', - 'latest_migration_id' + 'latest_migration_id', + 'mis_id' ]; public function user() diff --git a/app/Models/MigrationPatientNurse.php b/app/Models/MigrationPatientNurse.php index b70f5b7..30f8276 100644 --- a/app/Models/MigrationPatientNurse.php +++ b/app/Models/MigrationPatientNurse.php @@ -22,6 +22,7 @@ class MigrationPatientNurse extends Model 'user_id', 'mis_user_id', 'comment', + 'mis_id' ]; protected $casts = [ diff --git a/app/Models/MisMKSBMigration.php b/app/Models/MisMKSBMigration.php new file mode 100644 index 0000000..e9ff633 --- /dev/null +++ b/app/Models/MisMKSBMigration.php @@ -0,0 +1,36 @@ + 'int', + 'ingoing_date' => 'datetime:Y-m-d H:i:s', + 'out_date' => 'datetime:Y-m-d H:i:s', + 'diagnosis_id' => 'int', + 'interrupted_event_id' => 'int', + 'stationar_branch_id' => 'int', + 'visit_result_id' => 'int', + 'hospital_result_id' => 'int', + ]; + + public static function workColumns() { + return [ + 'MigrationPatientID as id', 'rf_MedicalHistoryID as medical_history_id', 'DateIngoing as ingoing_date', + 'DateOut as out_date', 'rf_DiagnosID as diagnosis_id', 'rf_InterruptEventID as interrupted_event_id', + 'rf_StationarBranchID as stationar_branch_id', 'rf_kl_VisitResultID as visit_result_id', + 'rf_kl_StatCureResultID as hospital_result_id' + ]; + } +} diff --git a/database/migrations/2026_06_03_105639_add_mis_id_column_in_medical_history_nurses_table.php b/database/migrations/2026_06_03_105639_add_mis_id_column_in_medical_history_nurses_table.php new file mode 100644 index 0000000..b653e39 --- /dev/null +++ b/database/migrations/2026_06_03_105639_add_mis_id_column_in_medical_history_nurses_table.php @@ -0,0 +1,28 @@ +bigInteger('mis_id')->unsigned()->index()->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('medical_history_nurses', function (Blueprint $table) { + $table->dropColumn('mis_id'); + }); + } +}; diff --git a/database/migrations/2026_06_03_105639_add_mis_id_column_in_migration_patient_nurses_table.php b/database/migrations/2026_06_03_105639_add_mis_id_column_in_migration_patient_nurses_table.php new file mode 100644 index 0000000..6f63e99 --- /dev/null +++ b/database/migrations/2026_06_03_105639_add_mis_id_column_in_migration_patient_nurses_table.php @@ -0,0 +1,28 @@ +bigInteger('mis_id')->unsigned()->index()->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('migration_patient_nurses', function (Blueprint $table) { + $table->dropColumn('mis_id'); + }); + } +}; diff --git a/resources/js/Pages/Nurse/Components/AddMedicalHistoryModal.vue b/resources/js/Pages/Nurse/Components/AddMedicalHistoryModal.vue index 8e571ff..ba3ee7e 100644 --- a/resources/js/Pages/Nurse/Components/AddMedicalHistoryModal.vue +++ b/resources/js/Pages/Nurse/Components/AddMedicalHistoryModal.vue @@ -4,7 +4,7 @@ import {computed, ref, watch} from "vue"; import AppRadio from "../../../Components/AppRadio.vue"; import {useDebounceFn} from "@vueuse/core"; import {format} from "date-fns"; -import {router} from "@inertiajs/vue3"; +import {router, usePage} from "@inertiajs/vue3"; import AppPanel from "../../../Components/AppPanel.vue" const show = defineModel('show', { default: false }) @@ -23,7 +23,8 @@ const form = ref({ birth_date: null, recipient_date: format(new Date(), 'yyyy-MM-dd HH:mm:ss'), death_date: null, - extract_date: null + extract_date: null, + mis_id: null }) const resetForm = () => { @@ -37,7 +38,8 @@ const resetForm = () => { birth_date: null, recipient_date: format(new Date(), 'yyyy-MM-dd HH:mm:ss'), death_date: null, - extract_date: null + extract_date: null, + mis_id: null } } @@ -116,7 +118,9 @@ const next = () => { const submit = () => { buttonLoading.value = true - axios.post('/api/nurse/patients', { + const departmentId = usePage().props.selectedDepartmentId + const userId = usePage().props.selectedUserId + axios.post(`/api/nurse/patients?departmentId=${departmentId}&userId=${userId}`, { ...form.value }).then(res => { router.reload({ @@ -216,7 +220,7 @@ const onAfterLeave = () => { -