diff --git a/modules/turnero/api/anexar_formulario.php b/modules/turnero/api/anexar_formulario.php index 2755ee8..f965e3e 100644 --- a/modules/turnero/api/anexar_formulario.php +++ b/modules/turnero/api/anexar_formulario.php @@ -31,10 +31,10 @@ if (!$form->fetch()) jsonError('Formulario no encontrado o inactivo.', 404); // Crear el consentimiento con token UUID (mismo formato que create_solicitud) $ins = $pdo->prepare( - "INSERT INTO turnero_consentimientos (turno_id, formulario_id, token, estado, datos_respuestas) - VALUES (?, ?, UUID(), 'enviado', '{}')" + "INSERT INTO turnero_consentimientos (turno_id, formulario_id, token, estado, datos_respuestas, creado_por) + VALUES (?, ?, UUID(), 'enviado', '{}', ?)" ); -$ins->execute([$turnoId, $formularioId]); +$ins->execute([$turnoId, $formularioId, adminId()]); $newId = (int)$pdo->lastInsertId(); $token = $pdo->query("SELECT token FROM turnero_consentimientos WHERE id = $newId")->fetchColumn(); diff --git a/modules/turnero/api/create_consent_token.php b/modules/turnero/api/create_consent_token.php index 2ab7803..fc850b2 100644 --- a/modules/turnero/api/create_consent_token.php +++ b/modules/turnero/api/create_consent_token.php @@ -68,10 +68,10 @@ if ($existente) { ); $stmt = $pdo->prepare( - "INSERT INTO turnero_consentimientos (turno_id, formulario_id, token, estado) - VALUES (?, ?, ?, 'pendiente')" + "INSERT INTO turnero_consentimientos (turno_id, formulario_id, token, estado, creado_por) + VALUES (?, ?, ?, 'pendiente', ?)" ); - $stmt->execute([$turnoId, $formularioId, $token]); + $stmt->execute([$turnoId, $formularioId, $token, adminId()]); } $url = BASE_URL . 'ver_formulario_enviado.php?token=' . urlencode($token); diff --git a/modules/turnero/api/create_solicitud.php b/modules/turnero/api/create_solicitud.php index a703f34..4784c8b 100644 --- a/modules/turnero/api/create_solicitud.php +++ b/modules/turnero/api/create_solicitud.php @@ -187,15 +187,15 @@ try { $consentimientosRequeridos = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmtCreateConsent = $pdo->prepare( - "INSERT IGNORE INTO turnero_consentimientos (turno_id, formulario_id, token, estado) - VALUES (?, ?, UUID(), 'pendiente')" + "INSERT IGNORE INTO turnero_consentimientos (turno_id, formulario_id, token, estado, creado_por) + VALUES (?, ?, UUID(), 'pendiente', ?)" ); $stmtRead = $pdo->prepare( "SELECT id, token, estado FROM turnero_consentimientos WHERE turno_id = ? AND formulario_id = ?" ); foreach ($consentimientosRequeridos as &$c) { - $stmtCreateConsent->execute([$turnoId, $c['formulario_id']]); + $stmtCreateConsent->execute([$turnoId, $c['formulario_id'], adminId()]); $stmtRead->execute([$turnoId, $c['formulario_id']]); $row = $stmtRead->fetch(PDO::FETCH_ASSOC); $c['id'] = $row['id'] ?? null; diff --git a/modules/turnero/api/get_consent_token.php b/modules/turnero/api/get_consent_token.php index 0f36fff..3d04f04 100644 --- a/modules/turnero/api/get_consent_token.php +++ b/modules/turnero/api/get_consent_token.php @@ -46,7 +46,7 @@ $token = sprintf( mt_rand(0,0xffff), mt_rand(0,0xffff), mt_rand(0,0xffff) ); $pdo->prepare( - "INSERT IGNORE INTO turnero_consentimientos (turno_id, formulario_id, token, estado) VALUES (?, ?, ?, 'pendiente')" -)->execute([$turnoId, $formularioId, $token]); + "INSERT IGNORE INTO turnero_consentimientos (turno_id, formulario_id, token, estado, creado_por) VALUES (?, ?, ?, 'pendiente', ?)" +)->execute([$turnoId, $formularioId, $token, adminId()]); jsonOk(['token' => $token, 'nuevo' => true]); diff --git a/modules/turnero/api/get_consentimientos.php b/modules/turnero/api/get_consentimientos.php index 3639d6d..fd3c215 100644 --- a/modules/turnero/api/get_consentimientos.php +++ b/modules/turnero/api/get_consentimientos.php @@ -257,8 +257,8 @@ if ($incluirSolicitud) { $existFormIds = array_map('intval', array_column($consentimientos, 'formulario_id')); $stmtIns = $pdo->prepare( "INSERT IGNORE INTO turnero_consentimientos - (turno_id, formulario_id, token, estado) - VALUES (?, ?, ?, 'pendiente')" + (turno_id, formulario_id, token, estado, creado_por) + VALUES (?, ?, ?, 'pendiente', ?)" ); $creados = 0; foreach ($requeridos as $r) { @@ -271,7 +271,7 @@ if ($incluirSolicitud) { mt_rand(0,0x3fff)|0x8000, mt_rand(0,0xffff), mt_rand(0,0xffff), mt_rand(0,0xffff) ); - $stmtIns->execute([$turnoId, (int)$r['formulario_id'], $token]); + $stmtIns->execute([$turnoId, (int)$r['formulario_id'], $token, adminId()]); $creados++; } } diff --git a/modules/turnero/api/send_consentimiento.php b/modules/turnero/api/send_consentimiento.php index f6cd547..f7cf7f1 100644 --- a/modules/turnero/api/send_consentimiento.php +++ b/modules/turnero/api/send_consentimiento.php @@ -103,8 +103,8 @@ try { WHERE turno_id = ? AND formulario_id = ?" ); $stmtInsertar = $pdo->prepare( - "INSERT INTO turnero_consentimientos (turno_id, formulario_id, token, estado) - VALUES (?, ?, ?, 'pendiente')" + "INSERT INTO turnero_consentimientos (turno_id, formulario_id, token, estado, creado_por) + VALUES (?, ?, ?, 'pendiente', ?)" ); $stmtActualizar = $pdo->prepare( "UPDATE turnero_consentimientos @@ -148,7 +148,7 @@ try { } } else { $token = generarUuid(); - $stmtInsertar->execute([$turnoId, $formularioId, $token]); + $stmtInsertar->execute([$turnoId, $formularioId, $token, adminId()]); $consentId = (int) $pdo->lastInsertId(); } diff --git a/ver_formulario_enviado.php b/ver_formulario_enviado.php index 6d9c5e1..83992e2 100644 --- a/ver_formulario_enviado.php +++ b/ver_formulario_enviado.php @@ -41,13 +41,15 @@ if ($modoTurnero) { ts.numero_orden, med.nombres AS medico_nombres, med.apellidos AS medico_apellidos, med.cod_especialidad AS medico_especialidad, - med.codigo AS medico_codigo, med.docidmedico AS medico_docid + med.codigo AS medico_codigo, med.docidmedico AS medico_docid, + cu.full_name AS creador_nombre FROM turnero_consentimientos tc JOIN lab_formularios f ON f.id = tc.formulario_id JOIN turnero_turnos t ON t.id = tc.turno_id LEFT JOIN turnero_solicitudes ts ON ts.turno_id = tc.turno_id LEFT JOIN lab_pacientes p ON p.id = COALESCE(ts.paciente_id, t.paciente_id) LEFT JOIN medicos med ON med.id = ts.medico_id + LEFT JOIN admin_users cu ON cu.id = tc.creado_por WHERE tc.token = ?", [$tokenTurnero] ); @@ -141,7 +143,7 @@ if ($modoTurnero) { 'fecha_nacimiento' => $tcRow['fecha_nacimiento'], 'paciente_telefono' => $tcRow['paciente_telefono'], 'eps' => $tcRow['eps'], - 'enviado_por_nombre'=> $_SESSION['admin_user']['full_name'] ?? $_SESSION['admin_user']['username'] ?? 'Turnero', + 'enviado_por_nombre'=> $tcRow['creador_nombre'] ?? ($_SESSION['admin_user']['full_name'] ?? $_SESSION['admin_user']['username'] ?? 'Turnero'), 'enviado_por_email' => $_SESSION['admin_user']['email'] ?? null, 'firma_profesional_svg' => $tcRow['firma_profesional_svg'] ?? null, 'datos_cliente' => $tcRow['datos_respuestas'] ?: '{}',