<?xml version="1.0" encoding="ISO-8859-1"?>
<ROOT>
	

	<NODE name="PMSICOMPLEMENTS" label="RECUPERATION DES DONNEES COMPLEMENTAIRES PMSI">
		
		<NODE label="Paramètres">
			<sqlcmd><![CDATA[
				
				INSERT INTO pmsi.t_medecins(code, nom, prenom, specialite_id, no_adeli, specialite_interne_id)
				SELECT 
					cj_pra.pra_libc,
					MAX(per_nom),
					MAX(COALESCE(per_prenom, '')),
					MAX(COALESCE(t_specialites_medecin.oid,0)),
					MAX(COALESCE(cj_prc.prc_identification, '')),
					MAX(COALESCE(t_specialites_internes_medecin.oid,0))
				FROM prod_cegi.cj_pra 
					LEFT JOIN prod_cegi.cj_prc ON (cj_pra.pra_id = cj_prc.pra_id)
					LEFT JOIN prod_cegi.cj_spe ON (cj_pra.spe_id = cj_spe.spe_id)
					LEFT JOIN pmsi.t_specialites_medecin ON (t_specialites_medecin.code = spe_libc)
					LEFT JOIN pmsi.t_specialites_internes_medecin ON (t_specialites_internes_medecin.code = spe_libc || '..')
					LEFT JOIN pmsi.t_medecins ON (cj_pra.pra_libc = t_medecins.code)
				WHERE cj_pra.pra_libc IN (SELECT CODE_MED_EXECUTANT FROM prod_cegiloghos.OPERA_ACT) AND t_medecins.code IS NULL
				GROUP BY 1;
										
			]]></sqlcmd>
		</NODE>
		
		
		
		
		
		<NODE label="Identités">
			<sqlcmd><![CDATA[

				
					
										
			]]></sqlcmd>
		</NODE>
				
		<NODE label="Médecins RSS">
			<sqlcmd><![CDATA[

				DROP TABLE IF EXISTS w_rss_medecins_loghos;
				CREATE TEMP TABLE w_rss_medecins_loghos AS
				SELECT p_rss.oid, no_sejour_administratif, CODE_MED_RESP_SEJOUR, t_medecins.oid AS medecin_id, p_rss.medecin_rss_id
				FROM [SCHEMA].p_rss
				JOIN prod_cegiloghos.OPERA_SEJ ON no_sejour_administratif = OPERA_SEJ.NO_DOSSIER AND
					(date_sortie = date(DATE_SORTIE_SEJOUR) OR date_entree = date(DATE_ENTREE_SEJOUR))
				JOIN pmsi.t_medecins ON CODE_MED_RESP_SEJOUR = t_medecins.code
				WHERE p_rss.medecin_rss_id = 0 OR 
					(p_rss.ghm_id = 0 AND p_rss.medecin_rss_id <> t_medecins.oid);


				UPDATE [SCHEMA].p_rss
				SET medecin_rss_id = medecin_id
				FROM w_rss_medecins_loghos
				WHERE w_rss_medecins_loghos.oid = p_rss.oid;

										
			]]></sqlcmd>
		</NODE>
		
		<NODE label="Unités médicales externes">
			<sqlcmd><![CDATA[
			
				DROP TABLE IF EXISTS w_rss_unites_loghos;
				CREATE TEMP TABLE w_rss_unites_loghos AS
				SELECT p_rss.oid, no_sejour_administratif, CODE_SERVICE_ENTREE, COALESCE(t_unites_medicales.oid,'0') AS unite_medicale_id
				FROM [SCHEMA].p_rss
				JOIN prod_cegiloghos.OPERA_SEJ ON no_sejour_administratif = OPERA_SEJ.NO_DOSSIER AND
					(date_sortie = date(DATE_SORTIE_SEJOUR) OR date_entree = date(DATE_ENTREE_SEJOUR))
				LEFT JOIN pmsi.t_unites_medicales ON CODE_SERVICE_ENTREE = t_unites_medicales.code
				WHERE p_rss.ghm_id = 0 AND
					p_rss.unite_medicale_principale_id = 0;

				INSERT INTO pmsi.t_unites_medicales (code, texte)
				SELECT
					CODE_SERVICE_ENTREE, MAX(LIBELLE_SERVICE_DISCIPLINE) AS LIBELLE_SERVICE_DISCIPLINE
				FROM w_rss_unites_loghos
				JOIN prod_cegiloghos.OPERA_PSDISC ON CODE_SERVICE_ENTREE = CODE_SERVICE_DISCIPLINE
				WHERE unite_medicale_id = 0
				GROUP BY 1;

				UPDATE w_rss_unites_loghos
				SET unite_medicale_id = t_unites_medicales.oid
				FROM pmsi.t_unites_medicales
				WHERE CODE_SERVICE_ENTREE = t_unites_medicales.code AND
					unite_medicale_id = 0;

				
				UPDATE [SCHEMA].p_rss
				SET unite_medicale_principale_id = unite_medicale_id
				FROM w_rss_unites_loghos
				WHERE w_rss_unites_loghos.oid = p_rss.oid;

				UPDATE [SCHEMA].p_rss_rum
				SET unite_medicale_id = w_rss_unites_loghos.unite_medicale_id
				FROM w_rss_unites_loghos
				WHERE w_rss_unites_loghos.oid = p_rss_rum.rss_id;
		
		]]></sqlcmd>
		</NODE>
		
		<NODE label="Médecins actes">
			<sqlcmd><![CDATA[

				UPDATE [SCHEMA].p_rss_actes 
				SET medecin_id = t_medecins.oid
				FROM prod_cegiloghos.OPERA_ACT
					JOIN prod_cegiloghos.OPERA_SEJ ON OPERA_ACT.NO_DOSSIER = OPERA_SEJ.NO_DOSSIER
					JOIN [SCHEMA].p_rss ON no_sejour_administratif = OPERA_SEJ.NO_DOSSIER AND
						date_sortie = date(DATE_SORTIE_SEJOUR)
					
					JOIN pmsi.t_medecins ON OPERA_ACT.CODE_MED_EXECUTANT = t_medecins.code
					JOIN pmsi.t_actes ON substring(CODE_CCAM, 1, 7) = t_actes.code
				WHERE ghm_id = 0 AND
					p_rss_actes.rss_id = p_rss.oid AND
					p_rss_actes.acte_id = t_actes.oid AND
					p_rss_actes.activite_ccam = CODE_ACTIVITE_CCAM AND
					p_rss_actes.date_acte = date(DATE_ACTE_DEBUT) AND
					p_rss_actes.medecin_id = 0;
					
				UPDATE [SCHEMA].p_rss_actes 
				SET medecin_id = t_medecins.oid
				FROM prod_cegiloghos.OPERA_ACT
					JOIN prod_cegiloghos.OPERA_SEJ ON OPERA_ACT.NO_DOSSIER = OPERA_SEJ.NO_DOSSIER
					JOIN [SCHEMA].p_rss ON no_sejour_administratif = OPERA_SEJ.NO_DOSSIER AND
						date_entree = date(DATE_ENTREE_SEJOUR)
					
					JOIN pmsi.t_medecins ON OPERA_ACT.CODE_MED_EXECUTANT = t_medecins.code
					JOIN pmsi.t_actes ON substring(CODE_CCAM, 1, 7) = t_actes.code
				WHERE ghm_id = 0 AND
					p_rss_actes.rss_id = p_rss.oid AND
					p_rss_actes.acte_id = t_actes.oid AND
					p_rss_actes.activite_ccam = CODE_ACTIVITE_CCAM AND
					p_rss_actes.date_acte = date(DATE_ACTE_DEBUT) AND
					p_rss_actes.medecin_id = 0;
										
			]]></sqlcmd>
		</NODE>
	
	</NODE>

	
	<NODE name="PMSIENCOURS" label="RECUPERATION DES DOSSIERS PMSI EN-COURS CEGI">
		
		<NODE label="Paramètres">
			<sqlcmd><![CDATA[

				
										
			]]></sqlcmd>
		</NODE>
		
		
		
		
		
		<NODE label="RSS">
			<sqlcmd><![CDATA[

				
										
										
			]]></sqlcmd>
		</NODE>
				
		<NODE label="Identités">
			<sqlcmd><![CDATA[

			
										
			]]></sqlcmd>
		</NODE>
		
		<NODE label="Rum">
			<sqlcmd><![CDATA[

				
										
										
			]]></sqlcmd>
		</NODE>
		
		<NODE label="Diagnostics">
			<sqlcmd><![CDATA[

				
											
										
			]]></sqlcmd>
		</NODE>
		
		<NODE label="Actes">
			<sqlcmd><![CDATA[

			
										
										
			]]></sqlcmd>
		</NODE>
		
		<NODE label="Factures">
			<sqlcmd><![CDATA[
	
				
																	
										
			]]></sqlcmd>
		</NODE>
	
		<NODE label="Prestations">
			<sqlcmd><![CDATA[

			
										
			]]></sqlcmd>
		</NODE>
		
		<NODE label="LPP">
			<sqlcmd><![CDATA[

				
										
			]]></sqlcmd>
		</NODE>
		
		<NODE label="UCD">
			<sqlcmd><![CDATA[

				
										
			]]></sqlcmd>
		</NODE>
		
		
		
		<NODE label="Compléments identifications Externes">
			<sqlcmd><![CDATA[
			
				
				
										
			]]></sqlcmd>
		</NODE>
		
		
		
	</NODE>

</ROOT>













