public function fetchFormValues($pid, $encounter, $formTables) { $res = array(); $count_folder = 0; foreach ($formTables as $formTables_details) { /***************Fetching the form id for the patient***************/ $query = "select form_id,encounter from forms where pid = ? and formdir = ? AND deleted=0"; $appTable = new ApplicationTable(); $form_ids = $appTable->zQuery($query, array($pid, $formTables_details[2])); /***************Fetching the form id for the patient***************/ if ($formTables_details[0] == 1) { //Fetching the values from an HTML form if (!$formTables_details[1]) { //Fetching the complete form foreach ($form_ids as $row) { //Fetching the values of each forms foreach ($row as $key => $value) { ob_start(); if (file_exists($GLOBALS['fileroot'] . '/interface/forms/' . $formTables_details[2] . '/report.php')) { include_once $GLOBALS['fileroot'] . '/interface/forms/' . $formTables_details[2] . '/report.php'; call_user_func($formTables_details[2] . "_report", $pid, $encounter, 2, $value); } $res[0][$value] = ob_get_clean(); } } } else { //Fetching a single field from the table $primary_key = ''; $query = "SHOW INDEX FROM ? WHERE Key_name='PRIMARY'"; $appTable = new ApplicationTable(); $res_primary = $appTable->zQuery($query, array($formTables_details[1])); foreach ($res_primary as $row_primary) { $primary_key = $row_primary['Column_name']; } unset($res_primary); $query = "select " . $formTables_details[3] . " from " . $formTables_details[1] . "\n join forms as f on f.pid=? AND f.encounter=? AND f.form_id=" . $formTables_details[1] . "." . $primary_key . " AND f.formdir=?\n where 1 = 1 "; $appTable = new ApplicationTable(); $result = $appTable->zQuery($query, array($pid, $encounter, $formTables_details[2])); foreach ($result as $row) { foreach ($row as $key => $value) { $res[0][$key] .= trim($value); } } } } else { if ($formTables_details[0] == 2) { //Fetching the values from an LBF form if (!$formTables_details[1]) { //Fetching the complete LBF foreach ($form_ids as $row) { foreach ($row as $key => $value) { //This section will be used to fetch complete LBF. This has to be completed. We are working on this. } } } elseif (!$formTables_details[3]) { //Fetching the complete group from an LBF foreach ($form_ids as $row) { //Fetching the values of each encounters foreach ($row as $key => $value) { ob_start(); ?> <table> <?php display_layout_rows_group_new($formTables_details[2], '', '', $pid, $value, array($formTables_details[1]), ''); ?> </table> <?php $res[0][$value] = ob_get_clean(); } } } else { $formid_list = ""; foreach ($form_ids as $row) { //Fetching the values of each forms foreach ($row as $key => $value) { if ($formid_list) { $formid_list .= ','; } $formid_list .= $value; } } $formid_list = $formid_list ? $formid_list : "''"; $lbf = "lbf_data"; $filename = "{$GLOBALS['srcdir']}/" . $formTables_details[2] . "/" . $formTables_details[2] . "_db.php"; if (file_exists($filename)) { include_once $filename; } $field_ids = explode(',', $formTables_details[3]); $fields_str = ''; foreach ($field_ids as $key => $value) { if ($fields_str != '') { $fields_str .= ","; } $fields_str .= "'{$value}'"; } $query = "select * from " . $lbf . "\n join forms as f on f.pid = ? AND f.form_id = " . $lbf . ".form_id AND f.formdir = ? AND " . $lbf . ".field_id IN (" . $fields_str . ")\n where deleted = 0"; $appTable = new ApplicationTable(); $result = $appTable->zQuery($query, array($pid, $formTables_details[2])); foreach ($result as $row) { preg_match('/\\.$/', trim($row['field_value']), $matches); if (count($matches) == 0) { $row['field_value'] .= ". "; } $res[0][$row['field_id']] .= $row['field_value']; } } } else { if ($formTables_details[0] == 3) { //Fetching documents from mapped folders $query = "SELECT c.id, c.name, d.id AS document_id, d.type, d.mimetype, d.url, d.docdate\n FROM categories AS c, documents AS d, categories_to_documents AS c2d\n WHERE c.id = ? AND c.id = c2d.category_id AND c2d.document_id = d.id AND d.foreign_id = ?"; $appTable = new ApplicationTable(); $result = $appTable->zQuery($query, array($formTables_details[2], $pid)); foreach ($result as $row_folders) { $r = \Documents\Plugin\Documents::getDocument($row_folders['document_id']); $res[0][$count_folder][0] = base64_encode($r); $res[0][$count_folder][1] = $row_folders['mimetype']; $res[0][$count_folder][2] = $row_folders['url']; $count_folder++; } } } } } return $res; }
public function retrieveAction() { // List of Preview Available File types $previewAvailableFiles = array('application/pdf', 'image/jpeg', 'image/png', 'image/gif', 'text/plain', 'text/html', 'text/xml'); $request = $this->getRequest(); $documentId = $this->params()->fromRoute('id'); $doEncryption = $this->params()->fromRoute('doencryption') == '1' ? true : false; $encryptionKey = $this->params()->fromRoute('key'); $type = $this->params()->fromRoute('download') == '1' ? "attachment" : "inline"; $result = $this->getDocumentsTable()->getDocument($documentId); $skip_headers = false; $contentType = $result['mimetype']; $document = \Documents\Plugin\Documents::getDocument($documentId, $doEncryption, $encryptionKey); $categoryIds = $this->getDocumentsTable()->getCategoryIDs(array('CCD', 'CCR', 'CCDA')); if (in_array($result['category_id'], $categoryIds) && $contentType == 'text/xml' && !$doEncryption) { $xml = simplexml_load_string($document); $xsl = new \DomDocument(); switch ($result['category_id']) { case $categoryIds['CCD']: $style = "ccd.xsl"; break; case $categoryIds['CCR']: $style = "ccr.xsl"; break; case $categoryIds['CCDA']: $style = "ccda.xsl"; break; } $xsl->load(__DIR__ . '/../../../../../public/xsl/' . $style); $proc = new \XSLTProcessor(); $proc->importStyleSheet($xsl); $document = $proc->transformToXML($xml); } if ($type == "inline" && !$doEncryption) { if (in_array($result['mimetype'], $previewAvailableFiles)) { if (in_array($result['category_id'], $categoryIds) && $contentType == 'text/xml') { $contentType = 'text/html'; } } else { $skip_headers = true; } } else { if ($doEncryption) { $contentType = "application/octet-stream"; } else { $contentType = $result['mimetype']; } } if (!$skip_headers) { $response = $this->getResponse(); $response->setContent($document); $headers = $response->getHeaders(); $headers->clearHeaders()->addHeaderLine('Content-Type', $contentType)->addHeaderLine('Content-Disposition', $type . '; filename="' . $result['name'] . '"')->addHeaderLine('Content-Length', strlen($document)); $response->setHeaders($headers); return $this->response; } }
public function getDocument($document_id) { $content = \Documents\Plugin\Documents::getDocument($document_id); return $content; }
public function fetchXmlDocuments() { $obj = new ApplicationTable(); $query = "SELECT doc.id \n\t FROM categories_to_documents AS cat_doc\n\t JOIN documents AS doc ON doc.imported = 0 AND doc.id = cat_doc.document_id AND doc.mimetype = 'text/xml'\n\t WHERE cat_doc.category_id = 1"; $result = $obj->zQuery($query); $count = 0; $module = array(); foreach ($result as $row) { $content = \Documents\Plugin\Documents::getDocument($row['id']); $module[$count]['doc_id'] = $row['id']; if (preg_match("/<ClinicalDocument/", $content)) { if (preg_match("/2.16.840.1.113883.3.88.11.32.1/", $content)) { $module[$count]['doc_type'] = 'CCD'; } else { $module[$count]['doc_type'] = 'CCDA'; } } elseif (preg_match("/<ccr:ContinuityOfCareRecord/", $content)) { $module[$count]['doc_type'] = 'CCR'; } $count++; } return $module; }