<?xml version="1.0" encoding="ISO-8859-15"?>
<VUE name="ACTI000129" 
	label="Activité Expert. Justificatif" 
	title="= 'Justificatif Contrôles Expert (' + SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL + ')'" 
	database="iCTI" 
	swf="*CTI_view1" 
	softCode="iCTI_activite" 
	softOption="iCTI_expert"
	globals="ACTI_globals.XML"
	componentsFile="ACTI_components.XML"
	helpFile="iCTI_ACTI_ACTI000129.HTML"
    helpDokuWIkiDir="activite:qualite:expert" 
    helpDokuWIkiFile="acti000128" 
>
	<CACHE cachable="false" />
	<VIEWPROPERTIES componentName="PROPERTIES_OCCUPATION" />
	<VIEWPROPERTIES>
		
		<PROPERTY dataLink="VIEWPROPERTIES" nameField="name" valueField="value"/>
		<PROPERTY name="EXPERT_CONTROLE_SELECT">
			<value><![CDATA[[EVAL 
				
				$mode = substr('[EXPERT_CONTROLE]',0,2);
				$oid = substr('[EXPERT_CONTROLE]',2);
				if ($mode == 'LS') {
                    $section_id = ACTI_get_section_id('[EXPERT_CONTROLE]');
                    $oid = ACTI_get_classe_oid('[EXPERT_CONTROLE]');
				}
				$subselect = '';
				
				if ($mode == 'LI') {$subselect = " AND expert_controle_id IN (SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)";}
				if ($mode == 'SL') {$subselect = " AND expert_controle_id NOT IN (SELECT to_id FROM activite.t_listes_contenu WHERE liste_id = $oid)";}
				if ($mode == 'LS') {$subselect = " AND expert_controle_id IN (SELECT oid FROM activite.t_expert_controle WHERE $section_id = $oid)";}
				if ($mode == 'C*') {$subselect = " AND expert_controle_id IN (SELECT oid FROM activite.t_expert_controle WHERE code ILIKE ANY (base.cti_select_codes('$oid')))";}
				if ($mode == 'DT') {$subselect = " AND expert_controle_id = $oid ";}
				
				
				
				$mode = substr('[EXPERT_CONTROLE_GRAVITE]',0,2);
				$oid = substr('[EXPERT_CONTROLE_GRAVITE]',2);
				if ($mode == 'DT') {$subselect = "$subselect AND expert_controle_gravite_id = $oid";}
				if ($mode == 'LI' && $oid == "59") {$subselect = "$subselect AND expert_controle_gravite_id IN (5,9)";}
				
			    $mode = substr('[EXPERT_CONTROLE_GRAVITE_ALERTES]',0,2);
                $oid = substr('[EXPERT_CONTROLE_GRAVITE_ALERTES]',2);
                if ($mode == 'D2' && $oid == "99") {$subselect = "$subselect AND alert_exp = '1'";}

                $subselect .= " AND expert_controle_is_active = '1' ";
				
				return "$subselect";
				
			EVAL]]]></value>
		</PROPERTY>
		
	</VIEWPROPERTIES>
	
	<SELECTIONS label="Paramètres de l'analyse" displayText="= var display:String = '';

					if (SELECT.EXPERT_CONTROLE != '-1') {display = display + 'Controle : #B#' + SELECT.EXPERT_CONTROLE_LABEL + '#/B# '}
					
                    if (SELECT.EXPERT_CONTROLE_GRAVITE != '-1') {display += ' #B#(' + SELECT.EXPERT_CONTROLE_GRAVITE_LABEL + ')#/B#'}

                    if (SELECT.EXPERT_CONTROLE_GRAVITE_ALERTES == 'D299') {display += ' #B#(' + 'Alertes' + ')#/B#'}                    
					
					return display;
					">
	
		<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="2009-01-01" globalListProvider="DATE_DEBUT"  printable="false" >
			</FIELD>
			<FIELD name="TOPERIODE" label="à" UI="combo" tree="true" width="200" default="2009-01-01"  globalListProvider="DATE_FIN"  printable="false">
			</FIELD>
		</GROUP>
		
		<GROUP label="Controle Expert">
			<FIELD name="EXPERT_CONTROLE" label="" UI="combo" tree="true" width="400" default="-1" globalListProvider="EXC" showIfNotDefault="true">
			</FIELD>
		</GROUP>
		
		<GROUP label="Gravité">
			<FIELD name="EXPERT_CONTROLE_GRAVITE" label="" UI="combo" default="-1" tree="true">
				<OPTION label="Pas de sélection" data="-1" aliasData="1" treeLevel="1"  />
				<OPTION label="Informations" data="DT0" treeLevel="1"  />
				<OPTION label="Avertissements" data="DT5" treeLevel="1"  />
				<OPTION label="Erreurs" data="DT9" treeLevel="1"  />
				<OPTION label="Avertissements et Erreurs" data="LI59" treeLevel="1"  />
			</FIELD>
		</GROUP>

        <GROUP label="Alertes expert">
            <FIELD name="EXPERT_CONTROLE_GRAVITE_ALERTES" label="Alertes" UI="check" selectedValue="D299" unselectedValue="" default="" showIfNotDefault="true" />
        </GROUP>
        
		<GROUP label="Force">
			<FIELD name="_FORCE_UPDATE" label="" UI="textArea" width="100" height="20" default="" visible="false" />
		</GROUP>		
	</SELECTIONS>
	
	<SELECTIONS componentName="FILTRES_SEJOURS_SELECTIONS" />
	<SELECTIONS componentName="FILTRES_PASSAGES_SELECTIONS" />
	
	<QUERIES>
		<QUERY label=""> 
			<SQL optimizer="V_SEJOURS_X">
				<select><![CDATA[
				
				
					SELECT 
						v_sejours_1.sejour_id,
						v_sejours_1.no_sejour,
						v_sejours_1.finess,
						p_patients.nom || ' ' || p_patients.prenom,
						medecin_adm_sejour_nom,
						date_entree,
						date_sortie,
						mode_sortie,
						sexe_texte_court,
						age,
						duree,
						v_expert_sejour_controle_1.date_signalement,
						v_expert_sejour_controle_1.expert_controle_code,
						v_expert_sejour_controle_1.expert_controle_id,
						v_expert_sejour_controle_1.expert_controle_texte,
						v_expert_sejour_controle_1.expert_controle_gravite_texte,
						v_expert_sejour_controle_1.code_justificatif,
						lieu_sortie_etage_code,
						lieu_sortie_lit_code,
						lieu_sortie_service_code,
						CASE 
							WHEN code_sorti = 1 AND nb_non_facture = 1 THEN 'Non facturé'
							WHEN code_sorti = 0 THEN 'Présent'
							WHEN code_sorti = 1 AND nb_non_facture = 0 THEN 'Facturé'
							ELSE 'Non détermminé'
						END as etat_sejour
					FROM activite.v_expert_sejour_controle_1 
						JOIN #V_SEJOURS_X# ON v_expert_sejour_controle_1.sejour_id = v_sejours_1.sejour_id
						JOIN activite.p_patients ON v_sejours_1.no_patient = p_patients.no_patient 
					WHERE
						(date_sortie >= '[PERIODE]' OR code_sorti <> '1') AND date_entree <= '[TOPERIODE]'
						[VIEW.SEJOURS_SELECT]
						[VIEW.EXPERT_CONTROLE_SELECT]
						[VIEW.PASSAGES_SELECT]
				
					ORDER BY 2
				;
				
				]]></select>
				<FIELDS>
					<FIELD name="OID" />
					<FIELD name="SEJ" />
					<FIELD name="FIN" />
					<FIELD name="NOM"  ifHideNames="Non autorisé"/>
					<FIELD name="MED" />
					<FIELD name="DATE" />
					<FIELD name="DATS" />
					<FIELD name="MODS" />
					<FIELD name="SEX" />
					<FIELD name="AGE" />
					<FIELD name="NBJ"/>
					<FIELD name="CXDS"/>
					<FIELD name="CXC"/>
					<FIELD name="CXI"/>
					<FIELD name="CXT"/>
					<FIELD name="CXG"/>
					<FIELD name="CXJ"/>
					<FIELD name="ETAGE"/>
					<FIELD name="LIT"/>
					<FIELD name="SERVICE"/>
					<FIELD name="SEJ_ETAT"/>
				</FIELDS>
			</SQL>
			
			<SQL optimizer="V_SEJOURS_X">
				<select><![CDATA[
				
				
					SELECT 
						-9999999, 
						COUNT(DISTINCT v_sejours_1.no_sejour)::text || ' séjours, '::text || COUNT(DISTINCT no_patient)::text || ' patients'::text,
						COUNT(*)::text || ' Erreurs'						
					FROM activite.v_expert_sejour_controle_1 
						JOIN #V_SEJOURS_X# ON v_expert_sejour_controle_1.sejour_id = v_sejours_1.sejour_id
					WHERE
						(date_sortie >= '[PERIODE]' OR code_sorti <> '1') AND date_entree <= '[TOPERIODE]'
						[VIEW.SEJOURS_SELECT]
						[VIEW.EXPERT_CONTROLE_SELECT]
						[VIEW.PASSAGES_SELECT]
				;
				
				]]></select>
				<FIELDS>
					<FIELD name="OID" />
					<FIELD name="NOM" />
					<FIELD name="CXT"/>
				</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" >
				
			<DATAGRID title="" total="true" headerHeight="36"  rowHeight="24"
				totalRowInRows="= ROW.OID == '-9999999'">
				<INSERT name="DATAGRID_MULTITAB_STYLES" />
				<COLUMN dataField="OID"
					type="Char"
					visible="false">
				</COLUMN>
				<COLUMN dataField="CXI"
					type="Char"
					visible="false">
				</COLUMN>
				<COLUMN dataField="FIN"
					frozen="left"
					width="60"
					type="Char"
					headerText="Finess" 
					textAlign="left" 
					visibleCondition="ENV.CONSOLIDATION == '1'"
					otherFunction="text"
					totalFunction="text" 
					totalComplement="">
				</COLUMN>
				<COLUMN dataField="SEJ"
					frozen="left"
					width="70"
					type="Char"
					headerText="N° Séjour" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text" 
					totalComplement="TOTAL">
				</COLUMN>
				<COLUMN dataField="NOM"
					frozen="left"
					minWidth="100"
					maxWidth="200"
					type="Char"
					headerText="Nom" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text"
					totalComplement="*ROW">
				</COLUMN>
				<COLUMN dataField="SEX"
					width="45"
					type="Char"
					headerText="Sexe" 
					fixed="false"
					textAlign="right" 
					otherFunction="text"
					totalFunction="text">
					<CELLSTYLE name="cellIndicator" value="femme, 12,right middle , 0xEB76B1" condition="ROW.SEX == 'F'" /> 
					<CELLSTYLE name="cellIndicator" value="homme, 12,right middle , 0x75a0eb " condition="ROW.SEX == 'M'" />
					<CELLSTYLE name="cellIndicator" value="rectangle, 10, left middle, 0x666666" condition="ROW.SEX != 'M' &amp;&amp; ROW.SEX != 'F'" /> 
				</COLUMN>
				<COLUMN dataField="AGE"
					width="40"
					type="Number"
					outputFormat="#"
					fixed="false"
					headerText="Age" 
					textAlign="right" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="DATE"
					width="55"
					type="Date"
					inputFormat="AAAA-MM-JJ"
					outputFormat="DD/MM/YY"
					fixed="false"
					headerText="Date&#xD;entrée" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="DATS"
					width="55"
					type="Date"
					inputFormat="AAAA-MM-JJ"
					outputFormat="DD/MM/YY"
					fixed="false"
					headerText="Date&#xD;sortie" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="MODS"
					width="50"
					type="Char"
					fixed="false"
					headerText="Mode&#xD;sortie" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="NBJ" 
					width="55"
					type="Number" 
					outputFormat="#j" 
					headerText="Durée&#xD;séjour" 
					fixed="false"
					textAlign="right" 
					totalFunction="sum"
					otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="SEJ_ETAT"
					width="75"
					type="Char"
					headerText="Etat" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text"
					totalComplement="*ROW">
				</COLUMN>
				<COLUMN dataField="ETAGE" 
					type="Char"
					width="65"
					fixed="false"
					headerText="Etage&#xD;sortie" 
					textAlign="left" 
					totalFunction="text" />
				<COLUMN dataField="LIT" 
					type="Char"
					width="55"
					fixed="false"
					headerText="Lit&#xD;sortie" 
					textAlign="left" 
					totalFunction="text" />
				<COLUMN dataField="SERVICE" 
					type="Char"
					width="70"
					fixed="false"
					headerText="Service&#xD;sortie" 
					textAlign="left" 
					totalFunction="text" />
				<COLUMN dataField="MED"
					minWidth="60"
					maxWidth="150"
					type="Char"
					fixed="false"
					headerText="Médecin" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="CXDS"
					width="90"
					type="Date"
					inputFormat="AAAA-MM-JJ"
					outputFormat="DD/MM/YY"
					fixed="false"
					headerText="Date&#xD;signalement" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text">
				</COLUMN>
				<COLUMN dataField="CXG"
					width="60"
					type="Char"
					headerText="Gravité" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text"
					totalComplement="">
				</COLUMN>
				<COLUMN dataField="CXC"
					width="120"
					type="Char"
					outputFormat="#"
					headerText="Code contrôle" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text" 
					totalComplement="">
				</COLUMN>
				<COLUMN dataField="CXT"
					minWidth="200"
					type="Char"
					headerText="Texte contrôle" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text"
					totalComplement="">
				</COLUMN>
				<COLUMN dataField="CXJ"
					width="200"
					type="Char"
					headerText="Justificatif contrôle" 
					textAlign="left" 
					otherFunction="text"
					totalFunction="text"
					totalComplement="">
				</COLUMN>
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>