Fetch title of parent query loop post

I have two custom post types: Offices and Doctors. I created a relationship between them so that I could assign doctors to specific offices. I have a query loop that lists each office each doctor that is in each office.

Each doctor is clickable. When clicked, it will take the user to a page that can be used to refer a patient to that specific office with that specific doctor.

The link looks something like this:

…com/?office_you_are_referring_to={OFFICE_NAME}&doctor_you_are_referring_to_{OFFICE_NAME}={DOCTOR_NAME}

The office name should be populated based on the post title of the parent query loop and the doctor name can just be the post title of the current query loop which is the doctor.

Tl;dr, within a query loop, is it possible to fetch the post title outside of the query loop?

Yes, you can temporarily store the parent post title with the following code block inside the parent loop.

$GLOBALS['post_title'] = {post_title};

And add use in child loop as {echo:get_parent_term_id}.

<?php

function get_parent_term_id() {
  if (isset($GLOBALS['parent_term_id'])) {
    return esc_html($GLOBALS['parent_term_id']);
  }
}
?>