- IBECEA37 ;EDE/WCJ-Multi-site maintain UC VISIT TRACKING FILE (#351.82) - CALLER/REQUESTOR ; 2-DEC-19
- ;;2.0;INTEGRATED BILLING;**663,671,669,677,689,696**;21-MAR-94;Build 3
- ;;Per VA Directive 6402, this routine should not be modified.
- ;; DBIA#1621 %ZTER (ERROR RECORDING)
- ;; DBIA#2729 MESSAGE ACTION API
- ;; DBIA#4678 VAFCTFU GET TREATING LIST
- ;; DBIA#3144 DIRECT RPC CALLS
- ;; DBIA#3149 XWBDRPC
- ;
- G AWAY
- ;
- AWAY Q ;thought I was being figurative??? Guess again!
- ;
- ; This routine is for maintaining file entries in the IB UC VISIT TRACKING (#351.82) file across all treating facilites that a veteran has been seen at.
- ; So, while the file will not be the same at each facility, entries for a single veteran should match at each of his/her treating facilities.
- ;
- ; Every time a record is added/updated in this file by a user, the UPDATED (#1.01) field is set.
- ; Nightly, this process will look for all the records in the file that have been updated.
- ; For each record that has been updated, this process will look for all the facilities a veteran has been treated at and execute a stored procedure (RPC) at each of those facilities
- ; to update their file. If successful at all of the veteran's treating facilities, the UPDATED field will be removed.
- ; If not successful, the record will remain flagged to indicate that it needs to be tried again at a later time.
- ;
- ; There are multiple calling entry points
- ; UPDATED - pretty much the process described above.
- ; DFN - synch the entries for one veteran across her/his treating facilities. This one is used when a veteran gets treated at a new facility and the new facility need to get
- ; caught up
- ; PULLTHEM - This is used when a veteran is seen at a new treatiing facility. It reaches out to each of the treating facilities and requests that all the veterans file entries that
- ; were created at a facility to be sent to the new one.
- ;
- ; High level process flow
- ; 1) get all the records that you want to update (either by UPDATED flag or DFN)
- ; 2) loop through those and for each, get the veteran and his/her treating facilities
- ; 3) loop through treating facilities and executing remote RPC passing in the information about the specific entry
- ; 4) wait a reasonable amount on time for results from the remote treating facilities
- ; 5) remove from index if successful
- ; 6) rinse, repeat
- ;
- UPDATED ; Get all in File that were UPDATED and not yet pushed out. They may have gotten to some sites but not all sites
- ;
- D MULTI("AC",1) ; "AC" index for updated (1's) records
- Q
- ;
- ; This was set up to pass in 1 regular index and an internal lookup value which it does an exact match on.
- ; This leads to the most efficient database call acording to the FileMan manual (didn't actually run performance tests)
- ; Any changes to this behavior would need to be tested/verified and potentially recoded.
- MULTI(IBINDEX,IBLOOKUP) ;
- ; IBINDEX = a single regular fileman index
- ; IBLOOKUP = internal value for that index
- ;
- K ^TMP("IBECEA_COPAY",$J) ; start fresh
- ;
- ;D FIND^DIC(file[,iens][,fields][,flags],[.]value[,number][,[.]indexes][,[.]screen][,identifier][,target_root][,msg_root]) ; this line is just for reference
- ; get all the requested entries
- D FIND^DIC(351.82,"",".01;.02:99;.03I;.04I;.05;.06I;.07I;1.01I","QEP",IBLOOKUP,"",IBINDEX)
- ;
- ; this is what the file looks like so you know what is being grabbed above.
- ;^IBUC(351.82,D0,0)= (#.01) PATIENT [1P:2] ^ (#.02) SITE [2P:4] ^ (#.03) VISIT DATE [3D] ^ (#.04) STATUS [4S] ^ (#.05) BILL NUMBER
- ; ==>[5P:350] ^ (#.06) COMMENT [6S] ^ (#.07) UNIQUE ID
- ;
- I '+$G(^TMP("DILIST",$J,0)) Q ; nothing to see here folks - the FIND returned no results (maybe a slow day).
- ;
- ; and this is what the results look like - returned in the TMP global - I am a visual person so bear with me
- ;^TMP("DILIST",1720,0)="50^*^0^"
- ;^TMP("DILIST",1720,0,"MAP")="IEN^.01I^.01^C2^.03I^.04I^.05^.06I^.07I^1.01I"
- ;^TMP("DILIST",1720,1,0)="1^1234567^PATIENT,TEST A^999^3190801^2^999-K909Z09^^^1"
- ; have at them
- ;N IBLOOP,IBDATA,IBIEN,IBDFN,IBSITE,IBFAC,IBVISDT,IBSTAT,IBBILL,IBCOMM,IBUNIQ,IBEXSITE,IBTFL,IBT,IBICN,IBH,IBX,IBR,IBERR,IBHERE,IBC,IBZ,IBOSITEIN,IBOSITEEX,IBPATPR,IBELGRP
- N IBLOOP,IBDATA,IBIEN,IBDFN,IBSITE,IBFAC,IBVISDT,IBSTAT,IBBILL,IBCOMM,IBUNIQ,IBEXSITE,IBTFL,IBT,IBICN,IBH,IBX,IBR,IBERR,IBHERE,IBC,IBZ,IBOSITEEX,IBPATPR,IBELGRP
- ;
- S IBPATPR=IBINDEX="B" ; Set IBPAT flag since behaviour will be even differenter than the others and we may need to check the flag often
- ;
- D SITE^IBAUTL ; returns IBSITE (external#) and IBFAC (internal#) based on IB SITE PARAMETERS for this site
- ;
- S (IBERR,IBLOOP)=0
- F IBLOOP=1:1:+$G(^TMP("DILIST",$J,0)) D
- . S IBDATA=$G(^TMP("DILIST",$J,IBLOOP,0)) ; data is packed in format described above
- . Q:IBDATA=""
- . S IBIEN=$P(IBDATA,U)
- . S IBDFN=$P(IBDATA,U,2)
- . ;
- . ;S IBOSITEIN=$P(IBDATA,U,4) ; IEN file 4 (originating site internal)
- . ;I IBOSITEIN'=IBFAC D REMOVE(IBIEN) Q ; if treatment is not for the current site, don't push out - it was pushed here. Only originating sites should push.
- . ;S IBOSITEEX=$$GET1^DIQ(4,IBOSITEIN,99) ; turn external site # into internal one
- . S IBOSITEEX=$P(IBDATA,U,4) ; IEN file 4 (originating site external)
- . I IBOSITEEX'=IBSITE D REMOVE(IBIEN) Q ; if treatment is not for the current site, don't push out - it was pushed here. Only originating sites should push.
- . ;
- . K IBTFL
- . S IBT=$$TFL(IBDFN,IBOSITEEX,.IBTFL)
- . I 'IBT D REMOVE(IBIEN) Q ; not seen at other treating facilites so no where to send - done with entry
- . ;
- . S IBICN=$$ICN^IBARXMU(IBDFN)
- . I 'IBICN D LOGRES(IBDFN,.IBERR,"Failed local ICN lookup.") Q ; no ICN - leave in the index and try again tomorrow since people eventually get ICNs according the MPI documentation
- . ;
- . S IBVISDT=$P(IBDATA,U,5)
- . S IBSTAT=$P(IBDATA,U,6)
- . S IBBILL=$P(IBDATA,U,7)
- . S IBCOMM=$P(IBDATA,U,8)
- . S IBUNIQ=$P(IBDATA,U,9)
- . S:IBUNIQ="" IBUNIQ=IBSITE_"_"_IBIEN ; The UNIQUE ID = SITE_IEN
- . S IBELGRP=$$GETELGP^IBECEA36(IBDFN,IBVISDT)
- . ;
- . ; send off calls to other treating facilities that this veteran has been seen at
- . ; the calls fire off the RPC (stored procedure) at each site
- . ; DBIA#3144 DIRECT RPC CALLS
- . ; DBIA#3149 XWBDRPC
- . S IBX=0 F S IBX=$O(IBTFL(IBX)) Q:IBX<1 D
- .. ;I IBPULL,+IBTFL(IBX)'=IBLOOKUP K IBTFL(IBX) Q ; if it's a pull from a specific site, only send to site doing the pulling - duh
- .. ;W:'$D(ZTQUEUED) !,"Now sending query to ",$P(IBTFL(IBX),"^",2)," ..."
- .. N IBH
- .. D:'IBPATPR EN1^XWB2HL7(.IBH,+IBTFL(IBX),"IBECEA COPAY SYNCH","",IBICN,IBOSITEEX,IBVISDT,IBSTAT,IBBILL,IBCOMM,IBUNIQ,IBELGRP) ; push one record
- .. D:IBPATPR EN1^XWB2HL7(.IBH,+IBTFL(IBX),"IBECEA COPAY SYNCH","",IBICN,IBOSITEEX) ; push a request for all records for a patient (used when playing catch up - possibly adding a treating facility)
- .. ; check for handle
- .. I $G(IBH(0))="" D Q
- ... S IBTFL(IBX,"ERR")="No handle returned from RPC"
- ... D LOGRES(,.IBERR,"No handle returned from call to site "_+IBTFL(IBX)_".") Q
- .. S $P(IBTFL(IBX),"^",3)=IBH(0) ; save handle for later.
- . ;
- . ; now lets look for the remote data
- . N IBREMOVE
- . S IBREMOVE=1 ; default this to remove from index
- . S IBX=0 F S IBX=$O(IBTFL(IBX)) Q:IBX<1 D
- .. I $D(IBTFL(IBX,"ERR")) S IBREMOVE=0 Q
- .. ;
- .. ;I IBPULL,+IBTFL(IBX)'=IBLOOKUP Q ; if it's a pull, only read from site doing the pulling - duh
- .. ;
- .. ; try up to 10 times for 2 seconds each (at each site)
- .. N IBR
- .. F IBC=1:1:10 D RPCCHK^XWB2HL7(.IBR,$P(IBTFL(IBX),U,3)) Q:$G(IBR(0))["Done" H 2
- .. ;
- .. ; If not done at one (or more) facility set a flag so it does not get removed from the index
- .. I $G(IBR(0))'["Done" D LOGRES(IBDFN,.IBERR,"No reply from site "_+IBTFL(IBX)_".") S IBREMOVE=0
- .. ; if done get data.
- .. I $G(IBR(0))["Done" D
- ... K IBR,IBHERE
- ... D RTNDATA^XWBDRPC(.IBHERE,$P(IBTFL(IBX),"^",3))
- ... I $D(IBHERE)>10 D ; not sure if was success or failure so save for now
- .... S IBERR=IBERR+1
- .... M ^TMP("IBECEA_COPAY",$J,IBDFN,IBERR,+IBTFL(IBX))=IBHERE
- .... I +$G(IBHERE(0))<0 S IBREMOVE=0 ; it failed to leave it
- ... E D
- .... S IBERR=IBERR+1
- .... M ^TMP("IBECEA_COPAY",$J,IBDFN,IBERR,+IBTFL(IBX))=^TMP($J,"XWB")
- .... K ^TMP($J,"XWB")
- .... S IBREMOVE=0 ; if any failed then leave it in to retry
- ... D CLEAR^XWBDRPC(.IBZ,$P(IBTFL(IBX),"^",3))
- .. E D LOGRES(IBDFN,.IBERR,"Unable to get remote information from this site.") S IBREMOVE=0 ; IBR(0) did not contain 'Done'
- . I IBREMOVE D REMOVE(IBIEN) Q
- . Q
- ;
- ; It was nice that we flagged the errors and stored in a TMP global but we should probably alert somebody
- D ALERTSO
- ;
- ; clean up
- K ^TMP("IBECEA_COPAY",$J)
- Q
- ;
- LOGRES(IBDFN,ERR,RESMESS) ; log results
- S ERR=ERR+1
- I $G(IBDFN)="" N IBDFN S IBDFN=0 ; if no DFN then it's a generic type error not really specific to a patient
- S ^TMP("IBECEA_COPAY",$J,IBDFN,ERR)=RESMESS
- Q
- ;
- ; I stole (and modified) from another routine because I wanted to parameterize site.
- ; they were using $$VASITE while we are using SITE^IBAUTL which grabs from different places.
- TFL(DFN,IBS,IBT) ; returns treating facility list (pass IBT by reference)
- ; supported references ia #2990, value returned is count
- ; needed to N Y because VAFCTFU1 will kill it
- ; DFN - Patient IEN
- ; IBS - External site
- ; IBT - By reference for results
- ;
- N IBC,IBZ,IBFT,Y
- D TFL^VAFCTFU1(.IBZ,DFN)
- Q:+$G(IBZ(1))=1 0
- S (IBZ,IBC)=0
- ; Return only remote facilities of certain types:
- S IBFT="^VAMC^M&ROC^RO-OC^"
- ; skip CERNER for now 200CRNR; IB*2.0*696
- ;F S IBZ=$O(IBZ(IBZ)) Q:IBZ<1 I +IBZ(IBZ)>0,+IBZ(IBZ)'=IBS,IBFT[("^"_$P(IBZ(IBZ),U,5)_"^") S IBT(+IBZ(IBZ))=IBZ(IBZ),IBC=IBC+1
- F S IBZ=$O(IBZ(IBZ)) Q:IBZ<1 I +IBZ(IBZ)>0,+IBZ(IBZ)'=IBS,IBFT[("^"_$P(IBZ(IBZ),U,5)_"^"),$P(IBZ(IBZ),U,1)'="200CRNR" S IBT(+IBZ(IBZ))=IBZ(IBZ),IBC=IBC+1
- Q IBC
- ;
- ALERTSO ; alert someone
- ; what is needed to actually be informative - maybe PATIENT NAME, FULL ICN (if available), RECEIVING SITE, ERROR MESSAGE
- ; screen out all but errors (get rid of 0's (info only) and 1's (successes))
- ;
- Q:'$D(^TMP("IBECEA_COPAY",$J))
- N SUBJ,MSG,XMTO,LN,IBDFN,IBRES,IBDATA,IBFAC,IBLN,IBL4,IBAD,IBLP
- S SUBJ="IBUC COPAY exceptions"
- S LN=0,IBDFN=""
- F S IBDFN=$O(^TMP("IBECEA_COPAY",$J,IBDFN)) Q:+IBDFN'=IBDFN D
- . S IBAD=0
- . S IBRES=0 F S IBRES=$O(^TMP("IBECEA_COPAY",$J,IBDFN,IBRES)) Q:'IBRES D
- .. I IBDFN D ; only for patient errors and not generic ones
- ... S IBLN=$P($$GET1^DIQ(2,IBDFN,.01),",",1) ; last name
- ... S IBL4=$$GET1^DIQ(2,IBDFN,.09),IBL4=$E(IBL4,$L(IBL4)-3,9999) ; last 4
- .. S IBDATA=$G(^TMP("IBECEA_COPAY",$J,IBDFN,IBRES))
- .. I IBDATA]"" D
- ... I $D(^TMP("IBECEA_COPAY",$J,"INDX",IBDFN,IBDATA)) S ^TMP("IBECEA_COPAY",$J,"INDX",IBDFN,IBDATA)=^TMP("IBECEA_COPAY",$J,"INDX",IBDFN,IBDATA)+1 Q
- ... I IBDFN=0,'IBAD S LN=LN+1,MSG(LN)="Generic Errors (not patient specific):",IBAD=1
- ... I IBDFN,'IBAD S LN=LN+1,MSG(LN)=IBLN_" "_IBL4,IBAD=1
- ... S LN=LN+1,MSG(LN)=IBDATA
- ... S ^TMP("IBECEA_COPAY",$J,"INDX",IBDFN,IBDATA)=1
- .. S IBFAC=0 F S IBFAC=$O(^TMP("IBECEA_COPAY",$J,IBDFN,IBRES,IBFAC)) Q:'IBFAC D
- ... S IBLP="" F S IBLP=$O(^TMP("IBECEA_COPAY",$J,IBDFN,IBRES,IBFAC,IBLP)) Q:IBLP="" D
- .... S IBDATA=$G(^TMP("IBECEA_COPAY",$J,IBDFN,IBRES,IBFAC,IBLP))
- .... I +IBDATA<0 D
- ..... I $D(^TMP("IBECEA_COPAY",$J,"INDX",IBDFN,IBFAC,IBDATA)) S ^TMP("IBECEA_COPAY",$J,"INDX",IBDFN,IBFAC,IBDATA)=^TMP("IBECEA_COPAY",$J,"INDX",IBDFN,IBFAC,IBDATA)+1 Q
- ..... I IBDFN,'IBAD S LN=LN+1,MSG(LN)=IBLN_" "_IBL4,IBAD=1
- ..... S LN=LN+1,MSG(LN)=$P(IBDATA,U,2,999)
- ..... S ^TMP("IBECEA_COPAY",$J,"INDX",IBDFN,IBFAC,IBDATA)=1
- . I $D(MSG)>1 S LN=LN+1,MSG(LN)=" "
- Q:'LN
- S XMTO("G.IBUC URGENT CARE EXCEPTIONS")=""
- D SENDMSG^XMXAPI(DUZ,SUBJ,"MSG",.XMTO)
- D CLEAN^DILF
- Q
- ;
- REMOVE(IBIEN) ; remove from UPDATED index - only called if sent to ALL other treating facilities successfully.
- N FDA,IENS,RETURN
- S IENS=IBIEN_","
- S FDA(351.82,IENS,1.01)=0
- D FILE^DIE("","FDA","RETURN")
- Q
- --- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HIBECEA37 12215 printed Feb 18, 2025@23:47:46 Page 2
- IBECEA37 ;EDE/WCJ-Multi-site maintain UC VISIT TRACKING FILE (#351.82) - CALLER/REQUESTOR ; 2-DEC-19
- +1 ;;2.0;INTEGRATED BILLING;**663,671,669,677,689,696**;21-MAR-94;Build 3
- +2 ;;Per VA Directive 6402, this routine should not be modified.
- +3 ;; DBIA#1621 %ZTER (ERROR RECORDING)
- +4 ;; DBIA#2729 MESSAGE ACTION API
- +5 ;; DBIA#4678 VAFCTFU GET TREATING LIST
- +6 ;; DBIA#3144 DIRECT RPC CALLS
- +7 ;; DBIA#3149 XWBDRPC
- +8 ;
- +9 GOTO AWAY
- +10 ;
- AWAY ;thought I was being figurative??? Guess again!
- QUIT
- +1 ;
- +2 ; This routine is for maintaining file entries in the IB UC VISIT TRACKING (#351.82) file across all treating facilites that a veteran has been seen at.
- +3 ; So, while the file will not be the same at each facility, entries for a single veteran should match at each of his/her treating facilities.
- +4 ;
- +5 ; Every time a record is added/updated in this file by a user, the UPDATED (#1.01) field is set.
- +6 ; Nightly, this process will look for all the records in the file that have been updated.
- +7 ; For each record that has been updated, this process will look for all the facilities a veteran has been treated at and execute a stored procedure (RPC) at each of those facilities
- +8 ; to update their file. If successful at all of the veteran's treating facilities, the UPDATED field will be removed.
- +9 ; If not successful, the record will remain flagged to indicate that it needs to be tried again at a later time.
- +10 ;
- +11 ; There are multiple calling entry points
- +12 ; UPDATED - pretty much the process described above.
- +13 ; DFN - synch the entries for one veteran across her/his treating facilities. This one is used when a veteran gets treated at a new facility and the new facility need to get
- +14 ; caught up
- +15 ; PULLTHEM - This is used when a veteran is seen at a new treatiing facility. It reaches out to each of the treating facilities and requests that all the veterans file entries that
- +16 ; were created at a facility to be sent to the new one.
- +17 ;
- +18 ; High level process flow
- +19 ; 1) get all the records that you want to update (either by UPDATED flag or DFN)
- +20 ; 2) loop through those and for each, get the veteran and his/her treating facilities
- +21 ; 3) loop through treating facilities and executing remote RPC passing in the information about the specific entry
- +22 ; 4) wait a reasonable amount on time for results from the remote treating facilities
- +23 ; 5) remove from index if successful
- +24 ; 6) rinse, repeat
- +25 ;
- UPDATED ; Get all in File that were UPDATED and not yet pushed out. They may have gotten to some sites but not all sites
- +1 ;
- +2 ; "AC" index for updated (1's) records
- DO MULTI("AC",1)
- +3 QUIT
- +4 ;
- +5 ; This was set up to pass in 1 regular index and an internal lookup value which it does an exact match on.
- +6 ; This leads to the most efficient database call acording to the FileMan manual (didn't actually run performance tests)
- +7 ; Any changes to this behavior would need to be tested/verified and potentially recoded.
- MULTI(IBINDEX,IBLOOKUP) ;
- +1 ; IBINDEX = a single regular fileman index
- +2 ; IBLOOKUP = internal value for that index
- +3 ;
- +4 ; start fresh
- KILL ^TMP("IBECEA_COPAY",$JOB)
- +5 ;
- +6 ;D FIND^DIC(file[,iens][,fields][,flags],[.]value[,number][,[.]indexes][,[.]screen][,identifier][,target_root][,msg_root]) ; this line is just for reference
- +7 ; get all the requested entries
- +8 DO FIND^DIC(351.82,"",".01;.02:99;.03I;.04I;.05;.06I;.07I;1.01I","QEP",IBLOOKUP,"",IBINDEX)
- +9 ;
- +10 ; this is what the file looks like so you know what is being grabbed above.
- +11 ;^IBUC(351.82,D0,0)= (#.01) PATIENT [1P:2] ^ (#.02) SITE [2P:4] ^ (#.03) VISIT DATE [3D] ^ (#.04) STATUS [4S] ^ (#.05) BILL NUMBER
- +12 ; ==>[5P:350] ^ (#.06) COMMENT [6S] ^ (#.07) UNIQUE ID
- +13 ;
- +14 ; nothing to see here folks - the FIND returned no results (maybe a slow day).
- IF '+$GET(^TMP("DILIST",$JOB,0))
- QUIT
- +15 ;
- +16 ; and this is what the results look like - returned in the TMP global - I am a visual person so bear with me
- +17 ;^TMP("DILIST",1720,0)="50^*^0^"
- +18 ;^TMP("DILIST",1720,0,"MAP")="IEN^.01I^.01^C2^.03I^.04I^.05^.06I^.07I^1.01I"
- +19 ;^TMP("DILIST",1720,1,0)="1^1234567^PATIENT,TEST A^999^3190801^2^999-K909Z09^^^1"
- +20 ; have at them
- +21 ;N IBLOOP,IBDATA,IBIEN,IBDFN,IBSITE,IBFAC,IBVISDT,IBSTAT,IBBILL,IBCOMM,IBUNIQ,IBEXSITE,IBTFL,IBT,IBICN,IBH,IBX,IBR,IBERR,IBHERE,IBC,IBZ,IBOSITEIN,IBOSITEEX,IBPATPR,IBELGRP
- +22 NEW IBLOOP,IBDATA,IBIEN,IBDFN,IBSITE,IBFAC,IBVISDT,IBSTAT,IBBILL,IBCOMM,IBUNIQ,IBEXSITE,IBTFL,IBT,IBICN,IBH,IBX,IBR,IBERR,IBHERE,IBC,IBZ,IBOSITEEX,IBPATPR,IBELGRP
- +23 ;
- +24 ; Set IBPAT flag since behaviour will be even differenter than the others and we may need to check the flag often
- SET IBPATPR=IBINDEX="B"
- +25 ;
- +26 ; returns IBSITE (external#) and IBFAC (internal#) based on IB SITE PARAMETERS for this site
- DO SITE^IBAUTL
- +27 ;
- +28 SET (IBERR,IBLOOP)=0
- +29 FOR IBLOOP=1:1:+$GET(^TMP("DILIST",$JOB,0))
- Begin DoDot:1
- +30 ; data is packed in format described above
- SET IBDATA=$GET(^TMP("DILIST",$JOB,IBLOOP,0))
- +31 if IBDATA=""
- QUIT
- +32 SET IBIEN=$PIECE(IBDATA,U)
- +33 SET IBDFN=$PIECE(IBDATA,U,2)
- +34 ;
- +35 ;S IBOSITEIN=$P(IBDATA,U,4) ; IEN file 4 (originating site internal)
- +36 ;I IBOSITEIN'=IBFAC D REMOVE(IBIEN) Q ; if treatment is not for the current site, don't push out - it was pushed here. Only originating sites should push.
- +37 ;S IBOSITEEX=$$GET1^DIQ(4,IBOSITEIN,99) ; turn external site # into internal one
- +38 ; IEN file 4 (originating site external)
- SET IBOSITEEX=$PIECE(IBDATA,U,4)
- +39 ; if treatment is not for the current site, don't push out - it was pushed here. Only originating sites should push.
- IF IBOSITEEX'=IBSITE
- DO REMOVE(IBIEN)
- QUIT
- +40 ;
- +41 KILL IBTFL
- +42 SET IBT=$$TFL(IBDFN,IBOSITEEX,.IBTFL)
- +43 ; not seen at other treating facilites so no where to send - done with entry
- IF 'IBT
- DO REMOVE(IBIEN)
- QUIT
- +44 ;
- +45 SET IBICN=$$ICN^IBARXMU(IBDFN)
- +46 ; no ICN - leave in the index and try again tomorrow since people eventually get ICNs according the MPI documentation
- IF 'IBICN
- DO LOGRES(IBDFN,.IBERR,"Failed local ICN lookup.")
- QUIT
- +47 ;
- +48 SET IBVISDT=$PIECE(IBDATA,U,5)
- +49 SET IBSTAT=$PIECE(IBDATA,U,6)
- +50 SET IBBILL=$PIECE(IBDATA,U,7)
- +51 SET IBCOMM=$PIECE(IBDATA,U,8)
- +52 SET IBUNIQ=$PIECE(IBDATA,U,9)
- +53 ; The UNIQUE ID = SITE_IEN
- if IBUNIQ=""
- SET IBUNIQ=IBSITE_"_"_IBIEN
- +54 SET IBELGRP=$$GETELGP^IBECEA36(IBDFN,IBVISDT)
- +55 ;
- +56 ; send off calls to other treating facilities that this veteran has been seen at
- +57 ; the calls fire off the RPC (stored procedure) at each site
- +58 ; DBIA#3144 DIRECT RPC CALLS
- +59 ; DBIA#3149 XWBDRPC
- +60 SET IBX=0
- FOR
- SET IBX=$ORDER(IBTFL(IBX))
- if IBX<1
- QUIT
- Begin DoDot:2
- +61 ;I IBPULL,+IBTFL(IBX)'=IBLOOKUP K IBTFL(IBX) Q ; if it's a pull from a specific site, only send to site doing the pulling - duh
- +62 ;W:'$D(ZTQUEUED) !,"Now sending query to ",$P(IBTFL(IBX),"^",2)," ..."
- +63 NEW IBH
- +64 ; push one record
- if 'IBPATPR
- DO EN1^XWB2HL7(.IBH,+IBTFL(IBX),"IBECEA COPAY SYNCH","",IBICN,IBOSITEEX,IBVISDT,IBSTAT,IBBILL,IBCOMM,IBUNIQ,IBELGRP)
- +65 ; push a request for all records for a patient (used when playing catch up - possibly adding a treating facility)
- if IBPATPR
- DO EN1^XWB2HL7(.IBH,+IBTFL(IBX),"IBECEA COPAY SYNCH","",IBICN,IBOSITEEX)
- +66 ; check for handle
- +67 IF $GET(IBH(0))=""
- Begin DoDot:3
- +68 SET IBTFL(IBX,"ERR")="No handle returned from RPC"
- +69 DO LOGRES(,.IBERR,"No handle returned from call to site "_+IBTFL(IBX)_".")
- QUIT
- End DoDot:3
- QUIT
- +70 ; save handle for later.
- SET $PIECE(IBTFL(IBX),"^",3)=IBH(0)
- End DoDot:2
- +71 ;
- +72 ; now lets look for the remote data
- +73 NEW IBREMOVE
- +74 ; default this to remove from index
- SET IBREMOVE=1
- +75 SET IBX=0
- FOR
- SET IBX=$ORDER(IBTFL(IBX))
- if IBX<1
- QUIT
- Begin DoDot:2
- +76 IF $DATA(IBTFL(IBX,"ERR"))
- SET IBREMOVE=0
- QUIT
- +77 ;
- +78 ;I IBPULL,+IBTFL(IBX)'=IBLOOKUP Q ; if it's a pull, only read from site doing the pulling - duh
- +79 ;
- +80 ; try up to 10 times for 2 seconds each (at each site)
- +81 NEW IBR
- +82 FOR IBC=1:1:10
- DO RPCCHK^XWB2HL7(.IBR,$PIECE(IBTFL(IBX),U,3))
- if $GET(IBR(0))["Done"
- QUIT
- HANG 2
- +83 ;
- +84 ; If not done at one (or more) facility set a flag so it does not get removed from the index
- +85 IF $GET(IBR(0))'["Done"
- DO LOGRES(IBDFN,.IBERR,"No reply from site "_+IBTFL(IBX)_".")
- SET IBREMOVE=0
- +86 ; if done get data.
- +87 IF $GET(IBR(0))["Done"
- Begin DoDot:3
- +88 KILL IBR,IBHERE
- +89 DO RTNDATA^XWBDRPC(.IBHERE,$PIECE(IBTFL(IBX),"^",3))
- +90 ; not sure if was success or failure so save for now
- IF $DATA(IBHERE)>10
- Begin DoDot:4
- +91 SET IBERR=IBERR+1
- +92 MERGE ^TMP("IBECEA_COPAY",$JOB,IBDFN,IBERR,+IBTFL(IBX))=IBHERE
- +93 ; it failed to leave it
- IF +$GET(IBHERE(0))<0
- SET IBREMOVE=0
- End DoDot:4
- +94 IF '$TEST
- Begin DoDot:4
- +95 SET IBERR=IBERR+1
- +96 MERGE ^TMP("IBECEA_COPAY",$JOB,IBDFN,IBERR,+IBTFL(IBX))=^TMP($JOB,"XWB")
- +97 KILL ^TMP($JOB,"XWB")
- +98 ; if any failed then leave it in to retry
- SET IBREMOVE=0
- End DoDot:4
- +99 DO CLEAR^XWBDRPC(.IBZ,$PIECE(IBTFL(IBX),"^",3))
- End DoDot:3
- +100 ; IBR(0) did not contain 'Done'
- IF '$TEST
- DO LOGRES(IBDFN,.IBERR,"Unable to get remote information from this site.")
- SET IBREMOVE=0
- End DoDot:2
- +101 IF IBREMOVE
- DO REMOVE(IBIEN)
- QUIT
- +102 QUIT
- End DoDot:1
- +103 ;
- +104 ; It was nice that we flagged the errors and stored in a TMP global but we should probably alert somebody
- +105 DO ALERTSO
- +106 ;
- +107 ; clean up
- +108 KILL ^TMP("IBECEA_COPAY",$JOB)
- +109 QUIT
- +110 ;
- LOGRES(IBDFN,ERR,RESMESS) ; log results
- +1 SET ERR=ERR+1
- +2 ; if no DFN then it's a generic type error not really specific to a patient
- IF $GET(IBDFN)=""
- NEW IBDFN
- SET IBDFN=0
- +3 SET ^TMP("IBECEA_COPAY",$JOB,IBDFN,ERR)=RESMESS
- +4 QUIT
- +5 ;
- +6 ; I stole (and modified) from another routine because I wanted to parameterize site.
- +7 ; they were using $$VASITE while we are using SITE^IBAUTL which grabs from different places.
- TFL(DFN,IBS,IBT) ; returns treating facility list (pass IBT by reference)
- +1 ; supported references ia #2990, value returned is count
- +2 ; needed to N Y because VAFCTFU1 will kill it
- +3 ; DFN - Patient IEN
- +4 ; IBS - External site
- +5 ; IBT - By reference for results
- +6 ;
- +7 NEW IBC,IBZ,IBFT,Y
- +8 DO TFL^VAFCTFU1(.IBZ,DFN)
- +9 if +$GET(IBZ(1))=1
- QUIT 0
- +10 SET (IBZ,IBC)=0
- +11 ; Return only remote facilities of certain types:
- +12 SET IBFT="^VAMC^M&ROC^RO-OC^"
- +13 ; skip CERNER for now 200CRNR; IB*2.0*696
- +14 ;F S IBZ=$O(IBZ(IBZ)) Q:IBZ<1 I +IBZ(IBZ)>0,+IBZ(IBZ)'=IBS,IBFT[("^"_$P(IBZ(IBZ),U,5)_"^") S IBT(+IBZ(IBZ))=IBZ(IBZ),IBC=IBC+1
- +15 FOR
- SET IBZ=$ORDER(IBZ(IBZ))
- if IBZ<1
- QUIT
- IF +IBZ(IBZ)>0
- IF +IBZ(IBZ)'=IBS
- IF IBFT[("^"_$PIECE(IBZ(IBZ),U,5)_"^")
- IF $PIECE(IBZ(IBZ),U,1)'="200CRNR"
- SET IBT(+IBZ(IBZ))=IBZ(IBZ)
- SET IBC=IBC+1
- +16 QUIT IBC
- +17 ;
- ALERTSO ; alert someone
- +1 ; what is needed to actually be informative - maybe PATIENT NAME, FULL ICN (if available), RECEIVING SITE, ERROR MESSAGE
- +2 ; screen out all but errors (get rid of 0's (info only) and 1's (successes))
- +3 ;
- +4 if '$DATA(^TMP("IBECEA_COPAY",$JOB))
- QUIT
- +5 NEW SUBJ,MSG,XMTO,LN,IBDFN,IBRES,IBDATA,IBFAC,IBLN,IBL4,IBAD,IBLP
- +6 SET SUBJ="IBUC COPAY exceptions"
- +7 SET LN=0
- SET IBDFN=""
- +8 FOR
- SET IBDFN=$ORDER(^TMP("IBECEA_COPAY",$JOB,IBDFN))
- if +IBDFN'=IBDFN
- QUIT
- Begin DoDot:1
- +9 SET IBAD=0
- +10 SET IBRES=0
- FOR
- SET IBRES=$ORDER(^TMP("IBECEA_COPAY",$JOB,IBDFN,IBRES))
- if 'IBRES
- QUIT
- Begin DoDot:2
- +11 ; only for patient errors and not generic ones
- IF IBDFN
- Begin DoDot:3
- +12 ; last name
- SET IBLN=$PIECE($$GET1^DIQ(2,IBDFN,.01),",",1)
- +13 ; last 4
- SET IBL4=$$GET1^DIQ(2,IBDFN,.09)
- SET IBL4=$EXTRACT(IBL4,$LENGTH(IBL4)-3,9999)
- End DoDot:3
- +14 SET IBDATA=$GET(^TMP("IBECEA_COPAY",$JOB,IBDFN,IBRES))
- +15 IF IBDATA]""
- Begin DoDot:3
- +16 IF $DATA(^TMP("IBECEA_COPAY",$JOB,"INDX",IBDFN,IBDATA))
- SET ^TMP("IBECEA_COPAY",$JOB,"INDX",IBDFN,IBDATA)=^TMP("IBECEA_COPAY",$JOB,"INDX",IBDFN,IBDATA)+1
- QUIT
- +17 IF IBDFN=0
- IF 'IBAD
- SET LN=LN+1
- SET MSG(LN)="Generic Errors (not patient specific):"
- SET IBAD=1
- +18 IF IBDFN
- IF 'IBAD
- SET LN=LN+1
- SET MSG(LN)=IBLN_" "_IBL4
- SET IBAD=1
- +19 SET LN=LN+1
- SET MSG(LN)=IBDATA
- +20 SET ^TMP("IBECEA_COPAY",$JOB,"INDX",IBDFN,IBDATA)=1
- End DoDot:3
- +21 SET IBFAC=0
- FOR
- SET IBFAC=$ORDER(^TMP("IBECEA_COPAY",$JOB,IBDFN,IBRES,IBFAC))
- if 'IBFAC
- QUIT
- Begin DoDot:3
- +22 SET IBLP=""
- FOR
- SET IBLP=$ORDER(^TMP("IBECEA_COPAY",$JOB,IBDFN,IBRES,IBFAC,IBLP))
- if IBLP=""
- QUIT
- Begin DoDot:4
- +23 SET IBDATA=$GET(^TMP("IBECEA_COPAY",$JOB,IBDFN,IBRES,IBFAC,IBLP))
- +24 IF +IBDATA<0
- Begin DoDot:5
- +25 IF $DATA(^TMP("IBECEA_COPAY",$JOB,"INDX",IBDFN,IBFAC,IBDATA))
- SET ^TMP("IBECEA_COPAY",$JOB,"INDX",IBDFN,IBFAC,IBDATA)=^TMP("IBECEA_COPAY",$JOB,"INDX",IBDFN,IBFAC,IBDATA)+1
- QUIT
- +26 IF IBDFN
- IF 'IBAD
- SET LN=LN+1
- SET MSG(LN)=IBLN_" "_IBL4
- SET IBAD=1
- +27 SET LN=LN+1
- SET MSG(LN)=$PIECE(IBDATA,U,2,999)
- +28 SET ^TMP("IBECEA_COPAY",$JOB,"INDX",IBDFN,IBFAC,IBDATA)=1
- End DoDot:5
- End DoDot:4
- End DoDot:3
- End DoDot:2
- +29 IF $DATA(MSG)>1
- SET LN=LN+1
- SET MSG(LN)=" "
- End DoDot:1
- +30 if 'LN
- QUIT
- +31 SET XMTO("G.IBUC URGENT CARE EXCEPTIONS")=""
- +32 DO SENDMSG^XMXAPI(DUZ,SUBJ,"MSG",.XMTO)
- +33 DO CLEAN^DILF
- +34 QUIT
- +35 ;
- REMOVE(IBIEN) ; remove from UPDATED index - only called if sent to ALL other treating facilities successfully.
- +1 NEW FDA,IENS,RETURN
- +2 SET IENS=IBIEN_","
- +3 SET FDA(351.82,IENS,1.01)=0
- +4 DO FILE^DIE("","FDA","RETURN")
- +5 QUIT