public function listAction()
 {
     $showAll = (int) $this->_getParam('showAll');
     $patientId = (int) $this->_getParam('patientId');
     $rows = array();
     $patientNote = new PatientNote();
     $patientNoteIterator = $patientNote->getIterator();
     $filters = array();
     $filters['patient_id'] = $patientId;
     $filters['posting'] = 1;
     if (!$showAll) {
         $filters['active'] = 1;
     }
     $patientNoteIterator->setFilters($filters);
     foreach ($patientNoteIterator as $note) {
         $tmp = array();
         $tmp['id'] = $note->patientNoteId;
         $tmp['data'][] = $note->priority;
         $tmp['data'][] = $note->noteDate;
         $tmp['data'][] = $note->user->username;
         $tmp['data'][] = $note->reason;
         $tmp['data'][] = $note->note;
         $tmp['data'][] = $note->active;
         $tmp['data'][] = $note->active;
         $rows[] = $tmp;
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct(array('rows' => $rows));
 }
 public function listAction()
 {
     $showAll = (int) $this->_getParam('showAll');
     $patientId = (int) $this->_getParam('patientId');
     $rows = array();
     $patientNote = new PatientNote();
     $patientNoteIterator = $patientNote->getIterator();
     $filters = array();
     $filters['patient_id'] = $patientId;
     $filters['posting'] = 1;
     if (!$showAll) {
         $filters['active'] = 1;
     }
     $patientNoteIterator->setFilters($filters);
     $reasons = array();
     $enumeration = new Enumeration();
     $enumeration->populateByEnumerationName(PatientNote::ENUM_REASON_PARENT_NAME);
     $enumerationsClosure = new EnumerationsClosure();
     $enumerationIterator = $enumerationsClosure->getAllDescendants($enumeration->enumerationId, 1);
     $ctr = 0;
     foreach ($enumerationIterator as $enum) {
         // since data type of patient_note.reason is tinyint we simply use the counter as id
         $reasons[$ctr++] = $enum->name;
     }
     foreach ($patientNoteIterator as $note) {
         $tmp = array();
         $tmp['id'] = $note->patientNoteId;
         $tmp['data'][] = $note->priority;
         $tmp['data'][] = $note->noteDate;
         $tmp['data'][] = $note->user->username;
         $tmp['data'][] = isset($reasons[$note->reason]) ? $reasons[$note->reason] : '';
         $tmp['data'][] = $note->note;
         $tmp['data'][] = $note->active ? __('No') : __('Yes');
         $tmp['data'][] = $note->active;
         $rows[] = $tmp;
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct(array('rows' => $rows));
 }
 public function listNotesAction()
 {
     $patientId = (int) $this->_getParam('patientId');
     $rows = array();
     $patientNote = new PatientNote();
     $patientNoteIterator = $patientNote->getIterator();
     $filters = array();
     $filters['patient_id'] = $patientId;
     $filters['active'] = 1;
     $filters['posting'] = 0;
     $patientNoteIterator->setFilters($filters);
     $reasons = $this->_getReasons();
     foreach ($patientNoteIterator as $note) {
         $tmp = array();
         $tmp['id'] = $note->patient_note_id;
         $tmp['data'][] = $note->priority;
         $tmp['data'][] = $note->note_date;
         $tmp['data'][] = $note->user->username;
         $tmp['data'][] = isset($reasons[$note->reason]) ? $reasons[$note->reason] : '';
         $tmp['data'][] = $note->note;
         $tmp['data'][] = $note->active ? __('No') : __('Yes');
         $rows[] = $tmp;
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct(array('rows' => $rows));
 }
 public function _setActivePatient($personId, $visitId)
 {
     if (!$personId > 0) {
         return;
     }
     $memcache = Zend_Registry::get('memcache');
     $patient = new Patient();
     $patient->personId = (int) $personId;
     $patient->populate();
     $patient->person->populate();
     $this->_patient = $patient;
     $this->view->patient = $this->_patient;
     $mostRecentRaw = $memcache->get('mostRecent');
     $currentUserId = (int) Zend_Auth::getInstance()->getIdentity()->personId;
     $personId = $patient->personId;
     $teamId = $patient->teamId;
     if ($mostRecentRaw === false) {
         $mostRecent = array();
     } else {
         $mostRecent = unserialize($mostRecentRaw);
     }
     if (!array_key_exists($currentUserId, $mostRecent)) {
         $mostRecent[$currentUserId] = array();
     }
     if (array_key_exists($personId, $mostRecent[$currentUserId])) {
         unset($mostRecent[$currentUserId][$personId]);
     }
     $name = $patient->person->last_name . ', ' . $patient->person->first_name . ' ' . substr($patient->person->middle_name, 0, 1) . ' #' . $patient->record_number;
     $mostRecent[$currentUserId][$patient->personId] = array('name' => $name, 'teamId' => $teamId);
     $memcache->set('mostRecent', serialize($mostRecent));
     if (strlen($patient->teamId) > 0) {
         $name = TeamMember::ENUM_PARENT_NAME;
         $enumeration = new Enumeration();
         $enumeration->populateByEnumerationName($name);
         $enumerationsClosure = new EnumerationsClosure();
         $rowset = $enumerationsClosure->getAllDescendants($enumeration->enumerationId, 1);
         $patientEnumerationId = 0;
         foreach ($rowset as $row) {
             if ($patient->teamId == $row->key) {
                 $patientEnumerationId = $row->enumerationId;
                 break;
             }
         }
         if ($patientEnumerationId !== 0) {
             $this->view->team = TeamMember::generateTeamTree($patientEnumerationId);
         }
     }
     // POSTINGS
     $allergies = array();
     $patientAllergy = new PatientAllergy();
     $patientAllergyIterator = $patientAllergy->getIteratorByPatient($personId);
     foreach ($patientAllergyIterator as $allergy) {
         if ($allergy->noKnownAllergies) {
             continue;
         }
         $allergies[] = $allergy->toArray();
     }
     $this->view->allergies = $allergies;
     $notes = array();
     $patientNote = new PatientNote();
     $patientNoteIterator = $patientNote->getIterator();
     $filters = array();
     $filters['patient_id'] = $personId;
     $filters['active'] = 1;
     $filters['posting'] = 1;
     $patientNoteIterator->setFilters($filters);
     foreach ($patientNoteIterator as $note) {
         $notes[] = $note->toArray();
     }
     $this->view->notes = $notes;
     //REMINDERS
     $ctr = 0;
     $hsa = new HealthStatusAlert();
     $hsaIterator = $hsa->getIteratorByStatusWithPatientId('active', $personId);
     foreach ($hsaIterator as $row) {
         $ctr++;
     }
     if ($ctr > 0) {
         $this->view->reminders = $ctr;
     }
     // VISITS
     //$this->_visit = null;
     if (!$visitId > 0) {
         return;
     }
     $visit = new Visit();
     $visit->encounter_id = (int) $visitId;
     $visit->populate();
     $this->_visit = $visit;
     $this->view->visit = $this->_visit;
 }