Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: OREVNTX

OREVNTX.m

Go to the documentation of this file.
  1. OREVNTX ; SLC/MKB - Event delayed orders RPC's ;06/16/10 05:32
  1. ;;3.0;ORDER ENTRY/RESULTS REPORTING;**141,243,280**;Dec 17, 1997;Build 85
  1. ;
  1. PAT(ORY,DFN) ; -- Returns currently delayed events for patient DFN
  1. N EVT,CNT,X,Y S DFN=+$G(DFN),(EVT,CNT)=0
  1. F S EVT=+$O(^ORE(100.2,"AE",DFN,EVT)) Q:EVT<1 S Y=+$O(^(EVT,0)) D
  1. . I $G(^ORE(100.2,Y,1)) K ^ORE(100.2,"AE",DFN,EVT,Y) Q
  1. . Q:$$LAPSED(Y) ;I $$EMPTY(Y) D CANCEL(Y) Q
  1. . Q:$O(^ORE(100.2,"DAD",Y,0)) ;has children
  1. . S X=$P($G(^ORD(100.5,EVT,0)),U,8),X="Delayed "_$$LOWER^VALM1(X)
  1. . S CNT=CNT+1,ORY(CNT)=Y_U_X
  1. S:CNT ORY(0)=CNT
  1. Q
  1. ;
  1. EXISTS(DFN,EVT) ; -- Returns 1 if patient DFN has delayed orders for EVT,
  1. ; or 2 if parent/sibling event has delayed orders, else 0
  1. ;
  1. N X,Y,I S Y=0 I '$G(DFN)!'$G(EVT) G EXQ
  1. I $O(^ORE(100.2,"AE",+DFN,+EVT,0)) S Y=1 G EXQ
  1. S X=+$P($G(^ORD(100.5,+EVT,0)),U,12) I X D G EXQ ;ck parent,siblings
  1. . I $O(^ORE(100.2,"AE",+DFN,X,0)) S Y=2 Q
  1. . S I=0 F S I=+$O(^ORD(100.5,"DAD",X,I)) Q:I<1 I $O(^ORE(100.2,"AE",+DFN,I,0)) S Y=2 Q
  1. EXQ Q Y
  1. ;
  1. LIST(ORY,DFN) ; -- Returns all processed events for patient DFN as
  1. ; ORY(#) = PatEvtIEN ^ Display Text ^ EvtDateTime
  1. ; in reverse chronological order
  1. N IDT,DA,CNT,X0,X1,EVT,DC,X
  1. S DFN=+$G(DFN),(IDT,CNT)=0
  1. F S IDT=$O(^ORE(100.2,"AC",DFN,IDT)) Q:IDT<1 D
  1. . S DA=0 F S DA=+$O(^ORE(100.2,"AC",DFN,IDT,DA)) Q:DA<1 D
  1. .. S X0=$G(^ORE(100.2,DA,0)),X1=$G(^(1)) Q:$P(X1,U,5) ;has parent
  1. .. S EVT=+$P(X0,U,2),DC=+$P(X1,U,3)
  1. .. I '$P(X0,U,4),'$O(^ORE(100.2,DA,2,0)),'$O(^ORE(100.2,DA,3,0)),'$D(^OR(100,"AEVNT",DFN_";DPT(",DA)) Q ;no orders
  1. .. S I=+$O(^ORE(100.2,DA,10,"B"),-1),X=$P($G(^(I,0)),U,2) I X="LP"!(X="CA") Q ;lapsed or cancelled
  1. .. ;Q if not current admission?
  1. .. S X=$S(EVT:$P($G(^ORD(100.5,EVT,0)),U,8),DC:$P($G(^ORD(100.6,DC,0)),U,5),1:"UNSPECIFIED EVENT")
  1. .. S X=$$LOWER^VALM1(X),CNT=CNT+1,ORY(CNT)=DA_U_X_U_$P(X1,U)
  1. S:CNT ORY(0)=CNT
  1. Q
  1. ;
  1. COMP(PTEVT) ; -- Returns 1 or 0, if PTEVT has been completed
  1. N Y,I S Y=$S($G(^ORE(100.2,+$G(PTEVT),1)):1,1:0)
  1. I Y S I=+$O(^ORE(100.2,+$G(PTEVT),10,0)) S:$P($G(^(I,0)),U,2)="CA" Y=0
  1. Q Y
  1. ;
  1. ACTIVE(ORY,TYPE) ; -- Returns all active events [of TYPE] from #100.5
  1. ; where TYPE=string containing any of the codes from the TYPE field
  1. N NM,IEN,CNT,X0,X S CNT=0,TYPE=$G(TYPE)
  1. S NM="" F S NM=$O(^ORD(100.5,"C",NM)) Q:NM="" D
  1. . S IEN=0 F S IEN=+$O(^ORD(100.5,"C",NM,IEN)) Q:IEN<1 D
  1. .. S X0=$G(^ORD(100.5,IEN,0)) I '$L($P(X0,U,2)) D ;Child event
  1. ... S X=$P(X0,U,12) S:X $P(X0,U,2)=$P($G(^ORD(100.5,+X,0)),U,2)
  1. .. I $L(TYPE),TYPE'[$P(X0,U,2) Q
  1. .. Q:$O(^ORD(100.5,"DAD",IEN,0)) ;Parent event
  1. .. S CNT=CNT+1,ORY(CNT)=IEN_U_X0
  1. S:CNT ORY(0)=CNT
  1. Q
  1. ;
  1. NAME(PTEVT) ; -- Return name of Patient Event
  1. N X,Y,Z S X=+$P($G(^ORE(100.2,+$G(PTEVT),0)),U,2),Z=$G(^(1))
  1. S:X Y=$P($G(^ORD(100.5,X,0)),U,8)
  1. I 'X S X=+$P(Z,U,3),Y=$P($G(^ORD(100.6,X,0)),U,5)
  1. S Y=$S('Z:"Delayed ",1:"")_$$LOWER^VALM1(Y)
  1. Q Y
  1. ;
  1. SHORTNM(PTEVT) ; -- Return Short Name of Patient Event
  1. ; or first 15 characters of Event Name if unspecified
  1. N X,Y,Y0 S X=+$P($G(^ORE(100.2,+$G(PTEVT),0)),U,2) I X D
  1. . S Y0=$G(^ORD(100.5,X,0)),Y=$P(Y0,U,10)
  1. . S:'$L(Y) Y=$E($P(Y0,U,8),1,15)
  1. I 'X S X=+$P($G(^ORE(100.2,+$G(PTEVT),1)),U,3),Y=$E($P($G(^ORD(100.6,X,0)),U,5),1,15)
  1. Q Y
  1. ;
  1. EVT(PTEVT) ; -- Return Event ptr #100.5, given PTEVT ptr #100.2
  1. Q +$P($G(^ORE(100.2,+$G(PTEVT),0)),U,2)
  1. ;
  1. DC(PTEVT) ; -- Return DC Rule ptr #100.6, given PTEVT ptr #100.2
  1. I $P($G(^ORE(100.2,+$G(PTEVT),1)),U,5) S PTEVT=$P(^(1),U,5) ;use parent
  1. Q +$P($G(^ORE(100.2,+$G(PTEVT),1)),U,3)
  1. ;
  1. TYPE(PTEVT) ; -- Return Type of Patient Event (i.e. A/D/T)
  1. N X,Y S X=+$P($G(^ORE(100.2,+$G(PTEVT),0)),U,2)
  1. I $P($G(^ORD(100.5,X,0)),U,12) S X=$P(^(0),U,12) ;use parent
  1. S Y=$S(X:$P($G(^ORD(100.5,X,0)),U,2),1:"DC")
  1. Q Y
  1. ;
  1. DIV(PTEVT) ; -- Return Division for PTEVT
  1. N X,Y S X=+$P($G(^ORE(100.2,+$G(PTEVT),0)),U,2)
  1. I $P($G(^ORD(100.5,X,0)),U,12) S X=$P(^(0),U,12) ;use parent
  1. S Y=+$P($G(^ORD(100.5,X,0)),U,3) S:Y<1 Y=+$G(DUZ(2))
  1. Q Y
  1. ;
  1. LOC(PTEVT) ; -- Return Default Ordering Location for PTEVT
  1. N X,X0,Y S X=+$P($G(^ORE(100.2,+$G(PTEVT),0)),U,2)
  1. S X0=$G(^ORD(100.5,X,0)),Y=+$P(X0,U,9)_";SC("
  1. I Y<1,$P(X0,U,12) S Y=+$P($G(^ORD(100.5,+$P(X0,U,12),0)),U,9)_";SC("
  1. S:Y<1 Y=$G(ORL)
  1. Q Y
  1. ;
  1. EMPTY(PTEVT) ; -- Returns 1 or 0, if PTEVT has delayed orders
  1. N Y,OR0,PAT,TYPE,PSO,IFN,STS S Y=1 I '$G(PTEVT) Q Y
  1. S OR0=$G(^ORE(100.2,+PTEVT,0)),PAT=+$P(OR0,U)_";DPT("
  1. S TYPE=$$TYPE(PTEVT) I TYPE="D" S PSO=+$O(^DIC(9.4,"C","PSO",0))
  1. S IFN=0 F S IFN=$O(^OR(100,"AEVNT",PAT,PTEVT,IFN)) Q:IFN<1 D Q:'Y
  1. . S STS=$P($G(^OR(100,IFN,3)),U,3) I STS=10 S Y=0 Q
  1. . ;I IFN=+$P(OR0,U,4),STS=11!(STS=6) S Y=0 Q
  1. . I TYPE="D",$P($G(^OR(100,IFN,0)),U,14)=PSO,STS=5!(STS=6) S Y=0 Q
  1. I Y,$D(^ORE(100.2,"DAD",PTEVT)) D ;ck child events
  1. . N CHLD S CHLD=0
  1. . F S CHLD=+$O(^ORE(100.2,"DAD",PTEVT,CHLD)) Q:CHLD<1 D Q:'Y
  1. .. S IFN=0 F S IFN=$O(^OR(100,"AEVNT",PAT,CHLD,IFN)) Q:IFN<1 I $P($G(^OR(100,IFN,3)),U,3)=10 S Y=0 Q
  1. Q Y
  1. ;
  1. EVTORDER(ORDER) ; -- Returns 1 or 0, if ORDER is for event
  1. ; Will return 0 if action DA is included but not NW
  1. N X0,X,Y S X0=$G(^OR(100,+ORDER,0)),X=+$P(ORDER,";",2),Y=0
  1. I $P(X0,U,17),X'>1 D
  1. . I $P($G(^ORE(100.2,+$P(X0,U,17),0)),U,4)=+ORDER S Y=1 Q
  1. . S DAD=+$P($G(^ORE(100.2,+$P(X0,U,17),1)),U,5) ;has parent?
  1. . I DAD,$P($G(^ORE(100.2,DAD,0)),U,4)=+ORDER S Y=1
  1. Q Y
  1. ;
  1. MANREL(ORDER) ; -- Returns 1 or 0, if ORDER was manually released
  1. N EVT,Y,RELDT,TYPE,EVTDT S Y=0
  1. S EVT=+$P($G(^OR(100,+ORDER,0)),U,17),RELDT=+$P($G(^(8,1,0)),U,16)
  1. G:EVT<1 MNQ G:RELDT<1 MNQ ;not delayed or released
  1. I '$D(^ORE(100.2,EVT,2,+ORDER)) S Y=1 G MNQ ;not rel'd by event
  1. S TYPE=$$TYPE(EVT),EVTDT=+$G(^ORE(100.2,EVT,1))
  1. I TYPE="M",$$FMDIFF^XLFDT(EVTDT,RELDT,2)<300 S Y=1
  1. MNQ Q Y
  1. ;
  1. CANCEL(PTEVT) ; -- Cancel empty PTEVT, event order
  1. S PTEVT=+$G(PTEVT) D DONE(PTEVT),ACTLOG(PTEVT,"CA")
  1. N IFN,DAD S IFN=+$P($G(^ORE(100.2,PTEVT,0)),U,4)
  1. I IFN<1 D ;ck for parent w/event order
  1. . S DAD=+$P($G(^ORE(100.2,PTEVT,1)),U,5) Q:DAD<1
  1. . Q:'$G(^ORE(100.2,DAD,1)) ;parent still active
  1. . S IFN=+$P($G(^ORE(100.2,DAD,0)),U,4)
  1. I IFN D:'$$DCD^ORCACT2(IFN) CLRDLY^ORCACT2(IFN) ;cancel event order
  1. Q
  1. ;
  1. DONE(PTEVT,WHEN,MVT,OR) ; -- Terminate PTEVT
  1. Q:'$G(PTEVT) Q:'$D(^ORE(100.2,PTEVT,0))
  1. N X0,X1,PAT,EVT,DAD
  1. S:'$G(WHEN) WHEN=+$E($$NOW^XLFDT,1,12) D D1
  1. S DAD=$P(X1,U,5) I DAD,$$ALLDONE(DAD) S PTEVT=DAD D D1 Q
  1. S DAD=PTEVT,PTEVT=0 ;if PTEVT=parent, terminate children too
  1. F S PTEVT=+$O(^ORE(100.2,"DAD",DAD,PTEVT)) Q:PTEVT<1 D D1
  1. Q
  1. D1 S X0=$G(^ORE(100.2,+PTEVT,0)),X1=$G(^(1)) Q:'$L(X0)
  1. S PAT=+$P(X0,U),EVT=+$P(X0,U,2) ;,ORD=+$P(X0,U,4)
  1. S $P(X1,U,1,2)=WHEN_U_$G(MVT),$P(X1,U,4)=$G(OR),^ORE(100.2,PTEVT,1)=X1
  1. S ^ORE(100.2,"AC",PAT,9999999-WHEN,PTEVT)=""
  1. S:$G(OR) ^ORE(100.2,"ASR",OR,PTEVT)=""
  1. K:EVT ^ORE(100.2,"AE",PAT,EVT,PTEVT)
  1. Q
  1. ;
  1. ALLDONE(DAD) ; -- Returns 1 or 0, if all child events are done
  1. N I,Y S Y=1,I=0
  1. F S I=+$O(^ORE(100.2,"DAD",+$G(DAD),I)) Q:I<1 I '$G(^ORE(100.2,I,1)) S Y=0 Q
  1. Q Y
  1. ;
  1. CHGEVT(IFN,NEWEVT) ; -- Change the Patient Event for order IFN to NEWEVT
  1. ; Includes adding or removing event pointer to order
  1. Q:'$G(IFN) N PAT,OLDEVT,OR3 S:$G(NEWEVT) NEWEVT=+NEWEVT
  1. S PAT=$P($G(^OR(100,+IFN,0)),U,2),OLDEVT=$P($G(^(0)),U,17),OR3=$G(^(3))
  1. Q:OLDEVT=NEWEVT K:OLDEVT ^OR(100,"AEVNT",PAT,OLDEVT,+IFN)
  1. S $P(^OR(100,+IFN,0),U,17)=NEWEVT S:NEWEVT ^OR(100,"AEVNT",PAT,NEWEVT,+IFN)=""
  1. I NEWEVT,$P(OR3,U,3)'=10 S $P(^OR(100,+IFN,3),U,3)=10,$P(^(8,1,0),U,15)=10
  1. I 'NEWEVT,$P(OR3,U,3)=10 S $P(^OR(100,+IFN,3),U,3)=11,$P(^(8,1,0),U,15)=11 D SET^ORDD100(+IFN,1)
  1. Q
  1. ;
  1. ACTLOG(PTEVT,ACTION,EVTYPE,SAVE) ; -- Log a note for ACTION on PTEVT
  1. ; SAVE => new data in VAIP() will be saved
  1. Q:'$G(PTEVT) Q:'$D(^ORE(100.2,PTEVT,0)) Q:'$L($G(ACTION))
  1. N I,HDR,LAST,TOTAL,DA,ORNOW,MVT
  1. F I=1:1:10 L +^ORE(100.2,PTEVT,10,0):1 Q:$T H 2
  1. Q:'$T "^" S HDR=$G(^ORE(100.2,PTEVT,10,0)) S:'$L(HDR) HDR="^100.25DA^^"
  1. S TOTAL=+$P(HDR,U,4),LAST=+$O(^ORE(100.2,PTEVT,10,"B"),-1)
  1. S I=LAST F I=(I+1):1 Q:'$D(^ORE(100.2,PTEVT,10,I,0))
  1. S DA=I,$P(HDR,U,3,4)=DA_U_(TOTAL+1)
  1. S ^ORE(100.2,PTEVT,10,0)=HDR L -^ORE(100.2,PTEVT,10,0)
  1. S ORNOW=+$$NOW^XLFDT,^ORE(100.2,PTEVT,10,"B",ORNOW,DA)=""
  1. S ^ORE(100.2,PTEVT,10,DA,0)=ORNOW_U_ACTION_U_$S(ACTION="LP":"",1:$G(DUZ))_U_$G(EVTYPE)
  1. S MVT=+$P($G(^ORE(100.2,PTEVT,1)),U,2)
  1. S:MVT ^ORE(100.2,"ADT",MVT,ORNOW,PTEVT,DA)=""
  1. I $G(SAVE),$G(VAIP(4)) S $P(^ORE(100.2,PTEVT,10,DA,0),U,5,7)=+VAIP(4)_U_+VAIP(8)_U_+VAIP(5)
  1. Q
  1. ;
  1. LAPSED(PTEVT) ; -- Ck if PTEVT has lapsed, if so lapse all orders
  1. N Y,X0,EVT,ENTERED,DAYS,ORN,ORCA,ORSIGDT S Y=0
  1. I $G(^ORE(100.2,PTEVT,1)) G LPQ ;already terminated
  1. S X0=$G(^ORE(100.2,PTEVT,0)),EVT=+$P(X0,U,2)
  1. S:$P($G(^ORD(100.5,EVT,0)),U,12) EVT=+$P(^(0),U,12) ;parent
  1. S ENTERED="9999999"
  1. ; if event order is signed then ENTERED needs to be the DT it was signed from file 100
  1. S ORN=$P(^ORE(100.2,PTEVT,0),U,4)
  1. I +ORN S ORCA=$P($G(^OR(100,+ORN,3)),U,7)
  1. I $G(ORCA) S ORSIGDT=$P($G(^OR(100,+ORN,8,ORCA,0)),U,6)
  1. I $G(ORSIGDT) S ENTERED=ORSIGDT
  1. ; if event order is not signed then ENTERED needs to be the ENTERED DT from file 100.2
  1. I ENTERED="9999999" S ENTERED=+$P(X0,U,5)
  1. S DAYS=+$P($G(^ORD(100.5,EVT,0)),U,6) I DAYS<1 G LPQ ;doesn't lapse
  1. I ENTERED>$$FMADD^XLFDT(DT,(0-DAYS)) G LPQ ;not lapsed yet
  1. D LP1(PTEVT) S Y=1 ;lapse orders, event
  1. N J S J=0 F S J=$O(^ORE(100.2,"DAD",PTEVT,J)) Q:'J D LP1(J)
  1. LPQ Q Y
  1. ;
  1. LP1(PTEVT) ; -- Lapse orders, event PTEVT
  1. N X0,PAT,IFN,STS
  1. S X0=$G(^ORE(100.2,PTEVT,0)),PAT=+$P(X0,U)_";DPT("
  1. S IFN=0 F S IFN=$O(^OR(100,"AEVNT",PAT,PTEVT,IFN)) Q:IFN<1 D
  1. . S STS=$P($G(^OR(100,IFN,3)),U,3) I (STS=10)!(STS=11)!(IFN=+$P(X0,U,4)) D
  1. .. D STATUS^ORCSAVE2(IFN,14)
  1. .. D ALPS^ORCSAVE2(IFN,1,"DELAYED ORDER")
  1. .. S $P(^OR(100,IFN,8,1,0),U,15)="" D:$P(^(0),U,4)=2 SIGN^ORCSAVE2(IFN,"","",5,1)
  1. D DONE(PTEVT),ACTLOG(PTEVT,"LP")
  1. Q