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

ORWDX3.m

Go to the documentation of this file.
ORWDX3 ; SLC/STAFF - Order dialog utilities ;Apr 12, 2022@12:12:08
 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**405**;Dec 17, 1997;Build 211
 ;Per VA Directive 6402, this routine should not be modified.
 ;
 ;Reference to DIC(9.4 supported by IA #2058
 ;Reference to ^DPT( supported by ICR #10035
 ;
 Q
 ;
SAVE ; From SAVE^ORWDX - moved here because of routine size. (Don't call into this tag directly. Call into SAVE^ORWDX).
 N ORDUZ,ORSTS,OREVENT,ORCAT,ORDA,ORTS,ORNEW,ORCHECK,ORLOG,ORLEAD,ORTRAIL,ORPKG,ORWP94,ORCATFN,OREVTYPE,ONPASS,OROVER,ORAGYCNT,ORAGY,ORCHKCNT,ORRCOMM
 N MSGCAPT,SENDMSG,NUM,ORALLGY,ORALLXST,ORALLCHKNM,ORDOI
 N XCNT,XCOMM,XDONE,XX  ;SBR
 S (XCOMM,XCNT)=""  ;SBR
 I $G(ORIFN)'="" D  ;SBR problem only occurs on change or renew orders
 . S XCNT=$O(^OR(100,+ORIFN,4.5,"ID","COMMENT",XCNT))  ;SBR
 . I XCNT'="" S XCOMM=$P($G(^OR(100,+ORIFN,4.5,XCNT,0)),"^",2)  ;SBR
 . I XCOMM'="" S XDONE=0,XX="" F  S XX=$O(ORDIALOG("WP",XCOMM,1,XX)) Q:XX=""  D  ;SBR
 . . I ORDIALOG("WP",XCOMM,1,XX,0)'="" S XDONE=1 Q  ;SBR
 . I XCOMM'="",'$G(XDONE),$D(ORDIALOG("WP",XCOMM)) K ORDIALOG("WP",XCOMM)  ;SBR
 S ORDOI=+$G(ORDIALOG(4,1))
 S ORCATFN="" I $L($P(DLG,U,2)) S ORCATFN=$P(DLG,U,2),DLG=$P(DLG,U,1)
 S SENDMSG=0 I $P($G(^ORD(100.98,ORDG,0)),U)="INPATIENT MEDICATIONS" D
 .Q:("^PSJ OR PAT OE^PSJI OR PAT FLUID OE^PSJ OR CLINIC OE^CLINIC OR PAT FLUID OE^"'[(U_DLG_U))
 .S MSGCAPT("PATIENT")=ORVP,MSGCAPT("USER")=ORNP,MSGCAPT("LOC")=+$G(ORL)
 .S MSGCAPT("DIALOG")=DLG,MSGCAPT("DISPLAY GROUP")=ORDG,MSGCAPT("QUICK ORDER")=ORIT
 .M MSGCAPT("ORDIALOG")=ORDIALOG
 .N NEWORDG S NEWORDG=$S(DLG="PSJI OR PAT FLUID OE":"IV MEDICATIONS",DLG="PSJ OR CLINIC OE":"CLINIC MEDICATIONS",DLG="CLINIC OR PAT FLUID OE":"CLINIC INFUSIONS",1:"UNIT DOSE MEDICATIONS")
 .S ORDG=$O(^ORD(100.98,"B",NEWORDG,"")),SENDMSG=1
 ;Remove treating facility if inpatient and IMO order 26.42
 I $G(^DPT(ORVP,.1))'="",$P($G(^ORD(100.98,ORDG,0)),U)="CLINIC MEDICATIONS" K ORDIALOG("ORTS")
 I $G(^DPT(ORVP,.1))'="",$P($G(^ORD(100.98,ORDG,0)),U)="CLINIC INFUSIONS" K ORDIALOG("ORTS")
 I $G(ORDIALOG("ORTS")) S ORTS=ORDIALOG("ORTS") K ORDIALOG("ORTS")
 I $G(ORDIALOG("ORSLOG")) S ORLOG=ORDIALOG("ORSLOG") K ORDIALOG("ORSLOG")
 I $D(ORDIALOG("OREVENT")) S OREVENT=ORDIALOG("OREVENT") K ORDIALOG("OREVENT")
 I $D(ORDIALOG("OVERRIDE")) S OROVER=ORDIALOG("OVERRIDE") K ORDIALOG("OVERRIDE")
 I $D(ORDIALOG("ORREMCOMMENT")) S ORRCOMM=ORDIALOG("ORREMCOMMENT") K ORDIALOG("ORREMCOMMENT")
 ;=====================================================
 ; Changed for v26.27 (RV)
 S ORCAT=$$INPT^ORCD,ORCAT=$S(ORCAT=1:"I",1:"O")
 ;I $L($G(OREVENT)) D
 ;. S ONPASS=0
 ;. S OREVTYPE=$$TYPE^OREVNTX(OREVENT)
 ;. I OREVTYPE="T" D ISPASS^OREVNTX1(.ONPASS,+OREVENT,"T")
 ;. S ORCAT=$S(OREVTYPE="A":"I",OREVTYPE="T":"I",ONPASS=1:"O",1:"O")
 ;E  S ORCAT=$S($L($P($G(^DPT(+ORVP,.1)),U)):"I",1:"O")
 ;=====================================================
 I DLG="PS MEDS" S ORWP94=1 D
 . I ORIT=$O(^ORD(101.41,"AB","PSO SUPPLY",0)) S DLG="PSO SUPPLY"
 . I ORIT=$O(^ORD(101.41,"AB","PSO OERR",0)) S DLG="PSO OERR"
 . I ORIT=$O(^ORD(101.41,"AB","PSJ OR PAT OE",0)) S DLG="PSJ OR PAT OE"
 I DLG="PSO OERR"!(DLG="PSO SUPPLY") S ORCAT="O" I $G(OREVENT("EFFECTIVE")) D
 . S ORDIALOG($O(^ORD(101.41,"B","OR GTX START DATE"_$S($G(ORWP94):"/TIME",1:""),0)),1)=OREVENT("EFFECTIVE")
 I DLG="PSO OERR" D
 . N DRUGPRMT,OIPRMT,ORDRUG,OROI
 . S DRUGPRMT=+$O(^ORD(101.41,"B","OR GTX DISPENSE DRUG",0))
 . S ORDRUG=$G(ORDIALOG(DRUGPRMT,1))
 . I ORDRUG,$$ISSUPPLY^ORUTL3(ORDRUG) D
 . . S ORDG=+$O(^ORD(100.98,"B","SUPPLIES/DEVICES",0))
 . S OIPRMT=+$O(^ORD(101.41,"B","OR GTX ORDERABLE ITEM",0))
 . S OROI=$G(ORDIALOG(OIPRMT,1))
 . I 'ORDRUG,OROI,$$ISOISPLY^ORUTL3(OROI) D
 . . S ORDG=+$O(^ORD(100.98,"B","SUPPLIES/DEVICES",0))
 I DLG="PSJ OR PAT OE" S ORCAT="I"
 I DLG="PSJ OR CLINIC OE" S ORCAT="I"
 I DLG="CLINIC OR PAT FLUID OE" S ORCAT="I"
 S:DLG="FHW1" ORCAT="I" S:DLG?1"FHW "2.7U1" MEAL" ORCAT="O"
 S ORVP=ORVP_";DPT(",ORL(2)=ORL_";SC(",ORL=ORL(2)
 I ORDG=$O(^ORD(100.98,"B","LAB",0)) D  ;use section
 . N OI,SUB S OI=+$G(ORDIALOG($$PTR^ORCD("OR GTX ORDERABLE ITEM"),1))
 . S SUB=$P($G(^ORD(101.43,OI,"LR")),U,6),ORDG=$$DGRP^ORMLR(SUB)
 I ORDG=$O(^ORD(100.98,"B","AP",0)) D  ;provides orders sort for AP orders by SP, CY and EM
 . N OI,SUB S OI=+$G(ORDIALOG($$PTR^ORCD("OR GTX ORDERABLE ITEM"),1))
 . S SUB=$P($G(^ORD(101.43,OI,"LR")),U,6),ORDG=$$DGRP^ORMLR(SUB)
 K:'ORDG ORDG K:'ORIT ORIT ; Dgrp & Quick must be non-zero
 M ORCHECK=ORDIALOG("ORCHECK") K ORDIALOG("ORCHECK")
 S ORALLGY=$O(^ORD(100.8,"B","ALLERGY-DRUG INTERACTION",0))
 I '$G(DT) S DT=$$DT^XLFDT
 S ORALLCHKNM="ORALLERGYCHK"
 I '$D(^TMP(ORALLCHKNM,$J,+ORVP,+ORDOI)),$D(^ORD(100.05,"C",+$G(ORIFN),"ACCEPTANCE_CPRS")) D
 . N ORAGY,ORCHK,ORDCHK,ORDRGLOC,ORMSG,ORSVR
 . I $G(OROVER)="" S OROVER="No override reason given"
 . S (NUM,ORAGY)=0
 . ;F  S ORAGY=$O(^ORD(100.05,"C",+$G(ORIFN),"ACCEPTANCE_CPRS",ORAGY)) Q:ORAGY=""  D
 . ;. S ORDCHK(1)=$G(^ORD(100.05,ORAGY,1))
 . ;. S ORDCHK(4)=$G(^ORD(100.05,ORAGY,4,1,0))
 . ;. I ORALLGY'=$P(ORDCHK(1),U,1) Q  ;ALLERGY-DRUG INTERACTION only
 . ;. S ORSVR=$P(ORDCHK(1),U,2) ;Severity
 . ;. S ORMSG=$G(^ORD(100.05,ORAGY,2,1,0))
 . ;. S ORCHKCNT=ORCHECK
 . ;. N CDL
 . ;. S CDL="" F  S CDL=$O(ORCHECK("NEW",CDL)) Q:CDL=""  D
 . ;. . I $O(ORCHECK("NEW",CDL,""),-1)>ORCHKCNT S ORCHKCNT=$O(ORCHECK("NEW",CDL,""),-1)
 . ;. S ORCHECK("NEW",1,$I(ORCHKCNT))=ORALLGY_U_ORSVR_U_ORMSG
 . ;. S ORCHECK("NEW",1,ORCHKCNT,"OVER")=OROVER
 . ;. S ORCHECK=ORCHECK+1
 . ;. I $G(ORRCOMM)]"",$P(ORDCHK(4),U,3)="R" D
 . ;. . S ORDRGLOC=$P(ORDCHK(4),U,4)_";"_$P(ORDCHK(4),U,1)
 . ;. . S ORCHECK("NEW",1,ORCHKCNT,"REMCOMM")=ORRCOMM
 . ;. . D SAVRCOM(ORVP,ORDRGLOC,ORRCOMM)
 . ;. ;SAVE DATA FOR ORDER CHECK INSTANCES FILE ENTRY (Create as if allergy order checks ran)
 . ;. N CLASS,CRC16,ING,ITM,NODE,SIGN
 . ;. S CRC16=$$CRC16^XLFCRC(ORMSG)
 . ;. S NUM=1+$G(NUM)
 . ;. K:NUM=1 ^TMP("OROCIDATA",$J,CRC16)
 . ;. S ^TMP("OROCIDATA",$J,CRC16,100.517,NUM,.01)=$P(ORDCHK(4),U,1) ;$P(DATA(J,ITM),U,6)
 . ;. S:$P(ORDCHK(4),U,2)'="" ^TMP("OROCIDATA",$J,CRC16,100.517,NUM,2)=$P(ORDCHK(4),U,2) ;$P(DATA(J,ITM),U,7)
 . ;. S ^TMP("OROCIDATA",$J,CRC16,100.517,NUM,6)=$P(ORDCHK(4),U,3) ;$P(DATA(J,ITM),U,2)
 . ;. S:$P(ORDCHK(4),U,4)="R" ^TMP("OROCIDATA",$J,CRC16,100.517,NUM,7)=$P(ORDCHK(4),U,4) ;$P(DATA(J,ITM),U)
 . ;. S ^TMP("OROCIDATA",$J,CRC16,100.517,NUM,8)=$P(ORDCHK(4),U,5) ;$P(DATA(J,ITM),U,3)
 . ;. S ^TMP("OROCIDATA",$J,CRC16,100.517,NUM,9)=$P(ORDCHK(4),U,6) ;$$UP^XLFSTR($P(DATA(J,ITM),U,8))
 . ;. S:$P(ORDCHK(4),U,1)'="" ^TMP("OROCIDATA",$J,CRC16,100.517,NUM,10)=$P(ORDCHK(4),U,1) ;SEVERE("MSG")
 . ;. S ^TMP("OROCIDATA",$J,CRC16,100.517,NUM,11)=$G(^ORD(100.05,ORAGY,4,1,4)) ;$P(DATA(J,ITM),U,10)
 . ;. S (ITM(1),SIGN)=0
 . ;. F  S SIGN=$O(^ORD(100.05,ORAGY,4,1,3,"B",SIGN)) Q:+SIGN=0  D
 . ;. . S ITM(1)=$G(ITM(1))+1
 . ;. . S ^TMP("OROCIDATA",$J,CRC16,"SIGN",NUM,"+"_ITM(1)_",")=SIGN
 . ;. S ^TMP("OROCIDATA",$J,CRC16,100.05,84)=$P($G(^ORD(100.05,ORAGY,8)),U,4)
 . ;. S CLASS=0
 . ;. F  S CLASS=$O(^ORD(100.05,ORAGY,4,1,1,"B",CLASS)) Q:+CLASS=0  D
 . ;. . S ITM(1)=$G(ITM(1))+1
 . ;. . S ^TMP("OROCIDATA",$J,CRC16,"CLASS",NUM,"+"_ITM(1)_",")=CLASS
 . ;. S ING=0
 . ;. F  S ING=$O(^ORD(100.05,ORAGY,4,1,2,"B",ING)) Q:+ING=0  D
 . ;. . S ITM(1)=$G(ITM(1))+1
 . ;. . S ^TMP("OROCIDATA",$J,CRC16,"INGREDIENT",NUM,"+"_ITM(1)_",")=ING
 S ORALLXST=0
 I $D(^TMP(ORALLCHKNM,$J,+ORVP,+ORDOI)) D
 . N ORCHKCNT,ORCHKSVR,ORTMPCHK
 . S ORCHKSVR=0
 . F  S ORCHKSVR=$O(ORCHECK("NEW",ORCHKSVR)) Q:ORCHKSVR=""  D  Q:ORALLXST
 . . S ORCHKCNT=0
 . . F  S ORCHKCNT=$O(ORCHECK("NEW",ORCHKSVR,ORCHKCNT)) Q:ORCHKCNT=""  D  Q:ORALLXST
 . . . I $P($G(ORCHECK("NEW",ORCHKSVR,ORCHKCNT)),U,1)'=ORALLGY Q
 . . . S ORALLXST=1
 . I ORALLXST Q
 . I $G(OROVER)="" S OROVER="No override reason given"
 . S ORCHKCNT=ORCHECK,ORAGYCNT=$O(^TMP(ORALLCHKNM,$J,+ORVP,+ORDOI,""),-1),ORCHECK=ORCHECK+ORAGYCNT
 . N CDL
 . S CDL="" F  S CDL=$O(ORCHECK("NEW",CDL)) Q:CDL=""  D
 . . I $O(ORCHECK("NEW",CDL,""),-1)>ORCHKCNT S ORCHKCNT=$O(ORCHECK("NEW",CDL,""),-1)
 . F ORAGY=1:1:ORAGYCNT D
 . . S ORTMPCHK=$G(^TMP(ORALLCHKNM,$J,+ORVP,+ORDOI,ORAGY))
 . . S ORCHECK("NEW",1,$I(ORCHKCNT))=$P(ORTMPCHK,U,2,4)
 . . S ORCHECK("NEW",1,ORCHKCNT,"OVER")=OROVER
 . . I $G(ORRCOMM)]"",$P(ORTMPCHK,U,5)=1 D
 . . . S ORCHECK("NEW",1,ORCHKCNT,"REMCOMM")=ORRCOMM
 . . . D SAVRCOM(ORVP,$P(ORTMPCHK,U,6),ORRCOMM)
 I ORALLXST=1 D
 . N ORCHKCNT,ORCHKSVR
 . S ORCHKSVR=0
 . F  S ORCHKSVR=$O(ORCHECK("NEW",ORCHKSVR)) Q:ORCHKSVR=""  D
 . . S ORCHKCNT=0
 . . F  S ORCHKCNT=$O(ORCHECK("NEW",ORCHKSVR,ORCHKCNT)) Q:ORCHKCNT=""  D
 . . . I $P($G(ORCHECK("NEW",ORCHKSVR,ORCHKCNT)),U,1)'=ORALLGY Q
 . . . I $G(OROVER)="" S OROVER="No override reason given"
 . . . S ORCHECK("NEW",ORCHKSVR,ORCHKCNT,"OVER")=OROVER
 . . . S ORTMPCHK=$G(^TMP(ORALLCHKNM,$J,+ORVP,+ORDOI,ORCHKCNT))
 . . . I $G(ORRCOMM)]"",$P(ORTMPCHK,U,5)=1 D
 . . . . S ORCHECK("NEW",ORCHKSVR,ORCHKCNT,"REMCOMM")=ORRCOMM
 . . . . D SAVRCOM(ORVP,$P(ORTMPCHK,U,6),ORRCOMM)
 D CLRALLGY^ORWDXC("",+ORVP)
 S ORDIALOG=$O(^ORD(101.41,"AB",DLG,0))
 I 'ORDIALOG S ORDIALOG=$O(^ORD(101.41,"B",DLG,0))
 I $D(ORDIALOG("ORLEAD")) S ORLEAD=ORDIALOG("ORLEAD")
 I $D(ORDIALOG("ORTRAIL")) S ORTRAIL=ORDIALOG("ORTRAIL")
 D GETDLG1^ORCD(ORDIALOG)
 I $L(ORCATFN) S ORCAT=ORCATFN
 I $G(ORWP94) D
 . N SIGPRMT S SIGPRMT=$O(^ORD(101.41,"B","OR GTX SIG",0))
 . N INSPRMT S INSPRMT=$O(^ORD(101.41,"B","OR GTX INSTRUCTIONS",0))
 . I $L($G(ORDIALOG(SIGPRMT,1))) S ORDIALOG(INSPRMT,"FORMAT")="@"
 . I ORCAT="O" S ORPKG=$O(^DIC(9.4,"C","PSO",0))
 . I ORCAT="I" S ORPKG=$O(^DIC(9.4,"C","PSJ",0))
 S ORSRC=$G(ORSRC)
 D DELPI^ORWDX1 ;delete empty PI
 I $G(ORIFN)="" D  ; new order
 . D EN^ORCSAVE
 . S REC="" I ORIFN D GETBYIFN^ORWORR(.REC,ORIFN)
 . I '$D(^TMP("ORECALL",$J,ORDIALOG)) M ^TMP("ORECALL",$J,ORDIALOG)=ORDIALOG
 E  D
 . N OR0
 . S OR0=$G(^OR(100,+ORIFN,0)),ORSTS=$P($G(^(3)),U,3),ORDG=$P(OR0,U,11)
 . I $L($P(OR0,U,17)),ORSTS=10 S OREVENT=$P(OR0,U,17),OREVENT("TS")=$P(OR0,U,13)
 . D XX^ORCSAVE ; edit order
 . S REC="" S ORIFN=+ORIFN_";"_ORDA D GETBYIFN^ORWORR(.REC,ORIFN)
 I SENDMSG D
 .S MSGCAPT("ORIGINAL IEN")=$G(ORIFN)
 .D MSG^ORUTL5(REC,.MSGCAPT)
 D:DLG="GMRCOR CONSULT" CHKAUTO^ORCSLT
 D DELORC^ORNORC(ORVP,.ORDIALOG) ; ajb remove order check info from 100.3
 Q
 ;
 ;
SAVRCOM(ORVP,AREC,RCOMM) ;Save Local Comment to Remote Allergy
 ;AREC: This will contain the allergy record identifier (RECID)
 ;      and the original comment presented to the user (PREVCOMM)
 N GMR,RECID,PREVCOMM,COMREC,DA,COMMID,LASTCOMM
 S RECID=$P(AREC,"~"),PREVCOMM=$P(AREC,"~",2,99)
 S DIC="^GMR(120.88,",DIC(0)="F"
 S DIE=DIC,LASTCOMM=""
 S COMMID=$O(^GMR(120.88,"PR",ORVP,RECID,""),-1)
 I COMMID]"" S LASTCOMM=$G(^GMR(120.88,COMMID,1))
 Q:LASTCOMM=RCOMM
 S DA(.01)=RECID,DA(.02)=ORVP,DA(.03)=$$NOW^XLFDT(),DA(.04)=DUZ,DA(1)=RCOMM
 M GMR(120.88,"+1,")=DA
 D UPDATE^DIE("","GMR",,"ERROR")
 Q