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

PSOERX1C.m

Go to the documentation of this file.
PSOERX1C ;ALB/BWF - eRx Utilities ; 11/27/2019 10:20am
 ;;7.0;OUTPATIENT PHARMACY;**467,520,527,508,551,581,617,646,700,746,769**;DEC 1997;Build 26
 ;
 Q
 ; select an item
PRINT(PSOIEN,OP) ;
 N %ZIS,POP,DIR
 S OP=$G(OP)
 D FULL^VALM1
 S VALMBCK="R"
 S %ZIS="Q",%ZIS("B")=$G(PSOPROP) D ^%ZIS Q:POP
 ; if queuing, queue it and quit.
 I $D(IO("Q")) D  Q
 .S ZTSAVE("PSOIEN")="",ZTSAVE("OP")="",ZTSAVE("VALMAR")="",ZTSAVE("VALMEVL")=""
 .S ZTRTN="PRINTQ^PSOERX1C(PSOIEN,OP)",ZTDESC="eRx Print" D ^%ZTLOAD
 .K ZTSAVE,ZTRTN
 .D TERM^VALM0
 .D REF^PSOERSE1
 D PRINTQ(PSOIEN,OP)
 K DIR S DIR(0)="E" D ^DIR K DIR
 D TERM^VALM0
 D REF^PSOERSE1
 Q
 ; fall through if no queueing
PRINTQ(PSOIEN,OP) ;
 N %ZIS,POP,RXDAT,PHARIEN,PRVIEN,PATIEN,PHARDAT,PRVDAT,PATDAT,PSOIENS,PHNM,PHAD1,PHAD2,PHCTY,LINE,LOOP,PROHIBIT,ERXWDATE
 N PHST,PHZIP,PHNCP,PHTEL,PRFNM,PRLNM,PRMNM,PRAD1,PRAD2,PRCTY,PRST,PRZIP,PRNPI,PRDEA,PRSTL,LTXT,MTYPE,NEWRXIEN,ERXEFFDT,PHW,SGLOOP
 N PRTEL,PRFAX,PRSUPER,PRAGNT,PTLNM,PTFNM,PTMNM,PTAD1,PTAD2,PTCTY,PTST,PTZIP,PTDOB,PTGEN,PTHPHON,S2017,MEDIEN,R2017
 N PHARIENS,PATIENS,PRVIENS,PTSSN,PRAGNTFN,PRAGNTMN,PRAGNTLN,TYPE,VALUE,SIEN,REFILL,IENS,CANREQ,CANRES,ERXDSUB,EXSTATUS
 N CHGMESRI,CHGMESRQ,RESPVAL,DRUGCODE,PRVNOTES,DUEINFO,DDOT,DUECNT,REASON,RESULT,ICDINFO,ICD,ICDZ,CLINIC
 S OP=$G(OP,"")
 S PSOIEN=$G(PSOIEN)
 I '$G(PSOIEN) D
 .I $D(RXOR) S PSOIEN=$$CHKERX^PSOERXU1($P(RXOR,U,2)) Q:PSOIEN
 .I $D(OR0) S PSOIEN=$$CHKERX^PSOERXU1(OR0)
 Q:'$G(PSOIEN)
 S MTYPE=$$GET1^DIQ(52.49,PSOIEN,.08,"I")
 S CHGMESRQ=$$GET1^DIQ(52.49,PSOIEN,315.1,"I")
 S CHGMESRI=$$GET1^DIQ(52.45,CHGMESRQ,.01,"I")
 S RESPVAL=$$GET1^DIQ(52.49,PSOIEN,52.1,"E")
 I MTYPE="CN"!(MTYPE="RE")!(MTYPE="IE") D
 .S CANRES=PSOIEN
 .S CANREQ=$$GETREQ^PSOERXU2(PSOIEN)
 .I $G(CANREQ) D
 ..S NEWRXIEN=$$RESOLV^PSOERXU2(CANREQ)
 ..; if there is no NewRx related to this request, pull the data from the cancel request itself.
 ..I '$P(NEWRXIEN,U) S NEWRXIEN=$G(CANREQ)
 I MTYPE="CA"!(MTYPE="RR") D
 .S CANREQ=PSOIEN,CANRES=$$GETRESP^PSOERXU2(CANREQ)
 .S NEWRXIEN=$$RESOLV^PSOERXU2(CANREQ)
 .I '$P(NEWRXIEN,U) S NEWRXIEN=$G(CANREQ)
 ; if we found the newrxien because of a different message type, reset PSOIEN to pull rx info from the newrx.
 S S2017=$$GET1^DIQ(52.49,PSOIEN,312.1,"I")
 I S2017 D
 .I MTYPE'="RE" D
 ..S MEDIEN=$O(^PS(52.49,PSOIEN,311,"C","P",0))
 .I MTYPE="RE" D
 ..S MEDIEN=$O(^PS(52.49,PSOIEN,311,"C","MR",0))
 S PSOIENS=PSOIEN_","
 I $D(ZTQUEUED) S ZTREQ="@"
 U IO
 D GETS^DIQ(52.49,PSOIENS,".04;.08;2.1;2.5","I","RXDAT")
 S PHARIEN=$G(RXDAT(52.49,PSOIENS,2.5,"I"))
 S:PHARIEN PHARIENS=PHARIEN_","
 S PRVIEN=$G(RXDAT(52.49,PSOIENS,2.1,"I"))
 S:PRVIEN PRVIENS=PRVIEN_","
 S PATIEN=$G(RXDAT(52.49,PSOIENS,.04,"I"))
 S:PATIEN PATIENS=PATIEN_","
 I $D(PHARIENS) D GETS^DIQ(52.47,PHARIENS,"**","E","PHARDAT")
 I $D(PRVIENS) D GETS^DIQ(52.48,PRVIENS,"**","E","PRVDAT")
 I $D(PATIENS) D GETS^DIQ(52.46,PATIENS,"**","E","PATDAT")
 ; pharmacy information
 I $D(PHARIENS) D
 .S PHNM=$G(PHARDAT(52.47,PHARIENS,.05,"E"))
 .S PHAD1=$G(PHARDAT(52.47,PHARIENS,1.1,"E"))
 .S PHAD2=$G(PHARDAT(52.47,PHARIENS,1.2,"E"))
 .S PHCTY=$G(PHARDAT(52.47,PHARIENS,1.3,"E"))
 .S PHST=$G(PHARDAT(52.47,PHARIENS,1.4,"E"))
 .S PHZIP=$G(PHARDAT(52.47,PHARIENS,1.5,"E"))
 .I S2017 D
 ..S PHNCP=$G(PHARDAT(52.47,PHARIENS,10.1,"E"))
 ..S PHTEL=$$COMMVAL^PSOERXU5(PHARIEN,52.47,7,"PT",1) ; Add extension
 .I 'S2017 D
 ..S PHNCP=$G(PHARDAT(52.47,PHARIENS,.02,"E"))
 ..S PHTEL=$$COMMVAL^PSOERXU5(PHARIEN,52.47,7,"PT",1)
 ; provider information
 I $D(PRVIENS) D
 .S PRFNM=$G(PRVDAT(52.48,PRVIENS,.03,"E"))
 .S PRMNM=$G(PRVDAT(52.48,PRVIENS,.04,"E"))
 .S PRLNM=$G(PRVDAT(52.48,PRVIENS,.02,"E"))
 .S PRAD1=$G(PRVDAT(52.48,PRVIENS,4.1,"E"))
 .S PRAD2=$G(PRVDAT(52.48,PRVIENS,4.2,"E"))
 .S PRCTY=$G(PRVDAT(52.48,PRVIENS,4.3,"E"))
 .S PRST=$G(PRVDAT(52.48,PRVIENS,4.4,"E"))
 .S PRZIP=$G(PRVDAT(52.48,PRVIENS,4.5,"E"))
 .I S2017 D
 ..S PRNPI=$G(PRVDAT(52.48,PRVIENS,15.1,"E"))
 ..S PRDEA=$G(PRVDAT(52.48,PRVIENS,14.5,"E"))
 ..S PRSTL=$G(PRVDAT(52.48,PRVIENS,14.1,"E"))
 .I 'S2017 D
 ..S PRNPI=$G(PRVDAT(52.48,PRVIENS,1.5,"E"))
 ..S PRDEA=$G(PRVDAT(52.48,PRVIENS,1.6,"E"))
 ..S PRSTL=$G(PRVDAT(52.48,PRVIENS,1.8,"E"))
 .I '$G(NEWRXIEN) S PRSUPER=$$GET1^DIQ(52.49,PSOIEN,2.6,"E")
 .I $G(NEWRXIEN) S PRSUPER=$$GET1^DIQ(52.49,NEWRXIEN,2.6,"E")
 .S PRAGNTFN=$$GET1^DIQ(52.48,PRVIEN,5.2,"E")
 .S PRAGNTMN=$$GET1^DIQ(52.48,PRVIEN,5.3,"E")
 .S PRAGNTLN=$$GET1^DIQ(52.48,PRVIEN,5.1,"E")
 .I S2017 D
 ..S PRTEL=$$COMMVAL^PSOERXU5(PRVIEN,52.48,11,"PT",1) ; Add extension
 ..S PRFAX=$$COMMVAL^PSOERXU5(PRVIEN,52.48,11,"F",1) ; Add extension
 .I 'S2017 D
 ..S SIEN=0
 ..F  S SIEN=$O(^PS(52.48,PRVIEN,3,SIEN)) Q:'SIEN  D
 ...S IENS=SIEN_","_PRVIEN_","
 ...S TYPE=$$GET1^DIQ(52.483,IENS,.02)
 ...S VALUE=$$GET1^DIQ(52.483,IENS,.01)
 ...D
 ....I TYPE="FAX" S PRFAX=VALUE Q
 ....I TYPE="TELEPHONE" S PRTEL=VALUE
 I '$D(PRVIENS) D
 .S (PRFNM,PRMNM,PRLNM,PRAD1,PRAD2,PRCTY,PRST,PRZIP)=""
 .S (PRNPI,PRDEA,PRSTL)=""
 .I '$G(NEWRXIEN) S PRSUPER=$$GET1^DIQ(52.49,PSOIEN,2.6,"E")
 .I $G(NEWRXIEN) S PRSUPER=$$GET1^DIQ(52.49,NEWRXIEN,2.6,"E")
 .S (PRAGNTFN,PRAGNTMN,PRAGNTLN)=""
 .S (PRTEL,PRFAX)=""
 S CLINIC=$$GET1^DIQ(52.48,PRVIEN,18.6)
 ; patient information
 I $D(PATIENS) D
 .S PTLNM=$G(PATDAT(52.46,PATIENS,.02,"E"))
 .S PTMNM=$G(PATDAT(52.46,PATIENS,.04,"E"))
 .S PTFNM=$G(PATDAT(52.46,PATIENS,.03,"E"))
 .S PTAD1=$G(PATDAT(52.46,PATIENS,3.1,"E"))
 .S PTAD2=$G(PATDAT(52.46,PATIENS,3.2,"E"))
 .S PTCTY=$G(PATDAT(52.46,PATIENS,3.3,"E"))
 .S PTST=$G(PATDAT(52.46,PATIENS,3.4,"E"))
 .S PTZIP=$G(PATDAT(52.46,PATIENS,3.5,"E"))
 .S PTDOB=$G(PATDAT(52.46,PATIENS,.08,"E"))
 .S PTGEN=$G(PATDAT(52.46,PATIENS,.07,"E"))
 .S PTSSN=$G(PATDAT(52.46,PATIENS,$S(S2017:18.2,1:1.4),"E"))
 .S PTHPHON=$$GETPTPH^PSOERXU7(PATIEN,S2017,"PT,HP")
 ;
 W !,$$TITLELN("PHARMACY INFORMATION")
 I MTYPE="RR" D
 .N NEWRXIEN
 .S NEWRXIEN=$$RESOLV^PSOERXU2(PSOIEN)
 .S:NEWRXIEN PHNCP=$$GET1^DIQ(52.49,NEWRXIEN,22.3)
 I $D(PHARIENS) D
 .W !,$$UP^XLFSTR(PHNM)
 .W !,"Address: "_PHAD1
 .W:$L(PHAD2) !,"         "_PHAD2
 .W !,"         "_PHCTY_", "_PHST_" "_PHZIP
 .S LTXT=""
 .D ADDITEM^PSOERX1A(.LTXT,"Primary Phone: ",PHTEL,1,40)
 .D ADDITEM^PSOERX1A(.LTXT,"NCPDP: ",PHNCP,42,26)
 .W !,LTXT S LTXT=""
 I '$D(PHARIENS) D
 .W !,"Recipient pharmacy name and address missing."
 .S LTXT=""
 .D ADDITEM^PSOERX1A(.LTXT,"NCPDP: ",$G(PHNCP),1,26)
 .W !!,LTXT S LTXT=""
 W !,$$TITLELN("PRESCRIBER INFORMATION")
 W !,"Name: "_PRLNM_", "_PRFNM_" "_PRMNM
 I $G(CLINIC)'="" W !,"Clinic: ",CLINIC
 W !,"Address: "_PRAD1
 I $L(PRAD2) W !,"         "_PRAD2
 W !,"         "_PRCTY_", "_PRST_" "_PRZIP
 W !,"NPI: "_PRNPI,?20,"DEA: "_PRDEA,?40,"State Lic: "_PRSTL
 W !,"Primary Phone: "_$G(PRTEL),?40,"Fax: "_$G(PRFAX)
 I $G(PRSUPER)'=""!($G(PRAGNTLN)'="") W !,"Supervisor: "_$G(PRSUPER) W:$G(PRAGNTLN)'="" ?45,"Agent: "_$G(PRAGNTLN)_", "_$G(PRAGNTFN)_" "_$G(PRAGNTMN)
 W !,$$TITLELN("PATIENT INFORMATION")
 S LTXT=""
 I $D(PATIENS) D
 .W !,"Name: "_PTLNM_", "_PTFNM_" "_PTMNM
 .W !,"DOB: ",PTDOB,?19,"Sex: ",PTGEN,?33,"Primary Phone: ",PTHPHON,?64,"SSN: ",PTSSN
 .W !,"Address: "_PTAD1
 .I $L(PTAD2) W !,"         "_PTAD2
 .W !,"         "_PTCTY_", "_PTST_" "_PTZIP
 .S LTXT=""
 I S2017 D
 .S PHW=$$BHW^PSOERXIU(PSOIEN) W !,PHW
 W !,$$TITLELN("PRESCRIPTION INFORMATION")
 Q:$$SHORTPI^PSOERX1D(PSOIEN,MTYPE,RESPVAL,CHGMESRI)
 W !,"eRx Drug: "_$$GET1^DIQ(52.49,PSOIEN,3.1,"E")_" "_$P($$ERXDRSCH^PSOERXUT(+PSOIENS),"^",2)
 W !,$$DRUGCODE(PSOIEN,+$G(MEDIEN))
 S ERXWDATE=$$GET1^DIQ(52.49,PSOIEN,5.9,"E")
 I 'S2017 W ?20,"Written Date: "_$$FMTE^XLFDT(ERXWDATE,"2D")
 I S2017 D
 .S ERXEFFDT=$$EFFDATE^PSOERXU5(PSOIEN,MEDIEN)
 .W ?20,"Written Date: "_$$FMTE^XLFDT($P(ERXWDATE,"."),1)_"      Issue Date: "_ERXEFFDT
 W !,"Qty: ",$$GET1^DIQ(52.49,PSOIEN,5.1,"E"),?20,"Days Supply: ",$$GET1^DIQ(52.49,PSOIEN,5.5,"E")
 I S2017 D
 .S REFILL=$$GET1^DIQ(52.49,PSOIEN,5.6,"E")
 .;setting 10.6 refill value
 I 'S2017 D
 .S REFILL=$$GET1^DIQ(52.49,PSOIEN,5.6,"E")
 .I REFILL="" D
 ..S REFILL=$$GET1^DIQ(52.49,PSOIEN,5.7,"I")
 ; refills for a refill response is # of refills-1
 I MTYPE="RE",REFILL S REFILL=REFILL-1
 W ?45,"Refills: "_REFILL
 I 'S2017 W !,"Code List Qualifier: "_$$GET1^DIQ(52.49,PSOIEN,5.2,"E")
 I S2017 D
 .N ERXQQ
 .S ERXQQ=$$GET1^DIQ(52.49311,MEDIEN_","_PSOIEN_",",2.2,"I"),ERXQQ=$$GET1^DIQ(52.45,ERXQQ,.02,"E")
 .W !,"Code List Qualifier: "_ERXQQ
 W !,"Drug Form: "_$$GET1^DIQ(52.49,PSOIEN,41,"E")
 W !,"Strength: "_$$GET1^DIQ(52.49,PSOIEN,43,"E")
 S EXSTATUS=$$GET1^DIQ(52.49,PSOIEN,1,"E")
 S ERXDSUB=$$GET1^DIQ(52.49,PSOIEN,5.8,"I")
 S ERXDSUB=$S(ERXDSUB=1:"NO",ERXDSUB=0:"YES",1:"")
 W !,"Substitutions?: "_ERXDSUB
 I S2017 D
 .I MTYPE="N"!((MTYPE="CX")&($$PROHIBIT^PSOERX1D(RESPVAL,CHGMESRI))) D
 ..S PROHIBIT=$$GET1^DIQ(52.49,PSOIEN,301.3,"I")
 ..S PROHIBIT=$S(PROHIBIT=1:"Yes",1:"No")
 ..W ?30,"Prohibit Renewals: "_PROHIBIT
 I 'S2017 W !,"SIG: "_$$GET1^DIQ(52.49,PSOIEN,7,"E")
 I S2017 D
 .W !,"eRx Sig:"
 .Q:$G(MEDIEN)=""
 .S SGLOOP=0 F  S SGLOOP=$O(^PS(52.49,PSOIEN,311,MEDIEN,8,SGLOOP)) Q:'SGLOOP  D
 ..W !,$G(^PS(52.49,PSOIEN,311,MEDIEN,8,SGLOOP,0))
 S PRVNOTES=$$GET1^DIQ(52.49,PSOIEN,8)
 I PRVNOTES'="" W !,"Provider Comments: ",PRVNOTES
 ;
 ;Prescriber Drug Use Evaluation
 D PDUEDATA^PSOERXU9(.DUEINFO,PSOIEN,1)
 I $D(DUEINFO) D
 . S $P(DDOT,".",81)=""
 . W !,$$TITLELN("PRESCRIBER DRUG USE EVALUATION")
 . S DUECNT=0 F  S DUECNT=$O(DUEINFO(DUECNT)) Q:'DUECNT  D
 . . W !,"Co-Agent: "_$P(DUEINFO(DUECNT),"^",8)
 . . S REASON=$P(DUEINFO(DUECNT),"^",2) I $$PRESOLV^PSOERXA1(REASON,"REA") S REASON=$$GET1^DIQ(52.45,$$PRESOLV^PSOERXA1(REASON,"REA"),.02)
 . . W !,"Reason: "_REASON
 . . S RESULT=$P(DUEINFO(DUECNT),"^",4) I $$PRESOLV^PSOERXA1(RESULT,"RES") S RESULT=$$GET1^DIQ(52.45,$$PRESOLV^PSOERXA1(RESULT,"RES"),.02)
 . . W !,"Result: "_RESULT
 . . W !,"Override: "_$P(DUEINFO(DUECNT),"^",9)
 . . I $O(DUEINFO(DUECNT)) W !,DDOT
 ;
 ;Diagnosis Code
 D GETDIAGS^PSOERUT3(PSOIEN,.ICDINFO)
 I $D(ICDINFO) D
 . S $P(DDOT,".",81)=""
 . W !,$$TITLELN("DIAGNOSIS INFORMATION")
 . S ICD=0 F  S ICD=$O(ICDINFO(ICD)) Q:'ICD  D
 . . S ICDZ=ICDINFO(ICD)
 . . W !,$S($P(ICDZ,"^")="P":"Primary",1:"Secondary")_" Dx:"
 . . W !,$P(ICDZ,"^",2)_" "_$P(ICDZ,"^",3)
 . . W !,$P(ICDZ,"^",4)
 . . I $O(ICDINFO(ICD)) W !,DDOT
 ;
 K ^TMP("PSOERX1C",$J) M ^TMP("PSOERX1C",$J)=@VALMAR
 W !!,"eRx Reference #: ",$$GET1^DIQ(52.49,PSOIEN,.01,"E"),"  Message ID: ",$$GET1^DIQ(52.49,PSOIEN,25,"E")
 W LTXT S LTXT=""
 S ERXDSUB=$$GET1^DIQ(52.49,PSOIEN,5.8,"I")
 S ERXDSUB=$S(ERXDSUB=1:"NO",ERXDSUB=0:"YES",1:"")
 ;;BEGIN TEST
 I MTYPE="CA"!(MTYPE="RR") D
 .S LINE=1 K @VALMAR
 .I MTYPE="CA" D CANREQ^PSOERXU5(CANREQ,.LINE,1),CANRES^PSOERXU5(CANREQ,.LINE,1),MSGHIS^PSOERXU3(CANREQ,.LINE)
 .I MTYPE="RR" D
 ..I S2017 D MEDDIS^PSOERXU7(CANREQ,.LINE)
 ..I 'S2017 D MEDDIS^PSOERXU3(CANREQ,"D",.LINE)
 ..D RRREQ^PSOERXU3(CANREQ,.LINE),RRRES^PSOERXU3(CANREQ,.LINE),MSGHIS^PSOERXU3(CANREQ,.LINE)
 .S LOOP=0 F  S LOOP=$O(@VALMAR@(LOOP)) Q:'LOOP  D
 ..W !,$G(@VALMAR@(LOOP,0))
 .K @VALMAR
 I MTYPE="CN"!(MTYPE="RE") D
 .S LINE=1 K @VALMAR
 .I MTYPE="CN" D CANRES^PSOERXU5(CANRES,.LINE,1),CANREQ^PSOERXU5(CANRES,.LINE,1),MSGHIS^PSOERXU3(CANRES,.LINE)
 .I MTYPE="RE" D
 ..S R2017=$$GET1^DIQ(52.49,CANREQ,312.1,"I")
 ..I 'S2017,'R2017 D MEDDIS^PSOERXU3(CANREQ,"D",.LINE)
 ..I S2017,'R2017 D MEDDIS^PSOERXU3(CANREQ,"D",.LINE)
 ..I S2017,R2017 D MEDDIS^PSOERXU7(CANREQ,.LINE)
 ..D RRRES^PSOERXU3(CANRES,.LINE),RRREQ^PSOERXU3(CANRES,.LINE),MSGHIS^PSOERXU3(CANRES,.LINE)
 ..S LOOP=0 F  S LOOP=$O(@VALMAR@(LOOP)) Q:'LOOP  D
 ...W !,$G(@VALMAR@(LOOP,0))
 ..K @VALMAR
 I ",CX,CR,"[(","_MTYPE_",") D
 .D CHGEND^PSOERX1D(PSOIEN,MTYPE,RESPVAL,CHGMESRI)
 W !,$$TITLELN("END OF eRx")
 K @VALMAR M @VALMAR=^TMP("PSOERX1C",$J) K ^TMP("PSOERX1C",$J)
 D:'$D(ZTQUEUED) ^%ZISC
 Q
 ;
TITLELN(TITLE) ; Title Line (Formats with _ around it, centered)
 N TITLELN
 S $P(TITLELN,"*",81)=""
 S $E(TITLELN,(82-$L(TITLE))\2,(82-$L(TITLE))\2+$L(TITLE)-1)=TITLE
 Q TITLELN
 ;
DISPCHK(CANREQ,LINE,S2017) ;
 N REQ2017,MTYPE
 S MTYPE=$$GET1^DIQ(52.49,CANREQ,.08,"I")
 I MTYPE="RE" S REQ2017=$$GET1^DIQ(52.49,CANREQ,312.1,"I")
 I $G(S2017),$G(REQ2017) D MEDDIS^PSOERXU7(CANREQ,.LINE) Q
 D MEDDIS^PSOERXU3(CANREQ,"D",.LINE)
 Q
 ;
DRUGCODE(PSOIEN,MEDIEN) ; Returns the Drug Code (Print format: e.g.: "NDC: 1939994449")
 N CODE,QUAL
 S CODE=$$GET1^DIQ(52.49311,MEDIEN_","_PSOIEN_",",1.1,"I")
 S QUAL=$$GET1^DIQ(52.49311,MEDIEN_","_PSOIEN_",",1.2,"E")
 S:QUAL="ND" QUAL="NDC"
 Q $S(CODE'="":QUAL_": "_CODE,1:"NDC:")
 Q