<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="PMSI000260" 
	label="PMSI. Etat des dossiers PMSI" 
	title="= 'Etat des dossiers PMSI (' + 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:sejours_analyse_globale:etat_des_dossiers_pmsi" helpDokuWIkiFile="pmsi000261"  helpFile="">
	
	<VIEWPROPERTIES componentName="PROPERTIES_ETATDOSSIER" />
	
	<VIEWPROPERTIES>
		<PROPERTY name="ETAT_SELECT" >
				<value><![CDATA[
						[EVAL 
							if ('[ETAT]' == 'EX') {
								return " AND en_cours = '0'";
							}		
							if ('[ETAT]' == 'NX') {
								return " AND en_cours <> '0'";
							}
							if ('[ETAT]' == 'NXFA') {
								return " AND en_cours <> '0' AND est_facture = '1'";
							}
							if ('[ETAT]' == 'NXNFVA') {
								return " AND en_cours <> '0' AND est_facture IS DISTINCT FROM '1' AND
									est_valide = '1'";
							}
							if ('[ETAT]' == 'NXNFNVGR') {
								return " AND en_cours <> '0' AND est_facture IS DISTINCT FROM '1' AND
									est_valide IS DISTINCT FROM '1' AND est_groupe = '1'";
							}
							if ('[ETAT]' == 'NXNFNVNG') {
								return " AND en_cours <> '0' AND est_facture IS DISTINCT FROM '1' AND
									est_valide IS DISTINCT FROM '1' AND est_groupe IS DISTINCT FROM '1'";
							}
							if ('[ETAT]' == 'NXNGNVGR') {
								return " AND en_cours <> '0' AND est_facture IS DISTINCT FROM '1' AND
									(est_groupe IS DISTINCT FROM '1' OR est_valide IS DISTINCT FROM '1' AND est_groupe = '1')";
							}
							return "";
						EVAL]
				]]></value>
		</PROPERTY>
		<PROPERTY name="NO_RSS_SELECT" >
				<value><![CDATA[
						[EVAL 
						if ('[NO_RSS]' == '') {return "";}
						
						return "
							AND v_rss_1.no_rss 
							= ANY (
								string_to_array(
									regexp_replace(
											trim(
												regexp_replace('[NO_RSS]', '[^0-9]', ' ', 'g')
											)
											, ' +', ' ', 'g'
										)
										, ' '
									)
								)";							
					EVAL]
				]]></value>
		</PROPERTY>
		<PROPERTY name="NO_SEJOUR_SELECT" >
				<value><![CDATA[
						[EVAL 
						if ('[NO_SEJOUR]' == '') {return "";}
						
						return "
                            AND trim(regexp_replace( v_rss_1.no_sejour_administratif  , '[^0-9]', ' '))
							= ANY (
								string_to_array(
									regexp_replace(
											trim(
												regexp_replace('[NO_SEJOUR]', '[^0-9]', ' ', 'g')
											)
											, ' +', ' ', 'g'
										)
										, ' '
									)
								)";							
					EVAL]
				]]></value>
		</PROPERTY>
		<PROPERTY name="NOM_SELECT"  >
				<value><![CDATA[
						[EVAL 
						if ('[NOM]' == '') {return "";}
						
						return "
							ANDidentite_nom || ' ' ||identite_nom_naissance || ' ' ||identite_prenom 
							ILIKE ALL (
								string_to_array(		
									'%' ||
									regexp_replace(
											regexp_replace(
													trim('[NOM]')
													, ' +', ' ', 'g'
											)
									, ' ', '% %', 'g'
									)
									|| '%'

								, ' '
								)
							)";							
					EVAL]
				]]></value>
		</PROPERTY>
		<PROPERTYx dataLink="VIEWPROPERTIES" nameField="name" valueField="value" />
	</VIEWPROPERTIES>
	
	<SELECTIONS label="Paramètres de l'analyse" displayText="= var display:String = '';
	
					if (SELECT.ETAT  != '-1') {
						display = display + 'Etat : #B#' + SELECT.ETAT_LABEL;
						display = display + '#/B# ';
					}
					
					if (SELECT.NO_RSS  != '') {
						display = display + 'N° RSS : #B#' + SELECT.NO_RSS;
						display = display + '#/B# ';
					}
					if (SELECT.NOM  != '') {
						display = display + 'Nom : #B#' + SELECT.NOM;
						display = display + '#/B# ';
					}
					
					
					if (display != '') {
					}
					return display;
					" 
			>
	
	
		<GROUP label="">
			<FIELD name="VIEW_DATATYPE" UI="text" forceValue="ETATDOSSIER" visible="false"  />
		</GROUP>
		
		<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="Etat">
			<FIELD name="ETAT" width="300" label="" UI="combo" default="-1" >
				<OPTION label="Pas de sélection" data="-1" />
				<OPTION label="Expédiés" data="EX" />
				<OPTION label="Non expédiés" data="NX" />
				<OPTION label="Non expédiés et Facturés" data="NXFA" />
				<OPTION label="Non Facturés et Validés" data="NXNFVA" />
				<OPTION label="Non Facturés et Groupés Non Validés" data="NXNFNVGR" />
				<OPTION label="Non Groupés" data="NXNFNVNG" />
				<OPTION label="Non Groupés et Groupés Non Validés" data="NXNGNVGR" />
			</FIELD>
		</GROUP>
		
		<GROUP label="N° de RSS">
			<FIELD name="NO_RSS" label="" UI="textArea" width="550" height="40" default="" showIfNotDefault="true" />
		</GROUP>
		<GROUP label="N° de séjour administratif">
			<FIELD name="NO_SEJOUR" label="" UI="textArea" width="550" height="40" default="" showIfNotDefault="true" />
		</GROUP>
		<GROUP label="Ou Nom">
			<FIELD name="NOM" label="" UI="text" width="550" default="" showIfNotDefault="true">
			</FIELD>
		</GROUP>
		
	</SELECTIONS>
		
	<SELECTIONS componentName="FILTRES_RSS_SELECTIONS" />

	<QUERIES>
		<QUERY label=""> 
			<SQL optimizer="V_RSS_X">
				<select><![CDATA[ 

					SELECT 
						v_rss_1.rss_id,
						v_rss_1.no_rss,
						CASE 
							WHEN v_rss_1.en_cours = '0' THEN 'Expédié'
							WHEN est_facture = '1' THEN 'Facturé'
							WHEN est_valide = '1' THEN 'Validé'
							WHEN est_groupe = '1' THEN 'Groupé'
							ELSE 'Sorti' END
							,
						CASE WHEN no_patient &gt; 0 THEN no_patient ELSE 0 END,
						v_rss_1.no_sejour_administratif,
						v_rss_1.finess,
						identite_nom || ' ' || identite_prenom,
						ghm_code,
						severite_ghm_code,
						ghs_code,
						ligne_oap_code,
						medecin_reference_rss_nom,
						diagnostic_principal_code,
						unite_medicale_principale_code,
						acte_principal_code,
						(min(array[to_char(date_acte, 'YYYYMMDD'::text), medecin_nom]))[2],
						date_entree,
						date_sortie,
						mode_sortie,
						sexe_texte_court,
						age,
						v_rss_1.date_naissance,
						prestation_principale_code,
						nb_rsa,
						nb_rum,
						duree_sejour,
						nb_seances,
						poids_bebe,
						age_gestationnel, 
						CASE WHEN date_groupage <> '20991231' THEN date_groupage ELSE NULL END, 
						CASE WHEN date_facture <> '20991231' THEN date_facture ELSE NULL END
					FROM 
						#V_RSS_X#
						LEFT JOIN pmsi.p_rss_etat ON v_rss_1.rss_id = p_rss_etat.rss_id
						LEFT JOIN pmsi.v_rss_actes_1 ON v_rss_1.rss_id = v_rss_actes_1.rss_id AND acte_code = acte_principal_code  AND activite_ccam = 1   
					WHERE 1=1
						AND date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						[VIEW.ETAT_SELECT]
						[VIEW.NO_RSS_SELECT]
						[VIEW.NO_SEJOUR_SELECT]
						[VIEW.NOM_SELECT]
						[VIEW.FILTRE_RSS_SELECT] 
					GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
					ORDER BY 2
				;
				
				]]></select>
				<FIELDS>
					<FIELD name="OID" />
					<FIELD name="RSS" />
					<FIELD name="EXP" />
					<FIELD name="PAT" />
					<FIELD name="SEJ" />
					<FIELD name="FIN" />
					<FIELD name="NOM"  ifHideNames="Non autorisé"/>
					<FIELD name="GHM" />
					<FIELD name="SEV" />
					<FIELD name="GHS" />
					<FIELD name="OAP" />
					<FIELD name="MED" />
					<FIELD name="DIAGP" />
					<FIELD name="UMP" />
					<FIELD name="ACTEP" />
					<FIELD name="MEDP" />
					<FIELD name="DATE" />
					<FIELD name="DATS" />
					<FIELD name="MODS" />
					<FIELD name="SEX" />
					<FIELD name="AGE" />
					<FIELD name="DATN"  ifHideNames="Non autorisé"/>
					<FIELD name="TYPF" />
					<FIELD name="NRSA"/>
					<FIELD name="NRUM"/>
					<FIELD name="NBJ"/>
					<FIELD name="NSEA"/>
					<FIELD name="PBB"/>
					<FIELD name="AGEST"/>
					<FIELD name="DATG"/>
					<FIELD name="DATF"/>
				</FIELDS>
			</SQL>
			
			<SQL optimizer="V_RSS_X">
				<select><![CDATA[ 

					SELECT 
						-9999999, 
						0, 
						'',
						0,
						'',
						'', 
						count(*)::text || ' séjours, '::text || COUNT(DISTINCT patient_id)::text || ' patients'::text , 
						'',
						'',
						'',
						'',
						'',
						'',
						'',
						'', 
						null,
						null,
						'',
						'',
						0, 
						null,
						'',
						count(*), SUM(nb_rum), SUM(duree_sejour), SUM(nb_seances),
						null,
						null,
						null,
						NULL,
						NULL
					FROM 
						#V_RSS_X#
						LEFT JOIN pmsi.p_rss_etat ON v_rss_1.rss_id = p_rss_etat.rss_id
					WHERE 1=1
						AND date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						[VIEW.ETAT_SELECT]
						[VIEW.NO_RSS_SELECT]
						[VIEW.NO_SEJOUR_SELECT]
						[VIEW.NOM_SELECT]
						[VIEW.FILTRE_RSS_SELECT] 
						
				
					ORDER BY 2
					;
				
				]]></select>
				<FIELDS>
					<FIELD name="OID" />
					<FIELD name="RSS" />
					<FIELD name="EXP" />
					<FIELD name="PAT" />
					<FIELD name="SEJ" />
					<FIELD name="FIN" />
					<FIELD name="NOM"  ifHideNames="Non autorisé"/>
					<FIELD name="GHM" />
					<FIELD name="SEV" />
					<FIELD name="GHS" />
					<FIELD name="OAP" />
					<FIELD name="MED" />
					<FIELD name="DIAGP" />
					<FIELD name="UMP" />
					<FIELD name="ACTEP" />
					<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="NRUM"/>
					<FIELD name="NBJ"/>
					<FIELD name="NSEA"/>
					<FIELD name="PBB"/>
					<FIELD name="AGEST"/>
					<FIELD name="DDR"/>
					<FIELD name="DGR"/>
					<FIELD name="DATG"/>
					<FIELD name="DATF"/>
				</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>
			
			<VIEWLINKx label="Créer un extrait de base" shortLabel="Extrait de base" view="PMSI000055.XML" rowContext="false">

			</VIEWLINKx>


		</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>
				<COLUMN dataField="FIN"
					frozen="left"
					width="60"
					type="Char"
					visible="true"
					headerText="Etablissement" 
					textAlign="left" 
					visibleCondition="ENV.CONSOLIDATION == '1'"
					otherFunction="text"
					totalFunction="text" 
					totalComplement="">
				</COLUMN>
				<COLUMN dataField="RSS"
					frozen="left"
					width="70"
					type="Number"
					visible="true"
					outputFormat="#"
					headerText="N° RSS" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text" 
					totalComplement="TOTAL">
				</COLUMN>
				<COLUMN dataField="PAT"
					frozen="left"
					width="80"
					type="Number"
					visible="true"
					outputFormat="#"
					headerText="N° Patient" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text" 
					totalComplement=""
					visibleCondition="SELECT.NIP != ''">
				</COLUMN>
				<COLUMN dataField="SEJ"
					frozen="left"
					width="80"
					type="Char"
					visible="true"
					outputFormat="#"
					headerText="N° séjour" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text" 
					totalComplement="">
				</COLUMN>
				<COLUMN dataField="NOM"
					frozen="left"
					minWidth="180"
					maxWidth="230"
					type="Char"
					visible="true"
					headerText="Nom" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text"
					totalComplement="*ROW">
				</COLUMN>
				<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>
				<COLUMN dataField="AGE"
					width="40"
					type="Number"
					outputFormat="#"
					fixed="false"
					visible="true"
					headerText="Age" 
					textAlign="right" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="DATE"
					width="60"
					type="Date"
					inputFormat="AAAA-MM-JJ"
					outputFormat="DD/MM/YY"
					visible="true"
					fixed="false"
					headerText="Date entrée" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="DATS"
					width="60"
					type="Date"
					inputFormat="AAAA-MM-JJ"
					outputFormat="DD/MM/YY"
					visible="true"
					fixed="false"
					headerText="Date sortie" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="EXP"
					width="60"
					type="Char"
					visible="true"
					fixed="false"
					headerText="Etat" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="TYPF"
					width="60"
					type="Char"
					visible="true"
					fixed="false"
					headerText="Type fact." 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="DATG"
					width="60"
					type="Date"
					inputFormat="AAAA-MM-JJ"
					outputFormat="DD/MM/YY"
					visible="true"
					fixed="false"
					headerText="Date groupage" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="DATF"
					width="60"
					type="Date"
					inputFormat="AAAA-MM-JJ"
					outputFormat="DD/MM/YY"
					visible="true"
					fixed="false"
					headerText="Date facture" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="GHM"
					width="55"
					type="Char"
					visible="true"
					fixed="false"
					headerText="GHM" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="MED"
					minWidth="60"
					maxWidth="150"
					type="Char"
					visible="true"
					fixed="false"
					headerText="Médecin responsable du séjour" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="UMP"
					width="50"
					type="Char"
					visible="true"
					fixed="false"
					headerText="UM" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="DIAGP"
					width="50"
					type="Char"
					fixed="false"
					visible="true"
					headerText="Diag P" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="ACTEP"
					width="60"
					type="Char"
					fixed="false"
					visible="true"
					headerText="Acte P" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="MEDP"
					minWidth="60"
					maxWidth="150"
					type="Char"
					visible="true"
					fixed="false"
					headerText="Médecin de l'Acte P" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>

			
