ORCSEND3 ;SLC/MKB,AGP-Release cont ;05/20/2008
;;3.0;ORDER ENTRY/RESULTS REPORTING;**243,282**;Dec 17, 1997;Build 6
;
;Per VHA Directive 2004-038, this routine should not be modified.
;
;Reference to PSJORPOE supported by IA #3167
;
CHILD(STRT) ; Create child order, send to package
N ORAPPT,ORPTS,A
K ORIFN D EN^ORCSAVE Q:'$G(ORIFN) D STARTDT^ORCSAVE2(ORIFN)
I $G(STRT) D DATES^ORCSAVE2(ORIFN,STRT)
S ORCHLD=+$G(ORCHLD)+1,^OR(100,ORPARENT,2,ORIFN,0)=ORIFN,ORLAST=ORIFN
S A=$G(^OR(100,ORPARENT,0)),ORAPPT=$P(A,U,18),ORPTS=$P(A,"^",13)
S $P(^OR(100,ORIFN,0),U,18)=ORAPPT,$P(^(3),U,9)=ORPARENT
I PKG="LR" I $P(^OR(100,ORIFN,0),U,13)="" S $P(^(0),"^",13)=ORPTS
N X0 S X0=$G(^OR(100,ORPARENT,8,1,0))
I $P(X0,U,4)'=2 D SIGN^ORCSAVE2(ORIFN,+$P(X0,U,5),ORNOW,$P(X0,U,4),1)
I $D(^OR(100,ORPARENT,9)) M ^OR(100,ORIFN,9)=^OR(100,ORPARENT,9)
I $G(ORENEW) S OLD=$O(ORENEW(0)) I OLD S $P(^OR(100,OLD,3),U,6)=ORIFN,$P(^OR(100,ORIFN,3),U,5)=OLD,$P(^(3),U,11)=2 K ORENEW(OLD)
D RELEASE^ORCSAVE2(ORIFN,1,ORNOW,DUZ,$G(NATURE)),NEW^ORMBLD(ORIFN)
Q
;
DOSES(IFN) ;
N I,CNT S CNT=0
S I=+$O(^OR(100,+$G(IFN),4.5,"ID","NOW",0)) I I,$G(^OR(100,+$G(IFN),4.5,I,1)) S CNT=CNT+1
Q CNT
;
GETORDER(IFN) ; Set ORX(Inst,Ptr)=Value
N I,X,Y,PTR,INST,TYPE,SOLCNT,ADDCNT
S (SOLCNT,ADDCNT)=0
S I=0 F S I=$O(^OR(100,IFN,4.5,I)) Q:I'>0 S X=$G(^(I,0)),Y=$G(^(1)) D
. S PTR=+$P(X,U,2),INST=+$P(X,U,3),TYPE=$P($G(^ORD(101.41,PTR,1)),U)
. I TYPE'="W" S ORX(PTR,INST)=Y Q
. ;S ORX(INST,PTR)="^OR(100,"_IFN_",4.5,"_I_",2)"
. S ORX(PTR,INST)="^OR(100,"_IFN_",4.5,"_I_",2)"
Q
PSJI ;
;IV dialog
N ORPARENT,OR0,ORNP,ORDIALOG,ORDUZ,ORLOG,ORL,ORDG,ORCAT,ORX,ORP,ORI,STS
N ORDOSE,ORT,ORSCH,ORDUR,ORSTRT,ORFRST,ORCONJ,ORID,ORDD,ORSTR,ORDGNM
N ORSTART,ORCHLD,ORLAST,ORSIG,OROI,ID,OR3,ORIG,CODE,PKG,ORENEW,I,ORADMIN
N ORDUR
N CNT
S ORPARENT=+ORIFN,OR0=$G(^OR(100,ORPARENT,0)),OR3=$G(^OR(100,ORPARENT,3))
S ORCAT="I",ORNP=+$P(OR0,U,4)
;Q:$P(OR0,U,12)'="I" S ORCAT="I",ORNP=+$P(OR0,U,4)
S ORDIALOG=+$P(OR0,U,5),ORDUZ=+$P(OR0,U,6),ORLOG=$P(OR0,U,7)
S ORL=$P(OR0,U,10),ORDG=+$P(OR0,U,11),PKG=$$GET1^DIQ(9.4,+$P(OR0,U,14)_",",1)
;Build ORDIALOG Array and ORX local array
D GETDLG1^ORCD(ORDIALOG),GETORDER(ORPARENT)
;
S ORSCH=$$PTR("SCHEDULE"),ORDUR=$$PTR("DURATION")
D STRT S ORSTART=$G(ORSTRT("BEG"))
S ORADMIN=$$PTR("ADMIN TIMES")
D DATES^ORCSAVE2(ORPARENT,ORSTART) Q:$$DOSES(ORPARENT)<1
S ORFRST=$$PTR("NOW"),ORSIG=$$PTR("SIG")
;
I $P(OR3,U,11)=2,$O(^OR(100,+$P(OR3,U,5),2,0)) D
. S ORENEW=+$P(OR3,U,5),I=0
. I $$VALUE^ORX8(ORENEW,"NOW") S I=$O(^OR(100,ORENEW,2,0))
. F S I=$O(^OR(100,ORENEW,2,I)) Q:I<1 S ORENEW(I)=""
;
PSJI1 ;
;Build Order Dialog Prompts that can have Multiple Responses
F ORP="ADDITIVE","ORDERABLE ITEM","STRENGTH PSIV","UNITS","VOLUME" D
. N PTR S PTR=$$PTR(ORP) Q:PTR'>0 Q:'$D(ORX(PTR,1))
. S CNT=0 F S CNT=$O(ORX(PTR,CNT)) Q:CNT'>0 S ORDIALOG(PTR,CNT)=ORX(PTR,CNT)
;
;Build Order Dialog Responses that should be in both Child Orders
F ORP="INFUSION RATE","IV TYPE","ROUTE","URGENCY","WORD PROCESSING 1" D
. N PTR S PTR=$$PTR(ORP) Q:PTR'>0 Q:'$D(ORX(PTR,1))
. S ORDIALOG(PTR,1)=ORX(PTR,1) S:$E(ORP)="O" OROI=ORX(PTR,1) Q
;
;If NOW order create NOW Child Order
I $G(ORX(ORFRST,1)) D
. S:$D(ORX(ORP,1)) ORDIALOG(ORP,1)=ORX(ORP,1)
. ;S ID=$G(ORX(ORI,ORID)) S:$P(ID,"&",6) ORDIALOG(ORDD,1)=$P(ID,"&",6)
. S ORDIALOG(ORSCH,1)="NOW",ORSTART=$$NOW^XLFDT
. D CHILD(ORSTART)
;
;Build Order Fields for non-NOW Child Order
F ORP=ORSCH,ORADMIN,ORDUR S:$D(ORX(ORP,1)) ORDIALOG(ORP,1)=ORX(ORP,1) K:'$D(ORX(ORP,1)) ORDIALOG(ORP,1)
S ORSTART=$G(ORSTRT(1))
D CHILD(ORSTART)
;
S:$G(ORCHLD) ^OR(100,ORPARENT,2,0)="^100.002PA^"_ORLAST_U_ORCHLD
S ORIFN=ORPARENT,ORQUIT=1,OR3=$G(^OR(100,ORIFN,3)),STS=$P(OR3,U,3)
I (STS=1)!(STS=13)!(STS=11) S ORERR="1^Unable to release orders"
D RELEASE^ORCSAVE2(ORIFN,1,ORNOW,DUZ,$G(NATURE)) K ^TMP("ORWORD",$J)
S $P(^OR(100,ORIFN,3),U,8)=1 ;veil parent order - set stop date/time?
Q:(STS=1)!(STS=13)!(STS=11) ;unsuccessful
PSJI2 ; ck if parent is unsigned or edit
I $P($G(^OR(100,ORIFN,8,1,0)),U,4)=2 S $P(^(0),U,4)="" K ^OR(100,"AS",ORVP,9999999-ORLOG,ORIFN,1) ;clear ES
Q:$P(OR3,U,11)'=1 S ORIG=$P(OR3,U,5) Q:ORIG'>0
S CODE=$S($P($G(^OR(100,ORIG,3)),U,3)=5:"CA",1:"DC")
D MSG^ORMBLD(ORIG,CODE) I "^1^13^"[(U_$P($G(^OR(100,ORIG,3)),U,3)_U) D
. N NATR S NATR=+$O(^ORD(100.02,"C","C",0))
. S $P(^OR(100,ORIG,3),U,3)=12,$P(^(3),U,7)=0,^(6)=NATR_U_DUZ_U_ORNOW
. D CANCEL^ORCSEND(ORIG) ;ck for unrel actions
Q
PTR(X) ; Returns ptr of prompt X in Order Dialog file
Q +$O(^ORD(101.41,"AB",$E("OR GTX "_X,1,63),0))
;
STRT ; Build ORSTRT(inst)=date.time array of start times by dose
N OI,PSOI,XD,XH,XM,XS,ORWD,ORI,SCH,ORSD,X,ORD K ORSTRT
S OI=$G(ORX($$PTR^ORCD("OR GTX ORDERABLE ITEM"),1))
;if OI is null assume Intermittent IV order this does not required a
;solution check for an additive only value
I OI="" S OI=$G(ORX($$PTR^ORCD("OR GTX ADDITIVE"),1))
S PSOI=+$P($G(^ORD(101.43,+OI,0)),U,2),(XD,XH,XM,XS)=0
S ORWD=+$G(^SC(+$G(ORL),42)) ;ward
;S ORI=0 F S ORI=$O(ORX(ORI)) Q:ORI<1 D
S SCH=$G(ORX(ORSCH,1)),ORSD="" S:'$L(SCH) X=$$NOW^XLFDT
S:$L(SCH) ORSD=$$STARTSTP^PSJORPOE(+ORVP,SCH,PSOI,ORWD),X=$P(ORSD,U,4)
S ORSTRT(1)=$$FMADD^XLFDT(X,XD,XH,XM,XS) ;START+OFFSET
; find beginning date.time for parent
S ORI=0,X=9999999 F S ORI=$O(ORSTRT(ORI)) Q:ORI<1 I ORSTRT(ORI)<X S X=ORSTRT(ORI)
S ORSTRT("BEG")=X
Q
ORCSEND3 ;SLC/MKB,AGP-Release cont ;05/20/2008
+1 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**243,282**;Dec 17, 1997;Build 6
+2 ;
+3 ;Per VHA Directive 2004-038, this routine should not be modified.
+4 ;
+5 ;Reference to PSJORPOE supported by IA #3167
+6 ;
CHILD(STRT) ; Create child order, send to package
+1 NEW ORAPPT,ORPTS,A
+2 KILL ORIFN
DO EN^ORCSAVE
IF '$GET(ORIFN)
QUIT
DO STARTDT^ORCSAVE2(ORIFN)
+3 IF $GET(STRT)
DO DATES^ORCSAVE2(ORIFN,STRT)
+4 SET ORCHLD=+$GET(ORCHLD)+1
SET ^OR(100,ORPARENT,2,ORIFN,0)=ORIFN
SET ORLAST=ORIFN
+5 SET A=$GET(^OR(100,ORPARENT,0))
SET ORAPPT=$PIECE(A,U,18)
SET ORPTS=$PIECE(A,"^",13)
+6 SET $PIECE(^OR(100,ORIFN,0),U,18)=ORAPPT
SET $PIECE(^(3),U,9)=ORPARENT
+7 IF PKG="LR"
IF $PIECE(^OR(100,ORIFN,0),U,13)=""
SET $PIECE(^(0),"^",13)=ORPTS
+8 NEW X0
SET X0=$GET(^OR(100,ORPARENT,8,1,0))
+9 IF $PIECE(X0,U,4)'=2
DO SIGN^ORCSAVE2(ORIFN,+$PIECE(X0,U,5),ORNOW,$PIECE(X0,U,4),1)
+10 IF $DATA(^OR(100,ORPARENT,9))
MERGE ^OR(100,ORIFN,9)=^OR(100,ORPARENT,9)
+11 IF $GET(ORENEW)
SET OLD=$ORDER(ORENEW(0))
IF OLD
SET $PIECE(^OR(100,OLD,3),U,6)=ORIFN
SET $PIECE(^OR(100,ORIFN,3),U,5)=OLD
SET $PIECE(^(3),U,11)=2
KILL ORENEW(OLD)
+12 DO RELEASE^ORCSAVE2(ORIFN,1,ORNOW,DUZ,$GET(NATURE))
DO NEW^ORMBLD(ORIFN)
+13 QUIT
+14 ;
DOSES(IFN) ;
+1 NEW I,CNT
SET CNT=0
+2 SET I=+$ORDER(^OR(100,+$GET(IFN),4.5,"ID","NOW",0))
IF I
IF $GET(^OR(100,+$GET(IFN),4.5,I,1))
SET CNT=CNT+1
+3 QUIT CNT
+4 ;
GETORDER(IFN) ; Set ORX(Inst,Ptr)=Value
+1 NEW I,X,Y,PTR,INST,TYPE,SOLCNT,ADDCNT
+2 SET (SOLCNT,ADDCNT)=0
+3 SET I=0
FOR
SET I=$ORDER(^OR(100,IFN,4.5,I))
IF I'>0
QUIT
SET X=$GET(^(I,0))
SET Y=$GET(^(1))
Begin DoDot:1
+4 SET PTR=+$PIECE(X,U,2)
SET INST=+$PIECE(X,U,3)
SET TYPE=$PIECE($GET(^ORD(101.41,PTR,1)),U)
+5 IF TYPE'="W"
SET ORX(PTR,INST)=Y
QUIT
+6 ;S ORX(INST,PTR)="^OR(100,"_IFN_",4.5,"_I_",2)"
+7 SET ORX(PTR,INST)="^OR(100,"_IFN_",4.5,"_I_",2)"
End DoDot:1
+8 QUIT
PSJI ;
+1 ;IV dialog
+2 NEW ORPARENT,OR0,ORNP,ORDIALOG,ORDUZ,ORLOG,ORL,ORDG,ORCAT,ORX,ORP,ORI,STS
+3 NEW ORDOSE,ORT,ORSCH,ORDUR,ORSTRT,ORFRST,ORCONJ,ORID,ORDD,ORSTR,ORDGNM
+4 NEW ORSTART,ORCHLD,ORLAST,ORSIG,OROI,ID,OR3,ORIG,CODE,PKG,ORENEW,I,ORADMIN
+5 NEW ORDUR
+6 NEW CNT
+7 SET ORPARENT=+ORIFN
SET OR0=$GET(^OR(100,ORPARENT,0))
SET OR3=$GET(^OR(100,ORPARENT,3))
+8 SET ORCAT="I"
SET ORNP=+$PIECE(OR0,U,4)
+9 ;Q:$P(OR0,U,12)'="I" S ORCAT="I",ORNP=+$P(OR0,U,4)
+10 SET ORDIALOG=+$PIECE(OR0,U,5)
SET ORDUZ=+$PIECE(OR0,U,6)
SET ORLOG=$PIECE(OR0,U,7)
+11 SET ORL=$PIECE(OR0,U,10)
SET ORDG=+$PIECE(OR0,U,11)
SET PKG=$$GET1^DIQ(9.4,+$PIECE(OR0,U,14)_",",1)
+12 ;Build ORDIALOG Array and ORX local array
+13 DO GETDLG1^ORCD(ORDIALOG)
DO GETORDER(ORPARENT)
+14 ;
+15 SET ORSCH=$$PTR("SCHEDULE")
SET ORDUR=$$PTR("DURATION")
+16 DO STRT
SET ORSTART=$GET(ORSTRT("BEG"))
+17 SET ORADMIN=$$PTR("ADMIN TIMES")
+18 DO DATES^ORCSAVE2(ORPARENT,ORSTART)
IF $$DOSES(ORPARENT)<1
QUIT
+19 SET ORFRST=$$PTR("NOW")
SET ORSIG=$$PTR("SIG")
+20 ;
+21 IF $PIECE(OR3,U,11)=2
IF $ORDER(^OR(100,+$PIECE(OR3,U,5),2,0))
Begin DoDot:1
+22 SET ORENEW=+$PIECE(OR3,U,5)
SET I=0
+23 IF $$VALUE^ORX8(ORENEW,"NOW")
SET I=$ORDER(^OR(100,ORENEW,2,0))
+24 FOR
SET I=$ORDER(^OR(100,ORENEW,2,I))
IF I<1
QUIT
SET ORENEW(I)=""
End DoDot:1
+25 ;
PSJI1 ;
+1 ;Build Order Dialog Prompts that can have Multiple Responses
+2 FOR ORP="ADDITIVE","ORDERABLE ITEM","STRENGTH PSIV","UNITS","VOLUME"
Begin DoDot:1
+3 NEW PTR
SET PTR=$$PTR(ORP)
IF PTR'>0
QUIT
IF '$DATA(ORX(PTR,1))
QUIT
+4 SET CNT=0
FOR
SET CNT=$ORDER(ORX(PTR,CNT))
IF CNT'>0
QUIT
SET ORDIALOG(PTR,CNT)=ORX(PTR,CNT)
End DoDot:1
+5 ;
+6 ;Build Order Dialog Responses that should be in both Child Orders
+7 FOR ORP="INFUSION RATE","IV TYPE","ROUTE","URGENCY","WORD PROCESSING 1"
Begin DoDot:1
+8 NEW PTR
SET PTR=$$PTR(ORP)
IF PTR'>0
QUIT
IF '$DATA(ORX(PTR,1))
QUIT
+9 SET ORDIALOG(PTR,1)=ORX(PTR,1)
IF $EXTRACT(ORP)="O"
SET OROI=ORX(PTR,1)
QUIT
End DoDot:1
+10 ;
+11 ;If NOW order create NOW Child Order
+12 IF $GET(ORX(ORFRST,1))
Begin DoDot:1
+13 IF $DATA(ORX(ORP,1))
SET ORDIALOG(ORP,1)=ORX(ORP,1)
+14 ;S ID=$G(ORX(ORI,ORID)) S:$P(ID,"&",6) ORDIALOG(ORDD,1)=$P(ID,"&",6)
+15 SET ORDIALOG(ORSCH,1)="NOW"
SET ORSTART=$$NOW^XLFDT
+16 DO CHILD(ORSTART)
End DoDot:1
+17 ;
+18 ;Build Order Fields for non-NOW Child Order
+19 FOR ORP=ORSCH,ORADMIN,ORDUR
IF $DATA(ORX(ORP,1))
SET ORDIALOG(ORP,1)=ORX(ORP,1)
IF '$DATA(ORX(ORP,1))
KILL ORDIALOG(ORP,1)
+20 SET ORSTART=$GET(ORSTRT(1))
+21 DO CHILD(ORSTART)
+22 ;
+23 IF $GET(ORCHLD)
SET ^OR(100,ORPARENT,2,0)="^100.002PA^"_ORLAST_U_ORCHLD
+24 SET ORIFN=ORPARENT
SET ORQUIT=1
SET OR3=$GET(^OR(100,ORIFN,3))
SET STS=$PIECE(OR3,U,3)
+25 IF (STS=1)!(STS=13)!(STS=11)
SET ORERR="1^Unable to release orders"
+26 DO RELEASE^ORCSAVE2(ORIFN,1,ORNOW,DUZ,$GET(NATURE))
KILL ^TMP("ORWORD",$JOB)
+27 ;veil parent order - set stop date/time?
SET $PIECE(^OR(100,ORIFN,3),U,8)=1
+28 ;unsuccessful
IF (STS=1)!(STS=13)!(STS=11)
QUIT
PSJI2 ; ck if parent is unsigned or edit
+1 ;clear ES
IF $PIECE($GET(^OR(100,ORIFN,8,1,0)),U,4)=2
SET $PIECE(^(0),U,4)=""
KILL ^OR(100,"AS",ORVP,9999999-ORLOG,ORIFN,1)
+2 IF $PIECE(OR3,U,11)'=1
QUIT
SET ORIG=$PIECE(OR3,U,5)
IF ORIG'>0
QUIT
+3 SET CODE=$SELECT($PIECE($GET(^OR(100,ORIG,3)),U,3)=5:"CA",1:"DC")
+4 DO MSG^ORMBLD(ORIG,CODE)
IF "^1^13^"[(U_$PIECE($GET(^OR(100,ORIG,3)),U,3)_U)
Begin DoDot:1
+5 NEW NATR
SET NATR=+$ORDER(^ORD(100.02,"C","C",0))
+6 SET $PIECE(^OR(100,ORIG,3),U,3)=12
SET $PIECE(^(3),U,7)=0
SET ^(6)=NATR_U_DUZ_U_ORNOW
+7 ;ck for unrel actions
DO CANCEL^ORCSEND(ORIG)
End DoDot:1
+8 QUIT
PTR(X) ; Returns ptr of prompt X in Order Dialog file
+1 QUIT +$ORDER(^ORD(101.41,"AB",$EXTRACT("OR GTX "_X,1,63),0))
+2 ;
STRT ; Build ORSTRT(inst)=date.time array of start times by dose
+1 NEW OI,PSOI,XD,XH,XM,XS,ORWD,ORI,SCH,ORSD,X,ORD
KILL ORSTRT
+2 SET OI=$GET(ORX($$PTR^ORCD("OR GTX ORDERABLE ITEM"),1))
+3 ;if OI is null assume Intermittent IV order this does not required a
+4 ;solution check for an additive only value
+5 IF OI=""
SET OI=$GET(ORX($$PTR^ORCD("OR GTX ADDITIVE"),1))
+6 SET PSOI=+$PIECE($GET(^ORD(101.43,+OI,0)),U,2)
SET (XD,XH,XM,XS)=0
+7 ;ward
SET ORWD=+$GET(^SC(+$GET(ORL),42))
+8 ;S ORI=0 F S ORI=$O(ORX(ORI)) Q:ORI<1 D
+9 SET SCH=$GET(ORX(ORSCH,1))
SET ORSD=""
IF '$LENGTH(SCH)
SET X=$$NOW^XLFDT
+10 IF $LENGTH(SCH)
SET ORSD=$$STARTSTP^PSJORPOE(+ORVP,SCH,PSOI,ORWD)
SET X=$PIECE(ORSD,U,4)
+11 ;START+OFFSET
SET ORSTRT(1)=$$FMADD^XLFDT(X,XD,XH,XM,XS)
+12 ; find beginning date.time for parent
+13 SET ORI=0
SET X=9999999
FOR
SET ORI=$ORDER(ORSTRT(ORI))
IF ORI<1
QUIT
IF ORSTRT(ORI)<X
SET X=ORSTRT(ORI)
+14 SET ORSTRT("BEG")=X
+15 QUIT