/application/controllers/patient_statistics.php

https://github.com/eriknjenga/ADT · PHP · 195 lines · 178 code · 17 blank · 0 comment · 35 complexity · c1414cf7fbce0b23aa812b15d6e455a2 MD5 · raw file

  1. <?php
  2. if (!defined('BASEPATH'))
  3. exit('No direct script access allowed');
  4. class Patient_Statistics extends MY_Controller {
  5. function __construct() {
  6. parent::__construct();
  7. }
  8. public function index() {
  9. $this -> checks();
  10. }
  11. public function refills() {
  12. $data['facilities'] = Reporting_Facility::getAll();
  13. $data['current'] = "refills";
  14. $data['title'] = "Number of Patients Who Visited for a Refill";
  15. $data['banner_text'] = "Refill Patients";
  16. $data['content_view'] = "refill_patients_v";
  17. $this -> load -> view("national_template", $data);
  18. }
  19. public function patients_per_regimen() {
  20. $data['facilities'] = Reporting_Facility::getAll();
  21. $data['current'] = "patients_per_regimen";
  22. $data['title'] = "Number of Patients per Regimen";
  23. $data['banner_text'] = "Regimen Patients";
  24. $data['content_view'] = "patients_per_regimen_v";
  25. $this -> load -> view("national_template", $data);
  26. }
  27. public function service_breakdown() {
  28. $data['facilities'] = Reporting_Facility::getAll();
  29. $data['current'] = "service_breakdown";
  30. $data['title'] = "Breakdown of Patient Numbers";
  31. $data['banner_text'] = "Breakdown of Patient Numbers";
  32. $data['content_view'] = "service_breakdown_v";
  33. $this -> load -> view("national_template", $data);
  34. }
  35. public function service_breakdown_data($facility, $year) {
  36. $title = "Number of Active Patients by Treatment Stage";
  37. $this -> load -> database();
  38. $sql = "";
  39. if ($facility == "0") {
  40. $sql = "select count(*) as total, line from patient p left join regimen r on p.current_regimen = r.id where year(date_enrolled) = '$year' and current_status = '1' group by line";
  41. } else {
  42. $sql = "select count(*) as total, line from patient p left join regimen r on p.current_regimen = r.id where year(date_enrolled) = '$year' and current_status = '1' and facility_code = '$facility' group by line";
  43. }
  44. $result = $this -> db -> query($sql) -> result_array();
  45. $result_array = array();
  46. foreach ($result as $result_element) {
  47. if ($result_element['line'] == "1") {
  48. $result_array[$result_element['line']]['line'] = "First Line";
  49. $result_array[$result_element['line']]['total'] = $result_element['total'];
  50. } else if ($result_element['line'] == "2") {
  51. $result_array[$result_element['line']]['line'] = "Second Line";
  52. $result_array[$result_element['line']]['total'] = $result_element['total'];
  53. } else {
  54. $result_array["other"]['line'] = "Others";
  55. if (isset($result_array["other"]['total'])) {
  56. $result_array["other"]['total'] += $result_element['total'];
  57. } else {
  58. $result_array["other"]['total'] = $result_element['total'];
  59. }
  60. }
  61. }
  62. $chart = '<chart pieRadius="100" showPercentageValues="1" showPercentInToolTip="0" decimals="0" caption="' . $title . '" bgColor="FFFFFF" showBorder="0" bgAlpha="100" exportEnabled="1" exportHandler="' . base_url() . 'scripts/FusionCharts/ExportHandlers/PHP/FCExporter.php" exportAtClient="0" exportAction="download">';
  63. foreach ($result_array as $result_element) {
  64. $chart .= '<set label="' . $result_element['line'] . '" value="' . $result_element['total'] . '"/>';
  65. }
  66. $chart .= '</chart>';
  67. echo $chart;
  68. }
  69. public function service_type_breakdown_data($facility, $year) {
  70. $title = "Number of Active Patients by Service Type";
  71. $this -> load -> database();
  72. $sql = "";
  73. if ($facility == "0") {
  74. $sql = "select count(*) as total, line from patient p left join regimen r on p.current_regimen = r.id where year(date_enrolled) = '$year' and current_status = '1' group by line";
  75. } else {
  76. $sql = "select count(*) as total, line from patient p left join regimen r on p.current_regimen = r.id where year(date_enrolled) = '$year' and current_status = '1' and facility_code = '$facility' group by line";
  77. }
  78. $result = $this -> db -> query($sql) -> result_array();
  79. $result_array = array();
  80. foreach ($result as $result_element) {
  81. if ($result_element['line'] == "1") {
  82. $result_array[$result_element['line']]['line'] = "First Line";
  83. $result_array[$result_element['line']]['total'] = $result_element['total'];
  84. } else if ($result_element['line'] == "2") {
  85. $result_array[$result_element['line']]['line'] = "Second Line";
  86. $result_array[$result_element['line']]['total'] = $result_element['total'];
  87. } else {
  88. $result_array["other"]['line'] = "Others";
  89. if (isset($result_array["other"]['total'])) {
  90. $result_array["other"]['total'] += $result_element['total'];
  91. } else {
  92. $result_array["other"]['total'] = $result_element['total'];
  93. }
  94. }
  95. }
  96. $chart = '<chart pieRadius="100" showPercentageValues="1" showPercentInToolTip="0" decimals="0" caption="' . $title . '" bgColor="FFFFFF" showBorder="0" bgAlpha="100" exportEnabled="1" exportHandler="' . base_url() . 'scripts/FusionCharts/ExportHandlers/PHP/FCExporter.php" exportAtClient="0" exportAction="download">';
  97. foreach ($result_array as $result_element) {
  98. $chart .= '<set label="' . $result_element['line'] . '" value="' . $result_element['total'] . '"/>';
  99. }
  100. $chart .= '</chart>';
  101. echo $chart;
  102. }
  103. public function patient_regimens($facility, $year) {
  104. $title = "Number of Active Patients by Regimen";
  105. $this -> load -> database();
  106. $sql = "";
  107. if ($facility == "0") {
  108. $sql = "select count(*) as total,concat(regimen_desc,' (',regimen_code,')') as regimen_desc from patient p left join regimen r on p.current_regimen = r.id where year(date_enrolled) = '$year' and current_status = '1' group by current_regimen";
  109. } else {
  110. $sql = "select count(*) as total,concat(regimen_desc,' (',regimen_code,')') as regimen_desc from patient p left join regimen r on p.current_regimen = r.id where year(date_enrolled) = '$year' and current_status = '1' and facility_code = '$facility' group by current_regimen";
  111. }
  112. $result = $this -> db -> query($sql) -> result_array();
  113. $result_array = array();
  114. foreach ($result as $result_element) {
  115. $result_array[$result_element['regimen_desc']]['total'] = $result_element['total'];
  116. if (strlen($result_element['regimen_desc']) > 0) {
  117. $result_array[$result_element['regimen_desc']]['regimen'] = $result_element['regimen_desc'];
  118. } else {
  119. $result_array[$result_element['regimen_desc']]['regimen'] = "Unknown";
  120. }
  121. }
  122. $chart = '<chart pieRadius="200" showPercentageValues="1" showPercentInToolTip="0" decimals="0" caption="' . $title . '" bgColor="FFFFFF" showBorder="0" bgAlpha="100" exportEnabled="1" exportHandler="' . base_url() . 'scripts/FusionCharts/ExportHandlers/PHP/FCExporter.php" exportAtClient="0" exportAction="download">';
  123. foreach ($result_array as $result_element) {
  124. $chart .= '<set label="' . $result_element['regimen'] . '" value="' . $result_element['total'] . '"/>';
  125. }
  126. $chart .= '</chart>';
  127. echo $chart;
  128. }
  129. public function monthly_new_patients($facility, $year) {
  130. $title = "New Patients Per Month";
  131. $this -> load -> database();
  132. $sql = "";
  133. if ($facility == "0") {
  134. $sql = "select month(date_enrolled) as month,count(*) as total from patient where year(date_enrolled) = '$year' group by month(date_enrolled)";
  135. } else {
  136. $sql = "select month(date_enrolled) as month,count(*) as total from patient where year(date_enrolled) = '$year' and facility_code = '$facility' group by month(date_enrolled)";
  137. }
  138. $result = $this -> db -> query($sql) -> result_array();
  139. $result_array = array();
  140. foreach ($result as $result_element) {
  141. $result_array[$result_element['month']]['total'] = $result_element['total'];
  142. $result_array[$result_element['month']]['month'] = date("M", mktime(0, 0, 0, $result_element['month'], 1, $year));
  143. }
  144. $chart = '<chart xAxisName="Month" yAxisName="Total Number Enrolled" showPercentageValues="1" showPercentInToolTip="0" decimals="0" caption="' . $title . '" bgColor="FFFFFF" showBorder="0" bgAlpha="100" exportEnabled="1" exportHandler="' . base_url() . 'scripts/FusionCharts/ExportHandlers/PHP/FCExporter.php" exportAtClient="0" exportAction="download">';
  145. foreach ($result_array as $result_element) {
  146. $chart .= '<set label="' . $result_element['month'] . '" value="' . $result_element['total'] . '"/>';
  147. }
  148. $chart .= '</chart>';
  149. echo $chart;
  150. }
  151. public function refill_stats($facility, $year) {
  152. $title = "New Patients Per Month";
  153. $this -> load -> database();
  154. $sql = "";
  155. if ($facility == "0") {
  156. $sql = "select count(distinct patient_id) as total, month(dispensing_date) as month from patient_visit where visit_purpose = '2' and year(dispensing_date) = '$year' group by month(dispensing_date)";
  157. } else {
  158. $sql = "select count(distinct patient_id) as total, month(dispensing_date) as month from patient_visit where visit_purpose = '2' and year(dispensing_date) = '$year' and facility = '$facility' group by month(dispensing_date)";
  159. }
  160. $result = $this -> db -> query($sql) -> result_array();
  161. $result_array = array();
  162. foreach ($result as $result_element) {
  163. $result_array[$result_element['month']]['total'] = $result_element['total'];
  164. $result_array[$result_element['month']]['month'] = date("M", mktime(0, 0, 0, $result_element['month'], 1, $year));
  165. }
  166. $chart = '<chart xAxisName="Month" yAxisName="Total Number Enrolled" showPercentageValues="1" showPercentInToolTip="0" decimals="0" caption="' . $title . '" bgColor="FFFFFF" showBorder="0" bgAlpha="100" exportEnabled="1" exportHandler="' . base_url() . 'scripts/FusionCharts/ExportHandlers/PHP/FCExporter.php" exportAtClient="0" exportAction="download">';
  167. foreach ($result_array as $result_element) {
  168. $chart .= '<set label="' . $result_element['month'] . '" value="' . $result_element['total'] . '"/>';
  169. }
  170. $chart .= '</chart>';
  171. echo $chart;
  172. }
  173. public function base_params($data) {
  174. $data['title'] = "Survey | Checks";
  175. $data['current_link'] = "checks";
  176. $this -> load -> view('template', $data);
  177. }
  178. }