public function detailsAction($id = null)
 {
     $this->permission('index');
     if (!$id) {
         return Brightery::error404();
     }
     $this->language->load("clinic_patients");
     $patient = $this->Database->query("SELECT users.*, `user_addresses`.`address`, `user_phones`.`phone`" . "FROM `users` " . "LEFT JOIN `user_addresses` ON `user_addresses`.`user_id`=`users`.`user_id`" . "LEFT JOIN `user_phones` ON `user_phones`.`user_id`=`users`.`user_id`" . "WHERE `users`.`user_id`='{$id}'" . "")->row();
     if (!$patient) {
         Brightery::error404();
     }
     $phones = new \modules\users\models\User_phones();
     $phones->_select = "user_phone_id, phone, user_id , `primary`";
     $phones->user_id = $id;
     $res = $phones->get();
     $user_phone_id = $res[0]->user_phone_id;
     $phones->user_phone_id = $user_phone_id;
     $address = new modules\users\models\User_addresses();
     $address->select = 'user_address_id ,user_id';
     $address->user_id = $id;
     $add = $address->get();
     $info = $this->Database->query("SELECT clinic_patient_diseases.*, `clinic_disease_templates`.`title`" . "FROM `clinic_patient_diseases` " . "JOIN `clinic_disease_templates` ON `clinic_disease_templates`.`clinic_disease_template_id`=`clinic_patient_diseases`.`clinic_disease_template_id`" . "JOIN `users` ON `users`.`user_id`=`clinic_patient_diseases`.`user_id`" . "WHERE `clinic_patient_diseases`.`user_id`='{$id}'" . "")->result();
     $notes = $this->Database->query("SELECT clinic_patients_notes.*, (SELECT fullname FROM users WHERE clinic_doctors.user_id = users.user_id ) as doctor_name" . " FROM clinic_patients_notes " . " LEFT JOIN clinic_doctors ON clinic_doctors.clinic_doctor_id = clinic_patients_notes.clinic_doctor_id " . "WHERE clinic_patients_notes.user_id = '{$id}'")->result();
     $xrays = $this->Database->query("SELECT clinic_xray_negative.*" . " FROM clinic_xray_negative " . "WHERE clinic_xray_negative.user_id = '{$id}'")->result();
     return $this->render('clinic_patients/details', ['patient' => $patient, 'diseases' => $info, 'phones' => $res, 'address' => $add, 'notes' => $notes, 'xrays' => $xrays, 'id' => $id]);
 }
Exemplo n.º 2
0
 public function manageAction($id = false)
 {
     $redirect = "management/users";
     $this->permission('manage');
     //        $model = new Users('register');
     if ($id) {
         $model = new \modules\users\models\Users('edit');
         $model_phone = new \modules\users\models\User_phones('edit');
         $model_phone->_select = 'user_phone_id ,phone';
         $model_phone->user_id = $id;
         //            $model_phone->status = 'active' ;
         $res = $model_phone->get();
         $user_phone_id = $res[0]->user_phone_id;
         $model_phone->user_phone_id = $user_phone_id;
     } else {
         $model = new \modules\users\models\Users('add');
         $model_phone = new \modules\users\models\User_phones('add');
     }
     if ($_POST) {
         $model->attributes['fullname'] = $this->input->post('fullname');
         $model->attributes['usergroup_id'] = $this->input->post('usergroup_id');
         $model->attributes['email'] = $this->input->post('email');
         $model->attributes['gender'] = $this->input->post('gender');
     }
     if ($this->input->post('password') != '') {
         $model->attributes['password'] = md5($this->input->post('password'));
     }
     //////////////////////////////////UserGroup/////////////////////////////
     $usergroups = Form_helper::queryToDropdown('usergroups', 'usergroup_id', 'name');
     if ($id) {
         $model->user_id = $id;
         $model_phone->user_id = $id;
     }
     $model_phone->phone = $this->input->post('phone');
     $model->language_id = $this->language->getDefaultLanguage();
     //?
     if (!$id) {
         if ($_POST) {
             $model->created = date("Y-m-d H:i:s");
         }
     }
     if ($r = $model->save()) {
         $model_phone->attributes['phone'] = $this->input->post('phone');
         $model_phone->attributes['user_id'] = $r;
         $model_phone->save();
         if ($this->input->get('url')) {
             $redirect = $this->input->get('url') . $r;
         }
         Uri_helper::redirect($redirect);
     } else {
         return $this->render('users/manage', ['item' => $id ? $model->get() : null, 'menu' => ['male' => 'Male', 'female' => 'Female'], 'usergroup' => $usergroups, 'phone' => $model_phone->get()]);
     }
 }
 public function manageAction($id = null)
 {
     $this->permission('manage');
     if ($_POST) {
         $model = new \modules\users\models\Users();
         $phones = $this->input->post('phone');
         $primary_phone = $this->input->post('primary_phone');
         $primary_address = $this->input->post('primary_address');
         $model->user_id = $id;
         $model->fullname = $this->input->post('fullname');
         $model->birthdate = $this->input->post('birthdate');
         $model->email = $this->input->post('email');
         $model->password = md5($this->input->post('password'));
         $model->gender = $this->input->post('gender');
         $model->image = $this->input->post('image');
         $model->save();
         $address = $this->input->post('address');
         $user_phone_id = $this->input->post('user_phone_id');
         $user_address_id = $this->input->post('user_address_id');
         foreach ($phones as $key => $value) {
             if (!$value) {
                 continue;
             }
             $prPhone = new \modules\users\models\User_phones();
             $prPhone->_select = 'user_phone_id';
             $prPhone->user_id = $id;
             $prPhone->primary = 1;
             $res = $prPhone->get();
             $userphoneid = $res[0]->user_phone_id;
             $phone = new \modules\users\models\User_phones();
             $phone->user_id = $id;
             $phone->phone = $value;
             if ($user_phone_id[$key] == $primary_phone) {
                 $phone->primary = 1;
                 $pPhone = new \modules\users\models\User_phones();
                 $pPhone->user_phone_id = $userphoneid;
                 $pPhone->primary = 0;
                 $pPhone->save();
             }
             if ($user_phone_id[$key]) {
                 $phone->user_phone_id = $user_phone_id[$key];
             }
             $phone->save();
         }
         foreach ($address as $key => $value) {
             if (!$value) {
                 continue;
             }
             $prAdd = new \modules\users\models\User_addresses();
             $prAdd->_select = 'user_address_id';
             $prAdd->user_id = $id;
             $prAdd->primary = 1;
             $res = $prAdd->get();
             $useraddressid = $res[0]->user_address_id;
             $addres = new \modules\users\models\User_addresses();
             $addres->user_id = $id;
             $addres->address = $value;
             if ($user_address_id[$key] == $primary_address) {
                 $addres->primary = 1;
                 $pAddress = new \modules\users\models\User_addresses();
                 $pAddress->user_address_id = $useraddressid;
                 $pAddress->primary = 0;
                 $pAddress->save();
             }
             if ($user_address_id[$key]) {
                 $addres->user_address_id = $user_address_id[$key];
             }
             $addres->save();
         }
         $model->save();
     }
     if ($model->save()) {
         return json_encode(['sucess' => 1, 'item' => $model, 'phones' => $phone, 'address' => $address]);
     } else {
         return json_encode(['sucess' => 0, 'errors' => $this->validation->errors()]);
     }
 }