false, 'error' => 'No symptoms or diagnosis provided.']);
exit;
}
$prompt = "You are a professional medical assistant. Based on the following symptoms and diagnosis, please generate a concise treatment plan and medical report for the patient.\n\n";
if (!empty($symptoms)) {
$prompt .= "Symptoms:\n" . strip_tags($symptoms) . "\n\n";
}
if (!empty($diagnosis)) {
$prompt .= "Diagnosis:\n" . strip_tags($diagnosis) . "\n\n";
}
$prompt .= "Please provide the report in a clear, professional format using HTML tags (like
, - , , etc.) for better readability.";
try {
$response = LocalAIApi::createResponse([
'input' => [
['role' => 'system', 'content' => 'You are a helpful medical assistant.'],
['role' => 'user', 'content' => $prompt],
],
]);
if (!empty($response['success'])) {
$text = LocalAIApi::extractText($response);
echo json_encode(['success' => true, 'report' => $text]);
} else {
echo json_encode(['success' => false, 'error' => $response['error'] ?? 'AI generation failed.']);
}
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}