Foundations for Safety-Critical on-Demand Medical Systems