source: WorldVistAEHR/trunk/r/SPINAL_CORD_DYSFUNCTION-SPN/SPNLGERX.m@ 1582

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

initial load of WorldVistAEHR

File size: 2.4 KB
Line 
1SPNLGERX ; ISC-SF/GMB - SCD GATHER OUTPATIENT PHARMACY DATA;11 MAY 94 [ 07/06/94 9:59 AM ] ;6/23/95 11:25
2 ;;2.0;Spinal Cord Dysfunction;;01/02/1997
3EXTRACT(DFN,FDATE,TDATE,CLEARTXT,ABORT) ;
4 ; DFN Patient's internal entry number in the Patient file
5 ; FDATE "From" date
6 ; TDATE "Thru" date, default=today
7 ; CLEARTXT 1=translate all codes to their meaning,
8 ; 0=don't translate codes (default=0)
9 N EXPDATE,RECNR,ZEROREC,TWOREC,ISSUDATE,ZDRUGNAM,UNITCOST,PATSTAT
10 N SCNUM,FILLDATE,QTY,SUPPLY,REFILLS,SIG,FILLNUM,SUBRECNR,UNITVAL
11 I '$D(TDATE) S TDATE=DT
12 I '$D(CLEARTXT) S CLEARTXT=0
13 ; We are interested in any drug whose prescription 'expiration' or
14 ; 'cancel' date falls on or after the 'from' date.
15 ; We are going to take only the fills or refills which occurred
16 ; during the 'from'-'thru' date range.
17 S EXPDATE=FDATE-.000001 ; for each expiration date
18 F S EXPDATE=$O(^PS(55,DFN,"P","A",EXPDATE)) Q:EXPDATE'>0 D
19 . S RECNR=0 ; for each prescription on that date
20 . F S RECNR=$O(^PS(55,DFN,"P","A",EXPDATE,RECNR)) Q:RECNR'>0 D
21 . . S TWOREC=$G(^PSRX(RECNR,2)) ; follow ptr to get prescripton info
22 . . Q:TWOREC=""
23 . . S FILLDATE=$P(TWOREC,U,2)
24 . . Q:FILLDATE>TDATE
25 . . S ZEROREC=$G(^PSRX(RECNR,0))
26 . . Q:ZEROREC=""
27 . . S ISSUDATE=$P(ZEROREC,U,13)
28 . . S ZDRUGNAM=$P($G(^PSDRUG(+$P(ZEROREC,U,6),0)),U,1) ; drug name
29 . . S UNITVAL=$P($G(^PSDRUG(+$P(ZEROREC,U,6),660)),U,6) ; current price
30 . . S FILLNUM=0
31 . . I FILLDATE'<FDATE,FILLDATE'>TDATE D
32 . . . S QTY=$P(ZEROREC,U,7) ; quantity
33 . . . S UNITCOST=$P(ZEROREC,U,17)
34 . . . S SUPPLY=$P(ZEROREC,U,8) ; days supply
35 . . . S PATSTAT=$P($G(^PS(53,+$P(ZEROREC,U,3),0)),U,1) ; follow ptr
36 . . . ; follow ptr to hospital location to stop code number
37 . . . S SCNUM=$$STOPCODE^SPNLGU(+$P(ZEROREC,U,5))
38 . . . S REFILLS=$P(ZEROREC,U,9) ; max number of refills
39 . . . S SIG=$P(ZEROREC,U,10)
40 . . . D ADDREC^SPNLGE("RX",FILLDATE_"^"_ZDRUGNAM_"^"_FILLNUM_"^"_ISSUDATE_"^"_QTY_"^"_UNITCOST_"^"_SUPPLY_"^"_UNITVAL_"^"_PATSTAT_"^"_SCNUM_"^"_REFILLS_"^"_SIG)
41 . . S SUBRECNR=0 ; for each refill of the drug
42 . . F FILLNUM=1:1 S SUBRECNR=$O(^PSRX(RECNR,1,SUBRECNR)) Q:SUBRECNR'>0 D
43 . . . S ZEROREC=$G(^PSRX(RECNR,1,SUBRECNR,0))
44 . . . S FILLDATE=$P(ZEROREC,U,1)
45 . . . Q:FILLDATE<FDATE!(FILLDATE>TDATE)
46 . . . S QTY=$P(ZEROREC,U,4)
47 . . . S UNITCOST=$P(ZEROREC,U,11)
48 . . . S SUPPLY=$P(ZEROREC,U,10)
49 . . . D ADDREC^SPNLGE("RX",FILLDATE_"^"_ZDRUGNAM_"^"_FILLNUM_"^"_ISSUDATE_"^"_QTY_"^"_UNITCOST_"^"_SUPPLY_"^"_UNITVAL)
50 Q
Note: See TracBrowser for help on using the repository browser.