Изменения в основном report

This commit is contained in:
brusnitsyn
2026-05-06 22:32:11 +09:00
parent c5da85763c
commit 723ccee8d3
56 changed files with 1911 additions and 3814 deletions

View File

@@ -3,7 +3,9 @@
namespace App\Data;
use App\Models\DepartmentPatient;
use App\Models\MedicalHistory;
use App\Models\MedicalHistorySnapshot;
use App\Models\MigrationPatient;
use App\Models\MisMedicalHistory;
use App\Models\MisMigrationPatient;
use Carbon\Carbon;
@@ -87,6 +89,51 @@ class UnifiedPatientData
);
}
public static function fromMedicalHistory(
MedicalHistory $patient,
bool $isRecipientToday = false,
?DepartmentPatient $linkedManualPatient = null,
?string $comment = null
): self {
$birthDate = $patient->birth_date?->format('Y-m-d');
$manualId = $linkedManualPatient?->department_patient_id;
$historyOriginalId = (int) ($patient->original_id ?? $patient->id);
$migration = $patient->relationLoaded('migrations')
? $patient->migrations->first()
: null;
if (! $migration && $patient->relationLoaded('latestMigration')) {
$migration = $patient->latestMigration;
}
$operations = self::extractOperations($patient->relationLoaded('operations') ? $patient->operations : collect());
return new self(
id: $manualId ? "manual:{$manualId}" : "mis:{$historyOriginalId}",
patientUid: "mis:{$historyOriginalId}",
sourceType: $manualId ? 'manual' : 'mis',
departmentPatientId: $manualId,
medicalHistoryId: $historyOriginalId,
fullname: $linkedManualPatient?->full_name ?: $patient->full_name,
birthDate: $linkedManualPatient?->birth_date?->format('Y-m-d') ?? $birthDate,
age: $patient->birth_date?->age ?? $linkedManualPatient?->birth_date?->age,
mkb: [
'ds' => $linkedManualPatient?->diagnosis_code ?: $migration?->diagnosis_code,
'name' => $linkedManualPatient?->diagnosis_name ?: $migration?->diagnosis_name,
],
operations: $operations,
patientKind: $linkedManualPatient?->patient_kind ?: self::resolvePatientKind($patient->urgency_id),
admittedAt: $linkedManualPatient?->admitted_at?->toIso8601String() ?? $patient->recipient_date?->toIso8601String(),
outcomeType: $patient->outcome_type ?? $linkedManualPatient?->outcome_type,
outcomeDate: $patient->outcome_date ?? $linkedManualPatient?->outcome_at?->toIso8601String(),
comment: $comment,
reanimationIsComplete: isset($patient->reanimation_is_complete) ? (bool) $patient->reanimation_is_complete : null,
isRecipientToday: $isRecipientToday,
isManual: (bool) $linkedManualPatient,
canManageManual: (bool) $linkedManualPatient,
);
}
public static function fromMisMigrationPatient(
MisMigrationPatient $migration,
bool $isRecipientToday = false,
@@ -133,6 +180,48 @@ class UnifiedPatientData
);
}
public static function fromMigrationPatient(
MigrationPatient $migration,
bool $isRecipientToday = false,
?DepartmentPatient $linkedManualPatient = null,
?string $comment = null
): self {
$medicalHistory = $migration->medicalHistory;
$birthDate = $medicalHistory?->birth_date?->format('Y-m-d');
$manualId = $linkedManualPatient?->department_patient_id;
$historyOriginalId = (int) ($medicalHistory?->original_id ?? $medicalHistory?->id ?? 0);
$operations = self::extractOperations(
$medicalHistory && $medicalHistory->relationLoaded('operations')
? $medicalHistory->operations
: collect()
);
return new self(
id: $manualId ? "manual:{$manualId}" : "mis:{$historyOriginalId}",
patientUid: "mis:{$historyOriginalId}",
sourceType: $manualId ? 'manual' : 'mis',
departmentPatientId: $manualId,
medicalHistoryId: $historyOriginalId,
fullname: $linkedManualPatient?->full_name ?: $medicalHistory?->full_name ?: 'Пациент без имени',
birthDate: $linkedManualPatient?->birth_date?->format('Y-m-d') ?? $birthDate,
age: $medicalHistory?->birth_date?->age ?? $linkedManualPatient?->birth_date?->age,
mkb: [
'ds' => $linkedManualPatient?->diagnosis_code ?: $migration->diagnosis_code,
'name' => $linkedManualPatient?->diagnosis_name ?: $migration->diagnosis_name,
],
operations: $operations,
patientKind: $linkedManualPatient?->patient_kind ?: self::resolvePatientKind($medicalHistory?->urgency_id),
admittedAt: $linkedManualPatient?->admitted_at?->toIso8601String() ?? $medicalHistory?->recipient_date?->toIso8601String(),
outcomeType: $migration->outcome_type ?? $linkedManualPatient?->outcome_type,
outcomeDate: $migration->outcome_date ?? $linkedManualPatient?->outcome_at?->toIso8601String(),
comment: $comment,
reanimationIsComplete: isset($medicalHistory->reanimation_is_complete) ? (bool) $medicalHistory->reanimation_is_complete : null,
isRecipientToday: $isRecipientToday,
isManual: (bool) $linkedManualPatient,
canManageManual: (bool) $linkedManualPatient,
);
}
public static function fromDepartmentPatient(
DepartmentPatient $patient,
bool $isRecipientToday = false,
@@ -235,6 +324,25 @@ class UnifiedPatientData
};
}
private static function extractOperations(Collection $operations): array
{
return $operations->map(function ($operation) {
$code = $operation->service_medical_code
?? $operation->serviceMedical?->ServiceMedicalCode
?? $operation->serviceMedical?->ServiceMedicalID
?? null;
$name = $operation->service_medical_name
?? $operation->serviceMedical?->ServiceMedicalName
?? null;
return [
'code' => $code,
'name' => $name,
];
})->values()->all();
}
private static function normalizeDateTime($value): ?string
{
if (! $value) {