<?xml version="1.0" encoding="ISO-8859-15"?>
<VUE name="ACTI000065" label="Activité. Liste des présents" title="= 'Liste des ' + SELECT.DATA_LABEL + ' ' + SELECT.REAPRE2 + ' (le ' + SELECT.TOPERIODE_LABEL + ' à ' + SELECT.TOHEURE_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:presents" 
    helpDokuWIkiFile="acti000066" 
>	
<VIEWPROPERTIES>
		<PROPERTYx dataLink="VIEWPROPERTIES" nameField="name" valueField="value" />

		<PROPERTY name="DATA_SELECT">
			<value><![CDATA[
						[EVAL 
							switch ('[DATA]') {
							case 'PRECP':
								return "AND est_chambre_particuliere = '1'";
								break;
							default:
								return "";
							}
						EVAL]
					]]></value>
		</PROPERTY>
		
		<PROPERTY name="REAPRE_SELECT">
			<value><![CDATA[
						[EVAL 
							if ('[REAPRE]' == '1') {return "";}
							if ('[REAPRE]' == '2') {return " AND est_mouvement_previsionnel = '1'";}
							return " AND est_mouvement_previsionnel <> '1'";
						EVAL]
					]]></value>
		</PROPERTY>
		
	</VIEWPROPERTIES>
	
	<SELECTIONS label="Paramètres de l'analyse">
		<GROUP label="Date">
			<FIELD name="TOPERIODE" label="Le" UI="combo" tree="true" width="200" default="2009-01-31" globalListProvider="DATE_FIN" />
			<FIELD name="TOHEURE" label="à" UI="combo" tree="false" width="80" default="12">
				<OPTION label="toute heure" data="-1" />
				<OPTION label="0h" data="0" />
				<OPTION label="1h" data="1" />
				<OPTION label="2h" data="2" />
				<OPTION label="3h" data="3" />
				<OPTION label="4h" data="4" />
				<OPTION label="5h" data="5" />
				<OPTION label="6h" data="6" />
				<OPTION label="7h" data="7" />
				<OPTION label="8h" data="8" />
				<OPTION label="9h" data="9" />
				<OPTION label="10h" data="10" />
				<OPTION label="11h" data="11" />
				<OPTION label="12h" data="12" />
				<OPTION label="13h" data="13" />
				<OPTION label="14h" data="14" />
				<OPTION label="15h" data="15" />
				<OPTION label="16h" data="16" />
				<OPTION label="17h" data="17" />
				<OPTION label="18h" data="18" />
				<OPTION label="19h" data="19" />
				<OPTION label="20h" data="20" />
				<OPTION label="21h" data="21" />
				<OPTION label="22h" data="22" />
				<OPTION label="23h" data="23" />
				<OPTION label="24h" data="24" />
			</FIELD>
		</GROUP>
		<GROUP label="Données">
			<FIELD name="DATA" label="" UI="combo" width="200" default="PRE">
				<OPTION label="Présents" data="PRE" />
				<OPTION label="Présents en chambre particulière" data="PRECP" />
			</FIELD>
			<FIELD name="REAPRE" label="" 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>
	</SELECTIONS>
	
	<SELECTIONS componentName="FILTRES_MOUVEMENTS_SELECTIONS" />
	
	<SELECTIONS componentName="FILTRES_SEJOURS_SELECTIONS" />
	<SELECTIONS componentName="FILTRES_PASSAGES_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, 
							v_sejours_1.age,
							v_sejours_1.sexe_texte_court,
							code_postal_code,
							p_patients.date_naissance,
							v_sejours_1.date_entree, 
							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 '[TOPERIODE]' > v_sejours_1.date_entree THEN '[TOPERIODE]' - v_sejours_1.date_entree ELSE 0 END,
							v_mouvements_sejour_2.lieu_etage_code,
							v_mouvements_sejour_2.lieu_lit_code,
							v_mouvements_sejour_2.lieu_service_code,
							medecin_mouvement_nom
						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_sejours_1.date_sortie >= '[TOPERIODE]'
							AND v_mouvements_sejour_2.date = '[TOPERIODE]'
							AND (
								[TOHEURE] = -1 
								OR (v_mouvements_sejour_2.heure_debut <= [TOHEURE]0000 AND v_mouvements_sejour_2.heure_fin >= [TOHEURE]0000)
								)
							AND service_facturation_est_absence IS DISTINCT FROM '1'

							[VIEW.DATA_SELECT]
							[VIEW.SEJOURS_SELECT] [VIEW.PASSAGES_SELECT]
							[VIEW.MOUVEMENTS_SELECT] [VIEW.REAPRE_SELECT]
							AND v_sejours_1.type_sejour <> '9'
							AND (v_mouvements_sejour_2.est_jour_hospitalisation = '1' OR v_mouvements_sejour_2.nb_ambulatoires > 0 OR v_mouvements_sejour_2.nb_externes > 0)
							
						GROUP BY 
							v_mouvements_sejour_2.no_sejour, 
							p_patients.nom,
							p_patients.prenom,
							v_sejours_1.age,
							v_sejours_1.sexe_texte_court,
							code_postal_code,
							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,
							v_mouvements_sejour_2.lieu_etage_code,
							v_mouvements_sejour_2.lieu_lit_code,
							v_mouvements_sejour_2.lieu_service_code,
							medecin_mouvement_nom
						
						ORDER BY 
							v_mouvements_sejour_2.no_sejour,
							v_mouvements_sejour_2.lieu_etage_code,
							v_mouvements_sejour_2.lieu_service_code,
							medecin_mouvement_nom
						)
						
						UNION ALL
						
						(
						SELECT 
							'-9999999', 
							COUNT(*)::text || ' présents'::text,
							base.cti_division(base.cti_sum_distinct_on(distinct array[v_sejours_1.sejour_id::numeric, v_sejours_1.age::numeric]), count(distinct v_sejours_1.no_sejour)),
							'',
							'',
							null,
							null,
							null,
							null,
							null,
							null,
							'',
							'',
							'',
							''
						FROM #V_SEJOURS_X#
						JOIN #V_MOUVEMENTS_SEJOUR_X# ON v_mouvements_sejour_2.no_sejour = v_sejours_1.no_sejour 
						WHERE 
							v_sejours_1.date_sortie >= '[TOPERIODE]'
							AND date = '[TOPERIODE]'
							AND (
								[TOHEURE] = -1 
								OR (v_mouvements_sejour_2.heure_debut <= [TOHEURE]0000 AND v_mouvements_sejour_2.heure_fin >= [TOHEURE]0000)
								)
							AND service_facturation_est_absence IS DISTINCT FROM '1'
							[VIEW.DATA_SELECT]
							[VIEW.SEJOURS_SELECT] [VIEW.PASSAGES_SELECT]
							[VIEW.MOUVEMENTS_SELECT] [VIEW.REAPRE_SELECT]
							AND v_sejours_1.type_sejour <> '9'
							AND (v_mouvements_sejour_2.est_jour_hospitalisation = '1' OR v_mouvements_sejour_2.nb_ambulatoires > 0 OR v_mouvements_sejour_2.nb_externes > 0)
						)
						ORDER BY 2
					]]>
				</select>
				<FIELDS>
					<FIELD name="SEJ" />
					<FIELD name="NOM" ifHideNames="Non autorisé" />
					<FIELD name="AGE" />
					<FIELD name="SEXE" />
					<FIELD name="CPOST" />
					<FIELD name="DNAT" />
					<FIELD name="DENT" />
					<FIELD name="HENT" />
					<FIELD name="DSOR" />
					<FIELD name="HSOR" />
					<FIELD name="DUR" />
					<FIELD name="ETA" />
					<FIELD name="LIT" />
					<FIELD name="SER" />
					<FIELD name="MED" />
				</FIELDS>
			</SQL>
		</QUERY>
		
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forRows="false" />
		
	</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="NOM" headerHeight="48" totalRowInRows="= ROW.SEJ == '-9999999'">
				<COLUMN dataField="SEJ" frozen="left" width="100" type="Char" headerText="No séjour" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="TOTAL" />
				<COLUMN dataField="NOM" frozen="left" type="Char" minWidth="180" headerText="Nom" textAlign="left" totalFunction="text" totalComplement="*ROW" />
				<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="60" type="Char" outputFormat="HH:MM" 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="60" type="Char" outputFormat="HH:MM" headerText="Heure sortie" textAlign="right" totalFunction="text" />
				<COLUMN dataField="AGE" width="40" type="Number" outputFormat="= if (ROW.SEJ == '-9999999') { return '#,0';} else { return '#';}" headerText="Age" textAlign="right" totalFunction="text" />
				<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="CPOST" width="50" type="Char" headerText="Code postal" textAlign="right" totalFunction="text" />
				<COLUMN dataField="DUR" type="Number" width="60" fixed="false" headerText="Présent depuis" description="Nombre de jours de présence à minuit depuis le début du séjour. C'est la durée de séjour -1 car la journée en cours n'est pas comptée dans la présence." outputFormat="0j" totalFunction="text" />
				<COLUMN dataField="ETA" type="Char" width="70" fixed="false" headerText="Etage" textAlign="left" totalFunction="text" />
				<COLUMN dataField="LIT" type="Char" width="45" 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" />
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>
