Добавлена возможность сохранения добавленного пациента

Исправлена инкрементация идентификаторов
This commit is contained in:
brusnitsyn
2026-05-05 21:03:14 +09:00
parent 717641e4bb
commit fe2264dfce
4 changed files with 72 additions and 9 deletions

View File

@@ -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);
}