SELECT COUNT(*)::bigint AS total
FROM invima_api_catalog
WHERE source_dataset_key = 'dispositivos'
  AND (
    (COALESCE(estado_registro, '') ILIKE '%vigente%' OR COALESCE(vigencia, '') ILIKE '%vigente%')
    AND COALESCE(estado_registro, '') NOT ILIKE '%no vigente%'
    AND COALESCE(vigencia, '') NOT ILIKE '%no vigente%'
  );
