Пример #1
0
/**
 * Function to check for existence of procedure(s) for a patient
 *
 * @param  string   $patient_id       pid of selected patient.
 * @param  string   $proc_title       procedure title
 * @param  string   $proc_code        procedure identifier code (array of <type(ICD9,CPT4)>:<identifier>||<type(ICD9,CPT4)>:<identifier>||<identifier> etc.)
 * @param  string   $results_comp     results comparison (eq,ne,gt,ge,lt,le)
 * @param  string   $result_data      results data 
 * @param  string   $num_items_comp   number items comparison (eq,ne,gt,ge,lt,le)
 * @param  integer  $num_items_thres  number of items threshold
 * @param  string   $intervalType     type of interval (ie. year)
 * @param  integer  $intervalValue    searched for within this many times of the interval type
 * @param  string   $dateTarget       target date(format Y-m-d H:i:s).
 * @return boolean                    true if check passed, otherwise false
 */
function exist_procedure_item($patient_id, $proc_title, $proc_code, $result_comp, $result_data = '', $num_items_comp, $num_items_thres, $intervalType = '', $intervalValue = '', $dateTarget = '')
{
    // Set date to current if not set
    $dateTarget = $dateTarget ? $dateTarget : date('Y-m-d H:i:s');
    // Set the table exception (for looking up pertinent date and pid sql columns)
    $table = "PROCEDURE-EXCEPTION";
    // Collect the correct column label for patient id in the table
    $patient_id_label = collect_database_label('pid', $table);
    // Get the interval sql query string
    $dateSql = sql_interval_string($table, $intervalType, $intervalValue, $dateTarget);
    // If just checking for existence (ie result_data is empty),
    //   then simply set the comparison operator to ne.
    if (empty($result_data)) {
        $result_comp = "ne";
    }
    // get the appropriate sql comparison operator
    $compSql = convertCompSql($result_comp);
    // explode the code array
    $codes = array();
    if (!empty($proc_code)) {
        $codes = explode("||", $proc_code);
    } else {
        $codes[0] = '';
    }
    // ensure proc_title is at least blank
    if (empty($proc_title)) {
        $proc_title = '';
    }
    // collect specific items (use both title and/or codes) that fulfill request
    $sqlBindArray = array();
    $sql_query = "SELECT procedure_result.result " . "FROM `procedure_type`, " . "`procedure_order`, " . "`procedure_report`, " . "`procedure_result` " . "WHERE procedure_type.procedure_type_id = procedure_order.procedure_type_id " . "AND procedure_order.procedure_order_id = procedure_report.procedure_order_id " . "AND procedure_report.procedure_report_id = procedure_result.procedure_report_id " . "AND ";
    foreach ($codes as $tem) {
        $sql_query .= "( ( (procedure_type.standard_code = ? AND procedure_type.standard_code != '') " . "OR (procedure_type.procedure_code = ? AND procedure_type.procedure_code != '') ) OR ";
        array_push($sqlBindArray, $tem, $tem);
    }
    $sql_query .= "(procedure_type.name = ? AND procedure_type.name != '') ) " . "AND procedure_result.result " . $compSql . " ? " . "AND " . add_escape_custom($patient_id_label) . " = ? " . $dateSql;
    array_push($sqlBindArray, $proc_title, $result_data, $patient_id);
    $sql = sqlStatementCdrEngine($sql_query, $sqlBindArray);
    // See if number of returned items passes the comparison
    return itemsNumberCompare($num_items_comp, $num_items_thres, sqlNumRows($sql));
}
Пример #2
0
function exist_procedure_item($patient_id, $proc_title, $proc_code, $result_comp, $result_data = '', $num_items_comp, $num_items_thres, $intervalType = '', $intervalValue = '', $dateTarget = '')
{
    // Set date to current if not set
    $dateTarget = $dateTarget ? $dateTarget : date('Y-m-d H:i:s');
    // Set the table exception (for looking up pertinent date and pid sql columns)
    $table = "PROCEDURE-EXCEPTION";
    // Collect the correct column label for patient id in the table
    $patient_id_label = collect_database_label('pid', $table);
    // Get the interval sql query string
    $dateSql = sql_interval_string($table, $intervalType, $intervalValue, $dateTarget);
    //
    // TODO
    // Figure out a way to use the identifiers codes
    // TODO
    //
    // If just checking for existence (ie result_data is empty),
    //   then simply set the comparison operator to ne.
    if (empty($result_data)) {
        $result_comp = "ne";
    }
    // get the appropriate sql comparison operator
    $compSql = convertCompSql($result_comp);
    // collect specific items that fulfill request
    $sql = sqlStatement("SELECT procedure_result.result " . "FROM `procedure_type`, " . "`procedure_order`, " . "`procedure_report`, " . "`procedure_result` " . "WHERE procedure_type.procedure_type_id = procedure_order.procedure_type_id " . "AND procedure_order.procedure_order_id = procedure_report.procedure_order_id " . "AND procedure_report.procedure_report_id = procedure_result.procedure_report_id " . "AND procedure_type.name = ? " . "AND procedure_result.result " . $compSql . " ? " . "AND " . add_escape_custom($patient_id_label) . " = ? " . $dateSql, array($proc_title, $result_data, $patient_id));
    // See if number of returned items passes the comparison
    return itemsNumberCompare($num_items_comp, $num_items_thres, sqlNumRows($sql));
}