diff --git a/custom/code_types.inc.php b/custom/code_types.inc.php index 58744583b34..ee9e52fe661 100644 --- a/custom/code_types.inc.php +++ b/custom/code_types.inc.php @@ -325,16 +325,47 @@ 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 @@ -342,26 +373,26 @@ function code_set_search($form_code_type,$search_term="",$count=false,$active=tr $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); } @@ -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']; } } } diff --git a/interface/code_systems/list_installed.php b/interface/code_systems/list_installed.php index 11540e0a2b5..75f524f872b 100644 --- a/interface/code_systems/list_installed.php +++ b/interface/code_systems/list_installed.php @@ -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; } diff --git a/interface/code_systems/list_staged.php b/interface/code_systems/list_staged.php index 952d1c87e88..330149ed2ee 100644 --- a/interface/code_systems/list_staged.php +++ b/interface/code_systems/list_staged.php @@ -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 } @@ -289,28 +311,42 @@ if ($success_flag === 1) { $action = ""; if ($installed_flag === 1) { - if (strtotime($current_revision) == strtotime($file_revision_date)) { - ?> -
-
?
- 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. ?> -
-
?
+
?
+
+
?
+ 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) ?>
?
+
+
?
+ strtotime($file_revision_date) && !($current_name=="SNOMED" && $file_revision=="US Extension") ) { + // Note the exception here when installing US Extension + ?> +
+
?
+
diff --git a/interface/code_systems/snomed_howto.php b/interface/code_systems/snomed_howto.php index a633dee122a..9e0e365e0b4 100644 --- a/interface/code_systems/snomed_howto.php +++ b/interface/code_systems/snomed_howto.php @@ -41,6 +41,8 @@
-
+
: ,
+
+