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

PSORRX2.m

Go to the documentation of this file.
PSORRX2 ;AITC/BWF - Remote RX driver ;8/30/16 12:00am
 ;;7.0;OUTPATIENT PHARMACY;**454,479,497,541,643,728**;DEC 1997;Build 5
 ;
 Q
 ; read response from refill site
READMSG(HLDAT,TYPE,LOCDRUG) ;
 H 3  ;*541 - WAIT TO ALLOW THE HOST SITE TO COMPLETE THE PROCESSING OF THE REFILL REQUEST AND SEND OVER THE LABEL INFO
 N ORFS,ORCS,ORRS,ORES,ORSS,HLQUIT,ORQUIT,OREMSG1,OREMSG2,ORSMSG,GBLLOC,LBLOOP,LBTXT,LBLOVF,DIR,ORERR,MSGDONE,MSGCNT,MSGTXT,PSORXMM,PSO59P02
 S ORFS="^",ORCS=$E($G(HL("ECH")),1),ORRS=$E($G(HL("ECH")),2),ORES=$E($G(HL("ECH")),3),ORSS=$E($G(HL("ECH")),4)
 S TYPE=$G(TYPE,"")
 S HLQUIT=0,ORQUIT="",OREMSG1="",OREMSG2="",ORERR=""
 F  X HLNEXT Q:HLQUIT'>0!(ORQUIT'="")  D
 .N LOOP
 .S LOOP=0 F  S LOOP=$O(HLNODE(LOOP)) Q:LOOP=""  S HLNODE=HLNODE_HLNODE(LOOP)
 .I $E(HLNODE,1,3)="MSA"&($P(HLNODE,ORFS,2)'="AA") S ORERR=$P(HLNODE,ORFS,4)
 .I $E(HLNODE,1,3)="ERR" S OREMSG1=$P(HLNODE,ORFS,9)
 .I $E(HLNODE,1,3)="NTE" D
 ..D REFNTE(.HLNODE,.HLDAT)
 ..S ORSMSG=$P(@HLDAT@(1),ORFS)
 .I $E(HLNODE,1,3)="PID" D
 ..S @HLDAT@(0)=$$FMADD^XLFDT($$NOW^XLFDT,2)_U_$$NOW^XLFDT
 ..D REFPID(.HLNODE,.HLDAT)
 .I $E(HLNODE,1,3)="ORC" D
 ..;;*541 ;COMPARE THE SELECTED RX# WITH THE RX# RETURNED IN THE HL7 RECORD - IF MATCHES, CONTINUE PROCESSING
 ..;IF THE RX#'S DO NOT MATCH, DISPLAY MESSAGE AND QUIT PROCESSING
 ..;SEND THIS INFO TO THE ERROR TRAP SO FURTHER RESEARCH CAN BE DONE TO FIND THE ROOT CAUSE OF THIS
 ..I $G(RRXNUM),$G(RRXNUM)'=$P($P(HLNODE,ORFS,3),ORCS) D     ;*541
 ...S ORERR="Label interrupted due to HL7 message corruption."  ;*541
 ...S ORERR(1)="Please request a Partial Fill in order to generate a reprint label."  ;541
 ...D APPERROR^%ZTER("MISMATCH RX")  ;*541
 ...S PSORXMM=1  ;*541
 ..I $G(PRXNUM),$G(PRXNUM)'=$P($P(HLNODE,ORFS,3),ORCS) D     ;*541
 ...S ORERR="Label interrupted due to HL7 message corruption."  ;*541
 ...S ORERR(1)="Please request a Partial Fill in order to generate a reprint label."  ;541
 ...D APPERROR^%ZTER("MISMATCH RX")  ;*541
 ...S PSORXMM=1  ;*541
 ..D REFORC(.HLNODE,.HLDAT,TYPE)
 .I $E(HLNODE,1,3)="RXD" D
 ..D REFRXD(.HLNODE,.HLDAT,TYPE)
 I '$L(ORERR),'$L(OREMSG1) D
 .I '$D(@HLDAT) S ORERR="No data was returned from the target vista." Q
 .I '$D(@HLDAT@("FLAG")) D MESS($S($G(PRXNUM):1,1:0))
 .W !!,"TRANSACTION SUCCESSFUL...  The "_$S($G(PRXNUM):"partial ",1:"refill ")_"for RX #"_RRXNUM_" has been recorded on"
 .W !,"the prescription at the host system."
 .W !!,"Select a printer to generate the label or '^' to bypass printing.",!
 .D LOGDATA^PSORWRAP(.HLDAT,TYPE,LOCDRUG,"",,$G(PSOHLSV("HOST RFIEN")),$G(PSOHLSV("HOST PARIEN")))
 I $L(ORERR) D
 . N PSOERR
 . K PSORRBLD  ; no need to rebuild worklist
 . I ORERR="Invalid Receiving Application" S ORERR="OneVA software not installed at host site"  ; This error is returned if patch is not installed at remote/host site.  Making it more user friendly.
 . W !!,ORERR
 . I $D(ORERR)=11 F PSOERR=1:1 W ! Q:'$D(ORERR(PSOERR))  W ORERR(PSOERR)  ;541
 . S DIR(0)="FO",DIR("A")="Press RETURN to continue"
 . D ^DIR
 . I $G(PSORXMM) D  ;*541
 .. W !!,"The "_$S($G(PRXNUM):"partial ",1:"refill ")_"for RX #"_RRXNUM_" has been recorded on the prescription"
 .. W !,"at the host system.",!
 .. D LOGDATA^PSORWRAP(.HLDAT,TYPE,LOCDRUG,"")
 I OREMSG1'="" D
 . K PSORRBLD  ; no need to rebuild worklist
 . W !!,OREMSG1_". "_$S($L(OREMSG2):OREMSG2_".",1:""),!
 . I '$D(ORSMSG) S DIR(0)="FO",DIR("A")="Press RETURN to continue" D ^DIR
 I $D(ORSMSG) D
 . I '$G(PSORXMM) D
 .. S MSGDONE=0
 .. F MSGCNT=1:1 D  Q:MSGDONE
 ... S MSGTXT=$P(ORSMSG,"|",MSGCNT) I MSGTXT']"" S MSGDONE=1 Q
 ... W !,MSGTXT
 .S DIR(0)="FO",DIR("A")="Press RETURN to continue" D ^DIR
 Q
 ; HLDAT(1)=MESSAGE^PATIENT DFN^RX NUMBER^REMOTE SITE#^FILL/PARTIAL DATE^PHARMACIST NAME^QUANTITY^DISPENSE DATE^DRUG NAME^DAYS SUPPLY
REFNTE(DATA,HLDAT) ;
 ; Message details
 N NTETYP,NTETEXT,NTETYPE,I,PSONRDAT,PSONR,PSONRNUM,PSONRTXT,PSOSUB,PSOSUBX
 S NTETYPE=$P(DATA,ORFS,3)
 S NTETEXT=$P(DATA,ORFS,4)
 I NTETYPE="L" D
 .I $L($P($G(@HLDAT@(1)),U)) S $P(@HLDAT@(1),U)=$P($G(@HLDAT@(1)),U)_"|"_NTETEXT Q
 .S $P(@HLDAT@(1),U)=NTETEXT
 I NTETYPE="O" D
 .S @HLDAT@("LBL",$O(@HLDAT@("LBL",""),-1)+1)=NTETEXT
 I NTETYPE="" D
 .I NTETEXT["PATCH INSTALLED FLAG" S @HLDAT@("FLAG",1)=NTETEXT Q
 .S @HLDAT@("NARR",$O(@HLDAT@("NARR",""),-1)+1)=NTETEXT
 Q
 ;
REFPID(DATA,HLDAT) ;
 ; patient IEN from remote site
 S $P(@HLDAT@(1),U,2)=$P($P($P(DATA,ORFS,4),ORCS,11),ORRS,2)
 Q
 ;
REFORC(DATA,HLDAT,TYPE) ;
 N RXNUM,RXSITE,RXDATE,PHARMLN,PHARMFN,REQSITE,PHONE,PHNAME,PNAME,RPDATE,RPROV
 S RXNUM=$P($P(DATA,ORFS,3),ORCS)
 S RXSITE=$P($P(DATA,ORFS,14),ORCS,4)
 S RPDATE=$P(DATA,ORFS,10)
 S RPROV=$P(DATA,ORFS,12)
 S PHNAME=$P(DATA,ORFS,11)
 S $P(@HLDAT@(1),U,3)=RXNUM
 S $P(@HLDAT@(1),U,4)=RXSITE
 S $P(@HLDAT@(1),U,5)=RPDATE
 S $P(@HLDAT@(1),U,6)=PHNAME
 S $P(@HLDAT@("RX0"),U)=RXNUM,$P(@HLDAT@("RX0"),U,2)=DFN,$P(@HLDAT@("RX0"),U,5)=$P($P($P(DATA,ORFS,22),ORCS,8),ORSS,2),$P(@HLDAT@("RX0"),U,6)=LOCDRUG
 S $P(@HLDAT@("RX0"),U,4)=$P($P($P(DATA,ORFS,20),ORRS,1),ORCS,2)
 S PSOHLSV("ORIG FILL DT")=$P(DATA,ORFS,15)
 S ($P(@HLDAT@("RX0"),U,13),PSOHLSV("ISSUED DT"))=$P(DATA,ORFS,16),$P(@HLDAT@("RX0"),U,19)=""
 ; don't forget copies in p18, if needed
 S $P(@HLDAT@("RX2"),U,2)=RPDATE,$P(@HLDAT@("RX2"),U,10)=$P($P($P(DATA,ORFS,20),ORRS,2),ORCS,2)
 S $P(@HLDAT@("RX3"),U)=$P(DATA,ORFS,28)
 I TYPE="RF" D
 .S $P(@HLDAT@("RREF0"),U)=RPDATE,$P(@HLDAT@("RREF0"),U,2)="W",$P(@HLDAT@("RREF0"),U,7)=$P($P($P(DATA,ORFS,20),ORRS,3),ORCS,2)
 .S $P(@HLDAT@("RREF0"),U,17)=$P($P($P(DATA,ORFS,20),ORRS,4),ORCS,2)
 I TYPE="PR" D
 .S $P(@HLDAT@("RPAR0"),U)=RPDATE,$P(@HLDAT@("RPAR0"),U,2)="W",$P(@HLDAT@("RPAR0"),U,7)=$P($P($P(DATA,ORFS,20),ORRS,3),ORCS,2)
 .S $P(@HLDAT@("RPAR0"),U,17)=$P($P($P(DATA,ORFS,20),ORRS,4),ORCS,2)
 S $P(@HLDAT@("ROR1"),U,5)=$P($P($P(DATA,ORFS,20),ORRS,5),ORCS,2)
 S @HLDAT@("RXSTA")=$P($P(DATA,ORFS,26),ORCS),@HLDAT@("RXSTA2")=$P($P(DATA,ORFS,26),ORCS,2)
 S @HLDAT@("PATST")=$P($P(DATA,ORFS,26),ORCS,4)
 ; HOST INFO
 ; P1 - NAME, P2 - ADDRESS~~CITY~STATE~ZIP, P3 - PHONE NUMBER, P4 - HOST SITE NUMBER
 S $P(DATA,ORFS,23)=$P($P(DATA,ORFS,23),ORSS)_ORSS_$P($P(DATA,ORFS,23),ORSS,3,5)
 S @HLDAT@("HINFO")=$P($P(DATA,ORFS,22),ORCS)_U_$P(DATA,ORFS,23)_U_$P(DATA,ORFS,24)
 S $P(@HLDAT@("HINFO"),U,4)=RXSITE
 S $P(@HLDAT@("HINFO"),U,5)=$P($P($P(DATA,ORFS,22),ORCS,8),ORSS,2)  ;Clinic
 S PSOHLSV("PROVIDER")=RPROV
 Q
REFRXD(DATA,HLDAT,TYPE)  ;
 N QTY,DSUPP,DNAME,HINFO,SIG1D,SIGDAT,SIGNUM,SIGTXT,I
 S ($P(@HLDAT@(1),U,7),$P(@HLDAT@("RX0"),U,7))=$P(DATA,ORFS,5)  ; quantity
 S $P(@HLDAT@(1),U,8)=$P(DATA,ORFS,4) ; dispense date
 S $P(@HLDAT@(1),U,9)=$P($P(DATA,ORFS,3),ORCS,1) ; drug name
 S ($P(@HLDAT@(1),U,10),$P(@HLDAT@("RX0"),U,8))=$P(DATA,ORFS,12) ; days supply
 S ($P(@HLDAT@("RX0"),U,9),PSOHLSV("# OF REFILLS"))=$P(DATA,ORFS,9),$P(@HLDAT@("RX0"),U,11)="W"
 S $P(@HLDAT@("RX0"),U,18)=$P(DATA,ORFS,23)  ; Copies
 S ($P(@HLDAT@("RX2"),U,6),PSOHLSV("EXP DT"))=$P(DATA,ORFS,20)  ; Rx Expiration Date 
 S PSOHLSV("ROUTING")="WINDOW" ;All OneVA fills are Window
 S PSOHLSV("CAP")=$P($P(DATA,ORFS,15),"~",2) ;Safety Cap
 S PSOHLSV("HOST RX LOG IEN")=$P($P(DATA,ORFS,8),":",5)
 S PSOHLSV("TOTAL FILLS")=PSOHLSV("# OF REFILLS")+1
 ;
 I TYPE="RF" D
 .S $P(@HLDAT@("RREF0"),U,4)=$P(DATA,ORFS,5),$P(@HLDAT@("RREF0"),U,10)=$P(DATA,ORFS,12)
 .S (@HLDAT@("RFIEN"),PSOHLSV("HOST RFIEN"))=$P($P(DATA,ORFS,8),":",3)
 I TYPE="PR" D
 .S $P(@HLDAT@("RPAR0"),U,4)=$P(DATA,ORFS,5),$P(@HLDAT@("RPAR0"),U,10)=$P(DATA,ORFS,12)
 .S (@HLDAT@("PARIEN"),PSOHLSV("HOST PARIEN"))=$P($P(DATA,ORFS,8),":",3)
 ;
 S @HLDAT@("RSIG")=$P($P($P(DATA,ORFS,16),ORRS,1),ORCS,2)_U_$P($P($P(DATA,ORFS,16),ORRS,1),ORCS)
 S @HLDAT@("RIEN")=$P($P(DATA,ORFS,8),":")
 ;I '$P($G(@HLDAT@("RSIG")),U,2) Q
 S SIG1D=0
 F I=2:1 D  Q:SIG1D
 .S SIGDAT=$P($P(DATA,ORFS,16),ORRS,I) I SIGDAT']"" S SIG1D=1 Q
 .S SIGNUM=$P(SIGDAT,ORCS),SIGNUM=$P(SIGNUM,"_",2),SIGTXT=$P(SIGDAT,ORCS,2) Q:'SIGNUM
 .S (@HLDAT@("RSIG1",SIGNUM),PSOHLSV("SIG",SIGNUM))=SIGTXT
 Q
PSORPH(DUZ) ;
 I $D(^XUSEC("PSORPH",DUZ)) Q 1
 Q 0
 ;
MESS(PSSMTYPE) ;
 N DIR,X,Y,DTOUT,DUOUT,DIRUT,DIROUT
 W !,"The OneVA "_$S(PSSMTYPE:"partial fill",1:"refill")_" cannot be sent to the Outpatient Pharmacy Automation"
 W !,"Interface (OPAI) to be filled by the Automated Dispensing Device (ADD)."
 w !,"Both your site and the remote site must have this capability available"
 W !,"at the same time. The remote site does not have this capability yet."
 W ! S DIR(0)="E",DIR("A")="Press Return to continue" D ^DIR K DIR W !
 Q