TIUP149 ;SLC/RMO - Post-Install for TIU*1*149 ;10/28/02@09:51:20
;;1.0;Text Integration Utilities;**149**;Jun 20, 1997
;
EN ;Entry point to queue a job to clean up certain documents
;linked to a different patient's visit
N ZTDESC,ZTIO,ZTRTN,ZTSAVE,ZTSK
;
W !!,"PATCH TIU*1*149"
W !!,"Search ALL entries in the TIU Document file (#8925) to link or"
W !,"unlink documents associated with a different patient's visit that"
W !,"meet the following criteria:"
W !!,"- Addenda or components where the parent points to the correct visit will"
W !," be linked, otherwise the addenda or components will be unlinked if they"
W !," are associated with an incorrect visit different than the parent."
W !!,"- Documents where the capture method is converted and a visit"
W !," exists will be linked, otherwise the document will be unlinked"
W !," from the incorrect visit."
W !!,"- Documents where the reference date is prior to 10/1/98 will"
W !," be unlinked from the incorrect visit."
W !!,"- Documents that are Discharge Summaries will be unlinked"
W !," from the incorrect visit."
W !
;
;Set variables
S ZTRTN="CLNUP^TIUP149",ZTIO="",ZTSAVE("DUZ")=""
S ZTDESC="Clean up TIU Documents Different Patient's Visit - Patch 149"
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 !!,"The task number is "_$G(ZTSK)_"."
Q
;
CLNUP ;Entry point to clean up documents pointing to a different patient's
;visit
; Input -- None
; Output -- ^XTMP("TIUP149", Global
N NDBIF,TIUDA,TIUS,TIURSTDA
;
;Initialize re-start if check point exists
I +$G(^XTMP("TIUP149","CHKPT")) D
. S TIURSTDA=+$G(^XTMP("TIUP149","CHKPT"))
ELSE D
. ;Clean up ^XTMP("TIUP149")
. K ^XTMP("TIUP149"),^XTMP("TIU/PXAPI")
. ;Initialize ^XTMP("TIUP149" if not re-start
. S ^XTMP("TIUP149",0)=$$FMADD^XLFDT(DT,90)_U_DT
. S ^XTMP("TIUP149","CNT","EX")=0 F TIUS=1:1:3 S ^XTMP("TIUP149","CNT","EX",TIUS)=0
. S ^XTMP("TIUP149","CNT","LNK")=0
. S ^XTMP("TIUP149","CNT","TOT")=0
. S ^XTMP("TIUP149","CHKPT")=""
K ^XTMP("TIUP149","STOP")
S ^XTMP("TIUP149","T0")=$$NOW^XLFDT
;
;Set integrated facility NDBI flag
S NDBIF=$$CHKINF
;
;Loop through documents
S TIUDA=$S($G(TIURSTDA):TIURSTDA,1:0)
F S TIUDA=$O(^TIU(8925,TIUDA)) Q:+TIUDA'>0!($G(ZTSTOP)) I $D(^(TIUDA,0)) D
. ;Clean up visit for one document
. D CLNONE(TIUDA,$G(NDBIF))
. ;
. ;Set check point for Document IEN
. S ^XTMP("TIUP149","CHKPT")=TIUDA
. ;
. ;Check if user requested to stop task
. I $$S^%ZTLOAD S ZTSTOP=1
;
;Send bulletin, re-set check point and clean up variables
I $G(ZTSTOP) S ^XTMP("TIUP149","STOP")=$$NOW^XLFDT
S ^XTMP("TIUP149","T1")=$$NOW^XLFDT
;
D MAIL^TIUP149P
;
I '$G(ZTSTOP) S ^XTMP("TIUP149","CHKPT")=""
K TIURSTDA
Q
;
CHKINF() ;Check if Integrated Facility
; Input -- TIUDA TIU Document file (#8925) IEN
; Output -- 1=Yes and 0=No
N Y
S Y=0
I $$VERSION^XPDUTL("NDBI PRIMARY SYSTEM") S Y=1
Q +$G(Y)
;
CLNONE(TIUDA,NDBIF) ;Entry point to clean up visit for one document
; Input -- TIUDA TIU Document file (#8925) IEN
; NDBIF Integrated Facility Flag (Optional)
; Output -- None
N TIUD0,TIUDFN,TIUMVSTF,TIUVSIT,VSIT
;
;Set variables
S TIUD0=$G(^TIU(8925,TIUDA,0))
S TIUDFN=$P(TIUD0,U,2)
S TIUVSIT=$P(TIUD0,U,3)
;
;Check if document linked to a different patient's visit can be
;cleaned up
I TIUVSIT>0,TIUDFN>0,+$G(^AUPNVSIT(+TIUVSIT,0)),$P(^(0),U,5)'=TIUDFN,$$CHKDOC(TIUDA,+$P(TIUD0,U,6),+TIUD0) D
. ;Exclude NDBI records
. I TIUVSIT=1,$G(NDBIF) D SETXTMP(TIUDA,3) Q
. ;Get correct visit to associate with document
. D GETVST(TIUDA,TIUDFN,+$P(TIUD0,U,6),.VSIT,.TIUMVSTF)
. ;If only one visit update the document with the visit
. I $G(VSIT)>0,'$G(TIUMVSTF) D
. . I $G(VSIT),$$UPDVST^TIUPXAP2(TIUDA,VSIT) D
. . . ;Document linked to visit
. . . D SETXTMP(TIUDA,,VSIT)
. . . ;Update kids that are addenda or components
. . . D UPDKIDS(TIUDA,VSIT)
. . ELSE D
. . . ;Unable to correct - entry in use
. . . D SETXTMP(TIUDA,1)
. ELSE D
. . ;Unlink document from visit
. . I $$DELVST(TIUDA) D
. . . D SETXTMP(TIUDA,2)
. . . ;Update kids that are addenda or components
. . . D UPDKIDS(TIUDA)
. . ELSE D
. . . ;Unable to correct - entry in use
. . . D SETXTMP(TIUDA,1)
S ^XTMP("TIUP149","CNT","TOT")=+$G(^XTMP("TIUP149","CNT","TOT"))+1
Q
;
CHKDOC(TIUDA,TIUDAD,TITLE) ;Check if document can be cleaned up
; Input -- TIUDA TIU Document file (#8925) IEN
; TIUDAD TIU document file (#8925) Parent's IEN
; TITLE TIU Document Definition file (#8925.1) IEN
; Output -- 1=Can be cleaned up and 0=Cannot be cleaned up
N TIUD13,Y
;
;Set variables
S Y=0
S TIUD13=$G(^TIU(8925,TIUDA,13))
;
;If document is an addendum or component and the parent and child visit fields
;are different, set clean-up flag to yes
I +$$ISADDNDM^TIULC1(TIUDA)!(+$$ISCOMP^TIUBR(TIUDA)) D G CHKDOCQ
. I $P($G(^TIU(8925,+TIUDAD,0)),U,3)'=$P($G(^TIU(8925,TIUDA,0)),U,3) S Y=1
;
;If capture method is converted or reference date is before 10/1/98 or
;document is a discharge summary, set clean up flag to yes
I ("^C^")[(U_$P(TIUD13,U,3)_U)!(+TIUD13&(+TIUD13<2981001))!(+$$ISDS^TIULX(TITLE)) S Y=1
;
CHKDOCQ Q +$G(Y)
;
GETVST(TIUDA,TIUDFN,TIUDAD,VSIT,TIUMVSTF) ;Get visit to associate with document
; Input -- TIUDA TIU Document file (#8925) IEN
; TIUDFN Patient file (#2) IEN
; TIUDAD TIU document file (#8925) Parent's IEN
; Output -- VSIT Visit file (#9000010) IEN
; TIUMVSTF Multiple Visit Flag
; 1=Multiple Visits
;
N TIUD13,TIUDTM,TIUHL,VSITS
;
;Set variables
S TIUD13=$G(^TIU(8925,TIUDA,13))
S TIUHL=$P($G(^TIU(8925,TIUDA,12)),U,11)
;
;Check if document is an addendum or component, if it is use visit of parent
I +$$ISADDNDM^TIULC1(TIUDA)!(+$$ISCOMP^TIUBR(TIUDA)) D G GETVSTQ
. I $D(^TIU(8925,+TIUDAD,0)),$P(^(0),U,3)>0 S VSIT=$P(^(0),U,3) D
. . I $P($G(^AUPNVSIT(+VSIT,0)),U,5)'=TIUDFN S VSIT=""
;
;If document is converted, check PCE for a visit
I (("^C^")[(U_$P(TIUD13,U,3)_U)) D
. ;For DS use patient movement date/time, otherwise use reference date/time
. I +$$ISDS^TIULX(+$G(^TIU(8925,TIUDA,0))) D
. . I +$G(^TIU(8925,TIUDA,14))>0,+$G(^DGPM(+^(14),0))>0 S TIUDTM=+^(0)
. ELSE D
. . I +TIUD13>0 S TIUDTM=+TIUD13
. ;Check PCE for a visit
. I $G(TIUDTM) D
. . S VSITS=$$GETENC^PXAPI(TIUDFN,TIUDTM,TIUHL)
. . I VSITS>0 S VSIT=+VSITS
. . ;Set a flag if multiple visits
. . I $P(VSITS,U,2)'="" S TIUMVSTF=1
GETVSTQ Q
;
SETXTMP(TIUDA,TIUEX,VSIT) ;Set ^XTMP for entries processed
; Input -- TIUDA TIU Document file (#8925) IEN
; TIUEX Unable to correct Exception types: (Optional)
; 1=Entry in Use
; 2=Unlink Visit
; 3=NDBI Fix Needed
; VSIT Visit file (#9000010) IEN (Optional)
; Output -- Set ^XTMP("TIUP149","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("TIUP149","LNK",TIUDA)=0_U_$G(TIUEX)
. S ^XTMP("TIUP149","CNT","EX",TIUEX)=+$G(^XTMP("TIUP149","CNT","EX",TIUEX))+1
. S ^XTMP("TIUP149","CNT","EX")=+$G(^XTMP("TIUP149","CNT","EX"))+1
ELSE D
. S ^XTMP("TIUP149","LNK",TIUDA)=1_U_U_$G(VSIT)
. S ^XTMP("TIUP149","CNT","LNK")=+$G(^XTMP("TIUP149","CNT","LNK"))+1
Q
;
DELVST(TIUDA,ERROR) ;Delete Visit in TIU Document file #8925
; Input -- TIUDA TIU Document file (#8925) IEN
; Output -- 1=Successful and 0=Failure
; ERROR Error Message (Optional)
N DIERR,OKF,TIUFDA
;
;Update document with visit
S TIUFDA(8925,TIUDA_",",.03)="@"
L +^TIU(8925,TIUDA):1 I $T D
. D FILE^DIE("","TIUFDA","") L -^TIU(8925,TIUDA)
. S ERROR=$G(DIERR)
. S OKF=$S(+$G(ERROR):0,1:1)
ELSE D
. S OKF=0
DELVSTQ Q +$G(OKF)
;
UPDKIDS(TIUDA,VSIT) ;Update Visit for kids that are addenda or components
; Input -- TIUDA TIU Document file (#8925) IEN
; VSIT Visit file (#9000010) IEN (Optional)
; Output -- None
N TIUKID
S TIUKID=0
F S TIUKID=$O(^TIU(8925,"DAD",TIUDA,TIUKID)) Q:'TIUKID D
. ;If document is an addendum or component and visit of parent is different than visit of kid
. I (+$$ISADDNDM^TIULC1(TIUKID)!(+$$ISCOMP^TIUBR(TIUKID))),$G(VSIT)'=$P($G(^TIU(8925,TIUKID,0)),U,3) D
. . ;Link kid to visit
. . I $G(VSIT)>0 D
. . . I $$UPDVST^TIUPXAP2(TIUKID,VSIT) D
. . . . D SETXTMP(TIUKID,,VSIT)
. . . ELSE D
. . . . D SETXTMP(TIUKID,1)
. . ELSE D
. . . ;Unlink kid from visit
. . . I $$DELVST(TIUKID) D
. . . . D SETXTMP(TIUKID,2)
. . . ELSE D
. . . . D SETXTMP(TIUKID,1)
Q
TIUP149 ;SLC/RMO - Post-Install for TIU*1*149 ;10/28/02@09:51:20
+1 ;;1.0;Text Integration Utilities;**149**;Jun 20, 1997
+2 ;
EN ;Entry point to queue a job to clean up certain documents
+1 ;linked to a different patient's visit
+2 NEW ZTDESC,ZTIO,ZTRTN,ZTSAVE,ZTSK
+3 ;
+4 WRITE !!,"PATCH TIU*1*149"
+5 WRITE !!,"Search ALL entries in the TIU Document file (#8925) to link or"
+6 WRITE !,"unlink documents associated with a different patient's visit that"
+7 WRITE !,"meet the following criteria:"
+8 WRITE !!,"- Addenda or components where the parent points to the correct visit will"
+9 WRITE !," be linked, otherwise the addenda or components will be unlinked if they"
+10 WRITE !," are associated with an incorrect visit different than the parent."
+11 WRITE !!,"- Documents where the capture method is converted and a visit"
+12 WRITE !," exists will be linked, otherwise the document will be unlinked"
+13 WRITE !," from the incorrect visit."
+14 WRITE !!,"- Documents where the reference date is prior to 10/1/98 will"
+15 WRITE !," be unlinked from the incorrect visit."
+16 WRITE !!,"- Documents that are Discharge Summaries will be unlinked"
+17 WRITE !," from the incorrect visit."
+18 WRITE !
+19 ;
+20 ;Set variables
+21 SET ZTRTN="CLNUP^TIUP149"
SET ZTIO=""
SET ZTSAVE("DUZ")=""
+22 SET ZTDESC="Clean up TIU Documents Different Patient's Visit - Patch 149"
+23 DO ^%ZTLOAD
+24 IF $GET(ZTSK)
Begin DoDot:1
+25 WRITE !!,"A task has been queued in the background and a bulletin will be sent"
+26 WRITE !,"to you upon completion of the task or if the task is stopped."
+27 WRITE !!,"The task number is "_$GET(ZTSK)_"."
End DoDot:1
+28 QUIT
+29 ;
CLNUP ;Entry point to clean up documents pointing to a different patient's
+1 ;visit
+2 ; Input -- None
+3 ; Output -- ^XTMP("TIUP149", Global
+4 NEW NDBIF,TIUDA,TIUS,TIURSTDA
+5 ;
+6 ;Initialize re-start if check point exists
+7 IF +$GET(^XTMP("TIUP149","CHKPT"))
Begin DoDot:1
+8 SET TIURSTDA=+$GET(^XTMP("TIUP149","CHKPT"))
End DoDot:1
+9 IF '$TEST
Begin DoDot:1
+10 ;Clean up ^XTMP("TIUP149")
+11 KILL ^XTMP("TIUP149"),^XTMP("TIU/PXAPI")
+12 ;Initialize ^XTMP("TIUP149" if not re-start
+13 SET ^XTMP("TIUP149",0)=$$FMADD^XLFDT(DT,90)_U_DT
+14 SET ^XTMP("TIUP149","CNT","EX")=0
FOR TIUS=1:1:3
SET ^XTMP("TIUP149","CNT","EX",TIUS)=0
+15 SET ^XTMP("TIUP149","CNT","LNK")=0
+16 SET ^XTMP("TIUP149","CNT","TOT")=0
+17 SET ^XTMP("TIUP149","CHKPT")=""
End DoDot:1
+18 KILL ^XTMP("TIUP149","STOP")
+19 SET ^XTMP("TIUP149","T0")=$$NOW^XLFDT
+20 ;
+21 ;Set integrated facility NDBI flag
+22 SET NDBIF=$$CHKINF
+23 ;
+24 ;Loop through documents
+25 SET TIUDA=$SELECT($GET(TIURSTDA):TIURSTDA,1:0)
+26 FOR
SET TIUDA=$ORDER(^TIU(8925,TIUDA))
IF +TIUDA'>0!($GET(ZTSTOP))
QUIT
IF $DATA(^(TIUDA,0))
Begin DoDot:1
+27 ;Clean up visit for one document
+28 DO CLNONE(TIUDA,$GET(NDBIF))
+29 ;
+30 ;Set check point for Document IEN
+31 SET ^XTMP("TIUP149","CHKPT")=TIUDA
+32 ;
+33 ;Check if user requested to stop task
+34 IF $$S^%ZTLOAD
SET ZTSTOP=1
End DoDot:1
+35 ;
+36 ;Send bulletin, re-set check point and clean up variables
+37 IF $GET(ZTSTOP)
SET ^XTMP("TIUP149","STOP")=$$NOW^XLFDT
+38 SET ^XTMP("TIUP149","T1")=$$NOW^XLFDT
+39 ;
+40 DO MAIL^TIUP149P
+41 ;
+42 IF '$GET(ZTSTOP)
SET ^XTMP("TIUP149","CHKPT")=""
+43 KILL TIURSTDA
+44 QUIT
+45 ;
CHKINF() ;Check if Integrated Facility
+1 ; Input -- TIUDA TIU Document file (#8925) IEN
+2 ; Output -- 1=Yes and 0=No
+3 NEW Y
+4 SET Y=0
+5 IF $$VERSION^XPDUTL("NDBI PRIMARY SYSTEM")
SET Y=1
+6 QUIT +$GET(Y)
+7 ;
CLNONE(TIUDA,NDBIF) ;Entry point to clean up visit for one document
+1 ; Input -- TIUDA TIU Document file (#8925) IEN
+2 ; NDBIF Integrated Facility Flag (Optional)
+3 ; Output -- None
+4 NEW TIUD0,TIUDFN,TIUMVSTF,TIUVSIT,VSIT
+5 ;
+6 ;Set variables
+7 SET TIUD0=$GET(^TIU(8925,TIUDA,0))
+8 SET TIUDFN=$PIECE(TIUD0,U,2)
+9 SET TIUVSIT=$PIECE(TIUD0,U,3)
+10 ;
+11 ;Check if document linked to a different patient's visit can be
+12 ;cleaned up
+13 IF TIUVSIT>0
IF TIUDFN>0
IF +$GET(^AUPNVSIT(+TIUVSIT,0))
IF $PIECE(^(0),U,5)'=TIUDFN
IF $$CHKDOC(TIUDA,+$PIECE(TIUD0,U,6),+TIUD0)
Begin DoDot:1
+14 ;Exclude NDBI records
+15 IF TIUVSIT=1
IF $GET(NDBIF)
DO SETXTMP(TIUDA,3)
QUIT
+16 ;Get correct visit to associate with document
+17 DO GETVST(TIUDA,TIUDFN,+$PIECE(TIUD0,U,6),.VSIT,.TIUMVSTF)
+18 ;If only one visit update the document with the visit
+19 IF $GET(VSIT)>0
IF '$GET(TIUMVSTF)
Begin DoDot:2
+20 IF $GET(VSIT)
IF $$UPDVST^TIUPXAP2(TIUDA,VSIT)
Begin DoDot:3
+21 ;Document linked to visit
+22 DO SETXTMP(TIUDA,,VSIT)
+23 ;Update kids that are addenda or components
+24 DO UPDKIDS(TIUDA,VSIT)
End DoDot:3
+25 IF '$TEST
Begin DoDot:3
+26 ;Unable to correct - entry in use
+27 DO SETXTMP(TIUDA,1)
End DoDot:3
End DoDot:2
+28 IF '$TEST
Begin DoDot:2
+29 ;Unlink document from visit
+30 IF $$DELVST(TIUDA)
Begin DoDot:3
+31 DO SETXTMP(TIUDA,2)
+32 ;Update kids that are addenda or components
+33 DO UPDKIDS(TIUDA)
End DoDot:3
+34 IF '$TEST
Begin DoDot:3
+35 ;Unable to correct - entry in use
+36 DO SETXTMP(TIUDA,1)
End DoDot:3
End DoDot:2
End DoDot:1
+37 SET ^XTMP("TIUP149","CNT","TOT")=+$GET(^XTMP("TIUP149","CNT","TOT"))+1
+38 QUIT
+39 ;
CHKDOC(TIUDA,TIUDAD,TITLE) ;Check if document can be cleaned up
+1 ; Input -- TIUDA TIU Document file (#8925) IEN
+2 ; TIUDAD TIU document file (#8925) Parent's IEN
+3 ; TITLE TIU Document Definition file (#8925.1) IEN
+4 ; Output -- 1=Can be cleaned up and 0=Cannot be cleaned up
+5 NEW TIUD13,Y
+6 ;
+7 ;Set variables
+8 SET Y=0
+9 SET TIUD13=$GET(^TIU(8925,TIUDA,13))
+10 ;
+11 ;If document is an addendum or component and the parent and child visit fields
+12 ;are different, set clean-up flag to yes
+13 IF +$$ISADDNDM^TIULC1(TIUDA)!(+$$ISCOMP^TIUBR(TIUDA))
Begin DoDot:1
+14 IF $PIECE($GET(^TIU(8925,+TIUDAD,0)),U,3)'=$PIECE($GET(^TIU(8925,TIUDA,0)),U,3)
SET Y=1
End DoDot:1
GOTO CHKDOCQ
+15 ;
+16 ;If capture method is converted or reference date is before 10/1/98 or
+17 ;document is a discharge summary, set clean up flag to yes
+18 IF ("^C^")[(U_$PIECE(TIUD13,U,3)_U)!(+TIUD13&(+TIUD13<2981001))!(+$$ISDS^TIULX(TITLE))
SET Y=1
+19 ;
CHKDOCQ QUIT +$GET(Y)
+1 ;
GETVST(TIUDA,TIUDFN,TIUDAD,VSIT,TIUMVSTF) ;Get visit to associate with document
+1 ; Input -- TIUDA TIU Document file (#8925) IEN
+2 ; TIUDFN Patient file (#2) IEN
+3 ; TIUDAD TIU document file (#8925) Parent's IEN
+4 ; Output -- VSIT Visit file (#9000010) IEN
+5 ; TIUMVSTF Multiple Visit Flag
+6 ; 1=Multiple Visits
+7 ;
+8 NEW TIUD13,TIUDTM,TIUHL,VSITS
+9 ;
+10 ;Set variables
+11 SET TIUD13=$GET(^TIU(8925,TIUDA,13))
+12 SET TIUHL=$PIECE($GET(^TIU(8925,TIUDA,12)),U,11)
+13 ;
+14 ;Check if document is an addendum or component, if it is use visit of parent
+15 IF +$$ISADDNDM^TIULC1(TIUDA)!(+$$ISCOMP^TIUBR(TIUDA))
Begin DoDot:1
+16 IF $DATA(^TIU(8925,+TIUDAD,0))
IF $PIECE(^(0),U,3)>0
SET VSIT=$PIECE(^(0),U,3)
Begin DoDot:2
+17 IF $PIECE($GET(^AUPNVSIT(+VSIT,0)),U,5)'=TIUDFN
SET VSIT=""
End DoDot:2
End DoDot:1
GOTO GETVSTQ
+18 ;
+19 ;If document is converted, check PCE for a visit
+20 IF (("^C^")[(U_$PIECE(TIUD13,U,3)_U))
Begin DoDot:1
+21 ;For DS use patient movement date/time, otherwise use reference date/time
+22 IF +$$ISDS^TIULX(+$GET(^TIU(8925,TIUDA,0)))
Begin DoDot:2
+23 IF +$GET(^TIU(8925,TIUDA,14))>0
IF +$GET(^DGPM(+^(14),0))>0
SET TIUDTM=+^(0)
End DoDot:2
+24 IF '$TEST
Begin DoDot:2
+25 IF +TIUD13>0
SET TIUDTM=+TIUD13
End DoDot:2
+26 ;Check PCE for a visit
+27 IF $GET(TIUDTM)
Begin DoDot:2
+28 SET VSITS=$$GETENC^PXAPI(TIUDFN,TIUDTM,TIUHL)
+29 IF VSITS>0
SET VSIT=+VSITS
+30 ;Set a flag if multiple visits
+31 IF $PIECE(VSITS,U,2)'=""
SET TIUMVSTF=1
End DoDot:2
End DoDot:1
GETVSTQ QUIT
+1 ;
SETXTMP(TIUDA,TIUEX,VSIT) ;Set ^XTMP for entries processed
+1 ; Input -- TIUDA TIU Document file (#8925) IEN
+2 ; TIUEX Unable to correct Exception types: (Optional)
+3 ; 1=Entry in Use
+4 ; 2=Unlink Visit
+5 ; 3=NDBI Fix Needed
+6 ; VSIT Visit file (#9000010) IEN (Optional)
+7 ; Output -- Set ^XTMP("TIUP149","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("TIUP149","LNK",TIUDA)=0_U_$GET(TIUEX)
+13 SET ^XTMP("TIUP149","CNT","EX",TIUEX)=+$GET(^XTMP("TIUP149","CNT","EX",TIUEX))+1
+14 SET ^XTMP("TIUP149","CNT","EX")=+$GET(^XTMP("TIUP149","CNT","EX"))+1
End DoDot:1
+15 IF '$TEST
Begin DoDot:1
+16 SET ^XTMP("TIUP149","LNK",TIUDA)=1_U_U_$GET(VSIT)
+17 SET ^XTMP("TIUP149","CNT","LNK")=+$GET(^XTMP("TIUP149","CNT","LNK"))+1
End DoDot:1
+18 QUIT
+19 ;
DELVST(TIUDA,ERROR) ;Delete Visit in TIU Document file #8925
+1 ; Input -- TIUDA TIU Document file (#8925) IEN
+2 ; Output -- 1=Successful and 0=Failure
+3 ; ERROR Error Message (Optional)
+4 NEW DIERR,OKF,TIUFDA
+5 ;
+6 ;Update document with visit
+7 SET TIUFDA(8925,TIUDA_",",.03)="@"
+8 LOCK +^TIU(8925,TIUDA):1
IF $TEST
Begin DoDot:1
+9 DO FILE^DIE("","TIUFDA","")
LOCK -^TIU(8925,TIUDA)
+10 SET ERROR=$GET(DIERR)
+11 SET OKF=$SELECT(+$GET(ERROR):0,1:1)
End DoDot:1
+12 IF '$TEST
Begin DoDot:1
+13 SET OKF=0
End DoDot:1
DELVSTQ QUIT +$GET(OKF)
+1 ;
UPDKIDS(TIUDA,VSIT) ;Update Visit for kids that are addenda or components
+1 ; Input -- TIUDA TIU Document file (#8925) IEN
+2 ; VSIT Visit file (#9000010) IEN (Optional)
+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 document is an addendum or component and visit of parent is different than visit of kid
+8 IF (+$$ISADDNDM^TIULC1(TIUKID)!(+$$ISCOMP^TIUBR(TIUKID)))
IF $GET(VSIT)'=$PIECE($GET(^TIU(8925,TIUKID,0)),U,3)
Begin DoDot:2
+9 ;Link kid to visit
+10 IF $GET(VSIT)>0
Begin DoDot:3
+11 IF $$UPDVST^TIUPXAP2(TIUKID,VSIT)
Begin DoDot:4
+12 DO SETXTMP(TIUKID,,VSIT)
End DoDot:4
+13 IF '$TEST
Begin DoDot:4
+14 DO SETXTMP(TIUKID,1)
End DoDot:4
End DoDot:3
+15 IF '$TEST
Begin DoDot:3
+16 ;Unlink kid from visit
+17 IF $$DELVST(TIUKID)
Begin DoDot:4
+18 DO SETXTMP(TIUKID,2)
End DoDot:4
+19 IF '$TEST
Begin DoDot:4
+20 DO SETXTMP(TIUKID,1)
End DoDot:4
End DoDot:3
End DoDot:2
End DoDot:1
+21 QUIT