refactored and added some new queries for medication