<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE 
    name="PMSI003595" 
    label="PMSI. Justificatif Simulation FG 2223 GHS" 
    title="= 'Justificatif Simulation FG 2223 (' + SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL + ')'" 
    database="iCTI" swf="*CTI_view1" 
    softCode="iCTI_pmsi" 
    typeEts="" 
    globals="PMSI_globals.XML" 
    componentsFile="PMSI_components.XML" 
    helpDokuWIkiDir="" 
    helpDokuWIkiFile="pmsi000038"  
    helpFile="iCTI_PMSI_PMSI000038.HTML"
>
    <VIEWPROPERTIES>
        <PROPERTY name="NO_RSS_SELECT" value="[EVAL 
                                            if (('[NO_RSS]' + 0) != 0) {return 'AND v_rss_1.no_rss = ' . ('[NO_RSS]' + 0);}
                                            return '';
                                        EVAL]" />
        <PROPERTY name="ECART_SELECT" value="[EVAL 
                                        $ecart_num = '[ECART]' + 0;
                                            if ($ecart_num != 0) {return 'AND abs((montant_ghs_theorique_fg1 + montant_exb_fg1 + montant_exh_fg1) - (montant_ghs_theorique_fg0 + montant_exb_fg0 + montant_exh_fg0)) &gt;= ' . $ecart_num;}
                                            return '';
                                        EVAL]" />
                                        
        <PROPERTY name="NOM_SELECT" value="[EVAL 
                                            if ('[NOM]' != '') {return 'AND p_identites.nom ILIKE ' .''. '[NOM]%' .''.  ' ' ;}
                                            return '';
                                        EVAL]" />
        <PROPERTY name="TYPREG_SELECT" value="[EVAL 
                                            if ('[TYPREG]' == 'EXB13') {return 'AND nb_exb_fg1 &gt; 0';}
                                            if ('[TYPREG]' == 'EXH13') {return 'AND nb_exh_fg1 &gt; 0';}
                                            if ('[TYPREG]' == 'EQ') {return 'AND t_ghm_fg0.code = ghm_fg1_code';}
                                            if ('[TYPREG]' == 'NE') {return 'AND t_ghm_fg0.code &lt;&gt; ghm_fg1_code';}
                                            if ('[TYPREG]' == 'NE5') {return 'AND substr(t_ghm_fg0.code, 1 , 5) &lt;&gt; substr(ghm_fg1_code, 1 , 5)';}
                                            if ('[TYPREG]' == 'TOT') {return &quot;AND substr(t_ghm_fg0.code, 1 , 5) = substr(ghm_fg1_code, 1 , 5) AND substr(t_ghm_fg0.code, 6 , 1) &lt;&gt; 'T' AND substr(ghm_fg1_code, 6 , 1) = 'T'&quot;;}
                                            if ('[TYPREG]' == 'DC') {return &quot;AND substr(t_ghm_fg0.code, 1 , 5) = substr(ghm_fg1_code, 1 , 5) AND substr(t_ghm_fg0.code, 6 , 1) &lt;&gt; 'T' AND substr(ghm_fg1_code, 6 , 1) &lt;&gt; 'T'  AND substr(ghm_fg1_code, 6 , 1) &lt; substr(t_ghm_fg0.code, 6 , 1)&quot;;}
                                            if ('[TYPREG]' == 'RC') {return &quot;AND substr(t_ghm_fg0.code, 1 , 5) = substr(ghm_fg1_code, 1 , 5) AND substr(t_ghm_fg0.code, 6 , 1) &lt;&gt; 'T' AND substr(ghm_fg1_code, 6 , 1) &lt;&gt; 'T'  AND substr(ghm_fg1_code, 6 , 1) &gt; substr(t_ghm_fg0.code, 6 , 1)&quot;;}
                                            return '';
                                        EVAL]" />
        <PROPERTY name="SIMULATION_FILTERS_RAAC">
            <value><![CDATA[[EVAL 
                // <?php
                $select = '';
            
                if ('[FILTRES_RSS_RAAC]' != '-1') {
                        if ('[FILTRES_RSS_RAAC]' == '1') {
                            $select = " AND v_rss_1.ghm_id IN (SELECT oid FROM pmsi.t_ghm_c WHERE substr(code, 0, 6) IN ('04C04',
                                                                                                                                                '06C03',
                                                                                                                                                '06C04',
                                                                                                                                                '06C07',
                                                                                                                                                '06C16',
                                                                                                                                                '07C09',
                                                                                                                                                '08C24',
                                                                                                                                                '08C25',
                                                                                                                                                '08C27',
                                                                                                                                                '08C48',
                                                                                                                                                '08C52',
                                                                                                                                                '10C13',
                                                                                                                                                '11C02',
                                                                                                                                                '12C11',
                                                                                                                                                '13C03',
                                                                                                                                                '13C14',
                                                                                                                                                '13C15',
																																				'04C02',
																																				'08C22'
																																				)
                                                )";
                        }
                        if ('[FILTRES_RSS_RAAC]' == '2') {
                            $select = " AND v_rss_1.ghm_id IN (SELECT oid FROM pmsi.t_ghm_c WHERE substr(code, 0, 6) IN ('04C04',
                                                                                                                                                '06C03',
                                                                                                                                                '06C04',
                                                                                                                                                '06C07',
                                                                                                                                                '06C16',
                                                                                                                                                '07C09',
                                                                                                                                                '08C24',
                                                                                                                                                '08C25',
                                                                                                                                                '08C27',
                                                                                                                                                '08C48',
                                                                                                                                                '08C52',
                                                                                                                                                '10C13',
                                                                                                                                                '11C02',
                                                                                                                                                '12C11',
                                                                                                                                                '13C03',
                                                                                                                                                '13C14',
                                                                                                                                                '13C15',
																																				'04C02',
																																				'08C22'
																																				)
                                                )";
                            $select .= " AND v_rss_1.duree_sejour <= 2";
                            $select .= " AND v_rss_1.mode_sortie NOT IN ('6','7','9')";                                                        
                        }                       
                        if ('[FILTRES_RSS_RAAC]' == '3') {
                            $select = " AND p_simulation_fg2223.is_raac = 'is_raac' ";
                        }                       
                }
                
                return $select;
                // ?>
            EVAL]]]></value>
        </PROPERTY>
    </VIEWPROPERTIES>

    <SELECTIONS label="Paramètres de l'analyse" displayText="= var display:String = '';
                    
                    if (SELECT.ECART  != '') {
                        display = display + 'Ecart minimum: #B#' + SELECT.ECART + ' euros #/B# ';
                    }
                    if (SELECT.TYPREG  != '-1') {
                        display = display + 'Type regroupage : #B#' + SELECT.TYPREG_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="Type regroupage">
            <FIELD name="TYPREG" label="" UI="combo" tree="false" width="400" default="-1">
                <OPTION label="Pas de sélection" data="-1"/>
                <OPTION label="GHM FG 2223 identique" data="EQ"/>
                <OPTION label="GHM FG 2223 différent" data="NE"/>
                <OPTION label="Racine GHM FG 2223 différente" data="NE5"/>
                <OPTION label="Regroupement en Très court séjour" data="TOT"/>
                <OPTION label="Regroupement en sévérité inférieure" data="DC"/>
                <OPTION label="Regroupement en sévérité supérieure" data="RC"/>
                <OPTION label="Regroupement en EXB" data="EXB13"/>
                <OPTION label="Regroupement en EXH" data="EXH13"/>
            </FIELD>
        </GROUP>
        <GROUP label="Ecart minimum">
            <FIELD name="ECART" label="" UI="number" width="100" default="" showIfNotDefault="true">
            </FIELD>
        </GROUP>
        <GROUP label="N° de RSS">
            <FIELD name="NO_RSS" label="" UI="number" width="100" default="" showIfNotDefault="true">
            </FIELD>
        </GROUP>
        <GROUP label="Ou Nom">
            <FIELD name="NOM" label="" UI="text" width="200" default="" showIfNotDefault="true">
            </FIELD>
        </GROUP>
    </SELECTIONS>
    <SELECTIONS label="Paramètres de l'analyse" displayText="= var display:String = '';
                    if (SELECT.FILTRES_RSS_RAAC  != '-1') {
                        display = display + '  Raac : #B#' + SELECT.FILTRES_RSS_RAAC_LABEL + '#/B#';
                    }
                    return display;
                    "> 
        <GROUP label="Séjours RAAC">
            <FIELD name="FILTRES_RSS_RAAC" width="300" label="Séjours RAAC" UI="combo" default="-1" >
                <OPTION label="Pas de sélection" data="-1"/>
                <OPTION label="Eligibles RAAC par liste GHM" data="1"/>     
                <OPTION label="Eligibles RAAC (GHM et moins de 3 nuits)" data="2"/>
                <OPTION label="RAAC" data="3"/>
            </FIELD>
        </GROUP>
    </SELECTIONS>        
    <SELECTIONS componentName="FILTRES_RSS_SELECTIONS"/>
    <QUERIES>
        <QUERY label="">
            <SQL optimizer="V_RSS_X">
                <select><![CDATA[
                (
                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, 
                    sexe, 
                    age, 
                    date_sortie, 
                    duree_sejour,
                    diagnostic_principal_code,
                    t_ghm_fg0.code,
                    t_ghs_fg0.code,
                    montant_ghs_theorique_fg0,
                    montant_exb_fg0,
                    montant_exh_fg0,
                    montant_ghs_theorique_fg0 + montant_exb_fg0 + montant_exh_fg0,
                    ghm_fg1_code,
                    ghs_fg1_code,
                    ghs_fg1_borne_basse,
                    ghs_fg1_borne_haute,
                    montant_ghs_theorique_fg1,
                    montant_exb_fg1,
                    nb_exh_fg1,
                    montant_exh_fg1,
                    montant_ghs_theorique_fg1 + montant_exb_fg1 + montant_exh_fg1,
                    (montant_ghs_theorique_fg1 + montant_exb_fg1 + montant_exh_fg1) - (montant_ghs_theorique_fg0 + montant_exb_fg0 + montant_exh_fg0)
                FROM 
                    #V_RSS_X#, 
                    pmsi.p_simulation_fg2223, 
                    pmsi.t_ghm t_ghm_fg0, 
                    pmsi.t_ghs t_ghs_fg0
                WHERE 1=1
                    AND date_sortie >= '[PERIODE]'
                    AND date_sortie <='[TOPERIODE]'
                    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 p_simulation_fg2223.ghm_fg0_id = t_ghm_fg0.oid
                    AND p_simulation_fg2223.ghs_fg0_id = t_ghs_fg0.oid
                    [VIEW.FILTRE_RSS_SELECT]
                    [VIEW.NO_RSS_SELECT]
                    [VIEW.NOM_SELECT]
                    [VIEW.ECART_SELECT]
                    [VIEW.TYPREG_SELECT]
                    [VIEW.SIMULATION_FILTERS_RAAC]                    
                )
                UNION ALL
                (
                SELECT 
                    -9999999, 
                    0, 
                    '', 
                    '',
                    SUM(nb_rsa)::text || ' séjours', 
                    '', 
                    0, 
                    null, 
                    0, 
                    '',
                    '', 
                    0,
                    SUM(montant_ghs_theorique_fg0),
                    SUM(montant_exb_fg0),
                    SUM(montant_exh_fg0),
                    SUM(montant_ghs_theorique_fg0 + montant_exb_fg0 + montant_exh_fg0 ),
                    '', 
                    0, 
                    0, 
                    0,
                    SUM(montant_ghs_theorique_fg1),
                    SUM(montant_exb_fg1),
                    SUM(nb_exh_fg1),
                    SUM(montant_exh_fg1),
                    SUM(montant_ghs_theorique_fg1 + montant_exb_fg1 + montant_exh_fg1),
                    SUM(montant_ghs_theorique_fg1 + montant_exb_fg1 + montant_exh_fg1) - SUM(montant_ghs_theorique_fg0 + montant_exb_fg0 + montant_exh_fg0 )
                FROM 
                    #V_RSS_X#, 
                    pmsi.p_simulation_fg2223, 
                    pmsi.t_ghm t_ghm_fg0
                WHERE 1=1
                    AND date_sortie >= '[PERIODE]'
                    AND date_sortie <='[TOPERIODE]'
                    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 p_simulation_fg2223.ghm_fg0_id = t_ghm_fg0.oid
                    [VIEW.FILTRE_RSS_SELECT]
                    [VIEW.NO_RSS_SELECT]
                    [VIEW.NOM_SELECT]
                    [VIEW.ECART_SELECT]
                    [VIEW.TYPREG_SELECT]
                    [VIEW.SIMULATION_FILTERS_RAAC]                    
                )
                ORDER BY 2
                ]]></select>
                <FIELDS>
                    <FIELD name="OID"/>
                    <FIELD name="RSS"/>
                    <FIELD name="SEJ"/>
                    <FIELD name="FIN"/>
                    <FIELD name="NOM" ifHideNames="Non autorisé"/>
                    <FIELD name="SEX"/>
                    <FIELD name="AGE"/>
                    <FIELD name="DATE"/>
                    <FIELD name="NBJ"/>
                    <FIELD name="DP"/>
                    <FIELD name="GHM12"/>
                    <FIELD name="GHS12"/>
                    <FIELD name="G12"/>
                    <FIELD name="B12"/>
                    <FIELD name="H12"/>
                    <FIELD name="T12"/>
                    <FIELD name="GHM13"/>
                    <FIELD name="GHS13"/>
                    <FIELD name="GHSBB13"/>
                    <FIELD name="GHSBH13"/>
                    <FIELD name="G13"/>
                    <FIELD name="B13"/>
                    <FIELD name="NH13"/>
                    <FIELD name="H13"/>
                    <FIELD name="T13"/>
                    <FIELD name="TEC"/>
                </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>
    </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="Simulation FG 2223">
            <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="SEJ" width="90" type="Char" visible="true" outputFormat="#" headerText="N° séjour" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="">
                </COLUMN>
                <COLUMN dataField="NOM" minWidth="100" 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="right" otherFunction="text" totalFunction="text">
                    <CELLSTYLE name="cellIndicator" value="femme, 12,left middle , 0xEB76B1" condition="ROW.SEX == '2'" /> 
                    <CELLSTYLE name="cellIndicator" value="homme, 12,left middle , 0x75a0eb " condition="ROW.SEX == '1'" /> 
					<CELLSTYLE name="cellIndicator" value="rectangle, 10,left middle , #FF5001 " condition="ROW.SEX == '3'" /> 
					<CELLSTYLE name="cellIndicator" value="rectangle, 10, left middle, 0x666666" condition="ROW.SEX != '2' &amp;&amp; ROW.SEX != '1' &amp;&amp; ROW.SEX != '3'" />
                </COLUMN>
                <COLUMN dataField="AGE" width="35" type="Number" outputFormat="#" visible="true" headerText="Age" 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 sortie" textAlign="left" otherFunction="text" totalFunction="text">
                </COLUMN>
                <COLUMN dataField="NBJ" width="40" visible="true"  type="Number" outputFormat="#" headerText="Durée sej" fixed="false" textAlign="right" totalFunction="sum" otherFunction="sum">
                </COLUMN>
                <COLUMN dataField="DP" width="45" type="Char"  visible="true" headerText="DP" textAlign="left" otherFunction="text" totalFunction="text">
                </COLUMN>
                <COLUMN dataField="GHM12" width="45" type="Char" visible="true" headerText="FG 2022 GHM" textAlign="left" otherFunction="text" totalFunction="text">
                </COLUMN>
                <COLUMN dataField="GHS12" width="40" type="Char" visible="true" headerText="FG 2022 GHS" textAlign="left" otherFunction="text" totalFunction="text">
                </COLUMN>
                <COLUMN dataField="G12" width="80" visible="true" type="Number" outputFormat="#E" fixed="false" headerText="FG 2022 GHS Théorique" description= "dont prudentiel" textAlign="right" otherFunction="sum" totalFunction="sum">
                </COLUMN>
                <COLUMN dataField="B12" width="70" visible="true" type="Number" outputFormat="#E" fixed="false" headerText="FG 2022 EXB" textAlign="right" otherFunction="sum" totalFunction="sum">
                </COLUMN>
                <COLUMN dataField="H12" width="70" visible="true" type="Number" outputFormat="#E" fixed="false" headerText="FG 2022 EXH" textAlign="right" otherFunction="sum" totalFunction="sum">
                </COLUMN>
                <COLUMN dataField="T12" width="80" visible="true" type="Number" outputFormat="#E" fixed="false" headerText="FG 2022 GHS+EXH" textAlign="right" otherFunction="sum" totalFunction="sum">
                </COLUMN>
                <COLUMN dataField="GHM13" width="45" type="Char" visible="true" headerText="FG 2223 GHM" textAlign="left" otherFunction="text" totalFunction="text">
                    <HEADERCELLSTYLE name="color" value="0xff5001"/>
                    <CELLSTYLE name="color" value="0xff5001"/>
                </COLUMN>
                <COLUMN dataField="GHS13" width="40" type="Char" visible="true" headerText="FG 2223 GHS" textAlign="left" otherFunction="text" totalFunction="text">
                    <HEADERCELLSTYLE name="color" value="0xff5001"/>
                    <CELLSTYLE name="color" value="0xff5001"/>
                </COLUMN>
                <COLUMN dataField="GHSBB13" width="50" visibleCondition="SELECT.TYPREG == 'EXB13'" type="Number" outputFormat="#" fixed="false" headerText="FG 2223 B.B." textAlign="right" otherFunction="sum" totalFunction="sum">
                    <HEADERCELLSTYLE name="color" value="0xff5001"/>
                    <CELLSTYLE name="color" value="0xff5001"/>
                </COLUMN>
                <COLUMN dataField="GHSBH13" width="50" visibleCondition="SELECT.TYPREG == 'EXH13'" type="Number" outputFormat="#" fixed="false" headerText="FG 2223 B.H." textAlign="right" otherFunction="sum" totalFunction="sum">
                    <HEADERCELLSTYLE name="color" value="0xff5001"/>
                    <CELLSTYLE name="color" value="0xff5001"/>
                </COLUMN>
                <COLUMN dataField="G13" width="80" visible="true" type="Number" outputFormat="#E" fixed="false" headerText="FG 2223 GHS Théorique"  description= "dont prudentiel et coefficient pacte responsabilité" textAlign="right" otherFunction="sum" totalFunction="sum">
                    <HEADERCELLSTYLE name="color" value="0xff5001"/>
                    <CELLSTYLE name="color" value="0xff5001"/>
                </COLUMN>
                <COLUMN dataField="B13" width="70" visibleCondition="SELECT.TYPREG != 'EXH13'" type="Number" outputFormat="#E" fixed="false" headerText="FG 2223 EXB" textAlign="right" otherFunction="sum" totalFunction="sum">
                    <HEADERCELLSTYLE name="color" value="0xff5001"/>
                    <CELLSTYLE name="color" value="0xff5001"/>
                </COLUMN>
                <COLUMN dataField="NH13" width="70" visibleCondition="SELECT.TYPREG == 'EXH13'" type="Number" outputFormat="#" fixed="false" headerText="FG 2223 Nb EXH" textAlign="right" otherFunction="sum" totalFunction="sum">
                    <HEADERCELLSTYLE name="color" value="0xff5001"/>
                    <CELLSTYLE name="color" value="0xff5001"/>
                </COLUMN>
                <COLUMN dataField="H13" width="70" visibleCondition="SELECT.TYPREG != 'EXB13'" type="Number" outputFormat="#E" fixed="false" headerText="FG 2223 EXH" textAlign="right" otherFunction="sum" totalFunction="sum">
                    <HEADERCELLSTYLE name="color" value="0xff5001"/>
                    <CELLSTYLE name="color" value="0xff5001"/>
                </COLUMN>
                <COLUMN dataField="T13" width="80" visible="true" type="Number" outputFormat="#E" fixed="false" headerText="FG 2223 GHS+EXH" textAlign="right" otherFunction="sum" totalFunction="sum">
                    <HEADERCELLSTYLE name="color" value="0xff5001"/>
                    <CELLSTYLE name="color" value="0xff5001"/>
                </COLUMN>
                <COLUMN dataField="TEC" width="80" visible="true" type="Number" outputFormat="#E" fixed="false" headerText="Ecart" textAlign="right" otherFunction="sum" totalFunction="sum">
                </COLUMN>
            </DATAGRID>
        </ONGLET>
    </PRESENTATION>
</VUE>