Highway to PSR2
[openemr.git] / library / classes / rulesets / library / RsPopulation.php
blob8b390a7397e478ce9b73404b329c452bcceb7583
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("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);
28 * Countable Interface
30 public function count()
32 return count($this->_patients);
36 * Iterator Interface
38 public function rewind()
40 reset($this->_patients);
43 public function current()
45 return current($this->_patients);
48 public function key()
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) {
70 if ($offset == "") {
71 $this->_patients[] = $value;
72 } else {
73 $this->_patients[$offset] = $value;
75 } else {
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;