<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="PMSI000144"
	label="PMSI. Justificatif SRC par critères"
	title="= 'Justificatif SRC (' + SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL + ') - ' + SELECT.VERSION_GROUPAGE_LABEL"
	database="iCTI"
	swf="*CTI_view1"
	softCode="iCTI_pmsi"
	globals="PMSI_globals.XML"
	componentsFile="PMSI_components.XML">

	<VIEWPROPERTIES>
		<PROPERTY name="NO_RSS_SELECT">
			<value><![CDATA[[EVAL

				if (('[NO_RSS]' + 0) != 0) {return 'AND v_rss_1.no_rss = ' . ('[NO_RSS]' + 0);}
				return '';

			EVAL]]]></value>
		</PROPERTY>
		<PROPERTY name="NOM_SELECT">
			<value><![CDATA[[EVAL

				if ('[NOM]' != '') {return 'AND identite_nom ILIKE ' .''. '[NOM]%' .''.  ' ' ;}
				return '';

			EVAL]]]></value>
		</PROPERTY>
		<PROPERTY name="IND_SRC_SELECT">
			<value><![CDATA[[EVAL

				if ('[IND_SRC]' == 'FRE') {return 'AND temp_pmsi000143_rss.src_facturee_nb_rss <> 0 ';}
				if ('[IND_SRC]' == 'FLE') {return 'AND temp_pmsi000143_rss.src_facturable_nb_rss <> 0 ';}
				if ('[IND_SRC]' == 'ECA') {return 'AND (temp_pmsi000143_rss.src_facturable_nb_rss <> temp_pmsi000143_rss.src_facturee_nb_rss
													OR temp_pmsi000143_rss.src_facturable_nb_prestations <> temp_pmsi000143_rss.src_facturee_nb_prestations
													OR temp_pmsi000143_rss.src_facturable_base_remboursement <> temp_pmsi000143_rss.src_facturee_base_remboursement
													) ';}
				if ('[IND_SRC]' == 'ECARSS') {return 'AND temp_pmsi000143_rss.src_facturable_nb_rss <> temp_pmsi000143_rss.src_facturee_nb_rss';}
				if ('[IND_SRC]' == 'ECADUR') {return 'AND temp_pmsi000143_rss.src_facturable_nb_prestations <> temp_pmsi000143_rss.src_facturee_nb_prestations';}
				if ('[IND_SRC]' == 'ECACA') {return 'AND temp_pmsi000143_rss.src_facturable_base_remboursement <> temp_pmsi000143_rss.src_facturee_base_remboursement';}
				if ('[IND_SRC]' == 'SRCNF') {return 'AND temp_pmsi000143_rss.src_facturable_nb_rss = 0 AND src_facturee_nb_rss = 0 AND temp_pmsi000143_rss.src_passage_nb_rss <> 0 ';}
				if ('[IND_SRC]' == 'NSRCF') {return 'AND temp_pmsi000143_rss.src_facturable_sans_src_ni_igs_nb_rss <> 0 ';}
				return '';

			EVAL]]]></value>
		</PROPERTY>
	</VIEWPROPERTIES>

	<SELECTIONS label="Paramètres de l'analyse" displayText="= var display:String = '';
					if (SELECT.IND_SRC  != '-1') {
						display = display + '#B#' + SELECT.IND_SRC_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 name="TOPERIODE" label="à" UI="combo" tree="true" width="200" default="2014-12-31"  globalListProvider="DATE_FIN" printable="false" />
		</GROUP>

		<GROUP label="Indicateur SRC">
			<FIELD name="IND_SRC" label="" UI="combo" default="-1" printable="false">
				<OPTION label="Pas de filtre" data="-1" />
				<OPTION label="SRC facturées" data="FRE" />
				<OPTION label="SRC facturables" data="FLE" />
				<OPTION label="Tout écart facturables/facturées" data="ECA" />
				<OPTION label="Ecarts RSS facturables/facturées" data="ECARSS" />
				<OPTION label="Ecarts Durée facturables/facturées" data="ECADUR" />
				<OPTION label="Ecarts CA facturables/facturées" data="ECACA" />
				<OPTION label="Séjours Passés en SRC mais non facturables" data="SRCNF" />
				<OPTION label="Séjours Non passés en SRC avec un acte éligible" data="NSRCF" />
			</FIELD>
		</GROUP>

		<GROUP label="N° de RSS">
			<FIELD name="NO_RSS" label="" UI="number" width="100" default="" showIfNotDefault="true" />
		</GROUP>
		<GROUP label="Ou Nom">
			<FIELD name="NOM" label="" UI="text" width="200" default="" showIfNotDefault="true" />
		</GROUP>
	</SELECTIONS>

	<SELECTIONS componentName="FILTRES_RSS_SELECTIONS" />

	<QUERIES>
		<QUERY label="">

			<SQL optimizer="V_RSS_X" cacheEnabled="false">
				<select><![CDATA[

					(SELECT
						v_rss_1.rss_id,
						v_rss_1.no_rss,
						v_rss_1.en_cours_texte_tres_court,
						CASE WHEN patient_no_patient > 0 THEN patient_no_patient ELSE 0 END,
						v_rss_1.no_sejour_administratif,
						v_rss_1.finess,
						identite_nom::text || ' '::text || identite_prenom::text,
						ghm_code,
						diagnostic_principal_code,
						acte_principal_code,
						v_rss_1.date_entree,
						v_rss_1.date_sortie,
						v_rss_1.age,
						igs2_rum,
						CASE
							WHEN v_rss_1.age BETWEEN 40 AND 59 THEN igs2_rum - 7
							WHEN v_rss_1.age BETWEEN 60 AND 69 THEN igs2_rum - 12
							WHEN v_rss_1.age BETWEEN 70 AND 74 THEN igs2_rum - 15
							WHEN v_rss_1.age BETWEEN 75 AND 79 THEN igs2_rum - 16
							WHEN v_rss_1.age >= 80 THEN igs2_rum - 18
							ELSE igs2_rum END as igs_sauf_age,
						temp_pmsi000143_rss.src_facturee_nb_prestations,
						temp_pmsi000143_rss.src_facturee_base_remboursement,
						temp_pmsi000143_rss.src_facturable_nb_prestations,
						temp_pmsi000143_rss.src_facturable_base_remboursement,
						temp_pmsi000143_rss.src_facturable_nb_prestations -	temp_pmsi000143_rss.src_facturee_nb_prestations,
						temp_pmsi000143_rss.src_facturable_base_remboursement -	temp_pmsi000143_rss.src_facturee_base_remboursement,

						temp_pmsi000143_rss.src_facturable_regle_justificatif,
						v_rss_1.mode_entree::text || v_rss_1.provenance::text

					FROM
						#V_RSS_X#
						JOIN pmsi.p_rss_src temp_pmsi000143_rss ON v_rss_1.rss_id = temp_pmsi000143_rss.oid
					WHERE 1=1
						AND mois_sortie IN ([VIEW.PERIODE_MOIS_LIST])
						AND v_rss_1.date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						[VIEW.FILTRE_RSS_SELECT]
						[VIEW.IND_SRC_SELECT]
					)

					UNION ALL

					(SELECT
						-9999997,
						null,
						'',
						0,
						'',
						'',
						count(DISTINCT v_rss_1.rss_id)::text || ' RSS dans la sélection'::text ,
						'',
						'',
						'',
						null,
						null,
						0,
						0,
						0,

						sum(temp_pmsi000143_rss.src_facturee_nb_prestations),
						sum(temp_pmsi000143_rss.src_facturee_base_remboursement),
						sum(temp_pmsi000143_rss.src_facturable_nb_prestations),
						sum(temp_pmsi000143_rss.src_facturable_base_remboursement),
						sum(temp_pmsi000143_rss.src_facturable_nb_prestations -	temp_pmsi000143_rss.src_facturee_nb_prestations),
						sum(temp_pmsi000143_rss.src_facturable_base_remboursement -	temp_pmsi000143_rss.src_facturee_base_remboursement),

						'',
						''::text

					FROM
						#V_RSS_X#
						JOIN pmsi.p_rss_src temp_pmsi000143_rss ON v_rss_1.rss_id = temp_pmsi000143_rss.oid
					WHERE 1=1
						AND mois_sortie IN ([VIEW.PERIODE_MOIS_LIST])
						AND v_rss_1.date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						[VIEW.FILTRE_RSS_SELECT]
						[VIEW.IND_SRC_SELECT]
					)

					UNION ALL

					(SELECT
						-9999999,
						null,
						'',
						0,
						'',
						'',
						SUM(temp_pmsi000143_rss.src_facturee_nb_rss)::text || ' RSS facturés, '::text  || SUM(temp_pmsi000143_rss.src_facturable_nb_rss)::text || ' RSS facturables'::text,
						'',
						'',
						'',
						null,
						null,
						0,
						0,
						0,

						sum(temp_pmsi000143_rss.src_facturee_nb_prestations),
						sum(temp_pmsi000143_rss.src_facturee_base_remboursement),
						sum(temp_pmsi000143_rss.src_facturable_nb_prestations),
						sum(temp_pmsi000143_rss.src_facturable_base_remboursement),
						sum(temp_pmsi000143_rss.src_facturable_nb_prestations -	temp_pmsi000143_rss.src_facturee_nb_prestations),
						sum(temp_pmsi000143_rss.src_facturable_base_remboursement -	temp_pmsi000143_rss.src_facturee_base_remboursement),

						'',
						''::text

					FROM
						#V_RSS_X#
						JOIN pmsi.p_rss_src temp_pmsi000143_rss ON v_rss_1.rss_id = temp_pmsi000143_rss.oid
					WHERE 1=1
						AND mois_sortie IN ([VIEW.PERIODE_MOIS_LIST])
						AND v_rss_1.date_sortie BETWEEN '[PERIODE]' AND '[TOPERIODE]'
						[VIEW.FILTRE_RSS_SELECT]
					)

					ORDER BY 2;

				]]></select>
				<FIELDS>
					<FIELD name="OID" />
					<FIELD name="RSS" />
					<FIELD name="EXP" />
					<FIELD name="PAT" />
					<FIELD name="SEJ" />
					<FIELD name="FIN" />
					<FIELD name="NOM"  ifHideNames="Non autorisé" />
					<FIELD name="GHM" />
					<FIELD name="DIAGP" />
					<FIELD name="ACTEP" />
					<FIELD name="DATE" />
					<FIELD name="DATS" />
					<FIELD name="AGE" />
					<FIELD name="IGS" />
					<FIELD name="IGSAGE" />

					<FIELD name="FREDUR" />
					<FIELD name="FRECA" />
					<FIELD name="FLEDUR" />
					<FIELD name="FLECA" />
					<FIELD name="ECADUR" />
					<FIELD name="ECACA" />

					<FIELD name="COMMEN" />
					<FIELD name="PROV" />
				</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>
			<VIEWREF label="Arrêté du 1er mars 2024 relatif aux forfaits alloués aux établissements de santé mentionnés à l'article L. 162-22-6 du code de la sécurité sociale ayant des activités de médecine, chirurgie, obstétrique et odontologie ou ayant une activité d'hospitalisation à domicile"
				shortLabel="Arrêté Prestations 2024" url="https://www.atih.sante.fr/arrete-prestations-et-tarifaires-mco-2024" rowContext="false" />
		</VIEWLINKS>
		<ONGLET excelLabel="Liste RSS" >
			<DATAGRID title="" total="true" key="RSS" showOthers="true" headerHeight="54"
				totalRowInRows="= ROW.OID == '-9999999'"
				selectRowInRows="= ROW.OID == '-9999997'">
				<ROWSTYLE name="fontSize" value="11" />
				<FOOTERROWSTYLE name="fontSize" value="11" />

				<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="Number" visible="true" outputFormat="#" headerText="N° RSS" textAlign="center" otherFunction="text" totalFunction="text" totalComplement="" />
				<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="100" maxWidth="200" type="Char" visible="true" headerText="Nom" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="*ROW" />

				<COLUMN dataField="AGE" width="30" type="Number" outputFormat="#" fixed="false" visible="true" headerText="Age" textAlign="right" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="DATE" width="60" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" visible="true" fixed="false" headerText="Date entrée" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="DATS" width="60" type="Date" inputFormat="AAAA-MM-JJ" outputFormat="DD/MM/YY" visible="true" fixed="false" headerText="Date sortie" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="PROV" width="60" type="Char" visible="true" fixed="false" headerText="Provenance" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="EXP" width="30" type="Char" visible="true" fixed="false" headerText="EXP" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="GHM" width="50" type="Char" visible="true" fixed="false" headerText="GHM" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="DIAGP" width="40" type="Char" fixed="false" visible="true" headerText="Diag P" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="ACTEP" width="60" type="Char" fixed="false" visible="true" headerText="Acte P" textAlign="left" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="IGS" width="30" type="Number" outputFormat="#" fixed="false" visible="true" headerText="IGS" textAlign="right" otherFunction="text" totalFunction="text" />
				<COLUMN dataField="IGSAGE" width="40" type="Number" outputFormat="#" fixed="false" visible="true" headerText="IGS&#xD;sauf&#xD;âge" textAlign="right" otherFunction="text" totalFunction="text" />

				<COLUMN dataField="COMMEN" minWidth="150" maxWidth="200" type="Char" visible="true" fixed="false" headerText="Règle" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="*ROW" />
				<COLUMN dataField="FLEDUR" width="60" type="Number" outputFormat="#" fixed="false" headerText="Durée&#xD;facturable" textAlign="right" totalFunction="sum" otherFunction="sum" />
				<COLUMN dataField="FLECA" width="70" type="Number" outputFormat="#E" fixed="false" headerText="C.A.&#xD;facturable" textAlign="right" totalFunction="sum" otherFunction="sum" />

				<COLUMN dataField="FREDUR" width="60" type="Number" outputFormat="#" fixed="false" headerText="Durée&#xD;facturée" textAlign="right" totalFunction="sum" otherFunction="sum" />
				<COLUMN dataField="FRECA" width="70" type="Number" outputFormat="#E" fixed="false" headerText="C.A.&#xD;facturé" textAlign="right" totalFunction="sum" otherFunction="sum" />

				<COLUMN dataField="ECADUR" width="50" type="Number" outputFormat="#" fixed="false" headerText="Ecart&#xD;durée" textAlign="right" totalFunction="sum" otherFunction="sum" />
				<COLUMN dataField="ECACA" width="70" type="Number" outputFormat="#E" fixed="false" headerText="Ecart&#xD;C.A." textAlign="right" totalFunction="sum" otherFunction="sum" />
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>