410 lines
14 KiB
PHP
410 lines
14 KiB
PHP
<?php
|
||
|
||
namespace App\Enums\Ambulatorio;
|
||
|
||
use Illuminate\Support\Facades\DB;
|
||
|
||
final class LocalAnatomicoRegiao
|
||
{
|
||
private const chaveLocalSafecare = [
|
||
'head' => 1,
|
||
'forehead' => 1,
|
||
'nose' => 1,
|
||
'chin' => 1,
|
||
'right_cheek' => 1,
|
||
'left_cheek' => 1,
|
||
|
||
'neck' => 2,
|
||
|
||
'right_deltoid' => 3,
|
||
'left_deltoid' => 3,
|
||
'right_chest' => 3,
|
||
'left_chest' => 3,
|
||
'abdomen' => 3,
|
||
'right_abdomen' => 3,
|
||
'left_abdomen' => 3,
|
||
'sacral' => 3,
|
||
|
||
'back_body_right' => 4,
|
||
'back_body_left' => 4,
|
||
'trapezius_right' => 4,
|
||
'trapezius_left' => 4,
|
||
'glute_right' => 4,
|
||
'glute_left' => 4,
|
||
'popliteal_right' => 4,
|
||
'popliteal_left' => 4,
|
||
'calf_right' => 4,
|
||
'calf_left' => 4,
|
||
|
||
'right_arm' => 5,
|
||
'left_arm' => 5,
|
||
'right_forearm' => 5,
|
||
'left_forearm' => 5,
|
||
'right_hand' => 5,
|
||
'left_hand' => 5,
|
||
|
||
'pinky' => 6,
|
||
'ring' => 6,
|
||
'middle' => 6,
|
||
'index' => 6,
|
||
'thumb' => 6,
|
||
'palm' => 6,
|
||
'right_pinky' => 6,
|
||
'right_ring' => 6,
|
||
'right_middle' => 6,
|
||
'right_index' => 6,
|
||
'right_thumb' => 6,
|
||
'right_palm' => 6,
|
||
|
||
'right_thigh' => 7,
|
||
'left_thigh' => 7,
|
||
'right_knee' => 7,
|
||
'left_knee' => 7,
|
||
'right_tibial' => 7,
|
||
'left_tibial' => 7,
|
||
'right_shin' => 7,
|
||
'left_shin' => 7,
|
||
'right_foot' => 7,
|
||
'left_foot' => 7,
|
||
|
||
'big_toe' => 8,
|
||
'second_toe' => 8,
|
||
'middle_toe' => 8,
|
||
'fourth_toe' => 8,
|
||
'little_toe' => 8,
|
||
'sole' => 8,
|
||
'right_big_toe' => 8,
|
||
'right_second_toe' => 8,
|
||
'right_middle_toe' => 8,
|
||
'right_fourth_toe' => 8,
|
||
'right_little_toe' => 8,
|
||
'right_sole' => 8,
|
||
|
||
'medial_forefoot' => 9,
|
||
'central_forefoot' => 9,
|
||
'distal_forefoot' => 9,
|
||
'plantar_arch' => 9,
|
||
'central_midfoot' => 9,
|
||
'distal_midfoot' => 9,
|
||
'medial_hindfoot' => 9,
|
||
'central_hindfoot' => 9,
|
||
'distal_hindfoot' => 9,
|
||
|
||
'right_heel' => 10,
|
||
'left_heel' => 10,
|
||
'right_achilles_tendon' => 10,
|
||
'left_achilles_tendon' => 10,
|
||
|
||
'right_external_malleolus' => 11,
|
||
'left_external_malleolus' => 11,
|
||
'right_external_arch' => 11,
|
||
'left_external_arch' => 11,
|
||
'right_external_metatarsal' => 11,
|
||
'left_external_metatarsal' => 11,
|
||
|
||
'side_head' => 12,
|
||
'side_neck' => 12,
|
||
'side_abdomen' => 12,
|
||
'side_sacral' => 12,
|
||
'side_trochanter1' => 12,
|
||
'side_trochanter2' => 12,
|
||
'side_malleolus' => 12,
|
||
|
||
'side_right_deltoid' => 13,
|
||
'side_right_arm' => 13,
|
||
'side_right_forearm' => 13,
|
||
'side_right_hand' => 13,
|
||
'side_right_chest' => 13,
|
||
'side_right_thigh' => 13,
|
||
'side_right_shin' => 13,
|
||
'side_right_foot' => 13,
|
||
|
||
'side_left_deltoid' => 14,
|
||
'side_left_arm' => 14,
|
||
'side_left_forearm' => 14,
|
||
'side_left_hand' => 14,
|
||
'side_left_chest' => 14,
|
||
'side_left_thigh' => 14,
|
||
'side_left_shin' => 14,
|
||
'side_left_foot' => 14,
|
||
|
||
'trochanter1' => 15,
|
||
'trochanter2' => 15,
|
||
'malleolus' => 15,
|
||
|
||
'upper_left' => 16,
|
||
'upper_right' => 16,
|
||
'lower_left' => 16,
|
||
'lower_right' => 16,
|
||
|
||
'left_foot_subarea_1' => 17,
|
||
'left_foot_subarea_2' => 17,
|
||
'left_foot_subarea_3' => 17,
|
||
'left_foot_subarea_4' => 17,
|
||
'left_foot_subarea_5' => 17,
|
||
'left_foot_subarea_6' => 17,
|
||
'left_foot_subarea_7' => 17,
|
||
'left_foot_subarea_8' => 17,
|
||
'left_foot_subarea_9' => 17,
|
||
'left_foot_subarea_10' => 17,
|
||
'left_foot_subarea_11' => 17,
|
||
'left_foot_subarea_12' => 17,
|
||
'left_foot_subarea_13' => 17,
|
||
'left_foot_subarea_14' => 17,
|
||
'left_foot_subarea_15' => 17,
|
||
|
||
'right_foot_subarea_1' => 18,
|
||
'right_foot_subarea_2' => 18,
|
||
'right_foot_subarea_3' => 18,
|
||
'right_foot_subarea_4' => 18,
|
||
'right_foot_subarea_5' => 18,
|
||
'right_foot_subarea_6' => 18,
|
||
'right_foot_subarea_7' => 18,
|
||
'right_foot_subarea_8' => 18,
|
||
'right_foot_subarea_9' => 18,
|
||
'right_foot_subarea_10' => 18,
|
||
'right_foot_subarea_11' => 18,
|
||
'right_foot_subarea_12' => 18,
|
||
'right_foot_subarea_13' => 18,
|
||
'right_foot_subarea_14' => 18,
|
||
'right_foot_subarea_15' => 18,
|
||
];
|
||
|
||
private const chaveTraduzida = [
|
||
|
||
'cabeca' => 'head',
|
||
'testa' => 'forehead',
|
||
'nariz' => 'nose',
|
||
'queixo' => 'chin',
|
||
'bochecha direita' => 'right_cheek',
|
||
'bochecha esquerda' => 'left_cheek',
|
||
|
||
'pescoco' => 'neck',
|
||
|
||
'deltoide direito' => 'right_deltoid',
|
||
'deltoide esquerdo' => 'left_deltoid',
|
||
'peito direito' => 'right_chest',
|
||
'peito esquerdo' => 'left_chest',
|
||
'abdomen' => 'abdomen',
|
||
'abdomen direito' => 'right_abdomen',
|
||
'abdomen esquerdo' => 'left_abdomen',
|
||
'sacral' => 'sacral',
|
||
|
||
'dorso direito' => 'back_body_right',
|
||
'dorso esquerdo' => 'back_body_left',
|
||
'trapezio direito' => 'trapezius_right',
|
||
'trapezio esquerdo' => 'trapezius_left',
|
||
'gluteo direito' => 'glute_right',
|
||
'gluteo esquerdo' => 'glute_left',
|
||
'poplitea direita' => 'popliteal_right',
|
||
'poplitea esquerda' => 'popliteal_left',
|
||
'panturrilha direita' => 'calf_right',
|
||
'panturrilha esquerda' => 'calf_left',
|
||
|
||
'braco direito' => 'right_arm',
|
||
'braco esquerdo' => 'left_arm',
|
||
'antebraco direito' => 'right_forearm',
|
||
'antebraco esquerdo' => 'left_forearm',
|
||
'mao direita' => 'right_hand',
|
||
'mao esquerda' => 'left_hand',
|
||
|
||
'minimo esquerdo' => 'pinky',
|
||
'anelar esquerdo' => 'ring',
|
||
'medio esquerdo' => 'middle',
|
||
'indicador esquerdo' => 'index',
|
||
'polegar esquerdo' => 'thumb',
|
||
'palma esquerda' => 'palm',
|
||
'minimo direito' => 'right_pinky',
|
||
'anelar direito' => 'right_ring',
|
||
'medio direito' => 'right_middle',
|
||
'indicador direito' => 'right_index',
|
||
'polegar direito' => 'right_thumb',
|
||
'palma direita' => 'right_palm',
|
||
|
||
'coxa direita' => 'right_thigh',
|
||
'coxa esquerda' => 'left_thigh',
|
||
'joelho direito' => 'right_knee',
|
||
'joelho esquerdo' => 'left_knee',
|
||
'tibial direita' => 'right_tibial',
|
||
'tibial esquerda' => 'left_tibial',
|
||
'canela direita' => 'right_shin',
|
||
'canela esquerda' => 'left_shin',
|
||
'pe direito' => 'right_foot',
|
||
'pe esquerdo' => 'left_foot',
|
||
|
||
'dedo 1 esquerdo' => 'big_toe',
|
||
'dedo 2 esquerdo' => 'second_toe',
|
||
'terceiro dedo esquerdo' => 'middle_toe',
|
||
'dedo 4 esquerdo' => 'fourth_toe',
|
||
'dedo 5 esquerdo' => 'little_toe',
|
||
'planta do pe esquerda' => 'sole',
|
||
'dedo 1 direito' => 'right_big_toe',
|
||
'dedo 2 direito' => 'right_second_toe',
|
||
'dedo 3 direito' => 'right_middle_toe',
|
||
'dedo 4 direito' => 'right_fourth_toe',
|
||
'dedo 5 direito' => 'right_little_toe',
|
||
'planta do pe direita' => 'right_sole',
|
||
|
||
'antepe medial' => 'medial_forefoot',
|
||
'antepe central' => 'central_forefoot',
|
||
'antepe distal' => 'distal_forefoot',
|
||
'arco plantar' => 'plantar_arch',
|
||
'mediope central' => 'central_midfoot',
|
||
'mediope distal' => 'distal_midfoot',
|
||
'retrope medial' => 'medial_hindfoot',
|
||
'retrope central' => 'central_hindfoot',
|
||
'retrope distal' => 'distal_hindfoot',
|
||
|
||
'calcanhar direito' => 'right_heel',
|
||
'calcanhar esquerdo' => 'left_heel',
|
||
'tendao de aquiles direito' => 'right_achilles_tendon',
|
||
'tendao de aquiles esquerdo' => 'left_achilles_tendon',
|
||
|
||
'maleolo externo direito' => 'right_external_malleolus',
|
||
'maleolo externo esquerdo' => 'left_external_malleolus',
|
||
'arco externo direito' => 'right_external_arch',
|
||
'arco externo esquerdo' => 'left_external_arch',
|
||
'metatarso externo direito' => 'right_external_metatarsal',
|
||
'metatarso externo esquerdo' => 'left_external_metatarsal',
|
||
|
||
'cabeca lateral' => 'side_head',
|
||
'pescoco lateral' => 'side_neck',
|
||
'abdomen lateral' => 'side_abdomen',
|
||
'sacral lateral' => 'side_sacral',
|
||
'trocanter 1 lateral' => 'side_trochanter1',
|
||
'trocanter 2 lateral' => 'side_trochanter2',
|
||
'maleolo lateral' => 'side_malleolus',
|
||
|
||
'deltoide direito lateral' => 'side_right_deltoid',
|
||
'braco direito lateral' => 'side_right_arm',
|
||
'antebraco direito lateral' => 'side_right_forearm',
|
||
'mao direita lateral' => 'side_right_hand',
|
||
'peito direito lateral' => 'side_right_chest',
|
||
'coxa direita lateral' => 'side_right_thigh',
|
||
'canela direita lateral' => 'side_right_shin',
|
||
'pe direito lateral' => 'side_right_foot',
|
||
|
||
'deltoide esquerdo lateral' => 'side_left_deltoid',
|
||
'braco esquerdo lateral' => 'side_left_arm',
|
||
'antebraco esquerdo lateral' => 'side_left_forearm',
|
||
'mao esquerda lateral' => 'side_left_hand',
|
||
'peito esquerdo lateral' => 'side_left_chest',
|
||
'coxa esquerda lateral' => 'side_left_thigh',
|
||
'canela esquerda lateral' => 'side_left_shin',
|
||
'pe esquerdo lateral' => 'side_left_foot',
|
||
|
||
'trocanter 1' => 'trochanter1',
|
||
'trocanter 2' => 'trochanter2',
|
||
'maleolo' => 'malleolus',
|
||
|
||
'superior esquerdo' => 'upper_left',
|
||
'superior direito' => 'upper_right',
|
||
'inferior esquerdo' => 'lower_left',
|
||
'inferior direito' => 'lower_right',
|
||
|
||
'subarea 1 do pe esquerdo' => 'left_foot_subarea_1',
|
||
'subarea 2 do pe esquerdo' => 'left_foot_subarea_2',
|
||
'subarea 3 do pe esquerdo' => 'left_foot_subarea_3',
|
||
'subarea 4 do pe esquerdo' => 'left_foot_subarea_4',
|
||
'subarea 5 do pe esquerdo' => 'left_foot_subarea_5',
|
||
'subarea 6 do pe esquerdo' => 'left_foot_subarea_6',
|
||
'subarea 7 do pe esquerdo' => 'left_foot_subarea_7',
|
||
'subarea 8 do pe esquerdo' => 'left_foot_subarea_8',
|
||
'subarea 9 do pe esquerdo' => 'left_foot_subarea_9',
|
||
'subarea 10 do pe esquerdo' => 'left_foot_subarea_10',
|
||
'subarea 11 do pe esquerdo' => 'left_foot_subarea_11',
|
||
'subarea 12 do pe esquerdo' => 'left_foot_subarea_12',
|
||
'subarea 13 do pe esquerdo' => 'left_foot_subarea_13',
|
||
'subarea 14 do pe esquerdo' => 'left_foot_subarea_14',
|
||
'subarea 15 do pe esquerdo' => 'left_foot_subarea_15',
|
||
|
||
'subarea 1 do pe direito' => 'right_foot_subarea_1',
|
||
'subarea 2 do pe direito' => 'right_foot_subarea_2',
|
||
'subarea 3 do pe direito' => 'right_foot_subarea_3',
|
||
'subarea 4 do pe direito' => 'right_foot_subarea_4',
|
||
'subarea 5 do pe direito' => 'right_foot_subarea_5',
|
||
'subarea 6 do pe direito' => 'right_foot_subarea_6',
|
||
'subarea 7 do pe direito' => 'right_foot_subarea_7',
|
||
'subarea 8 do pe direito' => 'right_foot_subarea_8',
|
||
'subarea 9 do pe direito' => 'right_foot_subarea_9',
|
||
'subarea 10 do pe direito' => 'right_foot_subarea_10',
|
||
'subarea 11 do pe direito' => 'right_foot_subarea_11',
|
||
'subarea 12 do pe direito' => 'right_foot_subarea_12',
|
||
'subarea 13 do pe direito' => 'right_foot_subarea_13',
|
||
'subarea 14 do pe direito' => 'right_foot_subarea_14',
|
||
'subarea 15 do pe direito' => 'right_foot_subarea_15',
|
||
];
|
||
|
||
public static function fromKey(?string $key, ?int $localAnatomicoId = null): ?int
|
||
{
|
||
if ($key === null) {
|
||
|
||
return null;
|
||
}
|
||
|
||
$key = self::normalizeKey($key);
|
||
|
||
$query = DB::table('cadastro_local_anatomico_regiao')
|
||
->where('key', $key);
|
||
|
||
if ($localAnatomicoId !== null) {
|
||
|
||
$query->where('local_anatomico_id', $localAnatomicoId);
|
||
} else {
|
||
|
||
$hint = self::chaveLocalSafecare[$key] ?? null;
|
||
|
||
if ($hint !== null) {
|
||
|
||
$query->where('local_anatomico_id', $hint);
|
||
}
|
||
}
|
||
|
||
$row = $query->first(['id']);
|
||
return $row ? (int) $row->id : null;
|
||
}
|
||
|
||
public static function fromDescricao(?string $descricao, ?int $localAnatomicoId = null): ?int
|
||
{
|
||
if ($descricao === null) {
|
||
|
||
return null;
|
||
}
|
||
|
||
$norm = self::normalize($descricao);
|
||
$key = self::chaveTraduzida[$norm] ?? null;
|
||
|
||
if ($key === null) {
|
||
|
||
return null;
|
||
}
|
||
|
||
return self::fromKey($key, $localAnatomicoId);
|
||
}
|
||
|
||
public static function localAnatomicoIdForKey(string $key): ?int
|
||
{
|
||
$key = self::normalizeKey($key);
|
||
return self::chaveLocalSafecare[$key] ?? null;
|
||
}
|
||
|
||
public static function normalize(string $text): string
|
||
{
|
||
$text = trim(mb_strtolower($text));
|
||
$text = str_replace(
|
||
['á','à','ã','â','ä','é','è','ê','ë','í','ì','î','ï','ó','ò','õ','ô','ö','ú','ù','û','ü','ç','́','’',"'",'º','ª'],
|
||
['a','a','a','a','a','e','e','e','e','i','i','i','i','o','o','o','o','o','u','u','u','u','c','','','','',''],
|
||
$text
|
||
);
|
||
|
||
return preg_replace('/\s+/', ' ', $text);
|
||
}
|
||
|
||
public static function normalizeKey(string $key): string
|
||
{
|
||
$key = trim(mb_strtolower($key));
|
||
$key = preg_replace('/\s+/', '_', $key);
|
||
|
||
return $key;
|
||
}
|
||
} |