Exemplo n.º 1
0
 /**
  * True if this search term object matches the passed Concept; false otherwise.
  * @param Concept $c
  * @param mixed $search_term_type One of the MCL_SEARCH_TERM_TYPE_* constants. Use to force a specific type of comparison
  * @return bool
  */
 public function isMatch(Concept $c, $search_term_type = null)
 {
     // Prepare the search term type for comparison
     if (is_null($search_term_type)) {
         $search_term_type = $this->term_type;
     }
     // Now do the comparison
     if ($search_term_type == MCL_SEARCH_TERM_TYPE_ALL) {
         return true;
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_CONCEPT_ID) {
         if ($this->needle == $c->concept_id) {
             return true;
         }
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_CONCEPT_ID_RANGE) {
         list($min, $max) = explode('-', $this->needle);
         if ($c->concept_id >= $min && $c->concept_id <= $max) {
             return true;
         }
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_MAP_CODE) {
         foreach ($c->getConceptMappingIds() as $mapcode_id) {
             $subject = $c->getConceptMapping($mapcode_id)->source_code;
             if (preg_match('/\\b' . addslashes($this->needle) . '/i', $subject)) {
                 return true;
             }
         }
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_MAP_CODE_RANGE) {
         // TODO: MCL_SEARCH_TERM_TYPE_MAP_CODE_RANGE
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_TEXT) {
         foreach ($c->getConceptNameIds() as $name_id) {
             $subject = $c->getConceptName($name_id)->name;
             if (preg_match('/\\b' . addslashes($this->needle) . '/i', $subject)) {
                 return true;
             }
         }
         foreach ($c->getConceptDescriptionIds() as $desc_id) {
             $subject = $c->getConceptDescription($desc_id)->description;
             if (preg_match('/\\b' . addslashes($this->needle) . '/i', $subject)) {
                 return true;
             }
         }
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_CONCEPT_NAME) {
         foreach ($c->getConceptNameIds() as $name_id) {
             $subject = $c->getConceptName($name_id)->name;
             if (preg_match('/\\b' . addslashes($this->needle) . '/i', $subject)) {
                 return true;
             }
         }
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_CONCEPT_DESCRIPTION) {
         foreach ($c->getConceptDescriptionIds() as $desc_id) {
             $subject = $c->getConceptDescription($desc_id)->description;
             if (preg_match('/\\b' . addslashes($this->needle) . '/i', $subject)) {
                 return true;
             }
         }
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_UUID) {
         if (strtolower($this->needle) == strtolower(substr($c->uuid, 0, strlen($this->needle)))) {
             return true;
         }
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_LIST) {
         // TODO: MCL_SEARCH_TERM_TYPE_LIST
     } elseif ($search_term_type == MCL_SEARCH_TERM_TYPE_MAP_SOURCE) {
         // TODO: MCL_SEARCH_TERM_TYPE_MAP_SOURCE
     }
     return false;
 }