<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="PMSI000015" 
	label="PMSI. Contrôle T2A. Extrait fiche n°5 (d'après liste RSS)" 
	title="= 'Contrôle T2A. Extrait fiche n°5 (' + SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL + ')'" 
	database="iCTI" 
	swf="*CTI_view1" 
	softCode="iCTI_pmsi"
	globals="PMSI_globals.XML"
	componentsFile="PMSI_components.XML"
    helpDokuWIkiDir="pmsi:qualite:etudes:" 
    helpDokuWIkiFile="pmsi000015"
    helpFile="iCTI_PMSI_PMSI000015.HTML">
	
	<VIEWPROPERTIES>

		<PROPERTY name="DATA" >
				<value><![CDATA[
						[EVAL 
						return pg_escape_bytea('[DATA]') ;			
					EVAL]
				]]></value>
		</PROPERTY>
		
		
		<PROPERTYx dataLink="VIEWPROPERTIES" nameField="name" valueField="value" />
	</VIEWPROPERTIES>
	
	<SELECTIONS label="Paramètres de l'analyse" displayText="= var display:String = '';
					
					
					if (display != '') {
					}
					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="Données (n° OGC et n° RSS). Copier depuis Excel les colonnes n° OGC et n° RSS, puis les coller dans Données. Attention, si vous rechargez l'application les numéros ne restent pas en colonne, refaire la manipulation du copier/coller. ">
			<FIELD name="DATA" label="" UI="textArea" width="430" height="70" default="" showIfNotDefault="true" />
		</GROUP>
		
	</SELECTIONS>
		

	<QUERIES>
		<QUERY label=""> 
			<SQL optimizer="V_RSS_X">
				<select><![CDATA[ 
				
				DROP TABLE IF EXISTS w_input;
				CREATE TABLE w_input (data text);
				INSERT INTO w_input
				SELECT
					'[VIEW.DATA]' AS data
				;
				
				
				DROP TABLE IF EXISTS w_input_rss;
				CREATE TEMP TABLE w_input_rss AS
				SELECT i AS indice, 
					split_part(data[i],'\011',1) AS no_sequence, 
					base.cti_to_number(split_part(data[i],'\011',2)) AS no_rss
				FROM (
					SELECT data, generate_series(1,nb) AS i
					FROM
					(
						SELECT data, array_upper(data,1) AS nb
						FROM
						(
						SELECT
							(string_to_array(data,'\015')) AS data
						FROM w_input
						) subview
					) subview
				) subview;
				
				-- Récupération des forfaits
				DROP TABLE IF EXISTS w_tm_forfait;
				CREATE TEMP TABLE w_tm_forfait AS
				SELECT rss_id, 
					SUM(CASE WHEN prestation_code IN ('GHS', 'EXH') AND v_rsf_detail_1.taux_remboursement < 100 THEN v_rsf_detail_1.base_remboursement - v_rsf_detail_1.sejour_remboursable ELSE 0 END) AS ticket_moderateur,
					SUM(CASE WHEN prestation_code IN ('GHS', 'EXH') AND v_rsf_detail_1.taux_remboursement = 100 OR prestation_code LIKE 'FJ%' THEN v_rsf_detail_1.base_remboursement - v_rsf_detail_1.sejour_remboursable ELSE 0 END) AS forfait_journalier
				FROM pmsi.v_rsf_detail_1 
				JOIN pmsi.p_rss ON p_rss.oid = v_rsf_detail_1.rss_id
				JOIN w_input_rss ON w_input_rss.no_rss = p_rss.no_rss
				WHERE prestation_code IN ('GHS', 'EXH', 'FJA', 'FJR') AND
					p_rss.date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
				GROUP BY 1;

				-- Liste des dossiers
				SELECT 
						v_rss_1.rss_id,
						w_input_rss.no_sequence,
						v_rss_1.no_rss,
						p_rsf_total.matricule_assure || '-' || p_rsf_total.cle_matricule_assure AS matricule_assure,
						v_rss_1.no_sejour_administratif AS numero_entree,
						CASE WHEN patient_no_patient > 0 THEN patient_no_patient ELSE 0 END AS ipp,
						identite_nom,
						identite_nom_naissance,
						identite_prenom,
						v_rss_1.date_naissance,
                        p_rsf_total.no_facture as fac_num,
						regime_code AS regime,
						no_caisse_gestionnaire AS caisse_gestionnaire,
						v_rss_1.date_entree,
						v_rss_1.date_sortie,
						duree_sejour,
						v_rss_1.taux_remboursement,
						p_vidhosp.taux_remboursement AS taux_remboursement_vidhosp,
						0::numeric AS majoration_parcours_soins,
						COALESCE(w_tm_forfait.ticket_moderateur,0) AS ticket_moderateur,
						COALESCE(w_tm_forfait.forfait_journalier,0) AS forfait_journalier,
                        diagnostic_principal_code,
						ghs_code AS ghs_initial,
						ghm_code AS ghm_initial
					FROM 
						#V_RSS_X#
						JOIN w_input_rss ON w_input_rss.no_rss = v_rss_1.no_rss
						JOIN pmsi.p_rsf_total ON p_rsf_total.rss_id = v_rss_1.rss_id
						LEFT JOIN pmsi.p_vidhosp ON p_vidhosp.rss_id = v_rss_1.rss_id
						LEFT JOIN w_tm_forfait ON w_tm_forfait.rss_id = v_rss_1.rss_id
					WHERE v_rss_1.date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
                    ORDER BY 1;
				]]></select>
				<FIELDS>
					<FIELD name="OID" />
					<FIELD name="SEQ" />
					<FIELD name="RSS" />
					<FIELD name="MAT" ifHideNames="Non autorisé"/>
					<FIELD name="ADM" />
					<FIELD name="IPP" />
					<FIELD name="NOM" ifHideNames="Non autorisé"/>
					<FIELD name="NNA" ifHideNames="Non autorisé"/>
					<FIELD name="PRE" ifHideNames="Non autorisé"/>
					<FIELD name="DNA" ifHideNames="Non autorisé"/>
                    <FIELD name="FAC" />
					<FIELD name="REG" />
					<FIELD name="CAI" />
					<FIELD name="DEN" />
					<FIELD name="DSO" />
					<FIELD name="DUR" />
					<FIELD name="TXF" />
					<FIELD name="TXV" />
					<FIELD name="MPS" />
					<FIELD name="MTM"/>
					<FIELD name="MFJ"/>
					<FIELD name="DGP"/>
					<FIELD name="GHS"/>
					<FIELD name="GHM"/>
				</FIELDS>
			</SQL>
			<SQL optimizer="V_RSS_X">
				<select><![CDATA[ 


				-- Liste des dossiers
				SELECT 
						-9999999 AS rss_id,
						count(*)::text || ' RSS extraits' AS nom
					FROM 
						#V_RSS_X#
						JOIN w_input_rss ON w_input_rss.no_rss = v_rss_1.no_rss
						JOIN pmsi.v_rsf_total_1 ON v_rsf_total_1.rss_id = v_rss_1.rss_id
						JOIN pmsi.p_rsf_total ON p_rsf_total.rss_id = v_rss_1.rss_id
						LEFT JOIN pmsi.p_vidhosp ON p_vidhosp.rss_id = v_rss_1.rss_id
						LEFT JOIN w_tm_forfait ON w_tm_forfait.rss_id = v_rss_1.rss_id
					WHERE v_rss_1.date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
				
				]]></select>
				<FIELDS>
					<FIELD name="OID" />
					<FIELD name="NOM" />
				</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" headerHeight="100"  
				totalRowInRows="= ROW.OID == '-9999999'"
			>
				<ROWSTYLE name="fontSize" value="11" />
				<FOOTERROWSTYLE name="fontSize" value="11" />
				<COLUMN dataField="OID"
					type="Char"
					visible="false">
				</COLUMN>
				<COLUMN dataField="SEQ"
					width="60"
					type="Number"
                    outputFormat="#"
					visible="true"
					headerText="N° OGC" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text" 
					totalComplement=""
                    description="à ne pas modifier, à indiquer par l'établissement.">
                    <CELLSTYLE name="backgroundColor" value="0xCCCCCC" condition="1==1"/> 
				</COLUMN>
				<COLUMN dataField="RSS"
					width="70"
					type="Number"
					visible="true"
					outputFormat="#"
					headerText="N° RSS" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text" 
					totalComplement="TOTAL"
                    description="Numéro de RSS">
				</COLUMN>
				<COLUMN dataField="MAT"
					width="115"
					type="Char"
					visible="true"
					outputFormat="#"
					headerText="NIR assuré social" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text" 
					totalComplement=""
                    description="Numéro de sécurité sociale">
				</COLUMN>

				<COLUMN dataField="ADM"
					width="80"
					type="Char"
					visible="true"
					outputFormat="#"
					headerText="N° Entrée" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text" 
					totalComplement=""
                    description="Numéro de séjour">
				</COLUMN>
				<COLUMN dataField="IPP"
					width="60"
					type="Number"
					visible="true"
					outputFormat="#"
					headerText="IPP Patient" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text" 
					totalComplement=""
                    description="Numéro Patient">
				</COLUMN>
				
				<COLUMN dataField="NOM"
					minWidth="100"
					type="Char"
					visible="true"
					headerText="Nom de Famille" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text"
					totalComplement="*ROW"
                    description="Nom de Famille/ Marital">
				</COLUMN>
				<COLUMN dataField="NNA"
					minWidth="100"
					type="Char"
					visible="true"
					headerText="Nom Naissance/Jeune fille" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text"
					totalComplement=""
                    description="Nom de Famille de Naissance">
				</COLUMN>
				<COLUMN dataField="PRE"
					minWidth="100"
					type="Char"
					visible="true"
					headerText="Prénom" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text"
					totalComplement=""
                    description="Prénom">
				</COLUMN>
				<COLUMN dataField="DNA"
					width="60"
					type="Date"
					inputFormat="AAAA-MM-JJ"
					outputFormat="DD/MM/YY"
					visible="true"
					fixed="false"
					headerText="Date de naissance" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text"
                    description="Date de naissance">
				</COLUMN>
                <COLUMN dataField="FAC"
					width="50"
					type="Char"
					visible="true"
					headerText="N° Facture" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text"
					totalComplement=""
                    description="Numéro de la Facture">
				</COLUMN>
				<COLUMN dataField="REG"
					width="50"
					type="Char"
					visible="true"
					headerText="Régime AM" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text"
					totalComplement=""
                    description="Régime de l'assuré à la date d'entrée dans l'établissement de santé">
				</COLUMN>
				<COLUMN dataField="CAI"
					width="50"
					type="Char"
					visible="true"
					headerText="Numéro caisse gestionnaire AM" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text"
					totalComplement=""
                    description="Correspond au Numéro de la caisse d'affiliation à la date d'entrée dans l'établissement.">
				</COLUMN>
				<COLUMN dataField="FIL1"
					width="50"
					type="Char"
					visible="true"
					headerText="N° activité" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text"
					totalComplement=""
                    description="Non alimenté par CTI">
				</COLUMN>
				<COLUMN dataField="FIL1"
					width="50"
					type="Char"
					visible="true"
					headerText="Activité" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text"
					totalComplement=""
                    description="Non alimenté par CTI">
				</COLUMN>
				<COLUMN dataField="DEN"
					width="60"
					type="Date"
					inputFormat="AAAA-MM-JJ"
					outputFormat="DD/MM/YY"
					visible="true"
					fixed="false"
					headerText="Date d'entrée" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text"
                    description="Date d'entrée dans l'établissement">
				</COLUMN>
				<COLUMN dataField="DSO"
					width="60"
					type="Date"
					inputFormat="AAAA-MM-JJ"
					outputFormat="DD/MM/YY"
					visible="true"
					fixed="false"
					headerText="Date de sortie" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text"
                    description="Date de sortie de l'établissement">
				</COLUMN>
				<COLUMN dataField="DUR" 
					width="50"
					visible="true"
					type="Number" 
					outputFormat="0" 
					headerText="Durée du séjour" 
					fixed="false"
					textAlign="center" 
					totalFunction="sum"
					otherFunction="sum"
                    description="Durée du séjour">
				</COLUMN>
				<COLUMN dataField="TXF" 
					width="50"
					visible="true"
					type="Number" 
					outputFormat="0" 
					headerText="Taux de prise en charge du séjour par l'AM" 
					fixed="false"
					textAlign="center" 
					totalFunction="sum"
					otherFunction="sum"
                    description="Taux de prise en charge du séjour par l'assurance maladie (Ex OQN)">
				</COLUMN>
				<COLUMN dataField="TXV" 
					width="50"
					visible="true"
					type="Number" 
					outputFormat="#" 
					headerText="Taux de prise en charge VID-HOSP/LAMDA"
					fixed="false"
					textAlign="center" 
					totalFunction="sum"
					otherFunction="sum"
                    description="Taux de prise en charge VID-HOSP/LAMDA (Ex DG) à l'entrée déclaré par l'établissement.">
				</COLUMN>
				<COLUMN dataField="MPS" 
					width="80"
					visible="true"
					type="Number" 
					outputFormat="#,00" 
					headerText="Majoration parcours de Soins" 
					fixed="false"
					textAlign="center" 
					totalFunction="sum"
					otherFunction="sum"
                    description="Il s'agit de la majoration liée à l'absence de recours au médecin traitant.">
				</COLUMN>
				<COLUMN dataField="MTM" 
					width="80"
					visible="true"
					type="Number" 
					outputFormat="#,00" 
					headerText="Ticket modérateur forfaitaire" 
					fixed="false"
					textAlign="center" 
					totalFunction="sum"
					otherFunction="sum"
                    description="Ticket modérateur forfaitaire">
				</COLUMN>
				<COLUMN dataField="MFJ" 
					width="80"
					visible="true"
					type="Number" 
					outputFormat="#,00" 
					headerText="Forfait journalier hospitalier" 
					fixed="false"
					textAlign="center" 
					totalFunction="sum"
					otherFunction="sum"
                    description="Forfait journalier hospitalier s'applique aux séjours en hospitalisation complète, dans les disciplines de médecine, chirurgie, obstétrique, odontologie, en soins de suite et de réadaptation et en psychiatrie.">
				</COLUMN>
				<COLUMN dataField="DGP"
					width="70"
					type="Char"
					visible="true"
					fixed="false"
					headerText="Diagnostic Principal" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text"
                    description="Diagnostic Principal">
				</COLUMN>
                <COLUMN dataField="GHS"
					width="40"
					type="Char"
					visible="true"
					fixed="false"
					headerText="GHS initial" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text"
                    description="Numéro du GHS avant contrôle">
				</COLUMN>
				<COLUMN dataField="GHSF"
					width="40"
					type="Char"
					visible="true"
					fixed="false"
					headerText="GHS final" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text"
                    description="Numéro du GHS après contrôle - Non alimenté pas CTI">
				</COLUMN>
				<COLUMN dataField="GHM"
					width="55"
					type="Char"
					visible="true"
					fixed="false"
					headerText="GHM initial" 
					textAlign="center" 
					otherFunction="text"
					totalFunction="text"
                    description="Numéro de GHM avant contrôle">
				</COLUMN>
			
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>

			
