It's true that "many are the afflictions of the righteous, and the Lord delivereth him out of them all" (Psa.34:19), but sometimes you have to meet certain conditions before the Lord will deliver you.
Whenever He doesn't deliver you and He allows the Devil to still plague you and to leave a thorn in your flesh, it's for a purpose, and He won't deliver you until you obey. If you're not willing to pay the price God requires for healing, He won't heal you! Only the obedient get healing. Health is a special blessing of God. You can only demand and expect it in prayer if you're obedient to the Lord. But if you're disobedient you can't demand anything!
Once God's forgiven you and healed you, then you'd better be sure you stick to the limits and the regulations and the rules and His Will and whatever conditions He has laid down, knowing that your health and well-being depends utterly on Him!
When you're healed, just remember it's a special blessing, a priceless privilege, which He can take away if you don't keep trusting Him for it and giving Him all the glory! So stay close to the Lord and do the things that He healed you for!--Use that strength that God gives you for His glory!