public function getContactAddress($contact_id, $location_type = false, $location_id = false) { if ($location_type && $location_id) { if ($pca = PatientContactAssignment::model()->find('patient_id=? and contact_id=? and ' . $location_type . '_id=?', array($this->id, $contact_id, $location_id))) { return $pca->address; } } else { if ($pca = PatientContactAssignment::model()->find('patient_id=? and contact_id=?', array($this->id, $contact_id))) { return $pca->address; } } return false; }
public function actionEditContact() { if (!($patient = Patient::model()->findByPk(@$_POST['patient_id']))) { throw new Exception("Patient not found: " . @$_POST['patient_id']); } if (!($contact = Contact::model()->findByPk(@$_POST['contact_id']))) { throw new Exception("Contact not found: " . @$_POST['contact_id']); } if (@$_POST['site_id']) { if (!($site = Site::model()->findByPk(@$_POST['site_id']))) { throw new Exception("Site not found: " . @$_POST['site_id']); } if (!($cl = ContactLocation::model()->find('contact_id=? and site_id=?', array($contact->id, $site->id)))) { $cl = new ContactLocation(); $cl->contact_id = $contact->id; $cl->site_id = $site->id; if (!$cl->save()) { throw new Exception("Unable to save contact location: " . print_r($cl->getErrors(), true)); } } } else { if (!($institution = Institution::model()->findByPk(@$_POST['institution_id']))) { throw new Exception("Institution not found: " . @$_POST['institution_id']); } if (!($cl = ContactLocation::model()->find('contact_id=? and institution_id=?', array($contact->id, $institution->id)))) { $cl = new ContactLocation(); $cl->contact_id = $contact->id; $cl->institution_id = $institution->id; if (!$cl->save()) { throw new Exception("Unable to save contact location: " . print_r($cl->getErrors(), true)); } } } if (!($pca = PatientContactAssignment::model()->findByPk(@$_POST['pca_id']))) { throw new Exception("PCA not found: " . @$_POST['pca_id']); } $pca->location_id = $cl->id; if (!$pca->save()) { throw new Exception("Unable to save patient contact assignment: " . print_r($pca->getErrors(), true)); } $this->redirect(array('/patient/view/' . $patient->id)); }
public function getAddress_targets() { if (Yii::app()->getController()->getAction()->id == 'create') { if (!($patient = Patient::model()->with(array('gp', 'practice'))->findByPk(@$_GET['patient_id']))) { throw new Exception('patient not found: ' . @$_GET['patient_id']); } } else { $patient = $this->event->episode->patient; } $options = array('Patient' . $patient->id => $patient->fullname . ' (Patient)'); if (!isset($patient->contact->address)) { $options['Patient' . $patient->id] .= ' - NO ADDRESS'; } if ($patient->gp) { if (@$patient->gp->contact) { $options['Gp' . $patient->gp_id] = $patient->gp->contact->fullname . ' (GP)'; } else { $options['Gp' . $patient->gp_id] = Gp::UNKNOWN_NAME . ' (GP)'; } if (!$patient->practice || !@$patient->practice->contact->address) { $options['Gp' . $patient->gp_id] .= ' - NO ADDRESS'; } } else { if ($patient->practice) { $options['Practice' . $patient->practice_id] = Gp::UNKNOWN_NAME . ' (GP)'; if (@$patient->practice->contact && !@$patient->practice->contact->address) { $options['Practice' . $patient->practice_id] .= ' - NO ADDRESS'; } } } // get the ids of the commissioning body types that should be shown as potential recipients to filter against $cbt_ids = array(); foreach (OphCoCorrespondence_CommissioningBodyType_Recipient::model()->getCommissioningBodyTypes() as $cbt) { $cbt_ids[] = $cbt->id; } if ($cbs = $patient->getDistinctCommissioningBodiesByType()) { $criteria = new CDbCriteria(); $criteria->addInCondition('id', array_keys($cbs)); $cbtype_lookup = CHtml::listData(CommissioningBodyType::model()->findAll($criteria), 'id', 'name'); foreach ($cbs as $cb_type_id => $cb_list) { foreach ($cb_list as $cb) { if (in_array($cb_type_id, $cbt_ids)) { $options['CommissioningBody' . $cb->id] = $cb->name . ' (' . $cbtype_lookup[$cb_type_id] . ')'; if (!$cb->getAddress()) { $options['CommissioningBody' . $cb->id] .= ' - NO ADDRESS'; } } // include all services at the moment, regardless of whether the commissioning body type is filtered if ($services = $cb->services) { foreach ($services as $svc) { $options['CommissioningBodyService' . $svc->id] = $svc->name . ' (' . $svc->getTypeShortName() . ')'; } } } } } foreach (PatientContactAssignment::model()->with(array('contact' => array('with' => array('address')), 'location' => array('with' => array('contact' => array('alias' => 'contact2', 'with' => array('label'))))))->findAll('patient_id=?', array($patient->id)) as $pca) { if ($pca->location) { $options['ContactLocation' . $pca->location_id] = $pca->location->contact->fullName . ' (' . $pca->location->contact->label->name . ', ' . $pca->location . ')'; } else { // Note that this index will always be the basis for a Person model search - if PCA has a wider use case than this, // this will need to be revisited $options['Contact' . $pca->contact_id] = $pca->contact->fullName . ' (' . $pca->contact->label->name; if ($pca->contact->address) { $options['Contact' . $pca->contact_id] .= ', ' . $pca->contact->address->address1 . ')'; } else { $options['Contact' . $pca->contact_id] .= ') - NO ADDRESS'; } } } asort($options); return $options; }