public function testProblemList()
 {
     $date = date('Y-m-d H:i:s');
     $comments = array();
     $comments[] = 'first comment';
     $comments[] = 'yet another comment';
     $problemInput = 'DMII KETOACD UNCONTROLD  (250.12)';
     $problemList = array();
     $problemList['code'] = '250.12';
     $problemList['dateOfOnset'] = $date;
     $problemList['immediacy'] = 'Chronic';
     $problemList['personId'] = '65650';
     $problemList['providerId'] = '1000172';
     $problemList['status'] = 'Active';
     $problemList['lastUpdated'] = $date;
     $problem = new ProblemList();
     $problemListComments = array();
     $tmpComment = array();
     $tmpComment['authorId'] = (int) Zend_Auth::getInstance()->getIdentity()->personId;
     $tmpComment['date'] = $date;
     foreach ($comments as $comment) {
         $tmpComment['comment'] = $comment;
         $problemListComments[] = $tmpComment;
     }
     $problem->setProblemListComments($problemListComments);
     $problem->populateWithArray($problemList);
     $problem->persist();
     // retrieve problem list id
     $problemListId = $problem->problemListId;
     // check if problem list successfully saved
     $problem = new ProblemList();
     $problem->problemListId = $problemListId;
     $problem->populate();
     // assert individual data
     foreach ($problemList as $fieldName => $value) {
         $this->assertEquals($problem->{$fieldName}, $value, "{$fieldName} not equal.");
     }
     // assert if comments contains the same number of comments
     $this->assertEquals(count($problem->problemListComments), count($comments), "Problem List Comments does not match.");
     // remove problem list by changing the status to Removed
     $status = 'Removed';
     $problem->status = $status;
     $problem->persist();
     $problem = new ProblemList();
     $problem->problemListId = $problemListId;
     $problem->populate();
     $this->assertEquals($problem->status, $status, "Status not equal.");
 }
 public function setFilters(array $filters)
 {
     $db = Zend_Registry::get('dbAdapter');
     $dbSelect = $db->select()->from(array('pl' => 'problemLists'))->joinLeft(array('plc' => 'problemListComments'), "pl.problemListId=plc.problemListId", array('problemListCommentId', 'date', 'authorId', 'comment'));
     if (!isset($filters[0]) || $filters[0] != '*') {
         foreach ($filters as $fieldName => $fieldValue) {
             if (is_array($fieldValue)) {
                 $orWhere = array();
                 foreach ($fieldValue as $val) {
                     $val = preg_replace('/[^a-zA-Z0-9\\%\\.]/', '', $val);
                     $orWhere[] = "pl.{$fieldName} = '{$val}'";
                 }
                 $dbSelect->where(implode(' OR ', $orWhere));
             } else {
                 $dbSelect->where("pl.{$fieldName} = ?", $fieldValue);
             }
         }
     }
     $dbSelect->order("code ASC");
     $rows = $db->fetchAll($dbSelect);
     $dataRows = array();
     foreach ($rows as $row) {
         if (!isset($dataRows[$row['problemListId']])) {
             $problemList = new ProblemList();
             $problemList->populateWithArray($row);
             $dataRows[$row['problemListId']] = $problemList;
         }
         if ((int) $row['problemListCommentId'] > 0) {
             $dataRows[$row['problemListId']]->addComment($row);
         }
     }
     $this->_dataCount = 0;
     $this->_data = array();
     foreach ($dataRows as $row) {
         $this->_dataCount++;
         $this->_data[] = $row;
     }
 }
 public function setFilters(array $filters)
 {
     if (isset($filters['context'])) {
         unset($filters['context']);
     }
     $db = Zend_Registry::get('dbAdapter');
     $dbSelect = $db->select()->from(array('pl' => 'problemLists'))->joinLeft(array('plc' => 'problemListComments'), "pl.problemListId=plc.problemListId", array('problemListCommentId', 'date', 'authorId', 'comment'));
     if (!isset($filters[0]) || $filters[0] != '*') {
         foreach ($filters as $fieldName => $fieldValue) {
             if (is_array($fieldValue)) {
                 $orWhere = array();
                 foreach ($fieldValue as $val) {
                     $val = preg_replace('/[^a-zA-Z0-9\\%\\.]/', '', $val);
                     $orWhere[] = "pl.{$fieldName} = '{$val}'";
                 }
                 $dbSelect->where(implode(' OR ', $orWhere));
             } else {
                 switch ($fieldName) {
                     case 'dateRange':
                         $dateRange = explode(';', $fieldValue);
                         $start = isset($dateRange[0]) ? date('Y-m-d 00:00:00', strtotime($dateRange[0])) : date('Y-m-d 00:00:00');
                         $end = isset($dateRange[1]) ? date('Y-m-d 23:59:59', strtotime($dateRange[1])) : date('Y-m-d 23:59:59', strtotime($start));
                         $dbSelect->where("pl.dateOfOnset BETWEEN '{$start}' AND '{$end}'");
                         break;
                     default:
                         $dbSelect->where("pl.{$fieldName} = ?", $fieldValue);
                 }
             }
         }
     }
     $dbSelect->order("code ASC");
     $rows = $db->fetchAll($dbSelect);
     $dataRows = array();
     foreach ($rows as $row) {
         if (!isset($dataRows[$row['problemListId']])) {
             $problemList = new ProblemList();
             $problemList->populateWithArray($row);
             $dataRows[$row['problemListId']] = $problemList;
         }
         if ((int) $row['problemListCommentId'] > 0) {
             $dataRows[$row['problemListId']]->addComment($row);
         }
     }
     $this->_dataCount = 0;
     $this->_data = array();
     foreach ($dataRows as $row) {
         $this->_dataCount++;
         $this->_data[] = $row;
     }
 }