source: WorldVistAEHR/trunk/r/DSS_EXTRACTS-ECX/ECXDRUG2.m@ 1042

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

revised back to 6/30/08 version

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