YTSEHS14 ;SLC/KCM - Score EHS-14 ; 3/25/22 2:02pm
;;5.01;MENTAL HEALTH;**202**;Dec 30, 1994;Build 47
;
DLLSTR(YSDATA,YS,YSTRNG) ; compute scores or report text based on YSTRNG
; input
; YSDATA(2)=adminId^patientDFN^instrumentName^dateGiven^isComplete
; YSDATA(2+n)=questionId^sequence^choiceId
; YS("AD")=adminId
; YSTRNG=1 for score, 2 for report
; output if YSTRNG=1: ^TMP($J,"YSCOR",n)=scaleId=score
; output if YSTRNG=2: append special "answers" to YSDATA
;
I YSTRNG=1 D SCORESV
I YSTRNG=2 D
. N SCORES,N
. D LDSCORES^YTSCORE(.YSDATA,.YS) ; puts score into ^TMP($J,"YSCOR",2)
. D REPORT(.SCORES)
. S N=$O(YSDATA(""),-1) ; get last node
. S YSDATA(N+1)="7771^9999;1^"_SCORES
Q
;
SCORESV ; calculate the score
; expects YSDATA from DLLSTR (YSDATA from LOADANSW^YTSCORE,SCALEG^YTQAPI3)
N I,J,QSTN,TOTAL,EMPWR,MOTIV,UTIL,GOAL
S I=2 F S I=$O(YSDATA(I)) Q:'I D
. S QSTN($P(YSDATA(I),U))=$P(YSDATA(I),U,3)
S TOTAL=$$AVERAGE(.QSTN,8651,8664) ; Total
S EMPWR=$$AVERAGE(.QSTN,8651,8654) ; Psychological Empowerment
S MOTIV=$$AVERAGE(.QSTN,8655,8656) ; Futuristic self-motivation
S UTIL=$$AVERAGE(.QSTN,8657,8660) ; Utilization of skills and resources
S GOAL=$$AVERAGE(.QSTN,8661,8664) ; Goal orientation
;
; set scores into ^TMP($J,"YSCOR",n)=scaleName=score {rawScore^tScore}
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 SCLID,SCLNM
S ^TMP($J,"YSCOR",1)="[DATA]"
S I=2,J=1 F S I=$O(^TMP($J,"YSG",I)) Q:'I D
. S SCLID=+$P(^TMP($J,"YSG",I),"=",2)
. S SCLNM=$P(^TMP($J,"YSG",I),U,4)
. S J=J+1
. I SCLID=1425 S ^TMP($J,"YSCOR",J)=SCLNM_"="_TOTAL
. I SCLID=1426 S ^TMP($J,"YSCOR",J)=SCLNM_"="_EMPWR
. I SCLID=1427 S ^TMP($J,"YSCOR",J)=SCLNM_"="_MOTIV
. I SCLID=1428 S ^TMP($J,"YSCOR",J)=SCLNM_"="_UTIL
. I SCLID=1429 S ^TMP($J,"YSCOR",J)=SCLNM_"="_GOAL
Q
AVERAGE(QSTN,FIRST,LAST) ;
N QID,SUM,CNT
S (SUM,CNT)=0
F QID=FIRST:1:LAST D Q:SUM<0
. I '$D(QSTN(QID)) S SUM=-1 Q
. S CNT=CNT+1,SUM=SUM+QSTN(QID)
Q $S(SUM<0:-1,1:+$FN(SUM/CNT,"",2))
;
REPORT(SCORES) ; build the scoring display for the report
; expects ^TMP($J,"YSCOR",...) and ^TMP($J,"YSG") from DLLSTR
; YSDATA from DLLSTR
N I,X,NAME,VAL,TOTAL,EMPWR,MOTIV,UTIL,GOAL
S I=0 F S I=$O(^TMP($J,"YSCOR",I)) Q:'I D
. S NAME=$E($P(^TMP($J,"YSCOR",I),"="),1,5)
. S VAL=$P(^TMP($J,"YSCOR",I),"=",2)
. S VAL=$S(VAL<0:" Missing responses",1:$J(VAL,5,2))
. I NAME="Total" S TOTAL=VAL
. I NAME="Psych" S EMPWR=VAL
. I NAME="Futur" S MOTIV=VAL
. I NAME="Utili" S UTIL=VAL
. I NAME="Goal " S GOAL=VAL
S X=""
S X=X_"| EHS-14 total score:"_TOTAL
S X=X_"| Psychological empowerment:"_EMPWR
S X=X_"| Futuristic self-motivation:"_MOTIV
S X=X_"| Utilization of skills and resources:"_UTIL
S X=X_"| Goal orientation:"_GOAL
S SCORES=X
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HYTSEHS14 3023 printed Dec 13, 2024@02:19:46 Page 2
YTSEHS14 ;SLC/KCM - Score EHS-14 ; 3/25/22 2:02pm
+1 ;;5.01;MENTAL HEALTH;**202**;Dec 30, 1994;Build 47
+2 ;
DLLSTR(YSDATA,YS,YSTRNG) ; compute scores or report text based on YSTRNG
+1 ; input
+2 ; YSDATA(2)=adminId^patientDFN^instrumentName^dateGiven^isComplete
+3 ; YSDATA(2+n)=questionId^sequence^choiceId
+4 ; YS("AD")=adminId
+5 ; YSTRNG=1 for score, 2 for report
+6 ; output if YSTRNG=1: ^TMP($J,"YSCOR",n)=scaleId=score
+7 ; output if YSTRNG=2: append special "answers" to YSDATA
+8 ;
+9 IF YSTRNG=1
DO SCORESV
+10 IF YSTRNG=2
Begin DoDot:1
+11 NEW SCORES,N
+12 ; puts score into ^TMP($J,"YSCOR",2)
DO LDSCORES^YTSCORE(.YSDATA,.YS)
+13 DO REPORT(.SCORES)
+14 ; get last node
SET N=$ORDER(YSDATA(""),-1)
+15 SET YSDATA(N+1)="7771^9999;1^"_SCORES
End DoDot:1
+16 QUIT
+17 ;
SCORESV ; calculate the score
+1 ; expects YSDATA from DLLSTR (YSDATA from LOADANSW^YTSCORE,SCALEG^YTQAPI3)
+2 NEW I,J,QSTN,TOTAL,EMPWR,MOTIV,UTIL,GOAL
+3 SET I=2
FOR
SET I=$ORDER(YSDATA(I))
if 'I
QUIT
Begin DoDot:1
+4 SET QSTN($PIECE(YSDATA(I),U))=$PIECE(YSDATA(I),U,3)
End DoDot:1
+5 ; Total
SET TOTAL=$$AVERAGE(.QSTN,8651,8664)
+6 ; Psychological Empowerment
SET EMPWR=$$AVERAGE(.QSTN,8651,8654)
+7 ; Futuristic self-motivation
SET MOTIV=$$AVERAGE(.QSTN,8655,8656)
+8 ; Utilization of skills and resources
SET UTIL=$$AVERAGE(.QSTN,8657,8660)
+9 ; Goal orientation
SET GOAL=$$AVERAGE(.QSTN,8661,8664)
+10 ;
+11 ; set scores into ^TMP($J,"YSCOR",n)=scaleName=score {rawScore^tScore}
+12 KILL ^TMP($JOB,"YSCOR")
+13 ;-->out
IF $DATA(^TMP($JOB,"YSG",1))
IF ^TMP($JOB,"YSG",1)="[ERROR]"
Begin DoDot:1
+14 SET ^TMP($JOB,"YSCOR",1)="[ERROR]"
+15 SET ^TMP($JOB,"YSCOR",2)="No Scale found for ADMIN"
End DoDot:1
QUIT
+16 ;
+17 NEW SCLID,SCLNM
+18 SET ^TMP($JOB,"YSCOR",1)="[DATA]"
+19 SET I=2
SET J=1
FOR
SET I=$ORDER(^TMP($JOB,"YSG",I))
if 'I
QUIT
Begin DoDot:1
+20 SET SCLID=+$PIECE(^TMP($JOB,"YSG",I),"=",2)
+21 SET SCLNM=$PIECE(^TMP($JOB,"YSG",I),U,4)
+22 SET J=J+1
+23 IF SCLID=1425
SET ^TMP($JOB,"YSCOR",J)=SCLNM_"="_TOTAL
+24 IF SCLID=1426
SET ^TMP($JOB,"YSCOR",J)=SCLNM_"="_EMPWR
+25 IF SCLID=1427
SET ^TMP($JOB,"YSCOR",J)=SCLNM_"="_MOTIV
+26 IF SCLID=1428
SET ^TMP($JOB,"YSCOR",J)=SCLNM_"="_UTIL
+27 IF SCLID=1429
SET ^TMP($JOB,"YSCOR",J)=SCLNM_"="_GOAL
End DoDot:1
+28 QUIT
AVERAGE(QSTN,FIRST,LAST) ;
+1 NEW QID,SUM,CNT
+2 SET (SUM,CNT)=0
+3 FOR QID=FIRST:1:LAST
Begin DoDot:1
+4 IF '$DATA(QSTN(QID))
SET SUM=-1
QUIT
+5 SET CNT=CNT+1
SET SUM=SUM+QSTN(QID)
End DoDot:1
if SUM<0
QUIT
+6 QUIT $SELECT(SUM<0:-1,1:+$FNUMBER(SUM/CNT,"",2))
+7 ;
REPORT(SCORES) ; build the scoring display for the report
+1 ; expects ^TMP($J,"YSCOR",...) and ^TMP($J,"YSG") from DLLSTR
+2 ; YSDATA from DLLSTR
+3 NEW I,X,NAME,VAL,TOTAL,EMPWR,MOTIV,UTIL,GOAL
+4 SET I=0
FOR
SET I=$ORDER(^TMP($JOB,"YSCOR",I))
if 'I
QUIT
Begin DoDot:1
+5 SET NAME=$EXTRACT($PIECE(^TMP($JOB,"YSCOR",I),"="),1,5)
+6 SET VAL=$PIECE(^TMP($JOB,"YSCOR",I),"=",2)
+7 SET VAL=$SELECT(VAL<0:" Missing responses",1:$JUSTIFY(VAL,5,2))
+8 IF NAME="Total"
SET TOTAL=VAL
+9 IF NAME="Psych"
SET EMPWR=VAL
+10 IF NAME="Futur"
SET MOTIV=VAL
+11 IF NAME="Utili"
SET UTIL=VAL
+12 IF NAME="Goal "
SET GOAL=VAL
End DoDot:1
+13 SET X=""
+14 SET X=X_"| EHS-14 total score:"_TOTAL
+15 SET X=X_"| Psychological empowerment:"_EMPWR
+16 SET X=X_"| Futuristic self-motivation:"_MOTIV
+17 SET X=X_"| Utilization of skills and resources:"_UTIL
+18 SET X=X_"| Goal orientation:"_GOAL
+19 SET SCORES=X
+20 QUIT