2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2011 Z&H Consultancy Services Private Limited <sam@zhservices.com>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Jacob T Paul <jacob@zhservices.com>
25 // Vinish K <vinish@zhservices.com>
27 // +------------------------------------------------------------------------------+
35 require_once("../../interface/globals.php");
36 require_once(dirname(__FILE__
)."/../../controllers/C_Document.class.php");
37 require_once(dirname(__FILE__
)."/../../library/options.inc.php");
38 require_once(dirname(__FILE__
) . "/../../library/log.inc");
39 require_once(dirname(__FILE__
) . "/../../library/patient.inc");
40 require_once(dirname(__FILE__
) . "/../../library/direct_message_check.inc");
43 if (!extension_loaded("soap")) {
47 require_once("server_med_rec.php");
48 require_once("factory_class.php");
49 class UserService
extends Userforms
53 * To display the result/report names from lists
55 public function get_display_field($data)
57 if ($this->valid($data[0])) {
58 $ret = generate_display_field(array('data_type'=>$data['data_type'],'list_id'=>$data['list_id']), $data['value']);
64 * To display the procedure order results
66 public function procedure_order($data)
68 if ($this->valid($data[0])) {
73 po.procedure_order_id, po.date_ordered, pc.procedure_order_seq,
74 pt1.procedure_type_id AS order_type_id, pc.procedure_name,
75 pr.procedure_report_id, pr.date_report, pr.date_collected,
76 pr.specimen_num, pr.report_status, pr.review_status
79 JOIN procedure_order_code AS pc
80 ON pc.procedure_order_id = po.procedure_order_id
81 LEFT JOIN procedure_type AS pt1
82 ON pt1.lab_id = po.lab_id
83 AND pt1.procedure_code = pc.procedure_code
84 LEFT JOIN procedure_report AS pr
85 ON pr.procedure_order_id = po.procedure_order_id
86 AND pr.procedure_order_seq = pc.procedure_order_seq
87 WHERE po.patient_id = ?
88 AND pr.review_status = 'reviewed'
89 ORDER BY po.date_ordered, po.procedure_order_id, pc.procedure_order_seq, pr.procedure_report_id";
90 $proc_result = sqlStatement($proc_query, array($pid));
91 while ($row = sqlFetchArray($proc_result)) {
92 $procedure_report_id = empty($row['procedure_report_id']) ?
'' : $row['procedure_report_id'];
93 $order_type_id = empty($row['order_type_id']) ?
'' : $row['order_type_id'];
95 $proc_order_query = "(SELECT
96 pt2.procedure_type, pt2.procedure_code, pt2.units AS pt2_units,
97 pt2.range AS pt2_range, pt2.procedure_type_id AS procedure_type_id,
98 pt2.name AS NAME, pt2.description, pt2.seq AS seq,
99 ps.procedure_result_id, ps.result_code AS result_code,
100 ps.result_text, ps.abnormal, ps.result,
101 ps.range, ps.result_status, ps.facility,
102 ps.comments, ps.units, ps.comments
104 procedure_type AS pt2
105 LEFT JOIN procedure_result AS ps
106 ON ps.procedure_report_id = ?
107 AND ps.result_code = pt2.procedure_code
109 AND ( pt2.procedure_type LIKE 'res%' OR pt2.procedure_type LIKE 'rec%' ))
112 pt2.procedure_type, pt2.procedure_code, pt2.units AS pt2_units,
113 pt2.range AS pt2_range, pt2.procedure_type_id AS procedure_type_id,
114 pt2.name AS NAME, pt2.description, pt2.seq AS seq,
115 ps.procedure_result_id, ps.result_code AS result_code,
116 ps.result_text, ps.abnormal, ps.result,
117 ps.range, ps.result_status, ps.facility,
118 ps.comments, ps.units, ps.comments
120 procedure_result AS ps
121 LEFT JOIN procedure_type AS pt2
123 AND ( pt2.procedure_type LIKE 'res%' OR pt2.procedure_type LIKE 'rec%' )
124 AND ps.result_code = pt2.procedure_code
125 WHERE ps.procedure_report_id = ?)
126 ORDER BY seq, NAME, procedure_type_id,result_code";
127 $proc_order_result = sqlStatement($proc_order_query, array($procedure_report_id,$order_type_id,$order_type_id,$procedure_report_id));
129 while ($rrow = sqlFetchArray($proc_order_result)) {
130 $arr[$i]['procedure_report_id'] = empty($row['procedure_report_id']) ?
'' : $row['procedure_report_id'] ;
131 $arr[$i]['date_ordered'] = empty($row['date_ordered']) ?
'' : $row['date_ordered'];
132 $arr[$i]['procedure_name'] = empty($row['procedure_name']) ?
'' : $row['procedure_name'];
133 $arr[$i]['result_text'] = empty($rrow['result_text']) ?
'' : $rrow['result_text'];
134 $arr[$i]['abnormal'] = empty($rrow['abnormal']) ?
'' : $rrow['abnormal'];
135 $arr[$i]['result'] = empty($rrow['result']) ?
'' : $rrow['result'];
136 $arr[$i]['range'] = empty($rrow['range']) ?
'' : $rrow['range'];
137 $arr[$i]['units'] = empty($rrow['units']) ?
'' : $rrow['units'];
138 $arr[$i]['result_status'] = empty($rrow['result_status']) ?
'' : $rrow['result_status'];
139 $arr[$i]['report_status'] = empty($row['report_status']) ?
'' : $row['report_status'];
149 * To display the patient uploaded files/pdf patient wise
151 public function patientuploadedfiles($data)
153 if ($this->valid($data[0])) {
159 ad.field_value AS doc_name,
163 ad2.field_value AS file_name,
164 ad3.field_value AS pat_comments
167 JOIN audit_master AS am
168 ON am.id = ad.audit_master_id
169 LEFT JOIN patient_data AS pd
171 JOIN audit_details AS ad2
172 ON am.id = ad2.audit_master_id
173 AND ad2.field_name = 'dlm_filename'
174 JOIN audit_details AS ad3
175 ON am.id = ad3.audit_master_id
176 AND ad3.field_name = 'dld_patient_comments'
177 WHERE ad.field_name = 'dlm_document_name'
178 AND approval_status = '1'
182 if (!empty($data[1])) {
183 $query .= " AND am.id = ?";
184 $res = sqlStatement($query, array($data[1]));
186 $res = sqlStatement($query);
190 for ($iter=0; $row=sqlFetchArray($res); $iter++
) {
200 public function createandstoretodirectory($data)
203 if ($this->valid($data[0])) {
206 $savedpath=$GLOBALS['OE_SITE_DIR']."/documents/myportal/patientuploads/".$pid;
207 if (is_dir($savedpath)) {
209 mkdir($savedpath, 0777, true);
210 chmod($savedpath, 0777);
213 $handler = fopen($savedpath."/".$file_name, "w");
214 fwrite($handler, base64_decode($data));
216 chmod($savedpath."/".$file_name, 0777);
218 throw new SoapFault("Server", "credentials failed");
223 * To move category,rename filename,input note and to move to new patient#
225 public function documents_update($data)
227 if ($this->valid($data[0])) {
228 $_POST['process'] = true;
229 $_POST['new_category_id'] = $data[1];
230 $_POST['new_patient_id'] = $data[4];
233 $file_path = $GLOBALS['OE_SITE_DIR']."/documents/myportal/unsigned/".$data[6];
234 } elseif ($data[9] == 1) {
235 $file_path = $GLOBALS['OE_SITE_DIR']."/documents/myportal/signed/".$data[6];
236 } elseif ($data[9] == 4) {
237 $file_path = $GLOBALS['OE_SITE_DIR']."/documents/myportal/patientuploads/".$data[5]."/".$data[6];
241 "pdf"=>"application/pdf"
242 ,"exe"=>"application/octet-stream"
243 ,"zip"=>"application/zip"
244 ,"docx"=>"application/msword"
245 ,"doc"=>"application/msword"
246 ,"xls"=>"application/vnd.ms-excel"
247 ,"ppt"=>"application/vnd.ms-powerpoint"
253 ,"wav"=>"audio/x-wav"
254 ,"mpeg"=>"video/mpeg"
257 ,"mov"=>"video/quicktime"
258 ,"avi"=>"video/x-msvideo"
261 ,"jsc"=>"application/javascript"
262 ,"js"=>"application/javascript"
268 $extension = strtolower(end(explode('.', $file_path)));
269 $mime_types = $mime_types[$extension];
270 $_FILES['file']['name'][0] = $data[6];
271 $_FILES['file']['type'][0] = $mime_types;
272 $_FILES['file']['tmp_name'][0] = $file_path;
273 $_FILES['file']['error'][0] = 0;
274 $_FILES['file']['size'][0] = filesize($file_path);
275 $_POST['category_id'] = $_POST['new_category_id'];
276 $_POST['patient_id'] = $_POST['new_patient_id'];
277 $_GET['patient_id'] = $_POST['patient_id'];
278 $_POST['destination'] = $data[3];
280 $cdoc = new C_Document();
281 $cdoc->upload_action_process();
282 if ($GLOBALS['document_storage_method']==0) {
284 copy($file_path, $cdoc->file_path
.$data[3]);
286 copy($file_path, $cdoc->file_path
.$data[6]);
290 $foreign_id = sqlQuery("select id from documents where foreign_id = ? order by id desc limit 1", array($_POST['new_patient_id']));
292 $_POST['encrypted'] = '';
293 $_POST['passphrase'] = '';
294 $_POST['process'] = true;
295 $_POST['foreign_id'] = $foreign_id['id'];
296 $_POST['note'] = $data[7];
297 $cdoc->note_action_process($_GET['patient_id']);
298 $sql_patient_no = "UPDATE documents_legal_detail SET dld_moved = '1' WHERE dld_master_docid = ? AND dld_id = ?";
299 sqlQuery($sql_patient_no, array($data[2],$data[8]));
305 * To display the files/pdfforms patient wise
307 public function userslistportal($data)
309 if ($this->valid($data[0])) {
315 dlm.dlm_document_name,
321 dld.dld_master_docid,
323 dld.dld_patient_comments,
329 documents_legal_master AS dlm
330 LEFT OUTER JOIN documents_legal_detail AS dld
331 ON dlm.dlm_document_id = dld_master_docid
332 JOIN patient_data AS pd
333 ON dld.dld_pid = pd.pid
334 WHERE dlm.dlm_effective_date <= NOW()
335 AND dlm.dlm_effective_date <> '0000-00-00 00:00:00'
336 AND dld.dld_id IS NOT NULL
337 AND dld.dld_signed IN (1,2,4)
338 AND dld.dld_moved = 0
339 AND dlm_subcategory NOT IN
344 documents_legal_categories
346 dlc_category_name = 'Layout Signed'
347 AND dlc_category_type = 2
349 ORDER BY dld.dld_pid ASC ";
351 $res = sqlStatement($query);
353 for ($iter=0; $row=sqlFetchArray($res); $iter++
) {
364 * To display the category list in Move To Category option
366 public function category_list($data)
368 if ($this->valid($data[0])) {
370 $query = "SELECT * FROM categories";
371 $res = sqlStatement($query);
373 for ($iter=0; $row=sqlFetchArray($res); $iter++
) {
383 //Converts a text to xml format.Format is as follows
384 public function text_to_xml($data)
386 if ($this->valid($data[0])) {
388 $doc = new DOMDocument();
389 $doc->formatOutput
= true;
391 $root = $doc->createElement("root");
392 $doc->appendChild($root);
394 $level = $doc->createElement("level");
395 $root->appendChild($level);
397 $element = $doc->createElement("text");
398 $element->appendChild(
399 $doc->createTextNode($text)
401 $level->appendChild($element);
402 return $doc->saveXML();
404 throw new SoapFault("Server", "credentials failed");
408 //Accepts an array and returns the result in xml format.Format is as follows
411 public function function_return_to_xml($var = array())
414 $doc = new DOMDocument();
415 $doc->formatOutput
= true;
417 $root = $doc->createElement("root");
418 $doc->appendChild($root);
421 $level = $doc->createElement("level");
422 $root->appendChild($level);
423 foreach ($var as $key => $value) {
424 $element = $doc->createElement("$key");
425 $element->appendChild(
426 $doc->createTextNode($value)
428 $level->appendChild($element);
431 return $doc->saveXML();
434 //When a filled PDf is rejected During audit , the file is deleted
437 public function delete_file($data)
439 if ($this->valid($data[0])) {
440 $file_name_with_path=$data[1];
441 @unlink
($file_name_with_path);
443 throw new SoapFault("Server", "credentials failed");
448 //Accepts a file path.Fetches the file in xml format.
449 //Transfer the file to portal in XML format
450 public function file_to_xml($data)
452 if ($this->valid($data[0])) {
453 $file_name_with_path=$data[1];
454 $path_parts = pathinfo($file_name_with_path);
455 $handler = fopen($file_name_with_path, "rb");
456 $returnData = fread($handler, filesize($file_name_with_path));
458 $doc = new DOMDocument();
459 $doc->formatOutput
= true;
461 $root = $doc->createElement("root");
462 $doc->appendChild($root);
464 $level = $doc->createElement("level");
465 $root->appendChild($level);
467 $filename = $doc->createElement("name");
468 $filename->appendChild(
469 $doc->createTextNode($path_parts['basename'])
471 $level->appendChild($filename);
473 $type = $doc->createElement("type");
475 $doc->createTextNode($path_parts['extension'])
477 $level->appendChild($type);
478 $content = $doc->createElement("file");
479 $content->appendChild(
480 $doc->createTextNode(base64_encode($returnData))
482 $level->appendChild($content);
483 return $doc->saveXML();
485 throw new SoapFault("Server", "credentials failed");
490 //File teceived from the portal side is saved to OpenEMR
492 public function store_to_file($data)
494 if ($this->valid($data[0])) {
495 $file_name_with_path=$data[1];
497 $savedpath=$GLOBALS['OE_SITE_DIR']."/documents/myportal/";
498 if (is_dir($savedpath)) {
500 mkdir($savedpath, 0777);
501 chmod($savedpath, 0777);
504 $savedpath=$GLOBALS['OE_SITE_DIR']."/documents/myportal/unsigned/";
505 if (is_dir($savedpath)) {
507 mkdir($savedpath, 0777);
508 chmod($savedpath, 0777);
511 $savedpath=$GLOBALS['OE_SITE_DIR']."/documents/myportal/signed/";
512 if (is_dir($savedpath)) {
514 mkdir($savedpath, 0777);
515 chmod($savedpath, 0777);
518 $savedpath=$GLOBALS['OE_SITE_DIR']."/documents/myportal/upload/";
519 if (is_dir($savedpath)) {
521 mkdir($savedpath, 0777);
522 chmod($savedpath, 0777);
525 $handler = fopen($file_name_with_path, "w");
526 fwrite($handler, base64_decode($data));
528 chmod($file_name_with_path, 0777);
530 throw new SoapFault("Server", "credentials failed");
535 //receive a batch of function calls received from Portal, execute it and return the results to the portal
536 //The results will be stored in the key, which is received from portal.
539 public static function batch_despatch($var, $func, $data_credentials)
542 if (UserService
::valid($data_credentials)) {
543 require_once("../../library/invoice_summary.inc.php");
544 require_once("../../library/options.inc.php");
545 require_once("../../library/acl.inc");
546 require_once("../../library/patient.inc");
547 if ($func=='ar_responsible_party') {
549 $encounter_id=$var['encounter'];
550 $x['ar_responsible_party']=ar_responsible_party($patient_id, $encounter_id);
551 return UserService
::function_return_to_xml($x);
552 } elseif ($func=='getInsuranceData') {
554 $given=$var['given'];
555 $x=getInsuranceData($pid, $type, $given);
556 return UserService
::function_return_to_xml($x);
557 } elseif ($func=='generate_select_list') {
558 $tag_name=$var['tag_name'];
559 $list_id=$var['list_id'];
560 $currvalue=$var['currvalue'];
561 $title=$var['title'];
562 $empty_name=$var['empty_name'];
563 $class=$var['class'];
564 $onchange=$var['onchange'];
565 $x['generate_select_list']=generate_select_list($tag_name, $list_id, $currvalue, $title, $empty_name, $class, $onchange);
566 return UserService
::function_return_to_xml($x);
567 } elseif ($func=='xl_layout_label') {
568 $constant=$var['constant'];
569 $x['xl_layout_label']=xl_layout_label($constant);
570 return UserService
::function_return_to_xml($x);
571 } elseif ($func=='generate_form_field') {
573 $currvalue=$var['currvalue'];
575 generate_form_field($frow, $currvalue);
576 $x['generate_form_field']=ob_get_contents();
578 return UserService
::function_return_to_xml($x);
579 } elseif ($func=='getInsuranceProviders') {
581 $provider=$var['provider'];
582 $insurancei=getInsuranceProviders();
585 } elseif ($func=='get_layout_form_value') {
587 $_POST=$var['post_array'];
588 $x['get_layout_form_value']=get_layout_form_value($frow);
589 return UserService
::function_return_to_xml($x);
590 } elseif ($func=='updatePatientData') {
591 $patient_data=$var['patient_data'];
592 $create=$var['create'];
593 updatePatientData($pid, $patient_data, $create);
595 return UserService
::function_return_to_xml($x);
596 } elseif ($func=='updateEmployerData') {
597 $employer_data=$var['employer_data'];
598 $create=$var['create'];
599 updateEmployerData($pid, $employer_data, $create);
601 return UserService
::function_return_to_xml($x);
602 } elseif ($func=='newHistoryData') {
603 newHistoryData($pid);
605 return UserService
::function_return_to_xml($x);
606 } elseif ($func=='newInsuranceData') {
608 foreach ($var as $key => $value) {
609 if ($key>=3) {//first 3 need to be skipped.
610 $var[$key]=formData($value);
614 $parameters[$key]=$var[$key];
618 $parameters[12]=fixDate($parameters[12]);
619 $parameters[27]=fixDate($parameters[27]);
620 call_user_func_array('newInsuranceData', $parameters);
622 return UserService
::function_return_to_xml($x);
623 } elseif ($func=='generate_layout_validation') {
624 $form_id=$var['form_id'];
626 generate_layout_validation($form_id);
631 throw new SoapFault("Server", "credentials failed");
635 //Writing patient credentials to table
636 public function insert_login_details($var)
639 $data_credentials=$var[0];
640 if (UserService
::valid($data_credentials)) {
641 $username=$var['username'];
642 $authPass=$var['authPass'];
643 $query="insert into patient_access_offsite(pid,portal_username,portal_pwd) values (?,?,?)";
644 sqlInsert($query, array($pid,$username,$authPass));
646 throw new SoapFault("Server", "credentials failed");
652 //Updating the password on a password change
654 public function update_password($var)
656 $data_credentials=$var[0];
657 global $pid,$auditmasterid;
658 if (UserService
::valid($data_credentials)=='existingpatient' || UserService
::valid($data_credentials)=='newpatient') {
659 $status = $var['new_pwd_status'];
660 $pwd=$var['new_pwd'];
661 $oldpwd = $var['old_pwd'];
666 $where = "portal_pwd_status=? and pid=?";
667 $set= "portal_pwd=?,portal_pwd_status=?";
673 $set= "portal_pwd=? ";
679 $qry = "select * from patient_access_offsite WHERE pid=? AND portal_pwd=?";
680 $res=sqlStatement($qry, array($pid,$oldpwd));
681 if (sqlNumRows($res)>0) {
682 $qry = "UPDATE patient_access_offsite SET $set WHERE $where";
683 sqlStatement($qry, $setarray);
688 } elseif (UserService
::valid($data_credentials) == 'newpatienttoapprove') {
689 $pwd=$var['new_pwd'];
690 $oldpwd = $var['old_pwd'];
691 $qry = "SELECT * from audit_details WHERE audit_master_id = ? AND table_name = 'patient_access_offsite' AND field_name = 'portal_pwd' AND field_value = ?";
692 $res=sqlStatement($qry, array($auditmasterid,$oldpwd));
693 if (sqlNumRows($res)>0) {
694 $qry = "UPDATE audit_details SET field_value = ? WHERE audit_master_id = ? AND table_name = 'patient_access_offsite' AND field_name = 'portal_pwd'";
695 sqlStatement($qry, array($pwd,$auditmasterid));
701 throw new SoapFault("Server", "credentials failed");
708 public function update_openemr_appointment($var)
710 $data_credentials=$var[0];
711 if (UserService
::valid($data_credentials)=='existingpatient' || UserService
::valid($data_credentials)=='newpatient') {
712 foreach ($var[1] as $key => $value) {
713 $eid=explode('_', $var[1][$key]);
714 if ($eid[0]=='calendar') {
715 sqlQuery("update openemr_postcalendar_events set pc_apptstatus='x' where pc_eid=?", array($eid[1]));
716 } elseif ($eid[0]=='audit') {
717 sqlQuery("update audit_master set approval_status='5' where id=?", array($eid[1]));
721 throw new SoapFault("Server", "credentials failed");
726 //Marking the Documents as ready to be signed
728 public function update_dlm_dld($var)
730 $data_credentials=$var[0];
731 if (UserService
::valid($data_credentials)) {
732 $qry=" UPDATE documents_legal_detail set dld_signed=2 where dld_id=?";
733 sqlStatement($qry, array($var['dld_id']));
735 throw new SoapFault("Server", "credentials failed");
740 //Setting PDF documets approve /denial status
742 public function update_dld_approve_deny($data)
744 if ($this->valid($data[0])) {
745 if (substr($data[1][2], 0, 3) == 'am-') {
746 $audid = substr($data[1][2], 3);
747 $status = sqlQuery("SELECT
749 ad.field_value AS uname,
750 CONCAT(ad4.field_value,' ',ad5.field_value,' ',ad6.field_value) AS name
753 JOIN audit_details ad
754 ON ad.audit_master_id = am.id
755 AND ad.table_name = 'patient_access_offsite'
756 AND ad.field_name = 'portal_username'
757 JOIN audit_details ad2
758 ON ad2.table_name = 'patient_access_offsite'
759 AND ad2.field_name = 'portal_username'
760 AND ad2.field_value = ad.field_value
761 JOIN audit_details ad3
762 ON ad3.table_name = 'patient_access_offsite'
763 AND ad3.field_name = 'portal_pwd'
764 AND ad3.audit_master_id = ad2.audit_master_id
765 JOIN audit_details ad4
766 ON ad4.table_name = 'patient_data'
767 AND ad4.field_name = 'fname'
768 AND ad4.audit_master_id = ad2.audit_master_id
769 JOIN audit_details ad5
770 ON ad5.table_name = 'patient_data'
771 AND ad5.field_name = 'mname'
772 AND ad5.audit_master_id = ad2.audit_master_id
773 JOIN audit_details ad6
774 ON ad6.table_name = 'patient_data'
775 AND ad6.field_name = 'lname'
776 AND ad6.audit_master_id = ad2.audit_master_id
777 JOIN audit_master am2
778 ON am2.id = ad3.audit_master_id
780 WHERE am.id = ?", array($audid));
781 if ($status['approval_status'] == '2') {
782 $result = UserService
::update_audited_data(array($data[0],'audit_master_id' => $audid));
783 UserService
::update_audit_master(array($data[0],'audit_master_id' => $audid,'approval_status' => '2'));
784 $pid = sqlQuery("SELECT pid FROM patient_access_offsite WHERE portal_username=?", array($status['uname']));
785 $qry = "UPDATE documents_legal_detail SET dld_pid=?,dld_signed=?,dld_denial_reason=? WHERE dld_id=?";
786 sqlStatement($qry, array($pid['pid'],$data[1][0],$data[1][1],$result['dld_id']));
788 return "Please approve the patient ".$status['name'].", for approving the selected document";
791 $qry = "UPDATE documents_legal_detail SET dld_signed=?,dld_denial_reason=? WHERE dld_id=?";
792 sqlStatement($qry, $data[1]);
795 throw new SoapFault("Server", "credentials failed");
799 //Marking PDF documets as signed
801 public function update_dld_signed($data)
803 if ($this->valid($data[0])) {
804 $qry = "UPDATE documents_legal_detail SET dld_signed=1,dld_filepath=?,dld_filename=? WHERE dld_id=?";
805 sqlStatement($qry, $data[1]);
807 throw new SoapFault("Server", "credentials failed");
811 //Marking PDF documets for audit.
813 public function update_dld_pending($data)
815 if ($this->valid($data[0])) {
816 $qry = "UPDATE documents_legal_detail SET dld_signed=0,dld_filepath=?,dld_filename=?, dld_file_for_pdf_generation=? WHERE dld_id=?";
817 sqlStatement($qry, $data[1]);
819 throw new SoapFault("Server", "credentials failed");
825 public function insert_dld($data)
827 global $pid,$auditmasterid;
828 if (UserService
::valid($data[0])=='existingpatient' || UserService
::valid($data[0])=='newpatient') {
829 sqlInsert("INSERT INTO documents_legal_detail (dld_pid,dld_signed,dld_filepath,dld_master_docid,dld_filename,dld_encounter,dld_file_for_pdf_generation) ".
830 " VALUES (?,?,?,?,?,?,?)", array($pid,$data[2],$data[3],$data[4],$data[5],$data[6],$data[7]));
831 } elseif (UserService
::valid($data[0])=='newpatienttoapprove') {
832 $param=array($data[0],'audit_master_id_to_delete'=>"",'pid'=>"$pid",'approval_status'=>'1',
833 'type'=>'3','ip_address'=>'',
834 'table_name_array'=>array('documents_legal_detail','patient_access_offsite'),
835 'field_name_value_array'=>array(array('dld_pid'=>"$pid",'dld_signed'=>$data[2],'dld_filepath'=>$data[3],'dld_master_docid'=>$data[4],'dld_filename'=>$data[5],'dld_encounter'=>$data[6],'dld_file_for_pdf_generation'=>$data[7]),
836 array('pid'=>"$pid",'portal_username'=>$data[0][6])),
837 'entry_identification_array'=>array(1,1),
839 UserService
::insert_to_be_audit_data($param);
841 throw new SoapFault("Server", "credentials failed");
846 //Inserting the entries for Master PDF documents uploaded
848 public function insert_dlm($data)
850 if ($this->valid($data[0])=='oemruser') {
851 sqlStatement("INSERT INTO documents_legal_master(dlm_category, dlm_subcategory,dlm_document_name,dlm_facility,dlm_provider,
852 dlm_filename,dlm_filepath,dlm_effective_date,content) values (?,?,?,?,?,?,?,?,?)", array($data[1],$data[2],$data[3],$data[4],$data[5],$data[6],$data[7],$data[8],$data[9]));
854 throw new SoapFault("Server", "credentials failed");
859 //REceive an array of Select cases from portal execute it and return
860 // it in the keys received from portal. A batch of queries execute and returns it in one batch.
862 public function batch_select($data)
864 if ($this->valid($data[0])) {
866 foreach ($batch as $key => $value) {
867 $batchkey=$value['batchkey'];
868 $case=$value['case'];
869 $param=$value['param'];
872 $return_array[$batchkey]=$this->selectquery(array($data[0],$arrproc));
876 return $return_array;
878 throw new SoapFault("Server", "credentials failed");
883 //Receive a batch of function calls from portal and execute it through batch despatch Function
884 //Any OpenEmr function can be executed this way, if necessary if clause is written in batch_despatch.
886 public function batch_function($data)
888 if ($this->valid($data[0])) {
890 foreach ($batch as $key => $value) {
891 $batchkey=$value['batchkey'];
892 $function=$value['funcname'];
893 $param=$value['param'];
895 $res=call_user_func_array("UserService::$function", $param);
896 $return_array[$batchkey]=$res;
899 return $return_array;
901 throw new SoapFault("Server", "credentials failed");
905 //Execute a batch of functions received from portal. But this function is limited to
906 // the functions written in the myportal module.
908 public function multiplecall($data)
911 foreach ($batch as $key => $value) {
912 $batchkey=$value['batchkey'];
913 $function=$value['funcname'];
914 $param=$value['param'];
915 if (is_array($param)) {
916 array_unshift($param, $data[0]);
921 $res= UserService
::$function($param);
922 $return_array[$batchkey]=$res;
925 return $return_array;
931 public function getversion($data)
933 global $v_offsite_portal;
934 return $v_offsite_portal;
938 public function loginchecking($data)
940 if ($this->valid($data[0])=='existingpatient' ||
$this->valid($data[0])=='newpatient') {
941 $res = sqlStatement("SELECT portal_pwd_status, 'yes' AS patient_status, portal_relation FROM patient_access_offsite WHERE BINARY portal_username=? AND BINARY portal_pwd=?", $data[1]);
942 return $this->resourcetoxml($res);
943 } elseif ($this->valid($data[0])=='newpatienttoapprove') {
944 $res = sqlStatement("
946 COUNT(*) AS portal_pwd_status,
947 'no' AS patient_status
950 JOIN audit_details ad
951 ON ad.audit_master_id = am.id
952 AND ad.table_name = 'patient_access_offsite'
953 AND ad.field_name = 'portal_username'
954 JOIN audit_details ad2
955 ON ad2.audit_master_id = am.id
956 AND ad2.table_name = 'patient_access_offsite'
957 AND ad2.field_name = 'portal_pwd'
958 WHERE am.approval_status = 1
959 AND ad.field_value = ?
960 AND ad2.field_value = ?;
962 return $this->resourcetoxml($res);
968 //Execute a query and return its results.
970 public function selectquery($data)
974 $utype = $this->valid($data[0]);
976 $newobj = factoryclass
::dynamic_class_factory($utype);
977 $sql_result_setarr = $newobj->query_formation($data[1]);
978 if (!empty($sql_result_setarr[1]) && $sql_result_setarr[1] == 'result') {
979 return $this->resourcetoxml2($sql_result_setarr[0]);
982 $sql_result_set = sqlStatement($sql_result_setarr[0], $sql_result_setarr[1]);
983 return $this->resourcetoxml($sql_result_set);
987 //Return an SQL resultset as an XML
990 public function resourcetoxml($sql_result_set)
992 $doc = new DOMDocument();
993 $doc->formatOutput
= true;
995 $root = $doc->createElement("root");
996 $doc->appendChild($root);
997 while ($row = sqlFetchArray($sql_result_set)) {
998 $level = $doc->createElement("level");
999 $root->appendChild($level);
1000 foreach ($row as $key => $value) {
1001 $element = $doc->createElement("$key");
1002 $element->appendChild(
1003 $doc->createTextNode($value)
1005 $level->appendChild($element);
1009 return $doc->saveXML();
1012 public function resourcetoxml2($row)
1014 $doc = new DOMDocument();
1015 $doc->formatOutput
= true;
1016 $root = $doc->createElement("root");
1017 $doc->appendChild($root);
1018 $level = $doc->createElement("level");
1019 $root->appendChild($level);
1020 foreach ($row as $key => $value) {
1021 $element = $doc->createElement("$key");
1022 $element->appendChild(
1023 $doc->createTextNode($value)
1025 $level->appendChild($element);
1028 return $doc->saveXML();
1031 //Writing facility payment configuration to table
1032 public function save_payment_configuration($var)
1034 $data_credentials=$var[0];
1035 if (UserService
::valid($data_credentials)) {
1036 if ($var['service'] == 'paypal') {
1037 if ($var['paypal'] != '') {
1038 $update_sql = "UPDATE payment_gateway_details SET login_id = ? WHERE service_name = 'paypal'";
1039 sqlStatement($update_sql, array($var['login_id']));
1041 $save_sql = "INSERT INTO payment_gateway_details (service_name,login_id) VALUES (?,?)";
1042 sqlStatement($save_sql, array($var['service'],$var['login_id']));
1044 } elseif ($var['service'] == 'authorize_net') {
1045 if ($var['authorize_net'] != '') {
1046 $update_sql = "UPDATE payment_gateway_details SET login_id = ?, transaction_key = ?, md5= ? WHERE service_name = 'authorize_net'";
1047 sqlStatement($update_sql, array($var['login_id'],$var['transaction_key'],$var['md5']));
1049 $save_sql = "INSERT INTO payment_gateway_details (service_name,login_id,transaction_key,md5) VALUES (?,?,?,?)";
1050 sqlStatement($save_sql, array($var['service'],$var['login_id'],$var['transaction_key'],$var['md5']));
1054 throw new SoapFault("Server", "credentials failed");
1058 //Writing patient's authorizenet profile id to table
1059 public function insert_authorizenet_details($var)
1062 $data_credentials=$var[0];
1063 if (UserService
::valid($data_credentials)) {
1064 $authorizenetid=$var['authorizenetid'];
1065 $query="UPDATE patient_access_offsite SET authorize_net_id = ? WHERE pid = ?";
1066 sqlInsert($query, array($authorizenetid,$pid));
1068 throw new SoapFault("Server", "credentials failed");
1072 public function valid($credentials)
1074 $timminus = date("Y-m-d H:m", (strtotime(date("Y-m-d H:m"))-7200)).":00";
1075 sqlStatement("DELETE FROM audit_details WHERE audit_master_id IN(SELECT id FROM audit_master WHERE type=5 AND created_time<=?)", array($timminus));
1076 sqlStatement("DELETE FROM audit_master WHERE type=5 AND created_time<=?", array($timminus));
1083 $tim = strtotime(gmdate("Y-m-d H:m"));
1084 $res = sqlStatement("SELECT * FROM audit_details WHERE field_value=?", array($credentials[3]));
1085 if (sqlNumRows($res)) {
1086 if ($GLOBALS['validated_offsite_portal'] !=true) {
1090 $grpID = sqlInsert("INSERT INTO audit_master SET type=5");
1091 sqlStatement("INSERT INTO audit_details SET field_value=? , audit_master_id=? ", array($credentials[3],$grpID));
1094 if (sha1($GLOBALS['portal_offsite_password'].date("Y-m-d H", $tim).$credentials[3])==$credentials[2]) {
1096 } elseif (sha1($GLOBALS['portal_offsite_password'].date("Y-m-d H", ($tim-3600)).$credentials[3])==$credentials[2]) {
1098 } elseif (sha1($GLOBALS['portal_offsite_password'].date("Y-m-d H", ($tim+
3600)).$credentials[3])==$credentials[2]) {
1102 if (($credentials[1]==$GLOBALS['portal_offsite_username'] && $ok==1 && $GLOBALS['portal_offsite_enable']==1)||
$GLOBALS['validated_offsite_portal']==true) {
1103 $prow = sqlQuery("SELECT * FROM patient_access_offsite WHERE portal_username=?", array($credentials[6]));
1104 if ($credentials[4] == 'existingpatient') {
1105 if (UserService
::validcredential($credentials) === 2) {
1107 } elseif (UserService
::validcredential($credentials) == true) {
1112 } elseif ($credentials[4] == 'oemruser') {
1113 if ($credentials[9]) {
1114 $prow = sqlQuery("SELECT pid FROM audit_master WHERE id=?", array($credentials[9]));
1118 } elseif ($credentials[4] == 'newpatient') {
1119 if (UserService
::validcredential($credentials) === 2) {
1121 } elseif (UserService
::validcredential($credentials)) {
1125 $prow = sqlQuery("SELECT IFNULL(MAX(pid)+1,1) AS pid FROM patient_data");
1129 if ($okE==1 ||
$okN == 2 ||
$okN == 1 ||
$okO == 1) {
1130 $pid = $prow['pid'];
1131 $GLOBALS['pid'] = $prow['pid'];
1132 } elseif ($okE == 2 ||
$okN == 3) {
1138 JOIN audit_details ad2
1139 ON ad2.audit_master_id = ad.audit_master_id
1140 AND ad2.table_name = 'patient_access_offsite'
1141 AND ad2.field_name = 'portal_pwd'
1142 WHERE ad.table_name = 'patient_access_offsite'
1143 AND ad.field_name = 'portal_username'
1144 AND ad.field_value = ?
1145 ", array($credentials[6]));
1146 $auditmasterid = $arow['audit_master_id'];
1147 $GLOBALS['auditmasterid'] = $arow['audit_master_id'];
1149 $GLOBALS['pid'] = 0;
1152 $_GET['site'] = $credentials[0];
1155 $portal = sqlQuery("SELECT allow_patient_portal FROM patient_data WHERE pid=?", array($pid));
1156 } elseif ($okE == 2) {
1157 $portal = sqlQuery("
1159 IF(COUNT(*),'yes','no') AS allow_patient_portal
1162 JOIN audit_details ad
1163 ON ad.audit_master_id = am.id
1164 AND ad.table_name = 'patient_access_offsite'
1165 AND ad.field_name = 'portal_username'
1166 WHERE am.approval_status = 1
1167 AND ad.field_value = ?
1168 ", array($credentials[6]));
1171 if (strtolower($portal['allow_patient_portal'])!='yes') {
1176 $GLOBALS['validated_offsite_portal'] = true;
1179 } elseif ($okE == 1) {
1180 return 'existingpatient';
1181 } elseif ($okE == 2) {
1182 return 'newpatienttoapprove';
1183 } elseif ($okN == 1 ||
$okN == 2) {
1184 return 'newpatient';
1185 } elseif ($okN == 3) {
1186 return 'newpatienttoapprove';
1198 public function validcredential($credentials)
1200 $tim = strtotime(gmdate("Y-m-d H:m"));
1201 if ($credentials[6]) {
1202 $prow = sqlQuery("SELECT * FROM patient_access_offsite WHERE portal_username=?", array($credentials[6]));
1203 $newpatient_to_approve = 0;
1204 if (!$prow['portal_pwd']) {
1205 $newpatient_to_approve = 1;
1208 ad2.field_value AS portal_pwd
1211 JOIN audit_details ad
1212 ON ad.audit_master_id = am.id
1213 AND ad.table_name = 'patient_access_offsite'
1214 AND ad.field_name = 'portal_username'
1215 JOIN audit_details ad2
1216 ON ad2.audit_master_id = am.id
1217 AND ad2.table_name = 'patient_access_offsite'
1218 AND ad2.field_name = 'portal_pwd'
1219 WHERE am.approval_status = 1
1220 AND ad.field_value = ?
1221 ", array($credentials[6]));
1224 if (sha1($prow['portal_pwd'].date("Y-m-d H", $tim).$credentials[8])==$credentials[7]) {
1225 if ($newpatient_to_approve) {
1230 } elseif (sha1($prow['portal_pwd'].date("Y-m-d H", ($tim-3600)).$credentials[8])==$credentials[7]) {
1231 if ($newpatient_to_approve) {
1236 } elseif (sha1($prow['portal_pwd'].date("Y-m-d H", ($tim+
3600)).$credentials[8])==$credentials[7]) {
1237 if ($newpatient_to_approve) {
1249 //for checking the connection
1253 public function check_connection($data)
1255 if ($this->valid($data[0])) {
1263 * Checks whether a module is installed or not
1264 * @param type $parameter_array
1267 public function checkModuleInstalled($parameter_array = array())
1269 if ($this->valid($parameter_array[0])) {
1270 $module_name = isset($parameter_array[1]) ?
$parameter_array[1] : '';
1271 $sql = "SELECT mod_id FROM modules WHERE mod_name = ? AND mod_active = '1'";
1272 $res = sqlStatement($sql, array($module_name));
1273 $row = sqlFetchArray($res);
1274 return !empty($row);
1281 * Soap function to add direct address
1285 public function addDirectAddress($data)
1287 if ($this->valid($data[0])=='existingpatient') {
1288 $qry = "SELECT email FROM users WHERE LOWER(email) = ?";
1289 $res=sqlStatement($qry, array(strtolower($data['direct_address_string'])));
1290 if (!(sqlNumRows($res) > 0)) {
1291 sqlStatement("INSERT INTO users SET fname=? , mname=?, lname = ?, email = ?, active = ?, abook_type = ? ", array($data['first_name'],$data['middle_name'], $data['middle_name'], $data['direct_address_string'], 1, 'emr_direct'));
1292 $status = 'insert-success';
1294 $status = 'duplicate-address';
1297 $status = 'auth-failed';
1300 return '<!--?xml version="1.0"?-->
1303 <status>' . $status . '</status>
1309 * Soap function to edit direct address
1311 public function updateDirectAddress($data)
1313 if ($this->valid($data[0])=='existingpatient') {
1314 $qry = "SELECT email FROM users WHERE LOWER(email) = ? AND id <> ?";
1315 $res=sqlStatement($qry, array($data['direct_address_string'], $data['id']));
1317 if (!(sqlNumRows($res) > 0)) {
1318 sqlStatement("UPDATE users SET fname=? , mname=?, lname = ?, email = ? WHERE id = ?", array($data['first_name'],$data['middle_name'], $data['middle_name'], $data['direct_address_string'], $data['id']));
1319 $status = 'insert-success';
1321 $status = 'duplicate-address';
1324 $status = 'auth-failed';
1327 return '<!--?xml version="1.0"?-->
1330 <status>' . $status . '</status>
1337 * Soap function to get direct address details
1339 public function getDirectAddressDetails($data)
1341 if ($this->valid($data[0])=='existingpatient') {
1342 $qry = "SELECT fname, mname, lname,email,id FROM users WHERE id = ?";
1344 $res=sqlStatement($qry, array($data['id']));
1345 if (sqlNumRows($res)>0) {
1346 return $this->resourcetoxml($res);
1348 $status = 'invalid-id';
1351 $status = 'auth-failed';
1354 return '<!--?xml version="1.0"?-->
1357 <status>' . $status . '</status>
1363 * Soap function to get list of direct address
1365 public function getDirectAddressList($data)
1367 $fh12 = fopen(sys_get_temp_dir() . '/scriptLog2.txt', 'a');
1368 fwrite($fh12, 'getDirectAddressList' . print_r($data, 1) . PHP_EOL
);
1372 if ($this->valid($data[0])=='existingpatient') {
1373 $qry = "SELECT fname, mname, lname,email,id FROM users WHERE abook_type = ?";
1374 $res=sqlStatement($qry, array('emr_direct'));
1375 if (sqlNumRows($res)>0) {
1376 return $this->resourcetoxml($res);
1378 $status = 'empty-records';
1381 $status = 'auth-failed';
1384 return '<!--?xml version="1.0"?-->
1387 <status>' . $status . '</status>
1392 $server = new SoapServer(null, array('uri' => "urn://portal/res"));
1393 $server->setClass('UserService');
1394 $server->setPersistence(SOAP_PERSISTENCE_SESSION
);