Skip to content

Commit

Permalink
Snomed support improvements and bug fixes:
Browse files Browse the repository at this point in the history
 -Supports import of snomed Spanish International code set
 -Searching function will support any snomed language international code set
 -Supports importing of snomed US extension set that precedes the main snomed English International set
 -Supports filename of the 03-01-2012 snomed US extension code set
  • Loading branch information
bradymiller committed Jan 30, 2013
1 parent 48e09b4 commit 2564654
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 31 deletions.
67 changes: 49 additions & 18 deletions custom/code_types.inc.php
Expand Up @@ -325,43 +325,74 @@ function code_set_search($form_code_type,$search_term="",$count=false,$active=tr
$res = sqlStatement($query,$sql_bind_array);
}
}
else if ($code_types[$form_code_type]['external'] == 2 || $code_types[$form_code_type]['external'] == 7) {
else if ($code_types[$form_code_type]['external'] == 2) {
// Search from SNOMED (RF1) diagnosis codeset tables OR Search from SNOMED (RF1) clinical terms codeset tables
if ($code_types[$form_code_type]['external'] == 2) {
// Search from SNOMED (RF1) diagnosis codeset tables
$diagnosis_sql_specific = " ref.FullySpecifiedName LIKE '%(disorder)' ";

// Search from SNOMED (RF1) diagnosis codeset tables
$diagnosis_sql_specific = " ref_conc.FullySpecifiedName LIKE '%(disorder)' ";
if ($active) {
// Only filter for active codes
// If there is no entry in codes sql table, then default to active
// (this is reason for including NULL below)
$active_query=" AND (c.active = 1 || c.active IS NULL) ";
}
else {
// Search from SNOMED (RF1) clinical terms codeset tables
$diagnosis_sql_specific = " 1=1 ";
// Ensure the sct_concepts sql table exists
$check_table = sqlQuery("SHOW TABLES LIKE 'sct_concepts'");
$check_table_2 = sqlQuery("SHOW TABLES LIKE 'sct_descriptions'");
if ( !(empty($check_table)) && !(empty($check_table_2)) ) {
$sql_bind_array = array();
$query = "SELECT ref_desc.ConceptId as code, ref_desc.Term as code_text, " .
"c.id, c.code_type, c.modifier, c.units, c.fee, " .
"c.superbill, c.related_code, c.taxrates, c.cyp_factor, c.active, c.reportable, c.financial_reporting, " .
"'" . add_escape_custom($form_code_type) . "' as code_type_name " .
"FROM `sct_concepts` as ref_conc " .
"LEFT OUTER JOIN `sct_descriptions` as ref_desc " .
"ON ref_conc.ConceptId = ref_desc.ConceptId AND ref_conc.ConceptStatus = 0 AND ref_desc.DescriptionStatus = 0 AND ref_desc.DescriptionType = 1 " .
"LEFT OUTER JOIN `codes` as c " .
"ON ref_desc.ConceptId = c.code AND c.code_type = ? ";
array_push($sql_bind_array,$code_types[$form_code_type]['id']);
if ($return_only_one) {
$query .= "WHERE (ref_desc.ConceptId = ? AND $diagnosis_sql_specific) $active_query $query_filter_elements ";
array_push($sql_bind_array,$search_term);
}
else {
$query .= "WHERE ((ref_desc.Term LIKE ? OR ref_desc.ConceptId LIKE ?) AND $diagnosis_sql_specific ) $active_query $query_filter_elements ";
array_push($sql_bind_array,"%".$search_term."%","%".$search_term."%");
}
$query .= "ORDER BY ref_desc.ConceptId $limit_query";
$res = sqlStatement($query,$sql_bind_array);
}
}
else if ($code_types[$form_code_type]['external'] == 7) {
// Search from SNOMED (RF1) diagnosis codeset tables OR Search from SNOMED (RF1) clinical terms codeset tables

if ($active) {
// Only filter for active codes
// If there is no entry in codes sql table, then default to active
// (this is reason for including NULL below)
$active_query=" AND (c.active = 1 || c.active IS NULL) ";
}
// Ensure the sct_concepts sql table exists
$check_table = sqlQuery("SHOW TABLES LIKE 'sct_concepts'");
$check_table = sqlQuery("SHOW TABLES LIKE 'sct_descriptions'");
if ( !(empty($check_table)) ) {
$sql_bind_array = array();
$query = "SELECT ref.ConceptId as code, ref.FullySpecifiedName as code_text, " .
$query = "SELECT ref.ConceptId as code, ref.Term as code_text, " .
"c.id, c.code_type, c.modifier, c.units, c.fee, " .
"c.superbill, c.related_code, c.taxrates, c.cyp_factor, c.active, c.reportable, c.financial_reporting, " .
"'" . add_escape_custom($form_code_type) . "' as code_type_name " .
"FROM `sct_concepts` as ref " .
"FROM `sct_descriptions` as ref " .
"LEFT OUTER JOIN `codes` as c " .
"ON ref.ConceptId = c.code AND c.code_type = ? ";
array_push($sql_bind_array,$code_types[$form_code_type]['id']);
if ($return_only_one) {
$query .= "WHERE (ref.ConceptId = ? AND $diagnosis_sql_specific) $active_query $query_filter_elements ";
$query .= "WHERE ref.ConceptId = ? $active_query $query_filter_elements ";
array_push($sql_bind_array,$search_term);
}
else {
$query .= "WHERE ((ref.FullySpecifiedName LIKE ? OR ref.ConceptId LIKE ?) AND $diagnosis_sql_specific ) $active_query $query_filter_elements ";
$query .= "WHERE (ref.Term LIKE ? OR ref.ConceptId LIKE ?) $active_query $query_filter_elements ";
array_push($sql_bind_array,"%".$search_term."%","%".$search_term."%");
}
$query .= "AND ref.ConceptStatus = 0 " .
$query .= "AND ref.DescriptionStatus = 0 AND ref.DescriptionType = 1 " .
"ORDER BY ref.ConceptId $limit_query";
$res = sqlStatement($query,$sql_bind_array);
}
Expand Down Expand Up @@ -532,15 +563,15 @@ function lookup_code_descriptions($codes) {
else if ($code_types[$codetype]['external'] == 2 || $code_types[$codetype]['external'] == 7) {
// Collect from SNOMED (RF1) Diagnosis codeset tables OR Search from SNOMED (RF1) clinical terms codeset tables
// Ensure the sct_concepts sql table exists
$check_table = sqlQuery("SHOW TABLES LIKE 'sct_concepts'");
$check_table = sqlQuery("SHOW TABLES LIKE 'sct_descriptions'");
if ( !(empty($check_table)) ) {
if ( !(empty($code)) ) {
$sql = "SELECT `FullySpecifiedName` FROM `sct_concepts` " .
"WHERE `ConceptId` = ? AND `ConceptStatus` = 0 LIMIT 1";
$sql = "SELECT `Term` FROM `sct_descriptions` " .
"WHERE `ConceptId` = ? AND `DescriptionStatus` = 0 AND `DescriptionType` = 1 LIMIT 1";
$crow = sqlQuery($sql, array($code) );
if (!empty($crow['FullySpecifiedName'])) {
if (!empty($crow['Term'])) {
if ($code_text) $code_text .= '; ';
$code_text .= $crow['FullySpecifiedName'];
$code_text .= $crow['Term'];
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions interface/code_systems/list_installed.php
Expand Up @@ -44,8 +44,8 @@

$db = isset($_GET['db']) ? $_GET['db'] : '0';

// For now, only order by the revision_date. When have different formats of a code type (such as WHO vs CMS for ICD10 or different languages for SNOMED, then will incorporate this field)
$rez = sqlStatement("SELECT DATE_FORMAT(`revision_date`,'%Y-%m-%d') as `revision_date`, `revision_version`, `name` FROM `standardized_tables_track` WHERE upper(`name`) = ? ORDER BY `revision_date` DESC", array($db) );
// For now, only order by the imported_date. When have different formats of a code type (such as WHO vs CMS for ICD10 or different languages for SNOMED, then will incorporate this field)
$rez = sqlStatement("SELECT DATE_FORMAT(`revision_date`,'%Y-%m-%d') as `revision_date`, `revision_version`, `name` FROM `standardized_tables_track` WHERE upper(`name`) = ? ORDER BY `imported_date` DESC", array($db) );
for($iter=0; $row=sqlFetchArray($rez); $iter++) {
$sqlReturn[$iter]=$row;
}
Expand Down
56 changes: 46 additions & 10 deletions interface/code_systems/list_staged.php
Expand Up @@ -160,6 +160,28 @@
array_push($revisions,$temp_date);
$supported_file = 1;
}
else if (preg_match("/sct1_National_US_([0-9]{8}).zip/",$file,$matches)) {

// This is the SNOMED US extension pack which can only be installed on top
// of a International SNOMED version.
// Hard code this version SNOMED feed to be US Extension
//
$version = "US Extension";
$date_release = substr($matches[1],0,4)."-".substr($matches[1],4,-2)."-".substr($matches[1],6);
$temp_date = array('date'=>$date_release, 'version'=>$version, 'path'=>$mainPATH."/".$matches[0]);
array_push($revisions,$temp_date);
$supported_file = 1;
}
else if (preg_match("/SnomedCT_Release-es_INT_([0-9]{8}).zip/",$file,$matches)) {

// Hard code this SNOMED version feed to be International:Spanish
//
$version = "International:Spanish";
$date_release = substr($matches[1],0,4)."-".substr($matches[1],4,-2)."-".substr($matches[1],6);
$temp_date = array('date'=>$date_release, 'version'=>$version, 'path'=>$mainPATH."/".$matches[0]);
array_push($revisions,$temp_date);
$supported_file = 1;
}
else {
// nothing
}
Expand Down Expand Up @@ -289,28 +311,42 @@
if ($success_flag === 1) {
$action = "";
if ($installed_flag === 1) {
if (strtotime($current_revision) == strtotime($file_revision_date)) {
?>
<div class="error_msg"><?php echo xlt("The installed version and the staged files are the same."); ?></div>
<div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
<?php
} else if (strtotime($current_revision) > strtotime($file_revision_date)) {
if ($current_name=="SNOMED" && $current_version!=$file_revision && $file_revision!="US Extension") {
// A new language of the SNOMED database has been staged, and will offer to Replace database with this staged version.
?>
<div class="error_msg"><?php echo xlt("The installed version is a more recent version than the staged files."); ?></div>
<div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
<div class="stg"><?php echo text(basename($file_revision_path)); ?> <?php echo xlt("is a different language version of the following database") . ": " . text($db); ?></div>
<?php
} else if ($current_name=="SNOMED" && $current_version=="US Extension" && $file_revision=="US Extension") {
$action=xl("REPLACE");
} else if ($current_name=="SNOMED" && $current_version=="US Extension" && $file_revision=="US Extension") {
// The Staged US Extension SNOMED package has already been installed
?>
<div class="error_msg"><?php echo xlt("The compatible staged US Extension SNOMED package has already been installed."); ?></div>
<div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
<?php
} else if ( ($current_name=="SNOMED" && $file_revision=="US Extension") && (strtotime($current_revision." +4 month") < strtotime($file_revision_date)) ) {
} else if ($current_name=="SNOMED" && $current_version!="International:English" && $file_revision=="US Extension") {
// The Staged US Extension SNOMED file is not compatible with non-english snomed sets
?>
<div class="error_msg"><?php echo xlt("The installed International SNOMED version is not compatible with the staged US Extension SNOMED package."); ?></div>
<div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
<?php
} else if ( ($current_name=="SNOMED" && $file_revision=="US Extension") && ((strtotime($current_revision." +6 month") < strtotime($file_revision_date)) || (strtotime($current_revision." -6 month") > strtotime($file_revision_date))) ) {
// The Staged US Extension SNOMED file is not compatible with the current SNOMED International Package (ie. the International package is outdated)
?>
<div class="error_msg"><?php echo xlt("The installed International SNOMED version is out of date and not compatible with the staged US Extension SNOMED file."); ?></div>
<div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
<?php
} else if ( (strtotime($current_revision) == strtotime($file_revision_date)) && !($current_name=="SNOMED" && $file_revision=="US Extension") ) {
// Note the exception here when installing US Extension
?>
<div class="error_msg"><?php echo xlt("The installed version and the staged files are the same."); ?></div>
<div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
<?php
} else if ( strtotime($current_revision) > strtotime($file_revision_date) && !($current_name=="SNOMED" && $file_revision=="US Extension") ) {
// Note the exception here when installing US Extension
?>
<div class="error_msg"><?php echo xlt("The installed version is a more recent version than the staged files."); ?></div>
<div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
<?php
} else {
?>
<div class="stg"><?php echo text(basename($file_revision_path)); ?> <?php echo xlt("is a more recent version of the following database") . ": " . text($db); ?></div>
Expand Down
4 changes: 3 additions & 1 deletion interface/code_systems/snomed_howto.php
Expand Up @@ -41,6 +41,8 @@
</li>
</ol>
<h5 class="error_msg"><?php echo xlt("NOTE: Only the Biannual International Snomed Release is currently supported"); ?></h5>
<h5 class="error_msg"><?php echo "(" . xlt("Additionally, the corresponding US Snomed Extension Package can be imported separately after installing the International Snomed Release") . ")"; ?></h5>
<h5 class="error_msg"><?php echo xlt("The following International Snomed Release languages are supported"); ?>: <?php echo xlt("English"); ?>, <?php echo xlt("Spanish"); ?></h5>
<h5 class="error_msg"><?php echo "(" . xlt("Additionally, the corresponding US Snomed Extension Package can be imported separately after installing the International (English version) Snomed Release") . ")"; ?></h5>
<h5 class="error_msg"><?php echo xlt("WARNING: If you are using the 2012-10-31 Spanish version, then note you need to unzip it once before placing it in the contrib/snomed (this is because the released file was \"double-zipped\")."); ?></h5>
</p>
</div>

0 comments on commit 2564654

Please sign in to comment.