GMTSXAP ; SLC/KER - List Parameters/Precedence            ; 02/27/2002
 ;;2.7;Health Summary;**47,49**;Oct 20, 1995
 Q
 ;                          
 ; External References in GMTSXAP
 ;   DBIA  2343  $$ACTIVE^XUSER
 ;   DBIA 10026  ^DIR
 ;                          
EN ; Main Entry Point for Health Summary
 N GMTSUSR S GMTSUSR=+($G(DUZ)) D PREF Q
EN2(X) ; Entry Point for User
 N GMTSUSR S GMTSUSR=+($G(X)) D PREF Q
 ;                          
PREF ; Get Preference - Precedence
 N GMTSACT Q:'$L($$UNM^GMTSXAW3(+($G(GMTSUSR))))
 S GMTSACT=$$ACTIVE^XUSER(+GMTSUSR) D:+GMTSACT'>0 DP^GMTSXAP2(GMTSUSR)
 Q:+GMTSACT'>0  S X=$$PRE(GMTSUSR) D:$L(X) EDIT^GMTSXAP2(GMTSUSR,X) Q
 ;                                  
PRE(GMTSUSR) ; Precedence of Parameter Entities
 ;                          
 ;   Input    User, pointer to NEW PERSON file
 ;
 ;   Output   String of Selected Entity Abbreviations,
 ;            delimited by a semi-colon, and arranged in
 ;            the order they should be used.
 ;                          
 ;               Example:  USR;SYS;NAT
 ;                          
 ;             Use "User" defined Health Summary Types, 
 ;             "System" defined Health Summary Types and
 ;             "National" Health Summary Types in that order.
 ;                          
 N GMTSEL,GMTSORD,GMTS,GMTSDEF,GMTSEXIT,GMTSINC,GMTSIN,GMTSCPL,GMTSPRE
 S GMTSUSR=+($G(GMTSUSR)),GMTSEXIT=0 Q:'$L($$UNM^GMTSXAW3(+($G(GMTSUSR)))) ""
 W:+($G(GMTSUSR))'=.5 !,"CPRS Reports Tab, Health Summary Type List (Contents)",!
 W:+($G(GMTSUSR))=.5 !,"Site Default CPRS Reports Tab, Health Summary Type List (Contents)",!
 D INA S GMTSIN=0 F  S GMTSIN=$O(GMTSINC(GMTSIN)) Q:+GMTSIN=0  Q:+($G(GMTSEXIT))>0  D INC(GMTSINC(GMTSIN)) Q:+($G(GMTSEXIT))>0
 I +GMTSEXIT>0,$D(GMTSEL("@")) D ADEL^GMTSXAP2
 Q:+($G(GMTSEXIT))>0 "" S X="" I '$D(GMTSEL)!($O(GMTSEL(0))'>0) Q X
 I $D(GMTSEL),$O(GMTSEL(0))>0 D ORD
 I +GMTSEXIT>0,$D(GMTSORD("@")) D ADEL^GMTSXAP2
 S:+($G(GMTSEXIT))=0 X=$$CPL
 I +GMTSEXIT>0,$D(GMTSCPL("@")) D ADEL^GMTSXAP2
 Q X
 ; Include Health Summary Types
INA ;   Input Array (from Parameter File)
 N GMTSI,GMTST,GMTSA,GMTSN,GMTSP,GMTSH,GMTSC,GMTSALW D EN^GMTSXAW
 S (GMTSC,GMTSI)=0 F  S GMTSI=$O(GMTSALW(GMTSI)) Q:+GMTSI=0  D
 . S GMTST=$G(GMTSALW(GMTSI)) Q:'$L(GMTST)  S GMTSA=$P(GMTST,"^",1) Q:$L(GMTSA)'=3  S GMTSN=$P(GMTST,"^",4) Q:'$L(GMTSN)
 . ; Include User Preferred Health Summary Types:  (Y/N)
 . ; Include System Defined Health Summary Types:  (Y/N)
 . ; Group National Types together (Remote Data Views): (Y/N)
 . S GMTSP="Include "_GMTSN_" Defined Health Summary Types"
 . S GMTSH=GMTSN_" Level Health Summary Types"
 . S:GMTSA="USR" GMTSP="Include "_GMTSN_" Preferred Health Summary Types",GMTSH=GMTSN_" Preferred Health Summary Types"
 . S GMTSC=GMTSC+1,GMTSINC(GMTSC)=GMTSA_"^"_GMTSP_"^"_GMTSH
 S GMTSC=GMTSC+1,GMTSA="NAT",GMTSN="National"
 S GMTSP="Group "_GMTSN_" Types together (Remote Data View)"
 S GMTSH="Nationally Exported Health Summary Types"
 S GMTSINC(GMTSC)=GMTSA_"^"_GMTSP_"^"_GMTSH
 Q
INC(X) ;   Select Health Summary Types to Include
 Q:+($G(GMTSEXIT))>0  N Y,DIR,%,%P,DTOUT,DUOUT,DIRUT,DIROUT,GMTSI,GMTST,GMTSA,GMTSO S GMTST=$G(X)
 S GMTSA=$P(GMTST,"^",1),GMTSO=$P(GMTST,"^",3),GMTST=$P(GMTST,"^",2) Q:'$L(GMTST)  Q:GMTSA'?3U
 S GMTSI=+($O(GMTSDEF(" "),-1))+1,GMTSDEF(GMTSI)=GMTSA_"^"_GMTST_"^"_GMTSO
 S DIR(0)="YAO",DIR("A")="  "_GMTST_":" F  Q:$L(DIR("A"))>51  S DIR("A")=DIR("A")_" "
 S DIR("A")=DIR("A")_" (Y/N)  " S:$L(GMTSO) DIR("A")="  "_DIR("A")
 S DIR("B")="Y",DIR("?")="^D INH1^GMTSXAP",DIR("??")="^D INH2^GMTSXAP"
 S:DIR("A")["Group Nat" DIR("B")="N"
 D ^DIR I Y="",X="@" D
 . N GMTSD S GMTSD=$P($G(^GMT(142.98,+($G(GMTSUSR)),1)),"^",2)
 . S GMTSEXIT="1^"_$S($L(GMTSD):"",1:"exiting")
 . S Y="@" K GMTSEL S GMTSEL("@")=""
 S:Y["^"!($D(DUOUT))!($D(DIROUT)) GMTSEXIT="1^exiting"
 S:$D(DTOUT) GMTSEXIT="1^try later"
 I +($G(GMTSEXIT))>0 W $S($L($P(GMTSEXIT,"^",2)):"...",1:""),$P(GMTSEXIT,"^",2) Q
 I +Y>0 S GMTSI=+($O(GMTSEL(" "),-1))+1,GMTSEL(GMTSI)=GMTSA_"^"_GMTST_"^"_GMTSO
 Q
INH1 ;     Include Help - Single ?
 W !,"        Enter either 'Y' or 'N'" D INH3 Q
INH2 ;     Include Help - Double ??
 W !,"        Select specified groups of Health Summary Types to include in the"
 W !,"        Health Summary Types list on the CPRS Reports Tab.  Groups include:",!
 W !,"            USR   User Preferred Health Summary Types in the Parameters file"
 W !,"            SYS   System Defined Summary Types in the parameters file"
 W !,"            NAT   National Health Summary Types (Remote Data Views)" D INH3 Q
INH3 ;     Include Help - Prompt
 I $L($G(DIR("A"))),$G(DIR("A"))'["Include",$G(DIR("A"))=$G(%P) D
 . N GMTSL S GMTSL="            ",GMTSL=$S($G(DIR("A"))[GMTSL:"  ",1:"")
 . S (%P,DIR("A"))=GMTSL_"  Include "_$$TRIM^GMTSXA(DIR("A")," ",1)
 Q
 ;                              
ORD ; Order of Health Summaries in List
 N GMTSI,GMTST,GMTSC,GMTSCNT,GMTSTOT,GMTSREM,GMTSSO,GMTSNXT,GMTSNXC
 S (GMTSSO,GMTSCNT,GMTSI)=0,(GMTSTOT,GMTST)=$$SLT^GMTSXAP2
 ;   One Selected
 I GMTST=1 D  Q
 . S (GMTSI,GMTSC)=0 F  S GMTSI=$O(GMTSEL(GMTSI)) Q:+GMTSI=0  D
 . . S GMTST=$P($G(GMTSEL(GMTSI)),"^",1)
 . . S:GMTST?3U GMTSC=GMTSC+1,GMTSORD(GMTSC)=GMTSEL(GMTSI)
 ;   Multiple Selected
 W !!!," You have selected multiple Health Summary types to be listed on the CPRS",!," reports tab.  Now you must select the order in which you want these to",!," be displayed."
 F  Q:+($G(GMTSEXIT))>0  D SO Q:+($G(GMTSEXIT))>0  Q:'$D(GMTSEL)
 Q
SO ;   Select Order
 N GMTSI,GMTSC,GMTSMAX,GMTSREO S GMTSI=0,GMTSREM=$$SLT^GMTSXAP2
 S GMTSCNT=GMTSTOT-GMTSREM,GMTSNXT=GMTSCNT+1,GMTSSO=+($G(GMTSSO))+1
 S GMTSNXC=$S(GMTSNXT=1:(GMTSNXT_"st"),GMTSNXT=2:(GMTSNXT_"nd"),GMTSNXT=3:(GMTSNXT_"rd"),1:(GMTSNXT_"th"))
 I +GMTSREM=1 D  Q
 . S Y=+GMTSREM D SET
 W ! D:+($G(GMTSSO))=1 SOHD D SOL,REO S (GMTSC,GMTSI)=0
 S GMTSMAX=GMTSREM
 W ! N DIR,DTOUT,DUOUT,DIRUT,DIROUT,X,Y
 S DIR(0)="NAO^1:"_GMTSMAX_":0"
 S DIR("?")="^D SOH1^GMTSXAP"
 S DIR("??")="^D SOH2^GMTSXAP"
 S DIR("A")="         Select the "_GMTSNXC_" to be listed:  "
 K DIR("B") S:+($O(GMTSREO(0)))>0 DIR("B")=+($O(GMTSREO(0)))
 D ^DIR I Y="",X="@" D
 . N GMTSD S GMTSD=$P($G(^GMT(142.98,+($G(GMTSUSR)),1)),"^",2)
 . S GMTSEXIT="1^"_$S($L(GMTSD):"",1:"exiting")
 . S Y="@" K GMTSORD S GMTSORD("@")=""
 S:Y["^"!($D(DUOUT))!($D(DIROUT)) GMTSEXIT="1^exiting" S:$D(DTOUT) GMTSEXIT="1^try later"
 I +($G(GMTSEXIT))>0 W $S($L($P(GMTSEXIT,"^",2)):"...",1:""),$P(GMTSEXIT,"^",2) Q
 I +Y>0,+Y'>GMTSREM D SET
 Q
SOL ;     List - Included Health Summaries
 N GMTSC,GMTSI S (GMTSC,GMTSI)=0 F  S GMTSI=$O(GMTSEL(GMTSI)) Q:+GMTSI=0  D
 . S GMTSC=GMTSC+1 W !,?9,$J(GMTSC,4),"  ",$P(GMTSEL(GMTSI),"^",3)
 Q
SOHD ;     Help Text
 W !,"    Order to Display Included Health Summary Types",! Q
SOH1 ;     Help - Single ?
 N GMTSC,GMTSI,GMTSN,GMTSCT S (GMTSC,GMTSI)=0,GMTSCT=+($G(GMTSNXT)) F  S GMTSI=$O(GMTSEL(GMTSI)) Q:+GMTSI=0  S GMTSC=GMTSC+1
 S GMTSN=$S(GMTSCT=1:"first",GMTSCT=2:"second",GMTSCT=3:"third",GMTSCT=4:"fourth",GMTSCT=5:"fifty",GMTSCT=6:"sixth",GMTSCT=7:"seventh",GMTSCT=8:"eighth",GMTSCT=9:"nineth",1:"")
 I '$L(GMTSN),+GMTSC>1 W !,?9,"Select a group of Health Summary Types to list (1-",GMTSC,")",!
 I $L(GMTSN),+GMTSC>1 W !,?9,"Select a group of Health Summary Types to list ",GMTSN," (1-",GMTSC,")",!
 D SOL
 Q
SOH2 ;     Help - Double ??
 W !,"         You have included multiple Health Summary types to be"
 W !,"         listed on the CPRS reports tab, Health Summary Types box."
 W !,"         Now you must select the order in which you want these"
 W !,"         to be listed.",!
 D SOL
 Q
 ;                                 
 ; Arrange
SET ;   Set Order
 D REO N GMTSO S GMTSO=+($O(GMTSORD(" "),-1))+1
 S:$L($G(GMTSREO(+$G(Y)))) GMTSORD(GMTSO)=$G(GMTSREO(+Y))
 S (GMTSC,GMTSI)=0
 F  S GMTSI=$O(GMTSEL(GMTSI)) Q:+GMTSI=0  D
 . S GMTSC=GMTSC+1 I GMTSC=+Y K GMTSEL(GMTSI),GMTSREO(GMTSC)
 Q
REO ;   Re-order
 K GMTSREO N GMTSC,GMTSI S (GMTSC,GMTSI)=0
 F  S GMTSI=$O(GMTSEL(GMTSI)) Q:+GMTSI=0  D
 . S GMTSC=GMTSC+1 S GMTSREO(GMTSC)=$G(GMTSEL(GMTSI))
 Q
CPL(X) ;   Compile Order
 Q:+($G(GMTSEXIT))>0 ""
 N GMTSI,GMTSA,GMTSOK,GMTSNEW S X="",GMTSI=0
 F  S GMTSI=$O(GMTSORD(GMTSI)) Q:+GMTSI=0  D
 . S GMTSA=$$UP^GMTSXA($P($G(GMTSORD(GMTSI)),"^",1))
 . S:GMTSA?3U X=$G(X)_";"_GMTSA
 S (GMTSNEW,X)=$$TRIM^GMTSXA(X,";",3)
 S GMTSOK=$$OK^GMTSXAP2 Q:GMTSOK'>0 ""
 Q X
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HGMTSXAP   8498     printed  Sep 23, 2025@19:36:54                                                                                                                                                                                                     Page 2
GMTSXAP   ; SLC/KER - List Parameters/Precedence            ; 02/27/2002
 +1       ;;2.7;Health Summary;**47,49**;Oct 20, 1995
 +2        QUIT 
 +3       ;                          
 +4       ; External References in GMTSXAP
 +5       ;   DBIA  2343  $$ACTIVE^XUSER
 +6       ;   DBIA 10026  ^DIR
 +7       ;                          
EN        ; Main Entry Point for Health Summary
 +1        NEW GMTSUSR
           SET GMTSUSR=+($GET(DUZ))
           DO PREF
           QUIT 
EN2(X)    ; Entry Point for User
 +1        NEW GMTSUSR
           SET GMTSUSR=+($GET(X))
           DO PREF
           QUIT 
 +2       ;                          
PREF      ; Get Preference - Precedence
 +1        NEW GMTSACT
           if '$LENGTH($$UNM^GMTSXAW3(+($GET(GMTSUSR))))
               QUIT 
 +2        SET GMTSACT=$$ACTIVE^XUSER(+GMTSUSR)
           if +GMTSACT'>0
               DO DP^GMTSXAP2(GMTSUSR)
 +3        if +GMTSACT'>0
               QUIT 
           SET X=$$PRE(GMTSUSR)
           if $LENGTH(X)
               DO EDIT^GMTSXAP2(GMTSUSR,X)
           QUIT 
 +4       ;                                  
PRE(GMTSUSR) ; Precedence of Parameter Entities
 +1       ;                          
 +2       ;   Input    User, pointer to NEW PERSON file
 +3       ;
 +4       ;   Output   String of Selected Entity Abbreviations,
 +5       ;            delimited by a semi-colon, and arranged in
 +6       ;            the order they should be used.
 +7       ;                          
 +8       ;               Example:  USR;SYS;NAT
 +9       ;                          
 +10      ;             Use "User" defined Health Summary Types, 
 +11      ;             "System" defined Health Summary Types and
 +12      ;             "National" Health Summary Types in that order.
 +13      ;                          
 +14       NEW GMTSEL,GMTSORD,GMTS,GMTSDEF,GMTSEXIT,GMTSINC,GMTSIN,GMTSCPL,GMTSPRE
 +15       SET GMTSUSR=+($GET(GMTSUSR))
           SET GMTSEXIT=0
           if '$LENGTH($$UNM^GMTSXAW3(+($GET(GMTSUSR))))
               QUIT ""
 +16       if +($GET(GMTSUSR))'=.5
               WRITE !,"CPRS Reports Tab, Health Summary Type List (Contents)",!
 +17       if +($GET(GMTSUSR))=.5
               WRITE !,"Site Default CPRS Reports Tab, Health Summary Type List (Contents)",!
 +18       DO INA
           SET GMTSIN=0
           FOR 
               SET GMTSIN=$ORDER(GMTSINC(GMTSIN))
               if +GMTSIN=0
                   QUIT 
               if +($GET(GMTSEXIT))>0
                   QUIT 
               DO INC(GMTSINC(GMTSIN))
               if +($GET(GMTSEXIT))>0
                   QUIT 
 +19       IF +GMTSEXIT>0
               IF $DATA(GMTSEL("@"))
                   DO ADEL^GMTSXAP2
 +20       if +($GET(GMTSEXIT))>0
               QUIT ""
           SET X=""
           IF '$DATA(GMTSEL)!($ORDER(GMTSEL(0))'>0)
               QUIT X
 +21       IF $DATA(GMTSEL)
               IF $ORDER(GMTSEL(0))>0
                   DO ORD
 +22       IF +GMTSEXIT>0
               IF $DATA(GMTSORD("@"))
                   DO ADEL^GMTSXAP2
 +23       if +($GET(GMTSEXIT))=0
               SET X=$$CPL
 +24       IF +GMTSEXIT>0
               IF $DATA(GMTSCPL("@"))
                   DO ADEL^GMTSXAP2
 +25       QUIT X
 +26      ; Include Health Summary Types
INA       ;   Input Array (from Parameter File)
 +1        NEW GMTSI,GMTST,GMTSA,GMTSN,GMTSP,GMTSH,GMTSC,GMTSALW
           DO EN^GMTSXAW
 +2        SET (GMTSC,GMTSI)=0
           FOR 
               SET GMTSI=$ORDER(GMTSALW(GMTSI))
               if +GMTSI=0
                   QUIT 
               Begin DoDot:1
 +3                SET GMTST=$GET(GMTSALW(GMTSI))
                   if '$LENGTH(GMTST)
                       QUIT 
                   SET GMTSA=$PIECE(GMTST,"^",1)
                   if $LENGTH(GMTSA)'=3
                       QUIT 
                   SET GMTSN=$PIECE(GMTST,"^",4)
                   if '$LENGTH(GMTSN)
                       QUIT 
 +4       ; Include User Preferred Health Summary Types:  (Y/N)
 +5       ; Include System Defined Health Summary Types:  (Y/N)
 +6       ; Group National Types together (Remote Data Views): (Y/N)
 +7                SET GMTSP="Include "_GMTSN_" Defined Health Summary Types"
 +8                SET GMTSH=GMTSN_" Level Health Summary Types"
 +9                if GMTSA="USR"
                       SET GMTSP="Include "_GMTSN_" Preferred Health Summary Types"
                       SET GMTSH=GMTSN_" Preferred Health Summary Types"
 +10               SET GMTSC=GMTSC+1
                   SET GMTSINC(GMTSC)=GMTSA_"^"_GMTSP_"^"_GMTSH
               End DoDot:1
 +11       SET GMTSC=GMTSC+1
           SET GMTSA="NAT"
           SET GMTSN="National"
 +12       SET GMTSP="Group "_GMTSN_" Types together (Remote Data View)"
 +13       SET GMTSH="Nationally Exported Health Summary Types"
 +14       SET GMTSINC(GMTSC)=GMTSA_"^"_GMTSP_"^"_GMTSH
 +15       QUIT 
INC(X)    ;   Select Health Summary Types to Include
 +1        if +($GET(GMTSEXIT))>0
               QUIT 
           NEW Y,DIR,%,%P,DTOUT,DUOUT,DIRUT,DIROUT,GMTSI,GMTST,GMTSA,GMTSO
           SET GMTST=$GET(X)
 +2        SET GMTSA=$PIECE(GMTST,"^",1)
           SET GMTSO=$PIECE(GMTST,"^",3)
           SET GMTST=$PIECE(GMTST,"^",2)
           if '$LENGTH(GMTST)
               QUIT 
           if GMTSA'?3U
               QUIT 
 +3        SET GMTSI=+($ORDER(GMTSDEF(" "),-1))+1
           SET GMTSDEF(GMTSI)=GMTSA_"^"_GMTST_"^"_GMTSO
 +4        SET DIR(0)="YAO"
           SET DIR("A")="  "_GMTST_":"
           FOR 
               if $LENGTH(DIR("A"))>51
                   QUIT 
               SET DIR("A")=DIR("A")_" "
 +5        SET DIR("A")=DIR("A")_" (Y/N)  "
           if $LENGTH(GMTSO)
               SET DIR("A")="  "_DIR("A")
 +6        SET DIR("B")="Y"
           SET DIR("?")="^D INH1^GMTSXAP"
           SET DIR("??")="^D INH2^GMTSXAP"
 +7        if DIR("A")["Group Nat"
               SET DIR("B")="N"
 +8        DO ^DIR
           IF Y=""
               IF X="@"
                   Begin DoDot:1
 +9                    NEW GMTSD
                       SET GMTSD=$PIECE($GET(^GMT(142.98,+($GET(GMTSUSR)),1)),"^",2)
 +10                   SET GMTSEXIT="1^"_$SELECT($LENGTH(GMTSD):"",1:"exiting")
 +11                   SET Y="@"
                       KILL GMTSEL
                       SET GMTSEL("@")=""
                   End DoDot:1
 +12       if Y["^"!($DATA(DUOUT))!($DATA(DIROUT))
               SET GMTSEXIT="1^exiting"
 +13       if $DATA(DTOUT)
               SET GMTSEXIT="1^try later"
 +14       IF +($GET(GMTSEXIT))>0
               WRITE $SELECT($LENGTH($PIECE(GMTSEXIT,"^",2)):"...",1:""),$PIECE(GMTSEXIT,"^",2)
               QUIT 
 +15       IF +Y>0
               SET GMTSI=+($ORDER(GMTSEL(" "),-1))+1
               SET GMTSEL(GMTSI)=GMTSA_"^"_GMTST_"^"_GMTSO
 +16       QUIT 
INH1      ;     Include Help - Single ?
 +1        WRITE !,"        Enter either 'Y' or 'N'"
           DO INH3
           QUIT 
INH2      ;     Include Help - Double ??
 +1        WRITE !,"        Select specified groups of Health Summary Types to include in the"
 +2        WRITE !,"        Health Summary Types list on the CPRS Reports Tab.  Groups include:",!
 +3        WRITE !,"            USR   User Preferred Health Summary Types in the Parameters file"
 +4        WRITE !,"            SYS   System Defined Summary Types in the parameters file"
 +5        WRITE !,"            NAT   National Health Summary Types (Remote Data Views)"
           DO INH3
           QUIT 
INH3      ;     Include Help - Prompt
 +1        IF $LENGTH($GET(DIR("A")))
               IF $GET(DIR("A"))'["Include"
                   IF $GET(DIR("A"))=$GET(%P)
                       Begin DoDot:1
 +2                        NEW GMTSL
                           SET GMTSL="            "
                           SET GMTSL=$SELECT($GET(DIR("A"))[GMTSL:"  ",1:"")
 +3                        SET (%P,DIR("A"))=GMTSL_"  Include "_$$TRIM^GMTSXA(DIR("A")," ",1)
                       End DoDot:1
 +4        QUIT 
 +5       ;                              
ORD       ; Order of Health Summaries in List
 +1        NEW GMTSI,GMTST,GMTSC,GMTSCNT,GMTSTOT,GMTSREM,GMTSSO,GMTSNXT,GMTSNXC
 +2        SET (GMTSSO,GMTSCNT,GMTSI)=0
           SET (GMTSTOT,GMTST)=$$SLT^GMTSXAP2
 +3       ;   One Selected
 +4        IF GMTST=1
               Begin DoDot:1
 +5                SET (GMTSI,GMTSC)=0
                   FOR 
                       SET GMTSI=$ORDER(GMTSEL(GMTSI))
                       if +GMTSI=0
                           QUIT 
                       Begin DoDot:2
 +6                        SET GMTST=$PIECE($GET(GMTSEL(GMTSI)),"^",1)
 +7                        if GMTST?3U
                               SET GMTSC=GMTSC+1
                               SET GMTSORD(GMTSC)=GMTSEL(GMTSI)
                       End DoDot:2
               End DoDot:1
               QUIT 
 +8       ;   Multiple Selected
 +9        WRITE !!!," You have selected multiple Health Summary types to be listed on the CPRS",!," reports tab.  Now you must select the order in which you want these to",!," be displayed."
 +10       FOR 
               if +($GET(GMTSEXIT))>0
                   QUIT 
               DO SO
               if +($GET(GMTSEXIT))>0
                   QUIT 
               if '$DATA(GMTSEL)
                   QUIT 
 +11       QUIT 
SO        ;   Select Order
 +1        NEW GMTSI,GMTSC,GMTSMAX,GMTSREO
           SET GMTSI=0
           SET GMTSREM=$$SLT^GMTSXAP2
 +2        SET GMTSCNT=GMTSTOT-GMTSREM
           SET GMTSNXT=GMTSCNT+1
           SET GMTSSO=+($GET(GMTSSO))+1
 +3        SET GMTSNXC=$SELECT(GMTSNXT=1:(GMTSNXT_"st"),GMTSNXT=2:(GMTSNXT_"nd"),GMTSNXT=3:(GMTSNXT_"rd"),1:(GMTSNXT_"th"))
 +4        IF +GMTSREM=1
               Begin DoDot:1
 +5                SET Y=+GMTSREM
                   DO SET
               End DoDot:1
               QUIT 
 +6        WRITE !
           if +($GET(GMTSSO))=1
               DO SOHD
           DO SOL
           DO REO
           SET (GMTSC,GMTSI)=0
 +7        SET GMTSMAX=GMTSREM
 +8        WRITE !
           NEW DIR,DTOUT,DUOUT,DIRUT,DIROUT,X,Y
 +9        SET DIR(0)="NAO^1:"_GMTSMAX_":0"
 +10       SET DIR("?")="^D SOH1^GMTSXAP"
 +11       SET DIR("??")="^D SOH2^GMTSXAP"
 +12       SET DIR("A")="         Select the "_GMTSNXC_" to be listed:  "
 +13       KILL DIR("B")
           if +($ORDER(GMTSREO(0)))>0
               SET DIR("B")=+($ORDER(GMTSREO(0)))
 +14       DO ^DIR
           IF Y=""
               IF X="@"
                   Begin DoDot:1
 +15                   NEW GMTSD
                       SET GMTSD=$PIECE($GET(^GMT(142.98,+($GET(GMTSUSR)),1)),"^",2)
 +16                   SET GMTSEXIT="1^"_$SELECT($LENGTH(GMTSD):"",1:"exiting")
 +17                   SET Y="@"
                       KILL GMTSORD
                       SET GMTSORD("@")=""
                   End DoDot:1
 +18       if Y["^"!($DATA(DUOUT))!($DATA(DIROUT))
               SET GMTSEXIT="1^exiting"
           if $DATA(DTOUT)
               SET GMTSEXIT="1^try later"
 +19       IF +($GET(GMTSEXIT))>0
               WRITE $SELECT($LENGTH($PIECE(GMTSEXIT,"^",2)):"...",1:""),$PIECE(GMTSEXIT,"^",2)
               QUIT 
 +20       IF +Y>0
               IF +Y'>GMTSREM
                   DO SET
 +21       QUIT 
SOL       ;     List - Included Health Summaries
 +1        NEW GMTSC,GMTSI
           SET (GMTSC,GMTSI)=0
           FOR 
               SET GMTSI=$ORDER(GMTSEL(GMTSI))
               if +GMTSI=0
                   QUIT 
               Begin DoDot:1
 +2                SET GMTSC=GMTSC+1
                   WRITE !,?9,$JUSTIFY(GMTSC,4),"  ",$PIECE(GMTSEL(GMTSI),"^",3)
               End DoDot:1
 +3        QUIT 
SOHD      ;     Help Text
 +1        WRITE !,"    Order to Display Included Health Summary Types",!
           QUIT 
SOH1      ;     Help - Single ?
 +1        NEW GMTSC,GMTSI,GMTSN,GMTSCT
           SET (GMTSC,GMTSI)=0
           SET GMTSCT=+($GET(GMTSNXT))
           FOR 
               SET GMTSI=$ORDER(GMTSEL(GMTSI))
               if +GMTSI=0
                   QUIT 
               SET GMTSC=GMTSC+1
 +2        SET GMTSN=$SELECT(GMTSCT=1:"first",GMTSCT=2:"second",GMTSCT=3:"third",GMTSCT=4:"fourth",GMTSCT=5:"fifty",GMTSCT=6:"sixth",GMTSCT=7:"seventh",GMTSCT=8:"eighth",GMTSCT=9:"nineth",1:"")
 +3        IF '$LENGTH(GMTSN)
               IF +GMTSC>1
                   WRITE !,?9,"Select a group of Health Summary Types to list (1-",GMTSC,")",!
 +4        IF $LENGTH(GMTSN)
               IF +GMTSC>1
                   WRITE !,?9,"Select a group of Health Summary Types to list ",GMTSN," (1-",GMTSC,")",!
 +5        DO SOL
 +6        QUIT 
SOH2      ;     Help - Double ??
 +1        WRITE !,"         You have included multiple Health Summary types to be"
 +2        WRITE !,"         listed on the CPRS reports tab, Health Summary Types box."
 +3        WRITE !,"         Now you must select the order in which you want these"
 +4        WRITE !,"         to be listed.",!
 +5        DO SOL
 +6        QUIT 
 +7       ;                                 
 +8       ; Arrange
SET       ;   Set Order
 +1        DO REO
           NEW GMTSO
           SET GMTSO=+($ORDER(GMTSORD(" "),-1))+1
 +2        if $LENGTH($GET(GMTSREO(+$GET(Y))))
               SET GMTSORD(GMTSO)=$GET(GMTSREO(+Y))
 +3        SET (GMTSC,GMTSI)=0
 +4        FOR 
               SET GMTSI=$ORDER(GMTSEL(GMTSI))
               if +GMTSI=0
                   QUIT 
               Begin DoDot:1
 +5                SET GMTSC=GMTSC+1
                   IF GMTSC=+Y
                       KILL GMTSEL(GMTSI),GMTSREO(GMTSC)
               End DoDot:1
 +6        QUIT 
REO       ;   Re-order
 +1        KILL GMTSREO
           NEW GMTSC,GMTSI
           SET (GMTSC,GMTSI)=0
 +2        FOR 
               SET GMTSI=$ORDER(GMTSEL(GMTSI))
               if +GMTSI=0
                   QUIT 
               Begin DoDot:1
 +3                SET GMTSC=GMTSC+1
                   SET GMTSREO(GMTSC)=$GET(GMTSEL(GMTSI))
               End DoDot:1
 +4        QUIT 
CPL(X)    ;   Compile Order
 +1        if +($GET(GMTSEXIT))>0
               QUIT ""
 +2        NEW GMTSI,GMTSA,GMTSOK,GMTSNEW
           SET X=""
           SET GMTSI=0
 +3        FOR 
               SET GMTSI=$ORDER(GMTSORD(GMTSI))
               if +GMTSI=0
                   QUIT 
               Begin DoDot:1
 +4                SET GMTSA=$$UP^GMTSXA($PIECE($GET(GMTSORD(GMTSI)),"^",1))
 +5                if GMTSA?3U
                       SET X=$GET(X)_";"_GMTSA
               End DoDot:1
 +6        SET (GMTSNEW,X)=$$TRIM^GMTSXA(X,";",3)
 +7        SET GMTSOK=$$OK^GMTSXAP2
           if GMTSOK'>0
               QUIT ""
 +8        QUIT X