File size: 4,864 Bytes
40256dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
08bc828
40256dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<!DOCTYPE html>
<html lang="es">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Historial de Consultas</title>
  <link rel="stylesheet" href="css/styles.css">
  <script src="api.js"></script>
  <script src="js/consultas.js"></script>
  <style>
    .consultations-list {
      margin-top: 20px;
      overflow-x: auto;
    }

    table {
      width: 100%;
      border-collapse: collapse;
      margin-top: 10px;
    }

    th, td {
      padding: 12px 15px;
      text-align: left;
      border-bottom: 1px solid #ddd;
    }

    th {
      background-color: #f8f9fa;
      font-weight: bold;
    }

    tr:hover {
      background-color: #f5f5f5;
    }

    .diagnosis-positive {
      color: #dc3545;
      font-weight: bold;
    }

    .diagnosis-negative {
      color: #28a745;
      font-weight: bold;
    }

    .filters {
      margin-bottom: 20px;
      display: flex;
      gap: 10px;
    }

    .filters input {
      padding: 8px;
      border: 1px solid #ddd;
      border-radius: 4px;
      flex-grow: 1;
    }

    .filters button {
      padding: 8px 15px;
      background-color: #007bff;
      color: white;
      border: none;
      border-radius: 4px;
      cursor: pointer;
    }

    .filters button:hover {
      background-color: #0056b3;
    }
  </style>
</head>
<body>
<div class="container">
  <header>
    <h1>Historial de Consultas</h1>
    <nav>
      <a href="index.html">Inicio</a>
      <a href="pacientes.html">Pacientes</a>
      <a href="consultas.html" class="active">Consultas</a>
    </nav>
  </header>

  <div class="content">
    <div class="filters">
      <input type="text" id="searchInput" placeholder="Buscar por nombre de paciente...">
      <button onclick="loadConsultations()">Buscar</button>
    </div>

    <div class="consultations-list">
      <table id="consultationsTable">
        <thead>
        <tr>
          <th>ID</th>
          <th>Paciente</th>
          <th>Fecha</th>
          <th>Diagnóstico</th>
          <th>Confianza</th>
          <th>Notas</th>
        </tr>
        </thead>
        <tbody id="consultationsBody">
        <!-- Las consultas se cargargan aqui -->
        </tbody>
      </table>
    </div>
  </div>
</div>

<script>
  // Funcion para cargar todas las consultas
  async function loadConsultations() {
    try {
      const searchTerm = document.getElementById('searchInput').value;
      let result;

      if (searchTerm) {
        const searchResp = await api.getPatients(searchTerm);
        if (searchResp.success && searchResp.patients.length > 0) {
          const allResp = await api.getConsultations(1, 200, searchTerm);
          displayConsultations(allResp.consultations || []);
          return;
        }
      }

      // Si no hay termino de busqueda o no se encontraron pacientes, cargar todas las consultas
      result = await api.getConsultations(1, 100);
      result.consultations = result.consultations || [];
      if (result.success) {
        displayConsultations(result.consultations || []);
      } else {
        alert('Error al cargar consultas: ' + (result.message || result.error));
      }
    } catch (error) {
      console.error('Error:', error);
      alert('Ocurrio un error al cargar las consultas');
    }
  }

  // Funcion para mostrar las consultas en la tabla
  function displayConsultations(consultations) {
    const tbody = document.getElementById('consultationsBody');
    tbody.innerHTML = '';

    if (consultations.length === 0) {
      tbody.innerHTML = '<tr><td colspan="6">No se encontraron consultas</td></tr>';
      return;
    }

    consultations.sort((a, b) => new Date(b.consultationDate) - new Date(a.consultationDate));

    consultations.forEach(consultation => {
      const row = document.createElement('tr');

      row.innerHTML = `
            <td>${consultation.consultationID}</td>
            <td>${consultation.patientName || consultation.patientName || consultation.patient_name || 'N/A'}</td>
            <td>${formatDate(consultation.consultationDate)}</td>
            <td class="${consultation.diabeticRetinopathy ? 'diagnosis-positive' : 'diagnosis-negative'}">
                ${consultation.diabeticRetinopathy ? 'Positivo' : 'Negativo'}
            </td>
            <td>${consultation.confidence ? consultation.confidence + '%' : 'N/A'}</td>
            <td>${consultation.notes || ''}</td>
        `;

      tbody.appendChild(row);
    });
  }

  // Funcion para formatear la fecha
  function formatDate(dateString) {
    if (!dateString) return 'N/A';
    const date = new Date(dateString);
    return date.toLocaleDateString() + ' ' + date.toLocaleTimeString();
  }

  // Cargar consultas al abrir la página
  document.addEventListener('DOMContentLoaded', () => {
    loadConsultations();
  });
</script>
</body>
</html>