2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2011 ZMG LLC <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 // Vinish K <vinish@zhservices.com>
26 // +------------------------------------------------------------------------------+
27 //SANITIZE ALL ESCAPES
28 $sanitize_all_escapes=true;
31 //STOP FAKE REGISTER GLOBALS
32 $fake_register_globals=false;
34 require_once('../globals.php');
35 require_once('../eRx_xml.php');
36 require_once('../../library/xmltoarray_parser_htmlfix.php');
37 require_once("{$GLOBALS['srcdir']}/lists.inc");
41 if($_REQUEST['patient'])
42 $patientid=$_REQUEST['patient'];
43 $cred=getErxCredentials();
44 $path = getErxSoapPath();
45 $path = explode(';',$path);
46 $client = new SoapClient($path[0]);
47 $xml1_0['credentials']['PartnerName']=$cred['0'];
48 $xml1_0['credentials']['Name']=$cred['1'];
49 $xml1_0['credentials']['Password']=$cred['2'];
51 $erxSiteID=sqlQuery("SELECT federal_ein FROM facility WHERE primary_business_entity='1'");
52 $account=sqlQuery("SELECT * FROM users AS u LEFT JOIN facility AS f ON f.id=u.facility_id WHERE u.username=?",array($_SESSION['authUser']));
53 $xml1_0['accountRequest']['AccountId']='1';
54 $xml1_0['accountRequest']['SiteId']=$erxSiteID['federal_ein'];
56 $xml1_0['patientRequest']['PatientId']=$patientid;
58 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
59 $xml1_0['patientInformationRequester']['UserType']='D';
60 $xml1_0['patientInformationRequester']['UserId']=$user_details['id'];
62 $xml = $client->GetPatientAllergyHistoryV3($xml1_0);
64 $xml_response=$xml->GetPatientAllergyHistoryV3Result
->XmlResponse
;
65 $xml_response_count=$xml->GetPatientAllergyHistoryV3Result
->RowCount
;
66 $xml_response = base64_decode($xml_response);
68 $xmltoarray = new xmltoarray_parser_htmlfix(); //create instance of class
69 $xmltoarray->xmlparser_setoption(XML_OPTION_SKIP_WHITE
, 1); //set options same as xml_parser_set_option
70 $xmltoarray->xmlparser_setoption(XML_OPTION_CASE_FOLDING
, 0);
71 $xmltoarray->xmlparser_fix_into_struct($xml_response); //fixes html values for XML
72 $array = $xmltoarray->createArray(); //creates an array with fixed html values
73 foreach($array as $key => $value){
74 $array[$key] = $xmltoarray->fix_html_entities($value); //returns proper html values
76 $allergyArray=$array['NewDataSet']['Table'];
80 for($i=0;$i<sizeof($allergyArray);$i++
)
82 $qoutcome=sqlStatement("SELECT option_id FROM list_options WHERE list_id='outcome' AND title = ?",array($allergyArray[$i]['AllergySeverityName']));
83 $routcome=sqlFetchArray($qoutcome);
84 if(!$routcome['option_id'])
86 $routcome=sqlQuery("SELECT option_id AS option_id FROM list_options WHERE list_id='outcome' ORDER BY ABS(option_id) DESC LIMIT 1");
87 sqlQuery("INSERT INTO list_options (list_id,option_id,title,seq) VALUES ('outcome',?,?,?)",array(($routcome['option_id']+
1),$allergyArray[$i]['AllergySeverityName'],($routcome['option_id']+
1)));
88 $routcome['option_id']=$routcome['option_id']+
1;
90 $res=sqlStatement("select * from lists where pid=? and type='allergy' and title=? and (enddate is null or enddate = '' or enddate = '0000-00-00')",array($patientid,$allergyArray[$i]['AllergyName']));
91 $row=sqlFetchArray($res);
92 if(sqlNumRows($res)==0)
94 sqlQuery("insert into lists (date,type,title,pid,user,outcome,external_allergyid,erx_source,begdate) values (NOW(),'allergy',?,?,?,?,?,'1',now())",
95 array($allergyArray[$i]['AllergyName'], $patientid, $_SESSION['authUserID'], $routcome['option_id'], $allergyArray[$i]['AllergyId']));
96 setListTouch ($patientid,'allergy');
99 elseif($row['erx_source']==0)
101 sqlQuery("update lists set outcome=?, erx_source='1', external_allergyid=? where pid=? and title=?",
102 array($routcome['option_id'], $allergyArray[$i]['AllergyId'], $patientid, $allergyArray[$i]['AllergyName']));
106 sqlQuery("update lists set outcome=? where pid=? and erx_source='1' and external_allergyid=? and title=?",
107 array($routcome['option_id'], $patientid, $allergyArray[$i]['AllergyId'], $allergyArray[$i]['AllergyName']));
109 //sqlQuery("update lists set enddate = null where type='allergy' and pid=? and title=?",array($patientid,$allergyArray[$i]['AllergyName']));
111 $res=sqlStatement("select id,title from lists where pid=? and type='allergy' and erx_source='1' and (enddate is null or enddate = '' or enddate = '0000-00-00')",array($patientid));
112 while($row=sqlFetchArray($res))
115 for($i=0;$i<sizeof($allergyArray);$i++
){
116 if($allergyArray[$i]['AllergyName']==$row['title'])
123 sqlQuery("update lists set enddate=now() where pid=? and id=? and type='allergy'",array($patientid,$row['id']));
127 $xml1_0['credentials']['PartnerName']=$cred['0'];
128 $xml1_0['credentials']['Name']=$cred['1'];
129 $xml1_0['credentials']['Password']=$cred['2'];
131 $xml1_0['accountRequest']['AccountId']='1';
132 $xml1_0['accountRequest']['SiteId']=$erxSiteID['federal_ein'];
134 $xml1_0['patientRequest']['PatientId']=$patientid;
136 $xml1_0['patientInformationRequester']['UserType']='D';
137 $xml1_0['patientInformationRequester']['UserId']=$user_details['id'];
139 $xml = $client->GetPatientFreeFormAllergyHistory($xml1_0);
140 $xml_response=$xml->GetPatientFreeFormAllergyHistoryResult
->patientFreeFormAllergyExtendedDetail
->PatientFreeFormAllergyExtendedDetail
;
141 $xml_response_count=$xml->GetPatientFreeFormAllergyHistoryResult
->result
->RowCount
;
142 if($xml_response_count>1){
143 for($i=0;$i<sizeof($xml_response);$i++
)
145 sqlQuery("update lists set erx_uploaded='0' where id=?",array($xml_response[$i]->ExternalId
));
148 elseif($xml_response_count==1){
149 sqlQuery("update lists set erx_uploaded='0' where id=?",array($xml_response->ExternalId
));
153 sqlQuery("update patient_data set soap_import_status=? where pid=?",array('4',$patientid));
154 if($xml_response_count==0)
155 echo htmlspecialchars( xl("Nothing to import for Allergy"), ENT_NOQUOTES
);
156 elseif($xml_response_count>0)
157 echo htmlspecialchars( xl("Allergy import successfully completed"), ENT_NOQUOTES
);