An adaptive pain management framework