YTSPEG ;BAL/KTL - Score PEG ; 3/25/22 2:02pm
;;5.01;MENTAL HEALTH;**234**;Dec 30, 1994;Build 38
;
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
Q
;
SCORESV ; calculate the score
; expects YSDATA from DLLSTR (YSDATA from LOADANSW^YTSCORE,SCALEG^YTQAPI3)
N I,J,CHOICE,SKPCNT,AVE,QUES,TOT
S (SKPCNT,AVE,TOT)=0
S I=2 F S I=$O(YSDATA(I)) Q:'I D
. S QUES=$P(YSDATA(I),U)
. S CHOICE=$P(YSDATA(I),U,3)
. I CHOICE=1155 S SKPCNT=SKPCNT+1 Q
. S TOT=TOT+CHOICE
I SKPCNT>0 S TOT=TOT*($S(SKPCNT=1:1.5,SKPCNT=2:3,1:1)) ; Estimated total if skipped questions
S AVE=$J(TOT/3,"",0) ;Whole number rounded average of answered questions
;
; 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=1502 S ^TMP($J,"YSCOR",J)=SCLNM_"="_AVE
Q
REPORT(SCORES) ; build the scoring display for the report
; expects ^TMP($J,"YSCOR",...) and ^TMP($J,"YSG") from DLLSTR
; YSDATA from DLLSTR
Q
N I,NAME,VAL
S SCORES="Negative"
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)
. I NAME="BIPOL" S SCORES=$S(+VAL=0:"Negative",1:"Positive")
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HYTSPEG 2070 printed Dec 13, 2024@02:20:31 Page 2
YTSPEG ;BAL/KTL - Score PEG ; 3/25/22 2:02pm
+1 ;;5.01;MENTAL HEALTH;**234**;Dec 30, 1994;Build 38
+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 ;S N=$O(YSDATA(""),-1) ; get last node
End DoDot:1
+15 QUIT
+16 ;
SCORESV ; calculate the score
+1 ; expects YSDATA from DLLSTR (YSDATA from LOADANSW^YTSCORE,SCALEG^YTQAPI3)
+2 NEW I,J,CHOICE,SKPCNT,AVE,QUES,TOT
+3 SET (SKPCNT,AVE,TOT)=0
+4 SET I=2
FOR
SET I=$ORDER(YSDATA(I))
if 'I
QUIT
Begin DoDot:1
+5 SET QUES=$PIECE(YSDATA(I),U)
+6 SET CHOICE=$PIECE(YSDATA(I),U,3)
+7 IF CHOICE=1155
SET SKPCNT=SKPCNT+1
QUIT
+8 SET TOT=TOT+CHOICE
End DoDot:1
+9 ; Estimated total if skipped questions
IF SKPCNT>0
SET TOT=TOT*($SELECT(SKPCNT=1:1.5,SKPCNT=2:3,1:1))
+10 ;Whole number rounded average of answered questions
SET AVE=$JUSTIFY(TOT/3,"",0)
+11 ;
+12 ; set scores into ^TMP($J,"YSCOR",n)=scaleName=score {rawScore^tScore}
+13 KILL ^TMP($JOB,"YSCOR")
+14 ;-->out
IF $DATA(^TMP($JOB,"YSG",1))
IF (^TMP($JOB,"YSG",1)="[ERROR]")
Begin DoDot:1
+15 SET ^TMP($JOB,"YSCOR",1)="[ERROR]"
+16 SET ^TMP($JOB,"YSCOR",2)="No Scale found for ADMIN"
End DoDot:1
QUIT
+17 ;
+18 NEW SCLID,SCLNM
+19 SET ^TMP($JOB,"YSCOR",1)="[DATA]"
+20 SET I=2
SET J=1
FOR
SET I=$ORDER(^TMP($JOB,"YSG",I))
if 'I
QUIT
Begin DoDot:1
+21 SET SCLID=+$PIECE(^TMP($JOB,"YSG",I),"=",2)
+22 SET SCLNM=$PIECE(^TMP($JOB,"YSG",I),U,4)
+23 SET J=J+1
+24 IF SCLID=1502
SET ^TMP($JOB,"YSCOR",J)=SCLNM_"="_AVE
End DoDot:1
+25 QUIT
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 QUIT
+4 NEW I,NAME,VAL
+5 SET SCORES="Negative"
+6 SET I=0
FOR
SET I=$ORDER(^TMP($JOB,"YSCOR",I))
if 'I
QUIT
Begin DoDot:1
+7 SET NAME=$EXTRACT($PIECE(^TMP($JOB,"YSCOR",I),"="),1,5)
+8 SET VAL=$PIECE(^TMP($JOB,"YSCOR",I),"=",2)
+9 IF NAME="BIPOL"
SET SCORES=$SELECT(+VAL=0:"Negative",1:"Positive")
End DoDot:1
+10 QUIT