YTSNPIQ ;SLC/KCM - Reporting logic for NPI-Q ; 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 BYKEY^YTSCORE(.YSDATA) ; just use "regular" scoring
I YSTRNG=2 D
. N SUMMARY,LN,SCORES
. D LDSCORES^YTSCORE(.YSDATA,.YS) ; puts scores into ^TMP($J,"YSCOR")
. D BLDSCR(.SCORES)
. D REPORT(.SUMMARY,.SCORES)
. S LN=$O(YSDATA(""),-1) ; get last node
. S YSDATA(LN+1)="7771^9999;1^"_SUMMARY
Q
;
REPORT(SUMMARY,SCORES) ; build .SCORE string
; expects YSDATA for answers
N QSTN,X
D BLDQSTN(.QSTN)
S X=""
S X=X_$$MKLN("|","Symptom","","Caregiver")
S X=X_$$MKLN("|","Present","Severity","Distress")
S X=X_"|--------------------------------------------------------"
S X=X_$$MKLN("|Delusions",QSTN(9176),QSTN(9177),QSTN(9178))
S X=X_$$MKLN("|Hallucinations",QSTN(9179),QSTN(9180),QSTN(9181))
S X=X_$$MKLN("|Agitation/Aggression",QSTN(9182),QSTN(9183),QSTN(9184))
S X=X_$$MKLN("|Depression/Dysphoria",QSTN(9185),QSTN(9186),QSTN(9187))
S X=X_$$MKLN("|Anxiety",QSTN(9188),QSTN(9189),QSTN(9190))
S X=X_$$MKLN("|Elation/Euphoria",QSTN(9191),QSTN(9192),QSTN(9193))
S X=X_$$MKLN("|Apathy/Indifference",QSTN(9194),QSTN(9195),QSTN(9196))
S X=X_$$MKLN("|Disinhibition",QSTN(9197),QSTN(9198),QSTN(9199))
S X=X_$$MKLN("|Irritability/Lability",QSTN(9200),QSTN(9201),QSTN(9202))
S X=X_$$MKLN("|Motor Disturbance",QSTN(9203),QSTN(9204),QSTN(9205))
S X=X_$$MKLN("|Nighttime Behaviors",QSTN(9206),QSTN(9207),QSTN(9208))
S X=X_$$MKLN("|Appetite/Eating",QSTN(9209),QSTN(9210),QSTN(9211))
S X=X_"|"
S X=X_$$MKLN("| TOTAL",SCORES("Symptoms"),SCORES("Severity"),SCORES("Distress"))
S SUMMARY=X
Q
MKLN(SYM,PRES,SEV,DIS) ; return a summary line
N LN,SPACES
S LN="",SPACES=" "
I PRES="No" S SEV="",DIS=""
S LN=LN_SYM_$E(SPACES,1,25-$L(SYM))
S LN=LN_PRES_$E(SPACES,1,10-$L(PRES))
S LN=LN_SEV_$E(SPACES,1,11-$L(SEV))
S LN=LN_DIS
Q LN
;
BLDQSTN(QSTN) ; build list of questions and response values in .QSTN
; expects YSDATA,YSTRNG from DLLSTR
N I,CID,QID,VAL
S I=2 F S I=$O(YSDATA(I)) Q:'I D
. S CID=$P(YSDATA(I),U,3),QID=$P(YSDATA(I),U),VAL="?"
. ; check the symptom selections
. I (QID=9176)!(QID=9179)!(QID=9182)!(QID=9185)!(QID=9188)!(QID=9191)!(QID=9194)!(QID=9197)!(QID=9200)!(QID=9203)!(QID=9206)!(QID=9209) D
. . I CID=1155!(CID=1156)!(CID=1157) S VAL="SKIP"
. . I CID=5690 S VAL="Yes"
. . I CID=5691 S VAL="No"
. E D
. . ; check the severity, distress selections
. . I CID=1155!(CID=1156)!(CID=1157) S VAL=""
. . I CID=5692 S VAL="Mild"
. . I CID=5693 S VAL="Moderate"
. . I CID=5694 S VAL="Severe"
. . I CID=5695 S VAL="Not distressing"
. . I CID=5696 S VAL="Minimal"
. . I CID=5697 S VAL="Mild"
. . I CID=5698 S VAL="Moderate"
. . I CID=5699 S VAL="Severe"
. . I CID=5700 S VAL="Extreme"
. S QSTN(QID)=VAL
Q
BLDSCR(SCORES) ; build array of .SCORES
; expects ^TMP($J,"YSCOR") from DLLSTR
N I,NAME,VALUE
S SCORES("Symptoms")=""
S SCORES("Severity")=""
S SCORES("Distress")=""
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="Symptoms" S SCORES("Symptoms")=VALUE
. I NAME="Severity" S SCORES("Severity")=VALUE
. I NAME="Distress" S SCORES("Distress")=VALUE
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HYTSNPIQ 3734 printed Dec 13, 2024@02:20:27 Page 2
YTSNPIQ ;SLC/KCM - Reporting logic for NPI-Q ; 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 ; just use "regular" scoring
IF YSTRNG=1
DO BYKEY^YTSCORE(.YSDATA)
+10 IF YSTRNG=2
Begin DoDot:1
+11 NEW SUMMARY,LN,SCORES
+12 ; puts scores into ^TMP($J,"YSCOR")
DO LDSCORES^YTSCORE(.YSDATA,.YS)
+13 DO BLDSCR(.SCORES)
+14 DO REPORT(.SUMMARY,.SCORES)
+15 ; get last node
SET LN=$ORDER(YSDATA(""),-1)
+16 SET YSDATA(LN+1)="7771^9999;1^"_SUMMARY
End DoDot:1
+17 QUIT
+18 ;
REPORT(SUMMARY,SCORES) ; build .SCORE string
+1 ; expects YSDATA for answers
+2 NEW QSTN,X
+3 DO BLDQSTN(.QSTN)
+4 SET X=""
+5 SET X=X_$$MKLN("|","Symptom","","Caregiver")
+6 SET X=X_$$MKLN("|","Present","Severity","Distress")
+7 SET X=X_"|--------------------------------------------------------"
+8 SET X=X_$$MKLN("|Delusions",QSTN(9176),QSTN(9177),QSTN(9178))
+9 SET X=X_$$MKLN("|Hallucinations",QSTN(9179),QSTN(9180),QSTN(9181))
+10 SET X=X_$$MKLN("|Agitation/Aggression",QSTN(9182),QSTN(9183),QSTN(9184))
+11 SET X=X_$$MKLN("|Depression/Dysphoria",QSTN(9185),QSTN(9186),QSTN(9187))
+12 SET X=X_$$MKLN("|Anxiety",QSTN(9188),QSTN(9189),QSTN(9190))
+13 SET X=X_$$MKLN("|Elation/Euphoria",QSTN(9191),QSTN(9192),QSTN(9193))
+14 SET X=X_$$MKLN("|Apathy/Indifference",QSTN(9194),QSTN(9195),QSTN(9196))
+15 SET X=X_$$MKLN("|Disinhibition",QSTN(9197),QSTN(9198),QSTN(9199))
+16 SET X=X_$$MKLN("|Irritability/Lability",QSTN(9200),QSTN(9201),QSTN(9202))
+17 SET X=X_$$MKLN("|Motor Disturbance",QSTN(9203),QSTN(9204),QSTN(9205))
+18 SET X=X_$$MKLN("|Nighttime Behaviors",QSTN(9206),QSTN(9207),QSTN(9208))
+19 SET X=X_$$MKLN("|Appetite/Eating",QSTN(9209),QSTN(9210),QSTN(9211))
+20 SET X=X_"|"
+21 SET X=X_$$MKLN("| TOTAL",SCORES("Symptoms"),SCORES("Severity"),SCORES("Distress"))
+22 SET SUMMARY=X
+23 QUIT
MKLN(SYM,PRES,SEV,DIS) ; return a summary line
+1 NEW LN,SPACES
+2 SET LN=""
SET SPACES=" "
+3 IF PRES="No"
SET SEV=""
SET DIS=""
+4 SET LN=LN_SYM_$EXTRACT(SPACES,1,25-$LENGTH(SYM))
+5 SET LN=LN_PRES_$EXTRACT(SPACES,1,10-$LENGTH(PRES))
+6 SET LN=LN_SEV_$EXTRACT(SPACES,1,11-$LENGTH(SEV))
+7 SET LN=LN_DIS
+8 QUIT LN
+9 ;
BLDQSTN(QSTN) ; build list of questions and response values in .QSTN
+1 ; expects YSDATA,YSTRNG from DLLSTR
+2 NEW I,CID,QID,VAL
+3 SET I=2
FOR
SET I=$ORDER(YSDATA(I))
if 'I
QUIT
Begin DoDot:1
+4 SET CID=$PIECE(YSDATA(I),U,3)
SET QID=$PIECE(YSDATA(I),U)
SET VAL="?"
+5 ; check the symptom selections
+6 IF (QID=9176)!(QID=9179)!(QID=9182)!(QID=9185)!(QID=9188)!(QID=9191)!(QID=9194)!(QID=9197)!(QID=9200)!(QID=9203)!(QID=9206)!(QID=9209)
Begin DoDot:2
+7 IF CID=1155!(CID=1156)!(CID=1157)
SET VAL="SKIP"
+8 IF CID=5690
SET VAL="Yes"
+9 IF CID=5691
SET VAL="No"
End DoDot:2
+10 IF '$TEST
Begin DoDot:2
+11 ; check the severity, distress selections
+12 IF CID=1155!(CID=1156)!(CID=1157)
SET VAL=""
+13 IF CID=5692
SET VAL="Mild"
+14 IF CID=5693
SET VAL="Moderate"
+15 IF CID=5694
SET VAL="Severe"
+16 IF CID=5695
SET VAL="Not distressing"
+17 IF CID=5696
SET VAL="Minimal"
+18 IF CID=5697
SET VAL="Mild"
+19 IF CID=5698
SET VAL="Moderate"
+20 IF CID=5699
SET VAL="Severe"
+21 IF CID=5700
SET VAL="Extreme"
End DoDot:2
+22 SET QSTN(QID)=VAL
End DoDot:1
+23 QUIT
BLDSCR(SCORES) ; build array of .SCORES
+1 ; expects ^TMP($J,"YSCOR") from DLLSTR
+2 NEW I,NAME,VALUE
+3 SET SCORES("Symptoms")=""
+4 SET SCORES("Severity")=""
+5 SET SCORES("Distress")=""
+6 SET I=0
FOR
SET I=$ORDER(^TMP($JOB,"YSCOR",I))
if 'I
QUIT
Begin DoDot:1
+7 SET NAME=$PIECE(^TMP($JOB,"YSCOR",I),"=")
+8 SET VALUE=$PIECE(^TMP($JOB,"YSCOR",I),"=",2)
+9 IF NAME="Symptoms"
SET SCORES("Symptoms")=VALUE
+10 IF NAME="Severity"
SET SCORES("Severity")=VALUE
+11 IF NAME="Distress"
SET SCORES("Distress")=VALUE
End DoDot:1
+12 QUIT