From c8679068a9e8930abc9db9ad05f5a6f07a035c8a Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Thu, 5 Mar 2026 05:14:09 +0000 Subject: [PATCH] adding ai generation --- api/ai_report.php | 54 ++++++++---- assets/js/ai_helper.js | 64 +++++++++++--- helpers.php | 22 +++++ includes/layout/footer.php | 36 ++++++-- includes/pages/departments.php | 2 +- includes/pages/doctors.php | 2 +- includes/pages/employees.php | 2 +- includes/pages/laboratory_inquiries.php | 4 +- includes/pages/laboratory_tests.php | 2 +- includes/pages/nurses.php | 2 +- includes/pages/patients.php | 6 +- includes/pages/poisons.php | 2 +- includes/pages/test_groups.php | 2 +- includes/pages/visits.php | 110 +++++++++++++----------- includes/pages/xray_groups.php | 2 +- includes/pages/xray_inquiries.php | 4 +- includes/pages/xray_tests.php | 2 +- 17 files changed, 217 insertions(+), 101 deletions(-) diff --git a/api/ai_report.php b/api/ai_report.php index 158ee92..98be7ff 100644 --- a/api/ai_report.php +++ b/api/ai_report.php @@ -5,28 +5,53 @@ require_once __DIR__ . '/../ai/LocalAIApi.php'; // Get JSON input $input = json_decode(file_get_contents('php://input'), true); +$target = $input['target'] ?? 'treatment_plan'; // symptoms, diagnosis, treatment_plan $symptoms = $input['symptoms'] ?? ''; $diagnosis = $input['diagnosis'] ?? ''; +$currentValue = $input['current_value'] ?? ''; // For expanding symptoms -if (empty($symptoms) && empty($diagnosis)) { - echo json_encode(['success' => false, 'error' => 'No symptoms or diagnosis provided.']); - exit; -} +$systemPrompt = 'You are a professional medical assistant.'; +$userPrompt = ""; -$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"; +switch ($target) { + case 'symptoms': + if (empty($currentValue)) { + $userPrompt = "Generate a list of common clinical symptoms for a general checkup in a professional medical format (HTML lists)."; + } else { + $userPrompt = "Rewrite and expand the following patient symptoms into a professional clinical description using HTML (bullet points or paragraph). Maintain the original meaning but make it clearer and more detailed:\n\n" . strip_tags($currentValue); + } + break; + + case 'diagnosis': + if (empty($symptoms)) { + echo json_encode(['success' => false, 'error' => 'Please enter symptoms first to get a diagnosis suggestion.']); + exit; + } + $userPrompt = "Based on the following symptoms, suggest a list of potential differential diagnoses. Provide the response in a clear HTML list format.\n\nSymptoms:\n" . strip_tags($symptoms); + break; + + case 'treatment_plan': + default: + if (empty($symptoms) && empty($diagnosis)) { + echo json_encode(['success' => false, 'error' => 'No symptoms or diagnosis provided.']); + exit; + } + $userPrompt = "Based on the following symptoms and diagnosis, please generate a concise treatment plan and medical report for the patient.\n\n"; + if (!empty($symptoms)) { + $userPrompt .= "Symptoms:\n" . strip_tags($symptoms) . "\n\n"; + } + if (!empty($diagnosis)) { + $userPrompt .= "Diagnosis:\n" . strip_tags($diagnosis) . "\n\n"; + } + $userPrompt .= "Please provide the report in a clear, professional format using HTML tags (like