<?xml version="1.0" encoding="ISO-8859-15"?>
<VUE name="PMSI000193" label="PMSI. MIG Cancer" title="= 'MIG Cancer (' + SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL + ')'" database="iCTI" swf="*CTI_view1" softCode="iCTI_pmsi" globals="PMSI_globals.XML" componentsFile="PMSI_components.XML" >
	<VIEWPROPERTIES>
		<PROPERTY dataLink="VIEWPROPERTIES" nameField="name" valueField="value"/>
		<PROPERTY name="PERIODE_D" value="[EVAL
											if ('[TYPE_COMPARAISON]' == 'S') {return '[PERIODE_D]';}
											if ('[TYPE_COMPARAISON]' == '2') {return '[VIEW.WPERIODE_D]';}
											if ('[TYPE_COMPARAISON]' == '3') {return '[VIEW.WPERIODE_D]';}
											return '0001-01-01';
										EVAL]"/>
		<PROPERTY name="TOPERIODE_D" value="[EVAL
											if ('[TYPE_COMPARAISON]' == 'S') {return '[TOPERIODE_D]';}
											if ('[TYPE_COMPARAISON]' == '2') {return '[VIEW.WTOPERIODE_D]';}
											if ('[TYPE_COMPARAISON]' == '3') {return '[VIEW.WTOPERIODE_D]';}
											return '0001-01-01';
										EVAL]"/>
		<PROPERTY name="PERIODE_2D" value="[EVAL
											if ('[TYPE_COMPARAISON]' == '3') {return '[VIEW.WPERIODE_2D]';}
											return '0001-01-01';
										EVAL]"/>
		<PROPERTY name="TOPERIODE_2D" value="[EVAL
											if ('[TYPE_COMPARAISON]' == '3') {return '[VIEW.WTOPERIODE_2D]';}
											return '0001-01-01';
										EVAL]"/>
		<PROPERTY name="CHAMP_SELECT" value="[EVAL
											if ('[CHAMP]' == 'EXGR') {
												$select = return  ' AND (v_rss_x.en_cours = ' .''. '0' .''. ' OR v_rss_x.en_cours_etat = ' .''. 'G' .''. ' OR v_rss_x.en_cours_etat = ' .''. 'V' .''. ' )';
											}
											else {
												if ('[CHAMP]' == 'EXGV') {
													$select = return  ' AND (v_rss_x.en_cours = ' .''. '0' .''. ' OR v_rss_x.en_cours_etat = ' .''. 'V' .''. ' )';
												}
												else {
													if ('[CHAMP]' == 'GR') {
														$select = return  ' AND (v_rss_x.en_cours_etat = ' .''. 'G' .''. ' OR v_rss_x.en_cours_etat = ' .''. 'V' .''. ' )';
													}
													else {
														$select = return  ' AND v_rss_x.en_cours = ' .''. '0' .''. ' ';
													}
												}
											}
										EVAL]"/>
	</VIEWPROPERTIES>
	<SELECTIONS label="Paramètres de l'analyse" displayText="= var display:String = '';
					if (SELECT.CHAMP  == 'EXGR' || SELECT.CHAMP  == 'EXGV' || SELECT.CHAMP  == 'GR') {
						display = display + '  Champ : #B#' + SELECT.CHAMP_LABEL + '#/B#';
					}
					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-07-01" printable="false" globalListProvider="DATE_DEBUT">
			</FIELD>
			<FIELD name="TOPERIODE" label="à" UI="combo" tree="true" width="200" default="2014-12-31" printable="false" globalListProvider="DATE_FIN">
			</FIELD>
		</GROUP>
		<GROUP label="Période précédente">
			<FIELD name="TYPE_COMPARAISON" label="" UI="combo" default="S" printable="false">
				<OPTION label="Pas de comparaison" data="-1"/>
				<OPTION label="Même période sur année précédente" data="2"/>
				<OPTION label="Même période sur deux années précédentes" data="3"/>
				<OPTION label="Saisie période" data="S"/>
			</FIELD>
		</GROUP>
		<GROUP label="">
			<FIELD name="PERIODE_D" label=" " UI="combo" tree="true" width="200" default="2014-01-01" printable="false" globalListProvider="DATE_DEBUT" visible="= SELECT.TYPE_COMPARAISON == 'S'">
			</FIELD>
			<FIELD name="TOPERIODE_D" label="à" UI="combo" tree="true" width="200" default="2014-06-30" printable="false" globalListProvider="DATE_FIN" visible="= SELECT.TYPE_COMPARAISON == 'S'">
			</FIELD>
		</GROUP>
		<GROUP label="Regroupement">
			<FIELD name="REG" label="" UI="combo" default="cmd" printable="false">
				<OPTION label="CMD" data="cmd"/>
				<OPTION label="GHM" data="ghm"/>
			</FIELD>
		</GROUP>
		<GROUP label="Champ">
			<FIELD name="CHAMP" label="" UI="combo" tree="true" width="400" default="EX" globalListProvider="CHAMP" showIfNotDefault="true">
			</FIELD>
		</GROUP>
	</SELECTIONS>
	<QUERIES>
		<QUERY label="">
			<SQL>
				<select><![CDATA[

				DROP TABLE IF EXISTS w_chim
				;

				CREATE TEMP TABLE w_chim AS
					SELECT
						[REG]_id as oid,
						[REG]_code as code,
						[REG]_code||' : '||[REG]_texte as texte,
						sum(CASE WHEN date_sortie >= '[PERIODE]' AND date_sortie <='[TOPERIODE]' THEN nb_rsa ELSE null END) as nsej1,
						COUNT(DISTINCT CASE WHEN date_sortie >= '[PERIODE]' AND date_sortie <='[TOPERIODE]' THEN patient_id ELSE null END) as npat1,
						sum(CASE WHEN date_sortie >= '[VIEW.PERIODE_D]' AND date_sortie <='[VIEW.TOPERIODE_D]' THEN nb_rsa ELSE null END) as nsej2,
						COUNT(DISTINCT CASE WHEN date_sortie >= '[VIEW.PERIODE_D]' AND date_sortie <='[VIEW.TOPERIODE_D]' THEN patient_id ELSE null END) as npat2,
						sum(CASE WHEN date_sortie >= '[VIEW.PERIODE_2D]' AND date_sortie <='[VIEW.TOPERIODE_2D]' THEN nb_rsa ELSE null END) as nsej3,
						COUNT(DISTINCT CASE WHEN date_sortie >= '[VIEW.PERIODE_2D]' AND date_sortie <='[VIEW.TOPERIODE_2D]' THEN patient_id ELSE null END) as npat3
					FROM pmsi.v_rss_1
					WHERE cmd_code <> 90
						AND mco <> '*'
						AND ghm_code NOT IN ('28Z08Z', '28Z09Z')
						AND (ghm_code LIKE '17M05%'
							OR ghm_code LIKE '17M06%'
							OR ghm_code = '28Z07Z'
							OR rss_id IN (SELECT rss_id FROM pmsi.v_rss_diagnostics_1 WHERE type_diagnostic = 'DA' AND diagnostic_code = 'Z511')
							)
						AND (date_sortie >= '[PERIODE]' AND date_sortie <='[TOPERIODE]'
							OR
							date_sortie >= '[VIEW.PERIODE_D]' AND date_sortie <='[VIEW.TOPERIODE_D]'
							OR
							date_sortie >= '[VIEW.PERIODE_2D]' AND date_sortie <='[VIEW.TOPERIODE_2D]'
							)
						[VIEW.CHAMP_SELECT]
					GROUP BY 1,2,3
				;

				DROP TABLE IF EXISTS w_rad
				;

				CREATE TEMP TABLE w_rad AS
					SELECT
						[REG]_id as oid,
						[REG]_code as code,
						[REG]_code||' : '||[REG]_texte as texte,
						sum(CASE WHEN date_sortie >= '[PERIODE]' AND date_sortie <='[TOPERIODE]' THEN nb_rsa ELSE null END) as nsej1,
						COUNT(DISTINCT CASE WHEN date_sortie >= '[PERIODE]' AND date_sortie <='[TOPERIODE]' THEN patient_id ELSE null END) as npat1,
						sum(CASE WHEN date_sortie >= '[VIEW.PERIODE_D]' AND date_sortie <='[VIEW.TOPERIODE_D]' THEN nb_rsa ELSE null END) as nsej2,
						COUNT(DISTINCT CASE WHEN date_sortie >= '[VIEW.PERIODE_D]' AND date_sortie <='[VIEW.TOPERIODE_D]' THEN patient_id ELSE null END) as npat2,
						sum(CASE WHEN date_sortie >= '[VIEW.PERIODE_2D]' AND date_sortie <='[VIEW.TOPERIODE_2D]' THEN nb_rsa ELSE null END) as nsej3,
						COUNT(DISTINCT CASE WHEN date_sortie >= '[VIEW.PERIODE_2D]' AND date_sortie <='[VIEW.TOPERIODE_2D]' THEN patient_id ELSE null END) as npat3
					FROM pmsi.v_rss_1
					WHERE cmd_code <> 90
						AND mco <> '*'
						AND (
							ghm_code IN ('28Z08Z','28Z09Z','28Z10Z','28Z11Z','28Z12Z','28Z13Z')
							OR
							ghm_code LIKE '17K04%'
							OR
							ghm_code LIKE '17K05%'
							OR
							ghm_code LIKE '17K06%'
							OR rss_id IN (SELECT rss_id FROM pmsi.v_rss_actes_4 WHERE actes_id IN (SELECT to_id FROM pmsi.v_listes_3 WHERE liste_code = 'CTI_RAD15_10A'))
							)
						AND (date_sortie >= '[PERIODE]' AND date_sortie <='[TOPERIODE]'
							OR
							date_sortie >= '[VIEW.PERIODE_D]' AND date_sortie <='[VIEW.TOPERIODE_D]'
							OR
							date_sortie >= '[VIEW.PERIODE_2D]' AND date_sortie <='[VIEW.TOPERIODE_2D]'
							)
						[VIEW.CHAMP_SELECT]
					GROUP BY 1,2,3
				;

				DROP TABLE IF EXISTS w_chir
				;

				CREATE TEMP TABLE w_chir AS
					SELECT
						[REG]_id as oid,
						[REG]_code as code,
						[REG]_code||' : '||[REG]_texte as texte,
						sum(CASE WHEN date_sortie >= '[PERIODE]' AND date_sortie <='[TOPERIODE]' THEN nb_rsa ELSE null END) as nsej1,
						COUNT(DISTINCT CASE WHEN date_sortie >= '[PERIODE]' AND date_sortie <='[TOPERIODE]' THEN patient_id ELSE null END) as npat1,
						sum(CASE WHEN date_sortie >= '[VIEW.PERIODE_D]' AND date_sortie <='[VIEW.TOPERIODE_D]' THEN nb_rsa ELSE null END) as nsej2,
						COUNT(DISTINCT CASE WHEN date_sortie >= '[VIEW.PERIODE_D]' AND date_sortie <='[VIEW.TOPERIODE_D]' THEN patient_id ELSE null END) as npat2,
						sum(CASE WHEN date_sortie >= '[VIEW.PERIODE_2D]' AND date_sortie <='[VIEW.TOPERIODE_2D]' THEN nb_rsa ELSE null END) as nsej3,
						COUNT(DISTINCT CASE WHEN date_sortie >= '[VIEW.PERIODE_2D]' AND date_sortie <='[VIEW.TOPERIODE_2D]' THEN patient_id ELSE null END) as npat3
					FROM pmsi.v_rss_1
					WHERE cmd_code <> 90
						AND mco <> '*'
						AND (diagnostic_principal_id IN (SELECT to_id FROM pmsi.v_listes_3 WHERE liste_code = 'CTI001007D')
							OR
							diagnostic_relie_id IN (SELECT to_id FROM pmsi.v_listes_3 WHERE liste_code = 'CTI001007D'))
						AND substr(ghm_code,3,1) = 'C'
						AND (date_sortie >= '[PERIODE]' AND date_sortie <='[TOPERIODE]'
							OR
							date_sortie >= '[VIEW.PERIODE_D]' AND date_sortie <='[VIEW.TOPERIODE_D]'
							OR
							date_sortie >= '[VIEW.PERIODE_2D]' AND date_sortie <='[VIEW.TOPERIODE_2D]'
							)
						[VIEW.CHAMP_SELECT]
					GROUP BY 1,2,3
				;

				(
					SELECT
						'1',
						'0',
						0,
						'CHIM',
						'CHIMIOTHERAPIE',
						sum(nsej1),
						sum(npat1),
						sum(nsej2),
						sum(npat2),
						sum(nsej3),
						sum(npat3)
					FROM w_chim
					HAVING count(*) > 0
				)
				UNION ALL
				(
					SELECT
						'1',
						'1',
						oid,
						code,
						texte,
						nsej1,
						npat1,
						nsej2,
						npat2,
						nsej3,
						npat3
					FROM w_chim
				)
				UNION ALL
				(
					SELECT
						'2',
						'0',
						0,
						'RAD',
						'RADIOTHERAPIE',
						sum(nsej1),
						sum(npat1),
						sum(nsej2),
						sum(npat2),
						sum(nsej3),
						sum(npat3)
					FROM w_rad
					HAVING count(*) > 0
				)
				UNION ALL
				(
					SELECT
						'2',
						'1',
						oid,
						code,
						texte,
						nsej1,
						npat1,
						nsej2,
						npat2,
						nsej3,
						npat3
					FROM w_rad
				)
				UNION ALL
				(
					SELECT
						'3',
						'0',
						0,
						'CHIR',
						'CHIRURGIE',
						sum(nsej1),
						sum(npat1),
						sum(nsej2),
						sum(npat2),
						sum(nsej3),
						sum(npat3)
					FROM w_chir
					HAVING count(*) > 0
				)
				UNION ALL
				(
					SELECT
						'3',
						'1',
						oid,
						code,
						texte,
						nsej1,
						npat1,
						nsej2,
						npat2,
						nsej3,
						npat3
					FROM w_chir
				)
				ORDER BY 1, 2, 3
				;

				]]></select>
				<FIELDS>
					<FIELD name="CHAP"/>
					<FIELD name="LVL"/>
					<FIELD name="OID"/>
					<FIELD name="COD"/>
					<FIELD name="TXT"/>
					<FIELD name="NBSEJ"/>
					<FIELD name="NBPAT"/>
					<FIELD name="NBSEJD"/>
					<FIELD name="NBPATD"/>
					<FIELD name="NBSEJ2D"/>
					<FIELD name="NBPAT2D"/>
				</FIELDS>
			</SQL>
		</QUERY>
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forSelections="false">
			<SQL select="SELECT 'WPERIODE_D', (date '[PERIODE]' + interval '1 day' - interval '1 year' - interval '1 day')::date
						UNION ALL
						SELECT 'WTOPERIODE_D', (date '[TOPERIODE]' + interval '1 day' - interval '1 year' - interval '1 day')::date
						UNION ALL
						SELECT 'WPERIODE_2D', (date '[PERIODE]' + interval '1 day' - interval '2 year' - interval '1 day')::date
						UNION ALL
						SELECT 'WTOPERIODE_2D', (date '[TOPERIODE]' + interval '1 day' - interval '2 year' - interval '1 day')::date
						">
				<FIELDS>
					<FIELD name="name"/>
					<FIELD name="value"/>
				</FIELDS>
			</SQL>
			<SQL select="SELECT 'PERIODE_D_LABEL',
							CASE WHEN extract(day from p_calendrier.date) &gt; 1 THEN p_calendrier.texte_court ELSE p_calendrier_mois.texte_court END
							FROM base.p_calendrier, base.p_calendrier_mois
							WHERE
							p_calendrier.mois = p_calendrier_mois.mois
							AND (p_calendrier.date + interval '1 day' + interval '1 year' - interval '1 day')::date = '[PERIODE]'
						UNION ALL
							SELECT 'TOPERIODE_D_LABEL',
							CASE WHEN dernier_jour = '1' THEN p_calendrier_mois.texte_court ELSE p_calendrier.texte_court END
							FROM base.p_calendrier, base.p_calendrier_mois
							WHERE
							p_calendrier.mois = p_calendrier_mois.mois
							AND (p_calendrier.date + interval '1 day' + interval '1 year' - interval '1 day')::date = '[TOPERIODE]'
						UNION ALL
						SELECT 'PERIODE_2D_LABEL',
							CASE WHEN extract(day from p_calendrier.date) &gt; 1 THEN p_calendrier.texte_court ELSE p_calendrier_mois.texte_court END
							FROM base.p_calendrier, base.p_calendrier_mois
							WHERE
							p_calendrier.mois = p_calendrier_mois.mois
							AND (p_calendrier.date + interval '1 day' + interval '2 year' - interval '1 day')::date = '[PERIODE]'
						UNION ALL
							SELECT 'TOPERIODE_2D_LABEL',
							CASE WHEN dernier_jour = '1' THEN p_calendrier_mois.texte_court ELSE p_calendrier.texte_court END
							FROM base.p_calendrier, base.p_calendrier_mois
							WHERE
							p_calendrier.mois = p_calendrier_mois.mois
							AND (p_calendrier.date + interval '1 day' + interval '2 year' - interval '1 day')::date = '[TOPERIODE]'
						">
				<FIELDS>
					<FIELD name="name"/>
					<FIELD name="value"/>
				</FIELDS>
			</SQL>
			<SQL select="SELECT 'SEUIL_YYYY',
							CASE WHEN extract('year' FROM '[TOPERIODE]'::date) = 2008 THEN '2008'
							WHEN extract('year' FROM '[TOPERIODE]'::date) = 2009 THEN '2009'
							WHEN extract('year' FROM '[TOPERIODE]'::date) = 2010 THEN '2010'
							WHEN extract('year' FROM '[TOPERIODE]'::date) = 2011 THEN '2011'
							ELSE '2010' END
						">
				<FIELDS>
					<FIELD name="name"/>
					<FIELD name="value"/>
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>
	<PRESENTATION>
		<VIEWLINKS>
			<VIEWLINK label="Liste des RSS" shortLabel="Liste RSS" view="PMSI000194.XML">
				<ARG name="PERIODE" value="	
					switch(COLUMN.NAME){
						case 'NBSEJ' :
							return SELECT.PERIODE;
						case 'NBSEJD' :
							if(SELECT.TYPE_COMPARAISON == 'S'){
								return SELECT.PERIODE_D;
							}else{
								return VIEW.WPERIODE_D;
							}
						case 'NBSEJ2D' :
								return VIEW.WPERIODE_2D;
							break;
					}
				"/>
				<ARG name="TOPERIODE" value="
					switch(COLUMN.NAME){
						case 'NBSEJ' :
							return SELECT.TOPERIODE;
						case 'NBSEJD' :
							if(SELECT.TYPE_COMPARAISON == 'S'){
								return SELECT.TOPERIODE_D;
							}else{
								return VIEW.WTOPERIODE_D;
							}
						case 'NBSEJ2D' :
								return VIEW.WTOPERIODE_2D;
							break;
					}
				"/>
				<ARG name="DATALVL" value="return ROW.LVL"/>
				<ARG name="DATAREG" value="return SELECT.REG"/>
				<ARG name="DATACOD" value="return ROW.COD"/>
				<ARG name="DATACHAP" value="return ROW.CHAP"/>
				<ARG name="CHAMP" value="return VIEW.CHAMP"/>
			</VIEWLINK>
			<VIEWREF label="Calcul de la file active de patients considerée pour le calibrage de la MIG Cancer" shortLabel="MIG Cancer" 
				url="http://www.ctisante.com/references/pmsi/file_active_patients_cancer_2009.pdf" rowContext="false" />
		</VIEWLINKS>
		<ONGLET excelLabel="MIG Cancer" label="MIG Cancer">
			<DATAGRID title="" key="COD" headerHeight="40" variableRowHeight="true" sortable="false">
				<ROWSTYLE name="rowHeight" value="24" condition="ROW.LVL == '0' "/>
				<ROWSTYLE name="backgroundColor" value="0xFFD393" condition="ROW.LVL == '0'"/>
				<ROWSTYLE name="fontSize" value="12" condition="ROW.LVL == '0' "/>
				<ROWSTYLE name="fontSize" value="12" condition="ROW.LVL == '2' "/>
				<ROWSTYLE name="fontWeight" value="bold" condition="ROW.LVL == '0'"/>
				<ROWSTYLE name="fontWeight" value="bold" condition="ROW.LVL == '2'"/>
				<ROWSTYLE name="borderSides" value="top bottom" condition="ROW.LVL == '0' "/>
				<ROWSTYLE name="borderStyle" value="solid" condition="ROW.LVL == '0'"/>
				<ROWSTYLE name="borderThickness" value="1" condition="ROW.LVL == '0' "/>
				<COLUMN dataField="CHAP" width="70" type="Char" headerText="chap" visible="false" textAlign="left" totalFunction="text" />
				<COLUMN dataField="LVL" width="70" type="Char" headerText="lvl" visible="false" textAlign="left" totalFunction="text" />
				<COLUMN dataField="COD" width="70" type="Char" headerText="Indicateur" visible="false" textAlign="left" totalFunction="text" totalComplement="TOTAL" />
				<COLUMN dataField="TXT"
						type="Char"
						minWidth="200"
						maxWidth="300"
						headerText="Texte"
						textAlign="left"
						totalFunction="text"
						totalComplement="TOTAL">
					<CELLSTYLE name="paddingLeft" value="15" condition="ROW.LVL == '1'"/>
					<CELLSTYLE name="paddingLeft" value="15" condition="ROW.LVL == '2'"/>
				</COLUMN>
				<COLUMN	dataField="NBSEJ2D"
						width="100"
						type="Number"
						outputFormat="#"
						headerText="return 'Séjours ' + VIEW.PERIODE_2D_LABEL + '-' + VIEW.TOPERIODE_2D_LABEL;"
						headerTextCalc="true"
						selectable="true"
						visibleCondition="SELECT.TYPE_COMPARAISON == '3'"
						textAlign="right" />
				<COLUMN dataField="NBSEJD"
						width="100"
						type="Number"
						outputFormat="#"
						headerText="if (SELECT.TYPE_COMPARAISON != 'S') {
									return 'Séjours ' + VIEW.PERIODE_D_LABEL + '-' + VIEW.TOPERIODE_D_LABEL;
								}
								else {
									return 'Séjours ' + SELECT.PERIODE_D_LABEL + '-' + SELECT.TOPERIODE_D_LABEL;
								}
								"
						headerTextCalc="true"
						selectable="true"
						visibleCondition="SELECT.TYPE_COMPARAISON != '-1'"
						textAlign="right" />
				<COLUMN dataField="NBSEJ"
						width="100"
						type="Number"
						outputFormat="#"
						headerText="'Séjours ' + SELECT.PERIODE_LABEL + '-' + SELECT.TOPERIODE_LABEL;"
						headerTextCalc="true"
						textAlign="right" />
				<COLUMN	dataField="NBPAT2D"
						width="100"
						type="Number"
						outputFormat="#"
						headerText="return 'Patients ' + VIEW.PERIODE_2D_LABEL + '-' + VIEW.TOPERIODE_2D_LABEL;"
						headerTextCalc="true"
						selectable="true"
						visibleCondition="SELECT.TYPE_COMPARAISON == '3'"
						textAlign="right" />
				<COLUMN dataField="NBPATD"
						width="100"
						type="Number"
						outputFormat="#"
						headerText="if (SELECT.TYPE_COMPARAISON != 'S') {
									return 'Patients ' + VIEW.PERIODE_D_LABEL + '-' + VIEW.TOPERIODE_D_LABEL;
								}
								else {
									return 'Patients ' + SELECT.PERIODE_D_LABEL + '-' + SELECT.TOPERIODE_D_LABEL;
								}
								"
						headerTextCalc="true"
						selectable="true"
						visibleCondition="SELECT.TYPE_COMPARAISON != '-1'"
						textAlign="right" />
				<COLUMN dataField="NBPAT"
						width="100"
						type="Number"
						outputFormat="#"
						headerText="'Patients ' + SELECT.PERIODE_LABEL + '-' + SELECT.TOPERIODE_LABEL;"
						headerTextCalc="true"
						textAlign="right" />
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>
