TIUDTBP0 ;AITC/CR/SGM - BOOKMARK TIU NOTE AFTER DOWNTIME ;8/20/18 4:02pm
 ;;1.0;TEXT INTEGRATION UTILITIES;**305**;JUN 20, 1997;Build 27
 ;
 ;  Last Edited: 09/22/2017 09:46 / Leidos/sgm
 ;  *** This routine only invoked by routine TIUDTBPN ***
 ;  Pertinent programmer notes at the end of this routine
 ;
 ; ICR Documentation for the TIUDTBP0 and TIUDTBPN routines
 ; ICR#    TYPE   DESCRIPTION
 ;-----  -------  -------------------------------------------
 ;  358  ContSub  File 405, Read access to fields and assoc. indexes
 ;                  Field #.02, transaction_type = 3^Discharge
 ;                              Cross_ref: ^DGPM("ATT3",d/t,da)=""
 ;                Flds: .01,.02,.04,.06,.07,.08,.09,.1,.11,.12,.18,.19
 ;  664  ContSub  DIVISION^VAUTOMA [TIU a subscriber]
 ; 1519  Sup      XUTMDEVQ: EN, $$NODEV
 ; 1557  Sup      $$ESBLOCK^XUSESIG1
 ; 2051  Sup      $$FIND1^DIC
 ; 2056  Sup      $$GET1^DIQ
 ; 2325  ContSub  $$CANDO^USRLA [TIU a subscriber]
 ; 2343  Sup      ^XUSER: $$ACTIVE, $$NAME, $$LOOKUP
 ; 3104  Private  File 8930.8, .01 field lookup of name
 ; 3869  ContSub  GETPLIST^SDAMA202 [TIU a subscriber]
 ;10006  Sup      ^DIC
 ;10026  Sup      ^DIR
 ;10028  Sup      EN^DIWE
 ;10035  Sup      File 2, multiple fields and their indexes
 ;                  fields: .01, .105, "ACA" index
 ;10039  Sup      File 42, Fileman lookup, fields .01, .015, 44
 ;10040  Sup      File 44, Fileman lookup, fields 2505,2506, "B" index
 ;10050  Sup      SIG^XUSESIG
 ;10060  Sup      File 200, all fields accessible by FM
 ;10061  Sup      IN5^VADPT
 ;10070  Sup      ^XMD
 ;10103  Sup      ^XLFDT: $$DOW, $$FMDIFF, $$FMTE, $$NOW
 ;10104  Sup      ^XLFSTR: $$CJ, $$UP
 ;10142  Sup      EN^DDIOL
 ;
 ;
 ;=====================================================================
 ;          DIC Lookup Module
 ;---------------------------------------------------------------------
DIC(LIN) ;  extrinsic function
 ; return -2:timeout, -1:'^'-out,  null/selection
 ; this calls returns the value of X
 N I,X,Y,DIC,DTOUT,DUOUT,LAB
 I LIN=1 D
 . ;   select note title
 . D TEXT("T2",1,12)
 . S DIC=8925.1,DIC(0)="AEMQ"
 . S DIC("S")="I $$GET1^DIQ(8925.1,+Y,1501)=""COMPUTER DOWNTIME"""
 . S Y=$$DICALL I Y>0 S TIUD("TITLE")=+Y,TIUD("TITLE",0)=$P(Y,U,2)
 . S X=(Y>0)
 . Q
 I LIN=2 D
 . ;   select signer/author of note, only active users
 . ;   with admin closure, author not required to be ASU certified
 . S DIC("S")="I +$$ACTIVE^XUSER(+Y)"
 . I TIUD("TYPE")="E" D
 . . N X,Y,EVENT,STAT,TX
 . . S STAT=$$FIND1(8925.6,,,"UNSIGNED") Q:STAT<1
 . . S EVENT=$$FIND1(8930.8,,,"SIGNATURE") Q:STAT<1
 . . S X=",$$CANDO^USRLA("_TIUD("TITLE")_","_STAT_","_EVENT_",+Y)"
 . . S DIC("S")=DIC("S")_X
 . . D TEXT("T15",0,0,0,0,,.TX) M DIC("A")=TX
 . . Q
 . S DIC=200,DIC(0)="AEMQ"
 . S DIC("A")="Who will be the AUTHOR of the note? "
 . S DIC("B")=$$UP^XLFSTR($$NAME^XUSER(DUZ,"F"))
 . S Y=$$DICALL I Y>0 S TIUD("SIGN")=+Y,TIUD("SIGN",0)=$P(Y,U,2)
 . S X=(Y>0)
 . Q
 I LIN=3 D
 . ;  select clinics to get notes
 . I $G(TIUD("CLSEL"))'=1 S X=1 Q
 . N INC,TIUDIC
 . S TIUDIC=44,TIUDIC(0)="QAEM"
 . S TIUDIC("A")="Select HOSPITAL LOCATION for Outpatient Notes: "
 . S X=TIUD("TIMS"),Y=TIUD("TIME")
 . S TIUDIC("S")="I $$DIC31^TIUDTBP0"
 . ;    this FOR loop will actually get all the selected locations
 . F INC=1:1 D  Q:Y<1
 . . K DIC M DIC=TIUDIC
 . . S Y=$$DICALL Q:Y<1  S TIUD("CLSEL",+Y)=$P(Y,U,2)
 . . I INC=1 S TIUDIC("A")="Select another HOSPITAL LOCATION: "
 . . Q
 . S X=+$O(TIUD("CLSEL",0)) ;   if no clinics selected, abort
 . Q
 I LIN=4 D
 . ;  select mail recipients
 . N INC,TIUDIC
 . D TEXT("T4",1,,,3)
 . S TIUDIC=200,TIUDIC(0)="QAEM"
 . S X="I $S($D(TIUD(""MAIL"",+Y)):0,DUZ=+Y:0,(Y>0&(Y<1)):1,1:$$ACTIVE^XUSER(+Y))>0"
 . S TIUDIC("S")=X
 . S Y=0 F INC=1:1 D  Q:Y<.5
 . . K DIC M DIC=TIUDIC
 . . S Y=$$DICALL Q:Y<.5  S TIUD("MAIL",+Y)=$P(Y,U,2)
 . . I INC=1 S TIUDIC("A")="Select another NEW PERSON NAME: "
 . . Q
 . S X=$S(Y<-1:0,1:1) I X S TIUD("MAIL",DUZ)=""
 . Q
 Q X
 ;
DICALL() ;
 N X,Y,D0,DA,DTOUT,DUOUT
 D ^DIC S:$D(DTOUT) Y=-3 S:$D(DUOUT) Y=-2
 Q Y
 ;
DIC31() ;
 ;  Called from ^DIC("S"), naked is set and Y is ien
 ;  Expects TIUD("TIMS") & TIUD("TIME")
 ;  If no date range, default to T @0000 - @2400
 ;  "I" node is inactive_dt^reactivated_dt
 ;  Do not allow selection of a clinic more than once
 ;  Return 1 if clinic is allowed
 N Z,ED,ST
 S ST=+$G(TIUD("TIMS")) I 'ST S ST=DT
 S ED=+$G(TIUD("TIME")) S:ED<ST ED=ST S:ED?7N ED=ED+.25
 S Z=$G(^("I"))
 S ST(0)=+Z,ED(0)=+$P(Z,U,2)
 I $D(TIUD("CLSEL",+Y)) S Z=0 ;  prevent picking twice
 I 'ST(0) S Z=1
 I ST(0)>0 D  ;                  has inactive date
 . I ST(0)'<ED S Z=1 Q  ;        inactive>downtime_end
 . I 'ED(0),ST(0)'>ST S Z=0 Q  ; inactive =< downtime start, no react
 . I ED(0),ED(0)'>ST S Z=1 Q  ;  reactivate =< downtime start
 . S Z=1 ;                    inact>downtime_start,react<downtime_end
 . Q
 Q Z
 ;
 ;=====================================================================
 ;          DIR PROMPTER
 ;=====================================================================
DIR(LIN) ;  extrinsic function
 ;  call returns the value of X
 ;  -3:timeout, -2:'^'-out,  null or value
 N X,Y,DIR,DIROUT,DIRUT,DTOUT,DUOUT
 I LIN=1 D
 . S DIR(0)="SOA^S:SCHEDULED;U:UNSCHEDULED"
 . S DIR("A")="Was the downtime (S)cheduled or (U)nscheduled? "
 . S X=0,Y=$$DIRCALL I $S(Y'?1U:0,"SU"'[Y:0,1:1) D  S Y=1
 . . S TIUD("SCH")=Y,TIUD("SCH",0)=$S(Y="S":"A ",1:"An un")_"scheduled"
 . . Q
 . S X=(Y=1)
 . Q
 I LIN=2 D
 . S X=$G(TIUD("TIMS"))
 . S DIR(0)="DOA^:"_$E($$NOW^XLFDT,1,12)_":AEPR"
 . S DIR("A")="What was the starting time of the outage? "
 . S X=0,Y=$$DIRCALL
 . I Y>0 S TIUD("TIMS")=Y,TIUD("TIMS",0)=$$DIRTIM(Y)
 . S X=(Y>0)
 . Q
 I LIN=3 D
 . N MAX,MIN
 . S X=$G(TIUD("TIMS")),(MAX,MIN)=""
 . S MIN=$G(TIUD("TIMS")),MAX=$E($$NOW^XLFDT,1,12)
 . S DIR(0)="DOA^"_MIN_":"_MAX_":AEPR"
 . S DIR("A")="What was the ending time of the outage? "
 . S X=0,Y=$$DIRCALL
 . I Y>0 S TIUD("TIME")=Y,TIUD("TIME",0)=$$DIRTIM(Y)
 . S X=(Y>0)
 . Q
 I LIN=4 D
 . S DIR(0)="DOA^::AETP"
 . S DIR("A")="What shall the Date/Time of the Note be? "
 . S DIR("B")="NOW"
 . S Y=$$DIRCALL S:Y>0 Y=$E(Y,1,12)
 . I Y>0 S TIUD("NOTEDT")=Y,TIUD("NOTEDT",0)=$$FMTE^XLFDT(Y)
 . S X=(Y>0)
 . Q
 I LIN=5 D
 . N TIUR
 . D TEXT("T3",,,,0,,.TIUR)
 . ; Outpatient word added at the request of business owner, 7-11-18, after demo 
 . S X="SO^A:All Outpatient Clinics;S:Selected Outpatient Clinics;N:No Outpatient Clinics"
 . S DIR(0)=X
 . S DIR("A")="File Notes for Outpatient Clinics? [A/S/N]"
 . S DIR("A",1)="In addition to Inpatients,"  ;added per business owner request 7-11-18
 . S DIR("?")=TIUR(6)
 . F I=1:1:5 S DIR("?",I)="   "_TIUR(I)
 . S Y=$$DIRCALL,X=0
 . I Y?1U,"ANS"[Y S TIUD("CLSEL")=$S(Y="N":0,Y="S":1,1:2),X=1
 . Q
 I LIN=6 D
 . ;    type of sig, esig or admin close
 . S TIUD("TYPE")="A",X=1
 . Q
 . ;
 . S DIR(0)=$$DIT(1),DIR("A")=$$DIT(2)
 . S Y=$$DIRCALL I Y?1U,"AE"[Y S TIUD("TYPE")=Y
 . S X=$S(Y'?1U:0,1:"AE"[Y)
 . Q
 I LIN=7 D
 . ;    edit text of note?
 . N I,J,GLX,LN,TX
 . S GLX=$NA(^TMP("TIUDT",$J)) K @GLX
 . S @GLX@(1,0)="Date/Time of Note:  "_TIUD("NOTEDT",0)
 . D TEXT("T7",0,0,0,0,,.TX)
 . S LN=1 F I=1:1:3 S LN=LN+1,@GLX@(LN,0)=TX(I)
 . F I=1:1 Q:'$D(TEXT(3,I))  S LN=LN+1,@GLX@(LN,0)=TEXT(3,I,0)
 . D EN^DDIOL(,GLX) K @GLX
 . S DIR(0)="Y",DIR("A")="Do you wish to edit the text",DIR("B")="No"
 . S X=$$DIRCALL
 . Q
 I LIN=8 D
 . S DIR(0)="Y",DIR("B")="No"
 . S DIR("A")="Do you wish to edit the text further"
 . S X=$$DIRCALL
 . Q
 I LIN=9 D
 . N TIUX
 . D TEXT("T14",1,0,1,,,.TIUX)
 . S DIR(0)="YOA",DIR("B")="Yes"  ; changed default from 'No' to 'Yes', per business owner request, 7-11-18
 . S DIR("?")="   " M DIR("?")=TIUX
 . S DIR("A")="Queue the report to Taskman?  "
 . S X=$$DIRCALL
 . Q
 Q X
 ;
DIRCALL() ;
 N X,Y,DIROUT,DIRUT,DTOUT,DUOUT
 W ! D ^DIR S:$D(DTOUT) Y=-3 S:$D(DUOUT) Y=-2
 Q Y
 ;
DIRTIM(Y) Q $$DOW^XLFDT(Y)_", "_$TR($$FMTE^XLFDT(Y),"@"," ")
 ;
DIT(L) ;
 ;;SA^E:ELECTRONIC SIGNATURE (/es/);A:ADMINSTRATIVE CLOSURE (/ac/)
 ;;Close notes by (E)lectronic Signature or (A)dministrative Closure? 
 Q $P($T(DIT+L),";",3,9)
 ;
 ;=====================================================================
 ;          Other Prompts
 ;=====================================================================
 ;
DIVISION() ;
 ;      if only one inpatient division, don't ask
 ;      VAUTOMA returns: Y=-1 or Y=1
 ;                       VAUTD = 0:if divisions selected
 ;                               1:if selected "ALL" divisions
 ;      TIUD("DIV")= 0:if multiple divisions selected
 ;                   1:if there is only one division
 ;                   2:all divisions
 ;      TIUD("DIV",ien)=division name, only if TIUD("DIV")=0
 N I,X,Y,VAUTD
 I $$CNTDIV^TIUUTL2=1 S TIUD("DIV")=1 Q 1
 D TEXT("T5",1,,,3) D DIVISION^VAUTOMA
 I Y<0!('$D(VAUTD)) Q -1
 S VAUTD=$S(VAUTD>0:2,1:0)
 M TIUD("DIV")=VAUTD
 Q 1
 ;
FIND1(FILE,IEN,FLG,VAL,IDX,SCR) ;
 N I,X,Y,DIERR,TIUER
 S FILE=$G(FILE),IEN=$G(IEN),FLG=$G(FLG),VAL=$G(VAL)
 I FLG="" S FLG="QX"
 I 'FILE!'$L(VAL) Q -1
 S Y=$$FIND1^DIC(FILE,IEN,FLG,VAL,.IDX,.SCR,"TIUER")
 I $D(DIERR) S Y=-1
 Q Y
 ;
GET1(FILE,IEN,FLD,FLG) ;
 N I,X,Y,DA,DIC,DIERR,TIUER
 S FILE=$G(FILE),FLD=$G(FLD),FLG=$G(FLG),IEN=$G(IEN)
 S:$E(IEN,$L(IEN))'="," IEN=IEN_","
 I 'FILE!'IEN!'FLD Q ""
 S X=$$GET1^DIQ(FILE,IEN,FLD,$G(FLG),,"TIUER")
 I $D(DIERR) S X=""
 Q X
 ;
 ;=====================================================================
 ;          Programmer Tools for Troubleshooting
 ;=====================================================================
TEST ;   programmer testing
 N EFORM,ERRON,NOKILL S (EFORM,ERRON,NOKILL)=1
 D START^TIUDTBPN
 Q
 ;
SAVE ;   save local and global variables to ^XTMP
 N I,X,GL
 S X=$$FMADD^XLFDT(DT,8)_U_DT_U
 S GL=$NA(^XTMP("TIUDTBP0")) L +@GL:5 E  Q
 S I=1+$P($G(@GL@(0)),U,3) S ^(0)=X_I L -@GL
 S @GL@(I)=$$NOW^XLFDT
 M @GL@(I,"VAR","TIUD")=TIUD
 S @GL@(I,"VAR","ZTSK")=$G(ZTSK)
 S @GL@(I,"VAR","DUZ")=DUZ
 M @GL@(I,"VAR-G","TMP")=@GLT
 Q
 ;
 ;=====================================================================
 ;          Generic Text Handler
 ;=====================================================================
 ; this program is not expecting the text lines to contain a ';' char.
 ; if there is formatting codes, they will be in the 3rd ';'-piece.
 ;
TEXT(TAG,WR,LF,CLR,PAD,CHR,TIUR) ;
 ; TAG - line label containing the text
 ;       all groups of text should end with ' ;;---'
 ;  WR - Boolean, write or do not write
 ;  LF - 0:no extra line feeds; 1:leading line feed; 2:trailing feed
 ; CLR - Boolean, clear screen first
 ; PAD - number of spaces begin each line with
 ;       If PAD="" then default to 3.  If PAD=0 then no padding
 ; CHR - for center justify, character to pad line, default is space
 ;.TIUR  - return array for text if desired (.TIUR(i)=text)
 ;
 N I,J,X,Y,FMT,LEN,SP
 S TAG=$G(TAG),WR=+$G(WR),LF=+$G(LF),CLR=+$G(CLR)
 S CHR=$G(CHR) S:CHR="" CHR=" "
 S PAD=$G(PAD) I PAD'?1.N S PAD=3
 S LEN=IOM S:'LEN LEN=80
 S $P(SP," ",LEN)=""
 S I=0 F J=1:1 S X=$T(@TAG+J) Q:X=" ;;---"  D
 . S I=I+1,X=$P(X,";",3,99),FMT=""
 . I X?1U1";".E S FMT=$E(X),X=$P(X,";",2,99)
 . I FMT="C" S X=$$CJ^XLFSTR(" "_X_" ",LEN,CHR)
 . I FMT="R" S X=$$RJ^XLFSTR(X,LEN,CHR)
 . I FMT="",PAD S X=$E(SP,1,PAD)_X
 . S TIUR(I)=X
 . I FMT="C" S I=I+1,TIUR(I)=" "
 . Q
 I WR W:CLR @IOF W:LF[1 ! F Y=1:1:I W !,TIUR(Y) I I=Y,LF[2 W !
 Q
 ;
T1 ;
 ;;C;Bookmark Progress Note after a Downtime
 ;;This is the utility to add a bookmark to the progress note of
 ;;each patient's electronic record after a VistA downtime.
 ;;
 ;;You will be asked a few questions, and then the utility
 ;;will place the note on the patient's record.
 ;;
 ;;---
T2 ;
 ;;Select the PROGRESS NOTE TITLE to be used for filing contingency
 ;;downtime bookmark progress notes.  The selected title must be mapped
 ;;to the VHA ENTERPRISE STANDARD TITLE of COMPUTER DOWNTIME
 ;;---
T3 ;
 ;;This option will look for all outpatients with visits that occured
 ;;during the downtime period.  You have the option to select visits
 ;;from (A)ll clinics or (S)elected clinics or (N)o clinics.
 ;;If Selected clinics is chosen, then only visits which have been
 ;;CHECKED OUT will be candidates for filing a downtime note.
 ;;   
 ;;---
T4 ;
 ;;In addition to yourself, who shall receive email notification
 ;;of this event?
 ;;---
T5 ;
 ;;Select DIVISION(s) to use when the task selects inpatients to file notes...
 ;;---
T61 ;
 ;;C;Potential Interruption in Electronic Medical Record Keeping  
 ;;|SU| interruption in access to the electronic medical records
 ;;occurred for |DUR| between:
 ;;     |ST| and |END|
 ;;
 ;;---
T62 ;
 ;;Before, during and after this period of downtime, medical record
 ;;documentation may have been collected on paper.  Documents such as
 ;;progress notes, orders, results, medication administration records
 ;;(MAR) and procedure reports may have been collected, but may not be
 ;;reflected in the electronic record or they may be scanned into the
 ;;record at a later date.
 ;;---
T7 ;
 ;;Creating TIU note text, you will have an opportunity to edit the text
 ;;The progress note will be generated with the following text:
 ;;  
 ;;---
T8 ;
 ;;     
 ;;The note(s) will have the following administrative closure (not a signature):
 ;;---
T9 ;
 ;;   
 ;;The note(s) will be signed with the following electronic signature:
 ;;---
T10 ;
 ;;You will now be asked for an electronic signature to begin this process.
 ;;If you are the author of the note, your signature will be appended.
 ;;Otherwise, the AUTHOR/SIGNER will get VistA alerts for each note.
 ;;---
T11 ;
 ;;You will now be asked for an electronic signature to begin this process.
 ;;This is a security measure to start the background task, but it is not used
 ;;to sign the notes themselves.  If you are not the AUTHOR, your name will
 ;;show for the administrative closure, but not as the author of the note.
 ;;---
T12 ;
 ;;You don't have an Electronic Signature Code on file, quitting...
 ;;---
T13 ;
 ;;You have 60 seconds/try and a maximum of 3 attempts to enter a proper code.
 ;;---
T14 ;
 ;;You can choose to queue this report to Taskman or you may run the
 ;;report to your terminal now.  In either case, a Mailman message will
 ;;be generated listing the patients who had a downtime note filed to
 ;;their medical record.
 ;;
 ;;If you choose to run this report to your terminal, you will see a
 ;;display of each patient found showing patient name, location, and
 ;;filing status of the note.
 ;;
 ;;If you do not choose to queue this report, your terminal could be
 ;;tied up for some time depending upon the inpatient and outpatient
 ;;volume seen during the downtime.
 ;;
 ;;---
T15 ;
 ;;The Author/Signer of these TIU notes must be authorized in ASU to
 ;;sign for this type of TIU Document.
 ;;  
 ;;---
T16 ;
 ;; Note  |                            |
 ;; Filed | Location                   | Patient Name
 ;;-------|----------------------------|-----------------------------------
 ;;---
T17 ;
 ;;Now generating progress notes for inpatients ...
 ;;Now generating progress notes for discharged patients ...
 ;;Now generating progress notes for outpatient clinics ...
 ;;---
 ;
 ;=====================================================================
 ;     PROGRAMMER NOTES
 ;---------------------------------------------------------------------
 ;Patch 305 - local, class III code remediated to national class I
 ; some class III original options left in code but are never executed
 ; in case in the future the VA decided it wants those original options
 ;    DIR(6) - always return admin closure
 ;    Programmer error tools
 ;      If +ERRON is defined, append output from ^TIUPNAPI call
 ;      If +NOKILL then do not kill off temp globals upon exit
 ;      If +EFORM then email has columnar versus delimited format
 ;
 ;Description of temporary global structure
 ;-------------------------------------------------------------------
 ;                                   DIV=file 4 ien
 ;     HLN=hospital location name     HL=file 44 ien
 ;     PNM=patient name              DFN=file 2 ien
 ;     WNM=ward name                WARD=file 42 ien
 ;  STATUS = p1[^p2]
 ;   p1 = Successful;Unsuccessful;Successful/unsigned;Error
 ;   p2 = [TIU_note extrinsic function return value]
 ; GLT = $NA(^TMP("TIUDTBPN",$J)
 ;@GLT@("DSP",TYP,inc)=display line    [Sort TYP = 1,2,3]
 ;@GLT@("F",2,DFN) = DFN^PNM
 ;@GLT@("F",42,s3) = WARD^WNM^DIV^HL  {s3 = WARD or WNM}
 ;@GLT@("F",44,HL) = HL^HLN^DIV
 ;@GLT@("SORT",1,WARD,PNM,DFN)="" for current inpatients
 ;@GLT@("SORT",2,PNM,DFN,DATE)="" for discharge patients
 ;@GLT@("SORT",3,PNM,DFN,DATE)=HL_U_HLN for outpatients
 ;    List of findings for mail message
 ;@GLT@("MSG",PNM,DFN,HLN,inc)=STATUS  [class III format  - p1]
 ;@GLT@("MSG",PNM,DFN,HLN,inc)=STATUS  [remediated format - p1^p2]
 ;@GLT@("SEND",0) = fm wp header
 ;@GLT@("SEND",inc,0) = line inc in mail message
 ;Merge @GLT@("VAR")=TIUD
 ;
 ;Notes on Find Patients modules to create a TIU note
 ;---------------------------------------------------------------------
 ;GETINP -  get all current inpatients whose admit<downtime_endtime
 ;   use admit movement xref as possible to admit without a ward
 ;   division check only done on inpatients
 ;
 ;GETINPD:
 ; Find any inpatients who were discharged during downtime by checking
 ; discharge movements using FOR loop on discharge movement xref.
 ;     Downtime_start '< discharge date.time < now
 ;     ^DGPM("AMV"_TT,Date,Patient,DA)
 ;
 ;INPCOM - common code for both current and discharged inpatients
 ;   Validate non-patient data, get iens, divisions, locations
 ;   Let IN5^VADPT determine if patient was an inpatient
 ;     check if patient was an inpatient at appropriate time
 ;     .VAIP - Both an input and output parameter
 ;     input: optional, VAIP("D")=<fmdt to find assoc. patient move>
 ;                                default to the end of downtime
 ; Output:
 ;   VAIP(1)    = movement ien
 ;   VAIP(2)    = trans type (1^admit 2^transfer 3^discharge...)
 ;   VAIP(5)    = ien^ward_name
 ;   VAIP(13)   = ien of admission movement
 ;   VAIP(13,4) = ien^ward_name
 ;   VAIP(17)   = ien of discharge movement
 ;   VAIP(17,4) = ien^ward_name
 ;
 ;GETOUT - Search for outpatient appts, get latest appt dt only
 ;  $$SDAPI^SDAMA301 retrieves ALL outpatients with filters applied
 ;     $$SDAPI returns -1, 0, # of records
 ;     Returns ^TMP($J,"SDAMA301",dfn,appt)= p1^p2^p3^p4 where
 ;     p1 = FM appt dt
 ;     p2 = clinic ien ; clinic name
 ;     p3 = R;SCHEDULED/KEPT  or  I;INPATIENT  or  NT;NO ACTION TAKEN
 ;     p4 = dfn ; patient name
 ;  Move and sort output from $$SDAPI
 ;  This only generates one note per patient based on location at
 ;     end of downtime
 ;  TIU API to create note kills ^TMP($J)
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HTIUDTBP0   19298     printed  Sep 23, 2025@20:16:09                                                                                                                                                                                                   Page 2
TIUDTBP0  ;AITC/CR/SGM - BOOKMARK TIU NOTE AFTER DOWNTIME ;8/20/18 4:02pm
 +1       ;;1.0;TEXT INTEGRATION UTILITIES;**305**;JUN 20, 1997;Build 27
 +2       ;
 +3       ;  Last Edited: 09/22/2017 09:46 / Leidos/sgm
 +4       ;  *** This routine only invoked by routine TIUDTBPN ***
 +5       ;  Pertinent programmer notes at the end of this routine
 +6       ;
 +7       ; ICR Documentation for the TIUDTBP0 and TIUDTBPN routines
 +8       ; ICR#    TYPE   DESCRIPTION
 +9       ;-----  -------  -------------------------------------------
 +10      ;  358  ContSub  File 405, Read access to fields and assoc. indexes
 +11      ;                  Field #.02, transaction_type = 3^Discharge
 +12      ;                              Cross_ref: ^DGPM("ATT3",d/t,da)=""
 +13      ;                Flds: .01,.02,.04,.06,.07,.08,.09,.1,.11,.12,.18,.19
 +14      ;  664  ContSub  DIVISION^VAUTOMA [TIU a subscriber]
 +15      ; 1519  Sup      XUTMDEVQ: EN, $$NODEV
 +16      ; 1557  Sup      $$ESBLOCK^XUSESIG1
 +17      ; 2051  Sup      $$FIND1^DIC
 +18      ; 2056  Sup      $$GET1^DIQ
 +19      ; 2325  ContSub  $$CANDO^USRLA [TIU a subscriber]
 +20      ; 2343  Sup      ^XUSER: $$ACTIVE, $$NAME, $$LOOKUP
 +21      ; 3104  Private  File 8930.8, .01 field lookup of name
 +22      ; 3869  ContSub  GETPLIST^SDAMA202 [TIU a subscriber]
 +23      ;10006  Sup      ^DIC
 +24      ;10026  Sup      ^DIR
 +25      ;10028  Sup      EN^DIWE
 +26      ;10035  Sup      File 2, multiple fields and their indexes
 +27      ;                  fields: .01, .105, "ACA" index
 +28      ;10039  Sup      File 42, Fileman lookup, fields .01, .015, 44
 +29      ;10040  Sup      File 44, Fileman lookup, fields 2505,2506, "B" index
 +30      ;10050  Sup      SIG^XUSESIG
 +31      ;10060  Sup      File 200, all fields accessible by FM
 +32      ;10061  Sup      IN5^VADPT
 +33      ;10070  Sup      ^XMD
 +34      ;10103  Sup      ^XLFDT: $$DOW, $$FMDIFF, $$FMTE, $$NOW
 +35      ;10104  Sup      ^XLFSTR: $$CJ, $$UP
 +36      ;10142  Sup      EN^DDIOL
 +37      ;
 +38      ;
 +39      ;=====================================================================
 +40      ;          DIC Lookup Module
 +41      ;---------------------------------------------------------------------
DIC(LIN)  ;  extrinsic function
 +1       ; return -2:timeout, -1:'^'-out,  null/selection
 +2       ; this calls returns the value of X
 +3        NEW I,X,Y,DIC,DTOUT,DUOUT,LAB
 +4        IF LIN=1
               Begin DoDot:1
 +5       ;   select note title
 +6                DO TEXT("T2",1,12)
 +7                SET DIC=8925.1
                   SET DIC(0)="AEMQ"
 +8                SET DIC("S")="I $$GET1^DIQ(8925.1,+Y,1501)=""COMPUTER DOWNTIME"""
 +9                SET Y=$$DICALL
                   IF Y>0
                       SET TIUD("TITLE")=+Y
                       SET TIUD("TITLE",0)=$PIECE(Y,U,2)
 +10               SET X=(Y>0)
 +11               QUIT 
               End DoDot:1
 +12       IF LIN=2
               Begin DoDot:1
 +13      ;   select signer/author of note, only active users
 +14      ;   with admin closure, author not required to be ASU certified
 +15               SET DIC("S")="I +$$ACTIVE^XUSER(+Y)"
 +16               IF TIUD("TYPE")="E"
                       Begin DoDot:2
 +17                       NEW X,Y,EVENT,STAT,TX
 +18                       SET STAT=$$FIND1(8925.6,,,"UNSIGNED")
                           if STAT<1
                               QUIT 
 +19                       SET EVENT=$$FIND1(8930.8,,,"SIGNATURE")
                           if STAT<1
                               QUIT 
 +20                       SET X=",$$CANDO^USRLA("_TIUD("TITLE")_","_STAT_","_EVENT_",+Y)"
 +21                       SET DIC("S")=DIC("S")_X
 +22                       DO TEXT("T15",0,0,0,0,,.TX)
                           MERGE DIC("A")=TX
 +23                       QUIT 
                       End DoDot:2
 +24               SET DIC=200
                   SET DIC(0)="AEMQ"
 +25               SET DIC("A")="Who will be the AUTHOR of the note? "
 +26               SET DIC("B")=$$UP^XLFSTR($$NAME^XUSER(DUZ,"F"))
 +27               SET Y=$$DICALL
                   IF Y>0
                       SET TIUD("SIGN")=+Y
                       SET TIUD("SIGN",0)=$PIECE(Y,U,2)
 +28               SET X=(Y>0)
 +29               QUIT 
               End DoDot:1
 +30       IF LIN=3
               Begin DoDot:1
 +31      ;  select clinics to get notes
 +32               IF $GET(TIUD("CLSEL"))'=1
                       SET X=1
                       QUIT 
 +33               NEW INC,TIUDIC
 +34               SET TIUDIC=44
                   SET TIUDIC(0)="QAEM"
 +35               SET TIUDIC("A")="Select HOSPITAL LOCATION for Outpatient Notes: "
 +36               SET X=TIUD("TIMS")
                   SET Y=TIUD("TIME")
 +37               SET TIUDIC("S")="I $$DIC31^TIUDTBP0"
 +38      ;    this FOR loop will actually get all the selected locations
 +39               FOR INC=1:1
                       Begin DoDot:2
 +40                       KILL DIC
                           MERGE DIC=TIUDIC
 +41                       SET Y=$$DICALL
                           if Y<1
                               QUIT 
                           SET TIUD("CLSEL",+Y)=$PIECE(Y,U,2)
 +42                       IF INC=1
                               SET TIUDIC("A")="Select another HOSPITAL LOCATION: "
 +43                       QUIT 
                       End DoDot:2
                       if Y<1
                           QUIT 
 +44      ;   if no clinics selected, abort
                   SET X=+$ORDER(TIUD("CLSEL",0))
 +45               QUIT 
               End DoDot:1
 +46       IF LIN=4
               Begin DoDot:1
 +47      ;  select mail recipients
 +48               NEW INC,TIUDIC
 +49               DO TEXT("T4",1,,,3)
 +50               SET TIUDIC=200
                   SET TIUDIC(0)="QAEM"
 +51               SET X="I $S($D(TIUD(""MAIL"",+Y)):0,DUZ=+Y:0,(Y>0&(Y<1)):1,1:$$ACTIVE^XUSER(+Y))>0"
 +52               SET TIUDIC("S")=X
 +53               SET Y=0
                   FOR INC=1:1
                       Begin DoDot:2
 +54                       KILL DIC
                           MERGE DIC=TIUDIC
 +55                       SET Y=$$DICALL
                           if Y<.5
                               QUIT 
                           SET TIUD("MAIL",+Y)=$PIECE(Y,U,2)
 +56                       IF INC=1
                               SET TIUDIC("A")="Select another NEW PERSON NAME: "
 +57                       QUIT 
                       End DoDot:2
                       if Y<.5
                           QUIT 
 +58               SET X=$SELECT(Y<-1:0,1:1)
                   IF X
                       SET TIUD("MAIL",DUZ)=""
 +59               QUIT 
               End DoDot:1
 +60       QUIT X
 +61      ;
DICALL()  ;
 +1        NEW X,Y,D0,DA,DTOUT,DUOUT
 +2        DO ^DIC
           if $DATA(DTOUT)
               SET Y=-3
           if $DATA(DUOUT)
               SET Y=-2
 +3        QUIT Y
 +4       ;
DIC31()   ;
 +1       ;  Called from ^DIC("S"), naked is set and Y is ien
 +2       ;  Expects TIUD("TIMS") & TIUD("TIME")
 +3       ;  If no date range, default to T @0000 - @2400
 +4       ;  "I" node is inactive_dt^reactivated_dt
 +5       ;  Do not allow selection of a clinic more than once
 +6       ;  Return 1 if clinic is allowed
 +7        NEW Z,ED,ST
 +8        SET ST=+$GET(TIUD("TIMS"))
           IF 'ST
               SET ST=DT
 +9        SET ED=+$GET(TIUD("TIME"))
           if ED<ST
               SET ED=ST
           if ED?7N
               SET ED=ED+.25
 +10       SET Z=$GET(^("I"))
 +11       SET ST(0)=+Z
           SET ED(0)=+$PIECE(Z,U,2)
 +12      ;  prevent picking twice
           IF $DATA(TIUD("CLSEL",+Y))
               SET Z=0
 +13       IF 'ST(0)
               SET Z=1
 +14      ;                  has inactive date
           IF ST(0)>0
               Begin DoDot:1
 +15      ;        inactive>downtime_end
                   IF ST(0)'<ED
                       SET Z=1
                       QUIT 
 +16      ; inactive =< downtime start, no react
                   IF 'ED(0)
                       IF ST(0)'>ST
                           SET Z=0
                           QUIT 
 +17      ;  reactivate =< downtime start
                   IF ED(0)
                       IF ED(0)'>ST
                           SET Z=1
                           QUIT 
 +18      ;                    inact>downtime_start,react<downtime_end
                   SET Z=1
 +19               QUIT 
               End DoDot:1
 +20       QUIT Z
 +21      ;
 +22      ;=====================================================================
 +23      ;          DIR PROMPTER
 +24      ;=====================================================================
DIR(LIN)  ;  extrinsic function
 +1       ;  call returns the value of X
 +2       ;  -3:timeout, -2:'^'-out,  null or value
 +3        NEW X,Y,DIR,DIROUT,DIRUT,DTOUT,DUOUT
 +4        IF LIN=1
               Begin DoDot:1
 +5                SET DIR(0)="SOA^S:SCHEDULED;U:UNSCHEDULED"
 +6                SET DIR("A")="Was the downtime (S)cheduled or (U)nscheduled? "
 +7                SET X=0
                   SET Y=$$DIRCALL
                   IF $SELECT(Y'?1U:0,"SU"'[Y:0,1:1)
                       Begin DoDot:2
 +8                        SET TIUD("SCH")=Y
                           SET TIUD("SCH",0)=$SELECT(Y="S":"A ",1:"An un")_"scheduled"
 +9                        QUIT 
                       End DoDot:2
                       SET Y=1
 +10               SET X=(Y=1)
 +11               QUIT 
               End DoDot:1
 +12       IF LIN=2
               Begin DoDot:1
 +13               SET X=$GET(TIUD("TIMS"))
 +14               SET DIR(0)="DOA^:"_$EXTRACT($$NOW^XLFDT,1,12)_":AEPR"
 +15               SET DIR("A")="What was the starting time of the outage? "
 +16               SET X=0
                   SET Y=$$DIRCALL
 +17               IF Y>0
                       SET TIUD("TIMS")=Y
                       SET TIUD("TIMS",0)=$$DIRTIM(Y)
 +18               SET X=(Y>0)
 +19               QUIT 
               End DoDot:1
 +20       IF LIN=3
               Begin DoDot:1
 +21               NEW MAX,MIN
 +22               SET X=$GET(TIUD("TIMS"))
                   SET (MAX,MIN)=""
 +23               SET MIN=$GET(TIUD("TIMS"))
                   SET MAX=$EXTRACT($$NOW^XLFDT,1,12)
 +24               SET DIR(0)="DOA^"_MIN_":"_MAX_":AEPR"
 +25               SET DIR("A")="What was the ending time of the outage? "
 +26               SET X=0
                   SET Y=$$DIRCALL
 +27               IF Y>0
                       SET TIUD("TIME")=Y
                       SET TIUD("TIME",0)=$$DIRTIM(Y)
 +28               SET X=(Y>0)
 +29               QUIT 
               End DoDot:1
 +30       IF LIN=4
               Begin DoDot:1
 +31               SET DIR(0)="DOA^::AETP"
 +32               SET DIR("A")="What shall the Date/Time of the Note be? "
 +33               SET DIR("B")="NOW"
 +34               SET Y=$$DIRCALL
                   if Y>0
                       SET Y=$EXTRACT(Y,1,12)
 +35               IF Y>0
                       SET TIUD("NOTEDT")=Y
                       SET TIUD("NOTEDT",0)=$$FMTE^XLFDT(Y)
 +36               SET X=(Y>0)
 +37               QUIT 
               End DoDot:1
 +38       IF LIN=5
               Begin DoDot:1
 +39               NEW TIUR
 +40               DO TEXT("T3",,,,0,,.TIUR)
 +41      ; Outpatient word added at the request of business owner, 7-11-18, after demo 
 +42               SET X="SO^A:All Outpatient Clinics;S:Selected Outpatient Clinics;N:No Outpatient Clinics"
 +43               SET DIR(0)=X
 +44               SET DIR("A")="File Notes for Outpatient Clinics? [A/S/N]"
 +45      ;added per business owner request 7-11-18
                   SET DIR("A",1)="In addition to Inpatients,"
 +46               SET DIR("?")=TIUR(6)
 +47               FOR I=1:1:5
                       SET DIR("?",I)="   "_TIUR(I)
 +48               SET Y=$$DIRCALL
                   SET X=0
 +49               IF Y?1U
                       IF "ANS"[Y
                           SET TIUD("CLSEL")=$SELECT(Y="N":0,Y="S":1,1:2)
                           SET X=1
 +50               QUIT 
               End DoDot:1
 +51       IF LIN=6
               Begin DoDot:1
 +52      ;    type of sig, esig or admin close
 +53               SET TIUD("TYPE")="A"
                   SET X=1
 +54               QUIT 
 +55      ;
 +56               SET DIR(0)=$$DIT(1)
                   SET DIR("A")=$$DIT(2)
 +57               SET Y=$$DIRCALL
                   IF Y?1U
                       IF "AE"[Y
                           SET TIUD("TYPE")=Y
 +58               SET X=$SELECT(Y'?1U:0,1:"AE"[Y)
 +59               QUIT 
               End DoDot:1
 +60       IF LIN=7
               Begin DoDot:1
 +61      ;    edit text of note?
 +62               NEW I,J,GLX,LN,TX
 +63               SET GLX=$NAME(^TMP("TIUDT",$JOB))
                   KILL @GLX
 +64               SET @GLX@(1,0)="Date/Time of Note:  "_TIUD("NOTEDT",0)
 +65               DO TEXT("T7",0,0,0,0,,.TX)
 +66               SET LN=1
                   FOR I=1:1:3
                       SET LN=LN+1
                       SET @GLX@(LN,0)=TX(I)
 +67               FOR I=1:1
                       if '$DATA(TEXT(3,I))
                           QUIT 
                       SET LN=LN+1
                       SET @GLX@(LN,0)=TEXT(3,I,0)
 +68               DO EN^DDIOL(,GLX)
                   KILL @GLX
 +69               SET DIR(0)="Y"
                   SET DIR("A")="Do you wish to edit the text"
                   SET DIR("B")="No"
 +70               SET X=$$DIRCALL
 +71               QUIT 
               End DoDot:1
 +72       IF LIN=8
               Begin DoDot:1
 +73               SET DIR(0)="Y"
                   SET DIR("B")="No"
 +74               SET DIR("A")="Do you wish to edit the text further"
 +75               SET X=$$DIRCALL
 +76               QUIT 
               End DoDot:1
 +77       IF LIN=9
               Begin DoDot:1
 +78               NEW TIUX
 +79               DO TEXT("T14",1,0,1,,,.TIUX)
 +80      ; changed default from 'No' to 'Yes', per business owner request, 7-11-18
                   SET DIR(0)="YOA"
                   SET DIR("B")="Yes"
 +81               SET DIR("?")="   "
                   MERGE DIR("?")=TIUX
 +82               SET DIR("A")="Queue the report to Taskman?  "
 +83               SET X=$$DIRCALL
 +84               QUIT 
               End DoDot:1
 +85       QUIT X
 +86      ;
DIRCALL() ;
 +1        NEW X,Y,DIROUT,DIRUT,DTOUT,DUOUT
 +2        WRITE !
           DO ^DIR
           if $DATA(DTOUT)
               SET Y=-3
           if $DATA(DUOUT)
               SET Y=-2
 +3        QUIT Y
 +4       ;
DIRTIM(Y)  QUIT $$DOW^XLFDT(Y)_", "_$TRANSLATE($$FMTE^XLFDT(Y),"@"," ")
 +1       ;
DIT(L)    ;
 +1       ;;SA^E:ELECTRONIC SIGNATURE (/es/);A:ADMINSTRATIVE CLOSURE (/ac/)
 +2       ;;Close notes by (E)lectronic Signature or (A)dministrative Closure? 
 +3        QUIT $PIECE($TEXT(DIT+L),";",3,9)
 +4       ;
 +5       ;=====================================================================
 +6       ;          Other Prompts
 +7       ;=====================================================================
 +8       ;
DIVISION() ;
 +1       ;      if only one inpatient division, don't ask
 +2       ;      VAUTOMA returns: Y=-1 or Y=1
 +3       ;                       VAUTD = 0:if divisions selected
 +4       ;                               1:if selected "ALL" divisions
 +5       ;      TIUD("DIV")= 0:if multiple divisions selected
 +6       ;                   1:if there is only one division
 +7       ;                   2:all divisions
 +8       ;      TIUD("DIV",ien)=division name, only if TIUD("DIV")=0
 +9        NEW I,X,Y,VAUTD
 +10       IF $$CNTDIV^TIUUTL2=1
               SET TIUD("DIV")=1
               QUIT 1
 +11       DO TEXT("T5",1,,,3)
           DO DIVISION^VAUTOMA
 +12       IF Y<0!('$DATA(VAUTD))
               QUIT -1
 +13       SET VAUTD=$SELECT(VAUTD>0:2,1:0)
 +14       MERGE TIUD("DIV")=VAUTD
 +15       QUIT 1
 +16      ;
FIND1(FILE,IEN,FLG,VAL,IDX,SCR) ;
 +1        NEW I,X,Y,DIERR,TIUER
 +2        SET FILE=$GET(FILE)
           SET IEN=$GET(IEN)
           SET FLG=$GET(FLG)
           SET VAL=$GET(VAL)
 +3        IF FLG=""
               SET FLG="QX"
 +4        IF 'FILE!'$LENGTH(VAL)
               QUIT -1
 +5        SET Y=$$FIND1^DIC(FILE,IEN,FLG,VAL,.IDX,.SCR,"TIUER")
 +6        IF $DATA(DIERR)
               SET Y=-1
 +7        QUIT Y
 +8       ;
GET1(FILE,IEN,FLD,FLG) ;
 +1        NEW I,X,Y,DA,DIC,DIERR,TIUER
 +2        SET FILE=$GET(FILE)
           SET FLD=$GET(FLD)
           SET FLG=$GET(FLG)
           SET IEN=$GET(IEN)
 +3        if $EXTRACT(IEN,$LENGTH(IEN))'=","
               SET IEN=IEN_","
 +4        IF 'FILE!'IEN!'FLD
               QUIT ""
 +5        SET X=$$GET1^DIQ(FILE,IEN,FLD,$GET(FLG),,"TIUER")
 +6        IF $DATA(DIERR)
               SET X=""
 +7        QUIT X
 +8       ;
 +9       ;=====================================================================
 +10      ;          Programmer Tools for Troubleshooting
 +11      ;=====================================================================
TEST      ;   programmer testing
 +1        NEW EFORM,ERRON,NOKILL
           SET (EFORM,ERRON,NOKILL)=1
 +2        DO START^TIUDTBPN
 +3        QUIT 
 +4       ;
SAVE      ;   save local and global variables to ^XTMP
 +1        NEW I,X,GL
 +2        SET X=$$FMADD^XLFDT(DT,8)_U_DT_U
 +3        SET GL=$NAME(^XTMP("TIUDTBP0"))
           LOCK +@GL:5
          IF '$TEST
               QUIT 
 +4        SET I=1+$PIECE($GET(@GL@(0)),U,3)
           SET ^(0)=X_I
           LOCK -@GL
 +5        SET @GL@(I)=$$NOW^XLFDT
 +6        MERGE @GL@(I,"VAR","TIUD")=TIUD
 +7        SET @GL@(I,"VAR","ZTSK")=$GET(ZTSK)
 +8        SET @GL@(I,"VAR","DUZ")=DUZ
 +9        MERGE @GL@(I,"VAR-G","TMP")=@GLT
 +10       QUIT 
 +11      ;
 +12      ;=====================================================================
 +13      ;          Generic Text Handler
 +14      ;=====================================================================
 +15      ; this program is not expecting the text lines to contain a ';' char.
 +16      ; if there is formatting codes, they will be in the 3rd ';'-piece.
 +17      ;
TEXT(TAG,WR,LF,CLR,PAD,CHR,TIUR) ;
 +1       ; TAG - line label containing the text
 +2       ;       all groups of text should end with ' ;;---'
 +3       ;  WR - Boolean, write or do not write
 +4       ;  LF - 0:no extra line feeds; 1:leading line feed; 2:trailing feed
 +5       ; CLR - Boolean, clear screen first
 +6       ; PAD - number of spaces begin each line with
 +7       ;       If PAD="" then default to 3.  If PAD=0 then no padding
 +8       ; CHR - for center justify, character to pad line, default is space
 +9       ;.TIUR  - return array for text if desired (.TIUR(i)=text)
 +10      ;
 +11       NEW I,J,X,Y,FMT,LEN,SP
 +12       SET TAG=$GET(TAG)
           SET WR=+$GET(WR)
           SET LF=+$GET(LF)
           SET CLR=+$GET(CLR)
 +13       SET CHR=$GET(CHR)
           if CHR=""
               SET CHR=" "
 +14       SET PAD=$GET(PAD)
           IF PAD'?1.N
               SET PAD=3
 +15       SET LEN=IOM
           if 'LEN
               SET LEN=80
 +16       SET $PIECE(SP," ",LEN)=""
 +17       SET I=0
           FOR J=1:1
               SET X=$TEXT(@TAG+J)
               if X=" ;;---"
                   QUIT 
               Begin DoDot:1
 +18               SET I=I+1
                   SET X=$PIECE(X,";",3,99)
                   SET FMT=""
 +19               IF X?1U1";".E
                       SET FMT=$EXTRACT(X)
                       SET X=$PIECE(X,";",2,99)
 +20               IF FMT="C"
                       SET X=$$CJ^XLFSTR(" "_X_" ",LEN,CHR)
 +21               IF FMT="R"
                       SET X=$$RJ^XLFSTR(X,LEN,CHR)
 +22               IF FMT=""
                       IF PAD
                           SET X=$EXTRACT(SP,1,PAD)_X
 +23               SET TIUR(I)=X
 +24               IF FMT="C"
                       SET I=I+1
                       SET TIUR(I)=" "
 +25               QUIT 
               End DoDot:1
 +26       IF WR
               if CLR
                   WRITE @IOF
               if LF[1
                   WRITE !
               FOR Y=1:1:I
                   WRITE !,TIUR(Y)
                   IF I=Y
                       IF LF[2
                           WRITE !
 +27       QUIT 
 +28      ;
T1        ;
 +1       ;;C;Bookmark Progress Note after a Downtime
 +2       ;;This is the utility to add a bookmark to the progress note of
 +3       ;;each patient's electronic record after a VistA downtime.
 +4       ;;
 +5       ;;You will be asked a few questions, and then the utility
 +6       ;;will place the note on the patient's record.
 +7       ;;
 +8       ;;---
T2        ;
 +1       ;;Select the PROGRESS NOTE TITLE to be used for filing contingency
 +2       ;;downtime bookmark progress notes.  The selected title must be mapped
 +3       ;;to the VHA ENTERPRISE STANDARD TITLE of COMPUTER DOWNTIME
 +4       ;;---
T3        ;
 +1       ;;This option will look for all outpatients with visits that occured
 +2       ;;during the downtime period.  You have the option to select visits
 +3       ;;from (A)ll clinics or (S)elected clinics or (N)o clinics.
 +4       ;;If Selected clinics is chosen, then only visits which have been
 +5       ;;CHECKED OUT will be candidates for filing a downtime note.
 +6       ;;   
 +7       ;;---
T4        ;
 +1       ;;In addition to yourself, who shall receive email notification
 +2       ;;of this event?
 +3       ;;---
T5        ;
 +1       ;;Select DIVISION(s) to use when the task selects inpatients to file notes...
 +2       ;;---
T61       ;
 +1       ;;C;Potential Interruption in Electronic Medical Record Keeping  
 +2       ;;|SU| interruption in access to the electronic medical records
 +3       ;;occurred for |DUR| between:
 +4       ;;     |ST| and |END|
 +5       ;;
 +6       ;;---
T62       ;
 +1       ;;Before, during and after this period of downtime, medical record
 +2       ;;documentation may have been collected on paper.  Documents such as
 +3       ;;progress notes, orders, results, medication administration records
 +4       ;;(MAR) and procedure reports may have been collected, but may not be
 +5       ;;reflected in the electronic record or they may be scanned into the
 +6       ;;record at a later date.
 +7       ;;---
T7        ;
 +1       ;;Creating TIU note text, you will have an opportunity to edit the text
 +2       ;;The progress note will be generated with the following text:
 +3       ;;  
 +4       ;;---
T8        ;
 +1       ;;     
 +2       ;;The note(s) will have the following administrative closure (not a signature):
 +3       ;;---
T9        ;
 +1       ;;   
 +2       ;;The note(s) will be signed with the following electronic signature:
 +3       ;;---
T10       ;
 +1       ;;You will now be asked for an electronic signature to begin this process.
 +2       ;;If you are the author of the note, your signature will be appended.
 +3       ;;Otherwise, the AUTHOR/SIGNER will get VistA alerts for each note.
 +4       ;;---
T11       ;
 +1       ;;You will now be asked for an electronic signature to begin this process.
 +2       ;;This is a security measure to start the background task, but it is not used
 +3       ;;to sign the notes themselves.  If you are not the AUTHOR, your name will
 +4       ;;show for the administrative closure, but not as the author of the note.
 +5       ;;---
T12       ;
 +1       ;;You don't have an Electronic Signature Code on file, quitting...
 +2       ;;---
T13       ;
 +1       ;;You have 60 seconds/try and a maximum of 3 attempts to enter a proper code.
 +2       ;;---
T14       ;
 +1       ;;You can choose to queue this report to Taskman or you may run the
 +2       ;;report to your terminal now.  In either case, a Mailman message will
 +3       ;;be generated listing the patients who had a downtime note filed to
 +4       ;;their medical record.
 +5       ;;
 +6       ;;If you choose to run this report to your terminal, you will see a
 +7       ;;display of each patient found showing patient name, location, and
 +8       ;;filing status of the note.
 +9       ;;
 +10      ;;If you do not choose to queue this report, your terminal could be
 +11      ;;tied up for some time depending upon the inpatient and outpatient
 +12      ;;volume seen during the downtime.
 +13      ;;
 +14      ;;---
T15       ;
 +1       ;;The Author/Signer of these TIU notes must be authorized in ASU to
 +2       ;;sign for this type of TIU Document.
 +3       ;;  
 +4       ;;---
T16       ;
 +1       ;; Note  |                            |
 +2       ;; Filed | Location                   | Patient Name
 +3       ;;-------|----------------------------|-----------------------------------
 +4       ;;---
T17       ;
 +1       ;;Now generating progress notes for inpatients ...
 +2       ;;Now generating progress notes for discharged patients ...
 +3       ;;Now generating progress notes for outpatient clinics ...
 +4       ;;---
 +5       ;
 +6       ;=====================================================================
 +7       ;     PROGRAMMER NOTES
 +8       ;---------------------------------------------------------------------
 +9       ;Patch 305 - local, class III code remediated to national class I
 +10      ; some class III original options left in code but are never executed
 +11      ; in case in the future the VA decided it wants those original options
 +12      ;    DIR(6) - always return admin closure
 +13      ;    Programmer error tools
 +14      ;      If +ERRON is defined, append output from ^TIUPNAPI call
 +15      ;      If +NOKILL then do not kill off temp globals upon exit
 +16      ;      If +EFORM then email has columnar versus delimited format
 +17      ;
 +18      ;Description of temporary global structure
 +19      ;-------------------------------------------------------------------
 +20      ;                                   DIV=file 4 ien
 +21      ;     HLN=hospital location name     HL=file 44 ien
 +22      ;     PNM=patient name              DFN=file 2 ien
 +23      ;     WNM=ward name                WARD=file 42 ien
 +24      ;  STATUS = p1[^p2]
 +25      ;   p1 = Successful;Unsuccessful;Successful/unsigned;Error
 +26      ;   p2 = [TIU_note extrinsic function return value]
 +27      ; GLT = $NA(^TMP("TIUDTBPN",$J)
 +28      ;@GLT@("DSP",TYP,inc)=display line    [Sort TYP = 1,2,3]
 +29      ;@GLT@("F",2,DFN) = DFN^PNM
 +30      ;@GLT@("F",42,s3) = WARD^WNM^DIV^HL  {s3 = WARD or WNM}
 +31      ;@GLT@("F",44,HL) = HL^HLN^DIV
 +32      ;@GLT@("SORT",1,WARD,PNM,DFN)="" for current inpatients
 +33      ;@GLT@("SORT",2,PNM,DFN,DATE)="" for discharge patients
 +34      ;@GLT@("SORT",3,PNM,DFN,DATE)=HL_U_HLN for outpatients
 +35      ;    List of findings for mail message
 +36      ;@GLT@("MSG",PNM,DFN,HLN,inc)=STATUS  [class III format  - p1]
 +37      ;@GLT@("MSG",PNM,DFN,HLN,inc)=STATUS  [remediated format - p1^p2]
 +38      ;@GLT@("SEND",0) = fm wp header
 +39      ;@GLT@("SEND",inc,0) = line inc in mail message
 +40      ;Merge @GLT@("VAR")=TIUD
 +41      ;
 +42      ;Notes on Find Patients modules to create a TIU note
 +43      ;---------------------------------------------------------------------
 +44      ;GETINP -  get all current inpatients whose admit<downtime_endtime
 +45      ;   use admit movement xref as possible to admit without a ward
 +46      ;   division check only done on inpatients
 +47      ;
 +48      ;GETINPD:
 +49      ; Find any inpatients who were discharged during downtime by checking
 +50      ; discharge movements using FOR loop on discharge movement xref.
 +51      ;     Downtime_start '< discharge date.time < now
 +52      ;     ^DGPM("AMV"_TT,Date,Patient,DA)
 +53      ;
 +54      ;INPCOM - common code for both current and discharged inpatients
 +55      ;   Validate non-patient data, get iens, divisions, locations
 +56      ;   Let IN5^VADPT determine if patient was an inpatient
 +57      ;     check if patient was an inpatient at appropriate time
 +58      ;     .VAIP - Both an input and output parameter
 +59      ;     input: optional, VAIP("D")=<fmdt to find assoc. patient move>
 +60      ;                                default to the end of downtime
 +61      ; Output:
 +62      ;   VAIP(1)    = movement ien
 +63      ;   VAIP(2)    = trans type (1^admit 2^transfer 3^discharge...)
 +64      ;   VAIP(5)    = ien^ward_name
 +65      ;   VAIP(13)   = ien of admission movement
 +66      ;   VAIP(13,4) = ien^ward_name
 +67      ;   VAIP(17)   = ien of discharge movement
 +68      ;   VAIP(17,4) = ien^ward_name
 +69      ;
 +70      ;GETOUT - Search for outpatient appts, get latest appt dt only
 +71      ;  $$SDAPI^SDAMA301 retrieves ALL outpatients with filters applied
 +72      ;     $$SDAPI returns -1, 0, # of records
 +73      ;     Returns ^TMP($J,"SDAMA301",dfn,appt)= p1^p2^p3^p4 where
 +74      ;     p1 = FM appt dt
 +75      ;     p2 = clinic ien ; clinic name
 +76      ;     p3 = R;SCHEDULED/KEPT  or  I;INPATIENT  or  NT;NO ACTION TAKEN
 +77      ;     p4 = dfn ; patient name
 +78      ;  Move and sort output from $$SDAPI
 +79      ;  This only generates one note per patient based on location at
 +80      ;     end of downtime
 +81      ;  TIU API to create note kills ^TMP($J)