/controllers/C_PatientFinder.class.php

https://github.com/ranjanprasad/openemr · PHP · 141 lines · 81 code · 18 blank · 42 comment · 11 complexity · 2be0f4d1f7f84422904c1f53c4e68a74 MD5 · raw file

  1. <?php
  2. require_once ($GLOBALS['fileroot'] . "/library/classes/Controller.class.php");
  3. require_once($GLOBALS['fileroot'] ."/library/classes/Provider.class.php");
  4. require_once($GLOBALS['fileroot'] ."/library/classes/InsuranceNumbers.class.php");
  5. class C_PatientFinder extends Controller {
  6. var $template_mod;
  7. var $_db;
  8. function C_PatientFinder($template_mod = "general") {
  9. parent::Controller();
  10. $this->_db = $GLOBALS['adodb']['db'];
  11. $this->template_mod = $template_mod;
  12. $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . $_SERVER['QUERY_STRING']);
  13. ///////////////////////////////////
  14. //// What should this be?????
  15. //////////////////////////////////
  16. $this->assign("CURRENT_ACTION", $GLOBALS['webroot']."/controller.php?" . "practice_settings&patient_finder&");
  17. /////////////////////////////////
  18. $this->assign("STYLE", $GLOBALS['style']);
  19. }
  20. function default_action($form_id='',$form_name='',$pid='') {
  21. return $this->find_action($form_id,$form_name,$pid);
  22. }
  23. /**
  24. * Function that will display a patient finder widged, allowing
  25. * the user to input search parameters to find a patient id.
  26. */
  27. function find_action($form_id, $form_name,$pid) {
  28. $isPid = false;
  29. //fix any magic quotes meddling
  30. if (get_magic_quotes_gpc()) {$form_id = stripslashes($form_id);}
  31. if (get_magic_quotes_gpc()) {$form_name = stripslashes($form_name);}
  32. if (get_magic_quotes_gpc()) {$pid = stripslashes($pid);}
  33. //prevent javascript injection, whitespace and semi-colons are the worry
  34. $form_id = preg_replace("/[^A-Za-z0-9\[\]\_\']/iS","",urldecode($form_id));
  35. $form_name = preg_replace("/[^A-Za-z0-9\[\]\_\']/iS","",urldecode($form_name));
  36. $this->assign('form_id', $form_id);
  37. $this->assign('form_name', $form_name);
  38. if(!empty($pid))
  39. $isPid = true;
  40. $this->assign('hidden_ispid', $isPid);
  41. return $this->fetch($GLOBALS['template_dir'] . "patient_finder/" . $this->template_mod . "_find.html");
  42. }
  43. /**
  44. * Function that will take a search string, parse it out and return all patients from the db matching.
  45. * @param string $search_string - String from html form giving us our search parameters
  46. */
  47. function find_action_process() {
  48. if ($_POST['process'] != "true")
  49. return;
  50. $isPub = false;
  51. $search_string = $_POST['searchstring'];
  52. if(!empty($_POST['pid']))
  53. {
  54. $isPub = !$_POST['pid'];
  55. }
  56. //get the db connection and pass it to the helper functions
  57. $sql = "SELECT CONCAT(lname, ' ', fname, ' ', mname) as name, DOB, pubpid, pid FROM patient_data";
  58. //parse search_string to determine what type of search we have
  59. $pos = strpos($search_string, ',');
  60. // get result set into array and pass to array
  61. $result_array = array();
  62. if($pos === false) {
  63. //no comma just last name
  64. $result_array = $this->search_by_lName($sql, $search_string);
  65. }
  66. else if($pos === 0){
  67. //first name only
  68. $result_array = $this->search_by_fName($sql, $search_string);
  69. }
  70. else {
  71. //last and first at least
  72. $result_array = $this->search_by_FullName($sql,$search_string);
  73. }
  74. $this->assign('search_string',$search_string);
  75. $this->assign('result_set', $result_array);
  76. $this->assign('ispub', $isPub);
  77. // we're done
  78. $_POST['process'] = "";
  79. }
  80. /**
  81. * Function that returns an array containing the
  82. * Results of a LastName search
  83. * @-param string $sql base sql query
  84. * @-param string $search_string parsed for last name
  85. */
  86. function search_by_lName($sql, $search_string) {
  87. $lName = mysql_real_escape_string($search_string);
  88. $sql .= " WHERE lname LIKE '$lName%' ORDER BY lname, fname";
  89. //print "SQL is $sql \n";
  90. $result_array = $this->_db->GetAll($sql);
  91. //print_r($result_array);
  92. return $result_array;
  93. }
  94. /**
  95. * Function that returns an array containing the
  96. * Results of a FirstName search
  97. * @param string $sql base sql query
  98. * @param string $search_string parsed for first name
  99. */
  100. function search_by_fName($sql, $search_string) {
  101. $name_array = split(",", $search_string);
  102. $fName = mysql_real_escape_string( trim($name_array[1]) );
  103. $sql .= " WHERE fname LIKE '$fName%' ORDER BY lname, fname";
  104. $result_array = $this->_db->GetAll($sql);
  105. return $result_array;
  106. }
  107. /**
  108. * Function that returns an array containing the
  109. * Results of a Full Name search
  110. * @param string $sql base sql query
  111. * @param string $search_string parsed for first, last and middle name
  112. */
  113. function search_by_FullName($sql, $search_string) {
  114. $name_array = split(",", $search_string);
  115. $lName = mysql_real_escape_string($name_array[0]);
  116. $fName = mysql_real_escape_string( trim($name_array[1]) );
  117. $sql .= " WHERE fname LIKE '%$fName%' AND lname LIKE '$lName%' ORDER BY lname, fname";
  118. //print "SQL is $sql \n";
  119. $result_array = $this->_db->GetAll($sql);
  120. return $result_array;
  121. }
  122. }
  123. ?>