return: text
lang: plpgsql
parameters:
  p0:
    type: text
    name: i_table_code
src: |
  DECLARE	
  	
  	
  	
  	result TEXT;
  BEGIN
  	
  		-- Si Toutes les tables, mettre à jour oid par codes 
    		IF (i_table_code = '*ALL') THEN
    			PERFORM base.cti_initialize_classes_by_code('pmsi');
    			PERFORM base.cti_initialize_listes_by_code('pmsi');
    		END IF;
    		
  		IF (i_table_code = 'FINESS' OR i_table_code = '*ALL') THEN
  			EXECUTE 'SELECT base.cti_update_classes(''base'', ''t_finess'', ''FINESS'','''');';
  		END IF;
  		IF (i_table_code = 'CODEPOST' OR i_table_code = '*ALL') THEN
  			EXECUTE 'SELECT base.cti_update_classes(''pmsi'', ''t_codes_postaux_c'', ''CODEPOST'','''');';
  		END IF;
  		IF (i_table_code = 'GHM' OR i_table_code = '*ALL') THEN
  			EXECUTE 'SELECT base.cti_update_classes(''pmsi'', ''t_ghm_c'', ''GHM'','''');';
  		END IF;
  		IF (i_table_code = 'ACTE' OR i_table_code = '*ALL') THEN
  			EXECUTE 'SELECT base.cti_update_classes(''pmsi'', ''t_actes_c'', ''ACTE'','''');';
  		END IF;
  		IF (i_table_code = 'DIAG' OR i_table_code = '*ALL') THEN
  			EXECUTE 'SELECT base.cti_update_classes(''pmsi'', ''t_diagnostics'', ''DIAG'','''');';
  		END IF;
  		IF (i_table_code = 'LPP' OR i_table_code = '*ALL') THEN
  			EXECUTE 'SELECT base.cti_update_classes(''pmsi'', ''t_lpp'', ''LPP'','''');';
  		END IF;
  		IF (i_table_code = 'UCD' OR i_table_code = '*ALL') THEN
  			EXECUTE 'SELECT base.cti_update_classes(''pmsi'', ''t_ucd'', ''UCD'','''');';
  		END IF;
  		IF (i_table_code = 'MEDECIN' OR i_table_code = '*ALL') THEN
  			EXECUTE 'SELECT base.cti_update_classes(''pmsi'', ''t_medecins_c'', ''MEDECIN'','''');';
  		END IF;
  		IF (i_table_code = 'PRESTA' OR i_table_code = '*ALL') THEN
  			EXECUTE 'SELECT base.cti_update_classes(''pmsi'', ''t_prestations'', ''PRESTA'','''');';
  		END IF;
  		IF (i_table_code = 'TYPEFACT' OR i_table_code = '*ALL') THEN
  			EXECUTE 'SELECT base.cti_update_classes(''pmsi'', ''t_prestations'', ''TYPEFACT'',''type_facturation_section'');';
  		END IF;
  		IF (i_table_code = 'UM' OR i_table_code = '*ALL') THEN
  			EXECUTE 'SELECT base.cti_update_classes(''pmsi'', ''t_unites_medicales'', ''UM'','''');';
  		END IF;
  		IF (i_table_code = 'UF' OR i_table_code = '*ALL') THEN
  			EXECUTE 'SELECT base.cti_update_classes(''pmsi'', ''t_unites_fonctionnelles'', ''UF'','''');';
  		END IF;
  		IF (i_table_code = 'COMED' OR i_table_code = '*ALL') THEN
  			EXECUTE 'SELECT base.cti_update_classes(''pmsi'', ''t_comites_medicaux'', ''COMED'','''');';
  		END IF;
  		IF (i_table_code = 'AGE' OR i_table_code = '*ALL') THEN
  			EXECUTE 'SELECT base.cti_update_classes(''pmsi'', ''t_ages_c'', ''AGE'','''');';
  		END IF;
  		IF (i_table_code = 'DURSEJ' OR i_table_code = '*ALL') THEN
  			EXECUTE 'SELECT base.cti_update_classes(''pmsi'', ''t_durees_sejour_c'', ''DURSEJ'','''');';
  		END IF;		
  		IF (i_table_code = 'INDICATIONUCD' OR i_table_code = '*ALL') THEN
  			EXECUTE 'SELECT base.cti_update_classes(''pmsi'', ''t_indication'', ''INDICATIONUCD'','''');';
  		END IF;
  		IF (i_table_code = 'EXPERTCTL' OR i_table_code = '*ALL') THEN
  			PERFORM base.cti_update_classes('pmsi', 't_expert_controle', 'EXPERTCTL','');
  		END IF;
    		IF (i_table_code = 'POLE' OR i_table_code = '*ALL') THEN
    			PERFORM base.cti_update_classes('base', 't_pole', 'POLE','');
    			UPDATE pmsi.t_pole SET 
    				section_id = t_pole.section_id,
    				section_code = t_pole.section_code,
    				section_texte = t_pole.section_texte
    			FROM base.t_pole as t_pole_base
    			WHERE t_pole.oid = t_pole_base.oid AND
    				(
    					t_pole.section_id IS DISTINCT FROM t_pole_base.section_id OR
    					t_pole.section_code IS DISTINCT FROM t_pole_base.section_code OR
    					t_pole.section_texte IS DISTINCT FROM t_pole_base.section_texte
    				)
    			;
    		END IF;
  		
  	RETURN 'OK';
  END;