source: FOIAVistA/trunk/r/DSS_EXTRACTS-ECX/ECXDRUG2.m@ 1608

Last change on this file since 1608 was 628, checked in by George Lilly, 15 years ago

initial load of FOIAVistA 6/30/08 version

File size: 3.8 KB
Line 
1ECXDRUG2 ;ALB/TMD-Pharmacy Extracts Incomplete Feeder Key Report ; 2/19/08 3:44pm
2 ;;3.0;DSS EXTRACTS;**40,68,84,105,111**;Dec 22, 1997;Build 4
3 ;
4EN ; entry point
5 N ECD,LINE,ECDRG,ECQTY,ECPRC
6 K ^TMP($J)
7 S ECD=ECSD1,ECED=ECED+.3
8 S LINE=$S(ECXOPT=1:"PRE",ECXOPT=2:"IVP",ECXOPT=3:"UDP",1:"EXIT")
9 D @LINE
10 Q
11 ;
12PRE ; entry point for PRE data
13 ; order through fills, refills and partial refills
14 N ECRFL,ECRX,ECREF,ECDATA,ECDATA1
15 K ^TMP($J,"ECXDSS")
16 ;call pharmacy api pso52ex
17 D EXTRACT^PSO52EX(ECD,ECED,"ECXDSS")
18 S ECREF="RF"
19 ;order thru fills and refills; refill values 0 thru 11
20 ; Note: refill 0 = original fill
21 F S ECD=$O(^TMP($J,"ECXDSS","AL",ECD)),IEN=0 Q:'ECD Q:ECD>ECED Q:ECXERR F S IEN=$O(^(ECD,IEN)),ECRFL="" Q:'IEN Q:ECXERR F S ECRFL=$O(^(IEN,ECRFL)) Q:ECRFL']"" Q:ECXERR D PRE2
22 ;
23 ;order thru partial fills
24 S ECD=ECSD1,ECREF="P"
25 F S ECD=$O(^TMP($J,"ECXDSS","AM",ECD)),IEN=0 Q:'ECD Q:ECD>ECED Q:ECXERR F S IEN=$O(^(ECD,IEN)),ECRFL="" Q:'IEN Q:ECXERR F S ECRFL=$O(^(IEN,ECRFL)) Q:'ECRFL Q:ECXERR D PRE2
26 K ^TMP($J,"ECXDSS")
27 Q
28 ;
29PRE2 ; get Prescription data
30 S ECDRG=+$P(^TMP($J,"ECXDSS",IEN,6),U)
31 I ECRFL>0&(ECREF="RF") D
32 .S ECQTY=^TMP($J,"ECXDSS",IEN,ECREF,ECRFL,1),ECPRC=^(1.2)
33 I ECRFL>0&(ECREF="P") D
34 .S ECQTY=^TMP($J,"ECXDSS",IEN,ECREF,ECRFL,.04),ECPRC=^(.042)
35 I 'ECRFL S ECQTY=^TMP($J,"ECXDSS",IEN,7),ECPRC=^(17)
36 D TEST
37 Q
38 ;
39IVP ; entry point for IVP data
40 N ON,DFN,DA,SA
41 F S ECD=$O(^ECX(728.113,"A",ECD)),DFN=0 Q:'ECD Q:ECXERR Q:ECD>ECED F S DFN=$O(^ECX(728.113,"A",ECD,DFN)),ON=0 Q:'DFN Q:ECXERR F S ON=$O(^ECX(728.113,"A",ECD,DFN,ON)),DA=0 Q:'ON K ^TMP($J,"A"),^("S") D
42 .F S DA=$O(^ECX(728.113,"A",ECD,DFN,ON,DA)) Q:'DA I $D(^ECX(728.113,DA,0)) S EC=^(0) D
43 ..S ECDRG=$P(EC,U,4)
44 ..S SA=$S($P(EC,U,8)]"":"A",$P(EC,U,9):"S",1:"")
45 ..I SA'="" D
46 ...I '$D(^TMP($J,SA,ECDRG)) S ^(ECDRG)=0,$P(^(ECDRG),U,2)=$P(EC,U,12)
47 ...S $P(^TMP($J,SA,ECDRG),U)=$P(^TMP($J,SA,ECDRG),U)+$S($P(EC,U,6)=1:1,$P(EC,U,6)=4:0,1:-1)
48 .;looped thru all DAs for this order - now put it together
49 .F SA="S","A" S ECDRG="" F S ECDRG=$O(^TMP($J,SA,ECDRG)) Q:ECDRG="" D
50 ..S ECQTY=$P(^TMP($J,SA,ECDRG),U),ECPRC=$P(^(ECDRG),U,2)
51 ..D TEST
52 K ^TMP($J,"A"),^TMP($J,"S")
53 Q
54 ;
55UDP ; entry point for UDP data
56 N ECXJ,ECDATA
57 F S ECD=$O(^ECX(728.904,"A",ECD)) Q:'ECD Q:ECD>ECED Q:ECXERR D
58 .S ECXJ=0 F S ECXJ=$O(^ECX(728.904,"A",ECD,ECXJ)) Q:'ECXJ Q:ECXERR I $D(^ECX(728.904,ECXJ,0)) D
59 ..S DATA=^ECX(728.904,ECXJ,0)
60 ..S ECDRG=$P(DATA,U,4),ECQTY=$P(DATA,U,5),ECCOST=$P(DATA,U,8)
61 ..S ECPRC=ECCOST/ECQTY
62 ..D TEST
63 Q
64 ;
65TEST ; retrieve NDC and PSNDF VA Product Code Entry and test for missing NDC or VA Prod Code
66 N ECTYPE,ECNDC,ECZERO,K,ECPROD,ECFCHAR,ECSTOCK,ECXPHA
67 S ECTYPE=0,ECXPHA=""
68 ; call pharmacy drug file (#50) api via ecxutl5
69 S ECXPHA=$$PHAAPI^ECXUTL5(ECDRG)
70 S ECNDC=$P(ECXPHA,U,3)
71 S ECNDC=$$RJ^XLFSTR($P(ECNDC,"-"),6,0)_$$RJ^XLFSTR($P(ECNDC,"-",2),4,0)_$$RJ^XLFSTR($P(ECNDC,"-",3),2,0),ECNDC=$TR(ECNDC,"*",0)
72 S ECZERO=1,ECSTOCK=0 F K=1:1:$L(ECNDC) D Q:'ECZERO!ECSTOCK
73 .S ECFCHAR=$E(ECNDC,K)
74 .I ECFCHAR="S" S ECSTOCK=1 Q
75 .I ECFCHAR'=0 S ECZERO=0 Q
76 I ECZERO!ECSTOCK!(ECNDC["N/A") S ECTYPE=2
77 S ECPROD=$P(ECXPHA,U,6),ECPROD=$$RJ^XLFSTR(ECPROD,5,0)
78 I ECTYPE,'ECPROD S ECTYPE=3
79 I 'ECTYPE,'ECPROD S ECTYPE=1
80 I ECTYPE D FILE
81 Q
82 ;
83FILE ; file record
84 N ECFKEY,ECGNAME,STATS,ECCOUNT,QTY,COST,ECCOST
85 ; create new record if none exists for this drug
86 I '$D(^TMP($J,ECDRG)) D
87 .S ECFKEY=ECPROD_ECNDC
88 .S ECGNAME=$P($G(^PSDRUG(ECDRG,0)),U)
89 .S ^TMP($J,ECDRG)=ECGNAME_U_ECFKEY_U_ECPRC_U_ECTYPE
90 .S ^TMP($J,ECDRG,0)="0^0^0"
91 ; add stats to record
92 S STATS=^TMP($J,ECDRG,0)
93 S ECCOUNT=$P(STATS,U),QTY=$P(STATS,U,2),COST=$P(STATS,U,3)
94 S ECCOUNT=ECCOUNT+1
95 S ECCOST=ECQTY*ECPRC
96 S ECQTY=ECQTY+QTY,ECCOST=ECCOST+COST
97 S ^TMP($J,ECDRG,0)=ECCOUNT_U_ECQTY_U_ECCOST
98 Q
99 ;
100EXIT S ECXERR=1 Q
Note: See TracBrowser for help on using the repository browser.