<?xml version="1.0" encoding="ISO-8859-15"?>
<VUE name="ACTI000134" 
	label="Activité. Liste des séjours" 
	title="= 'Justificatif occupation' +  ' ' + SELECT.REAPRE2 + ' par critères (' + SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL + ')'" 
	database="iCTI" swf="*CTI_view1" 
	softCode="iCTI_activite"
	globals="ACTI_globals.XML"
	componentsFile="ACTI_components.XML">
	
	<VIEWPROPERTIES>
		
		<PROPERTY dataLink="VIEWPROPERTIES" nameField="name" valueField="value" />
		
		
	</VIEWPROPERTIES>
	
	<SELECTIONS label="Paramètres de l'analyse">
	
		<GROUP>
			<FIELD name="ALIAS_PERIODE" label="" UI="combo" width="220" default="CUM_LAST_MONTH" tree="true" globalListProvider="ALIAS_PERIODE" />
            <FIELD name="PERIODE" label="Période" UI="combo" tree="true" width="200" default="2009-01-01" globalListProvider="DATE_DEBUT"  />
			<FIELD name="TOPERIODE" label="à" UI="combo" tree="true" width="200" default="2009-01-31" globalListProvider="DATE_FIN"  />
		</GROUP>
		
		<GROUP label="Données">
			<FIELD name="DATA" label="" UI="combo" width="250" default="-1" tree="true" >
				<OPTION label="Toutes les données" data="-1" treeLevel="1"/>
				<OPTION label="Entrées" data="ENT" treeLevel="1"/>
				<OPTION label="Entrées et mutations" data="ENTMUT" treeLevel="2"/>
				<OPTION label="Sorties" data="SOR" treeLevel="1"/>
				<OPTION label="Sorties et mutations" data="SORMUT" treeLevel="2"/>
				<OPTION label="Sorties facturées" data="SORFAC" treeLevel="2"/>
				<OPTION label="Sorties non facturées" data="SORNONFAC" treeLevel="2"/>
				<OPTION label="Journées hospitalisés" data="JRN" treeLevel="1"/>
				<OPTION label="Journées et ambulatoires" data="JRNAMB" treeLevel="2"/>
				<OPTION label="Journées hospitalisation" data="JRNHON" treeLevel="2"/>
				<OPTION label="Journées hospitalisés sortis" data="JRNSOR" treeLevel="2"/>
				<OPTION label="Journées hospitalisés facturées" data="JRNSORFAC" treeLevel="3"/>
				<OPTION label="Journées hospitalisation sortis" data="JRNSORHON" treeLevel="3"/>
				<OPTION label="Journées hospitalisation facturées" data="JRNSORHONFAC" treeLevel="3"/>
				<OPTION label="Chambres particulières" data="CP" treeLevel="1"/>
				<OPTION label="Externes" data="EXT" treeLevel="1"/>
				<OPTION label="Ambulatoires" data="AMB" treeLevel="1"/>
				<OPTION label="Séances" data="SEA" treeLevel="1"/>
				<OPTION label="Bébés" data="BB" treeLevel="1"/>
				<OPTION label="Urgences" data="URG" treeLevel="1"/>
				<OPTION label="Décès" data="DECES" treeLevel="1"/>
			</FIELD>
		</GROUP>		
		
	</SELECTIONS>
	
	<SELECTIONS componentName="DAYS_SELECTIONS" />
	
	<SELECTIONS componentName="FILTRES_SEJOURS_SELECTIONS" />
	
	<SELECTIONS componentName="FILTRES_PATIENTS_SELECTIONS" />
	

	<QUERIES>
	
		<QUERY label=""> 
			<SQL optimizer="V_SEJOURS_X" optimizer2="V_MOUVEMENTS_SEJOUR_X">
				<select>
					<![CDATA[
						
						(SELECT 
							v_mouvements_sejour_2.no_sejour, 
							p_patients.nom || ' ' || p_patients.prenom, 
							p_patients.date_naissance,
							v_sejours_1.date_entree, 
							code_postal_code,
							v_sejours_1.sexe_texte_court as code_sexe,
							v_sejours_1.age as age,
							substr(lpad(v_sejours_1.heure_entree, 6, '0'), 1, 2) || ':' || substr(lpad(v_sejours_1.heure_entree, 6, '0'), 3, 2) as heure_entree,
							CASE WHEN v_sejours_1.date_sortie <> '2099-12-31' THEN to_char(v_sejours_1.date_sortie,'YYYY-MM-DD') ELSE '' END::text as date_sortie, 
							CASE WHEN code_sorti = '1' THEN substr(lpad(v_sejours_1.heure_sortie, 6, '0'), 1, 2) || ':' || substr(lpad(v_sejours_1.heure_sortie, 6, '0'), 3, 2) ELSE NULL END as heure_sortie,
							CASE WHEN v_sejours_1.date_sortie <> '2099-12-31' THEN v_sejours_1.date_sortie - v_sejours_1.date_entree ELSE 0 END as duree_sejour, 
							v_sejours_1.mode_entree::text || v_sejours_1.provenance::text as prov,
							v_sejours_1.mode_sortie::text || v_sejours_1.destination::text as dest,
							lieu_sortie_service_code,
							lieu_sortie_etage_code,
							medecin_sejour_nom || ' ' || medecin_sejour_prenom

							

						FROM #V_SEJOURS_X#
						JOIN #V_MOUVEMENTS_SEJOUR_X# ON v_mouvements_sejour_2.no_sejour = v_sejours_1.no_sejour 
						JOIN activite.p_patients ON v_sejours_1.no_patient = p_patients.no_patient
						WHERE 
							v_mouvements_sejour_2.date [VIEW.PERIODE_ENHANCED] 
							AND v_mouvements_sejour_2.no_sejour = v_sejours_1.no_sejour
							AND v_sejours_1.type_sejour <> '9'
							[VIEW.SEJOURS_SELECT]
							[VIEW.JOURS_SELECT] [VIEW.PATIENTS_SELECT]
							
							
						GROUP BY 
							v_mouvements_sejour_2.no_sejour, 
							p_patients.nom, 
							p_patients.prenom, 
							p_patients.date_naissance, 
							v_sejours_1.date_entree, 
							v_sejours_1.heure_entree,
							v_sejours_1.date_sortie,
							v_sejours_1.heure_sortie,
							v_sejours_1.code_sorti,
							code_postal_code,
							v_sejours_1.sexe_texte_court,
							v_sejours_1.age,
							v_sejours_1.mode_entree,
							v_sejours_1.mode_sortie,
							v_sejours_1.provenance,
							v_sejours_1.destination,
							lieu_sortie_service_code,
							lieu_sortie_etage_code,
							lieu_sortie_unite_medicale_code,
							medecin_sejour_nom,
							medecin_sejour_prenom
						ORDER BY 
							v_mouvements_sejour_2.no_sejour
						)
						
						UNION ALL
						
						(SELECT 
							'-9999999', 
							COUNT(DISTINCT v_mouvements_sejour_2.no_sejour)::text || ' séjours, ' || COUNT(DISTINCT v_sejours_1.no_patient)::text || ' patients',
							null,
							null,
							'',
							'',
							base.cti_division(base.cti_sum_distinct_on(distinct array[v_sejours_1.no_sejour::text, v_sejours_1.age::text]), count(distinct v_sejours_1.no_sejour)),
							'',
							null,
							null,
							base.cti_sum_distinct_on(distinct array[v_sejours_1.no_sejour::text, (CASE WHEN date_sortie <> '2099-12-31'::date AND code_sorti = '1' THEN v_sejours_1.date_sortie - v_sejours_1.date_entree ELSE 0 END)::text]),
							--'',
							--'',
							--'',
							--'',
							'',
							'',
							'',
							'',
							''

						FROM #V_SEJOURS_X#
						JOIN #V_MOUVEMENTS_SEJOUR_X# ON v_mouvements_sejour_2.no_sejour = v_sejours_1.no_sejour 
						WHERE 
							date [VIEW.PERIODE_ENHANCED] 
							[VIEW.SEJOURS_SELECT]
							[VIEW.JOURS_SELECT] [VIEW.PATIENTS_SELECT]
							AND v_sejours_1.type_sejour <> '9'
						)
					]]>
				</select>
				<FIELDS>
					<FIELD name="SEJ" />
					<FIELD name="NOM" ifHideNames="Non autorisé" />
					<FIELD name="DNAT" />
					<FIELD name="DENT" />
					<FIELD name="CPOST" />
					<FIELD name="SEXE" />
					<FIELD name="AGE" />
					<FIELD name="HENT" />
					<FIELD name="DSOR" />
					<FIELD name="HSOR" />
					<FIELD name="DUR" />
				<!-- 	<FIELD name="ETA" />
					<FIELD name="LIT" />
					<FIELD name="SER" />
					<FIELD name="MED" /> -->
					<FIELD name="PROV" />
					<FIELD name="DEST" />
					<FIELD name="LSORT" />
					<FIELD name="ETAG" />
					<FIELD name="MEDEC" />
					
					
					
				</FIELDS>
			</SQL>
		</QUERY>
		
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forSelections="false">
			<SQL>
				<select><![CDATA[ 
					
					SELECT 
						'PERIODE_ENHANCED',
						CASE WHEN '[PERIODE]' = '[TOPERIODE]' THEN ' = ' || '''' || to_char(COALESCE(MIN(date),'[PERIODE]'::date), 'YYYY-MM-DD') || '''::date'
							ELSE ' BETWEEN ''' || to_char(COALESCE(MIN(date),'[PERIODE]'::date), 'YYYY-MM-DD') || '''::date AND ''' || to_char(COALESCE(MAX(date),'[TOPERIODE]'::date), 'YYYY-MM-DD') || '''::date'
						END
					FROM 
						activite.p_mouvements_sejour 
					WHERE 
						date BETWEEN '[PERIODE]' AND '[TOPERIODE]' 
						
				]]></select>
				<FIELDS>
					<FIELD name="name" />
					<FIELD name="value" />
				</FIELDS>
			</SQL>
		</QUERY>
		
	</QUERIES>
	
	<PRESENTATION>
	
		<VIEWLINKS>
			
			<VIEWLINK label="Détail séjour" shortLabel="Détail séjour" view="ACTI000020.XML">
			
				<ARG name="SEJOUR" value="ROW.SEJ" />
				
			</VIEWLINK>
		
		</VIEWLINKS>
	
		<ONGLET excelLabel="Liste séjours" label="Liste séjours" >
			
			<DATAGRID title="" total="true" key="SEJ" headerHeight="48"
				totalRowInRows="= ROW.SEJ == '-9999999'" >
				
				
				<COLUMN dataField="SEJ"
					width="100"
					type="Char"
					headerText="No séjour" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text"
					totalComplement="TOTAL" />
				<COLUMN dataField="NOM" 
					type="Char"
					minWidth="150"
					headerText="Nom" 
					textAlign="left" 
					totalFunction="text" 
					totalComplement="*ROW" />
				<COLUMN dataField="SEXE" 
					width="40"
					type="Char" 
					headerText="Sexe" 
					textAlign="right" 
					totalFunction="text">
						<CELLSTYLE name="cellIndicator" value="femme, 12,right middle , 0xEB76B1" condition="ROW.SEXE == 'F'" /> 
						<CELLSTYLE name="cellIndicator" value="homme, 12,right middle , 0x75a0eb " condition="ROW.SEXE == 'M'" />
						<CELLSTYLE name="cellIndicator" value="rectangle, 10, left middle, 0x666666" condition="ROW.SEXE != 'M' &amp;&amp; ROW.SEXE != 'F'" /> 
				</COLUMN>
				<COLUMN dataField="DNAT" 
					width="60"
					type="Date" 
					inputFormat="AAAA-MM-JJ"
					outputFormat="DD/MM/YY"
					headerText="Date naissance" 
					textAlign="right" 
					totalFunction="text" />
				<COLUMN dataField="AGE" 
					width="35"
					type="Number" 
					outputFormat="= if (ROW.SEJ == '-9999999') { return '#,0';} else { return '#';}"
					headerText="Age" 
					textAlign="right" 
					totalFunction="text" />
				<COLUMN dataField="CPOST" 
					width="50"
					type="Char" 
					headerText="Code postal" 
					textAlign="right" 
					totalFunction="text" />
				<COLUMN dataField="DENT" 
					width="60"
					type="Date" 
					inputFormat="AAAA-MM-JJ"
					outputFormat="DD/MM/YY"
					headerText="Date entrée" 
					textAlign="right" 
					totalFunction="text" />
				<COLUMN dataField="HENT" 
					width="50"
					type="Char" 
					headerText="Heure entrée" 
					textAlign="right" 
					totalFunction="text" />
				<COLUMN dataField="DSOR" 
					width="60"
					type="Date" 
					inputFormat="AAAA-MM-JJ"
					outputFormat="DD/MM/YY"
					headerText="Date sortie" 
					textAlign="right" 
					totalFunction="text" />
				<COLUMN dataField="HSOR" 
					width="50"
					type="Char" 
					headerText="Heure sortie" 
					textAlign="right" 
					totalFunction="text" />
				<COLUMN dataField="PROV" 
					width="50"
					type="Char" 
					headerText="ME / Prov." 
					textAlign="right" 
					totalFunction="text" />
				<COLUMN dataField="DEST" 
					width="50"
					type="Char" 
					headerText="MS / Dest." 
					textAlign="right" 
					totalFunction="text" />
				<COLUMN dataField="DUR" 
					type="Number"
					width="50"
					outputFormat="0#j"
					fixed="false"
					headerText="Durée" 
					textAlign="right" 
					totalFunction="text" />
					
				<COLUMN dataField="LSORT" 
					type="Char"
					width="70"
					fixed="false"
					headerText="Service sortie" 
					textAlign="left" 
					totalFunction="text" />
				<COLUMN dataField="ETAG" 
					type="Char"
					width="55"
					fixed="false"
					headerText="Étage sortie" 
					textAlign="left" 
					totalFunction="text" />
				<COLUMN dataField="MEDEC" 
					type="Char"
					minWidth="80"
					maxWidth="150"
					fixed="false"
					headerText="Médecin" 
					textAlign="left" 
					totalFunction="text" /> 
				<!-- <COLUMN dataField="ETA" 
					type="Char"
					width="70"
					fixed="false"
					headerText="Etage" 
					textAlign="left" 
					totalFunction="text" />
				<COLUMN dataField="LIT" 
					type="Char"
					width="55"
					fixed="false"
					headerText="Lit" 
					textAlign="left" 
					totalFunction="text" />
				<COLUMN dataField="SER" 
					type="Char"
					width="70"
					fixed="false"
					headerText="Serv. fact." 
					textAlign="left" 
					totalFunction="text" />
				<COLUMN dataField="MED" 
					type="Char"
					minWidth="80"
					maxWidth="150"
					fixed="false"
					headerText="Médecin" 
					textAlign="left" 
					totalFunction="text" /> -->
<!-- 				<COLUMN dataField="ENT" 
					width="80"
					type="Number" 
					fixed="false"
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'ENT' || SELECT.DATA == 'ENTMUT'"
					outputFormat='#'
					headerText="Entrées" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" />
				<COLUMN dataField="ENTMS" 
					width="70"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'ENTMUT'"
					headerText="Entrées Mutation Service" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" />
				<COLUMN dataField="ENTME" 
					width="70"
					type="Number" 
					fixed="false"
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'ENTMUT'"
					outputFormat='#'
					headerText="Entrées Mutation Etage" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" />
				<COLUMN dataField="SOR" 
					width="70"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'SOR' || SELECT.DATA == 'SORMUT'"
					headerText="Sorties" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" />
				<COLUMN dataField="SORMS" 
					width="70"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'SORMUT'"
					headerText="Sorties Mutation Service" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" />
				<COLUMN dataField="SORME" 
					width="70"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'SORMUT'"
					headerText="Sorties Mutation Etage" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" /> -->
<!-- 				<COLUMN dataField="SORNONFAC" 
					width="70"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'SORNONFAC'"
					headerText="Sorties Non facturées" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" /> -->
<!-- 				<COLUMN dataField="SORFAC" 
					width="70"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'SORFAC'"
					headerText="Sorties facturées" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" /> -->
<!-- 				<COLUMN dataField="JRN" 
					width="88"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'JRN' || SELECT.DATA == 'JRNAMB' || SELECT.DATA == 'JRNHON'"
					headerText="Journées hospitalisés" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" /> -->
	<!-- 			<COLUMN dataField="JRNSOR" 
					width="88"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'JRNSOR'"
					headerText="Journées hospitalisés sortis" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" />
				<COLUMN dataField="JRNSORFAC" 
					width="88"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'JRNSORFAC'"
					headerText="Journées hospitalisés facturées" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" /> -->
<!-- 				<COLUMN dataField="JRNHON" 
					width="104"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'JRNHON' || SELECT.DATA == 'JRNSORHONFAC'"
					headerText="Journées&#xD;hospitalisation" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" />
				<COLUMN dataField="JRNSORHON" 
					width="105"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'JRNSORHON'"
					headerText="Journées&#xD;hospitalisation&#xD;sortis" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" />
				<COLUMN dataField="JRNSORHONFAC" 
					width="105"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'JRNSORHONFAC'"
					headerText="Journées&#xD;hospitalisation&#xD;facturées" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" /> -->
<!-- 				<COLUMN dataField="NCP" 
					width="70"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'CP'"
					headerText="C.P." 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" />
				<COLUMN dataField="AMB" 
					width="70"
					type="Number" 
					fixed="false"
					visible="true"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'AMB' || SELECT.DATA == 'JRNAMB' || SELECT.DATA == 'JRNHON'"
					headerText="Ambulat." 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" />
				
				<COLUMN dataField="SEA" 
					width="70"
					type="Number" 
					fixed="false"
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'SEA' || SELECT.DATA == 'JRNHON'"
					outputFormat='#'
					headerText="Séances" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" /> -->
<!-- 				<COLUMN dataField="EXT" 
					width="70"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'EXT'"
					headerText="Externes" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" />
				<COLUMN dataField="BB" 
					width="70"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'BB'"
					headerText="Bébés" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" />
				<COLUMN dataField="URG" 
					width="70"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'URG'"
					headerText="Urgences" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" />
				<COLUMN dataField="DECES" 
					width="55"
					type="Number" 
					fixed="false"
					outputFormat='#'
					visibleCondition="SELECT.DATA == '-1' || SELECT.DATA == 'DECES'"
					headerText="Décès" 
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum" /> -->
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>
