<?xml version="1.0" encoding="ISO-8859-15"?>
<VUE 
	name="PMSI003600" 
	label="PMSI. Justificatif Simulation FG 2223 LPP" 
	title="= 'Justificatif Simulation FG 2223 LPP par RSS (' +  SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL + ')'" 
	database="iCTI" 
	swf="*CTI_view1" 
	softCode="iCTI_pmsi" 
	globals="PMSI_globals.XML" 
	componentsFile="PMSI_components.XML" 
>
	<VIEWPROPERTIES componentName="PROPERTIES_LPP"/>
	<SELECTIONS label="Paramètres de l'analyse" displayText="= var display:String = '';
					if (SELECT.LPP != '-1') {display = display + '#B#Analyse LPP#/B# : #B#' + SELECT.LPP_LABEL + '#/B#'}
					return display;
					">
		<GROUP label="Période">
			<FIELD name="PERIODE" label="" UI="combo" tree="true" width="200" default="2022-03-01">
				<OPTION dataLink="DATE_DEBUT" treeLevelField="lvl" dataField="cod" aliasField="alias" data2Field="mois" labelField="txt" />
			</FIELD>
			<FIELD name="TOPERIODE" label="à" UI="combo" tree="true" width="200" default="2023-02-28" >
				<OPTION dataLink="DATE_FIN" treeLevelField="lvl" dataField="cod" aliasField="alias" data2Field="mois" labelField="txt" />
			</FIELD>
		</GROUP>
		<GROUP label="LPP">
			<FIELD name="LPP" label="" UI="combo" tree="true" width="400" default="-1" globalListProvider="LPP" showIfNotDefault="true">
			</FIELD>
		</GROUP>
	</SELECTIONS>
	<SELECTIONS componentName="FILTRES_RSS_SELECTIONS"/>
	<QUERIES>
		<QUERY label="">
			<SQL optimizer="V_RSS_X">
				<select><![CDATA[
					DROP TABLE IF EXISTS w_lpp_205
					;
					CREATE TEMP TABLE w_lpp_205 AS
						SELECT t_lpp.code as lpp_code 
							FROM pmsi.t_listes
								JOIN pmsi.t_listes_contenu ON t_listes_contenu.liste_id = t_listes.oid 
								JOIN pmsi.t_listes_tables ON t_listes_tables.oid = t_listes.table_id
								JOIN pmsi.t_lpp ON t_lpp.oid = t_listes_contenu.to_id
							WHERE 1=1
								AND t_listes.is_cti = '1' 
								AND t_listes_tables.name = 't_lpp' 
								AND t_listes.code = 'CTI_DR23_1L'
					;
					(
					SELECT
						v_rss_1.rss_id,
						v_rss_1.no_rss,
						v_rss_1.no_sejour_administratif,
						v_rss_1.finess,
						identite_nom || ' ' || identite_prenom,
						date_lpp,
						lpp_code,
						lpp_texte,
						prix_unitaire,
						montant_facture,
						CASE WHEN lpp_code IN (SELECT lpp_code FROM w_lpp_205) THEN 0 ELSE montant_facture END,
						CASE WHEN lpp_code IN (SELECT lpp_code FROM w_lpp_205) THEN montant_facture ELSE 0 END
					FROM
						#V_RSS_X#,
						pmsi.p_simulation_fg2223,
						pmsi.v_rss_lpp_1
					WHERE 1=1
						AND v_rss_1.rss_id = v_rss_lpp_1.rss_id
						AND p_simulation_fg2223.rss_id = v_rss_1.rss_id
						AND p_simulation_fg2223.est_envoye = '1'
						AND p_simulation_fg2223.est_regroupe = '1'
						AND date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						[VIEW.LPP_SELECT]
						[VIEW.FILTRE_RSS_SELECT]
					)
					UNION ALL
					(
					SELECT
						-9999999,
						0,
						'',
						'',
						COUNT(DISTINCT v_rss_lpp_1.rss_id)::text || ' séjours,  ' || COUNT(DISTINCT v_rss_1.patient_id)::text || ' patients',
						null,
						'',
						COUNT(DISTINCT v_rss_lpp_1.lpp_id)::text || ' codes',
						0,
						sum(montant_facture),
						SUM(CASE WHEN lpp_code IN (SELECT lpp_code FROM w_lpp_205) THEN 0 ELSE montant_facture END),
						SUM(CASE WHEN lpp_code IN (SELECT lpp_code FROM w_lpp_205) THEN montant_facture ELSE 0 END)
					FROM
						#V_RSS_X#,
						pmsi.p_simulation_fg2223,
						pmsi.v_rss_lpp_1
					WHERE 1=1
						AND v_rss_1.rss_id = v_rss_lpp_1.rss_id
						AND p_simulation_fg2223.rss_id = v_rss_1.rss_id
						AND p_simulation_fg2223.est_envoye = '1'
						AND p_simulation_fg2223.est_regroupe = '1'
						AND date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						[VIEW.LPP_SELECT]
						[VIEW.FILTRE_RSS_SELECT]
					)
					ORDER BY 2, 5
					;
				]]></select>
				<FIELDS>
					<FIELD name="OID"/>
					<FIELD name="RSS"/>
					<FIELD name="SEJ"/>
					<FIELD name="FIN"/>
					<FIELD name="NOM" ifHideNames="Non autorisé"/>
					<FIELD name="DAT"/>
					<FIELD name="COD"/>
					<FIELD name="TXT"/>
					<FIELD name="PU"/>
					<FIELD name="MF12"/>
					<FIELD name="MF13"/>
					<FIELD name="MFEC"/>
				</FIELDS>
			</SQL>
		</QUERY>
        <QUERY type="comboLink" name="DATE_DEBUT" > 
            <SQL select="SELECT date, alias, texte, mois, level 
				FROM pmsi.v_calendrier_1 
				WHERE date_part('year',date) IN (SELECT annee_sortie FROM pmsi.p_simulation_fg2223 WHERE est_envoye &lt;&gt; '0' GROUP BY 1)" >
                <FIELDS>
                    <FIELD name="cod" />
                    <FIELD name="alias" />
                    <FIELD name="txt" />
                    <FIELD name="mois" />
                    <FIELD name="lvl" />
                </FIELDS>
            </SQL>
        </QUERY>
        <QUERY type="comboLink" name="DATE_FIN" > 
            <SQL select="SELECT date, alias, texte, mois, level 
				FROM pmsi.v_calendrier_2 
				WHERE date_part('year',date) IN (SELECT annee_sortie FROM pmsi.p_simulation_fg2223 WHERE est_envoye &lt;&gt; '0' GROUP BY 1)" >
                <FIELDS>
                    <FIELD name="cod" />
                    <FIELD name="alias" />
                    <FIELD name="txt" />
                    <FIELD name="mois" />
                    <FIELD name="lvl" />
                </FIELDS>
            </SQL>
        </QUERY>
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forSelections="false">
		</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="Justificatif LPP" label="Justificatif LPP">
			<DATAGRID title="" total="true" showOthers="false" key="RSS" headerHeight="48" totalRowInRows="= ROW.OID == '-9999999'">
				<COLUMN dataField="OID" type="Char" visible="false" />
				<COLUMN dataField="FIN" width="60" type="Char" visible="true" headerText="Etablissement" textAlign="left" visibleCondition="ENV.CONSOLIDATION == '1'" otherFunction="text" totalFunction="text" totalComplement="" />
				<COLUMN dataField="RSS" width="60" type="Char" visible="true" headerText="N° RSS" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="TOTAL" />
				<COLUMN dataField="SEJ" width="90" type="Char" visible="true" outputFormat="#" headerText="N° séjour" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="" />
				<COLUMN dataField="NOM" minWidth="150" type="Char" visible="true" headerText="Nom" textAlign="left" totalFunction="text" totalComplement="*ROW" />
				<COLUMN dataField="COD" type="Char" visibleCondition="SELECT.LPP == '-1' || SELECT.LPP.toString().substr(0,2) == 'LI'" headerText="Code LPP" width="60" textAlign="left"/>
				<COLUMN dataField="TXT" type="Char" visibleCondition="SELECT.LPP == '-1' || SELECT.LPP.toString().substr(0,2) == 'LI'" headerText="Texte LPP" minWidth="100" textAlign="left" totalFunction="text" totalComplement="*ROW"/>
				<COLUMN dataField="DAT" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" visible="true" headerText="Date" width="80" textAlign="left"/>
				<COLUMN dataField="PU" type="Number" visible="true" outputFormat="#,00E" headerText="Prix unitaire" width="80" textAlign="left"/>
				<COLUMN dataField="MF12" width="80" type="Number" outputFormat="#E" headerText="FG 2022 Montant LPP" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="MF13" width="80" type="Number" outputFormat="#E" headerText="FG 2223 Montant LPP" textAlign="right" totalFunction="sum" otherFunction="sum">
					<HEADERCELLSTYLE name="color" value="0xff5001"/>
					<CELLSTYLE name="color" value="0xff5001"/>
				</COLUMN>
				<COLUMN dataField="MFEC" width="80" type="Number" outputFormat="#E" headerText="Ecart. Montant LPP" textAlign="right" totalFunction="sum" otherFunction="sum" />
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>