* @copyright Copyright (c) 2022 Discover and Change, Inc. * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 */ use OpenEMR\Common\Csrf\CsrfUtils; use OpenEMR\Common\Database\QueryUtils; use OpenEMR\Common\Twig\TwigContainer; use OpenEMR\Common\Logging\SystemLogger; use OpenEMR\Services\Cda\CdaValidateDocumentObject; if (empty($noteid)) { $twig = new TwigContainer(null, $GLOBALS['kernel']); echo $twig->render('core/unauthorized.html.twig', ['pageTitle' => xl("Linked Documents")]); exit; } // Get the related document IDs if any. $linkedDocsSql = "SELECT id1 FROM gprelations WHERE " . "type1 = ? AND type2 = ? AND id2 = ?"; $tmp = QueryUtils::fetchRecords($linkedDocsSql, ['1','6',$noteid]); if (empty($tmp)) { return; } $enc_list = []; if (!empty($prow)) { $results = QueryUtils::fetchRecords("SELECT fe.encounter,fe.date,openemr_postcalendar_categories.pc_catname FROM form_encounter AS fe " . " LEFT JOIN openemr_postcalendar_categories ON fe.pc_catid=openemr_postcalendar_categories.pc_catid WHERE fe.pid = ? ORDER BY fe.date DESC", array($prow['pid'])); foreach ($enc_list as $row) { $enc_list[] = [ 'encounter' => $row['encounter'], 'pc_catname' => xl_appt_category($row['pc_catname']), 'date' => oeFormatShortDate(date("Y-m-d", strtotime($row['date']))) ]; } } // if we have phimail enabled, we are going to find out if our document is an xml file, if so, we are going to do a validation // report on the document. This would be a great thing for caching if we wanted to do that, we'll just compute on the fly for now. $records = []; $prow = $prow ?? null; $cdaDocumentValidator = new CdaValidateDocumentObject(); foreach ($tmp as $record) { $d = new Document($record['id1']); $docInformation = [ 'documentId' => $d->get_id(), 'title' => $d->get_name() . "-" . $d->get_id(), 'isCda' => false, 'hasPatient' => false, 'requiresValidation' => false ]; if (!empty($prow)) { $docInformation['hasPatient'] = true; $docInformation['pname'] = $prow['fname'] . " " . $prow['lname']; $docInformation['pid'] = $prow['pid']; $docInformation['pubpid'] = $prow['pubpid']; $docInformation['DOB'] = $prow['DOB']; } if ($cdaDocumentValidator->isCdaDocument($d)) { $docInformation['isCda'] = true; $docInformation['requiresValidation'] = true; } $records[] = $docInformation; } try { foreach ($records as $record) : ?>
" data-doc="">
errorLogCaller($exception->getMessage(), ['trace' => $exception->getTraceAsString()]); } ?>