Files
onboard/app/Services/PatientService.php

152 lines
4.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Services;
use App\Infrastructure\Reports\Sources\MisClinicalDataSource;
use App\Models\MisMedicalHistory;
class PatientService
{
public function __construct(
protected OutcomePatientService $outcomePatientService,
protected RecipientPatientService $recipientPatientService,
protected CurrentPatientService $currentPatientService,
?MisClinicalDataSource $misClinicalDataSource = null,
) {
$this->misClinicalDataSource = $misClinicalDataSource ?? app(MisClinicalDataSource::class);
}
protected MisClinicalDataSource $misClinicalDataSource;
/**
* Получить плановых или экстренных пациентов из МИС,
* при необходимости объединяя их с уже текущими в отделении.
*/
public function getPlanOrEmergencyPatients(
?string $type,
bool $isHeadOrAdmin,
int $branchId,
DateRange $dateRange,
bool $countOnly = false,
bool $onlyIds = false,
bool $includeCurrent = false,
bool $fillableAuto = false
) {
return $this->misClinicalDataSource->getPlanOrEmergencyPatients(
$type,
$isHeadOrAdmin,
$branchId,
$dateRange,
$countOnly,
$onlyIds,
$includeCurrent,
$fillableAuto
);
}
/**
* Получить всех MIS-пациентов в отделении:
* поступившие за период плюс уже текущие в отделении.
*/
public function getAllPatientsInDepartment(
bool $isHeadOrAdmin,
int $branchId,
DateRange $dateRange,
bool $countOnly = false,
bool $onlyIds = false,
bool $fillableAuto = false
) {
return $this->misClinicalDataSource->getAllPatientsInDepartment(
$isHeadOrAdmin,
$branchId,
$dateRange,
$countOnly,
$onlyIds,
$fillableAuto
);
}
/**
* Получить пациентов под наблюдением
*/
public function getObservationPatients(int $departmentId, bool $onlyIds = false)
{
$query = MisMedicalHistory::whereHas('observationPatient', function ($q) use ($departmentId) {
$q->where('rf_department_id', $departmentId);
});
if (! $onlyIds) {
$query->with(['observationPatient' => function ($query) use ($departmentId) {
$query->where('rf_department_id', $departmentId)
->select(['rf_medicalhistory_id', 'observation_patient_id', 'comment']);
}])
->orderBy('DateRecipient', 'DESC');
}
if ($onlyIds) {
$patients = $query->pluck('MedicalHistoryID');
} else {
$query->with([
'outcomeMigration.mainDiagnosis.mkb',
]);
$patients = $query->get();
}
return $patients->map(function ($patient) {
$patient->comment = $patient->observationPatient
->pluck('comment')
->filter()
->implode('; ');
return $patient;
});
}
/**
* Получить выбывших MIS-пациентов по типу исхода.
*/
public function getOutcomePatients(
int $branchId,
DateRange $dateRange,
string $outcomeType = 'all',
bool $onlyIds = false
) {
return $this->outcomePatientService->getOutcomePatients($branchId, $dateRange, $outcomeType, $onlyIds);
}
/**
* Получить пациентов с записями в реанимации по отделению.
*/
public function getReanimationPatients(
int $branchId,
DateRange $dateRange,
bool $onlyIds = false
) {
return $this->misClinicalDataSource->getReanimationPatients($branchId, $dateRange, $onlyIds);
}
/**
* Получить операции пациентов по типу срочности.
*/
public function getSurgicalPatients(
string $type,
int $branchId,
DateRange $dateRange,
bool $countOnly = false
) {
return $this->misClinicalDataSource->getSurgicalPatients($type, $branchId, $dateRange, $countOnly);
}
/**
* Получить количество пациентов по типу с учетом уже находящихся в отделении.
*/
public function getPatientsCountWithCurrent(
?string $type,
bool $isHeadOrAdmin,
int $branchId,
DateRange $dateRange
): int {
return $this->misClinicalDataSource->getPatientsCountWithCurrent($type, $isHeadOrAdmin, $branchId, $dateRange);
}
}