$DRG_obj = new DRG($pn);
$toggle = 0;
$thisfile = basename($_SERVER['PHP_SELF']);
if (isset($mode)) {
    /* Prepare the common data */
    $_POST['history'] = "Create " . date('Y-m-d H:i:s') . " " . $_SESSION['sess_user_name'] . "\n";
    //$_POST['modify_id']=$_SESSION['sess_user_name'];
    $_POST['create_id'] = $_SESSION['sess_user_name'];
    $_POST['create_time'] = date('YmdHis');
    switch ($mode) {
        case 'save':
            $DRG_obj->useInternalDRGCodes();
            // Set the core variables
            $DRG_obj->setDataArray($_POST);
            // transfer the data
            if ($DRG_obj->insertDataFromInternalArray()) {
                $oid = $db->Insert_ID();
                // Get the insert ID
                $group_nr = $DRG_obj->LastInsertPK('nr', $oid);
                $saveok = true;
                //header("location:$thisfile?sid=$sid&lang=$lang&saveok=1&pn=$pn&opnr=$opnr&group_nr=$group_nr&ln=$ln&fn=$fn&bd=$bd&dept_nr=$dept_nr&oprm=$oprm&y=$y&m=$m&d=$d&display=$display&target=$target");
                //exit;
            } else {
                $saveok = false;
            }
            break;
        case 'linkgroup':
            if (!$DRG_obj->EncounterDRGGroupExists($group_nr)) {
                $DRG_obj->useInternalDRG();
                // Set the core variables to encounter DRG table
                $_POST['clinician'] = $_SESSION['sess_user_name'];
        $data['code_version'] = $DRG_obj->OPSVersion();
        $data['responsible_clinician'] = $_SESSION['sess_user_name'];
        $data['responsible_dept_nr'] = $dept_nr;
        $DRG_obj->useProcedure();
        $qlist_type = 'procedure';
        break;
    case 'ops_intern_code':
        $DRG_obj->useInternalDRG();
        $qlist_type = 'drg_intern';
        if (isset($current) && $current) {
            if (!$DRG_obj->EncounterDRGGroupExists($sel)) {
                $data['group_nr'] = $sel;
                # pass the variable as reference
                $DRG_obj->setDataArray($data);
                # Now insert the data
                $DRG_obj->insertDataFromInternalArray();
                # Set all non-grouped diagnoses and procedures to this group number
                $DRG_obj->groupNonGroupedItems($sel);
                $saveok = 1;
                $multiple_save = false;
                $group_nr = $sel;
                //echo $thisfile;
            }
        }
}
if ($multiple_save) {
    for ($i = 0; $i < $lastindex; $i++) {
        $selx = "{$itemselector}{$i}";
        $hidx = "{$hidselector}{$i}";
        if (${$selx} == '') {
            continue;