Изменения в основном report
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Infrastructure\Reports\Sources\MisPatientSource;
|
||||
use App\Infrastructure\Reports\Sources\SpecialPatientSource;
|
||||
use App\Models\Department;
|
||||
use App\Models\DepartmentPatient;
|
||||
use App\Models\MedicalHistory;
|
||||
use App\Models\MisMedicalHistory;
|
||||
use App\Models\ObservationPatient;
|
||||
use App\Models\Report;
|
||||
@@ -192,13 +193,15 @@ class UnifiedPatientService
|
||||
|
||||
public function linkManualPatientToMis(DepartmentPatient $patient, int $medicalHistoryId): DepartmentPatient
|
||||
{
|
||||
$misPatient = MisMedicalHistory::where('MedicalHistoryID', $medicalHistoryId)->firstOrFail();
|
||||
$history = MedicalHistory::query()
|
||||
->where('original_id', $medicalHistoryId)
|
||||
->firstOrFail();
|
||||
|
||||
$patient->update([
|
||||
'rf_medicalhistory_id' => $misPatient->MedicalHistoryID,
|
||||
'rf_medicalhistory_id' => $history->original_id,
|
||||
'linked_to_mis_at' => now(),
|
||||
'full_name' => $patient->full_name ?: trim("{$misPatient->FAMILY} {$misPatient->Name} {$misPatient->OT}"),
|
||||
'birth_date' => $patient->birth_date ?: $misPatient->BD,
|
||||
'full_name' => $patient->full_name ?: $history->full_name,
|
||||
'birth_date' => $patient->birth_date ?: $history->birth_date,
|
||||
]);
|
||||
|
||||
return $patient->fresh();
|
||||
@@ -206,20 +209,13 @@ class UnifiedPatientService
|
||||
|
||||
public function searchMisPatients(Department $department, string $query): Collection
|
||||
{
|
||||
$branchId = \App\Models\MisStationarBranch::where('rf_DepartmentID', $department->rf_mis_department_id)
|
||||
->value('StationarBranchID');
|
||||
|
||||
return MisMedicalHistory::query()
|
||||
->whereHas('migrations', fn ($builder) => $builder->where('rf_StationarBranchID', $branchId))
|
||||
->where(function ($builder) use ($query) {
|
||||
$builder->where('FAMILY', 'like', "%{$query}%")
|
||||
->orWhere('Name', 'like', "%{$query}%")
|
||||
->orWhere('OT', 'like', "%{$query}%");
|
||||
})
|
||||
->with(['outcomeMigration.mainDiagnosis.mkb'])
|
||||
return MedicalHistory::query()
|
||||
->whereLike('full_name', "%{$query}%")
|
||||
->whereHas('migrations', fn ($builder) => $builder->department($department->rf_mis_department_id))
|
||||
->with(['latestMigration', 'operations'])
|
||||
->limit(20)
|
||||
->get()
|
||||
->map(fn (MisMedicalHistory $patient) => UnifiedPatientData::fromMisMedicalHistory($patient));
|
||||
->map(fn (MedicalHistory $patient) => UnifiedPatientData::fromMedicalHistory($patient));
|
||||
}
|
||||
|
||||
public function getObservationPatients(
|
||||
@@ -232,10 +228,11 @@ class UnifiedPatientService
|
||||
$misIds = $observationPatients->pluck('rf_medicalhistory_id')->filter()->unique()->values();
|
||||
$manualIds = $observationPatients->pluck('rf_department_patient_id')->filter()->unique()->values();
|
||||
|
||||
$misPatients = MisMedicalHistory::whereIn('MedicalHistoryID', $misIds)
|
||||
->with(['outcomeMigration.mainDiagnosis.mkb'])
|
||||
$misPatients = MedicalHistory::query()
|
||||
->whereIn('original_id', $misIds)
|
||||
->with(['latestMigration', 'operations'])
|
||||
->get()
|
||||
->keyBy('MedicalHistoryID');
|
||||
->keyBy('original_id');
|
||||
|
||||
$manualPatients = DepartmentPatient::whereIn('department_patient_id', $manualIds)->get()->keyBy('department_patient_id');
|
||||
|
||||
@@ -258,7 +255,7 @@ class UnifiedPatientService
|
||||
return null;
|
||||
}
|
||||
|
||||
return UnifiedPatientData::fromMisMedicalHistory(
|
||||
return UnifiedPatientData::fromMedicalHistory(
|
||||
$misPatients[$observation->rf_medicalhistory_id],
|
||||
false,
|
||||
null,
|
||||
@@ -290,14 +287,24 @@ class UnifiedPatientService
|
||||
$linkedManualPatients = $this->specialPatientSource->getLinkedManualPatientsForPeriod($department, $dateRange);
|
||||
|
||||
$mergedMisPatients = $misPatients->map(function ($patient) use ($linkedManualPatients) {
|
||||
$linkedManual = $linkedManualPatients->get($patient->MedicalHistoryID);
|
||||
$medicalHistoryId = $patient instanceof MedicalHistory
|
||||
? ($patient->original_id ?? $patient->id)
|
||||
: $patient->MedicalHistoryID;
|
||||
$linkedManual = $linkedManualPatients->get($medicalHistoryId);
|
||||
|
||||
return UnifiedPatientData::fromMisMedicalHistory(
|
||||
$patient,
|
||||
(bool) ($patient->is_recipient_today ?? false),
|
||||
$linkedManual,
|
||||
$this->resolveObservationComment($patient->MedicalHistoryID, null)
|
||||
);
|
||||
return $patient instanceof MedicalHistory
|
||||
? UnifiedPatientData::fromMedicalHistory(
|
||||
$patient,
|
||||
(bool) ($patient->is_recipient_today ?? false),
|
||||
$linkedManual,
|
||||
$this->resolveObservationComment($medicalHistoryId, null)
|
||||
)
|
||||
: UnifiedPatientData::fromMisMedicalHistory(
|
||||
$patient,
|
||||
(bool) ($patient->is_recipient_today ?? false),
|
||||
$linkedManual,
|
||||
$this->resolveObservationComment($medicalHistoryId, null)
|
||||
);
|
||||
});
|
||||
|
||||
$manualDtos = $this->specialPatientSource->getDtos($department, $status, $dateRange, self::SPECIAL_SOURCE_TYPES, $forSnapshots);
|
||||
|
||||
Reference in New Issue
Block a user