source: WorldVistAEHR/trunk/r/SPINAL_CORD_DYSFUNCTION-SPN/SPNLGUSN.m@ 648

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

initial load of WorldVistAEHR

File size: 3.3 KB
Line 
1SPNLGUSN ; ISC-SF/GMB - SCD GATHER LAST SEEN; 3 JUL 94 [ 07/12/94 7:03 AM ] ;6/23/95 11:50
2 ;;2.0;Spinal Cord Dysfunction;;01/02/1997
3SEEN(DFN,FDATE,TDATE,SEEN,LASTSEEN,SEENIP,SEENOP,SEENCH,SEENRX,SEENRA) ;
4 ; DFN Patient's internal entry number in the Patient file
5 ; FDATE "From" date
6 ; TDATE "Thru" date, default=today
7 ; During the time period FDATE thru TDATE,
8 ; SEEN (1/0) patient was (not) seen
9 ; LASTSEEN Date patient was last seen
10 ; SEENIP (1/0) patient was (not) seen as an inpatient
11 ; SEENOP (1/0) patient was (not) seen as an outpatient
12 ; SEENCH (1/0) patient was (not) seen for a lab test
13 ; SEENRX (1/0) patient was (not) seen in pharmacy
14 ; SEENRA (1/0) patient was (not) seen in radiology
15 N LASTIP,LASTOP,LASTCH,LASTRX,LASTRA
16 I '$D(TDATE) S TDATE=DT
17 S LASTSEEN=0
18 D IP(.SEENIP,.LASTIP)
19 I SEENIP,(LASTIP>LASTSEEN) S LASTSEEN=LASTIP
20 D OP(.SEENOP,.LASTOP)
21 I SEENOP,(LASTOP>LASTSEEN) S LASTSEEN=LASTOP
22 D CH(.SEENCH,.LASTCH)
23 I SEENCH,(LASTCH>LASTSEEN) S LASTSEEN=LASTCH
24 D RX(.SEENRX,.LASTRX)
25 I SEENRX,(LASTRX>LASTSEEN) S LASTSEEN=LASTRX
26 D RA(.SEENRA,.LASTRA)
27 I SEENRA,(LASTRA>LASTSEEN) S LASTSEEN=LASTRA
28 S SEEN=(SEENIP)!(SEENOP)!(SEENCH)!(SEENRX)!(SEENRA)
29 Q
30IP(SEEN,LASTSEEN) ;
31 N RECNR,NODE0,NODE70,ZDD,ZAD
32 S LASTSEEN=0
33 ; We will take all admissions which overlap the desired range, and adjust
34 ; the admit and/or discharge dates to conform with the desired range.
35 S RECNR=0 ; for each inpatient record
36 F S RECNR=$O(^DGPT("B",DFN,RECNR)) Q:RECNR="" D
37 . S NODE0=$G(^DGPT(RECNR,0))
38 . Q:$P(NODE0,U,11)'=1 ; 1=PTF record, 2=census record
39 . S NODE70=$G(^DGPT(RECNR,70))
40 . S ZDD=$P(NODE70,U,1)\1 ; Discharge date
41 . Q:ZDD'=0&(ZDD<FDATE)
42 . S ZAD=$P(NODE0,U,2)\1 Q:ZAD>TDATE ; Admit date
43 . S LASTSEEN=$S(ZDD>TDATE:TDATE,ZDD=0:TDATE,1:ZDD)
44 S SEEN=$S(LASTSEEN=0:0,1:1)
45 Q
46OP(SEEN,LASTSEEN) ;
47 N VASD,APPT,LASTAPPT
48 S VASD("F")=FDATE,VASD("T")=TDATE D SDA^VADPT
49 S (APPT,LASTAPPT)=0
50 F S APPT=$O(^UTILITY("VASD",$J,APPT)) Q:APPT="" D
51 . S LASTAPPT=APPT
52 I LASTAPPT=0 D
53 . S (SEEN,LASTSEEN)=0
54 E D
55 . S LASTSEEN=+^UTILITY("VASD",$J,LASTAPPT,"I")\1
56 . S SEEN=1
57 Q
58CH(SEEN,LASTSEEN) ;
59 N LFN,LASTDATE,TESTDATE
60 S (SEEN,LASTSEEN)=0
61 S LFN=+$P($G(^DPT(DFN,"LR")),U,1)
62 Q:'LFN
63 S LASTDATE=9999999-FDATE
64 S TESTDATE=9999999-(TDATE+1)
65 S TESTDATE=$O(^LR(LFN,"CH",TESTDATE))
66 Q:TESTDATE'>0!(TESTDATE>LASTDATE)
67 S LASTSEEN=9999999-TESTDATE\1
68 S SEEN=1
69 Q
70RX(SEEN,LASTSEEN) ;
71 N EXPDATE,RECNR,FILLDATE,SUBRECNR
72 S LASTSEEN=0
73 S EXPDATE=FDATE-.000001 ; For each expiration date
74 F S EXPDATE=$O(^PS(55,DFN,"P","A",EXPDATE)) Q:EXPDATE'>0 D
75 . S RECNR=0 ; For each prescription on that date
76 . F S RECNR=$O(^PS(55,DFN,"P","A",EXPDATE,RECNR)) Q:RECNR'>0 D
77 . . S FILLDATE=$P($G(^PSRX(RECNR,2)),U,2)
78 . . Q:FILLDATE>TDATE
79 . . S:FILLDATE'<FDATE LASTSEEN=FILLDATE ; original fill
80 . . S SUBRECNR=0 ; For each refill
81 . . F S SUBRECNR=$O(^PSRX(RECNR,1,SUBRECNR)) Q:SUBRECNR'>0 D Q:FILLDATE>TDATE
82 . . . S FILLDATE=$P($G(^PSRX(RECNR,1,SUBRECNR,0)),U,1)
83 . . . Q:FILLDATE<FDATE!(FILLDATE>TDATE)
84 . . . S:FILLDATE>LASTSEEN LASTSEEN=FILLDATE
85 S SEEN=$S(LASTSEEN=0:0,1:1)
86 Q
87RA(SEEN,LASTSEEN) ;
88 N LASTDATE,EXAMDATE
89 S (SEEN,LASTSEEN)=0
90 S LASTDATE=9999999.9999-FDATE
91 S EXAMDATE=9999999.9999-(TDATE+1)
92 S EXAMDATE=$O(^RADPT(DFN,"DT",EXAMDATE))
93 Q:EXAMDATE'>0!(EXAMDATE>LASTDATE)
94 S LASTSEEN=9999999.9999-EXAMDATE\1
95 S SEEN=1
96 Q
Note: See TracBrowser for help on using the repository browser.