Ejemplo n.º 1
0
 /**
  * Imports the 'Practice' CSV file.
  *
  * @param array $data
  */
 private function importPractice($data)
 {
     if (!($practice = Practice::model()->findByAttributes(array('code' => $data['code'])))) {
         $practice = new Practice();
         $practice->code = $data['code'];
     }
     $isNewRecord = $practice->isNewRecord;
     $practice->is_active = $data['status'] == 'A' || $data['status'] == 'P' ? '1' : '0';
     $practice->phone = $data['phone'];
     if ($practice->saveOnlyIfDirty()->save()) {
         if ($this->audit !== 'false') {
             Audit::add('ProcessHscicDataCommand', ($isNewRecord ? 'Insert' : 'Update') . ' Practice');
         }
     } else {
         // save has not been carried out, either mode was not dirty or save() failed
     }
     $contact = $practice->contact;
     $contact->primary_phone = $practice->phone;
     $isNewRecord = $contact->isNewRecord;
     if ($contact->saveOnlyIfDirty()->save()) {
         if ($this->audit !== 'false') {
             Audit::add('ProcessHscicDataCommand', ($isNewRecord ? 'Insert' : 'Update') . ' Practice-Contact');
         }
     } else {
         // save has not been carried out, either mode was not dirty or save() failed
     }
     if (!($address = $contact->address)) {
         $address = new Address();
         $address->contact_id = $contact->id;
     }
     $isNewRecord = $address->isNewRecord;
     $this->importAddress($address, array($data['name'], $data['addr1'], $data['addr2'], $data['addr3'], $data['addr4'], $data['addr5']));
     $address->postcode = $data['postcode'];
     $address->country_id = $this->countryId;
     if ($address->saveOnlyIfDirty()->save()) {
         if ($this->audit !== 'false') {
             Audit::add('ProcessHscicDataCommand', ($isNewRecord ? 'Insert' : 'Update') . ' Practice-Address');
         }
     } else {
         // save has not been carried out, either mode was not dirty or save() failed
     }
 }