YTSCAT ;SLC/KCM - CAT Scoring and Reporting ; 6/30/2021
;;5.01;MENTAL HEALTH;**182,199,202,217,221,234**;DEC 30,1994;Build 38
;
DLLSTR(YSDATA,YS,YSMODE) ; main tag for both scores and report text
;.YSDATA(1)=[DATA]
;.YSDATA(2)=adminId^dfn^testNm^dtGiven^complete
;.YSDATA(3..n)=questionId^sequence^choiceId
;.YS("AD")=adminId
;YSMODE=1 for calc score, 2 for report text
;
; if score, calculate based on answers in YSDATA, save in ^TMP($J,"YSCOR")
I YSMODE=1 D SCORE(.YSDATA) QUIT
; if report, build special text, add pseudo-question responses to YSDATA
I YSMODE=2 D REPORT(.YSDATA,.YS) QUIT
Q
SCORE(YSDATA) ; iterate through answers and calculate score
; looks like this is in every scoring routine...
; SCOREINS^YTSCORE sets up ^TMP($J,"YSG") with scales
; if no scales are defined, we can't score instrument
K ^TMP($J,"YSCOR")
I $D(^TMP($J,"YSG",1)),^TMP($J,"YSG",1)="[ERROR]" D Q ;-->out
. S ^TMP($J,"YSCOR",1)="[ERROR]"
. S ^TMP($J,"YSCOR",2)="No Scale found for ADMIN"
;
N TREE
D WP2JSON(.YSDATA,.TREE)
I $$INSNAME(TREE("report","tests",1,"type"))'=$P(^TMP($J,"YSG",2),U,2) D Q
. S ^TMP($J,"YSCOR",1)="[ERROR]"
. S ^TMP($J,"YSCOR",2)="Mismatch of test type"
;
; currently Severity is the only scale in use for CAT
N I,X,N,SNUM,SNAME,SCORE
S N=1,^TMP($J,"YSCOR",N)="[DATA]"
S I=1 F S I=$O(^TMP($J,"YSG",I)) Q:'I D
. S X=^TMP($J,"YSG",I) Q:$E(X,1,5)'="Scale"
. S SNUM=$P($P(X,"^"),"=",2),SNAME=$P(X,"^",4)
. I SNAME="Confidence" S SCORE=$G(TREE("report","tests",1,"confidence"))
. I SNAME="Percentile" S SCORE=$G(TREE("report","tests",1,"percentile"))
. I SNAME="Precision" S SCORE=$G(TREE("report","tests",1,"precision"))
. I SNAME="Probability" S SCORE=$G(TREE("report","tests",1,"prob"))
. I SNAME="Severity" S SCORE=$G(TREE("report","tests",1,"severity"))
. I SNAME="Probability",$L(SCORE) S SCORE=SCORE_U_SCORE*100
. I $L(SCORE) S N=N+1,^TMP($J,"YSCOR",N)=SNAME_"="_SCORE
Q
REPORT(YSDATA,YS) ; add textual scores to report
; at this point YTQRRPT has already called GETSCORE^YTQAPI8 so
; ^TMP($J,"YSCOR") is defined and we're in the middle of ALLANS^YTQAPI2
; YSDATA(2+n)=questionId^sequence^choiceId or text response
N I,TTYP,TREE,SCORTXT,ANSTXT,TSTTXT,ALLANS
S SCORTXT="",ANSTXT="",TSTTXT="",ALLANS=1
D WP2JSON(.YSDATA,.TREE)
S I=0 F S I=$O(TREE("report","tests",I)) Q:'I D
. S TTYP=$$LOW^XLFSTR(TREE("report","tests",I,"type"))
. S TSTTXT=TSTTXT_$S($L(TSTTXT):", ",1:"")_$$FULLNAME(TTYP)
. S SCORTXT=SCORTXT_"| | "_$$FULLNAME(TTYP)
. I TTYP="mdd" D ADDSCORE(I,"diag^conf")
. I TTYP="dep" D ADDSCORE(I,"cate^seve^prec^prob^perc")
. I TTYP="anx" D ADDSCORE(I,"cate^seve^prec^prob^perc")
. I TTYP="m/hm" D ADDSCORE(I,"cate^seve^prec")
. I TTYP="sud" D ADDSCORE(I,"cate^seve^prec")
. I TTYP="sa" D ADDSCORE(I,"cate^seve^prec")
. I TTYP="ptsd" D ADDSCORE(I,"cate^seve^prec")
. I TTYP="a/adhd" D ADDSCORE(I,"cate^seve^prec")
. I TTYP="sdoh" D ADDSCORE(I,"cate^seve^prec")
. I TTYP="ss" D ADDSCORE(I,"cate^seve^prec")
. I TTYP="ptsd-dx" D ADDSCORE(I,"diag^ptsd") ; special prob wording
. I TTYP="ptsd-e" D ADDSCORE(I,"cate^seve^prec")
. I TTYP="psy-c" D ADDSCORE(I,"cate^seve^prec")
. I TTYP="psy-s" D ADDSCORE(I,"cate^seve^prec")
. I $D(TREE("report","tests",I,"items"))>1 S ALLANS=0 D
. . D TM4TEST(I)
. . I TTYP="ptsd-dx" D ADDPTSD
. . D QA4TEST(I)
;
I ALLANS D QA4ALL ; prior to itemLevel=1 chg
S I=$O(YSDATA(""),-1)+1
S YSDATA(I)="7771^9999;1^"_SCORTXT ; scoring text
S YSDATA(I+1)="7772^9999;1^"_TSTTXT ; test names for note
Q
QA4TEST(ITEST) ; add Questions & Answers for 1 Test
; expects: TREE,SCORTXT,LN from REPORT
N ITEM,QID,TXT,DUR
S TXT=""
S ITEM=0 F S ITEM=$O(TREE("report","tests",ITEST,"items",ITEM)) Q:'ITEM D
. S QID=$G(TREE("report","tests",ITEST,"items",ITEM,"questionId"))
. I QID D
. . S TXT=TXT_$$QA4QID(QID)
. . S DUR=$G(TREE("report","tests",ITEST,"items",ITEM,"duration"),0)
. . I DUR S TXT=TXT_"("_$$TMSTR(DUR)_")"
S SCORTXT=SCORTXT_"||Questions and Answers:|"_TXT
Q
QA4QID(QID) ; return question & response text from answers
N ANS,QATXT
S QATXT=""
S ANS=0 F S ANS=$O(TREE("answers",ANS)) Q:'ANS I TREE("answers",ANS,"id")=QID D Q
. S QATXT=$$WRAP($G(TREE("answers",ANS,"text")),75,"|")
. S QATXT=QATXT_"| "_$$PAD(25,$G(TREE("answers",ANS,"responseText")))
Q QATXT
;
TM4TEST(SEQ) ; return a block of text with the completion time
N I,TTIME
I $G(TREE("status"))="declined" QUIT
;
S TTIME=0
S I=0 F S I=$O(TREE("report","tests",SEQ,"items",I)) Q:'I D
. S TTIME=TTIME+$G(TREE("report","tests",SEQ,"items",I,"duration"),0)
D ADDLN("| Total Elapsed Time: "_$$TMSTR(TTIME))
Q
QA4ALL ; add Questions & Answers for all tests together
; expects: TREE,SCORTXT,LN from REPORT
N I,TXT
S TXT=""
S I=0 F S I=$O(TREE("answers",I)) Q:'I D
. S TXT=TXT_$$WRAP($G(TREE("answers",I,"text")),75,"|")
. S TXT=TXT_"| "_$$PAD(25,$G(TREE("answers",I,"responseText")))
. S TXT=TXT_"("_$$TMSTR($G(TREE("answers",I,"duration"))/1000)_")"
S SCORTXT=SCORTXT_"||Questions and Answers:|"_TXT
Q
TM4ALL ; add elapsed time for all questions
N I,TTIME
S TTIME=0
S I=0 F S I=$O(TREE("answers",I)) Q:'I D
. S TTIME=TTIME+$G(TREE("answers",I,"duration"),0)
S TTIME=TTIME/1000
D ADDLN("| Total Elapsed Time: "_$$TMSTR(TTIME))
Q
ADDSCORE(SEQ,WHICH) ; return a block of text with the appropriate scores
; expects TREE,SCORTXT from REPORT
N I,X
I $G(TREE("status"))="declined" D ADDLN("| Interview declined.") QUIT
;
F I=1:1:$L(WHICH) S X=$P(WHICH,"^",I) D
. I X="diag" D ADDLN("| Diagnosis: "_$G(TREE("report","tests",SEQ,"diagnosis")))
. I X="conf" D ADDLN("| Confidence: "_$G(TREE("report","tests",SEQ,"confidence")))
. I X="seve" D ADDLN("| Severity: "_$G(TREE("report","tests",SEQ,"severity")))
. I X="cate" D ADDLN("| Category: "_$G(TREE("report","tests",SEQ,"category")))
. I X="prec" D ADDLN("| Precision: "_$G(TREE("report","tests",SEQ,"precision")))
. I X="prob" D ADDLN("| Probability: "_$J(+$G(TREE("report","tests",SEQ,"prob")),1,3))
. I X="ptsd" D ADDLN("| Probability of PTSD*: "_$J(+$G(TREE("report","tests",SEQ,"prob")),1,3))
. I X="perc" D ADDLN("| Percentile: "_$G(TREE("report","tests",SEQ,"percentile")))
Q
ADDPTSD ; add interpretive text for CAD-PTSD-DX
; expects SCORTXT
N I,X
F I=1:1 S X=$P($T(TXTPTSD+I),";;",2,99) Q:X="zzzzz" D ADDLN(X)
Q
ADDLN(TXT) ; add a line of text
; expects SCORTXT from REPORT>ADDSCORE
S SCORTXT=$G(SCORTXT)_TXT
Q
FULLNAME(TTYP) ; return full name for a CAT Test Type
S TTYP=$$LOW^XLFSTR(TTYP)
I TTYP="mdd" Q "Major Depressive Disorder"
I TTYP="dep" Q "Depression"
I TTYP="anx" Q "Anxiety Disorder"
I TTYP="m/hm" Q "Mania/Hypomania"
I TTYP="sud" Q "Substance Use Disorder"
I TTYP="sa" Q "Substance Use Disorder"
I TTYP="ptsd" Q "Post-Traumatic Stress Disorder"
I TTYP="a/adhd" Q "Adult ADHD"
I TTYP="sdoh" Q "Social Determinants of Health"
I TTYP="ss" Q "Suicide Scale"
I TTYP="ptsd-dx" Q "PTSD-Diagnosis"
I TTYP="ptsd-e" Q "PTSD-Expanded"
I TTYP="psy-c" Q "Psychosis - Clinician"
I TTYP="psy-s" Q "Psychosis - Self-Report"
Q "Unknown Test"
;
INSNAME(TTYP) ; return full name for a CAT Test Type
S TTYP=$$LOW^XLFSTR(TTYP)
I TTYP="mdd" Q "CAD-MDD"
I TTYP="dep" Q "CAT-DEP"
I TTYP="anx" Q "CAT-ANX"
I TTYP="m/hm" Q "CAT-MANIA-HYPOMANIA"
I TTYP="sud" Q "CAT-SUD"
I TTYP="sa" Q "CAT-SUD"
I TTYP="ptsd" Q "CAT-PTSD"
I TTYP="a/adhd" Q "CAT-ADHD"
I TTYP="sdoh" Q "CAT-SDOH"
I TTYP="ss" Q "CAT-SS"
I TTYP="ptsd-dx" Q "CAD-PTSD-DX"
I TTYP="ptsd-e" Q "CAT-PTSD-E"
I TTYP="psy-c" Q "CAT-PSYCHOSIS"
I TTYP="psy-s" Q "CAT-PSYCHOSIS"
Q "Unknown Test"
;
PAD(LEN,STR) ; return spaces until X is LEN
N X S X=" "
Q STR_$E(X,1,LEN-$L(STR))
;
TMSTR(ATIME) ; return a readable elapsed time
N MIN,SEC,X
S MIN=ATIME\60
S SEC=$P(ATIME-(60*MIN)+0.5,".")
S X=""
I MIN S X=MIN_$S(MIN=1:" minute ",1:" minutes ")
S X=X_SEC_$S(SEC=1:" second",1:" seconds")
Q X
;
WP2JSON(YSDATA,TREE) ; put YSDATA answer into M-subscript format
N I,J,K,L,S,JSON
S I=2,K=0 F S I=$O(YSDATA(I)) Q:'I Q:$P(YSDATA(I),U)'=8650 D
. S L=$P(YSDATA(I),"^",3,99)
. F J=1:1:$L(L,"|") S S=$P(L,"|",J) I $L(S) S K=K+1,JSON(K)=S
D DECODE^XLFJSON("JSON","TREE")
Q
WRAP(IN,MAX,PRE) ; Return with | and spacing in correct place
N X,I,J,TXT,WORD
S J=1,TXT(J)=PRE_$P(IN," ")
F I=2:1:$L(IN," ") S WORD=$P(IN," ",I) D
. I ($L(TXT(J))+$L(WORD)+1)<MAX S TXT(J)=TXT(J)_" "_WORD I 1
. E S J=J+1,TXT(J)=PRE_WORD
S X=TXT(1),I=1 F S I=$O(TXT(I)) Q:'I S X=X_TXT(I)
Q X
;
TXTPTSD ; Interpretive text for CAD-PTSD-DX
;;|| *The "Probability of PTSD" score, which ranges from 0 to 1, can be used
;;| as a measure of how confident you can be in the predicted diagnosis -
;;| e.g., 0.10 (very unlikely) . 0.50 (equivocal) . 0.90 (very likely).
;;| A mid-range score between 0.25-0.75 should be interpreted as somewhat
;;| equivocal, meaning that additional information is needed to make an
;;| accurate diagnosis; scores at either the low or high end of the range
;;| provide more confidence in the diagnosis presented.|
;;zzzzz
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HYTSCAT 9394 printed Dec 13, 2024@02:19:29 Page 2
YTSCAT ;SLC/KCM - CAT Scoring and Reporting ; 6/30/2021
+1 ;;5.01;MENTAL HEALTH;**182,199,202,217,221,234**;DEC 30,1994;Build 38
+2 ;
DLLSTR(YSDATA,YS,YSMODE) ; main tag for both scores and report text
+1 ;.YSDATA(1)=[DATA]
+2 ;.YSDATA(2)=adminId^dfn^testNm^dtGiven^complete
+3 ;.YSDATA(3..n)=questionId^sequence^choiceId
+4 ;.YS("AD")=adminId
+5 ;YSMODE=1 for calc score, 2 for report text
+6 ;
+7 ; if score, calculate based on answers in YSDATA, save in ^TMP($J,"YSCOR")
+8 IF YSMODE=1
DO SCORE(.YSDATA)
QUIT
+9 ; if report, build special text, add pseudo-question responses to YSDATA
+10 IF YSMODE=2
DO REPORT(.YSDATA,.YS)
QUIT
+11 QUIT
SCORE(YSDATA) ; iterate through answers and calculate score
+1 ; looks like this is in every scoring routine...
+2 ; SCOREINS^YTSCORE sets up ^TMP($J,"YSG") with scales
+3 ; if no scales are defined, we can't score instrument
+4 KILL ^TMP($JOB,"YSCOR")
+5 ;-->out
IF $DATA(^TMP($JOB,"YSG",1))
IF ^TMP($JOB,"YSG",1)="[ERROR]"
Begin DoDot:1
+6 SET ^TMP($JOB,"YSCOR",1)="[ERROR]"
+7 SET ^TMP($JOB,"YSCOR",2)="No Scale found for ADMIN"
End DoDot:1
QUIT
+8 ;
+9 NEW TREE
+10 DO WP2JSON(.YSDATA,.TREE)
+11 IF $$INSNAME(TREE("report","tests",1,"type"))'=$PIECE(^TMP($JOB,"YSG",2),U,2)
Begin DoDot:1
+12 SET ^TMP($JOB,"YSCOR",1)="[ERROR]"
+13 SET ^TMP($JOB,"YSCOR",2)="Mismatch of test type"
End DoDot:1
QUIT
+14 ;
+15 ; currently Severity is the only scale in use for CAT
+16 NEW I,X,N,SNUM,SNAME,SCORE
+17 SET N=1
SET ^TMP($JOB,"YSCOR",N)="[DATA]"
+18 SET I=1
FOR
SET I=$ORDER(^TMP($JOB,"YSG",I))
if 'I
QUIT
Begin DoDot:1
+19 SET X=^TMP($JOB,"YSG",I)
if $EXTRACT(X,1,5)'="Scale"
QUIT
+20 SET SNUM=$PIECE($PIECE(X,"^"),"=",2)
SET SNAME=$PIECE(X,"^",4)
+21 IF SNAME="Confidence"
SET SCORE=$GET(TREE("report","tests",1,"confidence"))
+22 IF SNAME="Percentile"
SET SCORE=$GET(TREE("report","tests",1,"percentile"))
+23 IF SNAME="Precision"
SET SCORE=$GET(TREE("report","tests",1,"precision"))
+24 IF SNAME="Probability"
SET SCORE=$GET(TREE("report","tests",1,"prob"))
+25 IF SNAME="Severity"
SET SCORE=$GET(TREE("report","tests",1,"severity"))
+26 IF SNAME="Probability"
IF $LENGTH(SCORE)
SET SCORE=SCORE_U_SCORE*100
+27 IF $LENGTH(SCORE)
SET N=N+1
SET ^TMP($JOB,"YSCOR",N)=SNAME_"="_SCORE
End DoDot:1
+28 QUIT
REPORT(YSDATA,YS) ; add textual scores to report
+1 ; at this point YTQRRPT has already called GETSCORE^YTQAPI8 so
+2 ; ^TMP($J,"YSCOR") is defined and we're in the middle of ALLANS^YTQAPI2
+3 ; YSDATA(2+n)=questionId^sequence^choiceId or text response
+4 NEW I,TTYP,TREE,SCORTXT,ANSTXT,TSTTXT,ALLANS
+5 SET SCORTXT=""
SET ANSTXT=""
SET TSTTXT=""
SET ALLANS=1
+6 DO WP2JSON(.YSDATA,.TREE)
+7 SET I=0
FOR
SET I=$ORDER(TREE("report","tests",I))
if 'I
QUIT
Begin DoDot:1
+8 SET TTYP=$$LOW^XLFSTR(TREE("report","tests",I,"type"))
+9 SET TSTTXT=TSTTXT_$SELECT($LENGTH(TSTTXT):", ",1:"")_$$FULLNAME(TTYP)
+10 SET SCORTXT=SCORTXT_"| | "_$$FULLNAME(TTYP)
+11 IF TTYP="mdd"
DO ADDSCORE(I,"diag^conf")
+12 IF TTYP="dep"
DO ADDSCORE(I,"cate^seve^prec^prob^perc")
+13 IF TTYP="anx"
DO ADDSCORE(I,"cate^seve^prec^prob^perc")
+14 IF TTYP="m/hm"
DO ADDSCORE(I,"cate^seve^prec")
+15 IF TTYP="sud"
DO ADDSCORE(I,"cate^seve^prec")
+16 IF TTYP="sa"
DO ADDSCORE(I,"cate^seve^prec")
+17 IF TTYP="ptsd"
DO ADDSCORE(I,"cate^seve^prec")
+18 IF TTYP="a/adhd"
DO ADDSCORE(I,"cate^seve^prec")
+19 IF TTYP="sdoh"
DO ADDSCORE(I,"cate^seve^prec")
+20 IF TTYP="ss"
DO ADDSCORE(I,"cate^seve^prec")
+21 ; special prob wording
IF TTYP="ptsd-dx"
DO ADDSCORE(I,"diag^ptsd")
+22 IF TTYP="ptsd-e"
DO ADDSCORE(I,"cate^seve^prec")
+23 IF TTYP="psy-c"
DO ADDSCORE(I,"cate^seve^prec")
+24 IF TTYP="psy-s"
DO ADDSCORE(I,"cate^seve^prec")
+25 IF $DATA(TREE("report","tests",I,"items"))>1
SET ALLANS=0
Begin DoDot:2
+26 DO TM4TEST(I)
+27 IF TTYP="ptsd-dx"
DO ADDPTSD
+28 DO QA4TEST(I)
End DoDot:2
End DoDot:1
+29 ;
+30 ; prior to itemLevel=1 chg
IF ALLANS
DO QA4ALL
+31 SET I=$ORDER(YSDATA(""),-1)+1
+32 ; scoring text
SET YSDATA(I)="7771^9999;1^"_SCORTXT
+33 ; test names for note
SET YSDATA(I+1)="7772^9999;1^"_TSTTXT
+34 QUIT
QA4TEST(ITEST) ; add Questions & Answers for 1 Test
+1 ; expects: TREE,SCORTXT,LN from REPORT
+2 NEW ITEM,QID,TXT,DUR
+3 SET TXT=""
+4 SET ITEM=0
FOR
SET ITEM=$ORDER(TREE("report","tests",ITEST,"items",ITEM))
if 'ITEM
QUIT
Begin DoDot:1
+5 SET QID=$GET(TREE("report","tests",ITEST,"items",ITEM,"questionId"))
+6 IF QID
Begin DoDot:2
+7 SET TXT=TXT_$$QA4QID(QID)
+8 SET DUR=$GET(TREE("report","tests",ITEST,"items",ITEM,"duration"),0)
+9 IF DUR
SET TXT=TXT_"("_$$TMSTR(DUR)_")"
End DoDot:2
End DoDot:1
+10 SET SCORTXT=SCORTXT_"||Questions and Answers:|"_TXT
+11 QUIT
QA4QID(QID) ; return question & response text from answers
+1 NEW ANS,QATXT
+2 SET QATXT=""
+3 SET ANS=0
FOR
SET ANS=$ORDER(TREE("answers",ANS))
if 'ANS
QUIT
IF TREE("answers",ANS,"id")=QID
Begin DoDot:1
+4 SET QATXT=$$WRAP($GET(TREE("answers",ANS,"text")),75,"|")
+5 SET QATXT=QATXT_"| "_$$PAD(25,$GET(TREE("answers",ANS,"responseText")))
End DoDot:1
QUIT
+6 QUIT QATXT
+7 ;
TM4TEST(SEQ) ; return a block of text with the completion time
+1 NEW I,TTIME
+2 IF $GET(TREE("status"))="declined"
QUIT
+3 ;
+4 SET TTIME=0
+5 SET I=0
FOR
SET I=$ORDER(TREE("report","tests",SEQ,"items",I))
if 'I
QUIT
Begin DoDot:1
+6 SET TTIME=TTIME+$GET(TREE("report","tests",SEQ,"items",I,"duration"),0)
End DoDot:1
+7 DO ADDLN("| Total Elapsed Time: "_$$TMSTR(TTIME))
+8 QUIT
QA4ALL ; add Questions & Answers for all tests together
+1 ; expects: TREE,SCORTXT,LN from REPORT
+2 NEW I,TXT
+3 SET TXT=""
+4 SET I=0
FOR
SET I=$ORDER(TREE("answers",I))
if 'I
QUIT
Begin DoDot:1
+5 SET TXT=TXT_$$WRAP($GET(TREE("answers",I,"text")),75,"|")
+6 SET TXT=TXT_"| "_$$PAD(25,$GET(TREE("answers",I,"responseText")))
+7 SET TXT=TXT_"("_$$TMSTR($GET(TREE("answers",I,"duration"))/1000)_")"
End DoDot:1
+8 SET SCORTXT=SCORTXT_"||Questions and Answers:|"_TXT
+9 QUIT
TM4ALL ; add elapsed time for all questions
+1 NEW I,TTIME
+2 SET TTIME=0
+3 SET I=0
FOR
SET I=$ORDER(TREE("answers",I))
if 'I
QUIT
Begin DoDot:1
+4 SET TTIME=TTIME+$GET(TREE("answers",I,"duration"),0)
End DoDot:1
+5 SET TTIME=TTIME/1000
+6 DO ADDLN("| Total Elapsed Time: "_$$TMSTR(TTIME))
+7 QUIT
ADDSCORE(SEQ,WHICH) ; return a block of text with the appropriate scores
+1 ; expects TREE,SCORTXT from REPORT
+2 NEW I,X
+3 IF $GET(TREE("status"))="declined"
DO ADDLN("| Interview declined.")
QUIT
+4 ;
+5 FOR I=1:1:$LENGTH(WHICH)
SET X=$PIECE(WHICH,"^",I)
Begin DoDot:1
+6 IF X="diag"
DO ADDLN("| Diagnosis: "_$GET(TREE("report","tests",SEQ,"diagnosis")))
+7 IF X="conf"
DO ADDLN("| Confidence: "_$GET(TREE("report","tests",SEQ,"confidence")))
+8 IF X="seve"
DO ADDLN("| Severity: "_$GET(TREE("report","tests",SEQ,"severity")))
+9 IF X="cate"
DO ADDLN("| Category: "_$GET(TREE("report","tests",SEQ,"category")))
+10 IF X="prec"
DO ADDLN("| Precision: "_$GET(TREE("report","tests",SEQ,"precision")))
+11 IF X="prob"
DO ADDLN("| Probability: "_$JUSTIFY(+$GET(TREE("report","tests",SEQ,"prob")),1,3))
+12 IF X="ptsd"
DO ADDLN("| Probability of PTSD*: "_$JUSTIFY(+$GET(TREE("report","tests",SEQ,"prob")),1,3))
+13 IF X="perc"
DO ADDLN("| Percentile: "_$GET(TREE("report","tests",SEQ,"percentile")))
End DoDot:1
+14 QUIT
ADDPTSD ; add interpretive text for CAD-PTSD-DX
+1 ; expects SCORTXT
+2 NEW I,X
+3 FOR I=1:1
SET X=$PIECE($TEXT(TXTPTSD+I),";;",2,99)
if X="zzzzz"
QUIT
DO ADDLN(X)
+4 QUIT
ADDLN(TXT) ; add a line of text
+1 ; expects SCORTXT from REPORT>ADDSCORE
+2 SET SCORTXT=$GET(SCORTXT)_TXT
+3 QUIT
FULLNAME(TTYP) ; return full name for a CAT Test Type
+1 SET TTYP=$$LOW^XLFSTR(TTYP)
+2 IF TTYP="mdd"
QUIT "Major Depressive Disorder"
+3 IF TTYP="dep"
QUIT "Depression"
+4 IF TTYP="anx"
QUIT "Anxiety Disorder"
+5 IF TTYP="m/hm"
QUIT "Mania/Hypomania"
+6 IF TTYP="sud"
QUIT "Substance Use Disorder"
+7 IF TTYP="sa"
QUIT "Substance Use Disorder"
+8 IF TTYP="ptsd"
QUIT "Post-Traumatic Stress Disorder"
+9 IF TTYP="a/adhd"
QUIT "Adult ADHD"
+10 IF TTYP="sdoh"
QUIT "Social Determinants of Health"
+11 IF TTYP="ss"
QUIT "Suicide Scale"
+12 IF TTYP="ptsd-dx"
QUIT "PTSD-Diagnosis"
+13 IF TTYP="ptsd-e"
QUIT "PTSD-Expanded"
+14 IF TTYP="psy-c"
QUIT "Psychosis - Clinician"
+15 IF TTYP="psy-s"
QUIT "Psychosis - Self-Report"
+16 QUIT "Unknown Test"
+17 ;
INSNAME(TTYP) ; return full name for a CAT Test Type
+1 SET TTYP=$$LOW^XLFSTR(TTYP)
+2 IF TTYP="mdd"
QUIT "CAD-MDD"
+3 IF TTYP="dep"
QUIT "CAT-DEP"
+4 IF TTYP="anx"
QUIT "CAT-ANX"
+5 IF TTYP="m/hm"
QUIT "CAT-MANIA-HYPOMANIA"
+6 IF TTYP="sud"
QUIT "CAT-SUD"
+7 IF TTYP="sa"
QUIT "CAT-SUD"
+8 IF TTYP="ptsd"
QUIT "CAT-PTSD"
+9 IF TTYP="a/adhd"
QUIT "CAT-ADHD"
+10 IF TTYP="sdoh"
QUIT "CAT-SDOH"
+11 IF TTYP="ss"
QUIT "CAT-SS"
+12 IF TTYP="ptsd-dx"
QUIT "CAD-PTSD-DX"
+13 IF TTYP="ptsd-e"
QUIT "CAT-PTSD-E"
+14 IF TTYP="psy-c"
QUIT "CAT-PSYCHOSIS"
+15 IF TTYP="psy-s"
QUIT "CAT-PSYCHOSIS"
+16 QUIT "Unknown Test"
+17 ;
PAD(LEN,STR) ; return spaces until X is LEN
+1 NEW X
SET X=" "
+2 QUIT STR_$EXTRACT(X,1,LEN-$LENGTH(STR))
+3 ;
TMSTR(ATIME) ; return a readable elapsed time
+1 NEW MIN,SEC,X
+2 SET MIN=ATIME\60
+3 SET SEC=$PIECE(ATIME-(60*MIN)+0.5,".")
+4 SET X=""
+5 IF MIN
SET X=MIN_$SELECT(MIN=1:" minute ",1:" minutes ")
+6 SET X=X_SEC_$SELECT(SEC=1:" second",1:" seconds")
+7 QUIT X
+8 ;
WP2JSON(YSDATA,TREE) ; put YSDATA answer into M-subscript format
+1 NEW I,J,K,L,S,JSON
+2 SET I=2
SET K=0
FOR
SET I=$ORDER(YSDATA(I))
if 'I
QUIT
if $PIECE(YSDATA(I),U)'=8650
QUIT
Begin DoDot:1
+3 SET L=$PIECE(YSDATA(I),"^",3,99)
+4 FOR J=1:1:$LENGTH(L,"|")
SET S=$PIECE(L,"|",J)
IF $LENGTH(S)
SET K=K+1
SET JSON(K)=S
End DoDot:1
+5 DO DECODE^XLFJSON("JSON","TREE")
+6 QUIT
WRAP(IN,MAX,PRE) ; Return with | and spacing in correct place
+1 NEW X,I,J,TXT,WORD
+2 SET J=1
SET TXT(J)=PRE_$PIECE(IN," ")
+3 FOR I=2:1:$LENGTH(IN," ")
SET WORD=$PIECE(IN," ",I)
Begin DoDot:1
+4 IF ($LENGTH(TXT(J))+$LENGTH(WORD)+1)<MAX
SET TXT(J)=TXT(J)_" "_WORD
IF 1
+5 IF '$TEST
SET J=J+1
SET TXT(J)=PRE_WORD
End DoDot:1
+6 SET X=TXT(1)
SET I=1
FOR
SET I=$ORDER(TXT(I))
if 'I
QUIT
SET X=X_TXT(I)
+7 QUIT X
+8 ;
TXTPTSD ; Interpretive text for CAD-PTSD-DX
+1 ;;|| *The "Probability of PTSD" score, which ranges from 0 to 1, can be used
+2 ;;| as a measure of how confident you can be in the predicted diagnosis -
+3 ;;| e.g., 0.10 (very unlikely) . 0.50 (equivocal) . 0.90 (very likely).
+4 ;;| A mid-range score between 0.25-0.75 should be interpreted as somewhat
+5 ;;| equivocal, meaning that additional information is needed to make an
+6 ;;| accurate diagnosis; scores at either the low or high end of the range
+7 ;;| provide more confidence in the diagnosis presented.|
+8 ;;zzzzz