The followings are the available columns in table 'commissioning_body_type':
Inheritance: extends BaseActiveRecordVersioned
 /**
  * Lists local authorities from Commissioning Body Service
  *
  * @throws CHttpException
  */
 public function actionList()
 {
     \Audit::add('admin-CommissioningBodyService', 'list');
     if (!($commissioning_bt = \CommissioningBodyType::model()->findByAttributes(array('shortname' => 'LA')))) {
         throw new \CHttpException(500, 'Local Authority Commissioning Body Type is not configured.');
     }
     $service_type = \CommissioningBodyServiceType::model()->findByAttributes(array('shortname' => 'SSD'));
     $data['title'] = 'CVI Social Services Depts.';
     $data['commissioning_bt'] = $commissioning_bt;
     $data['service_type'] = $service_type;
     $data['return_url'] = '/OphCoCvi/localAuthoritiesAdmin/list';
     $data['base_data_url'] = 'OphCoCvi/localAuthoritiesAdmin/';
     $this->render('//admin/commissioning_body_services', $data);
 }
 public function resourceToModel($res, $cb)
 {
     $cb->code = $res->code;
     $cb->name = $res->name;
     // Hard-coded for now
     $type = \CommissioningBodyType::model()->findByAttributes(array('shortname' => 'CCG'));
     if (!$type) {
         throw new \Exception("Failed to find commissioning body type 'CCG'");
     }
     $cb->commissioning_body_type_id = $type->id;
     $this->saveModel($cb);
     if ($res->address) {
         if (!($address = $cb->contact->address)) {
             $address = new \Address();
             $address->contact_id = $cb->contact->id;
         }
         $res->address->toModel($address);
         $this->saveModel($address);
     }
     // Associate with any services already in the db
     $crit = new \CDbCriteria();
     $crit->compare('code', $res->code);
     \CommissioningBodyService::model()->updateAll(array('commissioning_body_id' => $cb->id), $crit);
 }
 public function run($args)
 {
     $this->pcu = new PostCodeUtility();
     $this->country_id = Country::model()->findByAttributes(array('code' => 'GB'))->id;
     $this->cbt_id = CommissioningBodyType::model()->findByAttributes(array('shortname' => 'CCG'))->id;
     foreach (self::$files as $type => $params) {
         $f = $this->downloadAndOpen($params['url']);
         while ($row = fgetcsv($f)) {
             print "{$type} {$row[0]}\n";
             $data = array_combine(array_pad($params['fields'], count($row), ""), $row);
             $tx = Yii::app()->db->beginTransaction();
             try {
                 $this->{"import{$type}"}($data);
                 $tx->commit();
             } catch (Exception $e) {
                 $message = "Error processing {$type} row:\n" . CVarDumper::dumpAsString($row) . "\n{$e}";
                 Yii::log($message, CLogger::LEVEL_ERROR);
                 print "{$message}\n";
                 $tx->rollback();
             }
         }
         fclose($f);
     }
 }
 /**
  * Ajax action to get macro data for populating the letter elements.
  *
  * @throws Exception
  */
 public function actionGetMacroData()
 {
     if (!($patient = Patient::model()->findByPk(@$_GET['patient_id']))) {
         throw new Exception('Patient not found: ' . @$_GET['patient_id']);
     }
     if (!($macro = LetterMacro::model()->findByPk(@$_GET['macro_id']))) {
         throw new Exception('Macro not found: ' . @$_GET['macro_id']);
     }
     $data = array();
     $macro->substitute($patient);
     if ($macro->recipient && $macro->recipient->name == 'Patient') {
         $data['sel_address_target'] = 'Patient' . $patient->id;
         $contact = $patient;
         if ($patient->isDeceased()) {
             echo json_encode(array('error' => 'DECEASED'));
             return;
         }
     }
     if ($macro->recipient && $macro->recipient->name == 'GP' && ($contact = $patient->gp ? $patient->gp : $patient->practice)) {
         $data['sel_address_target'] = get_class($contact) . $contact->id;
     }
     if (isset($contact)) {
         $address = $contact->getLetterAddress(array('patient' => $patient, 'include_name' => true, 'include_label' => true, 'delimiter' => "\n"));
         if ($address) {
             $data['text_ElementLetter_address'] = $address;
         } else {
             $data['alert'] = 'The contact does not have a valid address.';
             $data['text_ElementLetter_address'] = '';
         }
         $data['text_ElementLetter_introduction'] = $contact->getLetterIntroduction(array('nickname' => $macro->use_nickname));
     }
     $data['check_ElementLetter_use_nickname'] = $macro->use_nickname;
     if ($macro->body) {
         $data['text_ElementLetter_body'] = $macro->body;
     }
     $cc = array('text' => array(), 'targets' => array());
     if ($macro->cc_patient) {
         if ($patient->isDeceased()) {
             $data['alert'] = "Warning: the patient cannot be cc'd because they are deceased.";
         } elseif ($patient->contact->address) {
             $cc['text'][] = $patient->getLetterAddress(array('include_name' => true, 'include_label' => true, 'delimiter' => ', ', 'include_prefix' => true));
             $cc['targets'][] = '<input type="hidden" name="CC_Targets[]" value="Patient' . $patient->id . '" />';
         } else {
             $data['alert'] = "Letters to the GP should be cc'd to the patient, but this patient does not have a valid address.";
         }
     }
     if ($macro->cc_doctor && ($cc_contact = $patient->gp ? $patient->gp : $patient->practice)) {
         $cc['text'][] = $cc_contact->getLetterAddress(array('patient' => $patient, 'include_name' => true, 'include_label' => true, 'delimiter' => ', ', 'include_prefix' => true));
         $cc['targets'][] = '<input type="hidden" name="CC_Targets[]" value="' . get_class($cc_contact) . $cc_contact->id . '" />';
     }
     if ($macro->cc_drss) {
         $commissioningbodytype = CommissioningBodyType::model()->find('shortname = ?', array('CCG'));
         if ($commissioningbodytype && ($commissioningbody = $patient->getCommissioningBodyOfType($commissioningbodytype))) {
             $drss = null;
             foreach ($commissioningbody->services as $service) {
                 if ($service->type->shortname == 'DRSS') {
                     $cc['text'][] = $service->getLetterAddress(array('include_name' => true, 'include_label' => true, 'delimiter' => ', ', 'include_prefix' => true));
                     $cc['targets'][] = '<input type="hidden" name="CC_Targets[]" value="CommissioningBodyService' . $service->id . '" />';
                     break;
                 }
             }
         }
     }
     $data['textappend_ElementLetter_cc'] = implode("\n", $cc['text']);
     $data['elementappend_cc_targets'] = implode("\n", $cc['targets']);
     echo json_encode($data);
 }
 public function actionDeleteCommissioningBodyTypes()
 {
     $criteria = new CDbCriteria();
     $criteria->addInCondition('id', @$_POST['commissioning_body_type']);
     foreach (CommissioningBodyType::model()->findAll($criteria) as $cbt) {
         if (!$cbt->delete()) {
             echo "0";
             return;
         }
     }
     Audit::add('admin-CommissioningBodyType', 'delete');
     echo "1";
 }
 */
?>
<div class="box admin">
	<h2>Commissioning body types</h2>
	<form id="admin_commissioning_body_types">
		<table class="grid">
			<thead>
				<tr>
					<th><input type="checkbox" id="checkall" class="co§mmissioning_body_type" /></th>
					<th>Code</th>
					<th>Name</th>
				</tr>
			</thead>
			<tbody>
				<?php 
foreach (CommissioningBodyType::model()->findAll(array('order' => 'name asc')) as $i => $cb) {
    ?>
					<tr class="clickable" data-id="<?php 
    echo $cb->id;
    ?>
" data-uri="admin/editCommissioningBodyType?commissioning_body_type_id=<?php 
    echo $cb->id;
    ?>
">
						<td><input type="checkbox" name="commissioning_body_type[]" value="<?php 
    echo $cb->id;
    ?>
" class="wards" /></td>
						<td><?php 
    echo $cb->shortname;
    ?>
 * (C) Moorfields Eye Hospital NHS Foundation Trust, 2008-2011
 * (C) OpenEyes Foundation, 2011-2013
 * This file is part of OpenEyes.
 * OpenEyes is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 * OpenEyes is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along with OpenEyes in a file titled COPYING. If not, see <http://www.gnu.org/licenses/>.
 *
 * @link http://www.openeyes.org.uk
 *
 * @author OpenEyes <*****@*****.**>
 * @copyright Copyright (c) 2008-2011, Moorfields Eye Hospital NHS Foundation Trust
 * @copyright Copyright (c) 2011-2013, OpenEyes Foundation
 * @license http://www.gnu.org/licenses/gpl-3.0.html The GNU General Public License V3.0
 */
if ($cbs_by_type = $this->patient->getDistinctCommissioningBodiesByType()) {
    foreach (CommissioningBodyType::model()->findAll() as $cbt) {
        if (array_key_exists($cbt->id, $cbs_by_type)) {
            ?>
			<section class="box patient-info js-toggle-container">
				<h3 class="box-title"><?php 
            echo $cbt->name;
            ?>
(s):</h3>
				<a href="#" class="toggle-trigger toggle-hide js-toggle">
					<span class="icon-showhide">
						Show/hide this section
					</span>
				</a>
				<div class="js-toggle-body">
					<?php 
            foreach ($cbs_by_type[$cbt->id] as $cb) {
 /**
  * Gets the zip file, extracts the CSV file (from the zip) and processes it.
  * 
  * @param string $type     like 'Gp'
  * @param string $interval full|monthly|quarterly
  * @param array  $fields
  * @param string $file     the zip file
  */
 private function processCSV($type, $interval, $fields, $file)
 {
     $lineCount = $this->getLineCountFromZip($file);
     $fileHandler = $this->getFilePointer($file);
     $this->pcu = new PostCodeUtility();
     $this->countryId = Country::model()->findByAttributes(array('code' => 'GB'))->id;
     $this->cbtId = CommissioningBodyType::model()->findByAttributes(array('shortname' => 'CCG'))->id;
     echo "Type: {$type}\n";
     echo "Total rows : {$lineCount}\n";
     echo 'Progress :          ';
     $i = 1;
     while ($row = fgetcsv($fileHandler)) {
         $percent = round($i / $lineCount * 100, 1);
         echo "";
         // 7 char back
         echo str_pad($percent, 5, ' ', STR_PAD_LEFT) . ' %';
         $data = array_combine(array_pad($fields, count($row), ''), $row);
         $transaction = Yii::app()->db->beginTransaction();
         try {
             if ($type == 'gp' && ($interval == 'monthly' || $interval == 'quarterly')) {
                 // Monthly and quarterly files contain both GPs and Practices.
                 if (preg_match('/^G\\d{7}$/', $data['code'])) {
                     $this->importGp($data);
                 } elseif (preg_match('/^([A-Z]\\d{5}|[A-Z]{3}\\d{3})$/', $data['code'])) {
                     $this->importPractice($data);
                 } else {
                     throw new Exception("Unknown code format: {$data['code']}", static::$UNRECOGNISED_CODE);
                 }
             } else {
                 $this->{"import{$type}"}($data);
             }
             $transaction->commit();
         } catch (Exception $e) {
             $message = "Error processing {$type} row:\n" . CVarDumper::dumpAsString($row) . "\n{$e}";
             Yii::log($message, CLogger::LEVEL_ERROR);
             echo "\n{$message}\n";
             $transaction->rollback();
             throw $e;
         }
         ++$i;
     }
     echo "\n";
 }
* (C) Moorfields Eye Hospital NHS Foundation Trust, 2008-2011
* (C) OpenEyes Foundation, 2011-2013
* This file is part of OpenEyes.
* OpenEyes is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* OpenEyes is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with OpenEyes in a file titled COPYING. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://www.openeyes.org.uk
*
* @author OpenEyes <*****@*****.**>
* @copyright Copyright (c) 2008-2011, Moorfields Eye Hospital NHS Foundation Trust
* @copyright Copyright (c) 2011-2012, OpenEyes Foundation
* @license http://www.gnu.org/licenses/gpl-3.0.html The GNU General Public License V3.0
*/
$exam_api = Yii::app()->moduleAPI->get('OphCiExamination');
$ccg = CommissioningBodyType::model()->find('shortname=?', array('CCG'));
$cb = $patient->getCommissioningBodyOfType($ccg);
$gp_cb = $patient->gp && $patient->practice ? $patient->practice->getCommissioningBodyOfType($ccg) : null;
?>

This email was generated from the OpenEyes Therapy Application event

<?php 
if ($site = $service_info->site) {
    echo 'Intended Site: ' . $site->name;
}
?>

Request for AMD Injection booking sent by: <?php 
echo $diagnosis->user->getReportDisplay() . "\n";
?>
 /**
  * @return array
  */
 private function getTemplateData()
 {
     // at the moment we are using a fixed type of commissioning body, but it's possible that in the future this
     // might need to be determined in a more complex fashion, so we pass the type through to the templates
     $cbody_type = CommissioningBodyType::model()->findByPk(1);
     return array('event' => $this->event, 'patient' => $this->event->episode->patient, 'cbody_type' => $cbody_type, 'diagnosis' => $this->getElement('Element_OphCoTherapyapplication_Therapydiagnosis'), 'suitability' => $this->getElement('Element_OphCoTherapyapplication_PatientSuitability'), 'service_info' => $this->getElement('Element_OphCoTherapyapplication_MrServiceInformation'), 'exceptional' => $this->getElement('Element_OphCoTherapyapplication_ExceptionalCircumstances'));
 }
Exemple #11
0
 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;
 }
Exemple #12
0
 public function actionEditCommissioningBodyService()
 {
     $address = new Address();
     $contact = new Contact();
     $address->country_id = 1;
     // to allow the commissioning body type list to be filtered
     $commissioning_bt = null;
     $commissioning_bst = null;
     if ($cbs_id = $this->getApp()->request->getQuery('commissioning_body_service_id')) {
         if (!($cbs = CommissioningBodyService::model()->findByPk($cbs_id))) {
             throw new Exception('CommissioningBody not found: ' . $cbs_id);
         }
         if ($cbs->contact) {
             $contact = $cbs->contact;
             if ($cbs->contact->address) {
                 $address = $cbs->contact->address;
             }
         }
     } else {
         $cbs = new CommissioningBodyService();
         if ($commissioning_bt_id = Yii::app()->request->getQuery('commissioning_body_type_id')) {
             if (!($commissioning_bt = CommissioningBodyType::model()->findByPk($commissioning_bt_id))) {
                 throw new CHttpException(404, 'Unrecognised Commissioning Body Type ID');
             }
         }
         if ($service_type_id = Yii::app()->request->getQuery('service_type_id')) {
             if (!($commissioning_bst = CommissioningBodyServiceType::model()->findByPk($service_type_id))) {
                 throw new CHttpException(404, 'Unrecognised Service Type ID');
             }
             $cbs->setAttribute('commissioning_body_service_type_id', $service_type_id);
         }
     }
     $errors = array();
     if (!($return_url = Yii::app()->request->getQuery('return_url'))) {
         $return_url = '/admin/commissioning_body_services';
     }
     if (!empty($_POST)) {
         $cbs->attributes = $_POST['CommissioningBodyService'];
         if (!$cbs->validate()) {
             $errors = $cbs->getErrors();
         }
         $contact->attributes = $_POST['Contact'];
         if (!$contact->validate()) {
             $errors = array_merge($errors, $contact->getErrors());
         }
         $address->attributes = $_POST['Address'];
         if (!$address->validate()) {
             $errors = array_merge($errors, $address->getErrors());
         }
         if (empty($errors)) {
             $transaction = Yii::app()->db->beginInternalTransaction();
             try {
                 if (!$contact->save()) {
                     throw new Exception('Unable to save contact: ' . print_r($contact->getErrors(), true));
                 }
                 if (!$address->id) {
                     $cbs->contact_id = $contact->id;
                     $address->contact_id = $contact->id;
                 }
                 $method = $cbs->id ? 'edit' : 'add';
                 if (!$cbs->save()) {
                     throw new Exception('Unable to save CommissioningBodyService: ' . print_r($cbs->getErrors(), true));
                 }
                 if (!$address->save()) {
                     throw new Exception('Unable to save CommissioningBodyService address: ' . print_r($address->getErrors(), true));
                 }
                 Audit::add('admin-CommissioningBodyService', $method, $cbs->id);
                 $transaction->commit();
             } catch (Exception $e) {
                 $transaction->rollback();
                 throw $e;
             }
             $this->redirect($return_url);
         }
     }
     $this->render('//admin/editCommissioningBodyService', array('commissioning_bt' => $commissioning_bt, 'commissioning_bst' => $commissioning_bst, 'cbs' => $cbs, 'address' => $address, 'errors' => $errors, 'return_url' => $return_url));
 }