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

FBFHLX.m

Go to the documentation of this file.
  1. FBFHLX ;WOIFO/SAB - TRANSMIT HL7 MESSAGES TO FPPS ;7/14/14 16:08
  1. ;;3.5;FEE BASIS;**61,121,122,154**;JUNE 6, 2011;Build 12
  1. ;;Per VA Directive 6402, this routine should not be modified.
  1. Q
  1. ;
  1. EN ; Entry Point
  1. ; may be called by scheduled option as non-interactive task
  1. ; may be called by user menu option as interactive task
  1. ;
  1. N FBMODE,FBQUIT
  1. S FBQUIT=0
  1. ;
  1. ; Determine Mode - (A)LL PENDING or BY SELECTED (I)NVOICE
  1. I $E(IOST,1,2)'="C-" S FBMODE="A" ; non-interactive is always ALL
  1. I $E(IOST,1,2)="C-" D
  1. . I '$D(^XUSEC("FBAA LEVEL 2",DUZ)) W !!?3,$C(7)_"You must hold the FBAA LEVEL 2 security key to transmit messages." S FBQUIT=1 Q
  1. . ; ask mode
  1. . W !,"This option transmits HL7 messages to FPPS for EDI invoices."
  1. . S DIR(0)="S^I:By Specified Invoice;A:All Pending Invoices"
  1. . S DIR("A")="Select Transmission Option"
  1. . S DIR("?",1)="Enter I to transmit a single invoice or A to transmit"
  1. . S DIR("?",2)="all pending invoices. If I is entered then you will be"
  1. . S DIR("?",3)="asked to select the invoice."
  1. . S DIR("?",4)=""
  1. . S DIR("?")="Enter a code from the list."
  1. . D ^DIR K DIR I $D(DIRUT) S FBQUIT=1 Q
  1. . S FBMODE=Y
  1. . ; confirm all
  1. . I FBMODE="A" D
  1. . . S DIR(0)="Y",DIR("A")="Transmit all pending invoices now"
  1. . . D ^DIR K DIR I 'Y!$D(DIRUT) S FBQUIT=1 Q
  1. Q:FBQUIT
  1. ;
  1. I FBMODE="A" D ALL
  1. I FBMODE="I" D BYINV
  1. ;
  1. Q
  1. ;
  1. ALL ; Transmit All Pending Invoices (interactive and non-interactive)
  1. ; input
  1. ; FBQUIT - boolean value (0 or 1), true if process should stop
  1. ; output
  1. ; FBQUIT - may change value
  1. ;
  1. N FBCNT,FBERR,FBHL,FBQDA,FBSTA,FBTTYP,FBXL,FBXMIT,FBFTRACK,HLFS,HLECH ; FB*3.5*122
  1. ;
  1. ; init
  1. S FBXL=20 ; last line used for message text (save 20 lines for header)
  1. S FBCNT("PENDT")=0 ; count of pending invoices that were transmitted
  1. S FBCNT("PENDE")=0 ; count of pending invoices that had exception
  1. ;
  1. ; save time that process started
  1. S FBXMIT("START")=$$NOW^XLFDT()
  1. I $E(IOST,1,2)="C-" W !!,"Starting Process..."
  1. D TIME^FBFHLX2("START",FBXMIT("START"),.FBFTRACK) I $G(FBFTRACK) Q ; active job to quit ; FB*3.5*122
  1. ;
  1. ; initialize HL variables
  1. D INIT^HLFNC2("FB FEE TO FPPS EVENT",.FBHL)
  1. I $G(FBHL) D
  1. . S FBQUIT=1
  1. . D PTXT^FBFHLX1(.FBXL,"Error: Unable to initialize HL variables.")
  1. . D PTXT^FBFHLX1(.FBXL,FBHL)
  1. E D
  1. . S HLFS=FBHL("FS")
  1. . S HLECH=FBHL("ECH")
  1. ;
  1. ; check for transmitted invoices w/o commit ACK
  1. S FBXMIT("ACK")=$$NOW^XLFDT()
  1. I 'FBQUIT,$E(IOST,1,2)="C-" W !!,"Checking for acknowledgements..."
  1. I 'FBQUIT D CHKACK^FBFHLX1
  1. ;
  1. S FBXMIT("SEND")=$$NOW^XLFDT()
  1. ;
  1. I 'FBQUIT,$E(IOST,1,2)="C-" W !!,"Transmitting Pending Invoices..."
  1. ; loop thru pending invoices and transmit
  1. S FBQDA=0 F S FBQDA=$O(^FBHL(163.5,"AC",0,FBQDA)) Q:'FBQDA!FBQUIT D
  1. . ; check for taskman quit request
  1. . I $D(ZTQUEUED),$$S^%ZTLOAD S ZTSTOP=1,FBQUIT=1 Q
  1. . S ^XTMP("FBFHLX","IEN")=$H_U_FBQDA_"^XMIT^" ; FB*3.5*122
  1. . ; try to transmit invoice
  1. . D INVOICE
  1. . ; update counters based on result
  1. . I FBERR S FBCNT("PENDE")=FBCNT("PENDE")+1
  1. . E S FBCNT("PENDT")=FBCNT("PENDT")+1
  1. . I FBCNT("PENDE")+FBCNT("PENDT")>9999 S (FBCNT("10K"),FBQUIT)=1 ; FB*3.5*121
  1. ;
  1. ; save time that process ended
  1. S FBXMIT("END")=$$NOW^XLFDT()
  1. I $E(IOST,1,2)="C-" W !!,"Process complete. Sending Summary Message to G.FEE..."
  1. D TIME^FBFHLX2("END",FBXMIT("END")) ; FB*3.5*121
  1. ;
  1. ; build and send summary mail message to G.FEE
  1. D SUMMSG^FBFHLX1
  1. ;
  1. ; clean-up
  1. K ^TMP($J,"FBE"),^TMP($J,"FBNA"),^TMP($J,"FBW"),^TMP($J,"FBX")
  1. ;
  1. Q
  1. ;
  1. BYINV ; Transmit Selected Invoices (interactive)
  1. ;
  1. N FBAAIN,FBERR,FBHL,FBQDA,FBSTA,FBTTYP,FBX,HLFS,HLECH
  1. ;
  1. ; initialize HL variables
  1. D INIT^HLFNC2("FB FEE TO FPPS EVENT",.FBHL)
  1. I $G(FBHL) D Q
  1. . W !,$C(7),"ERROR: Couldn't initialize HL variables!"
  1. . W !,FBHL
  1. S HLFS=FBHL("FS")
  1. S HLECH=FBHL("ECH")
  1. ;
  1. ; select invoice
  1. F Q:FBQUIT D
  1. . S DIC="^FBHL(163.5,",DIC(0)="AEQM"
  1. . D ^DIC I Y'>0 S FBQUIT=1 Q
  1. . S FBQDA=+Y
  1. . ;
  1. . ; get invoice number and switch to last entry for invoice
  1. . S FBAAIN=$P($G(^FBHL(163.5,FBQDA,0)),U)
  1. . S FBQDA=$$LAST^FBFHLU(FBAAIN)
  1. . I 'FBQDA W !,"Error, invalid data for invoice ",FBAAIN," in file 163.5" Q
  1. . S FBQY=$G(^FBHL(163.5,FBQDA,0))
  1. . ;
  1. . ; confirm
  1. . S FBX=$S($P(FBQY,U,3)=0:"",1:"re-")
  1. . S DIR(0)="Y"
  1. . S DIR("A")="Do you want to "_FBX_"transmit invoice "_FBAAIN
  1. . D ^DIR K DIR S:$D(DIRUT) FBQUIT=1 I 'Y Q
  1. . ;
  1. . ; if re-transmit then create a new pending entry for invoice
  1. . I FBX="re-" D
  1. . . D FILEQUE^FBFHLL(FBAAIN,$P(FBQY,U,2))
  1. . . S FBQDA=$$LAST^FBFHLU(FBAAIN)
  1. . . I FBQDA S FBQY=$G(^FBHL(163.5,FBQDA,0))
  1. . . E S FBQY=""
  1. . ;
  1. . ; check that pending entry was added
  1. . I FBX="re-",$P(FBQY,U,3)'=0 D Q
  1. . . W !,"Error adding entry to file 163.5. Can't re-transmit invoice."
  1. . ;
  1. . ; transmit specified invoice
  1. . D INVOICE
  1. . ;
  1. . ; report success or failure of transmit
  1. . I FBERR=0 W !,"Invoice has been transmitted to the HL7 package.",!!
  1. . I FBERR=1 D
  1. . . N FBL
  1. . . W $C(7),!,"Problems prevented transmission of the invoice."
  1. . . S FBL=0 F S FBL=$O(^TMP($J,"FBE",FBAAIN,FBL)) Q:'FBL D
  1. . . . W !," ",$G(^TMP($J,"FBE",FBAAIN,FBL))
  1. . . W !
  1. . ;
  1. . ; clean up after transmit
  1. . K ^TMP($J,"FBE",FBAAIN)
  1. . K ^TMP($J,"FBW",FBAAIN)
  1. ;
  1. Q
  1. ;
  1. INVOICE ; transmit invoice
  1. ; input
  1. ; FBQDA - ien of entry in file 163.5 to transmit, required
  1. ; output
  1. ; FBERR - error flag (0 or 1), true if error prevented transmit
  1. ; FBSTA - station number in transmitted message (may be null if err)
  1. ; FBTTYP - transaction type in transmitted message (may be null)
  1. ; ^TMP($J,"FBE",invoice number,#) - any exceptions
  1. ; ^TMP($J,"FBW",invoice number,#) - any warnings
  1. ;
  1. ; N FBAAIN,FBD,FBFILE,FBRESULT,FBQY
  1. ;
  1. ; initialize
  1. S FBERR=0
  1. S FBSTA=""
  1. S FBTTYP=""
  1. ;
  1. ; check for required input
  1. I '$G(FBQDA) S FBERR=1 Q
  1. ;
  1. ; lock record
  1. L +^FBHL(163.5,FBQDA):10
  1. I '$T D Q
  1. . S FBERR=1
  1. . S FBAAIN=+$P($G(^FBHL(163.5,FBQDA,0)),U)
  1. . I FBAAIN D POST^FBFHLU(FBAAIN,"E","Couldn't Lock Entry "_FBQDA_" in File 163.5.")
  1. ;
  1. ; get invoice number and file number
  1. I 'FBERR D
  1. . N FBQY
  1. . S FBQY=$G(^FBHL(163.5,FBQDA,0))
  1. . S FBAAIN=+$P(FBQY,U)
  1. . I 'FBAAIN D
  1. . . S FBERR=1
  1. . . D POST^FBFHLU(0,"E","Couldn't determine invoice # for entry "_FBQDA_" in file 163.5.")
  1. . Q:FBERR
  1. . S FBFILE=$P(FBQY,U,2)
  1. . I "^3^5^9^"'[(U_FBFILE_U) D
  1. . . S FBERR=1
  1. . . D POST^FBFHLU(FBAAIN,"E","Invalid File # for entry "_FBQDA_" in file 163.5.")
  1. ;
  1. ; gather invoice data
  1. I 'FBERR D @("EN^FBFHLD"_FBFILE) I $D(^TMP($J,"FBE",FBAAIN)) S FBERR=1
  1. S FBTTYP=$P($G(FBD(0,"INV")),U,2)
  1. S FBSTA=$P($G(FBD(0,"INV")),U,3)
  1. ;
  1. ; build HL segments
  1. I 'FBERR D EN^FBFHLS I $D(^TMP($J,"FBE",FBAAIN)) S FBERR=1
  1. ;
  1. ; generate HL message
  1. I 'FBERR D
  1. . K FBRESULT
  1. . D GENERATE^HLMA("FB FEE TO FPPS EVENT","GM",1,.FBRESULT)
  1. . I +$P(FBRESULT,U,2) D
  1. . . S FBERR=1
  1. . . D POST^FBFHLU(FBAAIN,"E","HL ERR:"_$P(FBRESULT,U,3))
  1. ;
  1. ; update file 163.5
  1. I 'FBERR D
  1. . N FBFDA
  1. . S FBFDA(163.5,FBQDA_",",2)="1" ; set status = transmitted
  1. . S FBFDA(163.5,FBQDA_",",3)=$P(FBRESULT,U) ; message ID
  1. . S FBFDA(163.5,FBQDA_",",4)=$$NOW^XLFDT() ; message date/time
  1. . S FBFDA(163.5,FBQDA_",",5)=FBTTYP ; transaction type
  1. . S FBFDA(163.5,FBQDA_",",6)=FBSTA ; station number
  1. . I $D(FBFDA) D FILE^DIE("","FBFDA")
  1. . ;
  1. . ; store HL segments in word-processing field
  1. . D MOVEHL
  1. . D WP^DIE(163.5,FBQDA_",",7,"","^TMP($J,""FBHLSEG"")")
  1. . K ^TMP($J,"FBHLSEG")
  1. ;
  1. ; unlock record
  1. L -^FBHL(163.5,FBQDA)
  1. ;
  1. ; clean-up
  1. K ^TMP("HLS",$J)
  1. Q
  1. ;
  1. MOVEHL ; Copy HL segment data into word-processing style array
  1. ; input
  1. ; ^TMP("HLS",$J, array
  1. ; output
  1. ; ^TMP($J,"HLSEG",#)=line of text
  1. ; there will be a blank line after each segment
  1. ;
  1. N FBI,FBII,FBL
  1. K ^TMP($J,"FBHLSEG")
  1. S FBL=0
  1. S FBI=0 F S FBI=$O(^TMP("HLS",$J,FBI)) Q:'FBI D
  1. . S FBL=FBL+1,^TMP($J,"FBHLSEG",FBL)=$G(^TMP("HLS",$J,FBI))
  1. . S FBII=0 F S FBII=$O(^TMP("HLS",$J,FBI,FBII)) Q:'FBII D
  1. . . S FBL=FBL+1,^TMP($J,"FBHLSEG",FBL)=$G(^TMP("HLS",$J,FBI,FBII))
  1. . S FBL=FBL+1,^TMP($J,"FBHLSEG",FBL)=""
  1. Q
  1. ;
  1. ;FBFHLX