<?xml version="1.0" encoding="ISO-8859-15"?>
<VUE name="PMSI000210"
	label="PMSI. Etude DMS Nat. +/- 10 jours"
	title="= 'Etude DMS Nat. +/- 10 jours (' + SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL + ')'" 
	database="iCTI" 
	swf="*CTI_view1" 
	softCode="iCTI_pmsi" 
	globals="PMSI_globals.XML" 
	componentsFile="PMSI_components.XML" helpDokuWIkiDir="pmsi:sejours_analyse_globale:dms:ecart_dms:" helpDokuWIkiFile="pmsi000014"  helpFile="pmsi:sejours_analyse_globale:dms:ecart_dms:pmsi000014.html">
	
	<VIEWPROPERTIES>
		<!-- Inutilisé dans la version actuelle de la requête.
		<PROPERTY name="ASO_SELECT" value="[EVAL 
				$select = '';
				if (('[MCO_M]' == 'M') &amp;&amp; ('[MCO_C]' == 'C') &amp;&amp; ('[MCO_O]' == 'O')) {
					$select = ' AND v_rss_1.mcos_code IN ('.''.'M'.''.', '.''.'C'.''.', '.''.'O'.''.')';
				}
				else if (('[MCO_M]' == 'M') &amp;&amp; ('[MCO_C]' == 'C') &amp;&amp; ('[MCO_O]' == 'Z')) {
					$select = ' AND v_rss_1.mcos_code IN ('.''.'M'.''.', '.''.'C'.''.')';
				}
				else if (('[MCO_M]' == 'M') &amp;&amp; ('[MCO_C]' == 'Z') &amp;&amp; ('[MCO_O]' == 'O')) {
					$select = ' AND v_rss_1.mcos_code IN ('.''.'M'.''.', '.''.'O'.''.')';
				}
				else if (('[MCO_M]' == 'M') &amp;&amp; ('[MCO_C]' == 'Z') &amp;&amp; ('[MCO_O]' == 'Z')) {
					$select = ' AND (v_rss_1.mcos_code = '.''.'M'.''.')';
				}
				else if (('[MCO_M]' == 'Z') &amp;&amp; ('[MCO_C]' == 'C') &amp;&amp; ('[MCO_O]' == 'O')) {
					$select = ' AND v_rss_1.mcos_code IN ('.''.'C'.''.', '.''.'O'.''.')';
				}
				else if (('[MCO_M]' == 'Z') &amp;&amp; ('[MCO_C]' == 'C') &amp;&amp; ('[MCO_O]' == 'Z')) {
					$select = ' AND (v_rss_1.mcos_code = '.''.'C'.''.')';
				}
				else if (('[MCO_M]' == 'Z') &amp;&amp; ('[MCO_C]' == 'Z') &amp;&amp; ('[MCO_O]' == 'O')) {
					$select = ' AND (v_rss_1.mcos_code = '.''.'O'.''.')';
				}
				else {
					$select = '';
				}
				return $select;
				EVAL]" />
		-->
	</VIEWPROPERTIES>
	
	<SELECTIONS label="Paramètres de l'analyse" displayText="= var display:String = 'Ecart en jours par rapport à la DMS nationale (hors séances, séjours d\'une nuit ou plus - Hospitalisés)';return display; ">
	
		<GROUP label="Période">
			<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">
			</FIELD>
			<FIELD name="TOPERIODE" label="à" UI="combo" tree="true" width="200" default="2014-12-31" globalListProvider="DATE_FIN">
			</FIELD>
		</GROUP>
		<GROUP label="C.A.S.">
			<FIELD name="CAS_C" label="Chirurgie (C)" UI="check" selectedValue="C" unselectedValue="Z" default="C" showIfNotDefault="true" />
			<FIELD name="CAS_K" label="Techniques peu invasives (K)" UI="check" selectedValue="K" unselectedValue="Z" default="K" showIfNotDefault="true" />
			<FIELD name="CAS_X" label="Sans Acte Classant (X)" UI="check" selectedValue="X" unselectedValue="Z" default="X" showIfNotDefault="true" />
		</GROUP>
		<GROUP label=" ">
			<FIELD name="CAS_N" label="Nouveaux Nés (N)" UI="check" selectedValue="N" unselectedValue="Z" default="N" showIfNotDefault="true" />
			<FIELD name="CAS_O" label="Obstétrique (O)" UI="check" selectedValue="O" unselectedValue="Z" default="O" showIfNotDefault="true" />		
		</GROUP>

	</SELECTIONS>

	<QUERIES>
	
		<QUERY label=""> 
			
			<SQL>
				<select><![CDATA[ 
				
					DROP TABLE IF EXISTS w_count
					;
					-----------------------------------------------------------------
					CREATE TEMP TABLE w_count AS
					(
						SELECT 
							cas_code AS code,
							count (rss_id) AS nb
						FROM
							pmsi.v_rss_1
						WHERE
							duree_sejour > 0
							AND nb_seances = 0
							AND v_rss_1.cas_code IN ('C','K','X','N','O','S','W')
							AND date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						GROUP BY cas_code
					)
					;
					------------------------------------------------------------------
					DROP TABLE IF EXISTS w_table_c
					;
					CREATE TEMP TABLE w_table_c AS
					(
						SELECT 
							cas_code,
							ecart_dms_nationale_ghs as ecart,
							count(rss_id) as nb_c,
							ROUND(100 * (count (rss_id) / (SELECT nb FROM w_count WHERE code = 'C')::NUMERIC), 1) AS pc_c
						FROM
							pmsi.v_rss_1
						WHERE
							cas_code = 'C'
							AND nb_seances = 0
							AND duree_sejour > 0
							AND date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						GROUP BY 1,2
					)
					;
					-------------------------------------------------------------------
					DROP TABLE IF EXISTS w_table_k
					;
					CREATE TEMP TABLE w_table_k AS
					(
						SELECT 
							cas_code,
							ecart_dms_nationale_ghs as ecart,
							count(rss_id) as nb_k,
							ROUND(100 * (count (rss_id) / (SELECT nb FROM w_count WHERE code = 'K')::NUMERIC), 1) AS pc_k
						FROM
							pmsi.v_rss_1
						WHERE
							cas_code = 'K'
							AND nb_seances = 0
							AND duree_sejour > 0
							AND date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						GROUP BY 1,2
					)
					;
					--------------------------------------------------------------------
					DROP TABLE IF EXISTS w_table_x
					;
					CREATE TEMP TABLE w_table_x AS
					(
						SELECT 
							cas_code,
							ecart_dms_nationale_ghs as ecart,
							count(rss_id) as nb_x,
							ROUND(100 * (count (rss_id) / (SELECT nb FROM w_count WHERE code = 'X')::NUMERIC), 1) AS pc_x
						FROM
							pmsi.v_rss_1
						WHERE
							cas_code = 'X'
							AND nb_seances = 0
							AND duree_sejour > 0
							AND date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						GROUP BY 1,2
					)
					;	
					--------------------------------------------------------------------
					DROP TABLE IF EXISTS w_table_n
					;
					CREATE TEMP TABLE w_table_n AS
					(
						SELECT 
							cas_code,
							ecart_dms_nationale_ghs as ecart,
							count(rss_id) as nb_n,
							ROUND(100 * (count (rss_id) / (SELECT nb FROM w_count WHERE code = 'N')::NUMERIC), 1) AS pc_n
						FROM
							pmsi.v_rss_1
						WHERE
							cas_code = 'N'
							AND nb_seances = 0
							AND duree_sejour > 0
							AND date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						GROUP BY 1,2
					)
					;
					-------------------------------------------------------------------------------------	
					DROP TABLE IF EXISTS w_table_o
					;
					CREATE TEMP TABLE w_table_o AS
					(
						SELECT 
							cas_code,
							ecart_dms_nationale_ghs as ecart,
							count(rss_id) as nb_o,
							ROUND(100 * (count (rss_id) / (SELECT nb FROM w_count WHERE code = 'O')::NUMERIC), 1) AS pc_o
						FROM
							pmsi.v_rss_1
						WHERE
							cas_code = 'O'
							AND nb_seances = 0
							AND duree_sejour > 0
							AND date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						GROUP BY 1,2
					)
					;
					-------------------------------------------------------------------------------------	
					
					DROP TABLE IF EXISTS w_ecart;

					CREATE TEMP TABLE w_ecart AS
					(
					(SELECT '<= -10' AS texte, -10 AS ecart) UNION (SELECT '-9' AS texte, -9 AS ecart) UNION (SELECT '-8' AS texte, -8 AS ecart) UNION
					(SELECT '-7' AS texte, -7 AS ecart) UNION (SELECT '-6' AS texte, -6 AS ecart) UNION (SELECT '-5' AS texte, -5 AS ecart) UNION
					(SELECT '-4' AS texte, -4 AS ecart) UNION (SELECT '-3' AS texte, -3 AS ecart) UNION (SELECT '-2' AS texte, -2 AS ecart) UNION
					(SELECT '-1' AS texte, -1 AS ecart) UNION (SELECT '0' AS texte, 0 AS ecart) UNION (SELECT '1' AS texte, 1 AS ecart) UNION
					(SELECT '2' AS texte, 2 AS ecart) UNION (SELECT '3' AS texte, 3 AS ecart) UNION (SELECT '4' AS texte, 4 AS ecart) UNION
					(SELECT '5' AS texte, 5 AS ecart) UNION (SELECT '6' AS texte, 6 AS ecart) UNION (SELECT '7' AS texte, 7 AS ecart) UNION
					(SELECT '8' AS texte, 8 AS ecart) UNION (SELECT '9' AS texte, 9 AS ecart) UNION (SELECT '>= 10' AS texte, 10 AS ecart)
					ORDER BY 2
					);

					-------------------------------------------------------------------------------------
					(
					SELECT
						-10 AS ecart,
						'<= -10' as texte,
						COALESCE((SELECT sum(nb_c) FROM w_table_c WHERE ecart <= -10), 0) AS nb_c,
						ROUND( 100 * (	COALESCE((SELECT sum(nb_c) FROM w_table_c WHERE ecart <= -10), 0) /
								(SELECT sum(nb_c) FROM w_table_c)::NUMERIC), 2) AS pc_c,
						COALESCE((SELECT sum(nb_k) FROM w_table_k WHERE ecart <= -10), 0) AS nb_k,
						ROUND( 100 * (	COALESCE((SELECT sum(nb_k) FROM w_table_k WHERE ecart <= -10), 0) /
								(SELECT sum(nb_k) FROM w_table_k)::NUMERIC), 2) AS pc_k,
						COALESCE((SELECT sum(nb_x) FROM w_table_x WHERE ecart <= -10), 0) AS nb_x,
						ROUND( 100 * (	COALESCE((SELECT sum(nb_x) FROM w_table_x WHERE ecart <= -10), 0) /
								(SELECT sum(nb_x) FROM w_table_x)::NUMERIC), 2) AS pc_x,
						COALESCE((SELECT sum(nb_n) FROM w_table_n WHERE ecart <= -10), 0) AS nb_n,
						ROUND( 100 * (	COALESCE((SELECT sum(nb_n) FROM w_table_n WHERE ecart <= -10), 0) /
								(SELECT sum(nb_n) FROM w_table_n)::NUMERIC), 2) AS pc_n,
						COALESCE((SELECT sum(nb_o) FROM w_table_o WHERE ecart <= -10), 0) AS nb_o,
						ROUND( 100 * (	COALESCE((SELECT sum(nb_o) FROM w_table_o WHERE ecart <= -10), 0) /
								(SELECT sum(nb_o) FROM w_table_o)::NUMERIC), 2) AS pc_o
						
								
					)
					UNION
					(
					SELECT
						w_ecart.ecart AS ecart,
						w_ecart.texte AS texte,
						COALESCE(w_table_c.nb_c, 0) AS nb_c,
						ROUND( 100 * (	COALESCE(w_table_c.nb_c, 0) /
								(SELECT sum(nb_c) FROM w_table_c)::NUMERIC), 2) AS pc_c,
						COALESCE(w_table_k.nb_k, 0) AS nb_k,
						ROUND( 100 * (	COALESCE(w_table_k.nb_k, 0) /
								(SELECT sum(nb_k) FROM w_table_k)::NUMERIC), 2) AS pc_k,
						COALESCE(w_table_x.nb_x, 0) AS nb_x,
						ROUND( 100 * (	COALESCE(w_table_x.nb_x, 0) /
								(SELECT sum(nb_x) FROM w_table_x)::NUMERIC), 2) AS pc_x,
						COALESCE(w_table_n.nb_n, 0) AS nb_n,
						ROUND( 100 * (	COALESCE(w_table_n.nb_n, 0) /
								(SELECT sum(nb_n) FROM w_table_n)::NUMERIC), 2) AS pc_n,
						COALESCE(w_table_o.nb_o, 0) AS nb_o,
						ROUND( 100 * (	COALESCE(w_table_o.nb_o, 0) /
								(SELECT sum(nb_o) FROM w_table_o)::NUMERIC), 2) AS pc_o
						
					FROM
						w_ecart
						LEFT JOIN w_table_c ON w_ecart.ecart = w_table_c.ecart
						LEFT JOIN w_table_k ON w_ecart.ecart = w_table_k.ecart
						LEFT JOIN w_table_x ON w_ecart.ecart = w_table_x.ecart
						LEFT JOIN w_table_n ON w_ecart.ecart = w_table_n.ecart
						LEFT JOIN w_table_o ON w_ecart.ecart = w_table_o.ecart
						

					WHERE w_ecart.ecart BETWEEN -9 AND 9
					)
					UNION
					(
					SELECT
						10 AS ecart,
						'>= 10' AS texte,
						COALESCE((SELECT sum(nb_c) FROM w_table_c WHERE ecart >= 10), 0) AS nb_c,
						ROUND( 100 * (	COALESCE((SELECT sum(nb_c) FROM w_table_c WHERE ecart >= 10), 0) /
								(SELECT sum(nb_c) FROM w_table_c)::NUMERIC), 2) AS pc_c,
						COALESCE((SELECT sum(nb_k) FROM w_table_k WHERE ecart >= 10), 0) AS nb_k,
						ROUND( 100 * (	COALESCE((SELECT sum(nb_k) FROM w_table_k WHERE ecart >= 10), 0) /
								(SELECT sum(nb_k) FROM w_table_k)::NUMERIC), 2) AS pc_k,
						COALESCE((SELECT sum(nb_x) FROM w_table_x WHERE ecart >= 10), 0) AS nb_x,
						ROUND( 100 * (	COALESCE((SELECT sum(nb_x) FROM w_table_x WHERE ecart >= 10), 0) /
								(SELECT sum(nb_x) FROM w_table_x)::NUMERIC), 2) AS pc_x,
						COALESCE((SELECT sum(nb_n) FROM w_table_n WHERE ecart >= 10), 0) AS nb_n,
						ROUND( 100 * (	COALESCE((SELECT sum(nb_n) FROM w_table_n WHERE ecart >= 10), 0) /
								(SELECT sum(nb_n) FROM w_table_n)::NUMERIC), 2) AS pc_n,
						COALESCE((SELECT sum(nb_o) FROM w_table_o WHERE ecart >= 10), 0) AS nb_o,
						ROUND( 100 * (	COALESCE((SELECT sum(nb_o) FROM w_table_o WHERE ecart >= 10), 0) /
								(SELECT sum(nb_o) FROM w_table_o)::NUMERIC), 2) AS pc_o
						
					)
					ORDER BY 1

				]]>
				</select>
				<FIELDS>
					<FIELD name="ECART" />
					<FIELD name="TEXTE" />
					<FIELD name="NBC" />
					<FIELD name="PCC" />											
					<FIELD name="NBK" />
					<FIELD name="PCK" />
					<FIELD name="NBX" />
					<FIELD name="PCX" />
					<FIELD name="NBN" />	
					<FIELD name="PCN" />
					<FIELD name="NBO" />
					<FIELD name="PCO" />
				</FIELDS>
			</SQL>
			
			
		</QUERY>

	</QUERIES>
	
	<PRESENTATION>
		
		<VIEWLINKS>
			<VIEWLINK label="Liste des RSS" shortLabel="Liste RSS" view="PMSI000005.XML">
				<ARG name="T_ECART_DMS" value="return '1'" />
				<ARG name="ECART_DMS_OPERATOR" value="
					if (ROW.ECART == '10') {return '2'}
					else if (ROW.ECART == '-10') {return '3'}
					else {return '1'}
					" />
				<ARG name="ECART_DMS_FIELD1" value="ROW.ECART" />
				<ARG name="CAS_C" value="if (COLUMN.NAME != 'NBK' &amp;&amp; COLUMN.NAME != 'NBX' &amp;&amp; COLUMN.NAME != 'NBN' &amp;&amp; COLUMN.NAME != 'NBO' &amp;&amp; COLUMN.NAME != 'NBS' &amp;&amp; COLUMN.NAME != 'NBW' ) {return 'C'} else {return '0'}" />
				<ARG name="CAS_K" value="if (COLUMN.NAME != 'NBC' &amp;&amp; COLUMN.NAME != 'NBX' &amp;&amp; COLUMN.NAME != 'NBN' &amp;&amp; COLUMN.NAME != 'NBO' &amp;&amp; COLUMN.NAME != 'NBS' &amp;&amp; COLUMN.NAME != 'NBW') {return 'K'} else {return '0'}" />
				<ARG name="CAS_X" value="if (COLUMN.NAME != 'NBC' &amp;&amp; COLUMN.NAME != 'NBK' &amp;&amp; COLUMN.NAME != 'NBN' &amp;&amp; COLUMN.NAME != 'NBO' &amp;&amp; COLUMN.NAME != 'NBS' &amp;&amp; COLUMN.NAME != 'NBW') {return 'X'} else {return '0'}" />
				<ARG name="CAS_N" value="if (COLUMN.NAME != 'NBC' &amp;&amp; COLUMN.NAME != 'NBK' &amp;&amp; COLUMN.NAME != 'NBX' &amp;&amp; COLUMN.NAME != 'NBO' &amp;&amp; COLUMN.NAME != 'NBS' &amp;&amp; COLUMN.NAME != 'NBW') {return 'N'} else {return '0'}" />
				<ARG name="CAS_O" value="if (COLUMN.NAME != 'NBC' &amp;&amp; COLUMN.NAME != 'NBK' &amp;&amp; COLUMN.NAME != 'NBX' &amp;&amp; COLUMN.NAME != 'NBN' &amp;&amp; COLUMN.NAME != 'NBS' &amp;&amp; COLUMN.NAME != 'NBW') {return 'O'} else {return '0'}" />
				

				<ARG name="PERIODE" value="SELECT.PERIODE" />
				<ARG name="TOPERIODE" value="SELECT.TOPERIODE" />
				<!-- séjours hospitalisés d'une nuit au moins -->
				<ARG name="T_DUREE_SEJOUR" value="return '1EX'" />
			</VIEWLINK>
		</VIEWLINKS>
		
		<ONGLET excelLabel="Etude" >
			<CHART title="Répartition DMS en % du nombre total de RSS par Catégories Activités de Soins" 
				type="lineChart" 
				subType="" 
				maxItems="21" 
				maxItemsSortOn="ECART" 
				maxItemsSortSeq="A" 
				sortField="ECART" 
				sortSeq="A">
				<CATEGORY field="TEXTE" type="Char" />
				<SERIE field="PCC" displayName="Chirurgie" visibleCondition="SELECT.CAS_C == 'C'" />
				<SERIE field="PCK" displayName="Techniques peu invasives" visibleCondition="SELECT.CAS_K == 'K'" />
				<SERIE field="PCX" displayName="Sans Acte classant" visibleCondition="SELECT.CAS_X == 'X'" />
				<SERIE field="PCN" displayName="Nouveaux Nés" visibleCondition="SELECT.CAS_N == 'N'" />
				<SERIE field="PCO" displayName="Obstétrique" visibleCondition="SELECT.CAS_O == 'O'" />
			</CHART>
			<DATAGRID title="" headerHeight="36" sortable="false" variableRowHeight="true" total="true" textAlign="center">

				<COLUMN dataField="ECART"
					type="Char"
					visible="false" />
				<COLUMN dataField="TEXTE"
					textAlign="center" 
					type="Char"
					headerText="Ecart en jours"
					width="100"
					totalFunction="text"
					totalComplement="TOTAL"
					largeSeparator="true" />
				<COLUMN dataField="NBC"
					textAlign="center" 
					type="Number"
					outputFormat="#"
					headerText="Nbre RSS Chirurgie"
					selectable="true"
					totalFunction="sum"
					visibleCondition="SELECT.CAS_C == 'C'"
					width="100" />
				<COLUMN dataField="PCC"
					textAlign="center" 
					type="Number"
					outputFormat="0#,0 %"
					headerText="% Chirurgie"
					totalFunction="sum"
					visibleCondition="SELECT.CAS_C == 'C'"
					width="100"
					largeSeparator="true" />
				<COLUMN dataField="NBK"
					textAlign="center" 
					type="Number"
					outputFormat="#"
					headerText="Nbre RSS Tech. peu invasives"
					selectable="true"
					totalFunction="sum"
					visibleCondition="SELECT.CAS_K == 'K'"
					width="100" />
				<COLUMN dataField="PCK"
					textAlign="center" 
					type="Number"
					outputFormat="0#,0 %"
					headerText="% Techniques peu invasives"
					totalFunction="sum"
					visibleCondition="SELECT.CAS_K == 'K'"
					width="100"
					largeSeparator="true" />
				<COLUMN dataField="NBX"
					textAlign="center" 
					type="Number"
					outputFormat="#"
					headerText="Nbre RSS Sans Acte classant"
					selectable="true"
					totalFunction="sum"
					visibleCondition="SELECT.CAS_X == 'X'"
					width="100" />
				<COLUMN dataField="PCX"
					textAlign="center" 
					type="Number"
					outputFormat="0#,0 %"
					headerText="% Sans Acte classant"
					totalFunction="sum"
					visibleCondition="SELECT.CAS_X == 'X'"
					width="100" />
				<COLUMN dataField="NBN"
					textAlign="center" 
					type="Number"
					outputFormat="#"
					headerText="Nbre RSS Nouveaux Nés"
					selectable="true"
					totalFunction="sum"
					visibleCondition="SELECT.CAS_N == 'N'"
					width="100" />
				<COLUMN dataField="PCN"
					textAlign="center" 
					type="Number"
					outputFormat="0#,0 %"
					headerText="% Nouveaux Nés"
					totalFunction="sum"
					visibleCondition="SELECT.CAS_N == 'N'"
					width="100" />
				<COLUMN dataField="NBO"
					textAlign="center" 
					type="Number"
					outputFormat="#"
					headerText="Nbre RSS Obstétrique"
					selectable="true"
					totalFunction="sum"
					visibleCondition="SELECT.CAS_O == 'O'"
					width="100" />
				<COLUMN dataField="PCO"
					textAlign="center" 
					type="Number"
					outputFormat="0#,0 %"
					headerText="% Obstétrique"
					totalFunction="sum"
					visibleCondition="SELECT.CAS_O == 'O'"
					width="100" />				
				<COLUMN 
					textAlign="center" 
					type="Char"
					headerText=""
					minWidth="100" />
			</DATAGRID>
		
		</ONGLET>
		
	</PRESENTATION>
</VUE>
