feat: módulo lab_examenes — CRUD catálogo de exámenes, items y tarifas
- Nuevo módulo lab_examenes con lista paginada, buscador y filtro por categoría - Vista de detalle/edición con campos completos de exam_tipos (CUPS, protocolo, tipo muestra, nivel, abreviatura, seremite, ayuno, instrucciones) - Sub-tabla inline de items de resultado (lab_items_resultado) con edición por fila - Sub-tabla de precios por tarifa (lab_tarifas) con modal de edición - APIs: list, get, save, save_item, save_tarifa, get_tarifas - Script ETL Firebird→MySQL (scripts/etl_examenes.php) para la migración inicial Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
229977785b
commit
fb0e77523c
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/_helpers.php';
|
||||
requireAdmin();
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') jsonError('Método no permitido', 405);
|
||||
|
||||
$d = inputJson();
|
||||
$examId = (int)($d['exam_tipo_id'] ?? 0);
|
||||
$tarifaId = (int)($d['tarifa_id'] ?? 0);
|
||||
if (!$examId || !$tarifaId) jsonError('exam_tipo_id y tarifa_id son requeridos');
|
||||
|
||||
$pdo = db();
|
||||
|
||||
if (!empty($d['_delete'])) {
|
||||
$pdo->prepare('DELETE FROM lab_tarifas WHERE exam_tipo_id = ? AND tarifa_id = ?')
|
||||
->execute([$examId, $tarifaId]);
|
||||
jsonOk([], 'Precio eliminado');
|
||||
}
|
||||
|
||||
$valor = (float)($d['valor'] ?? 0);
|
||||
$rec_urg = (float)($d['recargo_urg'] ?? 0);
|
||||
$rec_fes = (float)($d['recargo_fes'] ?? 0);
|
||||
$rec_esp = (float)($d['recargo_esp'] ?? 0);
|
||||
|
||||
$s = $pdo->prepare('SELECT COALESCE(codigo_legacy, codigo) FROM exam_tipos WHERE id = ?');
|
||||
$s->execute([$examId]);
|
||||
$leg = $s->fetchColumn();
|
||||
if (!$leg) jsonError('Examen no encontrado', 404);
|
||||
|
||||
// Check if price row exists (no unique key in schema, so do it manually)
|
||||
$s = $pdo->prepare('SELECT id FROM lab_tarifas WHERE exam_tipo_id = ? AND tarifa_id = ?');
|
||||
$s->execute([$examId, $tarifaId]);
|
||||
$precioId = $s->fetchColumn();
|
||||
|
||||
if ($precioId) {
|
||||
$pdo->prepare(
|
||||
'UPDATE lab_tarifas SET valor=?,recargo_urg=?,recargo_fes=?,recargo_esp=?,cod_examen_legacy=? WHERE id=?'
|
||||
)->execute([$valor, $rec_urg, $rec_fes, $rec_esp, $leg, $precioId]);
|
||||
} else {
|
||||
$pdo->prepare(
|
||||
'INSERT INTO lab_tarifas (cod_examen_legacy,exam_tipo_id,tarifa_id,valor,recargo_urg,recargo_fes,recargo_esp)
|
||||
VALUES (?,?,?,?,?,?,?)'
|
||||
)->execute([$leg, $examId, $tarifaId, $valor, $rec_urg, $rec_fes, $rec_esp]);
|
||||
}
|
||||
|
||||
jsonOk([], 'Precio guardado');
|
||||
Reference in New Issue
Block a user