if (empty($GLOBAL_CONFIG['pagin_patient_search_max_block_rows'])) {
    $pagen->setMaxCount(MAX_BLOCK_ROWS);
} else {
    $pagen->setMaxCount($GLOBAL_CONFIG['pagin_patient_search_max_block_rows']);
}
if (($mode == 'search' || $mode == 'paginate') && !empty($searchkey)) {
    # Convert other wildcards
    $searchkey = strtr($searchkey, '*?', '%_');
    # Save the search keyword for eventual pagination routines
    if ($mode == 'search') {
        $_SESSION['sess_searchkey'] = $searchkey;
    }
    include_once $root_path . 'include/inc_date_format_functions.php';
    include_once $root_path . 'include/care_api_classes/class_encounter.php';
    $enc_obj = new Encounter();
    $encounter =& $enc_obj->searchLimitEncounterBasicInfo($searchkey, $pagen->MaxCount(), $pgx, $oitem, $odir);
    //echo $enc_obj->getLastQuery();
    # Get the resulting record count
    $linecount = $enc_obj->LastRecordCount();
    if ($linecount == 1 && $mode == 'search') {
        $row = $encounter->FetchRow();
        header("location:" . $root_path . "modules/nursing/nursing-station-patientdaten-doconsil-" . $target . ".php" . URL_REDIRECT_APPEND . "&pn=" . $row['encounter_nr'] . "&edit=1&status=" . $status . "&target=" . $target . "&user_origin=" . $user_origin . "&noresize=1&mode=");
        exit;
    }
    //$linecount=$address_obj->LastRecordCount();
    $pagen->setTotalBlockCount($linecount);
    # Count total available data
    if (isset($totalcount) && $totalcount) {
        $pagen->setTotalDataCount($totalcount);
    } else {
        @$enc_obj->searchEncounterBasicInfo($searchkey);