public function actionSearch() { $term = trim(\Yii::app()->request->getParam('term', '')); $result = array(); $patientSearch = new PatientSearch(); if ($patientSearch->isValidSearchTerm($term)) { $dataProvider = $patientSearch->search($term); foreach ($dataProvider->getData() as $patient) { // check if the patient is already in the Request List $warning = ''; $isInList = $this->isPatientInRequestList($patient->id); if ($isInList) { $warning = "This patient is already requested for merge as {$isInList} patient."; } $result[] = array('id' => $patient->id, 'first_name' => $patient->first_name, 'last_name' => $patient->last_name, 'age' => $patient->isDeceased() ? 'Deceased' : $patient->getAge(), 'gender' => $patient->getGenderString(), 'genderletter' => $patient->gender, 'dob' => $patient->dob ? $patient->NHSDate('dob') : 'Unknown', 'hos_num' => $patient->hos_num, 'nhsnum' => $patient->nhsnum, 'all-episodes' => $this->getEpisodesHTML($patient), 'warning' => $warning); } } echo CJavaScript::jsonEncode($result); Yii::app()->end(); }
/** * Ajax search. */ public function actionAjaxSearch() { $term = trim(\Yii::app()->request->getParam('term', '')); $result = array(); $patientSearch = new PatientSearch(); if ($patientSearch->isValidSearchTerm($term)) { $dataProvider = $patientSearch->search($term); foreach ($dataProvider->getData() as $patient) { $result[] = array('id' => $patient->id, 'first_name' => $patient->first_name, 'last_name' => $patient->last_name, 'age' => $patient->isDeceased() ? 'Deceased' : $patient->getAge(), 'gender' => $patient->getGenderString(), 'genderletter' => $patient->gender, 'dob' => $patient->dob ? $patient->NHSDate('dob') : 'Unknown', 'hos_num' => $patient->hos_num, 'nhsnum' => $patient->nhsnum, 'label' => $patient->first_name . ' ' . $patient->last_name . ' (' . $patient->hos_num . ')'); } } echo CJavaScript::jsonEncode($result); Yii::app()->end(); }