<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="PMSI000266" label="PMSI. UCD OVALIDE" title="= 'PMSI. UCD OVALIDE : ' + VIEW.LAST_MAT2A_TEXT" database="iCTI" swf="*CTI_view1" softCode="iCTI_pmsi" skipFirstSelection="true" globals="PMSI_globals.XML" componentsFile="PMSI_components.XML" typeEts="1" helpDokuWIkiDir="" helpDokuWIkiFile="pmsi000266"  helpFile="iCTI_PMSI_PMSI000266.HTML">
	<CACHE cachable="false" />
	<VIEWPROPERTIES>
		<PROPERTY dataLink="VIEWPROPERTIES" nameField="name" valueField="value"/>
		<PROPERTY name="ROWS">
			<value><![CDATA[[EVAL 
				
				if ('[OPTION]' == 'ERR' ) {
					return "WHERE (	cti_quantite IS DISTINCT FROM mat2a_quantite OR
									cti_ecart IS DISTINCT FROM mat2a_ecart OR
									cti_depenses IS DISTINCT FROM mat2a_depenses) " ;
				}
				else {
					return "";
				}
				
			EVAL]]]></value>
		</PROPERTY>
	</VIEWPROPERTIES>
	<SELECTIONS label="" displayText="= var display:String = '';
					
					if (SELECT.OPTION  != 'ALL') {
						display = display + '#B#' + SELECT.OPTION_LABEL + '#/B# ';
					}
					
					if (display != '') {
					}
					return display;
					
					"> 
		<GROUP label="Lignes à afficher">
			<FIELD name="OPTION" width="200" label="" UI="combo" default="ALL">
				<OPTION label="Toutes les lignes" data="ALL" />
				<OPTION label="Uniquement les lignes en erreur" data="ERR" showIfNotDefault="true" />
			</FIELD>
		</GROUP>
	</SELECTIONS>
	<QUERIES>
		<QUERY label="">
			<SQL>
				<select><![CDATA[ 
					SELECT
						ucd.ucd_id,
						ucd.ucd_code,
						ucd.ucd_texte,
						
						ucd.cti_quantite,
						ucd.cti_depenses,
						ucd.cti_ecart,

						mat2a.mat2a_quantite,
						mat2a.mat2a_depenses,
						mat2a.mat2a_ecart
					FROM
						(
							SELECT
								mt2.ucd_code AS ucd_code,
								mt2.quantite AS mat2a_quantite,
								round(mt2.depenses) AS mat2a_depenses,
								round(mt2.ecart) AS mat2a_ecart
							FROM
								pmsi.w_mat2a_oqn_ucd mt2
								JOIN pmsi.p_mat2a_import ON p_mat2a_import.oid = mt2.mat2a_id
							WHERE
								p_mat2a_import.mat2a_annee::text || lpad(p_mat2a_import.mat2a_mois, 2, 0) = '[VIEW.LAST_MAT2A]'
							ORDER BY 1
						) mat2a 
						LEFT JOIN   
						(
							SELECT
								v_rss_ucd_1.ucd_id,
								v_rss_ucd_1.ucd_code AS ucd_code,
								v_rss_ucd_1.ucd_texte AS ucd_texte,
								round(sum(v_rss_ucd_1.nombre)) AS cti_quantite,
								round(sum(v_rss_ucd_1.montant_facture)) AS cti_depenses,
								round(sum(v_rss_ucd_1.montant_ecart_indemnisable)) AS cti_ecart
							FROM 
								pmsi.v_rss_ucd_1 
								JOIN pmsi.v_rss_1 ON v_rss_1.rss_id = v_rss_ucd_1.rss_id
								JOIN (
										SELECT rss_id FROM pmsi.v_rsf_detail_1 WHERE prestation_code = 'PH8' GROUP BY 1
									) rsf on rsf.rss_id = v_rss_ucd_1.rss_id
							WHERE
								v_rss_1.date_sortie between '[VIEW.LAST_MAT2A_FROM]'::date AND '[VIEW.LAST_MAT2A_TO]'::date
								AND v_rss_1.en_cours = '0'
								AND traitement_epmsi IN ('30')
                                AND v_rss_ucd_1.type_ucd_code = 'SUS'::text
							GROUP BY 1,2,3
						) ucd ON mat2a.ucd_code = ucd.ucd_code
					[VIEW.ROWS]
					ORDER BY 2
					;
				]]>
				</select>
				<FIELDS>
					<FIELD name="UCD_ID"/>
					<FIELD name="UCD_CODE"/>
					<FIELD name="UCD_TEXTE"/>
					
					<FIELD name="CTI_QUANTITE"/>
					<FIELD name="CTI_DEPENSES"/>
					<FIELD name="CTI_ECART"/>
					
					<FIELD name="MAT2A_QUANTITE"/>
					<FIELD name="MAT2A_DEPENSES"/>
					<FIELD name="MAT2A_ECART"/>
				</FIELDS>
			</SQL>
		</QUERY>
		<QUERY type="propertiesLink" name="VIEWPROPERTIES" forSelections="false">
			<SQL>
				<select><![CDATA[	
				
						SELECT 'LAST_MAT2A'::text, coalesce(max(mat2a_annee::text || lpad(mat2a_mois, 2, 0)::text), '2099-12-31') FROM pmsi.p_mat2a_import
					UNION
						SELECT 'LAST_MAT2A_FROM'::text, coalesce(to_char(date_trunc('year', to_date(max(mat2a_annee::text || lpad(mat2a_mois, 2, 0)::text), 'YYYYMM')), 'YYYY-MM-DD'), '2099-12-31') FROM pmsi.p_mat2a_import
					UNION
						SELECT 'LAST_MAT2A_TO'::text, coalesce(to_char((to_date(max(mat2a_annee::text || lpad(mat2a_mois, 2, 0)::text), 'YYYYMM') + interval '1 month' - interval '1 day'), 'YYYY-MM-DD'), '2099-12-31') FROM pmsi.p_mat2a_import
					UNION
						SELECT 'LAST_MAT2A_TEXT'::text, base.cti_to_french(to_char((to_date(max(mat2a_annee::text || lpad(mat2a_mois, 2, 0)::text), 'YYYYMM') + interval '1 month' - interval '1 day'), 'Mon YYYY')) FROM pmsi.p_mat2a_import
				]]></select>
				<FIELDS>
					<FIELD name="name"/>
					<FIELD name="value"/>
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>
	<PRESENTATION>
		<VIEWLINKS>
			<VIEWLINK label="Liste UCD" shortLabel="Liste UCD" view="PMSI000149.XML">
				<ARG name="_OPTION_FORCEDEFAULT"><value><![CDATA[ return '1'; ]]></value></ARG>
				<ARG name="UCD"><value><![CDATA[ return 'UC' + ROW.UCD_ID; ]]></value></ARG>
				<ARG name="CHAMP"><value><![CDATA[ return 'EXVA'; ]]></value></ARG>
				<ARG name="PERIODE"><value><![CDATA[ return VIEW.LAST_MAT2A_FROM; ]]></value></ARG>
				<ARG name="TOPERIODE"><value><![CDATA[ return VIEW.LAST_MAT2A_TO; ]]></value></ARG>
				<ARG name="GROUPBY"><value><![CDATA[ return 'UCD'; ]]></value></ARG>
				<ARG name="T_DUREE_SEJOUR"><value><![CDATA[ return '-1'; ]]></value></ARG>
			</VIEWLINK>
		</VIEWLINKS>
		<ONGLET>
			<DATAGRID title="Chiffrier OVALIDE" headerHeight="48" >
				
				
				<COLUMN dataField="UCD_ID" type="Char" width="100" headerText="UCD id" visible="false" />
				<COLUMN dataField="UCD_CODE" type="Char" width="80" headerText="UCD code" />
				<COLUMN dataField="UCD_TEXTE" type="Char" minWidth="300" headerText="UCD texte" />
				
				
				
				<COLUMN dataField="CTI_QUANTITE" type="Number" width="80" outputFormat="#" headerText="Quantité&#xD;CTI" textAlign="left">
					<HEADERCELLSTYLE name="backgroundColor" value="0xFFD393"/>
					<CELLSTYLE name="cellIndicator" value="circle, 5, right middle, 0xFFA500" condition="ROW.CTI_QUANTITE != ROW.MAT2A_QUANTITE" />
				</COLUMN>
				<COLUMN dataField="MAT2A_QUANTITE" type="Number" width="80" outputFormat="#" headerText="Quantité&#xD;OVALIDE" textAlign="left">
					<HEADERCELLSTYLE name="backgroundColor" value="0xFFD393"/>
				</COLUMN>
				
				
				
				<COLUMN dataField="CTI_DEPENSES" type="Number" width="80" outputFormat="0#E" headerText="Dépenses&#xD;CTI" textAlign="left">
					<CELLSTYLE name="cellIndicator" value="circle, 5, right middle, 0xFFA500" condition="ROW.CTI_DEPENSES != ROW.MAT2A_DEPENSES" />
				</COLUMN>
				<COLUMN dataField="MAT2A_DEPENSES" type="Number" width="80" outputFormat="0#E" headerText="Dépenses&#xD;OVALIDE" textAlign="left" />
				
				
				
				<COLUMN dataField="CTI_ECART" type="Number" width="80" outputFormat="0#E" headerText="Ecart&#xD;CTI" textAlign="left">
					<HEADERCELLSTYLE name="backgroundColor" value="0xFFD393"/>
					<CELLSTYLE name="cellIndicator" value="circle, 5, right middle, 0xFFA500" condition="ROW.CTI_ECART != ROW.MAT2A_ECART" />
				</COLUMN>
				<COLUMN dataField="MAT2A_ECART" type="Number" width="80" outputFormat="0#E" headerText="Ecart&#xD;OVALIDE" textAlign="left">
					<HEADERCELLSTYLE name="backgroundColor" value="0xFFD393"/>
				</COLUMN>
				
				
				
				<COLUMN dataField="" type="Char" width="100" headerText="" />
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>
