ABSPECP1 ; IHS/FCS/DRS - printing for PCS ; [ 10/09/2002 8:01 AM ]
;;1.0;PHARMACY POINT OF SALE;**3,12,17,23,42,44,49**;JUN 21, 2001;Build 38
;
;---------------------------------
;IHS/SD/lwj 10/08/02 NCPDP 5.1 changes
; With 5.1 the segments, fields, and field identifiers changed.
; This routine had to be adjusted to account for the differences
; between a 5.1 and 3.2 claims. Changes made where needed.
;---------------------------------
;IHS/SD/lwj 3/11/05 patch 12 need to add the DUR segment to
; the claim and response portions of the receipt
;---------------------------------
;IHS/SD/RLT - 05/01/06 - Patch 17
; Allow for double zeros in fields 440 and 441.
; Fix the displaying of multiple DUR sets.
;---------------------------------
;IHS/SD/RLT - 08/03/07 - 10/18/07 - Patch 23
; Diagnois Code
Q
TEST K TMP D FILEMAN("TMP",255)
;O 51:("TMP.OUT":"W") U 51 ZW TMP C 51
Q
FILEMAN(DEST,IEN,FIELDS,RX,RXFIELDS) ;EP - from ABSPECP0 and ABSPOS6E
; generalized FileMan fetch for pharm e-claims and responses
; DEST = destination (closed ref, used in @DEST@(subs) format)
; if global, it must be ^TMP or ^UTILITY
; FILE = file number (9002313.02 or 9002313.03)
; IEN as usual; FIELDS = the DR string of field numbers
; RX = prescription sub-entry; RXFIELDS = the DR string for it
; FIELDS, RX, RXFIELDS optional; they default to all RXs,all fields
; Returns @DEST@("C",field)=value for fields in the claim
; @DEST@("C",field,"RX",rx,field)=value
; @DEST@("R" similarly
; where "field" is field name (not field number)
K ^UTILITY("DIQ1",$J)
N FILE S FILE=9002313.02 D FM1
S FILE=9002313.03,IEN=$O(^ABSPR("B",IEN,""),-1) ; last resp
I IEN D
.D FM1
D FORMAT
Q
FORMAT ; ^UTILITY("DIQ1",$J,file,DA,field,*)->@TMP@(...)
;------------------------
;IHS/SD/lwj 10/08/02 NCPDP 5.1 changes
; added the NCPDP field to decipher the version - this will help
; in the data translation
;-------------------------
N SRC S SRC="^UTILITY(""DIQ1"",$J)"
N EFORMAT,INSURER,FILE,DA,FIELD
N NCPDP51 ;IHS/SD/lwj 10/08/02 NCPDP 5.1 change
S NCPDP51=0 ;IHS/SD/lwj 10/08/02 NCPDP 5.1 change
N RXSEQ ;IHS/SD/lwj 6/13/05 need to know the rx seq
S RXSEQ=1 ;IHS/SD/lwj 6/13/05 default it to one
S DA=$O(@SRC@(9002313.02,0))
S INSURER=$G(@SRC@(9002313.02,DA,.02,"I"))
I INSURER S EFORMAT=$P($G(^ABSPEI(INSURER,100)),U)
E S EFORMAT=0
I ('EFORMAT),$G(^ABSP(9002313.99,1,"ABSPICNV"))'=1 W "Internal error - no FORMAT for INSURER=",INSURER,! Q
;
S:$G(@SRC@(9002313.02,DA,102,"I"))=51 NCPDP51=1
;IHS/OIT/CASSEVERN/RAN - 02/10/2011 - Patch 42 Temporary change to allow printing of D.0 receipts as if they were 5.1 Receipts
S:$G(@SRC@(9002313.02,DA,102,"I"))="D0" NCPDP51=1
;
;ZW EFORMAT
S FILE="" F S FILE=$O(@SRC@(FILE)) Q:'FILE D
.S DA="" F S DA=$O(@SRC@(FILE,DA)) Q:'DA D
..N FIELD S FIELD="" F S FIELD=$O(@SRC@(FILE,DA,FIELD)) Q:'FIELD D
...I EFORMAT,'$$INCLUDE(EFORMAT,FILE,FIELD) D Q
....;W "FORMAT+n^",$T(+0)," excludes EFORMAT=",EFORMAT,", FIELD=",FIELD,!
...;IHS/SD/lwj 6/13/05 patch 12 need to know the rx sequence
...S:((FILE=9002313.0301)&(FIELD=.01)) RXSEQ=DA
...D FMTFIELD
Q
INCLUDE(EFORMAT,FILE,FIELD) ; is the field part of this protocol?
; returns 1 or 10 or 20 or 30 or 40 maybe with ^ID appended
;--------------------------------
;IHS/SD/lwj 10/08/02 NCPDP 5.1 changes - need to include all
; the new segments
;
;--------------------------------
;
N START,END
S START=10,END=40
I NCPDP51 S START=100,END=230
;
I FILE=9002313.03 Q 1 ; always yes for response fields
I FILE=9002313.0301 Q 1 ; always yes for response fields
I FILE=9002313.1101 Q 1 ; IHS/SD/lwj 3/11/05 patch 12 DUR resp segment
I FIELD<101!(FIELD>600) Q 1 ; yes for fields outside protocol range
N FIELDIEN S FIELDIEN=$O(^ABSPF(9002313.91,"B",FIELD,0))
I FIELDIEN="" Q 0 ; should never happen?
;IHS/OIT/CASSEVER/RAN 03/24/2011 patch 42 Get rid of references to formats for new method of claims processing
I $P($G(^ABSP(9002313.99,1,"ABSPICNV")),"^",1)=1 Q "110^"_$$FIELDID(FIELD)
;
;IHS/SD/lwj 10/08/02 NCPDP 5.1 nxt line remarked out, following added
;N I,FIND S FIND=0 F I=10,20,30,40 D Q:$G(FIND)
N I,FIND S FIND=0 F I=START:10:END D Q:$G(FIND)
.N J S J=0
.F S J=$O(^ABSPF(9002313.92,EFORMAT,I,J)) Q:'J D Q:$G(FIND)
..I $P(^ABSPF(9002313.92,EFORMAT,I,J,0),U,2)=FIELDIEN D
...S FIND=I
...S FIND=FIND_U_$$FIELDID(FIELD)
Q FIND
FIELDID(FIELD) ; the two character field ID, given the external field #
;--------------------------------------
;IHS/SD/lwj 10/08/02 NCPDP 5.1 changes
; With 5.1 all the fields will have a field identifier, except for the
; header segment. Must adjust this routine to account for that.
; (NCPDP51 is defined in the FORMAT subroutine and is based on fld 102)
;
;--------------------------------------
N ID
N FIELDIEN S FIELDIEN=$O(^ABSPF(9002313.91,"B",FIELD,0))
I FIELDIEN="" Q ""
;
S:'NCPDP51 ID=$P(^ABSPF(9002313.91,FIELDIEN,0),U,2)
S:NCPDP51 ID=$P($G(^ABSPF(9002313.91,FIELDIEN,5)),U)
;
;IHS/SD/lwj 10/08/02 NCPDP 5.1 nxt line remarked out - following added
;Q $P(^ABSPF(9002313.91,FIELDIEN,0),U,2)
Q ID
;
ISVARFLD(EFORMAT,FILE,FIELD) ; is it a variable length field?
;---------------------------------
;IHS/SD/lwj 10/08/02 NCPDP 5.1 changes
; if we are working with a 5.1 format, and it's any segment other
; than 100, return the field id.
;---------------------------------
; returns 2-char field ID if it is
N X S X=$$INCLUDE(EFORMAT,FILE,FIELD)
Q:(NCPDP51)&(X>100) $P(X,U,2) ;IHS/SD/lwj 10/08/02 NCPDP 5.1
I +X=20!(+X=40) Q $P(X,U,2)
E Q ""
FMTFIELD ; given FILE,DA,FIELD,@SRC@(FILE,DA,FIELD,"E" and "I"), set @TMP
; given INSURER and EFORMAT, too
; Fetch the INT and EXT values
;-----------------------------------------
;IHS/SD/lwj 10/08/02 NCPDP 5.1 changes
; needed to format a couple of the newer field a little different
;-----------------------------------------
;
N INT S INT=$G(@SRC@(FILE,DA,FIELD,"I"))
N EXT S EXT=$G(@SRC@(FILE,DA,FIELD,"E"))
; If it's a variable field, remove the field ID
N VARFIELD
;
;IHS/SD/lwj 10/08/02 NCPDP 5.1 fields need more formatting
N CKFLD,FLDLST
;IHS/SD/lwj 3/11/05 patch 12, need to format 412 (disp fee)
;nxt line remrkd out, following added
;S FLDLST=",409,448,449,477,480,481,482,483,487,558,562,566,"
;S FLDLST=",409,412,448,449,477,480,481,482,483,487,558,562,566,"
;IHS/OIT/SCR 12/05/08 patch 28 t4 need to format 438 (Incentive amount)
S FLDLST=",409,412,448,449,477,480,481,482,483,487,558,562,566,438,"
I FIELD=524 S VARFIELD="FO" ; have to hardcode response cases
E S VARFIELD=$$ISVARFLD(EFORMAT,FILE,FIELD)
I VARFIELD]"" D
.I $E(INT,1,2)=VARFIELD S INT=$E(INT,3,$L(INT))
.I $E(EXT,1,2)=VARFIELD S EXT=$E(EXT,3,$L(EXT))
;I FIELD=422 ZW VARFIELD,EFORMAT,FILE,FIELD,INT,EXT
; Trailing spaces, leading zeroes
F Q:$E(EXT,$L(EXT))'=" " S EXT=$E(EXT,1,$L(EXT)-1)
;IHS/SD/RLT - 05/01/06 - Patch 17
;Allow for double zeros in fields 440 and 441
;I FIELD'=407,FIELD'=302 D
;Patch 23 added 492 below
;OIT/CAS/RCS 10022012 - Patch 44, added fields 101, 104, 301, 303 and 110
; /IHS/OIT/RAM 03 OCT 17 ; CR09769 - P49 - REMOVE ZERO SUPPRESSION FROM REC REPORT OF DUR / NDC FIELD 476
I FIELD'=407,FIELD'=302,FIELD'=440,FIELD'=441,FIELD'=492,FIELD'=101,FIELD'=104,FIELD'=301,FIELD'=110,FIELD'=303,FIELD'=476 D
.F Q:$E(EXT)'=0 Q:$L(EXT)=1 S EXT=$E(EXT,2,$L(EXT))
I FIELD=426!(FIELD=430) D ; for some reason they're missed
.S EXT="$"_$J($$DFF2EXT^ABSPECFM(EXT),7,2)
;
;IHS/SD/lWJ 10/08/02 NCPDP 5.1 some more signed fields
S CKFLD=","_FIELD_","
S:FLDLST[CKFLD EXT="$"_$J($$DFF2EXT^ABSPECFM(EXT),7,2)
;
;IHS/SD/lwj 3/11/05 format .01 fld for claim DUR
S:((FIELD=.01)&(FILE=9002313.1001)) EXT=$E(EXT,3,$L(EXT))
;
; Format .01 fld for claim DIAG Patch 23
S:((FIELD=.01)&(FILE=9002313.0701)) EXT=$E(EXT,3,$L(EXT))
;
I FIELD=103 S EXT=$$TCODE^ABSPECP2(EXT)
; Get the field name
N FLDNAME S FLDNAME=$P(^DD(FILE,FIELD,0),U)
; If it's a date field that didn't get formatted, format it
I FLDNAME["Date",EXT?8N D
.N Y S Y=EXT-17000000 X ^DD("DD") S EXT=Y
; Other enumerated fields
;IHS/SD/lwj 10/08/02 NCPDP 5.1 field now include "Patient"
I FLDNAME="Patient Relationship Code" D
.S EXT=$S(EXT=1:"Cardholder",EXT=2:"Spouse",EXT=3:"Child",EXT=4:"Other Dependent",1:EXT)
I FLDNAME="Compound Code" D
.S EXT=$S(EXT=1:"Not a compound",EXT=2:"Compound",1:EXT)
I FLDNAME="Dispense As Written" S EXT=$$DAW^ABSPECP2(EXT)
I FLDNAME="Basis of Reimb Determination" S EXT=$$REIMB^ABSPECP2(EXT)
I FLDNAME="Diagnosis Code Count" S FLDNAME="DIAG Count" ;Patch 23
; Store it
I EXT="",'$$INCLUDE(EFORMAT,FILE,FIELD) Q
I FILE=9002313.02 D
.S @DEST@("C",FLDNAME)=EXT
E I FILE=9002313.0201 D
.S @DEST@("C",FLDNAME,"RX",DA)=EXT
E I FILE=9002313.1001 D ;IHS/SD/lwj 3/11/05 patch 12 clm DUR
.;IHS/SD/RLT - 05/01/06 - Patch 17
.;Fix displaying of multiple DUR sets
.;S @DEST@("C","DUR entry "_DA_": "_FLDNAME,"RX",DA)=EXT
.S @DEST@("C","DUR entry "_DA_": "_FLDNAME,"RX",RXSEQ)=EXT
E I FILE=9002313.0701 D ;Patch 23
.S @DEST@("C","DIAG entry "_DA_": "_FLDNAME,"RX",RXSEQ)=EXT ;Patch 23
E I FILE=9002313.03 D
.S @DEST@("R",FLDNAME)=EXT
E I FILE=9002313.0301 D
.I FLDNAME="Additional Message Information" S FLDNAME="Message (more)"
.S @DEST@("R",FLDNAME,"RX",DA)=EXT
E I FILE=9002313.1101 D ;IHS/SD/lwj 3/11/05 patch 12 DUR resp
.S @DEST@("R","DUR Resp "_DA_" "_FLDNAME,"RX",RXSEQ)=EXT
E D IMPOSS^ABSPOSUE("P","TI",,,"FMTFIELD",$T(+0))
Q
FM1 N DIC,DR,DA,DIQ,SUBFILE
I '$D(FIELDS) S FIELDS=".01:99999999"
I '$D(RX)
I '$D(RXFIELDS) S RXFIELDS=".01:99999999"
; Safety - make sure if DEST is global, it's probably a scratch global
I DEST?1"^".E I DEST'?1"^TMP("1E.E,DEST'?1"^UTILITY("1E.E D IMPOSS^ABSPOSUE("P","TI","Bad DEST",DEST,"FM1",$T(+0))
D FETCH ; gives ^UTILITY("DIQ1",$J,file,DA,field,"E") and ^("I")
Q
FETCH ;
I '$D(RX) N RX S RX=0 D Q
.; RX not yet determined: recurse
.N GLO S GLO="^ABSP"_$S(FILE=9002313.02:"C",FILE=9002313.03:"R")
.N SUB S SUB=$S(FILE=9002313.02:400,FILE=9002313.03:1000)
.F S RX=$O(@GLO@(FILE,IEN,SUB,RX)) Q:'RX D
..D 2
2 ; with RX determined
I FILE=9002313.03 D ; Reject Code(s) done manually
.N X S X=0 F S X=$O(^ABSPR(IEN,1000,RX,511,X)) Q:'X D
..;ZW X W ^(X,0),!
..N Y S Y=^ABSPR(IEN,1000,RX,511,X,0),Y=$P(Y,U)
..N Z S Z=$O(^ABSPF(9002313.93,"B",Y,0))
..;W Y," -> ",Z,!
..I Z,$D(^ABSPF(9002313.93,Z,0)) S Z=$P(^(0),U,2)
..S @DEST@("R","Reject Code","RX",RX,$S(Y?1"0"1N:+Y,1:Y))=Y_" "_Z
..;ZW @DEST@("R","Reject Code","RX") R ">>",%,!
.;Preferred Product data sent back
.N X S X=0 F S X=$O(^ABSPR(IEN,1000,RX,551.01,X)) Q:'X D
..N Y S Y=$G(^ABSPR(IEN,1000,RX,551.01,X,1)) I Y="" Q
..N Z S Z=$P(Y,"^",2)_" "_$P(Y,"^",5)
..S @DEST@("R","Preferred Product","RX",RX,X)=Z
.;Additional Message Information sent back
.N X S X=0 F S X=$O(^ABSPR(IEN,1000,RX,526,X)) Q:'X D
..N Y S Y=$G(^ABSPR(IEN,1000,RX,526,X,0)) I Y="" Q
..S @DEST@("R","Additional Information","RX",RX,X)=Y
S DIC=FILE,DA=IEN,DR=FIELDS,DIQ(0)="IEN"
S SUBFILE=FILE+.0001 ; as it happens to work out
S DA(SUBFILE)=RX
S DR(SUBFILE)=RXFIELDS
D EN^DIQ1
;
;IHS/SD/lwj 3/11/05 patch 12 retrieve the claim and resp DUR
D:FILE=9002313.02 SETCDUR ;retrieve the claim DUR info
D:FILE=9002313.03 SETRDUR ;retrieve the response DUR info
;
;
;IHS/SD/RLT - 08/03/07 - Patch 23
; Diagnois Code information
D:FILE=9002313.02 SETCDIAG ;retrieve the claim DIAG info
;
Q
SETCDUR ;------------------------------------------------------------
;IHS/SD/LWJ 3/11/05 patch 12
; set fields needed to retrieve DUR information from the claim
;------------------------------------------------------------
N DURCNT
;
S DURCNT=0
S DR(9002313.0201)=473.01
S DR(9002313.1001)=".01;439;440;441;474;475;476" ;fields
;
F S DURCNT=$O(^ABSPC(IEN,400,RX,473.01,DURCNT)) Q:DURCNT="" D
. S DA(9002313.1001)=DURCNT
. S DIQ(0)="IEN"
. D EN^DIQ1
;
Q
SETRDUR ;----------------------------------------------------------------
;IHS/SD/lwj 3/11/05 patch 12
; set fields needed to retrieve DUR information from the response
;----------------------------------------------------------------
N DURCNT
;
S DURCNT=0
S DR(9002313.0301)=567.01 ;DUR multiple
S DR(9002313.1101)=".01;439;528;529;530;531;532;533;544" ;fields
;
F S DURCNT=$O(^ABSPR(IEN,1000,RX,567.01,DURCNT)) Q:DURCNT="" D
. S DA(9002313.1101)=DURCNT
. S DIQ(0)="IEN"
. D EN^DIQ1
;
Q
SETCDIAG ;
;IHS/SD/RLT - 08/03/07 - 10/18/07 - Patch 23
; set Diagnosis Code information from the claim
;
N DIAGCNT
;
S DIAGCNT=0
S DR(9002313.0201)=491.01
S DR(9002313.0701)=".01;492;424" ;fields
;
F S DIAGCNT=$O(^ABSPC(IEN,400,RX,491.01,DIAGCNT)) Q:'+DIAGCNT D
. S DA(9002313.0701)=DIAGCNT
. S DIQ(0)="IEN"
. D EN^DIQ1
;
Q
ABSPECP1 ; IHS/FCS/DRS - printing for PCS ; [ 10/09/2002 8:01 AM ]
+1 ;;1.0;PHARMACY POINT OF SALE;**3,12,17,23,42,44,49**;JUN 21, 2001;Build 38
+2 ;
+3 ;---------------------------------
+4 ;IHS/SD/lwj 10/08/02 NCPDP 5.1 changes
+5 ; With 5.1 the segments, fields, and field identifiers changed.
+6 ; This routine had to be adjusted to account for the differences
+7 ; between a 5.1 and 3.2 claims. Changes made where needed.
+8 ;---------------------------------
+9 ;IHS/SD/lwj 3/11/05 patch 12 need to add the DUR segment to
+10 ; the claim and response portions of the receipt
+11 ;---------------------------------
+12 ;IHS/SD/RLT - 05/01/06 - Patch 17
+13 ; Allow for double zeros in fields 440 and 441.
+14 ; Fix the displaying of multiple DUR sets.
+15 ;---------------------------------
+16 ;IHS/SD/RLT - 08/03/07 - 10/18/07 - Patch 23
+17 ; Diagnois Code
+18 QUIT
TEST KILL TMP
DO FILEMAN("TMP",255)
+1 ;O 51:("TMP.OUT":"W") U 51 ZW TMP C 51
+2 QUIT
FILEMAN(DEST,IEN,FIELDS,RX,RXFIELDS) ;EP - from ABSPECP0 and ABSPOS6E
+1 ; generalized FileMan fetch for pharm e-claims and responses
+2 ; DEST = destination (closed ref, used in @DEST@(subs) format)
+3 ; if global, it must be ^TMP or ^UTILITY
+4 ; FILE = file number (9002313.02 or 9002313.03)
+5 ; IEN as usual; FIELDS = the DR string of field numbers
+6 ; RX = prescription sub-entry; RXFIELDS = the DR string for it
+7 ; FIELDS, RX, RXFIELDS optional; they default to all RXs,all fields
+8 ; Returns @DEST@("C",field)=value for fields in the claim
+9 ; @DEST@("C",field,"RX",rx,field)=value
+10 ; @DEST@("R" similarly
+11 ; where "field" is field name (not field number)
+12 KILL ^UTILITY("DIQ1",$JOB)
+13 NEW FILE
SET FILE=9002313.02
DO FM1
+14 ; last resp
SET FILE=9002313.03
SET IEN=$ORDER(^ABSPR("B",IEN,""),-1)
+15 IF IEN
Begin DoDot:1
+16 DO FM1
End DoDot:1
+17 DO FORMAT
+18 QUIT
FORMAT ; ^UTILITY("DIQ1",$J,file,DA,field,*)->@TMP@(...)
+1 ;------------------------
+2 ;IHS/SD/lwj 10/08/02 NCPDP 5.1 changes
+3 ; added the NCPDP field to decipher the version - this will help
+4 ; in the data translation
+5 ;-------------------------
+6 NEW SRC
SET SRC="^UTILITY(""DIQ1"",$J)"
+7 NEW EFORMAT,INSURER,FILE,DA,FIELD
+8 ;IHS/SD/lwj 10/08/02 NCPDP 5.1 change
NEW NCPDP51
+9 ;IHS/SD/lwj 10/08/02 NCPDP 5.1 change
SET NCPDP51=0
+10 ;IHS/SD/lwj 6/13/05 need to know the rx seq
NEW RXSEQ
+11 ;IHS/SD/lwj 6/13/05 default it to one
SET RXSEQ=1
+12 SET DA=$ORDER(@SRC@(9002313.02,0))
+13 SET INSURER=$GET(@SRC@(9002313.02,DA,.02,"I"))
+14 IF INSURER
SET EFORMAT=$PIECE($GET(^ABSPEI(INSURER,100)),U)
+15 IF '$TEST
SET EFORMAT=0
+16 IF ('EFORMAT)
IF $GET(^ABSP(9002313.99,1,"ABSPICNV"))'=1
WRITE "Internal error - no FORMAT for INSURER=",INSURER,!
QUIT
+17 ;
+18 IF $GET(@SRC@(9002313.02,DA,102,"I"))=51
SET NCPDP51=1
+19 ;IHS/OIT/CASSEVERN/RAN - 02/10/2011 - Patch 42 Temporary change to allow printing of D.0 receipts as if they were 5.1 Receipts
+20 IF $GET(@SRC@(9002313.02,DA,102,"I"))="D0"
SET NCPDP51=1
+21 ;
+22 ;ZW EFORMAT
+23 SET FILE=""
FOR
SET FILE=$ORDER(@SRC@(FILE))
IF 'FILE
QUIT
Begin DoDot:1
+24 SET DA=""
FOR
SET DA=$ORDER(@SRC@(FILE,DA))
IF 'DA
QUIT
Begin DoDot:2
+25 NEW FIELD
SET FIELD=""
FOR
SET FIELD=$ORDER(@SRC@(FILE,DA,FIELD))
IF 'FIELD
QUIT
Begin DoDot:3
+26 IF EFORMAT
IF '$$INCLUDE(EFORMAT,FILE,FIELD)
Begin DoDot:4
+27 ;W "FORMAT+n^",$T(+0)," excludes EFORMAT=",EFORMAT,", FIELD=",FIELD,!
End DoDot:4
QUIT
+28 ;IHS/SD/lwj 6/13/05 patch 12 need to know the rx sequence
+29 IF ((FILE=9002313.0301)&(FIELD=.01))
SET RXSEQ=DA
+30 DO FMTFIELD
End DoDot:3
End DoDot:2
End DoDot:1
+31 QUIT
INCLUDE(EFORMAT,FILE,FIELD) ; is the field part of this protocol?
+1 ; returns 1 or 10 or 20 or 30 or 40 maybe with ^ID appended
+2 ;--------------------------------
+3 ;IHS/SD/lwj 10/08/02 NCPDP 5.1 changes - need to include all
+4 ; the new segments
+5 ;
+6 ;--------------------------------
+7 ;
+8 NEW START,END
+9 SET START=10
SET END=40
+10 IF NCPDP51
SET START=100
SET END=230
+11 ;
+12 ; always yes for response fields
IF FILE=9002313.03
QUIT 1
+13 ; always yes for response fields
IF FILE=9002313.0301
QUIT 1
+14 ; IHS/SD/lwj 3/11/05 patch 12 DUR resp segment
IF FILE=9002313.1101
QUIT 1
+15 ; yes for fields outside protocol range
IF FIELD<101!(FIELD>600)
QUIT 1
+16 NEW FIELDIEN
SET FIELDIEN=$ORDER(^ABSPF(9002313.91,"B",FIELD,0))
+17 ; should never happen?
IF FIELDIEN=""
QUIT 0
+18 ;IHS/OIT/CASSEVER/RAN 03/24/2011 patch 42 Get rid of references to formats for new method of claims processing
+19 IF $PIECE($GET(^ABSP(9002313.99,1,"ABSPICNV")),"^",1)=1
QUIT "110^"_$$FIELDID(FIELD)
+20 ;
+21 ;IHS/SD/lwj 10/08/02 NCPDP 5.1 nxt line remarked out, following added
+22 ;N I,FIND S FIND=0 F I=10,20,30,40 D Q:$G(FIND)
+23 NEW I,FIND
SET FIND=0
FOR I=START:10:END
Begin DoDot:1
+24 NEW J
SET J=0
+25 FOR
SET J=$ORDER(^ABSPF(9002313.92,EFORMAT,I,J))
IF 'J
QUIT
Begin DoDot:2
+26 IF $PIECE(^ABSPF(9002313.92,EFORMAT,I,J,0),U,2)=FIELDIEN
Begin DoDot:3
+27 SET FIND=I
+28 SET FIND=FIND_U_$$FIELDID(FIELD)
End DoDot:3
End DoDot:2
IF $GET(FIND)
QUIT
End DoDot:1
IF $GET(FIND)
QUIT
+29 QUIT FIND
FIELDID(FIELD) ; the two character field ID, given the external field #
+1 ;--------------------------------------
+2 ;IHS/SD/lwj 10/08/02 NCPDP 5.1 changes
+3 ; With 5.1 all the fields will have a field identifier, except for the
+4 ; header segment. Must adjust this routine to account for that.
+5 ; (NCPDP51 is defined in the FORMAT subroutine and is based on fld 102)
+6 ;
+7 ;--------------------------------------
+8 NEW ID
+9 NEW FIELDIEN
SET FIELDIEN=$ORDER(^ABSPF(9002313.91,"B",FIELD,0))
+10 IF FIELDIEN=""
QUIT ""
+11 ;
+12 IF 'NCPDP51
SET ID=$PIECE(^ABSPF(9002313.91,FIELDIEN,0),U,2)
+13 IF NCPDP51
SET ID=$PIECE($GET(^ABSPF(9002313.91,FIELDIEN,5)),U)
+14 ;
+15 ;IHS/SD/lwj 10/08/02 NCPDP 5.1 nxt line remarked out - following added
+16 ;Q $P(^ABSPF(9002313.91,FIELDIEN,0),U,2)
+17 QUIT ID
+18 ;
ISVARFLD(EFORMAT,FILE,FIELD) ; is it a variable length field?
+1 ;---------------------------------
+2 ;IHS/SD/lwj 10/08/02 NCPDP 5.1 changes
+3 ; if we are working with a 5.1 format, and it's any segment other
+4 ; than 100, return the field id.
+5 ;---------------------------------
+6 ; returns 2-char field ID if it is
+7 NEW X
SET X=$$INCLUDE(EFORMAT,FILE,FIELD)
+8 ;IHS/SD/lwj 10/08/02 NCPDP 5.1
IF (NCPDP51)&(X>100)
QUIT $PIECE(X,U,2)
+9 IF +X=20!(+X=40)
QUIT $PIECE(X,U,2)
+10 IF '$TEST
QUIT ""
FMTFIELD ; given FILE,DA,FIELD,@SRC@(FILE,DA,FIELD,"E" and "I"), set @TMP
+1 ; given INSURER and EFORMAT, too
+2 ; Fetch the INT and EXT values
+3 ;-----------------------------------------
+4 ;IHS/SD/lwj 10/08/02 NCPDP 5.1 changes
+5 ; needed to format a couple of the newer field a little different
+6 ;-----------------------------------------
+7 ;
+8 NEW INT
SET INT=$GET(@SRC@(FILE,DA,FIELD,"I"))
+9 NEW EXT
SET EXT=$GET(@SRC@(FILE,DA,FIELD,"E"))
+10 ; If it's a variable field, remove the field ID
+11 NEW VARFIELD
+12 ;
+13 ;IHS/SD/lwj 10/08/02 NCPDP 5.1 fields need more formatting
+14 NEW CKFLD,FLDLST
+15 ;IHS/SD/lwj 3/11/05 patch 12, need to format 412 (disp fee)
+16 ;nxt line remrkd out, following added
+17 ;S FLDLST=",409,448,449,477,480,481,482,483,487,558,562,566,"
+18 ;S FLDLST=",409,412,448,449,477,480,481,482,483,487,558,562,566,"
+19 ;IHS/OIT/SCR 12/05/08 patch 28 t4 need to format 438 (Incentive amount)
+20 SET FLDLST=",409,412,448,449,477,480,481,482,483,487,558,562,566,438,"
+21 ; have to hardcode response cases
IF FIELD=524
SET VARFIELD="FO"
+22 IF '$TEST
SET VARFIELD=$$ISVARFLD(EFORMAT,FILE,FIELD)
+23 IF VARFIELD]""
Begin DoDot:1
+24 IF $EXTRACT(INT,1,2)=VARFIELD
SET INT=$EXTRACT(INT,3,$LENGTH(INT))
+25 IF $EXTRACT(EXT,1,2)=VARFIELD
SET EXT=$EXTRACT(EXT,3,$LENGTH(EXT))
End DoDot:1
+26 ;I FIELD=422 ZW VARFIELD,EFORMAT,FILE,FIELD,INT,EXT
+27 ; Trailing spaces, leading zeroes
+28 FOR
IF $EXTRACT(EXT,$LENGTH(EXT))'=" "
QUIT
SET EXT=$EXTRACT(EXT,1,$LENGTH(EXT)-1)
+29 ;IHS/SD/RLT - 05/01/06 - Patch 17
+30 ;Allow for double zeros in fields 440 and 441
+31 ;I FIELD'=407,FIELD'=302 D
+32 ;Patch 23 added 492 below
+33 ;OIT/CAS/RCS 10022012 - Patch 44, added fields 101, 104, 301, 303 and 110
+34 ; /IHS/OIT/RAM 03 OCT 17 ; CR09769 - P49 - REMOVE ZERO SUPPRESSION FROM REC REPORT OF DUR / NDC FIELD 476
+35 IF FIELD'=407
IF FIELD'=302
IF FIELD'=440
IF FIELD'=441
IF FIELD'=492
IF FIELD'=101
IF FIELD'=104
IF FIELD'=301
IF FIELD'=110
IF FIELD'=303
IF FIELD'=476
Begin DoDot:1
+36 FOR
IF $EXTRACT(EXT)'=0
QUIT
IF $LENGTH(EXT)=1
QUIT
SET EXT=$EXTRACT(EXT,2,$LENGTH(EXT))
End DoDot:1
+37 ; for some reason they're missed
IF FIELD=426!(FIELD=430)
Begin DoDot:1
+38 SET EXT="$"_$JUSTIFY($$DFF2EXT^ABSPECFM(EXT),7,2)
End DoDot:1
+39 ;
+40 ;IHS/SD/lWJ 10/08/02 NCPDP 5.1 some more signed fields
+41 SET CKFLD=","_FIELD_","
+42 IF FLDLST[CKFLD
SET EXT="$"_$JUSTIFY($$DFF2EXT^ABSPECFM(EXT),7,2)
+43 ;
+44 ;IHS/SD/lwj 3/11/05 format .01 fld for claim DUR
+45 IF ((FIELD=.01)&(FILE=9002313.1001))
SET EXT=$EXTRACT(EXT,3,$LENGTH(EXT))
+46 ;
+47 ; Format .01 fld for claim DIAG Patch 23
+48 IF ((FIELD=.01)&(FILE=9002313.0701))
SET EXT=$EXTRACT(EXT,3,$LENGTH(EXT))
+49 ;
+50 IF FIELD=103
SET EXT=$$TCODE^ABSPECP2(EXT)
+51 ; Get the field name
+52 NEW FLDNAME
SET FLDNAME=$PIECE(^DD(FILE,FIELD,0),U)
+53 ; If it's a date field that didn't get formatted, format it
+54 IF FLDNAME["Date"
IF EXT?8N
Begin DoDot:1
+55 NEW Y
SET Y=EXT-17000000
XECUTE ^DD("DD")
SET EXT=Y
End DoDot:1
+56 ; Other enumerated fields
+57 ;IHS/SD/lwj 10/08/02 NCPDP 5.1 field now include "Patient"
+58 IF FLDNAME="Patient Relationship Code"
Begin DoDot:1
+59 SET EXT=$SELECT(EXT=1:"Cardholder",EXT=2:"Spouse",EXT=3:"Child",EXT=4:"Other Dependent",1:EXT)
End DoDot:1
+60 IF FLDNAME="Compound Code"
Begin DoDot:1
+61 SET EXT=$SELECT(EXT=1:"Not a compound",EXT=2:"Compound",1:EXT)
End DoDot:1
+62 IF FLDNAME="Dispense As Written"
SET EXT=$$DAW^ABSPECP2(EXT)
+63 IF FLDNAME="Basis of Reimb Determination"
SET EXT=$$REIMB^ABSPECP2(EXT)
+64 ;Patch 23
IF FLDNAME="Diagnosis Code Count"
SET FLDNAME="DIAG Count"
+65 ; Store it
+66 IF EXT=""
IF '$$INCLUDE(EFORMAT,FILE,FIELD)
QUIT
+67 IF FILE=9002313.02
Begin DoDot:1
+68 SET @DEST@("C",FLDNAME)=EXT
End DoDot:1
+69 IF '$TEST
IF FILE=9002313.0201
Begin DoDot:1
+70 SET @DEST@("C",FLDNAME,"RX",DA)=EXT
End DoDot:1
+71 ;IHS/SD/lwj 3/11/05 patch 12 clm DUR
IF '$TEST
IF FILE=9002313.1001
Begin DoDot:1
+72 ;IHS/SD/RLT - 05/01/06 - Patch 17
+73 ;Fix displaying of multiple DUR sets
+74 ;S @DEST@("C","DUR entry "_DA_": "_FLDNAME,"RX",DA)=EXT
+75 SET @DEST@("C","DUR entry "_DA_": "_FLDNAME,"RX",RXSEQ)=EXT
End DoDot:1
+76 ;Patch 23
IF '$TEST
IF FILE=9002313.0701
Begin DoDot:1
+77 ;Patch 23
SET @DEST@("C","DIAG entry "_DA_": "_FLDNAME,"RX",RXSEQ)=EXT
End DoDot:1
+78 IF '$TEST
IF FILE=9002313.03
Begin DoDot:1
+79 SET @DEST@("R",FLDNAME)=EXT
End DoDot:1
+80 IF '$TEST
IF FILE=9002313.0301
Begin DoDot:1
+81 IF FLDNAME="Additional Message Information"
SET FLDNAME="Message (more)"
+82 SET @DEST@("R",FLDNAME,"RX",DA)=EXT
End DoDot:1
+83 ;IHS/SD/lwj 3/11/05 patch 12 DUR resp
IF '$TEST
IF FILE=9002313.1101
Begin DoDot:1
+84 SET @DEST@("R","DUR Resp "_DA_" "_FLDNAME,"RX",RXSEQ)=EXT
End DoDot:1
+85 IF '$TEST
DO IMPOSS^ABSPOSUE("P","TI",,,"FMTFIELD",$TEXT(+0))
+86 QUIT
FM1 NEW DIC,DR,DA,DIQ,SUBFILE
+1 IF '$DATA(FIELDS)
SET FIELDS=".01:99999999"
+2 IF '$DATA(RX)
+3 IF '$DATA(RXFIELDS)
SET RXFIELDS=".01:99999999"
+4 ; Safety - make sure if DEST is global, it's probably a scratch global
+5 IF DEST?1"^".E
IF DEST'?1"^TMP("1E.E
IF DEST'?1"^UTILITY("1E.E
DO IMPOSS^ABSPOSUE("P","TI","Bad DEST",DEST,"FM1",$TEXT(+0))
+6 ; gives ^UTILITY("DIQ1",$J,file,DA,field,"E") and ^("I")
DO FETCH
+7 QUIT
FETCH ;
+1 IF '$DATA(RX)
NEW RX
SET RX=0
Begin DoDot:1
+2 ; RX not yet determined: recurse
+3 NEW GLO
SET GLO="^ABSP"_$SELECT(FILE=9002313.02:"C",FILE=9002313.03:"R")
+4 NEW SUB
SET SUB=$SELECT(FILE=9002313.02:400,FILE=9002313.03:1000)
+5 FOR
SET RX=$ORDER(@GLO@(FILE,IEN,SUB,RX))
IF 'RX
QUIT
Begin DoDot:2
+6 DO 2
End DoDot:2
End DoDot:1
QUIT
2 ; with RX determined
+1 ; Reject Code(s) done manually
IF FILE=9002313.03
Begin DoDot:1
+2 NEW X
SET X=0
FOR
SET X=$ORDER(^ABSPR(IEN,1000,RX,511,X))
IF 'X
QUIT
Begin DoDot:2
+3 ;ZW X W ^(X,0),!
+4 NEW Y
SET Y=^ABSPR(IEN,1000,RX,511,X,0)
SET Y=$PIECE(Y,U)
+5 NEW Z
SET Z=$ORDER(^ABSPF(9002313.93,"B",Y,0))
+6 ;W Y," -> ",Z,!
+7 IF Z
IF $DATA(^ABSPF(9002313.93,Z,0))
SET Z=$PIECE(^(0),U,2)
+8 SET @DEST@("R","Reject Code","RX",RX,$SELECT(Y?1"0"1N:+Y,1:Y))=Y_" "_Z
+9 ;ZW @DEST@("R","Reject Code","RX") R ">>",%,!
End DoDot:2
+10 ;Preferred Product data sent back
+11 NEW X
SET X=0
FOR
SET X=$ORDER(^ABSPR(IEN,1000,RX,551.01,X))
IF 'X
QUIT
Begin DoDot:2
+12 NEW Y
SET Y=$GET(^ABSPR(IEN,1000,RX,551.01,X,1))
IF Y=""
QUIT
+13 NEW Z
SET Z=$PIECE(Y,"^",2)_" "_$PIECE(Y,"^",5)
+14 SET @DEST@("R","Preferred Product","RX",RX,X)=Z
End DoDot:2
+15 ;Additional Message Information sent back
+16 NEW X
SET X=0
FOR
SET X=$ORDER(^ABSPR(IEN,1000,RX,526,X))
IF 'X
QUIT
Begin DoDot:2
+17 NEW Y
SET Y=$GET(^ABSPR(IEN,1000,RX,526,X,0))
IF Y=""
QUIT
+18 SET @DEST@("R","Additional Information","RX",RX,X)=Y
End DoDot:2
End DoDot:1
+19 SET DIC=FILE
SET DA=IEN
SET DR=FIELDS
SET DIQ(0)="IEN"
+20 ; as it happens to work out
SET SUBFILE=FILE+.0001
+21 SET DA(SUBFILE)=RX
+22 SET DR(SUBFILE)=RXFIELDS
+23 DO EN^DIQ1
+24 ;
+25 ;IHS/SD/lwj 3/11/05 patch 12 retrieve the claim and resp DUR
+26 ;retrieve the claim DUR info
IF FILE=9002313.02
DO SETCDUR
+27 ;retrieve the response DUR info
IF FILE=9002313.03
DO SETRDUR
+28 ;
+29 ;
+30 ;IHS/SD/RLT - 08/03/07 - Patch 23
+31 ; Diagnois Code information
+32 ;retrieve the claim DIAG info
IF FILE=9002313.02
DO SETCDIAG
+33 ;
+34 QUIT
SETCDUR ;------------------------------------------------------------
+1 ;IHS/SD/LWJ 3/11/05 patch 12
+2 ; set fields needed to retrieve DUR information from the claim
+3 ;------------------------------------------------------------
+4 NEW DURCNT
+5 ;
+6 SET DURCNT=0
+7 SET DR(9002313.0201)=473.01
+8 ;fields
SET DR(9002313.1001)=".01;439;440;441;474;475;476"
+9 ;
+10 FOR
SET DURCNT=$ORDER(^ABSPC(IEN,400,RX,473.01,DURCNT))
IF DURCNT=""
QUIT
Begin DoDot:1
+11 SET DA(9002313.1001)=DURCNT
+12 SET DIQ(0)="IEN"
+13 DO EN^DIQ1
End DoDot:1
+14 ;
+15 QUIT
SETRDUR ;----------------------------------------------------------------
+1 ;IHS/SD/lwj 3/11/05 patch 12
+2 ; set fields needed to retrieve DUR information from the response
+3 ;----------------------------------------------------------------
+4 NEW DURCNT
+5 ;
+6 SET DURCNT=0
+7 ;DUR multiple
SET DR(9002313.0301)=567.01
+8 ;fields
SET DR(9002313.1101)=".01;439;528;529;530;531;532;533;544"
+9 ;
+10 FOR
SET DURCNT=$ORDER(^ABSPR(IEN,1000,RX,567.01,DURCNT))
IF DURCNT=""
QUIT
Begin DoDot:1
+11 SET DA(9002313.1101)=DURCNT
+12 SET DIQ(0)="IEN"
+13 DO EN^DIQ1
End DoDot:1
+14 ;
+15 QUIT
SETCDIAG ;
+1 ;IHS/SD/RLT - 08/03/07 - 10/18/07 - Patch 23
+2 ; set Diagnosis Code information from the claim
+3 ;
+4 NEW DIAGCNT
+5 ;
+6 SET DIAGCNT=0
+7 SET DR(9002313.0201)=491.01
+8 ;fields
SET DR(9002313.0701)=".01;492;424"
+9 ;
+10 FOR
SET DIAGCNT=$ORDER(^ABSPC(IEN,400,RX,491.01,DIAGCNT))
IF '+DIAGCNT
QUIT
Begin DoDot:1
+11 SET DA(9002313.0701)=DIAGCNT
+12 SET DIQ(0)="IEN"
+13 DO EN^DIQ1
End DoDot:1
+14 ;
+15 QUIT