TIUPXAP3 ;SLC/RMO - Link Document to Visit API ;Apr 11, 2018@12:07
;;1.0;TEXT INTEGRATION UTILITIES;**179,290**;Jun 20, 1997;Build 548
;
LNKVST(TIUDA,TIUVSIT) ;Entry point to link a document to an existing visit
; Input -- TIUDA TIU Document file (#8925) IEN
; Output -- 1=Successful and 0=Failure
; TIUVSIT Visit file (#9000010) IEN
N OKF,TIUMVSTF
;
;Check if document needs to be linked to a visit
I $D(^TIU(8925,TIUDA,0)),$P(^(0),U,3)'>0 D
. ;Get existing visit to associate with document
. D GETVST(TIUDA,.TIUVSIT,.TIUMVSTF)
. ;If only one visit update the document with the visit
. I $G(TIUVSIT)>0,'$G(TIUMVSTF) D
. . I $$UPDVST^TIUPXAP2(TIUDA,TIUVSIT) S OKF=1
Q +$G(OKF)
;
GETVST(TIUDA,TIUVSIT,TIUMVSTF) ;Get visit to associate with document
; Input -- TIUDA TIU Document file (#8925) IEN
; Output -- TIUVSIT Visit file (#9000010) IEN
; TIUMVSTF Multiple Visit Flag
; 1=Multiple Visits
;
N TIUD0,TIUDFN,TIUEDT,TIUHL,TIUVSITS,TIUVSTR
;
;Set variables
S TIUD0=$G(^TIU(8925,TIUDA,0))
S TIUDFN=$P(TIUD0,U,2),TIUEDT=$P(TIUD0,U,7)
S TIUHL=$P($G(^TIU(8925,TIUDA,12)),U,11)
S TIUVSTR=TIUHL_";"_TIUEDT_";"_$P(TIUD0,U,13)
;
;Check if document is an addendum, if it is use visit of parent
I +$$ISADDNDM^TIULC1(TIUDA) D G GETVSTQ
. I $D(^TIU(8925,+$P(TIUD0,U,6),0)),$P(^(0),U,3)>0 S TIUVSIT=$P(^(0),U,3)
;
;Check if a document has already been entered for the Vstring,
;if it has use the visit in the AVSTRV cross-reference
I +$G(TIUVSTR),+$O(^TIU(8925,"AVSTRV",+TIUDFN,TIUVSTR,0))>0 D G GETVSTQ:$G(TIUVSIT)>0
. S TIUVSIT=+$O(^TIU(8925,"AVSTRV",+TIUDFN,TIUVSTR,0))
. I $P($G(^AUPNVSIT(+TIUVSIT,0)),U,5)'=TIUDFN S TIUVSIT=""
;
;Check PCE for a visit
S TIUVSITS=$$GETENC^PXAPI(TIUDFN,TIUEDT,TIUHL)
I TIUVSITS>0 S TIUVSIT=+TIUVSITS
;
;Set a flag if multiple visits
I $P(TIUVSITS,U,2)'="" S TIUMVSTF=1
GETVSTQ K ^TMP("PXKENC",$J)
Q
LNKSVST(TIUY,TIUDFN,TIUDA,TIUVSTR) ;Entry point to link a document via its
; SECONDARY VISIT field to a daily
; hospitalization visit
; Input -- TIUDFN Patient file (#2) IEN
; TIUDA TIU Document file (#8925) IEN
; TIUVSTR IEN of visit or visit string
; Output -- TIUY=1 for Successful or
; 0^Message for Failure
K TIUY
S TIUY=0
S TIUDFN=+$G(TIUDFN) I ('TIUDFN)!('$D(^DPT(TIUDFN))) D Q
.S $P(TIUY,U,2)="Invalid patient specified."
S TIUDA=+$G(TIUDA) I ('TIUDA)!('$D(^TIU(8925,TIUDA))) D Q
.S $P(TIUY,U,2)="Invalid document number specified."
N TIUVSIT,TIUVDT
S TIUVSTR=$G(TIUVSTR),TIUVSIT=0
I TIUVSTR?1.N D Q:$P(TIUY,U,2)'=""
.S TIUVSIT=TIUVSTR,TIUVSTR=""
.I ('TIUVSIT)!('$D(^AUPNVSIT(TIUVSIT))) S $P(TIUY,U,2)="Invalid visit specified." Q
.I $P($G(^AUPNVSIT(TIUVSIT,0)),U,7)'="D" D
..S $P(TIUY,U,2)="The specified visit does not have a service category of daily hospitalization."
I TIUVSTR'="" D Q:$P(TIUY,U,2)'=""
.I TIUVSTR'?1.N1";"7N.1".".N1";"1U D Q
..S $P(TIUY,U,2)="Invalid visit string format."
.I $P(TIUVSTR,";",3)'="D" D Q
..S $P(TIUY,U,2)="The specified visit does not have a service category of daily hospitalization." Q
.;Check PCE for a visit
.N TIUVSITS,TIUPXAPI,SUCCESS,PIECE,EXIT
.S TIUVDT=$P(TIUVSTR,";",2)
.S TIUVSITS=$$GETENC^PXAPI(TIUDFN,TIUVDT,+TIUVSTR)
.F PIECE=1:1:$L(TIUVSITS,U) D Q:TIUVSIT>0
..S TIUVSIT=$P(TIUVSITS,U,PIECE)
..I $P($G(^TMP("PXKENC",$J,TIUVSIT,0)),U,7)'="D" S TIUVSIT=0
.K ^TMP("PXKENC",$J)
I TIUVSTR="",'TIUVSIT S $P(TIUY,U,2)="No visit specified." Q
;No visit found, create one
I 'TIUVSIT D
.K ^TMP("TIUPXAPI",$J),TIUVSIT S TIUPXAPI=$NA(^TMP("TIUPXAPI",$J))
.S @TIUPXAPI@("ENCOUNTER",1,"ENC D/T")=TIUVDT
.S @TIUPXAPI@("ENCOUNTER",1,"PATIENT")=TIUDFN
.S @TIUPXAPI@("ENCOUNTER",1,"HOS LOC")=+TIUVSTR
.S @TIUPXAPI@("ENCOUNTER",1,"SERVICE CATEGORY")=$P(TIUVSTR,";",3)
.S @TIUPXAPI@("ENCOUNTER",1,"ENCOUNTER TYPE")="P"
.I $$PROVIDER^TIUPXAP1(DUZ,TIUVDT) S @TIUPXAPI@("PROVIDER",1,"NAME")=DUZ
.S SUCCESS=$$DATA2PCE^PXAPI(TIUPXAPI,"TIU","TEXT INTEGRATION UTILITIES",.TIUVSIT,DUZ,0)
.K @TIUPXAPI
I '+$G(TIUVSIT) D Q
.S $P(TIUY,U,2)="Couldn't find nor create a visit for the given visit string."
;Set the document's SECONDARY VISIT field
N TIUDATA
K SUCCESS
S TIUDATA(1207)=TIUVSIT
D FILE^TIUSRVP(.SUCCESS,TIUDA,.TIUDATA,1)
I '+SUCCESS S $P(TIUY,U,2)=$P(SUCCESS,U,2) Q
;Set the parent document's SECONDARY VISIT field
N TIUDAD
S TIUDAD=+$P($G(^TIU(8925,TIUDA,0)),U,6)
I TIUDAD>0 D Q:$P(TIUY,U,2)'=""
.I '$D(^TIU(8925,TIUDAD)) S $P(TIUY,U,2)="Parent document not found." Q
.K SUCCESS,TIUDATA
.S TIUDATA(1207)=TIUVSIT
.D FILE^TIUSRVP(.SUCCESS,TIUDAD,.TIUDATA,1)
.I '+SUCCESS S $P(TIUY,U,2)=$P(SUCCESS,U,2) Q
S TIUY=1
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HTIUPXAP3 4867 printed Dec 13, 2024@02:44:45 Page 2
TIUPXAP3 ;SLC/RMO - Link Document to Visit API ;Apr 11, 2018@12:07
+1 ;;1.0;TEXT INTEGRATION UTILITIES;**179,290**;Jun 20, 1997;Build 548
+2 ;
LNKVST(TIUDA,TIUVSIT) ;Entry point to link a document to an existing visit
+1 ; Input -- TIUDA TIU Document file (#8925) IEN
+2 ; Output -- 1=Successful and 0=Failure
+3 ; TIUVSIT Visit file (#9000010) IEN
+4 NEW OKF,TIUMVSTF
+5 ;
+6 ;Check if document needs to be linked to a visit
+7 IF $DATA(^TIU(8925,TIUDA,0))
IF $PIECE(^(0),U,3)'>0
Begin DoDot:1
+8 ;Get existing visit to associate with document
+9 DO GETVST(TIUDA,.TIUVSIT,.TIUMVSTF)
+10 ;If only one visit update the document with the visit
+11 IF $GET(TIUVSIT)>0
IF '$GET(TIUMVSTF)
Begin DoDot:2
+12 IF $$UPDVST^TIUPXAP2(TIUDA,TIUVSIT)
SET OKF=1
End DoDot:2
End DoDot:1
+13 QUIT +$GET(OKF)
+14 ;
GETVST(TIUDA,TIUVSIT,TIUMVSTF) ;Get visit to associate with document
+1 ; Input -- TIUDA TIU Document file (#8925) IEN
+2 ; Output -- TIUVSIT Visit file (#9000010) IEN
+3 ; TIUMVSTF Multiple Visit Flag
+4 ; 1=Multiple Visits
+5 ;
+6 NEW TIUD0,TIUDFN,TIUEDT,TIUHL,TIUVSITS,TIUVSTR
+7 ;
+8 ;Set variables
+9 SET TIUD0=$GET(^TIU(8925,TIUDA,0))
+10 SET TIUDFN=$PIECE(TIUD0,U,2)
SET TIUEDT=$PIECE(TIUD0,U,7)
+11 SET TIUHL=$PIECE($GET(^TIU(8925,TIUDA,12)),U,11)
+12 SET TIUVSTR=TIUHL_";"_TIUEDT_";"_$PIECE(TIUD0,U,13)
+13 ;
+14 ;Check if document is an addendum, if it is use visit of parent
+15 IF +$$ISADDNDM^TIULC1(TIUDA)
Begin DoDot:1
+16 IF $DATA(^TIU(8925,+$PIECE(TIUD0,U,6),0))
IF $PIECE(^(0),U,3)>0
SET TIUVSIT=$PIECE(^(0),U,3)
End DoDot:1
GOTO GETVSTQ
+17 ;
+18 ;Check if a document has already been entered for the Vstring,
+19 ;if it has use the visit in the AVSTRV cross-reference
+20 IF +$GET(TIUVSTR)
IF +$ORDER(^TIU(8925,"AVSTRV",+TIUDFN,TIUVSTR,0))>0
Begin DoDot:1
+21 SET TIUVSIT=+$ORDER(^TIU(8925,"AVSTRV",+TIUDFN,TIUVSTR,0))
+22 IF $PIECE($GET(^AUPNVSIT(+TIUVSIT,0)),U,5)'=TIUDFN
SET TIUVSIT=""
End DoDot:1
if $GET(TIUVSIT)>0
GOTO GETVSTQ
+23 ;
+24 ;Check PCE for a visit
+25 SET TIUVSITS=$$GETENC^PXAPI(TIUDFN,TIUEDT,TIUHL)
+26 IF TIUVSITS>0
SET TIUVSIT=+TIUVSITS
+27 ;
+28 ;Set a flag if multiple visits
+29 IF $PIECE(TIUVSITS,U,2)'=""
SET TIUMVSTF=1
GETVSTQ KILL ^TMP("PXKENC",$JOB)
+1 QUIT
LNKSVST(TIUY,TIUDFN,TIUDA,TIUVSTR) ;Entry point to link a document via its
+1 ; SECONDARY VISIT field to a daily
+2 ; hospitalization visit
+3 ; Input -- TIUDFN Patient file (#2) IEN
+4 ; TIUDA TIU Document file (#8925) IEN
+5 ; TIUVSTR IEN of visit or visit string
+6 ; Output -- TIUY=1 for Successful or
+7 ; 0^Message for Failure
+8 KILL TIUY
+9 SET TIUY=0
+10 SET TIUDFN=+$GET(TIUDFN)
IF ('TIUDFN)!('$DATA(^DPT(TIUDFN)))
Begin DoDot:1
+11 SET $PIECE(TIUY,U,2)="Invalid patient specified."
End DoDot:1
QUIT
+12 SET TIUDA=+$GET(TIUDA)
IF ('TIUDA)!('$DATA(^TIU(8925,TIUDA)))
Begin DoDot:1
+13 SET $PIECE(TIUY,U,2)="Invalid document number specified."
End DoDot:1
QUIT
+14 NEW TIUVSIT,TIUVDT
+15 SET TIUVSTR=$GET(TIUVSTR)
SET TIUVSIT=0
+16 IF TIUVSTR?1.N
Begin DoDot:1
+17 SET TIUVSIT=TIUVSTR
SET TIUVSTR=""
+18 IF ('TIUVSIT)!('$DATA(^AUPNVSIT(TIUVSIT)))
SET $PIECE(TIUY,U,2)="Invalid visit specified."
QUIT
+19 IF $PIECE($GET(^AUPNVSIT(TIUVSIT,0)),U,7)'="D"
Begin DoDot:2
+20 SET $PIECE(TIUY,U,2)="The specified visit does not have a service category of daily hospitalization."
End DoDot:2
End DoDot:1
if $PIECE(TIUY,U,2)'=""
QUIT
+21 IF TIUVSTR'=""
Begin DoDot:1
+22 IF TIUVSTR'?1.N1";"7N.1".".N1";"1U
Begin DoDot:2
+23 SET $PIECE(TIUY,U,2)="Invalid visit string format."
End DoDot:2
QUIT
+24 IF $PIECE(TIUVSTR,";",3)'="D"
Begin DoDot:2
+25 SET $PIECE(TIUY,U,2)="The specified visit does not have a service category of daily hospitalization."
QUIT
End DoDot:2
QUIT
+26 ;Check PCE for a visit
+27 NEW TIUVSITS,TIUPXAPI,SUCCESS,PIECE,EXIT
+28 SET TIUVDT=$PIECE(TIUVSTR,";",2)
+29 SET TIUVSITS=$$GETENC^PXAPI(TIUDFN,TIUVDT,+TIUVSTR)
+30 FOR PIECE=1:1:$LENGTH(TIUVSITS,U)
Begin DoDot:2
+31 SET TIUVSIT=$PIECE(TIUVSITS,U,PIECE)
+32 IF $PIECE($GET(^TMP("PXKENC",$JOB,TIUVSIT,0)),U,7)'="D"
SET TIUVSIT=0
End DoDot:2
if TIUVSIT>0
QUIT
+33 KILL ^TMP("PXKENC",$JOB)
End DoDot:1
if $PIECE(TIUY,U,2)'=""
QUIT
+34 IF TIUVSTR=""
IF 'TIUVSIT
SET $PIECE(TIUY,U,2)="No visit specified."
QUIT
+35 ;No visit found, create one
+36 IF 'TIUVSIT
Begin DoDot:1
+37 KILL ^TMP("TIUPXAPI",$JOB),TIUVSIT
SET TIUPXAPI=$NAME(^TMP("TIUPXAPI",$JOB))
+38 SET @TIUPXAPI@("ENCOUNTER",1,"ENC D/T")=TIUVDT
+39 SET @TIUPXAPI@("ENCOUNTER",1,"PATIENT")=TIUDFN
+40 SET @TIUPXAPI@("ENCOUNTER",1,"HOS LOC")=+TIUVSTR
+41 SET @TIUPXAPI@("ENCOUNTER",1,"SERVICE CATEGORY")=$PIECE(TIUVSTR,";",3)
+42 SET @TIUPXAPI@("ENCOUNTER",1,"ENCOUNTER TYPE")="P"
+43 IF $$PROVIDER^TIUPXAP1(DUZ,TIUVDT)
SET @TIUPXAPI@("PROVIDER",1,"NAME")=DUZ
+44 SET SUCCESS=$$DATA2PCE^PXAPI(TIUPXAPI,"TIU","TEXT INTEGRATION UTILITIES",.TIUVSIT,DUZ,0)
+45 KILL @TIUPXAPI
End DoDot:1
+46 IF '+$GET(TIUVSIT)
Begin DoDot:1
+47 SET $PIECE(TIUY,U,2)="Couldn't find nor create a visit for the given visit string."
End DoDot:1
QUIT
+48 ;Set the document's SECONDARY VISIT field
+49 NEW TIUDATA
+50 KILL SUCCESS
+51 SET TIUDATA(1207)=TIUVSIT
+52 DO FILE^TIUSRVP(.SUCCESS,TIUDA,.TIUDATA,1)
+53 IF '+SUCCESS
SET $PIECE(TIUY,U,2)=$PIECE(SUCCESS,U,2)
QUIT
+54 ;Set the parent document's SECONDARY VISIT field
+55 NEW TIUDAD
+56 SET TIUDAD=+$PIECE($GET(^TIU(8925,TIUDA,0)),U,6)
+57 IF TIUDAD>0
Begin DoDot:1
+58 IF '$DATA(^TIU(8925,TIUDAD))
SET $PIECE(TIUY,U,2)="Parent document not found."
QUIT
+59 KILL SUCCESS,TIUDATA
+60 SET TIUDATA(1207)=TIUVSIT
+61 DO FILE^TIUSRVP(.SUCCESS,TIUDAD,.TIUDATA,1)
+62 IF '+SUCCESS
SET $PIECE(TIUY,U,2)=$PIECE(SUCCESS,U,2)
QUIT
End DoDot:1
if $PIECE(TIUY,U,2)'=""
QUIT
+63 SET TIUY=1
+64 QUIT