prepare('DELETE FROM lab_items_resultado WHERE id = ?')->execute([$id]); jsonOk([], 'Item eliminado'); } $codProt = trim($d['cod_protocolo'] ?? ''); $nombre = trim($d['nombre'] ?? ''); if (!$codProt) jsonError('cod_protocolo requerido'); if (!$nombre) jsonError('Nombre requerido'); $tipoSexo = in_array($d['tipo_sexo'] ?? '', ['M','F']) ? $d['tipo_sexo'] : null; $tipo = in_array($d['tipo'] ?? '', ['N','T']) ? $d['tipo'] : 'T'; $medida = trim($d['medida'] ?? '') ?: null; $abrev = trim($d['abreviatura'] ?? '') ?: null; $vmin = $d['vmin_ref'] !== '' && $d['vmin_ref'] !== null ? (float)$d['vmin_ref'] : null; $vmax = $d['vmax_ref'] !== '' && $d['vmax_ref'] !== null ? (float)$d['vmax_ref'] : null; $orden = (int)($d['orden'] ?? 0); $formula = trim($d['formula'] ?? '') ?: null; $cups_d = trim($d['cups_detalle'] ?? '') ?: null; $pdo = db(); if ($id) { $pdo->prepare( 'UPDATE lab_items_resultado SET cod_protocolo=?,nombre=?,tipo_sexo=?,tipo=?,medida=?, abreviatura=?,vmin_ref=?,vmax_ref=?,orden=?,formula=?,cups_detalle=? WHERE id=?' )->execute([$codProt,$nombre,$tipoSexo,$tipo,$medida,$abrev,$vmin,$vmax,$orden,$formula,$cups_d,$id]); jsonOk(['id' => $id], 'Item actualizado'); } else { $pdo->prepare( 'INSERT INTO lab_items_resultado (cod_protocolo,nombre,tipo_sexo,tipo,medida,abreviatura,vmin_ref,vmax_ref,orden,formula,cups_detalle) VALUES (?,?,?,?,?,?,?,?,?,?,?)' )->execute([$codProt,$nombre,$tipoSexo,$tipo,$medida,$abrev,$vmin,$vmax,$orden,$formula,$cups_d]); jsonOk(['id' => (int)$pdo->lastInsertId()], 'Item creado'); }