* добавил исход спец контингенту
* оптимизация обновления при редактировании спец контингента * добавил поддержку заключительных диагнозов * изменил определение законченной операции * добавил поддержку исхода операции * добавил определение отмены для операции через назначение * работа над диапазонами календарей, подсчет статистики * добавил статусы отчетов и подкорректировал привязку спец контингента к отчету * добавил новые сервисы для будущего кеширования * частичное разделение логики подсчета пациентов
This commit is contained in:
101
app/Services/RecipientPatientService.php
Normal file
101
app/Services/RecipientPatientService.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\MisMigrationPatient;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RecipientPatientService
|
||||
{
|
||||
public function __construct(
|
||||
protected CurrentPatientService $currentPatientService
|
||||
)
|
||||
{ }
|
||||
|
||||
// Получить IDs поступивших
|
||||
public function getRecipientMedicalHistoryIds(
|
||||
?string $type,
|
||||
bool $isHeadOrAdmin,
|
||||
int $branchId,
|
||||
DateRange $dateRange
|
||||
): array {
|
||||
return $this->buildRecipientQuery($type, $isHeadOrAdmin, $branchId, $dateRange, false)
|
||||
->distinct()
|
||||
->pluck('rf_MedicalHistoryID')
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Построить запрос для поступивших пациентов
|
||||
*/
|
||||
public function buildRecipientQuery(
|
||||
?string $type,
|
||||
bool $isHeadOrAdmin,
|
||||
int $branchId,
|
||||
DateRange $dateRange,
|
||||
bool $fillableAuto = false
|
||||
) {
|
||||
$startAt = $dateRange->start()->copy()->format('Y-m-d H:i:s');
|
||||
$endAt = $dateRange->end()->copy()->format('Y-m-d H:i:s');
|
||||
|
||||
if ($dateRange->isOneDay) {
|
||||
$startAt = $dateRange->startSql();
|
||||
$endAt = $dateRange->endSql();
|
||||
}
|
||||
|
||||
$query = DB::table('stt_medicalhistory as mh')
|
||||
->selectRaw('mh."MedicalHistoryID" as "rf_MedicalHistoryID"')
|
||||
->where('mh.MedicalHistoryID', '<>', 0);
|
||||
|
||||
$query->whereExists(function ($subQuery) use ($branchId, $startAt, $endAt) {
|
||||
$subQuery->select(DB::raw(1))
|
||||
->from('stt_migrationpatient as mp')
|
||||
->whereColumn('mp.rf_MedicalHistoryID', 'mh.MedicalHistoryID')
|
||||
->where('mp.rf_StationarBranchID', $branchId)
|
||||
->where('mp.DateIngoing', '>', $startAt)
|
||||
->where('mp.DateIngoing', '<=', $endAt);
|
||||
});
|
||||
|
||||
if ($type === 'plan') {
|
||||
$query->where('mh.rf_EmerSignID', 1);
|
||||
} elseif ($type === 'emergency') {
|
||||
$query->whereIn('mh.rf_EmerSignID', [2, 4]);
|
||||
}
|
||||
|
||||
return $query->distinct();
|
||||
}
|
||||
|
||||
// Получить IDs состоящих
|
||||
private function getCurrentMedicalHistoryIds(
|
||||
string $type,
|
||||
int $branchId,
|
||||
DateRange $dateRange,
|
||||
bool $fillableAuto,
|
||||
): array {
|
||||
return $this->currentPatientService->getCurrentMedicalHistoryIds($type, $branchId, $dateRange, $fillableAuto);
|
||||
}
|
||||
|
||||
public function resolvePlanOrEmergencyMedicalHistoryIds(
|
||||
?string $type,
|
||||
bool $isHeadOrAdmin,
|
||||
int $branchId,
|
||||
DateRange $dateRange,
|
||||
bool $includeCurrent,
|
||||
bool $fillableAuto
|
||||
): array {
|
||||
$recipientIds = $this->getRecipientMedicalHistoryIds(
|
||||
$type,
|
||||
$isHeadOrAdmin,
|
||||
$branchId,
|
||||
$dateRange
|
||||
);
|
||||
|
||||
if (!$includeCurrent) {
|
||||
return array_values(array_unique($recipientIds));
|
||||
}
|
||||
|
||||
$currentIds = $this->getCurrentMedicalHistoryIds($type, $branchId, $dateRange, $fillableAuto);
|
||||
|
||||
return array_values(array_unique(array_merge($recipientIds, $currentIds)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user