Automation in healthcare is a major challenge to improve quality of service while compressing costs. In particular, correct administration of medicines to patients is crucial to ensure quality of care during hospitalization and minimize medication errors. Mistakes are more likely to happen when medicine administration is done manually (dispensing, ordering or administrating). To reduce the risks related to medication errors, automation of the pharmacy processes appears as an appropriately tool to solve this situation. In this paper, we have proposed a new mathematical model to optimize the processes related to unit-doses management and prescriptions preparation in a network of hospitals. To model the uncertainty associated with the demand of medicines, the concept of p-robustness is included; the concept of resilience is also considered to model the risk of centralized distribution processes.