<?xml version="1.0" encoding="ISO-8859-15"?>
<VUE name="ACTI000124" label="Activité. Occupation" title="= 'Occupation par ' +  SELECT.GROUPBY_LABEL + ' (' + SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL + ')'" database="iCTI" swf="*CTI_view1" softCode="iCTI_activite" globals="ACTI_globals.XML" componentsFile="ACTI_components.XML" 
    helpFile="iCTI_ACTI_ACTI000123.HTML"
    helpDokuWIkiDir="activite:occupation_sejours:localisation" 
    helpDokuWIkiFile="acti000124" 
>
	<VIEWPROPERTIES componentName="PROPERTIES_OCCUPATION" />
	<VIEWPROPERTIES>
		
		<PROPERTY dataLink="VIEWPROPERTIES" nameField="name" valueField="value" />
		<PROPERTY name="REAPRE_SELECT">
			<value><![CDATA[
						[EVAL 
							if ('[REAPRE]' == '1' && '[ENV.OPTADM_PREVUS]' == '1') {return "";}
							if ('[REAPRE]' == '2' && '[ENV.OPTADM_PREVUS]' == '1') {return " AND est_mouvement_previsionnel = '1'";}
							return " AND est_mouvement_previsionnel <> '1'";
						EVAL]
					]]></value>
		</PROPERTY>
		
	</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="Regroupement">
			<FIELD name="GROUPBY" label="" UI="combo" width="220" tree="true" default="ETA">
				<OPTION label="PLACESREF" data="" globalListProvider="PLACESREF" />
			</FIELD>
			<FIELD name="GROUPBY_TAB" width="100" label="Présentation" UI="combo" default="AUTO" visible="= SELECT.GROUPBY_2 != '-1' ">
				<OPTION label="Automatique" data="AUTO" />
				<OPTION label="Arbre" data="TREE" />
				<OPTION label="Onglet" data="TAB" />
			</FIELD>
		</GROUP>
		<GROUP label="Eclatement">
			<FIELD name="GROUPBY_2" label="" UI="combo" width="200" default="-1" tree="true">
				<OPTION label="" data="-1" />
				<OPTION label="Année" data="ANNEE" />
				<OPTION label="Année-Trimestre" data="TRIM" /> 
				<OPTION label="Année-Mois" data="MOIS" />
				<OPTION label="Trimestre" data="NUMEROTRIM" />
				<OPTION label="Mois" data="NUMEROMOIS" />
				<OPTION label="Semaine" data="NUMEROSEMAINE" />
				<OPTION label="Jour de la semaine" data="NUMEROJOUR" />
				<OPTION label="Jour calendaire" data="JOUR" />
			</FIELD>
		</GROUP>
		
	</SELECTIONS>
	<SELECTIONS componentName="DAYS_SELECTIONS" />
	<SELECTIONS label="Modes de calcul" collapsible="true" displayText="= var display:String='';display=display+'Modes de calcul : #B#'+VIEW.OPTADM_DAYOUT+', '+SELECT.QJMUT_LABEL+'#/B#';return display;">
		<GROUP label="Modes">
			<FIELD name="REAPRE" label="" width="145" UI="combo" default="0" visible="= [ENV.OPTADM_PREVUS] == '1'" showIfNotDefault="true">
				<OPTION data="0" label="Prévus exclus" data2="" />
				<OPTION data="1" label="Prévus inclus" data2="(Réalisation et Prévisions)" />
				<OPTION data="2" label="Uniquement prévus" data2="(Prévisions)" />
			</FIELD>
		</GROUP>
		<GROUP label="">
			<FIELD name="QJMUT" label="" width="350" UI="combo" default="f">
				<OPTION data="d" label="Si mutation, journée affectée à la premiere localisation" />
				<OPTION data="f" label="Si mutation, journée affectée à la dernière localisation" />
				<OPTION data="12" label="Si mutation, journée affectée à la localisation occupée à 12h" />
				<OPTION data="prorata" label="Si mutation, journée affectée au prorata du temps passé" />
			</FIELD>
		</GROUP>
		
	</SELECTIONS>
	<SELECTIONS componentName="FILTRES_OCCUPATION_SOUSSELECTIONS" />
	<SELECTIONS componentName="FILTRES_MOUVEMENTS_SELECTIONS" />
	<SELECTIONS componentName="FILTRES_SEJOURS_SELECTIONS" />
	<SELECTIONS componentName="FILTRES_PATIENTS_SELECTIONS" />
	<SELECTIONS componentName="FILTRES_PASSAGES_SELECTIONS" />
	
	<QUERIES>
		<QUERY>
			<SQL optimizer="V_SEJOURS_X" optimizer2="V_MOUVEMENTS_SEJOUR_X">
				<select><![CDATA[	
					
					CTIPREPAR_TREE
						WORKTABLE{acti000124_placesref} 
						GROUPBY1{[VIEW.GROUPBY_PLACES_OID_FIELD],, [VIEW.GROUPBY_PLACES_COD_FIELD],, [VIEW.GROUPBY_PLACES_TXT_FIELD]} 
						GROUPBY1MODE{TAB}
						GROUPBY2{[VIEW.GROUPBY_2_PLACES_OID_FIELD],, [VIEW.GROUPBY_2_PLACES_COD_FIELD],, [VIEW.GROUPBY_2_PLACES_TXT_FIELD]} 
						SIGNIFDATA{[VIEW.ACTIVITE_SIGNIFICATIVE_DATA],, [ACTIVITE_SIGNIFICATIVE_MODE],, [ACTIVITE_SIGNIFICATIVE_NUMBER]}
					INDICATORS{ 
					
                        SUM(CASE WHEN v_places_1.est_ouvert = '1' THEN v_places_1.nb_lits_theoriques ELSE 0 END),,  
						SUM(CASE WHEN v_places_1.est_ouvert = '1' THEN v_places_1.nb_lits_ouverts ELSE 0 END),, 
						COUNT(DISTINCT date),, 
						COUNT(DISTINCT CASE WHEN v_places_1.est_ouvert = '1' THEN date ELSE NULL END)
					} 
					FROM activite.v_places_1 
					WHERE 
						date BETWEEN '[VIEW.PERIODE]' AND '[VIEW.TOPERIODE]' 
						[VIEW.ETAGE_PLACES_SELECT] [VIEW.JOURS_SELECT]
						
				]]></select>
			</SQL>
			<SQL optimizer="V_SEJOURS_X" optimizer2="V_MOUVEMENTS_SEJOUR_X">
				<select><![CDATA[ 
					
					CTISELECT_TREE 
						WORKTABLE{acti000124} 
						GROUPBY1{[VIEW.GROUPBY_OID_FIELD],, [VIEW.GROUPBY_COD_FIELD],, [VIEW.GROUPBY_TXT_FIELD]} 
						GROUPBY1MODE{TAB} 
						GROUPBY2{[VIEW.GROUPBY_2_OID_FIELD],, [VIEW.GROUPBY_2_COD_FIELD],, [VIEW.GROUPBY_2_TXT_FIELD]} 
						SIGNIFDATA{[VIEW.ACTIVITE_SIGNIFICATIVE_DATA],, [ACTIVITE_SIGNIFICATIVE_MODE],, [ACTIVITE_SIGNIFICATIVE_NUMBER]} 
					INDICATORS{ 
					
						0,,
						0,,
						0,,
						0,,
						
						SUM(nb_entrees_directes) ,, 
						SUM(nb_entrees_mutation_[VIEW.MUTATION_FIELD]) ,, 
						SUM(nb_sorties_directes) ,,
						SUM(nb_sorties_mutation_[VIEW.MUTATION_FIELD]) ,, 
						SUM([VIEW.JOURNEES_FIELD]) ,, 
						SUM([VIEW.CP_FIELD]) ,, 
						SUM(nb_ambulatoires) ,, 
						SUM(nb_seances) ,, 
						SUM(nb_urgences) ,,
						
						SUM([VIEW.JOURNEES_FIELD] + nb_ambulatoires + nb_seances_dans_taux),,
						0,,
						0
					}
					
				FROM #V_SEJOURS_X# 
					JOIN #V_MOUVEMENTS_SEJOUR_X# ON v_mouvements_sejour_2.no_sejour = v_sejours_1.no_sejour 
				WHERE 
					date BETWEEN '[VIEW.PERIODE]' AND '[VIEW.TOPERIODE]' 
					[VIEW.SEJOURS_SELECT] [VIEW.PATIENTS_SELECT] [VIEW.PASSAGES_SELECT]
					[VIEW.MOUVEMENTS_SELECT] [VIEW.REAPRE_SELECT] [VIEW.JOURS_SELECT] 
					AND v_sejours_1.type_sejour <> '9'
				
				
				AFTER{ 
					UPDATE acti000124 SET 
						
						indicateurs[1] = COALESCE(acti000124_placesref.indicateurs[1],0), 
						indicateurs[2] = COALESCE(acti000124_placesref.indicateurs[2],0), 
						indicateurs[3] = COALESCE(acti000124_placesref.indicateurs[3],0), 
						indicateurs[4] = COALESCE(acti000124_placesref.indicateurs[4],0),
						indicateurs[15] = base.cti_division(acti000124.indicateurs[14] , COALESCE(acti000124_placesref.indicateurs[1],0)) * 100,
						indicateurs[16] = base.cti_division(acti000124.indicateurs[14] , COALESCE(acti000124_placesref.indicateurs[2],0)) * 100
						
					FROM acti000124 acti000124_bis
						LEFT JOIN acti000124_placesref ON	(acti000124_placesref.oidt = acti000124_bis.oidt OR acti000124_placesref.oidt = -111) AND 
										(acti000124_placesref.oid1 = acti000124_bis.oid1 OR acti000124_placesref.oid1 = -111) AND 
										(acti000124_placesref.oid2 = acti000124_bis.oid2 OR acti000124_placesref.oid2 = -111) AND 
										(acti000124_placesref.oid3 = acti000124_bis.oid3 OR acti000124_placesref.oid3 = -111) 
					WHERE acti000124_bis.oidt = acti000124.oidt AND 
						acti000124_bis.oid1 = acti000124.oid1 AND 
						acti000124_bis.oid2 = acti000124.oid2 AND 
						acti000124_bis.oid3 = acti000124.oid3 
				} 
				
				]]></select>
				<FIELDS>
					<INSERT name="CTISELECT_TREE_FIELDS" />
					
					<FIELD name="PLA_THEO" />
					<FIELD name="PLA_OUV" />
					<FIELD name="JOUR_PER" />
					<FIELD name="JOUR_OUV" />
					<FIELD name="ENT" />
					<FIELD name="ENTM" />
					<FIELD name="SOR" />
					<FIELD name="SORM" />
					<FIELD name="JRN" />
					<FIELD name="NCP" />
					<FIELD name="AMB" />
					<FIELD name="SEA" />
					<FIELD name="URG" />
					<FIELD name="JOUR_HON" />
					<FIELD name="TAUX_THEO" />
					<FIELD name="TAUX_OUV" />
				</FIELDS>
			</SQL>
		</QUERY>
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forSelections="false">
			<SQL>
				<select><![CDATA[ 
					
						SELECT 
							'TOPERIODE', 
							to_char(COALESCE(MAX(date),'[TOPERIODE]'::date), 'YYYY-MM-DD')
						FROM 
							activite.p_mouvements_sejour 
						WHERE 
							date BETWEEN '[PERIODE]' AND '[TOPERIODE]' [VIEW.REAPRE_SELECT]
					UNION 
						SELECT 
							'PERIODE', 
							to_char(COALESCE(MIN(date),'[PERIODE]'::date), 'YYYY-MM-DD')
						FROM 
							activite.p_mouvements_sejour 
						WHERE 
							date BETWEEN '[PERIODE]' AND '[TOPERIODE]' [VIEW.REAPRE_SELECT]
					UNION ALL
						SELECT 'ANA_CROI_PERIODE', to_char(greatest(	date_trunc('year', '[TOPERIODE]'::date) - INTERVAL  '3 year', 
														(SELECT date_trunc('year', min(date_comptable)) FROM activite.p_chiffrier_comptable)
													)::date, 'YYYY-MM-DD')
					UNION ALL
						SELECT 'ANA_CROI_TOPERIODE', 	to_char(
									least(	date_trunc('year', '[TOPERIODE]'::date) - interval '1 day' + interval '1 year',
												'[TOPERIODE]'::date)
									, 'YYYY-MM-DD')
					UNION ALL
						SELECT 'COMP_PERIODE', to_char(
									greatest(	date_trunc('year', '[TOPERIODE]'::date),
												date_trunc('month', '[PERIODE]'::date))
									, 'YYYY-MM-DD')
					UNION ALL
						SELECT 'COMP_PERIODE_D', to_char(
									greatest(	date_trunc('year', '[TOPERIODE]'::date) - interval '1 year',
												date_trunc('month', '[PERIODE]'::date) - interval '1 year')
									, 'YYYY-MM-DD')
					UNION ALL
						SELECT 'COMP_TOPERIODE_D', 	to_char(
									least(	date_trunc('year', '[TOPERIODE]'::date) - interval '1 day',
												'[TOPERIODE]'::date - interval '1 year')
									, 'YYYY-MM-DD')
									
				]]></select>
				<FIELDS>
					<FIELD name="name" />
					<FIELD name="value" />
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>
	
	<PRESENTATION>
		<VIEWLINKS>
			<VIEWLINK label="Liste des séjours" shortLabel="Séjours" view="ACTI000052.XML" componentName="OCC_BASE_VIEWLINK" component3Name="STANDARD_BASE_VIEWLINK">
				<ARG name="DATA">
					<value><![CDATA[ 
						
						var s:String = '';
						switch (COLUMN.NAME) {
							case 'ENT' :	s = 'ENT'; 		break;
							case 'ENTM' :	s = 'ENTMUT';	break;
							case 'SOR' :	s = 'SOR';		break;
							case 'SORM' :	s = 'SORMUT';	break;
							case 'JRN' :	s = 'JRN';		break;
							case 'JRNM' :	s = 'JRN';		break;
							case 'NCP' :	s = 'CP';		break;
							case 'EXT' :	s = 'EXT';		break;
							case 'EXTM' :	s = 'EXT';		break;
							case 'AMB' :	s = 'AMB';		break;
							case 'AMBM' :	s = 'AMB';		break;
							case 'URG' :	s = 'URG';		break;
							case 'URGM' :	s = 'URG';		break;
							case 'BB' :		s = 'BB';		break;
							case 'BBM' :	s = 'BB';		break;
							case 'SEA' :	s = 'SEA';		break;
							case 'SEAM' :	s = 'SEA';		break;
							case 'JRNHON' :	s = 'JRNHON';	break;
							default :		s = '-1';		break;
						}
						return s;
						
					]]></value>
				</ARG>
			</VIEWLINK>
		</VIEWLINKS>
 		<ONGLET excelLabel="Localisation" label="Localisation" multiTab="true" multiTabBreakField="TABD" multiTabBreakLabelField="TABDL" multiTabBreakLonglabelField="TABDLL">
			<!-- <CHART title="Séjours" type="columnChart" serieIsCategory="true" fromTotal="true">
				<CATEGORY field="TXT" type="Char" />
				<SERIE field="ENT" displayName="Entrées Hospitalisés" />
				<SERIE field="SOR" displayName="Sorties Hospitalisés" />
				<SERIE field="AMB" displayName="Ambulatoires" />
			</CHART> -->
			
			<CHART title="Evolution" type="lineChart" condition="ROW.LVL == '1'">
				<CATEGORY field="COD" type="Char"/>
				<SERIE field="PLA_OUV" displayName="Places effectives"/>
				<SERIE field="JRN" displayName="Journées hospitalisés"/>
				<SERIE field="JOUR_HON" displayName="Journées hospitalisation" />
			</CHART>
			<DATAGRID title="" total="true" showOthers="true" headerHeight="48" selectRowInRows="= ROW.OID == '-9999997'" otherRowInRows="= ROW.OID == '-9999998'" totalRowInRows="= ROW.OID == '-9999999'">
				<INSERT name="DATAGRID_MULTITAB_STYLES" />

				<COLUMN dataField="OID" width="60" type="Char" visible="false" headerText="Oid" />
				<COLUMN dataField="COD" width="70" type="Char" visible="true" headerText="Code" textAlign="left" otherFunction="text" totalFunction="text">
					<INSERT name="COLUMN_COD_MULTITAB_STYLES" />
				</COLUMN>
				<COLUMN dataField="TXT" type="Char" minWidth="200" headerText="SELECT.GROUPBY_LABEL" headerTextCalc="true" textAlign="left" totalFunction="text" totalComplement="TOTAL" otherFunction="text" otherComplement="Autres" />
				
				<COLUMN dataField="PLA_THEO" type="Number" width="80" outputFormat="#" visible="true" headerText="Places&#xD;théoriques" totalFunction="text" otherFunction="text" otherComplement="" 
					description="Nombre de places théoriquement disponibles * Nombre de jours" />
				<COLUMN dataField="TAUX_THEO" width="90" type="Number"  visible="true" outputFormat="0#,0%" headerText="Taux&#xD;d'occupation&#xD;théorique" textAlign="right" totalFunction="text" otherFunction="text"
					description="(Nombre de journées hospitalisées + Nombre d'ambulatoires + Nombre de séances) / (Nombre de places théoriques)" >
					<CELLSTYLE name="fontWeight" value="bold" />
					<CELLSTYLE name="fontSize" value="11" />
				</COLUMN>
				<COLUMN dataField="PLA_OUV" type="Number" width="75" outputFormat="#" visible="true" headerText="Places&#xD;effectives" totalFunction="text" otherFunction="text" otherComplement="" 
					description="Nombre de places ouvertes * Nombre de jours" />
				<COLUMN dataField="TAUX_OUV" width="90" type="Number"  visible="true" outputFormat="0#,0%" headerText="Taux&#xD;d'occupation&#xD;effectif" textAlign="right" totalFunction="text" otherFunction="text"
					description="(Nombre de journées hospitalisées + Nombre d'ambulatoires + Nombre de séances) / (Nombre de places effectives)">
					<CELLSTYLE name="fontWeight" value="bold" />
					<CELLSTYLE name="fontSize" value="11" />
				</COLUMN>
				
				<COLUMN dataField="JOUR_PER" width="63" type="Number" outputFormat="#j" headerText="Jours&#xD;période" textAlign="right" totalFunction="sum" otherFunction="sum"
					description="Nombre de jours de la période d'analyse" />
				<COLUMN dataField="PLA_JOUR" type="Number" width="75" outputFormat="#,0" headerText="Places&#xD;effectives&#xD;/ jour" textAlign="right" totalComplement="" calc="true"
					description="Rapport entre le nombre de lits ouverts sur la période (Places effectives) et le nombre de jours de la période (Jours période)">
					<CALC formula="ROW.PLA_OUV / ROW.JOUR_PER" />
				</COLUMN>
				<COLUMN dataField="JOUR_OUV" width="63" type="Number" outputFormat="#j" headerText="Jours&#xD;ouverts" textAlign="right" totalFunction="sum" otherFunction="sum" 
					description="Nombre de jours ouverts sur la période d'analyse" />
				<COLUMN dataField="ENT" width="63" type="Number" selectable="true" outputFormat="#" headerText="Entrées" textAlign="right" totalFunction="sum" otherFunction="sum"
					description="Nombre d'entrées directes" />
				<COLUMN dataField="ENTM" width="75" type="Number" selectable="true" outputFormat="#" headerTextCalc="true" headerText="'Entrées (mutation ' + VIEW.MUTATION_FIELD_TEXT + ')'" visible="true" textAlign="right" totalFunction="sum" otherFunction="sum" 
					description="Nombre d'entrées par mutation" />
				<COLUMN dataField="EXTAMB" type="Number" visible="false" calc="true">
					<CALC formula="ROW.EXT + ROW.AMB" />
				</COLUMN>
				<COLUMN dataField="SOR" width="60" type="Number" selectable="true" outputFormat="#" headerText="Sorties" textAlign="right" totalFunction="sum" otherFunction="sum" 
					description="Nombre de sorties directes" />
				<COLUMN dataField="SORM" width="75" type="Number" selectable="true" visible="true" outputFormat="#" headerTextCalc="true" headerText="'Sorties (mutation ' + VIEW.MUTATION_FIELD_TEXT + ')'" textAlign="right" totalFunction="sum" otherFunction="sum" 
					description="Nombre de sorties par mutation" />
				<COLUMN dataField="AMB" width="95" selectable="true" type="Number" outputFormat="#" headerText="Ambulatoires" textAlign="right" totalFunction="sum" otherFunction="sum" 
					description="Nombre d'ambulatoires" />
				<COLUMN dataField="SEA" width="65" type="Number" selectable="true" outputFormat="#" headerText="Séances" textAlign="right" totalFunction="sum" otherFunction="sum"
					description="Nombre de séances" />
				<COLUMN dataField="JRN" width="88" type="Number" selectable="true" visible="true" outputFormat="#j" headerText="Journées&#xD;hospitalisés" textAlign="right" totalFunction="sum" otherFunction="sum"
					description="Nombre de journées des séjours hospitalisés" />
				<COLUMN dataField="JOUR_HON" width="100" type="Number" selectable="true" visible="true" outputFormat="#j" headerText="Journées&#xD;hospitalisation" textAlign="right" totalFunction="sum" otherFunction="sum"
					description="Nombre de journées des séjours hospitalisés + Nombre de séances + Nombre d'ambulatoires" />
				<COLUMN dataField="NCP" width="90" selectable="true" type="Number" outputFormat="#j" visible="true" headerText="Journées&#xD;chambres&#xD;particulières" textAlign="right" totalFunction="sum" otherFunction="sum" 
					description="Nombre de journées en chambre particulière" />
				<COLUMN dataField="URG" width="75" selectable="true" type="Number" outputFormat="#" headerText="Urgences" textAlign="right" totalFunction="sum" otherFunction="sum"
					description="Nombre d'entrées en urgences" />
			</DATAGRID>
		</ONGLET>		
	</PRESENTATION>
</VUE>
