Files
medicaltracker/public/api.php
T
Ty Clifford 96de47be43 - The medicine database is now much bigger and has a real update path.
Added:
Live source updater for RxNorm, DailyMed, and openFDA.
Admin dashboard panel to refresh medicine sources.
CLI updater for periodic jobs: 
[scripts/update_medicine_catalog.php](/Users/tyemeclifford/Documents/GH/workout/scripts/update_medicine_catalog.php)
Update history table: medication_source_updates.
Curl fallback for external fetches when PHP stream DNS fails.
README instructions for periodic updates.
I also ran the imports:
Current medication catalog count: 6,002.
Latest source imports:RxNorm: 3,875 inserted, 1,125 updated.
openFDA: 912 inserted, 88 updated.
DailyMed: 95 inserted.

Periodic update command:
/Users/tyemeclifford/frankenphp php-cli 
scripts/update_medicine_catalog.php 5000 all
2026-06-30 15:29:57 -04:00

62 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
require __DIR__ . '/../app/bootstrap.php';
try {
$action = $_GET['action'] ?? 'state';
$method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
if ($method === 'GET' && $action === 'state') {
json_response(state_payload($_GET));
exit;
}
if ($method === 'GET' && $action === 'library_search') {
json_response(library_search_payload($_GET));
exit;
}
if ($method !== 'POST') {
json_response(['error' => 'Unsupported method.'], 405);
exit;
}
$data = json_input();
$routes = [
'create_user' => 'create_user',
'public_signup' => 'public_signup',
'update_user' => 'update_user',
'delete_user' => 'delete_user',
'update_theme' => 'update_theme',
'create_exercise' => 'create_exercise',
'create_supplement' => 'create_supplement',
'create_nutrition_goal' => 'create_nutrition_goal',
'create_routine' => 'create_routine',
'create_workout' => 'create_workout',
'update_workout' => 'update_workout',
'create_nutrition_log' => 'create_nutrition_log',
'create_supplement_log' => 'create_supplement_log',
'create_body_metric' => 'create_body_metric',
'create_medication_log' => 'create_medication_log',
'create_vital_log' => 'create_vital_log',
'create_lab_result' => 'create_lab_result',
'create_symptom_log' => 'create_symptom_log',
'create_allergy_record' => 'create_allergy_record',
'create_appointment' => 'create_appointment',
'create_immunization_record' => 'create_immunization_record',
'refresh_medication_sources' => 'refresh_medication_sources',
];
if (!isset($routes[$action])) {
json_response(['error' => 'Unknown API action.'], 404);
exit;
}
json_response($routes[$action]($data));
} catch (InvalidArgumentException $exception) {
json_response(['error' => $exception->getMessage()], 400);
} catch (Throwable $exception) {
json_response(['error' => 'Server error: ' . $exception->getMessage()], 500);
}