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

PSOERXC1.m

Go to the documentation of this file.
PSOERXC1 ;ALB/BWF - eRx Utilities/RPC's ; 6/1/2018 5:14pm
 ;;7.0;OUTPATIENT PHARMACY;**508,551,567,581,631,617**;DEC 1997;Build 110
 ;
EN(SRCH,SORTT,PCVSTAT) ; -- main entry point for PSO ERX PATIENT CENTRIC VIEW
 N PSOC1RE
 D EN^VALM("PSO ERX PATIENT CENTRIC VIEW")
 Q
 ;
HDR ; -- header code
 N PSOLBK
 S VALMHDR(1)="                       Patient Centric View"
 S PSOLBK=$$GET1^DIQ(59,PSOSITE,10.2,"E")
 S VALMHDR(2)=$S(PSOLBK:$J(" ",21),1:$J(" ",14))_"ERX LOOK-BACK DAYS: "_$S(PSOLBK:PSOLBK,1:"Default value 365")_" ("_$$FMTE^XLFDT($$FMADD^XLFDT(DT,-$S(PSOLBK:PSOLBK,1:365)))_")"
 I $G(PSOC1RE) K @VALMAR,PSOC1RE D INIT
 Q
 ;
INIT ; -- init variables and list array
 N EBDATE,EDATE,BDATE,RXSTAT,RXDATE,ERXIEN,PATIEN,RDATE,ERXSTAT,COUNT,PNAME,DOB,DOB2,NEW,WAIT,IPR,HOLD,TOTAL,RXDATE2
 N RXSTATE,PATCNT,B,G,VAR,DIRECT,LINEVAR,EDAYS,EDLOOP,GLOB,LASTUSER,PATINFO,EDAYS2,PATLOOP,CCR,LINE,OTH,CNT,BDOVR,MTYPE
 N SVAL,P5246IEN,ESCODE,CSCNT,CSPREFIX
 S PSOSRCH=$S($D(SRCH):1,1:0) I PSOSRCH S PSOSRCH(VALMEVL)=""
 S PSOSRT=$S($D(SORTT):1,1:0) I PSOSRT S PSOSRT(VALMEVL)=""
 K ^TMP("CENTRIC",$J),^TMP("RDATE",$J),^TMP("PSOERXC1",$J)
 I '$D(PSOINST) D
 .D ^PSOLSET
 Q:'$D(PSOINST)
 S GLOB=$NA(^TMP("PSOERXC1",$J)) K @GLOB
 S BDATE=$$FMADD^XLFDT(DT,-365)
 S CNT=0,PATCNT=0
 S EDATE=DT_".9999"
 S RXDATE=BDATE
 S BDOVR=$$GET1^DIQ(59,PSOSITE,10.2,"E") I BDOVR S RXDATE=$$FMADD^XLFDT(DT,-BDOVR)
 S RXDATE2=BDATE
 F  S RXDATE=$O(^PS(52.49,"F",PSNPINST,RXDATE)) Q:'RXDATE!(RXDATE>EDATE)!(RXDATE="")!(PATCNT>998)  D
 .I $D(SRCH(1)) D  Q
 ..S SVAL=$P(SRCH(1),U)
 ..S ERXIEN=0 F  S ERXIEN=$O(^PS(52.49,"EPAT",PSNPINST,RXDATE,SVAL,ERXIEN)) Q:'ERXIEN!(PATCNT>998)  D
 ...D BLDITEM(ERXIEN,.PATCNT,$G(PCVSTAT))
 .I $D(SRCH(2)) D  Q
 ..S SVAL=$P(SRCH(2),U)
 ..S P5246IEN=0 F  S P5246IEN=$O(^PS(52.46,"DOB",SVAL,P5246IEN)) Q:'P5246IEN!(PATCNT>998)  D
 ...S ERXIEN=0 F  S ERXIEN=$O(^PS(52.49,"EPAT",PSNPINST,RXDATE,P5246IEN,ERXIEN)) Q:'ERXIEN!(PATCNT>998)  D
 ....D BLDITEM(ERXIEN,.PATCNT,$G(PCVSTAT))
 .S RXSTAT=0 F  S RXSTAT=$O(^PS(52.49,"F",PSNPINST,RXDATE,RXSTAT)) Q:'RXSTAT!(PATCNT=999)  D
 ..I +$G(STAT),$G(STAT)'=RXSTAT Q
 ..S RXSTATE=$$GET1^DIQ(52.45,RXSTAT,.01,"E")
 ..I ((RXSTATE="RJ")!(RXSTATE="RM")!(RXSTATE="PR")!(RXSTATE="E")) Q
 ..S ERXIEN=0 F  S ERXIEN=$O(^PS(52.49,"F",PSNPINST,RXDATE,RXSTAT,ERXIEN)) Q:'ERXIEN!(PATCNT=999)  D
 ...D BLDITEM(ERXIEN,.PATCNT,$G(PCVSTAT))
 S PATIEN=0,LINE=0
 I '$O(^TMP("CENTRIC",$J,0)) S LINE=$G(LINE)+1,VALMCNT=LINE D SET^VALM10(LINE,"No records found.") Q
 F  S PATIEN=$O(^TMP("CENTRIC",$J,PATIEN)) Q:'PATIEN  D
 .S PNAME=$$GET1^DIQ(52.46,PATIEN,.01)
 .S DOB=$$GET1^DIQ(52.46,PATIEN,.08,"I"),DOB2=$$FMTE^XLFDT(DOB,"5Z")
 .F  S RXDATE2=$O(^PS(52.49,"PAT2",PATIEN,RXDATE2)) Q:'RXDATE2!(RXDATE2>EDATE)  D
 ..S ERXIEN=0 F  S ERXIEN=$O(^PS(52.49,"PAT2",PATIEN,RXDATE2,ERXIEN)) Q:'ERXIEN  D
 ...Q:$$GET1^DIQ(52.49,ERXIEN,24.1,"I")'=PSNPINST
 ...I '$$CSFILTER^PSOERXUT(ERXIEN) Q
 ...S ERXSTAT=$$GET1^DIQ(52.49,ERXIEN,1,"E")
 ...I (ERXSTAT="PR")!(ERXSTAT="RM")!(ERXSTAT="RJ")!(ERXSTAT="E") Q
 ...S ESCODE=","_$S($E(ERXSTAT)="H":$E(ERXSTAT),1:ERXSTAT)_","
 ...I ",RRE,RXI,RXW,RXR,RXE,RXN,RXD,RXF,CAO,CAR,CAH,CAP,CAX,CAF,CXD,CXN,CXV,CXY,CXE,CXI,CXW,CRE,N,I,W,H,"'[ESCODE Q
 ...S MTYPE=$$GET1^DIQ(52.49,ERXIEN,.08,"I")
 ...S RDATE=$E($$GET1^DIQ(52.49,ERXIEN,.03,"I"),1,7)
 ...I '$D(^TMP("RDATE",$J,PATIEN,0)) S ^TMP("RDATE",$J,PATIEN,0)=$G(RDATE)
 ...I $D(^TMP("RDATE",$J,PATIEN,0)),^TMP("RDATE",$J,PATIEN,0)>$G(RDATE) S ^TMP("RDATE",$J,PATIEN,0)=$G(RDATE)
 ...S COUNT=$G(^TMP("CENTRIC",$J,PATIEN,0))
 ...I ERXSTAT="N" S $P(COUNT,U,1)=$P($G(COUNT),U)+1
 ...I ",W,RXW,CXW,"[(","_ERXSTAT_",") S $P(COUNT,U,2)=$P($G(COUNT),U,2)+1
 ...I ",I,RXI,CXI,"[(","_ERXSTAT_",") S $P(COUNT,U,3)=$P($G(COUNT),U,3)+1
 ...I $E(ERXSTAT)="H" S $P(COUNT,U,4)=$P($G(COUNT),U,4)+1
 ...I ",RXN,RXE,RXR,RXD,RXF,CAO,CAR,CAH,CAP,CAX,CAF,CXD,CXN,CXV,CXY,CXE,"[(","_ERXSTAT_",") D
 ....S $P(COUNT,U,5)=$P($G(COUNT),U,5)+1
 ...; finalize and display count for 'other' types.
 ...I MTYPE="IE",",RRE,CRE,"[(","_ERXSTAT_",") S $P(COUNT,U,6)=$P($G(COUNT),U,6)+1
 ...I $$GET1^DIQ(52.49,ERXIEN,95.1,"I") S $P(COUNT,U,7)=$P($G(COUNT),U,7)+1
 ...S ^TMP("CENTRIC",$J,PATIEN,0)=COUNT
 .S COUNT=$G(^TMP("CENTRIC",$J,PATIEN,0))
 .F G=1:1:7 D
 ..I $P(COUNT,U,G)="" D
 ...S $P(COUNT,U,G)=0
 .S NEW=$P(COUNT,U)
 .S WAIT=$P(COUNT,U,2)
 .S IPR=$P(COUNT,U,3)
 .S HOLD=$P(COUNT,U,4)
 .S CCR=$P(COUNT,U,5)
 .S OTH=$P(COUNT,U,6)
 .S CSCNT=$P(COUNT,U,7)
 .S EDAYS=$$FMDIFF^XLFDT(DT,$G(^TMP("RDATE",$J,PATIEN,0)))
 .S LASTUSER=$S($D(^XTMP("PSOERXLOCK",PATIEN)):$$GET1^DIQ(200,$P(^XTMP("PSOERXLOCK",PATIEN),U),.01,"E"),1:"")
 .S TOTAL=""
 .F B=1:1:6 D
 ..S VAR=$P(COUNT,U,B)
 ..S TOTAL=TOTAL+VAR
 .I TOTAL=0 Q
 .I TOTAL>999 S TOTAL=999
 .S EDAYS2=$S($L(EDAYS)=1:" "_EDAYS,1:EDAYS)
 .I $L(TOTAL)=1 S TOTAL="  "_TOTAL
 .I $L(TOTAL)=2 S TOTAL=" "_TOTAL
 .I NEW>99 S NEW=99
 .I $L(NEW)=1 S NEW=" "_NEW
 .I WAIT>99 S WAIT=99
 .I $L(WAIT)=1 S WAIT=" "_WAIT
 .I IPR>99 S IPR=99
 .I $L(IPR)=1 S IPR=" "_IPR
 .I HOLD>99 S HOLD=99
 .I $L(HOLD)=1 S HOLD=" "_HOLD
 .I CCR>99 S CCR=99
 .I $L(CCR)=1 S CCR="  "_CCR
 .I $L(CCR)=2 S CCR=" "_CCR
 .I OTH>99 S OTH=99
 .I $L(OTH)=1 S OTH="  "_OTH
 .I $L(OTH)=2 S OTH=" "_OTH
 .S CSPREFIX=$S($G(SORTBYCS):$S(CSCNT:"A",1:"B"),1:"Z")
 .I $G(SORTT)=1 S CSPREFIX=CSPREFIX_PNAME,DIRECT=1
 .I $G(SORTT)=2 S CSPREFIX=CSPREFIX_DOB,DIRECT=1
 .I '$G(SORTT)!($G(SORTT)=3) S CSPREFIX=CSPREFIX_(99999-EDAYS),DIRECT=1
 .S @GLOB@(CSPREFIX,PATIEN)=PNAME_U_DOB2_U_EDAYS2_U_LASTUSER_U_NEW_U_WAIT_U_IPR_U_HOLD_U_CCR_U_OTH_U_TOTAL_U_CSCNT
 I '$D(DIRECT) S DIRECT=-1
 S EDLOOP=""
 F  S EDLOOP=$O(@GLOB@(EDLOOP),DIRECT) Q:EDLOOP=""  D
 .S PATLOOP=""
 .F  S PATLOOP=$O(@GLOB@(EDLOOP,PATLOOP)) Q:PATLOOP=""  D
 ..S LINE=LINE+1,LINEVAR=""
 ..S PATINFO=$G(@GLOB@(EDLOOP,PATLOOP))
 ..S LINEVAR=$$SETFLD^VALM1(LINE_$S($P(PATINFO,U,12)>0:"]",1:"."),LINEVAR,"#")
 ..S LINEVAR=$$SETFLD^VALM1($P(PATINFO,U),LINEVAR,"ERX PATIENT")
 ..S LINEVAR=$$SETFLD^VALM1($P(PATINFO,U,2),LINEVAR,"DOB")
 ..S LINEVAR=$$SETFLD^VALM1($P(PATINFO,U,3),LINEVAR,"ED")
 ..S LINEVAR=$$SETFLD^VALM1($P(PATINFO,U,4),LINEVAR,"LOCKED BY")
 ..S LINEVAR=$$SETFLD^VALM1($P(PATINFO,U,5),LINEVAR,"NW")
 ..S LINEVAR=$$SETFLD^VALM1($P(PATINFO,U,6),LINEVAR,"WT")
 ..S LINEVAR=$$SETFLD^VALM1($P(PATINFO,U,7),LINEVAR,"IP")
 ..S LINEVAR=$$SETFLD^VALM1($P(PATINFO,U,8),LINEVAR,"HD")
 ..S LINEVAR=$$SETFLD^VALM1($P(PATINFO,U,9),LINEVAR,"CCR")
 ..S LINEVAR=$$SETFLD^VALM1($P(PATINFO,U,10),LINEVAR,"OTH")
 ..S LINEVAR=$$SETFLD^VALM1($P(PATINFO,U,11),LINEVAR,"TOT")
 ..D SET^VALM10(LINE,LINEVAR,PATLOOP)
 S VALMCNT=LINE
 K ^TMP("CENTRIC",$J),^TMP("RDATE",$J),^TMP("PSOERXC1",$J)
 Q
CENTSRCH ;
 N RES,SVAL,I,DONE,SRCHARY
 D FULL^VALM1
 S DONE=0
 S VALMBCK="R",PSOC1RE=1
 F I=1:1 D  Q:DONE
 .S RES=$$DIR(,I,.SRCHARY)
 .I '+RES S DONE=1 Q
 .S SRCHARY(+RES)=$P(RES,U,2,99)
 .I $D(SRCHARY(3)) S DONE=1 Q
 I '$D(SRCHARY) S VALMBCK="R" Q
 I $G(SRCHARY(3))]"" D  Q
 .I '$D(^PS(52.49,"B",SRCHARY(3))) W !,"eRx could not be found." D DIRE^PSOERXX1 S VALMBCK="R" Q
 .S ERXIEN=$O(^PS(52.49,"B",SRCHARY(3),0))
 .I ERXIEN,$$GET1^DIQ(52.49,ERXIEN,24.1,"I")'=PSNPINST W !!,"eRx does not belong to this division.",! D DIRE^PSOERXX1 S VALMBCK="R" Q
 .S PATIEN=$$GET1^DIQ(52.49,ERXIEN,.04,"I") Q:'PATIEN
 .S ERXLOCK=$$L^PSOERX1A(PATIEN,1)
 .I 'ERXLOCK S DIR(0)="E" D ^DIR K DIR S VALMBCK="R" Q
 .D EN^PSOERX1(ERXIEN)
 .D UL^PSOERX1A(PATIEN)
 .S VALMBCK="R"
 I $D(STYP) D EN(.SRCHARY,STYP) Q
 D EN(.SRCHARY)
 Q
CENTSORT ;
 N RES,STYP,SVAL
 D FULL^VALM1
 S VALMBCK="R",PSOC1RE=1
 S RES=$$DIR(1,0)
 I '+$P(RES,U) S VALMBCK="R" Q
 S STYP=$P(RES,U)
 I $D(SRCHARY) D EN(.SRCHARY,STYP) Q
 S SORTBYCS=$$ASKCSSORT()
 Q:SORTBYCS'?1N
 D EN(,STYP,PCVSTAT)
 Q
ASKCSSORT() ;
 Q:PSOCSERX'="B" 0
 S DIR(0)="Y"
 S DIR("B")="YES"
 W !!,"Do you want to group by controlled substance? ",!
 D ^DIR
 Q Y
SBN ;NOTES: KEEPS UNLOCKING REGARDLESS OF THE USER COMING BACK FROM AN ACTUAL LOCK. MAY NEED TO CONSIDER A TAG THAT DETERMINES WHETHER OR NOT TO
 ;GO TO THE LOCK IN THE FIRST PLACE, OR RE-WRITE THE ENTIRE SBN FUNCTIONS.
 N Y,ERXPAT,PATIEN,ERXLOCK,SRCH
 D FULL^VALM1
 S Y=+$P(XQORNOD(0),"=",2)
 I 'Y S VALMBCK="R" Q
 S PATIEN=$O(@VALMAR@("IDX",Y,"")) Q:'PATIEN
 S ERXLOCK=$$L^PSOERX1A(PATIEN,1)
 I 'ERXLOCK S DIR(0)="E" D ^DIR K DIR S VALMBCK="R" Q
 S SRCH(1)=PATIEN D EN^PSOERX(.SRCH,,1)
 D UL^PSOERX1A(PATIEN)
 S VALMBCK="R"
 K %
 Q
PATDATA ;
 I '$O(@VALMAR@("IDX",0)) S VALMSG="No records found!" S VALMBCK="" Q
 N DIR,Y,RESP,PATIEN,SRCH
 D FULL^VALM1
 S DIR(0)="N^"_VALMBG_":"_VALMLST_":0" D ^DIR
 I 'Y S VALMBCK="R" Q
 S RESP=Y
 S PATIEN=$O(@VALMAR@("IDX",RESP,"")) Q:'PATIEN 
 S ERXLOCK=$$L^PSOERX1A(PATIEN,1)
 I 'ERXLOCK S DIR(0)="E" D ^DIR K DIR S VALMBCK="R" Q
 S SRCH(1)=PATIEN D EN^PSOERX(.SRCH,,1)
 D UL^PSOERX1A(PATIEN)
 K %
 S VALMBCK="R"
 Q
DIR(SORT,CNT,SLIST) ;
 N DIR,Y,RLINE,STAG,SVAL
 K DIR
 S DIR(0)="SO^1:PATIENT NAME;2:DATE OF BIRTH"
 S DIR(0)=DIR(0)_";3:"_$S($G(SORT):"ELAPSED DAYS (ED)",1:"ERX REFERENCE NUMBER")
 I CNT<2 S DIR("L")="Select one of the following "_$S($G(SORT):"sort",1:"search")_" criteria:"
 I CNT>1 D
 .S DIR("L")=""
 .S DIR("L",11)="Select another search criteria or '^' to exit. Press enter to use the currently"
 .S DIR("L",12)="selected search criteria."
 S DIR("L",2)=""
 S DIR("L",3)=" "_$S($D(SLIST(1)):"*",1:"")_"1.) PATIENT NAME"
 S DIR("L",4)=" "_$S($D(SLIST(2)):"*",1:"")_"2.) DATE OF BIRTH"
 S DIR("L",5)=" "_$S($D(SLIST(3)):"*",1:"")_"3.) "
 S DIR("L",5)=DIR("L",5)_$S($G(SORT):"ELAPSED DAYS (ED)",1:"ERX REFERENCE NUMBER")
 S DIR("L",6)=""
 S DIR("L",7)=$S($D(SLIST):" * - indicates selected criteria.",1:"")
 D ^DIR K DIR Q:'Y 0
 S RES=Y I $G(SORT) Q RES
 S RLINE=$S(RES=1:"PAT",RES=2:"DOB",RES=3:"EREFNUM",1:"")
 I RLINE']"" Q 0
 S STAG=RLINE
 S SVAL=$$@STAG I SVAL="" Q 0
 Q RES_U_SVAL
PAT() ;
 N Y,DIC
 S DIC=52.46,DIC(0)="AEMQ" D ^DIC
 I Y<1 Q ""
 Q Y
DOB() ;
 N %DT,Y
 S %DT="A"
 S %DT("A")="Enter the Date of Birth (DOB): "
 D ^%DT
 I Y<1 Q ""
 Q Y
EREFNUM() ;
 N DIR,Y
 S DIR(0)="FO",DIR("A")="Enter the eRx Reference number" D ^DIR
 I Y=""!(Y="^") Q ""
 Q $$UP^XLFSTR(Y)
BLDITEM(ERXIEN,PATCNT,STAT) ;
 N PATIEN,DOB,ERXSTAT,ERXESTAT,ESCODE,MTYPE,DRGCSCH,ERXCSFLG
 I '$$CSFILTER^PSOERXUT(ERXIEN) Q
 S MTYPE=$$GET1^DIQ(52.49,ERXIEN,.08,"I")
 S ERXSTAT=$$GET1^DIQ(52.49,ERXIEN,1,"I")
 S ERXESTAT=$$GET1^DIQ(52.49,ERXIEN,1,"E")
 ; If the eRx is a new refill request and the status is refill request new, check for a response. 
 ; If no response within 14 days, change to RRE (refill request expired)
 I MTYPE="RR",ERXESTAT="RRN" D CHKEXP^PSOERX(ERXIEN,MTYPE)
 ; ChangeRequest messages will be checked for expiration status, but will not be displayed in the holding queue list view.
 I MTYPE="CR",ERXESTAT="CRN" D CHKEXP^PSOERX(ERXIEN,MTYPE)
 S ESCODE=","_$S($E(ERXESTAT)="H":$E(ERXESTAT),1:ERXESTAT)_","
 I ",RXI,RXR,RXE,RXW,RXN,RXD,RXF,CAO,CAR,CAH,CAP,CAX,CAF,CXD,CXN,CXV,CXY,CXE,CXI,CXW,N,I,W,H,"'[ESCODE Q
 I $G(STAT)]"" Q:'$$CHKSTAT(STAT,ERXESTAT,ERXSTAT)
 S PATIEN=$$GET1^DIQ(52.49,ERXIEN,.04,"I") Q:'PATIEN
 I $D(SRCH(1)),PATIEN'=$P($G(SRCH(1)),U) Q
 S DOB=$$GET1^DIQ(52.46,PATIEN,.08,"I")
 I $D(SRCH(2)),DOB'=$G(SRCH(2)) Q
 I $D(^TMP("CENTRIC",$J,PATIEN)) Q
 S ^TMP("CENTRIC",$J,PATIEN)="",PATCNT=$G(PATCNT)+1
 Q
CHKSTAT(FILSTAT,ERXSTAT,ERXISTAT) ;
 N RET,IWCHECK
 S RET=0
 I +$G(FILSTAT) S IWCHECK=$$GET1^DIQ(52.45,FILSTAT,.01,"E") ; checking user selected PCV filter for IP or WAIT status - both pass as numeric
 I $G(IWCHECK)="W" Q $S(",RXW,W,CXW,"'[(","_ERXSTAT_","):RET,1:1)
 I $G(IWCHECK)="I" Q $S(",RXI,I,CXI,"'[(","_ERXSTAT_","):RET,1:1)
 I $G(FILSTAT)="CCR" Q $S(",RXN,RXR,RXE,RXD,RXF,CAO,CAR,CAH,CAP,CAX,CAF,CXD,CXN,CXV,CXY,CXE,"'[(","_ERXSTAT_","):RET,1:1)
 I $G(FILSTAT)="AH" Q $S($E(ERXSTAT)'="H":RET,1:1)
 I $G(FILSTAT)'="A",FILSTAT'=ERXISTAT Q RET
 Q 1
EX ; early exit logic
 K PSOSRCH,PSOSRT,SRCH,SORTT,PSOPRMPT
 S PSOC1RE=1
 D EX^PSOORFI1
 Q
HELP ; -- help code
 S X="?" D DISP^XQORM1 W !!
 Q
 ;
EXIT ; -- exit code
 K PSOPRMPT,@VALMAR
 K CSPREFIX,SORTBYCS
 S PSOC1RE=1
 Q
 ;
EXPND ; -- expand code
 Q