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

PSOORROC.m

Go to the documentation of this file.
PSOORROC ;BHAM-ISC/EJW,SAB - Remote Data Interoperability Order Checks ;05/28/08
 ;;7.0;OUTPATIENT PHARMACY;**251**;DEC 1997;Build 202
 ;
 ;External references to ^ORRDI1 supported by DBIA 4659
 ;External references to ^XTMP("ORRDI" supported by DBIA 4660
 ;External reference to ^PS(50.605 supported by DBIA 696
 ;External reference to ^PSDRUG supported by DBIA 221
 ;External reference to ^PS(56 supported by DBIA 2229
 ;External reference to ^PS(50.416 supported by DBIA 692
 ;External reference to DDIEX^PSNAPIS supported by DBIA 2574
REMOTE(PSODFN,DREN) ;
 ; Input: DFN: PATIENT file (#2) IEN
 ;      : DREN: DRUG file (#50) IEN of order being checked
 I $T(HAVEHDR^ORRDI1)']"" Q
 I '$$HAVEHDR^ORRDI1 Q
 I $D(^XTMP("ORRDI","OUTAGE INFO","DOWN")) Q
 N PSORDI,RDIINST,RDIVUID,RDIRX,RDIDNAM,RDISTA,RDISIG,RDIDAYS,RDIQTY,RDIFILL,RDIEXP,RDIISS,RDIFILL,RDIREF,RDIPHYS,PSOPROD,PSOCLASS,DRNM,RDITMP,PSODC,IT,PSOICT,NDF,RDIDI,PSOPRODA,PSOFILE,PSOSIG
 I '$G(DT) S DT=$$DT^XLFDT
 S PSORDI=0
 I $T(GET^ORRDI1)]"" S PSORDI=$$GET^ORRDI1(PSODFN,"PSOO")
 I PSORDI<1 Q
 I '$D(^XTMP("ORRDI","PSOO",PSODFN)) Q
 K ^TMP($J,"PSORDI")
 D PARSE,FILTER
 I '$D(^TMP($J,"PSORDI")) Q
 D DRGNAME ; GET VA PRODUCT FILE NAME FOR FILE 50 DRUG BEING CHECKED
 S PSORDI="" F  S PSORDI=$O(^TMP($J,"PSORDI",PSORDI)) Q:'PSORDI  S RDITMP=^(PSORDI) D
 .S RDIINST=$P(RDITMP,"^")
 .S RDIVUID=$P(RDITMP,"^",2)
 .I RDIVUID="" Q
 .S RDIDNAM=$P(RDITMP,"^",3)
 .S RDISTA=$P(RDITMP,"^",4)
 .S RDIRX=$P(RDITMP,"^",5)
 .S RDIFILL=$P(RDITMP,"^",6)
 .S RDIDAYS=$P(RDITMP,"^",7) I $E(RDIDAYS)="D" S RDIDAYS=$P(RDIDAYS,"D",2)
 .S RDIQTY=$P(RDITMP,"^",8)
 .S RDIREF=$P(RDITMP,"^",9)
 .S RDIEXP=$P(RDITMP,"^",10)
 .S RDIPHYS=$P(RDITMP,"^",11)
 .S RDIISS=$P(RDITMP,"^",12)
 .S DRNM=$G(PSODRUG("NAME"))
 .D GETPROD
 .I DRNM'="" I PSODRUG("NAME")=DRNM S DD=$G(DD)+1,^TMP($J,"DD",DD,0)=PSODRUG("IEN")_"^"_PSODRUG("NAME")_"^"_"^"_RDIRX_"R;O"_"^"_RDIINST D  Q:'$G(PSOPHI)
 ..S ^TMP($J,"DD",DD,1)=RDIDNAM_"^"_RDISTA_"^"_RDIFILL_"^"_RDIDAYS_"^"_RDIQTY_"^"_RDIREF_"^"_RDIEXP_"^"_RDIPHYS_"^"_RDIISS
 ..M ^TMP($J,"DD",DD,1)=^TMP($J,"PSORDI",PSORDI,"SIG")
 Q
 ;
PARSE ; PULL INFORMATION FROM ^XTMP
 N PSORDI,LOCAL,NEWISS,BADEXP,PSOPRE,PSO30,NEWDC,NEWEXP
 S PSORDI=0 F  S PSORDI=$O(^XTMP("ORRDI","PSOO",PSODFN,PSORDI)) Q:'PSORDI  D
 .S RDISTA=$G(^XTMP("ORRDI","PSOO",PSODFN,PSORDI,5,0))
 .I RDISTA="DELETED" Q
 .S RDIINST=$G(^XTMP("ORRDI","PSOO",PSODFN,PSORDI,1,0))
 .S RDIDNAM=$G(^XTMP("ORRDI","PSOO",PSODFN,PSORDI,2,0))
 .S RDIVUID=$G(^XTMP("ORRDI","PSOO",PSODFN,PSORDI,3,0))
 .I RDIVUID="" Q
 .S RDIRX=$G(^XTMP("ORRDI","PSOO",PSODFN,PSORDI,4,0))
 .S RDIQTY=$G(^XTMP("ORRDI","PSOO",PSODFN,PSORDI,6,0)),RDIDAYS=$P(RDIQTY,";",2),RDIQTY=$P(RDIQTY,";")
 .I $E(RDIDAYS)="D" S RDIDAYS=$P(RDIDAYS,"D",2)
 .S RDIEXP=$G(^XTMP("ORRDI","PSOO",PSODFN,PSORDI,7,0))
 .S RDIISS=$G(^XTMP("ORRDI","PSOO",PSODFN,PSORDI,8,0))
 .I RDIEXP?."/" S BADEXP=1 D  I BADEXP Q
 ..I RDIISS?."/" Q
 ..S PSOPRE=$E(DT) I $P(RDIISS,"/",3)>($E(DT,2,3)+1) S PSOPRE=PSOPRE-1
 ..S NEWISS=PSOPRE_$P(RDIISS,"/",3)_$P(RDIISS,"/")_$P(RDIISS,"/",2) I NEWISS>(DT-10000) S RDIEXP=RDIISS,BADEXP=0
 .I RDISTA["EXPIRE" S PSO30=0 D  I PSO30 Q
 ..S PSOPRE=$E(DT) I $P(RDIEXP,"/",3)>($E(DT,2,3)+1) S PSO30=1 Q
 ..S NEWEXP=PSOPRE_$P(RDIEXP,"/",3)_$P(RDIEXP,"/")_$P(RDIEXP,"/",2)
 ..S X1=NEWEXP,X2=30 D C^%DTC I X<DT S PSO30=1
 .I RDIRX'="" S LOCAL=0 D CHKLOCAL I LOCAL Q
 .S RDIFILL=$G(^XTMP("ORRDI","PSOO",PSODFN,PSORDI,9,0))
 .I RDISTA["DISCONT" S PSO30=0 D  I PSO30 Q
 ..S PSOPRE=$E(DT) I $P(RDIFILL,"/",3)>($E(DT,2,3)+1) S PSO30=1 Q
 ..S NEWDC=PSOPRE_$P(RDIFILL,"/",3)_$P(RDIFILL,"/")_$P(RDIFILL,"/",2)
 ..S X1=NEWDC,X2=30+RDIDAYS D C^%DTC I X<DT S PSO30=1
 .S RDIREF=$G(^XTMP("ORRDI","PSOO",PSODFN,PSORDI,10,0))
 .S RDIPHYS=$G(^XTMP("ORRDI","PSOO",PSODFN,PSORDI,11,0))
 .S PSOSIG="" F  S PSOSIG=$O(^XTMP("ORRDI","PSOO",PSODFN,PSORDI,14,PSOSIG)) Q:PSOSIG=""  S PSOSIG(PSOSIG)=^(PSOSIG)
 .S ^TMP($J,"PSORDI",PSORDI)=RDIINST_"^"_RDIVUID_"^"_RDIDNAM_"^"_RDISTA_"^"_RDIRX_"^"_RDIFILL_"^"_RDIDAYS_"^"_RDIQTY_"^"_RDIREF_"^"_RDIEXP_"^"_RDIPHYS_"^"_RDIISS
 .S PSOSIG="" F  S PSOSIG=$O(PSOSIG(PSOSIG)) Q:PSOSIG=""  S ^TMP($J,"PSORDI",PSORDI,"SIG",PSOSIG)=PSOSIG(PSOSIG)
 Q
 ;
CHKLOCAL ; IF SAME RX NUMBER AND ISSUE DATE - LOCAL RX
 N PSOISS
 I $D(^PSRX("B",RDIRX)) D
 .N PSORX
 .S PSORX=$O(^PSRX("B",RDIRX,"")) I 'PSORX Q
 .S PSOISS=$P($G(^PSRX(PSORX,0)),"^",13)
 .S PSOISS=$E(PSOISS,4,5)_"/"_$E(PSOISS,6,7)_"/"_$E(PSOISS,2,3)
 .I PSOISS=RDIISS S LOCAL=1 Q
 Q
 ;
VAPROD(PSOPROD) ; GET VA PRODUCT FILE NAME AND DRUG CLASS
 S PSOCLASS=$$DCLCODE^PSNAPIS(,PSOPROD)
 S DRNM=$P($$PROD0^PSNAPIS(,PSOPROD),"^")
 Q
 ;
DRGNAME ; 
 N PSOY
 S PSOY=DREN_"^"_$P($G(^PSDRUG(DREN,0)),"^"),PSOY(0)=$G(^PSDRUG(DREN,0))
 S PSODRUG("IEN")=+PSOY,PSODRUG("VA CLASS")=$P(PSOY(0),"^",2)
 S PSODRUG("NDF")=$S($G(^PSDRUG(+PSOY,"ND"))]"":+^("ND")_"A"_$P(^("ND"),"^",3),1:0)
 I PSODRUG("NDF")=0 Q
 S PSOPROD=$P(PSODRUG("NDF"),"A",2) I PSOPROD D VAPROD(PSOPROD) S PSODRUG("NAME")=DRNM
 Q
 ;
FILTER ; FOR SAME DRUG VUID FOR SAME SITE, KEEP 1 ENTRY - CHECK BY ACTIVE STATUS FIRST THEN BY GREATEST EXPIRATION DATE
 N XX,RDI,OLDEXP,RDIEXP,RDIEXP2,OLDEXP2,PSORDI,RDISTA,OLDSTA,OLDRDI,ZZ
 S PSORDI=0
 F  S PSORDI=$O(^TMP($J,"PSORDI",PSORDI)) Q:'PSORDI  D
 .S XX=$G(^TMP($J,"PSORDI",PSORDI)),RDIINST=$P(XX,"^"),RDIVUID=$P(XX,"^",2),RDISTA=$P(XX,"^",4),RDIEXP=$P(XX,"^",10) Q:RDIINST=""  Q:RDIVUID=""  I RDIEXP="" Q
 .I $D(RDI(RDIINST,RDIVUID)) S ZZ=RDI(RDIINST,RDIVUID) D  Q
 ..I RDISTA="ACTIVE"!(RDISTA["SUSPEN") D  Q
 ...S OLDSTA=$P(ZZ,"^",2) I OLDSTA["ACTIVE"!(OLDSTA["SUSPEN") D CHKEXP Q
 ...S OLDRDI=$P(ZZ,"^") K ^TMP($J,"PSORDI",OLDRDI) D SETRDI
 ..S OLDSTA=$P(ZZ,"^",2) I OLDSTA["ACTIVE"!(OLDSTA["SUSPEN") K ^TMP($J,"PSORDI",PSORDI) Q
 ..D CHKEXP ; ALL OTHER STATUSES - KEEP BY GREATER EXPIRATION DATE
 .D SETRDI
 Q
 ;
CHKEXP ; 
 N PSOPRE
 S OLDEXP=$P(ZZ,"^",3) D  I OLDEXP2>RDIEXP2 K ^TMP($J,"PSORDI",PSORDI) Q
 .S PSOPRE=$E(DT) I $P(RDIEXP,"/",3)>($E(DT,2,3)+1) S PSOPRE=PSOPRE-1
 .S RDIEXP2=PSOPRE_$P(RDIEXP,"/",3)_$P(RDIEXP,"/")_$P(RDIEXP,"/",2)
 .S PSOPRE=$E(DT) I $P(OLDEXP,"/",3)>($E(DT,2,3)+1) S PSOPRE=PSOPRE-1
 .S OLDEXP2=PSOPRE_$P(OLDEXP,"/",3)_$P(OLDEXP,"/")_$P(OLDEXP,"/",2)
 S OLDRDI=$P(ZZ,"^") K ^TMP($J,"PSORDI",OLDRDI) D SETRDI
 Q
 ;
SETRDI ;
 S RDI(RDIINST,RDIVUID)=PSORDI_"^"_RDISTA_"^"_RDIEXP
 Q
 ;
GETPROD ;
 S PSOFILE=50.68
 S DRNM="",PSOCLASS="",PSOPROD=0
 N PSOPR
 K PSOPRODA
 N DIC
 D GETIREF^XTID(PSOFILE,.01,RDIVUID,"PSOPRODA",1) I 'PSOPRODA Q
 S PSOPR="" F  S PSOPR=$O(PSOPRODA(PSOFILE,.01,PSOPR)) Q:PSOPR=""  D  Q:DRNM'=""  Q:PSOCLASS'=""
 .I +(PSOPRODA(PSOFILE,.01,PSOPR)) S PSOPROD=+PSOPR D VAPROD(PSOPROD) Q
 .I +(PSOPRODA(PSOFILE,.01,PSOPR))=0 I '$O(PSOPRODA(PSOFILE,.01,PSOPR)) S PSOPROD=+PSOPR D VAPROD(PSOPROD) ; USE LAST ENTRY IF ALL ARE INACTIVE
 Q
 ;
RDUP ;display Remote orders - duplicate drug
 N PSOD0,PSOD1,PSOREMX,RDIINST,FSIG,PSOULN,PSOLF,PSORDI
 S $P(PSOULN,"-",79)="",PSOT="DD"
 S PSORDI=0 F  S PSORDI=$O(^TMP($J,"DD",PSORDI)) Q:'PSORDI  S PSOD0=^TMP($J,"DD",PSORDI,0),PSOD1=^(1),PSOREMX=$P($P(PSOD0,"^",4),";"),RDIINST=$P(PSOD0,"^",5),PSOLF=$P(PSOD1,"^",3) D
 .W !,PSOULN,!,"Duplicate Drug in Remote Rx",!!
 .W "Remote Location "_RDIINST,!,$J("Rx #: ",20)_$E(PSOREMX,1,$L(PSOREMX)-1),!,$J("Drug: ",20)_$P(PSOD1,"^")
 .D FSIG^PSOORRD2(.FSIG)
 .W !,$J("SIG: ",20) F I=1:1 Q:'$D(FSIG(I))  W ?20,FSIG(I),!
 .W $J("QTY: ",20)_$P(PSOD1,"^",5),?44,$J("Refills remaining: ",20)_$P(PSOD1,"^",6)
 .W !,$J("Provider: ",20)_$P(PSOD1,"^",8),?44,$J("Issued: ",20)_$P(PSOD1,"^",9)
 .W !,$J("Status: ",20)_$P(PSOD1,"^",2),?44,$J("Last filled on: ",20)_PSOLF
 .W !?44,$J("Days Supply: ",20)_$P(PSOD1,"^",4)
 .K DIR W ! S DIR(0)="E",DIR("?")="Press Return to continue",DIR("A")="Press Return to continue..." D ^DIR W !
 K PSOT,DIR,X,Y
 Q