Изменил привязку id при добавлении пациента

Изменил приоритет вывода карты после репликации
This commit is contained in:
brusnitsyn
2026-06-03 12:42:17 +09:00
parent c857bd9f72
commit e758769035
8 changed files with 154 additions and 41 deletions

View File

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