feat(lab_examenes): múltiples consentimientos por examen
Mismo patrón que turnero/configuracion: form_ids[] en lugar de formulario_id único, checkboxes en la vista, INSERT múltiple en save.php Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
b2bc0f950a
commit
cf8d011f09
@@ -31,7 +31,7 @@ $activo = (int)($d['activo'] ?? 1);
|
||||
$req_ayuno = (int)($d['requiere_ayuno'] ?? 0);
|
||||
$horas_ayuno = isset($d['horas_ayuno']) && $d['horas_ayuno'] !== '' ? (int)$d['horas_ayuno'] : null;
|
||||
$instruc = trim($d['instrucciones'] ?? '') ?: null;
|
||||
$formId = (int)($d['formulario_id'] ?? 0) ?: null;
|
||||
$formIds = array_values(array_unique(array_filter(array_map('intval', (array)($d['form_ids'] ?? [])))));
|
||||
|
||||
if ($codigo === '') jsonError('El código es requerido');
|
||||
if ($nombre === '') jsonError('El nombre es requerido');
|
||||
@@ -59,10 +59,8 @@ try {
|
||||
}
|
||||
|
||||
$pdo->prepare('DELETE FROM exam_tipo_consentimientos WHERE exam_tipo_id = ?')->execute([$examId]);
|
||||
if ($formId) {
|
||||
$pdo->prepare('INSERT INTO exam_tipo_consentimientos (exam_tipo_id, formulario_id) VALUES (?,?)')
|
||||
->execute([$examId, $formId]);
|
||||
}
|
||||
$ins = $pdo->prepare('INSERT INTO exam_tipo_consentimientos (exam_tipo_id, formulario_id) VALUES (?,?)');
|
||||
foreach ($formIds as $fid) { $ins->execute([$examId, $fid]); }
|
||||
|
||||
$pdo->commit();
|
||||
jsonOk(['id' => $examId], $id ? 'Examen actualizado' : 'Examen creado');
|
||||
|
||||
@@ -21,11 +21,11 @@ if ($id) {
|
||||
$protocolos = $pdo->query('SELECT codigo, nombre FROM lab_protocolos ORDER BY nombre')->fetchAll(PDO::FETCH_ASSOC);
|
||||
$muestras = $pdo->query('SELECT codigo, nombre FROM lab_tipos_muestra ORDER BY nombre')->fetchAll(PDO::FETCH_ASSOC);
|
||||
$formularios = $pdo->query('SELECT id, nombre FROM lab_formularios ORDER BY nombre')->fetchAll(PDO::FETCH_ASSOC);
|
||||
$formActual = null;
|
||||
$formsActuales = [];
|
||||
if ($id) {
|
||||
$s = $pdo->prepare('SELECT formulario_id FROM exam_tipo_consentimientos WHERE exam_tipo_id=? LIMIT 1');
|
||||
$s = $pdo->prepare('SELECT formulario_id FROM exam_tipo_consentimientos WHERE exam_tipo_id=?');
|
||||
$s->execute([$id]);
|
||||
$formActual = $s->fetchColumn() ?: null;
|
||||
$formsActuales = $s->fetchAll(PDO::FETCH_COLUMN);
|
||||
}
|
||||
|
||||
$titulo = $exam ? 'Editar: ' . htmlspecialchars($exam['nombre']) : 'Nuevo Examen';
|
||||
@@ -146,15 +146,19 @@ body { background:#f1f5f9 }
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<label class="form-label">Formulario consentimiento</label>
|
||||
<select id="f-formulario" class="form-select form-select-sm">
|
||||
<option value="">— ninguno —</option>
|
||||
<label class="form-label">Formularios consentimiento</label>
|
||||
<div id="f-formularios-wrap" class="border rounded p-2" style="max-height:120px;overflow-y:auto;background:#fffbeb">
|
||||
<?php foreach ($formularios as $f): ?>
|
||||
<option value="<?= $f['id'] ?>" <?= (int)$formActual === (int)$f['id'] ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars($f['nombre']) ?>
|
||||
</option>
|
||||
<div class="form-check mb-1">
|
||||
<input class="form-check-input f-formulario-chk" type="checkbox"
|
||||
value="<?= $f['id'] ?>" id="f-fc-<?= $f['id'] ?>"
|
||||
<?= in_array((int)$f['id'], array_map('intval', $formsActuales)) ? 'checked' : '' ?>>
|
||||
<label class="form-check-label small" for="f-fc-<?= $f['id'] ?>">
|
||||
<?= htmlspecialchars($f['nombre']) ?>
|
||||
</label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<label class="form-label">Se recibe de (lab externo)</label>
|
||||
@@ -311,7 +315,7 @@ async function guardarExamen() {
|
||||
instrucciones: document.getElementById('f-instrucciones').value.trim(),
|
||||
serecibe: document.getElementById('f-serecibe').value.trim(),
|
||||
activo: document.getElementById('f-activo').checked ? 1 : 0,
|
||||
formulario_id: document.getElementById('f-formulario').value || null,
|
||||
form_ids: [...document.querySelectorAll('.f-formulario-chk:checked')].map(c => parseInt(c.value)),
|
||||
};
|
||||
const r = await fetch(API+'save.php', {method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(payload)}).then(r=>r.json());
|
||||
if (r.ok) {
|
||||
|
||||
Reference in New Issue
Block a user