function add_next_image_with_rois_to_queue($workflow_id)
{
    $timeout = date("YmdHis", strtotime('now') - 1800);
    $workflow = new Workflow($workflow_id, true);
    $workflow_dom = $workflow->workflow_dom;
    $image_pids = $workflow->image_pids;
    $totalEntries = sizeOf($image_pids);
    $specimen_elements = $workflow_dom->getElementsByTagName('specimen');
    foreach ($specimen_elements as $specimen) {
        $specimen_pid = $specimen->getElementsByTagName('pid')->item(0)->nodeValue;
        $specimen_image_elements = $specimen->getElementsByTagName('image');
        foreach ($specimen_image_elements as $image) {
            $image_pid = $image->getElementsByTagName('pid')->item(0)->nodeValue;
            $status_dom = AP_Image::getImageStatusDom($image_pid);
            if ($status_dom != false && ($status_dom->getElementsByTagName('locked')->item(0)->nodeValue == "false" || $status_dom->getElementsByTagName('locked_time')->item(0)->nodeValue < $timeout)) {
                $status_dom = AP_Image::getImageLock($image_pid);
                $analyzedStatus = $status_dom->getElementsByTagName('analyzedStatus')->item(0)->nodeValue;
                $locked_by = $status_dom->getElementsByTagName('locked_by')->item(0)->nodeValue;
                $locked = $status_dom->getElementsByTagName('locked')->item(0)->nodeValue;
                $locked_time = $status_dom->getElementsByTagName('locked_time')->item(0)->nodeValue;
                $locked_session = $status_dom->getElementsByTagName('locked_session')->item(0)->nodeValue;
                $workflow_status = workflow_status($locked, $locked_time, $locked_session);
                $roi_pids = AP_Image::getROIListForImage($image_pid);
                $roi_count = sizeOf($roi_pids);
                $queue_item_html .= create_queue_list_image($image_pid, $specimen_pid, $analyzedStatus, $roi_count, $locked_by, $workflow_status, $workflow_id);
                //$queue_item_html .= '<div class="widget-content" id="content-'.str_replace(':', '__', $image_pid).'">'."\n";
                $found_queued_roi = false;
                foreach ($roi_pids as $roi_pid) {
                    $roi_status_dom = AP_ROI::getROILock($roi_pid);
                    if ($roi_status_dom != false) {
                        if (!$found_queued_roi) {
                            $queue_item_html .= '<div class="widget-content" id="content-' . str_replace(':', '__', $image_pid) . '">' . "\n";
                            $found_queued_roi = true;
                        }
                        $transcribedStatus = $roi_status_dom->getElementsByTagName('transcribedStatus')->item(0)->nodeValue;
                        $parsedL1Status = $roi_status_dom->getElementsByTagName('parsedL1Status')->item(0)->nodeValue;
                        $locked_by = $roi_status_dom->getElementsByTagName('locked_by')->item(0)->nodeValue;
                        $locked = $roi_status_dom->getElementsByTagName('locked')->item(0)->nodeValue;
                        $locked_time = $roi_status_dom->getElementsByTagName('locked_time')->item(0)->nodeValue;
                        $locked_session = $roi_status_dom->getElementsByTagName('locked_session')->item(0)->nodeValue;
                        $workflow_status = workflow_status($locked, $locked_time, $locked_session);
                        $queue_item_html .= create_queue_list_roi($roi_pid, $image_pid, $transcribedStatus, $parsedL1Status, $locked_by, $workflow_status, $workflow_id);
                    }
                }
                if ($found_queued_roi) {
                    $queue_item_html .= '</div><!-- widget-content -->' . "\n";
                }
                break 2;
            }
        }
    }
    echo $queue_item_html;
}