PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/registration_admission/admission_data_search.php

https://github.com/timschofield/2.8
PHP | 399 lines | 245 code | 75 blank | 79 comment | 49 complexity | 96ba318cb0714e151b67b9435596d1a4 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-2.0
  1. <?php
  2. error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
  3. require('./roots.php');
  4. require('../../include/helpers/inc_environment_global.php');
  5. /**
  6. * CARE2X Integrated Hospital Information System beta 2.0.1 - 2004-07-04
  7. * GNU General Public License
  8. * Copyright 2002,2003,2004,2005,2006 Elpidio Latorilla
  9. * elpidio@care2x.org,
  10. *
  11. * See the file "copy_notice.txt" for the licence notice
  12. */
  13. # Default value for the maximum nr of rows per block displayed, define this to the value you wish
  14. # In normal cases this value is derived from the db table "care_config_global" using the "pagin_insurance_list_max_block_rows" element.
  15. ///$db->debug=true;
  16. define('MAX_BLOCK_ROWS',30);
  17. define('MODULE','registration_admission');
  18. define('LANG_FILE_MODULAR','registration_admission.php');
  19. $local_user='aufnahme_user';
  20. require($root_path.'include/helpers/inc_front_chain_lang.php');
  21. require_once($root_path.'include/helpers/inc_date_format_functions.php');
  22. $thisfile=basename(__FILE__);
  23. $toggle=0;
  24. if($_COOKIE['ck_login_logged'.$sid]) $breakfile=$root_path.'modules/news/start_page.php'.URL_APPEND;
  25. else $breakfile='admission_pass.php'.URL_APPEND.'&target=entry';
  26. # Set value for the search mask
  27. $searchprompt=$LDEntryPrompt;
  28. # Special case for direct access from patient listings
  29. # If forward nr ok, use it as searchkey
  30. if(isset($fwd_nr)&&$fwd_nr&&is_numeric($fwd_nr)){
  31. $searchkey=$fwd_nr;
  32. $mode='search';
  33. }else{
  34. if(!isset($searchkey)) $searchkey='';
  35. }
  36. if(!isset($mode)) $mode='';
  37. // Initialize page's control variables
  38. if($mode=='paginate'){
  39. $searchkey=$_SESSION['sess_searchkey'];
  40. }else{
  41. # Reset paginator variables
  42. $pgx=0;
  43. $totalcount=0;
  44. $odir='';
  45. $oitem='';
  46. }
  47. #Load and create paginator object
  48. require_once($root_path.'include/core/class_paginator.php');
  49. $pagen=new Paginator($pgx,$thisfile,$_SESSION['sess_searchkey'],$root_path);
  50. if(isset($mode)&&($mode=='search'||$mode=='paginate')&&isset($searchkey)&&($searchkey)){
  51. include_once($root_path.'include/helpers/inc_date_format_functions.php');
  52. //$db->debug=true;
  53. if($mode!='paginate'){
  54. $_SESSION['sess_searchkey']=$searchkey;
  55. }
  56. # convert * and ? to % and &
  57. $searchkey=strtr($searchkey,'*?','%_');
  58. $GLOBAL_CONFIG=array();
  59. include_once($root_path.'include/core/class_globalconfig.php');
  60. $glob_obj=new GlobalConfig($GLOBAL_CONFIG);
  61. # Get the max nr of rows from global config
  62. $glob_obj->getConfig('pagin_patient_search_max_block_rows');
  63. if(empty($GLOBAL_CONFIG['pagin_patient_search_max_block_rows'])) $pagen->setMaxCount(MAX_BLOCK_ROWS); # Last resort, use the default defined at the start of this page
  64. else $pagen->setMaxCount($GLOBAL_CONFIG['pagin_patient_search_max_block_rows']);
  65. $searchkey=trim($searchkey);
  66. $suchwort=$searchkey;
  67. if(is_numeric($suchwort)) {
  68. $suchwort=(int) $suchwort;
  69. $numeric=1;
  70. if(empty($oitem)) $oitem='encounter_nr';
  71. if(empty($odir)) $odir='DESC'; # default, latest pid at top
  72. $sql2=" WHERE ( enc.encounter_nr='$suchwort' OR enc.encounter_nr $sql_LIKE '%.$suchwort' )";
  73. } else {
  74. # Try to detect if searchkey is composite of first name + last name
  75. if(stristr($searchkey,',')){
  76. $lastnamefirst=TRUE;
  77. }else{
  78. $lastnamefirst=FALSE;
  79. }
  80. $searchkey=strtr($searchkey,',',' ');
  81. $cbuffer=explode(' ',$searchkey);
  82. # Remove empty variables
  83. for($x=0;$x<sizeof($cbuffer);$x++){
  84. $cbuffer[$x]=trim($cbuffer[$x]);
  85. if($cbuffer[$x]!='') $comp[]=$cbuffer[$x];
  86. }
  87. # Arrange the values, ln= lastname, fn=first name, bd = birthday
  88. if($lastnamefirst){
  89. $fn=$comp[1];
  90. $ln=$comp[0];
  91. $bd=$comp[2];
  92. }else{
  93. $fn=$comp[0];
  94. $ln=$comp[1];
  95. $bd=$comp[2];
  96. }
  97. if(empty($oitem)) $oitem='name_last';
  98. # Check the size of the comp
  99. if(sizeof($comp)>1){
  100. $sql2=" WHERE ( reg.name_last $sql_LIKE '".strtr($ln,'+',' ')."%'
  101. AND reg.name_first $sql_LIKE '".strtr($fn,'+',' ')."%')";
  102. if($bd){
  103. $stddate=formatDate2STD($bd,$date_format);
  104. if(!empty($stddate)){
  105. $sql2.=" AND (reg.date_birth = '$stddate' OR reg.date_birth $sql_LIKE '%$bd%')";
  106. }
  107. }
  108. if(empty($odir)) $odir='DESC'; # default, latest birth at top
  109. }else{
  110. $sql2=" WHERE (reg.name_last $sql_LIKE '".strtr($suchwort,'+',' ')."%'
  111. OR reg.name_first $sql_LIKE '".strtr($suchwort,'+',' ')."%'";
  112. $bufdate=formatDate2STD($suchwort,$date_format);
  113. if(!empty($bufdate)){
  114. $sql2.= " OR reg.date_birth $sql_LIKE '$bufdate'";
  115. }
  116. $sql2.=")";
  117. if(empty($odir)) $odir='ASC'; # default, ascending alphabetic
  118. }
  119. }
  120. //gjergji - hide patient info of other departements
  121. /* if(isset($_SESSION['department_nr']) && $_SESSION['department_nr'] != '' ) {
  122. $cond.=" AND ( ";
  123. while (list($key, $val) = each($_SESSION['department_nr'])) {
  124. $tmp .= "enc.current_dept_nr = " . $val . " OR ";
  125. }
  126. $cond .= substr($tmp,0,-4) ;
  127. $cond .= " ) " ;
  128. }
  129. $sql2 .= $cond;*/
  130. //end : gjergji
  131. $sql2.=" AND enc.pid=reg.pid
  132. AND enc.encounter_status <> 'cancelled'
  133. AND enc.is_discharged=0
  134. AND enc.status NOT IN ('void','hidden','inactive','deleted') ORDER BY ";
  135. # Filter if it is staff nr
  136. if($oitem=='encounter_nr') $sql2.='enc.'.$oitem.' '.$odir;
  137. else $sql2.='reg.'.$oitem.' '.$odir;
  138. $dbtable='FROM care_encounter as enc,care_person as reg ';
  139. $sql='SELECT enc.encounter_nr, enc.encounter_class_nr, enc.is_discharged,
  140. reg.name_last, reg.name_first, reg.date_birth, reg.addr_zip,reg.sex '.$dbtable.$sql2;
  141. //echo $sql;
  142. if($ergebnis=$db->SelectLimit($sql,$pagen->MaxCount(),$pagen->BlockStartIndex()))
  143. {
  144. if ($linecount=$ergebnis->RecordCount())
  145. {
  146. if(($linecount==1)&&$numeric&&$mode=='search')
  147. {
  148. $zeile=$ergebnis->FetchRow();
  149. header('Location:admission_data_search.php'.URL_REDIRECT_APPEND.'&from=such&encounter_nr='.$zeile['encounter_nr'].'&target=search');
  150. exit;
  151. }
  152. $pagen->setTotalBlockCount($linecount);
  153. # If more than one count all available
  154. if(isset($totalcount)&&$totalcount){
  155. $pagen->setTotalDataCount($totalcount);
  156. }else{
  157. # Count total available data
  158. if($dbtype=='mysql' ){
  159. $sql='SELECT COUNT(enc.encounter_nr) AS "count" '.$dbtable.$sql2;
  160. }else{
  161. $sql='SELECT * '.$dbtable.$sql2;
  162. }
  163. if($result=$db->Execute($sql)){
  164. if ($totalcount=$result->RecordCount()) {
  165. if($dbtype=='mysql'){
  166. $rescount=$result->FetchRow();
  167. $totalcount=$rescount['count'];
  168. }
  169. }
  170. }
  171. $pagen->setTotalDataCount($totalcount);
  172. }
  173. # Set the sort parameters
  174. $pagen->setSortItem($oitem);
  175. $pagen->setSortDirection($odir);
  176. }
  177. }
  178. else {echo "<p>".$sql."<p>$LDDbNoRead";};
  179. }
  180. # Start Smarty templating here
  181. /**
  182. * LOAD Smarty
  183. */
  184. # Note: it is advisable to load this after the inc_front_chain_lang.php so
  185. # that the smarty script can use the user configured template theme
  186. require_once(CARE_BASE.'/include/helpers/smarty_care.class.php');
  187. $smarty = new smarty_care('common');
  188. # Title in the toolbar
  189. $smarty->assign('sToolbarTitle',"$LDAdmission :: $LDSearch");
  190. $smarty->assign('LDBack', $LDBack);
  191. $smarty->assign('LDHelp', $LDHelp);
  192. $smarty->assign('LDClose', $LDClose);
  193. $smarty->assign('breakfile',$breakfile);
  194. # Window bar title
  195. $smarty->assign('title',$LDPatientSearch);
  196. # href for help button
  197. $smarty->assign('pbHelp',CARE_GUI . "modules/" . MODULE . "/help/" . $lang . "/admission_how2search.html");
  198. # Onload Javascript code
  199. $smarty->assign('sOnLoadJs','onLoad="if(window.focus) window.focus();document.searchform.searchkey.select();"');
  200. # Hide the return button
  201. $smarty->assign('pbBack',FALSE);
  202. #
  203. # Load the tabs
  204. #
  205. $target='search';
  206. $parent_admit = TRUE;
  207. include('./gui_bridge/default/gui_tabs_patadmit.php');
  208. #
  209. # Prepare the javascript validator
  210. #
  211. if(!isset($searchform_count) || !$searchform_count){
  212. $smarty->assign('sJSFormCheck','<script language="javascript">
  213. <!--
  214. function chkSearch(d){
  215. if((d.searchkey.value=="") || (d.searchkey.value==" ")){
  216. d.searchkey.focus();
  217. return false;
  218. }else {
  219. return true;
  220. }
  221. }
  222. // -->
  223. </script>');
  224. }
  225. #
  226. # Prepare the form params
  227. #
  228. $sTemp = 'method="post" name="searchform';
  229. if($searchform_count) $sTemp = $sTemp."_".$searchform_count;
  230. $sTemp = $sTemp.'" onSubmit="return chkSearch(this)"';
  231. if(isset($search_script) && $search_script!='') $sTemp = $sTemp.' action="'.$search_script.'"';
  232. $smarty->assign('sFormParams',$sTemp);
  233. $smarty->assign('searchprompt',$searchprompt);
  234. #
  235. # Prepare the hidden inputs
  236. #
  237. $smarty->assign('sHiddenInputs','<button type="submit" class="button icon search"/>Search</button>
  238. <input type="hidden" name="sid" value="'.$sid.'">
  239. <input type="hidden" name="lang" value="'.$lang.'">
  240. <input type="hidden" name="noresize" value="'.$noresize.'">
  241. <input type="hidden" name="target" value="'.$target.'">
  242. <input type="hidden" name="user_origin" value="'.$user_origin.'">
  243. <input type="hidden" name="origin" value="'.$origin.'">
  244. <input type="hidden" name="retpath" value="'.$retpath.'">
  245. <input type="hidden" name="aux1" value="'.$aux1.'">
  246. <input type="hidden" name="ipath" value="'.$ipath.'">
  247. <input type="hidden" name="mode" value="search">');
  248. $smarty->assign('sCancelButton','<a href="patient.php'.URL_APPEND.'&target=search" class="button icon remove danger">Cancel</a>');
  249. if($mode=='search'||$mode=='paginate'){
  250. if ($linecount) $smarty->assign('LDSearchFound',str_replace("~nr~",$totalcount,$LDSearchFound).' '.$LDShowing.' '.$pagen->BlockStartNr().' '.$LDTo.' '.$pagen->BlockEndNr().'.');
  251. else $smarty->assign('LDSearchFound',str_replace('~nr~','0',$LDSearchFound));
  252. if ($linecount) {
  253. $smarty->assign('bShowResult',TRUE);
  254. # Load the common icons and images
  255. $img_options=createComIcon($root_path,'pdata.gif','0');
  256. $img_male=createComIcon($root_path,'spm.gif','0');
  257. $img_female=createComIcon($root_path,'spf.gif','0');
  258. $smarty->assign('LDCaseNr',$pagen->makeSortLink($LDCaseNr,'encounter_nr',$oitem,$odir,$targetappend));
  259. $smarty->assign('LDSex',$pagen->makeSortLink($LDSex,'sex',$oitem,$odir,$targetappend));
  260. $smarty->assign('LDLastName',$pagen->makeSortLink($LDLastName,'name_last',$oitem,$odir,$targetappend));
  261. $smarty->assign('LDFirstName',$pagen->makeSortLink($LDFirstName,'name_first',$oitem,$odir,$targetappend));
  262. $smarty->assign('LDBday',$pagen->makeSortLink($LDBday,'date_birth',$oitem,$odir,$targetappend));
  263. $smarty->assign('LDZipCode',$pagen->makeSortLink($LDZipCode,'addr_zip',$oitem,$odir,$targetappend));
  264. $smarty->assign('LDOptions',$LDOptions);
  265. $sTemp = '';
  266. while($zeile=$ergebnis->FetchRow()){
  267. $full_en=$zeile['encounter_nr'];
  268. $smarty->assign('toggle',$toggle);
  269. $toggle = !$toggle;
  270. $smarty->assign('sCaseNr',$full_en);
  271. if($zeile['encounter_class_nr']==2){
  272. $smarty->assign('sOutpatientIcon','<img '.createComIcon($root_path,'redflag.gif').'>');
  273. $smarty->assign('LDAmbulant',$LDAmbulant);
  274. }else{
  275. $smarty->assign('sOutpatientIcon','');
  276. $smarty->assign('LDAmbulant','');
  277. }
  278. switch(strtolower($zeile['sex'])){
  279. case 'f': $smarty->assign('sSex','<img '.$img_female.'>'); break;
  280. case 'm': $smarty->assign('sSex','<img '.$img_male.'>'); break;
  281. default: $smarty->assign('sSex','&nbsp;'); break;
  282. }
  283. $smarty->assign('sLastName',ucfirst($zeile['name_last']));
  284. $smarty->assign('sFirstName',ucfirst($zeile['name_first']));
  285. #
  286. # If person is dead show a black cross
  287. #
  288. if($zeile['death_date']&&$zeile['death_date']!=$dbf_nodate) $smarty->assign('sCrossIcon','<img '.createComIcon($root_path,'blackcross_sm.gif','0','absmiddle').'>');
  289. else $smarty->assign('sCrossIcon','');
  290. $smarty->assign('sBday',formatDate2Local($zeile['date_birth'],$date_format));
  291. $smarty->assign('sZipCode',$zeile['addr_zip']);
  292. $sTarget = "<a href=\"admission_data_search.php".URL_APPEND."&from=such&encounter_nr=$full_en&target=search\">";
  293. $sTarget=$sTarget.'<img '.$img_options.' title="'.$LDShowData.'"></a>';
  294. $smarty->assign('sOptions',$sTarget);
  295. if(!file_exists($root_path.'cache/barcodes/en_'.$full_en.'.png')){
  296. $smarty->assign('sHiddenBarcode',"<img src='".$root_path."classes/barcode/image.php?code=".$full_en."&style=68&type=I25&width=180&height=50&xres=2&font=5&label=2' border=0 width=0 height=0>");
  297. }
  298. #
  299. # Generate the row in buffer and append as string
  300. #
  301. ob_start();
  302. $smarty->display('registration_admission/admit_search_list_row.tpl');
  303. $sTemp = $sTemp.ob_get_contents();
  304. ob_end_clean();
  305. }
  306. #
  307. # Assign the rows string to template
  308. #
  309. $smarty->assign('sResultListRows',$sTemp);
  310. $smarty->assign('sPreviousPage',$pagen->makePrevLink($LDPrevious));
  311. $smarty->assign('sNextPage',$pagen->makeNextLink($LDNext));
  312. }
  313. }
  314. /*
  315. $smarty->assign('sPostText','<a href="admission_start.php'.URL_APPEND.'&mode=?">'.$LDAdmWantEntry.'</a><br>
  316. <a href="admission_list.php'.URL_APPEND.'">'.$LDAdmWantArchive.'</a>');
  317. */
  318. $smarty->assign('sPostText','<a href="admission_list.php'.URL_APPEND.'">'.$LDAdmWantArchive.'</a>');
  319. # Stop buffering, assign contents and display template
  320. $smarty->assign('sMainIncludeFile','registration_admission/admit_search_main.tpl');
  321. $smarty->assign('sMainBlockIncludeFile',__DIR__ . '/view/admit_plain.tpl');
  322. $smarty->display(CARE_BASE . 'main/view/mainframe.tpl');
  323. ?>