YTSMIDAS ;SLC/KCM - Score MIDAS ; 10/14/18 2:02pm
;;5.01;MENTAL HEALTH;**218**;Dec 30, 1994;Build 9
;
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 TXT,N
. D LDSCORES^YTSCORE(.YSDATA,.YS) ; puts score into ^TMP($J,"YSCOR",2)
. D REPORT(.TXT)
. S N=$O(YSDATA(""),-1) ; get last node
. S YSDATA(N+1)="7771^9999;1^"_TXT
Q
;
SCORESV ; calculate the score
; expects YSDATA from DLLSTR
N I,J,QSTN,VAL,TOTAL,SCLID,SCLNM
S TOTAL=0
S I=2 F S I=$O(YSDATA(I)) Q:'I D
. S QSTN=$P(YSDATA(I),U),VAL=$P(YSDATA(I),U,3)
. I VAL=1155!(VAL=1156)!(VAL=1157) Q ; don't include skipped questions
. ; only score the first five questions
. I ":8947:8948:8949:8950:8951:"[(":"_QSTN_":") S TOTAL=TOTAL+VAL
; 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 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=1480 S ^TMP($J,"YSCOR",J)=SCLNM_"="_TOTAL
Q
REPORT(TXT) ; build the scoring display for the report
; expects ^TMP($J,"YSCOR",...) and ^TMP($J,"YSG") from DLLSTR
; YSDATA from DLLSTR
; YSDATA(2+n)=questionId^sequence^choiceId or text response
N I,X,NAME,VALUE,TOTAL
S I=0 F S I=$O(^TMP($J,"YSCOR",I)) Q:'I D
. S NAME=$P(^TMP($J,"YSCOR",I),"=")
. S VALUE=$P(^TMP($J,"YSCOR",I),"=",2)
. I NAME="Total" S TOTAL=VALUE
I TOTAL<6 S TXT="I (Little or No Disability)"
I TOTAL>5,(TOTAL<11) S TXT="II (Mild Disability)"
I TOTAL>10,(TOTAL<21) S TXT="III (Moderate Disability)"
I TOTAL>20 S TXT="IV (Severe Disability)"
S TXT="| MIDAS Score "_TOTAL_"| MIDAS Grade "_TXT
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HYTSMIDAS 2231 printed Nov 22, 2024@17:30:06 Page 2
YTSMIDAS ;SLC/KCM - Score MIDAS ; 10/14/18 2:02pm
+1 ;;5.01;MENTAL HEALTH;**218**;Dec 30, 1994;Build 9
+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 TXT,N
+12 ; puts score into ^TMP($J,"YSCOR",2)
DO LDSCORES^YTSCORE(.YSDATA,.YS)
+13 DO REPORT(.TXT)
+14 ; get last node
SET N=$ORDER(YSDATA(""),-1)
+15 SET YSDATA(N+1)="7771^9999;1^"_TXT
End DoDot:1
+16 QUIT
+17 ;
SCORESV ; calculate the score
+1 ; expects YSDATA from DLLSTR
+2 NEW I,J,QSTN,VAL,TOTAL,SCLID,SCLNM
+3 SET TOTAL=0
+4 SET I=2
FOR
SET I=$ORDER(YSDATA(I))
if 'I
QUIT
Begin DoDot:1
+5 SET QSTN=$PIECE(YSDATA(I),U)
SET VAL=$PIECE(YSDATA(I),U,3)
+6 ; don't include skipped questions
IF VAL=1155!(VAL=1156)!(VAL=1157)
QUIT
+7 ; only score the first five questions
+8 IF ":8947:8948:8949:8950:8951:"[(":"_QSTN_":")
SET TOTAL=TOTAL+VAL
End DoDot:1
+9 ; set scores into ^TMP($J,"YSCOR",n)=scaleId=rawScore^tScore
+10 KILL ^TMP($JOB,"YSCOR")
+11 ;-->out
IF $DATA(^TMP($JOB,"YSG",1))
IF ^TMP($JOB,"YSG",1)="[ERROR]"
Begin DoDot:1
+12 SET ^TMP($JOB,"YSCOR",1)="[ERROR]"
+13 SET ^TMP($JOB,"YSCOR",2)="No Scale found for ADMIN"
End DoDot:1
QUIT
+14 ;
+15 SET ^TMP($JOB,"YSCOR",1)="[DATA]"
+16 SET I=2
SET J=1
FOR
SET I=$ORDER(^TMP($JOB,"YSG",I))
if 'I
QUIT
Begin DoDot:1
+17 SET SCLID=+$PIECE(^TMP($JOB,"YSG",I),"=",2)
+18 SET SCLNM=$PIECE(^TMP($JOB,"YSG",I),U,4)
+19 SET J=J+1
+20 IF SCLID=1480
SET ^TMP($JOB,"YSCOR",J)=SCLNM_"="_TOTAL
End DoDot:1
+21 QUIT
REPORT(TXT) ; build the scoring display for the report
+1 ; expects ^TMP($J,"YSCOR",...) and ^TMP($J,"YSG") from DLLSTR
+2 ; YSDATA from DLLSTR
+3 ; YSDATA(2+n)=questionId^sequence^choiceId or text response
+4 NEW I,X,NAME,VALUE,TOTAL
+5 SET I=0
FOR
SET I=$ORDER(^TMP($JOB,"YSCOR",I))
if 'I
QUIT
Begin DoDot:1
+6 SET NAME=$PIECE(^TMP($JOB,"YSCOR",I),"=")
+7 SET VALUE=$PIECE(^TMP($JOB,"YSCOR",I),"=",2)
+8 IF NAME="Total"
SET TOTAL=VALUE
End DoDot:1
+9 IF TOTAL<6
SET TXT="I (Little or No Disability)"
+10 IF TOTAL>5
IF (TOTAL<11)
SET TXT="II (Mild Disability)"
+11 IF TOTAL>10
IF (TOTAL<21)
SET TXT="III (Moderate Disability)"
+12 IF TOTAL>20
SET TXT="IV (Severe Disability)"
+13 SET TXT="| MIDAS Score "_TOTAL_"| MIDAS Grade "_TXT
+14 QUIT