SCAPMC23 ;ALB/REW - Team API's:TPPT ;02/19/2014
;;5.3;Scheduling;**41,148,603**;AUG 13, 1993;Build 79
;
;;1.0
TPPT(DFN,SCDATES,SCPOSA,SCUSRA,SCPURPA,SCROLEA,SCYESCL,SCLIST,SCERR) ; -- positions for a patient
; input:
; DFN = ien of PATIENT file(#2) [required]
; SCDATES("BEGIN") = begin date to search (inclusive)
; [default: TODAY]
; ("END") = end date to search (inclusive)
; [default: TODAY]
; ("INCL") = 1: only use patients who were assigned to
; team for entire date range
; 0: anytime in date range
; [default: 1]
; SCPOSA -array of pointers to team position - 404.57 (per SCPURPA)
; SCUSRA -array of pointers to user file - 8930 (per SCPURPA array)
; SCPURPA -array of pointers to team purpose file 403.47
; if none are defined - returns all teams
; if @SCPURPA@('exclude') is defined - exclude listed teams
; SCROLEA - array of pointers to std position file 403.46 (per SCPURPA)
; SCYESCL -boolean[0-NO(default)/1-YES] Include pts asc. via enrollment?
; SCLIST -array name to store list
; [ex. ^TMP("SCPT",$J)]
;
; SCERR = array NAME to store error messages.
; [ex. ^TMP("ORXX",$J)]
;
; Output:
; SCLIST() = array of positions (includes SCTP xref)
; Format:
; Subscript: Sequential # from 1 to n
; Piece Description
; 1 IEN of TEAM POSITION File (#404.57)
; 2 Name of Position
; 3 IEN of Team #404.51
; 4 IEN of file #404.43 (Pt Tm Pos Assign -404.43)
; 5 current effective date
; 6 current inactivate date (if any)
; 7 pointer to 403.46 (role)
; 8 Name of Standard Role
; 9 pointer to User Class (#8930)
; 10 Name of User Class
; 11 Pointer to patient team assignment (404.42)JLU
; Subscript: "SCTP",SCTM,IEN =""
;
; SCERR() = Array of DIALOG file messages(errors) .
; @SCERR@(0) = number of errors, undefined if none
; Format:
; Subscript: Sequential # from 1 to n
; Piece Description
; 1 IEN of DIALOG file
; Returned: 1 if ok, 0 if error
; Other:
; SCACTHIS = status (-1:err|0:inact|1:act)^404.59 ien ^actdt^inacdt
;
;
ST N SCPTTP,SCPTTP0,SCTP,SCR,SCACTHIS,SCTM,SCND,SCU,SCPTTPI,SCTPA,SCPTBEG,SCPTEND,SCTPPT,SCTEAMA,SCENROLL
N SCLSEQ,SCN,SCESEQ,SCPARM,SCBEGIN,SCEND,SCINCL,SCDTS,SCPTPA
; -- initialize control variables
G:'$$OKDATA PRACQ
; -- loop through patient team position assignment history
; -- 603 - changed quit condition on 3 for loops below to prevent endless loop when bad data
S (SCTP,SCTPA)=0
F S SCTP=$O(^SCPT(404.43,"ADFN",DFN,SCTP)) Q:SCTP="" D
.F SCPTTP=0:0 S SCPTTP=$O(^SCPT(404.43,"ADFN",DFN,SCTP,SCPTTP)) Q:SCPTTP="" D
.. ; S SCPTTPI=$O(^SCPT(404.43,"ADFN",DFN,SCTP,SCPTTP,0))
.. ; replaced line above with FOR LOOP and new dot level below. Now loops thru all assignments
.. ; made on a given day - PDR 9/98
.. S SCPTPA="" ; position assignment IEN
.. F S SCPTPA=$O(^SCPT(404.43,"ADFN",DFN,SCTP,SCPTTP,SCPTPA)) Q:SCPTPA="" D
... S SCPTTP0=$G(^SCPT(404.43,SCPTPA,0))
... S SCPTBEG=$P(SCPTTP0,U,3)
... S SCPTEND=$P(SCPTTP0,U,4)
... Q:1>$$DTCHK^SCAPU1(SCBEGIN,SCEND,SCINCL,SCPTBEG,SCPTEND)
... S SCACTHIS=$$ACTHIST^SCAPMCU2(404.59,SCTP,SCDATES,SCERR,"SCTPPT")
... ; --- below changes scacthis to send 404.43 data
... S:SCPTBEG>$P(SCACTHIS,U,3) $P(SCACTHIS,U,3)=SCPTBEG
... S:SCPTEND&((SCPTEND<$P(SCACTHIS,U,4))!('$P(SCACTHIS,U,4))) $P(SCACTHIS,U,4)=SCPTEND
... S $P(SCACTHIS,U,2)=SCPTPA ; SCPTTPI
... Q:'SCACTHIS
... Q:'$$OKARRAY^SCAPU1(.SCPOSA,.SCTP)
... S SCND=$G(^SCTM(404.57,SCTP,0)) ;the team position 0 node
... S SCU=$P(SCND,U,13)
... Q:'$$OKUSRCL^SCAPU1(.SCUSRA,.SCU)
... S SCTM=$P(SCND,U,2)
... S SCP=$P(^SCTM(404.51,+SCTM,0),U,3)
... Q:'$$OKARRAY^SCAPU1(.SCPURPA,.SCP)
... S SCPTA=0
... S SCR=+$P(SCND,U,3)
... Q:'$$OKARRAY^SCAPU1(.SCROLEA,.SCR)
... D BLD^SCAPMC24(.SCLIST,SCTM,SCTP,SCACTHIS,SCR)
; - if scyescl=1 get enrolled clinics & find positions associated w clinc for teams that the pt is in
G:'SCYESCL PRACQ
IF '$$TMPT^SCAPMC(DFN,SCDATES,.SCPURPA,"SCTEAMA",.SCERR) G PRACQ
IF '$$CLPT^SCAPMC29(DFN,SCDATES,"SCTEAMA","SCENROLL",.SCERR) G PRACQ
IF '$G(SCENROLL(0)) G PRACQ
S INDX=0
F INDX=1:1:$G(SCENROLL(0)) S SCX=$G(SCENROLL(INDX)) D
.IF 'SCX D Q
..S SCPARM("Enroll Xref")=$G(SCX)
..D ERR^SCAPMCU1(.SCESEQ,,SCPARM,"",.SCERR)
.S SC44=$P(SCX,U,1)
.S ENR("BEGIN")=$S(SCBEGIN>$P(SCX,U,3):SCBEGIN,1:$P(SCX,U,3))
.S ENR("END")=$S('$P(SCX,U,4):SCEND,(SCEND<$P(SCX,U,4)):SCEND,1:$P(SCX,U,4))
.S ENR("INCL")=SCINCL
.Q:'$$TPCL^SCAPMC(SC44,"ENR",.SCPOSA,.SCUSRA,.SCPURPA,.SCROLEA,.SCLIST,.SCERR)
PRACQ Q $G(@SCERR@(0))<1
;
OKDATA() ;setup/check variables
N SCOK
S SCOK=1
D INIT^SCAPMCU1(.SCOK) ; set default dates & error array (if undefined)
S SCYESCL=+$G(SCYESCL,0)
IF '$D(^DPT(+$G(DFN),0)) D S SCOK=0
. S SCPARM("Patient")=$G(DFN,"Undefined")
. D ERR^SCAPMCU1(.SCESEQ,4045101,.SCPARM,"",.SCERR)
;
Q SCOK
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSCAPMC23 5432 printed Dec 13, 2024@02:37:57 Page 2
SCAPMC23 ;ALB/REW - Team API's:TPPT ;02/19/2014
+1 ;;5.3;Scheduling;**41,148,603**;AUG 13, 1993;Build 79
+2 ;
+3 ;;1.0
TPPT(DFN,SCDATES,SCPOSA,SCUSRA,SCPURPA,SCROLEA,SCYESCL,SCLIST,SCERR) ; -- positions for a patient
+1 ; input:
+2 ; DFN = ien of PATIENT file(#2) [required]
+3 ; SCDATES("BEGIN") = begin date to search (inclusive)
+4 ; [default: TODAY]
+5 ; ("END") = end date to search (inclusive)
+6 ; [default: TODAY]
+7 ; ("INCL") = 1: only use patients who were assigned to
+8 ; team for entire date range
+9 ; 0: anytime in date range
+10 ; [default: 1]
+11 ; SCPOSA -array of pointers to team position - 404.57 (per SCPURPA)
+12 ; SCUSRA -array of pointers to user file - 8930 (per SCPURPA array)
+13 ; SCPURPA -array of pointers to team purpose file 403.47
+14 ; if none are defined - returns all teams
+15 ; if @SCPURPA@('exclude') is defined - exclude listed teams
+16 ; SCROLEA - array of pointers to std position file 403.46 (per SCPURPA)
+17 ; SCYESCL -boolean[0-NO(default)/1-YES] Include pts asc. via enrollment?
+18 ; SCLIST -array name to store list
+19 ; [ex. ^TMP("SCPT",$J)]
+20 ;
+21 ; SCERR = array NAME to store error messages.
+22 ; [ex. ^TMP("ORXX",$J)]
+23 ;
+24 ; Output:
+25 ; SCLIST() = array of positions (includes SCTP xref)
+26 ; Format:
+27 ; Subscript: Sequential # from 1 to n
+28 ; Piece Description
+29 ; 1 IEN of TEAM POSITION File (#404.57)
+30 ; 2 Name of Position
+31 ; 3 IEN of Team #404.51
+32 ; 4 IEN of file #404.43 (Pt Tm Pos Assign -404.43)
+33 ; 5 current effective date
+34 ; 6 current inactivate date (if any)
+35 ; 7 pointer to 403.46 (role)
+36 ; 8 Name of Standard Role
+37 ; 9 pointer to User Class (#8930)
+38 ; 10 Name of User Class
+39 ; 11 Pointer to patient team assignment (404.42)JLU
+40 ; Subscript: "SCTP",SCTM,IEN =""
+41 ;
+42 ; SCERR() = Array of DIALOG file messages(errors) .
+43 ; @SCERR@(0) = number of errors, undefined if none
+44 ; Format:
+45 ; Subscript: Sequential # from 1 to n
+46 ; Piece Description
+47 ; 1 IEN of DIALOG file
+48 ; Returned: 1 if ok, 0 if error
+49 ; Other:
+50 ; SCACTHIS = status (-1:err|0:inact|1:act)^404.59 ien ^actdt^inacdt
+51 ;
+52 ;
ST NEW SCPTTP,SCPTTP0,SCTP,SCR,SCACTHIS,SCTM,SCND,SCU,SCPTTPI,SCTPA,SCPTBEG,SCPTEND,SCTPPT,SCTEAMA,SCENROLL
+1 NEW SCLSEQ,SCN,SCESEQ,SCPARM,SCBEGIN,SCEND,SCINCL,SCDTS,SCPTPA
+2 ; -- initialize control variables
+3 if '$$OKDATA
GOTO PRACQ
+4 ; -- loop through patient team position assignment history
+5 ; -- 603 - changed quit condition on 3 for loops below to prevent endless loop when bad data
+6 SET (SCTP,SCTPA)=0
+7 FOR
SET SCTP=$ORDER(^SCPT(404.43,"ADFN",DFN,SCTP))
if SCTP=""
QUIT
Begin DoDot:1
+8 FOR SCPTTP=0:0
SET SCPTTP=$ORDER(^SCPT(404.43,"ADFN",DFN,SCTP,SCPTTP))
if SCPTTP=""
QUIT
Begin DoDot:2
+9 ; S SCPTTPI=$O(^SCPT(404.43,"ADFN",DFN,SCTP,SCPTTP,0))
+10 ; replaced line above with FOR LOOP and new dot level below. Now loops thru all assignments
+11 ; made on a given day - PDR 9/98
+12 ; position assignment IEN
SET SCPTPA=""
+13 FOR
SET SCPTPA=$ORDER(^SCPT(404.43,"ADFN",DFN,SCTP,SCPTTP,SCPTPA))
if SCPTPA=""
QUIT
Begin DoDot:3
+14 SET SCPTTP0=$GET(^SCPT(404.43,SCPTPA,0))
+15 SET SCPTBEG=$PIECE(SCPTTP0,U,3)
+16 SET SCPTEND=$PIECE(SCPTTP0,U,4)
+17 if 1>$$DTCHK^SCAPU1(SCBEGIN,SCEND,SCINCL,SCPTBEG,SCPTEND)
QUIT
+18 SET SCACTHIS=$$ACTHIST^SCAPMCU2(404.59,SCTP,SCDATES,SCERR,"SCTPPT")
+19 ; --- below changes scacthis to send 404.43 data
+20 if SCPTBEG>$PIECE(SCACTHIS,U,3)
SET $PIECE(SCACTHIS,U,3)=SCPTBEG
+21 if SCPTEND&((SCPTEND<$PIECE(SCACTHIS,U,4))!('$PIECE(SCACTHIS,U,4)))
SET $PIECE(SCACTHIS,U,4)=SCPTEND
+22 ; SCPTTPI
SET $PIECE(SCACTHIS,U,2)=SCPTPA
+23 if 'SCACTHIS
QUIT
+24 if '$$OKARRAY^SCAPU1(.SCPOSA,.SCTP)
QUIT
+25 ;the team position 0 node
SET SCND=$GET(^SCTM(404.57,SCTP,0))
+26 SET SCU=$PIECE(SCND,U,13)
+27 if '$$OKUSRCL^SCAPU1(.SCUSRA,.SCU)
QUIT
+28 SET SCTM=$PIECE(SCND,U,2)
+29 SET SCP=$PIECE(^SCTM(404.51,+SCTM,0),U,3)
+30 if '$$OKARRAY^SCAPU1(.SCPURPA,.SCP)
QUIT
+31 SET SCPTA=0
+32 SET SCR=+$PIECE(SCND,U,3)
+33 if '$$OKARRAY^SCAPU1(.SCROLEA,.SCR)
QUIT
+34 DO BLD^SCAPMC24(.SCLIST,SCTM,SCTP,SCACTHIS,SCR)
End DoDot:3
End DoDot:2
End DoDot:1
+35 ; - if scyescl=1 get enrolled clinics & find positions associated w clinc for teams that the pt is in
+36 if 'SCYESCL
GOTO PRACQ
+37 IF '$$TMPT^SCAPMC(DFN,SCDATES,.SCPURPA,"SCTEAMA",.SCERR)
GOTO PRACQ
+38 IF '$$CLPT^SCAPMC29(DFN,SCDATES,"SCTEAMA","SCENROLL",.SCERR)
GOTO PRACQ
+39 IF '$GET(SCENROLL(0))
GOTO PRACQ
+40 SET INDX=0
+41 FOR INDX=1:1:$GET(SCENROLL(0))
SET SCX=$GET(SCENROLL(INDX))
Begin DoDot:1
+42 IF 'SCX
Begin DoDot:2
+43 SET SCPARM("Enroll Xref")=$GET(SCX)
+44 DO ERR^SCAPMCU1(.SCESEQ,,SCPARM,"",.SCERR)
End DoDot:2
QUIT
+45 SET SC44=$PIECE(SCX,U,1)
+46 SET ENR("BEGIN")=$SELECT(SCBEGIN>$PIECE(SCX,U,3):SCBEGIN,1:$PIECE(SCX,U,3))
+47 SET ENR("END")=$SELECT('$PIECE(SCX,U,4):SCEND,(SCEND<$PIECE(SCX,U,4)):SCEND,1:$PIECE(SCX,U,4))
+48 SET ENR("INCL")=SCINCL
+49 if '$$TPCL^SCAPMC(SC44,"ENR",.SCPOSA,.SCUSRA,.SCPURPA,.SCROLEA,.SCLIST,.SCERR)
QUIT
End DoDot:1
PRACQ QUIT $GET(@SCERR@(0))<1
+1 ;
OKDATA() ;setup/check variables
+1 NEW SCOK
+2 SET SCOK=1
+3 ; set default dates & error array (if undefined)
DO INIT^SCAPMCU1(.SCOK)
+4 SET SCYESCL=+$GET(SCYESCL,0)
+5 IF '$DATA(^DPT(+$GET(DFN),0))
Begin DoDot:1
+6 SET SCPARM("Patient")=$GET(DFN,"Undefined")
+7 DO ERR^SCAPMCU1(.SCESEQ,4045101,.SCPARM,"",.SCERR)
End DoDot:1
SET SCOK=0
+8 ;
+9 QUIT SCOK
+10 ;