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

FBAAIAR1.m

Go to the documentation of this file.
  1. FBAAIAR1 ;ALB/FA - FEE IPAC Vendor DoD Invoice Number Inquiry Report ;1/16/2014
  1. ;;3.5;FEE BASIS;**123**;JAN 30, 1995;Build 51
  1. ;;Per VA Directive 6402, this routine should not be modified.
  1. ;
  1. ;
  1. ;-----------------------------------------------------------------------------
  1. ; Entry Points
  1. ; EN - DoD Invoice Inquiry Report - Run report
  1. ;-----------------------------------------------------------------------------
  1. ;
  1. Q
  1. ;
  1. EN ;EP
  1. ; Main report entry point
  1. N FBDODINV,FBFORMAT
  1. Q:'$$DODISEL(.FBDODINV) ; Select DoD Invoice number
  1. Q:'$$FORMAT(.FBFORMAT) ; Select Report Format
  1. Q:$$DEVICE(FBDODINV,FBFORMAT) ; Select Device and compile report
  1. Q
  1. ;
  1. DODISEL(FBDODINV) ; Ask for the DoD Invoice
  1. ; Input: None
  1. ; Output: FBDODINV - Selected DoD Invoice Number
  1. ; Returns: 1 - User quit out, 0 otherwise
  1. ; Called From: EN
  1. ;
  1. N DIR,DIROUT,DIRUT,DTOUT,DUOUT,RET,X,Y
  1. S RET=1 ; Assume DoD Invoice Selection
  1. W @IOF,!,"IPAC Vendor DoD Invoice Number Inquiry Report"
  1. W !!,"This report will display all of the VistA invoices for the "
  1. W !,"selected DoD Invoice Number."
  1. W !
  1. S DIR(0)="F^3:22"
  1. S DIR("A")="DoD Invoice Number"
  1. S DIR("?",1)="All of the associated VistA invoices will be displayed for the"
  1. S DIR("?",2)="selected DoD invoice number"
  1. W ! D ^DIR K DIR
  1. I $D(DIRUT)!(Y="") D
  1. . S RET=0 ; User wants to exit
  1. . W *7
  1. S FBDODINV=Y ; Selected DoD Invoice number
  1. Q RET
  1. ;
  1. FORMAT(FBFORMAT) ; Capture the report format from the user (normal or CSV output)
  1. ; Input: None
  1. ; Output: FBFORMAT - 1 - CSV Format, 0 otherwise
  1. ; Returns: 0 - User quit out, 1 otherwise
  1. ; Called From: EN
  1. ;
  1. N DIR,DIROUT,DIRUT,DTOUT,DUOUT,RET,X,Y
  1. S RET=1
  1. S DIR(0)="Y"
  1. S DIR("A")="Do you want to capture the output in a CSV format"
  1. S DIR("B")="NO"
  1. S DIR("?",1)="If you want to capture the output from this report in a comma-separated"
  1. S DIR("?",2)="values (CSV) format, then answer YES here. A CSV format is something that"
  1. S DIR("?",3)="could be easily imported into a spreadsheet program like Excel."
  1. S DIR("?",4)=" "
  1. S DIR("?")="If you just want a normal report output, then answer NO here."
  1. W ! D ^DIR K DIR
  1. I $D(DIRUT) D
  1. . S RET=0 ; User wants to exit
  1. . W *7
  1. S FBFORMAT=Y
  1. Q RET
  1. ;
  1. DEVICE(FBDODINV,FBFORMAT) ; Device Selection and Report compilation
  1. ; Input: FBDODINV - DoD invoice number to compile VistA invoices for
  1. ; FBFORMAT - 1 - CSV Format, 0 otherwise
  1. ; Output: Report is compiled if a device is selected
  1. ; Returns: 1 - User quit out, 0 otherwise
  1. ; Called From: EN
  1. N DIR,POP,RET,X,Y,ZTDESC,ZTRTN,ZTSAVE,ZTSK
  1. S RET=1
  1. I 'FBFORMAT D
  1. . W !!,"This report is 80 characters wide. Please choose an appropriate device.",!
  1. E D
  1. . W !!,"For CSV output, turn logging or capture on now."
  1. . W !,"To avoid undesired wrapping of the data saved to the file,"
  1. . W !,"please enter ""0;256;99999"" at the ""DEVICE:"" prompt.",!
  1. ;
  1. S ZTRTN="COMPILE^FBAAIAR1"
  1. S ZTDESC="Fee Basis IPAC Vendor DoD Invoice Inquiry Report"
  1. S ZTSAVE("FBDODINV")=""
  1. S ZTSAVE("FBFORMAT")=""
  1. D EN^XUTMDEVQ(ZTRTN,ZTDESC,.ZTSAVE,"QM",1)
  1. S:POP RET=0
  1. I $G(ZTSK) D
  1. . W !!,"Report compilation has started with task# ",ZTSK,".",!
  1. . S DIR(0)="E"
  1. . D ^DIR
  1. Q RET
  1. ;
  1. COMPILE ; Entry point for the compile to build the scratch global
  1. ; may be background task if job queued
  1. ; Input: FBDODINV - DoD Invoice number to use for selection
  1. ; FBFORMAT - 1 - CSV format, 0 otherwise
  1. ; Output: Report is compiled and output
  1. ; Called From: Report processing
  1. ;
  1. K ^TMP("FBAAIAR1",$J)
  1. I '$D(ZTQUEUED) W !!,"Compiling IPAC Vendor DoD Invoice Inquiry Report. Please wait ... "
  1. D COMPOUT(FBDODINV) ; Compile Outpatient invoices
  1. D COMPIN(FBDODINV) ; Compile Inpatient invoices
  1. D COMPRX(FBDODINV) ; Compile Pharmacy invoices
  1. ;
  1. D PRINT^FBAAIAR2(FBDODINV,FBFORMAT) ; Print report
  1. D ^%ZISC ; Close the device
  1. K ^TMP("FBAAIAR1",$J) ; Kill scratch global
  1. S:$D(ZTQUEUED) ZTREQ="@" ; Purge the task
  1. Q
  1. ;
  1. COMPOUT(FBDODINV) ; Compile Outpatient and Inpatient Ancillary Invoice data
  1. ; Input: FBDODINV - DoD Invoice number to use for selection
  1. ; Output: VistA invoices for the selected DoD invoice number are
  1. ; added to the temporary global
  1. ; Called From: COMPILE
  1. ;
  1. N DATA,IDTIEN,PATIEN,SVCIEN,VENIEN,VNAME
  1. S PATIEN=""
  1. F D Q:PATIEN="" ; Patient IEN
  1. . S PATIEN=$O(^FBAAC("DODI",FBDODINV,PATIEN))
  1. . Q:PATIEN=""
  1. . S VENIEN=""
  1. . F D Q:VENIEN="" ; Vendor IEN
  1. . . S VENIEN=$O(^FBAAC("DODI",FBDODINV,PATIEN,VENIEN))
  1. . . Q:VENIEN=""
  1. . . S VNAME=$P($G(^FBAAV(VENIEN,0)),U,1) ; Vendor Name
  1. . . S IDTIEN=""
  1. . . F D Q:IDTIEN="" ; Initial Service Date IEN
  1. . . . S IDTIEN=$O(^FBAAC("DODI",FBDODINV,PATIEN,VENIEN,IDTIEN))
  1. . . . Q:IDTIEN=""
  1. . . . S SVCIEN=""
  1. . . . F D Q:SVCIEN="" ; Service Provided IEN
  1. . . . . S SVCIEN=$O(^FBAAC("DODI",FBDODINV,PATIEN,VENIEN,IDTIEN,SVCIEN))
  1. . . . . Q:SVCIEN=""
  1. . . . . ;
  1. . . . . ; Store the row data for the invoice into the temporary global
  1. . . . . D ROWDATAO(VNAME,PATIEN,VENIEN,IDTIEN,SVCIEN)
  1. Q
  1. ;
  1. ROWDATAO(VNAME,PATIEN,VENIEN,IDTIEN,SVCIEN) ;
  1. ; Retrieves the information needed to display the VistA invoice row for an
  1. ; outpatient invoice or an Inpatient Ancillary invoice.
  1. ; Input: VNAME - Vendor Name of the Invoice
  1. ; PATIEN - Patient IEN
  1. ; VENIEN - Vendor IEN of the invoice
  1. ; IDTIEN - Internal Initial Treatment Date IEN
  1. ; SVCIEN - Invoice IEN
  1. ; ^TMP("FAAIAR1",$J) - Current temporary file
  1. ; Output: ^TMP("FAAIAR1",$J) - Updated with VistA Invoice data
  1. ; Called From: COMPOUT
  1. ;
  1. N DATA,INV0,INV2,INV3,INVNUM,TYPE,XX
  1. S INV0=$G(^FBAAC(PATIEN,1,VENIEN,1,IDTIEN,1,SVCIEN,0)) ; Outpatient Invoice 0 Node
  1. S INV2=$G(^FBAAC(PATIEN,1,VENIEN,1,IDTIEN,1,SVCIEN,2)) ; Outpatient Invoice 2 Node
  1. S INV3=$G(^FBAAC(PATIEN,1,VENIEN,1,IDTIEN,1,SVCIEN,3)) ; Outpatient Invoice 3 Node
  1. S INVNUM=$P(INV0,U,16) ; VistA Invoice #
  1. S ITYPE=+$P(INV0,U,9) ; Fee Program ptr
  1. S ITYPE=$S(ITYPE=2:0,1:1) ; 0 - Outpatient, 1: Inpatient Ancillary
  1. S TYPE=$S('ITYPE:"OUT",1:"ANC")
  1. S DATA=$$GETTYPEO(PATIEN,VENIEN,IDTIEN,SVCIEN,INV0,INV2) ; Void/Purge/Cancel flags
  1. S $P(DATA,U,2)=$P(INV0,U,14) ; Date Paid
  1. S $P(DATA,U,3)=$P(INV0,U,2) ; Amount Claimed
  1. S $P(DATA,U,4)=$P(INV0,U,3) ; Amount Paid
  1. S $P(DATA,U,5)=$P(INV0,U,4) ; Amount Adjusted
  1. S XX=IDTIEN_"-"_SVCIEN
  1. S ^TMP("FBAAIAR1",$J,VNAME,TYPE,INVNUM,XX)=DATA ; VistA invoice data for the invoice
  1. D TOTS(VNAME,TYPE,INVNUM,DATA) ; Gather totals for invoice
  1. Q
  1. ;
  1. GETTYPEO(PATIEN,VENIEN,IDTIEN,SVCIEN,INV0,INV2) ; Determines if the invoice has been
  1. ; cancelled, rejected, purged or voided or some combination
  1. ; Input: PATIEN - Patient IEN
  1. ; VENIEN - Vendor IEN
  1. ; IDTIEN - Initial Treatment Date IEN
  1. ; SVCIEN - Service Provided IEN
  1. ; INV0 - 0 node of the outpatient invoice
  1. ; INV2 - 2 node of the outpatient invoice
  1. ; Returns: V - Voided
  1. ; C - Cancelled
  1. ; R - Rejected
  1. ; P - Purged
  1. ; "" - Otherwise
  1. ; or any combination of C/V/R/P
  1. ; Called From: ROWDATAO
  1. N VAL
  1. S VAL=""
  1. S:$D(^FBAAC(PATIEN,1,VENIEN,1,IDTIEN,1,SVCIEN,"FBREJC")) VAL="R" ; Rejected
  1. S:$D(^FBAAC(PATIEN,"PURGE",VENIEN,0)) VAL=VAL_"P" ; Purged
  1. S:$P(INV2,U,4)'="" VAL=VAL_"C" ; Cancelled
  1. S:$P(INV0,U,21)'="" VAL=VAL_"V" ; Voided
  1. Q VAL
  1. ;
  1. COMPIN(FBDODINV) ; Compile Inpatient Invoice data
  1. ; Input: FBDODINV - DoD Invoice number to use for selection
  1. ; ^TMP("FAAIAR1",$J) - Current temporary file
  1. ; Output: ^TMP("FAAIAR1",$J) - Updated with VistA Invoice data
  1. ; Called From: COMPILE
  1. ;
  1. N DATA,INIEN,INVNUM,INV0,INV2,INV5,ITYPE,VNAME,XX
  1. S INIEN=""
  1. F D Q:INIEN="" ; Inpatient Invoice by DoD Invoice #
  1. . S INIEN=$O(^FBAAI("DODI",FBDODINV,INIEN))
  1. . Q:INIEN=""
  1. . S INV0=$G(^FBAAI(INIEN,0))
  1. . S INV2=$G(^FBAAI(INIEN,2))
  1. . S INV5=$G(^FBAAI(INIEN,5))
  1. . S XX=+$P(INV0,U,3) ; Vendor IEN
  1. . S VNAME=$P($G(^FBAAV(XX,0)),U,1) ; Vendor Name
  1. . S INVNUM=$P(INV0,U,1) ; VistA Invoice #
  1. . S DATA=$$GETTYPEI(INIEN,INV0,INV2) ; Type of Record
  1. . S $P(DATA,U,2)=$P(INV2,U,1) ; Date Paid
  1. . S $P(DATA,U,3)=$P(INV0,U,8) ; Amount Claimed
  1. . S $P(DATA,U,4)=$P(INV0,U,9) ; Amount Paid
  1. . S $P(DATA,U,5)=$P(INV0,U,10) ; Amount Adjusted
  1. . S ^TMP("FBAAIAR1",$J,VNAME,"INP",INVNUM,0)=DATA ; VistA invoice data for invoice
  1. . D TOTS(VNAME,"INP",INVNUM,DATA) ; Gather totals for invoice
  1. Q
  1. ;
  1. GETTYPEI(INVIEN,INV0,INV2) ; Determines if the inpatient invoice has been
  1. ; cancelled, rejected or voided or some combination
  1. ; Input: INVIEN - IEN of the inpatient invoice
  1. ; INV0 - 0 node of the inpatient invoice
  1. ; INV2 - 2 node of the inpatient invoice
  1. ; INV5 - 5 node of the inpatient invoice
  1. ; Returns: V - Voided
  1. ; C - Cancelled
  1. ; R - Rejected
  1. ; "" - Otherwise
  1. ; or any combination of C/V/R
  1. ; Called From: COMPIN
  1. N VAL
  1. S VAL=""
  1. S:$D(^FBAAI(INVIEN,"FBREJ")) VAL="R" ; Rejected
  1. S:$P(INV2,U,5)'="" VAL=VAL_"C" ; Cancelled
  1. S:$P(INV0,U,14)'="" VAL=VAL_"V" ; Voided
  1. Q VAL
  1. ;
  1. COMPRX(FBDODINV) ; Compile Pharmacy invoice data
  1. ; Input: FBDODINV - DoD Invoice number to use for selection
  1. ; ^TMP("FAAIAR1",$J) - Current temporary file
  1. ; Output: ^TMP("FAAIAR1",$J) - Updated with VistA Invoice data
  1. ; Called From: COMPILE
  1. ;
  1. N AMTA,AMTC,AMTP,DATA,DATEP,INVNUM,INV0,INV2,ITYPE,ITYPE2
  1. N PHIEN,RXIEN,RXINV,VNAME,XX
  1. S PHIEN="",DATEP="",ITYPE2=""
  1. F D Q:PHIEN="" ; Pharmacy Invoice by DoD Invoice #
  1. . S PHIEN=$O(^FBAA(162.1,"DODI",FBDODINV,PHIEN))
  1. . Q:PHIEN=""
  1. . S (AMTA,AMTC,AMTP)=0 ; Init amount tots for invoice
  1. . S RXINV=$G(^FBAA(162.1,PHIEN,0)) ; Invoice level data
  1. . S XX=+$P(RXINV,U,4) ; Vendor IEN
  1. . S VNAME=$P($G(^FBAAV(XX,0)),U,1) ; Vendor name
  1. . S INVNUM=$P(RXINV,U,1) ; VistA Invoice #
  1. . S RXIEN=""
  1. . F D Q:RXIEN="" ; Prescription level
  1. . . S RXIEN=$O(^FBAA(162.1,"DODI",FBDODINV,PHIEN,RXIEN))
  1. . . Q:RXIEN=""
  1. . . S INV0=$G(^FBAA(162.1,PHIEN,"RX",RXIEN,0)) ; Prescription 0 Node
  1. . . S INV2=$G(^FBAA(162.1,PHIEN,"RX",RXIEN,2)) ; Prescription 2 Node
  1. . . D GETTYPEP(PHIEN,RXIEN,INV2,.ITYPE2) ; Type of Pharmacy Record
  1. . . S XX=$P(INV2,U,8) ; Date Paid
  1. . . S DATEP=$S(DATEP="":XX,XX<DATEP:XX,1:DATEP) ; Find the lowest date paid
  1. . . S AMTC=AMTC+$P(INV0,U,4) ; Amount Claimed
  1. . . S AMTP=AMTP+$P(INV0,U,16) ; Amount Paid
  1. . . S AMTA=AMTA+$P(INV0,U,7) ; Amount Adjusted
  1. . S DATA=ITYPE2 ; Pharmacy Invoice Void/Cancel/Reject
  1. . S $P(DATA,U,2)=DATEP ; Lowest date paid
  1. . S $P(DATA,U,3)=AMTC ; Total Amount claimed for Invoice
  1. . S $P(DATA,U,4)=AMTP ; Total Amount paid for Invoice
  1. . S $P(DATA,U,5)=AMTA ; Total Amount adjusted for Invoice
  1. . S ^TMP("FBAAIAR1",$J,VNAME,"RX",INVNUM,0)=DATA ; VistA invoice data for invoice
  1. . D TOTS(VNAME,"RX",INVNUM,DATA) ; Gather totals for DoD invoice#
  1. Q
  1. ;
  1. GETTYPEP(PHIEN,RXIEN,INV2,ITYPE) ; Determines if the pharmacy invoice has any
  1. ; cancelled, rejected or voided prescriptions.
  1. ; Input: PHIEN - IEN of the pharmacy invoice
  1. ; RXIEN - Prescription IEN
  1. ; INV2 - 2 node of the pharmacy prescription invoice
  1. ; ITYPE - Current value for the pharmacy invoice
  1. ; Output: ITYPE - Updated value for the pharmacy invoice
  1. ; Called From: COMPRX
  1. I $D(^FBAA(162.1,PHIEN,"RX",RXIEN,"FBREJ")) D ; Rejected
  1. . S ITYPE=$S(ITYPE'["R":ITYPE_"R",1:ITYPE)
  1. I $P(INV2,U,11)'="" D Q ; Cancelled
  1. . S ITYPE=$S(ITYPE'["C":ITYPE_"C",1:ITYPE)
  1. I $P(INV2,U,3)'="" D Q ; Voided
  1. . S ITYPE=$S(ITYPE'["V":ITYPE_"V",1:ITYPE)
  1. Q
  1. ;
  1. TOTS(VNAME,TYPE,INVNUM,DATA) ; Gather totals and other data for all invoices for
  1. ; the specified DoD invoice#. Update the scratch global with information
  1. ; Input: VNAME - Vendor Name
  1. ; TYPE - "OUT" - Outpatient Invoice
  1. ; "ANC" - Inpatient Ancillary Invoice
  1. ; "INP" - Inpatient Invoice
  1. ; "RX" - Pharmacy Invoice
  1. ; INVNUM - VistA Invoice Number
  1. ; DATA - ^TMP("FBAAIAR1",$J,VNAME,TYPE,INVNUM)
  1. ; ^TMP("FBAAIAR1",$J,VNAME) - Current DoD Invoice Vendor totals
  1. ; ^TMP("FBAAIAR1",$J,VNAME,TYPE) - Current Type totals
  1. ; Output: ^TMP("FBAAIAR1",$J,VNAME) - Updated DoD Invoice Vendor totals
  1. ; ^TMP("FBAAIAR1",$J,VNAME,TYPE) - Updated Type totals
  1. ; Called From: COMPIN, COMPOUT, COMPRX
  1. ;
  1. N CURTOT
  1. S CURTOT=$G(^TMP("FBAAIAR1",$J,VNAME)) ; Current DoD Invoice Vendor totals
  1. S $P(CURTOT,U,1)=$P(DATA,U,3)+$P(CURTOT,U,1) ; New Claimed Total
  1. S $P(CURTOT,U,2)=$P(DATA,U,4)+$P(CURTOT,U,2) ; New Paid Total
  1. S $P(CURTOT,U,3)=$P(DATA,U,5)+$P(CURTOT,U,3) ; New Adjustment Total
  1. S $P(CURTOT,U,4)=$P(CURTOT,U,4)+1 ; New Invoice count
  1. S ^TMP("FBAAIAR1",$J,VNAME)=CURTOT
  1. S CURTOT=$G(^TMP("FBAAIAR1",$J,VNAME,TYPE)) ; Current DoD Invoice Vendor totals by type
  1. S $P(CURTOT,U,1)=$P(DATA,U,3)+$P(CURTOT,U,1) ; New Claimed Total
  1. S $P(CURTOT,U,2)=$P(DATA,U,4)+$P(CURTOT,U,2) ; New Paid Total
  1. S $P(CURTOT,U,3)=$P(DATA,U,5)+$P(CURTOT,U,3) ; New Adjustment Total
  1. S $P(CURTOT,U,4)=$P(CURTOT,U,4)+1 ; New Invoice count by type
  1. S ^TMP("FBAAIAR1",$J,VNAME,TYPE)=CURTOT
  1. Q
  1. ;