The followings are the available columns in table 'commissioning_body_patient_assignment':
Inheritance: extends BaseActiveRecordVersioned
示例#1
0
 public function canDelete()
 {
     if (CommissioningBodyPatientAssignment::model()->find('commissioning_body_id=?', array($this->id))) {
         return false;
     }
     if (CommissioningBodyPracticeAssignment::model()->find('commissioning_body_id=?', array($this->id))) {
         return false;
     }
     return true;
 }
示例#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);
     }
 }