Esempio n. 1
0
 public function searchByAddressAndKeywords($province, $district, $ward, $limit, $offset, $keywords)
 {
     $criteria = new CDbCriteria();
     if (!empty($province)) {
         $criteria->addCondition("province={$province}");
     }
     if (!empty($ward)) {
         $criteria->addCondition("ward={$ward}");
     }
     if (!empty($district)) {
         $criteria->addCondition("district={$district}");
     }
     if (!empty($keywords)) {
         $criteria->addSearchCondition('name', $keywords, TRUE, 'OR', 'LIKE');
         $criteria->addSearchCondition('address', $keywords, TRUE, 'OR', 'LIKE');
         $criteria->addSearchCondition('contact_num', $keywords, TRUE, 'OR', 'LIKE');
     }
     $criteria->limit = $limit;
     $criteria->offset = $offset;
     $data = Doctors::model()->findAll($criteria);
     $cnt = count($data);
     return array('cnt' => $cnt, 'data' => $data);
 }
 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);
 }
Esempio n. 3
0
 public function actionGetNearDoctor()
 {
     try {
         $request = Yii::app()->request;
         $lat = StringHelper::filterString($request->getQuery('lat'));
         $lng = StringHelper::filterString($request->getQuery('lng'));
         $limit = StringHelper::filterString($request->getQuery('limit'));
         $offset = StringHelper::filterString($request->getQuery('offset'));
         $data = Doctors::model()->getNearDoctors($lat, $lng, $limit, $offset);
         ResponseHelper::JsonReturnSuccess($data, 'Success');
     } catch (Exception $ex) {
         var_dump($ex->getMessage());
     }
 }
Esempio n. 4
0
 /**
  * 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 Doctors the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Doctors::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Esempio n. 5
0
 public function getNearDoctors($lat, $lng, $limit, $offset)
 {
     $retVal = array();
     $criteria = new CDbCriteria();
     if (!empty($lat) && !empty($lng)) {
         $criteria->select = "t.*, (2 * (3959 * ATAN2(\n          SQRT(\n            POWER(SIN((RADIANS(" . $lat . " - `t`.`lat` ) ) / 2 ), 2 ) +\n            COS(RADIANS(`t`.`lat`)) *\n            COS(RADIANS(" . $lat . ")) *\n            POWER(SIN((RADIANS(" . $lng . " - `t`.`lng` ) ) / 2 ), 2 )\n          ),\n          SQRT(1-(\n            POWER(SIN((RADIANS(" . $lat . " - `t`.`lat` ) ) / 2 ), 2 ) +\n            COS(RADIANS(`t`.`lat`)) *\n            COS(RADIANS(" . $lat . ")) *\n            POWER(SIN((RADIANS(" . $lng . " - `t`.`lng` ) ) / 2 ), 2 )\n          ))\n        )\n      )) as\n            distance";
         $criteria->having = 'distance < 3';
         $criteria->group = 't.id';
     }
     $criteria->order = 'distance ASC';
     $criteria->limit = $limit;
     $criteria->offset = $offset;
     $data = Doctors::model()->findAll($criteria);
     $attrs = $this->attributeLabels();
     foreach ($data as $item) {
         $itemArr = array();
         foreach ($attrs as $key => $value) {
             $itemArr[$key] = $item->{$key};
         }
         $itemArr['stars'] = Review::model()->sumRating($item->id, 1);
         $itemArr['reviews'] = Review::model()->countReview($item->id, 1);
         $retVal[] = $itemArr;
     }
     return $retVal;
 }