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

PSOERSE4.m

Go to the documentation of this file.
PSOERSE4 ;ALB/RM - PSO ERX UTILITY ROUTINE ;Jan 23, 2023@12:43:34
 ;;7.0;OUTPATIENT PHARMACY;**746**;DEC 16, 1997;Build 106
 ;
 ;
 Q  ;No Direct Call
 ;
BUILDLST(TMPGBL,ERXIEN,PNCOMM) ;
 ;Input : TMPGBL - The temporary global location to store the eRx data
 ;                 Example: ^TMP("TIUP",$J)
 ;        ERXIEN - Pointer to ERX HOLDING QUEUE file (#52.49) 
 ;        PNCOMM - Patient Progress Note Comment.
 ;                 Example. This is a sample eRx patient Progress Note.
 ;Output: Create/Build the eRx temporary global
 Q:'$G(ERXIEN)
 N PATIEN,PHARMIEN,PRVIEN,PHDAT,PATDAT,SUPDAT,PRVDAT,LINE,PRVLNM,PRVMI,PRVFN,EPAT,EPATDOB,VPATIEN,HARY,HL,PROHIBIT,ERXWRDT
 N VPATNM,VPATDOB,EPRVIEN,EPRVNM,EPRVNPI,EPRVDEA,VAPRVIEN,VAPRVNM,VAPRVNPI,VAPRVDEA,SUPIEN,ERXDRUG,ERXQTY,ERXFLS,CSCOMM,MEDIEN
 N ERXDS,ERXDT,VADRGIEN,VADRG,LINETXT,ERXCOMM,ERXRFLS,PATIENS,VAHREA,VAQTY,VAREF,VASIG,PATDAT,CURSTATE,CURSTATI,WDATE,RRNRXIEN
 N LHFOUND,LHMATCH,LHSTATI,VAPDEAEX,ERXCOMM,COMFRST,COMARY,SIGDATA,SIGLOOP,SFIRSPROT,SGLOOP,SIGARY,VADAYS,NRXIEN,ERXPNC,ERXPNARY,PNLOOP
 N SLOOP,VASIG,VASARY,FSSIG,VAHSTA,EDIRECT,VAHPER,PAMANVAL,DRMANVAL,PRMANVAL,VPATINST,VAPIARY,VLOOP,FSVPIN,S2017,NEWRXIEN
 N DRGARY,DLP,MTYPE,MTYPEE,ERXSTAT,STATIEN,PDIAGTXT,SDIAGTXT,RELIEN,RELMTYPE,ERRIEN,LERXSTAT,LOPSTAT,OPIEN,ERXDSUB,COM,EXSTATUS,R2017,REQIEN
 N SFIRST,PATPT,EPRVPT,CIEN,CHGMESRI,CHGMESRQ,NO311,RESPVAL,ERRFLG,PSNF,ERXPNAME,ERXRFNUM,LINE,HTWT,DDASH
 ;
 K @TMPGBL ;This variable needs to be new'ed in the calling routine
 S LINE=0 ;LINE here serves as the counter
 S ERXPNAME=$$GET1^DIQ(52.49,ERXIEN,.04,"E")
 S ERXRFNUM=$$GET1^DIQ(52.49,ERXIEN,.01,"E")
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="eRx Patient: "_ERXPNAME
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="eRx Reference #: "_ERXRFNUM
 S HTWT=$$BHW^PSOERXIU(ERXIEN)
 S LINE=LINE+1 S @TMPGBL@(LINE,0)=HTWT
 S LINE=LINE+1 S @TMPGBL@(LINE,0)=""
 ; set the standard field
 S S2017=$$GET1^DIQ(52.49,ERXIEN,312.1,"I")
 S MTYPE=$$GET1^DIQ(52.49,ERXIEN,.08,"I")
 S MTYPEE=$$GET1^DIQ(52.49,ERXIEN,.08,"E")
 S STATIEN=$$GET1^DIQ(52.49,ERXIEN,1,"I")
 S ERXSTAT=$$GET1^DIQ(52.49,ERXIEN,1)_" - "_$$GET1^DIQ(52.45,$$GET1^DIQ(52.49,ERXIEN,1,"I"),.02)
 I MTYPE'="IE" S ERRFLG=0
 S PATIEN=$$GET1^DIQ(52.49,ERXIEN,.04,"I") I 'PATIEN S PATIEN=$$GETPAT^PSOERXU5(ERXIEN)
 S PATIENS=PATIEN_","
 D GETS^DIQ(52.46,PATIENS,"**","IE","PATDAT")
 I 'ERRFLG D
 . S EPAT=$G(PATDAT(52.46,PATIENS,.01,"E"))
 . S EPATDOB=$G(PATDAT(52.46,PATIENS,.08,"I")),EPATDOB=$$FMTE^XLFDT(EPATDOB,"2D")
 I ERRFLG D
 . S (EPAT,EPATDOB)=""
 S VPATIEN=$$GET1^DIQ(52.49,ERXIEN,.05,"I")
 S VPATNM=$S(VPATIEN&'ERRFLG:$$GET1^DIQ(2,VPATIEN,.01,"E"),1:"NOT LINKED")
 S VPATDOB=$S(VPATIEN&'ERRFLG:$$GET1^DIQ(2,VPATIEN,.03,"I"),1:"N/A")
 I VPATDOB S VPATDOB=$$FMTE^XLFDT(VPATDOB,"2D")
 S PHARMIEN=$$GET1^DIQ(52.49,ERXIEN,2.5,"I")
 D GETS^DIQ(52.47,PHARMIEN,"**","E","PHDAT")
 S EPRVIEN=$$GET1^DIQ(52.49,ERXIEN,2.1,"I") I 'EPRVIEN S EPRVIEN=$$GETPROV^PSOERXU5(ERXIEN)
 S EPRVNM=$$GET1^DIQ(52.48,EPRVIEN,.01,"E")
 ; erx provider primary phone 2017071
 I S2017 D
 . S EPRVPT=$$COMMVAL^PSOERXU5(EPRVIEN,52.48,11,"PT",1)
 I 'S2017 D
 . N IENS,TYPE,EXT
 . S EPRVPT="",CIEN=$O(^PS(52.48,EPRVIEN,3,"C","TE",0))
 . I CIEN D
 . . S IENS=CIEN_","_EPRVIEN_","
 . . S EPRVPT=$$GET1^DIQ(52.483,IENS,.01,"I")
 . I 'CIEN D
 . . S CIEN=0
 . . F  S CIEN=$O(^PS(52.48,EPRVIEN,3,CIEN)) Q:CIEN'?1.N  D  Q:EPRVPT]""
 . . . S IENS=CIEN_","_EPRVIEN_","
 . . . S EPRVPT=$$GET1^DIQ(52.483,IENS,.01,"I")
 . . . S TYPE=$$GET1^DIQ(52.483,IENS,.02,"I")
 . . . S:TYPE="EM" EPRVPT=""
 . I EPRVPT]"" D
 . . S EXT=$$GET1^DIQ(52.483,IENS,.03,"I")
 . . S:EXT]"" EPRVPT=EPRVPT_"X"_EXT
 I 'S2017 S EPRVNPI=$$GET1^DIQ(52.48,EPRVIEN,1.5,"E")
 I S2017 S EPRVNPI=$$GET1^DIQ(52.48,EPRVIEN,15.1,"E")
 S EPRVDEA=$$GET1^DIQ(52.48,EPRVIEN,1.6,"E")
 S VAPRVIEN=$$GET1^DIQ(52.49,ERXIEN,2.3,"I")
 S ERXWRDT=$$GET1^DIQ(52.49,ERXIEN,5.9,"I")
 S VAPRVNM=$S(VAPRVIEN:$$GET1^DIQ(200,VAPRVIEN,.01,"E"),1:"NOT LINKED")
 S VAPRVNPI=$S(VAPRVIEN:$$GET1^DIQ(200,VAPRVIEN,41.99,"E"),1:"N/A")
 S VAPRVDEA=$S(VAPRVIEN:$$DEA^XUSER(0,VAPRVIEN,ERXWRDT),1:"N/A")
 D GETS^DIQ(52.48,EPRVIEN,"**","E","PRVDAT")
 S SUPIEN=$$GET1^DIQ(52.49,ERXIEN,2.6,"I")
 D GETS^DIQ(52.48,SUPIEN,"**","E","SUPDAT")
 S PAMANVAL=$$GET1^DIQ(52.49,ERXIEN,1.7,"I")
 S PRMANVAL=$$GET1^DIQ(52.49,ERXIEN,1.3,"I")
 S DRMANVAL=$$GET1^DIQ(52.49,ERXIEN,1.5,"I")
 S WDATE=$$GET1^DIQ(52.49,ERXIEN,5.9,"E")
 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")
 S:'ERRFLG PATPT=$$GETPTPH^PSOERXU7(PATIEN,S2017,"PT,HP")
 ; only set the hold reason if the eRx has a hold status
 S CURSTATE=$$GET1^DIQ(52.49,ERXIEN,1,"E")
 S (VAHSTA,VAHREA)=""
 I S2017,MTYPE'="RE" D
 . S MEDIEN=$O(^PS(52.49,ERXIEN,311,"C","P",0))
 . S EDIRECT=$$GET1^DIQ(52.49,MEDIEN_","_ERXIEN_",",8,"E")
 . I $G(MEDIEN) S ERXPNC=$$GET1^DIQ(52.49311,MEDIEN_","_ERXIEN_",",5) ;retrieved provider notes/comments
 I S2017,MTYPE="RE" D
 . S MEDIEN=$O(^PS(52.49,ERXIEN,311,"C","MR",0))
 I 'S2017 D
 . S EDIRECT=$$GET1^DIQ(52.49,ERXIEN,7,"E")
 I $E(CURSTATE,1)="H" D
 . S CURSTATI=$$GET1^DIQ(52.49,ERXIEN,1,"I")
 . S LHMATCH=999999,LHFOUND=0 F  S LHMATCH=$O(^PS(52.49,ERXIEN,19,LHMATCH),-1) Q:'LHMATCH!(LHFOUND)  D
 . . S LHSTATI=$$GET1^DIQ(52.4919,LHMATCH_","_ERXIEN_",",.02,"I") I LHSTATI=CURSTATI D  S LHFOUND=LHMATCH Q
 . . . S VAHREA=$$GET1^DIQ(52.4919,LHMATCH_","_ERXIEN_",",1)
 . . . S VAHSTA=$$GET1^DIQ(52.45,LHSTATI,.01,"E")_" - "_$$GET1^DIQ(52.45,LHSTATI,.02,"E")
 . . . S VAHPER=$$GET1^DIQ(52.4919,LHMATCH_","_ERXIEN_",",.03,"E")
 I (",RE,CN,"[(","_MTYPE_","))!((MTYPE="CX")&$$CHGMTYPE^PSOERX1D(ERXIEN,MTYPE,RESPVAL,CHGMESRI)) S MTYPEE=$G(MTYPEE)_" - "_$$GET1^DIQ(52.49,ERXIEN,52.1,"E")
 S LINETXT=""
 I $$GET1^DIQ(52.49,ERXIEN,95.1,"I") S $E(MTYPEE,63)="EPCS DEA VALIDATED"
 S LINE=LINE+1 S @TMPGBL@(LINE,0)=MTYPEE
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="eRx Status: "_$S($E(CURSTATE,1)="H":VAHSTA,1:ERXSTAT)
 I ",CX,CR,"[(","_MTYPE_","),$$QTSUMDT1^PSOERSE5(TMPGBL,ERXIEN,MTYPE,CHGMESRI,CHGMESRQ,RESPVAL,.LINE) D  Q
 . I ",CR,"[(","_MTYPE_",") D ADDPNOTE^PSOERX1H(.LINE,$G(PNCOMM))
 ;
 I $G(CSCOMM)]"" S LINE=LINE+1 S @TMPGBL@(LINE,0)="Current Status Details: "_CSCOMM
 I $D(LERXSTAT) S LINE=LINE+1 S @TMPGBL@(LINE,0)="Last New Rx status: "_LERXSTAT
 I $D(LOPSTAT) S LINE=LINE+1 S @TMPGBL@(LINE,0)="Outpatient Prescription status: "_LOPSTAT
 I @TMPGBL@(LINE,0)'="" S LINE=LINE+1 S @TMPGBL@(LINE,0)=""
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="**************************MEDICATION PRESCRIBED******************************"
 I 'ERRFLG,$L($G(PATPT)) S LINE=LINE+1 S @TMPGBL@(LINE,0)="eRx Patient Primary Telephone: "_PATPT
 S LINE=LINE+1
 D ADDITEM^PSOERX1A(.LINETXT,"eRx Patient: ",EPAT,1,52)
 D ADDITEM^PSOERX1A(.LINETXT,"DOB: ",EPATDOB,57,20)
 S @TMPGBL@(LINE,0)=LINETXT S LINETXT=""
 S LINE=LINE+1
 I $L($G(EPRVPT)) S LINE=LINE+1 S @TMPGBL@(LINE,0)="eRx Provider Primary Telephone: "_EPRVPT
 S LINE=LINE+1
 D ADDITEM^PSOERX1A(.LINETXT,"eRx Provider: ",EPRVNM,1,52)
 S @TMPGBL@(LINE,0)=LINETXT S LINETXT=""
 D ADDITEM^PSOERX1A(.LINETXT,"DEA#: ",EPRVDEA,30,20)
 D ADDITEM^PSOERX1A(.LINETXT,"NPI: ",EPRVNPI,57,20)
 S LINE=LINE+1 S @TMPGBL@(LINE,0)=LINETXT S LINETXT=""
 S LINE=LINE+1 S @TMPGBL@(LINE,0)=""
 S ERXDRUG=$$GET1^DIQ(52.49,ERXIEN,3.1,"E") I '$L(ERXDRUG) S ERXDRUG=$$GETDRUG^PSOERXU5(ERXIEN)
 S ERXQTY=$$GET1^DIQ(52.49,ERXIEN,5.1,"E")
 I $G(S2017) S ERXRFLS=$$GET1^DIQ(52.49,ERXIEN,5.6,"E")
 ;If the message type is 'CX' for RXCHANGERESPONSE, display the Prescriber Drug Use Evaluation.
 I MTYPE="CX" D DSPLYDUE^PSOERSE3(ERXIEN,.LINE,1,TMPGBL)
 ;setting 10.6 refill value
 I '$G(S2017) D
 . S ERXRFLS=$$GET1^DIQ(52.49,ERXIEN,5.6,"E")
 . I ERXRFLS="" S ERXRFLS=$$GET1^DIQ(52.49,ERXIEN,5.7,"I")
 S ERXDS=$$GET1^DIQ(52.49,ERXIEN,5.5,"E")
 S ERXDT=$$GET1^DIQ(52.49,ERXIEN,.03,"E")
 I S2017 D
 . S ERXDT=$S(MEDIEN:$$EFFDATE^PSOERXU5(ERXIEN,MEDIEN),1:"")
 S VADRGIEN=$$GET1^DIQ(52.49,ERXIEN,3.2,"I")
 S VADRG=$$GET1^DIQ(52.49,ERXIEN,3.2,"E")
 S VAREF=$$GET1^DIQ(52.49,ERXIEN,20.5,"E")
 S VAQTY=$$GET1^DIQ(52.49,ERXIEN,20.1,"E")
 S VADAYS=$$GET1^DIQ(52.49,ERXIEN,20.2,"E")
 I VADRG']"" S VADRG="NOT LINKED"
 D TXT2ARY^PSOERXD1(.DRGARY,ERXDRUG,,70)
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="eRx Drug: "_$G(DRGARY(1))_" "_$P($$ERXDRSCH^PSOERXUT(ERXIEN),"^",2)
 S DLP=1
 F  S DLP=$O(DRGARY(DLP)) Q:'DLP  D
 . S LINE=LINE+1 S @TMPGBL@(LINE,0)="          "_$G(DRGARY(DLP))
 S LINE=LINE+1
 D ADDITEM^PSOERX1A(.LINETXT,"eRx Qty: ",ERXQTY,1,17)
 D ADDITEM^PSOERX1A(.LINETXT,"eRx Refills: ",ERXRFLS,19,16)
 D ADDITEM^PSOERX1A(.LINETXT,"eRx Days Supply: ",ERXDS,37,20)
 I 'S2017 D ADDITEM^PSOERX1A(.LINETXT,"eRx Date: ",$P(ERXDT,"@"),58,22)
 S @TMPGBL@(LINE,0)=LINETXT S LINETXT=""
 I S2017 D
 . S LINE=LINE+1
 . D ADDITEM^PSOERX1A(.LINETXT,"eRx Written Date: ",$P(WDATE,"@"),1,35)
 . D ADDITEM^PSOERX1A(.LINETXT,"eRx Issue Date: ",ERXDT,40,70)
 . S @TMPGBL@(LINE,0)=LINETXT S LINETXT=""
 . S LINE=LINE+1
 . I MTYPE="N"!((MTYPE="CX")&$$PROHIBIT^PSOERX1D(RESPVAL,CHGMESRI)) D
 . . S PROHIBIT=$$GET1^DIQ(52.49,ERXIEN,301.3,"I")
 . . S PROHIBIT=$S(PROHIBIT=1:"Yes",1:"No")
 . . S @TMPGBL@(LINE,0)="Prohibit Renewals: "_PROHIBIT
 D TXT2ARY^PSOERXD1(.SIGARY,$G(EDIRECT),,70)
 S SFIRST=$O(SIGARY(0))
 I 'S2017 D
 . S SGLOOP=0 F  S SGLOOP=$O(SIGARY(SGLOOP)) Q:'SGLOOP  D
 . . S LINE=LINE+1 S @TMPGBL@(LINE,0)=$S(SGLOOP=SFIRST:"eRx Sig: ",1:"         ")_$G(SIGARY(SGLOOP))
 I S2017,$G(MEDIEN) D
 . S LINE=LINE+1 S @TMPGBL@(LINE,0)="eRx Sig: "
 . S SGLOOP=0 F  S SGLOOP=$O(^PS(52.49,ERXIEN,311,MEDIEN,8,SGLOOP)) Q:'SGLOOP  D
 . . I SGLOOP=1 S @TMPGBL@(LINE,0)=@TMPGBL@(LINE,0)_$G(^PS(52.49,ERXIEN,311,MEDIEN,8,SGLOOP,0)) Q
 . . S LINE=LINE+1 S @TMPGBL@(LINE,0)=$G(^PS(52.49,ERXIEN,311,MEDIEN,8,SGLOOP,0))
 . K ERXPNARY D TXT2ARY^PSOERXD1(.ERXPNARY,$G(ERXPNC),,80)
 . S LINE=LINE+1 S @TMPGBL@(LINE,0)="eRx Provider Notes/Comments:"
 . I $D(ERXPNARY) D
 . . S PNLOOP=0 F  S PNLOOP=$O(ERXPNARY(PNLOOP)) Q:'PNLOOP  D
 . . . S LINE=LINE+1 S @TMPGBL@(LINE,0)=$G(ERXPNARY(PNLOOP))
 I (",CX,CR,"[(","_MTYPE_",")),$$QTSUMDT2^PSOERSE5(TMPGBL,ERXIEN,MTYPE,CHGMESRI,RESPVAL,.LINE) D  Q
 . I ",CR,"[(","_MTYPE_",") D ADDPNOTE^PSOERX1H(.LINE,$G(PNCOMM))
 ;
DISPRX ;
 I "RR,CA,CN,IE"'[MTYPE!(MTYPE="N") D
 . I MTYPE="RE",$$GET1^DIQ(52.49,ERXIEN,52.1,"I")'="R" Q
 . S LINE=LINE+1 S @TMPGBL@(LINE,0)=""
 . S PSNF="" I $G(VADRGIEN) S PSNF=$S($P(^PSDRUG(VADRGIEN,0),"^",9):"***(N/F)***",1:"") ;p689
 . S LINE=LINE+1 S @TMPGBL@(LINE,0)="Vista Drug"_$S(DRMANVAL:"[v]",1:"")_": "_VADRG_" "_$P($$VADRSCH^PSOERXUT(VADRGIEN),"^",3)_PSNF
 . S LINE=LINE+1
 . D ADDITEM^PSOERX1A(.LINETXT,"Vista Qty: ",$G(VAQTY),1,25)
 . D ADDITEM^PSOERX1A(.LINETXT,"Vista Refills: ",$G(VAREF),27,18)
 . D ADDITEM^PSOERX1A(.LINETXT,"Vista Days Supply: ",$G(VADAYS),54,22)
 . S @TMPGBL@(LINE,0)=LINETXT S LINETXT=""
 . S VASIG=""
 . S SLOOP=0 F  S SLOOP=$O(^PS(52.49,ERXIEN,"SIG",SLOOP)) Q:'SLOOP  D
 . . I '$L($G(VASIG)) S VASIG=$G(^PS(52.49,ERXIEN,"SIG",SLOOP,0)) Q
 . . S VASIG=$G(VASIG)_" "_$G(^PS(52.49,ERXIEN,"SIG",SLOOP,0))
 . D TXT2ARY^PSOERXD1(.VASARY,VASIG,,68)
 . S FSSIG=$O(VASARY(0))
 . S ERXDSUB=$$GET1^DIQ(52.49,ERXIEN,5.8,"I")
 . S ERXDSUB=$S(ERXDSUB=1:"NO",ERXDSUB=0:"YES",1:"")
 . S LINE=LINE+1 S @TMPGBL@(LINE,0)="Substitutions? :"_ERXDSUB
 . S LINE=LINE+1 S @TMPGBL@(LINE,0)="Vista Sig: "_$S(FSSIG:$G(VASARY(FSSIG)),1:"")
 . S SLOOP=1 F  S SLOOP=$O(VASARY(SLOOP)) Q:'SLOOP  D
 . . S LINE=LINE+1 S @TMPGBL@(LINE,0)="                        "_VASARY(SLOOP)
 . S VPATINST=$$GET1^DIQ(52.49,ERXIEN,27,"E")
 . I VPATINST]"" S VPATINST=$$LSIG^PSOQUTIL(VPATINST)
 . D TXT2ARY^PSOERXD1(.VAPIARY,VPATINST," ",68)
 . S FSVPIN=$O(VAPIARY(0))
 . S LINE=LINE+1 S @TMPGBL@(LINE,0)=" Pat Inst: "_$S(FSVPIN:$G(VAPIARY(FSVPIN)),1:"")
 . S VLOOP=1 F  S VLOOP=$O(VAPIARY(VLOOP)) Q:'VLOOP  D
 . . S LINE=LINE+1 S @TMPGBL@(LINE,0)="           "_VAPIARY(VLOOP)
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="Hold Status: "_$G(VAHSTA)
 S VAHREA="Hold Reason: "_$G(VAHREA)
 D TXT2ARY^PSOERXD1(.HARY,VAHREA," ",80)
 S HL=0 F  S HL=$O(HARY(HL)) Q:'HL  D
 . S LINE=LINE+1 S @TMPGBL@(LINE,0)=$G(HARY(HL))
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="Placed on hold by: "_$G(VAHPER)
 S LINE=LINE+1 S @TMPGBL@(LINE,0)=""
 S ERXCOMM="eRx Notes: "_$$GET1^DIQ(52.49,ERXIEN,8,"E")
 D TXT2ARY^PSOERXD1(.COMARY,ERXCOMM," ",68)
 S COM=0 F  S COM=$O(COMARY(COM)) Q:'COM  S LINE=LINE+1 S @TMPGBL@(LINE,0)=$G(COMARY(COM))
 I ",CR,"[(","_MTYPE_",") D ADDPNOTE^PSOERX1H(.LINE,$G(PNCOMM))
 Q