function listNotesAction()
 {
     $personId = 0;
     $personId = (int) $this->_getParam('personId');
     $filter = $this->_getParam('filter');
     $clinicalNoteIterator = new ClinicalNoteIterator();
     $custom = $this->_getParam('custom');
     if (count($custom) > 0) {
         $custom = $this->_getParam('custom');
         $custom['personId'] = $personId;
         $clinicalNoteIterator->customView($custom);
     } else {
         $data = array();
         $data['personId'] = $personId;
         if ($filter == 'byAuthoringPersonId') {
             $data['authoringPersonId'] = $this->_getParam('authoringPersonId');
         }
         if ($filter == 'byDateRange') {
             $data['dateRange'] = $this->_getParam('dateRange');
         }
         if ($filter == 'byCurrentPractice' || $filter == 'bySelectedVisit') {
             $visitId = (int) $this->_getParam('visitId');
             $visit = new Visit();
             $visit->visitId = $visitId;
             $visit->populate();
             $building = new Building();
             $building->buildingId = $visit->buildingId;
             $building->populate();
             $data['locationId'] = $building->buildingId;
             $data['selectedVisit'] = date('Y-m-d', strtotime($visit->timestamp));
         }
         if ($filter == 'byVisitPractice' || $filter == 'byVisitBuilding') {
             $practiceId = 0;
             $buildingId = 0;
             $identity = Zend_Auth::getInstance()->getIdentity();
             $userId = $identity->userId;
             $user = new User();
             $user->userId = $userId;
             $user->populate();
             if (strlen($user->preferences) > 0) {
                 $this->xmlPreferences = new SimpleXMLElement($user->preferences);
                 $currentLocation = (string) $this->xmlPreferences->currentLocation;
                 $locationId = (int) $currentLocation;
                 if ($locationId > 0) {
                     $room = new Room();
                     $room->roomId = $locationId;
                     $room->populate();
                     $practiceId = $room->building->practiceId;
                     $buildingId = $room->buildingId;
                 }
             }
             $data['practiceId'] = $practiceId;
             $data['buildingId'] = $buildingId;
         }
         $clinicalNoteIterator->setFilter($filter, $data);
     }
     //trigger_error($cnSelect->__toString(),E_USER_NOTICE);
     //var_dump($db->query($cnSelect)->fetchAll());exit;
     $notes = array();
     foreach ($clinicalNoteIterator as $note) {
         if ($note['eSignatureId'] > 0) {
             $img = 'sm-signed.png';
             $alt = 'Signed';
         } else {
             $img = 'sm-editproblem.png';
             $alt = 'Editing';
         }
         $icon = '<img src="' . Zend_Registry::get('baseUrl') . 'img/' . $img . '" alt="' . $alt . '" />';
         $row = array();
         $row['id'] = $note['clinicalNoteId'];
         $row['data'][] = '';
         $row['data'][] = $icon . ' ' . date('Y-m-d', strtotime($note['dateTime']));
         $row['data'][] = $note['noteTitle'];
         $row['data'][] = $note['last_name'] . ', ' . $note['first_name'] . ' ' . substr($note['middle_name'], 0, 1);
         $location = '';
         $locationId = (int) $note['locationId'];
         if ($locationId > 0) {
             $location = Room::location($locationId);
         }
         $row['data'][] = $location;
         $row['data'][] = $row['id'];
         $row['data'][] = 0;
         $xml = simplexml_load_string($note['template']);
         $genericData = new GenericData();
         $filters = array();
         $filters['objectId'] = $note['clinicalNoteId'];
         $filters['objectClass'] = 'ClinicalNote';
         $genericDataIterator = $genericData->getIteratorByFilters($filters);
         $firstData = false;
         $childIcon = '<img src="' . Zend_Registry::get('baseUrl') . 'img/leaf.gif" alt="-" />';
         foreach ($genericDataIterator as $data) {
             if (!$firstData) {
                 $firstData = true;
                 //$row['id'] .= ':'.$data->revisionId;
                 $row['data'][6] = $data->revisionId;
                 continue;
             }
             $tmp = array();
             $tmp['id'] = $data->revisionId;
             $tmp['data'][] = $data->objectId;
             // '';
             $tmp['data'][] = '&nbsp; &nbsp; &nbsp;' . $childIcon . ' ' . date('Y-m-d', strtotime($data->dateTime));
             $tmp['data'][] = $note['noteTitle'];
             $tmp['data'][] = '';
             // Author
             $tmp['data'][] = '';
             // Location
             $tmp['data'][] = $note['clinicalNoteId'];
             $tmp['data'][] = $tmp['id'];
             $row['rows'][] = $tmp;
         }
         $notes[] = $row;
     }
     $acj = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $acj->suppressExit = true;
     $acj->direct(array("rows" => $notes));
 }
 function listNotesAction()
 {
     $personId = 0;
     $personId = (int) $this->_getParam('personId');
     $filter = $this->_getParam('filter');
     $clinicalNoteIterator = new ClinicalNoteIterator();
     $custom = $this->_getParam('custom');
     if (count($custom) > 0) {
         $custom = $this->_getParam('custom');
         $custom['personId'] = $personId;
         $clinicalNoteIterator->customView($custom);
     } else {
         $data = array();
         $data['personId'] = $personId;
         if ($filter == 'byAuthoringPersonId') {
             $data['authoringPersonId'] = $this->_getParam('authoringPersonId');
         }
         if ($filter == 'byDateRange') {
             $data['dateRange'] = $this->_getParam('dateRange');
         }
         $clinicalNoteIterator->setFilter($filter, $data);
     }
     //trigger_error($cnSelect->__toString(),E_USER_NOTICE);
     //var_dump($db->query($cnSelect)->fetchAll());exit;
     $notes = array();
     foreach ($clinicalNoteIterator as $note) {
         if ($note['eSignatureId'] > 0) {
             $img = 'sm-signed.png';
             $alt = 'Signed';
         } else {
             $img = 'sm-editproblem.png';
             $alt = 'Editing';
         }
         $icon = '<img src="' . Zend_Registry::get('baseUrl') . 'img/' . $img . '" alt="' . $alt . '" />';
         $row = array();
         $row['id'] = $note['clinicalNoteId'];
         $row['data'][] = '';
         $row['data'][] = $icon . ' ' . $note['dateTime'];
         $row['data'][] = $note['noteTitle'];
         $row['data'][] = $note['last_name'] . ', ' . $note['first_name'] . ' ' . substr($note['middle_name'], 0, 1);
         $row['data'][] = 'Main Clinic->General Care';
         // location->room temporarily hardcoded
         $xml = simplexml_load_string($note['template']);
         $genericData = new GenericData();
         $filters = array();
         $filters['objectId'] = $note['clinicalNoteId'];
         $filters['objectClass'] = 'ClinicalNote';
         $genericDataIterator = $genericData->getIteratorByFilters($filters);
         $firstData = false;
         $childIcon = '<img src="' . Zend_Registry::get('baseUrl') . 'img/leaf.gif" alt="-" />';
         foreach ($genericDataIterator as $data) {
             if (!$firstData) {
                 $firstData = true;
                 continue;
             }
             $tmp = array();
             $tmp['id'] = $data->revisionId;
             $tmp['data'][] = $data->objectId;
             // '';
             $tmp['data'][] = '&nbsp; &nbsp; &nbsp;' . $childIcon . ' ' . date('Y-m-d', strtotime($data->dateTime));
             $tmp['data'][] = $note['noteTitle'];
             $row['rows'][] = $tmp;
         }
         $notes[] = $row;
     }
     $acj = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $acj->suppressExit = true;
     $acj->direct(array("rows" => $notes));
 }