private function importGp(array $data) { if (!($gp = Gp::model()->findbyAttributes(array('nat_id' => $data['code'])))) { if ($data['status'] != 'A') { return; } $gp = new Gp(); $gp->nat_id = $data['code']; $gp->obj_prof = $data['code']; } if (!$gp->save()) { throw new Exception("Failed to save GP: " . print_r($gp->errors, true)); } $contact = $gp->contact; $contact->primary_phone = $data['phone']; if (preg_match("/^([\\S]+)\\s+([A-Z]{1,4})\$/i", trim($data['name']), $m)) { $contact->title = 'Dr'; $contact->first_name = $m[2]; $contact->last_name = $this->tidy($m[1]); } else { $contact->last_name = $data['name']; } if (!$contact->save()) { throw new Exception("Failed to save contact: " . print_r($contact->errors, true)); } if (!($address = $contact->address)) { $address = new Address(); $address->contact_id = $contact->id; } $this->importAddress($address, array($data['addr1'], $data['addr2'], $data['addr3'], $data['addr4'], $data['addr5'])); $address->postcode = $data['postcode']; $address->country_id = $this->country_id; if (!$address->save()) { throw new Exception("Failed to save address: " . print_r($address->errors, true)); } }
public function tearDown() { Gp::model()->deleteAll('id > 3)'); Yii::app()->db->createCommand('ALTER TABLE gp AUTO_INCREMENT = 4')->execute(); }
public function actionAssociatecontact() { if (!($patient = Patient::model()->findByPk(@$_GET['patient_id']))) { throw new Exception('Patient not found: ' . @$_GET['patient_id']); } if (@$_GET['contact_location_id']) { if (!($location = ContactLocation::model()->findByPk(@$_GET['contact_location_id']))) { throw new Exception("Can't find contact location: " . @$_GET['contact_location_id']); } $contact = $location->contact; } else { if (!($contact = Contact::model()->findByPk(@$_GET['contact_id']))) { throw new Exception("Can't find contact: " . @$_GET['contact_id']); } } // Don't assign the patient's own GP if ($contact->label == 'General Practitioner') { if ($gp = Gp::model()->find('contact_id=?', array($contact->id))) { if ($gp->id == $patient->gp_id) { return; } } } if (isset($location)) { if (!($pca = PatientContactAssignment::model()->find('patient_id=? and location_id=?', array($patient->id, $location->id)))) { $pca = new PatientContactAssignment(); $pca->patient_id = $patient->id; $pca->location_id = $location->id; if (!$pca->save()) { throw new Exception("Unable to save patient contact assignment: " . print_r($pca->getErrors(), true)); } } } else { if (!($pca = PatientContactAssignment::model()->find('patient_id=? and contact_id=?', array($patient->id, $contact->id)))) { $pca = new PatientContactAssignment(); $pca->patient_id = $patient->id; $pca->contact_id = $contact->id; if (!$pca->save()) { throw new Exception("Unable to save patient contact assignment: " . print_r($pca->getErrors(), true)); } } } $this->renderPartial('_patient_contact_row', array('pca' => $pca)); }
private function mapGp(\Patient $patient) { if ($code = $this->getAssignedProperty('GpCode')) { if ($gp = \Gp::model()->findByAttributes(array('nat_id' => $code))) { $patient->gp_id = $gp->id; } else { $this->addWarning("Could not find GP for code " . $code); } } else { if (!$this->partial_record) { $patient->gp_id = null; } } }
/** * Imports the 'Gp' CSV file. * * @param array $data */ private function importGp(array $data) { if (!($gp = Gp::model()->findbyAttributes(array('nat_id' => $data['code'])))) { $gp = new Gp(); $gp->nat_id = $data['code']; $gp->obj_prof = $data['code']; } $isNewRecord = $gp->isNewRecord; $gp->is_active = $data['status'] == 'A' || $data['status'] == 'P' ? '1' : '0'; if ($gp->saveOnlyIfDirty()->save()) { if ($this->audit !== 'false') { Audit::add('ProcessHscicDataCommand', ($isNewRecord ? 'Insert' : 'Update') . ' GP'); } } else { // save has not been carried out, either mode was not dirty or save() failed } $contact = $gp->contact; $contact->primary_phone = $data['phone']; /* * Regexp * the first part match a word (any number of char, no whithespace) * than (after the first word) can follow any number of whitepace * and for the last part the string must end 1 to 4 characters[A-Z] * * The goal is to extract the name initials from the field and use as a first name with the doctor title. * * Examples (egpam.zip): WELLINGS D, DONOGHUE CA, COLLOMBON MPM */ if (preg_match("/^([\\S]+)\\s+([A-Z]{1,4})\$/i", trim($data['name']), $m)) { $contact->title = 'Dr'; $contact->first_name = $m[2]; $contact->last_name = $this->tidy($m[1]); } else { $contact->last_name = $data['name']; } $isNewRecord = $contact->isNewRecord; if ($contact->saveOnlyIfDirty()->save()) { if ($this->audit !== 'false') { Audit::add('ProcessHscicDataCommand', ($isNewRecord ? 'Insert' : 'Update') . ' GP-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; } $this->importAddress($address, array($data['addr1'], $data['addr2'], $data['addr3'], $data['addr4'], $data['addr5'])); $address->postcode = $data['postcode']; $address->country_id = $this->countryId; $isNewRecord = $address->isNewRecord; if ($address->saveOnlyIfDirty()->save()) { if ($this->audit !== 'false') { Audit::add('ProcessHscicDataCommand', ($isNewRecord ? 'Insert' : 'Update') . ' GP-Address'); } } else { // save has not been carried out, either mode was not dirty or save() failed } $gp = null; }