**********PSEUDOCODE FOR 44 GROUP M3PI MODEL*****************************
*Pseudocode for the 44 Group Model of Version 5.01 of the M3PI 
*   Classification System

*Version 5.01 is for use with the MDS Version 2.0 assessment form.

*Last change: 03/26/96

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

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

*   This pseudocode has been placed in a ASCII text file called 
*      M3PC44.TXT.  This pseudocode was derived from a working
*      CLIPPER program which received extensive testing.  Standard
*      test databases with several hundred MDS+ records are available in 
*      both DBASE format (TEST501A.DBF and TEST501B.DBF) and ASCII format
*      (TEST501A.ASC and TEST501B.ASC).  These test databases should provide 
*      reasonably exhaustive testing of 44 group M3PI (RUG-III) 
*      classification code.

*---------------------------------------------------------------------------
*Calculation types (modes) used in this pseudocode:

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

*   For the Index maximizing method, 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).

*   The Medicare calculation type also uses an index maximizing methodology, 
*   but applies special rehabilitation group classification for Medicare
*   assessments which are 5 day preliminary assessments (AA8b = '1') or
*   readmission assessments (AA8b = '5').  For these two types of assessments
*   the Medicare methods considers rehabilitation therapies ordered (items
*   T1b, T1c, and T1d) in addition to rehabilitation therapies actually 
*   provided.  

*   The calculation type (hierarchical, Medicare, 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 = 'Mcare', then the type will be Medicare.
*        If c_type = any other value, then the method will be 
*                    index maximizing.

*---------------------------------------------------------------------------
*Syntax Used in this pseudocode:

*   1.  All lines with an asterisk (*) in the first column are documentation 
*         or comment lines.
*   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+ variables are represented in small letters without a
*         prefix.  ALL MDS+ VARIABLES ARE REQUIRED TO BE CHARACTER VARIABLES
*         IN THIS PSEUDOCODE.  The MDS+ variables names correspond to the 
*         labels on the MDS+ form.  The only confusion could result with 
*         regard to the variables i12b and i2a.  The i12b variable is from
*         the admission document (cover sheet), while the i2a variable
*         is from section I of the body of the assessment form.
*   5.  All local (non-MDS+) variables are represented in small letters with
*         a prefix of "c_" for character variables (e.g., c_m3), 
*         a prefix of "n_" for numeric variables (e.g., n_adlsum), and
*         a prefix of "l_" for logical variables (e.g., l_sad).  Logical
*         variable values are .T. (true) and .F. (false).
*   6.  The only command words and structures used in this pseudocode are:
*         a. RETURN 
*               (this command assumes that classification ceases with
*               the current group being accepted for the resident)
*         a. IF <logical condition> 
*               <arithmetic statement> executed if condition true 
*            ENDIF
*         b. IF <logical condition1> 
*               <arithmetic statement> executed if condition1 true 
*            ELSEIF <logical condition2>
*               <arithmetic statement> executed if condition2 true 
*            ENDIF
*         c. Logical operators used in logical conditions are
*                =       (equal)
*                >       (greater than)
*                <       (less than) 
*                >=      (greater than or equal to)
*                <=      (less than or equal to)
*         d. Relational operators used in logical conditions are
*                .AND.   (logical and)
*                .OR.    (logical or)
*         e. 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.

*---------------------------------------------------------------------------
*MDS Version 2.0 variables required by this pseudocode for M3PI calculation 
*are:
*    AA8b
*    B1,B2a,B3a,B3b,B3c,B3d,B4
*    E1a,E1g,E1j,E1n,E1o,E1p,E2,E4aA,E4bA,E4cA,E4dA,E4eA
*    G1aA,G1aB,G1bA,G1bB,G1hA,G1iA,G1iB
*    H3a
*    I1r,I1s,I1v,I1w,I1z,I1ee,I1ff,I2e,I2g,I2j
*    J1c,J1e,J1h,J1i,J1j,J1k,J1o,J5c
*    K3a,K5a,K5b
*    M2a,M2b,M4b,M4c,M4f,M4g,M5f,M5i,M6f
*    N1a,N1b,N1c,N1d
*    P1aa,P1ab,P1ac,P1ag,P1ah,P1ai,P1aj,P1ak,P1al,
*    P1baA,P1baB,P1bbA,P1bbB,P1bcA,P1bcB,P1bdA,
*    P3a,P3b,P3c,P3d,P3e,P3f,P3g,P3h,P3i,P8
*    T1b,T1c,T1d                                                

*---------------------------------------------------------------------------
*Processing required before execution of pseudocode: 
*   1.  Read MDS 2.0 record and store appropriate character values in the 
*          MDS 2.0 variables listed above.
*   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. 
*   3.  Recode some values for the required MDS+ variables (necessary 
*          recoding of values is given below).

*---------------------------------------------------------------------------
*Valid values for required MDS 2.0 variables.  

*VAR    RANGE                  SHORT DESCRIPTION
*---    -----------------      ----------------------------------------------
*AA8b   blank,1,2,3,4,5,6      Special assessment code                       
*B1     0,1,-                  Comatose                                         
*B2a    blank,0,1,-            Short-term memory OK                          
*B3a    blank,0,1,-,&          Memory Recall Current season                                
*B3b    blank,0,1,-,&          Memory Recall Location of own room                          
*B3c    blank,0,1,-,&          Memory Recall Staff names/faces                             
*B3d    blank,0,1,-,&          Memory Recall That he/she in nursing home                   
*B4     blank,0,1,2,3,-        Cognitive Skills/Daily Decision Making           
*E1a    blank,0,1,2,-          Negative statements                        
*E1g    blank,0,1,2,-          Recurrent statements of terrible future    
*E1j    blank,0,1,2,-          Unpleasant mood in morning                 
*E1n    blank,0,1,2,-          Repetitive physical movements              
*E1o    blank,0,1,2,-          Withdrawal from activities of interest     
*E1p    blank,0,1,2,-          Reduced social interaction                 
*E2     blank,0,1,2,-          Mood Persistence                                 
*E4aA   blank,0,1,2,3,-        Wandering behavior symptom frequency                 
*E4bA   blank,0,1,2,3,-        Verbal Abuse behavior symptom frequency                 
*E4cA   blank,0,1,2,3,-        Physical abuse behavior symptom frequency                 
*E4dA   blank,0,1,2,3,-        Socially Inappropriate behavior symptom frequency                 
*E4eA   blank,0,1,2,3,-        Resists Care behavior symptom frequency                 
*G1aA   0,1,2,3,4,8,-          Bed Mobility ADL Self-Performance                       
*G1aB   0,1,2,3,8,-,&          Bed Mobility ADL Support Provided                       
*G1bA   0,1,2,3,4,8,-          Transfer ADL Self-Performance                       
*G1bB   0,1,2,3,8,-,&          Transfer ADL Support Provided                       
*G1hA   0,1,2,3,4,8,-          Eating ADL Self-Performance                       
*G1iA   0,1,2,3,4,8,-          Toilet Use ADL Self-Performance                       
*G1iB   0,1,2,3,8,-,&          Toilet UseADL Support Provided                       
*H3a    0,1,-                  Any scheduled toileting plan                  
*I1r    0,1,-,&                Aphasia                                    
*I1s    0,1,-,&                Cerebral palsy                             
*I1v    0,1,-,&                Hemiplegia/hemiparesis                     
*I1w    0,1,-,&                Multiple sclerosis                         
*I1z    0,1,-,&                Quadriplegia                               
*I1ee   0,1,-,&                Depression                                 
*I1ff   0,1,-,&                Manic depressive (bipolar disease)         
*I2e    0,1,-,&                Pneumonia                                     
*I2g    0,1,-,&                Septicemia                                    
*I2j    0,1,-                  Urinary tract infection in last 30 days       
*J1c    0,1,-                  Dehydrated--output exceeds input           
*J1e    0,1,-,&                Delusions                                  
*J1h    0,1,-,&                Fever                                      
*J1i    0,1,-                  Hallucinations                             
*J1j    0,1,-,&                Internal bleeding                          
*J1k    0,1,-,&                Recurrent lung aspirations in last 90 days  
*J1o    0,1,-,&                Vomiting                                   
*J5c    0,1,-                  End-stage disease, 6 or fewer months to live  
*K3a    0,1,-                  Weight loss                                   
*K5a    0,1,-,&                Parenteral IV                                 
*K5b    0,1,-                  Feeding tube                                  
*M2a    0,1,2,3,4,-            Pressure ulcer                                
*M2b    0,1,2,3,4,-            Stasis ulcer                                  
*M4b    0,1,-,&                Burns (second or third degree)                
*M4c    0,1,-,&                Open lesions other than ulcers, rashes, cuts  
*M4f    0,1,-,&                Skin tears or cuts (other than surgery)       
*M4g    0,1,-,&                Surgical wounds                               
*M5f    0,1,-,&                Surgical wound care                           
*M5i    0,1,-,&                Other preventative/protective skin care       
*M6f    0,1,-,&                Application of dressings                      
*N1a    0,1,-                  Time Awake--Morning                                       
*N1b    0,1,-                  Time Awake--Afternoon                                     
*N1c    0,1,-                  Time Awake--Evening                                       
*N1d    0,1,-                  Time Awake--None of Above                                 
*P1aa   0,1,-,&                Chemotherapy                            
*P1ab   0,1,-,&                Dialysis                                
*P1ac   0,1,-,&                IV medication                           
*P1ag   0,1,-,&                Oxygen therapy                          
*P1ah   0,1,-,&                Radiation                               
*P1ai   0,1,-,&                Suctioning                              
*P1aj   0,1,-,&                Tracheostomy care                       
*P1ak   0,1,-,&                Transfusions                            
*P1al   0,1,-,&                Ventilator or respirator                
*P1baA  0 thru 7,-,&           Speech therapy--# days (last 7 days)   
*P1baB  0000 thru 9999,        Speech therapy--# minutes (last 7 day)               
*       ----,&&&&
*P1bbA  0 thru 7,-,&           Occupational therapy--# days (last 7 days)   
*P1bbB  0000 thru 9999,        Occupational therapy--# minutes (last 7 day)               
*       ----,&&&&
*P1bcA  0 thru 7,-,&           Physical therapy--# days (last 7 days)   
*P1bcB  0000 thru 9999,        Physical therapy--# minutes (last 7 day)               
*       ----,&&&&
*P1bdA  0 thru 7,-,&           Respiratory therapy--# days (last 7 days)   
*P3a    0 thru 7,-,&           Nursing rehab--Range of motion (passive)                     
*P3b    0 thru 7,-,&           Nursing rehab--Range of motion (active)                      
*P3c    0 thru 7,-,&           Nursing rehab--Splint or brace assistance                    
*P3d    0 thru 7,-,&           Nursing rehab--Bed mobility                               
*P3e    0 thru 7,-,&           Nursing rehab--Transfer                                   
*P3f    0 thru 7,-,&           Nursing rehab--Walking                                    
*P3g    0 thru 7,-,&           Nursing rehab--Dressing or grooming                       
*P3h    0 thru 7,-,&           Nursing rehab--Eating or swallowing                       
*P3i    0 thru 7,-,&           Nursing rehab--Amputation/prosthesis care                 
*P8     00 thru 14,--,&&       Physician Orders                                 
*T1b    0,1,-,blank            Ordered Therapies                             
*T1c    00 thru 15,--,         Estimate of days of therapy until day 15      
*       blank
*T1d    0000 thru 9999,        Estimate of minutes of therapy until day 15    
*       '----',blank

*---------------------------------------------------------------------------
*Necessary recoding of required MDS+ variables before applying the 
*classification logic:
*    For most MDS+ variables, values of blank(s) or dash(s) (-)
*       are recoded to values of 0(s) (character value).  This applies to
*       to all variables except for b3a, b3b, b3c, b3d, n1a, n1b, and n1c.
*       For b3a, b3b, b3c, and b3d, a value of blank, dash, or ampersand
*       is recoded to a 1 (character value), and for n1a, n1b, and n1c,
*       a value of dash is recoded to a 1.

*---------------------------------------------------------------------------
*Local variables used in the classification logic:

*    VARIABLE       DESCRIPTION
                      
*    c_type         determines whether the classificationn method is
*                      hierarchical, Medicare, or index maximizing.  This 
*                      variable should be set to 'Hier' for hierarchical,
*                      to "Mcare" for Medicare, or any other
*                      value for index maximizing.
*    c_m3           is the M3PI group to which the resident is assigned.
*    n_cmi          is a 48 element array (n_cmi[01] to n_cmi[48]) holding
*                      the Case Mix Index (CMI) set used in the index 
*                      maximizing method of classification.
*    n_cmi_high     the highest Case Mix Index previously found as a resident 
*                      is tested for classification.
*    n_adl_a        Bed mobility (ADL) scale score.
*    n_adl_b        Transfer (ADL) scale score.
*    n_adl_g        Eating (ADL) scale score.
*    n_adl_h        Toilet use (ADL) scale score.
*    n_adlsum       Total ADL scale score.
*    n_ther_min     Total minutes of rehabilitation therapy (PT, OT and ST)
*                      received by the resident.
*    n_ther_typ     Number of different therapies received (PT, OT and ST).
*    n_ther_dys     Number of days on which a therapy (PT, OT, and ST) is
*                      received.
*    n_nr5_sum      Number of nursing rehabilitation activities provided
*                      at least 5 days per week.
*    n_nr2_sum      Number of nursing rehabilitation activities provided
*                      at least 2 days per week.
*    n_nrtoil       n_nr5_sum with 1 added if there is a toileting program.
*    n_ext_trt      Number of extensive teatments.
*    n_awk_cnt      Scale indicating amount of time awake.
*    n_sad_cnt      Count of number of symptoms of depression.
*    l_sad          Logical variable indicating whether resident is
*                      depressed (true value -- .T.) or not (false
*                      value -- .F.).
*    l_reh_vh       Logical variable indicating whether the resident 
*                      qualifies for a Very High Rehab group.
*    l_reh_hi       Logical variable indicating whether the resident 
*                      qualifies for a High Rehab group.
*    l_reh_md       Logical variable indicating whether the resident 
*                      qualifies for a Medium Rehab group.
*    l_reh_lo       Logical variable indicating whether the resident 
*                      qualifies for a Low Rehab group.

*    l_complex      Logical variable indicating whether the resident has
*                      clinical qualifiers for Extensive or Special care.
*                      This logical variable is used to classify low
*                      ADL residents (< 7) in the Clinical Complex
*                      groups.

*++++++++++++++++++++++++++++++++++++++++
*   Group labels and order for the CMI array, n_cmi, for the 44 
*      group model are as follows:
*
*      Array
*    Element #   M3PI Group
*    ---------   -------------                                  
*        1       RVC:  Rehabilitation Very High / ADL 14 - 18
*        2       RVB:  Rehabilitation Very High / ADL  8 - 13
*        3       RVA:  Rehabilitation Very High / ADL  4 -  7
*        4       RHD:  Rehabilitation High / ADL 15 - 18
*        5       RHC:  Rehabilitation High / ADL 12 - 14
*        6       RHB:  Rehabilitation High / ADL  8 - 11
*        7       RHA:  Rehabilitation High / ADL  4 -  7
*        8       RMC:  Rehabilitation Medium / ADL 16 - 18
*        9       RMB:  Rehabilitation Medium / ADL  8 - 15
*       10       RMA:  Rehabilitation Medium / ADL  4 -  7
*       11       RLB:  Rehabilitation Low / ADL 12 - 18
*       12       RLA:  Rehabilitation Low / ADL  4 - 11
*       13       SE3:  Extensive Special Care 3 / All ADLs > 6
*       14       SE2:  Extensive Special Care 2 / All ADLs > 6
*       15       SE1:  Extensive Special Care 1 / All ADLs > 6
*       16       SSC:  Special Care / ADL 17 - 18
*       17       SSB:  Special Care / ADL 14 - 16
*       18       SSA:  Special Care / ADL  7 - 13
*       19       CD2:  Clin. Complex with Depression / ADL 17 - 18
*       20       CD1:  Clinically Complex / ADL 17 - 18
*       21       CC2:  Clin. Complex with Depression / ADL 11 - 16
*       22       CC1:  Clinically Complex / ADL 11 - 16
*       23       CB2:  Clin. Complex with Depression / ADL  6 - 10
*       24       CB1:  Clinically Complex / ADL  6 - 10
*       25       CA2:  Clin. Complex with Depression / ADL  4 -  5
*       26       CA1:  Clinically Complex / ADL  4 -  5
*       27       IB2:  Cognitive Impairment with Nursing Rehab / ADL   6 - 10
*       28       IB1:  Cognitive Impairment / ADL   6 - 10
*       29       IA2:  Cognitive 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

*  Note that array elements 46 through 48 are not used for the 44 group 
*     model.  These elements refer to the Rehabilitation groups
*     in the 35 group model.

**************************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_high is the highest CMI previously qualified for.
n_cmi_high = -99999

*Initialize adlsum as zero.
n_adlsum = 0


*++++++++++++++++++++++++++++++++++++++++
*Step II. Calculate M3PI ADL Index.
*         The ADL index is required for use in hierarchy Special Care
*         classification and for splitting hierarchy groups.
*         (The ADL index requires scoring conversion for the different
*         ADL's and then summation.  See Section II.B. of NHCMQ RUG III
*         system description from 3/20/92.)

*-------------------------------
*ADL scoring conversion for Bed mobility.

IF c_g1aa <= '1'
            n_adl_a = 1
ELSEIF c_g1aa =  '2'
            n_adl_a = 3
ELSEIF (c_g1aa = '3' .OR. c_g1aa = '4' .OR. c_g1aa = '8') .AND. c_g1ab <= '2'
            n_adl_a = 4
ELSEIF (c_g1aa = '3' .OR. c_g1aa = '4' .OR. c_g1aa = '8') .AND. ;
            (c_g1ab =  '3' .OR. c_g1ab = '8')
                 n_adl_a = 5
ENDIF

*-------------------------------
*ADL scoring conversion for Transfer.

IF c_g1ba <= '1'
            n_adl_b = 1
ELSEIF c_g1ba =  '2'
            n_adl_b = 3
ELSEIF (c_g1ba = '3' .OR. c_g1ba = '4' .OR. c_g1ba = '8') .AND. c_g1bb <= '2'
            n_adl_b = 4
ELSEIF (c_g1ba = '3' .OR. c_g1ba = '4' .OR. c_g1ba = '8') .AND. ;
            (c_g1bb =  '3' .OR. c_g1bb =  '8')
                 n_adl_b = 5
ENDIF

*-------------------------------
*ADL scoring conversion for Toilet Use.

IF c_g1ia <= '1'
            n_adl_g = 1
ELSEIF c_g1ia =  '2'
            n_adl_g = 3
ELSEIF (c_g1ia = '3' .OR. c_g1ia = '4' .OR. c_g1ia = '8') .AND. c_g1ib <= '2'
            n_adl_g = 4
ELSEIF (c_g1ia = '3' .OR. c_g1ia = '4' .OR. c_g1ia = '8') .AND. ;
            (c_g1ib =  '3' .OR. c_g1ib =  '8')
                 n_adl_g = 5
ENDIF

*-------------------------------
*ADL scoring conversion for Eating.

IF c_k5a = '1' .OR. c_k5b = '1'
   n_adl_h = 3
ELSEIF c_g1ha <= '1'
   n_adl_h = 1
ELSEIF c_g1ha = '2'
   n_adl_h = 2
ELSEIF c_g1ha = '3' .OR. c_g1ha = '4' .OR. c_g1ha = '8'
   n_adl_h = 3
ENDIF


*-------------------------------
*Sum the converted ADL scores to n_adlsum.

n_adlsum = n_adl_a + n_adl_b + n_adl_g + n_adl_h


*++++++++++++++++++++++++++++++++++++++++
*Step III. Determine Rehab and Rehab nursing variables needed for
*          Rehab group classification.
*          Variables needed to determine Rehab clinical hierarchy
*          group membership:
*             - Total minutes of rehab therapy (n_ther_min)
*             - Number of types of rehab therapy (n_ther_typ)
*             - Number of days of rehab therapy (n_ther_dys)
*             - Number of types of nursing rehab activities (n_nr5_sum
*               and n_nr2_sum)

*-------------------------------
*Determine n_ther_min -- the number of minutes of rehabilitation therapy
*   administered.

n_ther_min = VAL(c_p1bab) + VAL(c_p1bbb) + VAL(c_p1bcb)

*-------------------------------
*Determine n_ther_typ.
*   n_ther_typ represents the number of different rehab therapies (physical,
*      occupational, and speech) that were provided on one or more days 
*      during that period. 

n_ther_typ = 0
IF 1 <= VAL(c_p1baa) .AND. VAL(c_p1baa) <= 7
   n_ther_typ = n_ther_typ + 1
ENDIF
IF 1 <= VAL(c_p1bba) .AND. VAL(c_p1bba) <= 7
   n_ther_typ = n_ther_typ + 1
ENDIF
IF 1 <= VAL(c_p1bca) .AND. VAL(c_p1bca) <= 7
   n_ther_typ = n_ther_typ + 1
ENDIF

*-------------------------------
*Determine n_ther_dys.
*   n_ther_dys represents the number of days of therapy provided across 
*      physical, occupational, and speech therapies.

n_ther_dys = VAL(c_p1baa) + VAL(c_p1bba) + VAL(c_p1bca)

*-------------------------------
*Determine n_nr5_sum.
*   n_nr5_sum is the number of types of nursing rehab activities provided
*   at least 5 days per week.

n_nr5_sum = 0
IF c_p3a >= '5'
   n_nr5_sum = n_nr5_sum + 1
ENDIF
IF c_p3b >= '5'
   n_nr5_sum = n_nr5_sum + 1
ENDIF
IF c_p3c >= '5'
   n_nr5_sum = n_nr5_sum + 1
ENDIF
IF (c_p3f >= '5' .OR. c_p3d >= '5')
   n_nr5_sum = n_nr5_sum + 1
ENDIF
IF c_p3g >= '5'
   n_nr5_sum = n_nr5_sum + 1
ENDIF
IF c_p3h >= '5'
   n_nr5_sum = n_nr5_sum + 1
ENDIF
IF c_p3e >= '5'
   n_nr5_sum = n_nr5_sum + 1
ENDIF
IF c_p3i >= '5'
   n_nr5_sum = n_nr5_sum + 1
ENDIF

*-------------------------------
*Determine n_nr2_sum.
*   n_nr2_sum is the number of types of nursing rehab activities provided
*   at least 2 days per week.

n_nr2_sum = 0
IF c_p3a >= '2'
   n_nr2_sum = n_nr2_sum + 1
ENDIF
IF c_p3b >= '2'
   n_nr2_sum = n_nr2_sum + 1
ENDIF
IF c_p3c >= '2'
   n_nr2_sum = n_nr2_sum + 1
ENDIF
IF (c_p3f >= '2' .OR. c_p3d >= '2')
   n_nr2_sum = n_nr2_sum + 1
ENDIF
IF c_p3g >= '2'
   n_nr2_sum = n_nr2_sum + 1
ENDIF
IF c_p3h >= '2'
   n_nr2_sum = n_nr2_sum + 1
ENDIF
IF c_p3e >= '2'
   n_nr2_sum = n_nr2_sum + 1
ENDIF
IF c_p3i >= '2'
   n_nr2_sum = n_nr2_sum + 1
ENDIF

*++++++++++++++++++++++++++++++++++++++++
*Step IV.  Test Rehab group hierarchy membership.
*          Rehab groups are separated by several factors: Total minutes
*          of Rehab therapy, Number of types of therapy, and number of types
*          of nursing rehab activities (lowest rehab group).
*
* There are two different Rehab classification algorithms used in this 
* version, STANDARD and SPECIAL MEDICARE  
*
* The SPECIAL MEDICARE algorithm is employed if BOTH:
*    (1) The calculation method selected is Medicare (i.e., the
*        parameter c_type = 'Mcare') 
*    (2) The reason for assessments involves a supplemental assessment 
*        type of "5 day assessment" (AA8b = '1') OR "readmission assessment"
*        (AA8b = '5').
*
* The STANDARD algorithm is employed in all other cases.

*-------------------------------
*Classify residents into four Rehab hierarcy groups.

*-------------------------------
* Determine Very High Intensity Rehab membership.

* l_reh_vh indicates very high rehab group membership (set to false).
l_reh_vh = .F. 

IF ((c_aa8b = '1' .OR. c_aa8b = '5') .AND. c_type = 'Mcare')
   *Use SPECIAL MEDICARE algorithm.

   IF (c_t1b = '1' .AND. VAL(c_t1c) >= 8 .AND. VAL(c_t1d) >= 720 .AND. ;
       n_ther_typ >= 2 .AND. n_ther_dys >= 2 .AND. n_ther_min >= 90)

*         *Resident qualifies for Very High Intensity Rehab group, group 1.
          l_reh_vh = .T.

   ENDIF

ELSE
   *Use STANDARD algorithm.
 
   IF ( (n_ther_min >= 450 .AND. n_ther_typ >= 2) ;
        .AND. ;
        (VAL(c_p1baa) >= 5 .OR. VAL(c_p1bba) >= 5 .OR. VAL(c_p1bca) >= 5)  )

*          *Resident qualifies for Very High Intensity Rehab group, group 1.
           l_reh_vh = .T.

   ENDIF

ENDIF

*Determine final splits for Very High Intensity Rehab residents
*   on the basis of ADL sum.
IF l_reh_vh
   IF     (14 <= n_adlsum .AND. n_adlsum <= 18)
             c_m3 = 'RVC'
             n_cmi_high = n_cmi[1]                    
   ELSEIF (08 <= n_adlsum .AND. n_adlsum <= 13)
             c_m3 = 'RVB'
             n_cmi_high = n_cmi[2]                    
   ELSEIF (04 <= n_adlsum .AND. n_adlsum <= 07)
             c_m3 = 'RVA'
             n_cmi_high = n_cmi[3]                    
   ENDIF

*  *Return (end calculation) if hierarchical method
   IF c_type = 'Hier'
      RETURN
   ENDIF

ENDIF

*-------------------------------
* Determine High Intensity Rehab membership.

* l_reh_hi indicates high rehab group membership (set to false).
l_reh_hi = .F. 

IF ((c_aa8b = '1' .OR. c_aa8b = '5') .AND. c_type = 'Mcare')
   *Use SPECIAL MEDICARE algorithm.

   IF (c_t1b = '1' .AND. VAL(c_t1c) >= 8 .AND. VAL(c_t1d) >= 480 .AND. ;
       n_ther_dys >= 2 .AND. n_ther_min >= 60)

*         *Resident qualifies for High Intensity Rehab group.
          l_reh_hi= .T.

   ENDIF

ELSE
   *Use STANDARD algorithm.

   IF ( n_ther_min >= 300 ;
       .AND. ;
       (VAL(c_p1baa) >= 5 .OR. VAL(c_p1bba) >= 5 .OR. VAL(c_p1bca) >= 5) )

*          *Resident qualifies for High Intensity Rehab group.
          l_reh_hi= .T.

   ENDIF

ENDIF 

*Determine final splits for High Intensity Rehab residents
*  on the basis of ADL sum.
IF l_reh_hi
   IF     (15 <= n_adlsum .AND. n_adlsum <= 18)
          IF n_cmi[4] > n_cmi_high
*            *Accept RHD group since index is higher than previous high.
             c_m3 = 'RHD'
             n_cmi_high = n_cmi[4]                    
          ENDIF
   ELSEIF (12 <= n_adlsum .AND. n_adlsum <= 14)
          IF n_cmi[5] > n_cmi_high
*            *Accept RHC group since index is higher than previous high.
             c_m3 = 'RHC'
             n_cmi_high = n_cmi[5]                    
          ENDIF
   ELSEIF (08 <= n_adlsum .AND. n_adlsum <= 11)
          IF n_cmi[6] > n_cmi_high
*            *Accept RHB group since index is higher than previous high.
             c_m3 = 'RHB'
             n_cmi_high = n_cmi[6]                    
          ENDIF
   ELSEIF (04 <= n_adlsum .AND. n_adlsum <= 07)
          IF n_cmi[7] > n_cmi_high
*            *Accept RHA group since index is higher than previous high.
             c_m3 = 'RHA'
             n_cmi_high = n_cmi[7]                    
          ENDIF
   ENDIF

*  *Return (end calculation) if hierarchical method
   IF c_type = 'Hier' 
      RETURN
   ENDIF

ENDIF

*-------------------------------
* Determine Medium Intensity Rehab membership.

* l_reh_md indicates medium rehab group membership (set to false).
l_reh_md = .F. 

IF ((c_aa8b = '1' .OR. c_aa8b = '5') .AND. c_type = 'Mcare')
   *Use SPECIAL MEDICARE algorithm.

   IF (c_t1b = '1' .AND. VAL(c_t1c) >= 8 .AND. VAL(c_t1d) >= 240)

*         *Resident qualifies for Medium Intensity Rehab group.
          l_reh_md= .T.

   ENDIF

ELSE
   *Use STANDARD algorithm.

   IF ( n_ther_min >= 150 .AND. n_ther_dys >= 5 )  

*         *Resident qualifies for Medium Intensity Rehab group.
          l_reh_md= .T.

   ENDIF

ENDIF

*Determine final splits for Medium Intensity Rehab residents
*   on the basis of ADL sum.
IF l_reh_md
   IF     (16 <= n_adlsum .AND. n_adlsum <= 18)
          IF n_cmi[8] > n_cmi_high
*            *Accept RMC group since index is higher than previous high.
             c_m3 = 'RMC'
             n_cmi_high = n_cmi[8]                    
          ENDIF
   ELSEIF (08 <= n_adlsum .AND. n_adlsum <= 15)
          IF n_cmi[9] > n_cmi_high
*            *Accept RMB group since index is higher than previous high.
             c_m3 = 'RMB'
             n_cmi_high = n_cmi[9]                    
          ENDIF
   ELSEIF (04 <= n_adlsum .AND. n_adlsum <= 07)
          IF n_cmi[10] > n_cmi_high
*            *Accept RMA group since index is higher than previous high.
             c_m3 = 'RMA'
             n_cmi_high = n_cmi[10]                    
          ENDIF
   ENDIF

   *Return (end calculation) if hierarchical method
   IF c_type = 'Hier' 
      RETURN
   ENDIF

ENDIF

*-------------------------------
* Determine Low Intensity Rehab membership.

* l_reh_lo indicates low rehab group membership (set to false).
l_reh_lo = .F. 

IF ((c_aa8b = '1' .OR. c_aa8b = '5') .AND. c_type = 'Mcare')
   *Use SPECIAL MEDICARE algorithm.

   IF (c_t1b = '1' .AND. VAL(c_t1c) >= 5 .AND. VAL(c_t1d) >= 75 ;
       .AND. n_nr2_sum >= 2)

*         *Resident qualifies for Medium Intensity Rehab group.
          l_reh_lo= .T.

   ENDIF

ELSE
   *Use STANDARD algorithm.


   IF ( n_ther_min >= 45 .AND. n_nr5_sum >= 2 .AND. n_ther_dys >= 3 )

*         *Resident qualifies for Low Intensity Rehab group.
          l_reh_lo= .T.

   ENDIF

ENDIF

*Determine final splits for Low Intensity Rehab residents
*   on the basis of ADL sum.
IF l_reh_lo
   IF     (12 <= n_adlsum .AND. n_adlsum <= 18)
          IF n_cmi[11] > n_cmi_high
*            *Accept RLB group since index is higher than previous high.
             c_m3 = 'RLB'
             n_cmi_high = n_cmi[11]                    
          ENDIF
   ELSEIF (04 <= n_adlsum .AND. n_adlsum <= 11)
          IF n_cmi[12] > n_cmi_high
*            *Accept RMC group since index is higher than previous high.
             c_m3 = 'RLA'
             n_cmi_high = n_cmi[12]                    
          ENDIF
   ENDIF

*  *Return (end calculation) if hierarchical method
   IF c_type = 'Hier' 
      RETURN
   ENDIF

ENDIF

*++++++++++++++++++++++++++++++++++++++++
*Step V.  Test Extensive and Special Care hierarchy membership.

*To qualify for Extensive or Special care a resident must have
*    required clinical indicators plus an ADL sum of 7 or more.
*    Residents who have the required clinical indicators but too
*    low an ADL score are classified as Clinically Complex rather
*    than Extensive or Special care.
*The flag, l_complex, identifies a resident who has Extensive or
*    Special Care clinical indicators.  This flag will later be
*    used to qualify these residents for a Clinically Complex group.

*Set l_complex to false.
l_complex = .F.

*Test for P-feed, Suct, Trache, Vent/resp.--for Extensive.
IF (c_k5a = '1' .OR. c_p1ai = '1' .OR. c_p1aj = '1' .OR. c_p1al = '1')

*  *Set l_complex to true.
   l_complex = .T.

*  *Sum the number of extensive treatments and then determine
*   *   final splits for Extensive Care on the basis of the
*   *   number of extensive treatments (minimum of 1) and ADL sum.
*  *Note that Extensive classification requires an ADL sum >= 7.
   n_ext_trt = VAL(c_k5a) + VAL(c_p1ai) + VAL(c_p1aj) + VAL(c_p1al)
   IF     n_ext_trt >= 3 .AND. n_adlsum > 6
*         *Resident qualifies for the SE3 group.

          IF n_cmi[13] > n_cmi_high
*            *Accept SE3 group since index is higher than previous high.
             c_m3 = 'SE3'
             n_cmi_high = n_cmi[13]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

   ELSEIF n_ext_trt =  2 .AND. n_adlsum > 6
*         *Resident qualifies for the SE2 group.

          IF n_cmi[14] > n_cmi_high
*            *Accept SE2 group since index is higher than previous high.
             c_m3 = 'SE2'
             n_cmi_high = n_cmi[14]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

   ELSEIF n_ext_trt =  1 .AND. n_adlsum > 6
*         *Resident qualifies for the SE1 group.

          IF n_cmi[15] > n_cmi_high
             * accept SE1 group since index is higher than previous high
             c_m3 = 'SE1'
             n_cmi_high = n_cmi[15]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

   ENDIF

*Test for Burns, Coma, # of Ulcers at stage 3,4, etc.--for Special.
ELSEIF (c_m4b = '1' ;
        .OR. (c_b1 =  '1' .AND. c_n1d = '1' .AND. ;
              (c_g1aa = '4' .OR. c_g1aa = '8') .AND.;
              (c_g1ba = '4' .OR. c_g1ba = '8') .AND.;
              (c_g1ha = '4' .OR. c_g1ha = '8') .AND.;
              (c_g1ia = '4' .OR. c_g1ia = '8')) ;
        .OR. (c_j1h = '1' .AND. (c_j1o = '1' .OR. c_k3a = '1' .OR. ;
              c_i2e = '1' .OR. c_j1c = '1')) ;
        .OR. c_i1w = '1' ;
        .OR. (c_m2a = '3' .OR. c_m2a = '4') ;
        .OR. c_i1z = '1' .OR. c_i2g = '1' .OR. c_p1ac = '1' ;
        .OR. c_p1ah = '1' .OR. c_k5b = '1')

*  *Set l_complex to true.
   l_complex = .T.

*  *Determine final splits for Special care on the basis of ADL sum.
*  *Note that Extensive classification requires an ADL sum >= 7.
   IF     (17 <= n_adlsum .AND. n_adlsum <= 18)
*         *Resident qualifies for the SSC group.

          IF n_cmi[16] > n_cmi_high
             * accept SSC group since index is higher than previous high
             c_m3 = 'SSC'
             n_cmi_high = n_cmi[16]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

   ELSEIF (14 <= n_adlsum .AND. n_adlsum <= 16)
*         *Resident qualifies for the SSB group.

          IF n_cmi[17] > n_cmi_high
             * accept SSB group since index is higher than previous high
             c_m3 = 'SSB'
             n_cmi_high = n_cmi[17]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

   ELSEIF (07 <= n_adlsum .AND. n_adlsum <= 13)
*         *Resident qualifies for the SSA group.

          IF n_cmi[18] > n_cmi_high
             * accept SSA group since index is higher than previous high
             c_m3 = 'SSA'
             n_cmi_high = n_cmi[18]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

   ENDIF

ENDIF


*++++++++++++++++++++++++++++++++++++++++
*Step VI.   Determine depression variables needed for Clinically Complex
*           Classification.
*           Depression variables needed are:
*              - Amount of time awake (n_awk_cnt)
*              - Number of depression symptoms (n_sad_cnt)
*              - Whether the resident is defined as depressed or not (l_sad)

*-------------------------------
*Determine the amount of time awake (n_awk_cnt)--used in defining
*   number of depression symptoms.
n_awk_cnt=0
IF c_n1a = '1'
   n_awk_cnt = n_awk_cnt + 1
ENDIF
IF c_n1b = '1'
   n_awk_cnt = n_awk_cnt + 1
ENDIF
IF c_n1c = '1'
   n_awk_cnt = n_awk_cnt + 1
ENDIF

*-------------------------------
*Determine number of depression symptoms (n_sad_cnt).
n_sad_cnt = 0
IF (c_e1a = '1' .OR. c_e1a = '2')
       n_sad_cnt = n_sad_cnt + 1
ENDIF
IF (c_e1n = '1' .OR. c_e1n = '2' .OR. (c_e4ea >= '1' .AND. c_e4ea <= '3') ;
    .OR. c_e1o = '1' .OR. c_e1o = '2' .OR. c_e1p = '1' .OR. c_e1p = '2')
       n_sad_cnt = n_sad_cnt + 1
ENDIF
IF (c_e1j = '1' .OR. c_e1j = '2' .OR. c_n1d = '1' .OR. ;
    (n_awk_cnt <= 1 .AND. c_b1 <> '1'))
       n_sad_cnt = n_sad_cnt + 1
ENDIF
IF (c_e1g = '1' .OR. c_e1g = '2')
       n_sad_cnt = n_sad_cnt + 1
ENDIF
IF (c_k3a = '1')
       n_sad_cnt = n_sad_cnt + 1
ENDIF

*-------------------------------
*Determine whether resident is depressed (l_sad = .T.)
*   or not (l_sad = .F.)
l_sad = .F.
IF     ((c_e2 = '1' .OR. c_e2 = '2') .AND. n_sad_cnt >= 2)
       l_sad = .T.
ELSEIF ((c_i1ee = '1' .OR. c_i1ff = '1') .AND. n_sad_cnt >= 1)
       l_sad = .T.
ELSEIF ((c_i1ee = '1' .OR. c_i1ff = '1') .AND. (c_e2 = '1' .OR. c_e2 = '2'))
       l_sad = .T.
ENDIF


*++++++++++++++++++++++++++++++++++++++++
*Step VII. Test Clinically Complex hierarchy membership.

*  *Test for Extensive or Special Care clinical indicators with
*  *   low ADL sum, Aphasia, Aspirations, CP, Dehyd, Hemip, etc.
IF l_complex ;
   .OR. c_i1r = '1' .OR. c_j1k = '1' .OR. c_i1s = '1'  ;
   .OR. c_j1c = '1' .OR. c_i1v = '1' ;
   .OR. c_j1j = '1' .OR. c_i2e = '1' .OR. VAL(c_m2b) > 0 .OR. c_j5c = '1' ;
   .OR. c_i2j = '1' .OR. c_p1aa ='1' .OR. c_p1ab = '1' ;
   .OR. VAL(c_p8) >= 4 ;
   .OR. c_p1bda >= '1';
   .OR. c_p1ak = '1' ;
   .OR. c_p1ag = '1' ;
   .OR. (c_m4g = '1' .AND. c_m5f = '1') ;
   .OR. ((c_m4f = '1' .OR. c_m4c = '1') ;
         .AND. (c_m6f = '1' .OR. c_m5i = '1'))

*     *Determine final splits for Clinically Complex based on ADL sum
*     *    and depression.
      IF     (17 <= n_adlsum .AND. n_adlsum <= 18 .AND. l_sad)
*         *Resident qualifies for the CD2 group.

          IF n_cmi[19] > n_cmi_high
             * accept CD2 group since index is higher than previous high
             c_m3 = 'CD2'
             n_cmi_high = n_cmi[19]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

      ELSEIF (17 <= n_adlsum .AND. n_adlsum <= 18)
*         *Note the condition l_sad being false is implied here.
*         *Resident qualifies for the CD1 group.

          IF n_cmi[20] > n_cmi_high
             * accept CD1 group since index is higher than previous high
             c_m3 = 'CD1'
             n_cmi_high = n_cmi[20]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

      ELSEIF (11 <= n_adlsum .AND. n_adlsum <= 16 .AND. l_sad)
*         *Resident qualifies for the CC2 group.

          IF n_cmi[21] > n_cmi_high
             * accept CC2 group since index is higher than previous high
             c_m3 = 'CC2'
             n_cmi_high = n_cmi[21]
          ENDIF

*         *Return (end calculation) if hierarchical  method
          IF c_type = 'Hier'
             RETURN
          ENDIF

      ELSEIF (11 <= n_adlsum .AND. n_adlsum <= 16)
*         *Note the condition l_sad being false is implied here.
*         *Resident qualifies for the CC1 group.

          IF n_cmi[22] > n_cmi_high
             * accept CC1 group since index is higher than previous high
             c_m3 = 'CC1'
             n_cmi_high = n_cmi[22]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

      ELSEIF (06 <= n_adlsum .AND. n_adlsum <= 10 .AND. l_sad)
*         *Resident qualifies for the CB2 group.

          IF n_cmi[23] > n_cmi_high
             * accept CB2 group since index is higher than previous high
             c_m3 = 'CB2'
             n_cmi_high = n_cmi[23]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

      ELSEIF (06 <= n_adlsum .AND. n_adlsum <= 10)
*         *Note the condition l_sad being false is implied here.
*         *Resident qualifies for the CB1 group.

          IF n_cmi[24] > n_cmi_high
             * accept CB1 group since index is higher than previous high
             c_m3 = 'CB1'
             n_cmi_high = n_cmi[24]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

      ELSEIF (04 <= n_adlsum .AND. n_adlsum <= 05 .AND. l_sad)
*         *Resident qualifies for the CA2 group.

          IF n_cmi[25] > n_cmi_high
             * accept CA2 group since index is higher than previous high
             c_m3 = 'CA2'
             n_cmi_high = n_cmi[25]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

     ELSEIF (04 <= n_adlsum .AND. n_adlsum <= 05)
*         *Note the condition l_sad being false is implied here.
*         *Resident qualifies for the CA1 group.

          IF n_cmi[26] > n_cmi_high
             * accept CA1 group since index is higher than previous high
             c_m3 = 'CA1'
             n_cmi_high = n_cmi[26]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

      ENDIF

ENDIF


*++++++++++++++++++++++++++++++++++++++++
*Step VIII. Determine Variable needed to determine final splits for
*           Impaired Cognitive/Behavior and Physical Function clinical
*           hierarchy groups:
*             - Number of nursing rehab activities including a toileting
*               program (n_nrtoil)
*Determine n_nrtoil.
*   nrtoil = nr5_sum if there is no scheduled toileting plan.
*   nrtoil = nr5_sum + 1 if there is any scheduled toileting plan.
n_nrtoil = n_nr5_sum
IF c_h3a = '1'
   n_nrtoil = n_nrtoil + 1
ENDIF


*++++++++++++++++++++++++++++++++++++++++
*Step IX. Test Cognitive Impairment hierarchy membership.

IF ('1' <= c_b4 .AND. c_b4 <= '3' ;
   .AND. (c_b3a <> '1' .OR. c_b3b <> '1' .OR. c_b3c <> '1' ;
          .OR. c_b3d <> '1') ;
   .AND. c_b2a = '1')

*      *Determine final splits for Impaired Cognitive group based on
*      *   ADl sum and nursing rehab including toileting program
*      *   (n_nrtoil).
*      *Note ADL sum must be 10 or less to qualify for Cognitive
*      *   Impairment group.
       IF     (06 <= n_adlsum .AND. n_adlsum <= 10 .AND. n_nrtoil >= 2)
*         *Resident qualifies for the IB2 group.

          IF n_cmi[27] > n_cmi_high
             * accept IB2 group since index is higher than previous high
             c_m3 = 'IB2'
             n_cmi_high = n_cmi[27]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

       ELSEIF (06 <= n_adlsum .AND. n_adlsum <= 10)
*         *The condition n_nrtoil < 2 is implied here.
*         *Resident qualifies for the IB1 group.

          IF n_cmi[28] > n_cmi_high
             * accept IB1 group since index is higher than previous high
             c_m3 = 'IB1'
             n_cmi_high = n_cmi[28]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

       ELSEIF (04 <= n_adlsum .AND. n_adlsum <= 05 .AND. n_nrtoil >= 2)
*         *Resident qualifies for the IA2 group.

          IF n_cmi[29] > n_cmi_high
             * accept IA2 group since index is higher than previous high
             c_m3 = 'IA2'
             n_cmi_high = n_cmi[29]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

       ELSEIF (04 <= n_adlsum .AND. n_adlsum <= 05)
*         *The condition n_nrtoil < 2 is implied here.
*         *Resident qualifies for the IA1 group.

          IF n_cmi[30] > n_cmi_high
             * accept IA1 group since index is higher than previous high
             c_m3 = 'IA1'
             n_cmi_high = n_cmi[30]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

       ENDIF

ENDIF


*++++++++++++++++++++++++++++++++++++++++
*Step X. Test Behavior Problems hierarchy membership.

IF c_e4da = '3' .OR. c_e4ca = '3' .OR. c_e4ba = '3' ;
   .OR. c_e4aa = '3' .OR.  c_j1i = '1' .OR. c_j1e = '1'

*      *Determine final splits for Behavior Problems based on
*      *   ADL sum and nursing rehab including toileting program
*      *   (n_nrtoil).
*      *Note ADL sum must be 10 or less to qualify for Behavior
*      *   Problems group.
       IF     (06 <= n_adlsum .AND. n_adlsum <= 10 .AND. n_nrtoil >= 2)
*         *Resident qualifies for the BB2 group.

          IF n_cmi[31] > n_cmi_high
             * accept BB2 group since index is higher than previous high
             c_m3 = 'BB2'
             n_cmi_high = n_cmi[31]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

       ELSEIF (06 <= n_adlsum .AND. n_adlsum <= 10)
*         *The condition n_nrtoil < 2 is implied here.
*         *Resident qualifies for the BB1 group.

          IF n_cmi[32] > n_cmi_high
             * accept BB1 group since index is higher than previous high
             c_m3 = 'BB1'
             n_cmi_high = n_cmi[32]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

       ELSEIF (04 <= n_adlsum .AND. n_adlsum <= 05 .AND. n_nrtoil >= 2)
*         *Resident qualifies for the BA2 group.

          IF n_cmi[33] > n_cmi_high
             * accept BA2 group since index is higher than previous high
             c_m3 = 'BA2'
             n_cmi_high = n_cmi[33]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

       ELSEIF (04 <= n_adlsum .AND. n_adlsum <= 05)
*         *The condition n_nrtoil < 2 is implied here.
*         *Resident qualifies for the BA1 group.

          IF n_cmi[34] > n_cmi_high
             * accept BA1 group since index is higher than previous high
             c_m3 = 'BA1'
             n_cmi_high = n_cmi[34]
          ENDIF

*         *Return (end calculation) if hierarchical method
          IF c_type = 'Hier'
             RETURN
          ENDIF

       ENDIF

ENDIF


*++++++++++++++++++++++++++++++++++++++++
*Step XI. Test Physical Function hierarchy membership.

*All remaining residents tested for Physical Function membership.

*Determine final splits for Physical Function based on ADL sum and
*   nursing rehab including toileting program (n_nrtoil).

IF     (16 <= n_adlsum .AND. n_adlsum <= 18 .AND. n_nrtoil >=2)
*  *Resident qualifies for the PE2 group.

          IF n_cmi[35] > n_cmi_high
             * accept PE2 group since index is higher than previous high
             c_m3 = 'PE2'
          ENDIF

ELSEIF (16 <= n_adlsum .AND. n_adlsum <= 18)
*  *The condition n_nrtoil < 2 is implied here.
*  *Resident qualifies for the PE1 group.

          IF n_cmi[36] > n_cmi_high
             * accept PE1 group since index is higher than previous high
             c_m3 = 'PE1'
          ENDIF

ELSEIF (11 <= n_adlsum .AND. n_adlsum <= 15 .AND. n_nrtoil >=2)
*  *Resident qualifies for the PD2 group.

          IF n_cmi[37] > n_cmi_high
             * accept PD2 group since index is higher than previous high
             c_m3 = 'PD2'
          ENDIF

ELSEIF (11 <= n_adlsum .AND. n_adlsum <= 15)
*  *The condition n_nrtoil < 2 is implied here.
*  *Resident qualifies for the PD1 group.

          IF n_cmi[38] > n_cmi_high
             * accept PD1 group since index is higher than previous high
             c_m3 = 'PD1'
          ENDIF

ELSEIF (09 <= n_adlsum .AND. n_adlsum <= 10 .AND. n_nrtoil >=2)
*  *Resident qualifies for the PC2 group.

          IF n_cmi[39] > n_cmi_high
             * accept PC2 group since index is higher than previous high
             c_m3 = 'PC2'
          ENDIF

ELSEIF (09 <= n_adlsum .AND. n_adlsum <= 10)
*  *The condition n_nrtoil < 2 is implied here.
*  *Resident qualifies for the PC1 group.

          IF n_cmi[40] > n_cmi_high
             * accept PC1 group since index is higher than previous high
             c_m3 = 'PC1'
          ENDIF

ELSEIF (06 <= n_adlsum .AND. n_adlsum <= 08 .AND. n_nrtoil >=2)
*  *Resident qualifies for the PB2 group.

          IF n_cmi[41] > n_cmi_high
             * accept PB2 group since index is higher than previous high
             c_m3 = 'PB2'
          ENDIF

ELSEIF (06 <= n_adlsum .AND. n_adlsum <= 08)
*  *The condition n_nrtoil < 2 is implied here.
*  *Resident qualifies for the PB1 group.

          IF n_cmi[42] > n_cmi_high
             * accept PB1 group since index is higher than previous high
             c_m3 = 'PB1'
          ENDIF

ELSEIF (04 <= n_adlsum .AND. n_adlsum <= 05 .AND. n_nrtoil >=2)
*  *Resident qualifies for the PA2 group.

          IF n_cmi[43] > n_cmi_high
             * accept PA2 group since index is higher than previous high
             c_m3 = 'PA2'
          ENDIF

ELSEIF (04 <= n_adlsum .AND. n_adlsum <= 05)
*  *The condition n_nrtoil < 2 is implied here.
*  *Resident qualifies for the PA1 group.
          IF n_cmi[44] > n_cmi_high
             * accept PA1 group since index is higher than previous high
             c_m3 = 'PA1'
          ENDIF

ENDIF

RETURN
