diff --git a/modules/turnero/api/configurar_tomas.php b/modules/turnero/api/configurar_tomas.php index 67b5b1a..dc098b7 100644 --- a/modules/turnero/api/configurar_tomas.php +++ b/modules/turnero/api/configurar_tomas.php @@ -41,7 +41,9 @@ if ($tc['datos_respuestas']) { if (is_array($d)) $dr = $d; } -$dr['_tomas_config'] = $cfg; +// Merge: preserve config from other exams already saved +if (!isset($dr['_tomas_config']) || !is_array($dr['_tomas_config'])) $dr['_tomas_config'] = []; +foreach ($cfg as $k => $v) $dr['_tomas_config'][$k] = $v; if ($examType !== '') $dr['_c8j2g16'] = $examType; if ($otroHora !== '') $dr['_otro_hora'] = $otroHora; diff --git a/modules/turnero/api/get_consentimientos.php b/modules/turnero/api/get_consentimientos.php index 889cd74..637d093 100644 --- a/modules/turnero/api/get_consentimientos.php +++ b/modules/turnero/api/get_consentimientos.php @@ -56,7 +56,8 @@ $stmt = $pdo->prepare( tc.datos_respuestas, f.nombre AS formulario_nombre, f.esquema AS formulario_esquema, - f.es_toma_progresiva AS formulario_es_toma_prog + f.es_toma_progresiva AS formulario_es_toma_prog, + f.solo_profesional AS formulario_solo_profesional FROM turnero_consentimientos tc LEFT JOIN lab_formularios f ON f.id = tc.formulario_id WHERE tc.turno_id = ? @@ -130,8 +131,9 @@ foreach ($consentimientos as &$c) { } } + $soloPro = !empty($c['formulario_solo_profesional']); $c['requiere_firma_profesional'] = $tieneFirmaPro; - $c['requiere_firma_paciente'] = !($tieneFirmaPro && !$tieneFirmaPac); + $c['requiere_firma_paciente'] = $soloPro ? false : !($tieneFirmaPro && !$tieneFirmaPac); $c['origen_lugar_id'] = in_array((int)$c['formulario_id'], $fidsDeLugar, true) ? ($lugarDestinoId ?: -1) : null; $c['es_toma_progresiva'] = $esTomaProg; @@ -139,7 +141,7 @@ foreach ($consentimientos as &$c) { $c['tomas_firmadas'] = $tomasFirm; // Exponer campos firma_profesional (ids) para el frontend $c['campos_firma_pro'] = array_column($camposFirmaPro, 'id'); - unset($c['formulario_esquema'], $c['formulario_es_toma_prog'], $c['datos_respuestas']); + unset($c['formulario_esquema'], $c['formulario_es_toma_prog'], $c['formulario_solo_profesional'], $c['datos_respuestas']); } unset($c); @@ -302,7 +304,8 @@ if ($incluirSolicitud) { tc.datos_respuestas, f.nombre AS formulario_nombre, f.esquema AS formulario_esquema, - f.es_toma_progresiva AS formulario_es_toma_prog + f.es_toma_progresiva AS formulario_es_toma_prog, + f.solo_profesional AS formulario_solo_profesional FROM turnero_consentimientos tc LEFT JOIN lab_formularios f ON f.id = tc.formulario_id WHERE tc.turno_id = ? @@ -358,15 +361,16 @@ if ($incluirSolicitud) { if (!empty($dr2[$fid2]) && strlen($dr2[$fid2]) > 10) $tomasFirm++; } } + $soloPro2 = !empty($c['formulario_solo_profesional']); $c['requiere_firma_profesional'] = $tieneFirmaPro; - $c['requiere_firma_paciente'] = !($tieneFirmaPro && !$tieneFirmaPac); + $c['requiere_firma_paciente'] = $soloPro2 ? false : !($tieneFirmaPro && !$tieneFirmaPac); $c['origen_lugar_id'] = in_array((int)$c['formulario_id'], $fidsDeLugar, true) ? $lugarDestinoId : null; $c['es_toma_progresiva'] = $esTomaProg; $c['tomas_total'] = $tomasTotal2; $c['tomas_firmadas'] = $tomasFirm; $c['campos_firma_pro'] = array_column($camposFirmaPro, 'id'); - unset($c['formulario_esquema'], $c['formulario_es_toma_prog'], $c['datos_respuestas']); + unset($c['formulario_esquema'], $c['formulario_es_toma_prog'], $c['formulario_solo_profesional'], $c['datos_respuestas']); } unset($c); $respuesta['consentimientos'] = $consentimientos; diff --git a/modules/turnero/views/lugar.php b/modules/turnero/views/lugar.php index 9dafcc2..279238f 100644 --- a/modules/turnero/views/lugar.php +++ b/modules/turnero/views/lugar.php @@ -1609,9 +1609,10 @@ function renderConsentimientos(lista) { Siguiente toma `; } else if (LUGAR_FORM_MODO === 'embebido') { + const lblAccion = c.requiere_firma_paciente ? 'Firmar' : 'Completar'; btnAccion = ``; } else { btnAccion = ` +
+ +
Firma del paciente / responsable @@ -1614,7 +1623,22 @@ document.addEventListener('DOMContentLoaded', function() { } catch(e) {} } _mpApplyExamVisibility(examName); - if (_mpModoTurnero) _mpRenderBadges(); + if (_mpModoTurnero) { + _mpRenderBadges(); + var _chkd = Array.from(document.querySelectorAll('[name="_c8j2g16[]"]:checked,[name="_c8j2g16"]:checked')); + var _autoT = null; + for (var _i = 0; _i < _chkd.length && !_autoT; _i++) { + var _n = _chkd[_i].value, _g = _mpGetGroupsForExam(_n); + if (!Object.keys(_g).length) continue; + var _conf = _mpTomasConfig && Object.keys(_g).some(function(k){ return _mpTomasConfig[k]; }); + if (!_conf) _autoT = { name: _n, groups: _g, isModify: false }; + } + if (!_autoT && _chkd.length) { + var _n = _chkd[0].value, _g = _mpGetGroupsForExam(_n); + if (Object.keys(_g).length) _autoT = { name: _n, groups: _g, isModify: true }; + } + if (_autoT) _mpShowCfgPanel(_autoT.name, _autoT.groups, _autoT.isModify); + } }); // Botón "Usar todas" @@ -2505,6 +2529,48 @@ document.querySelectorAll('.turnero-firma-item').forEach(function(widget) { }); }); }); + +(function() { + var btn = document.getElementById('btn-completar-pro'); + if (!btn) return; + btn.addEventListener('click', function() { + var msgEl = document.getElementById('btn-completar-pro-msg'); + btn.disabled = true; + btn.innerHTML = 'Guardando...'; + var campos = {}; + document.querySelectorAll('[name]').forEach(function(el) { + var raw = el.name, isArr = raw.slice(-2) === '[]', name = isArr ? raw.slice(0,-2) : raw; + if (el.type === 'checkbox') { if (el.checked) { if (!Array.isArray(campos[name])) campos[name] = []; campos[name].push(el.value); } } + else if (el.type === 'radio') { if (el.checked) campos[name] = el.value; } + else if (el.value !== '') campos[name] = el.value; + }); + fetch(window.location.href, { + method: 'POST', headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ mp_completar: true, datos_respuestas: campos }) + }) + .then(function(r) { return r.json(); }) + .then(function(d) { + if (d.ok) { + document.getElementById('btn-completar-pro-wrap').style.display = 'none'; + var ok = document.createElement('div'); + ok.className = 'alert alert-success mt-4 d-flex align-items-center gap-2 no-print'; + ok.innerHTML = '
Completado correctamente.
'; + document.getElementById('btn-completar-pro-wrap').parentNode.appendChild(ok); + try { window.parent.postMessage({ type: 'turneroFirmado' }, '*'); } catch(e) {} + } else { + msgEl.innerHTML = '' + (d.error || 'Error al guardar') + ''; + btn.disabled = false; + btn.innerHTML = 'Guardar y completar'; + } + }) + .catch(function() { + msgEl.innerHTML = 'Error de conexión.'; + btn.disabled = false; + btn.innerHTML = 'Guardar y completar'; + }); + }); +})(); +