|
|
@@ -29,23 +29,25 @@ class ConveniosMedicosImportService
|
|
|
$labRows = [];
|
|
|
|
|
|
foreach ($rows as $row) {
|
|
|
- $col0 = $this->cell($row[0] ?? '');
|
|
|
- $col1 = $this->cell($row[1] ?? '');
|
|
|
- $col2 = $this->cell($row[2] ?? '');
|
|
|
+ $cells = collect($row)
|
|
|
+ ->map(fn ($value) => $this->cell($value))
|
|
|
+ ->values()
|
|
|
+ ->all();
|
|
|
|
|
|
- if ($col0 === '' && $col1 === '' && $col2 === '') {
|
|
|
+ $filled = array_values(array_filter($cells, fn ($value) => $value !== ''));
|
|
|
+
|
|
|
+ if (empty($filled)) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- $upper0 = mb_strtoupper($col0);
|
|
|
- $upper1 = mb_strtoupper($col1);
|
|
|
+ $upperFilled = array_map(fn ($value) => mb_strtoupper($value), $filled);
|
|
|
|
|
|
- if ($upper0 === 'ESPECIALIDADE') {
|
|
|
+ if ($upperFilled[0] === 'ESPECIALIDADE') {
|
|
|
$mode = self::MODE_CONSULTAS;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if (str_starts_with($upper0, 'LABORAT') && $upper1 === 'TELEFONE') {
|
|
|
+ if (str_starts_with($upperFilled[0], 'LABORAT') && in_array('TELEFONE', $upperFilled, true)) {
|
|
|
$mode = self::MODE_LABORATORIO;
|
|
|
continue;
|
|
|
}
|
|
|
@@ -55,12 +57,12 @@ class ConveniosMedicosImportService
|
|
|
}
|
|
|
|
|
|
if ($mode === self::MODE_CONSULTAS) {
|
|
|
- $specialty = $col0;
|
|
|
- $clinicName = $col1;
|
|
|
- $doctor = $col2;
|
|
|
- $phone = $this->cell($row[3] ?? '');
|
|
|
- $address = $this->cell($row[4] ?? '');
|
|
|
- $priceRaw = $this->cell($row[5] ?? '');
|
|
|
+ $specialty = $cells[0] ?? '';
|
|
|
+ $clinicName = $cells[1] ?? '';
|
|
|
+ $doctor = $cells[2] ?? '';
|
|
|
+ $phone = $cells[3] ?? '';
|
|
|
+ $address = $cells[4] ?? '';
|
|
|
+ $priceRaw = $cells[5] ?? '';
|
|
|
|
|
|
if ($clinicName === '' || $specialty === '') {
|
|
|
continue;
|
|
|
@@ -90,14 +92,15 @@ class ConveniosMedicosImportService
|
|
|
'price' => $this->parsePrice($priceRaw),
|
|
|
];
|
|
|
} elseif ($mode === self::MODE_LABORATORIO) {
|
|
|
- if ($col0 === '') {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ $rest = array_slice($filled, 1);
|
|
|
+
|
|
|
+ $phones = array_values(array_filter($rest, fn ($value) => $this->looksLikePhone($value)));
|
|
|
+ $others = array_values(array_filter($rest, fn ($value) => !$this->looksLikePhone($value)));
|
|
|
|
|
|
$labRows[] = [
|
|
|
- 'name' => $col0,
|
|
|
- 'phone' => $col1 ?: null,
|
|
|
- 'address' => $col2 ?: null,
|
|
|
+ 'name' => $filled[0],
|
|
|
+ 'phone' => $phones[0] ?? null,
|
|
|
+ 'address' => $others[0] ?? null,
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
@@ -218,4 +221,13 @@ class ConveniosMedicosImportService
|
|
|
|
|
|
return $stats;
|
|
|
}
|
|
|
+
|
|
|
+ private function looksLikePhone(string $value): bool
|
|
|
+ {
|
|
|
+ if (preg_match('/\p{L}/u', $value)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return strlen(preg_replace('/\D/', '', $value)) >= 8;
|
|
|
+ }
|
|
|
}
|