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("RsPatient.php");
10 /* Defines a population of patients
13 class RsPopulation
implements Countable
, Iterator
, ArrayAccess
15 protected $_patients = array();
18 * initialize the patient population
20 public function __construct(array $patientIdArray)
22 foreach ($patientIdArray as $patientId) {
23 $this->_patients
[]= new RsPatient($patientId);
30 public function count()
32 return count($this->_patients
);
38 public function rewind()
40 reset($this->_patients
);
43 public function current()
45 return current($this->_patients
);
50 return key($this->_patients
);
53 public function next()
55 return next($this->_patients
);
58 public function valid()
60 return $this->current() !== false;
65 * ArrayAccess Interface
67 public function offsetSet($offset, $value)
69 if ($value instanceof CqmPatient
) {
71 $this->_patients
[] = $value;
73 $this->_patients
[$offset] = $value;
76 throw new Exception("Value must be an instance of RsPatient");
80 public function offsetExists($offset)
82 return isset($this->_patients
[$offset]);
85 public function offsetUnset($offset)
87 unset($this->_patients
[$offset]);
90 public function offsetGet($offset)
92 return isset($this->_patients
[$offset]) ?
$this->container
[$offset] : null;