PXRMEXIC ;SLC/PKR,PJH - Routines to install repository entry components. ;09/27/2018
 ;;2.0;CLINICAL REMINDERS;**6,12,17,16,18,22,24,26,47,45**;Feb 04, 2005;Build 566
 ;=================================================
FILE(PXRMRIEN,SITEIEN,IND120,JND120,ACTION,ATTR,NAMECHG) ;Read and process a
 ;file entry in repository entry PXRMRIEN. IND120 and JND120 are the
 ;indexes for the component list. ACTION is one of the possible actions.
 I ACTION="S" Q
 N DATA,DUZ0S,EDULIST,FDA,FDAEND,FDASTART,FIELD,FILENUM
 N IEN,IENS,IENREND,IENROOT,IENRSTR,IENUSED,IND,INDICES
 N LINE,MSG,NAME,NEW01,PXNAT,PXRMEDOK,PXRMEXCH
 N SRCIEN,START,TEMP,TEXT,TFDA,TIENROOT,TIUFPRIV,TNAME,TOPFNUM,VERSN
 N WPLCNT,WPTMP,XUMF
 ;I $G(PXRMIGDS) S DUZ0S=DUZ(0),DUZ(0)="^",XUMF=1
 ;Set PXRMEDOK so files pointing to sponsors can be installed.
 ;Set PXRMEXCH so national entries can be installed and prevent
 ;execution of the input transform for custom logic fields.
 ;Set PXNAT to allow installation of national PCE data types.
 S (PXNAT,PXRMEDOK,PXRMEXCH)=1
 S TEMP=^PXD(811.8,PXRMRIEN,120,IND120,1,JND120,0)
 S FDASTART=+$P(TEMP,U,2)
 S FDAEND=+$P(TEMP,U,3)
 S IENRSTR=+$P(TEMP,U,4)
 S IENREND=+$P(TEMP,U,5)
 F IND=FDASTART:1:FDAEND D
 . S LINE=^PXD(811.8,PXRMRIEN,100,IND,0)
 . S INDICES=$P(LINE,"~",1)
 . S DATA=$P(LINE,"~",2)
 . S FILENUM=$P(INDICES,";",1)
 . S IENS=$P(INDICES,";",2)
 . I IND=FDASTART S SRCIEN=+IENS
 . S FIELD=$P(INDICES,";",3)
 . I LINE["WP-start" D
 .. S DATA="WPTMP("_IND_","_+FIELD_")"
 .. S WPLCNT=$P(LINE,"~",3)
 .. D WORDPROC(PXRMRIEN,.WPTMP,IND,+FIELD,.IND,WPLCNT)
 . I (IND=FDASTART)&((FIELD=.01)!(FIELD=.001)) D
 ..;Save the top level file number.
 .. S TOPFNUM=FILENUM
 ..;If the action is copy put it in the first open spot.
 .. I ACTION="C" S IENROOT(SRCIEN)=$$LOIEN^PXRMEXU5(TOPFNUM,0)
 ..;
 ..;If the entry does not exist and the action is not copy set the
 ..;action to install.
 .. I SITEIEN=0 S ACTION="I"
 ..;
 ..;If the action is install try to install at the source IEN. If
 ..;an entry already exists at the source IEN put it in the first
 ..;open spot. 
 .. I ACTION="I" D
 ... S IENUSED=+$$FIND1^DIC(FILENUM,"","QU","`"_SRCIEN)
 ... S IENROOT(SRCIEN)=$S(IENUSED=0:SRCIEN,1:$$LOIEN^PXRMEXU5(FILENUM))
 ..;
 ..;If the action is merge, overwrite,or update install at the site's
 ..;IEN.
 .. I (ACTION="M")!(ACTION="O")!(ACTION="U") S IENROOT(SRCIEN)=SITEIEN
 .;
 .;This line is use to convert pre-patch 12 disable text to the new
 .;value of 1 for disable
 . I FILENUM=801.41,FIELD=3,DATA'="",$L(DATA)>2 D
 ..I DATA="DISABLE AND DO NOT SEND MESSAGE" Q
 ..S DATA="DISABLE AND SEND MESSAGE"
 .;
 . S FDA(FILENUM,IENS,FIELD)=DATA
 ;
 ;Initialize the edit history.
 D INIEH(TOPFNUM,IENS,.FDA,.WPTMP)
 ;Build the IENROOT
 F IND=IENRSTR:1:IENREND D
 . I IND=0 Q
 . S TEMP=^PXD(811.8,PXRMRIEN,100,IND,0)
 . S IENROOT($P(TEMP,U,1))=$P(TEMP,U,2)
 ;Check for name changes, i.e., the copy action.
 D NAMECHG(.FDA,.NAMECHG,TOPFNUM)
 ;
 ;Special handling for file 142.
 I TOPFNUM=142 D  Q:'$D(FDA)
 . D SFMVPI^PXRMEXIU(.FDA,.NAMECHG,142.14)
 ;
 ;Special handling for file 801
 I TOPFNUM=801 D  Q:PXRMDONE
 . D SFMVPI^PXRMEXIU(.FDA,.NAMECHG,801.015)
 . D ROC^PXRMEXU5(.FDA,.IENROOT)
 ;
 ;Special handling for file 801.1
 I TOPFNUM=801.1 D  Q:PXRMDONE
 . D ROCR^PXRMEXU5(.FDA)
 ;
 I TOPFNUM=801.48 D DLINKSAV^PXRMEXU5(.FDA) Q:PXRMDONE
 ;Special handling for file 801.41
 I TOPFNUM=801.41 D  Q:PXRMDONE
 . I ACTION="M" D MOU^PXRMEXU5(801.41,SITEIEN,"18*",.FDA,.IENROOT,ACTION,.WPTMP)
 . D DLG^PXRMEXU4(.FDA,.NAMECHG)
 ;
 ;Special handling for file 810.9
 I TOPFNUM=810.9 D LOC^PXRMEXU0(.FDA)
 ;
 ;Special handling for file 811.2
 I TOPFNUM=811.2 D TAX^PXRMEXU0(.FDA,"CFR")
 ;
 I TOPFNUM=801.46 D DIALOGGF^PXRMEXU5(.FDA,.IENROOT)
 ;
 ;If the file number is 811.4 the user must have programmer
 ;access to install it.
 I (TOPFNUM=811.4)&(DUZ(0)'="@") D  Q
 . W !,"Only programmers can install Reminder Computed Findings."
 ;
 ;Special handling for file 811.5.
 I TOPFNUM=811.5 D  Q:'$D(FDA)
 .;If the site has any findings already mapped merge them in.
 . I (ACTION="M")!(ACTION="U") D MOU^PXRMEXU5(811.5,SITEIEN,"20*",.FDA,.IENROOT,ACTION,.WPTMP)
 . D SFMVPI^PXRMEXIU(.FDA,.NAMECHG,811.52)
 ;
 ;Special handling for file 811.9.
 I TOPFNUM=811.9 D
 .;Don't execute the input transform for custom logic fields.
 . S PXRMEXCH=1
 . D DEF^PXRMEXIU(.FDA,.NAMECHG)
 ;
 ;Special handling for file 8925.1
 I TOPFNUM=8925.1 D
 . S TIUFPRIV=1
 . D TIUOBJ^PXRMEXIU(.FDA)
 ;
 ;Special handling for file 9999999.09: Education Topics.
 I TOPFNUM=9999999.09 D EDU^PXRMEXIU(.FDA,.EDULIST)
 ;
 ;Special handling for file 9999999.15: Exams.
 I TOPFNUM=9999999.15 D EXAM^PXRMEXIU(.FDA)
 ;
 ;Special handling for file 9999999.64: Health Factors.
 I TOPFNUM=9999999.64 D HF^PXRMEXIU(.FDA)
 ;
 ;
 ;If FDA is not defined at this point the user has opted to abort
 ;the install.
 I '$D(FDA) Q
 ;
 ;If the action is merge, overwrite, or update do a test install
 ;before deleting the original entry.
 I (ACTION="M")!(ACTION="O")!(ACTION="U") D
 .;Make the .01 unique for the test install.
 . S IENS=$O(FDA(TOPFNUM,""))
 .;Get the length of the .01 field
 . D FIELD^DID(TOPFNUM,.01,"","FIELD LENGTH","ATTR")
 . S TNAME="tmp"_$E(FDA(TOPFNUM,IENS,.01),1,ATTR("FIELD LENGTH")-3)
 .;Make sure the test entry does not already exist.
 . D DELALL^PXRMEXFI(TOPFNUM,TNAME)
 . M TFDA=FDA
 . S TFDA(TOPFNUM,IENS,.01)=TNAME
 . K TIENROOT M TIENROOT=IENROOT
 . S TIENROOT(SRCIEN)=$$LOIEN^PXRMEXU5(TOPFNUM)
 . D UPDATE^DIE("E","TFDA","TIENROOT","MSG")
 . I $D(MSG) D  Q
 .. S TEXT(1)=ATTR("FILE NAME")_" entry "_$G(ATTR("PT01"))_" did not get installed!"
 .. S TEXT(2)="Examine the following error message for the reason."
 .. S TEXT(3)=""
 .. S TEXT(4)="The test update failed, UPDATE^DIE returned the following error message:"
 .. D MES^XPDUTL(.TEXT)
 .. D AWRITE^PXRMUTIL("MSG")
 .. H 2
 .;Delete the test entry.
 . D DELALL^PXRMEXFI(TOPFNUM,TNAME)
 .;If the original update worked put the entry at its original ien.
 .;Delete the existing entry.
 . D DELETE^PXRMEXFI(TOPFNUM,SITEIEN)
 D UPDATE^DIE("ES","FDA","IENROOT","MSG")
 I '$D(MSG),ATTR("FILE NUMBER")=9999999.64 D
 . ;Build a list of health factor categories that need the [C] appended
 . N IENS
 . S IENS=$O(FDA(9999999.64,""))
 . I FDA(9999999.64,IENS,.1)'="CATEGORY" Q
 . N L3C,LEN,NAME
 . S NAME=ATTR("NAME")
 . S LEN=$L(NAME),L3C=$E(NAME,(LEN-2),LEN)
 . I L3C'="[C]" S ^TMP($J,"HFCAT",NAME)=""
 I $D(MSG) D
 . S TEXT(1)=ATTR("FILE NAME")_" entry "_$G(ATTR("PT01"))_" did not get installed!"
 . S TEXT(2)="Examine the following error message for the reason."
 . S TEXT(3)=""
 . S TEXT(4)="The update failed, UPDATE^DIE returned the following error message:"
 . D MES^XPDUTL(.TEXT)
 . D AWRITE^PXRMUTIL("MSG")
 . W !
 . H 2
 ;
 I TOPFNUM=811.2 D
 .;Finish conversion from pointer based structure to Lexicon based.
 . N IEN,PDS
 . S IEN=+$O(^PXD(811.2,"B",ATTR("NAME"),""))
 . I IEN=0 Q
 . D EXCH^PXRMTXCR(IEN,"CFR")
 . S PDS=$P(^PXD(811.2,IEN,0),U,4)
 . I PDS="" D SPDS^PXRMPDS(IEN,PDS)
 .;If there are codes marked Use In Dialog build the 30 node.
 . D BLD30N^PXRMTAXD(IEN)
 ;
 S VERSN=$$GETTAGV^PXRMEXU3(^PXD(811.8,PXRMRIEN,100,3,0),"<PACKAGE_VERSION>")
 I TOPFNUM=811.9,VERSN=1.5 D
 . N IEN,PXRMEXCH,X
 . S IEN=+$O(^PXD(811.9,"B",ATTR("PT01"),""))
 . I IEN=0 Q
 .;For reminder definitions build the found/not found text counts.
 . D SFNFTC^PXRMEXU0(IEN)
 .;Build the internal logic and finding strings.
 . S X=$G(^PXD(811.9,IEN,30))
 . I X'="" D CPPCLS^PXRMLOGX(IEN,X)
 . S X=$G(^PXD(811.9,IEN,34))
 . I X'="" D CPRESLS^PXRMLOGX(IEN,X)
 . D BLDALL^PXRMLOGX(IEN,"","")
 ;If there are national education topics rename them so they start
 ;with VA-
 I $D(EDULIST),$G(PXRMNAT) D
 .;Get the length of the .01 field
 . D FIELD^DID(TOPFNUM,.01,"","FIELD LENGTH","ATTR")
 . S NAME=""
 . F  S NAME=$O(EDULIST(NAME)) Q:NAME=""  D
 .. I $E(NAME,1,3)="VA-" Q
 .. S TNAME="VA-"_$E(ATTR("FIELD LENGTH")-3)
 .. D RENAME^PXRMUTIL(TOPFNUM,NAME,TNAME)
 ;I $G(PXRMIGDS) S DUZ(0)=DUZ0S
 Q
 ;
 ;=================================================
INIEH(FILENUM,IENS,FDA,WPTMP) ;If the file is a clinical reminder file and
 ;it has an edit history initialize the history.
 I (FILENUM<800)!(FILENUM>811.9) Q
 N IENS,SFN,TARGET,WP
 D FIELD^DID(FILENUM,"CHANGE LOG","","SPECIFIER","TARGET")
 S SFN=+$G(TARGET("SPECIFIER"))
 I SFN=0 D FIELD^DID(FILENUM,"EDIT HISTORY","","SPECIFIER","TARGET")
 S SFN=+$G(TARGET("SPECIFIER"))
 I SFN=0 Q
 S IENS=$O(FDA(SFN,""))
 I IENS="" Q
 S FDA(SFN,IENS,.01)=$$FMTE^XLFDT($$NOW^XLFDT,"5Z")
 S FDA(SFN,IENS,1)="`"_DUZ
 ;The word-processing field is set when the packing is done.
 S WP=FDA(SFN,IENS,2)
 K @WP
 S @WP@(1)="Exchange Install"
 Q
 ;
 ;=================================================
NAMECHG(FDA,NAMECHG,FILENUM) ;If this component has been copied to a new
 ;name make the change.
 N CLASS,IENS,PT01
 S IENS=$O(FDA(FILENUM,""))
 S PT01=FDA(FILENUM,IENS,.01)
 I $D(NAMECHG(FILENUM,PT01)) D
 . S FDA(FILENUM,IENS,.01)=NAMECHG(FILENUM,PT01)
 . I (FILENUM<801.41)!(FILENUM>811.9) Q
 .;Once a component has been copied CLASS can no longer be national.
 . S CLASS=$G(FDA(FILENUM,IENS,100))
 . I CLASS["N" S FDA(FILENUM,IENS,100)="LOCAL"
 .;The Sponsor is also removed.
 . K FDA(FILENUM,IENS,101)
 Q
 ;
 ;=================================================
RTNLD(PXRMRIEN,START,END,ATTR,RTN) ;Load a routine from the repository into
 ;the array RTN.
 N IND,LINE,LN,ROUTINE
 S LINE=^PXD(811.8,PXRMRIEN,100,START,0)
 S ROUTINE=$P(LINE,";",1)
 S ROUTINE=$TR(ROUTINE," ","")
 S ATTR("FILE NUMBER")=0
 S ATTR("NAME")=$P(LINE,";",1)
 S ATTR("NAME")=$TR(ATTR("NAME")," ","")
 S ATTR("MIN FIELD LENGTH")=3
 S ATTR("FIELD LENGTH")=8
 S LN=0
 F IND=START:1:END D
 . S LN=LN+1
 . S LINE=^PXD(811.8,PXRMRIEN,100,IND,0)
 . S RTN(LN,0)=LINE
 Q
 ;
 ;=================================================
RTNSAVE(RTN,NAME) ;Save the routine loaded in RTN to the name
 ;found in NAMECHG.
 N DIE,XCN
 ;%ZOSF("SAVE") requires a global.
 K ^TMP($J,"PXRMRTN")
 S DIE="^TMP($J,""PXRMRTN"","
 M ^TMP($J,"PXRMRTN")=RTN
 S XCN=0
 S X=NAME
 X ^%ZOSF("SAVE")
 K ^TMP($J,"PXRMRTN")
 Q
 ;
 ;=================================================
WORDPROC(PXRMRIEN,WPTMP,I1,I2,IND,WPLCNT) ;Load WPTMP with the word
 ;processing field.
 N I3
 F I3=1:1:WPLCNT D
 . S IND=IND+1
 . S WPTMP(I1,I2,I3)=$G(^PXD(811.8,PXRMRIEN,100,IND,0))
 Q
 ;
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPXRMEXIC   10635     printed  Sep 23, 2025@19:20:57                                                                                                                                                                                                   Page 2
PXRMEXIC  ;SLC/PKR,PJH - Routines to install repository entry components. ;09/27/2018
 +1       ;;2.0;CLINICAL REMINDERS;**6,12,17,16,18,22,24,26,47,45**;Feb 04, 2005;Build 566
 +2       ;=================================================
FILE(PXRMRIEN,SITEIEN,IND120,JND120,ACTION,ATTR,NAMECHG) ;Read and process a
 +1       ;file entry in repository entry PXRMRIEN. IND120 and JND120 are the
 +2       ;indexes for the component list. ACTION is one of the possible actions.
 +3        IF ACTION="S"
               QUIT 
 +4        NEW DATA,DUZ0S,EDULIST,FDA,FDAEND,FDASTART,FIELD,FILENUM
 +5        NEW IEN,IENS,IENREND,IENROOT,IENRSTR,IENUSED,IND,INDICES
 +6        NEW LINE,MSG,NAME,NEW01,PXNAT,PXRMEDOK,PXRMEXCH
 +7        NEW SRCIEN,START,TEMP,TEXT,TFDA,TIENROOT,TIUFPRIV,TNAME,TOPFNUM,VERSN
 +8        NEW WPLCNT,WPTMP,XUMF
 +9       ;I $G(PXRMIGDS) S DUZ0S=DUZ(0),DUZ(0)="^",XUMF=1
 +10      ;Set PXRMEDOK so files pointing to sponsors can be installed.
 +11      ;Set PXRMEXCH so national entries can be installed and prevent
 +12      ;execution of the input transform for custom logic fields.
 +13      ;Set PXNAT to allow installation of national PCE data types.
 +14       SET (PXNAT,PXRMEDOK,PXRMEXCH)=1
 +15       SET TEMP=^PXD(811.8,PXRMRIEN,120,IND120,1,JND120,0)
 +16       SET FDASTART=+$PIECE(TEMP,U,2)
 +17       SET FDAEND=+$PIECE(TEMP,U,3)
 +18       SET IENRSTR=+$PIECE(TEMP,U,4)
 +19       SET IENREND=+$PIECE(TEMP,U,5)
 +20       FOR IND=FDASTART:1:FDAEND
               Begin DoDot:1
 +21               SET LINE=^PXD(811.8,PXRMRIEN,100,IND,0)
 +22               SET INDICES=$PIECE(LINE,"~",1)
 +23               SET DATA=$PIECE(LINE,"~",2)
 +24               SET FILENUM=$PIECE(INDICES,";",1)
 +25               SET IENS=$PIECE(INDICES,";",2)
 +26               IF IND=FDASTART
                       SET SRCIEN=+IENS
 +27               SET FIELD=$PIECE(INDICES,";",3)
 +28               IF LINE["WP-start"
                       Begin DoDot:2
 +29                       SET DATA="WPTMP("_IND_","_+FIELD_")"
 +30                       SET WPLCNT=$PIECE(LINE,"~",3)
 +31                       DO WORDPROC(PXRMRIEN,.WPTMP,IND,+FIELD,.IND,WPLCNT)
                       End DoDot:2
 +32               IF (IND=FDASTART)&((FIELD=.01)!(FIELD=.001))
                       Begin DoDot:2
 +33      ;Save the top level file number.
 +34                       SET TOPFNUM=FILENUM
 +35      ;If the action is copy put it in the first open spot.
 +36                       IF ACTION="C"
                               SET IENROOT(SRCIEN)=$$LOIEN^PXRMEXU5(TOPFNUM,0)
 +37      ;
 +38      ;If the entry does not exist and the action is not copy set the
 +39      ;action to install.
 +40                       IF SITEIEN=0
                               SET ACTION="I"
 +41      ;
 +42      ;If the action is install try to install at the source IEN. If
 +43      ;an entry already exists at the source IEN put it in the first
 +44      ;open spot. 
 +45                       IF ACTION="I"
                               Begin DoDot:3
 +46                               SET IENUSED=+$$FIND1^DIC(FILENUM,"","QU","`"_SRCIEN)
 +47                               SET IENROOT(SRCIEN)=$SELECT(IENUSED=0:SRCIEN,1:$$LOIEN^PXRMEXU5(FILENUM))
                               End DoDot:3
 +48      ;
 +49      ;If the action is merge, overwrite,or update install at the site's
 +50      ;IEN.
 +51                       IF (ACTION="M")!(ACTION="O")!(ACTION="U")
                               SET IENROOT(SRCIEN)=SITEIEN
                       End DoDot:2
 +52      ;
 +53      ;This line is use to convert pre-patch 12 disable text to the new
 +54      ;value of 1 for disable
 +55               IF FILENUM=801.41
                       IF FIELD=3
                           IF DATA'=""
                               IF $LENGTH(DATA)>2
                                   Begin DoDot:2
 +56                                   IF DATA="DISABLE AND DO NOT SEND MESSAGE"
                                           QUIT 
 +57                                   SET DATA="DISABLE AND SEND MESSAGE"
                                   End DoDot:2
 +58      ;
 +59               SET FDA(FILENUM,IENS,FIELD)=DATA
               End DoDot:1
 +60      ;
 +61      ;Initialize the edit history.
 +62       DO INIEH(TOPFNUM,IENS,.FDA,.WPTMP)
 +63      ;Build the IENROOT
 +64       FOR IND=IENRSTR:1:IENREND
               Begin DoDot:1
 +65               IF IND=0
                       QUIT 
 +66               SET TEMP=^PXD(811.8,PXRMRIEN,100,IND,0)
 +67               SET IENROOT($PIECE(TEMP,U,1))=$PIECE(TEMP,U,2)
               End DoDot:1
 +68      ;Check for name changes, i.e., the copy action.
 +69       DO NAMECHG(.FDA,.NAMECHG,TOPFNUM)
 +70      ;
 +71      ;Special handling for file 142.
 +72       IF TOPFNUM=142
               Begin DoDot:1
 +73               DO SFMVPI^PXRMEXIU(.FDA,.NAMECHG,142.14)
               End DoDot:1
               if '$DATA(FDA)
                   QUIT 
 +74      ;
 +75      ;Special handling for file 801
 +76       IF TOPFNUM=801
               Begin DoDot:1
 +77               DO SFMVPI^PXRMEXIU(.FDA,.NAMECHG,801.015)
 +78               DO ROC^PXRMEXU5(.FDA,.IENROOT)
               End DoDot:1
               if PXRMDONE
                   QUIT 
 +79      ;
 +80      ;Special handling for file 801.1
 +81       IF TOPFNUM=801.1
               Begin DoDot:1
 +82               DO ROCR^PXRMEXU5(.FDA)
               End DoDot:1
               if PXRMDONE
                   QUIT 
 +83      ;
 +84       IF TOPFNUM=801.48
               DO DLINKSAV^PXRMEXU5(.FDA)
               if PXRMDONE
                   QUIT 
 +85      ;Special handling for file 801.41
 +86       IF TOPFNUM=801.41
               Begin DoDot:1
 +87               IF ACTION="M"
                       DO MOU^PXRMEXU5(801.41,SITEIEN,"18*",.FDA,.IENROOT,ACTION,.WPTMP)
 +88               DO DLG^PXRMEXU4(.FDA,.NAMECHG)
               End DoDot:1
               if PXRMDONE
                   QUIT 
 +89      ;
 +90      ;Special handling for file 810.9
 +91       IF TOPFNUM=810.9
               DO LOC^PXRMEXU0(.FDA)
 +92      ;
 +93      ;Special handling for file 811.2
 +94       IF TOPFNUM=811.2
               DO TAX^PXRMEXU0(.FDA,"CFR")
 +95      ;
 +96       IF TOPFNUM=801.46
               DO DIALOGGF^PXRMEXU5(.FDA,.IENROOT)
 +97      ;
 +98      ;If the file number is 811.4 the user must have programmer
 +99      ;access to install it.
 +100      IF (TOPFNUM=811.4)&(DUZ(0)'="@")
               Begin DoDot:1
 +101              WRITE !,"Only programmers can install Reminder Computed Findings."
               End DoDot:1
               QUIT 
 +102     ;
 +103     ;Special handling for file 811.5.
 +104      IF TOPFNUM=811.5
               Begin DoDot:1
 +105     ;If the site has any findings already mapped merge them in.
 +106              IF (ACTION="M")!(ACTION="U")
                       DO MOU^PXRMEXU5(811.5,SITEIEN,"20*",.FDA,.IENROOT,ACTION,.WPTMP)
 +107              DO SFMVPI^PXRMEXIU(.FDA,.NAMECHG,811.52)
               End DoDot:1
               if '$DATA(FDA)
                   QUIT 
 +108     ;
 +109     ;Special handling for file 811.9.
 +110      IF TOPFNUM=811.9
               Begin DoDot:1
 +111     ;Don't execute the input transform for custom logic fields.
 +112              SET PXRMEXCH=1
 +113              DO DEF^PXRMEXIU(.FDA,.NAMECHG)
               End DoDot:1
 +114     ;
 +115     ;Special handling for file 8925.1
 +116      IF TOPFNUM=8925.1
               Begin DoDot:1
 +117              SET TIUFPRIV=1
 +118              DO TIUOBJ^PXRMEXIU(.FDA)
               End DoDot:1
 +119     ;
 +120     ;Special handling for file 9999999.09: Education Topics.
 +121      IF TOPFNUM=9999999.09
               DO EDU^PXRMEXIU(.FDA,.EDULIST)
 +122     ;
 +123     ;Special handling for file 9999999.15: Exams.
 +124      IF TOPFNUM=9999999.15
               DO EXAM^PXRMEXIU(.FDA)
 +125     ;
 +126     ;Special handling for file 9999999.64: Health Factors.
 +127      IF TOPFNUM=9999999.64
               DO HF^PXRMEXIU(.FDA)
 +128     ;
 +129     ;
 +130     ;If FDA is not defined at this point the user has opted to abort
 +131     ;the install.
 +132      IF '$DATA(FDA)
               QUIT 
 +133     ;
 +134     ;If the action is merge, overwrite, or update do a test install
 +135     ;before deleting the original entry.
 +136      IF (ACTION="M")!(ACTION="O")!(ACTION="U")
               Begin DoDot:1
 +137     ;Make the .01 unique for the test install.
 +138              SET IENS=$ORDER(FDA(TOPFNUM,""))
 +139     ;Get the length of the .01 field
 +140              DO FIELD^DID(TOPFNUM,.01,"","FIELD LENGTH","ATTR")
 +141              SET TNAME="tmp"_$EXTRACT(FDA(TOPFNUM,IENS,.01),1,ATTR("FIELD LENGTH")-3)
 +142     ;Make sure the test entry does not already exist.
 +143              DO DELALL^PXRMEXFI(TOPFNUM,TNAME)
 +144              MERGE TFDA=FDA
 +145              SET TFDA(TOPFNUM,IENS,.01)=TNAME
 +146              KILL TIENROOT
                   MERGE TIENROOT=IENROOT
 +147              SET TIENROOT(SRCIEN)=$$LOIEN^PXRMEXU5(TOPFNUM)
 +148              DO UPDATE^DIE("E","TFDA","TIENROOT","MSG")
 +149              IF $DATA(MSG)
                       Begin DoDot:2
 +150                      SET TEXT(1)=ATTR("FILE NAME")_" entry "_$GET(ATTR("PT01"))_" did not get installed!"
 +151                      SET TEXT(2)="Examine the following error message for the reason."
 +152                      SET TEXT(3)=""
 +153                      SET TEXT(4)="The test update failed, UPDATE^DIE returned the following error message:"
 +154                      DO MES^XPDUTL(.TEXT)
 +155                      DO AWRITE^PXRMUTIL("MSG")
 +156                      HANG 2
                       End DoDot:2
                       QUIT 
 +157     ;Delete the test entry.
 +158              DO DELALL^PXRMEXFI(TOPFNUM,TNAME)
 +159     ;If the original update worked put the entry at its original ien.
 +160     ;Delete the existing entry.
 +161              DO DELETE^PXRMEXFI(TOPFNUM,SITEIEN)
               End DoDot:1
 +162      DO UPDATE^DIE("ES","FDA","IENROOT","MSG")
 +163      IF '$DATA(MSG)
               IF ATTR("FILE NUMBER")=9999999.64
                   Begin DoDot:1
 +164     ;Build a list of health factor categories that need the [C] appended
 +165                  NEW IENS
 +166                  SET IENS=$ORDER(FDA(9999999.64,""))
 +167                  IF FDA(9999999.64,IENS,.1)'="CATEGORY"
                           QUIT 
 +168                  NEW L3C,LEN,NAME
 +169                  SET NAME=ATTR("NAME")
 +170                  SET LEN=$LENGTH(NAME)
                       SET L3C=$EXTRACT(NAME,(LEN-2),LEN)
 +171                  IF L3C'="[C]"
                           SET ^TMP($JOB,"HFCAT",NAME)=""
                   End DoDot:1
 +172      IF $DATA(MSG)
               Begin DoDot:1
 +173              SET TEXT(1)=ATTR("FILE NAME")_" entry "_$GET(ATTR("PT01"))_" did not get installed!"
 +174              SET TEXT(2)="Examine the following error message for the reason."
 +175              SET TEXT(3)=""
 +176              SET TEXT(4)="The update failed, UPDATE^DIE returned the following error message:"
 +177              DO MES^XPDUTL(.TEXT)
 +178              DO AWRITE^PXRMUTIL("MSG")
 +179              WRITE !
 +180              HANG 2
               End DoDot:1
 +181     ;
 +182      IF TOPFNUM=811.2
               Begin DoDot:1
 +183     ;Finish conversion from pointer based structure to Lexicon based.
 +184              NEW IEN,PDS
 +185              SET IEN=+$ORDER(^PXD(811.2,"B",ATTR("NAME"),""))
 +186              IF IEN=0
                       QUIT 
 +187              DO EXCH^PXRMTXCR(IEN,"CFR")
 +188              SET PDS=$PIECE(^PXD(811.2,IEN,0),U,4)
 +189              IF PDS=""
                       DO SPDS^PXRMPDS(IEN,PDS)
 +190     ;If there are codes marked Use In Dialog build the 30 node.
 +191              DO BLD30N^PXRMTAXD(IEN)
               End DoDot:1
 +192     ;
 +193      SET VERSN=$$GETTAGV^PXRMEXU3(^PXD(811.8,PXRMRIEN,100,3,0),"<PACKAGE_VERSION>")
 +194      IF TOPFNUM=811.9
               IF VERSN=1.5
                   Begin DoDot:1
 +195                  NEW IEN,PXRMEXCH,X
 +196                  SET IEN=+$ORDER(^PXD(811.9,"B",ATTR("PT01"),""))
 +197                  IF IEN=0
                           QUIT 
 +198     ;For reminder definitions build the found/not found text counts.
 +199                  DO SFNFTC^PXRMEXU0(IEN)
 +200     ;Build the internal logic and finding strings.
 +201                  SET X=$GET(^PXD(811.9,IEN,30))
 +202                  IF X'=""
                           DO CPPCLS^PXRMLOGX(IEN,X)
 +203                  SET X=$GET(^PXD(811.9,IEN,34))
 +204                  IF X'=""
                           DO CPRESLS^PXRMLOGX(IEN,X)
 +205                  DO BLDALL^PXRMLOGX(IEN,"","")
                   End DoDot:1
 +206     ;If there are national education topics rename them so they start
 +207     ;with VA-
 +208      IF $DATA(EDULIST)
               IF $GET(PXRMNAT)
                   Begin DoDot:1
 +209     ;Get the length of the .01 field
 +210                  DO FIELD^DID(TOPFNUM,.01,"","FIELD LENGTH","ATTR")
 +211                  SET NAME=""
 +212                  FOR 
                           SET NAME=$ORDER(EDULIST(NAME))
                           if NAME=""
                               QUIT 
                           Begin DoDot:2
 +213                          IF $EXTRACT(NAME,1,3)="VA-"
                                   QUIT 
 +214                          SET TNAME="VA-"_$EXTRACT(ATTR("FIELD LENGTH")-3)
 +215                          DO RENAME^PXRMUTIL(TOPFNUM,NAME,TNAME)
                           End DoDot:2
                   End DoDot:1
 +216     ;I $G(PXRMIGDS) S DUZ(0)=DUZ0S
 +217      QUIT 
 +218     ;
 +219     ;=================================================
INIEH(FILENUM,IENS,FDA,WPTMP) ;If the file is a clinical reminder file and
 +1       ;it has an edit history initialize the history.
 +2        IF (FILENUM<800)!(FILENUM>811.9)
               QUIT 
 +3        NEW IENS,SFN,TARGET,WP
 +4        DO FIELD^DID(FILENUM,"CHANGE LOG","","SPECIFIER","TARGET")
 +5        SET SFN=+$GET(TARGET("SPECIFIER"))
 +6        IF SFN=0
               DO FIELD^DID(FILENUM,"EDIT HISTORY","","SPECIFIER","TARGET")
 +7        SET SFN=+$GET(TARGET("SPECIFIER"))
 +8        IF SFN=0
               QUIT 
 +9        SET IENS=$ORDER(FDA(SFN,""))
 +10       IF IENS=""
               QUIT 
 +11       SET FDA(SFN,IENS,.01)=$$FMTE^XLFDT($$NOW^XLFDT,"5Z")
 +12       SET FDA(SFN,IENS,1)="`"_DUZ
 +13      ;The word-processing field is set when the packing is done.
 +14       SET WP=FDA(SFN,IENS,2)
 +15       KILL @WP
 +16       SET @WP@(1)="Exchange Install"
 +17       QUIT 
 +18      ;
 +19      ;=================================================
NAMECHG(FDA,NAMECHG,FILENUM) ;If this component has been copied to a new
 +1       ;name make the change.
 +2        NEW CLASS,IENS,PT01
 +3        SET IENS=$ORDER(FDA(FILENUM,""))
 +4        SET PT01=FDA(FILENUM,IENS,.01)
 +5        IF $DATA(NAMECHG(FILENUM,PT01))
               Begin DoDot:1
 +6                SET FDA(FILENUM,IENS,.01)=NAMECHG(FILENUM,PT01)
 +7                IF (FILENUM<801.41)!(FILENUM>811.9)
                       QUIT 
 +8       ;Once a component has been copied CLASS can no longer be national.
 +9                SET CLASS=$GET(FDA(FILENUM,IENS,100))
 +10               IF CLASS["N"
                       SET FDA(FILENUM,IENS,100)="LOCAL"
 +11      ;The Sponsor is also removed.
 +12               KILL FDA(FILENUM,IENS,101)
               End DoDot:1
 +13       QUIT 
 +14      ;
 +15      ;=================================================
RTNLD(PXRMRIEN,START,END,ATTR,RTN) ;Load a routine from the repository into
 +1       ;the array RTN.
 +2        NEW IND,LINE,LN,ROUTINE
 +3        SET LINE=^PXD(811.8,PXRMRIEN,100,START,0)
 +4        SET ROUTINE=$PIECE(LINE,";",1)
 +5        SET ROUTINE=$TRANSLATE(ROUTINE," ","")
 +6        SET ATTR("FILE NUMBER")=0
 +7        SET ATTR("NAME")=$PIECE(LINE,";",1)
 +8        SET ATTR("NAME")=$TRANSLATE(ATTR("NAME")," ","")
 +9        SET ATTR("MIN FIELD LENGTH")=3
 +10       SET ATTR("FIELD LENGTH")=8
 +11       SET LN=0
 +12       FOR IND=START:1:END
               Begin DoDot:1
 +13               SET LN=LN+1
 +14               SET LINE=^PXD(811.8,PXRMRIEN,100,IND,0)
 +15               SET RTN(LN,0)=LINE
               End DoDot:1
 +16       QUIT 
 +17      ;
 +18      ;=================================================
RTNSAVE(RTN,NAME) ;Save the routine loaded in RTN to the name
 +1       ;found in NAMECHG.
 +2        NEW DIE,XCN
 +3       ;%ZOSF("SAVE") requires a global.
 +4        KILL ^TMP($JOB,"PXRMRTN")
 +5        SET DIE="^TMP($J,""PXRMRTN"","
 +6        MERGE ^TMP($JOB,"PXRMRTN")=RTN
 +7        SET XCN=0
 +8        SET X=NAME
 +9        XECUTE ^%ZOSF("SAVE")
 +10       KILL ^TMP($JOB,"PXRMRTN")
 +11       QUIT 
 +12      ;
 +13      ;=================================================
WORDPROC(PXRMRIEN,WPTMP,I1,I2,IND,WPLCNT) ;Load WPTMP with the word
 +1       ;processing field.
 +2        NEW I3
 +3        FOR I3=1:1:WPLCNT
               Begin DoDot:1
 +4                SET IND=IND+1
 +5                SET WPTMP(I1,I2,I3)=$GET(^PXD(811.8,PXRMRIEN,100,IND,0))
               End DoDot:1
 +6        QUIT 
 +7       ;