SELECT 
DISTINCT A.codeTypePrestation
-- IFNULL(A.codeGarantie,A.codeGarantieActe),A.codePrestataire,A.numeroFeuilleMaladie,A.codeActe,A.codeTypePrestation
-- ,f.numeroBonConsultation,f.numeroBonOrdonnance,f.numeroBonHospitalisation,f.numeroBonOptique,f.numeroBonExamen,f.numeroBonKine,A.montantApayer
--  INTO @codeTypePrestation 
FROM p_prestationactes A
JOIN adherent B ON (B.id=A.idAdherent)
JOIN p_feuillemaladie f ON (f.id=A.numeroFeuilleMaladie)
WHERE fn_id_entetecontrat_police(B.idPolice,DATE(A.datesysteme))=fn_id_entetecontrat_police_courant(B.idPolice)
-- and A.idBeneficiaire=433
AND B.idPolice=185
AND A.codeGarantie='AUX'

SELECT * FROM p_feuillemaladie WHERE id	=6057

SELECT DISTINCT A.codeTypePrestation 
FROM p_prestationactes  A
JOIN adherent B ON (B.id=A.idAdherent)
WHERE fn_id_entetecontrat_police(B.idPolice,DATE(A.datesysteme))=fn_id_entetecontrat_police_courant(B.idPolice)
AND B.idPolice=185


IF (@codeTypePrestation="CONS") OR (@codeTypePrestation="HOSP")  THEN
	SELECT 	fn_libelle_prestataire(m.codePrestataire) AS Prestataire,fn_libelle_medecin_rp (m.codeMedecin) AS Medecin,s.libelle,A.montantApayer
	FROM p_prestationactes A
	JOIN adherent B ON (B.id=A.idAdherent)
	JOIN p_feuillemaladie f ON (f.id=A.numeroFeuilleMaladie)
	INNER JOIN p_medecinprestataire m ON ((m.codePrestataire=A.codePrestataire) AND (m.codeMedecin=A.codeMedecin))
	INNER JOIN p_specialite s ON ((m.codeSpecialite=s.codeSpecialite))
	WHERE fn_id_entetecontrat_police(B.idPolice,DATE(A.datesysteme))=fn_id_entetecontrat_police_courant(B.idPolice)
	AND A.codeGarantie='CON' AND (f.numeroFeuilleMaladie=921) ;
END IF;


IF (@codeTypePrestation="PHAR")  THEN
	SELECT forme,posologie,libelleMedicament,montantArembourser AS montantApayer
	FROM vw_p_detailprescription
	WHERE (numeroFeuilleMaladie=1915) AND (numeroBonOrdonnance=2505)
	ORDER BY  numeroFeuilleMaladie,ajPharmacie, libelleMedicament;	
END IF;

IF (@codeTypePrestation="EXA")  THEN
	SELECT 	fn_libelle_prestataire(codePrestataire) AS Prestataire,fn_libelle_acte_rp(codeActe) AS Acte,montantArembourser AS montantApayer
	FROM p_detailexamen
	WHERE (numeroFeuilleMaladie=7025)  -- AND (codeTypePrestation='EXAM')
	ORDER BY  numeroFeuilleMaladie;	
END IF;

IF (@codeTypePrestation="SEA")OR (@codeTypePrestation="ACT")  THEN
	SELECT 	fn_libelle_prestataire(P.codePrestataire) AS Prestataire,fn_libelle_medecin_rp (P.codeMedecin) AS Medecin,fn_libelle_acte_rp(P.codeActe) AS Acte,A.montantApayer AS montantApayer
	FROM p_prestationseances P
	INNER JOIN  p_prestationactes A ON (P.idPrestationactes=A.id)
	WHERE (P.numeroFeuilleMaladie=31231)  -- AND (codeTypePrestation='EXAM')
	ORDER BY  P.numeroFeuilleMaladie;	
	
	SELECT * FROM `p_prestationseances` WHERE (numeroFeuilleMaladie=31231)
	
	SELECT * FROM p_acte WHERE codeActe IN ('AMC','AC0000074','AER','AC0000016','LVO','AC0001201','AC0000214')
	
END IF;

IF (@codeTypePrestation="OPT")  THEN
	SELECT 	fn_libelle_prestataire(A.codePrestataire) AS Prestataire,fn_libelle_acte_rp(A.codeActe) AS Acte,
	CASE WHEN photogray="1" THEN "OUI" ELSE "NON" END AS photogray,
	CASE WHEN photochromique="1" THEN "OUI" ELSE "NON" END AS photochromique,
	CASE WHEN antireflet="1" THEN "OUI" ELSE "NON" END AS antireflet,
	CASE WHEN antiUV="1" THEN "OUI" ELSE "NON" END AS antiUV,
	CASE WHEN progressif="1" THEN "OUI" ELSE "NON" END AS progressif,
	A.montantApayer
	FROM p_prestationactes A 
	JOIN adherent B ON (B.id=A.idAdherent) 
	INNER JOIN p_optique o ON (A.numeroFeuilleMaladie=o.numeroFeuilleMaladie)
	WHERE A.numeroFeuilleMaladie=19410 AND A.codeGarantie='OPT'	
END IF;

-- AMP     BIL  BIO    DEN  CON HOS IMA MAT OPT PHA TRA 