**********PSEUDOCODE FOR 34 GROUP M3PI MODEL*****************************
*PSEUDOCODE FOR THE 34 GROUP MODEL OF VERSION 5.12B OF THE M3PI 
*   CLASSIFICATION SYSTEM

*Last change: 08/06/98

*Version 5.12B incorporates a single substantive change from 5.12.  That 
*  substantive change was to fix an error in the 5.12 RUGs Manual Calculator 
*  and allow the manual calculator screen to accept the valid codes 7 and 8 
*  for the AA8b item.  These two codes were incorrectly excluded from entry 
*  on the 5.12 manual calculator screen.  

*Version 5.12B also includes a few cosmetic changes:
*  1. In 5.12 the default RUGs group was labeled as "BCI" several times.  In
*     5.12B, these labels were corrected to "BC1".
*  2. Two control files (MDSSTRU1.DBF and VARLIST2.DBF) were incorrectly
*     dated in 5.12 resulting in occasional "nuisance" warnings.  In 5.12B,
*     these files were dated correctly to avoid these unnecessary warnings.  

*Version 5.12B is for use with the MDS Version 2.0 assessment form, and
*  this version implements a new version of the RUG-III 1997 Update.  
*  This version of RUG-III 1997 Update is based on nursing home staff 
*  time measurement studies conducted in nursing homes in a number of states
*  during 1995 and 1997. 

*The version of RUG-III used for classification is indicated by a two
*  digit suffix appended to the RUG group label.  For version 5.12B, a
*  suffix of "07" indicates a classification using the 44 group model 
*  and a suffix of "08" indicates a classification using the 34 group 
*  model.  For example "PA107" indicates the RUG-III PA1 group from
*  the 44 group model and version 5.12B, while "PA108" indicates the
*  RUG-III PA1 group from the 34 group model and version 5.12B.

*This document contains a long documentation section followed by the 
*   actual pseudocode.

**************************DOCUMENTATION*************************************

*   This pseudocode has been placed in a ASCII text file called  M3PC34.TXT.  
*      This pseudocode was derived from a working CLIPPER program which 
*      received extensive testing.  Standard test databases with about 3 
*      thousand MDS 2.0 records are available in both DBASE format 
*      (TST512BA.DBF and TST512BB.DBF) and ASCII format (TST512BA.ASC and 
*      TST512BB.ASC).  These test databases will provide exhaustive testing 
*      of M3PI (RUG-III) classification code.  
*
*   The TST512BA test database contains 1002 MDS 2.0 records specially 
*      fabricated to exercise RUG-III classifications.  The TST512BB test
*      database contains 1896 MDS 2.0 records with values for the 108 RUG-III
*      items from the research sample used to derive the 1997 Update to 
*      RUG-III.
*
*   The test databases are in the national standard format for the MDS 2.0.  
*      The national specifications for the MDS 2.0 are available on the HCFA 
*      World Wide site.  The address for this site is 
*
*           http://www.hcfa.gov/medicare/hsqb/mds20
*
*   In the TST512BA database, (1) the T3MDCR field contains M3PI Medicare PPS
*      classifications using the Medicare PPS 44 group calculation type (see 
*      below) and "A01" set of Case Mix Indices for use in PPS rural 
*      facilities, (2) the T3STATE field contains M3PI classifications using 
*      the 44 group hierarchical calculation type (see below), (3) the MCR_GP 
*      field contains M3PI classifications using the 34 group index
*      maximizing calculation type (see below) with the "B01" set of Case
*      Mix Indices for Medicaid 34 group classification based on nursing time 
*      only, (4) the MCR_GP field contains M3PI classifications using the 34 
*      group hierarchical calculation type (see below), and (5) the first 2 
*      characters of the S1 field hold the correct RUG-III ADL score.
*
*   In the TST512BB database, (1) the T3MDCR field contains M3PI Medicare PPS
*      classifications using the Medicare PPS 44 group calculation type (see 
*      below) and "A02" set of Case Mix Indices for use in PPS urban 
*      facilities, (2) the T3STATE field contains M3PI classifications using 
*      the 44 group hierarchical calculation type (see below), (3) the MCR_GP 
*      field contains M3PI classifications using the 34 group index
*      maximizing calculation type (see below) with the "B01" set of Case
*      Mix Indices for Medicaid 34 group classification based on nursing time 
*      only, (4) the MCR_GP field contains M3PI classifications using the 34 
*      group hierarchical calculation type (see below).

*---------------------------------------------------------------------------
*CALCULATION TYPES (MODES) USED IN THIS PSEUDOCODE:

*   This pseudocode allows 34 group M3PI classification using the 
*   Hierarchical type or the Index maximizing calculation types.  
*
*   For the Hierarchical type, a resident is placed in the first group 
*   for which they qualify.  The order of precedence of the groups in the 
*   34 group model is Extensive Care, Rehabilitation, Special Care, 
*   Clinically Complex, Cognitively Impaired, Behavior Problems, and 
*   Reduced Physical Function.  

*   For the Index maximizing calculation type, there is no order of 
*   precedence  for the groups.  For this latter method, all groups for 
*   which a resident would qualify are determined, and the resident is 
*   placed in the group with the highest CMI (Case Mix Index).  If the 
*   Index maximizing method is used, then a CMI set must be provided (this 
*   CMI set is assumed to be loaded into an array named n_cmi and the 
*   ordering of the elements in this array is given later in this 
*   documentation).

*   The calculation type (hierarchical or index maximizing) used 
*   is determined by a local variable c_type.  

*        IF c_type = 'Hier', then the type will be hierarchical.
*        If c_type = 'Index', then the method will be 
*                    index maximizing.

*---------------------------------------------------------------------------
*CMI SETS DISTRIBUTED WITH VERSION 5.12B:
*
*   For the index maximizing calculation type, a set of Case Mix Indices 
*      (CMIs) must be referenced.
*
*   Version 5.12B of the M3PI is distributed with 4 standard CMI sets
*      already defined.  Each CMI set is referenced by a control code
*      (A01, A02, B01, and B02 for the 4 standard sets included).  Each of
*      the 4 standard CMI sets are briefly described below with a more
*      detailed description available in the file CMI512A.TXT included
*      with the M3PI (RUG-III) processor.
*
*           CMI Set A01.  Set A01 is appropriate for RUG-III
*           classification of Medicare PPS residents in Rural facilities. 
*           This set is a provisional set for use with the Medicare
*           Prospective Payment System (PPS) to be implemented nationally
*           on 07/01/1998.  This set is based on nursing time,
*           rehabilitation time, and selected ancillary costs.
*      
*           CMI Set A02.  Set A02 is appropriate for RUG-III
*           classification of Medicare PPS residents in Urban facilities. 
*           This set is a provisional set for use with the Medicare
*           Prospective Payment System (PPS) to be implemented nationally
*           on 07/01/1998.  This set is based on nursing time,
*           rehabilitation time, and selected ancillary costs.
*      
*           CMI Set B01.  Set B01 is appropriate for 34 group RUG-III
*           classification for State Medicaid payment, acuity tracking by
*           facility, or other research purposes.  This set is based on
*           nursing time only.  In set B01, CMI's for the 14
*           rehabilitation groups from the 44 group model (RUC, RUB, RUA,
*           RVC, RVB, RVA, RHC, RHB, RHA, RMC, RMB, RMA, RLB, and RLA) are
*           not present (values are all 0).
*      
*           CMI Set B02.  Set B02 is appropriate for 44 group RUG-III
*           classification for acuity tracking by facility or other
*           research purposes.  This set and the 44 group model of version
*           5.12B are NOT appropriate for Medicaid payment purposes.  This
*           set is based on nursing time only.  In set B02, CMI's for the
*           4 rehabilitation groups from the 34 group model (RAD, RAC,
*           RAB, and RAA) are not present (values are all 0).

*---------------------------------------------------------------------------
*RUG-III GROUP LABELS AND ORDER OF GROUPS IN CMI ARRAY:

*   Order for the CMI (n_cmi) array is as follows:

*  Array
*Element #   M3PI Group
*---------   -------------
*       44 group model rehabilitation groups:
*    1       RUC:  Rehabilitation Ultra High / ADL 16 - 18  
*    2       RUB:  Rehabilitation Ultra High / ADL  9 - 15
*    3       RUA:  Rehabilitation Ultra High / ADL  4 -  8
*    4       RVC:  Rehabilitation Very High / ADL 16 - 18
*    5       RVB:  Rehabilitation Very High / ADL  9 - 15
*    6       RVA:  Rehabilitation Very High / ADL  4 -  8
*    7       RHC:  Rehabilitation High / ADL 13 - 18
*    8       RHB:  Rehabilitation High / ADL  8 - 12
*    9       RHA:  Rehabilitation High / ADL  4 -  7
*   10       RMC:  Rehabilitation Medium / ADL 15 - 18
*   11       RMB:  Rehabilitation Medium / ADL  8 - 14
*   12       RMA:  Rehabilitation Medium / ADL  4 -  7
*   13       RLB:  Rehabilitation Low / ADL 14 - 18
*   14       RLA:  Rehabilitation Low / ADL  4 - 13

*       Groups used in both 44 and 34 group models: 
*   15       SE3:  Extensive Special Care 3 / ADL > 6
*   16       SE2:  Extensive Special Care 2 / ADL > 6
*   17       SE1:  Extensive Special Care 1 / ADL > 6
*   18       SSC:  Special Care / ADL 17 - 18
*   19       SSB:  Special Care / ADL 15 - 16
*   20       SSA:  Special Care / ADL  4 - 14
*   21       CC2:  Clin. Complex with Depression / ADL 17 - 18
*   22       CC1:  Clinically Complex / ADL 17 - 18
*   23       CB2:  Clin. Complex with Depression / ADL 12 - 16
*   24       CB1:  Clinically Complex / ADL 12 - 16
*   25       CA2:  Clin. Complex with Depression / ADL  4 - 11
*   26       CA1:  Clinically Complex / ADL  4 - 11
*   27       IB2:  Cog. Impairment with Nursing Rehab / ADL   6 - 10
*   28       IB1:  Cognitive Impairment / ADL   6 - 10
*   29       IA2:  Cog. Impairment with Nursing Rehab / ADL   4 -  5
*   30       IA1:  Cognitive Impairment / ADL   4 -  5
*   31       BB2:  Behavior Problem with Nursing Rehab / ADL 6 - 10
*   32       BB1:  Behavior Problem / ADL   6 - 10
*   33       BA2:  Behavior Problem with Nursing Rehab / ADL 4 -  5
*   34       BA1:  Behavior Problem / ADL   4 -  5
*   35       PE2:  Physical Function with Nursing Rehab / ADL  16 - 18
*   36       PE1:  Physical Function / ADL  16 - 18
*   37       PD2:  Physical Function with Nursing Rehab / ADL  11 - 15
*   38       PD1:  Physical Function / ADL  11 - 15
*   39       PC2:  Physical Function with Nursing Rehab / ADL   9 - 10 
*   40       PC1:  Physical Function / ADL   9 - 10
*   41       PB2:  Physical Function with Nursing Rehab / ADL   6 -  8
*   42       PB1:  Physical Function / ADL   6 -  8
*   43       PA2:  Physical Function with Nursing Rehab / ADL   4 -  5
*   44       PA1:  Physical Function / ADL   4 -  5
*   45       BC1:  M3PI group not calculated due to data errors

*       34 group model rehabilitation groups:
*   46       RAD:  Rehabilitation All Levels / ADL 17 - 18
*   47       RAC:  Rehabilitation All Levels / ADL 14 - 16
*   48       RAB:  Rehabilitation All Levels / ADL  9 - 13
*   49       RAA:  Rehabilitation All Levels / ADL  4 -  8

*---------------------------------------------------------------------------
*SYNTAX USED IN THIS PSEUDOCODE:

*   1.  All lines with an asterisk (*) as the first nonblank character in
*         the line are documentation or comment lines.  All command lines
*         start with a character other than an asterisk.
*   2.  Any command line which ends with a semicolon (;) is continued on
*         the next line.  A semicolon is the continuation character and
*         this is the only punctuation used in command lines.
*   3.  All variables are represented in small letters, while command
*         words are represented in capital letters.
*   4.  All MDS 2.0 variables are represented in small letters with a
*         prefix of "m_" (e.g. m_b1 for the b1 item from the MDS 2.0).  
*         ALL MDS 2.0 VARIABLES ARE REQUIRED TO BE CHARACTER VARIABLES
*         IN THIS PSEUDOCODE.  The MDS 2.0 variables names correspond to the 
*         labels on the MDS 2.0 form.
*   5.  All local (non-MDS) variables are represented in small letters with
*         a prefix of "c_" for character variables (e.g., c_type) and 
*         a prefix of "n_" for numeric variables (e.g., n_adlsum)
*   6.  The only command words and structures used in this pseudocode are:
*         a. RETURN 
*               (this command is the last command and indicates the end
*               of the code)
*         b. IF <logical condition> 
*               <arithmetic statement> executed if condition true 
*            ENDIF
*         c. IF <logical condition1> 
*               <arithmetic statement> executed if condition1 true 
*            ELSEIF <logical condition2>
*               <arithmetic statement> executed if condition2 true 
*            ENDIF
*         d. Logical operators used in logical conditions are
*                =       (equal)
*                >       (greater than)
*                <       (less than) 
*                >=      (greater than or equal to)
*                <=      (less than or equal to)
*                <>      (not equal to--less than or greater than)
*               .NOT.    (logical negation)
*         e. Relational operators used in logical conditions are
*                .AND.   (logical and)
*                .OR.    (logical or)
*         f. VAL(c_var) -- the VAL function returns the numeric value
*                          for a character variable (c_var).
*   7.  Nested IF structures are indented for clarity.
*   8.  Single quotes (') delimit a character constant.

*---------------------------------------------------------------------------
*PROCESSING REQUIRED BEFORE EXECUTION OF PSEUDOCODE: 

*   1.  Read MDS 2.0 record and store appropriate character values in the 
*          MDS 2.0 variables listed below.
*   2.  Scan each required MDS 2.0 variable for valid value (valid values for 
*          each variable are given below).  If an invalid value occurs for 
*          ANY required MDS 2.0 variable, then the default M3PI class is
*          assigned (BC1) and the M3PI calculation code in this document
*          is skipped. 

*---------------------------------------------------------------------------
*MDS 2.0 ITEMS USED IN THIS PSEUDOCODE:

*All MDS 2.0 items in the code have been preceded by a prefix of 'm_'.  For 
*     example item b1 is presented as m_b1. 

*The 108 MDS Version 2.0 variables required by this pseudocode for M3PI 
*  classification are given below.  For each variable, the MDS 2.0 item
*  label, allowable range of values, and item description are given.  Note
*  that a blank space included in a quoted range below indicates that a 
*  blank value is allowable.  Please see a later section for out-of-range 
*  value handling.

*      ITEM
*      LABEL   RANGE               DESCRIPTION
*      -----  ------------------  -------------------------------------
*   1) aa8b   '12345678 '           Special assessment code                     
*   2) b1     '01-'               Comatose                                    
*   3) b2a    '01- '              Short-term memory OK                        
*   4) b4     '0123- '            Cognitive Skills/Daily Decision Making      
*   5) c4     '0123- '            Making Self Understood                      
*   6) e1a    '012- '             Negative statements                         
*   7) e1b    '012- '             Repetitive questions                        
*   8) e1c    '012- '             Repetitive verbalizations                   
*   9) e1d    '012- '             Persistent anger with self/others           
*  10) e1e    '012- '             Self deprecation                            
*  11) e1f    '012- '             Expression of unrealistic fears             
*  12) e1g    '012- '             Recurrent statements of terrible future     
*  13) e1h    '012- '             Repetitive health complaints                
*  14) e1i    '012- '             Repetitive anxious complaints/concerns      
*  15) e1j    '012- '             Unpleasant mood in morning                  
*  16) e1k    '012- '             Insomnia/change in sleeping pattern         
*  17) e1l    '012- '             Sad/pained/worried facial expressions       
*  18) e1m    '012- '             Crying/tearfulness                          
*  19) e1n    '012- '             Repetitive physical movements               
*  20) e1o    '012- '             Withdrawal from activities of interest      
*  21) e1p    '012- '             Reduced social interaction                  
*  22) e4aa   '0123- '            Behavior symptom frequency                  
*  23) e4ba   '0123- '            Behavior symptom frequency                  
*  24) e4ca   '0123- '            Behavior symptom frequency                  
*  25) e4da   '0123- '            Behavior symptom frequency                  
*  26) e4ea   '0123- '            Behavior symptom frequency                  
*  27) g1aa   '012348-'           ADL Self-Performance                        
*  28) g1ab   '01238-'            ADL Support Provided                        
*  29) g1ba   '012348-'           ADL Self-Performance                        
*  30) g1bb   '01238-'            ADL Support Provided                        
*  31) g1ha   '012348-'           ADL Self-Performance                        
*  32) g1ia   '012348-'           ADL Self-Performance                        
*  33) g1ib   '01238-'            ADL Support Provided                        
*  34) h3a    '01-'               Any scheduled toileting plan                
*  35) h3b    '01-'               Bladder retraining program                  
*  36) i1a    '01-'               Diabetes mellitus                           
*  37) i1r    '01-'               Aphasia                                     
*  38) i1s    '01-'               Cerebral palsy                              
*  39) i1v    '01-'               Hemiplegia/hemiparesis                      
*  40) i1w    '01-'               Multiple sclerosis                          
*  41) i1z    '01-'               Quadriplegia                                
*  42) i2e    '01-'               Pneumonia                                   
*  43) i2g    '01-'               Septicemia                                  
*  44) j1c    '01-'               Dehydrated--output exceeds input            
*  45) j1e    '01-'               Delusions                                   
*  46) j1h    '01-'               Fever                                       
*  47) j1i    '01-'               Hallucinations                              
*  48) j1j    '01-'               Internal bleeding                           
*  49) j1o    '01-'               Vomiting                                    
*  50) k3a    '01-'               Weight loss                                 
*  51) k5a    '01-'               Parenteral IV                               
*  52) k5b    '01-'               Feeding tube                                
*  53) k6a    '01234- '           Total calories (%) received in last 7 days  
*  54) k6b    '012345- '          Average fluid intake (daily) in last 7 days 
*  55) m1a    '0123456789-'       Stage 1                                     
*  56) m1b    '0123456789-'       Stage 2                                     
*  57) m1c    '0123456789-'       Stage 3                                     
*  58) m1d    '0123456789-'       Stage 4                                     
*  59) m2a    '01234-'            Pressure ulcer                              
*  60) m4b    '01-'               Burns (second or third degree)              
*  61) m4c    '01-'               Open lesions other than ulcers, rashes, cuts
*  62) m4g    '01-'               Surgical wounds                             
*  63) m5a    '01-'               Pressure relieving device(s) for chair      
*  64) m5b    '01-'               Pressure relieving device(s) for bed        
*  65) m5c    '01-'               Turning/repositioning program               
*  66) m5d    '01-'               Nutrition/hydration intervention            
*  67) m5e    '01-'               Ulcer care                                  
*  68) m5f    '01-'               Surgical wound care                         
*  69) m5g    '01-'               Application of dressings                    
*  70) m5h    '01-'               Application of ointments/medications        
*  71) m6b    '01-'               Infection of foot--e.g.,cellulitis, etc.    
*  72) m6c    '01-'               Open lesions on foot                        
*  73) m6f    '01-'               Application of dressings                    
*  74) n1a    '01-'               Morning                                     
*  75) n1b    '01-'               Afternoon                                   
*  76) n1c    '01-'               Evening                                     
*  77) o3     '01234567-'         Injections (number days)                    
*  78) p1aa   '01-'               Chemotherapy                                
*  79) p1ab   '01-'               Dialysis                                    
*  80) p1ac   '01-'               IV medication                               
*  81) p1ag   '01-'               Oxygen therapy                              
*  82) p1ah   '01-'               Radiation                                   
*  83) p1ai   '01-'               Suctioning                                  
*  84) p1aj   '01-'               Tracheostomy care                           
*  85) p1ak   '01-'               Transfusions                                
*  86) p1al   '01-'               Ventilator or respirator                    
*  87) p1baa  '01234567-'         # days for 15 min. or more (last 7 days)    
*  88) p1bab  '0000' thru '9999'  total # minutes (last 7 day)                
*                or '----'
*  89) p1bba  '01234567-'         # days for 15 min. or more (last 7 days)    
*  90) p1bbb  '0000' thru '9999'  total # minutes (last 7 day)                
*                or '----'
*  91) p1bca  '01234567-'         # days for 15 min. or more (last 7 days)    
*  92) p1bcb  '0000' thru '9999'  total # minutes (last 7 day)                
*                or '----'
*  93) p1bda  '01234567-'         # days for 15 min. or more (last 7 days)    
*  94) p3a    '01234567-'         Range of motion (passive)                   
*  95) p3b    '01234567-'         Range of motion (active)                    
*  96) p3c    '01234567-'         Splint or brace assistance                  
*  97) p3d    '01234567-'         Bed mobility                                
*  98) p3e    '01234567-'         Transfer                                    
*  99) p3f    '01234567-'         Walking                                     
* 100) p3g    '01234567-'         Dressing or grooming                        
* 101) p3h    '01234567-'         Eating or swallowing                        
* 102) p3i    '01234567-'         Amputation/prosthesis care                  
* 103) p3j    '01234567-'         Communication                               
* 104) p7     '00' thru '14'      Physician Visits                            
*                or '--'
* 105) p8     '00' thru '14'      Physician Orders                            
*                or '--'
* 106) t1b    '01- '              Ordered Therapies                           
* 107) t1c    '00' thru '15'      Estimate of days of therapy until day 15    
*                or '--'
*                or '  '
* 108) t1d    '0000' thru '9999'  Estimate of minutes of therapy until day 15 
*                or '----'
*                or '    '

*---------------------------------------------------------------------------
*HANDLING OF OUT-OF-RANGE VALUES FOR MDS 2.0 ITEMS:

*Before execution of M3PI RUG-III classification using this pseudocode, it is 
*  required that all 108 MDS 2.0 items be scanned for valid ranges using
*  the ranges given in the list above.  The M3PI standard for range checking 
*  is to completely skip the logic given in this pseudocode and assign a 
*  default classification (Group BC1) if ANY one of the 108 MDS 2.0 items is 
*  out-of-range for a record.

*The allowable ranges given above correspond to MDS 2.0 national 
*  specifications with one exception.  In the national standards, several
*  of the above MDS 2.0 items are allowed to have values consisting of 
*  ampersands (&).  The ampersand values indicate that the record is for
*  a partial quarterly assessment and the item in question does not even 
*  occur on that type of assessment.  The ampersand values have been 
*  EXCLUDED from the valid ranges to be used for M3PI classification.  
*  M3PI classification requires that all 108 items be available.  M3PI
*  classification will therefore produce a default classification (BC1) 
*  on all partial quarterly assessments.  

*Researchers may be interested in a best guess RUG-III classification even
*  when some required items are unavailable or out-of-range values are 
*  present.  The present pseudocode can be used for those purposes in the 
*  following manner:
*    1) Scan all items for valid values using the ranges above.
*    2) If AA8b has an invalid (out-of-range) value, recode it to a blank.
*    3) If any other item has an invalid (out-of-range) value, then recode  
*       it to dash (-) filled.  For example, if item b2a has a value of "2",
*       then this out-of-range value should be changed to a dash ("-"). 
*       Also, any item containing ampersands must be changed to dash-filled.
*       Finally, if a multi-character item contains a single dash, then 
*       fill out the value with dashes (e.g., "----" for a 4 character item).
*    4) Then execute the logic given in the pseudocode.

*---------------------------------------------------------------------------
*MDS 2.0 ITEM VALUE RECODING

*Previous versions of M3PI have required that some recoding of items
*  be performed before using the standard classification logic.  This is
*  not true of version 5.12B (the present version).  The present logic has 
*  been written to eliminate the need for all recoding before application of
*  the standard logic.

*---------------------------------------------------------------------------
*INPUT VARIABLES USED IN THE CLASSIFICATION LOGIC:

* VARIABLE       DESCRIPTION
                      
*   n_cmi     is the 49 element array holding the case mix indices for
*                the calculation selected; the first 44 entries are those
*                for the 44 group model, the 45th is for a default grouping
*                (used when data errors do not allow classification), and
*                the 46th thru 49th are for the 4 Rehabilitation groups
*                in the 34 group model.  The specific order of these
*                indices has been given above.  Note that elements 1 thru 44
*                define the 44 group model, while 15 thru 44 and
*                46 thru 49 define the 34 group model.
*   c_type    has a value of "Hier" if the calculation method is
*                hierarchical or a value of "Index" if the calculation
*                method is index maximization.  (Note a value of "Mcare" 
*                cannot be used for 34 group classification since the 
*                Special Medicare calculation is restricted to the 44 group
*                model only.

*---------------------------------------------------------------------------
*RESULTS VARIABLES PRODUCED BY THE CLASSIFICATION LOGIC:

* VARIABLE       DESCRIPTION

*   c_m3      is the M3PI RUG-III grouping calculated for the resident in this
*                routine.
*   n_adlsum  is the M3PI ADL index score calcuated for the resident.
*   n_cps     is the Cognitive Performance Scale score calculated for 
*                the resident.
*   n_cmi_hi  is the Case Mix Index associated with the M3PI grouping 
*                for the resident.

*---------------------------------------------------------------------------
*INTERMEDIATE VARIABLES CREATED FOR USE IN THE CLASSIFICATION LOGIC:

*Numeric Indicators for qualification in RUG-III clinical categories.  *
*  For each of these indicators a 0 (zero) indicates not qualified     *
*  and a 1 indicates qualified for the category.                       *
*      n_reh_u   - ultra high rehabilitation                           *
*      n_reh_v   - very high rehabilitation                            *
*      n_reh_h   - high rehabilitation                                 *
*      n_reh_m   - medium rehabilitation                               *
*      n_reh_l   - low rehabilitation                                  *
*      n_ext     - extensive care                                      *
*      n_spec    - special care                                        *
*      n_clin    - clinically complex                                  *
*      n_impair  - impaired cognition                                  *
*      n_behav   - behavior problems                                   *
*                                                                      *
*Other variables used in computations:                                 *
*      n_bedmb  - numeric recode of bed mobility ADL                   *
*      n_trans  - numeric recode of transfer ADL                       *
*      n_toilt  - numeric recode of toileting ADL                      *
*      n_intake - numeric indicator for parenteral/enteral intake level*
*      n_eatng  - numeric recode of eating ADL                         *
*      n_adlsum - RUG-III ADL Index (numeric value between 4 and 18)   * 
*      n_th_min - minutes of rehab therapies totaled across therapies  *
*      n_th_ty3 - number of types of rehab therapies received 3+ days  *
*                    each                                              *
*      n_th_ty5 - number of types of rehab therapies received 5+ days  *
*                    each                                              *
*      n_th_day - number of days of rehab therapies totaled across     *
*                    therapies                                         *
*      n_nrsum6 - number of nursing rehabilitation types on 6+ days    *
*                    each                                              *
*      n_ulcer  - numeric count of number of ulcers, all levels        *
*      n_sk_tr  - numeric count of selected skin treatments            *
*      n_n_awak - numeric count of periods that the resident is not    *
*                 awake                                                *
*      n_p7     - numerical version of p7 (MD visits) for ease of      *
*                 coding                                               *
*      n_p8     - numerical value of p8 (MD orders) for ease of        *
*                 coding                                               *
*      n_mood   - numeric count of mood indicators                     *
*      n_depres - numeric indicator of depression                      *
*      n_coma   - numeric indicator of coma with selected qualifiers   *
*      n_cog1   - numeric count of selected cognitive problems for     *
*                 Cognitive Performance Scale                          *
*      n_cog2   - second numeric count of selected cognitive problems  *
*                 for Cognitive Performance Scale                      *
*      n_cps    - numeric Cognitive Performance Scale code             *
*      n_ext_ct - count of number of selected hierarchy categories     *
*                 for which resident qualifies and selected extensive  *
*                 care services (used in Extensive Care classification)* 

************************************************************************
*PSEUDOCODE ORGANIZATION:

*Version 5.12B (like version 5.11) of M3PI classification use a somewhat 
*  different logic flow than all previous M3PI versions.  Version 5.12B 
*  employs a 2 stage process involving a clinical qualification stage followed 
*  by a classification stage as follows:
*      1.  Clinical Qualification Stage for the 44 group model.  Determine 
*          all of RUG-III clinical categories (Rehab, Extensive Special 
*          Care, Special Care, Clinically Complex, Cognitive Impairment, 
*          and Behavior Problems) for which a resident qualifies.  This 
*          first stage involves Step I through Step X in the pseudocode below. 
*      2.  Classification Stage. Scan all of the qualifications for a 
*          resident and classify the resident into a single clinical 
*          category using an hierarchical or index maximizing methodology 
*          and then classify the resident into one of the RUG-III groups 
*          contained in that clinical category.  This second stage involves 
*          Step XI in the pseudocode.

*The RUG-III 1997 Update classifies a resident into the Extensive Special 
*  Care groups based on consideration of not only qualification for the 
*  Extensive Special Care clinical category, but also qualification for 
*  the Special Care, Clinically Complex, and Cognitive Impairment Clinical 
*  categories.  This feature necessitates the stage two process.

************************************************************************
*DEVELOPMENT HISTORY Version 5.12B:  
*   CLIPPER/Pseudocode 08/06/1998 by BG  - adapted from Version 5.12
*                with with AA8b value range check in the manual calculator
*                adjusted to allow codes 7 and 8 as valid.

************************************************************************

**************************END OF DOCUMENTATION******************************


*************************BEGINNING OF PSEUDOCODE****************************

*****************************************
*Begin calculation.                     *
*****************************************

*++++++++++++++++++++++++++++++++++++++++
*Step I.  Initialize needed variables.  
*++++++++++++++++++++++++++++++++++++++++
*Initialize final M3PI group to default group.
c_m3 = 'BC1'

*Initialize highest M3PI CMI qualified for to large negative
*    number.
*n_cmi_hi is the highest CMI previously qualified for.
n_cmi_hi = -99999

*Initialize clinical category indicators
n_reh_u  = 0
n_reh_v  = 0
n_reh_h  = 0
n_reh_m  = 0
n_reh_l  = 0
n_ext    = 0
n_spec   = 0
n_clin   = 0
n_impair = 0
n_behav  = 0

*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*Step II. Calculate RUG-III ADL Index.                                     
*         The ADL index is required for use in splitting the Rehabilitation, 
*            Special Care, Clinically Complex, Impaired Cognition, Behavior 
*            Problems, and Reduced Physical Function RUG-III clinical 
*            categories.  The ADL index requires scoring conversion for 
*            4 different ADL's and then summation.
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

*ADL scoring conversion for Bed mobility
IF     (m_g1aa = '-' .OR. m_g1aa = '0' .OR. m_g1aa = '1')
              n_bedmb = 1
ELSEIF (m_g1aa =  '2')               
              n_bedmb = 3
ELSEIF (m_g1aa = '3' .OR. m_g1aa = '4' .OR. m_g1aa = '8') 
   IF     (m_g1ab = '-' .OR. m_g1ab = '0' ;
           .OR. m_g1ab = '1'  .OR. m_g1ab =  '2')
              n_bedmb = 4
   ELSEIF (m_g1ab = '3'  .OR. m_g1ab = '8')
              n_bedmb = 5
   ENDIF
ENDIF

*-------------------------------
*ADL scoring conversion for Transfer
IF     (m_g1ba = '-' .OR. m_g1ba = '0' .OR. m_g1ba = '1')
              n_trans = 1
ELSEIF (m_g1ba =  '2')               
              n_trans = 3
ELSEIF (m_g1ba = '3' .OR. m_g1ba = '4' .OR. m_g1ba = '8') 
   IF     (m_g1bb = '-' .OR. m_g1bb = '0' ;
           .OR. m_g1bb = '1' .OR. m_g1bb =  '2')
              n_trans = 4
   ELSEIF (m_g1bb = '3'  .OR. m_g1bb = '8')
              n_trans = 5
   ENDIF
ENDIF

*-------------------------------
*ADL scoring conversion for Toilet Use
IF     (m_g1ia = '-' .OR. m_g1ia = '0' .OR. m_g1ia = '1')
              n_toilt = 1
ELSEIF (m_g1ia =  '2')               
              n_toilt = 3
ELSEIF (m_g1ia = '3' .OR. m_g1ia = '4' .OR. m_g1ia = '8') 
   IF     (m_g1ib = '-' .OR. m_g1ib = '0' ;
           .OR. m_g1ib = '1' .OR. m_g1ib =  '2')
              n_toilt = 4
   ELSEIF (m_g1ib = '3'  .OR. m_g1ib = '8')
              n_toilt = 5
   ENDIF
ENDIF

*-------------------------------
*Code parenteral\enteral intake level--used for Eating scoring conversion and 
*later for Special Care and Clinically Complex qualification.
*   n_intake = 1 if (1) 51% or more of total calories are received 
*                through parenteral/enteral intake (k6a) or (2) 26% to 50% 
*                of total calories received through parenteral/enteral 
*                intake (k6a) and fluid intake is 501 or more cc per day 
*                (k6b). 
*   n_intake = 0 if parenteral/enteral intake is at a lower level (including 
*                none). 
n_intake = 0
IF     (m_k6a = '3' .OR. m_k6a = '4')
          n_intake = 1
ELSEIF (m_k6a = '2') .AND. ;
       (m_k6b = '2' .OR. m_k6b = '3' .OR. m_k6b = '4' .OR. m_k6b = '5')
          n_intake = 1
ENDIF

*ADL scoring conversion for Eating;
IF     (m_k5a = '1') .OR. (m_k5b = '1' .AND. n_intake = 1)  
          n_eatng = 3
ELSEIF (m_g1ha = '-' .OR. m_g1ha = '0' .OR. m_g1ha = '1')
          n_eatng = 1
ELSEIF (m_g1ha = '2')
          n_eatng = 2
ELSEIF (m_g1ha = '3' .OR. m_g1ha = '4' .OR. m_g1ha = '8')
          n_eatng = 3
ENDIF

*-------------------------------
*Sum the converted ADL scores to n_adlsum
   n_adlsum = n_bedmb + n_trans + n_toilt + n_eatng

*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*Step III. Determine Rehab and Rehab nursing variables needed for     
*            Rehab categories.                 
*                   
*          Variables needed to determine Rehab clinical hierarchy
*            qualification for Standard rehab classification:
*             - Total minutes of rehab therapy received (n_th_min)              
*             - Total number of days of rehab received (n_th_day)
*             - Number of types of rehab therapy (n_th_ty3) received 
*                  at 3+ days each
*             - Number of types of rehab therapy (n_th_ty5) received 
*                  at 5+ days each
*             - Number of types of nursing rehab activities (n_nrsum6) at
*                  6+ days each  (Note that n_nrsum6 includes any 
*                  scheduled toileting plan or bladder retraining program 
*                  as a component.)
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

*-------------------------------
*Determine n_th_min -- the number of minutes of rehab therapy received.

n_th_min = 0

*Add speech therapy minutes unless dash filled (value '----') 
IF (m_p1bab <> '----')
   n_th_min = n_th_min + VAL(m_p1bab)
ENDIF

*Add occupational therapy minutes unless dash filled (value '----') 
IF (m_p1bbb <> '----')
   n_th_min = n_th_min + VAL(m_p1bbb)
ENDIF

*Add physical therapy minutes unless dash filled (value '----')
IF (m_p1bcb <> '----')
   n_th_min = n_th_min + VAL(m_p1bcb)
ENDIF

*-------------------------------
*Determine n_th_day -- the number of days of rehab therapy received.

n_th_day = 0

*Add speech therapy days if in valid numeric range
IF ('1' <= m_p1baa .AND. m_p1baa <= '7')
   n_th_day = n_th_day + VAL(m_p1baa)
ENDIF

*Add occupational therapy days if in valid numeric range 
IF ('1' <= m_p1bba .AND. m_p1bba <= '7')
   n_th_day = n_th_day + VAL(m_p1bba)
ENDIF

*Add physical therapy days if in valid numeric range 
IF ('1' <= m_p1bca .AND. m_p1bca <= '7')
   n_th_day = n_th_day + VAL(m_p1bca)
ENDIF

*-------------------------------
*Determine n_th_ty3.                                                   
*   n_th_ty3 represents the number of different rehab therapies that   
*   were provided on 3 or more days during that period. It is used 
*   to determine qualification for Ultra High intensity rehab.               

n_th_ty3 = 0
IF ('3' <= m_p1baa .AND. m_p1baa <= '7')
   n_th_ty3 = n_th_ty3 + 1
ENDIF
IF ('3' <= m_p1bba .AND. m_p1bba <= '7')
   n_th_ty3 = n_th_ty3 + 1
ENDIF
IF ('3' <= m_p1bca .AND. m_p1bca <= '7')
   n_th_ty3 = n_th_ty3 + 1
ENDIF

*-------------------------------
*Determine n_th_ty5.                                                   
*   n_th_ty5 represents the number of different rehab therapies that   
*   were provided on 5 or more days during that period. It is used 
*   to determine qualification for Ultra High, Very High and High
*   intensity rehab.               

n_th_ty5 = 0
IF ('5' <= m_p1baa .AND. m_p1baa <= '7')
   n_th_ty5 = n_th_ty5 + 1
ENDIF
IF ('5' <= m_p1bba .AND. m_p1bba <= '7')
   n_th_ty5 = n_th_ty5 + 1
ENDIF
IF ('5' <= m_p1bca .AND. m_p1bca <= '7')
   n_th_ty5 = n_th_ty5 + 1
ENDIF

*-------------------------------
*Determine n_nrsum6.                                                      
*   n_nrsum6 is a count of the number of types of nursing rehab activities 
*   provided at least 6 days per week.  Note that a scheduled toileting 
*   plan or bladder retraining program is included in this count.  

n_nrsum6 = 0

*Add 1 for passive range of motion (p3a) or active range of motion (p3b)
IF (('6' <= m_p3a .AND. m_p3a <= '7') .OR. ;
    ('6' <= m_p3b .AND. m_p3b <= '7'))
   n_nrsum6 = n_nrsum6 + 1
ENDIF

*Add 1 for bed mobility (p3d) or walking (p3f) training 
IF (('6' <= m_p3d .AND. m_p3d <= '7') .OR. ;
    ('6' <= m_p3f .AND. m_p3f <= '7'))  
   n_nrsum6 = n_nrsum6 + 1
ENDIF

*Add 1 for splint or brace assistance (p3c)
IF ('6' <= m_p3c .AND. m_p3c <= '7')
   n_nrsum6 = n_nrsum6 + 1
ENDIF

*Add 1 for transfer training (p3e)
IF ('6' <= m_p3e .AND. m_p3e <= '7')
   n_nrsum6 = n_nrsum6 + 1
ENDIF

*Add 1 for dressing or grooming training (p3g)
IF ('6' <= m_p3g .AND. m_p3g <= '7')
   n_nrsum6 = n_nrsum6 + 1
ENDIF

*Add 1 for eating or swallowing training (p3h)
IF ('6' <= m_p3h .AND. m_p3h <= '7')
   n_nrsum6 = n_nrsum6 + 1
ENDIF

*Add 1 for amputation/prosthesis care (p3i)
IF ('6' <= m_p3i .AND. m_p3i <= '7')
   n_nrsum6 = n_nrsum6 + 1
ENDIF

*Add 1 for communication training (p3j)
IF ('6' <= m_p3j .AND. m_p3j <= '7')
   n_nrsum6 = n_nrsum6 + 1
ENDIF

*Add 1 for any scheduled toileting plan (h3a) or bladder retraining
*   program (h3b)
IF (m_h3a = '1' .OR. m_h3b = '1')
   n_nrsum6 = n_nrsum6 + 1
ENDIF

*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*Step IV. Test Rehab category qualification.
*          Rehab categories are separated by several factors: Total minutes    
*          of rehab therapy, number of types of therapy, and number of types 
*          of nursing rehab activities.
*
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

*-------------------------------
*Determine qualification for Ultra High Rehab
        *-------------------------------
        *Resident qualifies for Ultra High Intensity Rehab.
        *   Qualifications:  
        *      (1) 720+ minutes received across all types (n_th_min)
        *                AND 
        *      (2) 5+ days received for 1 type of therapy (n_th_ty5) 
        *                AND
        *      (3) 3+ days received for a second type of 
        *          therapy (n_th_ty3)

IF (         n_th_min >= 720 ;
       .AND. n_th_ty5 >= 1 ;
       .AND. n_th_ty3 >= 2   )

                     n_reh_u = 1

ENDIF

*-------------------------------
*Determine qualification for Very High Rehab
        *-------------------------------
        *Resident qualifies for Very High Intensity Rehab.
        *   Qualifications:  
        *      (1) 500+ minutes received across all types (n_th_min)
        *                AND 
        *      (2) 5+ days received for 1 type of therapy (n_th_ty5) 

IF (         n_th_min >= 500 ;
       .AND. n_th_ty5 >= 1  )

                     n_reh_v = 1

ENDIF

*-------------------------------
*Determine qualification for High Rehab
         *-------------------------------
         *Resident qualifies for High Intensity Rehab.
         *      Qualifications:  
         *         (1) 325+ minutes received across all types (n_th_min)
         *                   AND 
         *         (2) 5+ days received for 1 type of therapy (n_th_ty5) 
         *
IF (         n_th_min >= 325 ;
       .AND. n_th_ty5 >= 1   )

                     n_reh_h = 1

ENDIF

*-------------------------------
*Determine qualification for Medium Rehab
         *-------------------------------
         *Resident qualifies for Medium Rehab.
         *      Qualifications:  
         *         (1) 150+ minutes received across all types (n_th_min)
         *                AND 
         *         (2) 5+ days received across all types of
         *             therapy (n_th_day) 
         *
IF (n_th_min >= 150 .AND. n_th_day >= 5)

                     n_reh_m = 1

ENDIF

*-------------------------------
*Determine qualification for Low Rehab
         *-------------------------------
         *Resident qualifies for Low Intensity Rehab.
         *      Qualifications:  
         *         (1) 45+ minutes received across all types (n_th_min)
         *                AND 
         *         (2) 3+ days received across all types of
         *             therapy (n_th_day)
         *                AND  
         *         (3) 2+ nursing rehab activities at 6+ days
         *             each (n_nrsum6)
         *
IF (n_th_min >= 45 .AND. n_th_day >= 3 .AND. n_nrsum6 >= 2)

                     n_reh_l = 1

ENDIF

*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*Step V.  Test Extensive Care qualification.    
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

*-------------------------------
*Determine qualification for Extensive Care. 

*Check for required Extensive Care clinical indicators.
   *-------------------------------
   *Resident qualifies for Extensive Care category on the basis of clinical 
   *indicators.
   *   Qualifications:  
   *      Parenteral/IV feedings (k5a) OR IV medication (p1ac) OR
   *      suctioning (p1ai) OR tracheostomy care (p1aj) OR
   *      ventilator or respirator (p1al).

   *-------------------------------

IF (m_k5a  = '1' .OR. ;
    m_p1ac = '1' .OR. ;
    m_p1ai = '1' .OR. ;
    m_p1aj = '1' .OR. ;
    m_p1al = '1')

   n_ext = 1

ENDIF

*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*Step VI.  Test Special Care qualification.    
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

*-------------------------------
*Code count of all levels of ulcer (n_ulcer) for Special Care 
*   qualification 
n_ulcer = 0
IF (m_m1a >= '1' .AND. m_m1a <= '9') 
   n_ulcer = n_ulcer + VAL(m_m1a)
ENDIF
IF (m_m1b >= '1' .AND. m_m1b <= '9') 
   n_ulcer = n_ulcer + VAL(m_m1b)
ENDIF
IF (m_m1c >= '1' .AND. m_m1c <= '9') 
   n_ulcer = n_ulcer + VAL(m_m1c)
ENDIF
IF (m_m1d >= '1' .AND. m_m1d <= '9') 
   n_ulcer = n_ulcer + VAL(m_m1d)
ENDIF

*-------------------------------
*Code count of selected skin care treatments for Special Care 
*   qualification
n_sk_tr = 0
IF m_m5a = '1' .OR. m_m5b = '1' 
   n_sk_tr = n_sk_tr + 1
ENDIF
IF m_m5c = '1' 
   n_sk_tr = n_sk_tr + 1
ENDIF
IF m_m5d = '1' 
   n_sk_tr = n_sk_tr + 1
ENDIF
IF m_m5e = '1' 
   n_sk_tr = n_sk_tr + 1
ENDIF
IF m_m5g = '1' 
   n_sk_tr = n_sk_tr + 1
ENDIF
IF m_m5h = '1' 
   n_sk_tr = n_sk_tr + 1
ENDIF

*-------------------------------
*Check for required Special Care clinical indicators
         *-------------------------------
         *Resident qualifies for Special Care category on the basis of 
         *clinical indicators.
         *   Qualifications (any one sufficient):  
         *      1. Two or more ulcers of any type (n_ulcer) OR stage 3 
         *         or 4 pressure ulcer (m2a) 
         *            AND
         *         two or more selected skin care treatments (n_sk_tr).
         *      2. Feeding tube (k5b) WITH parenteral/enteral intake 
         *         (n_intake) AND aphasia (i1r).
         *      3. Surgical wounds (m4g) OR open lesions other than 
         *         ulcers, rashes, cuts (m4c)
         *            AND
         *         surgical wound care (m5f) OR application of 
         *         dressings (m5g) OR application of ointments (m5h).
         *      4. Respiratory therapy for 7 days (p1bda).
         *      5. Cerebral palsy (i1s) AND ADL score of 10 or more
         *         (n_adlsum).
         *      6. Fever (j1h)
         *            AND
         *         vomiting (j1o) OR weight loss (k3a) OR tube feeding 
         *         (k5b) WITH high parenteral/enteral intake (n_intake) 
         *         OR pneumonia (i2e) OR dehydrated (j1c).
         *      7. Multiple sclerosis (i1w) AND ADL score of 10 or more
         *         (n_adlsum).
         *      8. Quadriplegia (i1z) AND ADL score of 10 or more
         *         (n_adlsum).
         *      9. Radiation therapy (p1ah).

IF (      ((n_ulcer >= 2 .OR. m_m2a = '3' .OR. m_m2a = '4') ;
             .AND. ;
           n_sk_tr >= 2) ;
     .OR. ((m_k5b = '1' .AND. n_intake = 1) .AND. m_i1r='1') ;
     .OR. ((m_m4g = '1' .OR. m_m4c = '1') ;
             .AND. ;
           (m_m5f = '1' .OR. m_m5g = '1' .OR. m_m5h='1')) ;
     .OR.  m_p1bda = '7' ;
     .OR. (m_i1s = '1' .AND. n_adlsum >= 10) ;
     .OR. (m_j1h = '1' ;
             .AND. ;
           (m_j1o = '1' ;
                 .OR. m_k3a = '1' ;
                 .OR. (m_k5b= '1' .AND. n_intake = 1) ;
                 .OR. m_i2e='1' ;
                 .OR. m_j1c='1')) ; 
     .OR. (m_i1w  = '1' .AND. n_adlsum >= 10) ;
     .OR. (m_i1z  = '1' .AND. n_adlsum >= 10) ;
     .OR. m_p1ah = '1') 

         n_spec = 1

ENDIF

*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*Step VII. Test Clinically Complex qualification.
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

*-------------------------------
*Calculate the number of periods the resident is not awake (n_n_awak).
*   This variable is used in determining whether the resident is comatose 
*   or not.  This calculation influences qualification for both Clinically 
*   Complex and Cognitive Impairment.  This count (n_n_awak) is based on 
*   items n1a, n1b, and n1c.  For RUG-III classification, it is assumed 
*   that the resident is not awake, only if the response to an item is a 
*   0 (zero).  If the response to an item is '-' (unknown), then it is 
*   treated as if the resident were awake for that period.
n_n_awak = 0
IF m_n1a = '0'
   n_n_awak = n_n_awak + 1
ENDIF
IF m_n1b = '0'
   n_n_awak = n_n_awak + 1
ENDIF
IF m_n1c = '0'
   n_n_awak = n_n_awak + 1
ENDIF

*-------------------------------
*Calculate n_coma indicating whether the resident is comatose with qualifiers.  
*      n_coma = 1 if resident is comatose (b1 = 1) and not awake all three 
*                 periods (n_n_awak = 3) and ADL dependent (g1aa, g1ba, g1ha, 
*                 and g1ia all have values of '4' or '8').
*             = 0 otherwise. 

n_coma = 0

IF (         m_b1 = '1' ;
       .AND. n_n_awak  = 3 ;
       .AND. (m_g1aa = '4' .OR. m_g1aa = '8') ;
       .AND. (m_g1ba = '4' .OR. m_g1ba = '8') ;
       .AND. (m_g1ha = '4' .OR. m_g1ha = '8') ;
       .AND. (m_g1ia = '4' .OR. m_g1ia = '8') )

           n_coma = 1

ENDIF

*-------------------------------
*Make numeric versions of p7 and p8 for ease of coding, setting value to 0
*   if item dash filled (value of '--').
n_p7 = 0
IF m_p7 <> '--'
   n_p7 = VAL(m_p7)
ENDIF
n_p8 = 0
IF m_p8 <> '--' 
   n_p8 = VAL(m_p8)
ENDIF

*-------------------------------
*Check for Clinically Complex qualification.
         *Resident qualifies for Clinically Complex Care category on the 
         *basis of clinical indicators.
         *-------------------------------
         *   Qualifications (any one sufficient):  
         *      1. Feeding tube (k5b) WITH high parenteral/enteral  
         *         intake (n_intake).
         *      2. Comatose (b1) AND not awake (n_n_awak) AND
         *         ADL dependent (g1aa, g1ba, g1ha, g1ia).
         *      3. Septicemia (i2g).
         *      4. Burns--second or third degree (m4b).
         *      5. Dehydration (j1c).
         *      6. Hemiplegia/hemiparesis (i1v) and ADL score of
         *         10 or more (n_adlsum).
         *      7. Internal bleeding (j1j).
         *      8. Pneumonia (i2e).
         *      9. Chemotherapy (p1aa).
         *     10. Dialysis (p1ab).
         *     11. Physician order changes (p8) on 4 or more days
         *         AND physician visits (p7) on 1 or more days.
         *     12. Physician order changes (p8) on 2 or more days
         *         AND physician visits (p7) on 2 or more days.
         *     13. Diabetes (i1a) AND injections (o3) on 7 days
         *         AND physician order changes (p8) on 2 or more
         *         days.
         *     14. Transfusions (p1ak).
         *     15. Oxygen therapy (p1ag).
         *     16. Infection on foot (m6b) OR open lesion on foot (m6c)
         *            AND
         *         application of dressings to foot (m6f).  
         
IF (      (m_k5b  = '1' .AND. n_intake = 1) ;
     .OR. n_coma = 1  ;
     .OR. m_i2g = '1' ;
     .OR. m_m4b = '1' ;
     .OR. m_j1c = '1' ;
     .OR. (m_i1v = '1' .AND. n_adlsum >= 10) ;
     .OR. m_j1j = '1' ;
     .OR. m_i2e = '1' ;
     .OR. m_p1aa = '1' ;
     .OR. m_p1ab = '1' ;
     .OR. ((4 <= n_p8 .AND. n_p8 <= 14) .AND. ;
           (1 <= n_p7 .AND. n_p7 <= 14)) ;
     .OR. ((2 <= n_p8 .AND. n_p8 <= 14) .AND. ;
           (2 <= n_p7 .AND. n_p7 <= 14)) ;
     .OR. (m_i1a= '1' .AND. m_o3 = '7' ;
             .AND. (2 <= n_p8 .AND. n_p8 <= 14)) ;
     .OR. m_p1ak = '1' ;
     .OR. m_p1ag = '1' ;
     .OR. ((m_m6b = '1' .OR. m_m6c = '1') ;
             .AND. (m_m6f = '1' ))  ) 

         n_clin = 1

ENDIF

*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*Step VIII.  Determine depression variable (n_depres) needed 
*               for splitting the Clinically Complex Category.
*            n_depres is a depression flag indicating presence of 
*               depression (value 1) or absence of depression (value 0).
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

*-------------------------------
*Determine count of depression indicators (n_mood)
n_mood = 0
IF m_e1a = '1' .OR. m_e1a = '2'
   n_mood = n_mood +1
ENDIF
IF m_e1b = '1' .OR. m_e1b = '2'
   n_mood = n_mood +1
ENDIF
IF m_e1c = '1' .OR. m_e1c = '2'
   n_mood = n_mood +1
ENDIF
IF m_e1d = '1' .OR. m_e1d = '2'
   n_mood = n_mood +1
ENDIF
IF m_e1e = '1' .OR. m_e1e = '2'
   n_mood = n_mood +1
ENDIF
IF m_e1f = '1' .OR. m_e1f = '2'
   n_mood = n_mood +1
ENDIF
IF m_e1g = '1' .OR. m_e1g = '2'
   n_mood = n_mood +1
ENDIF
IF m_e1h = '1' .OR. m_e1h = '2'
   n_mood = n_mood +1
ENDIF
IF m_e1i = '1' .OR. m_e1i = '2'
   n_mood = n_mood +1
ENDIF
IF m_e1j = '1' .OR. m_e1j = '2'
   n_mood = n_mood +1
ENDIF
IF m_e1k = '1' .OR. m_e1k = '2'
   n_mood = n_mood +1
ENDIF
IF m_e1l = '1' .OR. m_e1l = '2'
   n_mood = n_mood +1
ENDIF
IF m_e1m = '1' .OR. m_e1m = '2'
   n_mood = n_mood +1
ENDIF
IF m_e1n = '1' .OR. m_e1n = '2'
   n_mood = n_mood +1
ENDIF
IF m_e1o = '1' .OR. m_e1o = '2'
   n_mood = n_mood +1
ENDIF
IF m_e1p = '1' .OR. m_e1p = '2'
   n_mood = n_mood +1
ENDIF

*-------------------------------
*Set depression flag (n_depres).
IF n_mood >= 3
   n_depres = 1
ELSE
   n_depres = 0
ENDIF
   
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*Step IX. Test Cognitive Impairment qualification.
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
*Note:  RUG-III Cognitive Impairment qualification is based on
*       the Cognitive Performance Scale.
*
*   Details concerning this scale are available in:
*
*       Morris JN, Fries BE, Morris JN, Fries BE, Mehr DR, Hawes C, 
*       Phillips C, Mor V, and Lipsitz LA.  "MDS Cognitive Performance 
*       Scale" J. Gerontology: Medical Sciences 49(4):M174-M182 (July) 
*       1994.   
*
*   For use in RUG-III classification, the Cognitive Performance 
*   Scale logic has been modified to use the same qualifiers for 
*   a comatose condition as used for Clinically Complex qualification.
*
*   Note that a previously calculated variable, n_coma, is used in the
*   Cognitive Performance Scale.
*      n_coma = 1 if resident is comatose (b1 = 1) and not awake 
*                 (n_n_awak = 3) and ADL dependent (g1aa, g1ba, g1ha, and 
*                 g1ia all have values of '4' or '8').
*             = 0 otherwise. 

*-------------------------------
*Calculate n_cog1 and n_cog2 variables used in Cognitive Performance Scale.
*   n_cog1 is a count of non-independence on three items (b2a, b4, and
*          c4).
*   n_cog2 is a count of moderate to severe impairment on two items
*          (b4 and c4).
*
*   Both n_cog1 and n_cog2 have default values of -1 (missing) and are
*   only calculated if item b2a is in the range 0 to 1, item b4 is in 
*   the range 0 to 3, and item c4 is in the range 0 to 3.

n_cog1 = -1
n_cog2 = -1

IF ((m_b2a >= '0' .AND. m_b2a <= '1') .AND. ;
    (m_b4  >= '0' .AND. m_b4  <= '3') .AND. ;
    (m_c4  >= '0' .AND. m_c4  <= '3') )

       n_cog1 = 0
       IF (m_b2a = '1')
          n_cog1 = n_cog1 + 1
       ENDIF
       IF (m_b4 = '1' .OR. m_b4 = '2')
          n_cog1 = n_cog1 + 1
       ENDIF
       IF (m_c4 = '1' .OR. m_c4 = '2' .OR. m_c4 = '3')
          n_cog1 = n_cog1 + 1
       ENDIF

       n_cog2 = 0
       IF (m_b4 = '2')
          n_cog2 = n_cog2 + 1
       ENDIF
       IF (m_c4 = '2' .OR. m_c4 = '3')
          n_cog2 = n_cog2 + 1
       ENDIF

ENDIF

*-------------------------------
*Calculate n_cps--Cognitive Performance Scale .
*
*   Cognitive Performance Scale Codes: 
*          0 = intact                                                  
*          1 = borderline                                      
*          2 = mild impairment                                         
*          3 = moderate impairment                                     
*          4 = moderately severe impairment                            
*          5 = severe impairment                                       
*          6 = very severe impairment                                  

*Set n_cps to a default of 0 and calculate
n_cps = 0

IF     (n_coma = 1 .AND.;
        .NOT. (m_b4 = '0' .OR. m_b4 = '1' .OR. m_b4 = '2'))
                 n_cps = 6 
ELSEIF m_b4= '3' 
       IF     (m_g1ha = '4' .OR. m_g1ha = '8')
                 n_cps = 6
       ELSEIF (m_g1ha = '-' .OR. m_g1ha = '0' .OR. m_g1ha = '1' ;
               .OR. m_g1ha ='2' .OR. m_g1ha ='3')
                 n_cps = 5
       ENDIF
ELSEIF (n_cog1 = 2 .OR. n_cog1 = 3)
       IF     n_cog2 = 2 
                 n_cps = 4
       ELSEIF n_cog2 = 1
                 n_cps = 3
       ELSEIF n_cog2 = 0
                 n_cps = 2 
       ENDIF
ELSEIF n_cog1 = 1
                 n_cps = 1
ENDIF

*-------------------------------
*Determine Cognitive Impairment qualification.
*   Qualification if Cognitive Performance Scale is 3 or more.   

IF n_cps >= 3 

   n_impair = 1

ENDIF

*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*Step X. Test Behavior Problems qualification.
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

*-------------------------------
*Check for Behavior Problems qualification.
         *-------------------------------
         *Behavior Problems Qualifications (any one sufficient):  
         *      1. Wandering occurred on 4 or more days (e4aa).
         *      2. Verbally abusive behavior occurred on 4 or more 
         *         days (e4ba).
         *      3. Physically abusive behavior occurred on 4 or 
         *         more days (e4ca).
         *      4. Socially inappropriate/disruptive behavior 
         *         occurred on 4 or more days (e4da).
         *      5. Resident resisted care on 4 or more days (e4ea).
         *      6. Hallucinations (j1i).
         *      7. Delusions (j1e).

IF (     (m_e4aa = '2' .OR. m_e4aa =  '3') ;
    .OR. (m_e4ba = '2' .OR. m_e4ba =  '3') ;
    .OR. (m_e4ca = '2' .OR. m_e4ca =  '3') ;
    .OR. (m_e4da = '2' .OR. m_e4da =  '3') ;
    .OR. (m_e4ea = '2' .OR. m_e4ea =  '3') ;
    .OR. (m_j1i = '1') ;
    .OR. (m_j1e = '1'))

         n_behav = 1

ENDIF

*++++++++++++++++++++++++++++++++++++++++
*Step XI. Classify into RUG-III Groups          
*++++++++++++++++++++++++++++++++++++++++

*-------------------------------
*Classify into Extensive Care Groups*****
*
*To be classified as Extensive Care a resident must qualify on the 
*    basis of having Extensive Care clinical indicators (n_ext = 1); and
*    an ADL sum of 7 or more.
*
*    Note that residents who have Extensive Care clinical indicators but 
*    have too low an ADL score (6 or less) are classified as Special Care 
*    rather than Extensive Care.                               
*
*Split into Extensive Care groups is based on a count (n_ext_ct) of other 
*   hierarchy category qualifications plus existence of 
*   parenteral/IV feeding (k5a) and IV medications (p1ac).  Accept 
*   classification into a group if CMI for that group is higher than 
*   previous high CMI.

IF ((n_ext = 1 .AND. n_adlsum >=7))

   n_ext_ct = n_spec + n_clin + n_impair
   IF m_k5a = '1'
      n_ext_ct = n_ext_ct + 1
   ENDIF
   IF m_p1ac= '1'
      n_ext_ct = n_ext_ct + 1
   ENDIF

   IF     (4 <= n_ext_ct .AND. n_ext_ct <= 5)
             IF n_cmi[15] > n_cmi_hi
                c_m3 = 'SE3'
                n_cmi_hi = n_cmi[15]                    
             ENDIF
   ELSEIF (2 <= n_ext_ct .AND. n_ext_ct <= 3)
             IF n_cmi[16] > n_cmi_hi
                c_m3 = 'SE2'
                n_cmi_hi = n_cmi[16]                    
             ENDIF
   ELSEIF (0 <= n_ext_ct .AND. n_ext_ct <= 1)
             IF n_cmi[17] > n_cmi_hi
                c_m3 = 'SE1'
                n_cmi_hi = n_cmi[17]                    
             ENDIF
   ENDIF

ENDIF

*-------------------------------
*Classify into Rehab Groups*****
*
*To be classified as Rehab a resident must satisfy one of the 
*   five following conditions:
*  1. Resident qualifies under the Ultra High Rehab conditions (n_reh_u = 1).   
*  2. Resident qualifies under the Very High Rehab conditions (n_reh_v = 1).   
*  3. Resident qualifies under the High Rehab conditions (n_reh_h = 1).   
*  4. Resident qualifies under the Medium Rehab conditions (n_reh_m = 1).   
*  5. Resident qualifies under the Low Rehab conditions (n_reh_l = 1).   
*
*   Classify if one of these 5 conditions present and (1) calculation  
*      type is Index Maximizing or (2) calculation type is Hierarchical 
*      and a previous classification has not been made (indicated by 
*      n_cmi_hi being at a default negative value).
*
*   Determine final splits for Rehab residents on the basis of ADL sum.  
*   Accept classification into a group if CMI for that group is higher 
*   than previous high CMI.

IF (   ( n_reh_u = 1 .OR. ;
         n_reh_v = 1 .OR. ;
         n_reh_h = 1 .OR. ;
         n_reh_m = 1 .OR. ;
         n_reh_l = 1 ) ;
     .AND. ;
       ( c_type = 'Index' .OR. ;
        (c_type = 'Hier' .AND. n_cmi_hi < 0) ) )

   IF     (17 <= n_adlsum .AND. n_adlsum <= 18)
             IF n_cmi[46] > n_cmi_hi
                c_m3 = 'RAD'
                n_cmi_hi = n_cmi[46]                    
             ENDIF
   ELSEIF (14 <= n_adlsum .AND. n_adlsum <= 16)
             IF n_cmi[47] > n_cmi_hi
                c_m3 = 'RAC'
                n_cmi_hi = n_cmi[47]                    
             ENDIF
   ELSEIF (10 <= n_adlsum .AND. n_adlsum <= 13)
             IF n_cmi[48] > n_cmi_hi
                c_m3 = 'RAB'
                n_cmi_hi = n_cmi[48]                    
             ENDIF
   ELSEIF ( 4 <= n_adlsum .AND. n_adlsum <=  9)
             IF n_cmi[49] > n_cmi_hi
                c_m3 = 'RAA'
                n_cmi_hi = n_cmi[49]                    
             ENDIF
   ENDIF

ENDIF

*-------------------------------
*Classify into Special Care Groups******
*
*To be classified as Special Care a resident must satisfy one of the 
*   three following conditions:
*   1. The resident has both Special Care clinical indicators (n_spec = 1) 
*      and an ADL sum of 7 or more, regardless of calculation method.  
*   2. The calculation method is Hierarchical and the resident has both
*      Extensive Care indicators (n_ext = 1) and an ADL sum of 6 or less.
*   3. The calculation method is Index Maximizing or Medicare and the 
*      resident has Extensive Care clinical indicators (n_ext = 1) with 
*      any ADL sum. 
*
*   Classify if one of these 3 conditions present and (1) calculation  
*      type is Medicare, (2) calculation type is Index Maximizing, or
*      (3) calculation type is Hierarchical and a previous classification
*      has not been made (indicated by n_cmi_hi being at a default 
*      negative value).
*
*   Note that residents who have Special Care clinical indicators but 
*   have too low an ADL score (6 or less) are classified as Clinically 
*   Complex rather than Special Care.                               
*
*Split into Special Care groups is based on ADL sum.  Accept classification 
*   into a group if CMI for that group is higher than previous high CMI.

IF (((n_spec = 1 .AND. n_adlsum >= 7) .OR. n_ext = 1) .AND. ;
    ( c_type = 'Mcare' .OR. ;
      c_type = 'Index' .OR. ;
     (c_type = 'Hier' .AND. n_cmi_hi < 0) ) )

   IF     (17 <= n_adlsum .AND. n_adlsum <= 18)
             IF n_cmi[18] > n_cmi_hi
                c_m3 = 'SSC'
                n_cmi_hi = n_cmi[18]                    
             ENDIF
   ELSEIF (15 <= n_adlsum .AND. n_adlsum <= 16)
             IF n_cmi[19] > n_cmi_hi
                c_m3 = 'SSB'
                n_cmi_hi = n_cmi[19]                    
             ENDIF
   ELSEIF ( 4 <= n_adlsum .AND. n_adlsum <= 14)
             IF n_cmi[20] > n_cmi_hi
                c_m3 = 'SSA'
                n_cmi_hi = n_cmi[20]                    
             ENDIF
   ENDIF

ENDIF

*-------------------------------
*Classify into Clinically Complex Groups*******                                             
*To be classified as Clinically Complex a resident must satisfy one of the 
*   four following conditions:
*   1. The resident has Clinically Complex clinical indicators (n_clin = 1),
*      regardless of calculation method. 
*   2. The calculation method is Hierarchical and the resident has both
*      Special Care indicators (n_spec = 1) and an ADL sum of 6 or less.
*   3. The calculation method is Index Maximizing or Medicare and the 
*      resident has Special Care clinical indicators (n_spec = 1) with 
*      any ADL sum. 
*   4. The calculation method is Index Maximizing or Medicare and the 
*      resident has Extensive Care clinical indicators (n_ext = 1) with 
*      any ADL sum. 
*
*   Classify if one of these 4 conditions present and (1) calculation  
*      type is Medicare, (2) calculation type is Index Maximizing, or
*      (3) calculation type is Hierarchical and a previous classification
*      has not been made (indicated by n_cmi_hi being at a default 
*      negative value).
*
*Split into Clinically Complex groups is based on ADL sum and depression.
*   Accept classification into a group if CMI for that group is higher 
*   than previous high CMI.

IF ((n_clin = 1 .OR. n_spec = 1 .OR. n_ext = 1) .AND. ;
    ( c_type = 'Mcare' .OR. ;
      c_type = 'Index' .OR. ;
     (c_type = 'Hier' .AND. n_cmi_hi < 0) ) )

   IF     (17 <= n_adlsum .AND. n_adlsum <= 18)
             IF n_depres = 1
                IF n_cmi[21] > n_cmi_hi
                   c_m3 = 'CC2'
                   n_cmi_hi = n_cmi[21]                    
                ENDIF
             ELSE
                IF n_cmi[22] > n_cmi_hi
                   c_m3 = 'CC1'
                   n_cmi_hi = n_cmi[22]                    
                ENDIF
             ENDIF
   ELSEIF (12 <= n_adlsum .AND. n_adlsum <= 16)
             IF n_depres = 1
                IF n_cmi[23] > n_cmi_hi
                    c_m3 = 'CB2'
                    n_cmi_hi = n_cmi[23]                    
                ENDIF
             ELSE 
                IF n_cmi[24] > n_cmi_hi
                   c_m3 = 'CB1'
                   n_cmi_hi = n_cmi[24]                    
                ENDIF
             ENDIF
   ELSEIF ( 4 <= n_adlsum .AND. n_adlsum <= 11)
             IF n_depres = 1
                IF n_cmi[25] > n_cmi_hi
                   c_m3 = 'CA2'
                   n_cmi_hi = n_cmi[25]                    
                ENDIF
             ELSE 
                IF n_cmi[26] > n_cmi_hi
                   c_m3 = 'CA1'
                   n_cmi_hi = n_cmi[26]                    
                ENDIF
             ENDIF
   ENDIF

ENDIF

*-------------------------------
*Classify into Cognitive Groups*****
*
*To be classified as Cognitive Impairment the resident has Cognitive
*   Impairment indicators (n_impair = 1); and an ADL sum of 10 or less; and
*   (1) calculation type is Medicare, (2) calculation type is Index 
*   Maximizing, or (3) calculation type is Hierarchical and a previous 
*   classification has not been made (indicated by n_cmi_hi being at a 
*   default negative value).
*
*Split into Impaired Cognitive groups is based on ADL sum and nursing 
*   rehab count (n_nrsum6).  Accept classification into a group if CMI
*   for that group is higher than previous high CMI.

IF ((n_impair = 1 .AND. 4 <= n_adlsum .AND. n_adlsum <= 10) .AND. ;
    ( c_type = 'Mcare' .OR. ;
      c_type = 'Index' .OR. ;
     (c_type = 'Hier' .AND. n_cmi_hi < 0) ) )

   IF      ( 6 <= n_adlsum .AND. n_adlsum <= 10)
             IF n_nrsum6 >= 2
                IF n_cmi[27] > n_cmi_hi
                   c_m3 = 'IB2'
                   n_cmi_hi = n_cmi[27]                    
                ENDIF
             ELSE
                IF n_cmi[28] > n_cmi_hi
                   c_m3 = 'IB1'
                   n_cmi_hi = n_cmi[28]                    
                ENDIF
             ENDIF
   ELSEIF ( 4 <= n_adlsum .AND. n_adlsum <=  5)
             IF n_nrsum6 >= 2
                IF n_cmi[29] > n_cmi_hi
                   c_m3 = 'IA2'
                   n_cmi_hi = n_cmi[29]                    
                ENDIF
             ELSE 
                IF n_cmi[30] > n_cmi_hi
                   c_m3 = 'IA1'
                   n_cmi_hi = n_cmi[30]                    
                ENDIF
             ENDIF
   ENDIF

ENDIF

*-------------------------------
*Classify into Behavioral Problems Groups******                                            
*
*To be classified as Behavior Problems the resident has Behavior 
*   Problems indicators (n_behav = 1); and an ADL sum of 10 or less; 
*   and (1) calculation type is Medicare, (2) calculation type is 
*   Index Maximizing, or (3) calculation type is Hierarchical and a 
*   previous classification has not been made (indicated by n_cmi_hi 
*   being at a default negative value).
*
*Split into Behavior Problems groups is based on ADL sum and nursing 
*   rehab count (n_nrsum6).  Accept classification into a group if CMI
*   for that group is higher than previous high CMI.

IF ((n_behav = 1 .AND. 4 <= n_adlsum .AND. n_adlsum <= 10) .AND. ;
    ( c_type = 'Mcare' .OR. ;
      c_type = 'Index' .OR. ;
     (c_type = 'Hier' .AND. n_cmi_hi < 0) ) )

   IF     ( 6 <= n_adlsum .AND. n_adlsum <= 10)
             IF n_nrsum6 >= 2 
                IF n_cmi[31] > n_cmi_hi
                   c_m3 = 'BB2'
                   n_cmi_hi = n_cmi[31]                    
                ENDIF
             ELSE 
                IF n_cmi[32] > n_cmi_hi
                   c_m3 = 'BB1'
                   n_cmi_hi = n_cmi[32]                    
                ENDIF
             ENDIF
   ELSEIF ( 4 <= n_adlsum .AND. n_adlsum <=  5)
             IF n_nrsum6 >= 2
                IF n_cmi[33] > n_cmi_hi
                   c_m3 = 'BA2'
                   n_cmi_hi = n_cmi[33]                    
                ENDIF
             ELSE    
                IF n_cmi[34] > n_cmi_hi
                   c_m3 = 'BA1'
                   n_cmi_hi = n_cmi[34]                    
                ENDIF
             ENDIF
   ENDIF

ENDIF

*-------------------------------
*Classify into Physical Groups********                                              
*   A resident is classified as reduced Physical Function if 
*   (1) calculation type is Medicare, (2) calculation type is Index 
*   Maximizing, or (3) calculation type is Hierarchical and a previous 
*   classification has not been made (indicated by n_cmi_hi being at a 
*   default negative value).
*
*Split into Physical Function groups is based on ADL sum and nursing 
*   rehab count (n_nrsum6).  Accept classification into a group if CMI
*   for that group is higher than previous high CMI.

IF  ( c_type = 'Mcare' .OR. ;
      c_type = 'Index' .OR. ;
     (c_type = 'Hier' .AND. n_cmi_hi < 0) ) 

   IF     (16 <= n_adlsum .AND. n_adlsum <= 18)
             IF n_nrsum6 >= 2 
                IF n_cmi[35] > n_cmi_hi
                   c_m3 = 'PE2'
                   n_cmi_hi = n_cmi[35]                    
                ENDIF
             ELSE
                IF n_cmi[36] > n_cmi_hi
                   c_m3 = 'PE1'
                   n_cmi_hi = n_cmi[36]                    
                ENDIF
             ENDIF

   ELSEIF (11 <= n_adlsum .AND. n_adlsum <= 15)
             IF n_nrsum6 >= 2 
                IF n_cmi[37] > n_cmi_hi
                   c_m3 = 'PD2'
                   n_cmi_hi = n_cmi[37]                    
                ENDIF
             ELSE 
                IF n_cmi[38] > n_cmi_hi
                   c_m3 = 'PD1'
                   n_cmi_hi = n_cmi[38]                    
                ENDIF
             ENDIF

   ELSEIF ( 9 <= n_adlsum .AND. n_adlsum <= 10)
             IF n_nrsum6 >= 2 
                IF n_cmi[39] > n_cmi_hi
                   c_m3 = 'PC2'
                   n_cmi_hi = n_cmi[39]                    
                ENDIF
             ELSE 
                IF n_cmi[40] > n_cmi_hi
                   c_m3 = 'PC1'
                   n_cmi_hi = n_cmi[40]                    
                ENDIF
             ENDIF

   ELSEIF ( 6 <= n_adlsum .AND. n_adlsum <=  8 )
             IF n_nrsum6 >= 2 
                IF n_cmi[41] > n_cmi_hi
                   c_m3 = 'PB2'
                   n_cmi_hi = n_cmi[41]                    
                ENDIF
             ELSE   
                IF n_cmi[42] > n_cmi_hi
                   c_m3 = 'PB1'
                   n_cmi_hi = n_cmi[42]                    
                ENDIF
             ENDIF

   ELSEIF ( 4 <= n_adlsum .AND. n_adlsum <=  5 )
             IF n_nrsum6 >= 2  
                IF n_cmi[43] > n_cmi_hi
                   c_m3 = 'PA2'
                   n_cmi_hi = n_cmi[43]                    
                ENDIF
             ELSE 
                IF n_cmi[44] > n_cmi_hi
                   c_m3 = 'PA1'
                   n_cmi_hi = n_cmi[44]                    
                ENDIF
             ENDIF
   ENDIF

ENDIF

*RUG-III Classification complete--end routine
RETURN