PageRenderTime 63ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/hxp/server.php

https://github.com/timschofield/2.8
PHP | 1096 lines | 927 code | 98 blank | 71 comment | 78 complexity | a31ddadd8fe00842f8acede4ce2863b3 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-2.0
  1. <?php
  2. /**
  3. * XML-RPC server for HXP. Version 0.1
  4. * Licence LGPL
  5. * Copyright 2004,2005 Elpidio Latorilla <elpidio@care2.net>
  6. * This server works only with the Incutio IXR library to be found at
  7. * http://scripts.incutio.com/xmlrpc/
  8. *
  9. * Usage:
  10. * Create a subdirectory in your web server root and name it "hxp"
  11. * Copy this file into this subdirectory.
  12. *
  13. * Other files that must be copied in the subdirectory:
  14. * ixr_library.inc.php
  15. * person.php
  16. * encounter.php
  17. * ward.php
  18. * department.php
  19. * room.php
  20. * system.php
  21. * emr.php
  22. * anon.php
  23. *
  24. */
  25. error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
  26. //error_reporting(E_ALL);
  27. require('./roots.php');
  28. require($root_path.'include/helpers/inc_environment_global.php');
  29. //include($root_path.'include/core/class_core.php');
  30. //$core = & new Core();
  31. include($root_path.'include/core/class_person.php');
  32. $person = & new Person();
  33. # Create the encounter object
  34. include($root_path.'include/core/class_encounter.php');
  35. $enc = & new Encounter();
  36. #Create the image object
  37. include($root_path.'modules/photolab/model/class_image.php');
  38. $img= & new Image();
  39. require('./include/inc_access.php');
  40. require_once('./class/xmlrpc/ixr_library.inc.php');
  41. function Person($args){
  42. global $person,$error;
  43. if(checkAccess($args[0])){
  44. $buf= $person->getAllInfoArray($args[1]);
  45. if($buf){
  46. return $buf;
  47. }else{
  48. return new IXR_Error(1006,'_ERROR_NORESULT');
  49. }
  50. }else{
  51. return new IXR_Error($error['code'],$error['msg']);
  52. }
  53. }
  54. function PersonBasic($args){
  55. global $person,$error;
  56. if(checkAccess($args[0])){
  57. $buf= $person->BasicDataArray($args[1]);
  58. if($buf){
  59. return $buf;
  60. }else{
  61. return new IXR_Error(1006,'_ERROR_NORESULT');
  62. }
  63. }else{
  64. return new IXR_Error($error['code'],$error['msg']);
  65. }
  66. }
  67. function PersonInfostring($args){
  68. global $person,$error;
  69. if(checkAccess($args[0])){
  70. $buf= $person->BasicDataArray($args[1]);
  71. if($buf){
  72. $infostr=$buf['name_last'].', '.$buf['name_first'].' '.$buf['date_birth'];
  73. return $infostr;
  74. }else{
  75. return new IXR_Error(1006,'_ERROR_NORESULT');
  76. }
  77. }else{
  78. return new IXR_Error($error['code'],$error['msg']);
  79. }
  80. }
  81. function PersonExists($args){
  82. global $person,$error;
  83. if(checkAccess($args[0])){
  84. $buf= $person->PIDbyData($args[1]);
  85. if($buf){
  86. return $buf;
  87. }else{
  88. return new IXR_Error(1006,'_ERROR_NORESULT');
  89. }
  90. }else{
  91. return new IXR_Error($error['code'],$error['msg']);
  92. }
  93. }
  94. function PersonSave($args){
  95. global $person,$error;
  96. if(checkAccess($args[0])){
  97. # Validate at least name, first name, and DOB
  98. if(empty($args[1]['name_last'])||empty($args[1]['name_first'])||empty($args[1]['birth_date'])){
  99. return new IXR_Error(1006,'_ERROR_DATA_INCOMPLETE');
  100. }else{
  101. # Prepare internal info
  102. $args[1]['status']='normal';
  103. $args[1]['history']="Create ".date('Y-m-d H:i:s')." ".$args[0]['usr']."\n";
  104. $args[1]['create_id']=$args[0]['usr'];
  105. $args[1]['create_time']=date('YmdHis');
  106. # Point the db table to care_person
  107. //$care->setDataArray='care_person';
  108. # Save the data
  109. if($person->insertDataFromArray($args[1])){
  110. return TRUE;
  111. }else{
  112. return new IXR_Error(1006,'_ERROR_SQL_NOINSERT');
  113. }
  114. }
  115. }else{
  116. return new IXR_Error($error['code'],$error['msg']);
  117. }
  118. }
  119. function PersonUpdate($args){
  120. global $person,$error;
  121. if(checkAccess($args[0])){
  122. # Validate the pid
  123. if(empty($args[1]['pid'])){
  124. return new IXR_Error(1006,'_ERROR_DATA_INCOMPLETE');
  125. }else{
  126. # Prepare internal info
  127. $args[1]['status']='normal';
  128. $args[1]['history']="Create ".date('Y-m-d H:i:s')." ".$args[0]['usr']."\n";
  129. $args[1]['create_id']=$args[0]['usr'];
  130. $args[1]['create_time']=date('YmdHis');
  131. # Set the where info
  132. $person->setWhere('pid='.$args[1]['pid']);
  133. $person->setDataArray($args[1]);
  134. # Update the data
  135. if($person->upateDataFromInternalArray($args[1]['pid'])){
  136. return TRUE;
  137. }else{
  138. return new IXR_Error(1006,'_ERROR_SQL_NOUPDATE');
  139. }
  140. }
  141. }else{
  142. return new IXR_Error($error['code'],$error['msg']);
  143. }
  144. }
  145. /**
  146. * @private
  147. */
  148. function _getPersonData($item,$hdr){
  149. global $person,$error;
  150. if(checkAccess($hdr[0])){
  151. $buf=$person->getValue($item,$hdr[1]);
  152. return $buf;
  153. }else{
  154. return new IXR_Error($error['code'],$error['msg']);
  155. }
  156. }
  157. function PersonNameFirst($args){
  158. return _getPersonData('name_first',$args);
  159. }
  160. function PersonNameFamily($args){
  161. return _getPersonData('name_last',$args);
  162. }
  163. function PersonNameMiddle($args){
  164. return _getPersonData('name_middle',$args);
  165. }
  166. function PersonNameMaiden($args){
  167. return _getPersonData('name_maiden',$args);
  168. }
  169. function PersonNameSecond($args){
  170. return _getPersonData('name_2',$args);
  171. }
  172. function PersonNameThird($args){
  173. return _getPersonData('name_3',$args);
  174. }
  175. function PersonNameOthers($args){
  176. return _getPersonData('name_others',$args);
  177. }
  178. function PersonBloodGroup($args){
  179. return _getPersonData('blood_group',$args);
  180. }
  181. function PersonSex($args){
  182. return _getPersonData('sex',$args);
  183. }
  184. function PersonBirthDate($args){
  185. return _getPersonData('date_birth',$args);
  186. }
  187. function PersonTitle($args){
  188. return _getPersonData('title',$args);
  189. }
  190. function PersonDiedDate($args){
  191. return _getPersonData('death_date',$args);
  192. }
  193. function PersonDiedENR($args){
  194. return _getPersonData('death_encounter_nr',$args);
  195. }
  196. function PersonDiedCause($args){
  197. return _getPersonData('death_cause',$args);
  198. }
  199. function PersonDiedCauseCode($args){
  200. return _getPersonData('death_cause_code',$args);
  201. }
  202. function PersonRegDate($args){
  203. return _getPersonData('date_reg',$args);
  204. }
  205. function PersonCitizenship($args){
  206. return _getPersonData('citizenship',$args);
  207. }
  208. function PersonCivilStatus($args){
  209. return _getPersonData('civil_status',$args);
  210. }
  211. function PersonAddrs($args){
  212. global $person,$error;
  213. if(checkAccess($args[0])){
  214. $item='addr_str, addr_str_nr, addr_citytown_nr, addr_zip';
  215. $buf=$person->getValueByList($item,$args[1]);
  216. if($buf){
  217. if($buf['addr_citytown_nr']) $buf['addr_citytown_name']=$person->CityTownName($buf['addr_citytown_nr']);
  218. else $buf['addr_citytown_name']='';
  219. return $buf;
  220. }else{
  221. return new IXR_Error(1006,'_ERROR_NORESULT');
  222. }
  223. }else{
  224. return new IXR_Error($error['code'],$error['msg']);
  225. }
  226. }
  227. function PersonAddrsTxt($args){
  228. global $error;
  229. # Get the address data
  230. $buf=PersonAddrs($args);
  231. if($buf&&(!isset($buf['error'])||!$buf['error'])){
  232. # If city town name ok, get the city town name
  233. return $buf['addr_str']." ".$buf['addr_str_nr']."\n".$buf['addr_zip']." ".$buf['addr_citytown_name'];
  234. }else{
  235. return new IXR_Error($error['code'],$error['msg']);
  236. }
  237. }
  238. function PersonAddrsStr($args){
  239. return _getPersonData('addr_str',$args);
  240. }
  241. function PersonAddrsStrNr($args){
  242. return _getPersonData('addr_str_nr',$args);
  243. }
  244. function PersonAddrsCTown($args){
  245. return 1;
  246. }
  247. function PersonAddrsZip($args){
  248. return _getPersonData('addr_zip',$args);
  249. }
  250. function PersonAddrsValid($args){
  251. return _getPersonData('addr_is_valid',$args);
  252. }
  253. function PersonPhone1($args){
  254. return _getPersonData('phone_1_nr',$args);
  255. }
  256. function PersonPhoneACode1($args){
  257. return _getPersonData('phone_1_code',$args);
  258. }
  259. function PersonPhone2($args){
  260. return _getPersonData('phone_2_nr',$args);
  261. }
  262. function PersonPhoneACode2($args){
  263. return _getPersonData('phone_2_code',$args);
  264. }
  265. function PersonCellPhone1($args){
  266. return _getPersonData('cellphone_1_nr',$args);
  267. }
  268. function PersonCellPhone2($args){
  269. return _getPersonData('cellphone_2_nr',$args);
  270. }
  271. function PersonFaxNr($args){
  272. return _getPersonData('fax',$args);
  273. }
  274. function PersonMotherPID($args){
  275. return _getPersonData('mother_pid',$args);
  276. }
  277. function PersonFatherPID($args){
  278. return _getPersonData('father_pid',$args);
  279. }
  280. function PersonRecStatus($args){
  281. return _getPersonData('status',$args);
  282. }
  283. function PersonRecHistory($args){
  284. return _getPersonData('history',$args);
  285. }
  286. function PersonContact($args){
  287. return _getPersonData('contact_person',$args);
  288. }
  289. function PersonContactPID($args){
  290. return _getPersonData('contact_pid',$args);
  291. }
  292. function PersonContactRelation($args){
  293. return _getPersonData('date_update',$args);
  294. }
  295. function PersonUpdateDate($args){
  296. return _getPersonData('date_update',$args);
  297. }
  298. function PersonSSNr($args){
  299. return _getPersonData('sss_nr',$args);
  300. }
  301. function PersonNatIDNr($args){
  302. return _getPersonData('nat_id_nr',$args);
  303. }
  304. function PersonOrgID($args){
  305. return _getPersonData('org_id',$args);
  306. }
  307. function PersonReligion($args){
  308. return _getPersonData('religion',$args);
  309. }
  310. function PersonPhoto($args){
  311. return _getPersonData('photo',$args);
  312. }
  313. function PersonPhotoFilename($args){
  314. return _getPersonData('photo_filename',$args);
  315. }
  316. function PersonEthnicOrig($args){
  317. return _getPersonData('ethnic_orig',$args);
  318. }
  319. function PersonInsClassNr($args){
  320. return _getPersonData('insurance_class_nr',$args);
  321. }
  322. function PersonInsNr1($args){
  323. return _getPersonData('insurance_nr',$args);
  324. }
  325. function PersonInsCoID1($args){
  326. return _getPersonData('insurance_firm_id',$args);
  327. }
  328. function PersonInsNr2($args){
  329. return _getPersonData('insurance_2_nr',$args);
  330. }
  331. function PersonInsCoID2($args){
  332. return _getPersonData('insurance_2_firm_id',$args);
  333. }
  334. function PersonAdd($args){
  335. return 1;
  336. }
  337. function _setPersonRecStatus($args,$stat=''){
  338. global $enc,$error;
  339. if(checkAccess($args[0])){
  340. $person->setWhereCondition('encounter_nr='.$args[1]);
  341. $data['status']=$stat;
  342. $data['modify_time']=date('YmdHis');
  343. $date['modify_id']=$args[0]['usr'];
  344. $person->setDataArray($data);
  345. if ($person->updateDataFromInternalArray($args[1])){
  346. return TRUE;
  347. }else{
  348. return new IXR_Error(1006,'_ERROR_NORESULT');
  349. }
  350. }else{
  351. return new IXR_Error($error['code'],$error['msg']);
  352. }
  353. }
  354. function PersonRecHide($args){
  355. return _setPersonRecStatus($args,'hidden');
  356. }
  357. function PersonRecLock($args){
  358. return _setPersonRecStatus($args,'locked');
  359. }
  360. function PersonRecDelete($args){
  361. return _setPersonRecStatus($args,'deleted');
  362. }
  363. function PersonRecNormal($args){
  364. return _setPersonRecStatus($args,'normal');
  365. }
  366. function PersonRecInvalidate($args){
  367. return _setPersonRecStatus($args,'invalid');
  368. }
  369. function PersonRecEmpty($args){
  370. return _setPersonRecStatus($args);
  371. }
  372. function PersonList($args){
  373. global $person, $error;
  374. if(checkAccess($args)){
  375. # Set field names of items to fetch
  376. $items='pid, name_last, name_first, date_birth, addr_zip, sex, death_date, status';
  377. if($buf=$person->getAllItemsObject($items)){
  378. return $buf->GetArray();
  379. }else{
  380. return new IXR_Error(1006,'_ERROR_NORESULT');
  381. }
  382. }else{
  383. return new IXR_Error($error['code'],$error['msg']);
  384. }
  385. }
  386. function PersonEnc($args){
  387. global $person, $error;
  388. if(checkAccess($args[0])){
  389. $buf=$person->EncounterList($args[1]);
  390. if($buf){
  391. return $buf->GetArray();
  392. }else{
  393. return new IXR_Error(1006,'_ERROR_NORESULT');
  394. }
  395. }else{
  396. return new IXR_Error($error['code'],$error['msg']);
  397. }
  398. }
  399. function PersonEncSearch($args){
  400. return 1;
  401. }
  402. function PersonSearch($args){
  403. global $person,$error;
  404. if(checkAccess($args[0])){
  405. $buf=$person->Persons($args[1]);
  406. if($buf){
  407. return $buf->GetArray();
  408. }else{
  409. return new IXR_Error(1006,'_ERROR_NORESULT');
  410. }
  411. }else{
  412. return new IXR_Error($error['code'],$error['msg']);
  413. }
  414. }
  415. function PersonSearchSelect($args){
  416. global $person,$error;
  417. if(checkAccess($args[0])){
  418. if(!isset($args[2])) $args[2]=100;
  419. if(!isset($args[3])) $args[3]=0;
  420. if(!isset($args[4])) $args[4]='';
  421. if(!isset($args[5])) $args[5]='';
  422. if(!isset($args[6])) $args[6]=FALSE;
  423. $buf=$person->SearchSelect($args[1],$args[2],$args[3],$args[4],$args[5],$args[6]);
  424. if($buf){
  425. return $buf->GetArray();
  426. }else{
  427. return new IXR_Error(1006,'_ERROR_NORESULT');
  428. }
  429. }else{
  430. return new IXR_Error($error['code'],$error['msg']);
  431. }
  432. }
  433. function PersonEncCurrNr($args){
  434. global $person,$error;
  435. if(checkAccess($args[0])){
  436. $buf=$person->CurrentEncounter($args[1]);
  437. if($buf){
  438. return $buf;
  439. }else{
  440. return new IXR_Error(1006,'_ERROR_NORESULT');
  441. }
  442. }else{
  443. return new IXR_Error($error['code'],$error['msg']);
  444. }
  445. }
  446. function PersonAppt($args){
  447. return 1;
  448. }
  449. function PersonApptList($args){
  450. global $error,$root_path;
  451. include($root_path.'modules/appointment_scheduler/model/class_appointment.php');
  452. $appt=& new Appointment();
  453. if(checkAccess($args[0])){
  454. $buf=$appt->getPersonsAppointmentsObj($args[1]);
  455. if($buf){
  456. return $buf->GetArray();
  457. //return true;
  458. }else{
  459. return new IXR_Error(1006,'_ERROR_NORESULT');
  460. }
  461. }else{
  462. return new IXR_Error($error['code'],$error['msg']);
  463. }
  464. }
  465. function PersonPhotoIDURL($args){
  466. global $error,$root_path, $person,$db, $httprotocol,$photoserver_ip;
  467. if(checkAccess($args[0])){
  468. include($root_path.'global_conf/inc_remoteservers_conf.php');
  469. # Prepare the url path for the image
  470. $d = $photoserver_http."uploads/registration/";
  471. $sql="SELECT photo_filename FROM $person->coretable WHERE pid=".$args[1];
  472. if($f=$db->Execute($sql)){
  473. if($f->RecordCount()){
  474. $buf=$f->FetchRow();
  475. if(empty($buf['photo_filename'])||!file_exists($root_path.'uploads/photos/registration/'.$buf['photo_filename'])){
  476. return new IXR_Error(1107,'_ERROR_FILE_NOEXISTS');
  477. }else{
  478. return $d.$buf['photo_filename'];
  479. }
  480. }else{
  481. return new IXR_Error(1005,'_ERROR_NORESULT');
  482. }
  483. }else{
  484. return new IXR_Error(1006,'_ERROR_SQL_QUERY');
  485. }
  486. }else{
  487. return new IXR_Error($error['code'],$error['msg']);
  488. }
  489. }
  490. function PersonImageAdd($args){
  491. return PersonPhotoIDSave($args);
  492. }
  493. function PersonPhotoIDSave($args){
  494. global $root_path, $img, $error, $person, $httprotocol, $main_domain;
  495. $type='registration';
  496. $picdir= $args[1];
  497. if(checkAccess($args[0])){
  498. include($root_path.'global_conf/inc_remoteservers_conf.php');
  499. $d=$root_path."photos/$type/";
  500. # Try to get the extension
  501. if(empty($args[2]['ext'])){
  502. if(!empty($args[2]['mime_type'])){
  503. if(stristr($args[2]['mime_type'],'gif')){
  504. $picext='gif';
  505. }elseif(stristr($args[2]['mime_type'],'jpg')){
  506. $picext='jpg';
  507. }elseif(stristr($args[2]['mime_type'],'jpeg')){
  508. $picext='jpeg';
  509. }elseif(stristr($args[2]['mime_type'],'png')){
  510. $picext='png';
  511. }
  512. }
  513. }else{
  514. $picext = $args[2]['ext'];
  515. }
  516. if(!empty($picext)&&(stristr($picext,'gif')||stristr($picext,'jpg')||stristr($picext,'png')||stristr($picext,'jpeg'))){
  517. $data['photo_filename']="$picdir.$picext";
  518. $data['history']=$person->ConcatHistory("PhotoID uploaded via HXP: ".date('Y-m-d H:i:s')." ".$args[0]['usr']."\n");
  519. $data['modify_id']=$args[0]['usr'];
  520. $data['modify_time']=date('YmdHis');
  521. $person->setDataArray($data);
  522. $person->setWhereCondition("pid=".$picdir);
  523. if($person->updateDataFromInternalArray($picdir)){
  524. # Create the filename
  525. $picfilename = $data['photo_filename'];
  526. $newfilepath="$d/$picfilename";
  527. if($fp=fopen($newfilepath,'wb')){
  528. fwrite($fp,base64_decode($args[2]['img']));
  529. fclose($fp);
  530. return "$photoserver_http$type/$picfilename";
  531. }else{
  532. # Delete the table record
  533. $img->Transact("DELETE FROM care_encounter_image WHERE nr=$picnr");
  534. return $d;
  535. return new IXR_Error(1100,'_ERROR_FILE_NOCREATE');
  536. }
  537. }else{
  538. return new IXR_Error(1108,'_ERROR_SQL_NOSAVE');
  539. }
  540. }else{
  541. return new IXR_Error(1105,'_ERROR_FILE_INVALID');
  542. }
  543. }else{
  544. return new IXR_Error($error['code'],$error['msg']);
  545. }
  546. }
  547. //################ Encounter Calls #######################
  548. function Enc($args){
  549. global $enc,$error;
  550. if(checkAccess($args[0])){
  551. $enc->loadEncounterData($args[1]);
  552. #return $enc->loadEncounterData($args[1]);
  553. if ($enc->is_loaded){
  554. return $enc->encounter;
  555. }else{
  556. return new IXR_Error(1006,'_ERROR_NORESULT');
  557. }
  558. }else{
  559. return new IXR_Error($error['code'],$error['msg']);
  560. }
  561. }
  562. function EncInfostring($args){
  563. global $enc,$error;
  564. if(checkAccess($args[0])){
  565. $enc->loadEncounterData($args[1]);
  566. #return $enc->loadEncounterData($args[1]);
  567. if ($enc->is_loaded){
  568. $infostr =$enc->encounter['name_last'].', '.$enc->encounter['name_first'].' '.$enc->encounter['date_birth'].' PID: '.$enc->encounter['pid'];
  569. return $infostr;
  570. }else{
  571. return new IXR_Error(1006,'_ERROR_NORESULT');
  572. }
  573. }else{
  574. return new IXR_Error($error['code'],$error['msg']);
  575. }
  576. }
  577. function _enclist($args,$method){
  578. global $enc,$error;
  579. if(checkAccess($args)){
  580. $buf=$enc->$method('%');
  581. if ($buf){
  582. return $buf->GetArray();
  583. }else{
  584. return new IXR_Error(1006,'_ERROR_NORESULT');
  585. }
  586. }else{
  587. return new IXR_Error($error['code'],$error['msg']);
  588. }
  589. }
  590. function EncList($args){
  591. return _enclist($args,'searchEncounterBasicInfo');
  592. }
  593. function EncOutpatientList($args){
  594. return _enclist($args,'searchOutpatientBasicInfo');
  595. }
  596. function EncInpatientList($args){
  597. return _enclist($args,'searchInpatientBasicInfo');
  598. }
  599. function EncSearch($args){
  600. global $enc,$error;
  601. if(checkAccess($args[0])){
  602. $buf=$enc->searchEncounterBasicInfo($args[1]);
  603. if ($buf){
  604. return $buf->GetArray();
  605. }else{
  606. return new IXR_Error(1006,'_ERROR_NORESULT');
  607. }
  608. }else{
  609. return new IXR_Error($error['code'],$error['msg']);
  610. }
  611. }
  612. function EncExists($args){
  613. global $enc,$error;
  614. if(checkAccess($args[0])){
  615. $buf=$enc->EncounterExists($args[1]);
  616. if ($buf){
  617. return $buf;
  618. }else{
  619. return new IXR_Error(1006,'_ERROR_NORESULT');
  620. }
  621. }else{
  622. return new IXR_Error($error['code'],$error['msg']);
  623. }
  624. }
  625. function EncPID($args){
  626. return EncExists($args);
  627. }
  628. function _encvalue($args,$method){
  629. global $enc,$error;
  630. if(checkAccess($args[0])){
  631. $buf=$enc->$method($args[1]);
  632. if ($buf){
  633. return $buf;
  634. }else{
  635. return new IXR_Error(1006,'_ERROR_NORESULT');
  636. }
  637. }else{
  638. return new IXR_Error($error['code'],$error['msg']);
  639. }
  640. }
  641. function EncAdmitDate($args){
  642. return _encvalue($args,'EncounterDate');
  643. }
  644. function EncAdmitType($args){
  645. return _encvalue($args,'EncounterType');
  646. }
  647. /**
  648. * @private
  649. */
  650. function _getValue($args,$item){
  651. global $enc,$error;
  652. if(checkAccess($args[0])){
  653. return $enc->getValue($item,$args[1]);
  654. }else{
  655. return new IXR_Error($error['code'],$error['msg']);
  656. }
  657. }
  658. function EncDischargeDate($args){
  659. return 1;
  660. }
  661. function EncDischargeTime($args){
  662. return 1;
  663. }
  664. function EncDischargeType($args){
  665. return 1;
  666. }
  667. function EncIsDischarge($args){
  668. return 1;
  669. }
  670. function EncPayType($args){
  671. return _getvalue($args,'financial_class');
  672. }
  673. function EncDeptCurrentNr($args){
  674. return _encvalue($args,'CurrentDeptNr');
  675. }
  676. function EncDeptIsIn($args){
  677. return _encvalue($args,'In_Dept');
  678. }
  679. function EncWardCurrentNr($args){
  680. return _encvalue($args,'CurrentWardNr');
  681. }
  682. function EncWardIsIn($args){
  683. return _encvalue($args,'In_Ward');
  684. }
  685. function EncFirmCurrentNr($args){
  686. return _encvalue($args,'CurrentFirmNr');
  687. }
  688. function EncAttdDr($args){
  689. return _encvalue($args,'CurrentAttDrNr');
  690. }
  691. function EncConsultingDr($args){
  692. return _encvalue($args,'ConsultingDr');
  693. }
  694. function EncStatus($args){
  695. return _encvalue($args,'EncounterStatus');
  696. }
  697. function EncReferer($args){
  698. return _encvalue($args,'Referer');
  699. }
  700. function EncRefererDept($args){
  701. return _encvalue($args,'RefererDept');
  702. }
  703. function EncRefererInst($args){
  704. return _encvalue($args,'RefererInstitution');
  705. }
  706. function EncRefererNotes($args){
  707. return _encvalue($args,'RefererNotes');
  708. }
  709. function EncRefererDiagnosis($args){
  710. return _encvalue($args,'RefererDiagnosis');
  711. }
  712. function EncRecomTherapy($args){
  713. return _encvalue($args,'RefererRecomTherapy');
  714. }
  715. function EncPostEncNotes($args){
  716. return _encvalue($args,'PostEncounterNotes');
  717. }
  718. function EncFollowUpResp($args){
  719. return _encvalue($args,'FollowUpResponsibility');
  720. }
  721. function EncFollowUpDate($args){
  722. return _encvalue($args,'FollowUpDate');
  723. }
  724. function EncExtraService($args){
  725. return 1;
  726. }
  727. function EncRecStatus($args){
  728. return _encvalue($args,'RecordStatus');
  729. }
  730. function EncRecHistory($args){
  731. return _encvalue($args,'RecordHistory');
  732. }
  733. /**
  734. * @private
  735. */
  736. function _setRecordStatus($args,$stat=''){
  737. global $enc,$error;
  738. if(checkAccess($args[0])){
  739. $enc->setWhereCondition('encounter_nr='.$args[1]);
  740. $data['status']=$stat;
  741. $data['modify_time']=date('YmdHis');
  742. $date['modify_id']=$args[0]['usr'];
  743. $enc->setDataArray($data);
  744. if ($enc->updateDataFromInternalArray($args[1])){
  745. return TRUE;
  746. }else{
  747. return new IXR_Error(1006,'_ERROR_NORESULT');
  748. }
  749. }else{
  750. return new IXR_Error($error['code'],$error['msg']);
  751. }
  752. }
  753. function EncRecHide($args){
  754. return _setRecordStatus($args,'hidden');
  755. }
  756. function EncRecLock($args){
  757. return _setRecordStatus($args,'locked');
  758. }
  759. function EncRecDelete($args){
  760. return _setRecordStatus($args,'deleted');
  761. }
  762. function EncRecNormal($args){
  763. return _setRecordStatus($args,'normal');
  764. }
  765. function EncRecInvalidate($args){
  766. return _setRecordStatus($args,'invalid');
  767. }
  768. function EncRecEmpty($args){
  769. return _setRecordStatus($args);
  770. }
  771. ######### EMR (Electronic Medical Calls #######
  772. function EMRImageAdd($args){
  773. return _ImageAdd($args,'encounter');
  774. }
  775. /*
  776. * Private image adder
  777. */
  778. function _ImageAdd($args,$type){
  779. global $root_path, $img, $error, $person,$httprotocol,$main_domain;
  780. $picdir= $args[1];
  781. $type='encounter';
  782. if(checkAccess($args[0])){
  783. include($root_path.'global_conf/inc_remoteservers_conf.php');
  784. $d=$root_path."photos/$type/$picdir";
  785. # Try to get the extension
  786. if(empty($args[2]['ext'])){
  787. if(!empty($args[2]['mime_type'])){
  788. if(stristr($args[2]['mime_type'],'gif')){
  789. $picext='gif';
  790. }elseif(stristr($args[2]['mime_type'],'jpg')){
  791. $picext='jpg';
  792. }elseif(stristr($args[2]['mime_type'],'jpeg')){
  793. $picext='jpeg';
  794. }elseif(stristr($args[2]['mime_type'],'png')){
  795. $picext='png';
  796. }
  797. }
  798. }else{
  799. $picext = $args[2]['ext'];
  800. }
  801. if(!empty($picext)&&(stristr($picext,'gif')||stristr($picext,'jpg')||stristr($picext,'png')||stristr($picext,'jpeg'))){
  802. # Prepare the data for saving to the db
  803. $data=array('encounter_nr'=>$args[1],
  804. 'upload_date'=>date('Y-m-d'),
  805. 'notes'=>$args[2]['notes']."\n ".date('Y-m-d H:i:s')." by ".$args[0]['usr']." via HXP\n",
  806. 'history'=>"HXP upload ".date('Y-m-d H:i:s')." ".$args[0]['usr']."\n",
  807. 'modify_time'=>0,
  808. 'create_id'=>$args[0]['usr'],
  809. 'create_time'=>date('YmdHis'),
  810. 'shot_date' => $args[2]['shot_date'],
  811. 'shot_nr' => 1,
  812. 'mime_type' => $picext);
  813. if($pknr = $img->saveImageData($data)){
  814. # Find the last inserted primary key based on the db type
  815. $picnr = $img->LastInsertPK('nr',$pknr);
  816. $picfilename = $picnr.'.'.$picext;
  817. if(!is_dir($d)){
  818. // if $d directory not exist create it with CHMOD 777
  819. mkdir($d,0777);
  820. // Copy the trap files to this new directory
  821. copy($root_path."photos/$type/donotremove/index.htm",$d.'/index.htm');
  822. copy($root_path."photos/$type/donotremove/index.php",$d.'/index.php');
  823. }
  824. // Store to the newly created directory
  825. $newfilepath="$d/$picfilename";
  826. if($fp=fopen($newfilepath,'wb')){
  827. fwrite($fp,base64_decode($args[2]['img']));
  828. fclose($fp);
  829. return "$photoserver_http$type/$picdir/$picfilename";
  830. }else{
  831. # Delete the table record
  832. $img->Transact("DELETE FROM care_encounter_image WHERE nr=$picnr");
  833. return new IXR_Error(1100,'_ERROR_FILE_NOCREATE');
  834. }
  835. }else{
  836. return new IXR_Error(1108,'_ERROR_SQL_NOSAVE');
  837. }
  838. }else{
  839. return new IXR_Error(1105,'_ERROR_FILE_INVALID');
  840. }
  841. }else{
  842. return new IXR_Error($error['code'],$error['msg']);
  843. }
  844. }
  845. function EMRImageURLList($args){
  846. global $root_path, $db, $error, $img;
  847. if(checkAccess($args[0])){
  848. include($root_path.'global_conf/inc_remoteservers_conf.php');
  849. # Prepare the main path for the image
  850. $picdir= $args[1];
  851. $d = $photoserver_localpath.$picdir;
  852. $sql="SELECT nr,mime_type FROM $img->coretable WHERE encounter_nr=".$args[1];
  853. if($buff=$db->Execute($sql)) {
  854. if($rec_count=$buff->RecordCount()) {
  855. while($row=$buff->FetchRow()){
  856. $data[]="http://$main_domain/$d/".$row['nr'].'.'.$row['mime_type'];
  857. }
  858. return $data;
  859. } else { return new IXR_Error(1301,'_ERROR_SQL_NORESULT');}
  860. } else { return new IXR_Error(1300,'_ERROR_SQL_QUERY');}
  861. }else{
  862. return new IXR_Error($error['code'],$error['msg']);
  863. }
  864. }
  865. ######### System Calls ############
  866. function SysAdvServerExists(){
  867. return FALSE;
  868. }
  869. function SysHdrKeyslang(){
  870. return FALSE;
  871. }
  872. function SysHdrKeyssid(){
  873. return FALSE;
  874. }
  875. function SysHdrKeysversion(){
  876. return '0.1';
  877. }
  878. /* Create the server and map the XML-RPC method names to the relevant functions */
  879. $server = new IXR_Server(array(
  880. 'Person'=>'Person',
  881. 'Person.Basic'=>'PersonBasic',
  882. 'Person.Infostring'=>'PersonInfostring',
  883. 'Person.Exists'=>'PersonExists',
  884. 'Person.Save'=>'PersonSave',
  885. 'Person.Update'=>'PersonUpdate',
  886. 'Person.List'=>'PersonList',
  887. 'Person.Encounter'=>'PersonEnc',
  888. 'Person.Encounter.Search'=>'PersonEncSearch',
  889. 'Person.Search'=>'PersonSearch',
  890. 'Person.Search.Select'=>'PersonSearchSelect',
  891. 'Person.Name.First'=>'PersonNameFirst',
  892. 'Person.Name.Family'=>'PersonNameFamily',
  893. 'Person.Name.Middle'=>'PersonNameMiddle',
  894. 'Person.Name.Maiden'=>'PersonNameMaiden',
  895. 'Person.Name.Second'=>'PersonNameSecond',
  896. 'Person.Name.Third'=>'PersonNameThird',
  897. 'Person.Name.Others'=>'PersonNameOthers',
  898. 'Person.Birth.Date'=>'PersonBirthDate',
  899. 'Person.Birth.Details'=>'PersonBirthDetails',
  900. 'Person.Died.Date'=>'PersonDiedDate',
  901. 'Person.Registry.Date'=>'PersonRegDate',
  902. 'Person.Appointment'=>'PersonAppt',
  903. 'Person.Appointment.List'=>'PersonApptList',
  904. 'Person.Address'=>'PersonAddrs',
  905. 'Person.Address.FullText'=>'PersonAddrsTxt',
  906. 'Person.Address.Street'=>'PersonAddrsStr',
  907. 'Person.Address.Street.Nr'=>'PersonAddrsStrNr',
  908. 'Person.Address.CityTown'=>'PersonAddrsCTown',
  909. 'Person.Address.Zip'=>'PersonAddrsZip',
  910. 'Person.Address.Email'=>'PersonAddrEmail',
  911. 'Person.Phone.1'=>'PersonPhone1',
  912. 'Person.Phone.1.Area.Code'=>'PersonPhoneACode1',
  913. 'Person.Phone.2'=>'PersonPhone2',
  914. 'Person.Phone.2.Area.Code'=>'PersonPhoneACode2',
  915. 'Person.Phone.Cell.1'=>'PersonCellPhone1',
  916. 'Person.Phone.Cell.2'=>'PersonCellPhone2',
  917. 'Person.Fax.Nr'=>'PersonFaxNr',
  918. 'Person.Blood.Group'=>'PersonBloodGroup',
  919. 'Person.Mother.PID'=>'PersonAddr',
  920. 'Person.Father.PID'=>'PersonAddr',
  921. 'Person.Contact'=>'PersonContact',
  922. 'Person.Contact.PID'=>'PersonContactPID',
  923. 'Person.Contact.Relation'=>'PersonContactRelation',
  924. 'Person.Org.ID'=>'PersonOrgID',
  925. 'Person.SS.Nr'=>'PersonContactRelation',
  926. 'Person.National.ID.Nr'=>'PersonContactRelation',
  927. 'Person.Photo'=>'PersonPhoto',
  928. 'Person.Photo.Filename'=>'PersonPhotoFilename',
  929. 'Person.Religion'=>'PersonReligion',
  930. 'Person.Ethnic.Origin'=>'PersonEthnicOrig',
  931. 'Person.Insurance.1.Nr'=>'PersonInsNr1',
  932. 'Person.Insurance.1.Co.ID'=>'PersonInsCoID1',
  933. 'Person.Insurance.2.Nr'=>'PersonInsNr2',
  934. 'Person.Insurance.2.Co.ID'=>'PersonInsCoID2',
  935. 'Person.Add'=>'PersonAdd',
  936. 'Person.Update'=>'PersonUpdate',
  937. 'Person.Record.Update.Date'=>'PersonRecUpdateDate',
  938. 'Person.Record.Status'=>'PersonRecStatus',
  939. 'Person.Record.Status.Hide'=>'PersonRecHide',
  940. 'Person.Record.Status.Lock'=>'PersonRecLock',
  941. 'Person.Record.Status.Delete'=>'PersonRecDelete',
  942. 'Person.Record.Status.Normalize'=>'PersonRecNormalize',
  943. 'Person.Record.Status.Invalidate'=>'PersonRecInvalidate',
  944. 'Person.Record.History'=>'PersonRecHistory',
  945. 'Person.Encounter.Current.Nr'=>'PersonEncCurrNr',
  946. 'Person.PhotoID.URL'=>'PersonPhotoIDURL',
  947. 'Person.PhotoID.Save'=>'PersonPhotoIDSave',
  948. 'Person.Image.Add'=>'PersonImageAdd',
  949. 'Encounter'=>'Enc',
  950. 'Encounter.Infostring'=>'EncInfostring',
  951. 'Encounter.List'=>'EncList',
  952. 'Encounter.Outpatient.List'=>'EncOutpatientList',
  953. 'Encounter.Inpatient.List'=>'EncInpatientList',
  954. 'Encounter.Exists'=>'EncExists',
  955. 'Encounter.Search'=>'EncSearch',
  956. 'Encounter.Status'=>'EncStatus',
  957. 'Encounter.PID'=>'EncPID',
  958. 'Encounter.Admission.Date'=>'EncAdmitDate',
  959. 'Encounter.Admission.Type'=>'EncAdmitType',
  960. 'Encounter.Discharge.Time'=>'EncDischargeTime',
  961. 'Encounter.Discharge.Is'=>'EncIsDischarge',
  962. 'Encounter.Discharge.Type'=>'EncDischargeType',
  963. 'Encounter.Payment.Type'=>'EncPayType',
  964. 'Encounter.Dept.Current.Nr'=>'EncDeptCurrentNr',
  965. 'Encounter.Firm.Current.Nr'=>'EncFirmCurrentNr',
  966. 'Encounter.Doctor.Attending'=>'EncAttdDr',
  967. 'Encounter.Doctor.Consulting'=>'EncConsultingDr',
  968. 'Encounter.Referer'=>'EncReferer',
  969. 'Encounter.Referer.Diagnosis'=>'EncRefererDiagnosis',
  970. 'Encounter.Referer.Therapy.Recommend'=>'EncRecomTherapy',
  971. 'Encounter.Referer.Notes'=>'EncRefererNotes',
  972. 'Encounter.Referer.Dept'=>'EncRefererDept',
  973. 'Encounter.Referer.Institution'=>'EncRefererInst',
  974. 'Encounter.Dept.Is.In'=>'EncDeptIsIn',
  975. 'Encounter.Ward.Current.Nr'=>'EncWardCurrentNr',
  976. 'Encounter.Ward.Is.In'=>'EncWardIsIn',
  977. 'Encounter.Followup.Date'=>'EncFollowUpDate',
  978. 'Encounter.Followup.Responsibility'=>'EncFollowUpResp',
  979. 'Encounter.Post.Notes'=>'EncPostNotes',
  980. 'Encounter.Service.Extra'=>'EncExtraService',
  981. 'Encounter.Record.Status'=>'EncRecStatus',
  982. 'Encounter.Record.Status.Hide'=>'EncRecHide',
  983. 'Encounter.Record.Status.Lock'=>'EncRecLock',
  984. 'Encounter.Record.Status.Delete'=>'EncRecDelete',
  985. 'Encounter.Record.Status.Normalize'=>'EncRecNormalize',
  986. 'Encounter.Record.Status.Invalidate'=>'EncRecInvalidate',
  987. 'Encounter.Record.History'=>'EncRecHistory',
  988. 'Encounter.Pregnancy'=>'EncWardIsIn',
  989. 'Encounter.Followup.Responsible'=>'EncFollowUpResp',
  990. 'EMR.Image.Add'=>'EMRImageAdd',
  991. 'EMR.Image.URL.List'=>'EMRImageURLList',
  992. 'EMR.Image.URL'=>'EMRImageURL',
  993. 'EMR.Image'=>'EMRImage',
  994. 'system.Server.Advanced.Exists'=>'SysAdvServerExists',
  995. 'system.Header.Keys.lang'=>'SysHdrKeysLang',
  996. 'system.Header.Keys.sid'=>'SysHdrKeyssid',
  997. 'system.Header.Keys.version'=>'SysHdrKeysversion'
  998. ));