ORQ1 ;slc/dcm - Get orders for a patient. ;Apr 09, 2020@12:52:38
;;3.0;ORDER ENTRY/RESULTS REPORTING;**27,72,78,141,190,215,444,515**;Dec 17, 1997;Build 8
;
;EPIP/RTW Modified for the Unified Action Profile 26 Oct 2016
EN(PAT,GROUP,FLG,EXPAND,SDATE,EDATE,DETAIL,MULT,XREF,GETKID,EVENT) ;Get orders
; Returns orders in ^TMP("ORR",$J,ORLIST,i) for defined context:
;
; PAT =patient variable ptr in format "DFN;DPT("
; GROUP=Display group
; FLG =#: Includes status:
; 1. All => 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
; 2. Active/Current => 3,4,5,6, 8,9, 11, 15
; Includes CONTEXT HRS 1,2,7,13 & Action Status=13
; Orders in ^OR(100,"AC",PAT,TM,IFN,ACTION)
; 3. Discontinued => 1 12,13
; 4. Completed/Expired => 2, 7
; 5. Expiring => 3,4,5,6, 8,9
; 6. Recent Activity => 1,2,3,4,5,6,7,8,9, 12, 15
; Orders in ^OR(100,"AR",PAT,TM,IFN,ACTION)
; 7. Pending => 5
; 8. Unverified => 1, 3,4,5,6, 8,9, 15
; 9. Unverified/Nurse => 1, 3,4,5,6, 8,9, 15
;10. Unverified/Clerk => 1, 3,4,5,6, 8,9, 15
;11. Unsigned => 1,2,3,4,5,6,7,8,9,10,11, 13,14,15
; Orders in ^OR(100,"AS",PAT,TM,IFN)
;12. Flagged => 1,2,3,4,5,6,7,8,9, 12,13,14,15
;13. Verbal/Phoned => 1,2,3,4,5,6,7,8,9, 13,14,15
; Nature of order of verbal or phoned
;14. Verb/Phn unsigned => 1,2,3,4,5,6,7,8,9, 13,14,15
; Nature of order V or P & unsigned
;15. Admission => 6, 10
;16. Discharge => 6, 10
;17. Transfer => 6, 10
; Orders in ^OR(100,"AEVNT",PAT,EVENT,IFN)
;18. On Hold => 3
;19. New Orders => 10,11
; Orders in ^TMP("ORNEW",$J,ORIFN)
;20. Chart Review => 1, 3,4,5,6, 8,9, 15
;21. Chart Copy Summary=> same as All w/screen on Nature of order
;22. Lapsed => 14
;23. Active status => 5,6
;24. All Delayed => 6, 10
;25. Out of OR => 6, 10
;26. Manual Release => 6, 10
;27. Expired => 7
;28. Discontinued Entered in Error => code handles this in ORQ12
; Orders in ^OR(100,"AEVNT",PAT,EVENT,IFN)
;29. Unverified => 1, 3,4,5,6, 29,30, 15
;30. Unverified/Nurse => 1, 3,4,5,6, 29,30, 15
;31. Unverified/Clerk => 1, 3,4,5,6, 29,30 15
;32. Unverified/Chart => 1, 3,4,5,6, 29,30 15
EN0 ; where order status=#:
; 1 => Discontinued (dc) 6 => Active (a) 11 => Unreleased (u)
; 2 => Complete (c) 7 => Expired (e) 12 => DC/Edit (dce)
; 3 => Hold (h) 8 => Scheduled (s) 13 => Cancelled (x)
; 4 => Flagged (?) 9 => Partial Results (pr) 14 => Lapsed (l)
; 5 => Pending (p) 10 => Delayed (d) 15 => Renewed (rn)
; 99 => No Status (')
; EXPAND=ifn of parent order, used to expand child orders
; SDATE =Start date
; EDATE =End date
; DETAIL=Data to be returned (optional, default=0):
; 0 => ^TMP("ORR",$J,ORLIST,i) = order #
; 1 => ^TMP("ORR",$J,ORLIST,i) = order #^display group^when entered^
; start d/t^stop d/t^status^sts abbrv
; ^TMP("ORR",$J,ORLIST,i,"TX",j) = order text
; MULT =0:Don't allow multiple occurrences of order
; =1:Allow multiple occurrences
; XREF =cross reference to use instead of ACT (AW for completed orders)
; GETKID=includes children of multiple orders
; EVENT =ptr to Patient Event file #100.2, for orders tied to an event
;
EN1 ; -- start here
Q:'$G(PAT) N X,ORLST,ORGRP,LAPSE
S:'$G(GROUP) GROUP=$O(^ORD(100.98,"B","ALL SERVICES",0))
S:'$G(FLG) FLG=2 S:'$G(DETAIL) DETAIL=0 S:'$G(MULT) MULT=0
I $G(EDATE)<$G(SDATE) S X=EDATE,EDATE=SDATE,SDATE=X
I $G(EDATE) S EDATE=$S($L(EDATE,".")=2:EDATE+.0001,1:EDATE+1)
I $G(SDATE) S SDATE=$S($L(SDATE,".")=2:SDATE-.0001,1:SDATE)
S SDATE=9999999-$S($G(SDATE):SDATE,FLG=6:DT-.7641,1:0),EDATE=9999999-$S($G(EDATE):EDATE,FLG=6:DT+.2359,1:9999998)
S ORLST=0,X=EDATE,EDATE=SDATE,SDATE=X D GRP(GROUP),LIST
S LAPSE=+$$GET^XPAR("ALL","OR DELAYED ORDERS LAPSE DAYS")
S:LAPSE LAPSE=$$FMADD^XLFDT(DT,(0-LAPSE)) ;=0 or cutoff date
I "^15^16^17^24^25^26^"[(U_FLG_U)!$G(EVENT) D EN^ORQ13 G ENQ
;RTW BEGIN UAP MODIFICATION
I $$GET1^DIQ(100.98,GROUP,.01)="DISCHARGE MEDS" D LOOP^ORQ11 G ENQ
I $$GET1^DIQ(100.98,GROUP,.01)="PHARMACY UAP" D LOOP^ORQ11 G ENQ
;RTW END UAP MODIFICATION
D @($S(FLG=2:"CUR",FLG=5:"EXG","^6^8^9^10^20^29^30^31^32^"[(U_FLG_U):"ACT",FLG=11:"SIG",FLG=19:"NEW","^1^3^4^7^12^13^14^18^21^22^23^27^28^"[(U_FLG_U):"LOOP",1:"QUIT")_"^ORQ11")
ENQ K ^TMP("ORGOTIT",$J)
Q
;
LIST ;Get entry in ^TMP("ORR",$J,ORLIST)
S ORLIST=$H
L +^TMP("ORR",$J,ORLIST):$S($G(DILOCKTM)>0:DILOCKTM,1:5) I '$T G LIST
I $D(^TMP("ORR",$J,ORLIST)) L -^TMP("ORR",$J,ORLIST) H 1 G LIST
S ^TMP("ORR",$J,ORLIST)=""
L -^TMP("ORR",$J,ORLIST)
Q
;
GRP(DG) ;Setup display groups
;DG=Display group to expand
N STK,MEM
S ORGRP(DG)="",STK=1,STK(STK)=DG_"^0",STK(0)=0,MEM=0
F S MEM=$O(^ORD(100.98,+STK(STK),1,MEM)) D @$S(+MEM'>0:"POP",1:"PROC") Q:STK<1
Q
;
POP S STK=STK-1,MEM=$P(STK(STK),"^",2)
Q
PROC S $P(STK(STK),"^",2)=MEM,DG=$P(^ORD(100.98,+STK(STK),1,MEM,0),"^",1)
S ORGRP(DG)="",STK=STK+1,STK(STK)=DG_"^0",MEM=0
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HORQ1 5267 printed Oct 16, 2024@18:33:38 Page 2
ORQ1 ;slc/dcm - Get orders for a patient. ;Apr 09, 2020@12:52:38
+1 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**27,72,78,141,190,215,444,515**;Dec 17, 1997;Build 8
+2 ;
+3 ;EPIP/RTW Modified for the Unified Action Profile 26 Oct 2016
EN(PAT,GROUP,FLG,EXPAND,SDATE,EDATE,DETAIL,MULT,XREF,GETKID,EVENT) ;Get orders
+1 ; Returns orders in ^TMP("ORR",$J,ORLIST,i) for defined context:
+2 ;
+3 ; PAT =patient variable ptr in format "DFN;DPT("
+4 ; GROUP=Display group
+5 ; FLG =#: Includes status:
+6 ; 1. All => 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
+7 ; 2. Active/Current => 3,4,5,6, 8,9, 11, 15
+8 ; Includes CONTEXT HRS 1,2,7,13 & Action Status=13
+9 ; Orders in ^OR(100,"AC",PAT,TM,IFN,ACTION)
+10 ; 3. Discontinued => 1 12,13
+11 ; 4. Completed/Expired => 2, 7
+12 ; 5. Expiring => 3,4,5,6, 8,9
+13 ; 6. Recent Activity => 1,2,3,4,5,6,7,8,9, 12, 15
+14 ; Orders in ^OR(100,"AR",PAT,TM,IFN,ACTION)
+15 ; 7. Pending => 5
+16 ; 8. Unverified => 1, 3,4,5,6, 8,9, 15
+17 ; 9. Unverified/Nurse => 1, 3,4,5,6, 8,9, 15
+18 ;10. Unverified/Clerk => 1, 3,4,5,6, 8,9, 15
+19 ;11. Unsigned => 1,2,3,4,5,6,7,8,9,10,11, 13,14,15
+20 ; Orders in ^OR(100,"AS",PAT,TM,IFN)
+21 ;12. Flagged => 1,2,3,4,5,6,7,8,9, 12,13,14,15
+22 ;13. Verbal/Phoned => 1,2,3,4,5,6,7,8,9, 13,14,15
+23 ; Nature of order of verbal or phoned
+24 ;14. Verb/Phn unsigned => 1,2,3,4,5,6,7,8,9, 13,14,15
+25 ; Nature of order V or P & unsigned
+26 ;15. Admission => 6, 10
+27 ;16. Discharge => 6, 10
+28 ;17. Transfer => 6, 10
+29 ; Orders in ^OR(100,"AEVNT",PAT,EVENT,IFN)
+30 ;18. On Hold => 3
+31 ;19. New Orders => 10,11
+32 ; Orders in ^TMP("ORNEW",$J,ORIFN)
+33 ;20. Chart Review => 1, 3,4,5,6, 8,9, 15
+34 ;21. Chart Copy Summary=> same as All w/screen on Nature of order
+35 ;22. Lapsed => 14
+36 ;23. Active status => 5,6
+37 ;24. All Delayed => 6, 10
+38 ;25. Out of OR => 6, 10
+39 ;26. Manual Release => 6, 10
+40 ;27. Expired => 7
+41 ;28. Discontinued Entered in Error => code handles this in ORQ12
+42 ; Orders in ^OR(100,"AEVNT",PAT,EVENT,IFN)
+43 ;29. Unverified => 1, 3,4,5,6, 29,30, 15
+44 ;30. Unverified/Nurse => 1, 3,4,5,6, 29,30, 15
+45 ;31. Unverified/Clerk => 1, 3,4,5,6, 29,30 15
+46 ;32. Unverified/Chart => 1, 3,4,5,6, 29,30 15
EN0 ; where order status=#:
+1 ; 1 => Discontinued (dc) 6 => Active (a) 11 => Unreleased (u)
+2 ; 2 => Complete (c) 7 => Expired (e) 12 => DC/Edit (dce)
+3 ; 3 => Hold (h) 8 => Scheduled (s) 13 => Cancelled (x)
+4 ; 4 => Flagged (?) 9 => Partial Results (pr) 14 => Lapsed (l)
+5 ; 5 => Pending (p) 10 => Delayed (d) 15 => Renewed (rn)
+6 ; 99 => No Status (')
+7 ; EXPAND=ifn of parent order, used to expand child orders
+8 ; SDATE =Start date
+9 ; EDATE =End date
+10 ; DETAIL=Data to be returned (optional, default=0):
+11 ; 0 => ^TMP("ORR",$J,ORLIST,i) = order #
+12 ; 1 => ^TMP("ORR",$J,ORLIST,i) = order #^display group^when entered^
+13 ; start d/t^stop d/t^status^sts abbrv
+14 ; ^TMP("ORR",$J,ORLIST,i,"TX",j) = order text
+15 ; MULT =0:Don't allow multiple occurrences of order
+16 ; =1:Allow multiple occurrences
+17 ; XREF =cross reference to use instead of ACT (AW for completed orders)
+18 ; GETKID=includes children of multiple orders
+19 ; EVENT =ptr to Patient Event file #100.2, for orders tied to an event
+20 ;
EN1 ; -- start here
+1 if '$GET(PAT)
QUIT
NEW X,ORLST,ORGRP,LAPSE
+2 if '$GET(GROUP)
SET GROUP=$ORDER(^ORD(100.98,"B","ALL SERVICES",0))
+3 if '$GET(FLG)
SET FLG=2
if '$GET(DETAIL)
SET DETAIL=0
if '$GET(MULT)
SET MULT=0
+4 IF $GET(EDATE)<$GET(SDATE)
SET X=EDATE
SET EDATE=SDATE
SET SDATE=X
+5 IF $GET(EDATE)
SET EDATE=$SELECT($LENGTH(EDATE,".")=2:EDATE+.0001,1:EDATE+1)
+6 IF $GET(SDATE)
SET SDATE=$SELECT($LENGTH(SDATE,".")=2:SDATE-.0001,1:SDATE)
+7 SET SDATE=9999999-$SELECT($GET(SDATE):SDATE,FLG=6:DT-.7641,1:0)
SET EDATE=9999999-$SELECT($GET(EDATE):EDATE,FLG=6:DT+.2359,1:9999998)
+8 SET ORLST=0
SET X=EDATE
SET EDATE=SDATE
SET SDATE=X
DO GRP(GROUP)
DO LIST
+9 SET LAPSE=+$$GET^XPAR("ALL","OR DELAYED ORDERS LAPSE DAYS")
+10 ;=0 or cutoff date
if LAPSE
SET LAPSE=$$FMADD^XLFDT(DT,(0-LAPSE))
+11 IF "^15^16^17^24^25^26^"[(U_FLG_U)!$GET(EVENT)
DO EN^ORQ13
GOTO ENQ
+12 ;RTW BEGIN UAP MODIFICATION
+13 IF $$GET1^DIQ(100.98,GROUP,.01)="DISCHARGE MEDS"
DO LOOP^ORQ11
GOTO ENQ
+14 IF $$GET1^DIQ(100.98,GROUP,.01)="PHARMACY UAP"
DO LOOP^ORQ11
GOTO ENQ
+15 ;RTW END UAP MODIFICATION
+16 DO @($SELECT(FLG=2:"CUR",FLG=5:"EXG","^6^8^9^10^20^29^30^31^32^"[(U_FLG_U):"ACT",FLG=11:"SIG",FLG=19:"NEW","^1^3^4^7^12^13^14^18^21^22^23^27^28^"[(U_FLG_U):"LOOP",1:"QUIT")_"^ORQ11")
ENQ KILL ^TMP("ORGOTIT",$JOB)
+1 QUIT
+2 ;
LIST ;Get entry in ^TMP("ORR",$J,ORLIST)
+1 SET ORLIST=$HOROLOG
+2 LOCK +^TMP("ORR",$JOB,ORLIST):$SELECT($GET(DILOCKTM)>0:DILOCKTM,1:5)
IF '$TEST
GOTO LIST
+3 IF $DATA(^TMP("ORR",$JOB,ORLIST))
LOCK -^TMP("ORR",$JOB,ORLIST)
HANG 1
GOTO LIST
+4 SET ^TMP("ORR",$JOB,ORLIST)=""
+5 LOCK -^TMP("ORR",$JOB,ORLIST)
+6 QUIT
+7 ;
GRP(DG) ;Setup display groups
+1 ;DG=Display group to expand
+2 NEW STK,MEM
+3 SET ORGRP(DG)=""
SET STK=1
SET STK(STK)=DG_"^0"
SET STK(0)=0
SET MEM=0
+4 FOR
SET MEM=$ORDER(^ORD(100.98,+STK(STK),1,MEM))
DO @$SELECT(+MEM'>0:"POP",1:"PROC")
if STK<1
QUIT
+5 QUIT
+6 ;
POP SET STK=STK-1
SET MEM=$PIECE(STK(STK),"^",2)
+1 QUIT
PROC SET $PIECE(STK(STK),"^",2)=MEM
SET DG=$PIECE(^ORD(100.98,+STK(STK),1,MEM,0),"^",1)
+1 SET ORGRP(DG)=""
SET STK=STK+1
SET STK(STK)=DG_"^0"
SET MEM=0
+2 QUIT