public function actionAddPatient()
 {
     $this->authenUser();
     $formAddPatient = new formAddPatient();
     $addPatient = new Patient();
     $systemCities = SystemCity::model()->findAll();
     $systemCitiesData = $this->generateSystemCities($systemCities);
     if (isset($_POST['formAddPatient'])) {
         $addPatient->attributes = $_POST['formAddPatient'];
         $addPatient->profile_creator = $this->userId;
         $addPatient->regDate();
         $addPatient->save();
         if ($addPatient->pid != NULL) {
             $patientAddress = $_POST['formAddPatient']['address'];
             $patientCity = $_POST['formAddPatient']['city'];
             if ($patientAddress != '' || $patientCity != '') {
                 $addPatientAddress = new PatientAddress();
                 $addPatientAddress->patient_pid = $addPatient->pid;
                 if ($patientAddress != '') {
                     $addPatientAddress->address = $patientAddress;
                 }
                 if ($patientCity != '') {
                     $addPatientAddress->city_id = $patientCity;
                 }
                 $addPatientAddress->save();
                 $this->redirect(array('manage/selectPatient'));
             }
         }
         Yii::app()->end();
     }
     $formAddPatient->generatePassword();
     $this->render('addPatient', array('formAddPatient' => $formAddPatient, 'systemCitiesData' => $systemCitiesData));
 }
示例#2
0
 public function resourceToModel($res, $patient)
 {
     $patient->nhs_num = $res->nhs_num;
     $patient->hos_num = $res->hos_num;
     $patient->gender = $res->gender;
     $patient->dob = $res->birth_date;
     $patient->date_of_death = $res->date_of_death;
     $patient->gp_id = $res->gp_ref ? $res->gp_ref->getId() : null;
     $patient->practice_id = $res->prac_ref ? $res->prac_ref->getId() : null;
     $this->saveModel($patient);
     $contact = $patient->contact;
     $contact->title = $res->title;
     $contact->last_name = $res->family_name;
     $contact->first_name = $res->given_name;
     $contact->primary_phone = $res->primary_phone;
     $this->saveModel($contact);
     $cur_addrs = array();
     foreach ($contact->addresses as $addr) {
         $cur_addrs[$addr->id] = PatientAddress::fromModel($addr);
     }
     $add_addrs = array();
     $matched_ids = array();
     foreach ($res->addresses as $new_addr) {
         $found = false;
         foreach ($cur_addrs as $id => $cur_addr) {
             if ($cur_addr->isEqual($new_addr)) {
                 $matched_ids[] = $id;
                 $found = true;
                 unset($cur_addrs[$id]);
                 break;
             }
         }
         if (!$found) {
             $add_addrs[] = $new_addr;
         }
     }
     $crit = new \CDbCriteria();
     $crit->compare('contact_id', $contact->id)->addNotInCondition('id', $matched_ids);
     \Address::model()->deleteAll($crit);
     foreach ($add_addrs as $add_addr) {
         $addr = new \Address();
         $addr->contact_id = $contact->id;
         $add_addr->toModel($addr);
         $this->saveModel($addr);
     }
     $cur_cb_ids = array();
     foreach ($patient->commissioningbodies as $cb) {
         $cur_cb_ids[] = $cb->id;
     }
     $new_cb_ids = array();
     foreach ($res->cb_refs as $cb_ref) {
         $new_cb_ids[] = $cb_ref->getId();
     }
     $add_cb_ids = array_diff($new_cb_ids, $cur_cb_ids);
     $del_cb_ids = array_diff($cur_cb_ids, $new_cb_ids);
     foreach ($add_cb_ids as $cb_id) {
         $cba = new \CommissioningBodyPatientAssignment();
         $cba->commissioning_body_id = $cb_id;
         $cba->patient_id = $patient->id;
         $this->saveModel($cba);
     }
     if ($del_cb_ids) {
         $crit = new \CDbCriteria();
         $crit->compare('patient_id', $patient->id)->addInCondition('commissioning_body_id', $del_cb_ids);
         \CommissioningBodyPatientAssignment::model()->deleteAll($crit);
     }
 }