Изменил привязку 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();

View File

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

View File

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

View File

@@ -22,6 +22,7 @@ class MigrationPatientNurse extends Model
'user_id',
'mis_user_id',
'comment',
'mis_id'
];
protected $casts = [

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
/**
* Стационарная карта больного
*/
class MisMKSBMigration extends MaterializedViewModel
{
protected $connection = 'mis';
protected $table = 'stt_MigrationPatient';
protected $primaryKey = 'MigrationPatientID';
protected $casts = [
'id' => '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'
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('medical_history_nurses', function (Blueprint $table) {
$table->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');
});
}
};

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('migration_patient_nurses', function (Blueprint $table) {
$table->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');
});
}
};

View File

@@ -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 = () => {
<AppPanel :loading="loadingChangeSelect" class="border-none!" no-padding>
<NGrid cols="2" x-gap="8">
<NFormItemGi v-if="form.patient_source === 'mis'" span="2" label="Поиск пациента">
<NSelect v-model:value="form.id"
<NSelect v-model:value="form.mis_id"
filterable
placeholder="Найти пациента по ФИО"
remote