From 3186ab8e802abc1b9291b0b9f323f9e1b349e856 Mon Sep 17 00:00:00 2001 From: "Ajil P.M" Date: Mon, 29 Jul 2013 18:27:20 +0530 Subject: [PATCH] CCR Import, made changes per comments in github. Signed-off-by: Ajil P.M Minor mods by brady to place it into 4.1.2 release. --- ccr/display.php | 52 ++- interface/main/left_nav.php | 6 + interface/patient_file/ccr_import.php | 66 ++++ interface/patient_file/ccr_pending_approval.php | 210 +++++++++++ interface/patient_file/ccr_review_approve.php | 456 ++++++++++++++++++++++++ library/ajax/ccr_import_ajax.php | 203 +++++++++++ library/classes/Document.class.php | 15 + library/parse_patient_xml.php | 296 +++++++++++++++ sql/4_1_1-to-4_1_2_upgrade.sql | 20 ++ sql/database.sql | 20 ++ templates/documents/general_view.html | 29 ++ version.php | 2 +- 12 files changed, 1359 insertions(+), 16 deletions(-) create mode 100644 interface/patient_file/ccr_import.php create mode 100644 interface/patient_file/ccr_pending_approval.php create mode 100644 interface/patient_file/ccr_review_approve.php create mode 100644 library/ajax/ccr_import_ajax.php create mode 100644 library/parse_patient_xml.php diff --git a/ccr/display.php b/ccr/display.php index d66827f0a..89b5c4c8a 100644 --- a/ccr/display.php +++ b/ccr/display.php @@ -1,31 +1,54 @@ 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; - } } ?> diff --git a/interface/main/left_nav.php b/interface/main/left_nav.php index aa399c694..eb4167484 100644 --- a/interface/main/left_nav.php +++ b/interface/main/left_nav.php @@ -1192,6 +1192,12 @@ if (!empty($reg)) { ?> + diff --git a/interface/patient_file/ccr_import.php b/interface/patient_file/ccr_import.php new file mode 100644 index 000000000..53c3f5b89 --- /dev/null +++ b/interface/patient_file/ccr_import.php @@ -0,0 +1,66 @@ + + * + * 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 ;. + * + * @package OpenEMR + * @author Eldho Chacko + * @author Ajil P M + * @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"); + +?> + + +<?php echo xlt('Import');?> + + + +
+

+ + + + + + + + + + + + + + + + + +
1.Documents. For CCR document of a new patient use Miscellanous->New Documents screen').'.'; ?>
2.
3.
4.Import->Pending Approval').'.'; ?>
+
+ + + diff --git a/interface/patient_file/ccr_pending_approval.php b/interface/patient_file/ccr_pending_approval.php new file mode 100644 index 000000000..c71b6641a --- /dev/null +++ b/interface/patient_file/ccr_pending_approval.php @@ -0,0 +1,210 @@ + + * + * 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 ;. + * + * @package OpenEMR + * @author Eldho Chacko + * @author Ajil P M + * @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']); +?> + + + <?php echo xlt('CCR Approve');?> + + + +
+ + + + + +<?php echo xlt('Pending Approval');?> + + + + + +
+

+
+
+
+ + + + + + + 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'])); + ?> + + + 0){ + $dup_res = sqlFetchArray($dup_query); + ?> + + + + + + + + + + + + +
+ + + + + +
+ + + + + + + + + +
+ +
+
+
+ + diff --git a/interface/patient_file/ccr_review_approve.php b/interface/patient_file/ccr_review_approve.php new file mode 100644 index 000000000..ce86df109 --- /dev/null +++ b/interface/patient_file/ccr_review_approve.php @@ -0,0 +1,456 @@ + + * + * 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 ;. + * + * @package OpenEMR + * @author Eldho Chacko + * @author Ajil P M + * @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'])); + ?> + + + <?php echo xlt('CCR Review and Approve');?> + + + +
+ + + + + + <?php echo xlt('CCR Review and Approve');?> + + + +
+ + + + + +<?php echo xlt('CCR Review and Approve');?> + + + + + +
+

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + " . ($patient_data[$res_pd['field_name']] ? text($patient_data[$res_pd['field_name']]): text($res_pd['field_name'])) . "" . + "" . + ""; + }else{ + echo "" . + "" . + ""; + } + if($i%2 == 0){ + if($i%4 == 2){ + echo ""; + }else{ + echo ""; + } + }else{ + echo ""; + } + } + } + ?> + +
" . + "" . text($query_oldpd['val']) . "" . ($patient_data[$res_pd['field_name']] ? text($patient_data[$res_pd['field_name']]): text($res_pd['field_name'])) . "" . + "" . text($query_oldpd['val']) . "
   
+
+   +
+ +
+ + + $v){ + $cnt++; + if($cnt%2 == 0){ + $class = 'alternate'; + }else{ + $class = ''; + } + if(in_array($res_existing_prob['diagnosis'],$aud_res['lists1'][$k])){ + $set = 1; + echo "" . + "" . + "" . + "" . + "" . + "" . + "" . + ""; + unset($aud_res['lists1'][$k]); + } + } + if($set == 0){ + echo "" . + "" . + ""; + } + echo ""; + } + foreach($aud_res['lists1'] as $key=>$val){ + if($val['activity'] == 1){ + $activity = 'Active'; + }else{ + $activity = 'Inactive'; + } + echo "" . + "" . + "" . + ""; + } + ?> + +
" . xlt('Title') . "" . xlt('Code') . "" . + "" . xlt('Status') . "
 " . text($res_existing_prob['title']) . " " . text($res_existing_prob['diagnosis']) . " " . xlt($activity) . "
" . xlt('Title') . "" . text($res_existing_prob['title']) . "" . xlt('Code') . "" . text($res_existing_prob['diagnosis']) . "" . xlt('Status') . "" . xlt($activity) . " 
" . xlt('Title') . "" . xlt('Code') . "" . xlt('Status') . "
+
+   +
+ +
+ + + " . + "" . + "" . + ""; + } + foreach($aud_res['lists2'] as $key=>$val){ + if($val['activity'] == 1){ + $activity = 'Active'; + }else{ + $activity = 'Inactive'; + } + echo "" . + "" . + "" . + "" . + "" . + ""; + } + ?> + +
" . xlt('Title') . "" . text($res_existing_alerts['title']) . "" . xlt('Date Time') . "" . text($res_existing_alerts['date']) . "" . xlt('Diagnosis') . "" . text($res_existing_alerts['diagnosis']) . "" . xlt('Reaction') . "" . text($res_existing_alerts['reaction']) . " 
" . xlt('Title') . "" . xlt('Date Time') . "" . xlt('Diagnosis') . "" . xlt('Reaction') . "
+
+   +
+ +
+ + + " . + "" . + "" . + "" . + "" . + ""; + } + foreach($aud_res['prescriptions'] as $key=>$val){ + if($val['active'] == 1){ + $activity = 'Active'; + }else{ + $activity = 'Inactive'; + } + echo "" . + "" . + "" . + "" . + "" . + ""; + } + ?> + +
" . xlt('Name') . "" . text($res_existing_medications['drug']) . "" . xlt('Date') . "" . text($res_existing_medications['date_added']) . "" . xlt('Status') . "" . xlt($activity) . " 
" . xlt('Form') . "" . text($res_existing_medications['form'])."   " . xlt('Strength') . "   " . text($res_existing_medications['size']) . "" . xlt('Quantity')."" . text($res_existing_medications['quantity']) . "" . xlt('Refills') . "" . text($res_existing_medications['refills']) . "
" . xlt('Name') . "" . xlt('Date') . "" . xlt('Status') . "" . + "
" . xlt('Form') . "" . + "   " . xlt('Strength') . "   " . xlt('Quantity') . "" . xlt('Refills') . "
+
+   +
+ +
+ + + " . + "" . + "" . + ""; + } + foreach($aud_res['immunizations'] as $key=>$val){ + echo "" . + "" . + "" . + ""; + } + ?> + +
" . xlt('Administered Date') . "" . text($res_existing_immunizations['administered_date']) . "" . xlt('Note') . "" . text($res_existing_immunizations['note']) . " 
" . xlt('Administered Date') . "" . xlt('Note') . "
+
+   +
+ +
+ + + " . + "" . + "" . + "" . + "" . + ""; + } + foreach($aud_res['procedure_result,procedure_type'] as $key=>$val){ + echo "" . + "" . + "" . + "" . + "" . + ""; + } + ?> + +
" . xlt('Name') . "" . text($res_existing_lab_results['result_text']) . "" . xlt('Date') . "" . text($res_existing_lab_results['date_ordered']) . "" . xlt('Result') . "" . text($res_existing_lab_results['result']) . "" . xlt('Abnormal') . "" . text($res_existing_lab_results['abnormal']) . " 
" . xlt('Name') . "" . xlt('Date') . "" . xlt('Result') . "" . xlt('Abnormal') . "
+
+ + + + + +
+
+ + diff --git a/library/ajax/ccr_import_ajax.php b/library/ajax/ccr_import_ajax.php new file mode 100644 index 000000000..78c037b4b --- /dev/null +++ b/library/ajax/ccr_import_ajax.php @@ -0,0 +1,203 @@ + + * + * 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 ;. + * + * @package OpenEMR + * @author Eldho Chacko + * @author Ajil P M + * @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; +} +?> diff --git a/library/classes/Document.class.php b/library/classes/Document.class.php index f449df4fd..e206ea4d6 100644 --- a/library/classes/Document.class.php +++ b/library/classes/Document.class.php @@ -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 index 000000000..4e3bc2eca --- /dev/null +++ b/library/parse_patient_xml.php @@ -0,0 +1,296 @@ + + * + * 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 ;. + * + * @package OpenEMR + * @author Eldho Chacko + * @author Ajil P M + * @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$val){ + if(substr($key,-4) == '-sel'){ + if(is_array($val)){ + for($i=0;$i 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'])); +} + +?> diff --git a/sql/4_1_1-to-4_1_2_upgrade.sql b/sql/4_1_1-to-4_1_2_upgrade.sql index dd478e4b3..c561fd967 100644 --- a/sql/4_1_1-to-4_1_2_upgrade.sql +++ b/sql/4_1_1-to-4_1_2_upgrade.sql @@ -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 + + diff --git a/sql/database.sql b/sql/database.sql index a679b5204..3d36acc34 100644 --- a/sql/database.sql +++ b/sql/database.sql @@ -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; + +-- -------------------------------------------------------- diff --git a/templates/documents/general_view.html b/templates/documents/general_view.html index 8c51d45dc..c7a7897fa 100644 --- a/templates/documents/general_view.html +++ b/templates/documents/general_view.html @@ -5,6 +5,7 @@ {php} include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); {/php} + @@ -49,6 +74,10 @@ {xl t='Download'} {xl t='Show Notes'} {$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 } + {xl t='Import'} + {/if} diff --git a/version.php b/version.php index 2c9c325bc..4b2bb17c2 100644 --- a/version.php +++ b/version.php @@ -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 -- 2.11.4.GIT