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); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Diagnosis the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Diagnosis::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }