source: WorldVistAEHR/trunk/r/DSS_EXTRACTS-ECX/ECXAPHA2.m@ 1297

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

revised back to 6/30/08 version

File size: 4.0 KB
Line 
1ECXAPHA2 ;ALB/TMD-Pharmacy Extracts Unusual Volumes Report ; 2/06/07 10:36am
2 ;;3.0;DSS EXTRACTS;**40,49,84,104**;Dec 22, 1997;Build 8
3 ;
4EN ; entry point
5 N COUNT,ECUNIT,LINE,ECDFN,ECD,ECDRG,ECDAY,ECDFN,ECQTY,ECUNIT,ECCOST,ECDS
6 K ^TMP($J)
7 S (COUNT,ECDS)=0,ECUNIT=""
8 S ECD=ECSD1,ECED=ECED+.3
9 S LINE=$S(ECXOPT=1:"PRE",ECXOPT=2:"IVP",ECXOPT=3:"UDP",1:"EXIT")
10 D @LINE
11 Q
12 ;
13PRE ; entry point for PRE data
14 ; order through fills, refills and partial refills
15 N ECRFL,ECRX,ECREF,ECDATA,ECDATA1,ECPRC
16 S ECREF=1
17 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 Q:ECXERR F S ECRFL=$O(^PSRX("AL",ECD,ECRX,ECRFL)) Q:ECRFL="" Q:ECXERR D PRE2
18 S ECD=ECSD1,ECREF="P"
19 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="" Q:ECXERR D PRE2
20 Q
21 ;
22PRE2 ; get Prescription data
23 S ECDATA=$G(^PSRX(ECRX,0))
24 I ECRFL D
25 .S ECDATA1=$G(^PSRX(ECRX,ECREF,ECRFL,0))
26 .S ECQTY=+$P(ECDATA1,U,4)
27 .S ECDS=+$P(ECDATA1,U,10)
28 .S ECPRC=+$P(ECDATA1,U,11)
29 I 'ECRFL D
30 .S ECQTY=+$P(ECDATA,U,7)
31 .S ECDS=+$P(ECDATA,U,8)
32 .S ECPRC=+$P(ECDATA,U,17)
33 ;check to see if quantity>threshold
34 I ECQTY>ECTHLD D
35 .S ECDAY=ECD
36 .S ECDFN=$P(ECDATA,U,2)
37 .S ECDRG=+$P(ECDATA,U,6)
38 .S ECCOST=ECQTY*ECPRC
39 .D FILE Q:ECXERR
40 Q
41 ;
42IVP ; entry point for IVP Data
43 N DFN,ON,DA,SA,ECCOUNT
44 F S ECD=$O(^ECX(728.113,"A",ECD)),DFN=0 Q:'ECD Q:ECD>ECED Q:ECXERR F S DFN=$O(^ECX(728.113,"A",ECD,DFN)),ON=0 Q:'DFN F S ON=$O(^ECX(728.113,"A",ECD,DFN,ON)),DA=0 Q:'ON K ^TMP($J,"A"),^("S") D Q:ECXERR
45 .F S DA=$O(^ECX(728.113,"A",ECD,DFN,ON,DA)) Q:'DA Q:ECXERR I $D(^ECX(728.113,DA,0)) S EC=^(0) Q:ECXERR D
46 ..S ECDRG=$P(EC,U,4)
47 ..S SA=$S($P(EC,U,8)]"":"A",$P(EC,U,9):"S",1:"")
48 ..; set up new record for first DA for this drug
49 ..I '$D(^TMP($J,SA,ECDRG)) D
50 ...S ECQTY=+$S(SA="A":+$P(EC,U,7),SA="S":+$P(EC,U,9),1:0)
51 ...S ECUNIT=$S(SA="A":$P(EC,U,8),SA="S":"ML",1:"")
52 ...S ECCOST=$P(EC,U,12),ECDFN=DFN
53 ...S ^TMP($J,SA,ECDRG)=ECUNIT_U_ECD_U_ECDFN_U_ECCOST_U_ECQTY
54 ...S ^(ECDRG,1)=0
55 ..; add to qty (0,1, or -1) to total
56 ..S ^TMP($J,SA,ECDRG,1)=^TMP($J,SA,ECDRG,1)+$S($P(EC,U,6)=1:1,$P(EC,U,6)=4:0,1:-1)
57 .; looped thru all DAs for this order - now check for unusual volumes
58 .F SA="S","A" S ECDRG="" F S ECDRG=$O(^TMP($J,SA,ECDRG)) Q:ECDRG="" Q:ECXERR D
59 ..S ECQTY=$P(^TMP($J,SA,ECDRG),U,5),ECCOUNT=^(ECDRG,1)
60 ..S ECQTY=ECQTY*ECCOUNT
61 ..; check to see if quantity is outside of threshold range
62 ..I (ECQTY>ECTHLD)!(ECQTY<-ECTHLD) D
63 ...S ECUNIT=$P(^TMP($J,SA,ECDRG),U)
64 ...S ECDAY=$P(^(ECDRG),U,2)
65 ...S ECDFN=$P(^(ECDRG),U,3)
66 ...S ECCOST=$P(^(ECDRG),U,4)*ECCOUNT
67 ...D FILE Q:ECXERR
68 K ^TMP($J,"A"),^("S")
69 Q
70 ;
71UDP ; entry point for UDP data
72 N ECXJ,ECDATA
73 F S ECD=$O(^ECX(728.904,"A",ECD)) Q:'ECD Q:ECD>ECED Q:ECXERR D
74 .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
75 ..S DATA=^ECX(728.904,ECXJ,0),ECQTY=$P(DATA,U,5)
76 ..;check to see if quantity>threshold
77 ..I ECQTY>ECTHLD D
78 ...S ECDFN=$P(DATA,U,2),ECDRG=$P(DATA,U,4),ECCOST=$P(DATA,U,8),ECDAY=ECD
79 ...D FILE Q:ECXERR
80 Q
81 ;
82FILE ; put records in temp file to print later
83 N OK,ECXPAT,ECNAME,ECSSN,ECGNAME,ECNDC,ECPROD,ECFKEY,ECXPHA
84 ; get demographics
85 S OK=$$PAT^ECXUTL3(ECDFN,$P(ECD,"."),"1;",.ECXPAT)
86 I 'OK Q
87 S ECNAME=ECXPAT("NAME")
88 S ECSSN=ECXPAT("SSN")
89 S ECDAY=$E(ECDAY,4,5)_"/"_$E(ECDAY,6,7)
90 ; get drug file data
91 S ECXPHA="",ECXPHA=$$PHAAPI^ECXUTL5(ECDRG)
92 S ECGNAME=$P(ECXPHA,U)
93 S ECNDC=$P(ECXPHA,U,3)
94 S ECNDC=$$RJ^XLFSTR($P(ECNDC,"-"),6,0)_$$RJ^XLFSTR($P(ECNDC,"-",2),4,0)_$$RJ^XLFSTR($P(ECNDC,"-",3),2,0)
95 S ECNDC=$TR(ECNDC,"*",0)
96 S ECPROD=$P(ECXPHA,U,6)
97 S ECPROD=$$RJ^XLFSTR(ECPROD,5,0)
98 S ECFKEY=ECPROD_ECNDC
99 I ECXOPT'=2 S ECUNIT=$P(ECXPHA,U,8)
100 ; file
101 S ^TMP($J,ECFKEY,-ECQTY,ECDAY,ECSSN)=ECNAME_U_ECSSN_U_ECDAY_U_ECGNAME_U_ECFKEY_U_ECQTY_U_ECUNIT_U_"$"_$FNUMBER(ECCOST,",",2)_U_ECDS
102 S COUNT=COUNT+1
103 I COUNT#100=0 I $$S^ZTLOAD S (ZSTOP,ECXERR)=1
104 Q
105 ;
106EXIT S ECXERR=1 Q
Note: See TracBrowser for help on using the repository browser.