92 lines
3.6 KiB
Mathematica
92 lines
3.6 KiB
Mathematica
PSAUP2 ;BIR/JMB-Upload and Process Prime Vendor Invoice Data - CONT'D ;8/13/97
|
|
;;3.0; DRUG ACCOUNTABILITY/INVENTORY INTERFACE;**19,37**; 10/24/97
|
|
;Checking the X12 invoice data.
|
|
K ^TMP("PSAPV SET",$J),PSAERR
|
|
S (PSASTCNT,PSAITCNT)=0
|
|
S PSALAST=""
|
|
S PSALINE=0 F S PSALINE=$O(^TMP("PSAPVS",$J,PSALINE)) Q:PSALINE="" S PSADATA=^(PSALINE) D
|
|
.;check segment order
|
|
.D ^PSAUP3 S PSALAST=$P(PSADATA,"^")
|
|
ISA .;control header
|
|
.I PSALAST="ISA" D Q
|
|
..S PSAISA=PSADATA,PSACTRL="" W "." I $L($P(PSADATA,"^",14))'=9 S PSASEG="ISA" D MSG^PSAUTL2
|
|
.;
|
|
IEA .;control trailer
|
|
.I PSALAST="IEA" D Q
|
|
..I $P(PSADATA,"^",3)'=$P(PSAISA,"^",14) S PSASEG="IEA" D MSG^PSAUTL2
|
|
.;
|
|
GS .;group header
|
|
.I PSALAST="GS" S PSAGS=PSADATA D Q
|
|
..F %=3,4 S PSAPC=$S(%=3:7,1:9) I $P(PSADATA,"^",%)'=$TR($P(PSAISA,"^",PSAPC)," ") S PSASEG="GS" D MSG^PSAUTL2
|
|
.;
|
|
GE .;group trailer
|
|
.I PSALAST="GE" D Q
|
|
..I $P(PSADATA,"^",3)'=$P($G(PSAGS),"^",7) S PSASEG="GE" D MSG^PSAUTL2
|
|
.;
|
|
ST .;set header
|
|
.I PSALAST="ST" D Q
|
|
..S PSAST=PSADATA,PSACTRL=$P(PSADATA,"^",3),PSASTCNT=1,PSAITCNT=0,PSANTYPE=""
|
|
..I $L(PSACTRL)>3,$L(PSACTRL)<10 Q
|
|
..S PSASEG="ST" D MSG^PSAUTL2 Q
|
|
.;
|
|
SE .;set trailer
|
|
.I PSALAST="SE" S PSASTCNT=PSASTCNT+1 D Q
|
|
..I $P(PSADATA,"^",3)'=PSACTRL S PSASEG="SE1" D MSG^PSAUTL2 Q
|
|
..I PSASTCNT'=$P(PSADATA,"^",2) S PSASEG="SE2" D MSG^PSAUTL2
|
|
.;
|
|
BIG .;beginning segment for invoice
|
|
.I PSALAST="BIG" S PSASTCNT=PSASTCNT+1 D Q
|
|
..I $P(PSADATA,"^",4)="" S $P(PSADATA,"^",4)=$P(PSADATA,"^",2)
|
|
..S $P(PSADATA,"^",5)=$TR($P(PSADATA,"^",5)," ")
|
|
..S ^TMP("PSAPV SET",$J,PSACTRL,"IN")=$P(PSADATA,"^",2,5)
|
|
.;
|
|
REF .;(not used)
|
|
.I PSALAST="REF" S PSASTCNT=PSASTCNT+1 Q
|
|
.;
|
|
.;buyer, seller, shipping addresses
|
|
N1 .I PSALAST="N1" S PSASTCNT=PSASTCNT+1,PSANTYPE=$P(PSADATA,"^",2) D Q
|
|
..I PSANTYPE'="BY",PSANTYPE'="DS",PSANTYPE'="ST" S PSASEG="N1" D MSG^PSAUTL2 Q
|
|
..S ^TMP("PSAPV SET",$J,PSACTRL,PSANTYPE)=$P(PSADATA,"^",3)
|
|
.;
|
|
N2 .I PSALAST="N2" D Q
|
|
..D:PSANTYPE="" NTYPE
|
|
..S $P(^TMP("PSAPV SET",$J,PSACTRL,PSANTYPE),"^",2)=$P(PSADATA,"^",2) S PSASTCNT=PSASTCNT+1
|
|
.;
|
|
N3 .I PSALAST="N3" D Q
|
|
..D:PSANTYPE="" NTYPE
|
|
..S $P(^TMP("PSAPV SET",$J,PSACTRL,PSANTYPE),"^",3)=$P(PSADATA,"^",2) S PSASTCNT=PSASTCNT+1
|
|
.;
|
|
N4 .I PSALAST="N4" D Q
|
|
..D:PSANTYPE="" NTYPE
|
|
..S $P(^TMP("PSAPV SET",$J,PSACTRL,PSANTYPE),"^",4,6)=$P(PSADATA,"^",2,4) S PSASTCNT=PSASTCNT+1,PSANTYPE=""
|
|
.;
|
|
DTM .;date time reference
|
|
.I PSALAST="DTM" S PSASTCNT=PSASTCNT+1 D Q
|
|
..S %=$S($P(PSADATA,"^",2)="002":5,$P(PSADATA,"^",2)="035":6,1:0) I '% Q
|
|
..S $P(^TMP("PSAPV SET",$J,PSACTRL,"IN"),"^",%)=$P(PSADATA,"^",3)
|
|
.;
|
|
IT1 .;invoice line item
|
|
.I PSALAST="IT1" S PSASTCNT=PSASTCNT+1,PSAITCNT=PSAITCNT+1 D ITEM Q
|
|
CTT .;item count
|
|
.I PSALAST="CTT" S PSASTCNT=PSASTCNT+1 D Q
|
|
..I PSAITCNT'=$P(PSADATA,"^",2) S PSASEG="CTT" D MSG^PSAUTL2
|
|
.;
|
|
UNKNOWN .;Segment we don't use
|
|
.S PSASTCNT=PSASTCNT+1
|
|
;
|
|
ERROR S PSASEG=$O(PSAERR("")) D:PSASEG'="" ERROR^PSAUTL2
|
|
Q
|
|
;
|
|
NTYPE S PSASEG="NONTYPE" D MSG^PSAUTL2
|
|
Q
|
|
;
|
|
ITEM ;check line item
|
|
I '$P(PSADATA,"^",2) S PSASEG="IT1-1" D MSG^PSAUTL2 Q
|
|
I $P(PSADATA,"^",6)'="DS" S PSASEG="IT1-2" D MSG^PSAUTL2 Q
|
|
;DAVE B (PSA*3*19) check for piece 10 (VSN) added
|
|
I $P(PSADATA,"^",8)="",$P(PSADATA,"^",10)="",$P(PSADATA,"^",12)="" S PSASEG="IT1-3" D MSG^PSAUTL2 Q
|
|
;"IT1" Seg=Qty Invoiced ^ Unit of Measure ^ Unit Price ^ Basic Unit Code "DS" ^ NDC ^ VSN
|
|
S PSAITEM=+$P(PSADATA,"^",2),^TMP("PSAPV SET",$J,PSACTRL,"IT",PSAITEM)=+$P(PSADATA,"^",3)_"^"_$P(PSADATA,"^",4)_"^"_$P(PSADATA,"^",5)_"^"_$P(PSADATA,"^",8)_"^"_$P(PSADATA,"^",10)
|
|
I $P(PSADATA,"^",12)'="",$P(PSADATA,"^",11)="UP" S $P(^TMP("PSAPV SET",$J,PSACTRL,"IT",PSAITEM),"^",26)=$P(PSADATA,"^",12)
|
|
Q
|