public function listAction()
 {
     $rows = array();
     $problem = array();
     $medication = array();
     $demographics = array();
     $labTestResults = array();
     $allergies = array();
     foreach ($this->_session->filters as $key => $filters) {
         if ($key == 'problem') {
             ${$key} = Patient::listProblems($filters);
         } else {
             if ($key == 'medication') {
                 ${$key} = Patient::listMedications($filters);
             } else {
                 if ($key == 'demographics') {
                     ${$key} = Patient::listDemographics($filters);
                 } else {
                     if ($key == 'labTestResults') {
                         ${$key} = Patient::listLabTestResults($filters);
                     } else {
                         if ($key == 'allergies') {
                             ${$key} = Patient::listAllergies($filters);
                         }
                     }
                 }
             }
         }
     }
     // intersect only for those that have filters
     $tmpArray = array();
     // holds a list of rows that needs to get the intersections
     foreach ($this->_session->filters as $key => $filters) {
         if (!$filters || !isset(${$key})) {
             continue;
         }
         $k = $key;
         if ($k == 'problem' || $k == 'medication') {
             $k .= 's';
         }
         $tmpArray[$k] = ${$key};
     }
     $patientList = null;
     foreach ($tmpArray as $key => $value) {
         if ($patientList === null) {
             $patientList = $value;
             continue;
         }
         $tmp = $patientList;
         $patientList = array();
         foreach ($tmp as $id => $val) {
             if (!isset($value[$id])) {
                 continue;
             }
             $val[$key] = $value[$id][$key];
             $patientList[$id] = $val;
         }
     }
     if ($patientList === null) {
         $patientList = array();
     }
     $this->_session->patientList = $patientList;
     foreach ($patientList as $key => $value) {
         $row = array();
         $row['id'] = $key;
         $row['data'][] = $value['MRN'];
         $row['data'][] = $value['lastName'];
         $row['data'][] = $value['firstName'];
         $row['data'][] = $value['middleName'];
         $row['data'][] = isset($value['problems']) ? implode('<br />', $value['problems']) : '';
         $row['data'][] = isset($value['medications']) ? implode('<br />', $value['medications']) : '';
         $row['data'][] = isset($value['demographics']) ? implode('<br />', $value['demographics']) : '';
         $row['data'][] = isset($value['labTestResults']) ? implode('<br />', $value['labTestResults']) : '';
         $row['data'][] = isset($value['allergies']) ? implode('<br />', $value['allergies']) : '';
         $rows[] = $row;
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct(array('rows' => $rows));
 }
 public function listAction()
 {
     $rows = array();
     $patientList = array();
     $problems = array();
     $medications = array();
     $demographics = array();
     $labTestResults = array();
     $allergies = array();
     $hsa = array();
     foreach ($this->_session->filters as $key => $filters) {
         if ($key == 'problems') {
             $problems = Patient::listProblems($filters);
         } else {
             if ($key == 'medications') {
                 $medications = Patient::listMedications($filters);
             } else {
                 if ($key == 'demographics') {
                     $filters['reminders'] = true;
                     $demographics = Patient::listDemographics($filters);
                 } else {
                     if ($key == 'labTestResults') {
                         $labTestResults = Patient::listLabTestResults($filters);
                     } else {
                         if ($key == 'allergies') {
                             $allergies = Patient::listAllergies($filters);
                         } else {
                             if ($key == 'hsa') {
                                 $hsa = Patient::listHSA($filters);
                             }
                         }
                     }
                 }
             }
         }
     }
     $tmpArray = array('demographics' => $demographics);
     // holds a list of rows that needs to get the intersections
     foreach ($this->_session->filters as $key => $filters) {
         if (!isset(${$key}) || !is_array(${$key})) {
             continue;
         }
         $tmpArray[$key] = ${$key};
     }
     $patientList = array();
     foreach ($tmpArray as $key => $value) {
         foreach ($value as $id => $val) {
             if (isset($patientList[$id])) {
                 continue;
             }
             $patientList[$id] = $val;
         }
     }
     if ($patientList === null) {
         $patientList = array();
     }
     $this->_session->patientList = $patientList;
     foreach ($patientList as $key => $value) {
         $addressId = isset($value['addressId']) ? (int) $value['addressId'] : 0;
         $address = $this->getAddress($addressId);
         $numberId = isset($value['numberId']) ? (int) $value['numberId'] : 0;
         $phone = $this->getPhone($numberId);
         $row = array();
         $row['id'] = $key;
         $row['data'][] = $value['MRN'];
         $row['data'][] = $value['lastName'];
         $row['data'][] = $value['firstName'];
         $row['data'][] = $value['middleName'];
         $row['data'][] = $address;
         $row['data'][] = $phone;
         $row['data'][] = isset($value['problems']) ? implode('<br />', $value['problems']) : '';
         $row['data'][] = isset($value['medications']) ? implode('<br />', $value['medications']) : '';
         $row['data'][] = isset($value['demographics']) ? implode('<br />', $value['demographics']) : '';
         $row['data'][] = isset($value['labTestResults']) ? implode('<br />', $value['labTestResults']) : '';
         $row['data'][] = isset($value['allergies']) ? implode('<br />', $value['allergies']) : '';
         $row['data'][] = isset($value['hsa']) ? implode('<br />', $value['hsa']) : '';
         $rows[] = $row;
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct(array('rows' => $rows));
 }