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

PSGSICHK.m

Go to the documentation of this file.
  1. PSGSICHK ;BIR/CML3-CHECKS SPECIAL INSTRUCTIONS ;19-Oct-2017 12:55;PT
  1. ;;5.0; INPATIENT MEDICATIONS ;**3,9,26,29,44,49,59,1013,110,139,146,160,175,201,185,1015,1022**;16 DEC 97;Build 20
  1. ;
  1. ; Reference to ^PS(50.605 is supported by DBIA 696.
  1. ; Reference to EN^PSOORDRG is supported by DBIA 2190.
  1. ; Reference to ^PSI(58.1 is supported by DBIA 2284.
  1. ; Reference to ^PSDRUG( is supported by DBIA 2192.
  1. ; Reference to ^PSD(58.8 is supported by DBIA 2283.
  1. ; Reference to ^PS(55 is supported by DBIA 2191.
  1. ; Reference to ^PS(51.2 is supported by DBIA 2178.
  1. ; Reference to ^PS(51 is supported by DBIA 2176.
  1. ; Reference to ^ORRDI1 is supported by DBIA 4659.
  1. ; Reference to ^XTMP("ORRDI" is supported by DBIA 4660.
  1. ; Reference to GETDATA^GMRAOR supported by DBIA 4847.
  1. ; Reference to ^TMP("GMRAOC" supported by DBIA 4848.
  1. ;Modified - IHS/MSC/MGH - 02/08/2012 - Line ENDL+2
  1. ;Modified - IHS/MSC/MGH - 04/06/2012 - IVSOL+5,ALGCLASS+13,ALGC2+19,CLASSDSP+5
  1. ; for adding reactions patch 1014
  1. ;Modified - IHS/MSC/MGH - 12/21/2012 - IVSOL+5,IVSOL+7 patch 1015
  1. START ;
  1. I $S(X'?.ANP:1,X["^":1,1:$L(X)>180) K X Q
  1. S Y="" F Y(1)=1:1:$L(X," ") S Y(2)=$P(X," ",Y(1)) I Y(2)]"" D CHK Q:'$D(X)
  1. I $D(X),Y]"",X'=$E(Y,1,$L(Y)-1) D EN^DDIOL("EXPANDS TO: ") W Y F Y(1)=1:1 S Y(2)=$P(Y," ",Y(1)) Q:Y(2)="" D:$L(Y(2))+$X>78 EN^DDIOL(Y(2)_" ")
  1. Q
  1. ;
  1. CHK ;
  1. I $L(Y(2))<31,$D(^PS(51,+$O(^PS(51,"B",Y(2),0)),0)),$P(^(0),"^",2)]"",$P(^(0),"^",4) S Y(2)=$P(^(0),"^",2)
  1. I $L(Y)+$L(Y(2))>180 K X Q
  1. S Y=Y_Y(2)_" " Q
  1. ;
  1. ENSET(X) ; expands the SPECIAL INSTRUCTIONS field contained in X into Y
  1. N X1,X2,Y S Y=""
  1. ;BHW;PSJ*5*185;Modified Logic below to NOT strip spaces and allow existing logic to flow.
  1. ; ;Removed code I X2]"" Before Set of Y and created argumentless DO structure.
  1. F X1=1:1:$L(X," ") S X2=$P(X," ",X1) D
  1. . I X2']"" S Y=Y_" " Q ;if multiple spaces in text and were $P'ing through text, X2 will="" so just add space and continue
  1. . S Y=Y_$S($L(X2)>30:X2,'$D(^PS(51,+$O(^PS(51,"B",X2,0)),0)):X2,$P(^(0),"^",2)]""&$P(^(0),"^",4):$P(^(0),"^",2),1:X2)_" "
  1. . Q
  1. ;BHW;Modified stripping of spaces at end of string
  1. F X1=$L(Y):-1:0 Q:$E(Y,X1,X1)'=" " S Y=$E(Y,1,X1-1)
  1. Q Y
  1. ;
  1. END ; used by DRUG (55.06,101 & 53.1,101) x-refs to warn user if patient is receiving or about to receive the drug just ordered
  1. Q:$D(PSJHLSKP)
  1. N Z,ZZ,STATUSNP I $G(PSJPWD)&($P($G(PSJSYSU),";")=3)&($G(PSGDRG)) I ($D(^PSI(58.1,"D",PSGDRG,PSJPWD)))!($D(^PSD(58.8,"D",PSGDRG,PSJPWD))) D EN^DDIOL(" *** A WARD STOCK ITEM ***")
  1. D NOW^%DTC
  1. N PSJDCHK F Z=%:0 S Z=$O(^PS(55,+PSGP,5,"AUS",Z)) Q:'Z!$D(DUOUT) F ZZ=0:0 S ZZ=$O(^PS(55,+PSGP,5,"AUS",Z,ZZ)) Q:'ZZ!$D(DUOUT) I +$G(^PS(55,+PSGP,5,ZZ,.2))=PSGX D PDWCHK(+PSGP,ZZ_"U") S PSJDCHK=1
  1. F STATUSNP="N","P" F Z=0:0 S Z=$O(^PS(53.1,"AS",STATUSNP,+PSGP,Z)) Q:'Z!$D(DUOUT) I +$G(^PS(53.1,+Z,.2))=PSGX D PDWCHK(+PSGP,Z_"P") S PSJDCHK=1
  1. I $D(PSJDCHK) N DIR D
  1. .S DIR(0)="Y",DIR("A")="Do you wish to continue entering this order",DIR("?",1)="Enter ""N"" if you wish to exit without creating a new order,"
  1. .S DIR("?")="or ""Y"" to continue with the order entry process." D ^DIR S:'Y Y=-1,X="^"
  1. K Z,ZZ
  1. Q
  1. ;
  1. ENDDC(PSGP,PSJDD) ; Perform Duplicate Drug, Duplicate Class,
  1. ; Drug-Drug interaction check, Drug-Allergy interaction check.
  1. N PSJLINE,Z,ZZ,PSJFST
  1. S (PSJLINE,PSJFST)=0
  1. I $G(PSJPWD)&($P($G(PSJSYSU),";")=3)&($G(PSJDD)) I ($D(^PSI(58.1,"D",PSJDD,PSJPWD)))!($D(^PSD(58.8,"D",PSJDD,PSJPWD))) W !?25,"*** A WARD STOCK ITEM ***"
  1. D EN^PSOORDRG(PSGP,PSJDD) K PSJPDRG N INTERVEN,PSJIREQ,PSJRXREQ S Y=1,(PSJIREQ,PSJRXREQ,INTERVEN,X)="" S DFN=PSGP
  1. I $T(HAVEHDR^ORRDI1)]"",$$HAVEHDR^ORRDI1,'$D(^XTMP("ORRDI","OUTAGE INFO","DOWN")) D
  1. . I $P($G(^XTMP("ORRDI","PSOO",PSGP,0)),"^",3)<0 W !,"Remote data not available - Only local order checks processed." D PAUSE^PSJLMUT1
  1. I $D(^TMP($J,"DD")) D ORDCHK^PSJLMUT1(PSGP,"DD",4)
  1. I $D(^TMP($J,"DC")) D ORDCHK^PSJLMUT1(PSGP,"DC",6)
  1. IVSOL ;*** Start order check for IV solution at this point.
  1. I '$D(PSJFST) N PSJFST S PSJFST=0
  1. I $D(^TMP($J,"DI")) S INTERVEN=1 D ORDCHK^PSJLMUT1(PSGP,"DI",8)
  1. ;*** Allergy/adverse reaction check.
  1. N PTR,X,CMP,CMPDR,CDRG
  1. S CMP=$P($G(^PSDRUG(PSJDD,999999935)),U,1) ;IHS/MSC/MGH check for compound
  1. S PTR=$P($G(^PSDRUG(PSJDD,"ND")),U)_"."_$P($G(^PSDRUG(PSJDD,"ND")),U,3)
  1. I +CMP=0 D ALGCHK(PSJDD)
  1. ;IHS/MSC/MGH Patch 1015 for compound meds
  1. I +CMP=1 D
  1. .S CMPDR=0
  1. .F S CMPDR=$O(^PSDRUG(PSJDD,999999936,CMPDR)) Q:'+CMPDR D
  1. ..S CDRG=$P($G(^PSDRUG(PSJDD,999999936,CMPDR,0)),U,1)
  1. ..I CDRG'="" S PTR=$P($G(^PSDRUG(CDRG,"ND")),U)_"."_$P($G(^PSDRUG(CDRG,"ND")),U,3)
  1. ..D ALGCHK(CDRG)
  1. ..;END mod for compound meds
  1. CONT ; Ask user if they wish to continue in spite of an order check.
  1. Q:'$D(PSJPDRG) N DIR S DIR(0)="Y",DIR("A")="Do you wish to continue entering this order",DIR("?",1)="Enter ""N"" if you wish to exit without creating a new order,"
  1. S DIR("?")="or ""Y"" to continue with the order entry process.",DIR("B")="NO" D ^DIR I 'Y S PSGORQF=1,X="^",COMQUIT=1 Q
  1. I 'INTERVEN!($P(PSJSYSU,";")'=3) Q
  1. NEW PSJY
  1. W:PSJIREQ !!,"This is a CRITICAL interaction, you must enter an intervention log to continue"
  1. S DIR(0)="Y",DIR("A")="Do you wish to log an intervention",DIR("?",1)="Enter ""N"" if you do not wish to log an intervention,",DIR("?")="or ""Y"" to log an intervention." D ^DIR S PSJY=Y D:Y ^PSJRXI
  1. I 'PSJY,PSJIREQ S PSGORQF=1,COMQUIT=1
  1. Q
  1. ALGCHK(PSJDD) ;CHECK FOR ALLERGIES
  1. ;IHS/MSC/MGH - 04/06/12
  1. ;K ^TMP("PSJDAI",$J) S PSJACK=$$ORCHK^GMRAOR(DFN,"DR",PTR,"",1) D:$G(PSJACK)=1
  1. S PSJACK=0
  1. K ^TMP("PSJDAI",$J) S PSJACK=$$ORCHK^GMRAOR(DFN,"DR",PTR,"",1) D:$G(PSJACK)=1
  1. .S ^TMP("PSJDAI",$J,0)=1
  1. .S I=0 F S I=$O(GMRAING(I)) Q:'I S ^TMP("PSJDAI",$J,I,0)=GMRAING(I)
  1. I $D(^TMP("PSJDAI",$J)) S PSJPDRG=1 D
  1. .W $C(7),!!,"A Drug-Allergy Reaction exists for this medication!",!!
  1. .W !?7,"Drug: "_$P($G(^PSDRUG(PSJDD,0)),"^") I $O(^TMP("PSJDAI",$J)) W !,"Ingredients: " D
  1. ..S I=0 F S I=$O(^TMP("PSJDAI",$J,I)) Q:'I W:$X+$L($G(^(I,0)))+2>IOM !?19 W:I=1 $G(^TMP("PSJDAI",$J,I,0)) W:I>1 ", ",$G(^TMP("PSJDAI",$J,I,0))
  1. .;IHS/MSC/MGH Added for reactions Patch 1014
  1. .I $O(GMRAREAC(0)) W !,?6,"Reactions: "
  1. .W ?19 S I=0 F S I=$O(GMRAREAC(I)) Q:'I W:$X+$L($G(GMRAREAC(I)))+2>IOM !?19 W $G(GMRAREAC(I))_", "
  1. .W !!
  1. ;K PSJACK,GMRAING,I,^TMP($J)
  1. K PSJACK,GMRAING,GMRAREAC,I,^TMP($J) ;IHS/MSC/MGH - 04/06/12
  1. D ALGCLASS(PSJDD)
  1. Q
  1. ;
  1. ENDL ; used by PSGTRAIN DRUG LOOK-UP option
  1. D ENCV^PSGSETU Q:$D(XQUIT)
  1. ;IHS/MSC/MGH changed for mixed case lookup, uses new cross-reference
  1. ;F S DIC="^PSDRUG(",DIC(0)="AEIMOQZ",DIC("A")="Select DRUG: " W ! D ^DIC K DIC Q:+Y'>0
  1. F S DIC="^PSDRUG(",DIC(0)="AEIMOQZ",D="BCAP",DIC("A")="Select DRUG: " W ! D IX^DIC K DIC Q:+Y'>0 D SF
  1. D ENKV^PSGSETU K N5,ND,Q,Y Q
  1. ;
  1. SF ;
  1. S Y=+Y,ND=$G(^PSDRUG(Y,0)),PSGID=+$G(^("I")) I PSGID W !!,"THIS DRUG IS INACTIVE AS OF ",$E($$ENDTC^PSGMI(PSGID),1,8)
  1. W !!,$S($P(ND,"^",9):"NON-",1:""),"FORMULARY ITEM" W:$P(ND,"^",10)]"" !,$P(ND,"^",10)
  1. S ND=$P($G(^PSDRUG(Y,2)),"^",3)["U" W !,$P("NOT^","^",ND+1)," A UNIT DOSE DRUG" W ! S ND=$G(^(8)),N5=$G(^(8.5)) W !?2,"DAY (nD) or DOSE (nL) LIMIT: " I ND W $P(ND,"^")
  1. W !?10,"UNIT DOSE MED ROUTE: " I $P(ND,"^",2) W $S($D(^PS(51.2,$P(ND,"^",2),0)):$P(^(0),"^"),1:$P(ND,"^",2))
  1. ; NAKED REF below refers to ^PS(51.2, on line above.
  1. W !?6,"UNIT DOSE SCHEDULE TYPE: " I $P(ND,"^",3)]"" W $P($P(";"_$P(^(0),"^",3),";"_$P(ND,"^",3)_":",2),";")
  1. W !?11,"UNIT DOSE SCHEDULE: " I $P(ND,"^",4)]"" W $P(ND,"^",4)
  1. W !,"CORRESPONDING OUTPATIENT DRUG: " I $P(ND,"^",5) W $S('$D(^PSDRUG(+$P(ND,"^",5),0)):$P(ND,"^",5),$P(^(0),"^")]"":$P(^(0),"^"),1:$P(ND,"^",5))
  1. W !?17,"ATC MNEMONIC: " I $P(N5,"^",2)]"" W $P(N5,"^",2)
  1. W !?17,"ATC CANISTER: " F Q=0:0 S Q=$O(^PSDRUG(Y,212,Q)) Q:'Q S ND=$G(^(Q,0)) I ND,$P(ND,"^",2) W ?31,$S('$D(^PS(57.5,+ND,0)):+ND_";PS(57.5,",$P(^(0),"^")]"":$P(^(0),"^"),1:+ND_";PS(57.5,"),?56,$P(ND,"^",2),!
  1. Q
  1. ;
  1. OCHK ; Add drugs in current order to ^TMP("ORDERS" and call order checker.
  1. ; Set PSJOCHK=1 so OP order check doesn't Kill array.
  1. ;
  1. K ^TMP($J,"ORDERS")
  1. N PSJOCHK S PSJOCHK=1
  1. PDWCHK(DFN,ON) ; Print Dup Drug order.
  1. N ND,ND0,ND2,X
  1. W:'$D(PSJDCHK) $C(7),$C(7),!!,"WARNING! THIS PATIENT HAS THE FOLLOWING ORDER(S) FOR THIS MEDICATION:",!!
  1. S ND=$$DRUGNAME^PSJLMUTL(DFN,ON)
  1. S F=$S(ON["P":"^PS(53.1,",1:"^PS(55,"_DFN_",5,"),ND0=$G(@(F_+ON_",0)")),ND2=$G(^(2)),X=$P(ND,U,2),X=$S(X=.2:$P($G(^(.2)),U,2),1:$G(^(.3)))
  1. W ?10,$P(ND,U),!,?13,"Give: ",X," ",$$ENMRN^PSGMI(+$P(ND0,U,3))," ",$P(ND2,U),!!
  1. Q
  1. ALGCLASS(PSJDD) ; checks any Drug allergies or reactions to see if
  1. ; the new drug is the same class
  1. ; this call can be removed by commenting out the call on IVSOL+16
  1. N PSJLIST,CT,CLS,CLCHK,CNT,PSJL,LIST,DCCNT,PSCLASS,LEN
  1. S PSCLASS=$P($G(^PSDRUG(PSJDD,0)),"^",2),LEN=4 I $E(PSCLASS,1,4)="CN10" S LEN=5 ;look at 5 chars if ANALGESICS
  1. I $T(GETDATA^GMRAOR)]"" G ALGC2
  1. S GMRA="0^0^111" D EN1^GMRADPT
  1. F PSJLIST=0:0 S PSJLIST=$O(GMRAL(PSJLIST)) Q:'PSJLIST D
  1. .K PSJAGL D EN1^GMRAOR2(PSJLIST,"PSJAGL")
  1. .; is the allergy/reaction drug class first four digits the same as the
  1. .; the class for the drug being entered?
  1. .S (CT,CLS)="",DCCNT=0
  1. .I $D(PSJAGL("V")) D
  1. ..;IHS/MSC/MGH Modified for reactions
  1. ..;F S DCCNT=$O(PSJAGL("V",DCCNT)) Q:'DCCNT S:$E($P($G(PSJAGL("V",DCCNT)),"^"),1,LEN)=$E(PSCLASS,1,LEN) (PSJPDRG,CLCHK)=1,CNT=$S('$D(CNT):1,1:CNT+1),LIST(CNT)=$P($G(PSJAGL),"^")_"^"_$P($G(PSJAGL("V",DCCNT)),"^",2)
  1. ..F S DCCNT=$O(PSJAGL("V",DCCNT)) Q:'DCCNT D
  1. ...I $E($P($G(PSJAGL("V",DCCNT)),"^"),1,LEN)=$E(PSCLASS,1,LEN) D
  1. ....S (PSJPDRG,CLCHK)=1,CNT=$S('$D(CNT):1,1:CNT+1)
  1. ....S LIST(CNT)=$P($G(PSJAGL),"^")_"^"_$P($G(PSJAGL("V",DCCNT)),"^",2)
  1. ....I $D(PSJAGL("S")) D
  1. .....N K S K=0 S K=$O(PSJAGL("S",K)) Q:'+K D
  1. ......S LIST(CNT,"S",K)=$G(PSJAGL("S",K))
  1. ..;END MOD
  1. D:$G(CLCHK)
  1. .W !!,$C(7),"A Drug-Allergy Reaction exists for this medication and/or class!"
  1. .F PSJL=0:0 S PSJL=$O(LIST(PSJL)) Q:'PSJL D
  1. ..W !?6,"Drug: "_$P(LIST(PSJL),"^"),!,"Drug Class: "_$P(LIST(PSJL),"^",2),!
  1. ..;IHS/MSC/MGH Updated for reactions Patch 1014
  1. ..N J S J=0 F S J=$O(LIST(PSJL,"S",J)) Q:J="" D
  1. ...I J=1 W !?6,"Reaction: "_$G(LIST(PSJL,"S",J))
  1. ...E W !,?19,$G(LIST(PSJL,"S",J))
  1. Q
  1. ALGC2 ;
  1. K GMRADRCL
  1. D GETDATA^GMRAOR(DFN) Q:'$D(^TMP("GMRAOC",$J,"APC"))
  1. N GMRACL,RET
  1. S RET=0,GMRACL="" F S GMRACL=$O(^TMP("GMRAOC",$J,"APC",GMRACL)) Q:'$L(GMRACL) D
  1. .N GMRANM,GMRALOC
  1. .S GMRALOC=^TMP("GMRAOC",$J,"APC",GMRACL)
  1. .S GMRANM=$P(^PS(50.605,+$O(^PS(50.605,"B",GMRACL,0)),0),U,2)
  1. .S GMRADRCL(GMRACL)=GMRACL_U_GMRANM_" ("_GMRALOC_")"
  1. .;IHS/MSC/MGH added for reaction data patch 1014
  1. .S J=0 F S J=$O(^TMP("GMRAOC",$J,"APC",GMRACL,"REAC",J)) Q:'+J D
  1. ..S GMRAREAC(GMRACL,J)=$G(^TMP("GMRAOC",$J,"APC",GMRACL,"REAC",J))
  1. .;END MOD
  1. .S RET=RET+1
  1. Q:'RET K ^TMP("GMRAOC",$J)
  1. ;IHS/GDIT/MSC/MGH fix for reactions patch 1022
  1. S CLCHK="",CT="" F S CT=$O(GMRADRCL(CT)) Q:CT="" D
  1. .I $E(PSCLASS,1,LEN)=$E(CT,1,LEN) D
  1. ..S CLCHK=$G(CLCHK)+1,^TMP($J,"PSJDRCLS",CLCHK)=CT_" "_$P(GMRADRCL(CT),"^",2)
  1. ..S K=0 F S K=$O(GMRAREAC(CT,K)) Q:'+K D
  1. ...I K=1 S ^TMP($J,"PSODRCLS","REAC",K)="Reactions: "_$G(GMRAREAC(CT,K))
  1. ...E S ^TMP($J,"PSODRCLS","REAC",K)=$G(GMRAREAC(CT,K))
  1. CLASSDSP ;
  1. I '$D(^TMP($J,"PSJDRCLS")) Q
  1. W $C(7),!,"A Drug-Allergy Reaction exists for this medication and/or class!",!
  1. W !,"Drug: "_$P($G(^PSDRUG(PSJDD,0)),"^")
  1. S CT="" F S CT=$O(^TMP($J,"PSJDRCLS",CT)) Q:CT="" W !,"Drug Class: "_^TMP($J,"PSJDRCLS",CT)
  1. ;IHS/MSC/MGH added patch 1014 for reactions
  1. ;IHS/GDIT/MSC/MGH fix for reactions patch 1022
  1. S K=0 F S K=$O(^TMP($J,"PSODRCLS","REAC",K)) Q:K="" D
  1. .I K=1 W !?6,"Reactions: "_$G(^TMP($J,"PSODRCLS","REAC",K))
  1. .E W !?19,$G(^TMP($J,"PSODRCLS","REAC",K))
  1. .;S K=0 F S K=$O(GMRAREAC(K)) Q:'+K D
  1. .;I K=1 W !?6,"Reactions: "_$G(GMRAREAC(K))
  1. .;E W !?19,$G(GMRAREAC(K))
  1. ;END MOD
  1. K ^TMP($J,"PSJDRCLS")
  1. S DIR("?",1)="Answer 'YES' if you DO want to enter a reaction for this medication,"
  1. S DIR("?")=" 'NO' if you DON'T want to enter a reaction for this medication,"
  1. S DIR(0)="SA^1:YES;0:NO",DIR("A")="Do you want to Intervene? ",DIR("B")="Y" W ! D ^DIR
  1. I Y D ^PSJRXI
  1. I '$G(Y) K DIR,DTOUT,DIRUT,DIROUT,DUOUT,Y Q
  1. Q