source: FOIAVistA/trunk/r/TEXT_INTEGRATION_UTILITIES-GMRP-TIU/TIUQRY.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.7 KB
Line 
1TIUQRY ; SLC/JER/CAM - Queries for Documents Across Patients ;3/27/03 16:15
2 ;;1.0;TEXT INTEGRATION UTILITIES;**150**;Jun 20, 1997
3QUERY(TIUY,QRY,PATIENT) ; Execute Query
4 N TIUPRM0,TIUPRM1,TIUPRM3,FLAGA,FLAGV S FLAGA=0,FLAGV=0
5 D SETPARM^TIULE
6 I '+$G(PATIENT("Patient.DFN")) S @TIUY@(0,"Documents")="0^ Patient not specified" Q
7 I '$O(QRY("Status",0)) D STATUS(.QRY)
8 I '$O(QRY("Title",0)),'$O(QRY("Class",0)) S @TIUY@(0,"Documents")="0^ Title or Class not specified" Q
9 I $O(QRY("Author",0)) S FLAGA=1
10 I $O(QRY("Location",0)) S FLAGV=1
11 D CHECKADD(.QRY)
12 D GATHER(TIUY,.QRY,.PATIENT,FLAGA,FLAGV)
13 K @TIUY@("INDX")
14 Q
15 ;
16GATHER(TIUY,QRY,PATIENT,FLAGA,FLAGV) ; Find/sort records for the list
17 N DFN,EARLY,LATE,RANGE,TIUC
18 S TIUC=0
19 S RANGE=$O(QRY("Reference",""))
20 S DFN=+$G(PATIENT("Patient.DFN"))
21 S EARLY=9999999-$P(RANGE,":")
22 S LATE=9999999-$P(RANGE,":",2)
23 I $O(QRY("Title",0)) D
24 .N GVN S GVN=$NA(^TIU(8925,"APT",DFN))
25 .N TIUT S TIUT=0
26 .F S TIUT=$O(QRY("Title",TIUT)) Q:+TIUT'>0 D
27 ..N TIUS S TIUS=0
28 ..F S TIUS=$O(QRY("Status",TIUS)) Q:+TIUS'>0 D
29 ...N TIUJ S TIUJ=LATE
30 ...F S TIUJ=$O(@GVN@(TIUT,TIUS,TIUJ)) Q:+TIUJ'>0!(+TIUJ>EARLY) D
31 ....N TIUDA
32 ....S TIUDA=0 F S TIUDA=$O(@GVN@(TIUT,TIUS,TIUJ,TIUDA)) Q:+TIUDA'>0 D
33 .....I FLAGA=0,FLAGV=0 D FOUNDTL(TIUY,TIUDA,.QRY,.PATIENT,.TIUC)
34 .....I FLAGA=1,FLAGV=0,$$AUTHOR(TIUDA,.QRY) D FOUNDTL(TIUY,TIUDA,.QRY,.PATIENT,.TIUC)
35 .....I FLAGA=0,FLAGV=1,$$VISIT(TIUDA,.QRY) D FOUNDTL(TIUY,TIUDA,.QRY,.PATIENT,.TIUC)
36 .....I FLAGA=1,FLAGV=1,$$AUTHOR(TIUDA,.QRY),$$VISIT(TIUDA,.QRY) D FOUNDTL(TIUY,TIUDA,.QRY,.PATIENT,.TIUC)
37 I $O(QRY("Class",0)) D
38 .N TIUCC S TIUCC=0
39 .F S TIUCC=$O(QRY("Class",TIUCC)) Q:TIUCC'>0 D STATCHK(TIUCC,.QRY,.TIUC,.DFN,.EARLY,.LATE,.FLAGA)
40 S @TIUY@(0,"Documents")=TIUC
41 Q
42 ;
43ACLSB(TIUCC,QRY,TIUC,DFN,EARLY,LATE,FLAGA) ; Using the ACLSB cross reference for a status of > 5
44 N TIUAUTH S TIUAUTH=0
45 F S TIUAUTH=$O(^TIU(8925,"ACLSB",TIUCC,TIUAUTH)) Q:(TIUAUTH'>0) D
46 .Q:(FLAGA=1)&'$$AUTHDOC(TIUAUTH,.QRY)
47 .N GVN S GVN=$NA(^TIU(8925,"ACLSB",TIUCC,TIUAUTH,DFN))
48 .N TIUD S TIUD=LATE
49 .F S TIUD=$O(@GVN@(TIUD)) Q:TIUD'>0!(TIUD>EARLY) D
50 ..N TIUDA S TIUDA=0
51 ..F S TIUDA=$O(@GVN@(TIUD,TIUDA)) Q:TIUDA'>0 D
52 ...I FLAGV=0,$$STAT(TIUDA,.QRY) D FOUNDDC(TIUY,TIUDA,.QRY,.PATIENT,.TIUC)
53 ...I FLAGV=1,$$VISIT(TIUDA,.QRY),$$STAT(TIUDA,.QRY) D FOUNDDC(TIUY,TIUDA,.QRY,.PATIENT,.TIUC)
54 Q
55 ;
56ACLAU(TIUCC,QRY,TIUC,DFN,EARLY,LATE,FLAGA) ; Using the ACLAU cross reference for a status of < 6
57 N TIUAUTH S TIUAUTH=0
58 F S TIUAUTH=$O(^TIU(8925,"ACLAU",TIUCC,TIUAUTH)) Q:(TIUAUTH'>0) D
59 .Q:(FLAGA=1)&'$$AUTHDOC(TIUAUTH,.QRY)
60 .N GVN S GVN=$NA(^TIU(8925,"ACLAU",TIUCC,TIUAUTH,DFN))
61 .N TIUD S TIUD=LATE
62 .F S TIUD=$O(@GVN@(TIUD)) Q:TIUD'>0!(TIUD>EARLY) D
63 ..N TIUDA S TIUDA=0
64 ..F S TIUDA=$O(@GVN@(TIUD,TIUDA)) Q:TIUDA'>0 D
65 ...I FLAGV=0,$$STAT(TIUDA,.QRY) D FOUNDDC(TIUY,TIUDA,.QRY,.PATIENT,.TIUC)
66 ...I FLAGV=1,$$VISIT(TIUDA,.QRY),$$STAT(TIUDA,.QRY) D FOUNDDC(TIUY,TIUDA,.QRY,.PATIENT,.TIUC)
67 Q
68 ;
69STATCHK(TIUCC,QRY,TIUC,DFN,EARLY,LATE,FLAGA) ; Check status(es) entered by user. Cross ref used depends on status of doc.
70 N TIUS S TIUS=0
71 F S TIUS=$O(QRY("Status",TIUS)) Q:TIUS'>0 D
72 .I TIUS>5 D ACLSB(TIUCC,.QRY,.TIUC,.DFN,.EARLY,.LATE,.FLAGA)
73 .I TIUS<6 D ACLAU(TIUCC,.QRY,.TIUC,.DFN,.EARLY,.LATE,.FLAGA)
74 Q
75 ;
76FOUNDTL(TIUY,TIUDA,QRY,PATIENT,TIUC) ;Sort by title, resolves document found
77 I TIUT=81,'$$DADINTYP(TIUDA,.QRY) Q
78 D RESOLVE^TIUQRYL(TIUY,TIUDA,.QRY,.PATIENT)
79 S @TIUY@("INDX",TIUDA)="",TIUC=TIUC+1
80 Q
81 ;
82FOUNDDC(TIUY,TIUDA,QRY,PATIENT,TIUC) ;Sort by document, resolves document found
83 I $D(@TIUY@("INDX",TIUDA)) Q ; Don't set up if already exists
84 D RESOLVE^TIUQRYL(TIUY,TIUDA,.QRY,.PATIENT)
85 S @TIUY@("INDX",TIUDA)="",TIUC=TIUC+1
86 Q
87 ;
88STAT(TIUDA1,QRY) ; Determines status of document then checks to see if
89 ; status is included in the status list selected for query.
90 ; TIUS=Status of document
91 N TIUS1,CHECK,TIUS S TIUS1=0,CHECK="",TIUS=0
92 ; CHECK returned as 1 if the status was selected in query.
93 S TIUS1=$P($G(^TIU(8925,TIUDA1,0)),U,5)
94 F S TIUS=$O(QRY("Status",TIUS)) Q:TIUS'>0 I TIUS=TIUS1 S CHECK=1
95 Q CHECK
96 ;
97AUTHDOC(TIUAUTH1,QRY) ; Checks to see if the author of the note being evaluated is
98 ; included in the author list selected for query.
99 N CHECK,TIUAUTH2
100 ; CHECK returned as 1 if the author was selected in query.
101 S CHECK="",TIUAUTH2=0
102 F S TIUAUTH2=$O(QRY("Author",TIUAUTH2)) Q:TIUAUTH2'>0!+CHECK I TIUAUTH2=TIUAUTH1 S CHECK=1
103 Q CHECK
104 ;
105AUTHOR(TIUDA1,QRY) ; Determines author of document then checks to see if author
106 ; is included in the author list selected for query.
107 N TIUAUTH,TIUAUTH1,CHECK S TIUAUTH=0,TIUAUTH1=0,CHECK=""
108 S TIUAUTH1=$P($G(^TIU(8925,TIUDA1,12)),U,2)
109 F S TIUAUTH=$O(QRY("Author",TIUAUTH)) Q:TIUAUTH'>0!+CHECK I TIUAUTH=TIUAUTH1 S CHECK=1
110 Q CHECK
111 ;
112VISIT(TIUDA1,QRY) ; Checks location of visit then checks to see if location is included
113 ; in the location list selected for query.
114 N TIUVST,TIUVST1,CHECK S TIUVST=0,TIUVST1=0,CHECK=0
115 S TIUVST1=$P($G(^TIU(8925,TIUDA1,12)),U,5)
116 F S TIUVST=$O(QRY("Location",TIUVST)) Q:TIUVST'>0!+CHECK I TIUVST=TIUVST1 S CHECK=1
117 Q CHECK
118 ;
119DADINTYP(TIUDA,QRY) ; Evaluates whether addendum's parent belongs is among
120 ; the selected types
121 N TIUI,TIUDTYP,TIUY S (TIUI,TIUY)=0
122 S TIUDTYP=+$G(^TIU(8925,+$P($G(^TIU(8925,+TIUDA,0)),U,6),0))
123 F S TIUI=$O(QRY("Title",TIUI)) Q:+TIUI'>0!+TIUY D
124 . S:TIUI=TIUDTYP TIUY=1
125 Q TIUY
126 ;
127CHECKADD(QRY) ; Assures that Addendum is included in the list of types
128 S QRY("Title",81)=""
129 Q
130 ;
131STATUS(QRY) ; Gets status(es)
132 N TIUI,TIUS,STATUS S (TIUI,TIUS)=0
133 S STATUS=""
134 F S STATUS=$O(^TIU(8925.6,"B",STATUS)) Q:STATUS="" D
135 .S TIUS=0
136 .F S TIUS=$O(^TIU(8925.6,"B",STATUS,TIUS)) Q:+TIUS'>0 D
137 ..S:($P(^TIU(8925.6,+TIUS,0),U,4)'="DEF") QRY("Status",TIUS)=""
138 Q
Note: See TracBrowser for help on using the repository browser.