Returns the static model of the specified AR class.
public static model ( $className = __CLASS__ ) : SecondaryToCommonOphthalmicDisorder | ||
Результат | SecondaryToCommonOphthalmicDisorder | the static model class |
/** * Wrapper to handle ordering for secondary to disorders * * @param $cod * @return mixed */ public function getNextDisplayOrderForParent($cod) { if (!array_key_exists($cod->id, $this->second_display_order)) { $criteria = new CDbCriteria(); $criteria->addCondition('parent_id = :id'); $criteria->params[':id'] = $cod->id; $criteria->order = 'display_order desc'; $criteria->limit = 1; if ($st = SecondaryToCommonOphthalmicDisorder::model()->find($criteria)) { $this->second_display_order[$cod->id] = $st->display_order; } else { $this->second_display_order[$cod->id] = 0; } } return ++$this->second_display_order[$cod->id]; }
public function actionImport($args) { $filename = $args[0]; if (!$filename) { $this->usageError('Import filename required'); } if (!file_exists($filename)) { $this->usageError("Cannot find import file " . $filename); } if (!$this->reset_parent) { $this->required_cols[] = 'disorder_id'; } $connection = Yii::app()->db; $transaction = $connection->beginTransaction(); try { SecondaryToCommonOphthalmicDisorder::model()->deleteAll(); $file = file($filename); $columns = array(); $count = 0; $warnings = array(); foreach ($file as $index => $line) { if (!$index) { $columns = str_getcsv($line, ',', '"'); foreach ($this->required_cols as $req) { if (!in_array($req, $columns)) { throw new Exception("Missing required column '{$req}' from file {$filename}"); } } } else { if (!strlen(trim($line))) { // skip empty line continue; } $record = str_getcsv($line, ',', '"'); $data = array(); foreach ($columns as $i => $col) { $data[$col] = $record[$i]; } if (!($subspecialty = $this->getSubspecialty($data['subspecialty_code']))) { $warnings[] = "no subspecialty found for {$data['subspecialty_code']}"; } else { if ($this->reset_parent) { $this->resetSubspecialty($subspecialty); } if ($cod = $this->getCOD($data['parent_disorder_id'], $subspecialty)) { if ($st_disorder = $this->getDisorder($data['disorder_id'])) { $st = new SecondaryToCommonOphthalmicDisorder(); $st->parent_id = $cod->id; $st->disorder_id = $st_disorder->id; $st->save(); $count++; } else { if (!$this->reset_parent) { $warnings[] = "Cannot find disorder with id {$data['disorder_id']}"; } } } else { $warnings[] = "{$data['parent_disorder_id']} not a common disorder for {$subspecialty->name}"; } } } } echo "Committing changes ...\n"; $transaction->commit(); echo "{$count} records created\n"; if ($warnings) { echo "There were " . count($warnings) . " warnings:\n"; foreach ($warnings as $warn) { echo $warn . "\n"; } } } catch (Exception $e) { $transaction->rollback(); $this->usageError($e->getMessage()); } }
public function getLetter_string() { $text = ""; $findings = array(); $finding_ids = array(); if ($et_findings = Element_OphCiExamination_FurtherFindings::model()->find('event_id=?', array($this->event_id))) { foreach (OphCiExamination_FurtherFindings_Assignment::model()->findAll('element_id=?', array($et_findings->id)) as $finding) { $finding_ids[] = $finding->finding_id; $findings[] = $finding; } } $disorders = array(); $disorder_ids = array('Left' => array(), 'Right' => array(), 'Both' => array()); $is_principal = array(); foreach (OphCiExamination_Diagnosis::model()->findAll('element_diagnoses_id=?', array($this->id)) as $diagnosis) { $disorder_ids[$diagnosis->eye->name][] = $diagnosis->disorder_id; $disorders[] = $diagnosis; $is_principal[$diagnosis->disorder_id] = $diagnosis->principal; } $secto_strings = array(); $used_disorder_ids = array(); $used_finding_ids = array(); if (isset(\Yii::app()->session['selected_firm_id']) && \Yii::app()->session['selected_firm_id'] !== null) { $firm = \Firm::model()->findByPk(\Yii::app()->session['selected_firm_id']); $subspecialty = $firm->serviceSubspecialtyAssignment->subspecialty; foreach ($disorders as $disorder) { foreach (\SecondaryToCommonOphthalmicDisorder::model()->with('parent')->findAll('t.disorder_id=? and parent.subspecialty_id=?', array($disorder->disorder_id, $subspecialty->id)) as $secto_disorder) { if ($secto_disorder->letter_macro_text) { if ($secto_disorder->parent->disorder_id) { if (in_array($secto_disorder->parent->disorder_id, $disorder_ids[$disorder->eye->name]) || in_array($secto_disorder->parent->disorder_id, $disorder_ids['Both'])) { $secto_strings[] = ($is_principal[$disorder->disorder_id] || $is_principal[$secto_disorder->parent->disorder_id] ? '' : 'Secondary diagnosis: ') . $disorder->eye->name . " " . $secto_disorder->letter_macro_text; $used_disorder_ids[] = $disorder->disorder_id; $used_disorder_ids[] = $secto_disorder->parent->disorder_id; } } elseif ($secto_disorder->parent->finding_id) { if (in_array($secto_disorder->parent->finding_id, $finding_ids)) { $secto_strings[] = ($is_principal[$disorder->disorder_id] ? '' : 'Secondary diagnosis: ') . $disorder->eye->name . " " . $secto_disorder->letter_macro_text; $used_disorder_ids[] = $disorder->disorder_id; $used_finding_ids[] = $secto_disorder->parent->finding_id; } } } } } foreach ($findings as $finding) { foreach (\SecondaryToCommonOphthalmicDisorder::model()->with('parent')->findAll('t.finding_id=? and parent.subspecialty_id=?', array($finding->finding_id, $subspecialty->id)) as $secto_disorder) { if ($secto_disorder->letter_macro_text) { if ($secto_disorder->parent->disorder_id) { if ($eye = $this->getEyeForDisorder($secto_disorder->parent->disorder_id, $disorder_ids)) { $secto_strings[] = ($is_principal[$secto_disorder->parent->disorder_id] ? '' : 'Secondary diagnosis: ') . $eye . " " . $secto_disorder->letter_macro_text; $used_disorder_ids[] = $secto_disorder->parent->disorder_id; $used_finding_ids[] = $finding->finding_id; } } } } } } $criteria = new \CDbCriteria(); $criteria->addCondition('element_diagnoses_id=:ed'); $criteria->params[':ed'] = $this->id; $criteria->addCondition('principal=1'); if (!empty($used_disorder_ids)) { $criteria->addNotInCondition('disorder_id', $used_disorder_ids); } if ($principal = OphCiExamination_Diagnosis::model()->find($criteria)) { $text .= "Principal diagnosis: " . $principal->eye->adjective . " " . $principal->disorder->term . "\n"; } if (!empty($secto_strings)) { $text .= implode("\n", $secto_strings) . "\n"; } $criteria = new \CDbCriteria(); $criteria->addCondition('element_diagnoses_id=:ed'); $criteria->params[':ed'] = $this->id; $criteria->addCondition('principal=0'); if (!empty($used_disorder_ids)) { $criteria->addNotInCondition('disorder_id', $used_disorder_ids); } foreach (OphCiExamination_Diagnosis::model()->findAll($criteria) as $diagnosis) { if ($diagnosis->disorder) { $text .= "Secondary diagnosis: " . $diagnosis->eye->adjective . " " . $diagnosis->disorder->term . "\n"; } } if ($ff = Element_OphCiExamination_FurtherFindings::model()->find('event_id=?', array($this->event_id))) { if ($string = $ff->getFurtherFindingsAssignedString($used_finding_ids)) { $text .= "Further Findings: {$string}\n"; } } return $text; }
/** * Returns a JSON response. Empty if the provided disorder id is not in the common list for the * current session firm subspecialty. Otherwise, contains details of disorder, and all secondary to disorders * configured for the disorder/subspecialty * * @param $id */ public function actionIsCommonOphthalmicWithSecondary($id) { $firm = Firm::model()->findByPk(Yii::app()->session['selected_firm_id']); $result = array(); if ($subspecialty_id = $firm->getSubspecialtyID()) { if ($cd = CommonOphthalmicDisorder::model()->with(array('disorder', 'secondary_to_disorders'))->findByAttributes(array('disorder_id' => $id, 'subspecialty_id' => $subspecialty_id))) { $result['disorder'] = array('id' => $cd->disorder_id, 'term' => $cd->disorder->term); if ($sts = $cd->secondary_to_disorders) { $result['secondary_to'] = array(); foreach ($sts as $st) { $result['secondary_to'][] = array('id' => $st->id, 'term' => $st->term); } } echo CJSON::encode($result); } elseif ($sts = SecondaryToCommonOphthalmicDisorder::model()->with(array('disorder', 'parent'))->findAll('t.disorder_id = :disorder_id AND parent.subspecialty_id = :subspecialty_id', array(":disorder_id" => $id, ":subspecialty_id" => $subspecialty_id))) { $result['disorder'] = array('id' => $sts[0]->disorder_id, 'term' => $sts[0]->disorder->term); $result['owned_by'] = array(); foreach ($sts as $st) { $result['owned_by'][] = array('id' => $st->parent->disorder_id); } echo CJSON::encode($result); } } }