Browse Source

[hack?] implement search in records list

Matthew Trejo 2 months ago
parent
commit
ced59529ce

+ 0 - 22
src/components/patients/MyPatientCard.tsx

@@ -183,28 +183,6 @@ export default function MyPatientCard({
             <span>{patient._count?.patientAppointments || 0} citas</span>
           </div>
         </div>
-
-        {/* Acciones */}
-        <div className="flex gap-2 pt-2">
-          <Button
-            variant="outline"
-            size="sm"
-            onClick={() => onViewRecords(patient.id)}
-            className="flex-1"
-          >
-            <FileText className="h-4 w-4 mr-2" />
-            Ver Historial
-          </Button>
-          <Button
-            variant="outline"
-            size="sm"
-            onClick={() => onViewAppointments(patient.id)}
-            className="flex-1"
-          >
-            <Calendar className="h-4 w-4 mr-2" />
-            Ver Citas
-          </Button>
-        </div>
       </CardContent>
     </Card>
   )

+ 13 - 0
src/components/records/RecordsFilters.tsx

@@ -103,6 +103,19 @@ export default function RecordsFilters({
               </div>
             )}
 
+            {/* Búsqueda por contenido del reporte */}
+            <div className="bg-muted rounded-xl p-4 border">
+              <Label htmlFor="contentSearch" className="text-foreground font-medium">Buscar en reportes</Label>
+              <Input
+                id="contentSearch"
+                type="text"
+                placeholder="Buscar por contenido, paciente..."
+                value={searchTerm}
+                onChange={(e) => onSearchChange(e.target.value)}
+                className="mt-2"
+              />
+            </div>
+
             {/* Filtro por fecha */}
             <div className="bg-muted rounded-xl p-4 border">
               <Label htmlFor="dateFilter" className="text-foreground font-medium">Filtrar por fecha</Label>

+ 12 - 2
src/components/sidebar/SidebarNavigation.tsx

@@ -52,12 +52,18 @@ export default function SidebarNavigation({ onItemClick, isCollapsed = false }:
     const currentPath = pathname
     const sectionsToExpand: string[] = []
     
-    if (isAdmin || isDoctor) {
+    if (isAdmin) {
       if (currentPath === "/dashboard") {
         sectionsToExpand.push("General")
       } else if (currentPath.startsWith("/admin") || currentPath.startsWith("/records")) {
         sectionsToExpand.push("Administración")
       }
+    } else if (isDoctor) {
+      if (currentPath === "/dashboard") {
+        sectionsToExpand.push("General")
+      } else if (currentPath.startsWith("/patients") || currentPath.startsWith("/records") || currentPath.startsWith("/appointments")) {
+        sectionsToExpand.push("Pacientes")
+      }
     } else {
       if (currentPath === "/dashboard") {
         sectionsToExpand.push("General")
@@ -68,7 +74,11 @@ export default function SidebarNavigation({ onItemClick, isCollapsed = false }:
       }
     }
     
-    setExpandedSections(sectionsToExpand)
+    setExpandedSections(prev => {
+      const newSet = new Set(prev)
+      sectionsToExpand.forEach(section => newSet.add(section))
+      return Array.from(newSet)
+    })
   }, [pathname, session])
 
   if (!session) return null

+ 13 - 1
src/hooks/useRecords.ts

@@ -134,6 +134,18 @@ export function useRecords() {
   useEffect(() => {
     let filtered = [...records]
 
+    // Filtro por búsqueda de texto
+    if (searchTerm) {
+      const term = searchTerm.toLowerCase()
+      filtered = filtered.filter((record) =>
+        record.content.toLowerCase().includes(term) ||
+        record.user.name.toLowerCase().includes(term) ||
+        record.user.lastname.toLowerCase().includes(term) ||
+        record.user.email.toLowerCase().includes(term) ||
+        record.user.username.toLowerCase().includes(term)
+      )
+    }
+
     // Filtro por fecha
     if (dateFilter) {
       const filterDate = new Date(dateFilter)
@@ -145,7 +157,7 @@ export function useRecords() {
 
     setFilteredRecords(filtered)
     setCurrentPage(1) // Resetear a la primera página cuando se filtran
-  }, [records, dateFilter])
+  }, [records, searchTerm, dateFilter])
 
   const downloadReport = (record: Record) => {
     try {