YTSPHQ9 ;SLC/KCM - Score PHQ9 ; 01/08/2016
;;5.01;MENTAL HEALTH;**141**;DEC 30,1994;Build 85
;
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 to YSDATA
I YSMODE=2 D REPORT(.YSDATA) 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
I $D(^TMP($J,"YSG",1)),^TMP($J,"YSG",1)="[ERROR]" D Q ;-->out
.K ^TMP($J,"YSCOR")
.S ^TMP($J,"YSCOR",1)="[ERROR]"
.S ^TMP($J,"YSCOR",2)="No Scale found for ADMIN"
;
N I,Q,C,S,V,T,E ; Q=question,C=choice,S=skips,V=value,T=total,E=error
S S=0,T=0,E=""
S I=2 F S I=$O(YSDATA(I)) Q:'I D
. S Q=$P(YSDATA(I),U) Q:Q=4019 ; q10 not part of score
. S C=$P(YSDATA(I),U,3)
. ; use choice ID's of 212, 1008, 1009, 1010 for scoring
. ; skipped questions are 1155, 1156, or 1157
. S V=$S(C=212:0,C=1008:1,C=1009:2,C=1010:3,C=1155!(C=1156)!(C=1157):"X",1:"?")
. S T=T+V S:V="X" S=S+1
; if 1 or 2 skipped questions, set their value to average and add to total
I S>0,(S<3) S V=T/(9-S) S T=T+(S*V) S T=+$P((T+0.5),".")
I S>2 S T="Due to missing Items, this administration cannot be scored."
I $L(E) S T="Due to unrecognized responses, this administration cannot be scored."
;
S S=$P(^YTT(601.87,419,0),U,4) ; 419 is PHQ9 Total scale
K ^TMP($J,"YSCOR")
S ^TMP($J,"YSCOR",1)="[DATA]"
S ^TMP($J,"YSCOR",2)=S_"="_T
Q
REPORT(YSDATA) ; return special question 9 text
; this was formerly handled in YTAPI2A
; Questions: 3382 = PHQ9 question #9
; Choices: 1008 = Several days, 1009 = More than half the days,
; 1010 = Nearly every day
N I,A
S A=0 ; A=answer
S I=2 F S I=$O(YSDATA(I)) Q:'I D Q:A
. I $P(YSDATA(I),U)=3382 S A=+$P(YSDATA(I),U,3) ; q9 is #3382
I A=1008!(A=1009)!(A=1010) D
. S I=$O(YSDATA(""),-1)+1
. S YSDATA(I)="7771^9999;1^Question 9 answered in the POSITIVE direction, additional clinical assessment is indicated."
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HYTSPHQ9 2407 printed Sep 02, 2024@19:05:43 Page 2
YTSPHQ9 ;SLC/KCM - Score PHQ9 ; 01/08/2016
+1 ;;5.01;MENTAL HEALTH;**141**;DEC 30,1994;Build 85
+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 to YSDATA
+10 IF YSMODE=2
DO REPORT(.YSDATA)
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 ;-->out
IF $DATA(^TMP($JOB,"YSG",1))
IF ^TMP($JOB,"YSG",1)="[ERROR]"
Begin DoDot:1
+5 KILL ^TMP($JOB,"YSCOR")
+6 SET ^TMP($JOB,"YSCOR",1)="[ERROR]"
+7 SET ^TMP($JOB,"YSCOR",2)="No Scale found for ADMIN"
End DoDot:1
QUIT
+8 ;
+9 ; Q=question,C=choice,S=skips,V=value,T=total,E=error
NEW I,Q,C,S,V,T,E
+10 SET S=0
SET T=0
SET E=""
+11 SET I=2
FOR
SET I=$ORDER(YSDATA(I))
if 'I
QUIT
Begin DoDot:1
+12 ; q10 not part of score
SET Q=$PIECE(YSDATA(I),U)
if Q=4019
QUIT
+13 SET C=$PIECE(YSDATA(I),U,3)
+14 ; use choice ID's of 212, 1008, 1009, 1010 for scoring
+15 ; skipped questions are 1155, 1156, or 1157
+16 SET V=$SELECT(C=212:0,C=1008:1,C=1009:2,C=1010:3,C=1155!(C=1156)!(C=1157):"X",1:"?")
+17 SET T=T+V
if V="X"
SET S=S+1
End DoDot:1
+18 ; if 1 or 2 skipped questions, set their value to average and add to total
+19 IF S>0
IF (S<3)
SET V=T/(9-S)
SET T=T+(S*V)
SET T=+$PIECE((T+0.5),".")
+20 IF S>2
SET T="Due to missing Items, this administration cannot be scored."
+21 IF $LENGTH(E)
SET T="Due to unrecognized responses, this administration cannot be scored."
+22 ;
+23 ; 419 is PHQ9 Total scale
SET S=$PIECE(^YTT(601.87,419,0),U,4)
+24 KILL ^TMP($JOB,"YSCOR")
+25 SET ^TMP($JOB,"YSCOR",1)="[DATA]"
+26 SET ^TMP($JOB,"YSCOR",2)=S_"="_T
+27 QUIT
REPORT(YSDATA) ; return special question 9 text
+1 ; this was formerly handled in YTAPI2A
+2 ; Questions: 3382 = PHQ9 question #9
+3 ; Choices: 1008 = Several days, 1009 = More than half the days,
+4 ; 1010 = Nearly every day
+5 NEW I,A
+6 ; A=answer
SET A=0
+7 SET I=2
FOR
SET I=$ORDER(YSDATA(I))
if 'I
QUIT
Begin DoDot:1
+8 ; q9 is #3382
IF $PIECE(YSDATA(I),U)=3382
SET A=+$PIECE(YSDATA(I),U,3)
End DoDot:1
if A
QUIT
+9 IF A=1008!(A=1009)!(A=1010)
Begin DoDot:1
+10 SET I=$ORDER(YSDATA(""),-1)+1
+11 SET YSDATA(I)="7771^9999;1^Question 9 answered in the POSITIVE direction, additional clinical assessment is indicated."
End DoDot:1
+12 QUIT