/library/freeb/Diagnosis.class.php

https://github.com/md-tech/openemr · PHP · 592 lines · 433 code · 71 blank · 88 comment · 84 complexity · 097308806592164c09ab89530c630c50 MD5 · raw file

  1. <?php
  2. require_once("DataObjectBase.class.php");
  3. require_once("xmlrpc.inc");
  4. class Diagnosis Extends DataObjectBase {
  5. function Diagnosis() {
  6. $this->_addFunc("relatedtohcfa", array( "name" => "FreeB.FBDiagnosis.RelatedToHCFA",
  7. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  8. "doc" => ""));
  9. $this->_addFunc("isrelatedtootheraccident", array( "name" => "FreeB.FBDiagnosis.isRelatedToOtherAccident",
  10. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  11. "doc" => ""));
  12. $this->_addFunc("dateofencounter", array("name" => "FreeB.FBDiagnosis.DateOfEncounter",
  13. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  14. "doc" => ""));
  15. $this->_addFunc("dateofonset", array( "name" => "FreeB.FBDiagnosis.DateOfOnset",
  16. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  17. "doc" => ""));
  18. $this->_addFunc("dateoffirstsymptom", array( "name" => "FreeB.FBDiagnosis.DateOfFirstSymptom",
  19. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  20. "doc" => ""));
  21. $this->_addFunc("isfirstoccurence", array( "name" => "FreeB.FBDiagnosis.isFirstOccurrence",
  22. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  23. "doc" => ""));
  24. $this->_addFunc("dateoffirstoccurence", array( "name" => "FreeB.FBDiagnosis.DateOfFirstOccurrence",
  25. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  26. "doc" => ""));
  27. $this->_addFunc("iscantwork", array( "name" => "FreeB.FBDiagnosis.isCantWork",
  28. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  29. "doc" => ""));
  30. $this->_addFunc("dateofcantworkstart", array( "name" => "FreeB.FBDiagnosis.DateOfCantWorkStart",
  31. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  32. "doc" => ""));
  33. $this->_addFunc("dateofcantworkend", array( "name" => "FreeB.FBDiagnosis.DateOfCantWorkEnd",
  34. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  35. "doc" => ""));
  36. $this->_addFunc("isrelatedtoemployment", array( "name" => "FreeB.FBDiagnosis.isRelatedToEmployment",
  37. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  38. "doc" => ""));
  39. $this->_addFunc("isrelatedtoautoaccident", array( "name" => "FreeB.FBDiagnosis.isRelatedToAutoAccident",
  40. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  41. "doc" => ""));
  42. $this->_addFunc("autoaccidentstate", array( "name" => "FreeB.FBDiagnosis.AutoAccidentState",
  43. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  44. "doc" => ""));
  45. $this->_addFunc("icd10code", array( "name" => "FreeB.FBDiagnosis.ICD10Code",
  46. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  47. "doc" => ""));
  48. $this->_addFunc("icd9code", array( "name" => "FreeB.FBDiagnosis.ICD9Code",
  49. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  50. "doc" => ""));
  51. $this->_addFunc("dateoflastvisit", array( "name" => "FreeB.FBDiagnosis.DateOfLastVisit",
  52. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  53. "doc" => ""));
  54. $this->_addFunc("comment", array( "name" => "FreeB.FBDiagnosis.Comment",
  55. "sig" => array(XMLRPCSTRING,XMLRPCINT),
  56. "doc" => ""));
  57. }
  58. function relatedtohcfa($m) {
  59. $err="";
  60. //unimplemented by OpenEMR
  61. $retval = "";
  62. // if we generated an error, create an error return response
  63. if ($err) {
  64. return $this->_handleError($err);
  65. }
  66. else {
  67. // otherwise, we create the right response
  68. // with the state name
  69. return new xmlrpcresp(new xmlrpcval($retval,"string"));
  70. }
  71. }
  72. function isrelatedtootheraccident($m) {
  73. $err="";
  74. //Now implemented by OpenEMR with Form: Misc Billing Options
  75. $pkey = false;
  76. $retval = "";
  77. $obj= $m->getparam(0);
  78. $key = $obj->getval();
  79. $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
  80. //echo $sql;
  81. $db = $GLOBALS['adodb']['db'];
  82. $results = $db->Execute($sql);
  83. if (!$results) {
  84. $err = $db->ErrorMsg();
  85. }
  86. else {
  87. if (!$results->EOF) {
  88. $retval = $results->fields['other_accident'];
  89. if ($retval == "1") {$pkey = true;};
  90. }
  91. }
  92. // if we generated an error, create an error return response
  93. if ($err) {
  94. return $this->_handleError($err);
  95. }
  96. else {
  97. // otherwise, we create the right response
  98. // with the state name
  99. return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
  100. }
  101. }
  102. function dateofencounter($m) {
  103. $err="";
  104. $retval ="";
  105. $obj= $m->getparam(0);
  106. $key = $obj->getval();
  107. $sql = "SELECT * FROM form_encounter where encounter = '" . $_SESSION['billkey'] .
  108. "' and pid = '" . $_SESSION['patient_id'] ."' order by date DESC";
  109. $db = $GLOBALS['adodb']['db'];
  110. $results = $db->Execute($sql);
  111. if (!$results) {
  112. $err = $db->ErrorMsg();
  113. }
  114. else {
  115. if (!$results->EOF) {
  116. $retval = $results->fields['date'];
  117. }
  118. }
  119. $retval = date("Y-m-d",strtotime($retval));
  120. $retval = $this->_isodate($retval);
  121. // if we generated an error, create an error return response
  122. if ($err) {
  123. return $this->_handleError($err);
  124. }
  125. else {
  126. // otherwise, we create the right response
  127. // with the state name
  128. return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME));
  129. }
  130. }
  131. function dateofonset($m) {
  132. $err="";
  133. $retval ="";
  134. $obj= $m->getparam(0);
  135. $key = $obj->getval();
  136. $sql = "SELECT * FROM form_encounter where encounter = '" . $_SESSION['billkey'] ."' and pid = '" . $_SESSION['patient_id'] ."' order by date DESC";
  137. //echo $sql;
  138. $db = $GLOBALS['adodb']['db'];
  139. $results = $db->Execute($sql);
  140. if (!$results) {
  141. $err = $db->ErrorMsg();
  142. }
  143. else {
  144. if (!$results->EOF) {
  145. $retval = $results->fields['onset_date'];
  146. }
  147. }
  148. $retval = date("Y-m-d",strtotime($retval));
  149. $retval = $this->_isodate($retval);
  150. // if we generated an error, create an error return response
  151. if ($err) {
  152. return $this->_handleError($err);
  153. }
  154. else {
  155. // otherwise, we create the right response
  156. // with the state name
  157. return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME));
  158. }
  159. }
  160. function dateoffirstsymptom($m) {
  161. $err="";
  162. $retval ="";
  163. $obj= $m->getparam(0);
  164. $key = $obj->getval();
  165. $sql = "SELECT * FROM form_encounter where encounter = '" . $_SESSION['billkey'] ."' and pid = '" . $_SESSION['patient_id'] ."' order by date DESC";
  166. //echo $sql;
  167. $db = $GLOBALS['adodb']['db'];
  168. $results = $db->Execute($sql);
  169. if (!$results) {
  170. $err = $db->ErrorMsg();
  171. }
  172. else {
  173. if (!$results->EOF) {
  174. $retval = $results->fields['onset_date'];
  175. }
  176. }
  177. $retval = date("Y-m-d",strtotime($retval));
  178. $retval = $this->_isodate($retval);
  179. // if we generated an error, create an error return response
  180. if ($err) {
  181. return $this->_handleError($err);
  182. }
  183. else {
  184. // otherwise, we create the right response
  185. // with the state name
  186. return new xmlrpcresp(new xmlrpcval($pkey,XMLRPCDATETIME));
  187. }
  188. }
  189. function isfirstoccurence($m) {
  190. $err="";
  191. //unimplemented by OpenEMR
  192. $pkey = false;
  193. // if we generated an error, create an error return response
  194. if ($err) {
  195. return $this->_handleError($err);
  196. }
  197. else {
  198. // otherwise, we create the right response
  199. // with the state name
  200. return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
  201. }
  202. }
  203. function dateoffirstoccurence($m) {
  204. $err="";
  205. $retval ="";
  206. $obj= $m->getparam(0);
  207. $key = $obj->getval();
  208. $sql = "SELECT * FROM form_encounter where encounter = '" . $_SESSION['billkey'] ."' and pid = '" . $_SESSION['patient_id'] ."' order by date DESC";
  209. //echo $sql;
  210. $db = $GLOBALS['adodb']['db'];
  211. $results = $db->Execute($sql);
  212. if (!$results) {
  213. $err = $db->ErrorMsg();
  214. }
  215. else {
  216. if (!$results->EOF) {
  217. $retval = $results->fields['onset_date'];
  218. }
  219. }
  220. $retval = date("Y-m-d",strtotime($retval));
  221. $retval = $this->_isodate($retval);
  222. // if we generated an error, create an error return response
  223. if ($err) {
  224. return $this->_handleError($err);
  225. }
  226. else {
  227. // otherwise, we create the right response
  228. // with the state name
  229. return new xmlrpcresp(new xmlrpcval($pkey,XMLRPCDATETIME));
  230. }
  231. }
  232. function iscantwork($m) {
  233. $err="";
  234. //Now implemented by OpenEMR with Form: Misc Billing Options
  235. $pkey = false;
  236. $retval = "";
  237. $obj= $m->getparam(0);
  238. $key = $obj->getval();
  239. $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
  240. //echo $sql;
  241. $db = $GLOBALS['adodb']['db'];
  242. $results = $db->Execute($sql);
  243. if (!$results) {
  244. $err = $db->ErrorMsg();
  245. }
  246. else {
  247. if (!$results->EOF) {
  248. $retval = $results->fields['is_unable_to_work'];
  249. if ($retval == "1") {$pkey = true;};
  250. }
  251. }
  252. // if we generated an error, create an error return response
  253. if ($err) {
  254. return $this->_handleError($err);
  255. }
  256. else {
  257. // otherwise, we create the right response
  258. // with the state name
  259. return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
  260. }
  261. }
  262. function dateofcantworkstart($m) {
  263. $err="";
  264. //Now implemented by OpenEMR with Form: Misc Billing Options
  265. $retval = "";
  266. $obj= $m->getparam(0);
  267. $key = $obj->getval();
  268. $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
  269. //echo $sql;
  270. $db = $GLOBALS['adodb']['db'];
  271. $results = $db->Execute($sql);
  272. if (!$results) {
  273. $err = $db->ErrorMsg();
  274. }
  275. else {
  276. if (!$results->EOF) {
  277. $retval = $results->fields['off_work_from'];
  278. }
  279. }
  280. $retval = date("Y-m-d",strtotime($retval));
  281. $retval = $this->_isodate($retval);
  282. // if we generated an error, create an error return response
  283. if ($err) {
  284. return $this->_handleError($err);
  285. }
  286. else {
  287. // otherwise, we create the right response
  288. // with the state name
  289. return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME));
  290. }
  291. }
  292. function dateofcantworkend($m) {
  293. $err="";
  294. //Now implemented by OpenEMR with Form: Misc Billing Options
  295. $retval = "";
  296. $obj= $m->getparam(0);
  297. $key = $obj->getval();
  298. $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
  299. //echo $sql;
  300. $db = $GLOBALS['adodb']['db'];
  301. $results = $db->Execute($sql);
  302. if (!$results) {
  303. $err = $db->ErrorMsg();
  304. }
  305. else {
  306. if (!$results->EOF) {
  307. $retval = $results->fields['off_work_to'];
  308. }
  309. }
  310. $retval = date("Y-m-d",strtotime($retval));
  311. $retval = $this->_isodate($retval);
  312. // if we generated an error, create an error return response
  313. if ($err) {
  314. return $this->_handleError($err);
  315. }
  316. else {
  317. // otherwise, we create the right response
  318. // with the state name
  319. return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME));
  320. }
  321. }
  322. function isrelatedtoemployment($m) {
  323. $err="";
  324. //Now implemented by OpenEMR with Form: Misc Billing Options
  325. $pkey = false;
  326. $retval = "";
  327. $obj= $m->getparam(0);
  328. $key = $obj->getval();
  329. $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
  330. //echo $sql;
  331. $db = $GLOBALS['adodb']['db'];
  332. $results = $db->Execute($sql);
  333. if (!$results) {
  334. $err = $db->ErrorMsg();
  335. }
  336. else {
  337. if (!$results->EOF) {
  338. $retval = $results->fields['employment_related'];
  339. if ($retval == "1") {$pkey = true;};
  340. }
  341. }
  342. // if we generated an error, create an error return response
  343. if ($err) {
  344. return $this->_handleError($err);
  345. }
  346. else {
  347. // otherwise, we create the right response
  348. // with the state name
  349. return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
  350. }
  351. }
  352. function isrelatedtoautoaccident($m) {
  353. $err="";
  354. //Now implemented by OpenEMR with Form: Misc Billing Options
  355. $pkey = false;
  356. $retval = "";
  357. $obj= $m->getparam(0);
  358. $key = $obj->getval();
  359. $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
  360. //echo $sql;
  361. $db = $GLOBALS['adodb']['db'];
  362. $results = $db->Execute($sql);
  363. if (!$results) {
  364. $err = $db->ErrorMsg();
  365. }
  366. else {
  367. if (!$results->EOF) {
  368. $retval = $results->fields['auto_accident'];
  369. if ($retval == "1") {$pkey = true;};
  370. }
  371. }
  372. // if we generated an error, create an error return response
  373. if ($err) {
  374. return $this->_handleError($err);
  375. }
  376. else {
  377. // otherwise, we create the right response
  378. // with the state name
  379. return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
  380. }
  381. }
  382. function autoaccidentstate($m) {
  383. $err="";
  384. $retval = "";
  385. $obj= $m->getparam(0);
  386. $key = $obj->getval();
  387. //Now implemented by OpenEMR with Form: Misc_billing_options
  388. $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
  389. //echo $sql;
  390. $db = $GLOBALS['adodb']['db'];
  391. $results = $db->Execute($sql);
  392. if (!$results) {
  393. $err = $db->ErrorMsg();
  394. }
  395. else {
  396. if (!$results->EOF) {
  397. $retval = $results->fields['accident_state'];
  398. }
  399. }
  400. // if we generated an error, create an error return response
  401. if ($err) {
  402. return $this->_handleError($err);
  403. }
  404. else {
  405. // otherwise, we create the right response
  406. // with the state name
  407. return new xmlrpcresp(new xmlrpcval($retval,"string"));
  408. }
  409. }
  410. function icd10code($m) {
  411. $err="";
  412. //unimplemented by OpenEMR
  413. $pkey = "";
  414. // if we generated an error, create an error return response
  415. if ($err) {
  416. return $this->_handleError($err);
  417. }
  418. else {
  419. // otherwise, we create the right response
  420. // with the state name
  421. return new xmlrpcresp(new xmlrpcval($pkey));
  422. }
  423. }
  424. function icd9code($m) {
  425. $err="";
  426. $obj= $m->getparam(0);
  427. $key = $obj->getval();
  428. $sql = "SELECT * FROM billing where id = '" . $key . "'";
  429. //echo $sql;
  430. $db = $GLOBALS['adodb']['db'];
  431. $results = $db->Execute($sql);
  432. if (!$results) {
  433. $err = $db->ErrorMsg();
  434. }
  435. else {
  436. if (!$results->EOF) {
  437. $retval = $results->fields['code'];
  438. }
  439. }
  440. $retval = str_replace("."," ", $retval);
  441. // if we generated an error, create an error return response
  442. if ($err) {
  443. return $this->_handleError($err);
  444. }
  445. else {
  446. // otherwise, we create the right response
  447. // with the state name
  448. return new xmlrpcresp(new xmlrpcval($retval,"string"));
  449. }
  450. }
  451. function dateoflastvisit($m){
  452. $err="";
  453. $retval ="";
  454. $obj= $m->getparam(0);
  455. $key = $obj->getval();
  456. $sql = "SELECT * FROM form_encounter where encounter = '" . $_SESSION['billkey'] ."' and pid = '" . $_SESSION['patient_id'] ."' order by date DESC";
  457. //echo $sql;
  458. $db = $GLOBALS['adodb']['db'];
  459. $results = $db->Execute($sql);
  460. if (!$results) {
  461. $err = $db->ErrorMsg();
  462. }
  463. else {
  464. if (!$results->EOF) {
  465. $retval = $results->fields['date'];
  466. }
  467. }
  468. $retval = date("Y-m-d",strtotime($retval));
  469. $retval = $this->_isodate($retval);
  470. // if we generated an error, create an error return response
  471. if ($err) {
  472. return $this->_handleError($err);
  473. }
  474. else {
  475. // otherwise, we create the right response
  476. // with the state name
  477. return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME));
  478. }
  479. }
  480. function comment($m){
  481. $err="";
  482. $retval ="";
  483. $obj= $m->getparam(0);
  484. $key = $obj->getval();
  485. $sql = "SELECT reason FROM form_encounter where encounter = '" . $_SESSION['billkey'] ."' and pid = '" . $_SESSION['patient_id'] ."'";
  486. //echo $sql;
  487. $db = $GLOBALS['adodb']['db'];
  488. $results = $db->Execute($sql);
  489. if (!$results) {
  490. $err = $db->ErrorMsg();
  491. }
  492. else {
  493. if (!$results->EOF) {
  494. $retval = $results->fields['reason'];
  495. }
  496. }
  497. // if we generated an error, create an error return response
  498. if ($err) {
  499. return $this->_handleError($err);
  500. }
  501. else {
  502. // otherwise, we create the right response
  503. // with the state name
  504. return new xmlrpcresp(new xmlrpcval($retval,"string"));
  505. }
  506. }
  507. }
  508. //'FreeB.FBDiagnosis.RelatedToHCFA' => \&FreeB_FBDiagnosis_RelatedToHCFA,
  509. //'FreeB.FBDiagnosis.isRelatedToOtherAccident' => \&FreeB_FBDiagnosis_isRelatedToOtherAccident,
  510. //'FreeB.FBDiagnosis.DateOfOnset' => \&FreeB_FBDiagnosis_DateOfOnset,
  511. //'FreeB.FBDiagnosis.DateOfFirstSymptom' => \&FreeB_FBDiagnosis_DateOfFirstSymptom,
  512. //'FreeB.FBDiagnosis.isFirstOccurrence' => \&FreeB_FBDiagnosis_isFirstOccurence,
  513. //'FreeB.FBDiagnosis.DateOfFirstOccurrence' => \&FreeB_FBDiagnosis_DateOfFirstOccurence,
  514. //'FreeB.FBDiagnosis.isCantWork' => \&FreeB_FBDiagnosis_isCantWork,
  515. //'FreeB.FBDiagnosis.DateOfCantWorkStart' => \&FreeB_FBDiagnosis_DateOfCantWorkStart,
  516. //'FreeB.FBDiagnosis.DateOfCantWorkEnd' => \&FreeB_FBDiagnosis_DateOfCantWorkEnd,
  517. //'FreeB.FBDiagnosis.isRelatedToEmployment' => \&FreeB_FBDiagnosis_isRelatedToEmployment,
  518. //'FreeB.FBDiagnosis.isRelatedToAutoAccident' => \&FreeB_FBDiagnosis_isRelatedToAutoAccident,
  519. //'FreeB.FBDiagnosis.AutoAccidentState' => \&FreeB_FBDiagnosis_AutoAccidentState,
  520. //'FreeB.FBDiagnosis.ICD10Code' => \&FreeB_FBDiagnosis_ICD9Code,
  521. //'FreeB.FBDiagnosis.ICD9Code' => \&FreeB_FBDiagnosis_ICD9Code,?>