Exemple #1
0
function search_test($type, $string, $mode = 'default', $return_only_one = false)
{
    echo "<ol>";
    $res = code_set_search($type, $string, false, true, $return_only_one, 0, 10, array(), null, $mode);
    while ($code = sqlFetchArray($res)) {
        echo "<li>" . $code['code_type_name'] . ":" . $code['code'] . ":" . $code['code_text'] . ":" . $code['code_text_short'] . "</li>";
    }
    echo "</ol>";
}
/**
* Code set searching "internal" function for when searching multiple code sets.
*
* It will also work for one code set search, although not meant for this.
* (This function is not meant to be called directly)
*
* @param array $form_code_types code set keys (will default to checking all active code types if blank)
* @param string $search_term search term
* @param integer $limit Number of results to return (NULL means return all)
* @param array $modes Holds the search modes to process along with the order of processing (default behavior is described in above function comment)
* @param boolean $count if true, then will only return the number of entries
* @param boolean $active if true, then will only return active entries
* @param integer $start Query start limit (for pagination)
* @param integer $number Query number returned (for pagination)
* @param array $filter_elements Array that contains elements to filter
* @return recordset/integer
*/
function multiple_code_set_search($form_code_types = array(), $search_term, $limit = NULL, $modes = NULL, $count = false, $active = true, $start = NULL, $number = NULL, $filter_elements = array())
{
    if (empty($form_code_types)) {
        // Collect the active code types
        $form_code_types = collect_codetypes("active", "array");
    }
    if ($count) {
        //start the counter
        $counter = 0;
    } else {
        // Figure out the appropriate limit clause
        $limit_query = limit_query_string($limit, $start, $number);
        // Prepare the sql bind array
        $sql_bind_array = array();
        // Start the query string
        $query = "SELECT * FROM ((";
    }
    // Loop through each code type
    $flag_first = true;
    $flag_hit = false;
    //ensure there is a hit to avoid trying an empty query
    foreach ($form_code_types as $form_code_type) {
        // see if there is a hit
        $mode_hit = NULL;
        // only use the count method here, since it's much more efficient than doing the actual query
        $mode_hit = sequential_code_set_search($form_code_type, $search_term, NULL, $modes, true, $active, NULL, NULL, $filter_elements, true);
        if ($mode_hit) {
            if ($count) {
                // count the hits
                $count_hits = code_set_search($form_code_type, $search_term, $count, $active, false, NULL, NULL, $filter_elements, NULL, $mode_hit);
                // increment the counter
                $counter += $count_hits;
            } else {
                $flag_hit = true;
                // build the query
                $return_query = code_set_search($form_code_type, $search_term, $count, $active, false, NULL, NULL, $filter_elements, NULL, $mode_hit, true);
                if (!empty($sql_bind_array)) {
                    $sql_bind_array = array_merge($sql_bind_array, $return_query['binds']);
                } else {
                    $sql_bind_array = $return_query['binds'];
                }
                if (!$flag_first) {
                    $query .= ") UNION ALL (";
                }
                $query .= $return_query['query'];
            }
            $flag_first = false;
        }
    }
    if ($count) {
        //return the count
        return $counter;
    } else {
        // Finish the query string
        $query .= ")) as atari {$limit_query}";
        // Process and return the query (if there was a hit)
        if ($flag_hit) {
            return sqlStatement($query, $sql_bind_array);
        }
    }
}
Exemple #3
0
 }
 $search_type = $default_search_type;
 if ($_POST['search_type']) {
     $search_type = $_POST['search_type'];
 }
 $ndc_applies = true;
 // Assume all payers require NDC info.
 echo $i ? "  <td></td>\n </tr>\n" : "";
 echo " <tr>\n";
 echo "  <td colspan='" . attr($FEE_SHEET_COLUMNS) . "' align='center' nowrap>\n";
 // If Search was clicked, do it and write the list of results here.
 // There's no limit on the number of results!
 //
 $numrows = 0;
 if ($_POST['bn_search'] && $_POST['search_term']) {
     $res = code_set_search($search_type, $_POST['search_term']);
     if (!empty($res)) {
         $numrows = sqlNumRows($res);
     }
 }
 echo "   <select name='Search Results' style='width:98%' " . "onchange='codeselect(this)'";
 if (!$numrows) {
     echo ' disabled';
 }
 echo ">\n";
 echo "    <option value=''> " . xlt("Search Results") . " ({$numrows} " . xlt("items") . ")\n";
 if ($numrows) {
     while ($row = sqlFetchArray($res)) {
         $code = $row['code'];
         if ($row['modifier']) {
             $code .= ":" . $row['modifier'];
    ?>

<table border='0'>
 <tr>
  <td><b><?php 
    echo xlt('Code');
    ?>
</b></td>
  <td><b><?php 
    echo xlt('Description');
    ?>
</b></td>
 </tr>
<?php 
    $search_term = $_REQUEST['search_term'];
    $res = code_set_search($form_code_type, $search_term);
    if ($form_code_type == 'PROD') {
        // Special case that displays search for products/drugs
        while ($row = sqlFetchArray($res)) {
            $drug_id = addslashes($row['drug_id']);
            $selector = addslashes($row['selector']);
            $desc = addslashes($row['name']);
            $anchor = "<a href='' " . "onclick='return selcode(\"PROD\", \"{$drug_id}\", \"{$selector}\", \"{$desc}\")'>";
            echo " <tr>";
            echo "  <td>{$anchor}" . text($drug_id . ":" . $selector) . "</a></td>\n";
            echo "  <td>{$anchor}" . text($desc) . "</a></td>\n";
            echo " </tr>";
        }
    } else {
        while ($row = sqlFetchArray($res)) {
            // Display normal search
    echo "  <td class='bold' align='right' nowrap>" . text(xl_list_label($prow['title'])) . "</td>\n";
}
?>
  <td></td>
  <td></td>
 </tr>
<?php 
// Flag is this is from an external set
$is_external_set = false;
if (in_array($filter_key, $external_sets)) {
    $is_external_set = true;
}
if ($filter) {
    $res = code_set_search($filter_key, $search, false, false, false, $fstart, $fend - $fstart);
} else {
    $res = code_set_search("--ALL--", $search, false, false, false, $fstart, $fend - $fstart);
}
for ($i = 0; $row = sqlFetchArray($res); $i++) {
    $all[$i] = $row;
}
if (!empty($all)) {
    $count = 0;
    foreach ($all as $iter) {
        $count++;
        $has_fees = false;
        foreach ($code_types as $key => $value) {
            if ($value['id'] == $iter['code_type']) {
                $has_fees = $value['fee'];
                break;
            }
        }
             } elseif (function_exists('code_set_search')) {
                 $result = code_set_search("ICD9", $search_term, $count = false, $active = true, $return_only_one = false, $start = 0, $number = 1000);
                 $numrows = sqlNumRows($result);
             } else {
                 $strQuery = "SELECT code_text,code_text_short,code,code_type \n                                    FROM  `codes` \n                                    WHERE `code_type` = 2  AND `code_text` LIKE ? LIMIT 1000";
                 $result = sqlStatement($strQuery, array("%" . $search_term . "%"));
                 $numrows = $result->_numOfRows;
             }
     }
 } else {
     $search_term = "";
     if (function_exists('main_code_set_search')) {
         $result = main_code_set_search("ICD9", $search_term, 1000);
         $numrows = sqlNumRows($result);
     } elseif (function_exists('code_set_search')) {
         $result = code_set_search("ICD9", $search_term, $count = false, $active = true, $return_only_one = false, $start = 0, $number = 1000);
         $numrows = sqlNumRows($result);
     } else {
         $strQuery = "SELECT code_text,code_text_short,code,code_type \n                                    FROM  `codes` \n                                    WHERE `code_type` = 2  AND `code_text` LIKE ? LIMIT 1000";
         $result = sqlStatement($strQuery, array("%" . $search_term . "%"));
         $numrows = $result->_numOfRows;
     }
 }
 if ($numrows > 0) {
     $xml_string .= "<status>0</status>";
     $xml_string .= "<reason>Diagnosis Codes Processed successfully</reason>";
     while ($res = sqlFetchArray($result)) {
         $xml_string .= "<DiagnosisCode>\n";
         foreach ($res as $fieldName => $fieldValue) {
             $rowValue = xmlsafestring($fieldValue);
             $xml_string .= "<{$fieldName}>{$rowValue}</{$fieldName}>\n";
    echo "  <td class='bold' align='right' nowrap>" . text(xl_list_label($prow['title'])) . "</td>\n";
}
?>
  <td></td>
  <td></td>
 </tr>
<?php 
// Flag is this is from an external set
$is_external_set = false;
if (in_array($filter_key, $external_sets)) {
    $is_external_set = true;
}
if ($filter) {
    $res = code_set_search($filter_key, $search, false, false, false, $fstart, $fend - $fstart, $filter_elements);
} else {
    $res = code_set_search("--ALL--", $search, false, false, false, $fstart, $fend - $fstart, $filter_elements);
}
for ($i = 0; $row = sqlFetchArray($res); $i++) {
    $all[$i] = $row;
}
if (!empty($all)) {
    $count = 0;
    foreach ($all as $iter) {
        $count++;
        $has_fees = false;
        foreach ($code_types as $key => $value) {
            if ($value['id'] == $iter['code_type']) {
                $has_fees = $value['fee'];
                break;
            }
        }