Framework for Algorithmically Optimizing Longitudinal Health Outcomes: Examples in Cancer Radiotherapy and Occupational Radiation Protection