ORCACT01 ;SLC/MKB-Validate order actions cont ;14-Mar-2011 19:37;PLS
;;3.0;ORDER ENTRY/RESULTS REPORTING;**94,116,134,141,163,187,190,1002,1004,213,243,1006,1010**;Dec 17, 1997;Build 47
;Modified - IHS/MSC/PLS - 08/09/10 - Line ES+5,ES+7,RW+2
; 03/02/11 - Line XFR+5 - added check for NV RX
ES ; -- sign [on chart]
I ORDSTS=11,VER<3,PKG'="OR" S ERROR="This order cannot be released and must be discontinued!" Q
N X I ACTSTS=11!(ACTSTS=10) D Q:$L($G(ERROR))
. I $P(ORA0,U,2)="DC",$$DONE^ORCACT0 D CANCEL^ORCSEND(+IFN),UNOTIF^ORCSIGN S OREBUILD=1 Q
. S X=$$DISABLED^ORCACT0 I X S ERROR=$P(X,U,2) Q
;I ACTION="OC",$G(DG)="NV RX" S:MEDPARM<2 ERROR="You are not authorized to release outside med orders!" Q
I ACTION="OC",$L($G(NV)) S:MEDPARM<2 ERROR="You are not authorized to release "_NV_" orders!" Q
;S X=$P(ORA0,U,4) I X=3 S:ACTSTS'=11&(ACTSTS'=10) ERROR="This order does not require a signature!" Q
S X=$P(ORA0,U,4) I X=3 Q:$L($G(NV)) S:ACTSTS'=11&(ACTSTS'=10) ERROR="This order does not require a signature!" Q
I X'=2 S ERROR="This order has been signed!" Q
I DG="O RX",ACTION'="ES",ACTION'="DS",$G(NATR)'="I" S ERROR="Outpatient meds may not be released without a clinician's signature!" Q
I (ACTION="ES"!(ACTION="DS")),$D(^XUSEC("ORELSE",DUZ)),$P(OR0,U,16)'<2 S ERROR="You are not privileged to sign this order!" Q
I ACTION="OC" S:MEDPARM<2 ERROR="You are not authorized to release med orders!" Q
I ACTION="RS" D Q:$D(ERROR) Q:$G(NATR)'="I"
. Q:ACTSTS=11 Q:ACTSTS=10 ;unreleased - ok
. S ERROR="This order has already been released!"
ES1 I PKG="PS" D ;authorized to write meds?
. N TYPE,OI,PSOI,DEAFLG,PKI,IVERROR
. S X=$G(^VA(200,DUZ,"PS"))
. I '$P(X,U) S ERROR="You are not authorized to sign med orders!" Q
. I $P(X,U,4),$$NOW^XLFDT>$P(X,U,4) S ERROR="You are no longer authorized to sign med orders!" Q
. ;Q:DG="IV RX" Q:$P(ORA0,U,2)="DC" ;don't need to ck DEA#
. Q:$P(ORA0,U,2)="DC"
. I DG="IV RX" D Q
. .I $$IVDEACHK(+IFN)=1 S ERROR="You must have a valid DEA# or VA# to sign this order!"
. S OI=+$$VALUE^ORX8(+IFN,"ORDERABLE")
. S PSOI=+$P($G(^ORD(101.43,OI,0)),U,2) Q:PSOI'>0
. S TYPE=$S($P(DG," ")="O":"O",1:"I"),DEAFLG=$$OIDEA^PSSUTLA1(PSOI,TYPE)
. I (DEAFLG>0||$$ISCLOZ^ORALWORD(OI)),'$L($$DEA^XUSER()) S ERROR="You must have a valid DEA# or VA# to sign this order!" Q
. D PKISITE^ORWOR(.PKI)
. I $G(PKI),ACTION="RS",DEAFLG=1 S ERROR="This order cannot be released without a Digital Signature" Q
Q
;
IVDEACHK(IFN) ; -- Returns value of prompt by ID
I '$G(IFN)!('$D(^OR(100,+$G(IFN),0))) Q ""
N I,DIAL,DIALTYP,FAIL,PATCLASS,RESULT,Y
S PATCLASS=$P(^OR(100,+IFN,0),U,12)
S RESULT=0
;if ORNP is not set then assume this is called from VistA not CPRS
I $G(ORNP)="" S ORNP=DUZ
S I=0,Y="" S:'$G(INST) INST=1
F S I=$O(^OR(100,+IFN,4.5,"ID","ORDERABLE",I)) Q:I'>0!(RESULT=1) D
.S Y=$G(^OR(100,+IFN,4.5,I,1)) Q:Y'>0
.;S PSOI=+$P($G(^ORD(101.43,Y,0)),U,2) Q:PSOI'>0
.I PATCLASS="I" D Q
..D FAILDEA^ORWDPS1(.FAIL,Y,ORNP,"I") I FAIL=1 S RESULT=1
.S DIAL=+$P(^OR(100,+IFN,4.5,I,0),U,2)
.S DIALTYP=$S($P(^ORD(101.41,DIAL,0),U)["ADDITIVE":"A",1:"S")
.D FDEA1^ORWDPS1(.FAIL,Y,DIALTYP,ORNP)
.I FAIL=1 S RESULT=1
.;I $$OIDEA^PSSUTLA1(PSOI,"I")>0 S RESULT=1 Q
Q RESULT
;
XFR ; -- transfer to inpt/outpt [IFN=order to be transferred]
N OI,PS I DG="TPN" S ERROR="TPN orders may not be copied!" Q
I $$INACTIVE^ORCACT03 S ERROR="Orders for inactive orderables may not be transferred; please enter a new order!" Q
S OI=+$O(^OR(100,+IFN,.1,"B",0)),ORPS=$G(^ORD(101.43,OI,"PS"))
I DG="UD RX",'$P(ORPS,U,2) S ERROR="This drug may not be ordered for an outpatient!" Q
I DG="O RX" D Q:$L($G(ERROR))
. I '$P(ORPS,U) S ERROR="This drug may not be ordered for an inpatient!" Q
. D:$O(^OR(100,+IFN,4.5,"ID","MISC",0)) DOSES^ORCACT02(+IFN)
I DG="NV RX" D Q:$L($G(ERROR))
.N XFRIO
.S XFRIO=$P($G(^TMP("BEHPSHMX",$J)),U,2)
.I XFRIO="I",'$P(ORPS,U) S ERROR="This drug may not be ordered as an inpatient medication!" Q
.I XFRIO="O",'$P(ORPS,U,2) S ERROR="This drug may not be ordered as outpatient medication!" Q
.D:$O(^OR(100,+IFN,4.5,"ID","MISC",0)) DOSES^ORCACT02(+IFN)
Q
;
RW ; -- rewrite/copy
I ACTSTS=12 S ERROR="Orders that have been dc'd due to editing may not be copied!" Q
;IHS/MSC/REC/PLS - 08/09/10
;I DG="NV RX" S ERROR="Outside med orders cannot be copied!" Q
I $L($G(NV)) S ERROR=NV_" orders cannot be copied!" Q
I DG="TPN" S ERROR="TPN orders may not be rewritten!" Q
I DG="UD RX",$$NTBG^ORCACT03(+IFN) S ERROR="This order has been marked 'Not to be Given' and may not be rewritten!" Q
I $$INACTIVE^ORCACT03 S ERROR="Orders for inactive orderables may not be copied; please enter a new order!" Q
I PKG="PS",'$$MEDOK^ORCACT03 S ERROR="This drug may not be ordered!" Q
I DG="O RX",$O(^OR(100,+IFN,4.5,"ID","MISC",0)) D DOSES^ORCACT02(+IFN) ;old form
Q
;
RN ; -- renew
I PKG'="PS",PKG'="OR" S ERROR="This order may not be renewed!" Q
I (ORDSTS=11)!(ORDSTS=10) S ERROR="This order has not been released to the service." Q
I ACTSTS=12 S ERROR="Orders that have been dc'd due to editing may not be renewed!" Q
I $P(OR3,U,6) S ERROR="This order has already been "_$S($P($G(^OR(100,+$P(OR3,U,6),3)),U,11)=1:"changed!",1:"renewed!") Q
I PKG="OR" D Q ;Generic orders
. I $$INACTIVE^ORCACT03 S ERROR="Orders for inactive orderables may not be renewed!" Q
. I DG="ADT" S ERROR="M.A.S. orders may not be renewed!" Q
. I "^1^2^6^7^"[(U_ORDSTS_U) Q ;ok
. S ERROR="This order may not be renewed!"
I (PKG="PS"),$$INACTIVE^ORCACT03 S ERROR="Orders for inactive orderables may not be renewed!" Q
I '$$MEDOK^ORCACT03 S ERROR="This drug may not be ordered!" Q
RN1 N PSIFN S PSIFN=$G(^OR(100,+IFN,4))
I PSIFN<1,'$O(^OR(100,+IFN,2,0)) S ERROR="Missing or invalid order number!" Q
I DG="O RX" D Q ;Outpt Meds
. ; IHS/CIA/DKM - 10/11/2005 - Modified next 3 lines to support ORWOR RX EXPIRED MAX parameter
. ;N ORZ,ORD S ORZ=$L($T(RENEW^PSORENW),",")
. ;I ORZ>1 S ORD=+$$VALUE^ORX8(+IFN,"DRUG"),X=$$RENEW^PSORENW(PSIFN,ORD)
. ;S:ORZ'>1 X=$$RENEW^PSORENW(PSIFN) I X<1 S ERROR=$P(X,U,2) Q
. N ORZ,ORD,DAYS S ORZ=$L($T(RENEW^PSORENW),","),DAYS=$$GET^XPAR("ALL","ORWOR RX EXPIRED MAX")
. I ORZ>1 S ORD=+$$VALUE^ORX8(+IFN,"DRUG"),X=$$RENEW^PSORENW(PSIFN,ORD,DAYS)
. S:ORZ'>1 X=$$RENEW^PSORENW(PSIFN,,DAYS) I X<1 S ERROR=$P(X,U,2) Q
. S X=+$P(X,U,2) D:X RESET^ORCACT03(+IFN,X)
. I $O(^OR(100,+IFN,4.5,"ID","MISC",0)) D DOSES^ORCACT02(+IFN) ;old format
I DG="UD RX",$$NTBG^ORCACT03(+IFN) S ERROR="This order has been marked 'Not to be Given' and may not be renewed!" Q
I ORDSTS=7,'$$IV^ORCACT03,$P(OR0,U,9)<$$FMADD^XLFDT(DT,-4) S ERROR="Inpatient med orders may not be renewed more than 4 days after expiration!" Q
I ORDSTS'=6,ORDSTS'=7 S ERROR="This order may not be renewed!" Q
RN2 I $O(^OR(100,+IFN,2,0))!$P(OR3,U,9) D Q:$D(ERROR)!'PSIFN
. I $P(OR3,U,9),$$VALUE^ORX8(+IFN,"SCHEDULE",1,"E")="NOW" S ERROR="One-time NOW orders may not be renewed!" Q
. N DAD,ORD3,I,Y S DAD=$S($P(OR3,U,9):+$P(OR3,U,9),1:+IFN),Y=0
. S ORD3=$G(^OR(100,DAD,3)) I $P(ORD3,U,6) S ERROR="This complex order has already been renewed!" Q
. I $P(ORD3,U,3)'=6 S ERROR="This complex order is not active and may not be renewed!" Q
. I '$$AND^ORX8(DAD) S ERROR="Complex orders with sequential doses may not be renewed!" Q
. S I=0 F S I=+$O(^OR(100,DAD,2,I)) Q:I<1 D Q:Y
.. I I=+$O(^OR(100,DAD,2,0)),$$VALUE^ORX8(I,"SCHEDULE",1,"E")="NOW",$$VALUE^ORX8(DAD,"NOW") Q ;ignore NOW orders
.. I $P($G(^OR(100,I,3)),U,3)'=6 S Y=1,ERROR="Complex orders with terminated doses may not be renewed!" Q
.. I PSIFN<1 S X=$$ACTIVE^PSJORREN(+ORVP,$G(^OR(100,I,4))) I +X'=1 S ERROR="This order may not be renewed: "_$S(+X>1:"Inactive orderable item",1:$P(X,U,2)) Q
;I DG="TPN" S ERROR="TPN orders may not be renewed!" Q
S X=$$ACTIVE^PSJORREN(+ORVP,PSIFN) Q:+X=1 ;Ok
I +X>1,$P(X,U,2) D RESET^ORCACT03(+IFN,+$P(X,U,2)) Q ;replace OI
S ERROR="This order may not be renewed: "_$P(X,U,2)
Q
;
XX ; -- edit/change--
I PKG="RA",ORDSTS'=11,ORDSTS'=10 S ERROR="Orders released to Radiology cannot be changed!" Q
I PKG="LR",ORDSTS'=11,ORDSTS'=10 S ERROR="Orders released to Lab cannot be changed!" Q
I PKG="FH",ORDSTS'=11,ORDSTS'=10 S ERROR="Orders released to Dietetics cannot be changed!" Q
I PKG="GMRC",ORDSTS'=11,ORDSTS'=10 S ERROR="Orders released to Consults cannot be changed!" Q
I DG="TPN" S ERROR="TPN orders may not be changed!" Q
I ORDSTS=3 S ERROR="Orders on hold may not be changed!" Q
I DG="UD RX",$$NTBG^ORCACT03(+IFN) S ERROR="This order has been marked 'Not to be Given' and may not be changed!" Q
I $O(^OR(100,+IFN,2,0)) S ERROR="Complex orders may not be changed!" Q
I $P(OR3,U,9) D Q:$D(ERROR)
. Q:$$VALUE^ORX8(+IFN,"SCHEDULE",1,"E")="NOW" ;NOW ok
. Q:'$O(^OR(100,+$P(OR3,U,9),4.5,"ID","CONJ",0)) ;no conj=1dose/ok
. S ERROR="Complex orders may not be changed!" Q
I $P(OR3,U,6) S ERROR="This order may not be changed - a "_$S($P($G(^OR(100,+$P(OR3,U,6),3)),U,11)=1:"change",1:"renewal")_" order already exists!" Q
I $P(OR3,U,11)=2 D Q:$D(ERROR)
. ;IHS/MSC/PLS - 11/04/2010 - Restore behavior
. ;I (ORDSTS=10!(ORDSTS=11)),DG'="O RX" S ERROR="Unreleased renewals may not be changed!" Q
. I (ORDSTS=10!(ORDSTS=11)) S ERROR="Unreleased renewals may not be changed!" Q
. I PKG="PS",ORDSTS=5 S ERROR="Pending renewals may not be changed!" Q
I $$INACTIVE^ORCACT03 S ERROR="Orders for inactive orderables may not be changed; please enter a new order!" Q
I PKG="PS",'$$MEDOK^ORCACT03 S ERROR="This drug may not be ordered!" Q
I DG="O RX",$O(^OR(100,+IFN,4.5,"ID","MISC",0)) D DOSES^ORCACT02(+IFN) ;old form
Q
;
ORCACT01 ;SLC/MKB-Validate order actions cont ;14-Mar-2011 19:37;PLS
+1 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**94,116,134,141,163,187,190,1002,1004,213,243,1006,1010**;Dec 17, 1997;Build 47
+2 ;Modified - IHS/MSC/PLS - 08/09/10 - Line ES+5,ES+7,RW+2
+3 ; 03/02/11 - Line XFR+5 - added check for NV RX
ES ; -- sign [on chart]
+1 IF ORDSTS=11
IF VER<3
IF PKG'="OR"
SET ERROR="This order cannot be released and must be discontinued!"
QUIT
+2 NEW X
IF ACTSTS=11!(ACTSTS=10)
Begin DoDot:1
+3 IF $PIECE(ORA0,U,2)="DC"
IF $$DONE^ORCACT0
DO CANCEL^ORCSEND(+IFN)
DO UNOTIF^ORCSIGN
SET OREBUILD=1
QUIT
+4 SET X=$$DISABLED^ORCACT0
IF X
SET ERROR=$PIECE(X,U,2)
QUIT
End DoDot:1
IF $LENGTH($GET(ERROR))
QUIT
+5 ;I ACTION="OC",$G(DG)="NV RX" S:MEDPARM<2 ERROR="You are not authorized to release outside med orders!" Q
+6 IF ACTION="OC"
IF $LENGTH($GET(NV))
IF MEDPARM<2
SET ERROR="You are not authorized to release "_NV_" orders!"
QUIT
+7 ;S X=$P(ORA0,U,4) I X=3 S:ACTSTS'=11&(ACTSTS'=10) ERROR="This order does not require a signature!" Q
+8 SET X=$PIECE(ORA0,U,4)
IF X=3
IF $LENGTH($GET(NV))
QUIT
IF ACTSTS'=11&(ACTSTS'=10)
SET ERROR="This order does not require a signature!"
QUIT
+9 IF X'=2
SET ERROR="This order has been signed!"
QUIT
+10 IF DG="O RX"
IF ACTION'="ES"
IF ACTION'="DS"
IF $GET(NATR)'="I"
SET ERROR="Outpatient meds may not be released without a clinician's signature!"
QUIT
+11 IF (ACTION="ES"!(ACTION="DS"))
IF $DATA(^XUSEC("ORELSE",DUZ))
IF $PIECE(OR0,U,16)'<2
SET ERROR="You are not privileged to sign this order!"
QUIT
+12 IF ACTION="OC"
IF MEDPARM<2
SET ERROR="You are not authorized to release med orders!"
QUIT
+13 IF ACTION="RS"
Begin DoDot:1
+14 ;unreleased - ok
IF ACTSTS=11
QUIT
IF ACTSTS=10
QUIT
+15 SET ERROR="This order has already been released!"
End DoDot:1
IF $DATA(ERROR)
QUIT
IF $GET(NATR)'="I"
QUIT
ES1 ;authorized to write meds?
IF PKG="PS"
Begin DoDot:1
+1 NEW TYPE,OI,PSOI,DEAFLG,PKI,IVERROR
+2 SET X=$GET(^VA(200,DUZ,"PS"))
+3 IF '$PIECE(X,U)
SET ERROR="You are not authorized to sign med orders!"
QUIT
+4 IF $PIECE(X,U,4)
IF $$NOW^XLFDT>$P(X,U,4)
SET ERROR="You are no longer authorized to sign med orders!"
QUIT
+5 ;Q:DG="IV RX" Q:$P(ORA0,U,2)="DC" ;don't need to ck DEA#
+6 IF $PIECE(ORA0,U,2)="DC"
QUIT
+7 IF DG="IV RX"
Begin DoDot:2
+8 IF $$IVDEACHK(+IFN)=1
SET ERROR="You must have a valid DEA# or VA# to sign this order!"
End DoDot:2
QUIT
+9 SET OI=+$$VALUE^ORX8(+IFN,"ORDERABLE")
+10 SET PSOI=+$PIECE($GET(^ORD(101.43,OI,0)),U,2)
IF PSOI'>0
QUIT
+11 SET TYPE=$SELECT($PIECE(DG," ")="O":"O",1:"I")
SET DEAFLG=$$OIDEA^PSSUTLA1(PSOI,TYPE)
+12 IF (DEAFLG>0||$$ISCLOZ^ORALWORD(OI))
IF '$LENGTH($$DEA^XUSER())
SET ERROR="You must have a valid DEA# or VA# to sign this order!"
QUIT
+13 DO PKISITE^ORWOR(.PKI)
+14 IF $GET(PKI)
IF ACTION="RS"
IF DEAFLG=1
SET ERROR="This order cannot be released without a Digital Signature"
QUIT
End DoDot:1
+15 QUIT
+16 ;
IVDEACHK(IFN) ; -- Returns value of prompt by ID
+1 IF '$GET(IFN)!('$DATA(^OR(100,+$GET(IFN),0)))
QUIT ""
+2 NEW I,DIAL,DIALTYP,FAIL,PATCLASS,RESULT,Y
+3 SET PATCLASS=$PIECE(^OR(100,+IFN,0),U,12)
+4 SET RESULT=0
+5 ;if ORNP is not set then assume this is called from VistA not CPRS
+6 IF $GET(ORNP)=""
SET ORNP=DUZ
+7 SET I=0
SET Y=""
IF '$GET(INST)
SET INST=1
+8 FOR
SET I=$ORDER(^OR(100,+IFN,4.5,"ID","ORDERABLE",I))
IF I'>0!(RESULT=1)
QUIT
Begin DoDot:1
+9 SET Y=$GET(^OR(100,+IFN,4.5,I,1))
IF Y'>0
QUIT
+10 ;S PSOI=+$P($G(^ORD(101.43,Y,0)),U,2) Q:PSOI'>0
+11 IF PATCLASS="I"
Begin DoDot:2
+12 DO FAILDEA^ORWDPS1(.FAIL,Y,ORNP,"I")
IF FAIL=1
SET RESULT=1
End DoDot:2
QUIT
+13 SET DIAL=+$PIECE(^OR(100,+IFN,4.5,I,0),U,2)
+14 SET DIALTYP=$SELECT($PIECE(^ORD(101.41,DIAL,0),U)["ADDITIVE":"A",1:"S")
+15 DO FDEA1^ORWDPS1(.FAIL,Y,DIALTYP,ORNP)
+16 IF FAIL=1
SET RESULT=1
+17 ;I $$OIDEA^PSSUTLA1(PSOI,"I")>0 S RESULT=1 Q
End DoDot:1
+18 QUIT RESULT
+19 ;
XFR ; -- transfer to inpt/outpt [IFN=order to be transferred]
+1 NEW OI,PS
IF DG="TPN"
SET ERROR="TPN orders may not be copied!"
QUIT
+2 IF $$INACTIVE^ORCACT03
SET ERROR="Orders for inactive orderables may not be transferred; please enter a new order!"
QUIT
+3 SET OI=+$ORDER(^OR(100,+IFN,.1,"B",0))
SET ORPS=$GET(^ORD(101.43,OI,"PS"))
+4 IF DG="UD RX"
IF '$PIECE(ORPS,U,2)
SET ERROR="This drug may not be ordered for an outpatient!"
QUIT
+5 IF DG="O RX"
Begin DoDot:1
+6 IF '$PIECE(ORPS,U)
SET ERROR="This drug may not be ordered for an inpatient!"
QUIT
+7 IF $ORDER(^OR(100,+IFN,4.5,"ID","MISC",0))
DO DOSES^ORCACT02(+IFN)
End DoDot:1
IF $LENGTH($GET(ERROR))
QUIT
+8 IF DG="NV RX"
Begin DoDot:1
+9 NEW XFRIO
+10 SET XFRIO=$PIECE($GET(^TMP("BEHPSHMX",$JOB)),U,2)
+11 IF XFRIO="I"
IF '$PIECE(ORPS,U)
SET ERROR="This drug may not be ordered as an inpatient medication!"
QUIT
+12 IF XFRIO="O"
IF '$PIECE(ORPS,U,2)
SET ERROR="This drug may not be ordered as outpatient medication!"
QUIT
+13 IF $ORDER(^OR(100,+IFN,4.5,"ID","MISC",0))
DO DOSES^ORCACT02(+IFN)
End DoDot:1
IF $LENGTH($GET(ERROR))
QUIT
+14 QUIT
+15 ;
RW ; -- rewrite/copy
+1 IF ACTSTS=12
SET ERROR="Orders that have been dc'd due to editing may not be copied!"
QUIT
+2 ;IHS/MSC/REC/PLS - 08/09/10
+3 ;I DG="NV RX" S ERROR="Outside med orders cannot be copied!" Q
+4 IF $LENGTH($GET(NV))
SET ERROR=NV_" orders cannot be copied!"
QUIT
+5 IF DG="TPN"
SET ERROR="TPN orders may not be rewritten!"
QUIT
+6 IF DG="UD RX"
IF $$NTBG^ORCACT03(+IFN)
SET ERROR="This order has been marked 'Not to be Given' and may not be rewritten!"
QUIT
+7 IF $$INACTIVE^ORCACT03
SET ERROR="Orders for inactive orderables may not be copied; please enter a new order!"
QUIT
+8 IF PKG="PS"
IF '$$MEDOK^ORCACT03
SET ERROR="This drug may not be ordered!"
QUIT
+9 ;old form
IF DG="O RX"
IF $ORDER(^OR(100,+IFN,4.5,"ID","MISC",0))
DO DOSES^ORCACT02(+IFN)
+10 QUIT
+11 ;
RN ; -- renew
+1 IF PKG'="PS"
IF PKG'="OR"
SET ERROR="This order may not be renewed!"
QUIT
+2 IF (ORDSTS=11)!(ORDSTS=10)
SET ERROR="This order has not been released to the service."
QUIT
+3 IF ACTSTS=12
SET ERROR="Orders that have been dc'd due to editing may not be renewed!"
QUIT
+4 IF $PIECE(OR3,U,6)
SET ERROR="This order has already been "_$SELECT($PIECE($GET(^OR(100,+$PIECE(OR3,U,6),3)),U,11)=1:"changed!",1:"renewed!")
QUIT
+5 ;Generic orders
IF PKG="OR"
Begin DoDot:1
+6 IF $$INACTIVE^ORCACT03
SET ERROR="Orders for inactive orderables may not be renewed!"
QUIT
+7 IF DG="ADT"
SET ERROR="M.A.S. orders may not be renewed!"
QUIT
+8 ;ok
IF "^1^2^6^7^"[(U_ORDSTS_U)
QUIT
+9 SET ERROR="This order may not be renewed!"
End DoDot:1
QUIT
+10 IF (PKG="PS")
IF $$INACTIVE^ORCACT03
SET ERROR="Orders for inactive orderables may not be renewed!"
QUIT
+11 IF '$$MEDOK^ORCACT03
SET ERROR="This drug may not be ordered!"
QUIT
RN1 NEW PSIFN
SET PSIFN=$GET(^OR(100,+IFN,4))
+1 IF PSIFN<1
IF '$ORDER(^OR(100,+IFN,2,0))
SET ERROR="Missing or invalid order number!"
QUIT
+2 ;Outpt Meds
IF DG="O RX"
Begin DoDot:1
+3 ; IHS/CIA/DKM - 10/11/2005 - Modified next 3 lines to support ORWOR RX EXPIRED MAX parameter
+4 ;N ORZ,ORD S ORZ=$L($T(RENEW^PSORENW),",")
+5 ;I ORZ>1 S ORD=+$$VALUE^ORX8(+IFN,"DRUG"),X=$$RENEW^PSORENW(PSIFN,ORD)
+6 ;S:ORZ'>1 X=$$RENEW^PSORENW(PSIFN) I X<1 S ERROR=$P(X,U,2) Q
+7 NEW ORZ,ORD,DAYS
SET ORZ=$LENGTH($TEXT(RENEW^PSORENW),",")
SET DAYS=$$GET^XPAR("ALL","ORWOR RX EXPIRED MAX")
+8 IF ORZ>1
SET ORD=+$$VALUE^ORX8(+IFN,"DRUG")
SET X=$$RENEW^PSORENW(PSIFN,ORD,DAYS)
+9 IF ORZ'>1
SET X=$$RENEW^PSORENW(PSIFN,,DAYS)
IF X<1
SET ERROR=$PIECE(X,U,2)
QUIT
+10 SET X=+$PIECE(X,U,2)
IF X
DO RESET^ORCACT03(+IFN,X)
+11 ;old format
IF $ORDER(^OR(100,+IFN,4.5,"ID","MISC",0))
DO DOSES^ORCACT02(+IFN)
End DoDot:1
QUIT
+12 IF DG="UD RX"
IF $$NTBG^ORCACT03(+IFN)
SET ERROR="This order has been marked 'Not to be Given' and may not be renewed!"
QUIT
+13 IF ORDSTS=7
IF '$$IV^ORCACT03
IF $PIECE(OR0,U,9)<$$FMADD^XLFDT(DT,-4)
SET ERROR="Inpatient med orders may not be renewed more than 4 days after expiration!"
QUIT
+14 IF ORDSTS'=6
IF ORDSTS'=7
SET ERROR="This order may not be renewed!"
QUIT
RN2 IF $ORDER(^OR(100,+IFN,2,0))!$PIECE(OR3,U,9)
Begin DoDot:1
+1 IF $PIECE(OR3,U,9)
IF $$VALUE^ORX8(+IFN,"SCHEDULE",1,"E")="NOW"
SET ERROR="One-time NOW orders may not be renewed!"
QUIT
+2 NEW DAD,ORD3,I,Y
SET DAD=$SELECT($PIECE(OR3,U,9):+$PIECE(OR3,U,9),1:+IFN)
SET Y=0
+3 SET ORD3=$GET(^OR(100,DAD,3))
IF $PIECE(ORD3,U,6)
SET ERROR="This complex order has already been renewed!"
QUIT
+4 IF $PIECE(ORD3,U,3)'=6
SET ERROR="This complex order is not active and may not be renewed!"
QUIT
+5 IF '$$AND^ORX8(DAD)
SET ERROR="Complex orders with sequential doses may not be renewed!"
QUIT
+6 SET I=0
FOR
SET I=+$ORDER(^OR(100,DAD,2,I))
IF I<1
QUIT
Begin DoDot:2
+7 ;ignore NOW orders
IF I=+$ORDER(^OR(100,DAD,2,0))
IF $$VALUE^ORX8(I,"SCHEDULE",1,"E")="NOW"
IF $$VALUE^ORX8(DAD,"NOW")
QUIT
+8 IF $PIECE($GET(^OR(100,I,3)),U,3)'=6
SET Y=1
SET ERROR="Complex orders with terminated doses may not be renewed!"
QUIT
+9 IF PSIFN<1
SET X=$$ACTIVE^PSJORREN(+ORVP,$GET(^OR(100,I,4)))
IF +X'=1
SET ERROR="This order may not be renewed: "_$SELECT(+X>1:"Inactive orderable item",1:$PIECE(X,U,2))
QUIT
End DoDot:2
IF Y
QUIT
End DoDot:1
IF $DATA(ERROR)!'PSIFN
QUIT
+10 ;I DG="TPN" S ERROR="TPN orders may not be renewed!" Q
+11 ;Ok
SET X=$$ACTIVE^PSJORREN(+ORVP,PSIFN)
IF +X=1
QUIT
+12 ;replace OI
IF +X>1
IF $PIECE(X,U,2)
DO RESET^ORCACT03(+IFN,+$PIECE(X,U,2))
QUIT
+13 SET ERROR="This order may not be renewed: "_$PIECE(X,U,2)
+14 QUIT
+15 ;
XX ; -- edit/change--
+1 IF PKG="RA"
IF ORDSTS'=11
IF ORDSTS'=10
SET ERROR="Orders released to Radiology cannot be changed!"
QUIT
+2 IF PKG="LR"
IF ORDSTS'=11
IF ORDSTS'=10
SET ERROR="Orders released to Lab cannot be changed!"
QUIT
+3 IF PKG="FH"
IF ORDSTS'=11
IF ORDSTS'=10
SET ERROR="Orders released to Dietetics cannot be changed!"
QUIT
+4 IF PKG="GMRC"
IF ORDSTS'=11
IF ORDSTS'=10
SET ERROR="Orders released to Consults cannot be changed!"
QUIT
+5 IF DG="TPN"
SET ERROR="TPN orders may not be changed!"
QUIT
+6 IF ORDSTS=3
SET ERROR="Orders on hold may not be changed!"
QUIT
+7 IF DG="UD RX"
IF $$NTBG^ORCACT03(+IFN)
SET ERROR="This order has been marked 'Not to be Given' and may not be changed!"
QUIT
+8 IF $ORDER(^OR(100,+IFN,2,0))
SET ERROR="Complex orders may not be changed!"
QUIT
+9 IF $PIECE(OR3,U,9)
Begin DoDot:1
+10 ;NOW ok
IF $$VALUE^ORX8(+IFN,"SCHEDULE",1,"E")="NOW"
QUIT
+11 ;no conj=1dose/ok
IF '$ORDER(^OR(100,+$PIECE(OR3,U,9),4.5,"ID","CONJ",0))
QUIT
+12 SET ERROR="Complex orders may not be changed!"
QUIT
End DoDot:1
IF $DATA(ERROR)
QUIT
+13 IF $PIECE(OR3,U,6)
SET ERROR="This order may not be changed - a "_$SELECT($PIECE($GET(^OR(100,+$PIECE(OR3,U,6),3)),U,11)=1:"change",1:"renewal")_" order already exists!"
QUIT
+14 IF $PIECE(OR3,U,11)=2
Begin DoDot:1
+15 ;IHS/MSC/PLS - 11/04/2010 - Restore behavior
+16 ;I (ORDSTS=10!(ORDSTS=11)),DG'="O RX" S ERROR="Unreleased renewals may not be changed!" Q
+17 IF (ORDSTS=10!(ORDSTS=11))
SET ERROR="Unreleased renewals may not be changed!"
QUIT
+18 IF PKG="PS"
IF ORDSTS=5
SET ERROR="Pending renewals may not be changed!"
QUIT
End DoDot:1
IF $DATA(ERROR)
QUIT
+19 IF $$INACTIVE^ORCACT03
SET ERROR="Orders for inactive orderables may not be changed; please enter a new order!"
QUIT
+20 IF PKG="PS"
IF '$$MEDOK^ORCACT03
SET ERROR="This drug may not be ordered!"
QUIT
+21 ;old form
IF DG="O RX"
IF $ORDER(^OR(100,+IFN,4.5,"ID","MISC",0))
DO DOSES^ORCACT02(+IFN)
+22 QUIT
+23 ;