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

PSOERX.m

Go to the documentation of this file.
PSOERX ;ALB/BWF - eRx Utilities/RPC's ; 8/3/2016 5:14pm
 ;;7.0;OUTPATIENT PHARMACY;**467,527,508,551,567,591,581,617,651**;DEC 1997;Build 30
 ;
EN(SRCH,SORTT,PCV) ; -- main entry point for PSO ERX HOLDING QUEUE
 N PSOREFSH
 D EN^VALM("PSO ERX HOLDING QUEUE")
 Q
 ;
HDR ; -- header code
 N PSOLBK
 S VALMHDR(1)="PSO ERX HOLDING QUEUE"
 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(PSOREFSH) K @VALMAR D INIT
 Q
 ;
INIT ; -- init variables and list array
 N LINE,LINEVAR,X,SGLOB,EF,ESIEN,CHKSTAT,EARY,SUBS,SUBS2,SVAL,SSTWO,EBDATE,ERXIEN,DTLOOP,PTLOOP,ERXDB,ERXDS,ERX,ERXDAT,P5246IEN,BDOVR,EEDATE
 N CNT
 S EF=52.49
 S SGLOB=$NA(^TMP("PSOERX",$J)) K @SGLOB
 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)=""
 ; initialize LINE
 I '$G(PSOPINST) Q
 F CHKSTAT="RJ","RM","PR","E" D
 .S ESIEN=$$PRESOLV^PSOERXA1(CHKSTAT,"ERX") Q:'ESIEN
 .S EARY(ESIEN)=""
 I $D(SRCH) D
 .I $D(SRCH(1)) S SUBS="EPAT",SVAL=$P(SRCH(1),U) Q
 .I $D(SRCH(4)) S SUBS="EPROV",SVAL=$P(SRCH(4),U) Q
 .I $D(SRCH(2)) S SUBS="F",SUBS2="DOB",SVAL=$P(SRCH(2),U) Q
 .I $D(SRCH(5)) S SUBS="F",SVAL=$P(SRCH(5),U) Q
 .I $D(SRCH(7)) S SUBS="MTYPE",SVAL=$P(SRCH(7),U) Q
 .S SUBS="F"
 I '$D(SRCH) S SUBS="F"
 S (LINE,CNT)=0
 ; Look back 90 days
 S EBDATE=$S($D(SRCH(3)):$P(SRCH(3),U),1:$$FMADD^XLFDT(DT,-90)),EEDATE=$S($D(SRCH(3)):$P(SRCH(3),U,2),1:DT_".9999")
 ; get lookback days override. Use it if we are not searching by date range.
 S BDOVR=$$GET1^DIQ(59,PSOSITE,10.2,"E")
 I $G(PCV) S BDOVR=365
 I BDOVR,'$D(SRCH(3)) S EBDATE=$$FMADD^XLFDT(DT,-BDOVR)
 F  S EBDATE=$O(^PS(52.49,SUBS,PSNPINST,EBDATE)) Q:'EBDATE!(EBDATE>EEDATE)!(CNT>998)  D
 .I $G(SUBS2)="DOB" D  Q
 ..S P5246IEN=0 F  S P5246IEN=$O(^PS(52.46,SUBS2,SVAL,P5246IEN)) Q:'P5246IEN!(CNT>998)  D
 ...S ERXIEN=0 F  S ERXIEN=$O(^PS(EF,"EPAT",PSNPINST,EBDATE,P5246IEN,ERXIEN)) Q:'ERXIEN!(CNT>998)  D
 ....D BLDITEM(ERXIEN,.CNT)
 .I $G(SVAL)]"" D  Q
 ..S ERXIEN=0 F  S ERXIEN=$O(^PS(EF,SUBS,PSNPINST,EBDATE,SVAL,ERXIEN)) Q:'ERXIEN!(CNT>998)  D
 ...I $D(PCV),$D(EARY($$GET1^DIQ(52.49,ERXIEN,1,"I"))) Q
 ...D BLDITEM(ERXIEN,.CNT)
 .S SSTWO=0 F  S SSTWO=$O(^PS(EF,SUBS,PSNPINST,EBDATE,SSTWO)) Q:'SSTWO!(CNT>998)  D
 ..; Filter out RJ, RM, and PR status erx's if we are not searching for a specific eRx status
 ..I '$D(SRCH(5)),$D(EARY(SSTWO)) Q
 ..; if we are coming from the patient centric view, block RM, RJ, and PR.
 ..I $D(SRCH),$D(PCV),$D(EARY(SSTWO)) Q
 ..S ERXIEN=0 F  S ERXIEN=$O(^PS(EF,SUBS,PSNPINST,EBDATE,SSTWO,ERXIEN)) Q:'ERXIEN!(CNT>998)  D
 ...D BLDITEM(ERXIEN,.CNT)
 S DTLOOP=0
 F  S DTLOOP=$O(@SGLOB@(DTLOOP)) Q:'DTLOOP  D
 .S PTLOOP=$S($G(SORTT)=3:0,1:"")
 .S PTLOOP="" F  S PTLOOP=$O(@SGLOB@(DTLOOP,PTLOOP),$S($G(SORTT)=3:-1,1:1)) Q:PTLOOP=""  D
 ..S ERXDB="" F  S ERXDB=$O(@SGLOB@(DTLOOP,PTLOOP,ERXDB)) Q:ERXDB=""  D
 ...S ERXDS="" F  S ERXDS=$O(@SGLOB@(DTLOOP,PTLOOP,ERXDB,ERXDS)) Q:ERXDS=""  D
 ....S ERX=0 F  S ERX=$O(@SGLOB@(DTLOOP,PTLOOP,ERXDB,ERXDS,ERX)) Q:'ERX  D
 .....S LINE=LINE+1,LINEVAR=""
 .....S ERXDAT=$G(@SGLOB@(DTLOOP,PTLOOP,ERXDB,ERXDS,ERX))
 .....S LINEVAR=$$SETFLD^VALM1(LINE_$S($$GET1^DIQ(52.49,ERX,95.1,"I"):"]",1:"."),LINEVAR,"#")
 .....S LINEVAR=$$SETFLD^VALM1($P(ERXDAT,U),LINEVAR,"PATIENT NAME")
 .....S LINEVAR=$$SETFLD^VALM1($P(ERXDAT,U,2),LINEVAR,"DOB")
 .....S LINEVAR=$$SETFLD^VALM1($P(ERXDAT,U,3),LINEVAR,"DRUG")
 .....S LINEVAR=$$SETFLD^VALM1($P(ERXDAT,U,4),LINEVAR,"PROVIDER")
 .....S LINEVAR=$$SETFLD^VALM1($P(ERXDAT,U,8),LINEVAR,"STA")
 .....S LINEVAR=$$SETFLD^VALM1($P(ERXDAT,U,7),LINEVAR,"RECORD DATE")
 .....D SET^VALM10(LINE,LINEVAR,ERX)
 I LINE=0 S LINE=LINE+1 D SET^VALM10(LINE,"No results for current query.")
 S VALMCNT=LINE
 K @SGLOB
 Q
BLDITEM(ERXIEN,CNT) ;
 N ERXIENS,ERXDAT,RXSTATN,MTYPE,RESTYPE,PATIEN,ERXQFLG,REQIEN,DELTA,FOUND,NMI,PATNM,NEWRX,PTDOBE,EXDS,EXPRIEN,EXPRNM
 N AUTOST,MANST,ERXSTAT,ERXISTAT,ERXDT,ERXEDT,PTDOB,CSPREFIX,CSERX
 ; Controlled Substance Prompts Filter
 I '$$CSFILTER^PSOERXUT(ERXIEN) Q 
 S ERXIENS=ERXIEN_","
 K ERXDAT D GETS^DIQ(52.49,ERXIENS,".03;.04;.08;1;4.9;3.1;2.1;1;1.2;1.3;52.1;95.1","IE","ERXDAT")
 S RXSTATN=$G(ERXDAT(EF,ERXIENS,1,"E"))
 S MTYPE=$G(ERXDAT(EF,ERXIENS,.08,"I"))
 S RESTYPE=$G(ERXDAT(EF,ERXIENS,52.1,"E"))
 S CSERX=$G(ERXDAT(EF,ERXIENS,95.1,"I"))
 I '$D(SRCH(5)),'$D(SRCH(7)),((RXSTATN="CAN")!(RXSTATN="ICA")!(RXSTATN="CNP")!(RXSTATN="CRP")!(RXSTATN="CRC")!(RXSTATN="CXP")!(RXSTATN="CXC")) Q
 I '$D(SRCH(5)),'$D(SRCH(7)),((RXSTATN="CAA")!(RXSTATN="CNE")!(RXSTATN="CRN")!(RXSTATN="CRR")!(RXSTATN="CRX")!(RXSTATN="CXA")!(RXSTATN="CXQ")) Q
 I '$D(SRCH(5)),'$D(SRCH(7)),(RXSTATN="CRE"),(MTYPE="CR") Q
 ; 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)
 ; ChangeRequest messages will be checked for expiration status, but will not be displayed in the holding queue list view.
 I MTYPE="RR",RXSTATN="RRN" D CHKEXP(ERXIEN,MTYPE)
 I MTYPE="CR",RXSTATN="CRN" D CHKEXP(ERXIEN,MTYPE)
 S PATIEN=$G(ERXDAT(EF,ERXIENS,.04,"I")) I 'PATIEN S PATIEN=$$GETPAT^PSOERXU5(ERXIEN)
 I $D(SRCH(1)),PATIEN'=$P($G(SRCH(1)),U) Q
 S PTDOB=$$GET1^DIQ(52.46,PATIEN,.08,"I")
 I $D(SRCH(2)),PTDOB'=$G(SRCH(2)) Q
 I '$D(SRCH)!($G(PCV)),MTYPE="IE",(RXSTATN'="RRE"),(RXSTATN'="CRE") Q 
 I '$D(SRCH)!($G(PCV)),MTYPE="RR" Q
 ; if this is not a search, is a refill response, and is a response type of 'approved', do not show in the holding queue.
 I '$D(SRCH(7)),'$D(SRCH(5))!($G(PCV)),MTYPE="RE",RESTYPE="A" Q
 ; do not display refill response with 'approved with changes' status in the holding queue.
 S ERXQFLG=0
 I '$D(SRCH)!($G(PCV)),MTYPE="RE","RXP,RXC,RXA,RRP,"[RXSTATN Q
 I '$D(SRCH)!($G(PCV)),MTYPE="RE",RESTYPE="AWC" D  Q:ERXQFLG
 .S REQIEN=$$GETREQ^PSOERXU2(ERXIEN) I 'REQIEN Q
 .D RRDELTA^PSOERXU2(.DELTA,REQIEN,ERXIEN)
 .I $D(DELTA(52.49,"EXTERNAL PROVIDER")) Q
 .S ERXQFLG=1
 I $D(SRCH(7)),MTYPE="" Q
 N FOUND,NMI
 S FOUND=0
 I $D(SRCH(7)) D  Q:'FOUND
 .F NMI=1:1 D  Q:$P(SRCH(7),U,NMI)=""!(FOUND)
 ..I $P(SRCH(7),U,NMI)=MTYPE S FOUND=1 Q
 ; patient name/dob
 S PATNM=$$GET1^DIQ(52.46,PATIEN,.01,"E") I MTYPE="IE"!(MTYPE="OE") S PATNM=$$GET1^DIQ(52.49,ERXIEN,.08,"E")
 I '$L(PATNM) D
 .S NEWRX=$$RESOLV^PSOERXU2(ERXIEN)
 .I NEWRX S PATNM=$$GET1^DIQ(52.49,ERXIEN,.04,"E")
 .I '$L(PATNM) S PATNM=$$GET1^DIQ(52.49,ERXIEN,.08,"E")
 .S PATNM="N/A"
 S PTDOBE=""
 I PTDOB]"" S PTDOBE=$$FMTE^XLFDT(PTDOB,"2D")
 I '$L(PTDOB) S (PTDOB,PTDOBE)="N/A"
 ; external drug/supply
 S EXDS=$G(ERXDAT(EF,ERXIENS,3.1,"E")) I '$L(EXDS) S EXDS=$$GETDRUG^PSOERXU5(ERXIEN) I '$L(EXDS) S EXDS="N/A"
 I $D(SRCH(6)),EXDS'[$P($G(SRCH(6)),U) Q
 ; external provider ien and name
 S EXPRIEN=$G(ERXDAT(EF,ERXIENS,2.1,"I")) I 'EXPRIEN S EXPRIEN=$$GETPROV^PSOERXU5(ERXIEN)
 I $D(SRCH(4)),EXPRIEN'=$P($G(SRCH(4)),U,1) Q
 ; if there is no external provider, quit - FUTURE ENHANCEMENT - may need to find a way to log, view, and deal with these instances.
 ; PSO*7*508 - if there is no provider, set it to 'UNKNOWN', and do not quit (may use N/A instead)
 S EXPRNM=$$GET1^DIQ(52.48,EXPRIEN,.01,"E") I '$L(EXPRNM) S EXPRNM="N/A"
 ; auto and manual validation status
 S AUTOST=$G(ERXDAT(EF,ERXIENS,1.2,"E"))
 S MANST=$G(ERXDAT(EF,ERXIENS,1.3,"E"))
 S ERXSTAT=$G(ERXDAT(EF,ERXIENS,1,"E"))
 S ERXISTAT=$G(ERXDAT(EF,ERXIENS,1,"I"))
 I $D(SRCH(5)),ERXSTAT'=$P(SRCH(5),U,2) Q
 ; date ERX was received
 S ERXDT=$G(ERXDAT(EF,ERXIENS,.03,"I")),ERXEDT=$$FMTE^XLFDT($P(ERXDT,"."),"2D")
 S CNT=CNT+1
 S CSPREFIX=$S($G(SORTBYCS,1):$S(CSERX:"A",1:"B"),1:"Z")
 I $G(SORTT) D  Q
 .I SORTT=1 S @SGLOB@(1,CSPREFIX_PATNM,ERXDT-9999999,EXPRNM,ERXIEN)=PATNM_U_PTDOBE_U_EXDS_U_EXPRNM_U_AUTOST_U_MANST_U_ERXEDT_U_ERXSTAT
 .I SORTT=2 S @SGLOB@(1,CSPREFIX_PTDOB,ERXDT-9999999,PATNM,ERXIEN)=PATNM_U_PTDOBE_U_EXDS_U_EXPRNM_U_AUTOST_U_MANST_U_ERXEDT_U_ERXSTAT
 .I SORTT=3 D
 ..S CSPREFIX=$S($G(SORTBYCS,1):$S(CSERX:"B",1:"A"),1:"Z")
 ..S @SGLOB@(1,CSPREFIX_$J(ERXDT-9999999,15,6),PATNM,EXPRNM,ERXIEN)=PATNM_U_PTDOBE_U_EXDS_U_EXPRNM_U_AUTOST_U_MANST_U_ERXEDT_U_ERXSTAT
 .I SORTT=4 S @SGLOB@(1,CSPREFIX_EXPRNM,ERXDT,PATNM,ERXIEN)=PATNM_U_PTDOBE_U_EXDS_U_EXPRNM_U_AUTOST_U_MANST_U_ERXEDT_U_ERXSTAT
 .I SORTT=5 S @SGLOB@(1,CSPREFIX_ERXSTAT,PATNM,ERXDT-9999999,ERXIEN)=PATNM_U_PTDOBE_U_EXDS_U_EXPRNM_U_AUTOST_U_MANST_U_ERXEDT_U_ERXSTAT
 .I SORTT=6 S @SGLOB@(1,CSPREFIX_EXDS,PATNM,ERXDT-9999999,ERXIEN)=PATNM_U_PTDOBE_U_EXDS_U_EXPRNM_U_AUTOST_U_MANST_U_ERXEDT_U_ERXSTAT
 .I SORTT=7 D
 ..; MTYPE was not defined for 'newrx's from the first release. The post-init converts 
 ..; all rx's to a newRx type
 ..I MTYPE="" S MTYPE="UNK"
 ..S @SGLOB@(1,CSPREFIX_MTYPE,ERXDT-9999999,PATNM,ERXIEN)=PATNM_U_PTDOBE_U_EXDS_U_EXPRNM_U_AUTOST_U_MANST_U_ERXEDT_U_ERXSTAT
 I $D(SRCH(7)) S @SGLOB@(9999999-ERXDT,PATNM,PTDOB,EXDS,ERXIEN)=PATNM_U_PTDOBE_U_EXDS_U_EXPRNM_U_AUTOST_U_MANST_U_ERXEDT_U_ERXSTAT Q
 S @SGLOB@(ERXDT,PATNM,PTDOB,EXDS,ERXIEN)=PATNM_U_PTDOBE_U_EXDS_U_EXPRNM_U_AUTOST_U_MANST_U_ERXEDT_U_ERXSTAT
 Q
 ;
HELP ; -- help code
 S X="?" D DISP^XQORM1 W !!
 Q
 ;
EXIT ; -- exit code
 K PSOSRCH(VALMEVL),PSOSRT(VALMEVL),@VALMAR,PSOREFSH
 ;Kill all the new variables I created. ZRF
 I VALMEVL=0 K PSOSRCH,PSOSRT
 ; instruct centric view to refresh
 I $D(PCV) S VALMBCK="R" S PSOC1RE=1 D FULL^VALM1
 K CSPREFIX,SORTBYCS
 Q
 ;
EX ; early exit logic
 K PSOSRCH,PSOSRT,SRCH,SORTT
 D EX^PSOORFI1
 Q
EXPND ; -- expand code
 Q
 ;
 ; search list and display results
 N RES,SVAL,I,DONE,SRCHARY,ERXIEN,ERXLOCK
 D FULL^VALM1
 S DONE=0
 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(8)) S DONE=1 Q
 I '$D(SRCHARY) S VALMBCK="R" Q
 I $G(SRCHARY(8))]"" D  Q
 .I '$D(^PS(52.49,"B",SRCHARY(8))) W !,"eRx could not be found." D DIRE^PSOERXX1 S VALMBCK="R" Q
 .S ERXIEN=$O(^PS(52.49,"B",SRCHARY(8),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)
 S VALMBCK="R"
 Q
 ; sort target list
SORT ;
 N RES,STYP,SVAL
 D FULL^VALM1
 S RES=$$DIR(1,0)
 K DIR
 I '+$P(RES,U) Q
 S STYP=$P(RES,U)
 S SORTBYCS=$$ASKCSSORT^PSOERXC1()
 Q:SORTBYCS'?1N
 I $D(SRCHARY) D EN(.SRCHARY,STYP) Q
 I $D(SRCH) D EN(.SRCH,STYP,1) Q
 D EN(,STYP)
 Q
DIR(SORT,CNT,SLIST) ;
 N DIR,Y,RLINE,STAG,SVAL
 K DIR
 S DIR(0)="SO^1:PATIENT NAME;2:DATE OF BIRTH;3:RECEIVED DATE RANGE;4:PROVIDER NAME;5:ERX STATUS;6:DRUG NAME;7:MESSAGE TYPE"
 I '$D(SORT) S DIR(0)=DIR(0)_";8: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",13)="Select another search criteria or '^' to exit. Press enter to use the currently"
 .S DIR("L",14)="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.) RECEIVED DATE"_$S('$G(SORT):" RANGE",1:"")
 S DIR("L",6)=" "_$S($D(SLIST(4)):"*",1:"")_"4.) PROVIDER NAME"
 S DIR("L",7)=" "_$S($D(SLIST(5)):"*",1:"")_"5.) ERX STATUS"
 S DIR("L",8)=" "_$S($D(SLIST(6)):"*",1:"")_"6.) DRUG NAME"
 S DIR("L",9)=" "_$S($D(SLIST(7)):"*",1:"")_"7.) MESSAGE TYPE"
 I '$D(SORT) S DIR("L",10)=" "_$S($D(SLIST(8)):"*",1:"")_"8.) ERX REFERENCE NUMBER"
 S DIR("L",11)=""
 S DIR("L",12)=$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:"RDT",RES=4:"PRVNM",RES=5:"ESTAT",RES=6:"DNAME",RES=7:"MTYPE",RES=8:"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
RDT() ;
 N BDATE,EDATE,%DT,Y
 S %DT="A"
 S %DT("A")="Enter the beginning date: "
 D ^%DT
 I Y<0 Q ""
 S BDATE=Y K Y,%DT
 S %DT="A"
 S %DT("A")="Enter the ending date: "
 S %DT("B")="T"
 D ^%DT
 I Y<0 Q ""
 S EDATE=Y_".999999"
 Q BDATE_U_EDATE
PRVNM() ;
 N Y,DIC
 S DIC("A")="Select PROVIDER: "
 S DIC=52.48,DIC(0)="AEQ" D ^DIC
 I Y<1 Q ""
 Q Y
ESTAT() ;
 ; prompt for erx status
 N Y,DIC
 S DIC("A")="Select eRx Status: "
 S DIC=52.45,DIC(0)="AEQ",DIC("S")="I $D(^PS(52.45,""TYPE"",""ERX"",Y))" D ^DIC
 I Y<1 Q ""
 Q Y
DNAME() ;
 N DIR,Y
 S DIR(0)="FO"
 S DIR("A")="Enter the name or partial name of the incoming eRx drug"
 D ^DIR
 I Y=""!(Y="^") Q ""
 Q $$UP^XLFSTR(Y)
MTYPE() ;
 N DIR,Y
 S DIR(0)="52.49,.08",DIR("A")="Select message type" D ^DIR
 I Y=""!(Y="^") Q ""
 Q Y
MTYPE2 ;
 N DIR,Y,DONE,SEL,SRCHARY,SORTT,SRCH,PSOSRCH,PSOSRT
 S VALMBCK="R"
 D FULL^VALM1
 S DIR(0)="52.49,.08",DIR("A")="Select message type" D ^DIR
 I Y=""!(Y="^") Q
 S SRCHARY(7)=Y D EN(.SRCHARY)
 Q
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)
CHKKEY(DUZ) ;
 I $D(^XUSEC("PSDRPH",DUZ))!($D(^XUSEC("PSO ERX ADV TECH",DUZ)))!($D(^XUSEC("PSO ERX TECH",DUZ)))!($D(^XUSEC("PSO ERX VIEW",DUZ))) Q 1
 Q 0
CHKEXP(IEN,MTYPE) ;
 N MSGDT,RELMSG,RELMSGT,FOUND,NMSTAT
 S FOUND=0
 S MSGDT=$$GET1^DIQ(52.49,IEN,.03,"I")
 S RELMSG=0 F  S RELMSG=$O(^PS(52.49,IEN,201,"B",RELMSG)) Q:'RELMSG  D
 .S RELMSGT=$$GET1^DIQ(52.49,IEN,.08,"I")
 .I $G(MTYPE)="CR",RELMSGT="CX" S FOUND=1 Q
 .I RELMSGT="RE" S FOUND=1
 Q:FOUND
 S NMSTAT=$S(MTYPE="RR":"RRX",MTYPE="CR":"CRX")
 I $$FMDIFF^XLFDT(DT,MSGDT)>14 D UPDSTAT^PSOERXU1(IEN,NMSTAT)
 Q