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

PSOERSE5.m

Go to the documentation of this file.
PSOERSE5 ;ALB/RM - PSO eRx UTILITIES ;Feb 12, 2024@12:43:34
 ;;7.0;OUTPATIENT PHARMACY;**746**;DEC 16, 1997;Build 106
 ;
 ;
 Q  ;No Direct Call
 ;
QTSUMDT1(TMPGBL,PSOIEN,MTYPE,CHGMESRI,CHGMESRQ,RESPVAL,LINE) ; Quit Summary Detail early?
 N FLG,NO311,RULE
 D
 . S FLG=0
 . I MTYPE="CX",RESPVAL?1"APPROVED".1" WITH CHANGES",",G,T,S,OS,D,"[(","_CHGMESRI_",") D  Q
 . . S FLG=1,RULE=0
 . S RULE=$$GETRULES^PSOERX1D(PSOIEN,MTYPE,RESPVAL,CHGMESRI,0)
 . S FLG=(RULE?1(1"1058",1"1059",1"1060",1"1043",1"1056"))
 I FLG S FLG=$$SETMRC(TMPGBL,PSOIEN,CHGMESRI,CHGMESRQ,RESPVAL,RULE,.LINE)
 Q FLG
 ;
SETMRC(TMPGBL,PSOIEN,CHGMESRI,CHGMESRQ,RESPVAL,RULE,LINE) ; Set values for MRC variables
 N CHGMESRE,CHMSSUB,I,IENS,NO311,NOTEARY,RET,X,REATXT
 S CHGMESRE=$$GET1^DIQ(52.45,CHGMESRQ,.02,"I")
 S @TMPGBL@(LINE,0)="Change Request Type: "_CHGMESRE
 I (CHGMESRI="U")!(CHGMESRI="D") D
 . S IENS=$O(^PS(52.49,PSOIEN,316,0))
 . I IENS D
 . . S IENS=IENS_","_PSOIEN_","
 . . S CHMSSUB=$$GET1^DIQ(52.49316,IENS,1,"I")
 . . S CHMSSUB=$$GET1^DIQ(52.45,CHMSSUB,.02,"E")
 . I 'IENS S CHMSSUB=""
 . K NOTEARY
 . D TXT2ARY^PSOERXD1(.NOTEARY,CHMSSUB," ",55)
 . I $D(NOTEARY) D
 . . S I=0
 . . F  S I=$O(NOTEARY(I)) Q:'I  D
 . . . S LINE=LINE+1 S @TMPGBL@(LINE,0)=$S(I=1:"Change Request Sub Type: ",1:$J("",25))_NOTEARY(I)
 . I '$D(NOTEARY) D
 . . S LINE=LINE+1 S @TMPGBL@(LINE,0)="Change Request Sub Type: "
 ;
 S X=$$GET1^DIQ(52.49,PSOIEN,317,,"REATXT")
 I $G(REATXT(1))'="" D
 . S X=REATXT(1) K RET D TXT2ARY^PSOERXD1(.RET,X," ",80)
 . S LINE=LINE+1 S @TMPGBL@(LINE,0)="Change Request Reason Text: "
 . S I=0 F  S I=$O(RET(I)) Q:I=""  S LINE=LINE+1 S @TMPGBL@(LINE,0)=RET(I)
 I RULE?1(1"1058",1"1059",1"1060") S NO311='$D(^PS(52.49,PSOIEN,311))
 I RULE'?1(1"1058",1"1059",1"1060") S NO311=0
 I $G(NO311) D RESTSMDT(TMPGBL,1,PSOIEN,RESPVAL,RULE,.LINE)
 Q $G(NO311)
 ;
RESTSMDT(TMPGBL,SMALLMP,PSOIEN,RESPVAL,RULE,LINE) ; Print rest of Summary/Details screen for CXD - G/T/S/OS/D
 N CHGMESRQ,FLG,STATUS
 I SMALLMP D MEDPRES(TMPGBL,PSOIEN,.LINE)
 I 'SMALLMP D:((RESPVAL="VALIDATED")&($$GET1^DIQ(52.49,PSOIEN,.08,"I")="CX"))
 . D DISPRX^PSOERSE4
 S CHGMESRQ=$$GET1^DIQ(52.49,PSOIEN,315.1,"I")
 D CXRES(TMPGBL,PSOIEN,RESPVAL,RULE,"1058,1059,1060,0",.LINE)
 D MEDREQDR(TMPGBL,PSOIEN,RULE,.LINE)
 D CXREQ(TMPGBL,PSOIEN,RULE,.LINE)
 D MSGHIS(TMPGBL,PSOIEN,.LINE)
 Q
 ;
MEDPRES(TMPGBL,PSOIEN,LINE) ; Medication Prescribed
 I @TMPGBL@(LINE,0)'="" S LINE=LINE+1 S @TMPGBL@(LINE,0)=""
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="**************************MEDICATION PRESCRIBED******************************"
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="No Medication information available on the Response."
 Q
 ;
CXRES(TMPGBL,ERXIEN,RESPVAL,RULE,RULES,LINE) ;
 N CODEIEN,COMM,COMMARY,COMMBY,COMMDTTM,DATE,DELTA,DRCVGST,ERESCODE,ERXDAT,FLG,FN,I
 N ID,IENS,IENS2,J,MIEN,MTYPE,NOTE,NOTEARY,PRIAUTH,PRAUTHST,RECODE,REQIEN,RESCODE
 N RESDESC,RESDTTM,RESIEN,RESTEXT,RESVAL,SFIEN,STATUS,STR1,STR1ARY,STR2,STR2ARY
 N TXT,XLINE
 I (","_RULES_",")[(","_$E(RULE,1,4)_",") D
 .S RESIEN=ERXIEN,REQIEN=$$RESOLV^PSOERXU2(ERXIEN)
 .S FLG=1
 I (","_RULES_",")'[(","_$E(RULE,1,4)_",") D
 .S MTYPE=$$GET1^DIQ(52.49,ERXIEN,.08,"I")
 .I MTYPE="CR" D  Q
 ..S RESIEN=$$GETRESP^PSOERXU2(ERXIEN)
 ..I RESIEN D  Q
 ...S REQIEN=ERXIEN
 ...S FLG=1
 ..S FLG=0
 .S FLG=0
 Q:'FLG
 S IENS=RESIEN_","
 D GETS^DIQ(52.49,RESIEN,".03;50;50.1;50.2;52.1;52.2;319.5;324","IE","ERXDAT")
 S RESDTTM=$G(ERXDAT(52.49,IENS,.03,"E"))
 S RESVAL=$G(ERXDAT(52.49,IENS,52.1,"E"))
 S RESCODE=$G(ERXDAT(52.49,IENS,52.1,"I"))
 S NOTE=$G(ERXDAT(52.49,IENS,52.2,"E"))
 S ID=$G(ERXDAT(52.49,IENS,319.5,"E"))
 S DATE=$G(ERXDAT(52.49,IENS,324,"I"))
 I $D(^PS(52.49,ERXIEN,311)) D
 . S SFIEN=$O(^PS(52.49,ERXIEN,311,"C","P",0))
 . Q:'SFIEN
 . S IENS2=SFIEN_","_IENS
 . D GETS^DIQ(52.49311,IENS2,"4.1;4.2;5","IE","ERXDAT")
 . S PRIAUTH=$G(ERXDAT(52.49311,IENS2,4.1,"E"))
 . S PRAUTHST=$G(ERXDAT(52.49311,IENS2,4.2,"E"))
 . S I=$O(^PS(52.49,RESIEN,311,SFIEN,7,0))
 . I I D
 . . S DRCVGST=$$GET1^DIQ(52.493117,I_","_IENS2,.02,"I")
 . . S DRCVGST=$$GET1^DIQ(52.45,DRCVGST,.02,"E")
 . I 'I S DRCVGST=""
 . F I="PRIAUTH","PRAUTHST","DRCVGST" S:@I="" @I=" "
 I '$D(^PS(52.49,ERXIEN,311)) S (PRIAUTH,PRAUTHST,DRCVGST)=" "
 S LINE=LINE+1 S @TMPGBL@(LINE,0)=""
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="*************************RXCHANGE RESPONSE INFORMATION**************************"
 S LINE=LINE+1 S @TMPGBL@(LINE,0)=RESVAL
 S @TMPGBL@(LINE,0)="Response Date/Time: "_RESDTTM
 I NOTE]"" D
 . K NOTEARY
 . D TXT2ARY^PSOERXD1(.NOTEARY,NOTE," ",74)
 . S I=0 F  S I=$O(NOTEARY(I)) Q:'I  D
 . . S LINE=LINE+1 S @TMPGBL@(LINE,0)=$S(I=1:"Note: ",1:$J("",6))_NOTEARY(I)
 S LINE=LINE+1 S @TMPGBL@(LINE,0)=""
 I RESPVAL="APPROVED" D
 . S XLINE=LINE
 . S @TMPGBL@(LINE,0)="Prior Authorization: "_PRIAUTH
 . S @TMPGBL@(LINE,0)="Prior Authorization Status: "_PRAUTHST
 . K NOTEARY D TXT2ARY^PSOERXD1(.NOTEARY,DRCVGST," ",58)
 . I $D(NOTEARY) D
 . . S I=0 F  S I=$O(NOTEARY(I)) Q:'I  D
 . . . S TXT=$S(I=1:"Drug Coverage Status: ",1:$J("",22))_NOTEARY(I)
 . . . S LINE=LINE+1 S @TMPGBL@(LINE,0)=TXT
 . I '$D(NOTEARY) S LINE=LINE+1 S @TMPGBL@(LINE,0)="Drug Coverage Status:"
 . I LINE>XLINE S LINE=LINE+1 S @TMPGBL@(LINE,0)=""
 I RESPVAL="VALIDATED" D
 . S XLINE=LINE
 . S @TMPGBL@(LINE,0)="ID: "_ID
 . S @TMPGBL@(LINE,0)="Date: "_DATE
 . I LINE>XLINE S LINE=LINE+1 S @TMPGBL@(LINE,0)=""
 S COMM=$$GET1^DIQ(52.49,RESIEN,50,"E")
 K COMMARY D TXT2ARY^PSOERXD1(.COMMARY,COMM," ",52)
 I $D(COMMARY) D
 . S I=0 F  S I=$O(COMMARY(I)) Q:'I  D
 . . S TXT=$S(I=1:"RxChange Response Comments: ",1:$J("",28))_COMMARY(I)
 . . S LINE=LINE+1 S @TMPGBL@(LINE,0)=TXT
 I '$D(COMMARY) D
 . S LINE=LINE+1 S @TMPGBL@(LINE,0)="RxChange Response Comments:"
 S COMMBY=$$GET1^DIQ(52.49,RESIEN,50.1,"E")
 S COMMDTTM=$$GET1^DIQ(52.49,RESIEN,50.2,"E")
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="Comments By: "_COMMBY
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="Comments Date/Time: "_COMMDTTM
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="" S XLINE=LINE
 S I=0 F  S I=$O(^PS(52.49,RESIEN,55,I)) Q:'I  D
 . S ERESCODE=$$GET1^DIQ(52.4955,I_","_IENS,.01,"E")
 . S CODEIEN=$$GET1^DIQ(52.4955,I_","_IENS,.01,"I")
 . S RESDESC=$$GET1^DIQ(52.45,CODEIEN,.02,"E")
 . S FLG=0
 . I RESPVAL="DENIED" S FLG=1
 . I FLG D
 . . S RESTEXT=RESVAL_" reason code: "_ERESCODE
 . . S LINE=LINE+1 S @TMPGBL@(LINE,0)=RESTEXT
 . . S @TMPGBL@(LINE,0)="Code Description: "_RESDESC
 I XLINE<LINE S LINE=LINE+1 S @TMPGBL@(LINE,0)=""
 Q
 ;
MEDREQDR(TMPGBL,PSOIEN,RULE,LINE) ; Medication Requested section driver
 N CNT,F,I,IENS,REQIEN
 S CNT=0,REQIEN=$S(RULE?1(1"1058",1"1061",1"0"):$$RESOLV^PSOERXU2(PSOIEN),1:PSOIEN)
 S I=0
 F  S I=$O(^PS(52.49,REQIEN,311,I)) Q:'I  D
 . S F=52.49311,IENS=I_","_REQIEN_","
 . D GETS^DIQ(F,IENS,"**","IE","DDAT")
 . I $G(DDAT(F,IENS,.02,"I"))="R" D  ; Only requested medications
 . . S CNT=CNT+1
 . . D MEDREQ(TMPGBL,REQIEN,F,IENS,I,.LINE,CNT)
 . K DDAT
 Q
 ;
MEDREQ(TMPGBL,REQIEN,F,IENS,IEN311,LINE,CNT) ; Medication Request section
 N DAYSUP,DRUG,FND,I,LTXT,NOTE,NOTEARY,QTY,QUOM,REFILL,SIG,SUB,TXT,SIGDATA,SIGARY
 S DRUG=$G(DDAT(F,IENS,.03,"E"))
 S SUB=$G(DDAT(F,IENS,2.7,"I"))
 S SUB=$S(SUB=1:"NO",SUB=0:"YES",1:"")
 S NOTE=$G(DDAT(F,IENS,5,"E"))
 S QTY=$G(DDAT(F,IENS,2.1,"E"))
 S REFILL=$G(DDAT(F,IENS,2.8,"E"))
 S DAYSUP=$G(DDAT(F,IENS,2.4,"E"))
 S QUOM=$G(DDAT(F,IENS,2.3,"I"))
 S QUOM=$$GET1^DIQ(52.45,QUOM,.02,"E")
 S LINE=LINE+1 S @TMPGBL@(LINE,0)=""
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="****************************MEDICATION REQUESTED "_CNT_"****************************"
 K NOTEARY
 D TXT2ARY^PSOERXD1(.NOTEARY,DRUG_" "_$P($$ERXDRSCH^PSOERXUT(ERXIEN),"^",2)," ",74)
 S I=0 F  S I=$O(NOTEARY(I)) Q:'I  D
 .S LINE=LINE+1 S @TMPGBL@(LINE,0)=$S(I=1:"Drug: ",1:$J("",6))_NOTEARY(I)
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="Substitutions: "_SUB
 D NOTE(TMPGBL,NOTE,"Note: ",1,.LINE)
 S LTXT=""
 D ADDITEM^PSOERX1A(.LTXT,"Qty: ",QTY,1,22)
 D ADDITEM^PSOERX1A(.LTXT,"Refills: ",REFILL,23,21)
 D ADDITEM^PSOERX1A(.LTXT,"Days Supply: ",DAYSUP,44,37)
 S LINE=LINE+1 S @TMPGBL@(LINE,0)=LTXT
 I QUOM="" D
 . S LINE=LINE+1 S @TMPGBL@(LINE,0)="Quantity Unit Of Measure:"
 I QUOM]"" D
 .K NOTEARY
 .D TXT2ARY^PSOERXD1(.NOTEARY,QUOM," ",54)
 .S I=0 F  S I=$O(NOTEARY(I)) Q:'I  D
 ..S TXT=$S(I=1:"Quantity Unit Of Measure: ",1:$J("",26))_NOTEARY(I)
 ..S LINE=LINE+1 S @TMPGBL@(LINE,0)=TXT
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="Sig: "
 S SIGDATA=""
 S I=0 F  S I=$O(^PS(52.49,REQIEN,311,IEN311,8,I)) Q:'I  D
 . S SIGDATA=SIGDATA_^PS(52.49,REQIEN,311,IEN311,8,I,0)_" "
 I $G(SIGDATA)'="" D
 . K SIGARY D TXT2ARY^PSOERXD1(.SIGARY,SIGDATA," ",80)
 . S I=0 F  S I=$O(SIGARY(I)) Q:I=""  D
 . . I I=1 S @TMPGBL@(LINE,0)=@TMPGBL@(LINE,0)_SIGARY(I) Q
 . . S LINE=LINE+1 S @TMPGBL@(LINE,0)=$J("",5)_SIGARY(I)
 S LINE=LINE+1 S @TMPGBL@(LINE,0)=""
 Q
 ;
NOTE(TMPGBL,STR,TITLE,REQUIRED,LINE) ; Print possibly multi-line comment
 N I,LEN,NOTEARY
 S LEN=$L(TITLE)
 D TXT2ARY^PSOERXD1(.NOTEARY,STR," ",80-LEN)
 I $D(NOTEARY) D
 . S I=0 F  S I=$O(NOTEARY(I)) Q:'I  D
 . . S LINE=LINE+1 S @TMPGBL@(LINE,0)=$S(I=1:TITLE,1:$J("",LEN))_NOTEARY(I)
 I '$D(NOTEARY) D:REQUIRED
 . S LINE=LINE+1 S @TMPGBL@(LINE,0)=TITLE
 Q
 ;
 ; rxchange request information
CXREQ(TMPGBL,ERXIEN,RULE,LINE) ;
 N COMM,COMMARY,COMMBY,COMMDTTM,CTXT,I,REQBY,REQDTTM,REQIEN
 ; - the next line of code will actually reference the related message of the rxchange request information
 ; - check that this is correct and test.
 S REQIEN=$S(RULE?1(1"1058",1"1059",1"1060",1"1061",1"1062".E,1"0"):$$RESOLV^PSOERXU2(ERXIEN),1:ERXIEN)
 S REQBY=$$GET1^DIQ(52.49,REQIEN,51.1,"E")
 S REQDTTM=$$GET1^DIQ(52.49,REQIEN,.03,"E")
 S COMM=$$GET1^DIQ(52.49,REQIEN,50,"E")
 S LINE=LINE+1 S @TMPGBL@(LINE,0)=""
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="************************RXCHANGE REQUEST INFORMATION**************************"
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="Requested By: "_REQBY
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="Request Date/Time: "_REQDTTM
 S LINE=LINE+1 S @TMPGBL@(LINE,0)=""
 K COMMARY D TXT2ARY^PSOERXD1(.COMMARY,COMM," ",53)
 I $D(COMMARY) D
 . S I=0 F  S I=$O(COMMARY(I)) Q:'I  D
 . .S CTXT=$S(I=1:"RxChange Request Comments: ",1:$J("",27))_COMMARY(I)
 . . S LINE=LINE+1 S @TMPGBL@(LINE,0)=CTXT
 I '$D(COMMARY) D
 . S LINE=LINE+1 S @TMPGBL@(LINE,0)="RxChange Request Comments:"
 S COMMBY=$$GET1^DIQ(52.49,REQIEN,50.1,"E")
 S COMMDTTM=$$GET1^DIQ(52.49,REQIEN,50.2,"E")
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="Comments By: "_COMMBY
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="Comments Date/Time: "_COMMDTTM
 Q
 ;
MSGHIS(TMPGBL,ERXIEN,LINE) ;
 N FLAG
 S FLAG=+$G(FLAG)
 N ERXREF,RELERX,ERXRES,I,ERXHID,FOUND,REQID,RESID,MTYPE
 S MTYPE=$$GET1^DIQ(52.49,ERXIEN,.08,"I")
 I ",CR,"[(","_MTYPE_",") S REQIEN=ERXIEN,RESIEN=$$GETRESP^PSOERXU2(ERXIEN)
 I ",CX,"[(","_MTYPE_",") S RESIEN=ERXIEN,REQIEN=$$RESOLV^PSOERXU2(ERXIEN)
 I MTYPE="IE" S RESIEN=ERXIEN,REQIEN=$$RESOLV^PSOERXU2(ERXIEN)
 S RESID=$$GET1^DIQ(52.49,RESIEN,.01,"E")
 S REQID=$$GET1^DIQ(52.49,REQIEN,.01,"E")
 S RELERX=$$GET1^DIQ(52.49,REQIEN,.14)
 S FOUND=0
 S I=ERXIEN F  S I=$O(^PS(52.49,ERXIEN,201,"B",I)) Q:'I!(FOUND)  D
 .I $$GET1^DIQ(52.49,I,.08,"E")="RE",$$GET1^DIQ(52.49,I,.14,"E")=$$GET1^DIQ(52.49,ERXIEN,.01,"E") S ERXRES=$$GET1^DIQ(52.49,I,.14,"E"),FOUND=1
 S LINE=LINE+1 S @TMPGBL@(LINE,0)=""
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="*****************************MESSAGE HISTORY********************************"
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="Request Reference #: "_$G(REQID)
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="New eRx Reference #: "_RELERX
 S LINE=LINE+1 S @TMPGBL@(LINE,0)="Response eRx Reference #: "_$G(RESID)
 Q
QTSUMDT2(TMPGBL,PSOIEN,MTYPE,CHGMESRI,RESPVAL,LINE) ; Quit Summary Detail later?
 N FLG,RULE
 D
 . S FLG=0
 . I MTYPE="CX",RESPVAL?1"APPROVED".1" WITH CHANGES",",G,T,S,OS,D,"[(","_CHGMESRI_",") D  Q
 . . S FLG=1,RULE=0
 . S RULE=$$GETRULES^PSOERX1D(PSOIEN,MTYPE,RESPVAL,CHGMESRI,0)
 . S FLG=RULE?1(1"1058",1"1059",1"1060",1"1043",1"1056")
 I FLG D RESTSMDT(TMPGBL,0,PSOIEN,RESPVAL,RULE,.LINE)
 Q FLG
 ;