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

ACHSEOB3.m

Go to the documentation of this file.
ACHSEOB3 ; IHS/ITSC/PMF - PROCESS EOBRS (4/6) - UPDATE DOCUMENT(1/2) ;   [ 09/17/2004  11:42 AM ]
 ;;3.1;CONTRACT HEALTH MGMT SYSTEM;**4,11**;JUN 11, 2001;Build 43
 ;ACHS*3.1*4 if error 32 happens, quit, don't keep going
 ;ACHS*3.1*11 Send vendor warning first 10 only no more suffix warnings
 ;
 ;
 S ACHSDERR="",$P(ACHSDERR,"0",40)="",ACHSERRA=0
 ;
 ; Lookup LOCATION using ASUFAC.
 I $D(ACHSISAO) D  I Y<1 S ACHSERRE=21,ACHSEDAT=Y D ^ACHSEOBG Q
 . S DIC="^AUTTLOC(",DIC(0)="",D="C",X=ACHSEOBR("A",14)
 . D IX^DIC S:Y>0 DUZ(2)=+Y
 . Q
 ;
 ; Get financial data for LOCATION.
 D ^ACHSUF
 I $G(ACHSERR) S ACHSERRE=22,ACHSEDAT=$P($G(^DIC(4,DUZ(2),0)),U) D ^ACHSEOBG Q
 ;
 ; Attempt to match the Financial Code of the Document to one of the facilities on this machine.
 I $P(ACHSEOBR("A",12),"-",2)'=ACHSFC D  I $G(ACHSERRE) D ^ACHSEOBG Q
 . S ACHSERRE=7,ACHSEDAT=ACHSEOBR("A",12)
 . S ACHSYAYA=3.14159,DUZ(2)=0 ; Original value maintained in calling routine, ACHSEOBB.
 . F  S ACHSYAYA=99,DUZ(2)=$O(^ACHSF("B",DUZ(2))) Q:'DUZ(2)  D ^ACHSUF I '$G(ACHSERR),$P(ACHSEOBR("A",12),"-",2)=ACHSFC K ACHSERRE,ACHSEDAT Q
 .Q
 ;
 ; Check x-ref for P.O. number.
 S ACHSX="1"_$E(ACHSEOBR("A",12),2)_$E(ACHSEOBR("A",12),8,12),DA=$O(^ACHSF(DUZ(2),"D","B",ACHSX,0))
 I 'DA S ACHSERRE=1,ACHSEDAT=ACHSEOBR("A",12) D ^ACHSEOBG Q
 ;
 ; Check existence of global node.
 I '$D(^ACHSF(DUZ(2),"D",DA,0)) S ACHSERRE=2,ACHSEDAT=DA D ^ACHSEOBG Q
 S ACHSDOCR=$G(^ACHSF(DUZ(2),"D",DA,0))
 S ACHSDCR=$P(ACHSDOCR,U,19)
 ;
 ; Check for same P.O. number.
 I $E(ACHSEOBR("A",12),8,12)'=$P(ACHSDOCR,U) S ACHSERRE=3,ACHSEDAT=ACHSEOBR("A",12) D ^ACHSEOBG Q
 ;
 ; Check for P.O. Authorization date.
 S %=+ACHSEOBR("B",10)-17000000
 I '$D(^ACHSF(DUZ(2),"D",DA,3)) S ACHSERRE=35,ACHSEDAT=$$FMTE^XLFDT(%) D ^ACHSEOBG Q
 ;
 ; Check for P.O. Authorization date match.
 I (%'>($P($G(^ACHSF(DUZ(2),"D",DA,3)),U)-1)&%'<($P($G(^(3)),U,2)+1)) S ACHSERRE=4,ACHSEDAT=$$FMTE^XLFDT(%) D ^ACHSEOBG
 ;
 ; Check for Blanket Indicator match.
 I (ACHSEOBR("C",11)="Y"&($P(ACHSDOCR,U,3)'=1))!(ACHSEOBR("C",11)="N"&($P(ACHSDOCR,U,3)=1)) S ACHSERRE=5,ACHSEDAT=ACHSEOBR("C",11) D ^ACHSEOBG Q
 ;
 ; Check for P.O. type match.
 S X=+ACHSEOBR("A",15),X=$S(X=43:1,X=57:2,X=64:3,1:0)
 I X'=$P(ACHSDOCR,U,4) S ACHSERRE=6,ACHSEDAT=ACHSEOBR("A",15) D ^ACHSEOBG Q
 ;
 ; Check for HRN match.
 I +ACHSEOBR("B",9)'=+$P(ACHSDOCR,U,21) S ACHSERRE=30,ACHSEDAT=ACHSEOBR("B",9) D ^ACHSEOBG
 ;
 S ACHSPSQN=+ACHSEOBR("A",8)
 S ACHSPIND=ACHSEOBR("C",13)
 S ACHSPDAT=ACHSEOBR("A",11)-17000000 ;EOBR DATE FROM TRANSACTION RECORD
 ;
 ; Quit if duplicate transaction.
 I $D(^ACHSF(DUZ(2),"D",DA,"EB1",ACHSPDAT,ACHSPSQN)) S ACHSERRE=8,ACHSEDAT=$$FMTE^XLFDT(ACHSPDAT) D ^ACHSEOBG Q
 ;
CKCK ; Look for previous check number and compare, if same, error 3*15
 ; If match, checks for paid dates and sequence numbers
 ; Checks CHS check number as well as EOBR check numbers first
 D AINFO S ACHSDIEN=DA N ACHSOCHK S ACHSOCHK=""
 I ACHSCHK]"",$D(^ACHSF(DUZ(2),"D",DA,"PA")),+($$DOC^ACHS(2,2))=ACHSCHK S ACHSERRE=41,ACHSEDAT=ACHSCHK D ^ACHSEOBG Q
 I ACHSCHK]"",$D(^ACHSF(DUZ(2),"D",DA,"T")) D  Q:ACHSOCHK=ACHSCHK
 .N ACHSTMP,ACHSTMP2,ACHSOSQN,ACHSOPDT S ACHSTMP=0
 .F  S ACHSTMP=$O(^ACHSF(DUZ(2),"D",DA,"T",ACHSTMP)) Q:'ACHSTMP  D  Q:ACHSOCHK=ACHSCHK
 ..S ACHSTMP2=$G(^ACHSF(DUZ(2),"D",DA,"T",ACHSTMP,0))
 ..S ACHSOCHK=+$P(ACHSTMP2,U,18) ; Strip zeros
 ..Q:ACHSOCHK'=ACHSCHK  ; No match, includes achsochk=""
 ..S ACHSOSQN=$P(ACHSTMP2,U,14),ACHSOPDT=$P(ACHSTMP2,U,13)
 ..I ACHSOPDT'=ACHSPDAT S ACHSOCHK="" Q  ; Different paid dates
 ..I ACHSOSQN'=ACHSPSQN S ACHSOCHK="" Q  ; Different sequence numbers
 ..S ACHSERRE=42,ACHSEDAT=ACHSCHK D ^ACHSEOBG ; Must be duplicate
 ;
 ; If document Cancelled, quit.
 I +$P(ACHSDOCR,U,12)=4 S ACHSERRE=9,ACHSEDAT=$P(ACHSDOCR,U,12) D ^ACHSEOBG Q
 ;
 ; Object Class match.
 D CHKOCC^ACHSEOBN
 ;
 ; CAN match.
 I $E(ACHSEOBR("C",8),1,7)'=$P($G(^ACHS(2,$P(ACHSDOCR,U,6),0)),U) S ACHSERRE=11,ACHSEDAT=ACHSEOBR("C",8) D ^ACHSEOBG
 ;
 ;
 ;ACHS*3.1*23 CHG "E" TO VAR ACHSREJ FOR REC E OR J
 S DFN=$P(ACHSDOCR,U,22),ACHSIPA=+$E(ACHSEOBR(ACHSREJ,8),1,7)_"."_$E(ACHSEOBR(ACHSREJ,8),8,9),ACHSFULP=$S(+ACHSEOBR("D",11):"P",1:"F")
 S ACHS3RDP=$S(+ACHSEOBR("D",11):+$E(ACHSEOBR("D",11),1,7)_"."_$E(ACHSEOBR("D",11),8,9),1:""),ACHS3RDS="",ACHSOB=ACHSEOBR(ACHSREJ,9)
 ;
 ;
 ; Check for Interim Denial.
 I +ACHSIPA=0,ACHSPIND="I" S ACHSERRE=31,ACHSEDAT=ACHSPIND D ^ACHSEOBG Q
 ;
 ; Is final pay a 0 amount.
 I +ACHSIPA=0,+ACHS3RDP=0,ACHSPIND'="F" S ACHSERRE=12,ACHSEDAT=ACHSPIND D ^ACHSEOBG Q
 ;
NOERR ;Most of the error checking is done by this time
 S ACHSWKLD=+ACHSEOBR("B",11)
 S:'ACHSWKLD ACHSWKLD=1
 ;BEGIN Y2K BLOCK
 S (ACHS,ACHSWKLD(1),ACHSWKLD(2))=0,ACHSSVDT="99999999"
 K %DT
P1 ;
 S ACHS=$O(^TMP("ACHSEOB",$J,"F",ACHS)) G P2:'ACHS S ACHSX=$G(^TMP("ACHSEOB",$J,"F",ACHS))
 K ACHSTEMP D REC2^ACHSEOBB(ACHSX,.ACHSTEMP)
 I ACHSTEMP("F",8)<+ACHSSVDT S ACHSSVDT=ACHSTEMP("F",8)
 S X=$E(ACHSTEMP("F",8),5,8)_$E(ACHSTEMP("F",8),1,4)
 D ^%DT
 S ACHS("FM")=Y,X=$E(ACHSTEMP("F",9),5,8)_$E(ACHSTEMP("F",9),1,4)
 D ^%DT
 S ACHS("TO")=Y
 F ACHS("X2")=0:1 S X1=ACHS("FM"),X2=ACHS("X2") D C^%DTC I X=ACHS("TO") S ACHSWKLD(1)=ACHSWKLD(1)+ACHS("X2")+1 Q
 S ACHSWKLD(2)=ACHSWKLD(2)+ACHSTEMP("F",11)
 G P1
 ;
P2 ;
 S X=ACHSSVDT,ACHSSVDT=$S(X=99999999:"",1:X-17000000)
 S:ACHSWKLD(1)>ACHSWKLD ACHSWKLD=ACHSWKLD(1)
 S:ACHSWKLD(2)>ACHSWKLD ACHSWKLD=ACHSWKLD(2)
 S ACHSDIEN=DA
 ;END Y2K BLOCK
 ;
 ; If there is a 3P pay amount, and the patient has no insurance on
 ; the local machine in Patient Registration, send a bulletin.
 I ACHS3RDP,ACHSSVDT,'$$INSURED^ACHS(DFN,ACHSSVDT) D SENDMSG^ACHSEOBN
 ;
 ; Vendor missing or no-match.
 D VNDR^ACHSEOBN
 I 'ACHSPROV S ACHSERRE=15,ACHSEDAT=ACHSEOBR("C",16) D ^ACHSEOBG Q
 ;ITSC/SET/JVK ACHS*3.1*11 -Check Base EIN only no warning for suffix mismatch
 ;I ACHSPROV'=$P(ACHSDOCR,U,8) S ACHSERRE=36,ACHSEDAT=ACHSEOBR("C",16) D ^ACHSEOBG
 I $E(ACHSPROV,1,10)'=$E($P(ACHSDOCR,U,8),1,10) S ACHSERRE=36,ACHSEDAT=ACHSEOBR("C",16) D ^ACHSEOBG
 ;
 K ACHSBLKF
 I ACHSEOBR("C",11)="Y",ACHSEOBR("C",13)="I" S ACHSBLKF=""
 S ACHSTYP=+ACHSEOBR("A",15),ACHSTYP=$S(ACHSTYP=43:1,ACHSTYP=57:2,ACHSTYP=64:3,1:0),ACHSDRG=""
 ;
 ; DRG exist on local machine.
 I +ACHSEOBR("B",12) S ACHSDRG=+ACHSEOBR("B",12) I '$D(^ICD(ACHSDRG)) S ACHSDRG="" S ACHSERRE=20,ACHSEDAT=ACHSEOBR("B",12) D ^ACHSEOBG
 ;
PROCESS ; Process the adjustment or payment.
 K ACHSERRE,ACHSEDAT
 S (ACHSADDT,ACHSDIDT,ACHSDITY)=""
 I $D(^ACHSF(DUZ(2),"D",ACHSDIEN,"PA")) D  Q:ACHSERRA>0  G INTEREST
 . ;
 . ; If there is an Adjustment amount, do the Adjustment first.
 .D A4A^ACHSAJ        ;AUTOMATIC ADJUSTMENT
 .Q:ACHSERRA>0        ;
 .D AINFO             ;
 .S ACHSOB=ACHSEOBR(ACHSREJ,9) ;ACHS*3.1*23 CHG "E" TO VAR ACHSREJ FOR REC E OR J 
 . ;
 . ; If any interest amount, treat as an adjustment.
 .;'INTEREST PAID' AND 'INTEREST ADDTNL PENALTY PAID' FROM TRANSACTION
 . I '$G(ACHSEOBR("I",12)),'$G(ACHSEOBR("I",13)) Q
 . S ACHSIPA=ACHSEOBR("I",12)+ACHSEOBR("I",13)
 . S ACHSIPA=$E(ACHSIPA,1,$L(ACHSIPA)-2)_"."_$E(ACHSIPA,$L(ACHSIPA)-1,$L(ACHSIPA))
 . D A4A^ACHSAJ
 ;
 ;
 ;ACHS*3.1*23 CHG "E" TO VAR ACHSREJ FOR REC E OR J
 I +ACHSEOBR(ACHSREJ,8)=0,+ACHS3RDP=0,ACHSPIND="F" D  G INTEREST
 .S X=0
 .S X1=0
 .D TRAN                     ;
 .D A3^ACHSPA:X1'=ACHSPDAT   ;AUTOMATIC EOBR PROCESSING IF EOBR DATE
 .                           ;AND PAID DATE NOT THE SAME ;THESE SEEM TO
 .                           ;BE GOTTEN FROM THE SAME FIELD?????
 .S ACHSERRE=32              ;WHY AUTO SET ERROR?????DOC CANCELLED BY FI
 .;ACHS*3.1*23 CHG "E" TO VAR ACHSREJ FOR REC E OR J
 .S ACHSEDAT=ACHSEOBR(ACHSREJ,8)_"  "_ACHSPIND  ;'IHS PAYMENT AMOUNT' 'TRANSACTION TYPE'
 .D ^ACHSEOBG                ;SET ERROR INTO ERROR GLOBAL ^ACHSEOBR("ER"
 .Q
 ;
 D A3^ACHSPA      ;AUTOMATIC EOBR PROCESSING
 Q:ACHSERRA>0
 ;
 ; Process Interest as Adjustment if any interest amounts were
 ; included with a final pay.
 ;IF 'INTEREST PAID' AND 'INTEREST ADDTNL PENALTY PAID' 
V I $G(ACHSEOBR("I",12))!$G(ACHSEOBR("I",13)) D  Q:ACHSERRA>0
 . S ACHSIPA=ACHSEOBR("I",12)+ACHSEOBR("I",13)
 .;THIS IS A PROBLEM IT DROPS DIGITS IF ACHSIPA ["."
 . S ACHSIPA=$E(ACHSIPA,1,$L(ACHSIPA)-2)_"."_$E(ACHSIPA,$L(ACHSIPA)-1,$L(ACHSIPA))
 . D A4A^ACHSAJ        ;AUTOMATIC ADJUSTMENT
 ;
 ;
INTEREST ; Post Interest data.
 ;
 ;ACHS*3.1*4  if an error has occurred, don't continue
 I $D(ACHSERRE) Q  ;  ACHS*3.1*4
 ;
 ;IF INTEREST DATA DO AUTOMATIC EOBR PROCESSING OF INTEREST DATA
 I $D(ACHSEOBR("I")) D AUTO^ACHSPAI
 ;
 ; Check/post ICD/CPT/Revenue codes(s), Procedure codes
 D ICD^ACHSEOB4,CPTREV^ACHSEOB4,PROC^ACHSEOB4
 ;
 ;IF REFERRAL PTR
 I $$DOC^ACHS(2,7) D
 .D DX^ACHSBMC        ;TRANSFER DX INFO INTO RCIS
 .D PX^ACHSBMC        ;TRANSFER PX INFO INTO RCIS
 ;
 ;IF 'DRG' IS NOT PRESENT SET DRG AND REFERRAL DRG AND REFERRED EST.COST
 I $D(^ACHSF(DUZ(2),"D",ACHSDIEN,8)),'$P(^ACHSF(DUZ(2),"D",ACHSDIEN,8),U) D
 .S ACHS("DX")=9,ACHS("PX")=10
 .D CDRG^ACHSPAM                ;THIS EXITS RIGHT AWAY
 ;
 ; Post CHS data to PCC
 S ACHSDOCR=$G(^ACHSF(DUZ(2),"D",ACHSDIEN,0))    ;DOCUMENT 0 NODE
 ;
 ;IF 'POST EOBR TO PAT CARE CMPNT' AND LINK TO PCC IS ON
 ;TRANSFER DATA TO PATIENT CARE COMPONENT
 I $$PARM^ACHS(2,22)="Y",$$LINK^ACHSPAP1 U IO(0) D ^ACHSPAP U IO
 Q
 ;
TRAN ;
 ;GET LAST TRANSACTION ENTRY ????
 ;REPLACE WITH $D(,-1)
 S X=$O(^ACHSF(DUZ(2),"D",ACHSDIEN,"T",X))
 Q:X=""
 G TRAN:X=0
 S X1=$S($P(^ACHSF(DUZ(2),"D",ACHSDIEN,"T",X,0),U,13):$P(^(0),U,13),1:0)
 G TRAN
 ;
AINFO ;Set basic info from A record.  IF THIS IS A STUFF WHY "C" IN HERE?????
 S ACHSCTL=ACHSEOBR("A",13)_ACHSEOBR("A",5)  ;FIRST 7 OF CONTROL #_ EOBR CONTROL #  ????
 S ACHSCHK=ACHSEOBR("A",9)     ;CHECK #
 S ACHSREM=ACHSEOBR("A",10)    ;EOBR REMIT. #
 S ACHSSV=ACHSEOBR("C",10)     ;EOBR SERVICES BILLED
 Q
 ;