YSBRPC ;SLC/DJE - MHA DASHBOARD ; Apr 01, 2021@16:33
;;5.01;MENTAL HEALTH;**202,221**;Dec 30, 1994;Build 11
;
; Routine retrieves Settings, Views, Widgets and User information
Q
RESTFUL(OUT,IN) ;main RPC that interprets RESTful calls
I $G(IN(1))="" D LOADDB(.OUT) Q
;Connector
I $E(IN(1),1,27)="GET /api/dashboard/getconn/" D GETCONN^YSBRPC(.OUT)
;HR
I $E(IN(1),1,34)="GET /api/dashboard/highrisk/cssrs/" D GETRPRT^YSBDD1(.OUT,+$P(IN(1),"GET /api/dashboard/highrisk/cssrs/",2))
I $E(IN(1),1,33)="GET /api/dashboard/highrisk/hrpp/" D HRPTPROF^YSBDD1(.OUT,+$P(IN(1),"GET /api/dashboard/highrisk/hrpp/",2))
I $E(IN(1),1,33)="GET /api/dashboard/highrisk/note/" D GETNOTE^YSBDD1(.OUT,+$P(IN(1),"GET /api/dashboard/highrisk/note/",2))
;
I $E(IN(1),1,28)="GET /api/dashboard/userpref/" D GETUSRP^YSBPREFS(.OUT)
I $E(IN(1),1,29)="POST /api/dashboard/userpref/" D USRP^YSBPREFS(.OUT,.IN)
;
Q
;I $E(IN(1),1,40)="GET /api/dashboard/highrisk/selcriteria/" D GETHRSEL^YSBDD1(.OUT,+$P(IN(1),"GET /api/dashboard/highrisk/selcriteria/",2))
;I $E(IN(1),1,41)="POST /api/dashboard/highrisk/selcriteria/" D HRWSEL^YSBDD2(.OUT,.IN)
;;MBC
;I $E(IN(1),1,28)="GET /api/dashboard/mbc/data/" D MBC0^YSBWMBC(.OUT)
;I $E(IN(1),1,27)="GET /api/dashboard/mbc/prf/" D PRF^YSBDD2(.OUT,+$P(IN(1),"GET /api/dashboard/mbc/prf/",2))
;I $E(IN(1),1,30)="GET /api/dashboard/mbc/visits/" D VST^YSBDD2(.OUT,+$P(IN(1),"GET /api/dashboard/mbc/visits/",2))
;I $E(IN(1),1,35)="GET /api/dashboard/mbc/selcriteria/" D GETMBSEL^YSBPREFS(.OUT)
;I $E(IN(1),1,36)="POST /api/dashboard/mbc/selcriteria/" D MBCWSEL^YSBPREFS(.OUT,.IN)
;I $E(IN(1),1,29)="GET /api/dashboard/mbc/ilist/" D GETILST^YSBPREFS(.OUT)
;I $E(IN(1),1,30)="POST /api/dashboard/mbc/ilist/" D ILST^YSBPREFS(.OUT,.IN)
;
LOADDB(JSONOUT) ;Load dashboard data. Currently close to everything is loaded. User data, widget and widget data.
N DATAOUT,DATAIN,ERRARY,I
D GETUSER(.DATAOUT) ;get the user data
D GETWDGT(.DATAOUT) ;process if call from dashboard
D SELPATS(.DATAOUT) ;get the patients
I '$D(DATAOUT("data",1,"patient_name")) D
. S DATAOUT("data",1)=""
D ENCODE^YSBJSON("DATAOUT","JSONOUT","ERRARY")
;I '$D(DATAOUT("data",1,"patient_name")) D NOPAT
Q
WEBWIDG(ARGS,RESULTS) ;Load dashboard data for a widget embedded in MHA Web
N WNAME,DATAOUT,ERRARY
S WNAME=$G(ARGS("widgetName"))
D GETUSER(.DATAOUT) ;get the user data
D GETWDGT(.DATAOUT,WNAME) ;process if call from dashboard
D SELPATS(.DATAOUT) ;get the patients
D ENCODE^YSBJSON("DATAOUT","JSONOUT","ERRARY")
D TOTMP(.JSONOUT)
S RESULTS=$NA(^TMP("YTQ-JSON",$J))
Q
TOTMP(JSONOUT) ; move JSONOUT array to ^TMP("YTQ-JSON)
N II,JJ
S JJ=$O(^TMP("YTQ-JSON",$J,"A"),-1)
S II=0 F S II=$O(JSONOUT(II)) Q:II="" D
. S JJ=JJ+1,^TMP("YTQ-JSON",$J,JJ,0)=JSONOUT(II)
Q
NOPAT ; no patients but JSON utility sets up "data":[""]. Needs to be "data":[]
Q
N II,BEF,AFT,PSTR,XSTR,DUN
S PSTR="""data"":[""""]",DUN=0
S II="" F S II=$O(JSONOUT(II)) Q:II=""!(DUN) D
. Q:JSONOUT(II)'[PSTR
. S BEF=$P(JSONOUT(II),PSTR),AFT=$P(JSONOUT(II),PSTR,2)
. S JSONOUT(II)=BEF_"""data"":[]"_AFT,DUN=1
Q
;
GETUSER(DATAOUT) ;user info
;Entry point for YSB GET USER RPC
;input DUZ as internal ien file 200 for user to check [optional default is current user]
; KEY as name of security key to check
N TODAY,HASSITE,SITE,I,Y,X
S X="TODAY" D ^%DT S TODAY=Y
S HASSITE=$$DIV4^XUSER(.SITE,DUZ)
I 'HASSITE I $G(DUZ(2))]"" S SITE(DUZ(2))="" ;Use Default site if not explicitly defined.
Q:'$D(SITE)
S DATAOUT("user","id")=DUZ
;S DATAOUT("user","name")=$P($G(^VA(200,DUZ,0)),U,1)
S I=0 F S I=$O(SITE(I)) Q:'I D
.S DATAOUT("user","site",I,"id")=$P(SITE(I),U)
S DATAOUT("user","time")=TODAY
Q
;
CHKCLIN(WIEN,ERR) ; Check if clinic is mental health used in get user and mh next appt and mh last appt
N CLINIC,N0,TOPCD,TOPNO
S (CLINIC,TOPCD,TOPNO)=""
I 'WIEN S ERR="NO IEN" Q 0
S N0=$G(^SC(WIEN,0))
S TOPCD=$P(N0,U,7)
I TOPCD S TOPNO=$$GET1^DIQ(40.7,TOPCD,1) ;get stop code number to check for mental health
I (TOPNO>=500),(TOPNO<600) Q 1
;credit stop code could be mental health, not sure if I should only do this for main stop code=telephone
S TOPCD=$P(N0,U,18)
I TOPCD S TOPNO=$$GET1^DIQ(40.7,TOPCD,1) ;get stop code number to check for mental health
I (TOPNO>=500),(TOPNO<600) Q 1
S ERR="NOT MENTAL HEALTH"
Q 0
;
GETWDGT(DATAOUT,WNAME)
N ID,COLSEQ,LOCATION,WIDGETN0,FIELDN0,COLUMN,SHOW,LOCID,SUBCOL,SUBCOLSEQ,SUBFIELDN0
N INSTID,INSTSEQ,MNGRP,MNSCL,SUB
N INSTS,ISTR,IIEN,ILAB,ILAB2,WIN1,COLCNT,IN0,YSDT,NOW
S NOW=$$NOW^XLFDT()
S WNAME=$G(WNAME)
S YSDT=$P(NOW,".",1)
S ID=0 F S ID=$O(^YSD(605.1,ID)) Q:'ID D ;starting point for load of all widgets
.S WIDGETN0=^YSD(605.1,ID,0)
.Q:$P(WIDGETN0,U)="MBC"
.I WNAME]"",($P(WIDGETN0,U)'=WNAME) Q ;If widget name passed in, only return Widget definition for that Widget
.S DATAOUT("widgets",ID,"id")=ID
.S DATAOUT("widgets",ID,"name")=$P(WIDGETN0,U)
.S COLSEQ=0 F S COLSEQ=$O(^YSD(605.1,ID,1,"AC",COLSEQ)) Q:'COLSEQ D
..S COLUMN=$O(^YSD(605.1,ID,1,"AC",COLSEQ,""))
..S FIELDN0=$G(^YSD(605.1,ID,1,COLUMN,0))
..S DATAOUT("widgets",ID,"columns",COLSEQ,"id")=COLUMN
..S DATAOUT("widgets",ID,"columns",COLSEQ,"name")=$P(FIELDN0,U)
..S DATAOUT("widgets",ID,"columns",COLSEQ,"label")=$P(FIELDN0,U,2)
..S SHOW="true"
..I $P(FIELDN0,U,4)=1 S SHOW="false" ;if hide by default then don't show
..S DATAOUT("widgets",ID,"columns",COLSEQ,"options","display")=SHOW
..S SUBCOLSEQ=0 F S SUBCOLSEQ=$O(^YSD(605.1,ID,1,COLUMN,1,"AC",SUBCOLSEQ)) Q:'SUBCOLSEQ D
...S SUBCOL=$O(^YSD(605.1,ID,1,COLUMN,1,"AC",SUBCOLSEQ,""))
...S SUBFIELDN0=$G(^YSD(605.1,ID,1,COLUMN,1,SUBCOLSEQ,0))
...S DATAOUT("widgets",ID,"columns",COLSEQ,"subcol",SUBCOLSEQ,"options","display")="true" ;Set up default def in 605.1?
...S DATAOUT("widgets",ID,"columns",COLSEQ,"subcol",SUBCOLSEQ,"id")=SUBCOL
...S DATAOUT("widgets",ID,"columns",COLSEQ,"subcol",SUBCOLSEQ,"name")=$P(SUBFIELDN0,U)
...S DATAOUT("widgets",ID,"columns",COLSEQ,"subcol",SUBCOLSEQ,"label")=$P(SUBFIELDN0,U,2)
.;Leave in sub-column process for potential High Risk use
.I ID=4 D ;Add on the Instrument Column/Sub-Columns for the MBC Widget
..S COLCNT=$O(DATAOUT("widgets",ID,"columns","A"),-1)
..K INSTS
..D IDFLT^YSBWHIG2(.INSTS) ;Don't show all instruments
..S INSTSEQ="" F S INSTSEQ=$O(INSTS(INSTSEQ)) Q:'INSTSEQ D
...S ISTR=INSTS(INSTSEQ),IIEN=$P(ISTR,U),ILAB=$P(ISTR,U,2)
...S MNGRP=$G(INSTS(INSTSEQ,"MNGRP")),MNSCL=$G(INSTS(INSTSEQ,"MNSCL"))
...S ILAB2=ILAB_$S(MNSCL]"":" / ",1:"")_MNSCL ;Add on display scale.
...S COLCNT=COLCNT+1
...S DATAOUT("widgets",ID,"columns",COLCNT,"id")=COLCNT
...S DATAOUT("widgets",ID,"columns",COLCNT,"name")=ILAB
...S DATAOUT("widgets",ID,"columns",COLCNT,"label")=ILAB ;ILAB2
...S DATAOUT("widgets",ID,"columns",COLCNT,"insttype")=INSTS(INSTSEQ,"TYPE")
...S DATAOUT("widgets",ID,"columns",COLCNT,"options","display")=$G(INSTS(INSTSEQ,"DISPLAY"))
...F SUB="1^score^Score","2^date^Date","3^trend^Trend" D
....S DATAOUT("widgets",ID,"columns",COLCNT,"subcol",$P(SUB,U),"options","display")=$G(INSTS(INSTSEQ,"DISPLAY"))
....S DATAOUT("widgets",ID,"columns",COLCNT,"subcol",$P(SUB,U),"id")=$P(SUB,U)
....S DATAOUT("widgets",ID,"columns",COLCNT,"subcol",$P(SUB,U),"name")=$P(SUB,U,2)
....S DATAOUT("widgets",ID,"columns",COLCNT,"subcol",$P(SUB,U),"label")=$P(SUB,U,3)
.S INSTSEQ=0 F S INSTSEQ=$O(^YSD(605.1,ID,3,INSTSEQ)) Q:'INSTSEQ D
..S INSTID=^YSD(605.1,ID,3,INSTSEQ,0)
..Q:INSTID="" ;Should not occur
..Q:'$D(^YTT(601.71,INSTID)) ;Instrument not installed in this environment
..S DATAOUT("widgets",ID,"instrumentList",INSTSEQ,"id")=INSTID
..S DATAOUT("widgets",ID,"instrumentList",INSTSEQ,"name")=$P(^YTT(601.71,INSTID,0),U)
.I ID=4 D ;if widget is MBC
..D GETLOCS^YSBWHIG2(.DATAOUT,ID)
Q
;
SELPATS(DATAOUT) ;
N WIDGETNUM
S WIDGETNUM=0 F S WIDGETNUM=$O(DATAOUT("widgets",WIDGETNUM)) Q:'WIDGETNUM D
.N WIDGETNAME
.S WIDGETNAME=DATAOUT("widgets",WIDGETNUM,"name")
.I WIDGETNAME="HIGH RISK" D HIGHRISK^YSBWHIGH(.DATAOUT)
.;I WIDGETNAME="MBC" D MBC^YSBWMBC(.DATAOUT)
Q
HRINIT(SAFHEAD,SAFDCL,SAFREV,SAFSCNO,SAFSCYES,CSREHEAD,CSRENEW,CSREUPD,SITES) ;
D GETLST^XPAR(.SAFHEAD,"ALL","YSB SAFETY PLAN HEADER TEXT")
D GETLST^XPAR(.SAFDCL,"ALL","YSB SAFETY PLAN DECLINE")
D GETLST^XPAR(.SAFREV,"ALL","YSB SAFETY PLAN REVIEWED")
D GETLST^XPAR(.SAFSCNO,"ALL","YSB SAFETY PLAN SOC CONT NO")
D GETLST^XPAR(.SAFSCYES,"ALL","YSB SAFETY PLAN SOC CONT YES")
D GETLST^XPAR(.CSREHEAD,"ALL","YSB CSRE HEADER TEXT")
D GETLST^XPAR(.CSRENEW,"ALL","YSB CSRE NEW EVALUATION")
D GETLST^XPAR(.CSREUPD,"ALL","YSB CSRE UPDATE EVALUATION")
D DIV4^XUSER(.SITES,DUZ)
I '$D(SITES) I $G(DUZ(2))]"" S SITES(DUZ(2))="" ;Use Default site if not explicitly defined.
Q
;D GETLST^XPAR(.SAFHFC,"SYS","YSB SAFETY PLAN HF CATEGORY")
;D GETLST^XPAR(.CSREHFC,"SYS","YSB CSRE HF CATEGORY")
;D GETLST^XPAR(.CSRETITL,"SYS","YSB CSRE DOCUMENT TITLE")
;
GETCONN(JSONOUT) ;Respond to the connection check
N DATAOUT,ERRARY
S DATAOUT("connection","status")="OK"
S DATAOUT("connection","datetime")=$$HTE^XLFDT($H,2)
D ENCODE^YSBJSON("DATAOUT","JSONOUT","ERRARY")
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HYSBRPC 9329 printed Nov 22, 2024@17:23:30 Page 2
YSBRPC ;SLC/DJE - MHA DASHBOARD ; Apr 01, 2021@16:33
+1 ;;5.01;MENTAL HEALTH;**202,221**;Dec 30, 1994;Build 11
+2 ;
+3 ; Routine retrieves Settings, Views, Widgets and User information
+4 QUIT
RESTFUL(OUT,IN) ;main RPC that interprets RESTful calls
+1 IF $GET(IN(1))=""
DO LOADDB(.OUT)
QUIT
+2 ;Connector
+3 IF $EXTRACT(IN(1),1,27)="GET /api/dashboard/getconn/"
DO GETCONN^YSBRPC(.OUT)
+4 ;HR
+5 IF $EXTRACT(IN(1),1,34)="GET /api/dashboard/highrisk/cssrs/"
DO GETRPRT^YSBDD1(.OUT,+$PIECE(IN(1),"GET /api/dashboard/highrisk/cssrs/",2))
+6 IF $EXTRACT(IN(1),1,33)="GET /api/dashboard/highrisk/hrpp/"
DO HRPTPROF^YSBDD1(.OUT,+$PIECE(IN(1),"GET /api/dashboard/highrisk/hrpp/",2))
+7 IF $EXTRACT(IN(1),1,33)="GET /api/dashboard/highrisk/note/"
DO GETNOTE^YSBDD1(.OUT,+$PIECE(IN(1),"GET /api/dashboard/highrisk/note/",2))
+8 ;
+9 IF $EXTRACT(IN(1),1,28)="GET /api/dashboard/userpref/"
DO GETUSRP^YSBPREFS(.OUT)
+10 IF $EXTRACT(IN(1),1,29)="POST /api/dashboard/userpref/"
DO USRP^YSBPREFS(.OUT,.IN)
+11 ;
+12 QUIT
+13 ;I $E(IN(1),1,40)="GET /api/dashboard/highrisk/selcriteria/" D GETHRSEL^YSBDD1(.OUT,+$P(IN(1),"GET /api/dashboard/highrisk/selcriteria/",2))
+14 ;I $E(IN(1),1,41)="POST /api/dashboard/highrisk/selcriteria/" D HRWSEL^YSBDD2(.OUT,.IN)
+15 ;;MBC
+16 ;I $E(IN(1),1,28)="GET /api/dashboard/mbc/data/" D MBC0^YSBWMBC(.OUT)
+17 ;I $E(IN(1),1,27)="GET /api/dashboard/mbc/prf/" D PRF^YSBDD2(.OUT,+$P(IN(1),"GET /api/dashboard/mbc/prf/",2))
+18 ;I $E(IN(1),1,30)="GET /api/dashboard/mbc/visits/" D VST^YSBDD2(.OUT,+$P(IN(1),"GET /api/dashboard/mbc/visits/",2))
+19 ;I $E(IN(1),1,35)="GET /api/dashboard/mbc/selcriteria/" D GETMBSEL^YSBPREFS(.OUT)
+20 ;I $E(IN(1),1,36)="POST /api/dashboard/mbc/selcriteria/" D MBCWSEL^YSBPREFS(.OUT,.IN)
+21 ;I $E(IN(1),1,29)="GET /api/dashboard/mbc/ilist/" D GETILST^YSBPREFS(.OUT)
+22 ;I $E(IN(1),1,30)="POST /api/dashboard/mbc/ilist/" D ILST^YSBPREFS(.OUT,.IN)
+23 ;
LOADDB(JSONOUT) ;Load dashboard data. Currently close to everything is loaded. User data, widget and widget data.
+1 NEW DATAOUT,DATAIN,ERRARY,I
+2 ;get the user data
DO GETUSER(.DATAOUT)
+3 ;process if call from dashboard
DO GETWDGT(.DATAOUT)
+4 ;get the patients
DO SELPATS(.DATAOUT)
+5 IF '$DATA(DATAOUT("data",1,"patient_name"))
Begin DoDot:1
+6 SET DATAOUT("data",1)=""
End DoDot:1
+7 DO ENCODE^YSBJSON("DATAOUT","JSONOUT","ERRARY")
+8 ;I '$D(DATAOUT("data",1,"patient_name")) D NOPAT
+9 QUIT
WEBWIDG(ARGS,RESULTS) ;Load dashboard data for a widget embedded in MHA Web
+1 NEW WNAME,DATAOUT,ERRARY
+2 SET WNAME=$GET(ARGS("widgetName"))
+3 ;get the user data
DO GETUSER(.DATAOUT)
+4 ;process if call from dashboard
DO GETWDGT(.DATAOUT,WNAME)
+5 ;get the patients
DO SELPATS(.DATAOUT)
+6 DO ENCODE^YSBJSON("DATAOUT","JSONOUT","ERRARY")
+7 DO TOTMP(.JSONOUT)
+8 SET RESULTS=$NAME(^TMP("YTQ-JSON",$JOB))
+9 QUIT
TOTMP(JSONOUT) ; move JSONOUT array to ^TMP("YTQ-JSON)
+1 NEW II,JJ
+2 SET JJ=$ORDER(^TMP("YTQ-JSON",$JOB,"A"),-1)
+3 SET II=0
FOR
SET II=$ORDER(JSONOUT(II))
if II=""
QUIT
Begin DoDot:1
+4 SET JJ=JJ+1
SET ^TMP("YTQ-JSON",$JOB,JJ,0)=JSONOUT(II)
End DoDot:1
+5 QUIT
NOPAT ; no patients but JSON utility sets up "data":[""]. Needs to be "data":[]
+1 QUIT
+2 NEW II,BEF,AFT,PSTR,XSTR,DUN
+3 SET PSTR="""data"":[""""]"
SET DUN=0
+4 SET II=""
FOR
SET II=$ORDER(JSONOUT(II))
if II=""!(DUN)
QUIT
Begin DoDot:1
+5 if JSONOUT(II)'[PSTR
QUIT
+6 SET BEF=$PIECE(JSONOUT(II),PSTR)
SET AFT=$PIECE(JSONOUT(II),PSTR,2)
+7 SET JSONOUT(II)=BEF_"""data"":[]"_AFT
SET DUN=1
End DoDot:1
+8 QUIT
+9 ;
GETUSER(DATAOUT) ;user info
+1 ;Entry point for YSB GET USER RPC
+2 ;input DUZ as internal ien file 200 for user to check [optional default is current user]
+3 ; KEY as name of security key to check
+4 NEW TODAY,HASSITE,SITE,I,Y,X
+5 SET X="TODAY"
DO ^%DT
SET TODAY=Y
+6 SET HASSITE=$$DIV4^XUSER(.SITE,DUZ)
+7 ;Use Default site if not explicitly defined.
IF 'HASSITE
IF $GET(DUZ(2))]""
SET SITE(DUZ(2))=""
+8 if '$DATA(SITE)
QUIT
+9 SET DATAOUT("user","id")=DUZ
+10 ;S DATAOUT("user","name")=$P($G(^VA(200,DUZ,0)),U,1)
+11 SET I=0
FOR
SET I=$ORDER(SITE(I))
if 'I
QUIT
Begin DoDot:1
+12 SET DATAOUT("user","site",I,"id")=$PIECE(SITE(I),U)
End DoDot:1
+13 SET DATAOUT("user","time")=TODAY
+14 QUIT
+15 ;
CHKCLIN(WIEN,ERR) ; Check if clinic is mental health used in get user and mh next appt and mh last appt
+1 NEW CLINIC,N0,TOPCD,TOPNO
+2 SET (CLINIC,TOPCD,TOPNO)=""
+3 IF 'WIEN
SET ERR="NO IEN"
QUIT 0
+4 SET N0=$GET(^SC(WIEN,0))
+5 SET TOPCD=$PIECE(N0,U,7)
+6 ;get stop code number to check for mental health
IF TOPCD
SET TOPNO=$$GET1^DIQ(40.7,TOPCD,1)
+7 IF (TOPNO>=500)
IF (TOPNO<600)
QUIT 1
+8 ;credit stop code could be mental health, not sure if I should only do this for main stop code=telephone
+9 SET TOPCD=$PIECE(N0,U,18)
+10 ;get stop code number to check for mental health
IF TOPCD
SET TOPNO=$$GET1^DIQ(40.7,TOPCD,1)
+11 IF (TOPNO>=500)
IF (TOPNO<600)
QUIT 1
+12 SET ERR="NOT MENTAL HEALTH"
+13 QUIT 0
+14 ;
GETWDGT(DATAOUT,WNAME) +1 NEW ID,COLSEQ,LOCATION,WIDGETN0,FIELDN0,COLUMN,SHOW,LOCID,SUBCOL,SUBCOLSEQ,SUBFIELDN0
+2 NEW INSTID,INSTSEQ,MNGRP,MNSCL,SUB
+3 NEW INSTS,ISTR,IIEN,ILAB,ILAB2,WIN1,COLCNT,IN0,YSDT,NOW
+4 SET NOW=$$NOW^XLFDT()
+5 SET WNAME=$GET(WNAME)
+6 SET YSDT=$PIECE(NOW,".",1)
+7 ;starting point for load of all widgets
SET ID=0
FOR
SET ID=$ORDER(^YSD(605.1,ID))
if 'ID
QUIT
Begin DoDot:1
+8 SET WIDGETN0=^YSD(605.1,ID,0)
+9 if $PIECE(WIDGETN0,U)="MBC"
QUIT
+10 ;If widget name passed in, only return Widget definition for that Widget
IF WNAME]""
IF ($PIECE(WIDGETN0,U)'=WNAME)
QUIT
+11 SET DATAOUT("widgets",ID,"id")=ID
+12 SET DATAOUT("widgets",ID,"name")=$PIECE(WIDGETN0,U)
+13 SET COLSEQ=0
FOR
SET COLSEQ=$ORDER(^YSD(605.1,ID,1,"AC",COLSEQ))
if 'COLSEQ
QUIT
Begin DoDot:2
+14 SET COLUMN=$ORDER(^YSD(605.1,ID,1,"AC",COLSEQ,""))
+15 SET FIELDN0=$GET(^YSD(605.1,ID,1,COLUMN,0))
+16 SET DATAOUT("widgets",ID,"columns",COLSEQ,"id")=COLUMN
+17 SET DATAOUT("widgets",ID,"columns",COLSEQ,"name")=$PIECE(FIELDN0,U)
+18 SET DATAOUT("widgets",ID,"columns",COLSEQ,"label")=$PIECE(FIELDN0,U,2)
+19 SET SHOW="true"
+20 ;if hide by default then don't show
IF $PIECE(FIELDN0,U,4)=1
SET SHOW="false"
+21 SET DATAOUT("widgets",ID,"columns",COLSEQ,"options","display")=SHOW
+22 SET SUBCOLSEQ=0
FOR
SET SUBCOLSEQ=$ORDER(^YSD(605.1,ID,1,COLUMN,1,"AC",SUBCOLSEQ))
if 'SUBCOLSEQ
QUIT
Begin DoDot:3
+23 SET SUBCOL=$ORDER(^YSD(605.1,ID,1,COLUMN,1,"AC",SUBCOLSEQ,""))
+24 SET SUBFIELDN0=$GET(^YSD(605.1,ID,1,COLUMN,1,SUBCOLSEQ,0))
+25 ;Set up default def in 605.1?
SET DATAOUT("widgets",ID,"columns",COLSEQ,"subcol",SUBCOLSEQ,"options","display")="true"
+26 SET DATAOUT("widgets",ID,"columns",COLSEQ,"subcol",SUBCOLSEQ,"id")=SUBCOL
+27 SET DATAOUT("widgets",ID,"columns",COLSEQ,"subcol",SUBCOLSEQ,"name")=$PIECE(SUBFIELDN0,U)
+28 SET DATAOUT("widgets",ID,"columns",COLSEQ,"subcol",SUBCOLSEQ,"label")=$PIECE(SUBFIELDN0,U,2)
End DoDot:3
End DoDot:2
+29 ;Leave in sub-column process for potential High Risk use
+30 ;Add on the Instrument Column/Sub-Columns for the MBC Widget
IF ID=4
Begin DoDot:2
+31 SET COLCNT=$ORDER(DATAOUT("widgets",ID,"columns","A"),-1)
+32 KILL INSTS
+33 ;Don't show all instruments
DO IDFLT^YSBWHIG2(.INSTS)
+34 SET INSTSEQ=""
FOR
SET INSTSEQ=$ORDER(INSTS(INSTSEQ))
if 'INSTSEQ
QUIT
Begin DoDot:3
+35 SET ISTR=INSTS(INSTSEQ)
SET IIEN=$PIECE(ISTR,U)
SET ILAB=$PIECE(ISTR,U,2)
+36 SET MNGRP=$GET(INSTS(INSTSEQ,"MNGRP"))
SET MNSCL=$GET(INSTS(INSTSEQ,"MNSCL"))
+37 ;Add on display scale.
SET ILAB2=ILAB_$SELECT(MNSCL]"":" / ",1:"")_MNSCL
+38 SET COLCNT=COLCNT+1
+39 SET DATAOUT("widgets",ID,"columns",COLCNT,"id")=COLCNT
+40 SET DATAOUT("widgets",ID,"columns",COLCNT,"name")=ILAB
+41 ;ILAB2
SET DATAOUT("widgets",ID,"columns",COLCNT,"label")=ILAB
+42 SET DATAOUT("widgets",ID,"columns",COLCNT,"insttype")=INSTS(INSTSEQ,"TYPE")
+43 SET DATAOUT("widgets",ID,"columns",COLCNT,"options","display")=$GET(INSTS(INSTSEQ,"DISPLAY"))
+44 FOR SUB="1^score^Score","2^date^Date","3^trend^Trend"
Begin DoDot:4
+45 SET DATAOUT("widgets",ID,"columns",COLCNT,"subcol",$PIECE(SUB,U),"options","display")=$GET(INSTS(INSTSEQ,"DISPLAY"))
+46 SET DATAOUT("widgets",ID,"columns",COLCNT,"subcol",$PIECE(SUB,U),"id")=$PIECE(SUB,U)
+47 SET DATAOUT("widgets",ID,"columns",COLCNT,"subcol",$PIECE(SUB,U),"name")=$PIECE(SUB,U,2)
+48 SET DATAOUT("widgets",ID,"columns",COLCNT,"subcol",$PIECE(SUB,U),"label")=$PIECE(SUB,U,3)
End DoDot:4
End DoDot:3
End DoDot:2
+49 SET INSTSEQ=0
FOR
SET INSTSEQ=$ORDER(^YSD(605.1,ID,3,INSTSEQ))
if 'INSTSEQ
QUIT
Begin DoDot:2
+50 SET INSTID=^YSD(605.1,ID,3,INSTSEQ,0)
+51 ;Should not occur
if INSTID=""
QUIT
+52 ;Instrument not installed in this environment
if '$DATA(^YTT(601.71,INSTID))
QUIT
+53 SET DATAOUT("widgets",ID,"instrumentList",INSTSEQ,"id")=INSTID
+54 SET DATAOUT("widgets",ID,"instrumentList",INSTSEQ,"name")=$PIECE(^YTT(601.71,INSTID,0),U)
End DoDot:2
+55 ;if widget is MBC
IF ID=4
Begin DoDot:2
+56 DO GETLOCS^YSBWHIG2(.DATAOUT,ID)
End DoDot:2
End DoDot:1
+57 QUIT
+58 ;
SELPATS(DATAOUT) ;
+1 NEW WIDGETNUM
+2 SET WIDGETNUM=0
FOR
SET WIDGETNUM=$ORDER(DATAOUT("widgets",WIDGETNUM))
if 'WIDGETNUM
QUIT
Begin DoDot:1
+3 NEW WIDGETNAME
+4 SET WIDGETNAME=DATAOUT("widgets",WIDGETNUM,"name")
+5 IF WIDGETNAME="HIGH RISK"
DO HIGHRISK^YSBWHIGH(.DATAOUT)
+6 ;I WIDGETNAME="MBC" D MBC^YSBWMBC(.DATAOUT)
End DoDot:1
+7 QUIT
HRINIT(SAFHEAD,SAFDCL,SAFREV,SAFSCNO,SAFSCYES,CSREHEAD,CSRENEW,CSREUPD,SITES) ;
+1 DO GETLST^XPAR(.SAFHEAD,"ALL","YSB SAFETY PLAN HEADER TEXT")
+2 DO GETLST^XPAR(.SAFDCL,"ALL","YSB SAFETY PLAN DECLINE")
+3 DO GETLST^XPAR(.SAFREV,"ALL","YSB SAFETY PLAN REVIEWED")
+4 DO GETLST^XPAR(.SAFSCNO,"ALL","YSB SAFETY PLAN SOC CONT NO")
+5 DO GETLST^XPAR(.SAFSCYES,"ALL","YSB SAFETY PLAN SOC CONT YES")
+6 DO GETLST^XPAR(.CSREHEAD,"ALL","YSB CSRE HEADER TEXT")
+7 DO GETLST^XPAR(.CSRENEW,"ALL","YSB CSRE NEW EVALUATION")
+8 DO GETLST^XPAR(.CSREUPD,"ALL","YSB CSRE UPDATE EVALUATION")
+9 DO DIV4^XUSER(.SITES,DUZ)
+10 ;Use Default site if not explicitly defined.
IF '$DATA(SITES)
IF $GET(DUZ(2))]""
SET SITES(DUZ(2))=""
+11 QUIT
+12 ;D GETLST^XPAR(.SAFHFC,"SYS","YSB SAFETY PLAN HF CATEGORY")
+13 ;D GETLST^XPAR(.CSREHFC,"SYS","YSB CSRE HF CATEGORY")
+14 ;D GETLST^XPAR(.CSRETITL,"SYS","YSB CSRE DOCUMENT TITLE")
+15 ;
GETCONN(JSONOUT) ;Respond to the connection check
+1 NEW DATAOUT,ERRARY
+2 SET DATAOUT("connection","status")="OK"
+3 SET DATAOUT("connection","datetime")=$$HTE^XLFDT($HOROLOG,2)
+4 DO ENCODE^YSBJSON("DATAOUT","JSONOUT","ERRARY")
+5 QUIT