Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: YTSMCMIA

YTSMCMIA.m

Go to the documentation of this file.
YTSMCMIA ;BAL/KTL - Extension of YTSMCMI4 MHA ANSWERS SPECIAL HANDLING ; 9/14/18 3:19pm
 ;;5.01;MENTAL HEALTH;**151,187,217**;Dec 30, 1994;Build 12
 ;
 ; MCMI4 Scoring
 ;
 ; Handle initial scoring and saving of administration
 ; Invoked from DATA1^YTSMCMI4 when YSTRING=1
 D ADDRSL  ;Add the MH Score Keys for each scale
 D CALW
 D BR      ;Get the Base Rate Score
 D BRADJ1  ;Do the first Adjustment to the Base Rate
 D BRADJ2  ;Do second Adjustment to the Base Rate
 D PR      ;Get the Percentile Ranking
 D SCORESV
 Q
ADDRSL  ;Add up the related scored answers for each scale
 N LINE,TEXT,NXTQUES,XI
 F LINE=1:1 S TEXT=$P($T(SCOREDAT+LINE),";",2) Q:TEXT="QUIT"  D
 .N SCALE,RAWTYPE,SCLRAW,QUESTIONS,I,SNAM,RVAL,ADVAL,NXTLIN,NXTSCL
 .S SCLRAW=$P(TEXT,"|",1,2),SCALE=$P(TEXT,"|",1) S RAWTYPE=$P(TEXT,"|",2) S QUESTIONS=$P(TEXT,"|",3)
 .S NXTLIN=$P($T(SCOREDAT+LINE+1),";",2)  ;For lines with too many questions, split into two $T lines
 .S NXTSCL=$P(NXTLIN,"|",1,2)
 .I NXTSCL=SCLRAW D
 ..S NXTQUES=$P(NXTLIN,"|",3)
 ..S QUESTIONS=QUESTIONS_"^"_NXTQUES
 ..S LINE=LINE+1
 .S SNAM=$$GET1^DIQ(601.87,SCALE_",",3,"I")
 .S RVAL=$P(RAWTYPE,"_"),ADVAL=$P(RAWTYPE,"_",2)
 .F XI=1:1:$L(QUESTIONS,U) D
 ..N NODE,DATA,RAW
 ..S NODE=$P(QUESTIONS,U,XI)+2 ;YSDATA question nodes start at 3
 ..S DATA=YSDATA(NODE)
 ..S RAW=$$GET1^DIQ(601.75,$P($G(DATA),U,3)_",",4,"I")
 ..;retrieval method section. For each RAWTYPE assign a value to RAW
 ..;typical case, YSDATA piece 3 has the MH CHOICE IEN and raw value is in LEGACY field
 ..; For MCMI4 exception where additive value depends on the scale. 
 ..; Therefore additive value defined in table as second "_" piece of the RAWTYPE
 ..; First "_" piece is the legacy value of MH CHOICE - 1=True 2=False
 ..I RAW=RVAL S YSRAWRSL(SNAM)=$G(YSRAWRSL(SNAM))+ADVAL
 .I '$D(YSRAWRSL(SNAM)) S YSRAWRSL(SNAM)=0
 Q
 N I,SNAM,TOT,MHK,QUES,TAR,VAL,ANS
 K YSRAWRSL
 F I=1140:1:1143,1145:1:1169,1240:1:1284 D  ;1142 VS 1143?
 .S SNAM=$$GET1^DIQ(601.87,I_",",3,"I")
 .S TOT=0
 .S MHK=0 F  S MHK=$O(^YTT(601.91,"AC",I,MHK)) Q:+MHK=0  D
 ..S QUES=$$GET1^DIQ(601.91,MHK_",",2,"I")
 ..S TAR=$$GET1^DIQ(601.91,MHK_",",3,"I")
 ..S VAL=$$GET1^DIQ(601.91,MHK_",",4,"I")
 ..S ANS=$G(YSQANS2(QUES)),ANS=$S(ANS=1:"True",ANS=2:"False",1:"")
 ..I ANS=TAR S TOT=TOT+VAL
 .;Save each scale in the YSRAWRSL(scalnam) array which is the format
 .;the calculations expect them to be in.
 .S YSRAWRSL(SNAM)=TOT
 Q
SCOREDAT ;SCALE IEN|RAW VALUE STORAGE TYPE|QUES#^QUES#...
 ;1140|1_1|2^4^5^6^8^9^10^11^12^15^16^17^19^20^21^22^23^24^26^29^30^32^35^36^37^38^39^42^43^46^48^50^51^52^53^54^59^60^63^65^66^67^70^71^72^73^74^75^77^79^82^83^84^85^87^88^90^92^93^96^97^99^100^103^105^106^109^111^112^115^117^119^120
 ;1140|1_1|122^126^128^129^132^133^135^137^139^140^141^142^145^147^149^152^154^155^156^158^159^162^164^166^167^168^169^170^171^172^173^174^175^178^179^180^183^184^185^187^188^189^190^191^192^193^194^195
 ;1141|2_1|65^71^90^99^159^162^187
 ;1141|1_1|2^3^8^20^30^46^67^73^75^84^154^155^158^173^174^185^188
 ;1142|1_1|1^14^16^17^18^22^28^31^32^34^37^39^41^44^51^64^74^78^80^101^107^109^112^113^120^151^164^170^178^193
 ;1143|1_1|49^98^160
 ;1145|2_1|30^154
 ;1145|1_1|17^24^70^92^190
 ;1145|1_2|6^15^43^90^119^139^149^180
 ;1146|2_1|46^67^154
 ;1146|1_1|23^24^52^92^93^112^178^184^193
 ;1146|1_2|5^12^26^99^135^195
 ;1147|2_1|53
 ;1147|1_1|17^22^39^59^70^90^126^170^178
 ;1147|1_2|23^51^71^93^111^169^175^184^193
 ;1148|2_1|67
 ;1148|1_1|5^23^72^175
 ;1148|1_2|4^42^60^77^109^133^162^173^194
 ;1149|2_1|6^15^24^26^139^178^195
 ;1149|1_1|8^75^155
 ;1149|1_2|10^30^46^84^117^154^171
 ;1150|2_1|26^120^178
 ;1150|1_1|30^46^67^84^142^154
 ;1150|1_2|8^20^53^75^129^155^174^185
 ;1151|1_1|10^19^83^117^171^191
 ;1151|1_2|29^38^54^67^87^106^132^142^159^189
 ;1152|2_1|48^158
 ;1152|1_1|36^38^105^152^159
 ;1152|1_2|11^19^65^83^147^183^191
 ;1153|1_1|11^16^21^74^145^172
 ;1153|1_2|9^50^66^97^103^115^141^152
 ;1154|2_1|83^147^152
 ;1154|1_2|2^35^48^63^73^128^140^158^179^188
 ;1155|1_1|21^37^52^79^88^97^100^168^172^184
 ;1155|1_2|17^32^82^96^122^137^167^187
 ;1156|2_1|20^75
 ;1156|1_1|4^12^23^70^93^156^164^178^195
 ;1156|1_2|39^59^85^100^126^166^192
 ;1157|1_1|18^58^70^90^93^121^123^126^148^163^167^172^195
 ;1157|1_2|13^24^44^92^112^156^165^190
 ;1158|1_1|4^59^80^82^93^100^111^126^137^156^166^192^193
 ;1158|1_2|16^18^37^70^134^164^178
 ;1159|1_1|13^24^68^96^148^167^180^195
 ;1159|1_2|21^52^79^88^104^136^153^172
 ;1160|1_1|33^41^44^51^91^108^109
 ;1160|1_2|31^72^89^113^123^143
 ;1161|2_1|20
 ;1161|1_1|1^57^113^118
 ;1161|1_2|7^28^41^120^146
 ;1162|1_1|37^50^54^82^83^105^155
 ;1162|1_2|3^27^56^108^163^177
 ;1163|2_1|75
 ;1163|1_1|17^28^39^51^71^77^85^93^101^111^114^120^178^193
 ;1163|1_2|14^34^64^118^151^170
 ;1164|1_1|65^83^126
 ;1164|1_2|25^45^94^130^161
 ;1165|2_1|158
 ;1165|1_1|11^65^152
 ;1165|1_2|36^61^81^105^116^124^144
 ;1166|1_1|44^47^57^74^89^110^113^143^157
 ;1166|1_2|62^76^91^125^150
 ;1167|1_1|18^24^52^82^89^92^95^104^123^136^148^156^165^172^182
 ;1167|1_2|33^58^80^121^131^138
 ;1168|1_1|28^41^59^64^70^80^111^118^120^170
 ;1168|1_2|1^22^57^78^101^107^114
 ;1169|1_1|13^54^79^88^112^121^136^172^189
 ;1169|1_2|68^95^127^148^182
 ;1240|2_1|154^185
 ;1240|1_1|12^15^24^104^149^180^190
 ;1241|2_1|30^46^67
 ;1241|1_1|26^99^139^175^178^195
 ;1242|1_1|6^17^43^70^90^92^111^118^119
 ;1243|2_1|30^46^84^154
 ;1243|1_1|15^26^99^139
 ;1244|2_1|67
 ;1244|1_1|23^58^111^135^156^178^192^193
 ;1245|1_1|5^12^24^52^92^93^112^184^195
 ;1246|1_1|17^23^33^51^52^71^89^126^184
 ;1247|1_1|39^59^93^112^169^175^178^192^195
 ;1248|2_1|53
 ;1248|1_1|22^70^90^101^107^111^170^193
 ;1249|1_1|4^5^23^51^72^99^109^135^184
 ;1250|2_1|185
 ;1250|1_1|26^60^162^169^173^194
 ;1251|2_1|53^67
 ;1251|1_1|42^77^85^93^133^151^175
 ;1252|1_1|10^38^83^117^132^142^171
 ;1253|2_1|6^15^24^26^139^195
 ;1253|1_1|30^46^84^154
 ;1254|2_1|135^170^178
 ;1254|1_1|8^20^27^53^67^75^155^174^185
 ;1255|1_1|8^20^53^75^129^155^174^185
 ;1256|2_1|5^26^149
 ;1256|1_1|10^30^46^84^117^154
 ;1257|2_1|14^93^120^156^175^178
 ;1257|1_1|67^142
 ;1258|1_1|10^19^38^83^117^132^159^171^183
 ;1259|2_1|93^178
 ;1259|1_1|8^67^75^142^154^155^174^185
 ;1260|1_1|29^54^79^87^106^180^189^191
 ;1261|2_1|188
 ;1261|1_1|10^38^83^103^159^171^183
 ;1262|2_1|48^73^158
 ;1262|1_1|11^19^147^152^153^168^191
 ;1263|2_1|63
 ;1263|1_1|25^36^61^65^85^105^126^130^144
 ;1264|1_1|9^11^65^66^88^103^152^153^159^172^191
 ;1265|1_1|19^21^50^97^141^166^187
 ;1266|1_1|16^37^74^115^137^145^168
 ;1267|2_1|85^118
 ;1267|1_1|2^20^35^63^174^188
 ;1268|1_1|23^44^51^52^99^128^131^135^137^140^169^179
 ;1269|2_1|19^83^147^152^183^191
 ;1269|1_1|48^73^158
 ;1270|1_1|21^32^79^88^96^100^122^167^172
 ;1271|2_1|75
 ;1271|1_1|12^17^24^34^39^51^52^59^153^184
 ;1272|1_1|9^37^74^82^97^115^137^145^168^187
 ;1273|1_1|4^12^23^39^52^59^70^93^164^178^192^195
 ;1274|1_1|17^40^85^100^126^156^166^167^184
 ;1275|2_1|20^53^67^75^154^155
 ;1275|1_1|92^107^170
 ;1276|1_1|18^33^44^89^92^121^123^131^163
 ;1277|2_1|154
 ;1277|1_1|5^58^70^90^93^111^126^156^165^195
 ;1278|1_1|13^24^68^79^88^106^112^148^167^172^190
 ;1279|1_1|14^70^101^111^151^156^170^178
 ;1280|1_1|4^17^39^59^93^100^126^134^166^192^193
 ;1281|1_1|16^18^37^74^80^82^115^137^164^187
 ;1282|1_1|12^15^21^24^104^149^153^180^195
 ;1283|1_1|17^52^79^88^172^182^184
 ;1284|1_1|13^32^68^96^106^112^122^136^148^167
 ;QUIT
 Q
CALW ; Calculate the W Scale
 N PAIR
 S YSRAWRSL("W Inconsistency")=0
 F PAIR="22-170","125-143","47-157","40-181","81-116","85-126","76-150","25-94","44-121","39-59","17-184","33-89","78-164","38-171","74-115","46-154","26-99","20-174","32-122","13-112","55-110","173-194","95-127","60-162","15-149" D
 .D WADD(PAIR)
 S N=N+1,YSDATA(N)="7774^9999;1^"_YSRAWRSL("W Inconsistency")
 Q
WADD(PAIR) ;
 N Q1,Q2,ADD
 S Q1=$G(YSQANS($P(PAIR,"-"))) S:Q1=2 Q1=0    ;False is 0 instead of 2
 S Q2=$G(YSQANS($P(PAIR,"-",2))) S:Q2=2 Q2=0  ;False is 0 instead of 2
 S ADD=$TR((Q1-Q2),"-")  ;W ?30,ADD
 S YSRAWRSL("W Inconsistency")=YSRAWRSL("W Inconsistency")+ADD
 Q
SCORESV ;
 N CNT,I,SEQ,SNAM,SCARR
 K ^TMP($J,"YSCOR")
 ;F SNAM="W Inconsistency","V Invalidity" D
 ;. S YBRS(SNAM,"RSL")=$G(YSRAWRSL(SNAM))  ;Patch to be able to graph the raw results for these two scales
 ;. ;There is no Base Rate or Percentile for these two calculated scales so need to substitute raw for br
 S ^TMP($J,"YSCOR",1)="[ERROR]"
 S CNT=1
 F I=1140:1:1169,1240:1:1284 D  ;1142 VS 1143? ADDED 1144 BACK IN FOR W INCONSISTENCY
 .S SEQ=$$GET1^DIQ(601.87,I_",",2,"I")
 .S SNAM=$$GET1^DIQ(601.87,I_",",3,"I")
 .S SCARR(I)=SNAM  ;Have to figure out Scale Order on Report - Maybe doesn't matter
 S SEQ=0 F  S SEQ=$O(SCARR(SEQ)) Q:SEQ=""  D
 .S CNT=CNT+1
 .S SNAM=SCARR(SEQ)
 .;S ^TMP($J,"YSCOR",CNT)=SNAM_"="_$G(YBRS(SNAM,"RSL"))_"^"_YSRAWRSL(SNAM)_"^"_$G(YPRS(SNAM,"RSL"))
 .S ^TMP($J,"YSCOR",CNT)=SNAM_"="_$G(YSRAWRSL(SNAM))_"^"_$G(YBRS(SNAM,"RSL"))_"^"_$G(YPRS(SNAM,"RSL"))
 S ^TMP($J,"YSCOR",1)="[DATA]"
 Q
EXTANS ;
 ;Extract the T/F responses to each question from YSDATA array
 ;TRUE=1 FALSE=2
 N X,QUEST,ANS,STR,PTR
 S X=2
 F  S X=$O(YSDATA(X)) Q:+X=0  D
 .S STR=YSDATA(X),QUES=$P(STR,"^",2),ANS=$P(STR,"^",3),PTR=$P(STR,"^")
 .S ANS=$S(ANS=3919:1,ANS=3920:2,1:"")
 .S YSQANS(QUES)=ANS
 .S YSQANS(QUES,"PTR")=PTR
 .S YSQANS2(PTR)=ANS
 Q
BR ;Get the Base Rate for each scale
 N SCALSTR,SCAL,PCE,I
 F I=1140:1:1142,1145:1:1169,1240:1:1284 D
 .;S SCAL=^YTT(601.87,I,0)
 .S SCAL=$$GET1^DIQ(601.87,I_",",3,"I")
 .S RAW=$G(YSRAWRSL(SCAL))
 .S YBRS(SCAL,"RSL")=$P(YBRS(SCAL,"STR"),"^",RAW+1)  ;Note RAW+1 because raw values start at 0 
 Q
BRADJ1 ;Adjust the Base Rate score for scales 1-8B and S-PP depending on the X Raw Score
 N SCALSTR,ADJARR,I,SCAL,BR,ADJ,XRAW
 ;1-8B
 F STEND="0^6;0","7^7;10","8^8;9","9^9;8","10^10;7","11^11;6","12^12;5","13^14;4","15^16;3","17^18;2","19^20;1","21^60;0" D
 .D SETADJ(STEND)
 F STEND="61^66;-1","67^71;-2","72^76;-3","77^82;-4","83^87;-5","88^93;-6","94^98;-7","99^104;-8","105^109;-9","110^114;-10","115^121;0" D
 .D SETADJ(STEND)
 S XRAW=YSRAWRSL("X Disclosure")
 S ADJ=ADJARR(XRAW)  ;Get the adjustment value based on the Raw X Disclosure Scale value
 F I=1145:1:1156 D
 .S SCAL=$$GET1^DIQ(601.87,I_",",3,"I")
 .S BR=YBRS(SCAL,"RSL")
 .S BR=BR+ADJ
 .S BR=$$BRFIX(BR)
 .S YBRS(SCAL,"RSL")=BR
 K ADJARR
 ;S-PP
 F STEND="0^6;0","7^8;5","9^10;4","11^12;3","13^16;2","17^20;1","21^60;0" D
 .D SETADJ(STEND)
 F STEND="61^71;-1","72^82;-2","83^93;-3","94^100;-4","101^114;-5","115^121;0" D
 .D SETADJ(STEND)
 S ADJ=ADJARR(XRAW)  ;Get the adjustment value based on the Raw X Disclosure Scale value for S-PP
 F I=1157:1:1169 D
 .S SCAL=$$GET1^DIQ(601.87,I_",",3,"I")
 .S BR=YBRS(SCAL,"RSL")
 .S BR=BR+ADJ
 .S BR=$$BRFIX(BR)
 .S YBRS(SCAL,"RSL")=BR
 Q
SETADJ(STEND) ; Set up the Base Rate Adjustment Array
 N BEG,END,VAL,I
 S BEG=$P(STEND,";"),END=$P(BEG,"^",2),BEG=$P(BEG,"^"),VAL=$P(STEND,";",2)
 F I=BEG:1:END S ADJARR(I)=VAL
 Q
BRADJ2 ;Adjust the Base Rate based on Scales A and CC
 N ACC,ABR,CCBR,ADJARR,I
 S ABR=$G(YBRS("A Generalized Anxiety","RSL"))
 S CCBR=$G(YBRS("CC Major Depression","RSL"))
 Q:((ABR<75)!(CCBR<75))
 S ACC=(ABR-75)+(CCBR-75)
 F STEND="0^4;-1","5^9;-2","10^14;-3","15^19;-4","20^24;-5","25^29;-5","30^34;-6","35^39;-6","40^44;-7","45^49;-7","50^54;-8","55^59;-8","60^64;-9","65^69;-9","70^75;-10","76^80;-10" D
 .D SETADJ(STEND)
 S ADJ=ADJARR(ACC)
 F I=1147,1156,1158 D
 .S SCAL=$$GET1^DIQ(601.87,I_",",3,"I")
 .S BR=YBRS(SCAL,"RSL")
 .S BR=BR+ADJ
 .S BR=$$BRFIX(BR)
 .S YBRS(SCAL,"RSL")=BR
 F STEND="0^4;-1","5^9;-1","10^14;-2","15^19;-2","20^24;-3","25^29;-3","30^34;-3","35^39;-3","40^44;-4","45^49;-4","50^54;-4","55^59;-4","60^64;-5","65^69;-5","70^75;-5","76^80;-5" D
 .D SETADJ(STEND)
 S ADJ=ADJARR(ACC)
 F I=1146,1157 D
 .S SCAL=$$GET1^DIQ(601.87,I_",",3,"I")
 .S BR=YBRS(SCAL,"RSL")
 .S BR=BR+ADJ
 .S BR=$$BRFIX(BR)
 .S YBRS(SCAL,"RSL")=BR
 Q
PR ;Get the Percentile for each scale based on adjusted Base Rate for Personality/Psychopathology
 ;  Get the Percentile for each Facet Scale based on RAW score for Grossman Facet Scales
 N SCALSTR,SCAL,PCE,I,RAW,BR
 F I=1145:1:1169,1240:1:1284 D
 .;S SCAL=^YTT(601.87,I,0)
 .S SCAL=$$GET1^DIQ(601.87,I_",",3,"I")
 .S BR=$G(YBRS(SCAL,"RSL"))
 .S YPRS(SCAL,"RSL")=$P(YPRS(SCAL,"STR"),"^",BR+1)  ;Note RAW+1 because raw values start at 0 
 ;Grossman Facet Percentile
 F I=1240:1:1284 D
 .S SCAL=$$GET1^DIQ(601.87,I_",",3,"I")
 .S RAW=$G(YSRAWRSL(SCAL))
 .S YPRS(SCAL,"RSL")=$P(YPRS(SCAL,"STR"),"^",RAW+1)  ;Note RAW+1 because raw values start at 0 
 Q
BRFIX(VAL) ;If adjusted base rate <0 set to 0. If >115 set to 115 PATCH X
 I VAL<0 S VAL=0
 I VAL>115 S VAL=115
 Q VAL