Site ID is missing in new browser tab from PDF generation

Situation
When using the Billing Manager and checking an encounter, then selecting HCFA Form, CMS 1500 PDF, then validate only in the popup, another popup shows “PDF” billing_process.php and an “open” button. Clicking on open results in a new tab with the error “Site ID is missing from session data!”.

I am logged into OpenEMR on only one tab in Chrome, and Chrome is set to allow cookies from the site. I tried clearing the browser cache and restarted Chrome. Looked at php.ini’s session.save_path and permissions on that path (rw for www-data). When I installed OpenEMR I made the recommended changes to php settings, and I also get this error right after logging in as administrator and going right to billing without delay so it does not seem like a timeout issue.

OpenEMR Version
I’m using OpenEMR version 5.0.2 patch 5

Browser:
Chrome version 86.0.4240.198 (windows 10 client)

Operating System
Ubuntu 21.04 with PHP 7.4.3

Logs
some array index errors in apache log, nothing that seems helpful.

I reviewed previous topics like Templates for Patient Documents: Site ID is missing from session data! - there was a note about a change to login.php going into the first 5.0.2 patch, but that code does not quite match what I have (which does not check PHP version > 7.3). Not sure if this is significant, as I’m not having any problem logging in.



So I don’t know what issue is. Sounds like a file permission maybe.

I reviewed all of the file permissions and cleaned up a few things, still with the same error. Looked into billing_process.php to see if I could find where a temp file is being placed, to see if it is being generated. In the section for $validatePass, for the 1500 form, I found this code:

    } else {
        $fname = tempnam($GLOBALS['temporary_files_dir'], 'PDF');
        file_put_contents($fname, $pdf->ezOutput());
        // Send the content for view.
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header('Content-type: application/pdf');
        header('Content-Disposition: inline; filename="' . $bat_filename . '"');
        header('Content-Transfer-Encoding: binary');
        header('Content-Length: ' . filesize($fname));
        ob_end_clean();
        @readfile($fname);
        unlink($fname);
        exit();

which led me to /tmp/systemd-private-(blah-blah)-apache2-(blah)/tmp/PDFZvQ1XJ, which I ftp’d to my Windows laptop and opened in Adobe - and it’s a perfect CMS 1500. If the file was written to tmp, then it should be readable from tmp.

I don’t know much about PHP yet… the header function says “inline” but the document tries to open in a separate browser tab instead of in the popup window like you showed above. I also observed that a text file opens up just fine in separate browser tabs - so the problem seems to be with displaying a PDF.

I checked Chrome settings, Privacy and Security, Site Settings, scrolled down to Additional Content Settings and opened it, PDF documents, “Download PDF files instead of automatically opening them in Chrome”. This was set to download, and so I changed it to open in Chrome. Problem solved.

I suppose that with the browser set to download PDF files, it tries to open a new tab to download it, and somehow failed at that point? Other sites just download a file which shows up as a downloads shortcut in a bottom bar. Is there some way to get OpenEMR to do this if the browser is set to download PDFs? Not that important, just wondering.

Globals->PDF Output Type

Thank you! There are so many ways to customize in settings, it’s going to take a while for me to learn.