public function listTeamJsonAction()
 {
     $this->_helper->autoCompleteDojo(array());
     $patientId = (int) $this->_getParam("patientId");
     $patient = new Patient();
     $patient->personId = $patientId;
     $patient->populate();
     $patient->person->populate();
     $db = Zend_Registry::get("dbAdapter");
     $dbSelect = $db->select()->from("patient")->where("teamId = ?", $patient->teamId);
     $patientIterator = $patient->getIterator($dbSelect);
     foreach ($patientIterator as $pat) {
         $tmp = array();
         $tmp['id'] = $pat->person_id;
         $tmp['data'][] = $pat->person->getDisplayName();
         $tmp['data'][] = $pat->email;
         $tmp['data'][] = $pat->phone_number;
         $rows[] = $tmp;
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct(array('rows' => $rows));
 }
 protected function _generateAppointments()
 {
     $patients = array();
     $patient = new Patient();
     $patientIterator = $patient->getIterator();
     foreach ($patientIterator as $row) {
         $patients[] = $row->personId;
     }
     $patientLen = count($patients) - 1;
     $startingDate = strtotime(date('Y-m-d'));
     $endingDate = strtotime('+1 month', $startingDate);
     $titles = array('Sick', 'Followup', 'Cough', 'Runny Nose', 'Lab Only', 'Annual');
     $titleLen = count($titles) - 1;
     $dates = $this->_generateDays();
     $providerIterator = new ProviderIterator();
     foreach ($providerIterator as $provider) {
         $providerId = $provider->personId;
         foreach ($dates as $date) {
             $timeSlots = array();
             echo 'current:' . $date . ' time:' . calcTS() . ' memory:' . memory_get_usage() / 1024 / 1024 . '<br/>';
             $hour = 8;
             while ($hour < 18) {
                 if (rand(0, 1) == 1) {
                     continue;
                 }
                 $plus = rand(0, 2) * 0.25;
                 $length = rand(1, 4) * 0.25;
                 if ($hour >= 12 && $hour < 13) {
                     // lunch time
                     $hour = 13;
                 }
                 $start = $date . ' ' . formatTime($hour);
                 $hour += $length;
                 if ($hour >= 12 && $hour < 13) {
                     // lunch time
                     $hour = 12;
                 }
                 $end = $date . ' ' . formatTime($hour);
                 $timeSlots[] = array('start' => $start, 'end' => $end);
             }
             $rows = array();
             $timeSlotLen = count($timeSlots) - 1;
             if ($timeSlotLen > $patientLen) {
                 // patients are less than time slots
                 $slots = $timeSlots;
                 foreach ($patients as $patientId) {
                     $row = array();
                     shuffle($slots);
                     $slot = array_shift($slots);
                     $row['start'] = $slot['start'];
                     $row['end'] = $slot['end'];
                     $row['patientId'] = $patientId;
                     $rows[] = $row;
                 }
             } else {
                 // patients are greater than time slots
                 $patientIds = $patients;
                 foreach ($timeSlots as $slot) {
                     $row = array();
                     $row['start'] = $slot['start'];
                     $row['end'] = $slot['end'];
                     shuffle($patientIds);
                     $patientId = array_shift($patientIds);
                     $row['patientId'] = $patientId;
                     $rows[] = $row;
                 }
             }
             foreach ($rows as $row) {
                 $app = new Appointment();
                 // disable cascadePersist, we only generate appointments
                 $this->_setORMPersistMode($app);
                 $app->patientId = $row['patientId'];
                 $app->start = $row['start'];
                 $app->end = $row['end'];
                 $title = $titles[rand(0, $titleLen)];
                 $app->title = $title;
                 $app->providerId = $providerId;
                 $app->createdDate = date('Y-m-d H:i:s');
                 $app->persist();
             }
         }
     }
 }