-
Notifications
You must be signed in to change notification settings - Fork 6
/
VPRJAQ.m
66 lines (66 loc) · 2.75 KB
/
VPRJAQ.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
VPRJAQ ;SLC/KCM -- Query for JSON objects across patients
;;1.0;JSON DATA STORE;;Sep 01, 2012
;
QCOUNT(CNTNM) ; Return a set of counts across patients
; return tallies as data:{items:[{"topic":"med","count":4}
I '$L(CNTNM) D SETERROR^VPRJRER(101) Q
N BUFFER S BUFFER=""
K:$D(^TMP($J)) ^TMP($J)
;
N TOPIC,DATA,COUNT,X
S DATA=0,TOPIC=""
F S TOPIC=$O(^VPRPTX("count",CNTNM,TOPIC)) Q:TOPIC="" D
. S COUNT=+^VPRPTX("count",CNTNM,TOPIC)
. S X=$S('DATA:"",1:",")_"{""topic"":"""_TOPIC_""",""count"":"_COUNT_"}"
. S DATA=DATA+1,DATA(DATA)=X
S X=$$BLDHEAD^VPRJCB(DATA) D STAGE^VPRJCB(X)
S DATA=0 F S DATA=$O(DATA(DATA)) Q:'DATA D STAGE^VPRJCB(DATA(DATA))
D STAGE^VPRJCB("]}}"),OUT^VPRJCB
Q
QINDEX(INDEX,RANGE,ORDER,BAIL,TEMPLATE,FILTER) ; Query across patients by index
I $G(INDEX)="pid",($G(TEMPLATE)="pid") D QPID Q
;
I '$L($G(INDEX)) D SETERROR^VPRJRER(101) Q
N VPRDATA,METHOD,CLAUSES
S RANGE=$G(RANGE),ORDER=$G(ORDER),BAIL=$G(BAIL),TEMPLATE=$G(TEMPLATE),FILTER=$G(FILTER)
S VPRDATA=0 S:'BAIL BAIL=999999
M INDEX=^VPRMETA("index",INDEX,"common")
S METHOD=$G(INDEX("method")) I '$L(METHOD) D SETERROR^VPRJRER(102,INDEX) Q
I $L(FILTER) D PARSE^VPRJCF(FILTER,.CLAUSES) Q:$G(HTTPERR)
D SETORDER^VPRJCO(.ORDER) Q:$G(HTTPERR)
K:$D(^TMP("VPRDATA",$J)) ^TMP("VPRDATA",$J)
D QATTR^VPRJAQA
D BUILD^VPRJCB
K:$D(^TMP("VPRDATA",$J)) ^TMP("VPRDATA",$J)
Q
QPID(FILTER) ; Custom query to just return all PID's (/vpr/all/index/pid/pid)
K:$D(^TMP($J)) ^TMP($J)
N COUNT,PID,LINE,BUFFER,CLAUSES,SITE
S FILTER=$G(FILTER)
I $L(FILTER) D PARSE^VPRJCF(FILTER,.CLAUSES) Q:$G(HTTPERR)
S COUNT=0,LINE=2,PID="",BUFFER="",JPID=""
F S JPID=$O(^VPRPT(JPID)) Q:JPID="" D
. F S PID=$O(^VPRPT(JPID,PID)) Q:'$L(PID) D
. . K SITE ; Ensure an empty array, so old data doesn't show up
. . S SITE("site")=$P(PID,";")
. . I $D(CLAUSES) Q:'$$EVALAND^VPRJGQF(.CLAUSES,$NA(SITE)) ;apply filter, quit if not true
. . S COUNT=COUNT+1
. . I $L(BUFFER)>4000 S ^TMP($J,LINE)=BUFFER,LINE=LINE+1,BUFFER=""
. . S BUFFER=BUFFER_$S(COUNT>1:",",1:"")_""""_PID_""""
S ^TMP($J,LINE)=BUFFER_"]}}"
S ^TMP($J,1)=$$BLDHEAD^VPRJCB(COUNT)
Q
QFIND(COLL,ORDER,BAIL,TEMPLATE,FILTER) ; Query across patients using filter criteria
N VPRDATA,CLAUSES,PREFIX,PID,KEY,JPID
S ORDER=$G(ORDER),BAIL=$G(BAIL),TEMPLATE=$G(TEMPLATE),FILTER=$G(FILTER)
S VPRDATA=0 S:'BAIL BAIL=999999
I $L(FILTER) D PARSE^VPRJCF(FILTER,.CLAUSES) Q:$G(HTTPERR)
D SETORDER^VPRJCO(.ORDER) Q:$G(HTTPERR)
K:$D(^TMP("VPRDATA",$J)) ^TMP("VPRDATA",$J)
S JPID="" F S JPID=$O(^VPRPT(JPID)) Q:JPID="" D
. S PID="" F S PID=$O(^VPRPT(JPID,PID)) Q:'$L(PID) D
. . S PREFIX="urn:va:"_COLL_":",KEY=PREFIX
. . F S KEY=$O(^VPRPT(JPID,PID,KEY)) Q:$E(KEY,1,$L(PREFIX))'=PREFIX D ADDONE^VPRJPQA(KEY,0)
D BUILD^VPRJCB
K:$D(^TMP("VPRDATA",$J)) ^TMP("VPRDATA",$J)
Q