| 1 | TIUP134 ;SLC/RMO - Post-Install for TIU*1*134 ;6/6/02@09:51:20
 | 
|---|
| 2 |  ;;1.0;Text Integration Utilities;**134**;Jun 20, 1997
 | 
|---|
| 3 |  ;
 | 
|---|
| 4 | EN ;Entry point to queue a job to automatically link the missing VISIT
 | 
|---|
| 5 |  ;field for a date range of documents
 | 
|---|
| 6 |  N TIUBEGDT,TIUENDT,ZTDESC,ZTIO,ZTRTN,ZTSAVE,ZTSK
 | 
|---|
| 7 |  ;
 | 
|---|
| 8 |  W !!,"PATCH TIU*1*134"
 | 
|---|
| 9 |  W !!,"Automatically Link the missing VISIT field for a date range of documents"
 | 
|---|
| 10 |  W !!,"Documents must meet the following criteria to be linked:"
 | 
|---|
| 11 |  W !,"- Date range cannot be before 10/1/98 or after 7/31/02"
 | 
|---|
| 12 |  W !,"- Entry Date/Time is within the selected date range"
 | 
|---|
| 13 |  W !,"- No visit has been associated with the document"
 | 
|---|
| 14 |  W !,"- A visit exists to be associated with the document"
 | 
|---|
| 15 |  W !,"- The capture method is direct or remote"
 | 
|---|
| 16 |  W !,"- The status is uncosigned or completed or amended"
 | 
|---|
| 17 |  W !,"- The document is under the progress notes class or consults"
 | 
|---|
| 18 |  W !,"- The document has a signature date/time"
 | 
|---|
| 19 |  W !,"- Workload data should be collected for the document"
 | 
|---|
| 20 |  W !!,"  Special Note about Parameters:",!
 | 
|---|
| 21 |  W !,"  The 'ASK DX/CPT ON ALL OPT VISITS' TIU Document parameter"
 | 
|---|
| 22 |  W !,"  is not date sensitive so collecting workload is based on"
 | 
|---|
| 23 |  W !,"  the value of this parameter at the time this routine is"
 | 
|---|
| 24 |  W !,"  invoked rather than at the time the visit was created."
 | 
|---|
| 25 |  ;
 | 
|---|
| 26 |  ;Ask date range
 | 
|---|
| 27 |  I '$$ASKRNG(.TIUBEGDT,.TIUENDT) G ENQ
 | 
|---|
| 28 |  ;
 | 
|---|
| 29 |  ;Set variables
 | 
|---|
| 30 |  S (ZTSAVE("TIUBEGDT"),ZTSAVE("TIUENDT"))=""
 | 
|---|
| 31 |  S ZTRTN="LNKRNG^TIUP134",ZTIO="",ZTSAVE("DUZ")=""
 | 
|---|
| 32 |  S ZTDESC="Automatically link missing VISIT field for File #8925 - Patch 134"
 | 
|---|
| 33 |  W ! D ^%ZTLOAD
 | 
|---|
| 34 |  I $G(ZTSK) D
 | 
|---|
| 35 |  . W !!,"A task has been queued in the background and a bulletin will be sent"
 | 
|---|
| 36 |  . W !,"to you upon completion of the task or if the task is stopped."
 | 
|---|
| 37 |  . W !,"Please only run one date range at a time."
 | 
|---|
| 38 |  . W !!,"The task number is "_$G(ZTSK)_"."
 | 
|---|
| 39 | ENQ Q
 | 
|---|
| 40 |  ;
 | 
|---|
| 41 | ASKRNG(BEGDT,ENDT) ;Prompt for date range
 | 
|---|
| 42 |  ; Input  -- None
 | 
|---|
| 43 |  ; Output -- 1=Successful and 0=Failure
 | 
|---|
| 44 |  ;           BEGDT Begin Date
 | 
|---|
| 45 |  ;           ENDT  End Date
 | 
|---|
| 46 |  N DIRUT,DTOUT,DUOUT,Y
 | 
|---|
| 47 |  W !!,"Please specify a date range:"
 | 
|---|
| 48 |  S BEGDT=+$$READ^TIUU("DA^"_2981001_":"_3020731_":E","   Beginning: ")
 | 
|---|
| 49 |  I +$D(DIRUT)!(BEGDT'>0) G ASKRNGQ
 | 
|---|
| 50 |  S ENDT=+$$READ^TIUU("DA^"_BEGDT_":"_3020731_":E","        Thru: ")_"."_235959
 | 
|---|
| 51 |  I +$D(DIRUT)!(ENDT'>0) G ASKRNGQ
 | 
|---|
| 52 |  S Y=1
 | 
|---|
| 53 | ASKRNGQ Q +$G(Y)
 | 
|---|
| 54 |  ;
 | 
|---|
| 55 | LNKRNG ;Entry point to automatically link a document to a visit for
 | 
|---|
| 56 |  ;a specified date range
 | 
|---|
| 57 |  ; Input  -- TIUBEGDT Begin Date
 | 
|---|
| 58 |  ;           TIUENDT  End Date
 | 
|---|
| 59 |  ; Output -- ^XTMP("TIUP134", Global
 | 
|---|
| 60 |  N TIUDA,TIUDT,TIURSTDT,TIUS
 | 
|---|
| 61 |  ;
 | 
|---|
| 62 |  ;Exit if required variables are not defined
 | 
|---|
| 63 |  I '$G(TIUBEGDT)!('$G(TIUENDT)) G LNKRNGQ
 | 
|---|
| 64 |  ;
 | 
|---|
| 65 |  ;Initialize re-start if check point exists
 | 
|---|
| 66 |  I +$G(^XTMP("TIUP134","CHKPT")) D
 | 
|---|
| 67 |  . S TIURSTDT=$P($G(^XTMP("TIUP134","CHKPT")),U,1)
 | 
|---|
| 68 |  ELSE  D
 | 
|---|
| 69 |  . ;Initialize ^XTMP("TIUP134" if not re-start
 | 
|---|
| 70 |  . S ^XTMP("TIUP134",0)=$$FMADD^XLFDT(DT,90)_U_DT
 | 
|---|
| 71 |  . S ^XTMP("TIUP134","CNT","EX")=0 F TIUS=1:1:3 S ^XTMP("TIUP134","CNT","EX",TIUS)=0
 | 
|---|
| 72 |  . S ^XTMP("TIUP134","CNT","LNK")=0
 | 
|---|
| 73 |  . S ^XTMP("TIUP134","CNT","TOT")=0
 | 
|---|
| 74 |  . S ^XTMP("TIUP134","CHKPT")=U_TIUBEGDT_U_TIUENDT
 | 
|---|
| 75 |  K ^XTMP("TIUP134","STOP")
 | 
|---|
| 76 |  S ^XTMP("TIUP134","T0")=$$NOW^XLFDT
 | 
|---|
| 77 |  ;
 | 
|---|
| 78 |  ;Loop through Entry Date/Time of documents by specified date range
 | 
|---|
| 79 |  S TIUDT=$S($G(TIURSTDT):TIURSTDT,1:TIUBEGDT)
 | 
|---|
| 80 |  F  S TIUDT=$O(^TIU(8925,"F",TIUDT)) Q:'TIUDT!(TIUDT>TIUENDT)!($G(ZTSTOP))  D
 | 
|---|
| 81 |  . ;Loop through documents for Entry Date/Time
 | 
|---|
| 82 |  . S TIUDA=0
 | 
|---|
| 83 |  . F  S TIUDA=+$O(^TIU(8925,"F",TIUDT,TIUDA)) Q:'TIUDA  D LNKONE(TIUDA)
 | 
|---|
| 84 |  . ;Set check point for Entry Date/Time
 | 
|---|
| 85 |  . S $P(^XTMP("TIUP134","CHKPT"),U,1)=TIUDT
 | 
|---|
| 86 |  . ;Check if user requested to stop task
 | 
|---|
| 87 |  . I $$S^%ZTLOAD S ZTSTOP=1
 | 
|---|
| 88 |  ;
 | 
|---|
| 89 | LNKRNGQ ;Send bulletin, re-set check point and clean up variables
 | 
|---|
| 90 |  I $G(ZTSTOP) S ^XTMP("TIUP134","STOP")=$$NOW^XLFDT
 | 
|---|
| 91 |  S ^XTMP("TIUP134","T1")=$$NOW^XLFDT
 | 
|---|
| 92 |  ;
 | 
|---|
| 93 |  D MAIL^TIUP134P
 | 
|---|
| 94 |  ;
 | 
|---|
| 95 |  I '$G(ZTSTOP) S ^XTMP("TIUP134","CHKPT")=""
 | 
|---|
| 96 |  K TIUBEGDT,TIUENDT,TIURSTDT
 | 
|---|
| 97 |  Q
 | 
|---|
| 98 |  ;
 | 
|---|
| 99 | LNKONE(TIUDA) ;Entry point to automatically link one document to visit
 | 
|---|
| 100 |  ; Input  -- TIUDA    TIU Document file (#8925) IEN
 | 
|---|
| 101 |  ; Output -- None
 | 
|---|
| 102 |  N TIUEX,TIUMVSTF,TIUVSIT
 | 
|---|
| 103 |  ;
 | 
|---|
| 104 |  ;Check if document can be linked
 | 
|---|
| 105 |  I $D(^TIU(8925,TIUDA,0)),$P(^(0),U,3)'>0,$$CHKDOC(TIUDA) D
 | 
|---|
| 106 |  . ;Get visit to associate with document
 | 
|---|
| 107 |  . D GETVST(TIUDA,.TIUVSIT,.TIUMVSTF)
 | 
|---|
| 108 |  . ;If only one visit update the document with the visit
 | 
|---|
| 109 |  . I $G(TIUVSIT)>0,'$G(TIUMVSTF) D
 | 
|---|
| 110 |  . . I $G(TIUVSIT),$$UPDVST^TIUPXAP2(TIUDA,TIUVSIT) D
 | 
|---|
| 111 |  . . . ;Document linked to visit
 | 
|---|
| 112 |  . . . D SETXTMP(TIUDA,,TIUVSIT)
 | 
|---|
| 113 |  . . . ;Update kids that are addenda
 | 
|---|
| 114 |  . . . D UPDKIDS(TIUDA,TIUVSIT)
 | 
|---|
| 115 |  . . ELSE  D
 | 
|---|
| 116 |  . . . ;Unable to automatically link - entry in use
 | 
|---|
| 117 |  . . . D SETXTMP(TIUDA,2)
 | 
|---|
| 118 |  . ELSE  D
 | 
|---|
| 119 |  . . ;Unable to automatically link - multiple visits or no matching visit
 | 
|---|
| 120 |  . . S TIUEX=$S($G(TIUMVSTF):1,1:3)
 | 
|---|
| 121 |  . . D SETXTMP(TIUDA,TIUEX)
 | 
|---|
| 122 |  S ^XTMP("TIUP134","CNT","TOT")=+$G(^XTMP("TIUP134","CNT","TOT"))+1
 | 
|---|
| 123 |  Q
 | 
|---|
| 124 |  ;
 | 
|---|
| 125 | CHKDOC(TIUDA) ;Check if document can be auto-linked
 | 
|---|
| 126 |  ; Input  -- TIUDA    TIU Document file (#8925) IEN
 | 
|---|
| 127 |  ; Output -- 1=Can be linked and 0=Cannot be linked
 | 
|---|
| 128 |  N TIUD0,TIUDPRM,Y
 | 
|---|
| 129 |  ;
 | 
|---|
| 130 |  ;Set variables
 | 
|---|
| 131 |  S Y=0
 | 
|---|
| 132 |  S TIUD0=$G(^TIU(8925,TIUDA,0))
 | 
|---|
| 133 |  D DOCPRM^TIULC1(+TIUD0,.TIUDPRM)
 | 
|---|
| 134 |  ;
 | 
|---|
| 135 |  ;Capture method must be direct or remote
 | 
|---|
| 136 |  I ("^D^R^")'[(U_$P($G(^TIU(8925,TIUDA,13)),U,3)_U) G CHKDOCQ
 | 
|---|
| 137 |  ;
 | 
|---|
| 138 |  ;Status must be uncosigned or completed or amended
 | 
|---|
| 139 |  I ("^6^7^8^")'[(U_$P(TIUD0,U,5)_U) G CHKDOCQ
 | 
|---|
| 140 |  ;
 | 
|---|
| 141 |  ;Document must be signed
 | 
|---|
| 142 |  I '+$G(^TIU(8925,TIUDA,15)) G CHKDOCQ
 | 
|---|
| 143 |  ;
 | 
|---|
| 144 |  ;Document cannot be a component
 | 
|---|
| 145 |  I $P($G(TIUDPRM(0)),U,4)="CO" G CHKDOCQ
 | 
|---|
| 146 |  ;
 | 
|---|
| 147 |  ;Document cannot be associated with a disposition location
 | 
|---|
| 148 |  I +$O(^PX(815,1,"DHL","B",+$P($G(^TIU(8925,TIUDA,12)),U,11),0)) G CHKDOCQ
 | 
|---|
| 149 |  ;
 | 
|---|
| 150 |  ;Document must be under progress notes class or consults
 | 
|---|
| 151 |  I '+$$ISA^TIULX(+TIUD0,3),'+$$ISA^TIULX(+TIUD0,+$$CLASS^TIUCNSLT) G CHKDOCQ
 | 
|---|
| 152 |  ;
 | 
|---|
| 153 |  ;Check if workload should be entered and set auto-link flag to yes
 | 
|---|
| 154 |  I $$WORKOK^TIUPXAP1(TIUDA),$$CHKWKL^TIUPXAP2(TIUDA,.TIUDPRM) S Y=1
 | 
|---|
| 155 | CHKDOCQ Q +$G(Y)
 | 
|---|
| 156 |  ;
 | 
|---|
| 157 | GETVST(TIUDA,TIUVSIT,TIUMVSTF) ;Get visit to associate with document
 | 
|---|
| 158 |  ; Input  -- TIUDA    TIU Document file (#8925) IEN
 | 
|---|
| 159 |  ; Output -- TIUVSIT  Visit file (#9000010) IEN
 | 
|---|
| 160 |  ;           TIUMVSTF Multiple Visit Flag
 | 
|---|
| 161 |  ;                    1=Multiple Visits
 | 
|---|
| 162 |  ;
 | 
|---|
| 163 |  N TIUD0,TIUDFN,TIUEDT,TIUHL,TIUVSITS,TIUVSTR
 | 
|---|
| 164 |  ;
 | 
|---|
| 165 |  ;Set variables
 | 
|---|
| 166 |  S TIUD0=$G(^TIU(8925,TIUDA,0))
 | 
|---|
| 167 |  S TIUDFN=$P(TIUD0,U,2),TIUEDT=$P(TIUD0,U,7)
 | 
|---|
| 168 |  S TIUHL=$P($G(^TIU(8925,TIUDA,12)),U,11)
 | 
|---|
| 169 |  S TIUVSTR=TIUHL_";"_TIUEDT_";"_$P(TIUD0,U,13)
 | 
|---|
| 170 |  ;
 | 
|---|
| 171 |  ;Check if document is an addendum, if it is use visit of parent
 | 
|---|
| 172 |  I +$$ISADDNDM^TIULC1(TIUDA) D  G GETVSTQ
 | 
|---|
| 173 |  . I $D(^TIU(8925,+$P(TIUD0,U,6),0)),$P(^(0),U,3)>0 S TIUVSIT=$P(^(0),U,3)
 | 
|---|
| 174 |  ;
 | 
|---|
| 175 |  ;Check if a document has already been entered for the Vstring,
 | 
|---|
| 176 |  ;if it has use the visit in the AVSTRV cross-reference
 | 
|---|
| 177 |  I +$G(TIUVSTR),+$O(^TIU(8925,"AVSTRV",+TIUDFN,TIUVSTR,0))>0 D  G GETVSTQ:$G(TIUVSIT)>0
 | 
|---|
| 178 |  . S TIUVSIT=+$O(^TIU(8925,"AVSTRV",+TIUDFN,TIUVSTR,0))
 | 
|---|
| 179 |  . I $P($G(^AUPNVSIT(+TIUVSIT,0)),U,5)'=TIUDFN S TIUVSIT=""
 | 
|---|
| 180 |  ;
 | 
|---|
| 181 |  ;Check PCE for a visit
 | 
|---|
| 182 |  S TIUVSITS=$$GETENC^PXAPI(TIUDFN,TIUEDT,TIUHL)
 | 
|---|
| 183 |  I TIUVSITS>0 S TIUVSIT=+TIUVSITS
 | 
|---|
| 184 |  ;
 | 
|---|
| 185 |  ;Set a flag if multiple visits
 | 
|---|
| 186 |  I $P(TIUVSITS,U,2)'="" S TIUMVSTF=1
 | 
|---|
| 187 | GETVSTQ Q
 | 
|---|
| 188 |  ;
 | 
|---|
| 189 | SETXTMP(TIUDA,TIUEX,TIUVSIT) ;Set ^XTMP for entries processed
 | 
|---|
| 190 |  ; Input  -- TIUDA    TIU Document file (#8925) IEN
 | 
|---|
| 191 |  ;           TIUEX    Unable to automatically link Exception types:  (Optional)
 | 
|---|
| 192 |  ;                    1=Multiple Visits
 | 
|---|
| 193 |  ;                    2=Entry in Use
 | 
|---|
| 194 |  ;                    3=No Matching Visit
 | 
|---|
| 195 |  ;           TIUVSIT  Visit file (#9000010) IEN  (Optional)
 | 
|---|
| 196 |  ; Output -- Set ^XTMP("TIUP134","LNK",TIUDA)=
 | 
|---|
| 197 |  ;               1st piece= 1=Linked and 0=Not Linked
 | 
|---|
| 198 |  ;               2nd piece= Exception type if not linked
 | 
|---|
| 199 |  ;               3rd piece= Visit file (#9000010) IEN if linked
 | 
|---|
| 200 |  I $G(TIUEX) D
 | 
|---|
| 201 |  . S ^XTMP("TIUP134","LNK",TIUDA)=0_U_$G(TIUEX)
 | 
|---|
| 202 |  . S ^XTMP("TIUP134","CNT","EX",TIUEX)=+$G(^XTMP("TIUP134","CNT","EX",TIUEX))+1
 | 
|---|
| 203 |  . S ^XTMP("TIUP134","CNT","EX")=+$G(^XTMP("TIUP134","CNT","EX"))+1
 | 
|---|
| 204 |  ELSE  D
 | 
|---|
| 205 |  . S ^XTMP("TIUP134","LNK",TIUDA)=1_U_U_$G(TIUVSIT)
 | 
|---|
| 206 |  . S ^XTMP("TIUP134","CNT","LNK")=+$G(^XTMP("TIUP134","CNT","LNK"))+1
 | 
|---|
| 207 |  Q
 | 
|---|
| 208 |  ;
 | 
|---|
| 209 | UPDKIDS(TIUDA,TIUVSIT) ;Update visit for kids that are addenda
 | 
|---|
| 210 |  ; Input  -- TIUDA    TIU Document file (#8925) IEN
 | 
|---|
| 211 |  ;           TIUVSIT  Visit file (#9000010) IEN
 | 
|---|
| 212 |  ; Output -- None
 | 
|---|
| 213 |  N TIUKID
 | 
|---|
| 214 |  S TIUKID=0
 | 
|---|
| 215 |  F  S TIUKID=$O(^TIU(8925,"DAD",TIUDA,TIUKID)) Q:'TIUKID  D
 | 
|---|
| 216 |  . I +$$ISADDNDM^TIULC1(TIUKID),$P($G(^TIU(8925,TIUKID,0)),U,3)'>0 D
 | 
|---|
| 217 |  . . I $$UPDVST^TIUPXAP2(TIUKID,TIUVSIT) D
 | 
|---|
| 218 |  . . . D SETXTMP(TIUKID,,TIUVSIT)
 | 
|---|
| 219 |  . . ELSE  D
 | 
|---|
| 220 |  . . . D SETXTMP(TIUKID,2)
 | 
|---|
| 221 |  Q
 | 
|---|