diff --git a/app/Http/Controllers/Api/NurseController.php b/app/Http/Controllers/Api/NurseController.php
index 23d4cdf..9cfb750 100644
--- a/app/Http/Controllers/Api/NurseController.php
+++ b/app/Http/Controllers/Api/NurseController.php
@@ -8,6 +8,8 @@ use App\Models\MedicalHistoryCorrection;
use App\Models\MedicalHistoryNurse;
use App\Models\MigrationPatient;
use App\Models\MigrationPatientCorrection;
+use App\Models\MigrationPatientNurse;
+use App\Models\MisStationarBranch;
use App\Models\UnifiedMedicalHistory;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@@ -35,6 +37,10 @@ class NurseController extends Controller
public function storePatient(Request $request)
{
+ $user = auth()->user();
+ $department = auth()->user()->department;
+ $misUserId = $user->rf_lpudoctor_id;
+
$data = $request->validate([
'source_type' => 'nullable',
'medical_card_number' => 'nullable',
@@ -51,12 +57,38 @@ class NurseController extends Controller
'comment' => 'nullable',
]);
- $data['user_id'] = auth()->user()->id;
+ $data['user_id'] = $user->id;
- $result = MedicalHistoryNurse::create($data);
+ $branch = 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
+ ];
+
+ DB::beginTransaction();
+
+ $historyNurse = MedicalHistoryNurse::create($data);
+ $migrationData['medical_history_id'] = $historyNurse->id;
+ $migrationNurse = MigrationPatientNurse::create($migrationData);
+ $historyNurse->update([
+ 'latest_migration_id' => $migrationNurse->id
+ ]);
+
+ if ($historyNurse && $migrationNurse) {
+ DB::commit();
+ } else {
+ DB::rollBack();
+ }
return response()->json([
- 'data' => $result,
+ 'data' => $historyNurse,
], 201);
}
diff --git a/app/Models/MedicalHistoryNurse.php b/app/Models/MedicalHistoryNurse.php
index 615be32..7733e2f 100644
--- a/app/Models/MedicalHistoryNurse.php
+++ b/app/Models/MedicalHistoryNurse.php
@@ -21,6 +21,7 @@ class MedicalHistoryNurse extends Model
'user_id',
'mis_user_id',
'comment',
+ 'latest_migration_id'
];
public function user()
diff --git a/database/migrations/2026_05_05_203152_add_latest_migration_id_column_in_medical_history_nurses_table.php b/database/migrations/2026_05_05_203152_add_latest_migration_id_column_in_medical_history_nurses_table.php
new file mode 100644
index 0000000..d463578
--- /dev/null
+++ b/database/migrations/2026_05_05_203152_add_latest_migration_id_column_in_medical_history_nurses_table.php
@@ -0,0 +1,28 @@
+bigInteger('latest_migration_id')->nullable();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('medical_history_nurses', function (Blueprint $table) {
+ $table->dropColumn('latest_migration_id');
+ });
+ }
+};
diff --git a/resources/js/Pages/Nurse/Components/AddMedicalHistoryModal.vue b/resources/js/Pages/Nurse/Components/AddMedicalHistoryModal.vue
index 1b3d689..0db3c5b 100644
--- a/resources/js/Pages/Nurse/Components/AddMedicalHistoryModal.vue
+++ b/resources/js/Pages/Nurse/Components/AddMedicalHistoryModal.vue
@@ -20,7 +20,7 @@ const form = ref({
urgency_id: 1,
visit_result_id: 0,
birth_date: null,
- recipient_date: new Date(),
+ recipient_date: format(new Date(), 'yyyy-MM-dd HH:mm:ss'),
death_date: null,
extract_date: null
})
@@ -34,7 +34,7 @@ const resetForm = () => {
urgency_id: 1,
visit_result_id: 0,
birth_date: null,
- recipient_date: new Date(),
+ recipient_date: format(new Date(), 'yyyy-MM-dd HH:mm:ss'),
death_date: null,
extract_date: null
}
@@ -133,6 +133,8 @@ const submit = () => {
buttonLoading.value = false
}
})
+ }).catch((e) => {
+ buttonLoading.value = false
})
}
@@ -217,16 +219,16 @@ watch(() => currentStep.value, (val) => {
-
+
-
+
-
+
-
+