<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="PMSI000212" label="PMSI Indicateurs I.P.A (arrêté 8 juin 2005)" title="= 'Justificatif Indicateurs I.P.A (' + SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL + ')'" database="iCTI" swf="*CTI_view1" softCode="iCTI_pmsi" globals="PMSI_globals.XML" componentsFile="PMSI_components.XML" helpFile="iCTI_PMSI_PMSI000212.HTML">
	<VIEWPROPERTIES>
		<PROPERTYx dataLink="VIEWPROPERTIES" nameField="name" valueField="value"/>
		<PROPERTY name="IPA_SELECT"> 
			<value><![CDATA[[EVAL 
			
				if ('[DATA_IPA]' == '00') {
					$select = '';
				}
				else if ('[DATA_IPA]' == '99') {
					if ('[IPA_MASTER]' == '1') {
						$select = "AND ((v_rss_ipa_2.categorie_ipa_code = '*' AND w_exclu_o_id IS NULL AND v_rss_ipa_2.ipa_est_maitre = '0')
											OR (v_rss_ipa_2.categorie_ipa_code = 'A' AND w_exclu_o_id IS NULL AND v_rss_ipa_2.ipa_est_maitre = '0')
											OR (v_rss_ipa_2.categorie_ipa_code IN ('B', 'C') AND w_exclu_o_id IS NULL AND w_exclu_a_id IS NULL AND v_rss_ipa_2.ipa_est_maitre = '0'))";
					}
					else {
						$select = "AND v_rss_ipa_2.ipa_code NOT LIKE 'D%'";
					}
				}
				else if ('[DATA_IPA]' == '991') {
					$select = "AND v_rss_ipa_2.ipa_code IN ('D05', 'D06')";
				}
				else if ('[DATA_IPA]' == '992') {
					$select = "AND v_rss_ipa_2.ipa_code IN ('D01', 'D02', 'D03', 'D04')";
				}
				else if ('[DATA_IPA]' == '993') {
					$select = "AND v_rss_ipa_2.ipa_code LIKE 'D%'";
				}
				else {
					$key = substr('[DATA_IPA]', 2);
					if (substr('[DATA_IPA]', 1, 1) == 'I') {
						if (substr('[DATA_IPA]', 0, 1) == 'I') {
							$select = "AND v_rss_ipa_2.ipa_id = $key";
						}
						else {
							$select = "AND v_rss_ipa_2.ipa_id <> $key";
						}
					}
					else {
						if (substr('[DATA_IPA]', 0, 1) == 'I') {
							$select = "AND v_rss_ipa_2.categorie_ipa_code = '$key'";
						}
						else {
							$select = "AND v_rss_ipa_2.categorie_ipa_code <> '$key'";
						}
					}
					
				}
				return $select;
				
			EVAL]]]></value>
		</PROPERTY>
		<PROPERTY name="IPA_MASTER"> 
			<value><![CDATA[[EVAL 
			
				if ('[DATA_IPA]' == '00') {
					$select = '';
				}
				else if ('[IPA_MASTER]' == '0') {
					$select = "AND v_rss_ipa_2.ipa_est_maitre = '1'";
				}
				else if ('[IPA_MASTER]' == '1') {
					if ('[DATA_IPA]' == '99') {
					}
					if ('[DATA_IPA]' == '991' || '[DATA_IPA]' == '992' || '[DATA_IPA]' == '993') {
						$select = "AND v_rss_ipa_2.ipa_est_maitre = '0' AND w_exclu_o_id IS NULL AND w_exclu_a_id IS NULL AND w_exclu_bc_id IS NULL AND w_exclu_d_id IS NULL" ;
					}
					else {
						$code = substr('[DATA_IPA]', 2, 1);
						if ($code == 'A') {
							$select = "AND v_rss_ipa_2.ipa_est_maitre = '0' AND w_exclu_o_id IS NULL" ;
						}
						else if ($code == 'B' || $code == 'C') {
							$select = "AND v_rss_ipa_2.ipa_est_maitre = '0' AND w_exclu_o_id IS NULL AND w_exclu_a_id IS NULL" ;
						}
						else if ($code == 'D') {
							$select = "AND v_rss_ipa_2.ipa_est_maitre = '0' AND w_exclu_o_id IS NULL AND w_exclu_a_id IS NULL AND w_exclu_bc_id IS NULL AND w_exclu_d_id IS NULL" ;
						}
						else {
							$select = "AND v_rss_ipa_2.ipa_est_maitre = '0'";
						}
					}
				}
				else {
					if ('[DATA_IPA]' == '991' || '[DATA_IPA]' == '992' || '[DATA_IPA]' == '993' || '[DATA_IPA]' == '99') {
						$select = "AND v_rss_ipa_2.ipa_est_maitre = '1'";
					}
					else {
						if (substr('[DATA_IPA]', 2, 1) == 'A') {
							$select = "AND (v_rss_ipa_2.ipa_est_maitre = '1' OR (v_rss_ipa_2.ipa_est_maitre = '0' AND w_exclu_o_id IS NULL))" ;
						}
						else if (substr('[DATA_IPA]', 2, 1) == 'B' || substr('[DATA_IPA]', 2, 1) == 'C') {
							$select = "AND (v_rss_ipa_2.ipa_est_maitre = '1' OR (v_rss_ipa_2.ipa_est_maitre = '0' AND w_exclu_o_id IS NULL AND w_exclu_a_id IS NULL))" ;
						}
						else {
							$select = "AND v_rss_ipa_2.ipa_est_maitre = '1'";
						}
					}
				}
				return $select;
				
			EVAL]]]></value>
		</PROPERTY>
	</VIEWPROPERTIES>
	<SELECTIONS label="Paramètres de l'analyse" displayText="= var display:String = '';
																if (SELECT.DATA_IPA == '00') {
																}
																else if (SELECT.DATA_IPA == '99') {
																	display = display + '  Codes I.P.A : #B#Toutes les exclusions I.P.A. (Codes commençant par *, A, B ou C)#/B#';
																}
																else if (SELECT.DATA_IPA == '991') {
																	display = display + '  Codes I.P.A :  #B#Chirurgie ambulatoire (D05) et en hospitalisation complète (D06)#/B#';
																}
																else if (SELECT.DATA_IPA == '992') {
																	display = display + '  Codes I.P.A : #B#Médecine interventionnelle (D01), Hospit. partielle séjours (D02), Hospit. partielle séances (D03), Hospit. complète (D04)#/B#';
																}
																else if (SELECT.DATA_IPA == '993') {
																	display = display + '  Codes I.P.A : #B#' + [SELECT.DATA_IPA_LABEL] + ' (Codes commençant par D)#/B#';
																}
																else {
																	display = display + '  Code I.P.A : #B#' + [SELECT.DATA_IPA_LABEL] + '#/B#';
																}
																if (display != '') {
																	if (SELECT.IPA_MASTER == '0') {
																		display = display + ' (indicateur principal)';
																	}
																	else if (SELECT.IPA_MASTER == '1') {
																		display = display + ' (indicateur secondaire)';
																	}
																	else {
																		display = display + ' (indicateur principal ou secondaire)';
																	}
																}
																return display; ">
		<GROUP label="Date sortie">
			<FIELD name="ALIAS_PERIODE" label="" UI="combo" width="220" default="CUM_LAST_MONTH" tree="true" globalListProvider="ALIAS_PERIODE" />
			<FIELD name="PERIODE" label="" UI="combo" tree="true" width="200" default="2014-01-01" globalListProvider="DATE_DEBUT" printable="false">
			</FIELD>
			<FIELD name="TOPERIODE" label="à" UI="combo" tree="true" width="200" default="2014-12-31" globalListProvider="DATE_FIN" printable="false">
			</FIELD>
		</GROUP>
		<GROUP label="Indicateur">
			<FIELD name="DATA_IPA" label="" UI="combo" tree="true" default="00" printable="false" showIfNotDefault="true">
				<OPTION label="Pas de sélection (Base)" data="00"/>
				<OPTION label="Séjours Exclus uniquement (*, A, B et C)" data="99"/>
				<OPTION label="Séjours Médecine uniquement (D01 à D04)" data="992"/>
				<OPTION label="Séjours Chirurgie uniquement (D05, D06)" data="991"/>
				<OPTION label="Séjours Médecine et Chirurgie (D01 à D06)" data="993"/>
				<OPTION dataLink="INDICATEURS_IPA" treeLevelField="lvl" dataField="cod" labelField="txt"/>
			</FIELD>
		</GROUP>
		<GROUP label="">
			<FIELD name="IPA_MASTER" label="" UI="combo" default="0" printable="false" showIfNotDefault="true">
				<OPTION label="Code IPA principal" data="0"/>
				<OPTION label="Code IPA secondaire" data="1"/>
				<OPTION label="Code IPA principal ou secondaire" data="2"/>
			</FIELD>
		</GROUP>
	</SELECTIONS>
	<SELECTIONS componentName="FILTRES_RSS_SELECTIONS"/>
	<QUERIES>
		<QUERY label="">
			<SQL optimizer="V_RSS_X">
				<select><![CDATA[ 
				
				-- Exclusions de la base d'analyse
				
				DROP TABLE IF EXISTS w_exclu_o
				;
				CREATE TEMP TABLE w_exclu_o AS
				SELECT
					rss_id AS w_exclu_o_id
				FROM pmsi.v_rss_ipa_2
				WHERE
					categorie_ipa_code = '*'
					AND ipa_est_maitre = '1'
				;
				CREATE INDEX w_exclu_o_i1 ON w_exclu_o
				USING btree
				(w_exclu_o_id);
				
				-- Séjours d'obstétrique/néonat
				
				DROP TABLE IF EXISTS w_exclu_a
				;
				CREATE TEMP TABLE w_exclu_a AS
				SELECT
					rss_id AS w_exclu_a_id
				FROM pmsi.v_rss_ipa_2
				WHERE
					categorie_ipa_code = 'A'
					AND ipa_est_maitre = '1'
				;
				CREATE INDEX w_exclu_a_i1 ON w_exclu_a
				USING btree
				(w_exclu_a_id);
				
				-- Séjours de chirurgie et de médecine spécialisées
				
				DROP TABLE IF EXISTS w_exclu_bc
				;
				CREATE TEMP TABLE w_exclu_bc AS
				SELECT
					rss_id AS w_exclu_bc_id
				FROM pmsi.v_rss_ipa_2
				WHERE
					categorie_ipa_code IN ('B', 'C')
				;
				CREATE INDEX w_exclu_bc_i1 ON w_exclu_bc
				USING btree
				(w_exclu_bc_id);
				
				-- Séjours de chirurgie et de médecine
				
				DROP TABLE IF EXISTS w_exclu_d
				;
				CREATE TEMP TABLE w_exclu_d AS
				SELECT
					rss_id AS w_exclu_d_id
				FROM pmsi.v_rss_ipa_2
				WHERE
					categorie_ipa_code = 'D'
					AND ipa_est_maitre = '1'
				;
				CREATE INDEX w_exclu_d_i1 ON w_exclu_d
				USING btree
				(w_exclu_d_id);
				
				(SELECT 
					v_rss_1.rss_id, 
					(v_rss_1.no_rss)::text, 
					v_rss_1.finess, 
					p_identites.nom || ' ' || p_identites.prenom, 
					v_rss_1.ghm_code, 
					v_rss_ipa_2.ipa_code,
					v_rss_1.diagnostic_principal_code,
					v_rss_1.diagnostic_relie_code,
					v_rss_1.prestation_principale_code,
					v_rss_1.acte_principal_code
				FROM [VIEW.V_RSS_VIEW_OPTIMIZE]
					LEFT JOIN pmsi.v_rss_ipa_2 ON v_rss_ipa_2.rss_id = v_rss_1.rss_id
					LEFT JOIN w_exclu_o ON w_exclu_o.w_exclu_o_id = v_rss_ipa_2.rss_id
					LEFT JOIN w_exclu_a ON w_exclu_a.w_exclu_a_id = v_rss_ipa_2.rss_id
					LEFT JOIN w_exclu_bc ON w_exclu_bc.w_exclu_bc_id = v_rss_ipa_2.rss_id
					LEFT JOIN w_exclu_d ON w_exclu_d.w_exclu_d_id = v_rss_ipa_2.rss_id
					JOIN pmsi.p_identites ON v_rss_1.rss_id = p_identites.rss_id
				WHERE 
					v_rss_1.date_sortie &gt;= '[PERIODE]' AND v_rss_1.date_sortie &lt;='[TOPERIODE]'
					[VIEW.FILTRE_RSS_SELECT]
					[VIEW.IPA_SELECT]
					[VIEW.IPA_MASTER]
				GROUP BY 1,2,3,4,5,6,7,8,9,10
				)
				
				UNION ALL
				
				(SELECT 
					-9999999, 
					COUNT(DISTINCT v_rss_1.no_rss)::text || ' RSS'::text, 
					'', 
					COUNT(DISTINCT v_rss_1.rss_id)::text || ' séjours, '::text || COUNT(DISTINCT v_rss_1.patient_id)::text || ' patients'::text , 
					'', 
					'', 
					'', 
					'', 
					'', 
					''
				FROM [VIEW.V_RSS_VIEW_OPTIMIZE]
					LEFT JOIN pmsi.v_rss_ipa_2 ON v_rss_ipa_2.rss_id = v_rss_1.rss_id
					LEFT JOIN w_exclu_o ON w_exclu_o.w_exclu_o_id = v_rss_ipa_2.rss_id
					LEFT JOIN w_exclu_a ON w_exclu_a.w_exclu_a_id = v_rss_ipa_2.rss_id
					LEFT JOIN w_exclu_bc ON w_exclu_bc.w_exclu_bc_id = v_rss_ipa_2.rss_id
					LEFT JOIN w_exclu_d ON w_exclu_d.w_exclu_d_id = v_rss_ipa_2.rss_id
					JOIN pmsi.p_identites ON v_rss_1.rss_id = p_identites.rss_id
				WHERE
					v_rss_1.date_sortie &gt;= '[PERIODE]' AND v_rss_1.date_sortie &lt;='[TOPERIODE]'
					[VIEW.FILTRE_RSS_SELECT]
					[VIEW.IPA_SELECT]
					[VIEW.IPA_MASTER]
				)
				
				ORDER BY 2
				]]>
				</select>
				<FIELDS>
					<FIELD name="OID"/>
					<FIELD name="RSS"/>
					<FIELD name="FIN"/>
					<FIELD name="NOM" ifHideNames="Non autorisé"/>
					<FIELD name="GHM"/>
					<FIELD name="IPA"/>
					<FIELD name="DIAGP"/>
					<FIELD name="DIAGR"/>
					<FIELD name="PREST"/>
					<FIELD name="ACTEP"/>
				</FIELDS>
			</SQL>
		</QUERY>
		<QUERY type="comboLink" name="INDICATEURS_IPA">
			<!--
			<SQL select="SELECT code, code || ' - ' || texte FROM base.t_ipa ORDER BY code">
				<FIELDS>
					<FIELD name="cod"/>
					<FIELD name="txt"/>
				</FIELDS>
			</SQL>
			-->
			<SQL select="SELECT code, texte, level FROM pmsi.v_ipa_1 " >
				<FIELDS>
					<FIELD name="cod" />
					<FIELD name="txt" />
					<FIELD name="lvl" />
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>
	<PRESENTATION>
		
		<VIEWLINKS>
			<VIEWLINK label="Détail RSS" shortLabel="Détail RSS" view="PMSI000006.XML">
				<ARG name="OID" value="ROW.OID"/>
			</VIEWLINK>
		</VIEWLINKS>
		
		<ONGLET excelLabel="Liste RSS">
			<DATAGRID title="" total="true" key="RSS" headerHeight="36" totalRowInRows="= ROW.OID == '-9999999'">
				<ROWSTYLE name="fontSize" value="11"/>
				<FOOTERROWSTYLE name="fontSize" value="11"/>
				<COLUMN dataField="OID" type="Char" visible="false" />
				<COLUMN dataField="FIN" width="60" type="Char" visible="true" headerText="Etablissement" textAlign="left" visibleCondition="ENV.CONSOLIDATION == '1'" otherFunction="text" totalFunction="text" totalComplement="" />
				<COLUMN dataField="RSS" width="80" type="Char" visible="true" headerText="N° RSS" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="TOTAL" />
				<COLUMN dataField="NOM" minWidth="150" maxWidth="200" type="Char" visible="true" headerText="Nom" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="*ROW" />
				<COLUMN dataField="IPA" width="50" type="Char" visible="true" headerText="IPA" textAlign="left" otherFunction="text" totalFunction="text">
					<CELLSTYLE name="fontWeight" value="bold" />
				</COLUMN>
				<COLUMN dataField="GHM" width="60" type="Char" visible="true" headerText="GHM" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="DIAGP" width="50" type="Char" visible="true" headerText="Diag Principal" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="DIAGR" width="50" type="Char" visible="true" headerText="Diag Relié" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="PREST" width="70" type="Char" visible="true" headerText="Prestation" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="ACTEP" width="70" type="Char" visible="true" headerText="Acte P" textAlign="left" otherFunction="text" totalFunction="text" />
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>
