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

OCXOZ10.m

Go to the documentation of this file.
OCXOZ10 ;SLC/RJS,CLA - Order Check Scan ;OCT 30,2024 at 12:49
 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**32,221,243**;Dec 17,1997;Build 242
 ;;  ;;ORDER CHECK EXPERT version 1.01 released OCT 29,1998
 ;
 ; ***************************************************************
 ; ** Warning: This routine is automatically generated by the   **
 ; ** Rule Compiler (^OCXOCMP) and ANY changes to this routine  **
 ; ** will be lost the next time the rule compiler executes.    **
 ; ***************************************************************
 ;
 Q
 ;
R71R1A ; Verify all Event/Elements of  Rule #71 'OPIOID MEDICATIONS'  Relation #1 'OPIOID MED ORDER AND DUP OPIOID MEDS'
 ;  Called from EL138+5^OCXOZ0H, and EL139+5^OCXOZ0H.
 ;
 Q:$G(OCXOERR)
 ;
 ;      Local Extrinsic Functions
 ; MCE138( ---------->  Verify Event/Element: 'DUP OPIOID MEDS'
 ; MCE139( ---------->  Verify Event/Element: 'OPIOID MED ORDER'
 ;
 Q:$G(^OCXS(860.2,71,"INACT"))
 ;
 I $$MCE139 D 
 .I $$MCE138 D R71R1B
 Q
 ;
R71R1B ; Send Order Check, Notication messages and/or Execute code for  Rule #71 'OPIOID MEDICATIONS'  Relation #1 'OPIOID MED ORDER AND DUP OPIOID MEDS'
 ;  Called from R71R1A+12.
 ;
 Q:$G(OCXOERR)
 ;
 ;      Local Extrinsic Functions
 ; GETDATA( ---------> GET DATA FROM THE ACTIVE DATA FILE
 ;
 Q:$D(OCXRULE("R71R1B"))
 ;
 N OCXNMSG,OCXCMSG,OCXPORD,OCXFORD,OCXDATA,OCXNUM,OCXDUZ,OCXQUIT,OCXLOGS,OCXLOGD
 I ($G(OCXOSRC)="CPRS ORDER PRESCAN") S OCXCMSG=(+OCXPSD)_"^33^^Duplicate opioid medications: "_$$GETDATA(DFN,"138^139",158) I 1
 E  S OCXCMSG="Duplicate opioid medications: "_$$GETDATA(DFN,"138^139",158)
 S OCXNMSG=""
 ;
 Q:$G(OCXOERR)
 ;
 ; Send Order Check Message
 ;
 S OCXOCMSG($O(OCXOCMSG(999999),-1)+1)=OCXCMSG
 Q
 ;
R72R1A ; Verify all Event/Elements of  Rule #72 'AUTO DCED CONTROLLED SUBSTANCE ORDERS'  Relation #1 'PHARM DCED AND PHARM HASH MISMATCH'
 ;  Called from EL142+5^OCXOZ0H, and EL143+5^OCXOZ0H.
 ;
 Q:$G(OCXOERR)
 ;
 ;      Local Extrinsic Functions
 ; MCE142( ---------->  Verify Event/Element: 'HL7 PHARMACY DCED ORDER'
 ; MCE143( ---------->  Verify Event/Element: 'HL7 PHARMACY HASH MISMATCH'
 ;
 Q:$G(^OCXS(860.2,72,"INACT"))
 ;
 I $$MCE142 D 
 .I $$MCE143 D R72R1B
 Q
 ;
R72R1B ; Send Order Check, Notication messages and/or Execute code for  Rule #72 'AUTO DCED CONTROLLED SUBSTANCE ORDERS'  Relation #1 'PHARM DCED AND PHARM HASH MISMATCH'
 ;  Called from R72R1A+12.
 ;
 Q:$G(OCXOERR)
 ;
 ;      Local Extrinsic Functions
 ; NEWRULE( ---------> NEW RULE MESSAGE
 ;
 Q:$D(OCXRULE("R72R1B"))
 ;
 N OCXNMSG,OCXCMSG,OCXPORD,OCXFORD,OCXDATA,OCXNUM,OCXDUZ,OCXQUIT,OCXLOGS,OCXLOGD
 S OCXCMSG=""
 S OCXNMSG="Med order(s) DCed. Resubmit or contact Pharmacy."
 ;
 Q:$G(OCXOERR)
 ;
 ; Send Notification
 ;
 S (OCXDUZ,OCXDATA)="",OCXNUM=0
 I ($G(OCXOSRC)="GENERIC HL7 MESSAGE ARRAY") D
 .S OCXDATA=$G(^TMP("OCXSWAP",$J,"OCXODATA","ORC",2))_"|"_$G(^TMP("OCXSWAP",$J,"OCXODATA","ORC",3))
 .S OCXDATA=$TR(OCXDATA,"^","@"),OCXNUM=+OCXDATA
 I ($G(OCXOSRC)="CPRS ORDER PROTOCOL") D
 .I $P($G(OCXORD),U,3) S OCXDUZ(+$P(OCXORD,U,3))=""
 .S OCXNUM=+$P(OCXORD,U,2)
 S:($G(OCXOSRC)="CPRS ORDER PRESCAN") OCXNUM=+$P(OCXPSD,"|",5)
 S OCXRULE("R72R1B")=""
 I $$NEWRULE(DFN,OCXNUM,72,1,74,OCXNMSG) D  I 1
 .D:($G(OCXTRACE)<5) EN^ORB3(74,DFN,OCXNUM,.OCXDUZ,OCXNMSG,.OCXDATA)
 Q
 ;
R72R2A ; Verify all Event/Elements of  Rule #72 'AUTO DCED CONTROLLED SUBSTANCE ORDERS'  Relation #2 'PHARM DCED AND DEA CERT REVOKED'
 ;  Called from EL142+6^OCXOZ0H, and EL141+5^OCXOZ0H.
 ;
 Q:$G(OCXOERR)
 ;
 ;      Local Extrinsic Functions
 ; MCE141( ---------->  Verify Event/Element: 'HL7 DEA CERT REVOKED'
 ; MCE142( ---------->  Verify Event/Element: 'HL7 PHARMACY DCED ORDER'
 ;
 Q:$G(^OCXS(860.2,72,"INACT"))
 ;
 I $$MCE142 D 
 .I $$MCE141 D R72R2B^OCXOZ11
 Q
 ;
CKSUM(STR) ;  Compiler Function: GENERATE STRING CHECKSUM
 ;
 N CKSUM,PTR,ASC S CKSUM=0
 S STR=$TR(STR,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
 F PTR=$L(STR):-1:1 S ASC=$A(STR,PTR)-42 I (ASC>0),(ASC<51) S CKSUM=CKSUM*2+ASC
 Q +CKSUM
 ;
GETDATA(DFN,OCXL,OCXDFI) ;     This Local Extrinsic Function returns runtime data
 ;
 N OCXE,VAL,PC S VAL=""
 F PC=1:1:$L(OCXL,U) S OCXE=$P(OCXL,U,PC) I OCXE S VAL=$G(^TMP("OCXCHK",$J,DFN,OCXE,OCXDFI)) Q:$L(VAL)
 Q VAL
 ;
MCE138() ; Verify Event/Element: DUP OPIOID MEDS
 ;
 ;  OCXDF(158) -> DUPLICATE OPIOID MEDICATIONS TEXT data field
 ;  OCXDF(157) -> DUPLICATE OPIOID MEDICATIONS FLAG data field
 ;  OCXDF(37) -> PATIENT IEN data field
 ;
 N OCXRES
 S OCXDF(37)=$G(DFN) I $L(OCXDF(37)) S OCXRES(138,37)=OCXDF(37)
 Q:'(OCXDF(37)) 0 I $D(^TMP("OCXCHK",$J,OCXDF(37),138)) Q $G(^TMP("OCXCHK",$J,OCXDF(37),138))
 S OCXRES(138)=0,OCXDF(157)=$P($$OPIOID(OCXDF(37)),"^",1) I $L(OCXDF(157)) S OCXRES(138,157)=OCXDF(157) I (OCXDF(157))
 E  Q 0
 S OCXDF(158)=$P($$OPIOID(OCXDF(37)),"^",2),OCXRES(138)=11 M ^TMP("OCXCHK",$J,OCXDF(37),138)=OCXRES(138)
 Q +OCXRES(138)
 ;
MCE139() ; Verify Event/Element: OPIOID MED ORDER
 ;
 ;  OCXDF(37) -> PATIENT IEN data field
 ;
 N OCXRES
 S OCXDF(37)=$G(DFN) I $L(OCXDF(37)) S OCXRES(139,37)=OCXDF(37)
 Q:'(OCXDF(37)) 0 I $D(^TMP("OCXCHK",$J,OCXDF(37),139)) Q $G(^TMP("OCXCHK",$J,OCXDF(37),139))
 Q 0
 ;
MCE141() ; Verify Event/Element: HL7 DEA CERT REVOKED
 ;
 ;
 N OCXRES
 I $L(OCXDF(37)) S OCXRES(141,37)=OCXDF(37)
 Q:'(OCXDF(37)) 0 I $D(^TMP("OCXCHK",$J,OCXDF(37),141)) Q $G(^TMP("OCXCHK",$J,OCXDF(37),141))
 Q 0
 ;
MCE142() ; Verify Event/Element: HL7 PHARMACY DCED ORDER
 ;
 ;
 N OCXRES
 I $L(OCXDF(37)) S OCXRES(142,37)=OCXDF(37)
 Q:'(OCXDF(37)) 0 I $D(^TMP("OCXCHK",$J,OCXDF(37),142)) Q $G(^TMP("OCXCHK",$J,OCXDF(37),142))
 Q 0
 ;
MCE143() ; Verify Event/Element: HL7 PHARMACY HASH MISMATCH
 ;
 ;
 N OCXRES
 I $L(OCXDF(37)) S OCXRES(143,37)=OCXDF(37)
 Q:'(OCXDF(37)) 0 I $D(^TMP("OCXCHK",$J,OCXDF(37),143)) Q $G(^TMP("OCXCHK",$J,OCXDF(37),143))
 Q 0
 ;
NEWRULE(OCXDFN,OCXORD,OCXRUL,OCXREL,OCXNOTF,OCXMESS) ; Has this rule already been triggered for this order number
 ;
 ;
 Q:'$G(OCXDFN) 0 Q:'$G(OCXRUL) 0
 Q:'$G(OCXREL) 0  Q:'$G(OCXNOTF) 0  Q:'$L($G(OCXMESS)) 0
 S OCXORD=+$G(OCXORD),OCXDFN=+OCXDFN
 ;
 N OCXNDX,OCXDATA,OCXDFI,OCXELE,OCXGR,OCXTIME,OCXCKSUM,OCXTSP,OCXTSPL
 ;
 S OCXTIME=(+$H)
 S OCXCKSUM=$$CKSUM(OCXMESS)
 ;
 S OCXTSP=($H*86400)+$P($H,",",2)
 S OCXTSPL=($G(^OCXD(860.7,"AT",OCXTIME,OCXDFN,OCXRUL,+OCXORD,OCXCKSUM))+$G(OCXTSPI,300))
 ;
 Q:(OCXTSPL>OCXTSP) 0
 ;
 K OCXDATA
 S OCXDATA(OCXDFN,0)=OCXDFN
 S OCXDATA("B",OCXDFN,OCXDFN)=""
 S OCXDATA("AT",OCXTIME,OCXDFN,OCXRUL,+OCXORD,OCXCKSUM)=OCXTSP
 ;
 S OCXGR="^OCXD(860.7"
 D SETAP(OCXGR_")",0,.OCXDATA,OCXDFN)
 ;
 K OCXDATA
 S OCXDATA(OCXRUL,0)=OCXRUL_U_(OCXTIME)_U_(+OCXORD)
 S OCXDATA(OCXRUL,"M")=OCXMESS
 S OCXDATA("B",OCXRUL,OCXRUL)=""
 S OCXGR=OCXGR_","_OCXDFN_",1"
 D SETAP(OCXGR_")","860.71P",.OCXDATA,OCXRUL)
 ;
 K OCXDATA
 S OCXDATA(OCXREL,0)=OCXREL
 S OCXDATA("B",OCXREL,OCXREL)=""
 S OCXGR=OCXGR_","_OCXRUL_",1"
 D SETAP(OCXGR_")","860.712",.OCXDATA,OCXREL)
 ;
 S OCXELE=0 F  S OCXELE=$O(^OCXS(860.2,OCXRUL,"C","C",OCXELE)) Q:'OCXELE  D
 .;
 .N OCXGR1
 .S OCXGR1=OCXGR_","_OCXREL_",1"
 .K OCXDATA
 .S OCXDATA(OCXELE,0)=OCXELE
 .S OCXDATA(OCXELE,"TIME")=OCXTIME
 .S OCXDATA(OCXELE,"LOG")=$G(OCXOLOG)
 .S OCXDATA("B",OCXELE,OCXELE)=""
 .K ^OCXD(860.7,OCXDFN,1,OCXRUL,1,OCXREL,1,OCXELE)
 .D SETAP(OCXGR1_")","860.7122P",.OCXDATA,OCXELE)
 .;
 .S OCXDFI=0 F  S OCXDFI=$O(^TMP("OCXCHK",$J,OCXDFN,OCXELE,OCXDFI)) Q:'OCXDFI  D
 ..N OCXGR2
 ..S OCXGR2=OCXGR1_","_OCXELE_",1"
 ..K OCXDATA
 ..S OCXDATA(OCXDFI,0)=OCXDFI
 ..S OCXDATA(OCXDFI,"VAL")=^TMP("OCXCHK",$J,OCXDFN,OCXELE,OCXDFI)
 ..S OCXDATA("B",OCXDFI,OCXDFI)=""
 ..D SETAP(OCXGR2_")","860.71223P",.OCXDATA,OCXDFI)
 ;
 Q 1
 ;
SETAP(ROOT,DD,DATA,DA) ;  Set Rule Event data
 M @ROOT=DATA
 I +$G(DD) S @ROOT@(0)="^"_($G(DD))_"^"_($P($G(@ROOT@(0)),U,3)+1)_"^"_$G(DA)
 I '$G(DD) S $P(@ROOT@(0),U,3,4)=($P($G(@ROOT@(0)),U,3)+1)_"^"_$G(DA)
 ;
 Q
 ;
 ;
OPIOID(ORPT) ;determine if pat is receiving opioid med
 ; rtn 1^opioid drug 1, opioid drug 2, opioid drug3, ...
 N ORDG,ORTN,ORNUM,ORDI,ORDCLAS,ORDERS,ORTEXT,DUP,DUPI,DUPJ,DUPLEN
 S ORDG=0,ORTN=0,DUPI=0,DUPLEN=20
 K ^TMP("ORR",$J)
 S ORDG=$O(^ORD(100.98,"B","RX",ORDG))
 D EN^ORQ1(ORPT_";DPT(",ORDG,2,"","","",0,0)
 N J,HOR,SEQ,X S J=1,HOR=0,SEQ=0
 S HOR=$O(^TMP("ORR",$J,HOR)) Q:+HOR<1 ORTN
 F  S SEQ=$O(^TMP("ORR",$J,HOR,SEQ)) Q:+SEQ<1  D
 .S X=^TMP("ORR",$J,HOR,SEQ)
 .S ORNUM=+$P(X,";")
 .Q:ORNUM=+$G(ORIFN)  ;quit if dup med order # = current order #
 .S ORDI=$$VALUE^ORCSAVE2(ORNUM,"DRUG")
 .I +$G(ORDI)>0 D
 ..S ORDCLAS=$P(^PSDRUG(ORDI,0),U,2)  ;va drug class
 ..I ($G(ORDCLAS)="CN101")!($G(ORDCLAS)="CN102") D  ;opioid classes
 ...S ORTEXT=$$FULLTEXT^ORQOR1(ORNUM)
 ...S ORTEXT=$P(ORTEXT,U)_" ["_$P(ORTEXT,U,2)_"]"
 ...S DUPI=DUPI+1,DUP(DUPI)=" ["_DUPI_"] "_ORTEXT
 ...S ORTN=1
 I DUPI>0 D
 .;S DUPLEN=$P(215/DUPI,".")
 .S DUPLEN=500
 .F DUPJ=1:1:DUPI D
 ..I DUPJ=1 S ORDERS=$E(DUP(DUPJ),1,DUPLEN)
 ..E  S ORDERS=ORDERS_", "_$E(DUP(DUPJ),1,DUPLEN)
 K ^TMP("ORR",$J)
 Q ORTN_U_$G(ORDERS)
 ;