public function searchAction() { //Parâmetros da pesquisa em comum $searchDataArray = array(); $searchDataArray['startDate'] = $this->_request->getParam("startDate"); $searchDataArray['endDate'] = $this->_request->getParam("endDate"); $searchDataArray['sector'] = $this->_request->getParam("cddepartment"); //paciente $searchDataArray['nrsample'] = $this->_request->getParam("nrsample"); $searchDataArray['cdrequest'] = $this->_request->getParam("cdrequest"); $searchDataArray['cdpatient'] = $this->_request->getParam("cdpatient"); //ficha - mapa de trabalho $searchDataArray['cdmap'] = $this->_request->getParam("nrplug"); $searchDataArray['startPage'] = $this->_request->getParam("nrhomepage"); $searchDataArray['endPage'] = $this->_request->getParam("nrlastpage"); //ultimos resultados $searchDataArray['startTime'] = $this->_request->getParam("startTime"); $searchDataArray['endTime'] = $this->_request->getParam("endTime"); $request = new RequestModel(); $dados = $request->fetchAll($request->getRequestsData($searchDataArray, array(4))); $response = new stdClass(); $index = 0; foreach ($dados as $row) { switch ($row['fgstatus']) { case 4: $fgstatus = "Lançada"; break; default: $fgstatus = "ERRO!"; // Não deve cair aqui pois ainda não está lançado, logo nãpo há conferência break; } $response->rows[$index]['cell'] = array($row['nmbarcodesample'], $fgstatus, $row['idexamination'], $row['idmaterial'], $row['nmclient'], $row['nmdepartment'], $row['cdrequest']); $index++; } $response = json_encode($response); print_r($response); return $response; }
public function searchAction() { $var = $this->_request->getParams(); // var_dump($var); die; //PESQUISA POR PACIENTE $cdpatient = null; $nrsample = null; $cdrequest = null; $sector = null; $startdate = null; $enddate = null; //PESQUISA POR MAPA $sector2 = null; $cdmap = null; $homepage = null; $lastpage = null; $dtfirstmaps = null; $dtendmaps = null; $page = $this->_request->getParam("page", 1); $limit = $this->_request->getParam("rows"); $sidx = $this->_request->getParam("sidx", 1); $sord = $this->_request->getParam("sord"); //Pesquisa por Paciente $requestModel = new RequestModel(); // <- Instanciando a classe Request $cdpatient = $this->_request->getParam("cdpatient"); // passando o valor dos parâmetros para as variaveis $nrsample = $this->_request->getParam("nrsample"); $cdrequest = $this->_request->getParam("cdrequest"); $sector = $this->_request->getParam("sector"); if ($sector == 'Nenhuma opção selecionada') { $sector = null; } $startdate = $this->_request->getParam("startdate"); $enddate = $this->_request->getParam("enddate"); //PESQUISA POR MAPA $sector2 = $this->_request->getParam("sector2"); if ($sector2 == 'Nenhuma opção selecionada') { $sector2 = null; } $cdmap = $this->_request->getParam("cdmap"); $homepage = $this->_request->getParam("homepage"); $lastpage = $this->_request->getParam("lastpage"); $dtfirstmaps = $this->_request->getParam("dtfirstmaps"); $dtendmaps = $this->_request->getParam("dtendmaps"); $array = array(); $requestModel->getAdapter()->beginTransaction(); try { //PESQUISA POR PACIENTE if (isset($cdpatient) && $cdpatient != null) { $array['cdpatient'] = $cdpatient; } else { $array['cdpatient'] = null; } if (isset($cdrequest) && $cdrequest != null) { $array['cdrequest'] = $cdrequest; } else { $array['cdrequest'] = null; } if (isset($nrsample) && $nrsample != null) { $array['nrsample'] = $nrsample; } else { $array['nrsample'] = null; } if (isset($sector) && $sector != null) { $array['sector'] = $sector; } else { $array['sector'] = null; } if (isset($startdate) && $startdate != null) { $startdate = new Zend_Date($startdate, 'YYYY-MM-dd HH:mm:ss'); $array['startdate'] = $startdate->toString('YYYY-MM-dd HH:mm:ss'); } else { $array['startdate'] = null; } if (isset($enddate) && $enddate != null) { $enddate = new Zend_Date($enddate, 'YYYY-MM-dd HH:mm:ss'); $array['enddate'] = $enddate->toString('YYYY-MM-dd HH:mm:ss'); } else { $array['enddate'] = null; } //PESQUISA POR MAPA DE TRABALHO if (isset($sector2) && $sector2 != null) { $array['sector2'] = $sector2; } else { $array['sector2'] = null; } if (isset($cdmap) && $cdmap != null) { $array['cdmap'] = $cdmap; } else { $array['cdmap'] = null; } if (isset($homepage) && $homepage != null) { $array['homepage'] = $homepage; } else { $array['homepage'] = null; } if (isset($lastpage) && $lastpage != null) { $array['lastpage'] = $lastpage; } else { $array['lastpage'] = null; } if (isset($dtfirstmaps) && $dtfirstmaps != null) { $dtfirstmaps = new Zend_Date($dtfirstmaps, 'YYYY-MM-dd HH:mm:ss'); $array['dtfirstmaps'] = $dtfirstmaps->toString('YYYY-MM-dd HH:mm:ss'); } else { $array['dtfirstmaps'] = null; } if (isset($dtendmaps) && $dtendmaps != null) { $dtendmaps = new Zend_Date($dtendmaps, 'YYYY-MM-dd HH:mm:ss'); $array['dtendmaps'] = $dtendmaps->toString('YYYY-MM-dd HH:mm:ss'); } else { $array['dtendmaps'] = null; } // $array['cdpatient'], $array['cdrequest'], $array['nrsample'], $array['sector'], $array['startdate'], $array['enddate'], $array['sector2'], $array['cdplug'], $array['homepage'], $array['lastpage'], $array['dtfirstmaps'], $array['dtendmaps'] if ($array['cdpatient'] == null && $array['cdrequest'] == null && $array['nrsample'] == null && $array['sector'] == null && $array['startdate'] == null && $array['enddate'] == null && $array['sector2'] == null && $array['cdmap'] == null && $array['homepage'] == null && $array['lastpage'] == null && $array['dtfirstmaps'] == null && $array['dtendmaps'] == null) { $dados = null; $count = count($dados); } else { $dados = $requestModel->fetchAll($requestModel->getRequestsData($array, array(3))); $count = count($dados); $array['rows'] = $this->_request->getParam('rows'); $array['page'] = $this->_request->getParam('page'); $array['sidx'] = $this->_request->getParam('sidx'); $array['sord'] = $this->_request->getParam('sord'); $dados = $requestModel->fetchAll($requestModel->getRequestsData($array, array(3))); } if ($count > 0 && $limit > 0) { $total_pages = ceil($count / $limit); } else { $total_pages = 0; } if ($page > $total_pages) { $page = $total_pages; } $response = new stdClass(); $response->page = $page; $response->total = $total_pages; $response->records = $count; $index = 0; foreach ($dados as $row) { switch ($row->fgstatus) { case '1': $fgcollection = "Coletado"; break; case '2': $fgcollection = "Faltante"; break; case '3': $fgcollection = "Em Mapa"; break; case '4': $fgcollection = "Lançada"; break; case '5': $fgcollection = "Conferida"; break; } $response->rows[$index]['cell'] = array($row['nmbarcodesample'], $fgcollection, $row['nmexamination'], $row['nmmaterial'], $row['nmclient'], $row['nmdepartment'], $row['cdrequest'], $row['cddepartment']); $index++; } $this->view->dados = $response; } catch (Exception $e) { $requestModel->getAdapter()->rollback(); echo $e->getMessage(); } }