<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="ECO000080" label="ECO. Justificatif UCD" title="= 'Justificatif des mouvements de UCD par ' + SELECT.GROUPBY_LABEL + ' de ' + SELECT.PERIODE_LABEL + ' à ' + SELECT.TOPERIODE_LABEL " database="iCTI" swf="*CTI_view1" globals="ECO_globals.XML" componentsFile="ECO_components.XML" dboptimizer="ECO_dboptimizer.XML" softCode="iCTI_eco">

	<VIEWPROPERTIES componentName="PROPERTIES_MOUVEMENTS"/>
	<VIEWPROPERTIES componentName="PROPERTIES_GROUPBY"/>
	<VIEWPROPERTIES componentName="PROPERTIES_DATA"/>

	<SELECTIONS label="Paramètres de l'analyse" displayText="">
		<GROUP label="Période">
			<FIELD name="ALIAS_PERIODE" label="" UI="combo" width="180" default="CUM_LAST_MONTH" tree="true" globalListProvider="ALIAS_PERIODE" />
			<FIELD name="PERIODE" label="" UI="combo" tree="true" width="200" default="2010-01-01" globalListProvider="PERIODE_DEBUT">
			</FIELD>
			<FIELD name="TOPERIODE" label="au" UI="combo" tree="true" width="200" default="2010-01-31" globalListProvider="PERIODE_FIN">
			</FIELD>
		</GROUP>

		<GROUP label="Regroupement">
			<FIELD name="GROUPBY" label="" UI="combo" width="200" default="SEJ" tree="true" visible = "false">
				<OPTION label="Séjour" data="SEJ" />
			</FIELD>
			<FIELD name="GROUPBY_TAB" width="100" label="Présentation" UI="combo" default="AUTO" visible="false">
				<OPTION label="Automatique" data="AUTO"/>
				<OPTION label="Arbre" data="TREE"/>
				<OPTION label="Onglet" data="TAB"/>
			</FIELD>
			<FIELD name="GROUPBY_2" label="" UI="combo" width="200" default="RSS" tree="true" visible = "false">
				<OPTION label="RSS" data="RSS" />
			</FIELD>
			<FIELD name="GROUPBY_3" label="" width="200" UI="combo" default="UCD" tree="true" visible="false">
				<OPTION label="UCD" data="UCD" />
			</FIELD>
		</GROUP>

	</SELECTIONS>
	<SELECTIONS componentName="FILTRES_ARTICLE_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_FOURNISSEUR_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_MOUVEMENT_SELECTIONS"/>
	<SELECTIONS componentName="FILTRES_PROVIDER_SELECTIONS"/>
	<SELECTIONS label="Filtre Indicateur" collapsible="true" displayText="= var display:String = '';

					if (SELECT.DATA01 != '-1') {
						display = display + '  #B#Indicateur#/B# = ' + SELECT.DATA01_LABEL;
					}
					return display;">

		<GROUP label="">
			<FIELD name="DATA01" label="Indicateur" UI="combo" width="210" default="-1" tree="true">
				<OPTION label="" data="-1"/>
				<OPTION label="" data="" globalListProvider="DATA_AP_IND" condition="dataItem.data5 &gt; 10 and dataItem.data5 &lt; 20"/>
			</FIELD>
		</GROUP>
	</SELECTIONS>
	<QUERIES>
		<QUERY labele="">
			<SQL optimizer="V_MOUVEMENTS_ARTICLES_X" optimizer2="V_ALL_X">
				<select><![CDATA[		

					DROP TABLE IF EXISTS ECO000080;
					CREATE TEMP TABLE ECO000080 AS 
					SELECT
						rss_id,
						rss_code,
						rss_texte,
						sejour_id,
						sejour_code,
						sejour_texte,
						CASE WHEN ucd_id > 0 THEN ucd_id ELSE 0-article_id END AS ucd_id,
						CASE WHEN ucd_id > 0 THEN ucd_code ELSE 'A-'||article_code END AS ucd_code,
						CASE WHEN ucd_id > 0 THEN ucd_texte ELSE article_texte END AS ucd_texte,
						lpp_id,
						CASE WHEN ucd_tarifs_id IS NOT NULL THEN 'SUS' ELSE 'INC' END AS type_ucd_code,
						date::date as date,
						SUM(sortie_quantite-entree_quantite) AS sortie_quantite,
						SUM(sortie_montant-entree_montant) AS sortie_montant,
						AVG(prix_unitaire) As prix_unitaire,
						MAX(montant_ligne_facture) AS montant_ligne_facture,
						MAX(quantite_ligne_facture) AS quantite_ligne_facture,
						MAX(ca_ghs) AS ca_ghs,
						MAX(encours) AS encours,	  
						MAX(ucd_code || ' ' || article_code || ' ' || article_texte)::text AS article_texte,
						array_to_string(array_agg(DISTINCT type_mouvement_code),',') AS type_mouvement_code,
						array_to_string(array_agg(DISTINCT lieu_code),',') AS lieu_code,
						array_to_string(array_agg(DISTINCT unite_fonctionnelle_code),',') AS UF_CODE,
						array_to_string(array_agg(DISTINCT gestionnaire_code),',') as gestionnaire_code,
						array_to_string(array_agg(DISTINCT CASE WHEN unite_stockage_article_id <> 0 AND unite_stockage_article_code <> 'UN' THEN unite_stockage_article_texte ELSE '' END),',') as unite_stockage_article_texte
					FROM #V_MOUVEMENTS_ARTICLES_X##V_ALL_X#
					WHERE (date BETWEEN '[PERIODE]' AND '[TOPERIODE]')
						AND (ucd_id != 0 OR type_article_cti_code = 'MED')
						AND type_mouvement_id IN (SELECT to_id from eco.t_classes JOIN eco.t_classes_sections ON t_classes.oid = classe_id
							JOIN eco.t_classes_sections_elements ON section_id = t_classes_sections.oid
							WHERE t_classes.code = 'CTI_TYPMVT' AND t_classes_sections.code = '01')
						AND sejour_code IS NOT NULL
						AND sejour_code <> ''
						[VIEW.ARTICLE_SELECT]
						[VIEW.FOURNISSEUR_SELECT]
						[VIEW.MOUVEMENT_SELECT]
						[VIEW.PROVIDER_SELECT]
					GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12
					;

				
				]]>				</select>
			</SQL>
			<SQL optimizer="V_MOUVEMENTS_ARTICLES_X" optimizer2="V_ALL_X">
				<select><![CDATA[		
					SELECT
						[VIEW.GROUPBY_OID_FIELD],
						[VIEW.GROUPBY_COD_FIELD],
						[VIEW.GROUPBY_TXT_FIELD],
						[VIEW.GROUPBY_2_OID_FIELD],
						[VIEW.GROUPBY_2_COD_FIELD],
						[VIEW.GROUPBY_2_TXT_FIELD],
						[VIEW.GROUPBY_3_OID_FIELD],
						[VIEW.GROUPBY_3_COD_FIELD],
						[VIEW.GROUPBY_3_TXT_FIELD],
						date::text,
						type_ucd_code,
						sum(sortie_quantite),
						sum(sortie_montant),
						sum(CASE WHEN montant_ligne_facture = 0 THEN ca_ghs ELSE 0 END),
						base.cti_division(sum(CASE WHEN quantite_ligne_facture = 0 THEN 100*sortie_montant ELSE 0 END),sum(CASE WHEN montant_ligne_facture = 0 THEN ca_ghs ELSE 0 END)),
						sum(CASE WHEN quantite_ligne_facture != 0  THEN quantite_ligne_facture ELSE 0 END),
						sum(CASE WHEN quantite_ligne_facture != 0  THEN montant_ligne_facture ELSE 0 END),
						sum(CASE WHEN quantite_ligne_facture != 0  THEN sortie_quantite - quantite_ligne_facture ELSE 0 END),
						sum(CASE WHEN quantite_ligne_facture != 0  THEN sortie_montant - montant_ligne_facture ELSE 0 END),
						AVG(prix_unitaire),
						AVG(CASE WHEN quantite_ligne_facture != 0  THEN sortie_montant/quantite_ligne_facture ELSE 0 END),
						MAX(article_texte),
						MAX(type_ucd_code)::text ,
						MAX(type_mouvement_code)::text ,
						MAX(lieu_code)::text ,
						MAX(uf_code)::text ,
						MAX(gestionnaire_code)::text ,
						MAX(unite_stockage_article_texte)::text
					FROM ECO000080 v_eco_view_1
					WHERE 1=1
						[VIEW.MOUVEMENT_FACTURE_SELECT]
				GROUP BY 1,2,3,4,5,6,7,8,9,10,11
				UNION ALL
				SELECT
						-9999999 AS LVL,
						'TOTAL', 
						COUNT(DISTINCT rss_texte)::text || ' Patients',
						0,
						COUNT(DISTINCT rss_id)::text || ' RSS',
						'',
						0,
						COUNT(DISTINCT ucd_id)::text || ' UCD',
						'',
						'',
						'',
						sum(sortie_quantite),
						sum(sortie_montant),
						sum(CASE WHEN montant_ligne_facture = 0 THEN ca_ghs ELSE 0 END),
						base.cti_division(sum(CASE WHEN montant_ligne_facture = 0 THEN 100*sortie_montant ELSE 0 END),sum(CASE WHEN montant_ligne_facture = 0 THEN ca_ghs ELSE 0 END)),
						sum(CASE WHEN quantite_ligne_facture != 0  THEN quantite_ligne_facture ELSE 0 END),
						sum(CASE WHEN quantite_ligne_facture != 0  THEN montant_ligne_facture ELSE 0 END),
						sum(CASE WHEN quantite_ligne_facture != 0  THEN sortie_quantite - quantite_ligne_facture ELSE 0 END),
						sum(CASE WHEN quantite_ligne_facture != 0  THEN sortie_montant - montant_ligne_facture ELSE 0 END),
						AVG(prix_unitaire),
						AVG(CASE WHEN quantite_ligne_facture != 0  THEN sortie_montant/quantite_ligne_facture ELSE 0 END),
						MAX(article_texte),
						''::text ,
						MAX(type_mouvement_code)::text ,
						MAX(lieu_code)::text ,
						MAX(uf_code)::text ,
						MAX(gestionnaire_code)::text ,
						MAX(unite_stockage_article_texte)::text
					FROM ECO000080 v_eco_view_1
					WHERE 1=1
						[VIEW.MOUVEMENT_FACTURE_SELECT]
				GROUP BY 1,2
				;
				]]>				</select>
				<FIELDS>
					<!-- <INSERT name="CTISELECT_TREE_FIELDS"/> -->
					<FIELD name="OID1" />
					<FIELD name="COD1" />
					<FIELD name="TXT1" />
					<FIELD name="OID2" />
					<FIELD name="COD2" />
					<FIELD name="TXT2" />
					<FIELD name="OID3" />
					<FIELD name="COD3" />
					<FIELD name="TXT3" />
					<FIELD name="DATE" />
					<FIELD name="SUS" />
					<FIELD name="QSOR" />
					<FIELD name="MSOR" />
					<FIELD name="MGHS" />
					<FIELD name="PGHS" />
					<FIELD name="QFAC" />
					<FIELD name="MFAC" />
					<FIELD name="QECA" />
					<FIELD name="MECA" />
					<FIELD name="PU" />
					<FIELD name="PUF" />

					<FIELD name="ARTI" />
					<FIELD name="TUCD" />
					<FIELD name="TMVT" />
					<FIELD name="LIEU" />
					<FIELD name="UF" />
					<FIELD name="GEST" />
					<FIELD name="UNIT" />
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>

	<PRESENTATION>
		<VIEWLINKS>
			<VIEWLINK label="Détail mouvements séjour" shortLabel="Mouvements séjour" view="ECO000010.XML" componentName="ECO_VIEWLINK">
				<ARGS name="SPEC">
					<value><![CDATA[
						LINKVARIABLES['RSS'] = ROW.COD2
						LINKVARIABLES['SEJ'] = ROW.COD1
						LINKVARIABLES['UCD'] = 'DT' + ROW.OID3
						LINKVARIABLES['GROUPBY'] = 'UCD'
						LINKVARIABLES['GROUPBY_2'] = 'MVT'
						return 'OK';
					]]>					</value>
				</ARGS>
			</VIEWLINK>
			<VIEWLINK label="Détail Séjour Activité" shortLabel="Dossier Activité" view="ACTI000020.XML" rowcontext="true" visible="= ROW.COD1 != '0'">
				<ARGS name="SPEC">
					<value><![CDATA[
						LINKVARIABLES['SEJOUR'] = ROW.COD1
						return 'OK';
					]]>					</value>
				</ARGS>
			</VIEWLINK>
			<VIEWLINK label="Détail RSS PMSI" shortLabel="Dossier PMSI" view="PMSI000006.XML" rowcontexte="true" visible="= ROW.COD2 != '0'">
				<ARGS name="SPEC">
					<value><![CDATA[
						LINKVARIABLES['OID'] = ROW.OID2
						return 'OK';
					]]>					</value>
				</ARGS>
			</VIEWLINK>
		</VIEWLINKS>
		<ONGLET label="Onglet" multiTab="true">

			<DATAGRID title="" total="true" headerHeight="40" totalRowInRows="= ROW.OID1 == '-9999999'" variableRowHeight="true">


				<COLUMN dataField="OID1" type="Number" visible="false" />
				<COLUMN dataField="COD1" type="Char" width="100" outputFormat="#" headerText="N° Séjour" textAlign="left" totalComplement="*ROW">
				</COLUMN>
				<COLUMN dataField="OID2" type="Number" visible="false" />
				<COLUMN dataField="COD2" type="Char" width="100" outputFormat="#" headerText="N° RSS" textAlign="left" totalComplement="*ROW">
				</COLUMN>
				<COLUMN dataField="TXT1" type="Char" width="100" headerText="N° Patient" textAlign="left" totalComplement="*ROW"/>
				<COLUMN dataField="DATE" type="Date" width="100" headerText="Date" textAlign="left" totalComplement="*ROW"/>
				<COLUMN dataField="OID3" type="Number" visible="false" />
				<COLUMN dataField="COD3" type="Char" width="100" outputFormat="#" headerText="Code UCD" textAlign="left" totalComplement="*ROW">
				</COLUMN>
				<COLUMN dataField="TXT3" type="Char" minWidth="100" headerText="Texte" textAlign="left" totalComplement="*ROW"/>

				<COLUMN dataField="TUCD" type="Char" width="40" headerText="Type UCD" textAlign="left" totalComplement="*ROW"/>
				<COLUMN dataField="PU" type="Number" width="60" outputFormat="#E" headerText="PU Stock" textAlign="right" totalComplement="*ROW" />
				<COLUMN dataField="QSOR" type="Number" width="80" outputFormat="#" headerText="Sorties" textAlign="right" totalComplement="*ROW" />
				<COLUMN dataField="MSOR" type="Number" width="80" outputFormat="#E" headerText="Montant Sorties" textAlign="right" totalComplement="*ROW" />
				<COLUMN dataField="PUF" type="Number" width="60" outputFormat="#E" headerText="PU facturé" textAlign="right" totalComplement="*ROW" />

				<COLUMN dataField="QFAC" type="Number" width="80" outputFormat="#" headerText="UCD Facturés" textAlign="right" totalComplement="*ROW" />
				<COLUMN dataField="MFAC" type="Number" width="80" outputFormat="#E" headerText="Montant Facturé" textAlign="right" totalComplement="*ROW" />
				<COLUMN dataField="QECA" type="Number" width="80" outputFormat="#" headerText="Qté Ecart" textAlign="right" totalComplement="*ROW" />
				<COLUMN dataField="MECA" type="Number" width="80" outputFormat="#E" headerText="Montant Ecart" textAlign="right" totalComplement="*ROW" />
				<COLUMN dataField="MGHS" type="Number" width="80" outputFormat="#E" headerText="CA GHS théorique" textAlign="right" totalComplement="*ROW" />
				<COLUMN dataField="PGHS" type="Number" width="80" outputFormat="#%" headerText="Part dans le GHS" textAlign="right" totalComplement="*ROW" />
				<COLUMN dataField="TMVT" type="Char" width="40" headerText="Mvt" textAlign="left" totalComplement="*ROW"/>
				<COLUMN dataField="LIEU" type="Char" width="50" headerText="Lieu" textAlign="left" totalComplement="*ROW"/>
				<COLUMN dataField="UF" type="Char" width="50" headerText="U.F." textAlign="left" totalComplement="*ROW"/>
				<COLUMN dataField="GEST" type="Char" width="60" headerText="Gest" textAlign="left" totalComplement="*ROW"/>
				<COLUMN dataField="UNIT" type="Char" width="50" headerText="Unité" textAlign="left" totalComplement="*ROW"/>
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>

			
