Добавлено сохранение правок поверх МИС
Добавлено версионирование сохраненных правок Добавлено сохранение отчета мед. сестры
This commit is contained in:
@@ -4,14 +4,16 @@ namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\MedicalHistory;
|
||||
use App\Models\MedicalHistoryCorrection;
|
||||
use App\Models\MedicalHistoryNurse;
|
||||
use App\Models\UnifiedMedicalHistory;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class NurseController extends Controller
|
||||
{
|
||||
public function getPatient($id, Request $request)
|
||||
{
|
||||
return MedicalHistory::where('id', $id)->first();
|
||||
return UnifiedMedicalHistory::where('id', $id)->first();
|
||||
}
|
||||
|
||||
public function searchPatients(Request $request)
|
||||
@@ -54,4 +56,31 @@ class NurseController extends Controller
|
||||
'data' => $result,
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function storeCorrection($id, Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'medical_card_number' => 'nullable',
|
||||
'full_name' => 'nullable',
|
||||
'birth_date' => 'nullable',
|
||||
'recipient_date' => 'nullable',
|
||||
'extract_date' => 'nullable',
|
||||
'death_date' => 'nullable',
|
||||
'male' => 'nullable',
|
||||
'urgency_id' => 'nullable',
|
||||
'hospital_result_id' => 'nullable',
|
||||
'visit_result_id' => 'nullable',
|
||||
'mis_user_id' => 'nullable',
|
||||
'comment' => 'nullable',
|
||||
]);
|
||||
|
||||
$data['medical_history_id'] = $id;
|
||||
$data['user_id'] = auth()->user()->id;
|
||||
|
||||
$result = MedicalHistoryCorrection::create($data);
|
||||
|
||||
return response()->json([
|
||||
'data' => $result,
|
||||
], 201);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace App\Http\Controllers\Web;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Department;
|
||||
use App\Services\DateRangeService;
|
||||
use App\Services\MedicalHistoryService;
|
||||
use App\Services\UnifiedMedicalHistoryService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Inertia\Inertia;
|
||||
@@ -14,7 +14,7 @@ class NurseReportController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected DateRangeService $dateRangeService,
|
||||
protected MedicalHistoryService $medicalHistoryService
|
||||
protected UnifiedMedicalHistoryService $unifiedMedicalHistoryService
|
||||
)
|
||||
{}
|
||||
|
||||
@@ -30,11 +30,11 @@ class NurseReportController extends Controller
|
||||
$department = Department::where('department_id', $departmentId)->firstOrFail();
|
||||
$dateRange = $this->dateRangeService->getDateRangeFromRequest($request, $user);
|
||||
|
||||
$inDepartmentHistories = $this->medicalHistoryService->getDepartmentHistories($dateRange, $department->rf_mis_department_id);
|
||||
$recipientHistories = $this->medicalHistoryService->getRecipientHistories($dateRange, $department->rf_mis_department_id);
|
||||
$dischargedHistories = $this->medicalHistoryService->getDischargedHistories($dateRange, $department->rf_mis_department_id);
|
||||
$deceasedHistories = $this->medicalHistoryService->getDeceasedHistories($dateRange, $department->rf_mis_department_id);
|
||||
$transferredHistories = $this->medicalHistoryService->getTransferredHistories($dateRange, $department->rf_mis_department_id);
|
||||
$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);
|
||||
|
||||
return Inertia::render('Nurse/Report/Index', [
|
||||
'inDepartmentHistories' => $inDepartmentHistories,
|
||||
|
||||
@@ -18,6 +18,9 @@ class MedicalHistoryCorrection extends Model
|
||||
'urgency_id',
|
||||
'hospital_result_id',
|
||||
'visit_result_id',
|
||||
'user_id',
|
||||
'mis_user_id',
|
||||
'comment',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
|
||||
@@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UnifiedMedicalHistory extends MaterializedViewModel
|
||||
{
|
||||
protected $table = 'v_unified_medical_history';
|
||||
protected $table = 'v_unified_medical_history_nurse';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $casts = [
|
||||
@@ -16,4 +16,31 @@ class UnifiedMedicalHistory extends MaterializedViewModel
|
||||
'death_date' => 'datetime',
|
||||
'male' => 'boolean',
|
||||
];
|
||||
|
||||
public function migrations(): \Illuminate\Database\Eloquent\Relations\HasMany|MedicalHistory
|
||||
{
|
||||
return $this->hasMany(MigrationPatient::class, 'medical_history_id', 'id');
|
||||
}
|
||||
|
||||
public function operations(): \Illuminate\Database\Eloquent\Relations\HasMany|MedicalHistory
|
||||
{
|
||||
return $this->hasMany(SurgicalOperation::class, 'medical_history_id', 'id');
|
||||
}
|
||||
|
||||
public function latestMigration()
|
||||
{
|
||||
return $this->hasOne(MigrationPatient::class, 'medical_history_id', 'id')
|
||||
->latest('ingoing_date');
|
||||
}
|
||||
|
||||
public function operationsInDepartment($query, $departmentId)
|
||||
{
|
||||
return $this->operations()->where('department_id', $departmentId);
|
||||
}
|
||||
|
||||
// Скоупы
|
||||
public function scopeUrgency($query, $typeId) // 1 = Экстренно, 2 = Планово
|
||||
{
|
||||
return $query->where('urgency_id', $typeId);
|
||||
}
|
||||
}
|
||||
|
||||
118
app/Services/UnifiedMedicalHistoryService.php
Normal file
118
app/Services/UnifiedMedicalHistoryService.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\MedicalHistory;
|
||||
use App\Models\MigrationPatient;
|
||||
use App\Models\UnifiedMedicalHistory;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class UnifiedMedicalHistoryService
|
||||
{
|
||||
public function getHistories(DateRange $dateRange, int $departmentId)
|
||||
{
|
||||
$query = UnifiedMedicalHistory::query();
|
||||
|
||||
$query->where('recipient_date', '>=', $dateRange->startSql())
|
||||
->where('recipient_date', '<', $dateRange->endSql())
|
||||
// 1. Оставляем только тех пациентов, у которых БЫЛО движение в этом отделении
|
||||
->whereHas('latestMigration', fn($q) => $q->where('department_id', $departmentId))
|
||||
|
||||
// 2. Загружаем ТОЛЬКО последнее движение в этом отделении (не все миграции)
|
||||
->with(['latestMigration' => fn($q) => $q->where('department_id', $departmentId)]);
|
||||
|
||||
$result = $query->paginate();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getUrgencyHistory(DateRange $dateRange, int $departmentId, int $urgencyId)
|
||||
{
|
||||
$query = UnifiedMedicalHistory::query();
|
||||
|
||||
$query->where('recipient_date', '>=', $dateRange->startSql())
|
||||
->where('recipient_date', '<', $dateRange->endSql())
|
||||
->urgency($urgencyId)
|
||||
->whereHas('migrations', function ($m) use ($departmentId) {
|
||||
$m->where('department_id', $departmentId);
|
||||
})
|
||||
->with([
|
||||
'migrations' => fn ($m) => $m->where('department_id', $departmentId),
|
||||
'migrations.operations'
|
||||
]);
|
||||
|
||||
$result = $query->paginate();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getDepartmentHistories(DateRange $dateRange, int $departmentId)
|
||||
{
|
||||
return UnifiedMedicalHistory::query()
|
||||
->whereHas('migrations', function ($q) use ($departmentId, $dateRange) {
|
||||
$q->department($departmentId)->current($dateRange);
|
||||
})
|
||||
->with(['latestMigration' => function ($q) use ($departmentId, $dateRange) {
|
||||
$q->department($departmentId)->current($dateRange); // подгружаем только отфильтрованные движения
|
||||
}])
|
||||
->get()
|
||||
// Сортировка по дате поступления в отделение (поле дочерней таблицы)
|
||||
->sortByDesc(fn ($mh) => $mh->latestMigration->ingoing_date ?? $mh->recipient_date)
|
||||
->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить карты поступившие сегодня
|
||||
* @param DateRange $dateRange
|
||||
* @param int $departmentId
|
||||
*/
|
||||
public function getRecipientHistories(DateRange $dateRange, int $departmentId)
|
||||
{
|
||||
$now = Carbon::now();
|
||||
|
||||
return UnifiedMedicalHistory::query()
|
||||
->whereHas('migrations', function ($q) use ($departmentId, $dateRange) {
|
||||
$q->department($departmentId)->admitted($dateRange->startSql(), $dateRange->endSql());
|
||||
})
|
||||
->with(['latestMigration' => function ($q) use ($departmentId) {
|
||||
$q->department($departmentId);
|
||||
}])
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getDischargedHistories(DateRange $dateRange, int $departmentId)
|
||||
{
|
||||
return UnifiedMedicalHistory::query()
|
||||
->whereHas('migrations', function ($q) use ($departmentId, $dateRange) {
|
||||
$q->department($departmentId)->discharged($dateRange->startSql(), $dateRange->endSql());
|
||||
})
|
||||
->with(['latestMigration' => function ($q) use ($departmentId) {
|
||||
$q->department($departmentId);
|
||||
}])
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getDeceasedHistories(DateRange $dateRange, int $departmentId)
|
||||
{
|
||||
return UnifiedMedicalHistory::query()
|
||||
->whereHas('migrations', function ($q) use ($departmentId, $dateRange) {
|
||||
$q->department($departmentId)->deceased($dateRange->startSql(), $dateRange->endSql());
|
||||
})
|
||||
->with(['latestMigration' => function ($q) use ($departmentId) {
|
||||
$q->department($departmentId);
|
||||
}])
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getTransferredHistories(DateRange $dateRange, int $departmentId)
|
||||
{
|
||||
return UnifiedMedicalHistory::query()
|
||||
->whereHas('migrations', function ($q) use ($departmentId, $dateRange) {
|
||||
$q->department($departmentId)->transferred($dateRange->startSql(), $dateRange->endSql());
|
||||
})
|
||||
->with(['latestMigration' => function ($q) use ($departmentId) {
|
||||
$q->department($departmentId);
|
||||
}])
|
||||
->get();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user