Форматирование
This commit is contained in:
@@ -6,7 +6,6 @@ use App\Models\MisMedicalHistory;
|
||||
use App\Models\MisMigrationPatient;
|
||||
use App\Models\MisReanimation;
|
||||
use App\Models\MisSurgicalOperation;
|
||||
use App\Models\ObservationPatient;
|
||||
|
||||
class PatientService
|
||||
{
|
||||
@@ -14,8 +13,7 @@ class PatientService
|
||||
protected OutcomePatientService $outcomePatientService,
|
||||
protected RecipientPatientService $recipientPatientService,
|
||||
protected CurrentPatientService $currentPatientService
|
||||
)
|
||||
{ }
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Получить плановых или экстренных пациентов
|
||||
@@ -63,6 +61,7 @@ class PatientService
|
||||
return $res->get()
|
||||
->map(function ($patient) use ($recipientIds) {
|
||||
$patient->is_recipient_today = in_array($patient->MedicalHistoryID, $recipientIds, true);
|
||||
|
||||
return $patient;
|
||||
});
|
||||
|
||||
@@ -94,7 +93,10 @@ class PatientService
|
||||
$allIds = array_unique(array_merge($recipientIds, $currentIds));
|
||||
|
||||
if (empty($allIds)) {
|
||||
if ($countOnly) return 0;
|
||||
if ($countOnly) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return collect();
|
||||
}
|
||||
|
||||
@@ -179,10 +181,11 @@ class PatientService
|
||||
])
|
||||
->orderBy('DateRecipient', 'DESC');
|
||||
|
||||
return $res->get()
|
||||
->map(function ($patient) use ($recipientIds) {
|
||||
$patient->is_recipient_today = in_array($patient->MedicalHistoryID, $recipientIds);
|
||||
return $patient;
|
||||
return $res->get()
|
||||
->map(function ($patient) use ($recipientIds) {
|
||||
$patient->is_recipient_today = in_array($patient->MedicalHistoryID, $recipientIds);
|
||||
|
||||
return $patient;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -195,7 +198,7 @@ class PatientService
|
||||
$q->where('rf_department_id', $departmentId);
|
||||
});
|
||||
|
||||
if (!$onlyIds) {
|
||||
if (! $onlyIds) {
|
||||
$query->with(['observationPatient' => function ($query) use ($departmentId) {
|
||||
$query->where('rf_department_id', $departmentId)
|
||||
->select(['rf_medicalhistory_id', 'observation_patient_id', 'comment']);
|
||||
@@ -203,8 +206,9 @@ class PatientService
|
||||
->orderBy('DateRecipient', 'DESC');
|
||||
}
|
||||
|
||||
if ($onlyIds) $patients = $query->pluck('MedicalHistoryID');
|
||||
else {
|
||||
if ($onlyIds) {
|
||||
$patients = $query->pluck('MedicalHistoryID');
|
||||
} else {
|
||||
$query->with([
|
||||
'outcomeMigration.mainDiagnosis.mkb',
|
||||
]);
|
||||
@@ -216,6 +220,7 @@ class PatientService
|
||||
->pluck('comment')
|
||||
->filter()
|
||||
->implode('; ');
|
||||
|
||||
return $patient;
|
||||
});
|
||||
}
|
||||
@@ -233,28 +238,58 @@ class PatientService
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить пациентов, находящихся в реанимации на конец периода
|
||||
* Получить пациентов с записями в реанимации по отделению
|
||||
*/
|
||||
public function getReanimationPatients(
|
||||
int $branchId,
|
||||
DateRange $dateRange,
|
||||
bool $onlyIds = false
|
||||
) {
|
||||
$medicalHistoryIds = MisReanimation::query()
|
||||
$currentIds = $this->getAllPatientsInDepartment(
|
||||
true,
|
||||
$branchId,
|
||||
$dateRange,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
)->all();
|
||||
|
||||
$outcomeIds = $this->getOutcomePatients(
|
||||
$branchId,
|
||||
$dateRange,
|
||||
'all',
|
||||
true
|
||||
)->all();
|
||||
|
||||
$reportCohortIds = array_values(array_unique(array_merge($currentIds, $outcomeIds)));
|
||||
|
||||
if (empty($reportCohortIds)) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$reanimationByMedicalHistory = MisReanimation::query()
|
||||
->join('stt_migrationpatient as mp', 'mp.MigrationPatientID', '=', 'stt_reanimation.rf_MigrationPatientID')
|
||||
->where('stt_reanimation.rf_StationarBranchID', $branchId)
|
||||
->where('mp.rf_StationarBranchID', $branchId)
|
||||
->where('mp.rf_MedicalHistoryID', '<>', 0)
|
||||
->where('stt_reanimation.DateIn', '<=', $dateRange->endSql())
|
||||
->where(function ($query) use ($dateRange) {
|
||||
$query->where('stt_reanimation.DateOut', '>=', $dateRange->endSql())
|
||||
->orWhereNull('stt_reanimation.DateOut')
|
||||
->orWhereDate('stt_reanimation.DateOut', '1900-01-01')
|
||||
->orWhereDate('stt_reanimation.DateOut', '2222-01-01');
|
||||
})
|
||||
->distinct()
|
||||
->pluck('mp.rf_MedicalHistoryID')
|
||||
->toArray();
|
||||
->whereIn('mp.rf_MedicalHistoryID', $reportCohortIds)
|
||||
->selectRaw('
|
||||
mp."rf_MedicalHistoryID" as medical_history_id,
|
||||
MAX(stt_reanimation."DateIn") as reanimation_date_in,
|
||||
BOOL_OR(COALESCE(stt_reanimation."isComplete", false)) as reanimation_is_complete
|
||||
')
|
||||
->groupBy('mp.rf_MedicalHistoryID')
|
||||
->get();
|
||||
|
||||
$medicalHistoryIds = $reanimationByMedicalHistory
|
||||
->pluck('medical_history_id')
|
||||
->map(fn ($id) => (int) $id)
|
||||
->values()
|
||||
->all();
|
||||
|
||||
$reanimationDateByMedicalHistory = $reanimationByMedicalHistory
|
||||
->pluck('reanimation_date_in', 'medical_history_id');
|
||||
$reanimationCompleteByMedicalHistory = $reanimationByMedicalHistory
|
||||
->pluck('reanimation_is_complete', 'medical_history_id');
|
||||
|
||||
if (empty($medicalHistoryIds)) {
|
||||
return collect();
|
||||
@@ -312,7 +347,16 @@ class PatientService
|
||||
},
|
||||
])
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->get();
|
||||
->get()
|
||||
->map(function ($patient) use ($reanimationDateByMedicalHistory, $reanimationCompleteByMedicalHistory) {
|
||||
$reanimationDateIn = $reanimationDateByMedicalHistory->get($patient->MedicalHistoryID);
|
||||
if ($reanimationDateIn) {
|
||||
$patient->DateRecipient = $reanimationDateIn;
|
||||
}
|
||||
$patient->reanimation_is_complete = (bool) $reanimationCompleteByMedicalHistory->get($patient->MedicalHistoryID, false);
|
||||
|
||||
return $patient;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -325,9 +369,9 @@ class PatientService
|
||||
bool $countOnly = false
|
||||
) {
|
||||
$query = MisSurgicalOperation::where('rf_StationarBranchID', $branchId)
|
||||
->completed()
|
||||
->where('Date', '>=', $dateRange->startSql())
|
||||
->where('Date', '<=', $dateRange->endSql());
|
||||
->completed()
|
||||
->where('Date', '>=', $dateRange->startSql())
|
||||
->where('Date', '<=', $dateRange->endSql());
|
||||
|
||||
if ($type === 'plan') {
|
||||
$query->where('rf_TypeSurgOperationInTimeID', 6);
|
||||
|
||||
Reference in New Issue
Block a user