public function actionGetTreatment() { if (!isset($_GET['q'])) { throw new CHttpException(401, 'Missing diagnosis name'); } $lat = @$_GET['lat']; $long = @$_GET['long']; $diagnosisName = @$_GET['q']; $data = array(); $diagnosis = Diagnosis::model()->findByAttributes(array('name' => $diagnosisName)); if (!$diagnosis) { throw new CHttpException(401, 'Invalid diagnosis name'); } $treatment = Treatment::model()->findByAttributes(array('diagnosis_id' => $diagnosis->id)); $data['action'] = $treatment->action; $diagnosisType = DiagnosisTypes::model()->findByAttributes(array('diagnosis_id' => $diagnosis->id)); $doctors = Doctors::model()->findAllByAttributes(array('type' => $diagnosisType->doctor_type_id)); //how to compute for nearest place for the doctor foreach ($doctors as $d) { $data['doctors'][] = array('id' => $d->id, 'name' => $d->getFullname(), 'address' => $d->address, 'type' => $diagnosisType->doctorType->name, 'contact_no' => $d->contact_no, 'schedule' => $d->schedule, 'other_info' => $d->other_info, 'lat' => $d->lat, 'long' => $d->long); } echo CJSON::encode($data); }