File size: 3,155 Bytes
1739591
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# api_callers.py (New file or integrated into your agent script)
import requests
import json
import os
# Assume your .NET API base URL is an environment variable or configured elsewhere
DOTNET_API_BASE_URL = os.getenv("DOTNET_API_BASE_URL", "http://localhost:5030/api") # Example
# If your API needs an API key for authentication:
DOTNET_API_KEY = os.getenv("DOTNET_API_AUTH_KEY")

def get_vaccination_statistics(wilaya: str) -> str:
    """
    Fetches vaccination statistics for a specified Algerian Wilaya (province/state).
    For example, can provide vaccination coverage rates for different vaccines.
    Input must be the name of the Wilaya.
    """
    print(f"--- API Tool: Fetching statistics for Wilaya: {wilaya} ---")
    try:
        headers = {}
        if DOTNET_API_KEY:
            headers["Authorization"] = f"Bearer {DOTNET_API_KEY}" # Or your API's auth scheme

        # Adjust endpoint and parameters as per your API design
        response = requests.get(f"{DOTNET_API_BASE_URL}/statistics/coverage", params={"wilaya": wilaya}, headers=headers)
        response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx)
        
        data = response.json() # Assuming your API returns JSON
        print(f"   API Response (Statistics for {wilaya}): {data}")
        return json.dumps(data) # Return JSON string to the agent
    except requests.exceptions.RequestException as e:
        print(f"   ❌ Error calling statistics API for {wilaya}: {e}")
        return f"Error fetching statistics: {str(e)}"
    except json.JSONDecodeError:
        print(f"   ❌ Error decoding JSON response from statistics API for {wilaya}.")
        return "Error: Invalid JSON response from statistics API."




def get_patient_vaccination_record(patient_id: str) -> str:
    """
    Retrieves the vaccination record for a specific patient using their unique ID.
    Input must be the patient's unique identifier.
    """
    print(f"--- API Tool: Fetching record for Patient ID: {patient_id} ---")
    try:
        headers = {}
        if DOTNET_API_KEY:
            headers["Authorization"] = f"Bearer {DOTNET_API_KEY}"
        # Adjust endpoint as per your API design
        response = requests.get(f"{DOTNET_API_BASE_URL}/doctors/vaccination-history/{patient_id}", headers=headers)
        response.raise_for_status()
        
        data = response.json()
        print(f"   API Response (Record for patient {patient_id}): {data}")
        return json.dumps(data)
    except requests.exceptions.RequestException as e:
        # Handle specific errors like 404 for not found patient
        if e.response is not None and e.response.status_code == 404:
            print(f"   Patient ID {patient_id} not found in API.")
            return f"Patient record not found for ID {patient_id}."
        print(f"   ❌ Error calling patient record API for {patient_id}: {e}")
        return f"Error fetching patient record: {str(e)}"
    except json.JSONDecodeError:
        print(f"   ❌ Error decoding JSON response from patient record API for {patient_id}.")
        return "Error: Invalid JSON response from patient record API."