/src/Ben/UserBundle/Stats/StatsQuery.php

https://github.com/benaich/Doctors · PHP · 138 lines · 106 code · 19 blank · 13 comment · 3 complexity · a208ae5763daa70e77d5e0f6cde43325 MD5 · raw file

  1. <?php
  2. namespace Ben\UserBundle\Stats;
  3. Class StatsQuery{
  4. private $dateFrom;
  5. private $dateTo;
  6. private $rangeDate;
  7. function __construct($daterange = null){
  8. $pattern = '#^[0-9]{4}/[0-9]{1,2}/[0-9]{1,2} - [0-9]{4}/[0-9]{1,2}/[0-9]{1,2}$#';
  9. $this->rangeDate = '';
  10. if (preg_match($pattern, $daterange)) {
  11. $date = explode("-", $daterange);
  12. $this->dateFrom = $date[0];
  13. $this->dateTo = $date[1];
  14. $this->rangeDate .= (empty($this->dateFrom)) ? '' : " and c.created >= '".$this->dateFrom."'" ;
  15. $this->rangeDate .= (empty($this->dateTo)) ? '' : " and c.created <= '".$this->dateTo."'" ;
  16. }
  17. }
  18. public function getMeds()
  19. {
  20. return "select m.name as label, coalesce(sum(cm.count), 0 ) as data from meds m
  21. left join consultation_meds cm on cm.meds_id = m.id
  22. left join consultation c on cm.consultation_id = c.id
  23. where 1=1 {$this->rangeDate}
  24. group by m.id
  25. union
  26. select 'total' as label, sum(count) as data from consultation_meds cm
  27. left join consultation c on cm.consultation_id = c.id
  28. where 1=1 {$this->rangeDate}";
  29. }
  30. public function getConsultations()
  31. {
  32. return "select c.diagnosis as label, count(*) as data from consultation c where 1=1 {$this->rangeDate} group by label";
  33. }
  34. public function getStock()
  35. {
  36. return "select count(*) as data from meds c where 1=1 {$this->rangeDate}";
  37. }
  38. public function getGeneral_consultations()
  39. {
  40. return "select count(*) as data from consultation c where c.type = 'Consultation generale' {$this->rangeDate}";
  41. }
  42. public function getSpecial_consultations()
  43. {
  44. return "select count(*) as data from consultation c where c.type != 'Consultation generale' {$this->rangeDate}";
  45. }
  46. public function getOriented()
  47. {
  48. return "select count(*) as data from (select id from consultation c where c.type != 'Consultation generale' {$this->rangeDate} group by c.person_id)A";
  49. }
  50. /* Effectif des étudiants ayant une couverture sociale par type de couverture */
  51. public function getCnss()
  52. {
  53. return "select cnsstype as label, count(*) as data from person c where 1=1 {$this->rangeDate} group by label";
  54. }
  55. /* Nombre des consultations médicales à la demande */
  56. public function getConsultations_demande()
  57. {
  58. return "select count(*) as data from consultation c where motiftype = 'CONSULTATION MEDICALE A LA DEMANDE' {$this->rangeDate}";
  59. }
  60. /* Nombre des consultations médicales à la demande par sexe */
  61. public function getConsultations_demande_gender()
  62. {
  63. return "select gender as label, count(*) as data from person p inner join consultation c on c.person_id = p.id where motiftype = 'CONSULTATION MEDICALE A LA DEMANDE' {$this->rangeDate} group by gender";
  64. }
  65. /* Nombre des résidents ayant subi une consultation médicale à la demande */
  66. public function getConsultations_demande_resident()
  67. {
  68. return "select count(*) as data from person p inner join consultation c on c.person_id = p.id where motiftype = 'CONSULTATION MEDICALE A LA DEMANDE' and resident = true {$this->rangeDate}";
  69. }
  70. /* Nombre des résidents ayant subi une consultation médicale à la DEMANDE par sexe*/
  71. public function getConsultations_demande_resident_gender()
  72. {
  73. return "select gender as label, count(*) as data from person p inner join consultation c on c.person_id = p.id where motiftype = 'CONSULTATION MEDICALE A LA DEMANDE' and resident = true {$this->rangeDate} group by gender";
  74. }
  75. /* Nombre des résidents ayant subi un examen médical systématique */
  76. public function getConsultations_systematique_resident()
  77. {
  78. return "select count(*) as data from person p inner join consultation c on c.person_id = p.id where motiftype = 'EXAMEN MEDICAL SYSTEMATIQUE' and resident = true {$this->rangeDate}";
  79. }
  80. /* Nombre des résidents ayant subi un examen médical systématique par sexe */
  81. public function getConsultations_systematique_resident_gender()
  82. {
  83. return "select gender as label, count(*) as data from person p inner join consultation c on c.person_id = p.id where motiftype = 'EXAMEN MEDICAL SYSTEMATIQUE' and resident = true {$this->rangeDate} group by gender";
  84. }
  85. /* Nombre de cas de troubles visuels corrigés et non corrigés */
  86. public function getConsultations_visual_issue()
  87. {
  88. return "select fixedvisualissue as label, count(*) as data from test left join consultation c on c.id = test.consultation_id where hasvisualissue = 1 {$this->rangeDate} group by fixedvisualissue";
  89. }
  90. /* Nombre des malades orientés vers la consultation médicale spécialisée par spécialité médicale */
  91. public function getConsultations_special()
  92. {
  93. return "select name as label, count(*) as data from person p inner join consultation c on c.person_id = p.id where type = 'Consultation specialise' {$this->rangeDate} group by name";
  94. }
  95. /* Nombre des malades ayant subi une consultation médicale spécialisée par spécialité et par sexe */
  96. public function getConsultations_special_gender()
  97. {
  98. return "select gender, name as label, count(*) as data from person p inner join consultation c on c.person_id = p.id where type = 'Consultation specialise' {$this->rangeDate} group by name, gender";
  99. }
  100. /* Nombre de cas des maladies dépistées */
  101. public function getConsultations_chronic()
  102. {
  103. return "select count(*) as data from consultation c where chronic = 1 {$this->rangeDate}";
  104. }
  105. /* Nombre de cas des maladies dépistées */
  106. public function getConsultations_not_chronic()
  107. {
  108. return "select count(*) as data from consultation c where chronic = 0 {$this->rangeDate}";
  109. }
  110. /* Structures sanitaires de référence par structure */
  111. public function getConsultations_structures()
  112. {
  113. return "select infrastructure as label, count(*) as data from consultation c where type = 'Consultation specialise' {$this->rangeDate} group by label";
  114. }
  115. public function get($value)
  116. {
  117. return $this->{'get'.ucfirst($value)}();
  118. }
  119. }