Need to convert string of term ids into comma separated integers for use in an arguments array

You should be able to change these lines

if ( !empty($terms) ) {
    foreach( $terms as $term ) {
        echo $term->term_id . ','; 
    }

}

to this:

if ( !empty($terms) ) {
    // create an empty array
    $procedures_to_include = array();
    foreach( $terms as $term ) {
        // now instead of echoing, add each term to the array
        $procedures_to_include[] = $term->term_id;
    }

}

Basically instead of echoing manually, you’re creating the array to begin with, and in your get_terms call you can just use $procedures_to_include directly:

$terms = get_terms( array(
    'taxonomy'      =>  'procedures',
    'hide_empty'    =>  true,
    'include'       =>  $procedures_to_include
) );