<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="PMSI000194" label="PMSI. MIG Cancer" title="= 'Justificatif 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 name="SPFILTER">
			<value><![CDATA[[EVAL 
				
				// <?php
				$toReturn = '';
				switch('[DATACHAP]'){
					case '1' :
						$toReturn = "
							AND ghm_code NOT IN ('28Z08Z', '28Z09Z')
							AND (ghm_code LIKE '17M05%'
								OR ghm_code LIKE '17M06%'
								OR ghm_code = '28Z07Z'
								OR v_rss_1.rss_id IN (SELECT rss_id FROM pmsi.v_rss_diagnostics_1 WHERE type_diagnostic = 'DA' AND diagnostic_code = 'Z511')
								)
						";
						break;
					case '2' :
						$toReturn = "
							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 v_rss_1.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'))
								)
						";
						break;
					case '3' :
						$toReturn = "
							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'
						";
					;
				}
				return $toReturn;
				// ?>
				
			EVAL]]]></value>
		</PROPERTY>
		<PROPERTY name="SPFILTER2">
			<value><![CDATA[[EVAL 
				
				// <?php
				$toReturn = '';
				if('[DATALVL]' == '1'){
					$toReturn = "AND [DATAREG]_code = '[DATACOD]'";
				}
				return $toReturn;
				// ?>
				
			EVAL]]]></value>
		</PROPERTY>
		<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="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="2014-01-01" globalListProvider="DATE_DEBUT" printable="false">
			</FIELD>
			<FIELD name="TOPERIODE" label="à" UI="combo" tree="true" width="200" default="2014-12-31" globalListProvider="DATE_FIN" printable="false">
			</FIELD>
		</GROUP>
		<GROUP label="Champ">
			<FIELD name="CHAMP" label="" UI="combo" tree="true" width="400" default="EX" globalListProvider="CHAMP" showIfNotDefault="true">
			</FIELD>
		</GROUP>
		<GROUP label="ViewLinks">
			<FIELD name="DATALVL" label="" UI="text" width="100" default="" visible="false" />
			<FIELD name="DATAREG" label="" UI="text" width="100" default="" visible="false" />
			<FIELD name="DATACOD" label="" UI="text" width="100" default="" visible="false" />
			<FIELD name="DATACHAP" label="" UI="text" width="100" default="" visible="false" />
		</GROUP>
	</SELECTIONS>
	<QUERIES>
		<QUERY label="">
			<SQL>
				<select><![CDATA[
				
				DROP TABLE IF EXISTS w_tmp
				;

				CREATE TEMP TABLE w_tmp AS
					SELECT
						v_rss_1.rss_id,
						v_rss_1.no_rss,
						v_rss_1.finess,
						v_rss_1.patient_id,
						p_identites.nom || ' ' || p_identites.prenom as nom_prenom,
						v_rss_1.ghm_code,
						v_rss_1.ligne_oap_code,
						v_rss_1.medecin_reference_rss_nom,
						v_rss_1.diagnostic_principal_code,
						v_rss_1.acte_principal_code,
						v_rss_1.date_entree,
						v_rss_1.date_sortie,
						v_rss_1.sexe_texte_court,
						v_rss_1.age,
						v_rss_1.nb_rsa,
						v_rss_1.duree_sejour,
						v_rss_1.base_remboursement,
						v_rss_1.t2a_facture,
						v_rss_1.code_postal
					FROM pmsi.v_rss_1
						JOIN pmsi.p_identites ON p_identites.rss_id = v_rss_1.rss_id
					WHERE 
						cmd_code <> 90
						AND mco <> '*'
						AND v_rss_1.date_sortie >= '[PERIODE]' 
						AND v_rss_1.date_sortie <='[TOPERIODE]'
						[VIEW.SPFILTER]
						[VIEW.SPFILTER2]
						[VIEW.CHAMP_SELECT]
					GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
				;
				
				(
					SELECT
						rss_id,
						no_rss,
						finess,
						nom_prenom,
						ghm_code,
						ligne_oap_code,
						medecin_reference_rss_nom,
						diagnostic_principal_code,
						acte_principal_code,
						date_entree,
						date_sortie,
						sexe_texte_court,
						age,
						nb_rsa,
						duree_sejour,
						base_remboursement,
						t2a_facture,
						code_postal
					FROM w_tmp
				)
				UNION ALL
				(
					SELECT
						-9999999,
						null,
						'',
						COUNT(DISTINCT rss_id)::text || ' séjours, ' || COUNT(DISTINCT patient_id)::text || ' patients' ,
						'',
						'',
						'',
						'',
						'',
						null,
						null,
						'',
						null,
						SUM(nb_rsa),
						SUM(duree_sejour),
						SUM(base_remboursement),
						SUM(t2a_facture),
						null
					FROM w_tmp
				)
				ORDER BY 2
				;
				]]></select>
				<FIELDS>
					<FIELD name="OID"/>
					<FIELD name="RSS"/>
					<FIELD name="FIN"/>
					<FIELD name="NOM" ifHideNames="Non autorisé"/>
					<FIELD name="GHM"/>
					<FIELD name="OAP"/>
					<FIELD name="MED"/>
					<FIELD name="DIAGP"/>
					<FIELD name="ACTEP"/>
					<FIELD name="DATE"/>
					<FIELD name="DATS"/>
					<FIELD name="SEX"/>
					<FIELD name="AGE"/>
					<FIELD name="NRSA"/>
					<FIELD name="NBJ"/>
					<FIELD name="CA"/>
					<FIELD name="CAT2A"/>
					<FIELD name="CP"/>
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>
	<PRESENTATION>
		<VIEWLINKS>
			<VIEWLINK label="Détail RSS" shortLabel="Détail RSS" view="PMSI000006.XML">
				<ARG name="OID" value="ROW.OID"/>
			</VIEWLINK>
		</VIEWLINKS>
		<ONGLET excelLabel="Liste RSS">
			<DATAGRID title="" total="true" key="RSS" headerHeight="36" totalRowInRows="= ROW.OID == '-9999999'">
				<ROWSTYLE name="fontSize" value="11"/>
				<FOOTERROWSTYLE name="fontSize" value="11"/>
				<COLUMN dataField="OID" type="Char" visible="false">
				</COLUMN>
				<COLUMN dataField="FIN" width="60" type="Char" visible="true" headerText="Etablissement" textAlign="left" visibleCondition="ENV.CONSOLIDATION == '1'" otherFunction="text" totalFunction="text" totalComplement="">
				</COLUMN>
				<COLUMN dataField="RSS" width="60" type="Char" visible="true" headerText="N° RSS" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="TOTAL">
				</COLUMN>
				<COLUMN dataField="NOM" minWidth="150" maxWidth="200" type="Char" visible="true" headerText="Nom" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="*ROW">
				</COLUMN>
				<COLUMN dataField="SEX" width="40" type="Char" visible="true" headerText="Sexe" textAlign="left" otherFunction="text" totalFunction="text">
				</COLUMN>
				<COLUMN dataField="AGE" width="40" type="Number" outputFormat="#" visible="true" headerText="Age" textAlign="right" otherFunction="text" totalFunction="text">
				</COLUMN>
				<COLUMN dataField="CP" width="60" type="Number" outputFormat="#" visible="true" headerText="Code Postal" textAlign="right" otherFunction="text" totalFunction="text">
				</COLUMN>
				<COLUMN dataField="DATE" width="60" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" visible="true" headerText="Date entrée" textAlign="left" otherFunction="text" totalFunction="text">
				</COLUMN>
				<COLUMN dataField="DATS" width="60" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" visible="true" headerText="Date sortie" textAlign="left" otherFunction="text" totalFunction="text">
				</COLUMN>
				<COLUMN dataField="GHM" width="60" type="Char" visible="true" headerText="GHM" textAlign="left" otherFunction="text" totalFunction="text">
				</COLUMN>
				<COLUMN dataField="OAP" width="50" type="Char" visible="true" headerText="OAP" textAlign="left" otherFunction="text" totalFunction="text">
				</COLUMN>
				<COLUMN dataField="MED" minWidth="60" maxWidth="150" type="Char" visible="true" fixed="false" headerText="Médecin" textAlign="left" otherFunction="text" totalFunction="text">
				</COLUMN>
				<COLUMN dataField="DIAGP" width="50" type="Char" visible="true" headerText="Diag P" fixed="false" textAlign="left" otherFunction="text" totalFunction="text">
				</COLUMN>
				<COLUMN dataField="ACTEP" width="60" type="Char" visible="true" headerText="Acte P" fixed="false" textAlign="left" otherFunction="text" totalFunction="text">
				</COLUMN>
				<COLUMN dataField="NRSA" width="50" visible="false" type="Number" outputFormat="#" headerText="Nb RSA" fixed="false" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="NBJ" width="50" visible="false" type="Number" outputFormat="#" headerText="Durée séjour" fixed="false" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="CA" width="100" type="Number" fixed="false" outputFormat="#E" headerText="C.A." textAlign="right">
				</COLUMN>
				<COLUMN dataField="CAT2A" width="100" type="Number" fixed="false" outputFormat="#E" headerText="C.A. T2A" textAlign="right">
				</COLUMN>
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>
