<?xml version="1.0" encoding="ISO-8859-1"?>
<ROOT>
	<NODE name="EXECENV" label="TRAITEMENT ENVIRONNEMENT [FINESS] [FINESS_TEXTE]">
		<conditionx><![CDATA[
				"[FINESS]" == "290019777"
			]]></conditionx>
		<NODE name="INIT" label="Initialisations">
			<sqlcmd><![CDATA[

			]]></sqlcmd>
		</NODE>
		<NODE name="COPY" label="Copie">
			
			<sqlcmd><![CDATA[
			
				SELECT * FROM  dblink(
					'dbname=[DBNAME] port=[DBPORT] host=[DBHOST] user=[DBUSERNAME] password=[DBPASSWORD]',
					'SELECT base.cti_copy_table
						(
						''dbname=[DBNAME_CONSO] port=[DBPORT_CONSO] host=[DBHOST_CONSO] user=[DBUSERNAME] password=[DBPASSWORD]'',
						''SELECT p_benchmark.*,
							CASE 
								WHEN type_indicateur = ''''GHM'''' THEN t_ghm.code 
								WHEN type_indicateur = ''''GHM5'''' THEN t_ghm5.code 
								ELSE ''''''''
							END::text AS parent_code
						 FROM pmsi.p_benchmark
						 LEFT JOIN pmsi.t_ghm ON parent_id = t_ghm.oid AND type_indicateur = ''''GHM''''
						 LEFT JOIN pmsi.t_ghm5 ON parent_id = t_ghm5.oid AND type_indicateur = ''''GHM5''''
						 WHERE type_ligne IN (''''GRP'''',''''REG'''') OR finess = ''''[FINESS]'''''',
						''temp e_benchmark''
						)
						.,
						TRUNCATE pmsi.p_benchmark.,
						INSERT INTO pmsi.p_benchmark (
							type_ligne,
							finess,
							region_id,
							type_indicateur,
							parent_id,
							date_reference,
							mois_reference,
							indicateur_1,
							indicateur_2,
							indicateur_3
						)
						SELECT 
							type_ligne,
							finess,
							region_id,
							type_indicateur,
							CASE 
								WHEN type_indicateur = ''GHM'' THEN t_ghm.oid 
								WHEN type_indicateur = ''GHM5'' THEN t_ghm5.oid
								ELSE 0
							END::bigint AS parent_id,
							date_reference,
							mois_reference,
							indicateur_1,
							indicateur_2,
							indicateur_3
						FROM e_benchmark
						LEFT JOIN pmsi.t_ghm ON parent_code = t_ghm.code AND type_indicateur = ''GHM''
						LEFT JOIN pmsi.t_ghm5 ON parent_code = t_ghm5.code AND type_indicateur = ''GHM5''
						.,
                        SELECT pmsi.cti_reorganize_benchmark(''0'')
                        .,
						ANALYSE pmsi.p_benchmark
						.,
					'
					) AS toto(xxxx text)
				;
			]]></sqlcmd>	

		</NODE>
	</NODE>
	<NODE name="INIT" label="INITIALISATIONS">
		<NODE label="Calculs groupe">
			<sqlcmd><![CDATA[
					
					SELECT pmsi.cti_reorganize_benchmark('1')
					;
					
			]]></sqlcmd>
		</NODE>
	</NODE>
	<NODE name="POST" label="TRAITEMENTS COMPLEMENTAIRES">
			
	</NODE>
</ROOT>
