DINIT125 ;SFISC/MKO-SORT TEMPLATE FILE ;1:13 PM  13 Nov 1998
 ;;22.2;VA FileMan;;Jan 05, 2016;Build 42
 ;;Per VA Directive 6402, this routine should not be modified.
 ;;Submitted to OSEHRA 5 January 2015 by the VISTA Expertise Network.
 ;;Based on Medsphere Systems Corporation's MSC FileMan 1051.
 ;;Licensed under the terms of the Apache License, Version 2.0.
 ;
 F I=1:2 S X=$T(Q+I) Q:X=""  S Y=$E($T(Q+I+1),4,999),X=$E(X,4,999) S:$A(Y)=126 I=I+1,Y=$E(Y,2,999)_$E($T(Q+I+1),5,99) S:$A(Y)=61 Y=$E(Y,2,999) S @X=Y
 G ^DINIT126
Q Q
 ;;^DD(.4014,14,21,1,0)
 ;;=Fields are assigned a probability rating based on the number of hits
 ;;^DD(.4014,14,21,2,0)
 ;;=found for the query (or sort) condition.  The probability rating is used
 ;;^DD(.4014,14,21,3,0)
 ;;=to determine the order in which query conditions should be executed
 ;;^DD(.4014,14,21,4,0)
 ;;=during the sort phase.  Fields with a higher probability rating are
 ;;^DD(.4014,14,21,5,0)
 ;;=executed first to most quickly cut down the number of records that have
 ;;^DD(.4014,14,21,6,0)
 ;;=to be processed.
 ;;^DD(.4014,14,23,0)
 ;;=^^1^1^2930125^
 ;;^DD(.4014,14,23,1,0)
 ;;=Calculated by a call to the FileMan Query Optimizer routine ^DIOQ.
 ;;^DD(.4014,14,"DT")
 ;;=2930125
 ;;^DD(.4014,15,0)
 ;;=DATA TYPE FOR SORTING^P.81'^DI(.81,^0;10^Q
 ;;^DD(.4014,15,21,0)
 ;;=^^5^5^2930514^
 ;;^DD(.4014,15,21,1,0)
 ;;=This pointer to the FileMan DATA TYPE file is entered automatically by
 ;;^DD(.4014,15,21,2,0)
 ;;=FileMan during the sort/print.  Note that if sorting by a pointer or a
 ;;^DD(.4014,15,21,3,0)
 ;;=variable pointer, FileMan will follow the pointer chain until it gets to
 ;;^DD(.4014,15,21,4,0)
 ;;=one of the other data types, in order to determine how to correctly set up
 ;;^DD(.4014,15,21,5,0)
 ;;=the sort logic.
 ;;^DD(.4014,15,23,0)
 ;;=^^1^1^2930514^
 ;;^DD(.4014,15,23,1,0)
 ;;=Pointer to DATA TYPE file, derived by FileMan in routine DTYP^DIP1.
 ;;^DD(.4014,15,"DT")
 ;;=2930514
 ;;^DD(.4014,16,0)
 ;;=COMPUTED FIELD CODE^K^^CM;E1,245^K:$L(X)>245 X D:$D(X) ^DIM
 ;;^DD(.4014,16,3)
 ;;=This is Standard MUMPS code, generated for sorting by computed fields or pointer fields.
 ;;^DD(.4014,16,9)
 ;;=@
 ;;^DD(.4014,16,21,0)
 ;;=^^3^3^2930201^
 ;;^DD(.4014,16,21,1,0)
 ;;=This field contains MUMPS code used to find the actual value of a field
 ;;^DD(.4014,16,21,2,0)
 ;;=that is computed or a pointer.  The code is generated by DICOMP.  This
 ;;^DD(.4014,16,21,3,0)
 ;;=code may execute code in OVERFLOW nodes as well.
 ;;^DD(.4014,16,23,0)
 ;;=^^1^1^2930201^
 ;;^DD(.4014,16,23,1,0)
 ;;=Generated by DICOMP.  Put into the DPP array in C^DIP0.
 ;;^DD(.4014,16,"DT")
 ;;=2930201
 ;;^DD(.4014,17,0)
 ;;=MULTIPLE FIELD DATA^.40141^^1;0
 ;;^DD(.4014,18,0)
 ;;=RELATIONAL JUMP FIELD DATA^.401418^^2;0
 ;;^DD(.4014,19,0)
 ;;=OVERFLOW DATA^.401419^^3;0
 ;;^DD(.4014,19,21,0)
 ;;=^^5^5^2930201^
 ;;^DD(.4014,19,21,1,0)
 ;;=This field contains the first subscript from the part of the DPP array
 ;;^DD(.4014,19,21,2,0)
 ;;=that contains overflow code executed when sorting by a field that is
 ;;^DD(.4014,19,21,3,0)
 ;;=gotten to relationally or a computed field.  Overflow code is generated
 ;;^DD(.4014,19,21,4,0)
 ;;=when needed by DICOMP.  This field will typically look something like
 ;;^DD(.4014,19,21,5,0)
 ;;="OVF0".
 ;;^DD(.4014,19,23,0)
 ;;=^^1^1^2930201^
 ;;^DD(.4014,19,23,1,0)
 ;;=Generated by DICOMP from DIP0 during the sort/print option.
 ;;^DD(.4014,19,"DT")
 ;;=2930201
 ;;^DD(.4014,20,0)
 ;;=SUBHEADER OUTPUT TRANSFORM^K^^OUT;E1,245^K:$L(X)>245 X D:$D(X) ^DIM
 ;;^DD(.4014,20,3)
 ;;=This is Standard MUMPS code.  This is used only when sorting by a user-specified cross-reference in input variable BY(0).
 ;;^DD(.4014,20,9)
 ;;=@
 ;;^DD(.4014,20,21,0)
 ;;=^^6^6^2930204^
 ;;^DD(.4014,20,21,1,0)
 ;;=Defined only when using the BY(0) input variable to the FileMan print,
 ;;^DD(.4014,20,21,2,0)
 ;;=EN1^DIP, which allows the user to specify a cross-reference to sort on.
 ;;^DD(.4014,20,21,3,0)
 ;;=The user is allowed to specify MUMPS code that can be used as an output
 ;;^DD(.4014,20,21,4,0)
 ;;=transform for any of the subheaders (i.e., subscripts in the
 ;;^DD(.4014,20,21,5,0)
 ;;=cross-reference) in the S input array.  This output transform code is
 ;;^DD(.4014,20,21,6,0)
 ;;=stored in this field.
 ;;^DD(.4014,20,23,0)
 ;;=^^4^4^2930204^
 ;;^DD(.4014,20,23,1,0)
 ;;=Stores output transform code from the third piece of S(0,N) where N is
 ;;^DD(.4014,20,23,2,0)
 ;;=the sort level.  This is an input array used in conjunction with BY(0)
 ;;^DD(.4014,20,23,3,0)
 ;;=when user specifies a specific cross-reference to use for the sort, in
 ;;^DD(.4014,20,23,4,0)
 ;;=in the FileMan print routine EN1^DIP.
 ;;^DD(.4014,20,"DT")
 ;;=2930204
 ;;^DD(.4014,21,0)
 ;;=TEXT SORT FLAG^S^SORT:SORT LIKE TEXT;RANGE:TREAT RANGE LIKE TEXT;^SRTTXT;1^Q
 ;;^DD(.4014,21,21,0)
 ;;=^^12^12^2931221^
 ;;^DD(.4014,21,21,1,0)
 ;;=This flag will be set in one of two cases.
 ;;^DD(.4014,21,21,2,0)
 ;;= 1) If the user entered the ;TXT qualifier, the flag will be set to
 ;;^DD(.4014,21,21,3,0)
 ;;="SORT", and will cause a space to be inserted at the beginning of each
 ;;^DD(.4014,21,21,4,0)
 ;;=sort value, causing even numeric fields to be sorted as if they were text.
 ;;^DD(.4014,21,21,5,0)
 ;;= 2) If the user entered a FROM or TO value that is a non-canonic number,
 ;;^DD(.4014,21,21,6,0)
 ;;=the flag will be set to RANGE, and will cause sort values that are numeric
 ;;^DD(.4014,21,21,7,0)
 ;;=to be treated as if they were text, when seeing whether they fall within
 ;;^DD(.4014,21,21,8,0)
 ;;=the from/to range.  However, they will still sort like numbers (MUMPS sort
 ;;^DD(.4014,21,21,9,0)
 ;;=sequence).
 ;;^DD(.4014,21,21,10,0)
 ;;= 
 ;;^DD(.4014,21,21,11,0)
 ;;=The flag is set automatically when the user is entering the sort fields in
 ;;^DD(.4014,21,21,12,0)
 ;;=^DIP, and the from/to values in ^DIP1.
 ;;^DD(.4014,21,"DT")
 ;;=2931221
 ;;^DD(.40141,0)
 ;;=MULTIPLE FIELD DATA SUB-FIELD^^1^2
 ;;^DD(.40141,0,"DT")
 ;;=2930201
 ;;^DD(.40141,0,"IX","B",.40141,.01)
 ;;=
 ;;^DD(.40141,0,"NM","MULTIPLE FIELD DATA")
 ;;=
 ;;^DD(.40141,0,"UP")
 ;;=.4014
 ;;^DD(.40141,.01,0)
 ;;=MULT.FILE OR SUBFILE NO.^MNJ13,5^^0;1^K:+X'=X!(X>9999999.99999)!(X<0)!(X?.E1"."6N.N) X
 ;;^DD(.40141,.01,1,0)
 ;;=^.1
 ;;^DD(.40141,.01,1,1,0)
 ;;=.40141^B
 ;;^DD(.40141,.01,1,1,1)
 ;;=S ^DIBT(DA(2),2,DA(1),1,"B",$E(X,1,30),DA)=""
 ;;^DD(.40141,.01,1,1,2)
 ;;=K ^DIBT(DA(2),2,DA(1),1,"B",$E(X,1,30),DA)
 ;;^DD(.40141,.01,3)
 ;;=Type a Number between 0 and 9999999.99999, 5 Decimal Digits.  This is the file/subfile number when sorting by a multiple field.
 ;;^DD(.40141,.01,21,0)
 ;;=^^4^4^2930201^
 ;;^DD(.40141,.01,21,1,0)
 ;;=All files or subfiles needed to get back up to the top level from a
 ;;^DD(.40141,.01,21,2,0)
 ;;=multiple field will be represented by an entry in this field.  The
 ;;^DD(.40141,.01,21,3,0)
 ;;=file or subfile number will be used as a subscript in the DPP array
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HDINIT125   7145     printed  Sep 23, 2025@20:26:48                                                                                                                                                                                                    Page 2
DINIT125  ;SFISC/MKO-SORT TEMPLATE FILE ;1:13 PM  13 Nov 1998
 +1       ;;22.2;VA FileMan;;Jan 05, 2016;Build 42
 +2       ;;Per VA Directive 6402, this routine should not be modified.
 +3       ;;Submitted to OSEHRA 5 January 2015 by the VISTA Expertise Network.
 +4       ;;Based on Medsphere Systems Corporation's MSC FileMan 1051.
 +5       ;;Licensed under the terms of the Apache License, Version 2.0.
 +6       ;
 +7        FOR I=1:2
               SET X=$TEXT(Q+I)
               if X=""
                   QUIT 
               SET Y=$EXTRACT($TEXT(Q+I+1),4,999)
               SET X=$EXTRACT(X,4,999)
               if $ASCII(Y)=126
                   SET I=I+1
                   SET Y=$EXTRACT(Y,2,999)_$EXTRACT($TEXT(Q+I+1),5,99)
               if $ASCII(Y)=61
                   SET Y=$EXTRACT(Y,2,999)
               SET @X=Y
 +8        GOTO ^DINIT126
Q          QUIT 
 +1       ;;^DD(.4014,14,21,1,0)
 +2       ;;=Fields are assigned a probability rating based on the number of hits
 +3       ;;^DD(.4014,14,21,2,0)
 +4       ;;=found for the query (or sort) condition.  The probability rating is used
 +5       ;;^DD(.4014,14,21,3,0)
 +6       ;;=to determine the order in which query conditions should be executed
 +7       ;;^DD(.4014,14,21,4,0)
 +8       ;;=during the sort phase.  Fields with a higher probability rating are
 +9       ;;^DD(.4014,14,21,5,0)
 +10      ;;=executed first to most quickly cut down the number of records that have
 +11      ;;^DD(.4014,14,21,6,0)
 +12      ;;=to be processed.
 +13      ;;^DD(.4014,14,23,0)
 +14      ;;=^^1^1^2930125^
 +15      ;;^DD(.4014,14,23,1,0)
 +16      ;;=Calculated by a call to the FileMan Query Optimizer routine ^DIOQ.
 +17      ;;^DD(.4014,14,"DT")
 +18      ;;=2930125
 +19      ;;^DD(.4014,15,0)
 +20      ;;=DATA TYPE FOR SORTING^P.81'^DI(.81,^0;10^Q
 +21      ;;^DD(.4014,15,21,0)
 +22      ;;=^^5^5^2930514^
 +23      ;;^DD(.4014,15,21,1,0)
 +24      ;;=This pointer to the FileMan DATA TYPE file is entered automatically by
 +25      ;;^DD(.4014,15,21,2,0)
 +26      ;;=FileMan during the sort/print.  Note that if sorting by a pointer or a
 +27      ;;^DD(.4014,15,21,3,0)
 +28      ;;=variable pointer, FileMan will follow the pointer chain until it gets to
 +29      ;;^DD(.4014,15,21,4,0)
 +30      ;;=one of the other data types, in order to determine how to correctly set up
 +31      ;;^DD(.4014,15,21,5,0)
 +32      ;;=the sort logic.
 +33      ;;^DD(.4014,15,23,0)
 +34      ;;=^^1^1^2930514^
 +35      ;;^DD(.4014,15,23,1,0)
 +36      ;;=Pointer to DATA TYPE file, derived by FileMan in routine DTYP^DIP1.
 +37      ;;^DD(.4014,15,"DT")
 +38      ;;=2930514
 +39      ;;^DD(.4014,16,0)
 +40      ;;=COMPUTED FIELD CODE^K^^CM;E1,245^K:$L(X)>245 X D:$D(X) ^DIM
 +41      ;;^DD(.4014,16,3)
 +42      ;;=This is Standard MUMPS code, generated for sorting by computed fields or pointer fields.
 +43      ;;^DD(.4014,16,9)
 +44      ;;=@
 +45      ;;^DD(.4014,16,21,0)
 +46      ;;=^^3^3^2930201^
 +47      ;;^DD(.4014,16,21,1,0)
 +48      ;;=This field contains MUMPS code used to find the actual value of a field
 +49      ;;^DD(.4014,16,21,2,0)
 +50      ;;=that is computed or a pointer.  The code is generated by DICOMP.  This
 +51      ;;^DD(.4014,16,21,3,0)
 +52      ;;=code may execute code in OVERFLOW nodes as well.
 +53      ;;^DD(.4014,16,23,0)
 +54      ;;=^^1^1^2930201^
 +55      ;;^DD(.4014,16,23,1,0)
 +56      ;;=Generated by DICOMP.  Put into the DPP array in C^DIP0.
 +57      ;;^DD(.4014,16,"DT")
 +58      ;;=2930201
 +59      ;;^DD(.4014,17,0)
 +60      ;;=MULTIPLE FIELD DATA^.40141^^1;0
 +61      ;;^DD(.4014,18,0)
 +62      ;;=RELATIONAL JUMP FIELD DATA^.401418^^2;0
 +63      ;;^DD(.4014,19,0)
 +64      ;;=OVERFLOW DATA^.401419^^3;0
 +65      ;;^DD(.4014,19,21,0)
 +66      ;;=^^5^5^2930201^
 +67      ;;^DD(.4014,19,21,1,0)
 +68      ;;=This field contains the first subscript from the part of the DPP array
 +69      ;;^DD(.4014,19,21,2,0)
 +70      ;;=that contains overflow code executed when sorting by a field that is
 +71      ;;^DD(.4014,19,21,3,0)
 +72      ;;=gotten to relationally or a computed field.  Overflow code is generated
 +73      ;;^DD(.4014,19,21,4,0)
 +74      ;;=when needed by DICOMP.  This field will typically look something like
 +75      ;;^DD(.4014,19,21,5,0)
 +76      ;;="OVF0".
 +77      ;;^DD(.4014,19,23,0)
 +78      ;;=^^1^1^2930201^
 +79      ;;^DD(.4014,19,23,1,0)
 +80      ;;=Generated by DICOMP from DIP0 during the sort/print option.
 +81      ;;^DD(.4014,19,"DT")
 +82      ;;=2930201
 +83      ;;^DD(.4014,20,0)
 +84      ;;=SUBHEADER OUTPUT TRANSFORM^K^^OUT;E1,245^K:$L(X)>245 X D:$D(X) ^DIM
 +85      ;;^DD(.4014,20,3)
 +86      ;;=This is Standard MUMPS code.  This is used only when sorting by a user-specified cross-reference in input variable BY(0).
 +87      ;;^DD(.4014,20,9)
 +88      ;;=@
 +89      ;;^DD(.4014,20,21,0)
 +90      ;;=^^6^6^2930204^
 +91      ;;^DD(.4014,20,21,1,0)
 +92      ;;=Defined only when using the BY(0) input variable to the FileMan print,
 +93      ;;^DD(.4014,20,21,2,0)
 +94      ;;=EN1^DIP, which allows the user to specify a cross-reference to sort on.
 +95      ;;^DD(.4014,20,21,3,0)
 +96      ;;=The user is allowed to specify MUMPS code that can be used as an output
 +97      ;;^DD(.4014,20,21,4,0)
 +98      ;;=transform for any of the subheaders (i.e., subscripts in the
 +99      ;;^DD(.4014,20,21,5,0)
 +100     ;;=cross-reference) in the S input array.  This output transform code is
 +101     ;;^DD(.4014,20,21,6,0)
 +102     ;;=stored in this field.
 +103     ;;^DD(.4014,20,23,0)
 +104     ;;=^^4^4^2930204^
 +105     ;;^DD(.4014,20,23,1,0)
 +106     ;;=Stores output transform code from the third piece of S(0,N) where N is
 +107     ;;^DD(.4014,20,23,2,0)
 +108     ;;=the sort level.  This is an input array used in conjunction with BY(0)
 +109     ;;^DD(.4014,20,23,3,0)
 +110     ;;=when user specifies a specific cross-reference to use for the sort, in
 +111     ;;^DD(.4014,20,23,4,0)
 +112     ;;=in the FileMan print routine EN1^DIP.
 +113     ;;^DD(.4014,20,"DT")
 +114     ;;=2930204
 +115     ;;^DD(.4014,21,0)
 +116     ;;=TEXT SORT FLAG^S^SORT:SORT LIKE TEXT;RANGE:TREAT RANGE LIKE TEXT;^SRTTXT;1^Q
 +117     ;;^DD(.4014,21,21,0)
 +118     ;;=^^12^12^2931221^
 +119     ;;^DD(.4014,21,21,1,0)
 +120     ;;=This flag will be set in one of two cases.
 +121     ;;^DD(.4014,21,21,2,0)
 +122     ;;= 1) If the user entered the ;TXT qualifier, the flag will be set to
 +123     ;;^DD(.4014,21,21,3,0)
 +124     ;;="SORT", and will cause a space to be inserted at the beginning of each
 +125     ;;^DD(.4014,21,21,4,0)
 +126     ;;=sort value, causing even numeric fields to be sorted as if they were text.
 +127     ;;^DD(.4014,21,21,5,0)
 +128     ;;= 2) If the user entered a FROM or TO value that is a non-canonic number,
 +129     ;;^DD(.4014,21,21,6,0)
 +130     ;;=the flag will be set to RANGE, and will cause sort values that are numeric
 +131     ;;^DD(.4014,21,21,7,0)
 +132     ;;=to be treated as if they were text, when seeing whether they fall within
 +133     ;;^DD(.4014,21,21,8,0)
 +134     ;;=the from/to range.  However, they will still sort like numbers (MUMPS sort
 +135     ;;^DD(.4014,21,21,9,0)
 +136     ;;=sequence).
 +137     ;;^DD(.4014,21,21,10,0)
 +138     ;;= 
 +139     ;;^DD(.4014,21,21,11,0)
 +140     ;;=The flag is set automatically when the user is entering the sort fields in
 +141     ;;^DD(.4014,21,21,12,0)
 +142     ;;=^DIP, and the from/to values in ^DIP1.
 +143     ;;^DD(.4014,21,"DT")
 +144     ;;=2931221
 +145     ;;^DD(.40141,0)
 +146     ;;=MULTIPLE FIELD DATA SUB-FIELD^^1^2
 +147     ;;^DD(.40141,0,"DT")
 +148     ;;=2930201
 +149     ;;^DD(.40141,0,"IX","B",.40141,.01)
 +150     ;;=
 +151     ;;^DD(.40141,0,"NM","MULTIPLE FIELD DATA")
 +152     ;;=
 +153     ;;^DD(.40141,0,"UP")
 +154     ;;=.4014
 +155     ;;^DD(.40141,.01,0)
 +156     ;;=MULT.FILE OR SUBFILE NO.^MNJ13,5^^0;1^K:+X'=X!(X>9999999.99999)!(X<0)!(X?.E1"."6N.N) X
 +157     ;;^DD(.40141,.01,1,0)
 +158     ;;=^.1
 +159     ;;^DD(.40141,.01,1,1,0)
 +160     ;;=.40141^B
 +161     ;;^DD(.40141,.01,1,1,1)
 +162     ;;=S ^DIBT(DA(2),2,DA(1),1,"B",$E(X,1,30),DA)=""
 +163     ;;^DD(.40141,.01,1,1,2)
 +164     ;;=K ^DIBT(DA(2),2,DA(1),1,"B",$E(X,1,30),DA)
 +165     ;;^DD(.40141,.01,3)
 +166     ;;=Type a Number between 0 and 9999999.99999, 5 Decimal Digits.  This is the file/subfile number when sorting by a multiple field.
 +167     ;;^DD(.40141,.01,21,0)
 +168     ;;=^^4^4^2930201^
 +169     ;;^DD(.40141,.01,21,1,0)
 +170     ;;=All files or subfiles needed to get back up to the top level from a
 +171     ;;^DD(.40141,.01,21,2,0)
 +172     ;;=multiple field will be represented by an entry in this field.  The
 +173     ;;^DD(.40141,.01,21,3,0)
 +174     ;;=file or subfile number will be used as a subscript in the DPP array