<?xml version="1.0" encoding="ISO-8859-1"?>
<VUE name="COMPTA000052" 
	label="Compta. Evolution mensuelle coût patient SHS" 
	title="= 'Coût patient SHS par ' +  SELECT.GROUPBY_LABEL + ' (' + SELECT.MOIS_LABEL + ' à ' + SELECT.TOMOIS_LABEL + ' vs ' + SELECT.MOIS_D_LABEL + ' à ' + SELECT.TOMOIS_D_LABEL + ')'" 
	database="iCTI" 
	swf="*CTI_view1" 
	globals="COMPTA_globals.XML"
	componentsFile="COMPTA_components.XML"
	dboptimizer="COMPTA_dboptimizer.XML"
	softCode="iCTI_compta"
	softOption="iCTI_compta_analytique_shs">

	<VIEWPROPERTIES componentName="PROPERTIES_COUT_PATIENT"/>
	
	<VIEWPROPERTIES>
		<PROPERTY name="AFTER">
			<value><![CDATA[[EVAL 
								
								$after = "";
								
								switch ('[DATA1]') {
								case 'MCOU':
									$after = "$after indicateurs[7] = indicateurs[3], ";
									$after = "$after indicateurs[8] = indicateurs[4], ";
									break;
								case 'MFAC':
									$after = "$after indicateurs[7] = indicateurs[1], ";
									$after = "$after indicateurs[8] = indicateurs[2], ";
									break;
								case 'MRES':
									$after = "$after indicateurs[7] = indicateurs[1] - indicateurs[3], ";
									$after = "$after indicateurs[8] = indicateurs[2] - indicateurs[4], ";
									break;
								case 'MMCOU':
									$after = "$after indicateurs[7] = base.cti_division(indicateurs[3],indicateurs[5]), ";
									$after = "$after indicateurs[8] = base.cti_division(indicateurs[4],indicateurs[6]), ";
									break;
								case 'MMFAC':
									$after = "$after indicateurs[7] = base.cti_division(indicateurs[1],indicateurs[5]), ";
									$after = "$after indicateurs[8] = base.cti_division(indicateurs[2],indicateurs[6]), ";
									break;
								case 'MMRES':
									$after = "$after indicateurs[7] = base.cti_division((indicateurs[1] - indicateurs[3]),indicateurs[5]), ";
									$after = "$after indicateurs[8] = base.cti_division((indicateurs[2] - indicateurs[4]),indicateurs[6]), ";
									break;
								default:
									$after = "$after indicateurs[7] = indicateurs[1] - indicateurs[3], ";
									$after = "$after indicateurs[8] = indicateurs[2] - indicateurs[4], ";
								}
								
								switch ('[DATA2]') {
								case 'MCOU':
									$after = "$after indicateurs[11] = indicateurs[3], ";
									$after = "$after indicateurs[12] = indicateurs[4], ";
									break;
								case 'MFAC':
									$after = "$after indicateurs[11] = indicateurs[1], ";
									$after = "$after indicateurs[12] = indicateurs[2], ";
									break;
								case 'MRES':
									$after = "$after indicateurs[11] = indicateurs[1] - indicateurs[3], ";
									$after = "$after indicateurs[12] = indicateurs[2] - indicateurs[4], ";
									break;
								case 'MMCOU':
									$after = "$after indicateurs[11] = base.cti_division(indicateurs[3],indicateurs[5]), ";
									$after = "$after indicateurs[12] = base.cti_division(indicateurs[4],indicateurs[6]), ";
									break;
								case 'MMFAC':
									$after = "$after indicateurs[11] = base.cti_division(indicateurs[1],indicateurs[5]), ";
									$after = "$after indicateurs[12] = base.cti_division(indicateurs[2],indicateurs[6]), ";
									break;
								case 'MMRES':
									$after = "$after indicateurs[11] = base.cti_division((indicateurs[1] - indicateurs[3]),indicateurs[5]), ";
									$after = "$after indicateurs[12] = base.cti_division((indicateurs[2] - indicateurs[4]),indicateurs[6]), ";
									break;
								default:
									$after = "0, ";
									$after = "0, ";
								}
								
								switch ('[DATA3]') {
								case 'MCOU':
									$after = "$after indicateurs[15] = indicateurs[3], ";
									$after = "$after indicateurs[16] = indicateurs[4] ";
									break;
								case 'MFAC':
									$after = "$after indicateurs[15] = indicateurs[1], ";
									$after = "$after indicateurs[16] = indicateurs[2] ";
									break;
								case 'MRES':
									$after = "$after indicateurs[15] = indicateurs[1] - indicateurs[3], ";
									$after = "$after indicateurs[16] = indicateurs[2] - indicateurs[4] ";
									break;
								case 'MMCOU':
									$after = "$after indicateurs[15] = base.cti_division(indicateurs[3],indicateurs[5]), ";
									$after = "$after indicateurs[16] = base.cti_division(indicateurs[4],indicateurs[6]) ";
									break;
								case 'MMFAC':
									$after = "$after indicateurs[15] = base.cti_division(indicateurs[1],indicateurs[5]), ";
									$after = "$after indicateurs[16] = base.cti_division(indicateurs[2],indicateurs[6]) ";
									break;
								case 'MMRES':
									$after = "$after indicateurs[15] = base.cti_division((indicateurs[1] - indicateurs[3]),indicateurs[5]), ";
									$after = "$after indicateurs[16] = base.cti_division((indicateurs[2] - indicateurs[4]),indicateurs[6]) ";
									break;
								default:
									$after = "0, ";
									$after = "0 ";
								}

								
								return $after;
					EVAL]]]></value>
		</PROPERTY>
		
	</VIEWPROPERTIES>

	
	<SELECTIONS label="Paramètres de l'analyse" displayText="">
		<GROUP label="Période">
			<FIELD name="MOIS" label="" UI="combo" width="250" default="201001" globalListProvider="MOIS">
			</FIELD>
			<FIELD name="TOMOIS" label="" UI="combo" width="250" default="201001" globalListProvider="MOIS">
			</FIELD>
		</GROUP>
		<GROUP label="Période précédente">
			<FIELD name="MOIS_D" label="" UI="combo" width="250" default="201001" globalListProvider="MOIS">
			</FIELD>
			<FIELD name="TOMOIS_D" label="" UI="combo" width="250" default="201001" globalListProvider="MOIS">
			</FIELD>
		</GROUP>
		
		<GROUP label="Données">
			<FIELD name="DATA1" label="" UI="combo" default="MCOU">
				<OPTION label="Résultat" data="MRES" data2="#E" data3="Résultat"/>
				<OPTION label="Coût" data="MCOU" data2="#E" data3="Coût"/>
				<OPTION label="Montant facturé" data="MFAC" data2="#E" data3="Facturé"/>
				<OPTION label="Résultat moyen" data="MMRES" data2="#E" data3="Résultat M"/>
				<OPTION label="Montant facturé moyen" data="MMFAC" data2="#E" data3="Facturé M"/>
				<OPTION label="Coût moyen" data="MMCOU" data2="#E" data3="Coût M"/>
				
			</FIELD>
			<FIELD name="DATA2" label="" UI="combo" default="-1">
				<OPTION label="" data="-1" data2=""/>
				<OPTION label="Résultat" data="MRES" data2="#E" data3="Résultat"/>
				<OPTION label="Coût" data="MCOU" data2="#E" data3="Coût"/>
				<OPTION label="Montant facturé" data="MFAC" data2="#E" data3="Facturé"/>
				<OPTION label="Résultat moyen" data="MMRES" data2="#E" data3="Résultat M"/>
				<OPTION label="Montant facturé moyen" data="MMFAC" data2="#E" data3="Facturé M"/>
				<OPTION label="Coût moyen" data="MMCOU" data2="#E" data3="Coût M"/>
			</FIELD>
			<FIELD name="DATA3" label="" UI="combo" default="-1">
				<OPTION label="" data="-1" data2=""/>
				<OPTION label="Résultat" data="MRES" data2="#E" data3="Résultat"/>
				<OPTION label="Coût" data="MCOU" data2="#E" data3="Coût"/>
				<OPTION label="Montant facturé" data="MFAC" data2="#E" data3="Facturé"/>
				<OPTION label="Résultat moyen" data="MMRES" data2="#E" data3="Résultat M"/>
				<OPTION label="Montant facturé moyen" data="MMFAC" data2="#E" data3="Facturé M"/>
				<OPTION label="Coût moyen" data="MMCOU" data2="#E" data3="Coût M"/>
			</FIELD>
		</GROUP>
		
		<GROUP label="Regroupement">
			<FIELD name="GROUPBY" label="" UI="combo" width="200" default="CSC" tree="true">
				<OPTION label="Elément de coût" data="CSC" treeLevel="1"  globalListProvider="CSC_GROUPBY_OPTION"/>
				<OPTION label="Unité d'oeuvre" data="CSU" treeLevel="1"  globalListProvider="CSU_GROUPBY_OPTION"/>
				<OPTION label="GHM" data="CSG" treeLevel="1"  globalListProvider="CSG_GROUPBY_OPTION"/>
				<OPTION label="Service" data="CSF" treeLevel="1"  globalListProvider="CSF_GROUPBY_OPTION"/>
				<OPTION label="Activité" data="CSA" treeLevel="1"  globalListProvider="CSA_GROUPBY_OPTION"/>
				<OPTION label="Etage" data="CSE" treeLevel="1"  globalListProvider="CSE_GROUPBY_OPTION"/>
				<OPTION label="Médecin" data="CSM" treeLevel="1"  globalListProvider="CSM_GROUPBY_OPTION"/>
				<OPTION label="Mois" data="MOI" treeLevel="1"  />
				<OPTION label="Exercice" data="EXE" treeLevel="2"  />
			</FIELD>
			<FIELD name="GROUPBY_TAB" width="100" label="Présentation" UI="combo" default="AUTO" visible="= SELECT.GROUPBY_2 != '-1' ">
				<OPTION label="Automatique" data="AUTO"/>
				<OPTION label="Arbre" data="TREE"/>
				<OPTION label="Onglet" data="TAB"/>
			</FIELD>
		</GROUP>
		<GROUP label="">
			<FIELD name="GROUPBY_2" label="" width="200" UI="combo" default="-1" tree="true">
				<OPTION label="Pas de second niveau" data="-1"/>
				<OPTION label="Elément de coût" data="CSC" treeLevel="1"  globalListProvider="CSC_GROUPBY_OPTION"/>
				<OPTION label="Unité d'oeuvre" data="CSU" treeLevel="1"  globalListProvider="CSU_GROUPBY_OPTION"/>
				<OPTION label="GHM" data="CSG" treeLevel="1"  globalListProvider="CSG_GROUPBY_OPTION"/>
				<OPTION label="Service" data="CSF" treeLevel="1"  globalListProvider="CSF_GROUPBY_OPTION"/>
				<OPTION label="Activité" data="CSA" treeLevel="1"  globalListProvider="CSA_GROUPBY_OPTION"/>
				<OPTION label="Etage" data="CSE" treeLevel="1"  globalListProvider="CSE_GROUPBY_OPTION"/>
				<OPTION label="Médecin" data="CSM" treeLevel="1"  globalListProvider="CSM_GROUPBY_OPTION"/>
				<OPTION label="Mois" data="MOI" treeLevel="1"  />
				<OPTION label="Exercice" data="EXE" treeLevel="2"  />
			</FIELD>
		</GROUP>
	</SELECTIONS>
	

	<SELECTIONS componentName="FILTRES_COUT_PATIENT"/>
	
	<QUERIES>
		<QUERY label="">
			<SQL>
				<select><![CDATA[		
					CTISELECT_TREE
						GROUPBY1{[VIEW.GROUPBY_OID_FIELD],, [VIEW.GROUPBY_COD_FIELD],, [VIEW.GROUPBY_TXT_FIELD]}
						GROUPBY1MODE{[GROUPBY_TAB]}
						GROUPBY2{[VIEW.GROUPBY_2_OID_FIELD],, [VIEW.GROUPBY_2_COD_FIELD],, [VIEW.GROUPBY_2_TXT_FIELD]}
						INDICATORS{
							sum(CASE WHEN v_couts_patient_shs_1.mois_comptable_id BETWEEN '[MOIS]' AND '[TOMOIS]' THEN v_couts_patient_shs_1.montant_facture ELSE 0 END),
							sum(CASE WHEN v_couts_patient_shs_1.mois_comptable_id BETWEEN '[MOIS_D]' AND '[TOMOIS_D]' THEN v_couts_patient_shs_1.montant_facture ELSE 0 END),
							
							sum(CASE WHEN v_couts_patient_shs_1.mois_comptable_id BETWEEN '[MOIS]' AND '[TOMOIS]' THEN v_couts_patient_shs_1.cout ELSE 0 END),
							sum(CASE WHEN v_couts_patient_shs_1.mois_comptable_id BETWEEN '[MOIS_D]' AND '[TOMOIS_D]' THEN v_couts_patient_shs_1.cout ELSE 0 END),
						
							count(DISTINCT CASE WHEN v_couts_patient_shs_1.mois_comptable_id BETWEEN '[MOIS]' AND '[TOMOIS]' THEN v_couts_patient_shs_1.no_sejour ELSE NULL END),
							count(DISTINCT CASE WHEN v_couts_patient_shs_1.mois_comptable_id BETWEEN '[MOIS_D]' AND '[TOMOIS_D]' THEN v_couts_patient_shs_1.no_sejour ELSE NULL END),
						
						
							0,0,0,0,
								
							0,0,0,0,
							
							0,0,0,0
						}
					FROM compta.v_couts_patient_shs_1
					WHERE (v_couts_patient_shs_1.mois_comptable_id BETWEEN [MOIS] AND [TOMOIS] OR
						v_couts_patient_shs_1.mois_comptable_id BETWEEN [MOIS_D] AND [TOMOIS_D])
						[VIEW.COUT_PATIENT_SELECT]
						
					AFTER{
						UPDATE w_table SET 
							[VIEW.AFTER]
						.,	
						UPDATE w_table SET 
							indicateurs[9] = indicateurs[7] - indicateurs[8],
							indicateurs[10] = CASE 
											WHEN indicateurs[7] > 0 AND indicateurs[8] > 0 THEN base.cti_division(indicateurs[7] - indicateurs[8], indicateurs[8]) * 100
											ELSE 0 END,
							indicateurs[13] = indicateurs[11] - indicateurs[12],
							indicateurs[14] = CASE 
											WHEN indicateurs[11] > 0 AND indicateurs[12] > 0 THEN base.cti_division(indicateurs[11] - indicateurs[12], indicateurs[12]) * 100
											ELSE 0 END,
							indicateurs[17] = indicateurs[15] - indicateurs[16],
							indicateurs[18] = CASE 
											WHEN indicateurs[15] > 0 AND indicateurs[16] > 0 THEN base.cti_division(indicateurs[15] - indicateurs[16], indicateurs[16]) * 100
											ELSE 0 END
					}
					

				]]></select>
				<FIELDS>
					<INSERT name="CTISELECT_TREE_FIELDS"/>
					<FIELD name="MFACF"/>
					<FIELD name="MFACE"/>
					<FIELD name="MCOUF"/>
					<FIELD name="MCOUE"/>
					<FIELD name="NSEJF"/>
					<FIELD name="NSEJE"/>
					<FIELD name="F1"/>
					<FIELD name="D1"/>
					<FIELD name="E1"/>
					<FIELD name="P1"/>
					<FIELD name="F2"/>
					<FIELD name="D2"/>
					<FIELD name="E2"/>
					<FIELD name="P2"/>
					<FIELD name="F3"/>
					<FIELD name="D3"/>
					<FIELD name="E3"/>
					<FIELD name="P3"/>
				</FIELDS>
			</SQL>
		</QUERY>
	</QUERIES>
	<PRESENTATION>
		<VIEWLINKS>
			<VIEWLINKx label="Liste des séjours" shortLabel="Liste séjours" view="ACTI000019.XML" componentName="PRESTATIONS_BASE_VIEWLINK">
				
			</VIEWLINKx>
		</VIEWLINKS>
		<ONGLET excelLabel="Répartition mensuelle" label="Répartition mensuelle" multiTab="true">
			<CHART title="Comparatif" type="columnChart" maxItems="20" maxItemsSortOn="F1" maxItemsSortSeq="D" sortField="COD" sortSeq="A" >
				<CATEGORY field="COD" type="Char"/>
				<SERIE field="D1" displayName="SELECT.DATA13 + ' ' + SELECT.MOIS_D_LABEL + '-' + SELECT.TOMOIS_D_LABEL" displayNameCalc="true"/>
				<SERIE field="F1" displayName="SELECT.DATA13 + ' ' + SELECT.MOIS_LABEL + '-' + SELECT.TOMOIS_LABEL" displayNameCalc="true"/>
			</CHART>
			<CHART title="Comparatif" type="columnChart" maxItems="20" maxItemsSortOn="F2" maxItemsSortSeq="D" sortField="COD" sortSeq="A" visibleCondition="SELECT.DATA2 != '-1'">
				<CATEGORY field="COD" type="Char"/>
				<SERIE field="D2" displayName="SELECT.DATA23 + ' ' + SELECT.MOIS_D_LABEL + '-' + SELECT.TOMOIS_D_LABEL" displayNameCalc="true"/>
				<SERIE field="F2" displayName="SELECT.DATA23 + ' ' + SELECT.MOIS_LABEL + '-' + SELECT.TOMOIS_LABEL" displayNameCalc="true"/>
			</CHART>
			<CHART title="Comparatif" type="columnChart" maxItems="20" maxItemsSortOn="F3" maxItemsSortSeq="D" sortField="COD" sortSeq="A" visibleCondition="SELECT.DATA3 != '-1'">
				<CATEGORY field="COD" type="Char"/>
				<SERIE field="D3" displayName="SELECT.DATA33 + ' ' + SELECT.MOIS_D_LABEL + '-' + SELECT.TOMOIS_D_LABEL" displayNameCalc="true"/>
				<SERIE field="F3" displayName="SELECT.DATA33 + ' ' + SELECT.MOIS_LABEL + '-' + SELECT.TOMOIS_LABEL" displayNameCalc="true"/>
			</CHART>
			<DATAGRID title="" total="true" showOthers="true" headerHeight="70" variableRowHeight="true" sortable="= SELECT.GROUPBY_2 == '-1' || SELECT.GROUPBY_TAB == 'TAB'" selectRowInRows="= ROW.OID == '-9999997'" otherRowInRows="= ROW.OID == '-9999998'" totalRowInRows="= ROW.OID == '-9999999'">
				<INSERT name="DATAGRID_MULTITAB_STYLES"/>
				<COLUMN dataField="OID" width="60" type="Char" visible="false" headerText="Oid">
				</COLUMN>
				<COLUMN dataField="COD" width="60" type="Char" visible="true" headerText="Code" textAlign="left" otherFunction="text" totalFunction="text" totalComplement="TOTAL">
				</COLUMN>
				<COLUMN dataField="TXT" type="Char" minWidth="50" headerText="SELECT.GROUPBY_LABEL" headerTextCalc="true" textAlign="left" totalFunction="text" otherFunction="text" otherComplement="*ROW" >
				</COLUMN>
				<COLUMN dataField="D1" width="85" visible="true" type="Number" outputFormat="#E" fixed="false" selectable="true" headerText="SELECT.DATA13 + ' ' + SELECT.MOIS_D_LABEL + '- ' + SELECT.TOMOIS_D_LABEL" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="F1" width="85" visible="true" type="Number" outputFormat="#E" fixed="false" selectable="true" headerText="SELECT.DATA13 + ' ' + SELECT.MOIS_LABEL + '- ' + SELECT.TOMOIS_LABEL" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="E1" type="Number" headerText="Ecart" width="70" visible="true" outputFormat="#E" fixed="false" textAlign="right" totalFunction="sum" totalComplement="" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="P1" type="Number" headerText="% évol." width="45" visible="true" outputFormat="= if (ROW.D1 != 0 &amp;&amp; ROW.F1 != 0) {return '0%'} else {return '#'}" fixed="false" textAlign="right" totalFunction="sum" totalComplement="" otherFunction="sum" >
				</COLUMN>
				<COLUMN dataField="D2" width="85" visibleCondition="SELECT.DATA2 != '-1'" type="Number" outputFormat="#E" fixed="false" selectable="true" headerText="SELECT.DATA23 + ' ' + SELECT.MOIS_D_LABEL + '- ' + SELECT.TOMOIS_D_LABEL" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="F2" width="85" visibleCondition="SELECT.DATA2 != '-1'" type="Number" outputFormat="#E" fixed="false" selectable="true" headerText="SELECT.DATA23 + ' ' + SELECT.MOIS_LABEL + '- ' + SELECT.TOMOIS_LABEL" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="E2" type="Number" headerText="Ecart" width="70" visibleCondition="SELECT.DATA2 != '-1'" outputFormat="#E" fixed="false" textAlign="right" totalFunction="sum" totalComplement="" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="P2" type="Number" headerText="% évol." width="45" visibleCondition="SELECT.DATA2 != '-1'" outputFormat="= if (ROW.D2 !=0  &amp;&amp;  ROW.F2 != 0) {return '0%'} else {return '#'}" fixed="false" textAlign="right" totalFunction="sum" totalComplement="" otherFunction="sum" >
				</COLUMN>
				<COLUMN dataField="D3" width="85" visibleCondition="SELECT.DATA3 != '-1'" type="Number" outputFormat="#E" fixed="false" selectable="true" headerText="SELECT.DATA33 + ' ' + SELECT.MOIS_D_LABEL + '- ' + SELECT.TOMOIS_D_LABEL" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="F3" width="85" visibleCondition="SELECT.DATA3 != '-1'" type="Number" outputFormat="#E" fixed="false" selectable="true" headerText="SELECT.DATA33 + ' ' + SELECT.MOIS_LABEL + '- ' + SELECT.TOMOIS_LABEL" headerTextCalc="true" textAlign="right" totalFunction="sum" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="E3" type="Number" headerText="Ecart" width="70" visibleCondition="SELECT.DATA3 != '-1'" outputFormat="#E" fixed="false" textAlign="right" totalFunction="sum" totalComplement="" otherFunction="sum">
				</COLUMN>
				<COLUMN dataField="P3" type="Number" headerText="% évol." width="45" visibleCondition="SELECT.DATA3 != '-1'" outputFormat="= if (ROW.D3 !=0  &amp;&amp;  ROW.F3 != 0) {return '0%'} else {return '#'}" fixed="false" textAlign="right" totalFunction="sum" totalComplement="" otherFunction="sum" >
				</COLUMN>
			</DATAGRID>
		</ONGLET>
	</PRESENTATION>
</VUE>
