CCR Import, made changes per comments in github.
authorAjil P.M <ajilpm@zhservices.com>
Mon, 29 Jul 2013 12:57:20 +0000 (29 18:27 +0530)
committerbradymiller <bradymiller@users.sourceforge.net>
Thu, 1 Aug 2013 04:30:13 +0000 (31 21:30 -0700)
Signed-off-by: Ajil P.M <ajilpm@zhservices.com>
Minor mods by brady to place it into 4.1.2 release.

12 files changed:
ccr/display.php
interface/main/left_nav.php
interface/patient_file/ccr_import.php [new file with mode: 0644]
interface/patient_file/ccr_pending_approval.php [new file with mode: 0644]
interface/patient_file/ccr_review_approve.php [new file with mode: 0644]
library/ajax/ccr_import_ajax.php [new file with mode: 0644]
library/classes/Document.class.php
library/parse_patient_xml.php [new file with mode: 0644]
sql/4_1_1-to-4_1_2_upgrade.sql
sql/database.sql
templates/documents/general_view.html
version.php

index d66827f..89b5c4c 100644 (file)
@@ -1,31 +1,54 @@
 <?php
 require_once(dirname(__FILE__) . "/../interface/globals.php");
 require_once(dirname(__FILE__) . "/../library/classes/Document.class.php");
+require_once(dirname(__FILE__) . "/../library/classes/CouchDB.class.php");
 
 $type = $_GET['type'];
 $document_id = $_GET['doc_id'];
 $d = new Document($document_id);
 $url =  $d->get_url();
-$url = preg_replace("|^(.*)://|","",$url);
+$storagemethod = $d->get_storagemethod();
+$couch_docid = $d->get_couch_docid();
+$couch_revid = $d->get_couch_revid();
 
-// Collect filename and path
-$from_all = explode("/",$url);
-$from_filename = array_pop($from_all);
-$from_pathname_array = array();
-for ($i=0;$i<$d->get_path_depth();$i++) {
+if($couch_docid && $couch_revid){
+       $couch = new CouchDB();
+       $data = array($GLOBALS['couchdb_dbase'],$couch_docid);
+       $resp = $couch->retrieve_doc($data);
+       $xml = base64_decode($resp->data);
+       if($content=='' && $GLOBALS['couchdb_log']==1){                         
+               $log_content = date('Y-m-d H:i:s')." ==> Retrieving document\r\n";
+               $log_content = date('Y-m-d H:i:s')." ==> URL: ".$url."\r\n";
+               $log_content .= date('Y-m-d H:i:s')." ==> CouchDB Document Id: ".$couch_docid."\r\n";
+               $log_content .= date('Y-m-d H:i:s')." ==> CouchDB Revision Id: ".$couch_revid."\r\n";
+               $log_content .= date('Y-m-d H:i:s')." ==> Failed to fetch document content from CouchDB.\r\n";
+               //$log_content .= date('Y-m-d H:i:s')." ==> Will try to download file from HardDisk if exists.\r\n\r\n";
+               $this->document_upload_download_log($d->get_foreign_id(),$log_content);
+               die(xlt("File retrieval from CouchDB failed"));
+       }
+}else{
+  $url = preg_replace("|^(.*)://|","",$url);
+  // Collect filename and path
+  $from_all = explode("/",$url);
+  $from_filename = array_pop($from_all);
+  $from_pathname_array = array();
+  for ($i=0;$i<$d->get_path_depth();$i++) {
   $from_pathname_array[] = array_pop($from_all);
-}
-$from_pathname_array = array_reverse($from_pathname_array);
-$from_pathname = implode("/",$from_pathname_array);
-$temp_url = $GLOBALS['OE_SITE_DIR'] . '/documents/' . $from_pathname . '/' . $from_filename;
-if (!file_exists($temp_url)) {
+  }
+  $from_pathname_array = array_reverse($from_pathname_array);
+  $from_pathname = implode("/",$from_pathname_array);
+  $temp_url = $GLOBALS['OE_SITE_DIR'] . '/documents/' . $from_pathname . '/' . $from_filename;
+  if (!file_exists($temp_url)) {
   echo xl('The requested document is not present at the expected location on the filesystem or there are not sufficient permissions to access it.','','',' ') . $temp_url;
-}else{
+  }else{
   $url = $temp_url;
   $f = fopen($url,"r");
   $xml = fread($f,filesize($url));
   fclose($f);
-  if($type == "CCR"){
+  }
+}
+
+if($type == "CCR"){
     $xmlDom = new DOMDocument();
     $xmlDom->loadXML($xml);
     $ss = new DOMDocument();
@@ -34,7 +57,7 @@ if (!file_exists($temp_url)) {
     $proc->importStylesheet($ss);
     $s_html = $proc->transformToXML($xmlDom);
     echo $s_html;
-  }else{
+}else{
     $xmlDom = new DOMDocument();
     $xmlDom->loadXML($xml);
     $ss = new DOMDocument();
@@ -43,6 +66,5 @@ if (!file_exists($temp_url)) {
                $xslt->importStyleSheet($ss);
                $html = $xslt->transformToXML($xmlDom);
                echo $html;
-  }
 }
 ?>
index aa399c6..eb41674 100644 (file)
@@ -1192,6 +1192,12 @@ if (!empty($reg)) {
 ?>
         </ul>
       </li>
+      <li class="collapsed" ><a class="collapsed_lv2"><span><?php echo xlt('Import') ?></span></a>
+        <ul>
+          <?php genMiscLink('RTop','ccr','0',xlt('Upload'),'patient_file/ccr_import.php'); ?>
+          <?php genMiscLink('RTop','apr','0',xlt('Pending Approval'),'patient_file/ccr_pending_approval.php'); ?>
+        </ul>
+      </li>
 <?php } // end if gbl_nav_visit_forms ?>
 
     </ul>
diff --git a/interface/patient_file/ccr_import.php b/interface/patient_file/ccr_import.php
new file mode 100644 (file)
index 0000000..53c3f5b
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+/**
+ * interface/patient_file/ccr_import.php Upload screen and parser for the CCR XML.
+ *
+ * Functions to upload the CCR XML and to parse and insert it into audit tables.
+ *
+ * Copyright (C) 2013 Z&H Consultancy Services Private Limited <sam@zhservices.com>
+ *
+ * LICENSE: This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
+ *
+ * @package OpenEMR
+ * @author  Eldho Chacko <eldho@zhservices.com>
+ * @author  Ajil P M <ajilpm@zhservices.com>
+ * @link    http://www.open-emr.org
+ */
+
+//SANITIZE ALL ESCAPES
+$sanitize_all_escapes=true;
+//
+
+//STOP FAKE REGISTER GLOBALS
+$fake_register_globals=false;
+//
+
+require_once(dirname(__FILE__) . "/../globals.php");
+
+?>
+<html>
+<head>
+<title><?php echo xlt('Import');?></title>
+<link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
+</head>
+<body class="body_top" >
+<center>
+<p><b><?php echo xlt("Steps for uploading CCR XML");?></b></p>
+<table style="width:85%;font-size:14px;" >
+  <tr>
+    <td>1.</td>
+    <td><?php echo xlt('To upload CCR document of already existing patient use Patient Summary Screen->Documents. For CCR document of a new patient use Miscellanous->New Documents screen').'.'; ?></td>
+  </tr>
+  <tr>
+    <td>2.</td>
+    <td><?php echo xlt('Upload the xml file under the category CCR').'.'; ?></td>
+  </tr>
+  <tr>
+    <td>3.</td>
+    <td><?php echo xlt('After Uploading click the button "Import"').'.'; ?></td>
+  </tr>
+  <tr>
+    <td>4.</td>
+    <td><?php echo xlt('Approve the patient from Patient/Client->Import->Pending Approval').'.'; ?></td>
+  </tr>
+</table>
+</center>
+</form>
+</body>
+</html>
diff --git a/interface/patient_file/ccr_pending_approval.php b/interface/patient_file/ccr_pending_approval.php
new file mode 100644 (file)
index 0000000..c71b664
--- /dev/null
@@ -0,0 +1,210 @@
+<?php
+/**
+ * interface/patient_file/ccr_pending_approval.php Approval screen for uploaded CCR XML.
+ *
+ * Approval screen for uploaded CCR XML.
+ *
+ * Copyright (C) 2013 Z&H Consultancy Services Private Limited <sam@zhservices.com>
+ *
+ * LICENSE: This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
+ *
+ * @package OpenEMR
+ * @author  Eldho Chacko <eldho@zhservices.com>
+ * @author  Ajil P M <ajilpm@zhservices.com>
+ * @link    http://www.open-emr.org
+ */
+
+//SANITIZE ALL ESCAPES
+$sanitize_all_escapes=true;
+//
+
+//STOP FAKE REGISTER GLOBALS
+$fake_register_globals=false;
+//
+
+require_once(dirname(__FILE__) . "/../globals.php");
+require_once(dirname(__FILE__) . "/../../library/options.inc.php");
+require_once(dirname(__FILE__) . "/../../library/patient.inc");
+require_once(dirname(__FILE__) . "/../../library/parse_patient_xml.php");
+
+if($_REQUEST['approve'] == 1){
+       insert_patient($_REQUEST['am_id']);
+?>
+  <html>
+               <head>
+                       <title><?php echo xlt('CCR Approve');?></title>
+                       <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css" >
+               </head>
+               <body class="body_top" >
+                       <center><?php echo xlt('Approved Successfully'); ?></center>
+               </body>
+       </html>
+       <?php
+       exit;
+}
+
+?>
+<html>
+<head>
+<title><?php echo xlt('Pending Approval');?></title>
+<link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
+<style>
+
+table {
+       color: #000;
+       font: .8em/1.6em "Trebuchet MS",Verdana,sans-serif;
+       border-collapse: collapse;
+       margin: 0 auto;
+       border: 1px solid #CCC;
+}
+
+tbody th,td {
+       border-left: 0;
+       padding: 8px
+}
+
+tbody{
+       background: rgb(255,255,255); /* Old browsers */
+       background: -moz-linear-gradient(top, rgba(255,255,255,1) 0%, rgba(229,229,229,1) 100%); /* FF3.6+ */
+       background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,1)), color-stop(100%,rgba(229,229,229,1))); /* Chrome,Safari4+ */
+       background: -webkit-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(229,229,229,1) 100%); /* Chrome10+,Safari5.1+ */
+       background: -o-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(229,229,229,1) 100%); /* Opera 11.10+ */
+       background: -ms-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(229,229,229,1) 100%); /* IE10+ */
+       background: linear-gradient(to bottom, rgba(255,255,255,1) 0%,rgba(229,229,229,1) 100%); /* W3C */
+       filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#e5e5e5',GradientType=0 ); /* IE6-9 */
+}
+
+tbody th {
+       color: #3e3e3e;
+       padding: 5px 10px;
+       background: #f5f6f6; /* Old browsers */
+       background: -moz-linear-gradient(top, #f5f6f6 0%, #dbdce2 21%, #b8bac6 49%, #dddfe3 80%, #f5f6f6 100%); /* FF3.6+ */
+       background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f5f6f6), color-stop(21%,#dbdce2), color-stop(49%,#b8bac6), color-stop(80%,#dddfe3), color-stop(100%,#f5f6f6)); /* Chrome,Safari4+ */
+       background: -webkit-linear-gradient(top, #f5f6f6 0%,#dbdce2 21%,#b8bac6 49%,#dddfe3 80%,#f5f6f6 100%); /* Chrome10+,Safari5.1+ */
+       background: -o-linear-gradient(top, #f5f6f6 0%,#dbdce2 21%,#b8bac6 49%,#dddfe3 80%,#f5f6f6 100%); /* Opera 11.10+ */
+       background: -ms-linear-gradient(top, #f5f6f6 0%,#dbdce2 21%,#b8bac6 49%,#dddfe3 80%,#f5f6f6 100%); /* IE10+ */
+       background: linear-gradient(to bottom, #f5f6f6 0%,#dbdce2 21%,#b8bac6 49%,#dddfe3 80%,#f5f6f6 100%); /* W3C */
+       filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f5f6f6', endColorstr='#f5f6f6',GradientType=0 ); /* IE6-9 */
+       border-bottom: 1px solid;
+}
+
+tbody tr.odd {
+       background-color: #F7F7F7;
+       color: #666
+}
+
+.button-link {
+       padding: 3px 10px;
+       background: #c0c0c0;
+       color: #000 !important;
+       -webkit-border-radius: 4px;
+       -moz-border-radius: 4px;
+       border-radius: 4px;
+       border: solid 1px #000000;
+       -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
+       -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
+       box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
+       -webkit-transition-duration: 0.2s;
+       -moz-transition-duration: 0.2s;
+       transition-duration: 0.2s;
+       -webkit-user-select:none;
+       -moz-user-select:none;
+       -ms-user-select:none;
+       user-select:none;
+}
+
+.button-link:hover {
+       background: #808080;
+       border: solid 1px #000000;
+       text-decoration: none;
+       color: #FFF !important;
+}
+
+</style>
+<script type="text/javascript" >
+  
+</script>
+</head>
+<body class="body_top" >
+<center>
+<p><b><?php echo xlt('Pending Approval');?></b></p>
+</center>
+<form method="post" name="approve" "onsubmit='return top.restoreSession()'" >
+<center>
+<table style="width:80%;" border="0" >
+       <tr>
+               <th>
+                       <?php echo xlt('Patient Name'); ?>
+               </th>
+               <th>
+                       <?php echo xlt('Match Found'); ?>
+               </th>
+               <th>
+                       <?php echo xlt('Action'); ?>
+               </th>
+       </tr>
+       <?php
+       $query = sqlStatement("SELECT *,am.id amid,CONCAT(ad.field_value,' ',ad1.field_value) as pat_name FROM audit_master am JOIN audit_details ad ON
+               ad.audit_master_id = am.id AND ad.table_name = 'patient_data' AND ad.field_name = 'lname' JOIN audit_details ad1 ON
+               ad1.audit_master_id = am.id AND ad1.table_name = 'patient_data' AND ad1.field_name = 'fname' WHERE type='11' AND approval_status='1'");
+       if(sqlNumRows($query) > 0){
+               while($res = sqlFetchArray($query)){
+               $dup_query = sqlStatement("SELECT * FROM audit_master am JOIN audit_details ad ON ad.audit_master_id = am.id AND ad.table_name = 'patient_data'
+                       AND ad.field_name = 'lname' JOIN audit_details ad1 ON ad1.audit_master_id = am.id AND ad1.table_name = 'patient_data' AND
+                       ad1.field_name = 'fname' JOIN audit_details ad2 ON ad2.audit_master_id = am.id AND ad2.table_name = 'patient_data' AND ad2.field_name = 'DOB'
+                       JOIN patient_data pd ON pd.lname = ad.field_value AND pd.fname = ad1.field_value AND pd.DOB = DATE(ad2.field_value) WHERE am.id = ?",
+               array($res['amid']));
+       ?>
+       <tr>
+               <td class="bold" >
+                       <?php echo text($res['pat_name']); ?>
+               </td>
+                       <?php
+                       if(sqlNumRows($dup_query)>0){
+                               $dup_res = sqlFetchArray($dup_query);
+                       ?>
+               <td align="center" class="bold" >
+                       <?php echo xlt('Yes'); ?>
+               </td>
+               <td align="center" >
+                       <a href="ccr_review_approve.php?revandapprove=1&amid=<?php echo attr($res['amid']); ?>&pid=<?php echo attr($dup_res['pid']); ?>" class="button-link" onclick="top.restoreSession()" ><?php echo xlt('Review & Approve'); ?></a>
+               </td>
+               <?php
+                       }else{
+               ?>
+               <td align="center" class="bold" >
+                       <?php echo xlt('No'); ?>
+               </td>
+               <td align="center" >
+                       <a href="ccr_pending_approval.php?approve=1&am_id=<?php echo attr($res['amid']); ?>" class="button-link" onclick="top.restoreSession()" ><?php echo xlt('Approve'); ?></a>
+               </td>
+               <?php
+                       }
+               ?>
+       </tr>
+       <?php
+               }
+       }else{
+       ?>
+               <tr>
+                       <td colspan="3" >
+                               <?php echo xlt('Nothing Pending for Approval')."."; ?>
+                       </td>
+               </tr>
+       <?php
+       }
+?>
+</table>
+</center>
+</form>
+</body>
+</html>
diff --git a/interface/patient_file/ccr_review_approve.php b/interface/patient_file/ccr_review_approve.php
new file mode 100644 (file)
index 0000000..ce86df1
--- /dev/null
@@ -0,0 +1,456 @@
+<?php
+/**
+ * interface/patient_file/ccr_review_approve.php Approval screen for uploaded CCR XML.
+ *
+ * Approval screen for uploaded CCR XML.
+ *
+ * Copyright (C) 2013 Z&H Consultancy Services Private Limited <sam@zhservices.com>
+ *
+ * LICENSE: This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
+ *
+ * @package OpenEMR
+ * @author  Eldho Chacko <eldho@zhservices.com>
+ * @author  Ajil P M <ajilpm@zhservices.com>
+ * @link    http://www.open-emr.org
+ */
+
+//SANITIZE ALL ESCAPES
+$sanitize_all_escapes=true;
+//
+
+//STOP FAKE REGISTER GLOBALS
+$fake_register_globals=false;
+//
+
+require_once(dirname(__FILE__) . "/../globals.php");
+require_once(dirname(__FILE__) . "/../../library/parse_patient_xml.php");
+
+$patient_data = array(
+       'sex'                                           => 'Sex',
+       'pubpid'                                => 'External ID',
+       'street'                                => 'Street',
+       'city'                                  => 'City',
+       'state'                                 => 'State',
+       'postal_code'           => 'Postal Code',
+);
+
+if($_POST["setval"] == 'approve'){
+  insertApprovedData($_REQUEST);
+  $query = "UPDATE audit_master SET approval_status = '2' WHERE id=?";
+  sqlQuery($query,array($_REQUEST['amid']));
+       ?>
+       <html>
+               <head>
+                       <title><?php echo xlt('CCR Review and Approve');?></title>
+                       <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css" >
+               </head>
+               <body class="body_top" >
+                       <center><?php echo xlt('Approved Successfully'); ?></center>
+               </body>
+       </html>
+       <?php
+       exit;
+}elseif($_POST["setval"] == 'discard'){
+  $query = "UPDATE audit_master SET approval_status = '3' WHERE id=?";
+  sqlQuery($query,array($_REQUEST['amid']));
+       ?>
+       <html>
+               <head>
+                       <title><?php echo xlt('CCR Review and Approve');?></title>
+                       <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css" >
+               </head>
+               <body class="body_top" >
+                       <center><?php echo xlt('Discarded'); ?></center>
+               </body>
+       </html>
+       <?php
+       exit;
+}
+
+?>
+<html>
+<head>
+<title><?php echo xlt('CCR Review and Approve');?></title>
+<link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css" >
+<style>
+
+table {
+       color: #000;
+       font: .85em/1.6em "Trebuchet MS",Verdana,sans-serif;
+       border-collapse: collapse;
+       margin: 0 auto;
+       border: 1px solid #CCC;
+}
+
+tbody th,td {
+       border-left: 0;
+       padding: 8px;
+}
+
+tbody {
+       background: #D4D4D4;
+}
+
+table table tbody tr {
+       background: #EEEEEE;
+}
+
+.alternate{
+       background-color: #C4C4C4;
+}
+
+</style>
+<script type="text/javascript" >
+
+function submit_form(val){
+       document.getElementById('setval').value = val;
+  top.restoreSession();
+       document.forms['approveform'].submit();
+}
+
+</script>
+</head>
+<body class="body_top" >
+<center>
+<p><b><?php echo xlt('CCR Patient Review');?></b></p>
+</center>
+<form method="post" name="approveform" "onsubmit='return top.restoreSession()'" >
+       <table border="0" width="90%;" >
+               <tr>
+                       <td>
+                               <u><?php echo xlt('Demographics'); ?></u>
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               <table border="0" width="95%" >
+                                       <tr>
+                                               <?php
+                                                       $query_pd = sqlStatement("SELECT ad.id as adid, table_name, field_name, field_value FROM audit_master am JOIN audit_details ad ON ad.audit_master_id = am.id
+                                                               WHERE am.id = ? AND ad.table_name = 'patient_data' ORDER BY ad.id",array($_REQUEST['amid']));
+                                                       $i = 0;
+                                                       while($res_pd = sqlFetchArray($query_pd)){
+                                                               if($res_pd['field_name'] != 'lname' && $res_pd['field_name'] != 'fname' && $res_pd['field_name'] != 'DOB'){
+                                                                       $i++;
+                                                                       $query_oldpd = sqlQuery("SELECT ".$res_pd['field_name']." AS val FROM patient_data WHERE pid = ?",array($_REQUEST['pid']));
+                                                                       if($res_pd['field_name'] == 'sex'){
+                                                                               echo "<td>" . ($patient_data[$res_pd['field_name']] ? text($patient_data[$res_pd['field_name']]): text($res_pd['field_name'])) . "</td>" .
+                                                                                       "<td><select name='" . $res_pd['table_name'] . "-" . $res_pd['field_name'] . "' style='width:150px;' >" .
+                      "<option value='Male' " . ($res_pd['field_value'] == 'Male' ? 'selected' : '' ) . " >" . xlt('Male') . "</option>" .
+                                                                                       "<option value='Female' ".($res_pd['field_value'] == 'Female' ? 'selected' : '' )." >".xlt('Female')."</option></select>" .
+                      "<span style='color:red;padding-left:25px;' >" . text($query_oldpd['val']) . "</span></td>" .
+                                                                                       "<td><select name='" . $res_pd['table_name'] . "-" . $res_pd['field_name'] . "-sel'>" .
+                      "<option value='ignore' >" . xlt('Ignore') . "</option> " .
+                      "<option value='update' >" . xlt('Update') . "</option></select></td>";
+                                                                       }else{
+                                                                               echo "<td>" . ($patient_data[$res_pd['field_name']] ? text($patient_data[$res_pd['field_name']]): text($res_pd['field_name'])) . "</td>" .
+                                                                                       "<td><input type='text' name='" . $res_pd['table_name'] . "-" . $res_pd['field_name'] . "' value='" . attr($res_pd['field_value']) . "' >" .
+                      "<span style='color:red;padding-left:25px;' >" . text($query_oldpd['val']) . "</span></td>" .
+                                                                                       "<td><select name='" . $res_pd['table_name'] . "-" . $res_pd['field_name'] . "-sel' >" .
+                      "<option value='ignore' >" . xlt('Ignore') . "</option><option value='update' >" . xlt('Update') . "</option></select></td>";
+                                                                       }
+                                                                       if($i%2 == 0){
+                                                                               if($i%4 == 2){
+                                                                                       echo "</tr><tr class='alternate' >";
+                                                                               }else{
+                                                                                       echo "</tr><tr>";
+                                                                               }
+                                                                       }else{
+                                                                               echo "<td>&nbsp;&nbsp;&nbsp;</td>";
+                                                                       }
+                                                               }
+                                                       }
+                                               ?>
+                                       </tr>
+                               </table>
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               &nbsp;
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               <u><?php echo xlt('Problems'); ?></u>
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               <table border="0" width="95%" >
+                                       <tr>
+                                               <?php
+                                                       $query_existing_prob = sqlStatement("SELECT * FROM lists WHERE pid = ? AND TYPE = 'medical_problem'",array($_REQUEST['pid']));
+                                                       $result = array();
+                                                       while($res_existing_prob = sqlFetchArray($query_existing_prob)){
+                                                               array_push($result,$res_existing_prob);
+                                                       }
+                                                       $aud_res = createAuditArray($_REQUEST['amid'],'lists1');
+                                                       while($res_existing_prob = array_shift($result)){
+                                                               if($res_existing_prob['activity'] == 1){
+                                                                       $activity = 'Active';
+                                                               }else{
+                                                                       $activity = 'Inactive';
+                                                               }
+                                                               $set = 0;
+                                                               $cnt = 0;
+                                                               foreach($aud_res['lists1'] as $k=>$v){
+                                                                       $cnt++;
+                                                                       if($cnt%2 == 0){
+                                                                               $class = 'alternate';
+                                                                       }else{
+                                                                               $class = '';
+                                                                       }
+                                                                       if(in_array($res_existing_prob['diagnosis'],$aud_res['lists1'][$k])){
+                                                                               $set = 1;
+                                                                               echo "<tr class='$class' ><td>" . xlt('Title') . "</td><td><input type='text' name='lists1-title[]' value='' ></td>" .
+                                                                               "<td>" . xlt('Code') . "</td>" .
+                    "<td><input type='text' name='lists1-diagnosis[]' value='" . attr($aud_res['lists1'][$k]['diagnosis']) . "' >" .
+                                                                               "<input type='hidden' name='lists1-old-diagnosis[]' value='" . attr($res_existing_prob['diagnosis']) . "' ></td>" .
+                                                                               "<td>" . xlt('Status') . "</td><td><input type='text' name='lists1-activity[]' value='" . $activity . "' ></td>" .
+                    "<td rowspan='2' ><select name='lists1-sel[]'><option value='ignore' >" . xlt('Ignore') . "</option>" .
+                    "<option value='update' >" . xlt('Update') . "</option></select></td></tr>" .
+                                                                               "<tr style='color:red' ><td>&nbsp;</td><td>" . text($res_existing_prob['title']) . "</td><td>&nbsp;</td>" .
+                    "<td>" . text($res_existing_prob['diagnosis']) . "</td>" .
+                                                                               "<td>&nbsp;</td><td>" . xlt($activity) . "</td>";
+                                                                               unset($aud_res['lists1'][$k]);
+                                                                       }
+                                                               }
+                                                               if($set == 0){
+                                                                       echo "<tr><td>" . xlt('Title') . "</td><td>" . text($res_existing_prob['title']) . "</td>" .
+                                                                       "<td>" . xlt('Code') . "</td><td>" . text($res_existing_prob['diagnosis']) . "</td>" .
+                                                                       "<td>" . xlt('Status') . "</td><td>" . xlt($activity) . "</td><td>&nbsp;</td>";
+                                                               }
+                                                               echo "</tr>";
+                                                       }
+                                                       foreach($aud_res['lists1'] as $key=>$val){
+                                                               if($val['activity'] == 1){
+                                                                       $activity = 'Active';
+                                                               }else{
+                                                                       $activity = 'Inactive';
+                                                               }
+                                                               echo "<tr><td>" . xlt('Title') . "</td><td><input type='text' name='lists1-title[]' value='' ></td>" .
+                                                                       "<td>" . xlt('Code') . "</td><td><input type='text' name='lists1-diagnosis[]' value='" . attr($val['diagnosis']) . "' ></td>" .
+                                                                       "<td>" . xlt('Status') . "</td><td><input type='text' name='lists1-activity[]' value='" . $activity . "' ></td>" .
+                                                                       "<td><select name='lists1-sel[]'><option value='ignore' >" . xlt('Ignore') . "</option>" .
+                  "<option value='insert' >" . xlt('Insert') . "</option></select></td></tr>";
+                                                       }
+                                               ?>
+                                       </tr>
+                               </table>
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               &nbsp;
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               <u><?php echo xlt('Allergy'); ?></u>
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               <table border="0" width="95%" >
+                                       <tr>
+                                               <?php
+                                                       $query_existing_alerts = sqlStatement("SELECT * FROM lists WHERE pid = ? AND TYPE = 'allergy'",array($_REQUEST['pid']));
+                                                       $result = array();
+                                                       while($res_existing_alerts = sqlFetchArray($query_existing_alerts)){
+                                                               array_push($result,$res_existing_alerts);
+                                                       }
+                                                       $aud_res = createAuditArray($_REQUEST['amid'],'lists2');
+                                                       while($res_existing_alerts = array_shift($result)){
+                                                               if($res_existing_alerts['activity'] == 1){
+                                                                       $activity = 'Active';
+                                                               }else{
+                                                                       $activity = 'Inactive';
+                                                               }
+                                                               echo "<tr><td>" . xlt('Title') . "</td><td>" . text($res_existing_alerts['title']) . "</td>" .
+                                                               "<td>" . xlt('Date Time') . "</td><td>" . text($res_existing_alerts['date']) . "</td>" .
+                "<td>" . xlt('Diagnosis') . "</td><td>" . text($res_existing_alerts['diagnosis']) . "</td>" .
+                                                               "<td>" . xlt('Reaction') . "</td><td>" . text($res_existing_alerts['reaction']) . "</td><td>&nbsp;</td></tr>";
+                                                       }
+                                                       foreach($aud_res['lists2'] as $key=>$val){
+                                                               if($val['activity'] == 1){
+                                                                       $activity = 'Active';
+                                                               }else{
+                                                                       $activity = 'Inactive';
+                                                               }
+                                                               echo "<tr><td>" . xlt('Title') . "</td><td><input type='text' name='lists2-title[]' value='" . attr($val['title']) . "' ></td>" .
+                                                                       "<td>" . xlt('Date Time') . "</td><td><input type='text' name='lists2-date[]' value='" . attr($val['date']) . "' ></td>" .
+                  "<td>" . xlt('Diagnosis') . "</td><td><input type='text' name='lists2-diagnosis[]' value='" . attr($val['diagnosis']) . "' ></td>" .
+                                                                       "<td>" . xlt('Reaction') . "</td><td><input type='text' name='lists2-reaction[]' value='" . attr($val['reaction']) . "' ></td>" .
+                                                                       "<td><select name='lists2-sel[]'><option value='ignore' >" . xlt('Ignore') . "</option>" .
+                  "<option value='insert' >" . xlt('Insert') . "</option></select></td>" .
+                                                                       "<input type='hidden' name='lists2-type[]' value='" . attr($val['type']) . "' ></tr>";
+                                                       }
+                                               ?>
+                                       </tr>
+                               </table>
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               &nbsp;
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               <u><?php echo xlt('Medications'); ?></u>
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               <table border="0" width="95%" >
+                                       <tr>
+                                               <?php
+                                                       $query_existing_medications = sqlStatement("SELECT * FROM prescriptions WHERE patient_id = ?",array($_REQUEST['pid']));
+                                                       $result = array();
+                                                       while($res_existing_medications = sqlFetchArray($query_existing_medications)){
+                                                               array_push($result,$res_existing_medications);
+                                                       }
+                                                       $aud_res = createAuditArray($_REQUEST['amid'],'prescriptions');
+                                                       while($res_existing_medications = array_shift($result)){
+                                                               if($res_existing_medications['active'] == 1){
+                                                                       $activity = 'Active';
+                                                               }else{
+                                                                       $activity = 'Inactive';
+                                                               }
+                                                               echo "<tr><td>" . xlt('Name') . "</td><td>" . text($res_existing_medications['drug']) . "</td>" .
+                                                                       "<td>" . xlt('Date') . "</td><td>" . text($res_existing_medications['date_added']) . "</td>" .
+                                                                       "<td>" . xlt('Status') . "</td><td>" . xlt($activity) . "</td><td rowspan='2' >&nbsp;</td></tr><tr><td>" . xlt('Form') . "</td>" .
+                  "<td>" . text($res_existing_medications['form'])."&nbsp;&nbsp;&nbsp;" . xlt('Strength') . "&nbsp;&nbsp;&nbsp;" . text($res_existing_medications['size']) . "</td>" .
+                                                                       "<td>" . xlt('Quantity')."</td><td>" . text($res_existing_medications['quantity']) . "</td>" .
+                                                                       "<td>" . xlt('Refills') . "</td><td>" . text($res_existing_medications['refills']) . "</td></tr>";
+                                                       }
+                                                       foreach($aud_res['prescriptions'] as $key=>$val){
+                                                               if($val['active'] == 1){
+                                                                       $activity = 'Active';
+                                                               }else{
+                                                                       $activity = 'Inactive';
+                                                               }
+                                                               echo "<tr><td>" . xlt('Name') . "</td><td><input type='text' name='prescriptions-drug[]' value='" . attr($val['drug']) . "' ></td>" .
+                                                                       "<td>" . xlt('Date') . "</td><td><input type='text' name='prescriptions-date_added[]' value='" . attr($val['date_added']) . "' ></td>" .
+                                                                       "<td>" . xlt('Status') . "</td><td><input type='text' name='prescriptions-active[]' value='" . $activity . "' ></td><td rowspan='2' >" .
+                                                                       "<select name='prescriptions-sel[]'><option value='ignore' >" . xlt('Ignore') . "</option>" .
+                  "<option value='insert' >" . xlt('Insert') . "</option></select></td></tr><tr><td>" . xlt('Form') . "</td>" .
+                                                                       "<td><input type='text' size='8' name='prescriptions-form[]' value='" . attr($val['form']) . "' >" .
+                  "&nbsp;&nbsp;&nbsp;" . xlt('Strength') . "&nbsp;&nbsp;&nbsp;<input type='text' size='7' name='prescriptions-size[]' value='" . attr($val['size']) . "' ></td>" .
+                                                                       "<td>" . xlt('Quantity') . "</td><td><input type='text' name='prescriptions-quantity[]' value='" . attr($val['quantity']) . "' ></td>" .
+                                                                       "<td>" . xlt('Refills') . "</td><td><input type='text' name='prescriptions-refills[]' value='" . attr($val['refills']) . "' ></td></tr>";
+                                                       }
+                                               ?>
+                                       </tr>
+                               </table>
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               &nbsp;
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               <u><?php echo xlt('Immunizations'); ?></u>
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               <table border="0" width="95%" >
+                                       <tr>
+                                               <?php
+                                                       $query_existing_immunizations = sqlStatement("SELECT * FROM immunizations WHERE patient_id = ?",array($_REQUEST['pid']));
+                                                       $result = array();
+                                                       while($res_existing_immunizations = sqlFetchArray($query_existing_immunizations)){
+                                                               array_push($result,$res_existing_immunizations);
+                                                       }
+                                                       $aud_res = createAuditArray($_REQUEST['amid'],'immunizations');
+                                                       while($res_existing_immunizations = array_shift($result)){
+                                                               echo "<tr><td>" . xlt('Administered Date') . "</td>" .
+                                                                       "<td>" . text($res_existing_immunizations['administered_date']) . "</td>" .
+                                                                       "<td>" . xlt('Note') . "</td><td>" . text($res_existing_immunizations['note']) . "</td>" .
+                                                                       "<td>&nbsp;</td></tr>";
+                                                       }
+                                                       foreach($aud_res['immunizations'] as $key=>$val){
+                                                               echo "<tr><td>" . xlt('Administered Date') . "</td>" .
+                                                                       "<td><input type='text' name='immunizations-administered_date[]' value='" . attr($val['administered_date']) . "' ></td>" .
+                                                                       "<td>" . xlt('Note') . "</td><td><input type='text' name='immunizations-note[]' value='" . attr($val['note']) . "' ></td>" .
+                                                                       "<td><select name='immunizations-sel[]'><option value='ignore' >" . xlt('Ignore') . "</option>" .
+                  "<option value='insert' >" . xlt('Insert') . "</option></select></td></tr>";
+                                                       }
+                                               ?>
+                                       </tr>
+                               </table>
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               &nbsp;
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               <u><?php echo xlt('Lab Results'); ?></u>
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               <table border="0" width="95%" >
+                                       <tr>
+                                               <?php
+                                                       $query_existing_lab_results = sqlStatement("SELECT * FROM procedure_order AS po LEFT JOIN procedure_order_code AS poc
+                                                               ON poc.procedure_order_id = po.procedure_order_id LEFT JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id
+                                                               LEFT JOIN procedure_result AS prs ON prs.procedure_report_id = pr.procedure_report_id WHERE patient_id = ?",array($_REQUEST['pid']));
+                                                       $result = array();
+                                                       while($res_existing_lab_results = sqlFetchArray($query_existing_lab_results)){
+                                                               array_push($result,$res_existing_lab_results);
+                                                       }
+                                                       $aud_res = createAuditArray($_REQUEST['amid'],'procedure_result,procedure_type');
+                                                       while($res_existing_lab_results = array_shift($result)){
+                                                               echo "<tr><td>" . xlt('Name') . "</td>" .
+                                                                       "<td>" . text($res_existing_lab_results['result_text']) . "</td>" .
+                                                                       "<td>" . xlt('Date') . "</td><td>" . text($res_existing_lab_results['date_ordered']) . "</td>" .
+                                                                       "<td>" . xlt('Result') . "</td><td>" . text($res_existing_lab_results['result']) . "</td>" .
+                                                                       "<td>" . xlt('Abnormal') . "</td><td>" . text($res_existing_lab_results['abnormal']) . "</td>" .
+                                                                       "<td>&nbsp;</td></tr>";
+                                                       }
+                                                       foreach($aud_res['procedure_result,procedure_type'] as $key=>$val){
+                                                               echo "<tr><td>" . xlt('Name') . "</td>" .
+                                                                       "<td><input type='text' name='procedure_type-name[]' value='" . attr($val['name']) . "' ></td>" .
+                                                                       "<td>" . xlt('Date') . "</td><td><input type='text' name='procedure_result-date[]' value='" . attr($val['date']) . "' ></td>" .
+                                                                       "<td>" . xlt('Result') . "</td><td><input type='text' name='procedure_result-result[]' value='" . attr($val['result']) . "' ></td>" .
+                                                                       "<td>" . xlt('Abnormal') . "</td><td><input type='text' name='procedure_result-abnormal[]' value='" . attr($val['abnormal']) . "' ></td>" .
+                                                                       "<td><select name='procedure_result-sel[]'><option value='ignore' >" . xlt('Ignore') . "</option>" .
+                  "<option value='insert' >" . xlt('Insert') . "</option></select></td></tr>";
+                                                       }
+                                               ?>
+                                       </tr>
+                               </table>
+                       </td>
+               </tr>
+               <tr>
+                       <td align="center" >
+                               <input type="button" name="approve" value="<?php echo xlt('Approve'); ?>" onclick="top.restoreSession();submit_form('approve');" >
+                               <input type="button" name="discard" value="<?php echo xlt('Discard'); ?>" onclick="top.restoreSession();submit_form('discard');" >
+        <?php
+        $aud_res = createAuditArray($_REQUEST['amid'],'documents');
+        ?>
+        <input type="hidden" name="doc_id" id="doc_id" value="<?php echo $aud_res['documents']['']['id']; ?>" >
+                               <input type="hidden" name="setval" id="setval" value="" >
+                       </td>
+               </tr>
+       </table>
+</form>
+</body>
+</html>
diff --git a/library/ajax/ccr_import_ajax.php b/library/ajax/ccr_import_ajax.php
new file mode 100644 (file)
index 0000000..78c037b
--- /dev/null
@@ -0,0 +1,203 @@
+<?php
+/**
+ * library/ccr_import_ajax.php Functions related to patient CCR/CCD/CCDA parsing.
+ *
+ * Functions related to patient CCR/CCD/CCDA parsing and insert/update to corresponding tables.
+ *
+ * Copyright (C) 2013 Z&H Consultancy Services Private Limited <sam@zhservices.com>
+ *
+ * LICENSE: This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
+ *
+ * @package OpenEMR
+ * @author  Eldho Chacko <eldho@zhservices.com>
+ * @author  Ajil P M <ajilpm@zhservices.com>
+ * @link    http://www.open-emr.org
+ */
+
+//SANITIZE ALL ESCAPES
+$sanitize_all_escapes=true;
+//
+
+//STOP FAKE REGISTER GLOBALS
+$fake_register_globals=false;
+//
+
+require_once(dirname(__FILE__) . "/../../interface/globals.php");
+require_once(dirname(__FILE__) . "/../parse_patient_xml.php");
+require_once(dirname(__FILE__) . "/../classes/Document.class.php");
+require_once(dirname(__FILE__) . "/../classes/CouchDB.class.php");
+
+if($_REQUEST["ccr_ajax"] == "yes"){
+  $doc_id = $_REQUEST["document_id"];
+  $d = new Document($doc_id);
+  $url =  $d->get_url();
+  $storagemethod = $d->get_storagemethod();
+  $couch_docid = $d->get_couch_docid();
+  $couch_revid = $d->get_couch_revid();
+  if($storagemethod == 1){
+    $couch = new CouchDB();
+    $data = array($GLOBALS['couchdb_dbase'],$couch_docid);
+    $resp = $couch->retrieve_doc($data);
+    $content = $resp->data;
+    if($content=='' && $GLOBALS['couchdb_log']==1){                            
+      $log_content = date('Y-m-d H:i:s')." ==> Retrieving document\r\n";
+      $log_content = date('Y-m-d H:i:s')." ==> URL: ".$url."\r\n";
+      $log_content .= date('Y-m-d H:i:s')." ==> CouchDB Document Id: ".$couch_docid."\r\n";
+      $log_content .= date('Y-m-d H:i:s')." ==> CouchDB Revision Id: ".$couch_revid."\r\n";
+      $log_content .= date('Y-m-d H:i:s')." ==> Failed to fetch document content from CouchDB.\r\n";
+      $log_content .= date('Y-m-d H:i:s')." ==> Will try to download file from HardDisk if exists.\r\n\r\n";
+      $this->document_upload_download_log($d->get_foreign_id(),$log_content);
+      die(xlt("File retrieval from CouchDB failed"));
+    }
+    $content = base64_decode($content);
+  }else{
+    $url = preg_replace("|^(.*)://|","",$url);
+    $from_all = explode("/",$url);
+    $from_filename = array_pop($from_all);
+    $from_pathname_array = array();
+    for ($i=0;$i<$d->get_path_depth();$i++) {
+      $from_pathname_array[] = array_pop($from_all);
+    }
+    $from_pathname_array = array_reverse($from_pathname_array);
+    $from_pathname = implode("/",$from_pathname_array);
+    $temp_url = $GLOBALS['OE_SITE_DIR'] . '/documents/' . $from_pathname . '/' . $from_filename;
+    if (!file_exists($temp_url)) {
+      echo xlt('The requested document is not present at the expected location on the filesystem or there are not sufficient permissions to access it') . '.' . $temp_url;
+    }else{
+      $content = file_get_contents($temp_url);
+    }
+  }
+  //fields to which the corresponding elements are to be inserted
+  //format - level 1 key is the main tag in the XML eg:- //Problems or //Problems/Problem according to the content in the XML.
+  //level 2 key is 'table name:field name' and level 2 value is the sub tag under the main tag given in level 1 key
+  //eg:- 'Type/Text' if the XML format is '//Problems/Problem/Type/Text' or 'id/@extension' if it is an attribute
+  //level 2 key can be 'table name:#some value' for checking whether a particular tag exits in the XML section
+  $field_mapping = array(
+    '//Problems/Problem' => array(
+      'lists1:diagnosis' => 'Description/Code/Value',
+      'lists1:comments' => 'CommentID',
+      'lists1:activity' => 'Status/Text',
+    ),
+    '//Alerts/Alert' => array(
+      'lists2:type' => 'Type/Text',
+      'lists2:diagnosis' => 'Description/Code/Value',
+      'lists2:date' => 'Agent/EnvironmentalAgents/EnvironmentalAgent/DateTime/ExactDateTime',
+      'lists2:title' => 'Agent/EnvironmentalAgents/EnvironmentalAgent/Description/Text',
+      'lists2:reaction' => 'Reaction/Description/Text',
+    ),
+    '//Medications/Medication' => array(
+      'prescriptions:date_added' => 'DateTime/ExactDateTime',
+      'prescriptions:active' => 'Status/Text',
+      'prescriptions:drug' => 'Product/ProductName/Text',
+      'prescriptions:size' => 'Product/Strength/Value',
+      'prescriptions:unit' => 'Product/Strength/Units/Unit',
+      'prescriptions:form' => 'Product/Form/Text',
+      'prescriptions:quantity' => 'Quantity/Value',
+      'prescriptions:note' => 'PatientInstructions/Instruction/Text',
+      'prescriptions:refills' => 'Refills/Refill/Number',
+    ),
+    '//Immunizations/Immunization' => array(
+      'immunizations:administered_date' => 'DateTime/ExactDateTime',
+      'immunizations:note' => 'Directions/Direction/Description/Text',
+    ),
+    '//Results/Result' => array(
+      'procedure_result:date' => 'DateTime/ExactDateTime',
+      'procedure_type:name' => 'Test/Description/Text',
+      'procedure_result:result' => 'Test/TestResult/Value',
+      'procedure_result:range' => 'Test/NormalResult/Normal/Value',
+      'procedure_result:abnormal' => 'Test/Flag/Text',
+    ),
+    '//Actors/Actor' => array(
+      'patient_data:fname' => 'Person/Name/CurrentName/Given',
+      'patient_data:lname' => 'Person/Name/CurrentName/Family',
+      'patient_data:DOB' => 'Person/DateOfBirth/ExactDateTime',
+      'patient_data:sex' => 'Person/Gender/Text',
+      'patient_data:abname' => 'InformationSystem/Name',
+      'patient_data:#Type' => 'InformationSystem/Type',
+      'patient_data:pubpid' => 'IDs/ID',
+      'patient_data:street' => 'Address/Line1',
+      'patient_data:city' => 'Address/City',
+      'patient_data:state' => 'Address/State',
+      'patient_data:postal_code' => 'Address/PostalCode',
+      'patient_data:phone_contact' => 'Telephone/Value',
+    ),
+  );
+  if(!empty($content)){
+    $var = array();
+    $res = parseXmlStream($content,$field_mapping);
+    $var = array(
+      'approval_status' => 1,
+      'type' => 11,
+      'ip_address' => $_SERVER['REMOTE_ADDR'],
+    );
+    foreach($res as $sections=>$details){
+      foreach($details as $cnt=>$vals){
+        foreach($vals as $key=>$val){
+          if(array_key_exists('#Type',$res[$sections][$cnt])){
+            if($key == 'postal_code'){
+              $var['field_name_value_array']['misc_address_book'][$cnt]['zip'] = $val;
+            }elseif($key == 'phone_contact'){
+              $var['field_name_value_array']['misc_address_book'][$cnt]['phone'] = $val;
+            }elseif($key == 'abname'){
+              $values = explode(' ',$val);
+              if($values[0]){
+                $var['field_name_value_array']['misc_address_book'][$cnt]['lname'] = $values[0];
+              }
+              if($values[1]){
+                $var['field_name_value_array']['misc_address_book'][$cnt]['fname'] = $values[1];
+              }
+            }else{
+              $var['field_name_value_array']['misc_address_book'][$cnt][$key] = $val;
+            }
+            $var['entry_identification_array']['misc_address_book'][$cnt] = $cnt;
+          }else{
+            if($sections == 'lists1' && $key == 'activity'){
+              if($val == 'Active'){
+                $val = 1;
+              }else{
+                $val = 0;
+              }
+            }
+            if($sections == 'lists2' && $key == 'type'){
+              if(strpos($val,"-")){
+                $vals = explode("-",$val);
+                $val = $vals[0];
+              }else{
+                $val = "";
+              }
+            }
+            if($sections == 'prescriptions' && $key == 'active'){
+              if($val == 'Active'){
+                $val = 1;
+              }else{
+                $val = 0;
+              }
+            }
+            $var['field_name_value_array'][$sections][$cnt][$key] = $val;
+            $var['entry_identification_array'][$sections][$cnt] = $cnt;
+          }
+        }
+        if(array_key_exists('#Type',$var['field_name_value_array']['misc_address_book'][$cnt])){
+          unset($var['field_name_value_array']['misc_address_book'][$cnt]['#Type']);
+        }
+      }
+    }
+    $var['field_name_value_array']['documents'][0]['id'] = $doc_id;
+    insert_ccr_into_audit_data($var);
+    $d->update_imported($doc_id);
+    echo xlt('Successfully Imported the details. Please approve the patient from the Pending Approval Screen').'.';
+  }else{
+    exit(xlt('Could not read the file'));
+  }
+  exit;
+}
+?>
index f449df4..e206ea4 100644 (file)
@@ -99,6 +99,12 @@ class Document extends ORDataObject{
        */
        var $list_id;
 
+  /*
+       *       Whether the file is already imported
+       *       @var int
+       */
+       var $imported;
+
        /**
         * Constructor sets all Document attributes to their default value
         * @param int $id optional existing id of a specific document, if omitted a "blank" document is created 
@@ -347,6 +353,15 @@ class Document extends ORDataObject{
     $type = sqlQuery("SELECT c.name FROM categories AS c LEFT JOIN categories_to_documents AS ctd ON c.id = ctd.category_id WHERE ctd.document_id = ?",array($doc_id));
     return $type['name'];
   }
+  function set_imported($imported) {
+               $this->imported = $imported;
+       }
+       function get_imported() {
+               return $this->imported;
+       }
+  function update_imported($doc_id) {
+               sqlQuery("UPDATE documents SET imported = 1 WHERE id = ?",array($doc_id));
+       }
        /*
        *       Overridden function to stor current object state in the db.
        *       current overide is to allow for a just in time foreign id, often this is needed 
diff --git a/library/parse_patient_xml.php b/library/parse_patient_xml.php
new file mode 100644 (file)
index 0000000..4e3bc2e
--- /dev/null
@@ -0,0 +1,296 @@
+<?php
+/**
+ * library/parse_patient_xml.php Functions related to patient CCR/CCD/CCDA parsing.
+ *
+ * Functions related to patient CCR/CCD/CCDA parsing and insert/update to corresponding tables.
+ *
+ * Copyright (C) 2013 Z&H Consultancy Services Private Limited <sam@zhservices.com>
+ *
+ * LICENSE: This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
+ *
+ * @package OpenEMR
+ * @author  Eldho Chacko <eldho@zhservices.com>
+ * @author  Ajil P M <ajilpm@zhservices.com>
+ * @link    http://www.open-emr.org
+ */
+
+//SANITIZE ALL ESCAPES
+$sanitize_all_escapes=true;
+//
+
+//STOP FAKE REGISTER GLOBALS
+$fake_register_globals=false;
+//
+
+function parseXmlStream($content,$field_mapping){
+       $res = array();
+       $xml = new DOMDocument;
+       $xml->loadXML($content);
+       $xpath = new DOMXpath($xml);
+       $rootNamespace = $xml->lookupNamespaceUri($xml->namespaceURI);
+       $xpath->registerNamespace('x',$rootNamespace);
+       foreach($field_mapping as $skey=>$sval){
+               $path = preg_replace("/\/([a-zA-Z])/","/x:$1",$skey);
+               $elements = $xpath->query($path);
+               if(!is_null($elements)){
+                       $ele_cnt = 1;
+                       foreach($elements as $element){
+                               foreach($sval as $field => $innerpath){
+                                       $ipath = preg_replace(array("/^([a-zA-Z])/","/\/([a-zA-Z])/"),array("x:$1","/x:$1"),$innerpath);
+                                       $val = $xpath->query($ipath, $element)->item(0)->textContent;
+                                       if($val){
+            $field_details = explode(':',$field);
+                                               $res[$field_details[0]][$ele_cnt][$field_details[1]] = $val;
+                                       }
+                               }
+                               $ele_cnt++;
+                       }
+               }
+       }
+       return $res;
+}
+
+function insert_ccr_into_audit_data($var){
+  $audit_master_id_to_delete = $var['audit_master_id_to_delete'];
+  $approval_status = $var['approval_status'];
+  $type = $var['type'];
+  $ip_address = $var['ip_address'];
+  $field_name_value_array = $var['field_name_value_array'];
+  $entry_identification_array = $var['entry_identification_array'];
+  if($audit_master_id_to_delete){
+    $qry = "DELETE from audit_details WHERE audit_master_id=?";
+    sqlStatement($qry,array($audit_master_id_to_delete));
+    $qry = "DELETE from audit_master WHERE id=?";
+    sqlStatement($qry,array($audit_master_id_to_delete));
+  }
+  $master_query = "INSERT INTO audit_master SET pid = ?,approval_status = ?,ip_address = ?,type = ?";
+  $audit_master_id = sqlInsert($master_query,array(0,$approval_status,$ip_address,$type));
+  $detail_query = "INSERT INTO `audit_details` (`table_name`, `field_name`, `field_value`, `audit_master_id`, `entry_identification`) VALUES ";
+  $detail_query_array = '';
+  foreach($field_name_value_array as $key=>$val){
+    foreach($field_name_value_array[$key] as $cnt=>$field_details){
+      foreach($field_details as $field_name=>$field_value){
+        $detail_query .= "(? ,? ,? ,? ,?),";
+        $detail_query_array[] = $key;
+        $detail_query_array[] = trim($field_name);
+        $detail_query_array[] = trim($field_value);
+        $detail_query_array[] = $audit_master_id;
+        $detail_query_array[] = trim($entry_identification_array[$key][$cnt]);
+      }
+    }
+  }
+  $detail_query = substr($detail_query, 0, -1);
+  $detail_query = $detail_query.';';
+  sqlInsert($detail_query,$detail_query_array);
+}
+
+function insert_patient($audit_master_id){
+       $prow = sqlQuery("SELECT IFNULL(MAX(pid)+1,1) AS pid FROM patient_data");
+       $pid = $prow['pid'];
+       $res = sqlStatement("SELECT DISTINCT ad.table_name,entry_identification FROM audit_master as am,audit_details as ad WHERE am.id=ad.audit_master_id AND am.approval_status = '1' AND am.id=? AND am.type=11 ORDER BY ad.id",array($audit_master_id));
+       $tablecnt = sqlNumRows($res);
+       while($row = sqlFetchArray($res)){
+               $resfield = sqlStatement("SELECT * FROM audit_details WHERE audit_master_id=? AND table_name=? AND entry_identification=?",array($audit_master_id,$row['table_name'],$row['entry_identification']));
+               $table = $row['table_name'];
+               $newdata = array();
+               while($rowfield = sqlFetchArray($resfield)){
+                       if($table == 'patient_data'){
+                               if($rowfield['field_name'] == 'DOB'){
+                                       $newdata['patient_data'][$rowfield['field_name']] = substr($rowfield['field_value'],0,10);
+                               }else{
+                                       $newdata['patient_data'][$rowfield['field_name']] = $rowfield['field_value'];
+                               }
+                       }elseif($table == 'lists1'){
+                               $newdata['lists1'][$rowfield['field_name']] = $rowfield['field_value'];
+                       }elseif($table == 'lists2'){
+                               $newdata['lists2'][$rowfield['field_name']] = $rowfield['field_value'];
+                       }elseif($table == 'prescriptions'){
+                               $newdata['prescriptions'][$rowfield['field_name']] = $rowfield['field_value'];
+                       }elseif($table == 'immunizations'){
+                               $newdata['immunizations'][$rowfield['field_name']] = $rowfield['field_value'];
+                       }elseif($table == 'procedure_result'){
+                               $newdata['procedure_result'][$rowfield['field_name']] = $rowfield['field_value'];
+                       }elseif($table == 'procedure_type'){
+                               $newdata['procedure_type'][$rowfield['field_name']] = $rowfield['field_value'];
+                       }elseif($table == 'misc_address_book'){
+                               $newdata['misc_address_book'][$rowfield['field_name']] = $rowfield['field_value'];
+                       }elseif($table == 'documents'){
+                               $newdata['documents'][$rowfield['field_name']] = $rowfield['field_value'];
+                       }
+               }
+               if($table == 'patient_data'){
+                       updatePatientData($pid,$newdata['patient_data'],true);
+               }elseif($table == 'lists1'){
+                       sqlInsert("INSERT INTO lists(".
+                               "pid,diagnosis,activity".
+                               ") VALUES (".
+                               "'".add_escape_custom($pid)."',".
+                               "'".add_escape_custom($newdata['lists1']['diagnosis'])."',".
+                               "'".add_escape_custom($newdata['lists1']['activity'])."')"
+                       );
+               }elseif($table == 'lists2'){
+                       sqlInsert("INSERT INTO lists(".
+                               "pid,date,type,title,diagnosis,reaction".
+                               ") VALUES (".
+                               "'".add_escape_custom($pid)."',".
+                               "'".add_escape_custom($newdata['lists2']['date'])."',".
+                               "'".add_escape_custom($newdata['lists2']['type'])."',".
+                               "'".add_escape_custom($newdata['lists2']['title'])."',".
+        "'".add_escape_custom($newdata['lists2']['diagnosis'])."',".
+                               "'".add_escape_custom($newdata['lists2']['reaction'])."')"
+                       );
+               }elseif($table == 'prescriptions'){
+                       sqlInsert("INSERT INTO prescriptions(".
+                               "patient_id,date_added,active,drug,size,form,quantity".
+                               ") VALUES (".
+                               "'".add_escape_custom($pid)."',".
+                               "'".add_escape_custom($newdata['prescriptions']['date_added'])."',".
+                               "'".add_escape_custom($newdata['prescriptions']['active'])."',".
+                               "'".add_escape_custom($newdata['prescriptions']['drug'])."',".
+                               "'".add_escape_custom($newdata['prescriptions']['size'])."',".
+                               "'".add_escape_custom($newdata['prescriptions']['form'])."',".
+                               "'".add_escape_custom($newdata['prescriptions']['quantity'])."')"
+                       );
+               }elseif($table == 'immunizations'){
+                       sqlInsert("INSERT INTO immunizations(".
+                               "patient_id,administered_date,note".
+                               ") VALUES (".
+                               "'".add_escape_custom($pid)."',".
+                               "'".add_escape_custom($newdata['immunizations']['administered_date'])."',".
+                               "'".add_escape_custom($newdata['immunizations']['note'])."')"
+                       );
+               }elseif($table == 'procedure_result'){
+                       /*sqlInsert("INSERT INTO procedure_result(".
+                               "date,result,abnormal".
+                               ") VALUES (".
+                               "'".add_escape_custom($newdata['procedure_result']['date'])."',".
+                               "'".add_escape_custom($newdata['procedure_result']['result'])."',".
+                               "'".add_escape_custom($newdata['procedure_result']['abnormal'])."')"
+                       );*/
+               }elseif($table == 'procedure_type'){
+                       /*sqlInsert("INSERT INTO procedure_type(".
+                               "name".
+                               ") VALUES (".
+                               "'".add_escape_custom($newdata['procedure_type']['name'])."')"
+                       );*/
+               }elseif($table == 'misc_address_book'){
+                       sqlInsert("INSERT INTO misc_address_book(".
+                               "lname,fname,street,city,state,zip,phone".
+                               ") VALUES (".
+                               "'".add_escape_custom($newdata['misc_address_book']['lname'])."',".
+                               "'".add_escape_custom($newdata['misc_address_book']['fname'])."',".
+                               "'".add_escape_custom($newdata['misc_address_book']['street'])."',".
+                               "'".add_escape_custom($newdata['misc_address_book']['city'])."',".
+                               "'".add_escape_custom($newdata['misc_address_book']['state'])."',".
+                               "'".add_escape_custom($newdata['misc_address_book']['zip'])."',".
+                               "'".add_escape_custom($newdata['misc_address_book']['phone'])."')"
+                       );
+               }elseif($table == 'documents'){
+                       sqlQuery("UPDATE documents SET foreign_id = ? WHERE id =? ",array($pid,$newdata['documents']['id']));
+               }
+       }
+       sqlQuery("UPDATE audit_master SET approval_status=2 WHERE id=?",array($audit_master_id));
+}
+
+function createAuditArray($am_id,$table_name){
+       if(strpos($table_name,',')){
+               $tables = explode(',',$table_name);
+               $arr = array($am_id);
+               $table_qry = "";
+               for($i=0;$i<count($tables);$i++){
+                       $table_qry .= "?,";
+                       array_unshift($arr,$tables[$i]);
+               }
+               $table_qry = substr($table_qry,0,-1);
+               $query = sqlStatement("SELECT * FROM audit_master am LEFT JOIN audit_details ad ON ad.audit_master_id = am.id AND ad.table_name IN ($table_qry) 
+               WHERE am.id = ? AND am.type = 11 AND am.approval_status = 1 ORDER BY ad.entry_identification,ad.field_name",$arr);
+       }else{
+               $query = sqlStatement("SELECT * FROM audit_master am LEFT JOIN audit_details ad ON ad.audit_master_id = am.id AND ad.table_name = ? 
+                       WHERE am.id = ? AND am.type = 11 AND am.approval_status = 1 ORDER BY ad.entry_identification,ad.field_name",array($table_name,$am_id));
+       }
+       $result = array();
+       while($res = sqlFetchArray($query)){
+               $result[$table_name][$res['entry_identification']][$res['field_name']] = $res['field_value'];
+       }
+       return $result;
+}
+
+function insertApprovedData($data){
+  $patient_data_fields = '';
+  $patient_data_values = array();
+       foreach($data as $key=>$val){
+               if(substr($key,-4) == '-sel'){
+                       if(is_array($val)){
+                               for($i=0;$i<count($val);$i++){
+                                       if($val[$i] == 'insert'){
+                                               if(substr($key,0,-4) == 'lists1'){
+                                                       if($_REQUEST['lists1-activity'][$i] == 'Active'){
+                                                               $activity = 1;
+                                                       }elseif($_REQUEST['lists1-activity'][$i] == 'Inactive'){
+                                                               $activity = 0;
+                                                       }
+              $query = "INSERT INTO lists (pid,diagnosis,activity) VALUES (?,?,?)";
+              sqlQuery($query,array($_REQUEST['pid'],$_REQUEST['lists1-diagnosis'][$i],$activity));
+                                               }elseif(substr($key,0,-4) == 'lists2'){
+              $query = "INSERT INTO lists (pid,date,type,title,diagnosis,reaction) VALUES (?,?,?,?,?,?)";
+              sqlQuery($query,array($_REQUEST['pid'],$_REQUEST['lists2-date'][$i],$_REQUEST['lists2-type'][$i],$_REQUEST['lists2-title'][$i],$_REQUEST['lists2-diagnosis'][$i],$_REQUEST['lists2-reaction'][$i]));
+                                               }elseif(substr($key,0,-4) == 'prescriptions'){
+                                                       if($_REQUEST['prescriptions-active'][$i] == 'Active'){
+                                                               $active = 1;
+                                                       }elseif($_REQUEST['prescriptions-active'][$i] == 'Inactive'){
+                                                               $active = 0;
+                                                       }
+              $query = "INSERT INTO prescriptions (patient_id,date_added,active,drug,size,form,quantity) VALUES (?,?,?,?,?,?,?)";
+              sqlQuery($query,array($_REQUEST['pid'],$_REQUEST['prescriptions-date_added'][$i],$active,$_REQUEST['prescriptions-drug'][$i],$_REQUEST['prescriptions-size'][$i],$_REQUEST['prescriptions-form'][$i],$_REQUEST['prescriptions-quantity'][$i]));
+                                               }elseif(substr($key,0,-4) == 'immunizations'){
+              $query = "INSERT INTO immunizations (patient_id,administered_date,note) VALUES (?,?,?)";
+              sqlQuery($query,array($_REQUEST['pid'],$_REQUEST['immunizations-administered_date'][$i],$_REQUEST['immunizations-note'][$i]));
+                                               }elseif(substr($key,0,-4) == 'procedure_result'){
+              //$query = "INSERT INTO procedure_type (name) VALUES (?)";
+              //sqlQuery($query,array($_REQUEST['procedure_type-name'][$i]));
+              //$query = "INSERT INTO procedure_result (date,result,abnormal) VALUES (?,?,?)";
+              //sqlQuery($query,array($_REQUEST['procedure_result-date'][$i],$active,$_REQUEST['procedure_result-abnormal'][$i]));
+                                               }
+                                       }elseif($val[$i] == 'update'){
+                                               if(substr($key,0,-4) == 'lists1'){
+                                                       if($_REQUEST['lists1-activity'][$i] == 'Active'){
+                                                               $activity = 1;
+                                                       }elseif($_REQUEST['lists1-activity'][$i] == 'Inactive'){
+                                                               $activity = 0;
+                                                       }
+              $query = "UPDATE lists SET diagnosis=?,activity=? WHERE pid=? AND diagnosis=?";
+              sqlQuery($query,array($_REQUEST['lists1-diagnosis'][$i],$activity,$_REQUEST['pid'],$_REQUEST['lists1-old-diagnosis'][$i]));
+                                               }
+                                       }
+                               }
+                       }else{
+                               if(substr($key,0,12) == 'patient_data'){
+                                       if($val == 'update'){
+                                               $var_name = substr($key,0,-4);
+                                               $field_name = substr($var_name,13);
+            $patient_data_fields .= $field_name.'=?,';
+            array_push($patient_data_values,$_REQUEST[$var_name]);
+                                       }
+                               }
+                       }
+               }
+       }
+       if(count($patient_data_values) > 0){
+    array_push($patient_data_values,$_REQUEST['pid']);
+    $patient_data_fields = substr($patient_data_fields,0,-1);
+    $query = "UPDATE patient_data SET $patient_data_fields WHERE pid=?";
+    sqlQuery($query,$patient_data_values);
+       }
+  sqlQuery("UPDATE documents SET foreign_id = ? WHERE id =? ",array($_REQUEST['pid'],$_REQUEST['doc_id']));
+}
+
+?>
index dd478e4..c561fd9 100644 (file)
@@ -476,3 +476,23 @@ ALTER TABLE `procedure_order_code`
   ADD COLUMN `do_not_send` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0 = normal, 1 = do not transmit to lab';
 #EndIf
 
+#IfNotTable misc_address_book
+CREATE TABLE `misc_address_book` (
+  `id` bigint(20) NOT NULL AUTO_INCREMENT,
+  `fname` varchar(255) DEFAULT NULL,
+  `mname` varchar(255) DEFAULT NULL,
+  `lname` varchar(255) DEFAULT NULL,
+  `street` varchar(60) DEFAULT NULL,
+  `city` varchar(30) DEFAULT NULL,
+  `state` varchar(30) DEFAULT NULL,
+  `zip` varchar(20) DEFAULT NULL,
+  `phone` varchar(30) DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB;
+#EndIf
+
+#IfMissingColumn documents imported
+ALTER TABLE `documents` ADD COLUMN `imported` TINYINT DEFAULT 0 NULL COMMENT 'Parsing status for CCR/CCD/CCDA importing';
+#EndIf
+
+
index a679b52..3d36acc 100644 (file)
@@ -672,6 +672,7 @@ CREATE TABLE `documents` (
   `couch_revid` VARCHAR(100) DEFAULT NULL,
   `storagemethod` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '0->Harddisk,1->CouchDB',
   `path_depth` TINYINT DEFAULT '1' COMMENT 'Depth of path to use in url to find document. Not applicable for CouchDB.',
+  `imported` TINYINT DEFAULT 0 NULL COMMENT 'Parsing status for CCR/CCD/CCDA importing',
   PRIMARY KEY  (`id`),
   KEY `revision` (`revision`),
   KEY `foreign_id` (`foreign_id`),
@@ -5787,3 +5788,22 @@ CREATE TABLE `product_warehouse` (
 ) ENGINE=MyISAM;
 
 -- --------------------------------------------------------
+
+--
+-- Table structure for table `misc_address_book`
+--
+
+CREATE TABLE `misc_address_book` (
+  `id` bigint(20) NOT NULL AUTO_INCREMENT,
+  `fname` varchar(255) DEFAULT NULL,
+  `mname` varchar(255) DEFAULT NULL,
+  `lname` varchar(255) DEFAULT NULL,
+  `street` varchar(60) DEFAULT NULL,
+  `city` varchar(30) DEFAULT NULL,
+  `state` varchar(30) DEFAULT NULL,
+  `zip` varchar(20) DEFAULT NULL,
+  `phone` varchar(30) DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB;
+
+-- --------------------------------------------------------
index 8c51d45..c7a7897 100644 (file)
@@ -5,6 +5,7 @@
 <script type="text/javascript" src="library/dynarch_calendar.js"></script>
 {php} include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); {/php}
 <script type="text/javascript" src="library/dynarch_calendar_setup.js"></script>
+<script type="text/javascript" src="library/js/jquery-1.9.1.min.js"></script>
 <script language="JavaScript">
  var mypcc = '{php} echo $GLOBALS['phone_country_code'] {/php}';
 
        {literal}}{/literal}
  {literal}}{/literal}
 
+ // Process click on Import link.
+ function import_ccr(docid) {literal}{
+  top.restoreSession();
+  $.ajax({
+    url: "library/ajax/ccr_import_ajax.php",
+    type: "POST",
+    dataType: "html",
+    data:
+    {
+      ccr_ajax : "yes",
+      document_id : docid,
+    },
+    success: function(data){
+      alert(data);
+      top.restoreSession();
+      document.location.reload();
+    },
+    error:function(){
+      alert("failure");
+    }
+  });
+ }{/literal}
+
+
 </script>
 
 </head>
             <a class="css_button" href="{$web_path}" onclick="top.restoreSession()"><span>{xl t='Download'}</span></a>
             <a class="css_button" href='' onclick='return showpnotes({$file->get_id()})'><span>{xl t='Show Notes'}</span></a>
             {$delete_string}
+            {if $file->get_ccr_type($file->get_id()) eq "CCR" and $file->get_mimetype($file->get_id()) eq "application/xml" and
+            $file->get_imported($file->get_id()) eq 0 }
+            <a class="css_button" href='javascript:' onclick='return import_ccr({$file->get_id()})'><span>{xl t='Import'}</span></a>
+            {/if}
         </td>
     </tr>
     <tr>
index 2c9c325..4b2bb17 100644 (file)
@@ -17,7 +17,7 @@ $v_realpatch = '0';
 // is a database change in the course of development.  It is used
 // internally to determine when a database upgrade is needed.
 //
-$v_database = 96;
+$v_database = 97;
 
 // Access control version identifier, this is to be incremented whenever there
 // is a access control change in the course of development.  It is used