YTSPEB27 ;SLC/KCM - Score PEBS-27 ; 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,ALL,TOTAL,HEALTH,LABOR,CHILD,HUMAN,SKILL
S I=2 F S I=$O(YSDATA(I)) Q:'I D
. S QSTN($P(YSDATA(I),U))=$P(YSDATA(I),U,3)
S ALL="8674,8675,8676,8677,8679,8680,8681,8670,8682,8683,8665,8666,8667,8668,8672,8686,8687,8688,8689,8690"
S TOTAL=$$AVERAGE(.QSTN,ALL)
S HEALTH=$$AVERAGE(.QSTN,"8674,8675,8676,8677")
S LABOR=$$AVERAGE(.QSTN,"8679,8680,8681")
S CHILD=$$AVERAGE(.QSTN,"8670,8682,8683")
S HUMAN=$$AVERAGE(.QSTN,"8665,8666,8667,8668,8672")
S SKILL=$$AVERAGE(.QSTN,"8686,8687,8688,8689,8690")
;
; 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=1430 S ^TMP($J,"YSCOR",J)=SCLNM_"="_TOTAL
. I SCLID=1431 S ^TMP($J,"YSCOR",J)=SCLNM_"="_HEALTH
. I SCLID=1432 S ^TMP($J,"YSCOR",J)=SCLNM_"="_LABOR
. I SCLID=1433 S ^TMP($J,"YSCOR",J)=SCLNM_"="_CHILD
. I SCLID=1434 S ^TMP($J,"YSCOR",J)=SCLNM_"="_HUMAN
. I SCLID=1435 S ^TMP($J,"YSCOR",J)=SCLNM_"="_SKILL
Q
AVERAGE(QSTN,LIST) ; return average value for questions in LIST
N I,QID,SUM,CNT
S (SUM,CNT)=0
F I=1:1:$L(LIST,",") S QID=$P(LIST,",",I) 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,HEALTH,LABOR,CHILD,HUMAN,SKILL
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="Physi" S HEALTH=VAL
. I NAME="Labor" S LABOR=VAL
. I NAME="Child" S CHILD=VAL
. I NAME="Human" S HUMAN=VAL
. I NAME="Soft " S SKILL=VAL
S X=""
S X=X_"| PEBS-27 total score:"_TOTAL
S X=X_"| Physical & mental health:"_HEALTH
S X=X_"| Labor market exclusion:"_LABOR
S X=X_"| Child Care:"_CHILD
S X=X_"| Human Capital:"_HUMAN
S X=X_"| Soft Skills:"_SKILL
S SCORES=X
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HYTSPEB27 3266 printed Dec 13, 2024@02:20:30 Page 2
YTSPEB27 ;SLC/KCM - Score PEBS-27 ; 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,ALL,TOTAL,HEALTH,LABOR,CHILD,HUMAN,SKILL
+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 SET ALL="8674,8675,8676,8677,8679,8680,8681,8670,8682,8683,8665,8666,8667,8668,8672,8686,8687,8688,8689,8690"
+6 SET TOTAL=$$AVERAGE(.QSTN,ALL)
+7 SET HEALTH=$$AVERAGE(.QSTN,"8674,8675,8676,8677")
+8 SET LABOR=$$AVERAGE(.QSTN,"8679,8680,8681")
+9 SET CHILD=$$AVERAGE(.QSTN,"8670,8682,8683")
+10 SET HUMAN=$$AVERAGE(.QSTN,"8665,8666,8667,8668,8672")
+11 SET SKILL=$$AVERAGE(.QSTN,"8686,8687,8688,8689,8690")
+12 ;
+13 ; set scores into ^TMP($J,"YSCOR",n)=scaleName=score {rawScore^tScore}
+14 KILL ^TMP($JOB,"YSCOR")
+15 ;-->out
IF $DATA(^TMP($JOB,"YSG",1))
IF ^TMP($JOB,"YSG",1)="[ERROR]"
Begin DoDot:1
+16 SET ^TMP($JOB,"YSCOR",1)="[ERROR]"
+17 SET ^TMP($JOB,"YSCOR",2)="No Scale found for ADMIN"
End DoDot:1
QUIT
+18 ;
+19 NEW SCLID,SCLNM
+20 SET ^TMP($JOB,"YSCOR",1)="[DATA]"
+21 SET I=2
SET J=1
FOR
SET I=$ORDER(^TMP($JOB,"YSG",I))
if 'I
QUIT
Begin DoDot:1
+22 SET SCLID=+$PIECE(^TMP($JOB,"YSG",I),"=",2)
+23 SET SCLNM=$PIECE(^TMP($JOB,"YSG",I),U,4)
+24 SET J=J+1
+25 IF SCLID=1430
SET ^TMP($JOB,"YSCOR",J)=SCLNM_"="_TOTAL
+26 IF SCLID=1431
SET ^TMP($JOB,"YSCOR",J)=SCLNM_"="_HEALTH
+27 IF SCLID=1432
SET ^TMP($JOB,"YSCOR",J)=SCLNM_"="_LABOR
+28 IF SCLID=1433
SET ^TMP($JOB,"YSCOR",J)=SCLNM_"="_CHILD
+29 IF SCLID=1434
SET ^TMP($JOB,"YSCOR",J)=SCLNM_"="_HUMAN
+30 IF SCLID=1435
SET ^TMP($JOB,"YSCOR",J)=SCLNM_"="_SKILL
End DoDot:1
+31 QUIT
AVERAGE(QSTN,LIST) ; return average value for questions in LIST
+1 NEW I,QID,SUM,CNT
+2 SET (SUM,CNT)=0
+3 FOR I=1:1:$LENGTH(LIST,",")
SET QID=$PIECE(LIST,",",I)
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,HEALTH,LABOR,CHILD,HUMAN,SKILL
+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="Physi"
SET HEALTH=VAL
+10 IF NAME="Labor"
SET LABOR=VAL
+11 IF NAME="Child"
SET CHILD=VAL
+12 IF NAME="Human"
SET HUMAN=VAL
+13 IF NAME="Soft "
SET SKILL=VAL
End DoDot:1
+14 SET X=""
+15 SET X=X_"| PEBS-27 total score:"_TOTAL
+16 SET X=X_"| Physical & mental health:"_HEALTH
+17 SET X=X_"| Labor market exclusion:"_LABOR
+18 SET X=X_"| Child Care:"_CHILD
+19 SET X=X_"| Human Capital:"_HUMAN
+20 SET X=X_"| Soft Skills:"_SKILL
+21 SET SCORES=X
+22 QUIT