public static double flowToSvO2(Mode ecmo, double flow, Patient patient) throws Exception {
    if (ecmo == Mode.VV) {
      // VV ECMO
      if (patient.getHeartFunction() == Patient.HeartFunction.BAD) {
        // SvO2_VV_LGHP and SvO2_VV_LPHP
        throw new Exception("VV ECMO and bad heart function not ideal");
      }
      else { 
        // Heart function is good
        if (flow < 50) {
          return 0.1 + flow / 50 * 0.4;
        }
        else if (flow < 120) {
          return 0.5 + (flow - 50) / 70 * 0.28;
        }
        else if (flow < 150) {
          return 0.78 + (flow - 120) / 30 * 0.12;
        }
        else {
          return 0.9;
        }
      }
    }
    else { 
      // VA ECMO
      if (flow < 50) {
        return 0.1 + flow / 50 * 0.4;
      }
      else if (flow < 120) {
        return 0.5 + (flow - 50) / 70 * 0.25;
      }
      else if (flow < 150) {
        return 0.75 + (flow - 120) / 30 * 0.05;
      }
      else {
        return 0.8;
      }
    }
  }