File size: 2,052 Bytes
128cf85
 
 
 
 
23a6f54
128cf85
 
 
 
 
 
 
 
 
 
 
 
 
 
18cd20d
128cf85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
 * API Service for Medical Multi-Agent System
 * Handles communication with backend Web API
 */

const API_BASE_URL = process.env.REACT_APP_API_URL || "https://0a986f11bced.ngrok-free.app";

class ApiService {
  constructor() {
    this.baseUrl = API_BASE_URL;
  }

  /**
   * Generic API call wrapper
   */
  async apiCall(endpoint, options = {}) {
    const url = `${this.baseUrl}${endpoint}`;
    const config = {
      headers: {
        "Content-Type": "application/json",
        "ngrok-skip-browser-warning": "true",
        ...options.headers,
      },
      ...options,
    };

    try {
      const response = await fetch(url, config);

      if (!response.ok) {
        const errorData = await response
          .json()
          .catch(() => ({ detail: "Unknown error" }));
        throw new Error(
          `API Error: ${response.status} - ${
            errorData.detail || response.statusText
          }`
        );
      }

      return await response.json();
    } catch (error) {
      console.error("API call failed:", error);
      throw error;
    }
  }

  /**
   * Health check
   */
  async healthCheck() {
    return this.apiCall("/api/health");
  }

  /**
   * Start new chat session
   */
  async startChat() {
    return this.apiCall("/api/chat/start", {
      method: "POST",
    });
  }

  /**
   * Send message to AI
   */
  async sendMessage(message) {
    return this.apiCall("/api/chat/send", {
      method: "POST",
      body: JSON.stringify({ message }),
    });
  }

  /**
   * Get current session status and patient record
   */
  async getSessionStatus() {
    return this.apiCall("/api/chat/status");
  }

  /**
   * Generate doctor summary
   */
  async generateSummary() {
    return this.apiCall("/api/chat/summary", {
      method: "POST",
    });
  }

  /**
   * Reset current session
   */
  async resetSession() {
    return this.apiCall("/api/chat/reset", {
      method: "DELETE",
    });
  }
}

// Export singleton instance
export const apiService = new ApiService();
export default apiService;