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

ABSPOSEX.m

Go to the documentation of this file.
ABSPOSEX ; IHS/OIT/SCR - PATIENT EXPENSE gereration routine ; [ 10/24/2005 10:09:07 AM ]
 ;;1.0;PHARMACY POINT OF SALE;**30,34,36**;JUN 21, 2001;Build 38
 ;
 Q
MAIN ;EP
 N ABSPPNAM,ABSPPIEN,ABSPPINF,ABSPPHRM,ABSPRXDT,ABSPARRY,ABSPDOB,ABSPDONE,ABSPTMP,ABSPPHRN,ABSPEND
 N ABSPPDOB,ABSPQUIT,ABSPSDAT,ABSPSDAT,ABSPSTRT,ABSPEND,ABSPPRMI,ABSPFROM,ABSPTO,ABSPPROV
 N ABSPDTOT,ABSPDINS,ABSPDDUE,ABSPGTOT,ABSPGINS,ABSPGDUE ;IHS/OIT/SCR 082509 patch 34
 N IO ;IHS/OIT/SCR 011110 patch 36
 D AUTO^ABSPOSM1()
 S ABSPDONE=0
 S ABSPQUIT=0
 S ABSPPINF=$$GETPAT
 Q:ABSPPINF<1
 S ABSPPIEN=$P(ABSPPINF,U,1)  ;VA(200 patient IEN
 S ABSPPNAM=$P(ABSPPINF,U,2)  ;VA(200 patient name
 S ABSPPDOB=$$DOB^AUPNPAT(ABSPPIEN,"E")
 S ABSPPHRN=$$HRN^AUPNPAT(ABSPPIEN,DUZ(2))
 F  Q:ABSPDONE=1  D
 .S ABSPSTRT=$$BDT()
 .I ABSPSTRT=-1 D
 ..S ABSPQUIT=1
 ..S ABSPDONE=1
 ..Q
 .Q:ABSPQUIT
 .S ABSPEND=$$EDT()
 .I ABSPEND=-1 D
 ..S ABSPQUIT=1
 ..S ABSPDONE=1
 ..Q
 .Q:ABSPQUIT
 .I ABSPSTRT<0 S ABSPDONE=1 Q
 .I ABSPEND<0 S ABSPDONE=1 Q
 .S X2=ABSPSTRT,X1=ABSPEND D ^%DTC
 .I X<0 D EN^DDIOL("Ending Date is BEFORE Beginning Date Please enter new dates","","!!,*7")
 .I X>=0 S ABSPDONE=1
 .Q
 Q:ABSPQUIT
 D DEVSEL  ;IHS/OIT/SCR 011110 patch 36 NEEDS TO COME BEFORE FIND TO KEEP LOCAL VARIABLES
 D FIND(ABSPSTRT,ABSPEND,ABSPPIEN,.ABSPTMP)
 S ABSPSDAT=""
 S Y=ABSPSTRT D DD^%DT S ABSPFROM=Y
 S Y=ABSPEND D DD^%DT S ABSPTO=Y
 ;D DEVSEL  ;IHS/OIT/SCR 011110 patch 36 start changes
 I $O(ABSPTMP(""))="" D  Q
 .D ^%ZISC
 .W !,"NO TRANSACTIONS FOUND FOR THIS DATE RANGE"
 .Q
 U IO
 W @IOF ;IHS/OIT/SCR 011110 patch 36 end changes
 W !,"PATIENT: "_ABSPPNAM_"   DOB: "_ABSPPDOB_"    HRN: "_ABSPPHRN
 W !?15,"     PHARMACY RELEASE DATES FROM "_ABSPFROM_" TO "_ABSPTO
 S ABSPGTOT=0,ABSPGINS=0,ABSPGDUE=0  ;IHS/OIT/SCR 082509 patch 34
 F  S ABSPSDAT=$O(ABSPTMP(ABSPSDAT)) Q:ABSPSDAT=""  D
 .Q:ABSPTMP(ABSPSDAT)=""
 .S Y=ABSPSDAT D DD^%DT
 .W !!?10,"RELEASE DATE: "_Y
 .S ABSPPHRM=""
 .F  S ABSPPHRM=$O(ABSPTMP(ABSPSDAT,ABSPPHRM)) Q:ABSPPHRM=""  D
 ..S ABSPDTOT=0,ABSPDINS=0,ABSPDDUE=0  ;IHS/OIT/SCR 082509 patch 34
 ..W !!?8,"PHARMACY: "_$P($G(^ABSP(9002313.56,ABSPPHRM,0)),"^",1)
 ..S ABSPPRMI=""
 ..F  S ABSPPRMI=$O(ABSPTMP(ABSPSDAT,ABSPPHRM,ABSPPRMI)) Q:ABSPPRMI=""  D
 ...W !!,"RX #/REFILL: `"_ABSPPRMI_"/"_$P(ABSPTMP(ABSPSDAT,ABSPPHRM,ABSPPRMI),U,1)
 ...S Y=$P(ABSPTMP(ABSPSDAT,ABSPPHRM,ABSPPRMI),"^",2) D DD^%DT
 ...W !?0,"TRANSACTION DATE: "_Y,?40,"TRANSACTION TYPE: "_$P(ABSPTMP(ABSPSDAT,ABSPPHRM,ABSPPRMI),"^",4)
 ...W !?5,"DRUG NAME: "_$P(ABSPTMP(ABSPSDAT,ABSPPHRM,ABSPPRMI),"^",5),?50,"NDC#: "_$P(ABSPTMP(ABSPSDAT,ABSPPHRM,ABSPPRMI),"^",6)
 ...W !?5,"QTY: "_$P(ABSPTMP(ABSPSDAT,ABSPPHRM,ABSPPRMI),"^",9),?50,"D/S: "_$P(ABSPTMP(ABSPSDAT,ABSPPHRM,ABSPPRMI),"^",10)
 ...S ABSPPROV=$P(ABSPTMP(ABSPSDAT,ABSPPHRM,ABSPPRMI),"^",7)
 ...W !?5,"PROVIDER NAME: "_$P(^VA(200,ABSPPROV,0),"^",1),?50,"PROVIDER NPI#: "_$P(ABSPTMP(ABSPSDAT,ABSPPHRM,ABSPPRMI),"^",8)
 ...W !?0,"TOTAL PRICE: "_$P(ABSPTMP(ABSPSDAT,ABSPPHRM,ABSPPRMI),"^",11),?25,"INSURER PAID: "_$P(ABSPTMP(ABSPSDAT,ABSPPHRM,ABSPPRMI),"^",12),?53,"AMOUNT DUE: "_$P(ABSPTMP(ABSPSDAT,ABSPPHRM,ABSPPRMI),"^",13)
 ...;IHS/OIT/SCR 082509 patch 34 START CHANGES
 ...S ABSPDTOT=ABSPDTOT+$P(ABSPTMP(ABSPSDAT,ABSPPHRM,ABSPPRMI),"^",11)
 ...S ABSPDINS=ABSPDINS+$P(ABSPTMP(ABSPSDAT,ABSPPHRM,ABSPPRMI),"^",12)
 ...S ABSPDDUE=ABSPDDUE+$P(ABSPTMP(ABSPSDAT,ABSPPHRM,ABSPPRMI),"^",13)
 ..Q
 .W !!,?0,"TOTAL FOR DATE: "_ABSPDTOT,?25,"INS PAID FOR DATE: "_ABSPDINS,?53,"DUE FOR DATE: "_ABSPDDUE
 .S ABSPGTOT=ABSPGTOT+ABSPDTOT
 .S ABSPGINS=ABSPGINS+ABSPDINS
 .S ABSPGDUE=ABSPGDUE+ABSPDDUE
 .Q
 ;IHS/OIT/SCR 082509 patch 34 END CHANGES
 W !!,?0,"GRAND TOTAL: "_ABSPGTOT,?25,"TOTAL INS PAID: "_ABSPGINS,?53,"TOTAL DUE: "_ABSPGDUE
 D ^%ZISC  ;IHS/OIT/SCR 1/4/10 patch 36 close the device that was opened
 Q
FIND(ABSPSTRT,ABSPEND,ABSPPIEN,ABSPTMP) ; FIND PRESCRIPTIONS FOR THIS PATIENT IN A DATE RANGE 
 N ABSPDONE,ABSPRDT,ABSPPHRM,ABSPRMI,ABSPCTYP,ABSPDAT,ABSPTRXI,ABSPDRGP,ABSPDRGN,ABSPNDC,ABSPPROV
 N ABSPPNPI,ABSPQTY,ABSPDAYS,ABSPCPAY,ABSPDAYS,ABSPTDAT,ABSPDONE,ABSPCTYN,ABSPTPAT,ABSPTRNS,ABSPRXR,ABSPRXN
 N ABSPRESP,ABSPPSTN,ABSPNET,RESP
 S ABSPRDT=ABSPSTRT-1
 S ABSPDONE=0
 S ABSPRMI=""
 F  S ABSPRDT=$O(^ABSPECX("RPT","B",ABSPRDT)) Q:ABSPRDT=""!ABSPDONE  D
 .I ABSPRDT>ABSPEND S ABSPDONE=1 Q
 .F  S ABSPRMI=$O(^ABSPECX("RPT","B",ABSPRDT,ABSPRMI)) Q:ABSPRMI'=+ABSPRMI  D
 ..S ABSPTRNS=$P(^ABSPECX("RPT",ABSPRMI,0),U,3)
 ..Q:ABSPTRNS=""
 ..S ABSPTPAT=$P(^ABSPTL(ABSPTRNS,0),U,6) ;TRANSACTION PATIENT
 ..Q:ABSPTPAT'=ABSPPIEN  ;NOT SELECTED PATIENT
 ..S ABSPPHRM=$P(^ABSPTL(ABSPTRNS,1),U,7)
 ..S:ABSPPHRM="" ABSPPHRM=0   ;IHS/OIT/SCR 010410 patch 36
 ..S ABSPCTYP=$P(^ABSPECX("RPT",ABSPRMI,0),U,6)
 ..;S ABSPRICE=$P(^ABSPTL(ABSPTRNS,5),U,5) IHS/OIT/SCR 010420 patch 36
 ..S ABSPRICE=$P($G(^ABSPTL(ABSPTRNS,5)),U,5)
 ..S ABSPRESP=$P(^ABSPTL(ABSPTRNS,0),U,5)  ;POINTER TO RESPONSE FILE
 ..S ABSPPSTN=$P(^ABSPTL(ABSPTRNS,0),U,9)  ;POSITION IN CLAIM
 ..S ABSPTDAT=$P(^ABSPECX("RPT",ABSPRMI,0),U,2) ;TRANSACTION LAST UPDATE
 ..S ABSPTRXI=$P(^ABSPECX("RPT",ABSPRMI,0),U,4) ;POINTER TO PRESCRIPTION FILE
 ..S ABSPCTYN=""
 ..S ABSPNET=0
 ..I ABSPCTYP=1 D
 ...S ABSPCTYN="REJECTED"
 ...S ABSPPAID=0
 ...S ABSPCPAY=ABSPRICE
 ...Q
 ..I ABSPCTYP=4 D
 ...S ABSPCTYN="E PAYABLE"
 ...Q:ABSPRESP=""
 ...Q:ABSPPSTN=""
 ...S ABSPCPAY=$$505^ABSPOS03(ABSPRESP,ABSPPSTN) ;PATIENT PAY AMOUNT
 ...S ABSPPAID=$$509^ABSPOS03(ABSPRESP,ABSPPSTN) ;(#509) Total Amount Paid
 ...Q
 ..I ABSPCTYP=9 D
 ...S ABSPCTYN="PAPER"
 ...S ABSPPAID=0
 ...S ABSPCPAY=ABSPRICE
 ...Q
 ..Q:ABSPCTYN=""
 ..S ABSPTRXR=$P(^ABSPECX("RPT",ABSPRMI,0),U,5) ;REFILL NUMBER
 ..S ABSPTRXN=$P($G(^PSRX(ABSPTRXI,0)),U,1)  ;EXTERNAL PRESCRIPTION NUMBER
 ..S ABSPDRGP=$P($G(^PSRX(ABSPTRXI,0)),U,6) ;POINTER TO DRUG FILE
 ..S ABSPDRGN=$P(^PSDRUG(ABSPDRGP,0),U,1) ;DRUG NAME
 ..S ABSPDSYN=$P(^PSDRUG(ABSPDRGP,0),U,1) ;DRUG NAME
 ..S ABSPNDC=$P(^ABSPTL(ABSPTRNS,1),U,2)  ;NDC NUMBER
 ..S ABSPPROV=$P(^PSRX(ABSPTRXI,0),U,4) ;POINTER TO NEW PERSON FILE (PROVIDER)
 ..S ABSPPNPI=$P($$NPI^XUSNPI("Individual_ID",ABSPPROV),U)  ;PROVIDER NPI
 ..S ABSPQTY=$P(^PSRX(ABSPTRXI,0),U,7) ;PRESCRIPTION QUANTITY
 ..S ABSPDAYS=$P(^PSRX(ABSPTRXI,0),U,8) ;PRESCRIPTION DAYS SUPPLY
 ..S ABSPCPAY=$FNUMBER(ABSPCPAY,"",2)
 ..S ABSPPAID=$FNUMBER(ABSPPAID,"",2)
 ..S ABSPRICE=$FNUMBER(ABSPRICE,"",2)
 ..S ABSPTMP(ABSPRDT)=1
 ..S ABSPTMP(ABSPRDT,ABSPPHRM,ABSPTRXI)=ABSPTRXR_"^"_ABSPTDAT_"^"_ABSPCTYP_"^"_ABSPCTYN_"^"_ABSPDRGN_"^"_ABSPNDC_"^"_ABSPPROV_"^"_ABSPPNPI_"^"_ABSPQTY_"^"_ABSPDAYS_"^"_ABSPRICE_"^"_ABSPPAID_"^"_ABSPCPAY
 ..Q
 .Q
 Q
GETPAT() ;Prompt the user for which patient they would like to generate an E1 for
 N ABSPDUZ2,ABSPDONE,Y,DIC
 S ABSPDONE=0   ;set to one when we are done prompting
 S Y=0
 S ABSPDUZ2=+$G(DUZ(2)),DUZ(2)=0
 S DIC=2,DIC(0)="AEMQZ"
 S DIC("A")="Generate A patient expense report for which Patient? "
 F  D  Q:ABSPDONE
 . D ^DIC
 . S:(($G(DUOUT))!($G(DTOUT))!(Y>0)!(X="")) ABSPDONE=1
 K DIC
 S DUZ(2)=ABSPDUZ2
 Q Y
GETPHARM() ;when more than one pharmacy is set up for this site, prompt
 ; for which one to use
 N ABSPHARM,ABSPHLDP,Y,ABSPDONE,ABSPHCNT,DIC
 S (ABSPHCNT,ABSPDONE,PHARM,Y)=0   ;initialize beginning variables
 F  S ABSPHARM=$O(^ABSP(9002313.56,PHARM)) Q:'+ABSPHARM  D
 . S ABSPHCNT=ABSPHCNT+1
 . S:ABSPHCNT=1 ABSPHLDP=ABSPHARM
 Q:ABSPHCNT=1 ABSPHLDP
 W !!
 S DIC=9002313.56,DIC(0)="AEMQZ"
 S DIC("B")=$P($G(^ABSP(9002313.56,ABSPHLDP,0)),U)
 S DIC("A")="Please specify the pharmacy: "
 F  D  Q:ABSPDONE
 . D ^DIC
 . S:(($G(DUOUT))!($G(DTOUT))!(Y>0)) ABSPDONE=1
 Q +Y
BDT()  ; ENTER BEGINING DATE
 N ABSPBDT,DIR,X1,X
 W !
 K DIR
 S DIR(0)="DEX"
 S DIR("A")="Enter Beginning Prescription Release Date"
 D ^DIR
 I $D(DIRUT) Q -1
 S ABSPBDT=+Y
 S X1=ABSPBDT D C^%DTC
 Q X
EDT()  ; ENTER END DATE
 N ABSPEDT,DIR,X1,X
 W !
 K DIR
 S DIR(0)="DEX"
 S DIR("A")="Enter Ending Prescription Release Date"
 D ^DIR
 I $D(DIRUT) Q -1
 S ABSPEDT=+Y
 S X1=ABSPEDT D C^%DTC
 Q X
DEVSEL ; SELECT DEVICE
 N ABSPSTOP
 S ABSPSTOP=0
 D ^%ZIS
 I POP D
 .D ^%ZIS
 .Q
 I $D(DUOUT) D
  .D ^%ZISC
  .S ABSPSTOP=1
  .Q
 Q:ABSPSTOP
 I POP D
 .W "DEVICE UNAVAILABLE" G DEVSEL
 Q
ZEND  ; CLOSE DEVICE
 D ^%ZISC
 Q