TIUP134 ;SLC/RMO - Post-Install for TIU*1*134 ;6/6/02@09:51:20
 ;;1.0;Text Integration Utilities;**134**;Jun 20, 1997
 ;
EN ;Entry point to queue a job to automatically link the missing VISIT
 ;field for a date range of documents
 N TIUBEGDT,TIUENDT,ZTDESC,ZTIO,ZTRTN,ZTSAVE,ZTSK
 ;
 W !!,"PATCH TIU*1*134"
 W !!,"Automatically Link the missing VISIT field for a date range of documents"
 W !!,"Documents must meet the following criteria to be linked:"
 W !,"- Date range cannot be before 10/1/98 or after 7/31/02"
 W !,"- Entry Date/Time is within the selected date range"
 W !,"- No visit has been associated with the document"
 W !,"- A visit exists to be associated with the document"
 W !,"- The capture method is direct or remote"
 W !,"- The status is uncosigned or completed or amended"
 W !,"- The document is under the progress notes class or consults"
 W !,"- The document has a signature date/time"
 W !,"- Workload data should be collected for the document"
 W !!,"  Special Note about Parameters:",!
 W !,"  The 'ASK DX/CPT ON ALL OPT VISITS' TIU Document parameter"
 W !,"  is not date sensitive so collecting workload is based on"
 W !,"  the value of this parameter at the time this routine is"
 W !,"  invoked rather than at the time the visit was created."
 ;
 ;Ask date range
 I '$$ASKRNG(.TIUBEGDT,.TIUENDT) G ENQ
 ;
 ;Set variables
 S (ZTSAVE("TIUBEGDT"),ZTSAVE("TIUENDT"))=""
 S ZTRTN="LNKRNG^TIUP134",ZTIO="",ZTSAVE("DUZ")=""
 S ZTDESC="Automatically link missing VISIT field for File #8925 - Patch 134"
 W ! D ^%ZTLOAD
 I $G(ZTSK) D
 . W !!,"A task has been queued in the background and a bulletin will be sent"
 . W !,"to you upon completion of the task or if the task is stopped."
 . W !,"Please only run one date range at a time."
 . W !!,"The task number is "_$G(ZTSK)_"."
ENQ Q
 ;
ASKRNG(BEGDT,ENDT) ;Prompt for date range
 ; Input  -- None
 ; Output -- 1=Successful and 0=Failure
 ;           BEGDT Begin Date
 ;           ENDT  End Date
 N DIRUT,DTOUT,DUOUT,Y
 W !!,"Please specify a date range:"
 S BEGDT=+$$READ^TIUU("DA^"_2981001_":"_3020731_":E","   Beginning: ")
 I +$D(DIRUT)!(BEGDT'>0) G ASKRNGQ
 S ENDT=+$$READ^TIUU("DA^"_BEGDT_":"_3020731_":E","        Thru: ")_"."_235959
 I +$D(DIRUT)!(ENDT'>0) G ASKRNGQ
 S Y=1
ASKRNGQ Q +$G(Y)
 ;
LNKRNG ;Entry point to automatically link a document to a visit for
 ;a specified date range
 ; Input  -- TIUBEGDT Begin Date
 ;           TIUENDT  End Date
 ; Output -- ^XTMP("TIUP134", Global
 N TIUDA,TIUDT,TIURSTDT,TIUS
 ;
 ;Exit if required variables are not defined
 I '$G(TIUBEGDT)!('$G(TIUENDT)) G LNKRNGQ
 ;
 ;Initialize re-start if check point exists
 I +$G(^XTMP("TIUP134","CHKPT")) D
 . S TIURSTDT=$P($G(^XTMP("TIUP134","CHKPT")),U,1)
 ELSE  D
 . ;Initialize ^XTMP("TIUP134" if not re-start
 . S ^XTMP("TIUP134",0)=$$FMADD^XLFDT(DT,90)_U_DT
 . S ^XTMP("TIUP134","CNT","EX")=0 F TIUS=1:1:3 S ^XTMP("TIUP134","CNT","EX",TIUS)=0
 . S ^XTMP("TIUP134","CNT","LNK")=0
 . S ^XTMP("TIUP134","CNT","TOT")=0
 . S ^XTMP("TIUP134","CHKPT")=U_TIUBEGDT_U_TIUENDT
 K ^XTMP("TIUP134","STOP")
 S ^XTMP("TIUP134","T0")=$$NOW^XLFDT
 ;
 ;Loop through Entry Date/Time of documents by specified date range
 S TIUDT=$S($G(TIURSTDT):TIURSTDT,1:TIUBEGDT)
 F  S TIUDT=$O(^TIU(8925,"F",TIUDT)) Q:'TIUDT!(TIUDT>TIUENDT)!($G(ZTSTOP))  D
 . ;Loop through documents for Entry Date/Time
 . S TIUDA=0
 . F  S TIUDA=+$O(^TIU(8925,"F",TIUDT,TIUDA)) Q:'TIUDA  D LNKONE(TIUDA)
 . ;Set check point for Entry Date/Time
 . S $P(^XTMP("TIUP134","CHKPT"),U,1)=TIUDT
 . ;Check if user requested to stop task
 . I $$S^%ZTLOAD S ZTSTOP=1
 ;
LNKRNGQ ;Send bulletin, re-set check point and clean up variables
 I $G(ZTSTOP) S ^XTMP("TIUP134","STOP")=$$NOW^XLFDT
 S ^XTMP("TIUP134","T1")=$$NOW^XLFDT
 ;
 D MAIL^TIUP134P
 ;
 I '$G(ZTSTOP) S ^XTMP("TIUP134","CHKPT")=""
 K TIUBEGDT,TIUENDT,TIURSTDT
 Q
 ;
LNKONE(TIUDA) ;Entry point to automatically link one document to visit
 ; Input  -- TIUDA    TIU Document file (#8925) IEN
 ; Output -- None
 N TIUEX,TIUMVSTF,TIUVSIT
 ;
 ;Check if document can be linked
 I $D(^TIU(8925,TIUDA,0)),$P(^(0),U,3)'>0,$$CHKDOC(TIUDA) D
 . ;Get visit to associate with document
 . D GETVST(TIUDA,.TIUVSIT,.TIUMVSTF)
 . ;If only one visit update the document with the visit
 . I $G(TIUVSIT)>0,'$G(TIUMVSTF) D
 . . I $G(TIUVSIT),$$UPDVST^TIUPXAP2(TIUDA,TIUVSIT) D
 . . . ;Document linked to visit
 . . . D SETXTMP(TIUDA,,TIUVSIT)
 . . . ;Update kids that are addenda
 . . . D UPDKIDS(TIUDA,TIUVSIT)
 . . ELSE  D
 . . . ;Unable to automatically link - entry in use
 . . . D SETXTMP(TIUDA,2)
 . ELSE  D
 . . ;Unable to automatically link - multiple visits or no matching visit
 . . S TIUEX=$S($G(TIUMVSTF):1,1:3)
 . . D SETXTMP(TIUDA,TIUEX)
 S ^XTMP("TIUP134","CNT","TOT")=+$G(^XTMP("TIUP134","CNT","TOT"))+1
 Q
 ;
CHKDOC(TIUDA) ;Check if document can be auto-linked
 ; Input  -- TIUDA    TIU Document file (#8925) IEN
 ; Output -- 1=Can be linked and 0=Cannot be linked
 N TIUD0,TIUDPRM,Y
 ;
 ;Set variables
 S Y=0
 S TIUD0=$G(^TIU(8925,TIUDA,0))
 D DOCPRM^TIULC1(+TIUD0,.TIUDPRM)
 ;
 ;Capture method must be direct or remote
 I ("^D^R^")'[(U_$P($G(^TIU(8925,TIUDA,13)),U,3)_U) G CHKDOCQ
 ;
 ;Status must be uncosigned or completed or amended
 I ("^6^7^8^")'[(U_$P(TIUD0,U,5)_U) G CHKDOCQ
 ;
 ;Document must be signed
 I '+$G(^TIU(8925,TIUDA,15)) G CHKDOCQ
 ;
 ;Document cannot be a component
 I $P($G(TIUDPRM(0)),U,4)="CO" G CHKDOCQ
 ;
 ;Document cannot be associated with a disposition location
 I +$O(^PX(815,1,"DHL","B",+$P($G(^TIU(8925,TIUDA,12)),U,11),0)) G CHKDOCQ
 ;
 ;Document must be under progress notes class or consults
 I '+$$ISA^TIULX(+TIUD0,3),'+$$ISA^TIULX(+TIUD0,+$$CLASS^TIUCNSLT) G CHKDOCQ
 ;
 ;Check if workload should be entered and set auto-link flag to yes
 I $$WORKOK^TIUPXAP1(TIUDA),$$CHKWKL^TIUPXAP2(TIUDA,.TIUDPRM) S Y=1
CHKDOCQ Q +$G(Y)
 ;
GETVST(TIUDA,TIUVSIT,TIUMVSTF) ;Get visit to associate with document
 ; Input  -- TIUDA    TIU Document file (#8925) IEN
 ; Output -- TIUVSIT  Visit file (#9000010) IEN
 ;           TIUMVSTF Multiple Visit Flag
 ;                    1=Multiple Visits
 ;
 N TIUD0,TIUDFN,TIUEDT,TIUHL,TIUVSITS,TIUVSTR
 ;
 ;Set variables
 S TIUD0=$G(^TIU(8925,TIUDA,0))
 S TIUDFN=$P(TIUD0,U,2),TIUEDT=$P(TIUD0,U,7)
 S TIUHL=$P($G(^TIU(8925,TIUDA,12)),U,11)
 S TIUVSTR=TIUHL_";"_TIUEDT_";"_$P(TIUD0,U,13)
 ;
 ;Check if document is an addendum, if it is use visit of parent
 I +$$ISADDNDM^TIULC1(TIUDA) D  G GETVSTQ
 . I $D(^TIU(8925,+$P(TIUD0,U,6),0)),$P(^(0),U,3)>0 S TIUVSIT=$P(^(0),U,3)
 ;
 ;Check if a document has already been entered for the Vstring,
 ;if it has use the visit in the AVSTRV cross-reference
 I +$G(TIUVSTR),+$O(^TIU(8925,"AVSTRV",+TIUDFN,TIUVSTR,0))>0 D  G GETVSTQ:$G(TIUVSIT)>0
 . S TIUVSIT=+$O(^TIU(8925,"AVSTRV",+TIUDFN,TIUVSTR,0))
 . I $P($G(^AUPNVSIT(+TIUVSIT,0)),U,5)'=TIUDFN S TIUVSIT=""
 ;
 ;Check PCE for a visit
 S TIUVSITS=$$GETENC^PXAPI(TIUDFN,TIUEDT,TIUHL)
 I TIUVSITS>0 S TIUVSIT=+TIUVSITS
 ;
 ;Set a flag if multiple visits
 I $P(TIUVSITS,U,2)'="" S TIUMVSTF=1
GETVSTQ Q
 ;
SETXTMP(TIUDA,TIUEX,TIUVSIT) ;Set ^XTMP for entries processed
 ; Input  -- TIUDA    TIU Document file (#8925) IEN
 ;           TIUEX    Unable to automatically link Exception types:  (Optional)
 ;                    1=Multiple Visits
 ;                    2=Entry in Use
 ;                    3=No Matching Visit
 ;           TIUVSIT  Visit file (#9000010) IEN  (Optional)
 ; Output -- Set ^XTMP("TIUP134","LNK",TIUDA)=
 ;               1st piece= 1=Linked and 0=Not Linked
 ;               2nd piece= Exception type if not linked
 ;               3rd piece= Visit file (#9000010) IEN if linked
 I $G(TIUEX) D
 . S ^XTMP("TIUP134","LNK",TIUDA)=0_U_$G(TIUEX)
 . S ^XTMP("TIUP134","CNT","EX",TIUEX)=+$G(^XTMP("TIUP134","CNT","EX",TIUEX))+1
 . S ^XTMP("TIUP134","CNT","EX")=+$G(^XTMP("TIUP134","CNT","EX"))+1
 ELSE  D
 . S ^XTMP("TIUP134","LNK",TIUDA)=1_U_U_$G(TIUVSIT)
 . S ^XTMP("TIUP134","CNT","LNK")=+$G(^XTMP("TIUP134","CNT","LNK"))+1
 Q
 ;
UPDKIDS(TIUDA,TIUVSIT) ;Update visit for kids that are addenda
 ; Input  -- TIUDA    TIU Document file (#8925) IEN
 ;           TIUVSIT  Visit file (#9000010) IEN
 ; Output -- None
 N TIUKID
 S TIUKID=0
 F  S TIUKID=$O(^TIU(8925,"DAD",TIUDA,TIUKID)) Q:'TIUKID  D
 . I +$$ISADDNDM^TIULC1(TIUKID),$P($G(^TIU(8925,TIUKID,0)),U,3)'>0 D
 . . I $$UPDVST^TIUPXAP2(TIUKID,TIUVSIT) D
 . . . D SETXTMP(TIUKID,,TIUVSIT)
 . . ELSE  D
 . . . D SETXTMP(TIUKID,2)
 Q
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HTIUP134   8640     printed  Sep 23, 2025@20:19:05                                                                                                                                                                                                     Page 2
TIUP134   ;SLC/RMO - Post-Install for TIU*1*134 ;6/6/02@09:51:20
 +1       ;;1.0;Text Integration Utilities;**134**;Jun 20, 1997
 +2       ;
EN        ;Entry point to queue a job to automatically link the missing VISIT
 +1       ;field for a date range of documents
 +2        NEW TIUBEGDT,TIUENDT,ZTDESC,ZTIO,ZTRTN,ZTSAVE,ZTSK
 +3       ;
 +4        WRITE !!,"PATCH TIU*1*134"
 +5        WRITE !!,"Automatically Link the missing VISIT field for a date range of documents"
 +6        WRITE !!,"Documents must meet the following criteria to be linked:"
 +7        WRITE !,"- Date range cannot be before 10/1/98 or after 7/31/02"
 +8        WRITE !,"- Entry Date/Time is within the selected date range"
 +9        WRITE !,"- No visit has been associated with the document"
 +10       WRITE !,"- A visit exists to be associated with the document"
 +11       WRITE !,"- The capture method is direct or remote"
 +12       WRITE !,"- The status is uncosigned or completed or amended"
 +13       WRITE !,"- The document is under the progress notes class or consults"
 +14       WRITE !,"- The document has a signature date/time"
 +15       WRITE !,"- Workload data should be collected for the document"
 +16       WRITE !!,"  Special Note about Parameters:",!
 +17       WRITE !,"  The 'ASK DX/CPT ON ALL OPT VISITS' TIU Document parameter"
 +18       WRITE !,"  is not date sensitive so collecting workload is based on"
 +19       WRITE !,"  the value of this parameter at the time this routine is"
 +20       WRITE !,"  invoked rather than at the time the visit was created."
 +21      ;
 +22      ;Ask date range
 +23       IF '$$ASKRNG(.TIUBEGDT,.TIUENDT)
               GOTO ENQ
 +24      ;
 +25      ;Set variables
 +26       SET (ZTSAVE("TIUBEGDT"),ZTSAVE("TIUENDT"))=""
 +27       SET ZTRTN="LNKRNG^TIUP134"
           SET ZTIO=""
           SET ZTSAVE("DUZ")=""
 +28       SET ZTDESC="Automatically link missing VISIT field for File #8925 - Patch 134"
 +29       WRITE !
           DO ^%ZTLOAD
 +30       IF $GET(ZTSK)
               Begin DoDot:1
 +31               WRITE !!,"A task has been queued in the background and a bulletin will be sent"
 +32               WRITE !,"to you upon completion of the task or if the task is stopped."
 +33               WRITE !,"Please only run one date range at a time."
 +34               WRITE !!,"The task number is "_$GET(ZTSK)_"."
               End DoDot:1
ENQ        QUIT 
 +1       ;
ASKRNG(BEGDT,ENDT) ;Prompt for date range
 +1       ; Input  -- None
 +2       ; Output -- 1=Successful and 0=Failure
 +3       ;           BEGDT Begin Date
 +4       ;           ENDT  End Date
 +5        NEW DIRUT,DTOUT,DUOUT,Y
 +6        WRITE !!,"Please specify a date range:"
 +7        SET BEGDT=+$$READ^TIUU("DA^"_2981001_":"_3020731_":E","   Beginning: ")
 +8        IF +$DATA(DIRUT)!(BEGDT'>0)
               GOTO ASKRNGQ
 +9        SET ENDT=+$$READ^TIUU("DA^"_BEGDT_":"_3020731_":E","        Thru: ")_"."_235959
 +10       IF +$DATA(DIRUT)!(ENDT'>0)
               GOTO ASKRNGQ
 +11       SET Y=1
ASKRNGQ    QUIT +$GET(Y)
 +1       ;
LNKRNG    ;Entry point to automatically link a document to a visit for
 +1       ;a specified date range
 +2       ; Input  -- TIUBEGDT Begin Date
 +3       ;           TIUENDT  End Date
 +4       ; Output -- ^XTMP("TIUP134", Global
 +5        NEW TIUDA,TIUDT,TIURSTDT,TIUS
 +6       ;
 +7       ;Exit if required variables are not defined
 +8        IF '$GET(TIUBEGDT)!('$GET(TIUENDT))
               GOTO LNKRNGQ
 +9       ;
 +10      ;Initialize re-start if check point exists
 +11       IF +$GET(^XTMP("TIUP134","CHKPT"))
               Begin DoDot:1
 +12               SET TIURSTDT=$PIECE($GET(^XTMP("TIUP134","CHKPT")),U,1)
               End DoDot:1
 +13      IF '$TEST
               Begin DoDot:1
 +14      ;Initialize ^XTMP("TIUP134" if not re-start
 +15               SET ^XTMP("TIUP134",0)=$$FMADD^XLFDT(DT,90)_U_DT
 +16               SET ^XTMP("TIUP134","CNT","EX")=0
                   FOR TIUS=1:1:3
                       SET ^XTMP("TIUP134","CNT","EX",TIUS)=0
 +17               SET ^XTMP("TIUP134","CNT","LNK")=0
 +18               SET ^XTMP("TIUP134","CNT","TOT")=0
 +19               SET ^XTMP("TIUP134","CHKPT")=U_TIUBEGDT_U_TIUENDT
               End DoDot:1
 +20       KILL ^XTMP("TIUP134","STOP")
 +21       SET ^XTMP("TIUP134","T0")=$$NOW^XLFDT
 +22      ;
 +23      ;Loop through Entry Date/Time of documents by specified date range
 +24       SET TIUDT=$SELECT($GET(TIURSTDT):TIURSTDT,1:TIUBEGDT)
 +25       FOR 
               SET TIUDT=$ORDER(^TIU(8925,"F",TIUDT))
               if 'TIUDT!(TIUDT>TIUENDT)!($GET(ZTSTOP))
                   QUIT 
               Begin DoDot:1
 +26      ;Loop through documents for Entry Date/Time
 +27               SET TIUDA=0
 +28               FOR 
                       SET TIUDA=+$ORDER(^TIU(8925,"F",TIUDT,TIUDA))
                       if 'TIUDA
                           QUIT 
                       DO LNKONE(TIUDA)
 +29      ;Set check point for Entry Date/Time
 +30               SET $PIECE(^XTMP("TIUP134","CHKPT"),U,1)=TIUDT
 +31      ;Check if user requested to stop task
 +32               IF $$S^%ZTLOAD
                       SET ZTSTOP=1
               End DoDot:1
 +33      ;
LNKRNGQ   ;Send bulletin, re-set check point and clean up variables
 +1        IF $GET(ZTSTOP)
               SET ^XTMP("TIUP134","STOP")=$$NOW^XLFDT
 +2        SET ^XTMP("TIUP134","T1")=$$NOW^XLFDT
 +3       ;
 +4        DO MAIL^TIUP134P
 +5       ;
 +6        IF '$GET(ZTSTOP)
               SET ^XTMP("TIUP134","CHKPT")=""
 +7        KILL TIUBEGDT,TIUENDT,TIURSTDT
 +8        QUIT 
 +9       ;
LNKONE(TIUDA) ;Entry point to automatically link one document to visit
 +1       ; Input  -- TIUDA    TIU Document file (#8925) IEN
 +2       ; Output -- None
 +3        NEW TIUEX,TIUMVSTF,TIUVSIT
 +4       ;
 +5       ;Check if document can be linked
 +6        IF $DATA(^TIU(8925,TIUDA,0))
               IF $PIECE(^(0),U,3)'>0
                   IF $$CHKDOC(TIUDA)
                       Begin DoDot:1
 +7       ;Get visit to associate with document
 +8                        DO GETVST(TIUDA,.TIUVSIT,.TIUMVSTF)
 +9       ;If only one visit update the document with the visit
 +10                       IF $GET(TIUVSIT)>0
                               IF '$GET(TIUMVSTF)
                                   Begin DoDot:2
 +11                                   IF $GET(TIUVSIT)
                                           IF $$UPDVST^TIUPXAP2(TIUDA,TIUVSIT)
                                               Begin DoDot:3
 +12      ;Document linked to visit
 +13                                               DO SETXTMP(TIUDA,,TIUVSIT)
 +14      ;Update kids that are addenda
 +15                                               DO UPDKIDS(TIUDA,TIUVSIT)
                                               End DoDot:3
 +16                                  IF '$TEST
                                           Begin DoDot:3
 +17      ;Unable to automatically link - entry in use
 +18                                           DO SETXTMP(TIUDA,2)
                                           End DoDot:3
                                   End DoDot:2
 +19                      IF '$TEST
                               Begin DoDot:2
 +20      ;Unable to automatically link - multiple visits or no matching visit
 +21                               SET TIUEX=$SELECT($GET(TIUMVSTF):1,1:3)
 +22                               DO SETXTMP(TIUDA,TIUEX)
                               End DoDot:2
                       End DoDot:1
 +23       SET ^XTMP("TIUP134","CNT","TOT")=+$GET(^XTMP("TIUP134","CNT","TOT"))+1
 +24       QUIT 
 +25      ;
CHKDOC(TIUDA) ;Check if document can be auto-linked
 +1       ; Input  -- TIUDA    TIU Document file (#8925) IEN
 +2       ; Output -- 1=Can be linked and 0=Cannot be linked
 +3        NEW TIUD0,TIUDPRM,Y
 +4       ;
 +5       ;Set variables
 +6        SET Y=0
 +7        SET TIUD0=$GET(^TIU(8925,TIUDA,0))
 +8        DO DOCPRM^TIULC1(+TIUD0,.TIUDPRM)
 +9       ;
 +10      ;Capture method must be direct or remote
 +11       IF ("^D^R^")'[(U_$PIECE($GET(^TIU(8925,TIUDA,13)),U,3)_U)
               GOTO CHKDOCQ
 +12      ;
 +13      ;Status must be uncosigned or completed or amended
 +14       IF ("^6^7^8^")'[(U_$PIECE(TIUD0,U,5)_U)
               GOTO CHKDOCQ
 +15      ;
 +16      ;Document must be signed
 +17       IF '+$GET(^TIU(8925,TIUDA,15))
               GOTO CHKDOCQ
 +18      ;
 +19      ;Document cannot be a component
 +20       IF $PIECE($GET(TIUDPRM(0)),U,4)="CO"
               GOTO CHKDOCQ
 +21      ;
 +22      ;Document cannot be associated with a disposition location
 +23       IF +$ORDER(^PX(815,1,"DHL","B",+$PIECE($GET(^TIU(8925,TIUDA,12)),U,11),0))
               GOTO CHKDOCQ
 +24      ;
 +25      ;Document must be under progress notes class or consults
 +26       IF '+$$ISA^TIULX(+TIUD0,3)
               IF '+$$ISA^TIULX(+TIUD0,+$$CLASS^TIUCNSLT)
                   GOTO CHKDOCQ
 +27      ;
 +28      ;Check if workload should be entered and set auto-link flag to yes
 +29       IF $$WORKOK^TIUPXAP1(TIUDA)
               IF $$CHKWKL^TIUPXAP2(TIUDA,.TIUDPRM)
                   SET Y=1
CHKDOCQ    QUIT +$GET(Y)
 +1       ;
GETVST(TIUDA,TIUVSIT,TIUMVSTF) ;Get visit to associate with document
 +1       ; Input  -- TIUDA    TIU Document file (#8925) IEN
 +2       ; Output -- TIUVSIT  Visit file (#9000010) IEN
 +3       ;           TIUMVSTF Multiple Visit Flag
 +4       ;                    1=Multiple Visits
 +5       ;
 +6        NEW TIUD0,TIUDFN,TIUEDT,TIUHL,TIUVSITS,TIUVSTR
 +7       ;
 +8       ;Set variables
 +9        SET TIUD0=$GET(^TIU(8925,TIUDA,0))
 +10       SET TIUDFN=$PIECE(TIUD0,U,2)
           SET TIUEDT=$PIECE(TIUD0,U,7)
 +11       SET TIUHL=$PIECE($GET(^TIU(8925,TIUDA,12)),U,11)
 +12       SET TIUVSTR=TIUHL_";"_TIUEDT_";"_$PIECE(TIUD0,U,13)
 +13      ;
 +14      ;Check if document is an addendum, if it is use visit of parent
 +15       IF +$$ISADDNDM^TIULC1(TIUDA)
               Begin DoDot:1
 +16               IF $DATA(^TIU(8925,+$PIECE(TIUD0,U,6),0))
                       IF $PIECE(^(0),U,3)>0
                           SET TIUVSIT=$PIECE(^(0),U,3)
               End DoDot:1
               GOTO GETVSTQ
 +17      ;
 +18      ;Check if a document has already been entered for the Vstring,
 +19      ;if it has use the visit in the AVSTRV cross-reference
 +20       IF +$GET(TIUVSTR)
               IF +$ORDER(^TIU(8925,"AVSTRV",+TIUDFN,TIUVSTR,0))>0
                   Begin DoDot:1
 +21                   SET TIUVSIT=+$ORDER(^TIU(8925,"AVSTRV",+TIUDFN,TIUVSTR,0))
 +22                   IF $PIECE($GET(^AUPNVSIT(+TIUVSIT,0)),U,5)'=TIUDFN
                           SET TIUVSIT=""
                   End DoDot:1
                   if $GET(TIUVSIT)>0
                       GOTO GETVSTQ
 +23      ;
 +24      ;Check PCE for a visit
 +25       SET TIUVSITS=$$GETENC^PXAPI(TIUDFN,TIUEDT,TIUHL)
 +26       IF TIUVSITS>0
               SET TIUVSIT=+TIUVSITS
 +27      ;
 +28      ;Set a flag if multiple visits
 +29       IF $PIECE(TIUVSITS,U,2)'=""
               SET TIUMVSTF=1
GETVSTQ    QUIT 
 +1       ;
SETXTMP(TIUDA,TIUEX,TIUVSIT) ;Set ^XTMP for entries processed
 +1       ; Input  -- TIUDA    TIU Document file (#8925) IEN
 +2       ;           TIUEX    Unable to automatically link Exception types:  (Optional)
 +3       ;                    1=Multiple Visits
 +4       ;                    2=Entry in Use
 +5       ;                    3=No Matching Visit
 +6       ;           TIUVSIT  Visit file (#9000010) IEN  (Optional)
 +7       ; Output -- Set ^XTMP("TIUP134","LNK",TIUDA)=
 +8       ;               1st piece= 1=Linked and 0=Not Linked
 +9       ;               2nd piece= Exception type if not linked
 +10      ;               3rd piece= Visit file (#9000010) IEN if linked
 +11       IF $GET(TIUEX)
               Begin DoDot:1
 +12               SET ^XTMP("TIUP134","LNK",TIUDA)=0_U_$GET(TIUEX)
 +13               SET ^XTMP("TIUP134","CNT","EX",TIUEX)=+$GET(^XTMP("TIUP134","CNT","EX",TIUEX))+1
 +14               SET ^XTMP("TIUP134","CNT","EX")=+$GET(^XTMP("TIUP134","CNT","EX"))+1
               End DoDot:1
 +15      IF '$TEST
               Begin DoDot:1
 +16               SET ^XTMP("TIUP134","LNK",TIUDA)=1_U_U_$GET(TIUVSIT)
 +17               SET ^XTMP("TIUP134","CNT","LNK")=+$GET(^XTMP("TIUP134","CNT","LNK"))+1
               End DoDot:1
 +18       QUIT 
 +19      ;
UPDKIDS(TIUDA,TIUVSIT) ;Update visit for kids that are addenda
 +1       ; Input  -- TIUDA    TIU Document file (#8925) IEN
 +2       ;           TIUVSIT  Visit file (#9000010) IEN
 +3       ; Output -- None
 +4        NEW TIUKID
 +5        SET TIUKID=0
 +6        FOR 
               SET TIUKID=$ORDER(^TIU(8925,"DAD",TIUDA,TIUKID))
               if 'TIUKID
                   QUIT 
               Begin DoDot:1
 +7                IF +$$ISADDNDM^TIULC1(TIUKID)
                       IF $PIECE($GET(^TIU(8925,TIUKID,0)),U,3)'>0
                           Begin DoDot:2
 +8                            IF $$UPDVST^TIUPXAP2(TIUKID,TIUVSIT)
                                   Begin DoDot:3
 +9                                    DO SETXTMP(TIUKID,,TIUVSIT)
                                   End DoDot:3
 +10                          IF '$TEST
                                   Begin DoDot:3
 +11                                   DO SETXTMP(TIUKID,2)
                                   End DoDot:3
                           End DoDot:2
               End DoDot:1
 +12       QUIT