<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="PMSI000117" label="PMSI. Liste des patients par critère" title="= 'Liste des patients (' + SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL + ') - ' + SELECT.VERSION_GROUPAGE_LABEL" database="iCTI" swf="*CTI_view1" softCode="iCTI_pmsi" globals="PMSI_globals.XML" componentsFile="PMSI_components.XML" helpDokuWIkiDir="pmsi:file_active" helpDokuWIkiFile="pmsi000114"  helpFile="iCTI_PMSI_PMSI000117.HTML">
	<VIEWPROPERTIES>
		<PROPERTY name="NOM_SELECT">
			<value><![CDATA[[EVAL 
				
				if ('[NOM]' != '') {return 'AND identite_nom ILIKE ' .''. '[NOM]%' .''.  ' ' ;}
				return '';
				
			EVAL]]]></value>
		</PROPERTY>
		<PROPERTYx dataLink="VIEWPROPERTIES" nameField="name" valueField="value" />
		<PROPERTY name="NIP_SELECT">
			<value><![CDATA[[EVAL 
				
				if ('[NIP]' != ''&& Number([NIP]) > 0) {
					return 'AND no_patient ILIKE ' .''. '[NIP]%' .''.  ' ' ;
				}
				else {
					return '';
				}
				
			EVAL]]]></value>
		</PROPERTY>
	</VIEWPROPERTIES>
	<SELECTIONS label="Paramètres de l'analyse" displayText="">
		<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 name="TOPERIODE" label="à" UI="combo" tree="true" width="200" default="2014-12-31" globalListProvider="DATE_FIN" printable="false" />
		</GROUP>
		<GROUP label="Nom">
			<FIELD name="NOM" label="" UI="text" width="200" default="" showIfNotDefault="true" />
		</GROUP>
		<GROUP label="N° Patient (NIP)">
			<FIELD name="NIP" label="" UI="number" width="200" default="" showIfNotDefault="true" />
		</GROUP>
	</SELECTIONS>
	<SELECTIONS componentName="FILTRES_RSS_SELECTIONS" />
	<QUERIES>
		<QUERY label="">
			<SQL optimizer="V_RSS_X">
			<comment><![CDATA[ 			
			
				Calcule pour les patients concernés, leur intervalle d'entrée dans l'établissement
					- Entre 0 et 1 an
					- Entre 1 et 2 ans
					- A partir de 3 ans et plus
			
			]]></comment>
			<select><![CDATA[ 
			
				DROP TABLE IF EXISTS w_patients_intervalle_entree
				;

				CREATE TEMP TABLE w_patients_intervalle_entree AS
					with patients AS (
						SELECT 	
							patient_id,
							v_rss_1.rss_id,
							MIN(date_sortie) AS date_sortie_min
						FROM #V_RSS_X#
						WHERE 
							patient_id > 0 AND 
							v_rss_1.date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]' 
							[VIEW.FILTRE_RSS_SELECT]
						GROUP BY 1,2
						ORDER BY 2)
					SELECT 
						patients.patient_id,
						patients.rss_id,
						patients.date_sortie_min,
						DATE_PART('year', AGE(patients.date_sortie_min, MIN(v_rss_1.date_sortie))) AS intervalle
					FROM #V_RSS_X#
					JOIN patients ON v_rss_1.patient_id = patients.patient_id 
					GROUP BY 1,2,3
					ORDER BY 3 
				;
			
			]]></select>
			</SQL>
			<SQL optimizer="V_RSS_X">
				<select><![CDATA[
					
					(SELECT 
						SUBSTR(MIN(SUBSTR(date_sortie::text || v_rss_1.no_rss::text || '                                   ',1,20)|| v_rss_1.rss_id::text), 21, 50),
						SUBSTR(MIN(SUBSTR(date_sortie::text || v_rss_1.no_rss::text || '                                   ',1,20)|| v_rss_1.no_rss::text), 21, 50),
						CASE WHEN no_patient > 0 THEN no_patient ELSE 0 END,      
						SUBSTR(MIN(SUBSTR(date_sortie::text || v_rss_1.no_rss::text || '                                   ',1,20)|| v_rss_1.finess::text), 21, 50),
						identite_nom || ' ' || identite_prenom, 
						SUBSTR(MIN(SUBSTR(date_sortie::text || v_rss_1.no_rss::text || '                                   ',1,20)|| v_rss_1.ghm_code), 21, 50),
						SUBSTR(MIN(SUBSTR(date_sortie::text || v_rss_1.no_rss::text || '                                   ',1,20)|| v_rss_1.ligne_oap_code), 21, 50),
						SUBSTR(MIN(SUBSTR(date_sortie::text || v_rss_1.no_rss::text || '                                   ',1,20)|| medecin_reference_rss_nom), 21, 50),
						SUBSTR(MIN(SUBSTR(date_sortie::text || v_rss_1.no_rss::text || '                                   ',1,20)|| diagnostic_principal_code), 21, 50),
						SUBSTR(MIN(SUBSTR(date_sortie::text || v_rss_1.no_rss::text || '                                   ',1,20)|| v_rss_1.date_entree::text), 21, 50),
						MIN(date_sortie), 
						SUBSTR(MIN(SUBSTR(date_sortie::text || v_rss_1.no_rss::text || '                                   ',1,20)|| v_rss_1.mode_sortie::text), 21, 50),
						sexe_texte_court, 
						SUBSTR(MIN(SUBSTR(date_sortie::text || v_rss_1.no_rss::text || '                                   ',1,20)|| v_rss_1.age::text), 21, 50),
						v_rss_1.date_naissance, 
						SUBSTR(MIN(SUBSTR(date_sortie::text || v_rss_1.no_rss::text || '                                   ',1,20)|| v_rss_1.code_postal::text), 21, 50), 
						SUM(nb_rsa),
						count(DISTINCT CASE WHEN w_patients_intervalle_entree.intervalle < 1 THEN v_rss_1.patient_id ELSE NULL END),
						count(DISTINCT CASE WHEN w_patients_intervalle_entree.intervalle BETWEEN 1 AND 2 THEN v_rss_1.patient_id ELSE NULL END),
						count(DISTINCT CASE WHEN w_patients_intervalle_entree.intervalle > 2 THEN v_rss_1.patient_id ELSE NULL END)
					FROM #V_RSS_X#
					JOIN w_patients_intervalle_entree ON v_rss_1.patient_id = w_patients_intervalle_entree.patient_id AND v_rss_1.rss_id = w_patients_intervalle_entree.rss_id						
					WHERE 
						date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						[VIEW.FILTRE_RSS_SELECT]
						[VIEW.NOM_SELECT]
						[VIEW.NIP_SELECT]
					GROUP BY 
						v_rss_1.patient_id, 
						no_patient,      
						identite_nom, identite_prenom,
						sexe_texte_court, 
						v_rss_1.date_naissance,
						w_patients_intervalle_entree.intervalle
					)
					
					UNION ALL
					
					(SELECT 
						'-9999999', 
						'',      
						0, 
						'', 
						COUNT(DISTINCT v_rss_1.patient_id)::text || ' patients' , 
						'', 
						'', 
						'', 
						'',       
						null, 
						null, 
						'',      
						'', 
						'', 
						null, 
						'',       
						SUM(nb_rsa),
						count(DISTINCT CASE WHEN w_patients_intervalle_entree.intervalle < 1 THEN v_rss_1.patient_id ELSE NULL END),
						count(DISTINCT CASE WHEN w_patients_intervalle_entree.intervalle BETWEEN 1 AND 2 THEN v_rss_1.patient_id ELSE NULL END),
						count(DISTINCT CASE WHEN w_patients_intervalle_entree.intervalle > 2 THEN v_rss_1.patient_id ELSE NULL END)
					FROM #V_RSS_X#
					JOIN w_patients_intervalle_entree ON v_rss_1.patient_id = w_patients_intervalle_entree.patient_id AND v_rss_1.rss_id = w_patients_intervalle_entree.rss_id		
					WHERE
						date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'	
						[VIEW.FILTRE_RSS_SELECT]
						[VIEW.NOM_SELECT]
					)
					
					ORDER BY 2;
					
				]]></select>
				<FIELDS>
					<FIELD name="OID" />
					<FIELD name="RSS" />
					<FIELD name="PAT" />
					<FIELD name="FIN" />
					<FIELD name="NOM" ifHideNames="Non autorisé" />
					<FIELD name="GHM" />
					<FIELD name="OAP" />
					<FIELD name="MED" />
					<FIELD name="DIAGP" />
					<FIELD name="DATE" />
					<FIELD name="DATS" />
					<FIELD name="MODS" />
					<FIELD name="SEX" />
					<FIELD name="AGE" />
					<FIELD name="DATN" ifHideNames="Non autorisé" />
					<FIELD name="CODP" />
					<FIELD name="NRSA" />
					<FIELD name="PATINT1" />
					<FIELD name="PATINT2" />
					<FIELD name="PATINT3" />
				</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 patients">
			<DATAGRID title="" total="true" key="RSS" headerHeight="48" totalRowInRows="= ROW.OID == '-9999999'">
				<ROWSTYLE name="fontSize" value="11" />
				<FOOTERROWSTYLE name="fontSize" value="11" />
				<COLUMN dataField="OID" type="Char" visible="false" />
				<COLUMN dataField="PAT" width="80" type="Number" visible="true" outputFormat="#" headerText="N° Patient" textAlign="center" otherFunction="text" totalFunction="text" totalComplement="TOTAL" />
				<COLUMN dataField="FIN" width="60" type="Char" visible="true" headerText="Etablissement" textAlign="left" visibleCondition="ENV.CONSOLIDATION == '1'" otherFunction="text" totalFunction="text" totalComplement="" />
				<COLUMN dataField="NOM" minWidth="150" maxWidth="200" type="Char" visible="true" headerText="Nom" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="*ROW" />
				<COLUMN dataField="SEX" width="40" type="Char" visible="true" headerText="Sexe" fixed="false" textAlign="right" otherFunction="text" totalFunction="text">
					<CELLSTYLE name="cellIndicator" value="femme, 12,left middle , 0xEB76B1" condition="ROW.SEX == 'F'" /> 
					<CELLSTYLE name="cellIndicator" value="homme, 12,left middle , 0x75a0eb " condition="ROW.SEX == 'M'" /> 
					<CELLSTYLE name="cellIndicator" value="rectangle, 10,left middle , #FF5001 " condition="ROW.SEX == 'I'" /> 
					<CELLSTYLE name="cellIndicator" value="rectangle, 10, left middle, 0x666666" condition="ROW.SEX != 'F' &amp;&amp; ROW.SEX != 'M' &amp;&amp; ROW.SEX != 'I'" />
				</COLUMN>
				<COLUMN dataField="DATN" width="60" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" visible="true" fixed="false" headerText="Date naissance" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="AGE" width="40" type="Number" outputFormat="#" fixed="false" visible="true" headerText="Age" textAlign="right" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="CODP" width="40" type="Char" outputFormat="#" fixed="false" visible="true" headerText="Code postal" textAlign="right" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="RSS" width="80" type="Number" visible="true" outputFormat="#" headerText="1er Séjour N°RSS" textAlign="center" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="DATE" width="80" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" visible="true" fixed="false" headerText="1er Séjour Date entrée" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="DATS" width="80" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" visible="true" fixed="false" headerText="1er Séjour Date sortie" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="GHM" width="80" type="Char" visible="true" fixed="false" headerText="1er Séjour GHM" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="MED" minWidth="60" maxWidth="150" type="Char" visible="true" fixed="false" headerText="1er Séjour Médecin" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="DIAGP" width="80" type="Char" fixed="false" visible="true" headerText="1er Séjour Diag P" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="NRSA" width="50" visible="true" type="Number" outputFormat="#" fixed="false" headerText="Nb total séjours" textAlign="right" totalFunction="sum" otherFunction="sum" />
				<COLUMN dataField="PATINT1" width="80" visible="true" type="Number" outputFormat="#" fixed="false" headerText="Nouveaux patients (Ets) 0-1 an" textAlign="right" totalFunction="sum" otherFunction="sum" 
					description="Patients dont la première venue dans l'établissement est dans l'intervalle de temps 0-1 an"/>
				<COLUMN dataField="PATINT2" width="80" visible="true" type="Number" outputFormat="#" fixed="false" headerText="Nouveaux patients (Ets) 1-2 ans" textAlign="right" totalFunction="sum" otherFunction="sum" 
					description="Patients dont la première venue dans l'établissement est dans l'intervalle de temps 1-2 ans"/>
				<COLUMN dataField="PATINT3" width="80" visible="true" type="Number" outputFormat="#" fixed="false" headerText="Nouveaux patients (Ets) 3 ans et plus" textAlign="right" totalFunction="sum" otherFunction="sum" 
					description="Patients dont la première venue dans l'établissement est dans l'intervalle de temps 3 ans et plus"/>
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>
