source: FOIAVistA/trunk/r/SPINAL_CORD_DYSFUNCTION-SPN/SPNLGSOP.m@ 1397

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

initial load of FOIAVistA 6/30/08 version

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