/**
  * Assigns relevancy to all visible terms
  * NOTE: This is inefficient because it requires an additional pass through ALL concepts.
  * Probably better to replace this with individual SQL queries 
  */
 private function _assignRelevancy(ConceptSearchResultsGroup $csrg)
 {
     // Prepare arrays of search terms used to assign concept relevancy
     $ctsc = $csrg->csg->getSearchTermCollection();
     $arr_numeric_term_type = array(MCL_SEARCH_TERM_TYPE_UUID, MCL_SEARCH_TERM_TYPE_CONCEPT_ID, MCL_SEARCH_TERM_TYPE_CONCEPT_ID_RANGE, MCL_SEARCH_TERM_TYPE_MAP_CODE);
     $arr_numeric_search_term = $ctsc->getSearchTerms($arr_numeric_term_type, null, true);
     $arr_text_term_type = array(MCL_SEARCH_TERM_TYPE_TEXT, MCL_SEARCH_TERM_TYPE_CONCEPT_NAME);
     $arr_text_search_term = $ctsc->getSearchTerms($arr_text_term_type, null, true);
     // Iterate through each dictionary source in the group
     foreach ($csrg->getDictionarySources() as $dict_key) {
         // Iterate through concepts in the current dictionary source
         $arr_concept_id = $csrg->getVisibleConceptIds($dict_key);
         foreach ($arr_concept_id as $_concept_id) {
             // Get the concept and relevancy
             $c = $csrg->getConcept($_concept_id, $dict_key);
             $relevancy = $csrg->getRelevancy($c);
             // Bump up relevancy for exact matches: CONCEPT_ID, ID RANGES, MAP_CODE, UUID
             if ($relevancy < MCL_MAX_RELEVANCY) {
                 foreach ($arr_numeric_search_term as $search_term) {
                     if ($search_term->isMatch($c)) {
                         $relevancy = MCL_MAX_RELEVANCY;
                         break;
                     }
                 }
             }
             // Bump up exact name matches: TEXT, NAME
             if ($relevancy < MCL_MAX_RELEVANCY) {
                 // loop through each concept name
                 foreach ($c->getConceptNameIds() as $concept_name_id) {
                     $concept_name = $c->getConceptName($concept_name_id)->name;
                     if (str_word_count($concept_name) !== count($arr_text_search_term)) {
                         break;
                     }
                     $match = true;
                     foreach ($arr_text_search_term as $search_term) {
                         if (!$search_term->isMatch($c, MCL_SEARCH_TERM_TYPE_CONCEPT_NAME)) {
                             $match = false;
                             break;
                         }
                     }
                     if ($match) {
                         $relevancy = MCL_MAX_RELEVANCY;
                         break;
                     }
                 }
             }
             // Set relevancy
             $csrg->setRelevancy($c, $relevancy);
         }
         // End concept loop
     }
     // End dictionary source loop
 }
 /**
  * Render the concept column
  */
 protected function _renderColumn_Concept(ConceptSearchResultsGroup $csrg, Concept $c, $group_i, $i)
 {
     echo "\n<td class=\"col_1\">\n\t";
     // Concept ID, name, datatype/class
     echo '<table class="tblConceptHeader" cellpadding="0" cellspacing="1">' . "\n\t\t<tr>";
     // Concept ID
     $concept_key = $c->css_dict->dict_id . '_' . $group_i . '_' . $c->concept_id;
     echo '<td class="td_concept_id" nowrap="nowrap">';
     echo '<a id="concept_id_' . $concept_key . '" href="' . $this->getSearchUrl('id:' . $c->concept_id, array('source' => $c->css_dict->dict_db)) . '">' . $c->concept_id . '</a>&nbsp;-&nbsp;</td>' . "\n\t\t";
     echo '<td class="td_concept_name">';
     $concept_name_class = 'concept_name';
     if ($c->retired) {
         $concept_name_class .= ' spanRetired';
     }
     // Concept name
     $concept_name = htmlentities($c->getPreferredName());
     $arr_term_type = array(MCL_SEARCH_TERM_TYPE_TEXT, MCL_SEARCH_TERM_TYPE_CONCEPT_NAME);
     $arr_search_term = $csrg->csg->getSearchTermCollection()->getSearchTerms($arr_term_type, null, true);
     foreach ($arr_search_term as $search_term) {
         $concept_name = preg_replace('/\\b(' . addslashes($search_term->needle) . ')/i', '<span class="h">$1</span>', $concept_name);
     }
     echo "<span class=\"" . $concept_name_class . "\">" . $concept_name . '</span> ';
     // Language
     echo '<span class="language">[' . $c->getPreferredLocale() . ']</span>';
     // Class and datatype
     echo '<br /><span class="concept_class">' . $c->class_name . '</span> / ';
     echo '<span class="concept_datatype">' . $c->datatype_name . '</span>';
     echo '</td></tr></table>' . "\n";
     // Start the content div
     echo '<div class="content">';
     // Dictionary
     echo '<div style="margin-top:4px;"><em>Dictionary:</em> ';
     echo '<span class="mcl_dict_color_' . $c->css_dict->dict_id . '">';
     echo $c->css_dict->dict_name . ' (' . $c->css_dict->dict_db . ')';
     echo '</span></div>';
     // Relevancy
     if ($this->show_relevancy) {
         echo '<p>Rating: ' . number_format($csrg->getRelevancy($c), 2) . '</p>';
     }
     // Concept synonyms
     if ($c->getNumberSynonyms() > 1) {
         echo '<div style="margin-top:4px;"><em>Synonyms:</em>';
         echo '<ul class="concept_synonyms">';
         foreach ($c->getConceptNameIds() as $_name_i) {
             $cn = $c->getConceptName($_name_i);
             if ($c->getPreferredNameId() != $cn->concept_name_id) {
                 $concept_name = htmlentities($cn->name);
                 foreach ($arr_search_term as $search_term) {
                     $concept_name = preg_replace('/\\b(' . addslashes($search_term->needle) . ')/i', '<span class="h">$1</span>', $concept_name);
                 }
                 echo '<li>' . $concept_name . ' <em>[' . $cn->locale . ']</em></li>';
             }
         }
         echo '</ul></div>';
     }
     // Concept Attributes
     // Start the concept attributes table
     echo '<div style="cursor:pointer;padding-top:8px;" ' . "onclick=\"javascript:toggleConceptDetailsPane('" . $concept_key . "');\">" . '<img id="img_toggle_' . $concept_key . '" src="images/box_plus.jpg" border="0" alt="Toggle" />&nbsp;&nbsp;' . '<span style="color:black;">Concept Attributes</span></div>';
     echo '<table id="tbl_attr_' . $concept_key . '" class="tbl_numeric_range" cellspacing="0" style="display:none;">';
     // Numeric Range
     $range = null;
     if ($range = $c->getNumericRange()) {
         echo '<tr class="attr_header"><th>&nbsp;</th><th>Absolute</th><th>Critical</th><th>Normal</th></tr>';
         echo '<tr class="attr"><th>High</th><td>' . $range->absolute_high . '</td><td>' . $range->critical_high . '</td><td>' . $range->normal_high . '</td></tr>';
         echo '<tr class="attr"><th>Low</th><td>' . $range->absolute_low . '</td><td>' . $range->critical_low . '</td><td>' . $range->normal_low . '</td></tr>';
     }
     // Other attributes
     echo '<tr class="attr_header"><th>Attr</th><th colspan="3">Value</th></tr>';
     if ($range) {
         if ($range->units) {
             echo '<tr class="attr"><th>Units</th><td colspan="3">' . $range->units . '</td></tr>';
         }
         echo '<tr class="attr"><th>Precise</th><td colspan="3">';
         if (is_null($range->precise)) {
             echo 'null';
         } elseif (!$range->precise) {
             echo 'No';
         } else {
             echo 'Yes';
         }
         echo '</td></tr>';
     }
     if ($c->uuid) {
         // concept uuid div - this is only displayed on mouseover of the concept name
         echo '<tr class="attr"><th>UUID</th><td colspan="3">' . '<pre style="font-size:8pt;margin:0;padding:0;">' . substr($c->uuid, 0, 16) . "\n" . substr($c->uuid, 16, 16) . '</pre></td></tr>';
     }
     echo '<tr class="attr"><th>Is Set</th><td colspan="3">';
     if ($c->is_set) {
         echo 'Yes';
     } else {
         echo 'No';
     }
     echo '</td></tr>';
     if ($c->hasAttributes()) {
         foreach ($c->getAttributesArray() as $attr_name => $attr_value) {
             if (!$attr_value) {
                 continue;
             }
             echo '<tr class="attr"><th>' . $attr_name . '</th><td colspan="3">' . $attr_value . '</td></tr>';
         }
     }
     echo '</table>';
     // end the content div
     echo '</div>';
     echo '</td>';
 }