2 // Copyright (C) 2011 Ken Chapple <ken@mi-squared.com>
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.
9 require_once( 'AmcFilterIF.php' );
11 abstract class AbstractAmcReport
implements RsReportIF
13 protected $_amcPopulation;
15 protected $_resultsArray = array();
19 protected $_beginMeasurement;
20 protected $_endMeasurement;
22 public function __construct( array $rowRule, array $patientIdArray, $dateTarget )
24 // require all .php files in the report's sub-folder
25 $className = get_class( $this );
26 foreach ( glob( dirname(__FILE__
)."/../reports/".$className."/*.php" ) as $filename ) {
27 require_once( $filename );
29 // require common .php files
30 foreach ( glob( dirname(__FILE__
)."/../reports/common/*.php" ) as $filename ) {
31 require_once( $filename );
33 // require clinical types
34 foreach ( glob( dirname(__FILE__
)."/../../../ClinicalTypes/*.php" ) as $filename ) {
35 require_once( $filename );
38 $this->_amcPopulation
= new AmcPopulation( $patientIdArray );
39 $this->_rowRule
= $rowRule;
40 $this->_ruleId
= isset( $rowRule['id'] ) ?
$rowRule['id'] : '';
41 // Parse measurement period, which is stored as array in $dateTarget ('dateBegin' and 'dateTarget').
42 $this->_beginMeasurement
= $dateTarget['dateBegin'];
43 $this->_endMeasurement
= $dateTarget['dateTarget'];
46 public abstract function createNumerator();
47 public abstract function createDenominator();
48 public abstract function getObjectToCount();
50 public function getResults() {
51 return $this->_resultsArray
;
54 public function execute()
56 $numerator = $this->createNumerator();
57 if ( !$numerator instanceof AmcFilterIF
) {
58 throw new Exception( "Numerator must be an instance of AmcFilterIF" );
61 $denominator = $this->createDenominator();
62 if ( !$denominator instanceof AmcFilterIF
) {
63 throw new Exception( "Denominator must be an instance of AmcFilterIF" );
66 $totalPatients = count( $this->_amcPopulation
);
68 // Figure out object to be counted
69 // (patients, labs, transitions, visits, or prescriptions)
70 $object_to_count = $this->getObjectToCount();
71 if (empty($object_to_count)) {
72 $object_to_count="patients";
75 $numeratorObjects = 0;
76 $denominatorObjects = 0;
77 foreach ( $this->_amcPopulation
as $patient )
79 // If begin measurement is empty, then make the begin
80 // measurement the patient dob.
81 $tempBeginMeasurement = "";
82 if (empty($this->_beginMeasurement
)) {
83 $tempBeginMeasurement = $patient->dob
;
86 $tempBeginMeasurement = $this->_beginMeasurement
;
89 if ($object_to_count == "patients") {
91 if ( !$denominator->test( $patient, $tempBeginMeasurement, $this->_endMeasurement
) ) {
94 $denominatorObjects++
;
95 if ( !$numerator->test( $patient, $tempBeginMeasurement, $this->_endMeasurement
) ) {
101 //Counting other objects (ie. not patients)
102 //Need to create the objects and send each one through the test function.
107 $percentage = calculate_percentage( $denominatorObjects, 0, $numeratorObjects );
108 $result = new AmcResult( $this->_rowRule
, $totalPatients, $denominatorObjects, 0, $numeratorObjects, $percentage );
109 $this->_resultsArray
[]= $result;