return: SETOF record
lang: plpgsql
parameters:
  p0:
    type: text
    name: i_indicateur_code
src: |
  DECLARE	
  	sqlcmd text;
  	
  	temp_cursor refcursor;
  	_oid integer;
  	_maxind integer;
  	_indicateur_id bigint;
  	
  	row  RECORD;
  BEGIN
  	_indicateur_id = 0;
  	OPEN temp_cursor FOR 
  	SELECT oid FROM pmsi.t_indicateurs WHERE code = i_indicateur_code;
  	
  	FETCH temp_cursor INTO _oid;
  	WHILE FOUND LOOP
  		_indicateur_id = _oid;
  	FETCH temp_cursor INTO _oid;
  	END LOOP;
  	CLOSE temp_cursor;
  		
  	
  	FOR row IN 
  		SELECT * FROM pmsi.cti_prepare_jauge_indicateurs(_indicateur_id, 'v_rss_1', '') AS (name text, value text)
  		UNION
  		SELECT * FROM pmsi.cti_prepare_jauge_indicateurs(_indicateur_id, 'v_rss_rum_1', '') AS (name text, value text)
  		UNION
  		SELECT * FROM pmsi.cti_prepare_jauge_indicateurs(_indicateur_id, 'v_rsf_detail_1', '') AS (name text, value text)
  		UNION
  		SELECT * FROM pmsi.cti_prepare_jauge_indicateurs(_indicateur_id, 'v_rsf_detail_6', '') AS (name text, value text)
  		UNION
  		SELECT * FROM pmsi.cti_prepare_jauge_indicateurs(_indicateur_id, 'v_rss_lpp_1', '') AS (name text, value text)
  		UNION
  		SELECT * FROM pmsi.cti_prepare_jauge_indicateurs(_indicateur_id, 'v_rss_ucd_1', '') AS (name text, value text)
  		UNION
  		SELECT * FROM pmsi.cti_prepare_jauge_indicateurs(_indicateur_id, 'v_rss_actes_1', '') AS (name text, value text)
  		UNION
  		SELECT * FROM pmsi.cti_prepare_jauge_indicateurs(_indicateur_id, 'v_rss_diagnostics_1', '') AS (name text, value text)
  		UNION
  		SELECT * FROM pmsi.cti_prepare_jauge_indicateurs(_indicateur_id, 'v_rss_cancero_1', '') AS (name text, value text)
  		UNION
  		SELECT * FROM pmsi.cti_prepare_jauge_indicateurs(_indicateur_id, 'v_rsf_detail_rum_1', '') AS (name text, value text)
  		UNION
  		SELECT * FROM pmsi.cti_prepare_jauge_indicateurs(_indicateur_id, 'v_rss_sae_1', '') AS (name text, value text)
  		UNION
  		
  		
  		SELECT 'RUBRIQUES_RAPPORT',
  			base.cti_group_concat(
  			CASE WHEN table_name <> '*CALC' THEN 'SUM(indicateurs[000' || oid || '])'
  			ELSE 
  					replace(
  						replace(
  							column_name,
  							'[1]', 
  							'SUM(indicateurs[000' || indicateur_associe_1_id || '])'
  						),
  						'[2]', 
  						'SUM(indicateurs[000' || indicateur_associe_2_id || '])'
  					)
  			END)
  		FROM (SELECT * FROM pmsi.t_indicateurs 
  			WHERE oid = _indicateur_id 
  		) subview
  		
  	LOOP
  	
  	
  		RETURN NEXT row;
  	END LOOP;
  	RETURN ;
  END;