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

PSGVBW.m

Go to the documentation of this file.
  1. PSGVBW ;BIR/CML,MV - VERIFY ORDERS BY WARD, WARD GROUP, PATIENT, OR PRIORITY ;10/22/98 3:14 PM
  1. ;;5.0;INPATIENT MEDICATIONS;**5,16,39,59,62,67,58,81,80,110,111,133,139,155,241,243,265,275,304,325,422,407**;DEC 16, 1997;Build 26
  1. ;
  1. ; Reference to ^PS(55 is supported by DBIA #2191
  1. ; Reference to ^PS(51.1 is supported by DBIA #2177
  1. ; Reference to ^DPT is supported by DBIA #10035
  1. ;
  1. N PSJNEW,PSGPTMP,PPAGE,CL,CG S PSJNEW=1
  1. START ; Lookup patient by ward group, ward, priority, or patient; depending on value of PSGSS
  1. ;
  1. D ENCV^PSGSETU I $D(XQUIT) K XQUIT Q
  1. D ^PSIVXU I $D(XQUIT) K XQUIT Q
  1. Q:$G(DONE) ;P407
  1. D NOW^%DTC S PSGDT=%
  1. I '$D(^XTMP("PSJPVNV")) D
  1. .K DIR S DIR(0)="Y",DIR("A")="Display an Order Summary",DIR("B")="NO"
  1. .S DIR("?",1)="Enter 'YES' to see a summary of orders by type and ward group",DIR("?")="or 'NO' to go directly to patient selection."
  1. .D ^DIR K DIR Q:$D(DIRUT)!$D(DUOUT) I Y D CNTORDRS^PSGVBWU
  1. K ^TMP("PSJ",$J) S PSGPXN=0 D GTOOP G:$D(DIRUT) DONE L +^PS(53.45,PSJSYSP):1 E D LOCKERR^PSJOE G DONE
  1. S PSGSSH="VBW",PSGPXN=0,PSJPROT=$S($P(PSJSYSU,";",3)=3:3,$G(PSJRNF):3,$G(PSJIRNF):3,1:1)
  1. S PSGVBWW=$S(PSJTOO=1:"NON-VERIFIED",PSJTOO=2:"PENDING",1:"NON-VERIFIED AND/OR PENDING")
  1. F K ^TMP("PSJSELECT",$J) D PRI^PSGSEL Q:"^"[PSGSS F S (PSGP,WD,WG)=0 S PSGPTMP=0,PPAGE=1 K PSGPRIF D @PSGSS Q:+Y'>0 D GO
  1. ;
  1. DONE ; Cleanup
  1. D DONE2
  1. K SETWDN,PTPRI,SETTM,SETPN,SUBS,TMPWD,STATUS
  1. K CHK,D0,DRGI,FQC,J,ND,ON,PN,PSGODT,PSGOEA,PSGOP,PSGSS,PSGSSH,RB,SD,ST,TM,WD,WDN,WG,PRI,PSJPNV,PSJCT,PSGCLF,PSGPRIF,LIDT,WDNAME,IFPRI
  1. K PSGODDD,PSGOEORF,PSJORL,PSJORPCL,PSJORTOU,PSJORVP,PSGTOL,PSJTOO,PSGUOW,PSGONV,PX,PSGOEAV,PSGPX,PSGVBWTO,PSGVBWW,PSJOPC,PSGOENOF,PSJPROT,PSJLM,PSJASK
  1. K PSJPAC,PSJINDEX,PSJCNT,PSIVSN,PSGWORP1,PSGWORP2,PSGVBY,PSGVBWN,PSGVBTM,PSGVBPN,PSGPXN,PSGPRIN,PSGPRD,PSGINWD,PSGINCL,PRDON,PRDNS,PRD,PPN,ORDT
  1. L -^PS(53.45,PSJSYSP) G:$G(PSGPXN) ^PSGPER1 D ENKV^PSGSETU K ND Q
  1. ;
  1. DONE2 ; Partial Cleanup
  1. K ^TMP("PSGVBW",$J),^TMP("PSGVBW2",$J),^TMP("PSGVBW3",$J),^TMP("PSJSELECT",$J),^TMP("PSJLIST",$J),^TMP("PSJON",$J)
  1. K PRD
  1. Q
  1. ;
  1. GO ; Find and display matching patients
  1. D START^PSIVARH
  1. I PSGSS'="P" W !,"...a few moments, please..." K ^TMP("PSGVBW",$J),^TMP("PSGVBW2",$J) D ARRAY K CHK,ON,PN,RB,SD,TM,WD,WDN,WG,X,Y
  1. I PSGSS'="P",'$D(^TMP("PSGVBW",$J)) W !,$C(7),"NO ",PSGVBWW," ORDERS FOR ",$S(PSGSS="P":"PATIENT",PSGSS="L":"CLINIC GROUP",PSGSS="C":"CLINIC",PSGSS="PR":"PRIORITY",1:"WARD"),$S(PSGSS="G":" GROUP",1:"")," SELECTED." Q
  1. D ^PSGVBW0,DONE2 Q
  1. ;
  1. G ; Select a Ward Group
  1. K DIR S DIR(0)="FAO",DIR("A")="Select WARD GROUP: "
  1. S DIR("?")="^D GDIC^PSGVBW" W ! D ^DIR
  1. I Y="^OTHER" D OUTPT^PSGVBW1 Q
  1. GDIC ; Ward Group lookup
  1. K DIC S DIC="^PS(57.5,",DIC(0)="QEMI" D ^DIC K DIC S:+Y>0 WG=+Y
  1. W:X["?" !!,"Enter ""^OTHER"" to include all orders from the wards that do not",!,"belong to a ward group, or orders that have neither a ward nor a clinic.",! ;PSJ*5*241: Updated help text
  1. Q
  1. C ; Select a Clinic
  1. K DIR S DIR(0)="FAO",DIR("A")="Select CLINIC: "
  1. S DIR("?")="^D CDIC^PSGVBW" W ! D ^DIR
  1. CDIC ; Clinic lookup
  1. K DIC S DIC="^SC(",DIC(0)="QEMIZ" D ^DIC K DIC S:+Y>0 CL=+Y
  1. W:X["?" !!,"Enter the clinic you want to use to select patients for processing.",!
  1. Q
  1. L ; Select a Clinic Group
  1. K DIR S DIR(0)="FAO",DIR("A")="Select CLINIC GROUP: "
  1. S DIR("?")="^D LDIC^PSGVBW" W ! D ^DIR
  1. LDIC ; Clinic Group lookup
  1. K DIC S DIC="^PS(57.8,",DIC(0)="QEMI" D ^DIC K DIC S:+Y>0 CG=+Y
  1. W:X["?" !!,"Enter the name of the clinic group you want to use to select patients for processing."
  1. Q
  1. W ; Select a Ward
  1. K DIR S DIR(0)="FAO",DIR("A")="Select WARD: "
  1. S DIR("?")="^D WDIC^PSGVBW" W ! D ^DIR
  1. I Y="^OTHER" D OUTPT^PSGVBW1 Q
  1. WDIC ; Ward lookup
  1. K DIC S DIC="^DIC(42,",DIC(0)="QEMIZ" D ^DIC K DIC S:+Y>0 WD=+Y
  1. W:X["?" !!,"Enter ""^OTHER"" for Outpatient IV orders",!
  1. Q
  1. PR ; Select order priority
  1. K DIR S DIR(0)="SO^1:STAT;2:ASAP;3:ROUTINE"
  1. S DIR("A")="Select 1-3 ",DIR("?")=" Choose a Priority."
  1. S DIR("?",1)="Enter a PRIORITY to include all patients with orders containing that PRIORITY"
  1. D ^DIR S:Y>0 PRD=+Y S:+Y>0 WDN=$S(PRD=1:"STAT",PRD=2:"ASAP",3:"ROUTINE")
  1. Q
  1. P ; Select patient
  1. K ^TMP("PSJSELECT",$J) S PSJCNT=1 F D ^PSJP Q:PSGP<0 D
  1. .S PSJNV=0
  1. .NEW ON,XX F ON=0:0 S ON=$O(^PS(53.1,"AS","N",PSGP,ON)) Q:'ON S ND=$P($G(^PS(53.1,ON,0)),U,4) S XX=$S(ND="U"&(PSJPAC'=2):1,ND'="U"&(PSJPAC'=1):1,1:0) I XX S PSJNV=1 Q
  1. .;S PSJNV=$O(^PS(53.1,"AS","N",+PSGP,0)),PSJPEN=$O(^PS(53.1,"AS","P",+PSGP,0))
  1. .S PSJPEN=$O(^PS(53.1,"AS","P",+PSGP,0))
  1. .I 'PSJNV D ^PSJAC D
  1. ..I '$D(PSGDT) D NOW^%DTC S PSGDT=$E(%,1,12)
  1. ..S X1=$P(PSGDT,"."),X2=-2 D C^%DTC S PSGODT=X_(PSGDT#1)
  1. ..I PSJPAC'=2 F ST="C","O","OC","P","R" F SD=$S(ST="O":PSJPAD,1:PSGODT):0 S SD=$O(^PS(55,PSGP,5,"AU",ST,SD)) Q:'SD!PSJNV F ON=0:0 S ON=$O(^PS(55,PSGP,5,"AU",ST,SD,ON)) Q:'ON I $D(^PS(55,PSGP,5,ON,0)),$P(^(0),"^",9)'["D" D IFT I S PSJNV=1 Q
  1. ..I PSJPAC'=1 F SD=+PSJPAD:0 S SD=$O(^PS(55,PSGP,"IV","AIS",SD)) Q:'SD!(SD'=+SD) F ON=0:0 S ON=$O(^PS(55,PSGP,"IV","AIS",SD,ON)) Q:'ON I $D(^PS(55,PSGP,"IV",ON,0)),$P(^(0),"^",17)'["D" D IFT2 I S PSJNV=1 Q
  1. .S X=$S(PSJTOO=1:PSJNV,PSJTOO=2:PSJPEN,1:(PSJNV+PSJPEN))
  1. .I X D SETPN S ^TMP("PSJSELECT",$J,PSJCNT)=PN,^TMP("PSJSELECT",$J,"B",$P(PN,U),PSJCNT)="",PSJCNT=PSJCNT+1 Q
  1. .W !,"No ",PSGVBWW," orders found for this patient."
  1. S:$D(^TMP("PSJSELECT",$J)) Y=1
  1. Q
  1. ARRAY ; put patient(s) with non-verified orders into array
  1. I '$D(PSGDT) D NOW^%DTC S PSGDT=$E(%,1,12)
  1. S X1=$P(PSGDT,"."),X2=-2 D C^%DTC S PSGODT=X_(PSGDT#1),PSGVBWW=$S(PSJTOO=1:"NON-VERIFIED",PSJTOO=2:"PENDING",1:"NON-VERIFIED AND/OR PENDING") I PSGSS="P" D IF S:$T ^TMP("PSGVBW",$J)=$P(PSGP(0),"^")_"^"_PSGP Q
  1. G CG:PSGSS="L",CL:PSGSS="C",WD:PSGSS="W",PRI:PSGSS="PR" S WD=0 F S WD=$O(^PS(57.5,"AC",WG,WD)) Q:'WD D WD
  1. Q
  1. ;
  1. CG ; Find all clinics in selected clinic group
  1. S CL="" F S CL=$O(^PS(57.8,"AD",CG,CL)) Q:CL="" D CL
  1. Q
  1. CL ; Find all patients in selected clinic
  1. S WDN=$S($D(^SC(CL,0)):$P(^(0),"^"),1:"")
  1. S PSGP="",PSGCLF=1 F S PSGP=$O(^PS(53.1,"AD",CL,PSGP)) Q:PSGP="" D ^PSJAC,IF
  1. K PSGCLF
  1. Q
  1. WD ; Find all patients in selected ward
  1. S WDN=$S($D(^DIC(42,WD,0)):$P(^(0),"^"),1:"")
  1. I WDN]"" S PSGP=0 F S PSGP=$O(^DPT("CN",WDN,PSGP)) Q:'PSGP D
  1. .I $S($D(^PS(55,"APV",PSGP)):1,$D(^PS(55,"APIV",PSGP)):1,$O(^PS(55,PSGP,5,"AUS",PSGDT)):1,1:$D(^PS(53.1,"AC",PSGP))) D ^PSJAC,IF
  1. Q
  1. PRI ; Find orders with selected Priority
  1. ; Once a patient is identified in any status index ("I", "N", or "P"), all orders for that patient are checked in the
  1. ; IF subroutine. To prevent unnecessary duplication of processing, "PSGVBW3" node of ^TMP, sorted by patient, will be
  1. ; set when a patient's orders are processed, and checked for each status index. If patient exists in the "PSGVBW3" node,
  1. ; patient has already been processed, so quit.
  1. N NDP2,PSGALL,ND0,PSGPRIFZ K ^TMP("PSGVBW3",$J)
  1. S PSGPRIF=1 F STATUS="I","N","P" S PSGP=0 F S PSGP=$O(^PS(53.1,"AS",STATUS,PSGP)) Q:'PSGP Q:($D(^TMP("PSGVBW3",$J,PSGP))) D ^PSJAC,IF
  1. K ^TMP("PSGVBW3",$J)
  1. Q
  1. IF ;BHW;PSJ*5*155;Added PSGCLF and PS(53.1,"AD" Check below. If called from CL subroutine and the order Doesn't exist for that Clinic, then QUIT.;PSJ*5*241:Changed quit conditions
  1. W "." I PSJTOO'=1 S ON=0 F S ON=$O(^PS(53.1,"AS","P",PSGP,ON)) Q:'ON!(($G(WDN)="ZZ")&(+$P($G(^PS(53.1,+$G(ON),"DSS")),U,1)'=0)) D
  1. .Q:(($G(PSGCLF))&('$D(^PS(53.1,"AD",+$G(CL),PSGP,+$G(ON))))) ;PSJ*5*265 - move quit condition inside loop
  1. .S X=$P($G(^PS(53.1,ON,0)),U,4),IFPRI=0,Y=0 I "FIU"[X D D:Y SET
  1. ..I $G(PSGPRIF) D Q:'IFPRI
  1. ...N PRIO S PRIO=$P($G(^PS(53.1,+ON,.2)),"^",4),PRIO=$S(PRIO="S":1,PRIO="A":2,1:3) S IFPRI=$S(PRD=PRIO:1,1:"")
  1. ..I PSJPAC=3 S Y=1 Q
  1. ..I PSJPAC=2 S Y=X'="U" Q
  1. ..I PSJPAC=1 S Y=X="U"
  1. I PSJTOO=2 D Q
  1. .I '$G(PSGPRIF),$D(^TMP("PSGVBW2",$J)) D SET2
  1. ;PSJ*5*422 add PSJXXX to get all orders
  1. N PRIOAR,PSJXXX,XX
  1. F X="N","I" I $D(^PS(53.1,"AS",X,PSGP)) S (XX,PSJXXX)=0 D I XX!PSJXXX D SET K ON
  1. . F ON=0:0 S ON=$O(^PS(53.1,"AS",X,PSGP,ON)) Q:'ON!(($G(WDN)="ZZ")&(+$P($G(^PS(53.1,+$G(ON),"DSS")),U,1)'=0)) D Q:($G(PRD)&$G(XX))
  1. .. S ND=$P($G(^PS(53.1,ON,0)),U,4),XX=$S(ND="U"&(PSJPAC'=2):1,ND'="U"&(PSJPAC'=1):1,1:0)
  1. .. S:XX PSJXXX=1 I XX D
  1. ... S PRIOAR=$P($G(^PS(53.1,+$G(ON),.2)),U,4),PRIOAR=$S(PRIOAR="S":"S",PRIOAR="A":"A",1:"R")
  1. ... I $G(PRD) S XX=$S(PRD=1&(PRIOAR="S"):1,PRD=2&(PRIOAR="A"):1,PRD=3&(PRIOAR="R"):1,1:0) Q
  1. ... S PRIOAR(PRIOAR)=ON
  1. . Q:$G(PRD) S ON=$S($G(PRIOAR("S")):PRIOAR("S"),$G(PRIOAR("A")):PRIOAR("A"),1:$G(PRIOAR("R")))
  1. S X1=$P(PSGDT,"."),X2=-2 D C^%DTC S PSGODT=X_(PSGDT#1)
  1. I PSJPAC'=2 F ST="C","O","OC","P","R" F SD=$S(ST="O":PSJPAD,1:PSGODT):0 S SD=$O(^PS(55,PSGP,5,"AU",ST,SD)) Q:'SD F ON=0:0 S ON=$O(^PS(55,PSGP,5,"AU",ST,SD,ON)) Q:'ON I $D(^PS(55,PSGP,5,ON,0)),$P(^(0),"^",9)'["D" D IFT I D SET
  1. ;*PSJ*5*241:Expired IV orders must be one-time
  1. I PSJPAC'=1 F SD=+PSJPAD:0 S SD=$O(^PS(55,PSGP,"IV","AIS",SD)) Q:'SD F ON=0:0 S ON=$O(^PS(55,PSGP,"IV","AIS",SD,ON)) Q:'ON D
  1. .N SCH,STYPE S STYPE=0,SCH=$P($G(^PS(55,PSGP,"IV",ON,0)),U,9)
  1. .S:SCH]"" SCH=$O(^PS(51.1,"APPSJ",SCH,STYPE)) S:SCH]"" STYPE=$P($G(^PS(51.1,SCH,0)),U,5)
  1. .I $D(^PS(55,PSGP,"IV",ON,0)),$P(^(0),"^",17)'["D",'(($P(^(0),"^",17)="E")&($G(STYPE)'="O")) D IFT2 I D SET
  1. I '$G(PSGPRIF),$D(^TMP("PSGVBW2",$J)) D SET2
  1. Q
  1. ;
  1. IFT ; Loop through active UD orders in ^PS(55 that have not been verified by pharmacist.
  1. S ND=$G(^PS(55,PSGP,5,ON,4)) I $S(SD>PSGDT:$S(ND="":1,'$P(ND,"^",$S(PSJSYSU:PSJSYSU,1:1)):1,$P(ND,"^",13):1,$P(ND,"^",19):1,$P(ND,"^",23):1,1:$P(ND,"^",16)),ST="O":$S(ND="":1,1:'$P(ND,"^",$S(PSJSYSU:PSJSYSU,1:1))),1:$P(ND,"^",16))
  1. Q
  1. ;
  1. IFT2 ; Loop through active IV orders in ^PS(55 that have not been verified by pharmacist.
  1. ;S ND=$G(^PS(55,PSGP,"IV",ON,4)) I $S((SD>PSGDT)&(ND=""):1,'$P(ND,"^",$S(+PSJSYSU=1:1,1:4)):1,1:0)
  1. S ND=$G(^PS(55,PSGP,"IV",ON,4))
  1. I ($P($G(^PS(55,PSGP,"IV",ON,.2)),"^",4)="D")&('$P(ND,"^",$S(+PSJSYSU=1:1,1:4))) Q
  1. I $S((SD>PSGDT)&('$P(ND,"^",$S(+PSJSYSU=1:1,1:4))):1,1:0)
  1. Q
  1. SET ; Set patient specific variables for ^TMP subscripts
  1. S PRDON=""
  1. I $G(ON) S PRDON=$P($G(^PS(53.1,+ON,.2)),"^",4),PRDON=$S(PRDON="A":"ASAP",PRDON="S":"STAT",PRDON="R":"ROUTINE",1:"zz")
  1. S PTPRI=$S(PRDON="STAT":1,PRDON="ASAP":2,PRDON="ROUTINE":3,1:3)
  1. I $G(PSGPRIF) Q:(PRD'=PTPRI)
  1. K DIC,X,Y,WDNAME,TMPWD S WDNAME=$G(^DPT(+PSGP,.1)) S X=WDNAME,DIC="^DIC(42,",DIC(0)="BOXZ" D ^DIC S TMPWD=+Y
  1. S TM=$S(PSJPRB="":"",1:$P($G(^PS(57.7,TMPWD,1,+$O(^PS(57.7,"AWRT",TMPWD,PSJPRB,0)),0)),"^")) S:TM="" TM="zz"
  1. ;
  1. SETPN ; If searching for specific priority:
  1. ; - set patient into ^TMP("PSGBW" sorted by Priority Name, Priority #, Team, Patient Name^IEN^SSN
  1. ; If not searching for specific priority:
  1. ; - set patient into ^TMP("PSGVBW2" sorted by 'Patient Name^IEN^SSN', then Priority
  1. ; - set patient into ^TMP("PSGVBW3" sorted by Patient IEN
  1. I $G(PSGP(0))="" D DEM^VADPT S PSGP(0)=VADM(1)
  1. S PN=$P(PSGP(0),"^")_U_PSGP_U_PSJPBID
  1. Q:PSGSS="P"
  1. I $G(PSGPRIF) S ^TMP("PSGVBW",$J,WDN,PTPRI,TM,PN)="" Q
  1. S ^TMP("PSGVBW2",$J,PN,+$G(PTPRI))=WDN_"^"_TM,^TMP("PSGVBW3",$J,+PSGP)=""
  1. Q
  1. ;
  1. SET2 ; If not searching for a specific priority,find the highest priority order associated with patient.
  1. ; Set the patient into ^TMP("PSGVBW" sorted by highest Priority Name, Priority #, Team, Patient Name^IEN^SSN
  1. S SETPN="" F S SETPN=$O(^TMP("PSGVBW2",$J,SETPN)) Q:SETPN="" D
  1. .S PTPRI=$O(^TMP("PSGVBW2",$J,SETPN,0)) Q:'$G(PTPRI)
  1. .S SUBS=$G(^TMP("PSGVBW2",$J,SETPN,PTPRI)),SETWDN=$P(SUBS,"^"),SETTM=$P(SUBS,"^",2) Q:SETWDN=""!(SETTM="")
  1. .S ^TMP("PSGVBW",$J,SETWDN,PTPRI,SETTM,SETPN)=""
  1. K ^TMP("PSGVBW2",$J)
  1. Q
  1. GTOOP ; Get 'Type Of Order' and Package
  1. I $P(PSJSYSU,";",3)<2,'$G(PSJRNF),'$G(PSJIRNF) S PSJPAC=0,PSJTOO=1 D GTPAC Q
  1. S (PSJPAC,PSJTOO)=0 W !!,"1) Non-Verified Orders",!,"2) Pending Orders",!!
  1. N DIR S DIR(0)="LAO^1:2",DIR("A")="Select Order Type(s) (1-2): ",DIR("?")="^D TOH^PSGVBW" D ^DIR
  1. I 'Y D EXIT("TYPE OF ORDER") Q
  1. S PSJTOO=$S($L(Y)>2:3,1:$P(Y,","))
  1. D GTPAC
  1. I 'PSJPAC D EXIT("PACKAGE") Q
  1. Q
  1. ;
  1. GTPAC ; Prompt user for Package
  1. I ($G(PSJRNF))&('$G(PSJIRNF))&(PSJTOO=2) S PSJPAC=1 Q
  1. I ($G(PSJIRNF))&('$G(PSJRNF))&(PSJTOO=2) S PSJPAC=2 Q
  1. W !!,"1) Unit Dose Orders",!,"2) IV Orders",!
  1. K DIR S DIR(0)="LAO^1:2",DIR("A")="Select Package(s) (1-2): ",DIR("?")="^D TOH^PSGVBW" W ! D ^DIR
  1. S PSJPAC=$S($L(Y)>2:3,1:$P(Y,","))
  1. Q
  1. EXIT(X) ; Generic user error message
  1. W !!,X," not selected, option terminated."
  1. Q
  1. ;
  1. TOH ; Help text
  1. W !!,"SELECT FROM:",!?5,"1 - NON-VERIFIED ORDERS",!?5,"2 - PENDING ORDERS"
  1. W !!?2,"Enter '1' if you want to verify non-verified orders. Enter '2' if you",!,"want to complete pending orders. Enter '1,2' or '1-2' if you want to do both." Q