public function actionCreatePatientAndSick() { $this->retVal = new stdClass(); $request = Yii::app()->request; if ($request->isPostRequest && isset($_POST)) { try { $name = StringHelper::filterString($request->getPost('name')); $dob = StringHelper::filterString($request->getPost('dob')); $gender = StringHelper::filterString($request->getPost('gender')); $user_id = StringHelper::filterString($request->getPost('user_id')); $relation = StringHelper::filterString($request->getPost('relationshipWithUser')); $blood = StringHelper::filterString($request->getPost('bloodType')); $sicks = StringHelper::filterString($request->getPost('sicks')); $patient_model = new Patient(); $patient_model->name = $name; $patient_model->dob = $dob; $patient_model->gender = $gender; $patient_model->last_updated = time(); $patient_model->bloodType = $blood; $patient_model->relationshipWithUser = $relation; $patient_model->save(FALSE); $user_patient = new UserPatient(); $user_patient->user_id = $user_id; $user_patient->patient_id = $patient_model->patient_id; $user_patient->save(FALSE); $sick_arr = json_decode($sicks); foreach ($sick_arr as $sick) { $model = new PatientSick(); $model->patient_id = $user_patient->patient_id; $model->sick_id = $sick; $model->save(FALSE); $this->createScheduleSick($sick, $patient_id); } $this->retVal->message = "Success"; $this->retVal->patient_id = $patient_model->patient_id; } catch (exception $e) { $this->retVal->message = $e->getMessage(); } header('Content-type: application/json'); echo CJSON::encode($this->retVal); Yii::app()->end(); } }
public function updateSickPatient($sicks, $patient_id) { $sick_del = PatientSick::model()->findAllByAttributes(array('patient_id' => $patient_id)); foreach ($sick_del as $sick) { $sick->delete(); } $sick_arr = json_decode($sicks); foreach ($sick_arr as $sick) { $model = new PatientSick(); $model->patient_id = $patient_id; $model->sick_id = $sick; $model->save(FALSE); $this->createScheduleSick($sick, $patient_id); } }