This seems like alot of code just t get the active order, why don't you just call OrderService.getActiveOrders(patient, drugOrderType,.....) and loop through to find the one that matches the drug