SELECT idCollege INTO @idCollege FROM beneficiaire WHERE id =  3567;

SELECT codeReseau INTO @codeReseau FROM college WHERE id = @idCollege;


SELECT idCollege  FROM beneficiaire WHERE id =  3567;

SELECT codeReseau  FROM college WHERE id = 87;

SELECT 
		MAX(numeroFeuilleMaladie) 
	FROM p_prestationactes 
	WHERE datePrestation = ( SELECT MAX(datePrestation)
		FROM p_prestationactes 
		WHERE idBeneficiaire 	='8378'
		-- AND codePrestataire 	= p_codePrestataire
		AND tiersPayant 	= "1"
		AND codeTypePrestation 	= "CONS"
		AND codeActe 		!="A00000003"
	)
	AND idBeneficiaire 	= '8378'
	-- AND codePrestataire 	= p_codePrestataire
	AND tiersPayant 	= "1"
	AND codeTypePrestation 	= "CONS"
	AND codeActe 		!="A00000003";

SELECT fn_denieremaladie_beneficiaire(8378, p_codePrestataire)

 SELECT * FROM p_prestationactes WHERE id>=1005  ORDER BY id
 
 
 SELECT `indicatifTelephone`,societeuser.* FROM `societeuser`



SELECT idCollege ,codeReseau 
FROM beneficiaire b 
INNER JOIN college c ON (c.id=b.idCollege) 
WHERE b.id =  3567;


SELECT * FROM beneficiaire WHERE numeroBeneficiaire='0066011105'









CREATE TEMPORARY TABLE temp_beneficiaire_l
	SELECT
		A.*
	FROM vw_p_beneficiaire A 
	WHERE (A.idBeneficiaire=p_idBeneficiaire);
	
	SELECT 
		A.*,
		 		
		fn_college_couvert(A.idCollege, @codeReseau, A.prestationParLienParente, p_codePrestataire)
		+ fn_prestataire_en_plus(A.idCollege, p_codePrestataire, A.prestationParLienParente, A.codeLienParente, @codeReseau)
		- fn_prestataire_en_moins(A.idCollege, p_codePrestataire, A.prestationParLienParente, A.codeLienParente, @codeReseau) AS college_couvert, 
		 
		-- fn_tm_college(A.idCollege, @codeReseau, A.prestationParLienParente, A.codeLienParente, p_codePrestataire) AS tm,
		fn_ticketModerateur_college(A.idCollege, A.codeLienParente) AS tm,
		
		fn_derogation_en_cours(p_codePrestataire, p_idBeneficiaire) AS derogation_en_cours,		
		fn_tm_derogation_en_cours(p_codePrestataire, A.idBeneficiaire) AS tmDerogation,	
		 	
		fn_derogation_finger_en_cours(p_codePrestataire, p_idBeneficiaire)
		+IFNULL(A.derogationFingerPermanent,0) 
		+fn_derogation_finger_prestataire(p_codePrestataire) AS derogation_finger_en_cours,
		 
		fn_tm_prestataire_en_plus(A.idCollege, p_codePrestataire, A.prestationParLienParente, A.codeLienParente) AS tmPrestataireEnPlus,
		fn_tm_prestataire_tm(A.idCollege, p_codePrestataire, A.prestationParLienParente, A.codeLienParente) AS tmPrestataireTm,
		fn_tm_prestataire_tm_existe(A.idCollege, p_codePrestataire, A.prestationParLienParente, A.codeLienParente) AS tmPrestataireTmExiste,
		@dateConsultation AS derniereDateConsultation,
		@codeMedecin AS dernierMedecinConsulte,
		@numeroBonConsultation AS dernierBonConsultation,
		@codeActe AS dernierActe,
		@dateDernierActe AS dateDernierActe,
		@codeReseau AS codeReseau
	FROM temp_beneficiaire_l A 
	WHERE (A.idBeneficiaire=p_idBeneficiaire);