Работа над журналом для ст. мед сестер
This commit is contained in:
15
tests/Unit/DateRangeServiceTest.php
Normal file
15
tests/Unit/DateRangeServiceTest.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use App\Services\DateRangeService;
|
||||
|
||||
it('parses unix seconds and milliseconds as the same report date', function () {
|
||||
$service = app(DateRangeService::class);
|
||||
|
||||
$seconds = 1777215600;
|
||||
$milliseconds = $seconds * 1000;
|
||||
|
||||
expect($service->parseDate($seconds)->format('Y-m-d H:i:s'))
|
||||
->toBe('2026-04-27 00:00:00')
|
||||
->and($service->parseDate($milliseconds)->format('Y-m-d H:i:s'))
|
||||
->toBe('2026-04-27 00:00:00');
|
||||
});
|
||||
147
tests/Unit/Reports/ReportStatisticsReadServiceTest.php
Normal file
147
tests/Unit/Reports/ReportStatisticsReadServiceTest.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
use App\Infrastructure\Reports\Services\CalculatedMetricsSynchronizer;
|
||||
use App\Infrastructure\Reports\Services\ReportReadContextResolver;
|
||||
use App\Infrastructure\Reports\Services\ReportStatisticsReadService;
|
||||
use App\Models\Department;
|
||||
use App\Models\User;
|
||||
use App\Services\DateRange;
|
||||
use App\Services\PatientService;
|
||||
use App\Services\SnapshotService;
|
||||
use App\Services\UnifiedPatientService;
|
||||
use Carbon\Carbon;
|
||||
|
||||
it('returns empty statistics when department branch cannot be resolved', function () {
|
||||
$department = (new Department())->forceFill([
|
||||
'department_id' => 100,
|
||||
'rf_mis_department_id' => 200,
|
||||
]);
|
||||
$user = \Mockery::mock(User::class);
|
||||
$dateRange = reportStatisticsDateRange();
|
||||
|
||||
$contextResolver = \Mockery::mock(ReportReadContextResolver::class);
|
||||
$contextResolver->shouldReceive('resolveBranchId')
|
||||
->once()
|
||||
->with($department)
|
||||
->andReturn(null);
|
||||
|
||||
$service = new ReportStatisticsReadService(
|
||||
unifiedPatientService: \Mockery::mock(UnifiedPatientService::class),
|
||||
patientService: \Mockery::mock(PatientService::class),
|
||||
snapshotService: \Mockery::mock(SnapshotService::class),
|
||||
contextResolver: $contextResolver,
|
||||
calculatedMetricsSynchronizer: \Mockery::mock(CalculatedMetricsSynchronizer::class),
|
||||
);
|
||||
|
||||
expect($service->getReportStatistics($department, $user, $dateRange))->toMatchArray([
|
||||
'recipientCount' => 0,
|
||||
'extractCount' => 0,
|
||||
'currentCount' => 0,
|
||||
'deadCount' => 0,
|
||||
'surgicalCount' => [0, 0],
|
||||
'recipientIds' => [],
|
||||
'percentDead' => 0,
|
||||
'beds' => 0,
|
||||
]);
|
||||
});
|
||||
|
||||
it('reads live report statistics from replica when snapshots are not active', function () {
|
||||
$department = (new Department())->forceFill([
|
||||
'department_id' => 100,
|
||||
'rf_mis_department_id' => 200,
|
||||
]);
|
||||
$department->setRelation('metrikaDefault', collect([
|
||||
(object) ['rf_metrika_item_id' => 1, 'value' => 42],
|
||||
]));
|
||||
|
||||
$user = \Mockery::mock(User::class);
|
||||
$dateRange = reportStatisticsDateRange();
|
||||
|
||||
$contextResolver = \Mockery::mock(ReportReadContextResolver::class);
|
||||
$contextResolver->shouldReceive('resolveBranchId')
|
||||
->once()
|
||||
->with($department)
|
||||
->andReturn(10);
|
||||
$contextResolver->shouldReceive('shouldUseSnapshots')
|
||||
->once()
|
||||
->with($department, $dateRange)
|
||||
->andReturn(false);
|
||||
|
||||
$unifiedPatientService = \Mockery::mock(UnifiedPatientService::class);
|
||||
$unifiedPatientService->shouldReceive('getLivePatientCountByStatus')
|
||||
->once()
|
||||
->with($department, $user, 'plan', $dateRange, 10, true)
|
||||
->andReturn(7);
|
||||
$unifiedPatientService->shouldReceive('getLivePatientCountByStatus')
|
||||
->once()
|
||||
->with($department, $user, 'emergency', $dateRange, 10, true)
|
||||
->andReturn(5);
|
||||
$unifiedPatientService->shouldReceive('getLivePatientCountByStatus')
|
||||
->once()
|
||||
->with($department, $user, 'current', $dateRange, 10)
|
||||
->andReturn(30);
|
||||
$unifiedPatientService->shouldReceive('getLivePatientCountByStatus')
|
||||
->once()
|
||||
->with($department, $user, 'recipient', $dateRange, 10)
|
||||
->andReturn(4);
|
||||
$unifiedPatientService->shouldReceive('getLivePatientCountByStatus')
|
||||
->once()
|
||||
->with($department, $user, 'outcome', $dateRange, 10)
|
||||
->andReturn(8);
|
||||
$unifiedPatientService->shouldReceive('getLivePatientCountByStatus')
|
||||
->once()
|
||||
->with($department, $user, 'outcome-deceased', $dateRange, 10)
|
||||
->andReturn(2);
|
||||
$unifiedPatientService->shouldReceive('getRecipientIdsForReport')
|
||||
->once()
|
||||
->with($department, $user, $dateRange, 10)
|
||||
->andReturn([11, 12]);
|
||||
|
||||
$patientService = \Mockery::mock(PatientService::class);
|
||||
$patientService->shouldReceive('getSurgicalPatients')
|
||||
->once()
|
||||
->with('emergency', 10, $dateRange, true)
|
||||
->andReturn(3);
|
||||
$patientService->shouldReceive('getSurgicalPatients')
|
||||
->once()
|
||||
->with('plan', 10, $dateRange, true)
|
||||
->andReturn(6);
|
||||
|
||||
$calculatedMetricsSynchronizer = \Mockery::mock(CalculatedMetricsSynchronizer::class);
|
||||
$calculatedMetricsSynchronizer->shouldReceive('getManualSurgicalCounts')
|
||||
->once()
|
||||
->with($department, $dateRange)
|
||||
->andReturn([1, 2]);
|
||||
|
||||
$service = new ReportStatisticsReadService(
|
||||
unifiedPatientService: $unifiedPatientService,
|
||||
patientService: $patientService,
|
||||
snapshotService: \Mockery::mock(SnapshotService::class),
|
||||
contextResolver: $contextResolver,
|
||||
calculatedMetricsSynchronizer: $calculatedMetricsSynchronizer,
|
||||
);
|
||||
|
||||
expect($service->getReportStatistics($department, $user, $dateRange))->toMatchArray([
|
||||
'recipientCount' => 4,
|
||||
'extractCount' => 8,
|
||||
'currentCount' => 30,
|
||||
'deadCount' => 2,
|
||||
'surgicalCount' => [4, 8],
|
||||
'recipientIds' => [11, 12],
|
||||
'planCount' => 7,
|
||||
'emergencyCount' => 5,
|
||||
'percentDead' => 25.0,
|
||||
'beds' => 42,
|
||||
]);
|
||||
});
|
||||
|
||||
function reportStatisticsDateRange(): DateRange
|
||||
{
|
||||
return new DateRange(
|
||||
Carbon::parse('2026-04-08 06:00:00'),
|
||||
Carbon::parse('2026-04-09 06:00:00'),
|
||||
'2026-04-08 06:00:00',
|
||||
'2026-04-09 06:00:00',
|
||||
true,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user