YTSYMRS ;BAL/KTL - Score YMRS ; 10/14/18 2:02pm
;;5.01;MENTAL HEALTH;**249**;Dec 30, 1994;Build 30
;
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 SCOREVAL,LEVEL,N
. D LDSCORES^YTSCORE(.YSDATA,.YS) ; puts score into ^TMP($J,"YSCOR",2)
. D REPORT(.YSDATA) ;Get numerical answer values for report questions
Q
;
SCORESV ; calculate the score
; expects YSDATA from DLLSTR
N YTI,YTRAW,YTCNT,YTCHC,SCORE
S YTRAW=0,YTCNT=0
S YTI=2 F S YTI=$O(YSDATA(YTI)) Q:'YTI D
. S YTCHC=$P(YSDATA(YTI),U,3)
. I (YTCHC=1155)!(YTCHC=1156)!(YTCHC=1157) Q ; N/A or skipped
. S YTCNT=YTCNT+1
. S YTRAW=YTRAW+$P(^YTT(601.75,YTCHC,0),U,2)
I YTCNT=0 S SCORE="" I 1 ; everything skipped or N/A
E S SCORE=YTRAW
;
; set scores into ^TMP($J,"YSCOR",n)=scaleId=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"
S ^TMP($J,"YSCOR",1)="[DATA]"
S ^TMP($J,"YSCOR",2)=$P(^YTT(601.87,1580,0),U,4)_"="_SCORE
Q
REPORT(YSDATA) ; build the numerical answer array for the report
; expects ^TMP($J,"YSCOR",...) and ^TMP($J,"YSG") from DLLSTR
; YSDATA from DLLSTR
; Question IEN = 9396-9406
; Answer array = 7771-7781
N YTI,YTRAW,YTCNT,YTCHC,YTQUE,YTANS,N,TMPYS
S N=$O(YSDATA(""),-1) ; get last node
S YTRAW=0,YTCNT=0
S YTI=2 F S YTI=$O(YSDATA(YTI)) Q:'YTI D
. S YTQUE=$P(YSDATA(YTI),U)
. S YTCHC=$P(YSDATA(YTI),U,3)
. S YTANS=YTQUE-1625 ;e.g. 9396-1625=7771
. I (YTCHC=1155)!(YTCHC=1156)!(YTCHC=1157) D Q ; N/A or skipped
.. S N=N+1,TMPYS(N)=YTANS_"^9999;1^"_$S(YTCHC=1155:"Skipped",YTCHC=1156:"Not asked (due to responses on other questions)",1:"Missing")
. S N=N+1,TMPYS(N)=YTANS_"^9999;1^"_$P(^YTT(601.75,YTCHC,0),U,2)
M YSDATA=TMPYS
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HYTSYMRS 2211 printed Dec 13, 2024@02:21:55 Page 2
YTSYMRS ;BAL/KTL - Score YMRS ; 10/14/18 2:02pm
+1 ;;5.01;MENTAL HEALTH;**249**;Dec 30, 1994;Build 30
+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 SCOREVAL,LEVEL,N
+12 ; puts score into ^TMP($J,"YSCOR",2)
DO LDSCORES^YTSCORE(.YSDATA,.YS)
+13 ;Get numerical answer values for report questions
DO REPORT(.YSDATA)
End DoDot:1
+14 QUIT
+15 ;
SCORESV ; calculate the score
+1 ; expects YSDATA from DLLSTR
+2 NEW YTI,YTRAW,YTCNT,YTCHC,SCORE
+3 SET YTRAW=0
SET YTCNT=0
+4 SET YTI=2
FOR
SET YTI=$ORDER(YSDATA(YTI))
if 'YTI
QUIT
Begin DoDot:1
+5 SET YTCHC=$PIECE(YSDATA(YTI),U,3)
+6 ; N/A or skipped
IF (YTCHC=1155)!(YTCHC=1156)!(YTCHC=1157)
QUIT
+7 SET YTCNT=YTCNT+1
+8 SET YTRAW=YTRAW+$PIECE(^YTT(601.75,YTCHC,0),U,2)
End DoDot:1
+9 ; everything skipped or N/A
IF YTCNT=0
SET SCORE=""
IF 1
+10 IF '$TEST
SET SCORE=YTRAW
+11 ;
+12 ; set scores into ^TMP($J,"YSCOR",n)=scaleId=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 SET ^TMP($JOB,"YSCOR",1)="[DATA]"
+18 SET ^TMP($JOB,"YSCOR",2)=$PIECE(^YTT(601.87,1580,0),U,4)_"="_SCORE
+19 QUIT
REPORT(YSDATA) ; build the numerical answer array for the report
+1 ; expects ^TMP($J,"YSCOR",...) and ^TMP($J,"YSG") from DLLSTR
+2 ; YSDATA from DLLSTR
+3 ; Question IEN = 9396-9406
+4 ; Answer array = 7771-7781
+5 NEW YTI,YTRAW,YTCNT,YTCHC,YTQUE,YTANS,N,TMPYS
+6 ; get last node
SET N=$ORDER(YSDATA(""),-1)
+7 SET YTRAW=0
SET YTCNT=0
+8 SET YTI=2
FOR
SET YTI=$ORDER(YSDATA(YTI))
if 'YTI
QUIT
Begin DoDot:1
+9 SET YTQUE=$PIECE(YSDATA(YTI),U)
+10 SET YTCHC=$PIECE(YSDATA(YTI),U,3)
+11 ;e.g. 9396-1625=7771
SET YTANS=YTQUE-1625
+12 ; N/A or skipped
IF (YTCHC=1155)!(YTCHC=1156)!(YTCHC=1157)
Begin DoDot:2
+13 SET N=N+1
SET TMPYS(N)=YTANS_"^9999;1^"_$SELECT(YTCHC=1155:"Skipped",YTCHC=1156:"Not asked (due to responses on other questions)",1:"Missing")
End DoDot:2
QUIT
+14 SET N=N+1
SET TMPYS(N)=YTANS_"^9999;1^"_$PIECE(^YTT(601.75,YTCHC,0),U,2)
End DoDot:1
+15 MERGE YSDATA=TMPYS
+16 QUIT