/** * Selector is a string key or an array of keys. Keys may be in one of these formats: * * Fully specified Integer: <dictionary_name>:datatype(<concept_datatype_id>) * Fully specified name: <dictionary_name>:datatype(<concept_datatype_name>) * Default dictionary: <concept_datatype_id> * Only name: <concept_datatype_name> * * <concept_datatype_name> must be quoted if it contains non-word characters. * Note that setDefaultDictionary() must be called if using the default dictionary format. */ public function getDatatypes($selector) { $cdc = new ConceptDatatypeCollection(); if (!is_array($selector)) { $selector = array($selector); } foreach ($selector as $key) { $key = strtolower(trim($key)); // <dictionary_name>:datatype(<concept_datatype_id>) OR <dictionary_name>:datatype(<concept_datatype_name>) if (strpos($key, ':datatype(', 0) !== false && strpos($key, ')', strlen($key) - 1) !== false) { // Parse out dict_name and datatype_identifier $dict_name = trim(substr($key, 0, strpos($key, ':datatype'))); $datatype_identifier = trim(substr($key, strlen($dict_name) + strlen(':datatype('), strlen($key) - strlen($dict_name) - strlen(':datatype(') - 1)); if (substr($datatype_identifier, 0, 1) == '"' && substr($datatype_identifier, strlen($datatype_identifier) - 1, 1) == '"') { $datatype_identifier = trim(substr($datatype_identifier, 1, strlen($datatype_identifier) - 2)); } // <dictionary_name>:datatype(<concept_datatype_id>) if ($this->isInteger($datatype_identifier)) { $new_key = $dict_name . ':datatype(' . $datatype_identifier . ')'; if ($this->IsMember($new_key)) { $cdc->Add($new_key, $this->Get($new_key)); } } else { foreach ($this->getKeys() as $datatype_key) { $datatype = $this->Get($datatype_key); if (strtolower($datatype->name) == $datatype_identifier && strtolower($datatype->getSourceDictionary()->dict_db) == $dict_name) { $cdc->Add($datatype_key, $datatype); break; } } } } else { // <concept_datatype_id> - this uses the default dictionary setting if ($this->isInteger($key)) { // Default dictionary key if (!$this->css_dict) { trigger_error('Default dictionary must be set in ConceptDatatypeCollection if using default dictionary format', E_USER_ERROR); } $key = $this->css_dict->dict_db . ':datatype(' . $key . ')'; if ($this->IsMember($key)) { $cdc->Add($key, $this->Get($key)); } } else { foreach ($this->getKeys() as $datatype_key) { $datatype = $this->Get($datatype_key); if (strtolower($datatype->name) == $key) { $cdc->Add($datatype_key, $datatype); } } } } } return $cdc; }
/** * Loads the concept datatypes from the specified dictionary. * @return ConceptDatatypeCollection */ public function loadConceptDatatypes(ConceptSearchSource $css_dict) { // get the data $sql_datatypes = 'select concept_datatype_id, name, description, hl7_abbreviation, uuid ' . 'from concept_datatype ' . 'where retired != 1 ' . 'order by name'; if ($this->debug) { echo '<p><b>Loading concept datatypes for ' . $css_dict->dict_db . ':</b><br> ' . $sql_datatypes . '</p>'; } $rsc_datatypes = mysql_query($sql_datatypes, $css_dict->getConnection()); if (!$rsc_datatypes) { echo "Could not query db in ConceptSearchFactory::_loadConceptDatatypes: " . mysql_error(); } // Create the datatype collection $cdc = new ConceptDatatypeCollection(); while ($row = mysql_fetch_assoc($rsc_datatypes)) { $cd = new ConceptDatatype($row['concept_datatype_id'], $row['name'], $row['description'], $row['hl7_abbreviation'], $row['uuid']); $cd->setSourceDictionary($css_dict); // $key = '<database_name>:datatype(<concept_datatype_id>) $key = $css_dict->dict_db . ':datatype(' . $row['concept_datatype_id'] . ')'; $cdc->Add($key, $cd); } return $cdc; }