ORRCDPT ;SLC/MKB - Patient List for Physician Dashboard ; 19 Sept 2003 10:09 AM
;;1.0;CARE MANAGEMENT;**5**;Jul 15, 2003;Build 4
;
MAIN(ORY,USER,TYPE,LIST) ; -- Return patient list for dashboard
; where USER = pointer to #200
; TYPE = (C)linician or (N)urse view
; LIST(#) = <list-type>:<list-ID>:<clinic start>:<clinic stop>
; RPC = ORRC DASHBOARD PATIENTS
;
D EXPDATES(.LIST) ;expand dates
S USER=+$G(USER),TYPE=$$UP^XLFSTR($G(TYPE))
I TYPE="N" D EN^ORRCDPT1(.ORY,USER,.LIST) Q
I $O(LIST(0)) D EN1(.ORY,USER,.LIST) Q
D EN(.ORY,USER)
Q
;
EN(ORY,ORUSR) ; -- Return each patient to list on dashboard for ORUSR
; in @ORY@(#) = "Patient=<dfn>^<name>^<ssn>^<dob>^<age>"
; = "Result=ORR:##^ORR:##^...^*ORR:##"
; = "Task=TSK:##^TSK:##^...^*TSK:##"
; = "Event=VST:ID^VST:ID^...^VST:ID"
; = "Unsigned=ORD:##^...^ORD:##^DOC:##^...^DOC:##"
; = "Notifications=1"
; RPC = ORRC PHY DASHBD PATIENTS
S ORUSR=+$G(ORUSR) K ^TMP($J,"ORRCPTS"),^TMP($J,"ORRCY"),^TMP($J,"ORRCLST")
D RSLT,TASK,EVNT,SIGN ;build ^TMP($J,"ORRCY",DFN,"<type>",ID)=* or null
I $D(^TMP($J,"ORRCY")) D FORMAT
K ^TMP($J,"ORRCY")
Q
;
EN1(ORY,ORUSR,ORLST) ; -- Return patients on ORLST for ORUSR's dashboard
; in @ORY@(#) = "Patient=<dfn>^<name>^<ssn>^<dob>^<age>"
; = "Result=ORR:##^ORR:##^...^*ORR:##"
; = "Task=TSK:##^TSK:##^...^*TSK:##"
; = "Event=VST:ID^VST:ID^...^VST:ID"
; = "Unsigned=ORD:##^...^ORD:##^DOC:##^...^DOC:##"
; = "Error=^<error description>"
N ORI,ORX,X,ORID,ORPAT,ORTN,ORBEG,OREND,ORJ,PAT,ERRI S ORUSR=+$G(ORUSR),ERRI=0
K ^TMP($J,"ORRCY"),^TMP($J,"ORRCNOTF"),^TMP($J,"ORRCPTS")
S ^TMP($J,"ORRCLST")=""
N ORSRV,FROM
S ORSRV=$G(^VA(200,DUZ,5)) I +ORSRV>0 S ORSRV=$P(ORSRV,U)
S FROM=$$GET^XPAR("USR^SRV.`"_+$G(ORSRV),"ORLP DEFAULT LIST SOURCE",1,"Q")
S ORI=0 F S ORI=$O(ORLST(ORI)) Q:ORI<1 S ORX=$G(ORLST(ORI)) D
. S X=$$UP^XLFSTR($P(ORX,":")),ORID=+$P(ORX,":",2) D Q:'$G(ORPAT(1))
.. I X="X" D DEFLIST^ORQPTQ11(.ORPAT) D:$G(FROM)="M" Q
... S ORJ=0 F S ORJ=$O(^TMP("OR",$J,"PATIENTS",ORJ)) Q:ORJ<1 S PAT=+$G(^(ORJ,0)),^TMP($J,"ORRCY",PAT)=""
.. I X="T" D TEAMPTS^ORQPTQ1(.ORPAT,ORID) Q
.. S ORTN=$S(X="P":"PROV",X="S":"SPEC",X="W":"WARD",X="C":"CLIN",1:"") Q:'$L(ORTN)
.. I X'="C" S ORTN=ORTN_"PTS^ORQPTQ2(.ORPAT,ORID)" D @ORTN Q
.. S ORBEG=$P(ORX,":",3),OREND=$P(ORX,":",4)
.. D CLINPTS^ORQPTQ2(.ORPAT,ORID,ORBEG,OREND)
.. I $D(ORPAT(1)),'+$G(ORPAT(1)),ORPAT(1)'="^No appointments." S ERRI=ERRI+1,^TMP($J,"ORRCDPT_ERROR",ERRI)=ORPAT(1)
. S ORJ=0 F S ORJ=$O(ORPAT(ORJ)) Q:ORJ<1 S PAT=+$G(ORPAT(ORJ)),^TMP($J,"ORRCY",PAT)=""
I $D(^TMP($J,"ORRCY")) D ;there are patients on selected list(s)
. ; build ^TMP($J,"ORRCY",DFN,"<type>",ID)=* or null:
. D RSLT,TASK,EVNT,SIGN,FORMAT
D ERROR(.ORY)
K ^TMP($J,"ORRCY"),^TMP($J,"ORRCNOTF"),^TMP($J,"ORRCLST"),^TMP($J,"ORRCDPT_ERROR")
Q
;
ERROR(ORY) ; -- process errors
I '$D(^TMP($J,"ORRCDPT_ERROR")) Q
N I,J S I=0,J=0
I '$D(ORY) S ORY=$$GETRET
F S I=$O(@ORY@(I)) Q:I'>0 S J=I
S I=0
F S I=$O(^TMP($J,"ORRCDPT_ERROR",I)) Q:I'>0 S J=J+1,@ORY@(J)="Error="_^TMP($J,"ORRCDPT_ERROR",I)
Q
;
RSLT ; -- find patients with unack'd results for ORUSR's orders
N ORACK,PAT
D PATS^ORRCACK(.ORACK,ORUSR) S PAT=0
F S PAT=+$O(@ORACK@(PAT)) Q:PAT<1 M ^TMP($J,"ORRCY",PAT,"R")=@ORACK@(PAT)
K @ORACK
Q
;
TASK ; -- find patients with tasks not complete
N ORTSK,PAT
D PATS^ORRCTSK(.ORTSK,ORUSR) S PAT=0
F S PAT=+$O(@ORTSK@(PAT)) Q:PAT<1 M ^TMP($J,"ORRCY",PAT,"T")=@ORTSK@(PAT)
K @ORTSK
Q
;
EVNT ; -- find patients that ORUSR has outstanding ADT alerts for
N OREVT,PAT
D PATS^ORRCEVT(.OREVT,ORUSR) S PAT=0
F S PAT=+$O(@OREVT@(PAT)) Q:PAT<1 M ^TMP($J,"ORRCY",PAT,"E")=@OREVT@(PAT)
K @OREVT
Q
;
SIGN ; -- find patients that have orders or notes ORUSR needs to sign
N ORDER,ORDOC,PAT
;D PTUNS^ORRCOR(.ORDER,ORUSR) S PAT=0
;F S PAT=+$O(ORDER(PAT)) Q:PAT<1 M ^TMP($J,"ORRCY",PAT,"U")=ORDER(PAT)
D GETPTUNS^ORRCTIU(.ORDOC,ORUSR) S PAT=0
F S PAT=+$O(@ORDOC@(PAT)) Q:PAT<1 M ^TMP($J,"ORRCY",PAT,"U")=@ORDOC@(PAT)
K @ORDOC
Q
;
FORMAT ; -- Format return array ^TMP($J,"ORRCPTS") from temp array ^TMP($J,"ORRCY")
N ORPT,ORN,DFN,VADM,VA,VAERR
S ORY=$$GETRET
S (ORPT,ORN)=0 F S ORPT=$O(^TMP($J,"ORRCY",ORPT)) Q:ORPT<1 D
. S DFN=ORPT D DEM^VADPT
. S ORN=ORN+1,@ORY@(ORN)="Patient="_DFN_U_VADM(1)_U_VA("PID")_U_$$FMTHL7^XLFDT(+VADM(3))_U_VADM(4)
. I $D(^TMP($J,"ORRCY",ORPT,"R")) D ADD("Result")
. I $D(^TMP($J,"ORRCY",ORPT,"T")) D ADD("Task")
. I $D(^TMP($J,"ORRCY",ORPT,"E")) D ADD("Event")
. I $D(^TMP($J,"ORRCY",ORPT,"U")) D ADD("Unsigned")
. I $G(^TMP($J,"ORRCNOTF",ORPT)) S ORN=ORN+1,@ORY@(ORN)="Notifications=1"
Q
;
GETRET() ;Returns the return variable pointer
Q $NA(^TMP($J,"ORRCPTS"))
;
ADD(TYPE) ; -- Add item IDs from ^TMP($J,"ORRCY",PAT,<TYPE>) into return array
N ORX,ORSUB,ORID,X,ORU
S ORX=TYPE_"=",ORSUB=$E(TYPE),ORID="",ORU=""
F S ORID=$O(^TMP($J,"ORRCY",ORPT,ORSUB,ORID)) Q:ORID="" S X=$G(^(ORID))_ORID D
. I $L(ORX)+$L(X)>254 S ORN=ORN+1,@ORY@(ORN)=ORX,ORX=TYPE_"=",ORU=""
. S ORX=ORX_ORU_X,ORU=U
S ORN=ORN+1,@ORY@(ORN)=ORX
Q
;
EXPDATES(LIST) ;Expand dates for clinic appointments, if they need to be expanded. These would be a year or quarter indicators on clinic appt lists.
;Ex. YC = current year, YC-4 = current year - 4, etc.
N I,RANGE S I=0
F S I=$O(LIST(I)) Q:I'>0 D
.I $P(LIST(I),":",1)="c",$L(LIST(I),":")=3 D
..S RANGE=$$RNG2FM^ORRHCU($P(LIST(I),":",3))
..S $P(LIST(I),":",3)=$P(RANGE,":",1)
..S $P(LIST(I),":",4)=$P(RANGE,":",2)
Q
;
ORRCDPT ;SLC/MKB - Patient List for Physician Dashboard ; 19 Sept 2003 10:09 AM
+1 ;;1.0;CARE MANAGEMENT;**5**;Jul 15, 2003;Build 4
+2 ;
MAIN(ORY,USER,TYPE,LIST) ; -- Return patient list for dashboard
+1 ; where USER = pointer to #200
+2 ; TYPE = (C)linician or (N)urse view
+3 ; LIST(#) = <list-type>:<list-ID>:<clinic start>:<clinic stop>
+4 ; RPC = ORRC DASHBOARD PATIENTS
+5 ;
+6 ;expand dates
DO EXPDATES(.LIST)
+7 SET USER=+$GET(USER)
SET TYPE=$$UP^XLFSTR($GET(TYPE))
+8 IF TYPE="N"
DO EN^ORRCDPT1(.ORY,USER,.LIST)
QUIT
+9 IF $ORDER(LIST(0))
DO EN1(.ORY,USER,.LIST)
QUIT
+10 DO EN(.ORY,USER)
+11 QUIT
+12 ;
EN(ORY,ORUSR) ; -- Return each patient to list on dashboard for ORUSR
+1 ; in @ORY@(#) = "Patient=<dfn>^<name>^<ssn>^<dob>^<age>"
+2 ; = "Result=ORR:##^ORR:##^...^*ORR:##"
+3 ; = "Task=TSK:##^TSK:##^...^*TSK:##"
+4 ; = "Event=VST:ID^VST:ID^...^VST:ID"
+5 ; = "Unsigned=ORD:##^...^ORD:##^DOC:##^...^DOC:##"
+6 ; = "Notifications=1"
+7 ; RPC = ORRC PHY DASHBD PATIENTS
+8 SET ORUSR=+$GET(ORUSR)
KILL ^TMP($JOB,"ORRCPTS"),^TMP($JOB,"ORRCY"),^TMP($JOB,"ORRCLST")
+9 ;build ^TMP($J,"ORRCY",DFN,"<type>",ID)=* or null
DO RSLT
DO TASK
DO EVNT
DO SIGN
+10 IF $DATA(^TMP($JOB,"ORRCY"))
DO FORMAT
+11 KILL ^TMP($JOB,"ORRCY")
+12 QUIT
+13 ;
EN1(ORY,ORUSR,ORLST) ; -- Return patients on ORLST for ORUSR's dashboard
+1 ; in @ORY@(#) = "Patient=<dfn>^<name>^<ssn>^<dob>^<age>"
+2 ; = "Result=ORR:##^ORR:##^...^*ORR:##"
+3 ; = "Task=TSK:##^TSK:##^...^*TSK:##"
+4 ; = "Event=VST:ID^VST:ID^...^VST:ID"
+5 ; = "Unsigned=ORD:##^...^ORD:##^DOC:##^...^DOC:##"
+6 ; = "Error=^<error description>"
+7 NEW ORI,ORX,X,ORID,ORPAT,ORTN,ORBEG,OREND,ORJ,PAT,ERRI
SET ORUSR=+$GET(ORUSR)
SET ERRI=0
+8 KILL ^TMP($JOB,"ORRCY"),^TMP($JOB,"ORRCNOTF"),^TMP($JOB,"ORRCPTS")
+9 SET ^TMP($JOB,"ORRCLST")=""
+10 NEW ORSRV,FROM
+11 SET ORSRV=$GET(^VA(200,DUZ,5))
IF +ORSRV>0
SET ORSRV=$PIECE(ORSRV,U)
+12 SET FROM=$$GET^XPAR("USR^SRV.`"_+$GET(ORSRV),"ORLP DEFAULT LIST SOURCE",1,"Q")
+13 SET ORI=0
FOR
SET ORI=$ORDER(ORLST(ORI))
IF ORI<1
QUIT
SET ORX=$GET(ORLST(ORI))
Begin DoDot:1
+14 SET X=$$UP^XLFSTR($PIECE(ORX,":"))
SET ORID=+$PIECE(ORX,":",2)
Begin DoDot:2
+15 IF X="X"
DO DEFLIST^ORQPTQ11(.ORPAT)
IF $GET(FROM)="M"
Begin DoDot:3
+16 SET ORJ=0
FOR
SET ORJ=$ORDER(^TMP("OR",$JOB,"PATIENTS",ORJ))
IF ORJ<1
QUIT
SET PAT=+$GET(^(ORJ,0))
SET ^TMP($JOB,"ORRCY",PAT)=""
End DoDot:3
QUIT
+17 IF X="T"
DO TEAMPTS^ORQPTQ1(.ORPAT,ORID)
QUIT
+18 SET ORTN=$SELECT(X="P":"PROV",X="S":"SPEC",X="W":"WARD",X="C":"CLIN",1:"")
IF '$LENGTH(ORTN)
QUIT
+19 IF X'="C"
SET ORTN=ORTN_"PTS^ORQPTQ2(.ORPAT,ORID)"
DO @ORTN
QUIT
+20 SET ORBEG=$PIECE(ORX,":",3)
SET OREND=$PIECE(ORX,":",4)
+21 DO CLINPTS^ORQPTQ2(.ORPAT,ORID,ORBEG,OREND)
+22 IF $DATA(ORPAT(1))
IF '+$GET(ORPAT(1))
IF ORPAT(1)'="^No appointments."
SET ERRI=ERRI+1
SET ^TMP($JOB,"ORRCDPT_ERROR",ERRI)=ORPAT(1)
End DoDot:2
IF '$GET(ORPAT(1))
QUIT
+23 SET ORJ=0
FOR
SET ORJ=$ORDER(ORPAT(ORJ))
IF ORJ<1
QUIT
SET PAT=+$GET(ORPAT(ORJ))
SET ^TMP($JOB,"ORRCY",PAT)=""
End DoDot:1
+24 ;there are patients on selected list(s)
IF $DATA(^TMP($JOB,"ORRCY"))
Begin DoDot:1
+25 ; build ^TMP($J,"ORRCY",DFN,"<type>",ID)=* or null:
+26 DO RSLT
DO TASK
DO EVNT
DO SIGN
DO FORMAT
End DoDot:1
+27 DO ERROR(.ORY)
+28 KILL ^TMP($JOB,"ORRCY"),^TMP($JOB,"ORRCNOTF"),^TMP($JOB,"ORRCLST"),^TMP($JOB,"ORRCDPT_ERROR")
+29 QUIT
+30 ;
ERROR(ORY) ; -- process errors
+1 IF '$DATA(^TMP($JOB,"ORRCDPT_ERROR"))
QUIT
+2 NEW I,J
SET I=0
SET J=0
+3 IF '$DATA(ORY)
SET ORY=$$GETRET
+4 FOR
SET I=$ORDER(@ORY@(I))
IF I'>0
QUIT
SET J=I
+5 SET I=0
+6 FOR
SET I=$ORDER(^TMP($JOB,"ORRCDPT_ERROR",I))
IF I'>0
QUIT
SET J=J+1
SET @ORY@(J)="Error="_^TMP($JOB,"ORRCDPT_ERROR",I)
+7 QUIT
+8 ;
RSLT ; -- find patients with unack'd results for ORUSR's orders
+1 NEW ORACK,PAT
+2 DO PATS^ORRCACK(.ORACK,ORUSR)
SET PAT=0
+3 FOR
SET PAT=+$ORDER(@ORACK@(PAT))
IF PAT<1
QUIT
MERGE ^TMP($JOB,"ORRCY",PAT,"R")=@ORACK@(PAT)
+4 KILL @ORACK
+5 QUIT
+6 ;
TASK ; -- find patients with tasks not complete
+1 NEW ORTSK,PAT
+2 DO PATS^ORRCTSK(.ORTSK,ORUSR)
SET PAT=0
+3 FOR
SET PAT=+$ORDER(@ORTSK@(PAT))
IF PAT<1
QUIT
MERGE ^TMP($JOB,"ORRCY",PAT,"T")=@ORTSK@(PAT)
+4 KILL @ORTSK
+5 QUIT
+6 ;
EVNT ; -- find patients that ORUSR has outstanding ADT alerts for
+1 NEW OREVT,PAT
+2 DO PATS^ORRCEVT(.OREVT,ORUSR)
SET PAT=0
+3 FOR
SET PAT=+$ORDER(@OREVT@(PAT))
IF PAT<1
QUIT
MERGE ^TMP($JOB,"ORRCY",PAT,"E")=@OREVT@(PAT)
+4 KILL @OREVT
+5 QUIT
+6 ;
SIGN ; -- find patients that have orders or notes ORUSR needs to sign
+1 NEW ORDER,ORDOC,PAT
+2 ;D PTUNS^ORRCOR(.ORDER,ORUSR) S PAT=0
+3 ;F S PAT=+$O(ORDER(PAT)) Q:PAT<1 M ^TMP($J,"ORRCY",PAT,"U")=ORDER(PAT)
+4 DO GETPTUNS^ORRCTIU(.ORDOC,ORUSR)
SET PAT=0
+5 FOR
SET PAT=+$ORDER(@ORDOC@(PAT))
IF PAT<1
QUIT
MERGE ^TMP($JOB,"ORRCY",PAT,"U")=@ORDOC@(PAT)
+6 KILL @ORDOC
+7 QUIT
+8 ;
FORMAT ; -- Format return array ^TMP($J,"ORRCPTS") from temp array ^TMP($J,"ORRCY")
+1 NEW ORPT,ORN,DFN,VADM,VA,VAERR
+2 SET ORY=$$GETRET
+3 SET (ORPT,ORN)=0
FOR
SET ORPT=$ORDER(^TMP($JOB,"ORRCY",ORPT))
IF ORPT<1
QUIT
Begin DoDot:1
+4 SET DFN=ORPT
DO DEM^VADPT
+5 SET ORN=ORN+1
SET @ORY@(ORN)="Patient="_DFN_U_VADM(1)_U_VA("PID")_U_$$FMTHL7^XLFDT(+VADM(3))_U_VADM(4)
+6 IF $DATA(^TMP($JOB,"ORRCY",ORPT,"R"))
DO ADD("Result")
+7 IF $DATA(^TMP($JOB,"ORRCY",ORPT,"T"))
DO ADD("Task")
+8 IF $DATA(^TMP($JOB,"ORRCY",ORPT,"E"))
DO ADD("Event")
+9 IF $DATA(^TMP($JOB,"ORRCY",ORPT,"U"))
DO ADD("Unsigned")
+10 IF $GET(^TMP($JOB,"ORRCNOTF",ORPT))
SET ORN=ORN+1
SET @ORY@(ORN)="Notifications=1"
End DoDot:1
+11 QUIT
+12 ;
GETRET() ;Returns the return variable pointer
+1 QUIT $NAME(^TMP($JOB,"ORRCPTS"))
+2 ;
ADD(TYPE) ; -- Add item IDs from ^TMP($J,"ORRCY",PAT,<TYPE>) into return array
+1 NEW ORX,ORSUB,ORID,X,ORU
+2 SET ORX=TYPE_"="
SET ORSUB=$EXTRACT(TYPE)
SET ORID=""
SET ORU=""
+3 FOR
SET ORID=$ORDER(^TMP($JOB,"ORRCY",ORPT,ORSUB,ORID))
IF ORID=""
QUIT
SET X=$GET(^(ORID))_ORID
Begin DoDot:1
+4 IF $LENGTH(ORX)+$LENGTH(X)>254
SET ORN=ORN+1
SET @ORY@(ORN)=ORX
SET ORX=TYPE_"="
SET ORU=""
+5 SET ORX=ORX_ORU_X
SET ORU=U
End DoDot:1
+6 SET ORN=ORN+1
SET @ORY@(ORN)=ORX
+7 QUIT
+8 ;
EXPDATES(LIST) ;Expand dates for clinic appointments, if they need to be expanded. These would be a year or quarter indicators on clinic appt lists.
+1 ;Ex. YC = current year, YC-4 = current year - 4, etc.
+2 NEW I,RANGE
SET I=0
+3 FOR
SET I=$ORDER(LIST(I))
IF I'>0
QUIT
Begin DoDot:1
+4 IF $PIECE(LIST(I),":",1)="c"
IF $LENGTH(LIST(I),":")=3
Begin DoDot:2
+5 SET RANGE=$$RNG2FM^ORRHCU($PIECE(LIST(I),":",3))
+6 SET $PIECE(LIST(I),":",3)=$PIECE(RANGE,":",1)
+7 SET $PIECE(LIST(I),":",4)=$PIECE(RANGE,":",2)
End DoDot:2
End DoDot:1
+8 QUIT
+9 ;