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

PSD79P.m

Go to the documentation of this file.
PSD79P ;DAL/RJS - PSD*3*79 DATA FIX ;8/15/12
 ;;3.0;DRUG ACCOUNTABILITY/INVENTORY INTERFACE;**79**;10/24/97;Build 20
 Q
EN ; POST INSTALL ENTRY POINT
 ;Identify and fix multiple Pharmacy Dispensing numbers assigned to a single request number in the Narcotics
 ;Area Of Use (NAOU) during order processing.
 S ZTDESC="CONTROLLED SUBSTANCES - PSD*3*79 POST INSTALL",ZTIO="",ZTDTH=$H,ZTRTN="START^PSD79P",ZTSAVE="" D ^%ZTLOAD
 D BMES^XPDUTL("PSD*3*79 POST INSTALL Task Queued!")
 K ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE
 Q
START ;
 K ^TMP($J,"PSD79P")
 N PSDPN,PSDTR,PSD81,PSDREQ,PSDNAOU,PSDRG,PSD8
 ; Gathering All entries in 58.81  (PSDPN: Pharmacy Dispensing #, PSDTR: Transaction IEN, PSDNAOU: NAOU, PSDREQ: Order Request #, PSDRG: Drug IEN)
 S PSDPN="" F  S PSDPN=$O(^PSD(58.81,"D",PSDPN)) Q:PSDPN=""  D
 .S PSDTR=0 F  S PSDTR=$O(^PSD(58.81,"D",PSDPN,PSDTR)) Q:'PSDTR  D
 ..S PSD81(0)=$G(^PSD(58.81,PSDTR,0)),PSDREQ=$P(PSD81(0),"^",20),PSDNAOU=$P(PSD81(0),"^",18),PSDRG=$P(PSD81(0),"^",5)
 ..I $G(PSDNAOU),$G(PSDRG),$G(PSDREQ) D
 ...S ^TMP($J,"PSD79P",PSDNAOU,PSDRG,PSDREQ,PSDTR)=""
 ...S ^TMP($J,"PSD79P",PSDNAOU,PSDRG,PSDREQ)=$G(^TMP($J,"PSD79P",PSDNAOU,PSDRG,PSDREQ))+1
 ;
 K ^TMP($J,"PSD79P1")
 ; Identifying entries with issue (missing 58.8 sub-file correspong record)
 S PSDNAOU=0 F  S PSDNAOU=$O(^TMP($J,"PSD79P",PSDNAOU)) Q:'PSDNAOU  D
 .S PSDRG=0 F  S PSDRG=$O(^TMP($J,"PSD79P",PSDNAOU,PSDRG)) Q:'PSDRG  D
 ..S PSDREQ=0 F  S PSDREQ=$O(^TMP($J,"PSD79P",PSDNAOU,PSDRG,PSDREQ)) Q:'PSDREQ  D
 ...I $G(^TMP($J,"PSD79P",PSDNAOU,PSDRG,PSDREQ))>1 D
 ....S PSDTR=0 F  S PSDTR=$O(^TMP($J,"PSD79P",PSDNAOU,PSDRG,PSDREQ,PSDTR)) Q:'PSDTR  D
 .....S PSD8(0)=$G(^PSD(58.8,PSDNAOU,1,PSDRG,3,PSDREQ,0)) I $P(PSD8(0),"^",17)="" Q
 .....I PSDTR'=$P(PSD8(0),"^",17) S ^TMP($J,"PSD79P1",PSDNAOU,PSDRG,PSDTR)=PSDREQ_"^"_$P(PSD8(0),"^",17)
 ;
 K ^TMP($J,"PSD79P2")
 ; Fixing entries with issue (missing 58.8 sub-file correspong record)
 S PSDNAOU=0 F  S PSDNAOU=$O(^TMP($J,"PSD79P1",PSDNAOU)) Q:'PSDNAOU  D
 .S PSDRG=0 F  S PSDRG=$O(^TMP($J,"PSD79P1",PSDNAOU,PSDRG)) Q:'PSDRG  D
 ..S PSDTR=0 F  S PSDTR=$O(^TMP($J,"PSD79P1",PSDNAOU,PSDRG,PSDTR)) Q:'PSDTR  D
 ...S PSDREQ=$P($G(^TMP($J,"PSD79P1",PSDNAOU,PSDRG,PSDTR)),"^",1),PSDTRN=$P($G(^TMP($J,"PSD79P1",PSDNAOU,PSDRG,PSDTR)),"^",2)
 ...S PSD81(0)=$G(^PSD(58.81,PSDTR,0)),PSDPN=$P(PSD81(0),"^",17),PSD81(1)=$G(^PSD(58.81,PSDTR,1))
 ...S PSD8(0)=$G(^PSD(58.8,PSDNAOU,1,PSDRG,3,PSDREQ,0)),PSDRQ=$P($G(^PSD(58.8,PSDNAOU,1,PSDRG,3,0)),"^",3)
 ...S PSDS=$P(PSD81(0),"^",3),PSDQTY=$P(PSD81(0),"^",6),PSDSTAT=$P(PSD81(0),"^",11),PSDMFR=$P(PSD81(0),"^",13)
 ...S PSDDDT=$P(PSD81(0),"^",4)
 ...S PSDLOT=$P(PSD81(0),"^",14),PSDXDT=$P(PSD81(0),"^",15),PSDCSTAT=$P(PSD81(0),"^",12),PSDCDT=$P(PSD81(0),"^",19)
 ...S PSDDBY=$P(PSD81(1),"^",1),PSDRBY=$P(PSD81(1),"^",3),PSDT=$P(PSD81(1),"^",6),PSDUZ=$P(PSD81(1),"^",7)
 ...S PSDRDT=$P(PSD81(1),"^",4),PSDRQTY=$P(PSD81(1),"^",8)
 ...D DIE
 ;
 ; Generating Mailman message with entries cleaned up or No transactions to report message
 K D,D0,DI,DIC,DQ,PSD8,PSD81,PSDA,PSDCDT,PSDCNT,PSDCSTAT,PSDDBY,PSDDDT,PSDLOT,PSDMFR,PSDNAOU,PSDPN
 K PSDQTY,PSDRBY,PSDRDT,PSDREQ,PSDRQ,PSDRQTY,PSDS,PSDSTAT,PSDT,PSDTR,PSDTRN,PSDUZ,PSDXDT,X
 I '$D(^TMP($J,"PSD79P1")) D NOMAIL,MAIL Q
 S PSDCNTR=1,PSDROU="PSD79PR",PSDLN="",$P(PSDLN,"=",80)=""
 K PSD1,PSD2 F PSD3=1:1 S PSD1=$T(HDR+PSD3) Q:PSD1[";;END"  S PSD2=$P(PSD1,";;",2),PSD2(PSD3,0)=PSD1,^TMP($J,PSDROU,PSDCNTR)=PSD2,PSDCNTR=PSDCNTR+1
 S ^TMP($J,PSDROU,PSDCNTR)="",PSDCNTR=PSDCNTR+1
 S PSDDAT="" D TXT("NAOU",0),TXT("Pharmacy",44),TXT("Transaction",55),TXT("Old",70),TXT("/",73),TXT("New",74)
 S ^TMP($J,PSDROU,PSDCNTR)=PSDDAT,PSDCNTR=PSDCNTR+1
 S PSDDAT="" D TXT("Drug Name",2),TXT("Dispensing #",43),TXT("Number",58),TXT("Request #",69)
 S ^TMP($J,PSDROU,PSDCNTR)=PSDDAT,PSDCNTR=PSDCNTR+1
 S ^TMP($J,PSDROU,PSDCNTR)=PSDLN,PSDCNTR=PSDCNTR+1
 S PSDNAOU=0 F  S PSDNAOU=$O(^TMP($J,"PSD79P2",PSDNAOU)) Q:'PSDNAOU  D
 .S PSDNAOUN=$P(^PSD(58.8,PSDNAOU,0),"^",1),^TMP($J,PSDROU,PSDCNTR)=PSDNAOUN,PSDCNTR=PSDCNTR+1
 .S PSDDRG=0 F  S PSDRG=$O(^TMP($J,"PSD79P2",PSDNAOU,PSDRG)) Q:'PSDRG  D
 ..S PSDFLG=0,PSDRGN=$P(^PSDRUG(PSDRG,0),"^",1) I $L(PSDRGN)>40 S PSDRGN=$E(PSDRGN,1,45)
 ..S PSDTR=0 F  S PSDTR=$O(^TMP($J,"PSD79P2",PSDNAOU,PSDRG,PSDTR)) Q:'PSDTR  D
 ...S:'PSDFLG PSDDAT="" D TXT(PSDRGN,2)
 ...S PSD0=$G(^TMP($J,"PSD79P2",PSDNAOU,PSDRG,PSDTR))
 ...S PSDPN1=$P(PSD0,"^",2),PSDRQ1=$P(PSD0,"^",1),PSDRQ2=$P(PSD0,"^",3)
 ...S PSDPN2=$P(PSD0,"^",5),PSDTR2=$P(PSD0,"^",4)
 ...S:PSDFLG PSDDAT="" D TXT(PSDPN1,45),TXT(PSDTR,57),TXT(PSDRQ2,(73-$L(PSDRQ2))),TXT("/",73),TXT(PSDRQ1,74)
 ...S ^TMP($J,PSDROU,PSDCNTR)=PSDDAT,PSDCNTR=PSDCNTR+1,PSDFLG=1
 ...S PSDDAT="" D TXT(PSDPN2,45),TXT(PSDTR2,57),TXT(PSDRQ2,(73-$L(PSDRQ2))),TXT("/",73),TXT("NA",74)
 ...S ^TMP($J,PSDROU,PSDCNTR)=PSDDAT,PSDCNTR=PSDCNTR+1
 ...S ^TMP($J,PSDROU,PSDCNTR)="",PSDCNTR=PSDCNTR+1 K PSDATA
 D MAIL
 ;
EXIT ;
 K PSD0,PSD3,PSDCNTR,PSDDAT,PSDDRG,PSDFLG,PSDLN,PSDNAOU,PSDNAOUN,PSDPN1,PSDPN2
 K PSDRG,PSDRGN,PSDROU,PSDRQ1,PSDRQ2,PSDTR,PSDTR2,XMDUN,XMDUZ,XMSUB,XMTEXT,XMY
 K ^TMP($J,"PSD79P"),^TMP($J,"PSD79P1"),^TMP($J,"PSD79P2"),^TMP($J,"PSD79PR")
 Q
DIE ;create the order request
 F  L +^PSD(58.8,PSDNAOU,1,PSDRG,0):$S($G(DILOCKTM)>0:DILOCKTM,1:3) I  Q
DIE2 S PSDA=$P(^PSD(58.8,PSDNAOU,1,PSDRG,3,0),"^",3)+1 I $D(^PSD(58.8,PSDNAOU,1,PSDRG,3,PSDA)) S $P(^PSD(58.8,PSDNAOU,1,PSDRG,3,0),"^",3)=$P(^PSD(58.8,PSDNAOU,1,PSDRG,3,0),"^",3)+1 G DIE2
 K DA,DIC,DIE,DD,DR,DO S DIC(0)="L",(DIC,DIE)="^PSD(58.8,"_PSDNAOU_",1,"_PSDRG_",3,",DA(2)=PSDNAOU,DA(1)=PSDRG,(X,DINUM)=PSDA D FILE^DICN K DIC
 S DA=PSDA,DA(1)=PSDRG,DA(2)=PSDNAOU,DR="1////"_PSDT_";2////"_+PSDS_";3////"_PSDUZ_";4////"_PSDDBY_";5////"_PSDQTY_";6////"_PSDRBY_";7////"_PSDMFR_";8////"_PSDLOT_";9////"_PSDXDT
 S DR=DR_";10////"_PSDSTAT_";11////"_PSDCSTAT_";12////"_PSDCDT_";14////"_PSDDDT_";15////"_PSDRDT_";16////"_PSDPN_";17////"_PSDTR_";19////"_PSDRQTY_";20////"_PSDQTY_";22////"
 D ^DIE K D,DA,DIE,DIC,DD,DR,DO,DINUM,X
 ;Saving Comments
 N TMP,COMM5881,COMM588 D GETS^DIQ(58.81,PSDTR_",","26","","TMP")
 M COMM5881=TMP(58.81,PSDTR_",",26)
 I $D(COMM5881(1)) D
 . S COMM588(58.800118,PSDA_","_PSDRG_","_PSDNAOU_",",13)="COMM5881"
 . D UPDATE^DIE("","COMM588")
 L -^PSD(58.8,PSDNAOU,1,PSDRG,0)
 F  L +^PSD(58.81,PSDTR,0):$S($G(DILOCKTM)>0:DILOCKTM,1:3) I  Q
 S DIE="^PSD(58.81,",DA=PSDTR,DR="40////"_PSDA
 D ^DIE K DIE,DR,DA
 L -^PSD(58.81,PSDTR,0)
 S ^TMP($J,"PSD79P2",PSDNAOU,PSDRG,PSDTR)=PSDA_"^"_PSDPN_"^"_PSDREQ_"^"_PSDTRN_"^"_$P(^PSD(58.8,PSDNAOU,1,PSDRG,3,PSDREQ,0),"^",16)
 Q
MAIL ;CREATE AND SEND MAIL
 N DIFROM
 S PSDCNTR=PSDCNTR+1,^TMP($J,PSDROU,PSDCNTR)="",PSDCNTR=PSDCNTR+1,^TMP($J,PSDROU,PSDCNTR)="***** End Of Report *****"
 S XMTEXT="^TMP($J,"""_PSDROU_""","
 N PSDUSR S PSDUSR=.5 F  S PSDUSR=$O(^XUSEC("PSDMGR",PSDUSR)) Q:'PSDUSR  S XMY(PSDUSR)=""
 S XMSUB="PSD*3*79 TRANSACTION REPORT",XMDUZ="PSD*3*79 POST INSTALL"
 D ^XMD
 Q
NOMAIL ;
 S PSDCNTR=1,PSDROU="PSD79PR",PSDLN="",$P(PSDLN,"=",80)=""
 S ^TMP($J,PSDROU,PSDCNTR)="",PSDCNTR=PSDCNTR+1
 S ^TMP($J,PSDROU,PSDCNTR)="THERE WERE NO TRANSACTIONS TO REPORT."
 Q
TXT(PSDVAL,PSDCOL) S:'$D(PSDDAT) PSDDAT="" S PSDDAT=$$SETSTR^VALM1(PSDVAL,PSDDAT,PSDCOL,$L(PSDVAL)) Q
 Q
HDR ; MAILMAN REPORT INTRODUCTION
 ;;  This report contains Controlled Substance drugs that assigned multiple 
 ;;  Pharmacy Dispensing numbers to a single request number in the Narcotics
 ;;  Area Of Use (NAOU) during order processing.
 ;;
 ;;  These transactions have been identified and corrected.
 ;;END