PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/library/classes/rulesets/Cqm/library/AbstractCqmReport.php

https://bitbucket.org/astawiarski/openemr
PHP | 161 lines | 14 code | 4 blank | 143 comment | 0 complexity | 389a6a967530acc82dedd96d504b8021 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-2.0, MPL-2.0
  1. <?php
  2. // Copyright (C) 2011 Ken Chapple <ken@mi-squared.com>
  3. //
  4. // This program is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU General Public License
  6. // as published by the Free Software Foundation; either version 2
  7. // of the License, or (at your option) any later version.
  8. //
  9. require_once( dirname(__FILE__)."/../../../../clinical_rules.php" );
  10. abstract class AbstractCqmReport implements RsReportIF
  11. {
  12. protected $_cqmPopulation;
  13. protected $_resultsArray = array();
  14. protected $_rowRule;
  15. protected $_ruleId;
  16. protected $_beginMeasurement;
  17. protected $_endMeasurement;
  18. public function __construct( array $rowRule, array $patientIdArray, $dateTarget )
  19. {
  20. // require all .php files in the report's sub-folder
  21. $className = get_class( $this );
  22. foreach ( glob( dirname(__FILE__)."/../reports/".$className."/*.php" ) as $filename ) {
  23. require_once( $filename );
  24. }
  25. // require common .php files
  26. foreach ( glob( dirname(__FILE__)."/../reports/common/*.php" ) as $filename ) {
  27. require_once( $filename );
  28. }
  29. // require clinical types
  30. foreach ( glob( dirname(__FILE__)."/../../../ClinicalTypes/*.php" ) as $filename ) {
  31. require_once( $filename );
  32. }
  33. $this->_cqmPopulation = new CqmPopulation( $patientIdArray );
  34. $this->_rowRule = $rowRule;
  35. $this->_ruleId = isset( $rowRule['id'] ) ? $rowRule['id'] : '';
  36. // Calculate measurement period
  37. $tempDateArray = explode( "-",$dateTarget );
  38. $tempYear = $tempDateArray[0];
  39. $this->_beginMeasurement = $tempDateArray[0] . "-01-01 00:00:00";
  40. $this->_endMeasurement = $tempDateArray[0] . "-12-31 23:59:59";
  41. }
  42. public abstract function createPopulationCriteria();
  43. public function getBeginMeasurement() {
  44. return $this->_beginMeasurement;
  45. }
  46. public function getEndMeasurement() {
  47. return $this->_endMeasurement;
  48. }
  49. public function getResults() {
  50. return $this->_resultsArray;
  51. }
  52. public function execute()
  53. {
  54. $populationCriterias = $this->createPopulationCriteria();
  55. if ( !is_array( $populationCriterias ) ) {
  56. $tmpPopulationCriterias = array();
  57. $tmpPopulationCriterias[]= $populationCriterias;
  58. $populationCriterias = $tmpPopulationCriterias;
  59. }
  60. foreach ( $populationCriterias as $populationCriteria )
  61. {
  62. if ( $populationCriteria instanceof CqmPopulationCrtiteriaFactory )
  63. {
  64. $initialPatientPopulationFilter = $populationCriteria->createInitialPatientPopulation();
  65. if ( !$initialPatientPopulationFilter instanceof CqmFilterIF ) {
  66. throw new Exception( "InitialPatientPopulation must be an instance of CqmFilterIF" );
  67. }
  68. $denominator = $populationCriteria->createDenominator();
  69. if ( !$denominator instanceof CqmFilterIF ) {
  70. throw new Exception( "Denominator must be an instance of CqmFilterIF" );
  71. }
  72. $numerators = $populationCriteria->createNumerators();
  73. if ( !is_array( $numerators ) ) {
  74. $tmpNumerators = array();
  75. $tmpNumerators[]= $numerators;
  76. $numerators = $tmpNumerators;
  77. }
  78. $exclusion = $populationCriteria->createExclusion();
  79. if ( !$exclusion instanceof CqmFilterIF ) {
  80. throw new Exception( "Exclusion must be an instance of CqmFilterIF" );
  81. }
  82. $totalPatients = count( $this->_cqmPopulation );
  83. $initialPatientPopulation = 0;
  84. $denominatorPatientPopulation = 0;
  85. $exclusionsPatientPopulation = 0;
  86. $numeratorPatientPopulations = $this->initNumeratorPopulations( $numerators );
  87. foreach ( $this->_cqmPopulation as $patient )
  88. {
  89. if ( !$initialPatientPopulationFilter->test( $patient, $this->_beginMeasurement, $this->_endMeasurement ) )
  90. {
  91. continue;
  92. }
  93. $initialPatientPopulation++;
  94. if ( !$denominator->test( $patient, $this->_beginMeasurement, $this->_endMeasurement ) )
  95. {
  96. continue;
  97. }
  98. $denominatorPatientPopulation++;
  99. if ( $exclusion->test( $patient, $this->_beginMeasurement, $this->_endMeasurement ) )
  100. {
  101. $exclusionsPatientPopulation++;
  102. }
  103. foreach ( $numerators as $numerator ) {
  104. $this->testNumerator( $patient, $numerator, $numeratorPatientPopulations );
  105. }
  106. }
  107. // tally results, run exclusion on each numerator
  108. $pass_filt = $denominatorPatientPopulation;
  109. $exclude_filt = $exclusionsPatientPopulation;
  110. foreach ( $numeratorPatientPopulations as $title => $pass_targ ) {
  111. $percentage = calculate_percentage( $pass_filt, $exclude_filt, $pass_targ );
  112. $this->_resultsArray[]= new CqmResult( $this->_rowRule, $title, $populationCriteria->getTitle(),
  113. $totalPatients, $pass_filt, $exclude_filt, $pass_targ, $percentage );
  114. }
  115. }
  116. }
  117. return $this->_resultsArray;
  118. }
  119. private function initNumeratorPopulations( array $numerators )
  120. {
  121. $numeratorPatientPopulations = array();
  122. foreach ( $numerators as $numerator ) {
  123. $numeratorPatientPopulations[$numerator->getTitle()] = 0;
  124. }
  125. return $numeratorPatientPopulations;
  126. }
  127. private function testNumerator( $patient, $numerator, &$numeratorPatientPopulations )
  128. {
  129. if ( $numerator instanceof CqmFilterIF )
  130. {
  131. if ( $numerator->test( $patient, $this->_beginMeasurement, $this->_endMeasurement ) ) {
  132. $numeratorPatientPopulations[$numerator->getTitle()]++;
  133. }
  134. }
  135. else
  136. {
  137. throw new Exception( "Numerator must be an instance of CqmFilterIF" );
  138. }
  139. }
  140. }