TIUVSIT ; SLC/JER - Interactive Visit look-up; 28-OCT-2003 [1/27/05 12:35pm]
;;1.0;TEXT INTEGRATION UTILITIES;**39,91,107,117,179,190**;Jun 20, 1997;Build 1
ENPN(TIUY,DFN,ALLOWNEW) ; Entry point for Progress Notes
N DIRUT,DUOUT,DTOUT,TIULOC,TIUINOUT
I +$G(DFN)'>0 Q
I +$D(^DPT(DFN,.1)) D MAIN^TIUMOVE(.TIUY,DFN,"","","","1","CURRENT",0) Q
S TIUINOUT=$$INOUT
I $D(DIRUT) Q
I $P(TIUINOUT,U)="o" D MAIN(.TIUY,DFN,"","","","",1,"","",$G(ALLOWNEW)) Q
D MAIN^TIUMOVE(.TIUY,DFN,"","","",1,"LAST",1)
Q
MAIN(TIUY,DFN,TIUSSN,TIUVDT,TIULDT,TIUDFLT,TIUMODE,TIULOC,TIUOCC,LETNEW) ;Control
N TIUFUTUR
AGN K ^TMP("TIUVN",$J),^TMP("TIUVDT",$J),^TMP("TIUVNI",$J),^TMP("TIUNOT",$J),^TMP($J,"SDAMA301")
N C,I,N,TIUI,TIUII,TIUDA,TIUER,TIUOK,TIUX,TIUOUT,X,TIUNVIS,VASD,VAERR
N TIUPICK,TIULAST,TIUSDC,TIUVTRY,TIUAPPTS,TIUARR
S TIUMODE=$G(TIUMODE,1),LETNEW=$G(LETNEW,1)
S:+$G(DFN)'>0 DFN=+$$PATIENT^TIULA($G(TIUSSN)) I +DFN'>0 S TIUOUT=1 Q
S TIUOCC=$G(TIUOCC,20)
S TIUARR("FLDS")="1;2"
S TIUARR(1)=2000000,TIUARR(4)=DFN,TIUARR("MAX")=1
S TIUAPPTS=$$SDAPI^SDAMA301(.TIUARR)
K ^TMP($J,"SDAMA301")
I TIUAPPTS=-1 D Q
. W !!,"Could not retrieve patient information due to a problem with the database.",!,"Please contact IRM"
I '$G(TIUAPPTS),(+TIUMODE'>0) Q
; No appointments
I '$G(TIUAPPTS),(+TIUMODE>0) D I +$G(TIUX)'>0 Q
. W !!,"No SCHEDULED APPOINTMENTS on file"
. D MAIN^TIUVISIT(.TIUY,DFN,$G(TIUSSN),$G(TIUVDT),$G(TIULDT),$G(TIUDFLT),$G(TIUMODE),$G(TIULOC),$G(TIUOCC),$G(LETNEW),"H",1,.TIUFUTUR)
. I +$G(TIUOUT) Q
. I '$D(TIUY),+LETNEW,'+$G(TIUVTRY) D ADD(DFN,.TIUX,1,.TIUSDC)
I '$G(TIUAPPTS),(+TIUX>0) G VADPT
I '$D(^TMP("TIUVN",$J)) D GETAPPT^TIUVSIT1(DFN,$G(TIULOC),$G(TIUOCC),$G(TIULDT),"",.TIULAST,$G(TIUVDT),+$G(TIUFUTUR)) S TIUFUTUR=0
; error in visit lookup
I +TIUMODE,$D(^TMP("TIUVERR",$J)) D Q
. W !!,$G(^TMP("TIUVERR",$J)),!
. I $D(^TMP("TIUVERR",$J,115)) W ^TMP("TIUVERR",$J,115),!
. K ^TMP("TIUVERR",$J)
; no appointments scheduled w/in selection range
I +TIUMODE,'$D(^TMP("TIUVN",$J)),+LETNEW D G:+$G(TIUFUTUR) AGN Q:+$G(TIUX)'>0 G VADPT
. N WHATNOW
. W !!,"No SCHEDULED APPOINTMENTS found through "
. W $$DATE^TIULS($$FMADD^XLFDT(DT,1),"AMTH DD, CCYY"),"...",!
. S WHATNOW=$$UP^XLFSTR($E($$NOTFOUND^TIUVSIT1))
. Q:$S(+$G(DUOUT):1,+$G(DTOUT):1,+$G(DIROUT):1,1:0)
. I $E(WHATNOW)="U" D Q
. . D MAIN^TIUVISIT(.TIUY,DFN,$G(TIUSSN),$G(TIUVDT),$G(TIULDT),$G(TIUDFLT),$G(TIUMODE),$G(TIULOC),$G(TIUOCC),$G(LETNEW),"H",1,.TIUFUTUR) Q:+$G(TIUFUTUR)
. . I '$D(TIUY),+LETNEW,'+$G(TIUVTRY) D ADD(DFN,.TIUX,1,.TIUSDC)
. I $E(WHATNOW)="F" S TIUFUTUR=1 Q ; FUTURE
. D ADD(DFN,.TIUX,$S($E(WHATNOW)="N":"",1:1),.TIUSDC)
I '+TIUMODE,'$D(^TMP("TIUVNI",$J)) Q
I '+TIUMODE,$G(TIUDFLT)="LAST" D Q:+$G(TIUX)'>0 G VADPT
. N TIUI S TIUI=+$O(^TMP("TIUVNI",$J,0))
. S TIUX=$$GETVSIT(TIUI)
I +TIUMODE,($G(TIUDFLT)="LAST"),(+$O(^TMP("TIUVNI",$J,0))>0) S TIUPICK=+$O(^TMP("TIUVNI",$J,0))
S (TIUER,TIUOK,TIUI)=0
W !!,"The following SCHEDULED VISITS are available:",!
F S TIUI=$O(^TMP("TIUVN",$J,TIUI)) Q:+TIUI'>0 D Q:+TIUER!+TIUOK!+$G(TIUX)!+$G(TIUOUT)
. S TIUII=TIUI D WRITE
. I '(TIUI#5) D BREAK I $S($G(X)="U":1,$G(X)["UNS":1,1:0) D Q
. . D MAIN^TIUVISIT(.TIUY,DFN,$G(TIUSSN),$G(TIUVDT),$G(TIULDT),$G(TIUDFLT),$G(TIUMODE),$G(TIULOC),$G(TIUOCC),$G(LETNEW),"H",1,.TIUFUTUR)
. . S TIUOUT=1
. I $G(X)["?" S X="",TIUI=TIUI-5
. I $G(X)["F" S X=""
I +$G(TIUFUTUR),$S(+TIUOK:1,+TIUER:1,$D(TIUY)>9:1,+$G(TIUX):1,1:0) S TIUFUTUR=0
I +$G(TIUFUTUR) S TIUOUT=0 G AGN
G:$D(TIUOUT) CLEAN
G AGN:+TIUER
I +$G(TIUII)#5,+TIUMODE D BREAK I $S($G(X)="U":1,$G(X)["UNS":1,1:0) D G:+$G(TIUFUTUR) AGN Q
. D MAIN^TIUVISIT(.TIUY,DFN,$G(TIUSSN),$G(TIUVDT),$G(TIULDT),$G(TIUDFLT),$G(TIUMODE),$G(TIULOC),$G(TIUOCC),$G(LETNEW),"H",1,.TIUFUTUR)
G:$D(TIUOUT) CLEAN
I $S(+TIUER:1,$G(X)["?":1,$G(X)["F":1,1:0) G AGN
I +TIUOK,'+$G(TIUNVIS) D
. S TIUX=$$GETVSIT(+TIUOK)
. W " ",$$DATE^TIULS(+$P(TIUX,";",2),"AMTH DD CCYY@HR:MIN")
VADPT D PATVADPT^TIULV(.TIUY,DFN,"",$G(TIUX),$G(TIUSDC))
CLEAN K ^TMP("TIUVN",$J),^TMP("TIUVDT",$J),^TMP("TIUVNI",$J),^TMP("TIUNOT",$J)
Q
BREAK ; Handle prompting
I TIUII=1 S (TIUOK,X)=1
W !,"CHOOSE 1-",TIUII,", or",!
W:'(TIUII#20) "<M>ORE VISITS, " W "<U>NSCHEDULED VISITS, "
I +$P(TIUPRM0,U,14) W:'+LETNEW " or " W "<F>UTURE VISITS, "
W:+LETNEW "or <N>EW VISIT"
W:$D(^TMP("TIUVN",$J,TIUII+1)) !,"<RETURN> TO CONTINUE",!,"OR '^' TO QUIT"
W ": " W:$D(TIUPICK) $P(^TMP("TIUVN",$J,TIUPICK),U),"// " R X:DTIME
S X=$$UP^XLFSTR(X)
I $S('$T:1,X["^":1,1:0) S (TIUER,TIUOUT)=1 Q
S:X=""&$D(TIUPICK) X=TIUPICK
I X["?" D HELP^TIUVSITH(X) Q
I $S(X="M":1,X="MORE":1,1:0) D MORE Q
I $S(X="F":1,X["FUT":1,1:0) D FUTURE Q
I $S(X="U":1,X["UNS":1,1:0) Q
I +LETNEW'>0,(X=""),'$D(^TMP("TIUVN",$J,TIUII+1)) S (TIUER,TIUOUT)=1 Q
I +LETNEW,$S(X="N":1,X="NEW":1,X=""&'$D(^TMP("TIUVN",$J,TIUII+1)):1,1:0) D ADD(DFN,.TIUX,$S(X="N":0,X="NEW":0,1:1),.TIUSDC) I +$G(TIUX)'>0 S (TIUER,TIUOUT)=1 Q
I $S(X="":1,X="N":1,X="NEW":1,1:0) Q
I X'=+X!'$D(^TMP("TIUVN",$J,+X)) W !!,$C(7),"INVALID RESPONSE",! G BREAK
S TIUOK=X
Q
INOUT() ; Ask INPATIENT/OUTPATIENT
N TIUPRMT S TIUPRMT="Is this note for INPATIENT or OUTPATIENT care? "
W:'$D(^DPT(DFN,.1)) !!,"This patient is not currently admitted to the facility...",!
Q $$READ^TIUU("SA^i:INPATIENT;o:OUTPATIENT",TIUPRMT,"OUTPATIENT")
MORE ; Modify date range, list more visits
N TIUI,TIUCNT
S TIUI=+$O(^TMP("TIUVDT",$J,0)),TIUCNT=+$G(^TMP("TIUVDT",$J,+TIUI))
D GETAPPT^TIUVSIT1(DFN,$G(TIULOC),$G(TIUOCC),TIUI,TIUCNT,.TIULAST)
Q
FUTURE ; Get future appointments
D GETAPPT^TIUVSIT1(DFN,$G(TIULOC),$G(TIUOCC),$G(TIULDT),"",.TIULAST,$G(TIUVDT),1)
I $D(^TMP("TIUVERR",$J)) D
. W !!,$G(^TMP("TIUVERR",$J)),!
. I $D(^TMP("TIUVERR",$J,115)) W ^TMP("TIUVERR",$J,115),!
I $P(+$G(^TMP("TIUVNI",$J,1)),".")'>+$$NOW^XLFDT D
. W !!,"No Future Appointments found...",!
E I $P(+$G(^TMP("TIUVNI",$J,1)),".")'>$$FMADD^XLFDT(DT,1) D
. W !!,"No Appointments found more than one day in future..."
S TIUI=0,TIUFUTUR=1
Q
GETVSIT(TIUOK) ; Get associated visit
N APPT,TIUVSIT,VLOC,VSTOP,VDT,VTYPE
S APPT=$G(^TMP("TIUVNI",$J,+TIUOK))
S VDT=+APPT,VLOC=$P(APPT,U,2)
S VSTOP=$P($G(^SC(+VLOC,0)),U,7)
S VTYPE=$S($P(APPT,U,3)="I":"I",1:"A")
S TIUVSIT=VLOC_";"_VDT_";"_VTYPE
Q TIUVSIT
ADD(DFN,VSTR,ASK,VSTOP) ; Add a visit for patient
N VTYPE,VDT,VLOC,TIUY,DA,DIE,DR,TIUAPDT,X,Y W !
S ASK=$G(ASK,1)
I +ASK D
. W !,$C(7),$C(7),"Patient & Visit are Required...",!
. S TIUY=$$READ^TIUU("YAO","Do you wish to add a NEW Visit? ","NO")
I +ASK,(+TIUY'>0) S TIUX=0,TIUER=1 Q
I $G(VLOC)']"" S VLOC=$$SELLOC
I +VLOC'>0 S TIUER=1 Q
S VSTOP=+$P(^SC(+VLOC,0),U,7)
S VDT=+$$READ^TIUU("D^:NOW:ERSX","Enter Visit Date/Time","NOW","Precise Date & Time are Required")
I +VDT'>0 S TIUER=1 Q
S TIUAPDT=+$O(^TMP("TIUNOT",$J,+VLOC,+$P(VDT,".")))
I +TIUAPDT>0,(+$P(TIUAPDT,".")=+$P(VDT,".")) D Q
. W !!,$C(7)," Item #",+$G(^TMP("TIUNOT",$J,+VLOC,+TIUAPDT))
. W " is scheduled for ",$$DATE^TIULS(TIUAPDT,"MM/DD/YY HR:MIN")
. W " at this location..."
. W !!,"Please select the existing appointment, rather than creating a "
. W "redundant one.",!
. S TIUER=1
S VTYPE=$$VSITYPE(VSTOP)
S VSTR=+VLOC_";"_+VDT_";"_VTYPE
I +VSTR'>0 S TIUER=1 Q
S TIUNVIS=+VDT,TIUER=0
Q
WRITE ; Writes each list element
N TIUX S TIUX=^TMP("TIUVN",$J,TIUI)
W !,$J(TIUII,4),"> ",$P(TIUX,U),?27,$E($P(TIUX,U,3),1,21),?50,$P(TIUX,U,2)
Q
SELLOC() ; Select Hospital Location
N DIC,X,Y,TIUAPDT S DIC=44,DIC(0)="AEMQ"
S DIC("A")="PATIENT LOCATION: "
S DIC("B")=$P($$PERSLOC^TIULE(DUZ),U,2)
S:DIC("B")']"" DIC("B")=$P($G(^SC(+$G(^DISV(DUZ,"^SC(")),0)),U)
S DIC("S")="I $$GOODLOC^TIUPREF(Y)"
D ^DIC K DIC("S")
Q Y
DEFER(DA,TIUSDC) ; Mark record for deferred crediting of stop code
N DIE,DR,X,Y,TIUVSIT
I +$G(TIUSDC)'>0 Q
S DIE=8925
S:$$WORKOK^TIUPXAP1(+DA) DR=".11////1;"
S DR=$G(DR)_"1206////^S X="_+TIUSDC
D ^DIE
;If not called via the broker try to link document to an existing visit
I '$$BROKER^XWBLIB,$$LNKVST^TIUPXAP3(+DA,.TIUVSIT)
Q
CREDIT(TIUDA) ; Call EN3^SDACS to Credit Stop Code
N DA,DFN,VSIT,TIU,TIUD0,TIUDPRM
S TIUD0=$G(^TIU(8925,+TIUDA,0))
I TIUD0']"" Q
D DOCPRM^TIULC1(+TIUD0,.TIUDPRM)
; If SUPPRESS DX/CPT ON NEW VISIT is set to YES, then Quit
I +$P($G(TIUDPRM(0)),U,14)>0 Q
S DFN=+$P(TIUD0,U,2),VSIT=$P(TIUD0,U,3)
D GETTIU^TIULD(.TIU,TIUDA)
D CREDIT^TIUPXAPI(DFN,.TIU,VSIT)
Q
REMFLAG(DA) ; Remove credit flag from TIU Document Record
N DIE,DR,X,Y
S DIE=8925,DR=".11///@" D ^DIE
Q
VSITYPE(VSTOP) ; Call reader to get VISIT TYPE
N DFLT,PROMPT,X,Y S VSTOP=$P($G(^DIC(40.7,+$G(VSTOP),0)),U)
S DFLT=$S(VSTOP["TELE":"TELEPHONE",1:"AMBULATORY")
S PROMPT="TYPE OF VISIT: "
S X="SMA^a:AMBULATORY (WALK-IN);t:TELEPHONE;i:IN HOSPITAL;e:EVENT (HISTORICAL)"
S Y=$$READ^TIUU(X,PROMPT,DFLT) W " ",$P(Y,U,2),!
S Y=$$UP^XLFSTR($P(Y,U))
Q Y
GETAPPT(DFN,CLINIC,OCCLIM,INDEX,COUNT,LAST,EARLY,FUTURE) ; Get list
D GETAPPT^TIUVSIT1($G(DFN),$G(CLINIC),$G(OCCLIM),$G(INDEX),$G(COUNT),$G(LAST),$G(EARLY),$G(FUTURE))
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HTIUVSIT 9192 printed Oct 16, 2024@18:47:03 Page 2
TIUVSIT ; SLC/JER - Interactive Visit look-up; 28-OCT-2003 [1/27/05 12:35pm]
+1 ;;1.0;TEXT INTEGRATION UTILITIES;**39,91,107,117,179,190**;Jun 20, 1997;Build 1
ENPN(TIUY,DFN,ALLOWNEW) ; Entry point for Progress Notes
+1 NEW DIRUT,DUOUT,DTOUT,TIULOC,TIUINOUT
+2 IF +$GET(DFN)'>0
QUIT
+3 IF +$DATA(^DPT(DFN,.1))
DO MAIN^TIUMOVE(.TIUY,DFN,"","","","1","CURRENT",0)
QUIT
+4 SET TIUINOUT=$$INOUT
+5 IF $DATA(DIRUT)
QUIT
+6 IF $PIECE(TIUINOUT,U)="o"
DO MAIN(.TIUY,DFN,"","","","",1,"","",$GET(ALLOWNEW))
QUIT
+7 DO MAIN^TIUMOVE(.TIUY,DFN,"","","",1,"LAST",1)
+8 QUIT
MAIN(TIUY,DFN,TIUSSN,TIUVDT,TIULDT,TIUDFLT,TIUMODE,TIULOC,TIUOCC,LETNEW) ;Control
+1 NEW TIUFUTUR
AGN KILL ^TMP("TIUVN",$JOB),^TMP("TIUVDT",$JOB),^TMP("TIUVNI",$JOB),^TMP("TIUNOT",$JOB),^TMP($JOB,"SDAMA301")
+1 NEW C,I,N,TIUI,TIUII,TIUDA,TIUER,TIUOK,TIUX,TIUOUT,X,TIUNVIS,VASD,VAERR
+2 NEW TIUPICK,TIULAST,TIUSDC,TIUVTRY,TIUAPPTS,TIUARR
+3 SET TIUMODE=$GET(TIUMODE,1)
SET LETNEW=$GET(LETNEW,1)
+4 if +$GET(DFN)'>0
SET DFN=+$$PATIENT^TIULA($GET(TIUSSN))
IF +DFN'>0
SET TIUOUT=1
QUIT
+5 SET TIUOCC=$GET(TIUOCC,20)
+6 SET TIUARR("FLDS")="1;2"
+7 SET TIUARR(1)=2000000
SET TIUARR(4)=DFN
SET TIUARR("MAX")=1
+8 SET TIUAPPTS=$$SDAPI^SDAMA301(.TIUARR)
+9 KILL ^TMP($JOB,"SDAMA301")
+10 IF TIUAPPTS=-1
Begin DoDot:1
+11 WRITE !!,"Could not retrieve patient information due to a problem with the database.",!,"Please contact IRM"
End DoDot:1
QUIT
+12 IF '$GET(TIUAPPTS)
IF (+TIUMODE'>0)
QUIT
+13 ; No appointments
+14 IF '$GET(TIUAPPTS)
IF (+TIUMODE>0)
Begin DoDot:1
+15 WRITE !!,"No SCHEDULED APPOINTMENTS on file"
+16 DO MAIN^TIUVISIT(.TIUY,DFN,$GET(TIUSSN),$GET(TIUVDT),$GET(TIULDT),$GET(TIUDFLT),$GET(TIUMODE),$GET(TIULOC),$GET(TIUOCC),$GET(LETNEW),"H",1,.TIUFUTUR)
+17 IF +$GET(TIUOUT)
QUIT
+18 IF '$DATA(TIUY)
IF +LETNEW
IF '+$GET(TIUVTRY)
DO ADD(DFN,.TIUX,1,.TIUSDC)
End DoDot:1
IF +$GET(TIUX)'>0
QUIT
+19 IF '$GET(TIUAPPTS)
IF (+TIUX>0)
GOTO VADPT
+20 IF '$DATA(^TMP("TIUVN",$JOB))
DO GETAPPT^TIUVSIT1(DFN,$GET(TIULOC),$GET(TIUOCC),$GET(TIULDT),"",.TIULAST,$GET(TIUVDT),+$GET(TIUFUTUR))
SET TIUFUTUR=0
+21 ; error in visit lookup
+22 IF +TIUMODE
IF $DATA(^TMP("TIUVERR",$JOB))
Begin DoDot:1
+23 WRITE !!,$GET(^TMP("TIUVERR",$JOB)),!
+24 IF $DATA(^TMP("TIUVERR",$JOB,115))
WRITE ^TMP("TIUVERR",$JOB,115),!
+25 KILL ^TMP("TIUVERR",$JOB)
End DoDot:1
QUIT
+26 ; no appointments scheduled w/in selection range
+27 IF +TIUMODE
IF '$DATA(^TMP("TIUVN",$JOB))
IF +LETNEW
Begin DoDot:1
+28 NEW WHATNOW
+29 WRITE !!,"No SCHEDULED APPOINTMENTS found through "
+30 WRITE $$DATE^TIULS($$FMADD^XLFDT(DT,1),"AMTH DD, CCYY"),"...",!
+31 SET WHATNOW=$$UP^XLFSTR($EXTRACT($$NOTFOUND^TIUVSIT1))
+32 if $SELECT(+$GET(DUOUT)
QUIT
+33 IF $EXTRACT(WHATNOW)="U"
Begin DoDot:2
+34 DO MAIN^TIUVISIT(.TIUY,DFN,$GET(TIUSSN),$GET(TIUVDT),$GET(TIULDT),$GET(TIUDFLT),$GET(TIUMODE),$GET(TIULOC),$GET(TIUOCC),$GET(LETNEW),"H",1,.TIUFUTUR)
if +$GET(TIUFUTUR)
QUIT
+35 IF '$DATA(TIUY)
IF +LETNEW
IF '+$GET(TIUVTRY)
DO ADD(DFN,.TIUX,1,.TIUSDC)
End DoDot:2
QUIT
+36 ; FUTURE
IF $EXTRACT(WHATNOW)="F"
SET TIUFUTUR=1
QUIT
+37 DO ADD(DFN,.TIUX,$SELECT($EXTRACT(WHATNOW)="N":"",1:1),.TIUSDC)
End DoDot:1
if +$GET(TIUFUTUR)
GOTO AGN
if +$GET(TIUX)'>0
QUIT
GOTO VADPT
+38 IF '+TIUMODE
IF '$DATA(^TMP("TIUVNI",$JOB))
QUIT
+39 IF '+TIUMODE
IF $GET(TIUDFLT)="LAST"
Begin DoDot:1
+40 NEW TIUI
SET TIUI=+$ORDER(^TMP("TIUVNI",$JOB,0))
+41 SET TIUX=$$GETVSIT(TIUI)
End DoDot:1
if +$GET(TIUX)'>0
QUIT
GOTO VADPT
+42 IF +TIUMODE
IF ($GET(TIUDFLT)="LAST")
IF (+$ORDER(^TMP("TIUVNI",$JOB,0))>0)
SET TIUPICK=+$ORDER(^TMP("TIUVNI",$JOB,0))
+43 SET (TIUER,TIUOK,TIUI)=0
+44 WRITE !!,"The following SCHEDULED VISITS are available:",!
+45 FOR
SET TIUI=$ORDER(^TMP("TIUVN",$JOB,TIUI))
if +TIUI'>0
QUIT
Begin DoDot:1
+46 SET TIUII=TIUI
DO WRITE
+47 IF '(TIUI#5)
DO BREAK
IF $SELECT($GET(X)="U":1,$GET(X)["UNS":1,1:0)
Begin DoDot:2
+48 DO MAIN^TIUVISIT(.TIUY,DFN,$GET(TIUSSN),$GET(TIUVDT),$GET(TIULDT),$GET(TIUDFLT),$GET(TIUMODE),$GET(TIULOC),$GET(TIUOCC),$GET(LETNEW),"H",1,.TIUFUTUR)
+49 SET TIUOUT=1
End DoDot:2
QUIT
+50 IF $GET(X)["?"
SET X=""
SET TIUI=TIUI-5
+51 IF $GET(X)["F"
SET X=""
End DoDot:1
if +TIUER!+TIUOK!+$GET(TIUX)!+$GET(TIUOUT)
QUIT
+52 IF +$GET(TIUFUTUR)
IF $SELECT(+TIUOK:1,+TIUER:1,$DATA(TIUY)>9:1,+$GET(TIUX):1,1:0)
SET TIUFUTUR=0
+53 IF +$GET(TIUFUTUR)
SET TIUOUT=0
GOTO AGN
+54 if $DATA(TIUOUT)
GOTO CLEAN
+55 if +TIUER
GOTO AGN
+56 IF +$GET(TIUII)#5
IF +TIUMODE
DO BREAK
IF $SELECT($GET(X)="U":1,$GET(X)["UNS":1,1:0)
Begin DoDot:1
+57 DO MAIN^TIUVISIT(.TIUY,DFN,$GET(TIUSSN),$GET(TIUVDT),$GET(TIULDT),$GET(TIUDFLT),$GET(TIUMODE),$GET(TIULOC),$GET(TIUOCC),$GET(LETNEW),"H",1,.TIUFUTUR)
End DoDot:1
if +$GET(TIUFUTUR)
GOTO AGN
QUIT
+58 if $DATA(TIUOUT)
GOTO CLEAN
+59 IF $SELECT(+TIUER:1,$GET(X)["?":1,$GET(X)["F":1,1:0)
GOTO AGN
+60 IF +TIUOK
IF '+$GET(TIUNVIS)
Begin DoDot:1
+61 SET TIUX=$$GETVSIT(+TIUOK)
+62 WRITE " ",$$DATE^TIULS(+$PIECE(TIUX,";",2),"AMTH DD CCYY@HR:MIN")
End DoDot:1
VADPT DO PATVADPT^TIULV(.TIUY,DFN,"",$GET(TIUX),$GET(TIUSDC))
CLEAN KILL ^TMP("TIUVN",$JOB),^TMP("TIUVDT",$JOB),^TMP("TIUVNI",$JOB),^TMP("TIUNOT",$JOB)
+1 QUIT
BREAK ; Handle prompting
+1 IF TIUII=1
SET (TIUOK,X)=1
+2 WRITE !,"CHOOSE 1-",TIUII,", or",!
+3 if '(TIUII#20)
WRITE "<M>ORE VISITS, "
WRITE "<U>NSCHEDULED VISITS, "
+4 IF +$PIECE(TIUPRM0,U,14)
if '+LETNEW
WRITE " or "
WRITE "<F>UTURE VISITS, "
+5 if +LETNEW
WRITE "or <N>EW VISIT"
+6 if $DATA(^TMP("TIUVN",$JOB,TIUII+1))
WRITE !,"<RETURN> TO CONTINUE",!,"OR '^' TO QUIT"
+7 WRITE ": "
if $DATA(TIUPICK)
WRITE $PIECE(^TMP("TIUVN",$JOB,TIUPICK),U),"// "
READ X:DTIME
+8 SET X=$$UP^XLFSTR(X)
+9 IF $SELECT('$TEST:1,X["^":1,1:0)
SET (TIUER,TIUOUT)=1
QUIT
+10 if X=""&$DATA(TIUPICK)
SET X=TIUPICK
+11 IF X["?"
DO HELP^TIUVSITH(X)
QUIT
+12 IF $SELECT(X="M":1,X="MORE":1,1:0)
DO MORE
QUIT
+13 IF $SELECT(X="F":1,X["FUT":1,1:0)
DO FUTURE
QUIT
+14 IF $SELECT(X="U":1,X["UNS":1,1:0)
QUIT
+15 IF +LETNEW'>0
IF (X="")
IF '$DATA(^TMP("TIUVN",$JOB,TIUII+1))
SET (TIUER,TIUOUT)=1
QUIT
+16 IF +LETNEW
IF $SELECT(X="N":1,X="NEW":1,X=""&'$DATA(^TMP("TIUVN",$JOB,TIUII+1)):1,1:0)
DO ADD(DFN,.TIUX,$SELECT(X="N":0,X="NEW":0,1:1),.TIUSDC)
IF +$GET(TIUX)'>0
SET (TIUER,TIUOUT)=1
QUIT
+17 IF $SELECT(X="":1,X="N":1,X="NEW":1,1:0)
QUIT
+18 IF X'=+X!'$DATA(^TMP("TIUVN",$JOB,+X))
WRITE !!,$CHAR(7),"INVALID RESPONSE",!
GOTO BREAK
+19 SET TIUOK=X
+20 QUIT
INOUT() ; Ask INPATIENT/OUTPATIENT
+1 NEW TIUPRMT
SET TIUPRMT="Is this note for INPATIENT or OUTPATIENT care? "
+2 if '$DATA(^DPT(DFN,.1))
WRITE !!,"This patient is not currently admitted to the facility...",!
+3 QUIT $$READ^TIUU("SA^i:INPATIENT;o:OUTPATIENT",TIUPRMT,"OUTPATIENT")
MORE ; Modify date range, list more visits
+1 NEW TIUI,TIUCNT
+2 SET TIUI=+$ORDER(^TMP("TIUVDT",$JOB,0))
SET TIUCNT=+$GET(^TMP("TIUVDT",$JOB,+TIUI))
+3 DO GETAPPT^TIUVSIT1(DFN,$GET(TIULOC),$GET(TIUOCC),TIUI,TIUCNT,.TIULAST)
+4 QUIT
FUTURE ; Get future appointments
+1 DO GETAPPT^TIUVSIT1(DFN,$GET(TIULOC),$GET(TIUOCC),$GET(TIULDT),"",.TIULAST,$GET(TIUVDT),1)
+2 IF $DATA(^TMP("TIUVERR",$JOB))
Begin DoDot:1
+3 WRITE !!,$GET(^TMP("TIUVERR",$JOB)),!
+4 IF $DATA(^TMP("TIUVERR",$JOB,115))
WRITE ^TMP("TIUVERR",$JOB,115),!
End DoDot:1
+5 IF $PIECE(+$GET(^TMP("TIUVNI",$JOB,1)),".")'>+$$NOW^XLFDT
Begin DoDot:1
+6 WRITE !!,"No Future Appointments found...",!
End DoDot:1
+7 IF '$TEST
IF $PIECE(+$GET(^TMP("TIUVNI",$JOB,1)),".")'>$$FMADD^XLFDT(DT,1)
Begin DoDot:1
+8 WRITE !!,"No Appointments found more than one day in future..."
End DoDot:1
+9 SET TIUI=0
SET TIUFUTUR=1
+10 QUIT
GETVSIT(TIUOK) ; Get associated visit
+1 NEW APPT,TIUVSIT,VLOC,VSTOP,VDT,VTYPE
+2 SET APPT=$GET(^TMP("TIUVNI",$JOB,+TIUOK))
+3 SET VDT=+APPT
SET VLOC=$PIECE(APPT,U,2)
+4 SET VSTOP=$PIECE($GET(^SC(+VLOC,0)),U,7)
+5 SET VTYPE=$SELECT($PIECE(APPT,U,3)="I":"I",1:"A")
+6 SET TIUVSIT=VLOC_";"_VDT_";"_VTYPE
+7 QUIT TIUVSIT
ADD(DFN,VSTR,ASK,VSTOP) ; Add a visit for patient
+1 NEW VTYPE,VDT,VLOC,TIUY,DA,DIE,DR,TIUAPDT,X,Y
WRITE !
+2 SET ASK=$GET(ASK,1)
+3 IF +ASK
Begin DoDot:1
+4 WRITE !,$CHAR(7),$CHAR(7),"Patient & Visit are Required...",!
+5 SET TIUY=$$READ^TIUU("YAO","Do you wish to add a NEW Visit? ","NO")
End DoDot:1
+6 IF +ASK
IF (+TIUY'>0)
SET TIUX=0
SET TIUER=1
QUIT
+7 IF $GET(VLOC)']""
SET VLOC=$$SELLOC
+8 IF +VLOC'>0
SET TIUER=1
QUIT
+9 SET VSTOP=+$PIECE(^SC(+VLOC,0),U,7)
+10 SET VDT=+$$READ^TIUU("D^:NOW:ERSX","Enter Visit Date/Time","NOW","Precise Date & Time are Required")
+11 IF +VDT'>0
SET TIUER=1
QUIT
+12 SET TIUAPDT=+$ORDER(^TMP("TIUNOT",$JOB,+VLOC,+$PIECE(VDT,".")))
+13 IF +TIUAPDT>0
IF (+$PIECE(TIUAPDT,".")=+$PIECE(VDT,"."))
Begin DoDot:1
+14 WRITE !!,$CHAR(7)," Item #",+$GET(^TMP("TIUNOT",$JOB,+VLOC,+TIUAPDT))
+15 WRITE " is scheduled for ",$$DATE^TIULS(TIUAPDT,"MM/DD/YY HR:MIN")
+16 WRITE " at this location..."
+17 WRITE !!,"Please select the existing appointment, rather than creating a "
+18 WRITE "redundant one.",!
+19 SET TIUER=1
End DoDot:1
QUIT
+20 SET VTYPE=$$VSITYPE(VSTOP)
+21 SET VSTR=+VLOC_";"_+VDT_";"_VTYPE
+22 IF +VSTR'>0
SET TIUER=1
QUIT
+23 SET TIUNVIS=+VDT
SET TIUER=0
+24 QUIT
WRITE ; Writes each list element
+1 NEW TIUX
SET TIUX=^TMP("TIUVN",$JOB,TIUI)
+2 WRITE !,$JUSTIFY(TIUII,4),"> ",$PIECE(TIUX,U),?27,$EXTRACT($PIECE(TIUX,U,3),1,21),?50,$PIECE(TIUX,U,2)
+3 QUIT
SELLOC() ; Select Hospital Location
+1 NEW DIC,X,Y,TIUAPDT
SET DIC=44
SET DIC(0)="AEMQ"
+2 SET DIC("A")="PATIENT LOCATION: "
+3 SET DIC("B")=$PIECE($$PERSLOC^TIULE(DUZ),U,2)
+4 if DIC("B")']""
SET DIC("B")=$PIECE($GET(^SC(+$GET(^DISV(DUZ,"^SC(")),0)),U)
+5 SET DIC("S")="I $$GOODLOC^TIUPREF(Y)"
+6 DO ^DIC
KILL DIC("S")
+7 QUIT Y
DEFER(DA,TIUSDC) ; Mark record for deferred crediting of stop code
+1 NEW DIE,DR,X,Y,TIUVSIT
+2 IF +$GET(TIUSDC)'>0
QUIT
+3 SET DIE=8925
+4 if $$WORKOK^TIUPXAP1(+DA)
SET DR=".11////1;"
+5 SET DR=$GET(DR)_"1206////^S X="_+TIUSDC
+6 DO ^DIE
+7 ;If not called via the broker try to link document to an existing visit
+8 IF '$$BROKER^XWBLIB
IF $$LNKVST^TIUPXAP3(+DA,.TIUVSIT)
+9 QUIT
CREDIT(TIUDA) ; Call EN3^SDACS to Credit Stop Code
+1 NEW DA,DFN,VSIT,TIU,TIUD0,TIUDPRM
+2 SET TIUD0=$GET(^TIU(8925,+TIUDA,0))
+3 IF TIUD0']""
QUIT
+4 DO DOCPRM^TIULC1(+TIUD0,.TIUDPRM)
+5 ; If SUPPRESS DX/CPT ON NEW VISIT is set to YES, then Quit
+6 IF +$PIECE($GET(TIUDPRM(0)),U,14)>0
QUIT
+7 SET DFN=+$PIECE(TIUD0,U,2)
SET VSIT=$PIECE(TIUD0,U,3)
+8 DO GETTIU^TIULD(.TIU,TIUDA)
+9 DO CREDIT^TIUPXAPI(DFN,.TIU,VSIT)
+10 QUIT
REMFLAG(DA) ; Remove credit flag from TIU Document Record
+1 NEW DIE,DR,X,Y
+2 SET DIE=8925
SET DR=".11///@"
DO ^DIE
+3 QUIT
VSITYPE(VSTOP) ; Call reader to get VISIT TYPE
+1 NEW DFLT,PROMPT,X,Y
SET VSTOP=$PIECE($GET(^DIC(40.7,+$GET(VSTOP),0)),U)
+2 SET DFLT=$SELECT(VSTOP["TELE":"TELEPHONE",1:"AMBULATORY")
+3 SET PROMPT="TYPE OF VISIT: "
+4 SET X="SMA^a:AMBULATORY (WALK-IN);t:TELEPHONE;i:IN HOSPITAL;e:EVENT (HISTORICAL)"
+5 SET Y=$$READ^TIUU(X,PROMPT,DFLT)
WRITE " ",$PIECE(Y,U,2),!
+6 SET Y=$$UP^XLFSTR($PIECE(Y,U))
+7 QUIT Y
GETAPPT(DFN,CLINIC,OCCLIM,INDEX,COUNT,LAST,EARLY,FUTURE) ; Get list
+1 DO GETAPPT^TIUVSIT1($GET(DFN),$GET(CLINIC),$GET(OCCLIM),$GET(INDEX),$GET(COUNT),$GET(LAST),$GET(EARLY),$GET(FUTURE))
+2 QUIT