<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="PMSI000255" label="PMSI. Chiffrier OVALIDE" database="iCTI" swf="*CTI_view1" softCode="iCTI_pmsi" helpDokuWIkiDir="pmsi:controles:ovalide" helpDokuWIkiFile="pmsi000255"  helpFile="iCTI_PMSI_PMSI000255.HTML">
	<CACHE cachable="false" />
	<QUERIES>
		<QUERY label="">
			<SQL>
				<select><![CDATA[ 
					SELECT
						last_rss_imports.oid AS import_id,
						CASE WHEN last_rss_imports.mat2a_ok = 0 THEN '' ELSE 'V' END AS mat2a_ok,
						last_rss_imports.annee,
						last_rss_imports.mois,
						to_char(date_import, 'DD/MM/YYYY') AS date_import,
						mat2a_rsa_transmis AS mat2a_rsa_transmis,
						nb_rsa_transmis AS cti_rsa_transmis,
						mat2a_rsa_traites AS mat2a_rsa_traites,
						nb_rsa_traites AS cti_rsa_traites,
						mat2a_rsa_0_nuits AS mat2a_rsa_0_nuits,
						nb_rsa_0_nuits AS cti_rsa_0_nuits,
						mat2a_rsa_seances AS mat2a_rsa_seances,
						nb_rsa_seances AS cti_rsa_seances,
						mat2a_rsa_prestations_nb_total AS mat2a_nb_rsa_prestations,
						nb_total_rsa_prestations AS cti_nb_rsa_prestations,
						round(mat2a_rsa_prestations_base_remb) AS mat2a_br_rsa_prestations,
						round(br_total_rsa_prestations) AS cti_br_rsa_prestations,
						mat2a_nb_sejours_valorises AS mat2a_nb_sejours_valorises,
						nb_sejours_valorises AS cti_nb_sejours_valorises,
						round(mat2a_br_sejours_valorises) AS mat2a_br_sejours_valorises,
						round(br_sejours_valorises) AS cti_br_sejours_valorises
						
					FROM
						(
						SELECT
							p_imports.*,
							p_imports_stats.*,
							subq2.annee,
							subq2.mois
						FROM pmsi.p_imports
							JOIN pmsi.p_imports_stats on p_imports_stats.import_id = p_imports.oid
							JOIN
								(
								SELECT 
									annee,
									max(mois) AS mois,
									(max(ARRAY [annee::text || lpad(mois, 2, '0'), lpad(oid::text, 4, '0')]))[2]::numeric AS oid
								FROM
									(
									SELECT 
										to_char(date_debut, 'YYYY') AS annee,
										to_char(date_fin - '3 days'::interval, 'MM') AS mois,
										oid
									FROM pmsi.p_imports
									WHERE 1=1
										AND date_fin - date_debut < 400 
										AND date_debut < now()
									) AS subq1
								GROUP BY 1
								) AS subq2 ON subq2.oid = p_imports.oid
						) AS last_rss_imports
						LEFT JOIN
							(
							SELECT *
							FROM pmsi.p_mat2a_import
							JOIN 
								(
								SELECT
									mat2a_annee::text || lpad(mat2a_mois, 2, '0') AS annee,
									(max(ARRAY [mat2a_date::text, oid::text]))[2] AS oid
								FROM pmsi.p_mat2a_import
								GROUP BY 1
								) AS subq1 ON subq1.oid = p_mat2a_import.oid
							) AS last_mat2a_imports ON last_rss_imports.annee::text || lpad(last_rss_imports.mois, 2, '0') = last_mat2a_imports.annee::text
					WHERE 1=1
						AND last_rss_imports.annee >= 2014 -- uniquement valable depuis 2014
					ORDER BY 3 DESC, 4 DESC
					;
				]]>
				</select>
				<FIELDS>
					<FIELD name="IMPORT_ID"/>
					<FIELD name="MAT2A_OK"/>
					<FIELD name="ANNEE"/>
					<FIELD name="MOIS"/>
					<FIELD name="DATE"/>
					<FIELD name="MAT2A_RSA_TRANSMIS"/>
					<FIELD name="CTI_RSA_TRANSMIS"/>
					<FIELD name="MAT2A_RSA_TRAITES"/>
					<FIELD name="CTI_RSA_TRAITES"/>
					<FIELD name="MAT2A_RSA_0_NUITS"/>
					<FIELD name="CTI_RSA_0_NUITS"/>
					<FIELD name="MAT2A_RSA_SEANCES"/>
					<FIELD name="CTI_RSA_SEANCES"/>
					<FIELD name="MAT2A_NB_RSA_PRESTATIONS"/>
					<FIELD name="CTI_NB_RSA_PRESTATIONS"/>
					<FIELD name="MAT2A_BR_RSA_PRESTATIONS"/>
					<FIELD name="CTI_BR_RSA_PRESTATIONS"/>
					<FIELD name="MAT2A_NB_SEJOURS_VALORISES"/>
					<FIELD name="CTI_NB_SEJOURS_VALORISES"/>
					<FIELD name="MAT2A_BR_SEJOURS_VALORISES"/>
					<FIELD name="CTI_BR_SEJOURS_VALORISES"/>
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>
	<PRESENTATION>
		<VIEWLINKS>
			<VIEWLINK label="Valider" shortLabel="Valider" view="PMSI000256.XML">
				<ARG name="VAL_OID" value="ROW.IMPORT_ID" />
				<ARG name="VAL_OPTION" value="'V'" />
			</VIEWLINK>
			<VIEWLINK label="IN-Valider" shortLabel="IN-Valider" view="PMSI000256.XML">
				<ARG name="VAL_OID" value="ROW.IMPORT_ID" />
				<ARG name="VAL_OPTION" value="'IV'" />
			</VIEWLINK>
		</VIEWLINKS>
		<ONGLET>
			<DATAGRID title="Chiffrier OVALIDE" headerHeight="48" >
				<COLUMN dataField="IMPORT_ID" type="Char" width="60" outputFormat="#" visible="false" />
				<COLUMN dataField="MAT2A_OK" type="Char" width="60" outputFormat="#" headerText="Validé" textAlign="left" />
				<COLUMN dataField="ANNEE" type="Char" width="60" outputFormat="#" headerText="Année" textAlign="left" />
				<COLUMN dataField="MOIS" type="Char" width="60" outputFormat="#" headerText="Mois" textAlign="left" />
				<COLUMN dataField="DATE" type="Char" width="80" outputFormat="#" headerText="Date" textAlign="left" />
				<COLUMN dataField="CTI_RSA_TRANSMIS" type="Number" width="90" outputFormat="#" headerText="RSA&#xD;transmis&#xD;CTI" textAlign="left">
					<CELLSTYLE name="cellIndicator" value="circle, 5, right middle, 0xFFA500" condition="ROW.CTI_RSA_TRANSMIS != ROW.MAT2A_RSA_TRANSMIS" />
					<HEADERCELLSTYLE name="backgroundColor" value="0xFFD393"/>
				</COLUMN>
				<COLUMN dataField="MAT2A_RSA_TRANSMIS" type="Number" width="90" outputFormat="#" headerText="RSA&#xD;transmis&#xD;OVALIDE" textAlign="left">
					<HEADERCELLSTYLE name="backgroundColor" value="0xFFD393"/>
				</COLUMN>
				<COLUMN dataField="CTI_RSA_TRAITES" type="Number" width="90" outputFormat="#" headerText="RSA&#xD;traités&#xD;CTI" textAlign="left">
					<CELLSTYLE name="cellIndicator" value="circle, 5, right middle, 0xFFA500" condition="ROW.CTI_RSA_TRAITES != ROW.MAT2A_RSA_TRAITES" />
				</COLUMN>
				<COLUMN dataField="MAT2A_RSA_TRAITES" type="Number" width="90" outputFormat="#" headerText="RSA&#xD;traités&#xD;OVALIDE" textAlign="left">
				</COLUMN>
				<COLUMN dataField="CTI_RSA_0_NUITS" type="Number" width="90" outputFormat="#" headerText="RSA&#xD;0 nuits&#xD;CTI" textAlign="left">
					<CELLSTYLE name="cellIndicator" value="circle, 5, right middle, 0xFFA500" condition="ROW.CTI_RSA_0_NUITS != ROW.MAT2A_RSA_0_NUITS" />
					<HEADERCELLSTYLE name="backgroundColor" value="0xFFD393"/>
				</COLUMN>
				<COLUMN dataField="MAT2A_RSA_0_NUITS" type="Number" width="90" outputFormat="#" headerText="RSA&#xD;0 nuits&#xD;OVALIDE" textAlign="left">
					<HEADERCELLSTYLE name="backgroundColor" value="0xFFD393"/>
				</COLUMN>
				<COLUMN dataField="CTI_RSA_SEANCES" type="Number" width="90" outputFormat="#" headerText="RSA&#xD;séances&#xD;CTI" textAlign="left">
					<CELLSTYLE name="cellIndicator" value="circle, 5, right middle, 0xFFA500" condition="ROW.CTI_RSA_SEANCES != ROW.MAT2A_RSA_SEANCES" />
				</COLUMN>
				<COLUMN dataField="MAT2A_RSA_SEANCES" type="Number" width="90" outputFormat="#" headerText="RSA&#xD;séances&#xD;OVALIDE" textAlign="left">
				</COLUMN>
				<COLUMN dataField="CTI_NB_RSA_PRESTATIONS" type="Number" width="90" outputFormat="#" headerText="Nombre&#xD;Prestations&#xD;CTI" textAlign="left" visible="false">
					<CELLSTYLE name="cellIndicator" value="circle, 5, right middle, 0xFFA500" condition="ROW.CTI_NB_RSA_PRESTATIONS != ROW.MAT2A_NB_RSA_PRESTATIONS" />
					<HEADERCELLSTYLE name="backgroundColor" value="0xFFD393"/>
				</COLUMN>
				<COLUMN dataField="MAT2A_NB_RSA_PRESTATIONS" type="Number" width="90" outputFormat="#" headerText="Nombre&#xD;Prestations&#xD;OVALIDE" textAlign="left" visible="false">
					<HEADERCELLSTYLE name="backgroundColor" value="0xFFD393"/>
				</COLUMN>
				<COLUMN dataField="CTI_BR_RSA_PRESTATIONS" type="Number" width="100" outputFormat="# E" headerText="Base Remb.&#xD;Prestations&#xD;CTI" textAlign="left" visibleCondition="ENV.TYPEETS == '1'">
					<CELLSTYLE name="cellIndicator" value="circle, 5, right middle, 0xFFA500" condition="ROW.CTI_BR_RSA_PRESTATIONS != ROW.MAT2A_BR_RSA_PRESTATIONS" />
				</COLUMN>
				<COLUMN dataField="MAT2A_BR_RSA_PRESTATIONS" type="Number" width="100" outputFormat="# E" headerText="Base Remb.&#xD;Prestations&#xD;OVALIDE" textAlign="left" visibleCondition="ENV.TYPEETS == '1'">
				</COLUMN>
				<COLUMN dataField="CTI_NB_SEJOURS_VALORISES" type="Number" width="90" outputFormat="#" headerText="Nb Séjours&#xD;valorisés&#xD;CTI" textAlign="left" visibleCondition="ENV.TYPEETS != '1'">
					<CELLSTYLE name="cellIndicator" value="circle, 5, right middle, 0xFFA500" condition="ROW.CTI_NB_SEJOURS_VALORISES != ROW.MAT2A_NB_SEJOURS_VALORISES" />
					<HEADERCELLSTYLE name="backgroundColor" value="0xFFD393"/>
				</COLUMN>
				<COLUMN dataField="MAT2A_NB_SEJOURS_VALORISES" type="Number" width="90" outputFormat="#" headerText="Nb Séjours&#xD;valorisés&#xD;OVALIDE" textAlign="left" visibleCondition="ENV.TYPEETS != '1'">
					<HEADERCELLSTYLE name="backgroundColor" value="0xFFD393"/>
				</COLUMN>
				<COLUMN dataField="CTI_BR_SEJOURS_VALORISES" type="Number" width="100" outputFormat="# E" headerText="Base Remb.&#xD;Séjours valorisés&#xD;CTI" textAlign="left" visibleCondition="ENV.TYPEETS != '1'">
					<CELLSTYLE name="cellIndicator" value="circle, 5, right middle, 0xFFA500" condition="ROW.CTI_BR_SEJOURS_VALORISES != ROW.MAT2A_BR_SEJOURS_VALORISES" />
				</COLUMN>
				<COLUMN dataField="MAT2A_BR_SEJOURS_VALORISES" type="Number" width="100" outputFormat="# E" headerText="Base Remb.&#xD;Séjours valorisés&#xD;OVALIDE" textAlign="left" visibleCondition="ENV.TYPEETS != '1'">
				</COLUMN>
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>
