Files
html/api/ethica-hcp-by-country.php
opus 305c6a7db4
Some checks failed
WEVAL NonReg / nonreg (push) Has been cancelled
auto-commit via WEVIA vault_git intent 2026-04-18T14:52:19+00:00
2026-04-18 16:52:19 +02:00

22 lines
928 B
PHP

<?php
header('Content-Type: application/json');
$host = '10.1.0.3'; $port = '5432'; $db = 'adx_system'; $user = 'admin'; $pass = 'admin123';
$pdo = null;
try {
$pdo = new PDO("pgsql:host=$host;port=$port;dbname=$db", $user, $pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $e) {
echo json_encode(['ok'=>false,'error'=>$e->getMessage()]); exit;
}
$rows = $pdo->query("SELECT pays, COUNT(*) AS c FROM ethica.medecins_real GROUP BY pays ORDER BY c DESC")->fetchAll(PDO::FETCH_ASSOC);
$total = array_sum(array_column($rows, 'c'));
echo json_encode([
'ok' => true,
'ts' => date('c'),
'table' => 'ethica.medecins_real',
'total_hcps' => (int)$total,
'by_country' => array_map(fn($r)=>['pays'=>$r['pays'] ?: 'UNKNOWN','count'=>(int)$r['c'],'pct'=>round($r['c']*100/max(1,$total),1)], $rows),
'summary' => count($rows) . ' pays'
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);