95 lines
2.8 KiB
PHP
95 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Service\Client;
|
|
|
|
use App\Service\Client\Interfaces\InfoclinicaClientServiceInterface;
|
|
use App\Service\Client\AbstractHttpClientService;
|
|
use Symfony\Contracts\HttpClient\ResponseInterface;
|
|
use App\Dto\RegistrationDto;
|
|
use App\Dto\AnonymousReserveRequestDto;
|
|
|
|
final class InfoclinicaClientService extends AbstractHttpClientService implements InfoclinicaClientServiceInterface
|
|
{
|
|
public function __construct(
|
|
string $userAgent,
|
|
string $baseUrl
|
|
) {
|
|
parent::__construct($userAgent, $baseUrl);
|
|
}
|
|
|
|
private function normalizeSchedule(array $schedules): array
|
|
{
|
|
$nearestDate = [];
|
|
$schedule = [];
|
|
|
|
foreach ($schedules as $item) {
|
|
foreach ($item['workdates'] as $workdate) {
|
|
$dateKey = key($workdate);
|
|
|
|
foreach ($workdate[$dateKey] as $scheduleItem) {
|
|
$isFree = false;
|
|
|
|
foreach ($scheduleItem['intervals'] as $interval) {
|
|
if ($interval['isFree'] === true) {
|
|
if (empty($nearestDate[$scheduleItem['depnum']])) {
|
|
$nearestDate[$scheduleItem['depnum']] = $dateKey;
|
|
}
|
|
|
|
$isFree = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
$schedule[$scheduleItem['depnum']][$dateKey] = $scheduleItem;
|
|
$schedule[$scheduleItem['depnum']][$dateKey]['isFree'] = $isFree;
|
|
}
|
|
}
|
|
}
|
|
|
|
return [
|
|
'schedule' => $schedule,
|
|
'nearestDate' => $nearestDate
|
|
];
|
|
}
|
|
|
|
public function getSchedule(string $queryString): array
|
|
{
|
|
$httpResponse = $this->request('GET', '/api/reservation/intervals?' . $queryString);
|
|
$responseArray = $httpResponse->toArray();
|
|
|
|
if ($responseArray['data']) {
|
|
return $this->normalizeSchedule($responseArray['data']);
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
public function getFilialsList(): array
|
|
{
|
|
$httpResponse = $this->request('GET', '/filials/list');
|
|
return $httpResponse->toArray();
|
|
}
|
|
|
|
public function registration(RegistrationDto $dto): array
|
|
{
|
|
$httpResponse = $this->request('GET', '/api/reservation/intervals?' . $queryString);
|
|
$responseArray = $httpResponse->toArray();
|
|
|
|
if ($responseArray['data']) {
|
|
return $this->normalizeSchedule($responseArray['data']);
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
public function anonymousReserve(AnonymousReserveRequestDto $dto): array
|
|
{
|
|
$httpResponse = $this->request('POST', '/api/reservation/anonymous-reserve', [
|
|
'body' => json_encode($dto->toArray(), JSON_UNESCAPED_UNICODE)
|
|
]);
|
|
|
|
return $httpResponse->toArray();
|
|
}
|
|
|
|
}
|