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

PSOERXU8.m

Go to the documentation of this file.
PSOERXU8 ;ALB/BLB - eRx Utilities/RPC's ; 08/18/2020 10:02am
 ;;7.0;OUTPATIENT PHARMACY;**581,617,700,743,746**;DEC 1997;Build 106
 ;
 ;  Reference to ^XTV(8991.9) in ICR #7002
 ;  Reference to ^VA(200 supported by ICR #10060
 Q
BPROC(PSOIEN,BTYPE,MVFLD,VBFLD,VBDTTMF,VDTTM) ;
 N MBMSITE,ERXPAT,ERXSTAT,ERESTAT,ERXDT,ERXIEN,ERXARY,DIR,Y,L,LINE,CNT,EHID,EDRUG,EPROV,EPAT,ERXRDT,ERXRECDT,ERXEDT,I,FLG
 N REXEDT,EEPROV,ERXPROV,EXARY,MTYPE,RESTYPE,CSMSG,ERXID
 S MBMSITE=$S($$GET1^DIQ(59.7,1,102,"I")="MBM":1,1:0)
 S MTYPE=$$GET1^DIQ(52.49,PSOIEN,.08,"I")
 S RESTYPE=$$GET1^DIQ(52.49,PSOIEN,52.1,"I")
 I MTYPE="CX" Q
 I MTYPE="RE",RESTYPE="R" Q
 S ERXPAT=$$GET1^DIQ(52.49,PSOIEN,.04,"I") Q:'ERXPAT
 S ERXPROV=$$GET1^DIQ(52.49,PSOIEN,2.1,"I")
 S ERXRECDT=$P($$GET1^DIQ(52.49,PSOIEN,.03,"I"),".")
 S ERXEDT=ERXRECDT_".2359"
 S ERXDT=ERXRECDT-.0001
 F  S ERXDT=$O(^PS(52.49,"PAT2",ERXPAT,ERXDT)) Q:ERXDT>ERXEDT!(ERXDT="")  D
 . S ERXIEN=0 F  S ERXIEN=$O(^PS(52.49,"PAT2",ERXPAT,ERXDT,ERXIEN)) Q:'ERXIEN  D
 . . I '$G(MBMSITE),$$GET1^DIQ(52.49,ERXIEN,24.1,"I")'=PSNPINST Q
 . . S ERESTAT=$$GET1^DIQ(52.49,ERXIEN,1)
 . . I (",PR,RM,RJ,CAN,CXQ,"[(","_ERESTAT_","))!(",E,"[(","_$E(ERESTAT)_",")) Q
 . . ; do not process any rx's that are not a 'newRx'.
 . . I $$GET1^DIQ(52.49,ERXIEN,.08,"I")'="N" Q
 . . ; eRx Provider already validated
 . . I BTYPE="PR",$$GET1^DIQ(52.49,ERXIEN,1.8,"I") Q
 . . Q:PSOIEN=ERXIEN
 . . I BTYPE="PR",$$GET1^DIQ(52.49,ERXIEN,2.1,"I")'=ERXPROV Q
 . . S EXARY(ERXIEN)=""
 I '$O(EXARY(0)) Q
 W !!
 I BTYPE="PA" D
 . W !,"This patient has other prescriptions for: "_$$FMTE^XLFDT(ERXRECDT)
 . W !,"Patient: "_$$GET1^DIQ(52.46,ERXPAT,.01,"E")
 I BTYPE="PR" D
 . W !,"There are other prescriptions for this patient, written by this provider on"
 . W !,$$FMTE^XLFDT(ERXRECDT)
 . W !,"Provider: "_$$GET1^DIQ(52.48,ERXPROV,.01,"E")
 . W !,"Patient: "_$$GET1^DIQ(52.46,ERXPAT,.01,"E")
 W !!,?4,"DRUG",?42,"PROVIDER",?67,"STA",?71,"REC DATE"     ;P700 Adding Status
 S $P(LINE,"-",80)="" W !,LINE
 S L=0,CNT=0 F  S L=$O(EXARY(L)) Q:'L  D
 . S CNT=CNT+1
 . S EHID=$$GET1^DIQ(52.49,L,.01,"E")
 . S EDRUG=$$GET1^DIQ(52.49,L,3.1,"E")
 . S EEPROV=$$GET1^DIQ(52.49,L,2.1,"I")
 . S EPROV=$$GET1^DIQ(52.48,EEPROV,.01,"E")
 . S EPAT=$$GET1^DIQ(52.46,ERXPAT,.01,"E")
 . S ERXRDT=$P($$GET1^DIQ(52.49,L,.03,"I"),".")     ;P700
 . W !,CNT_".) "_$E(EDRUG,1,37),?42,$E(EPROV,1,24),?67,$E(RXSTAT,1,3),?71,$$FMTE^XLFDT(ERXRDT,"2Z")     ;P700
 W !!,"Would you like to apply the above validation to these prescriptions?"
 K Y S DIR(0)="YO"
 S DIR("B")="N" D ^DIR K DIR
 I Y="^"!(Y=0) Q
 S (CNT,CSMSG,ERXID)=0
 F  S ERXID=$O(EXARY(ERXID)) Q:'ERXID  D
 . S CNT=$G(CNT)+1
 . I $$GET1^DIQ(52.49,ERXID,95.1,"I") D
 . . I BTYPE="PA",'$$VALPTADD^PSOERXUT(+$$GET1^DIQ(52.49,PSOIEN,.05,"I")) D
 . . . W !,CNT,". ERX#: ",$$GET1^DIQ(52.49,ERXID,.01),"    ERX DRUG: ",$$GET1^DIQ(52.49,ERXID,3.1)
 . . . W !,"Unable to validate - VistA Patient does not have a current mailing",!,"or residential address on file.",!
 . . . K EXARY(ERXID) S CSMSG=1
 . . I BTYPE="PR" D
 . . . K ERXMSG D PRDRVAL^PSOERXUT(.ERXMSG,"VP",ERXID,$$GET1^DIQ(52.49,PSOIEN,2.3,"I"))
 . . . I +ERXMSG!($P(ERXMSG,"^",2)="W") Q
 . . . W !,CNT,". ERX#: ",$$GET1^DIQ(52.49,ERXID,.01),"    ERX DRUG: ",$$GET1^DIQ(52.49,ERXID,3.1)
 . . . S I=0 F  S I=$O(ERXMSG(I)) Q:'I  D
 . . . . W !,"Unable to validate - ",$P(ERXMSG(I),"^"),! K EXARY(ERXID) S CSMSG=1
 . I '$O(EXARY(ERXID)),$G(CSMSG) S DIR(0)="E" D ^DIR
 S I=0 F  S I=$O(EXARY(I)) Q:'I  D
 . I BTYPE="PA" S FDA(52.49,I_",",.05)=$$GET1^DIQ(52.49,PSOIEN,.05,"I")
 . I BTYPE="PR" S FDA(52.49,I_",",2.3)=$$GET1^DIQ(52.49,PSOIEN,2.3,"I")
 . S FDA(52.49,I_",",MVFLD)=1,FDA(52.49,I_",",VBFLD)=$G(DUZ),FDA(52.49,I_",",VBDTTMF)=VDTTM
 . D FILE^DIE(,"FDA") K FDA
 . I $$GET1^DIQ(52.49,I,1,"E")="N" D UPDSTAT^PSOERXU1(I,"I")
 . I $$GET1^DIQ(52.49,I,1.3,"I"),$$GET1^DIQ(52.49,I,1.5,"I"),$$GET1^DIQ(52.49,I,1.7,"I") D
 . . D UPDSTAT^PSOERXU1(I,"W")
 Q
 ;
VADEA(NPIEN,ERXIEN) ; Get Provider's VA DEA Matching DEATXT if possible. If no match, get default USER FOR INPATIENT DEA#.
 N ERXPROV,ERXPRDEA,RXWRDATE,VADEASUF,RXDEADT,VADEA,VADEADSP
 Q:'$G(ERXIEN) ""
 Q:'$D(^PS(52.49,ERXIEN,0)) ""
 Q:'$G(NPIEN) ""
 S ERXPROV=$$GET1^DIQ(52.49,ERXIEN,2.1,"I")             ; eRx Provider IEN
 S ERXPRDEA=$$UP^XLFSTR($$GET1^DIQ(52.48,ERXPROV,1.6))  ; eRx Provider DEA#
 S RXWRDATE=$$GET1^DIQ(52.49,ERXIEN,5.9,"I")            ; eRx Written Date
 S RXDEADT=$$FMADD^XLFDT(RXWRDATE,-3650)
 ;
 S VADEA=$$UP^XLFSTR($$DEA^XUSER(0,NPIEN,RXDEADT,$P(ERXPRDEA,"-"))),VADEADSP=$P(VADEA,"^")
 I VADEA="" S VADEA=$$PRDEA^XUPSPRA(NPIEN),VADEADSP=VADEA
 I VADEA="",$O(^VA(200,NPIEN,"PS4",0)) D
 . N DEACNT,DEAVAIEN,DEAXUIEN,DEAXTV S DEAVAIEN=0 F DEACNT=0:1 S DEAVAIEN=$O(^VA(200,NPIEN,"PS4",DEAVAIEN)) Q:'DEAVAIEN  D
 . . S DEAXUIEN=$P(^VA(200,NPIEN,"PS4",DEAVAIEN,0),"^",3),VADEADSP=$P(^VA(200,NPIEN,"PS4",DEAVAIEN,0),"^")
 . . I DEAXUIEN,$D(^XTV(8991.9,DEAXUIEN,0)),(VADEADSP=$P(^XTV(8991.9,DEAXUIEN,0),"^")) S VADEA=VADEADSP
 I $L(VADEADSP)>8 D
 . S VADEASUF=$$VADEASUF(VADEADSP,NPIEN) Q:VADEASUF=""
 . S VADEA=$P(VADEA,"-")_"-"_VADEASUF,VADEADSP=VADEA
 Q VADEA_"^"_VADEADSP
 ;
VADEASUF(DEATXT,NPIEN) ; Get Provider's VA DEA Suffix
 N NPDEAIEN,IENS,DNDEAIEN
 K DEASUFF S DEASUFF=""
 S DNDEAIEN=$$FIND1^DIC(8991.9,,,DEATXT) Q:'DNDEAIEN ""
 Q:$$GET1^DIQ(8991.9,DNDEAIEN,.07,"I")'=1 ""
 S NPDEAIEN=$$FIND1^DIC(200.5321,","_NPIEN_",",,DEATXT)
 S IENS=NPDEAIEN_","_NPIEN_","
 S DEASUFF=$$GET1^DIQ(200.5321,IENS,.02,"E")
 Q DEASUFF
 ;
DEAFOUND(DEATXT,NPIEN) ; Is DEA=DEATXT found on profile=NPIEN profile in ^VA(200,NPIEN,"PS4"?
 I '$L($G(DEATXT))!'$G(NPIEN)!'$D(^VA(200,+$G(NPIEN),"PS4")) Q 0
 Q $D(^VA(200,NPIEN,"PS4","B",$P(DEATXT,"-")))
 ;
ERXSIG(ERXIEN) ; Returns the eRx SIG
 ; Input: (r) ERXIEN - Pointer to ERX HOLDING QUEUE File (#52.49)
 ;Output:     ERXSIG - eRx SIG in one string
 ;
 N ERXSIG,SIG,I,S2017,MSGTYPE,RESTYPE,MEDIEN
 S ERXSIG=""
 I '$D(^PS(52.49,+$G(ERXIEN),0)) Q ERXSIG
 S S2017=+$G(^PS(52.49,ERXIEN,312))
 S MSGTYPE=$P($G(^PS(52.49,ERXIEN,0)),"^",8)
 S RESTYPE=$P($G(^PS(52.49,ERXIEN,52)),"^")
 I S2017 D
 . I MSGTYPE="CX" S MEDIEN=$O(^PS(52.49,ERXIEN,311,"C","P",0))
 . I MSGTYPE="RE",(RESTYPE="R") S MEDIEN=$O(^PS(52.49,ERXIEN,311,"C","MR",0))
 . I MSGTYPE="N"!'$G(MEDIEN) S MEDIEN=$O(^PS(52.49,ERXIEN,311,0))
 . I '$G(MEDIEN) Q
 . F I=1:1 Q:'$D(^PS(52.49,ERXIEN,311,MEDIEN,8,I))  D
 . . S ERXSIG=ERXSIG_$G(^PS(52.49,ERXIEN,311,MEDIEN,8,I,0))_" "
 . S $E(ERXSIG,$L(ERXSIG))=""
 I 'S2017 D
 . S ERXSIG=$P($G(^PS(52.49,ERXIEN,7)),"^")
 Q ERXSIG
 ;
VISTASIG(ERXIEN) ; Returns the VistA SIG, if present
 ; Input: (r) ERXIEN   - Pointer to ERX HOLDING QUEUE File (#52.49)
 ;Output:     VISTASIG - VistA SIG in one string
 ;
 N VISTASIG,SIG
 S VISTASIG=""
 S SIG=0 F  S SIG=$O(^PS(52.49,ERXIEN,"SIG",SIG)) Q:'SIG  D
 . S VISTASIG=VISTASIG_$G(^PS(52.49,ERXIEN,"SIG",SIG,0))
 ; VA Patient Instructions
 I $$GET1^DIQ(52.49,ERXIEN,27)'="" D
 . S VISTASIG=VISTASIG_$S($E(VISTASIG,$L(VISTASIG))=" ":"",1:" ")_$$GET1^DIQ(52.49,ERXIEN,27)
 Q VISTASIG
 ;
RENEWALS(ERXIEN) ; Returns whether Renewals are Prohibited or no
 ; Input: ERXIEN   - Pointer to ERX HOLDING QUEUE File (#52.49)
 ;Output: RENEWALS - 1: Renewals are Allowed | 0 - Renewals are Prohibited
 N RENEWALS,MTYPE,CHGMESRQ,CHGMESRI,RESPVAL
 S RENEWALS=0,MTYPE=$$GET1^DIQ(52.49,ERXIEN,.08,"I")
 S CHGMESRQ=$$GET1^DIQ(52.49,ERXIEN,315.1,"I")
 S CHGMESRI=$$GET1^DIQ(52.45,CHGMESRQ,.01,"I")
 S RESPVAL=$$GET1^DIQ(52.49,ERXIEN,52.1,"E")
 I MTYPE="N"!((MTYPE="CX")&($$PROHIBIT^PSOERX1D(RESPVAL,CHGMESRI))) D
 . S RENEWALS=$S($$GET1^DIQ(52.49,ERXIEN,301.3,"I"):0,1:1)
 Q RENEWALS
 ;
SUFCHK(RESULT,ERXPRDEA,VADEADFL,ERXSUFF) ; Check for matching DEA, mismatched suffix
 I ERXPRDEA'="",($L(VADEADFL)>8),(ERXPRDEA'=VADEADFL),($P(ERXPRDEA,"-")=$P(VADEADFL,"-")),'$G(ERXSUFF) D  ; PSO*7*743
 . D SUFFWARN^PSOERXUT(.RESULT,ERXPRDEA,$S($L($G(VADEADFL)>8):VADEADFL,1:VADEANUM),0)
 . S RESULT=$S($G(RESULT)="0^B":RESULT,1:"0^W")
 Q