forked from KRMAssociatesInc/JDS-GTM
-
Notifications
You must be signed in to change notification settings - Fork 2
/
VPRJSES.m
57 lines (57 loc) · 1.64 KB
/
VPRJSES.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
VPRJSES ;CNP/JD -- Handle Session operations
;;1.0;JSON DATA STORE;;Nov 04, 2014
;
Q
;
SET(ARGS,BODY) ; Store or update a session based on the passed in session id (sid)
N DEMOG,ERR,SID,INCR
D DECODE^VPRJSON("BODY","DEMOG","ERR") ; From JSON to an array
I $D(ERR) D SETERROR^VPRJRER(202) Q ""
I $G(DEMOG("_id"))="" D SETERROR^VPRJRER(220) Q ""
S SID=DEMOG("_id")
TSTART ():SERIAL
I $O(^VPRJSES(SID,""))']"" S INCR=$I(^VPRJSES(0))
K ^VPRJSES(SID)
M ^VPRJSES(SID)=DEMOG
TCOMMIT
Q ""
;
CLR(RESULT,ARGS) ; Clear ALL sessions!!!
;**** This operation is IRREVERSIBLE!!!!!! ****
N VPRJA S VPRJA=0
TSTART (VPRJA):SERIAL
F S VPRJA=$O(^VPRJSES(VPRJA)) Q:VPRJA']"" K ^VPRJSES(VPRJA)
S ^VPRJSES(0)=0
TCOMMIT
S RESULT="{}"
Q
;
DEL(RESULT,ARGS) ; Delete a given session
I $$UNKARGS^VPRJCU(.ARGS,"_id") Q
I $G(ARGS("_id"))="" D SETERROR^VPRJRER(111,"_id is blank") Q
K ^VPRJSES(ARGS("_id"))
S RESULT="{}"
Q
;
LEN(RESULT,ARGS) ; Returns the total number of sessions
N VPRJA,VPRJB,VPRJQ
S (VPRJA,VPRJB)=0
L +^VPRJSES:$G(^VPRCONFIG("timeout","gds"),5) E D SETERROR^VPRJRER(502) Q
F S VPRJA=$O(^VPRJSES(VPRJA)) Q:VPRJA']"" S VPRJB=VPRJB+1
L -^VPRJSES
S VPRJQ=""""
S RESULT="{"_VPRJQ_"length"_VPRJQ_":"_VPRJQ_VPRJB_VPRJQ_"}"
Q
;
GET(RESULT,ARGS) ; Returns session info
N DEMOG,ERR,SID,BODY
I $$UNKARGS^VPRJCU(.ARGS,"_id") Q
I $G(ARGS("_id"))="" D SETERROR^VPRJRER(111,"_id is blank") Q
S SID=ARGS("_id")
L +^VPRJSES(SID):$G(^VPRCONFIG("timeout","gds"),5) E D SETERROR^VPRJRER(502) Q ""
M DEMOG=^VPRJSES(SID)
L -^VPRJSES(SID)
D ENCODE^VPRJSON("DEMOG","BODY","ERR") ; From an array to JSON
I $D(ERR) D SETERROR^VPRJRER(202) Q
M RESULT=BODY
Q