PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/myportal/soap_service/server_med_rec.php

http://openemr.codeplex.com
PHP | 432 lines | 372 code | 28 blank | 32 comment | 37 complexity | 0df2235be3c8a1b47e8cd733547aef34 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, LGPL-3.0, BSD-3-Clause, GPL-2.0, MPL-2.0, GPL-3.0
  1. <?php
  2. // +-----------------------------------------------------------------------------+
  3. // Copyright (C) 2011 Z&H Consultancy Services Private Limited <sam@zhservices.com>
  4. //
  5. //
  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.
  10. //
  11. //
  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.
  16. //
  17. //
  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.
  22. //
  23. // Author: Eldho Chacko <eldho@zhservices.com>
  24. // Jacob T Paul <jacob@zhservices.com>
  25. //
  26. // +------------------------------------------------------------------------------+
  27. //SANITIZE ALL ESCAPES
  28. $sanitize_all_escapes=true;
  29. //
  30. //STOP FAKE REGISTER GLOBALS
  31. $fake_register_globals=false;
  32. //
  33. require_once("server_audit.php");
  34. class Userforms extends UserAudit{
  35. public function issue_type($data){
  36. if(UserService::valid($data[0])=='existingpatient'){
  37. global $ISSUE_TYPES;
  38. require_once("../../library/lists.inc");
  39. return $ISSUE_TYPES;
  40. }
  41. else{
  42. throw new SoapFault("Server", "credentials failed");
  43. }
  44. }
  45. public function print_report($data){
  46. global $pid;
  47. if(UserService::valid($data[0])=='existingpatient'){
  48. $repArr = $data[1];
  49. $type = $data[3];
  50. global $ISSUE_TYPES;
  51. require_once("../../library/forms.inc");
  52. require_once("../../library/billing.inc");
  53. require_once("../../library/pnotes.inc");
  54. require_once("../../library/patient.inc");
  55. require_once("../../library/options.inc.php");
  56. require_once("../../library/acl.inc");
  57. require_once("../../library/lists.inc");
  58. require_once("../../library/report.inc");
  59. require_once("../../library/classes/Document.class.php");
  60. require_once("../../library/classes/Note.class.php");
  61. require_once("../../library/formatting.inc.php");
  62. require_once("../../custom/code_types.inc.php");
  63. foreach($repArr as $value){
  64. ob_start();
  65. if($type=="profile"){
  66. $this->getIncudes($value);
  67. $out .= ob_get_clean();
  68. }
  69. else{
  70. if($type=='issue')
  71. $this->getIid($value);
  72. if($type=='forms')
  73. $this->getforms($value);
  74. $out .= ob_get_clean();
  75. }
  76. }
  77. return $out;
  78. }
  79. else{
  80. throw new SoapFault("Server", "credentials failed");
  81. }
  82. }
  83. public function print_ccr_report($data){
  84. if(UserService::valid($data[0])=='existingpatient'){
  85. $ccraction = $data[1];
  86. $raw = $data[2];
  87. require_once("../../ccr/createCCR.php");
  88. ob_start();
  89. createCCR($ccraction,$raw);
  90. $html = ob_get_clean();
  91. if($ccraction=='viewccd')
  92. {
  93. $html = preg_replace('/<!DOCTYPE html PUBLIC "-\/\/W3C\/\/DTD HTML 4.01\/\/EN" "http:\/\/www.w3.org\/TR\/html4\/strict.dtd">/','',$html);
  94. $pos1 = strpos($html,'body {');
  95. $pos2 = strpos($html,'.h1center');
  96. $tes = substr("$html",$pos1,($pos2-$pos1));
  97. $html = str_replace($tes,'',$html);
  98. $html = str_replace('h3>','h2>',$html);
  99. $html = base64_encode($html);
  100. }
  101. else{
  102. $pos1 = strpos($html,'*{');
  103. $pos2 = strpos($html,'h1');
  104. $tes = substr("$html",$pos1,($pos2-$pos1));
  105. $html = str_replace($tes,'',$html);
  106. }
  107. return $html;
  108. }
  109. else{
  110. throw new SoapFault("Server", "credentials failed");
  111. }
  112. }
  113. //Return the forms requested from Portal.
  114. private function getforms($fId){
  115. global $pid;
  116. $GLOBALS['pid'] = $pid;
  117. $inclookupres = sqlStatement("SELECT DISTINCT formdir FROM forms WHERE pid = ? AND deleted=0",array($pid));
  118. while($result = sqlFetchArray($inclookupres)) {
  119. $formdir = $result['formdir'];
  120. if (substr($formdir,0,3) == 'LBF')
  121. include_once($GLOBALS['incdir'] . "/forms/LBF/report.php");
  122. else
  123. include_once($GLOBALS['incdir'] . "/forms/$formdir/report.php");
  124. }
  125. $N = 6;
  126. $inclookupres = sqlStatement("SELECT encounter,form_id,formdir,id FROM forms WHERE pid = ? AND deleted=0
  127. AND id =? ",array($pid,$fId));
  128. while($result = sqlFetchArray($inclookupres)) {
  129. $form_encounter=$result['encounter'];
  130. $form_id=$result['form_id'];
  131. $formdir = $result['formdir'];
  132. $id=$result['id'];
  133. ob_start();
  134. if (substr($formdir,0,3) == 'LBF')
  135. call_user_func("lbf_report", $pid, $form_encounter, $N, $form_id, $formdir);
  136. else
  137. call_user_func($formdir . "_report", $pid, $form_encounter, $N, $form_id);
  138. $out=ob_get_clean();
  139. ?> <table>
  140. <tr class=text>
  141. <th><?php echo htmlspecialchars($formdir,ENT_QUOTES);?></th>
  142. </tr>
  143. </table>
  144. <?php echo $out;?>
  145. <?php
  146. }
  147. }
  148. private function getIid($val){
  149. global $pid;
  150. global $ISSUE_TYPES;
  151. $inclookupres = sqlStatement("SELECT DISTINCT formdir FROM forms WHERE pid = ? AND deleted=?",array($pid,0));
  152. while($result = sqlFetchArray($inclookupres)) {
  153. $formdir = $result['formdir'];
  154. if (substr($formdir,0,3) == 'LBF')
  155. include_once($GLOBALS['incdir'] . "/forms/LBF/report.php");
  156. else
  157. include_once($GLOBALS['incdir'] . "/forms/$formdir/report.php");
  158. }
  159. ?>
  160. <tr class=text>
  161. <td></td>
  162. <td>
  163. <?php
  164. $irow = sqlQuery("SELECT type, title, comments, diagnosis FROM lists WHERE id =? ",array($val));
  165. $diagnosis = $irow['diagnosis'];
  166. if ($prevIssueType != $irow['type'])
  167. {
  168. $disptype = $ISSUE_TYPES[$irow['type']][0];
  169. ?>
  170. <div class='issue_type' style='font-weight: bold;'><?php echo htmlspecialchars($disptype,ENT_QUOTES);?>:</div>
  171. <?php
  172. $prevIssueType = $irow['type'];
  173. }
  174. ?>
  175. <div class='text issue'>
  176. <span class='issue_title'><?php echo htmlspecialchars($irow['title'],ENT_QUOTES);?>:</span>
  177. <span class='issue_comments'><?php echo htmlspecialchars($irow['comments'],ENT_QUOTES);?></span>
  178. <?php
  179. if ($diagnosis)
  180. {
  181. ?>
  182. <div class='text issue_diag'>
  183. <span class='bold'>[<?php echo htmlspecialchars(xl('Diagnosis'),ENT_QUOTES);?>]</span><br>
  184. <?php
  185. $dcodes = explode(";", $diagnosis);
  186. foreach ($dcodes as $dcode)
  187. {
  188. ?>
  189. <span class='italic'><?php echo htmlspecialchars($dcode,ENT_QUOTES);?></span>:
  190. <?php
  191. echo htmlspecialchars(lookup_code_descriptions($dcode),ENT_QUOTES);
  192. ?>
  193. <br>
  194. <?php
  195. }
  196. ?>
  197. </div>
  198. <?php
  199. }
  200. if ($irow['type'] == 'ippf_gcac')
  201. {
  202. ?>
  203. <table>
  204. <?php
  205. display_layout_rows('GCA', sqlQuery("SELECT * FROM lists_ippf_gcac WHERE id = ?",array($rowid)));
  206. ?>
  207. </table>
  208. <?php
  209. }
  210. else if ($irow['type'] == 'contraceptive')
  211. {
  212. ?>
  213. <table>
  214. <?php
  215. display_layout_rows('CON', sqlQuery("SELECT * FROM lists_ippf_con WHERE id = ?",array($rowid)));
  216. ?>
  217. </table>
  218. <?php
  219. }
  220. ?>
  221. </div>
  222. <?php
  223. ?>
  224. </td>
  225. <?php
  226. }
  227. private function getIncudes($val){
  228. global $pid;
  229. if ($val == "demographics")
  230. {
  231. ?>
  232. <hr />
  233. <div class='text demographics' id='DEM'>
  234. <?php
  235. // printRecDataOne($patient_data_array, getRecPatientData ($pid), $N);
  236. $result1 = getPatientData($pid);
  237. $result2 = getEmployerData($pid);
  238. ?>
  239. <table>
  240. <tr><td><h6><?php echo htmlspecialchars(xl('Patient Data').":",ENT_QUOTES);?></h6></td></tr>
  241. <?php
  242. display_layout_rows('DEM', $result1, $result2);
  243. ?>
  244. </table>
  245. </div>
  246. <?php
  247. }
  248. elseif ($val == "history")
  249. {
  250. ?>
  251. <hr />
  252. <div class='text history' id='HIS'>
  253. <?php
  254. $result1 = getHistoryData($pid);
  255. ?>
  256. <table>
  257. <tr><td><h6><?php echo htmlspecialchars(xl('History Data').":",ENT_QUOTES);?></h6></td></tr>
  258. <?php
  259. display_layout_rows('HIS', $result1);
  260. ?>
  261. </table>
  262. </div>
  263. <?php
  264. }
  265. elseif ($val == "insurance")
  266. {
  267. ?>
  268. <hr />
  269. <div class='text insurance'>";
  270. <h6><?php echo htmlspecialchars(xl('Insurance Data').":",ENT_QUOTES);?></h6>
  271. <br><span class=bold><?php echo htmlspecialchars(xl('Primary Insurance Data').":",ENT_QUOTES);?></span><br>
  272. <?php
  273. printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"primary"), $N);
  274. ?>
  275. <span class=bold><?php echo htmlspecialchars(xl('Secondary Insurance Data').":",ENT_QUOTES);?></span><br>
  276. <?php
  277. printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"secondary"), $N);
  278. ?>
  279. <span class=bold><?php echo htmlspecialchars(xl('Tertiary Insurance Data').":",ENT_QUOTES);?></span><br>
  280. <?php
  281. printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"tertiary"), $N);
  282. ?>
  283. </div>
  284. <?php
  285. }
  286. elseif ($val == "billing")
  287. {
  288. ?>
  289. <hr />
  290. <div class='text billing'>
  291. <h6><?php echo htmlspecialchars(xl('Billing Information').":",ENT_QUOTES);?></h6>
  292. <?php
  293. if (count($ar['newpatient']) > 0) {
  294. $billings = array();
  295. ?>
  296. <table>
  297. <tr><td width='400' class='bold'><?php echo htmlspecialchars(xl('Code'),ENT_QUOTES);?></td><td class='bold'><?php echo htmlspecialchars(xl('Fee'),ENT_QUOTES);?></td></tr>
  298. <?php
  299. $total = 0.00;
  300. $copays = 0.00;
  301. foreach ($ar['newpatient'] as $be) {
  302. $ta = split(":",$be);
  303. $billing = getPatientBillingEncounter($pid,$ta[1]);
  304. $billings[] = $billing;
  305. foreach ($billing as $b) {
  306. ?>
  307. <tr>
  308. <td class=text>
  309. <?php
  310. echo htmlspecialchars($b['code_type'],ENT_QUOTES) . ":\t" .htmlspecialchars( $b['code'],ENT_QUOTES) . "&nbsp;". htmlspecialchars($b['modifier'],ENT_QUOTES) . "&nbsp;&nbsp;&nbsp;" . htmlspecialchars($b['code_text'],ENT_QUOTES) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  311. ?>
  312. </td>
  313. <td class=text>
  314. <?php
  315. echo htmlspecialchars(oeFormatMoney($b['fee']),ENT_QUOTES);
  316. ?>
  317. </td>
  318. </tr>
  319. <?php
  320. $total += $b['fee'];
  321. if ($b['code_type'] == "COPAY") {
  322. $copays += $b['fee'];
  323. }
  324. }
  325. }
  326. echo "<tr><td>&nbsp;</td></tr>";
  327. echo "<tr><td class=bold>".htmlspecialchars(xl('Sub-Total'),ENT_QUOTES)."</td><td class=text>" . htmlspecialchars(oeFormatMoney($total + abs($copays)),ENT_QUOTES) . "</td></tr>";
  328. echo "<tr><td class=bold>".htmlspecialchars(xl('Paid'),ENT_QUOTES)."</td><td class=text>" . htmlspecialchars(oeFormatMoney(abs($copays)),ENT_QUOTES) . "</td></tr>";
  329. echo "<tr><td class=bold>".htmlspecialchars(xl('Total'),ENT_QUOTES)."</td><td class=text>" .htmlspecialchars(oeFormatMoney($total),ENT_QUOTES) . "</td></tr>";
  330. echo "</table>";
  331. echo "<pre>";
  332. //print_r($billings);
  333. echo "</pre>";
  334. } else {
  335. printPatientBilling($pid);
  336. }
  337. echo "</div>\n"; // end of billing DIV
  338. }
  339. elseif ($val == "immunizations")
  340. {
  341. ?>
  342. <hr />
  343. <div class='text immunizations'>
  344. <h6><?php echo htmlspecialchars(xl('Patient Immunization').":",ENT_QUOTES);?></h6>
  345. <?php
  346. $sql = "select i1.immunization_id as immunization_id, if(i1.administered_date,concat(i1.administered_date,' - ') ,substring(i1.note,1,20) ) as immunization_data from immunizations i1 where i1.patient_id = ? order by administered_date desc";
  347. $result = sqlStatement($sql,array($pid));
  348. while ($row=sqlFetchArray($result)) {
  349. echo htmlspecialchars($row{'immunization_data'},ENT_QUOTES);
  350. echo generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
  351. ?>
  352. <br>
  353. <?php
  354. }
  355. ?>
  356. </div>
  357. <?php
  358. }
  359. elseif ($val == "batchcom")
  360. {
  361. ?>
  362. <hr />
  363. <div class='text transactions'>
  364. <h6><?php htmlspecialchars(xl('Patient Communication sent').":",ENT_QUOTES);?></h6>
  365. <?php
  366. $sql="SELECT concat( 'Messsage Type: ', batchcom.msg_type, ', Message Subject: ', batchcom.msg_subject, ', Sent on:', batchcom.msg_date_sent ) AS batchcom_data, batchcom.msg_text, concat( users.fname, users.lname ) AS user_name FROM `batchcom` JOIN `users` ON users.id = batchcom.sent_by WHERE batchcom.patient_id=?";
  367. $result = sqlStatement($sql,array($pid));
  368. while ($row=sqlFetchArray($result)) {
  369. echo htmlspecialchars($row{'batchcom_data'}.", ".xl('By').": ".$row{'user_name'},ENT_QUOTES);
  370. ?>
  371. <br><?php echo htmlspecialchars(xl('Text'),ENT_QUOTES);?>:<br><?php echo htmlspecialchars($row{'msg_txt'},ENT_QUOTES);?><br>
  372. <?php
  373. }
  374. ?>
  375. </div>
  376. <?php
  377. }
  378. elseif ($val == "notes")
  379. {
  380. ?>
  381. <hr />
  382. <div class='text notes'>
  383. <h6><?php echo htmlspecialchars(xl('Patient Notes').":",ENT_QUOTES);?></h6>
  384. <?php
  385. printPatientNotes($pid);
  386. ?>
  387. </div>
  388. <?php
  389. }
  390. elseif ($val == "transactions")
  391. {
  392. ?>
  393. <hr />
  394. <div class='text transactions'>
  395. <h6><?php echo htmlspecialchars(xl('Patient Transactions').":",ENT_QUOTES);?></h6>
  396. <?php
  397. printPatientTransactions($pid);
  398. ?>
  399. </div>
  400. <?php
  401. }
  402. }
  403. }
  404. ?>