source: FOIAVistA/trunk/r/SPINAL_CORD_DYSFUNCTION-SPN/SPNLGROP.m@ 1742

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

initial load of FOIAVistA 6/30/08 version

File size: 5.1 KB
Line 
1SPNLGROP ; ISC-SF/GMB - SCD GATHER OUTPATIENT DATA;20 MAY 94 [ 08/08/94 1:09 PM ] ;6/23/95 11:38
2 ;;2.0;Spinal Cord Dysfunction;**7,20**;01/02/1997
3ROLLUP(DFN,FDATE,TDATE,HI) ;
4 ; DFN Patient's internal entry number in the Patient file
5 ; FDATE "From" date
6 ; TDATE "Thru" date, default=today
7 ; HI 1=keep track of individual patient usage
8 ; 0=don't keep track
9 ; Data will be rolled up into the following global:
10 ; ^TMP("SPN",$J,"OP",
11 ; with the following nodes:
12 ; "PAT") # patients
13 ; "VISITS") # visits
14 ; "VISITS",-visits) # patients who made this many visits
15 ; "STOPS") # stops
16 ; "SC",stopcd) # patients who stopped at this stop code
17 ; "SC",stopcd,"NAME") name of the stop code
18 ; "SC",stopcd,"VISITS") # visits to this stop code
19 ; "SC",stopcd,"STOPS") # stops to this stop code
20 ; ... and individual patient usage ...
21 ; "HI","H1",-visits,-ndscnums,DFN)
22 ; NOTE: A visit is when a patient goes to a hospital on a given day.
23 ; A stop is when a patient goes to a stop code (clinic) in the
24 ; hospital. There can be any number of stops per visit.
25 ; Now for the tricky part....
26 ; Visits to a stop code are calculated by dividing the visit (1)
27 ; by the number of >different< stop codes gone to. So if four
28 ; different clinics were gone to, then each gets .25 visit.
29 ; The following global is used as a scratch pad:
30 ; ^TMP("SPN",$J,"TMP":
31 ; "SC",scnum,date)="" this stop code was visited on these dates
32 ; "VI",date,scnum)="" these stop codes were visited on this date
33 ; "VI",date) # different stop codes visited on this date
34 N APPT,APPTINFO,SCNUM,SCDATE,VISITS,STOPS,WHEN,RECNR,SCPTR
35 N NDSCNUMS,TSTOPS,VASD,SC,VIFRACTN
36 I '$D(TDATE) S TDATE=DT
37 K ^TMP("SPN",$J,"TMP")
38 ; The following call returns all scheduled appointments which were
39 ; kept, and all future appointments, within the from/to dates
40 S VASD("F")=FDATE,VASD("T")=TDATE D SDA^VADPT
41 S APPT=0 ; for each date/time of appt.
42 F S APPT=$O(^UTILITY("VASD",$J,APPT)) Q:APPT="" D
43 . S APPTINFO=$G(^UTILITY("VASD",$J,APPT,"I"))
44 . I $P($G(APPTINFO),U,3)="I" Q ;inpatient appointment 12/2/2002
45 . S SCDATE=$P(APPTINFO,U,1)\1
46 . ; follow clinic ptr to hospital location to stop code number
47 . S SCNUM=$$STOPCODE^SPNLGU($P(APPTINFO,U,2))
48 . S SC(SCNUM)=$G(SC(SCNUM))+1 ; # times this stop code was visited
49 . S ^TMP("SPN",$J,"TMP","SC",SCNUM,SCDATE)=""
50 . S ^TMP("SPN",$J,"TMP","VI",SCDATE,SCNUM)=""
51 ; Now we count all "walk-ins" without appointments (unscheduled)
52 D UNSCH^SPNLGEOP(DFN,FDATE,TDATE,"D CB^SPNLGROP(Y,Y0,.SDSTOP)")
53 S (TSTOPS,NDSCNUMS)=0 ; track total stops & # of different stop codes
54 S SCNUM="" ; for each stop code the patient visited
55 F S SCNUM=$O(SC(SCNUM)) Q:SCNUM="" D
56 . S STOPS=SC(SCNUM)
57 . S ^("STOPS")=$G(^TMP("SPN",$J,"OP","SC",SCNUM,"STOPS"))+STOPS
58 . S TSTOPS=TSTOPS+STOPS
59 . S NDSCNUMS=NDSCNUMS+1
60 . S ^(SCNUM)=$G(^TMP("SPN",$J,"OP","SC",SCNUM))+1
61 . S SCDATE="" ; for every day on which it was visited
62 . F S SCDATE=$O(^TMP("SPN",$J,"TMP","SC",SCNUM,SCDATE)) Q:SCDATE="" D
63 . . ; increment the count of different stop codes visited on that date
64 . . S ^(SCDATE)=$G(^TMP("SPN",$J,"TMP","VI",SCDATE))+1
65 S VISITS=0,SCDATE="" ; for every day the patient visited
66 F S SCDATE=$O(^TMP("SPN",$J,"TMP","VI",SCDATE)) Q:SCDATE="" D
67 . S VISITS=VISITS+1
68 . S VIFRACTN=1/^TMP("SPN",$J,"TMP","VI",SCDATE) ; fraction of a visit
69 . S SCNUM="" ; for every stop code visited on that day
70 . F S SCNUM=$O(^TMP("SPN",$J,"TMP","VI",SCDATE,SCNUM)) Q:SCNUM="" D
71 . . ; track what portion of the visits went to a particular stop code
72 . . S ^("VISITS")=$G(^TMP("SPN",$J,"OP","SC",SCNUM,"VISITS"))+VIFRACTN
73 Q:VISITS=0
74 K ^TMP("SPN",$J,"TMP")
75 S ^("VISITS")=$G(^TMP("SPN",$J,"OP","VISITS"))+VISITS
76 S ^(-VISITS)=$G(^TMP("SPN",$J,"OP","VISITS",-VISITS))+1
77 S ^("STOPS")=$G(^TMP("SPN",$J,"OP","STOPS"))+TSTOPS
78 S ^("PAT")=$G(^TMP("SPN",$J,"OP","PAT"))+1
79 S:HI ^TMP("SPN",$J,"OP","HI","H1",-VISITS,-NDSCNUMS,DFN)=""
80 Q
81NAMEIT ;
82 N SCNUM,SCNAME,SCPTR
83 S SCNUM=""
84 F S SCNUM=$O(^TMP("SPN",$J,"OP","SC",SCNUM)) Q:SCNUM="" D
85 . S SCPTR=$O(^DIC(40.7,"C",SCNUM,0))
86 . I SCPTR'>0 D
87 . . S SCNAME="Not Identified"
88 . E D
89 . . S SCNAME=$E($P($G(^DIC(40.7,SCPTR,0)),U,1),1,35)
90 . . I SCNAME="" S SCNAME="Not Identified"
91 . S ^TMP("SPN",$J,"OP","SC",SCNUM,"NAME")=SCNAME
92 Q
93 ;
94CB(SPNOE,SPNOE0,SPNSTOP) ; -- callback code called for each
95 ; record in query result set
96 ;
97 ; input: SPNOE := ien of Outpatient Encounter
98 ; SPNOE0 := zeroth node of Outpatient Encounter
99 ; SPNSTOP := tells query to stop processing by setting to 1
100 ;
101 N SPNDATE,SCDATE,SCDATE,SCPTR,SCNUM
102 IF $P(SPNOE0,U,6) G CBQ ; -- quit if encounter has parent
103 IF $P(SPNOE0,U,8)'=2 G CBQ ; -- quit if not standalone encounter
104 ;
105 S SPNDATE=+SPNOE0 ; -- encounter date
106 S SCDATE=SPNDATE\1
107 S SCPTR=+$P(SPNOE0,U,3) ; -- stop code pointer
108 IF 'SCPTR G CBQ
109 S SCNUM=$P($G(^DIC(40.7,SCPTR,0)),U,2)
110 S SC(SCNUM)=$G(SC(SCNUM))+1 ; # times this stop code was visited
111 S ^TMP("SPN",$J,"TMP","SC",SCNUM,SCDATE)=""
112 S ^TMP("SPN",$J,"TMP","VI",SCDATE,SCNUM)=""
113CBQ Q
114 ;
Note: See TracBrowser for help on using the repository browser.