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

ONCACDU2.m

Go to the documentation of this file.
ONCACDU2 ;Hines OIFO/GWB - Utility routine ;05/03/12
 ;;2.2;ONCOLOGY;**1,4,7,5,6**;Jul 31, 2013;Build 10
 ;
VAFLD(ACDANS) ;Convert data to NAACCR format
 I ACDANS="N" S ACDANS=0
 I ACDANS="Y" S ACDANS=1
 I ACDANS="U" S ACDANS=9
 Q ACDANS
 ;
ICN(ACD160) ;Patient ICN (2,991.01 & 991.02) [72-94]
 ;  ICN OR X =999999999999V999999 format
 N X,ONC201,ONCPT01
 S X=""
 I ACD160="" Q X
 S ONC201=$P($G(^ONCO(160,ACD160,0)),U,1)
 S ONCPT01=$P(ONC201,";",1)
 S X=$$GETICN^MPIF001(ONCPT01)
 I $P(X,U,1)="-1" S X=""
 Q X
 ;
VASIT() ;VISN (160.1,7) [2340-2341]
 N X
 S OSPIEN=$O(^ONCO(160.1,0))
 S X=$P($G(^ONCO(160.1,OSPIEN,1)),U,7)
 K OSPIEN
 Q X
 ;
COCACC() ;COC ACCREDITATION (160.1,68) [2547-2548]
 N X
 S OSPIEN=$O(^ONCO(160.1,0))
 S X=$P($G(^ONCO(160.1,OSPIEN,7)),U,2)
 K OSPIEN
 Q X
 ;
SNCNT(IEN) ;Sequence Number--Central [380] 281-282
 N BEHAV,DATEDX,HIST,PRIMST,X
 S DATEDX=$E($$GET1^DIQ(165.5,IEN,3,"I"),1,3)
 S PRIMST=$$GET1^DIQ(165.5,IEN,20,"I")
 S HIST=$E($$GET1^DIQ(165.5,IEN,22.3,"I"),1,4)
 S BEHAV=$E($$GET1^DIQ(165.5,IEN,22.3,"I"),5)
 S X=""
 I DATEDX>295,DATEDX<303,$E(PRIMST,3,4)=53,HIST<9590,BEHAV=2 S X=98
 Q X
 ;
COCO(IEN) ;COC Coding Sys--Original [2150] 1202-1203
 N X
 S DATEDX=$$GET1^DIQ(165.5,IEN,3,"I")
 S X=$S(DATEDX>3021231:"08",DATEDX>2951231:"07",1:"05")
 Q X
 ;
VENDOR() ;Vendor Name [2170] 1204-1213
 N X,VERSION,EXTR,SUFFIX
 S EXTR=$G(^ONCO(160.16,EXTRACT,0))
 S SUFFIX=$S(EXTR["VACCR":"A",EXTR["STATE":"B",1:"")
 S VERSION=$P($G(^ONCO(160.16,EXTRACT,0))," ",3)
 S X="VA"_VERSION_$E($T(LOGO+3^ONCODIS),62,64)_SUFFIX
 Q X
 ;
WORD(IEN,NODE,LEN) ;Get word processing data
 N X
 S X=""
 I $D(^ONCO(165.5,IEN,NODE,0)) D
 .N CNT,LINE,ONCLINE
 .S CNT=0
 .S (LINE,ONCLINE)=""
 .F  S CNT=$O(^ONCO(165.5,IEN,NODE,CNT)) Q:CNT<1  D  Q:($L(ONCLINE)>LEN)
 ..Q:'$D(^ONCO(165.5,IEN,NODE,CNT,0))
 ..S ONCLINE=LINE_^ONCO(165.5,IEN,NODE,CNT,0)_" "
 ..I ($L(ONCLINE)>LEN) S LINE=$E(ONCLINE,1,LEN) Q
 ..S LINE=LINE_^ONCO(165.5,IEN,NODE,CNT,0)_" "
 .S X=LINE
 S X=$TR(X,$C(10,12,13),"   ")
 Q X
 ;
STAGE(IEN,TYPE) ;TNM Descriptors
 ;TNM Path Descriptor [910] 956-956
 ;TNM Clin Descriptor [980] 974-974
 N CD,LOC,PD,X
 S X=""
 S CD=$$GET1^DIQ(165.5,IEN,241,"I")
 S PD=$$GET1^DIQ(165.5,IEN,242,"I")
 I TYPE="C",CD'="" S X=CD G STAGEEX
 I TYPE="P",PD'="" S X=PD G STAGEEX
 S LOC=$S(TYPE="P":89.1,TYPE="C":37,1:"")
 I TYPE'="" D
 .N STRING
 .S STRING=$$GET1^DIQ(165.5,IEN,LOC,"E")
 .I ($P(STRING," ")["m")&($P(STRING," ")["y") S X=6 Q
 .I $P(STRING," ")["m" S X=3 Q
 .I TYPE="P",$P(STRING," ")["y" S X=4 Q
STAGEEX Q X
 ;
CCOUNTY(ACD160) ;County--Current [1840] 2192-2194
 I $$DPTLRT^ONCOES(ACD160)="LRT" S X="" G CCEX
 N DPT,DPTPNT,X
 S DPT=$$GET1^DIQ(160,ACD160,.01,"I")
 S DPTPNT=$P(DPT,";",1)
 S X=$$GET1^DIQ(2,DPTPNT,.117)
CCEX Q X
 ;
SUB(IEN,CNT,FIELD) ;
 ;Subsq RX 2nd Course Date [1660] 988-995
 N HEMA,HEMAPT,I,X
 S CNT=CNT-1
 S X=""
 I $O(^ONCO(165.5,IEN,4,0)) D
 .N IENS,SUB,SUBFLD,ENTRY,SUBIEN
 .S SUBIEN=0 F I=1:1 S SUBIEN=$O(^ONCO(165.5,IEN,4,SUBIEN)) Q:(I=CNT)!(SUBIEN'>0)
 .I SUBIEN="" S X="" Q
 .S IENS=SUBIEN_","_IEN
 .S ENTRY=$$GET1^DIQ(165.51,IENS,FIELD,"I") I ENTRY="",FIELD'=".07",FIELD'=".08" S X="" Q
 .S HEMA=""
 .S HEMAPT=$$GET1^DIQ(165.51,IENS,.02,"I")
 .S:HEMAPT'="" HEMA=$P($G(^ONCO(167,HEMAPT,0)),U,1)
 .I $S(FIELD=".01":1,FIELD=".05":1,FIELD=".06":1,FIELD=".07":1,FIELD=".08":1,FIELD=".09":1,FIELD="37":1,FIELD=".041":1,FIELD=".051":1,FIELD=".061":1,FIELD=".071":1,FIELD=".081":1,FIELD=".091":1,1:0) D  Q
 ..I FIELD=".06" S X=$S(ENTRY="01":1,ENTRY="02":2,ENTRY="03":3,$E(ENTRY,1)=8:0,1:ENTRY) Q
 ..I FIELD=".07" S X=$S(ENTRY="00":0,ENTRY="01":1,$E(ENTRY,1)=8:0,ENTRY=99:9,1:"") Q:X'=""  S X=$S(HEMA=30:2,HEMA=40:2,1:"") Q
 ..I FIELD=".08" S X=$S(ENTRY="01":1,ENTRY=87:7,ENTRY=88:8,$E(ENTRY,1)=8:0,ENTRY=99:9,1:ENTRY) Q:X'=""  S X=$S(HEMA=10:4,HEMA=11:2,HEMA=12:3,HEMA=20:5,1:"") Q
 ..S X=ENTRY
 .I $$GET1^DIQ(165.5,IEN,3,"I")<2980000 S X=ENTRY Q
 .S SUBFLD=$S(FIELD=33:"RR5",FIELD=35:"SC5",FIELD=36:"SO5",FIELD=.04:"SPS",1:"") I SUBFLD="" S X="" Q
 .S X=$$SUB164^ONCACDU2(IEN,SUBFLD,ENTRY)
 I FIELD=.04,$L(X)=1 S X="0"_X
 Q X
 ;
SUB164(IEN,SUBFLD,ENTRY) ;ICDO TOPOGRAPHY (164)
 N X,TOP1,TOP2
 S X=""
 S TOP1=$$GET1^DIQ(165.5,IEN,20,"I") D:TOP1'=""
 .S TOP2=$$GET1^DIQ(164,TOP1,107,"I")
 .I (TOP1=67420)!(TOP1=67421)!(TOP1=67423)!(TOP1=67424)!($E(TOP1,3,4)=76)!(TOP1=67809),($G(FIELD)=58.6)!($G(FIELD)=58.7) S TOP2=67420
 .I ($G(FIELD)=58.2)!($G(FIELD)=50.2)!($G(FIELD)=138)!($G(FIELD)=138.1)!($G(FIELD)=139)!($G(FIELD)=139.1)!($G(FIELD)=74)!($G(FIELD)=23),($E(TOP1,3,4)=76)!(TOP1=67809)!(TOP1=67420)!(TOP1=67421)!(TOP1=67423)!(TOP1=67424) S TOP2=67141
 .I $$HEMATO^ONCFUNC(IEN),TOP1=67179 S TOP2=67420  ;p5 item#18
 .I ($G(FIELD)=58.2)!($G(FIELD)=50.2),TOP1=67422 S TOP2=67770
 .I $G(SUBFLD)="SUA",($E(TOP1,3,4)=77) S TOP2=67141
 .D:TOP2'=""
 ..S X=$P($G(^ONCO(164,TOP2,SUBFLD,ENTRY,0)),U,2)
 Q X
 ;
RXPRI(IEN,FIELD,SUBFLD) ;
 ;RX Hosp--Surg Prim Site    [670] 457-458
 ;RX Hosp--Surg Site 98-02   [746] 478-479
 ;RX Hosp--Scope Reg 98-02   [747] 480-480
 ;RX Hosp--Surg Oth 98-02    [748] 481-481
 ;RX Summ--Surg Prim Site   [1290] 859-860
 ;RX Summ--Surgical Approch [1310] 865-865
 ;RX Summ--Reconstruct 1st  [1330] 867-867
 ;RX Summ--Surg Site 98-02  [1646] 939-940
 ;RX Summ--Scope Reg 98-02  [1647] 941-941
 ;RX Summ--Surg Oth 98-02   [1648] 942-942
 N X,ENTRY
 S X=""
 S TOP1=$$GET1^DIQ(165.5,IEN,20,"I")
 S ENTRY=$$GET1^DIQ(165.5,IEN,FIELD,"I") D:ENTRY'=""
 .I (TOP1=67420)!(TOP1=67421)!(TOP1=67423)!(TOP1=67424)!($E(TOP1,3,4)=76)!(TOP1=67809),($G(FIELD)=58.6)!($G(FIELD)=58.7) S X=$$SUB164^ONCACDU2(IEN,SUBFLD,ENTRY) Q
 .I $$GET1^DIQ(165.5,IEN,3,"I")<2980000,(FIELD=23)!(FIELD=74)!(FIELD=50.2)!(FIELD=58.2)!(FIELD=58.6)!(FIELD=58.7) S X=$S(FIELD=23:$$GET1^DIQ(160.4,ENTRY,.01,"I"),FIELD=74:$$GET1^DIQ(160.6,ENTRY,.01,"I"),1:ENTRY) Q
 .S X=$$SUB164^ONCACDU2(IEN,SUBFLD,ENTRY)
 Q X
 ;
FNODE(ACD160,FIELD) ;FOLLOW-UP (160,400)
 ;Date of Last Contact     [1750] 1294-1301
 ;Vital Status             [1760] 1302-1302
 ;Quality of Survival      [1780] 1304-1304
 ;Follow-Up Source         [1790] 1305-1305
 ;Next Follow-Up Source    [1800] 1306-1306
 ;Unusual Follow-Up Method [1850] 1341-1341
 ;Following Registry       [2440] 2475-2484
 N FNODE,X
 S FNODE=$$LAST(ACD160),X=""
 I FNODE'="" D
 .N IENS
 .S IENS=FNODE_","_ACD160_","
 .S X=$$GET1^DIQ(160.04,IENS,FIELD,"I")
 Q X
 ;
LAST(ACD160) ;Get last FOLLOW-UP(160,400)
 N DLC
 S X="",DLC=0
 S DLC=$O(^ONCO(160,ACD160,"F","AA",DLC))
 S:DLC'="" X=$O(^ONCO(160,ACD160,"F","AA",DLC,0))
 I X'>0 S X=""
 Q X
 ;
FCNODE(ACD160,FIELD,IE) ;FOLLOW-UP CONTACT (160,420)
 ;Follow-Up Contact--City  [1842] 1357-1376
 ;Follow-Up Contact--State [1844] 1377-1378
 ;Follow-Up Contact--Postal[1846] 1379-1387
 ;Follow-Up Contact--Name  [2394] 2284-2313
 ;Follow-Up Contact--No&St [2392] 2314-2353
 ;Follow-Up Contact--Suppl [2393] 2354-2393
 N CONTACT,FCNODE,X
 S X=""
 S FCNODE=$O(^ONCO(160,ACD160,"C","B"),-1)
 I FCNODE'="" D
 .N IENS
 .S IENS=FCNODE_","_ACD160_","
 .S CONTACT=$$GET1^DIQ(160.03,IENS,1,"I")
 I $G(CONTACT) S X=$$GET1^DIQ(165,CONTACT,FIELD,IE)
 Q X
 ;
CS(IEN) ;Cancer Status [1770] 1303-1303
 N X,Z,FNODE
 S FNODE=0
 S X=""
 S FNODE=$O(^ONCO(165.5,IEN,"TS",FNODE))
 I FNODE>0 D
 .N IENS,PT
 .S FNODE=$O(^ONCO(165.5,IEN,"TS"," "),-1)
 .Q:FNODE<1
 .S IENS=FNODE_","_IEN_","
 .S PT=$$GET1^DIQ(165.573,IENS,.02,"I")
 .Q:PT<1
 .S X=$$GET1^DIQ(164.42,PT,1,"I")
 Q X
 ;
CCTST(ACD160) ;
 ;Addr Current--City      [1810] 1307-1326
 N D0,PT,X
 S D0=ACD160
 S X="" S PT=$P($G(^ONCO(160,D0,0)),";",1)
 I $$DPTLRT^ONCOES(D0)="LRT" S X=$$GET1^DIQ(67,PT,.114,"E")
 I $$DPTLRT^ONCOES(D0)="DPT" S X=$$GET1^DIQ(2,PT,.114,"E")
 S X=$$STRIP^XLFSTR(X,"!""""#$%&'()*+,-./:;<=>?[>]^_\{|}~`")
 Q X
 ;
CSTST(ACD160) ;
 ;Addr Current--State [1820] 1327-1328
 N ONCX,XPT,XX,PT
 S (XPT,XX)=""
 S ITEM=1820 D CHKADDS^ONCACDU1 I ONCADDF'="" Q ONCADDF  ;check override
 S ONCX=$$GET1^DIQ(160,ACD160,.115,"E")
 ;S X=$S(X="CANAD":"CD",X="EU":"YY",X="MX":"XX",X="NF":"NL",X="PH":"XX",X="UN":"ZZ",1:X)
 I ONCX="" S PT=$P($G(^ONCO(160,ACD160,0)),";",1) D
 .I $$DPTLRT(ACD160)="LRT" S XPT=$$GET1^DIQ(67,PT,.115,"I") S:$G(XPT) XX=$$GET1^DIQ(5,XPT,1,"E")
 .I $$DPTLRT(ACD160)="DPT" S XPT=$$GET1^DIQ(2,PT,.1173,"I") S:$G(XPT) XX=$$GET1^DIQ(779.004,XPT,.01,"E") D:XPT=""
 ..S XPT=$$GET1^DIQ(2,PT,.115,"I") S:$G(XPT) XX=$$GET1^DIQ(5,XPT,1,"E")
 I (ONCX=""),(XX'=""),(XX'="USA"),(XX'="CAN") S ONCX="XX"
 I (ONCX=""),(XX="") S ONCX="YY"
 I (ONCX=""),(XX="USA") S ONCX="US"
 I (ONCX=""),(XX="CAN") S ONCX="CD"
 I ONCX="UN" S ONCX="ZZ"
 Q ONCX
 ;
ADDCTRY(IEN,ITEM) ;
 ;Addr at DX--Country [102] 436-438
 ;Addr Current--Country [1832] 439-441
 ;Followup Contact--Country [1847] 447-449
 ; Value derived from:
 ;    ITEM #102 - STATE AT DX (#165.5,16) pointer to File #5
 ;    ITEM #1832 - COUNTRY FILE (#2,.1173) pointer to File #779.004 or State File (#2,.115) to File #5
 ;    ITEM #1847 - ZIP CODE (#165,.119 --> #5.11,3) pointer to File #5
 ;
 ; IF VALUE IS NOT FILLED IN OR NOT FOUND, DEFAULT TO "ZZU" (UNKNOWN)
 ;
 N XX
 D CHKADDS^ONCACDU1 I ONCADDF'="" Q ONCADDF  ;check override
 S ACDANS="USA"
 I ITEM=102 S XX=$S($$GET1^DIQ(165.5,IEN,16,"I")'="":$$GET1^DIQ(5,$$GET1^DIQ(165.5,IEN,16,"I"),1,"I"),1:"")
 I ITEM=1832 D
 .S (X,XX)="" S PT=$P($G(^ONCO(160,ACD160,0)),";",1)
 .I $$DPTLRT(ACD160)="LRT" S X=$$GET1^DIQ(67,PT,.115,"I") S:$G(X) XX=$$GET1^DIQ(5,X,1,"E")
 .I $$DPTLRT(ACD160)="DPT" S X=$$GET1^DIQ(2,PT,.1173,"I") S:$G(X) (XX,ACDANS)=$$GET1^DIQ(779.004,X,.01,"E")
 .S X=$$GET1^DIQ(2,PT,.115,"I") S:$G(X) XX=$$GET1^DIQ(5,X,1,"E")
 I ITEM=1847 S XX="",VICPNT=$$FCNODE^ONCACDU2(ACD160,.119,"I") S:$G(VICPNT) STATE=$P($G(^VIC(5.11,VICPNT,0)),U,4) S:$G(STATE)'="" XX=$$GET1^DIQ(5,STATE,1,"I") K STATE,VICPNT
 I XX="QC"!(XX="AB")!(XX="ZZMB")!(XX="NB")!(XX="NF")!(XX="NS")!(XX="NT")!(XX="ON")!(XX="PE")!(XX="SK")!(XX="YT")!(XX="CANAD")!(XX="MB")!(XX="NU")!(XX="BC") S ACDANS="CAN"
 I XX="FM" S ACDANS="FSM"
 I XX="GU" S ACDANS="GUM"
 I XX="MH" S ACDANS="MHL"
 I XX="MP" S ACDANS="MNP"
 I XX="PW" S ACDANS="PWL"
 I XX="UM" S ACDANS="UMI"
 I XX="FG" S ACDANS="ZZX"
 I XX="MX" S ACDANS="MEX"
 I XX="EU" S ACDANS="ZZE"
 I XX="PH" S ACDANS="PHL"
 I XX="AS" S ACDANS="ASM"
 I XX="PR" S ACDANS="PRI"
 I XX="VI" S ACDANS="VIR"
 I XX="ZZEQ" S ACDANS="KIR"
 I XX="ZZIQ" S ACDANS="ZZP"
 I XX="ZZYQ" S ACDANS="JPN"
 I XX="UN"!(XX="") S ACDANS="ZZU"
 Q ACDANS
 ;
DPTLRT(ACD160) ;check if pt from Patient or Referral file
 N DPTLRT
 S DPTLRT=""
 I $P($G(^ONCO(160,ACD160,0)),U,1)["LRT" S DPTLRT="LRT"
 I $P($G(^ONCO(160,ACD160,0)),U,1)["DPT" S DPTLRT="DPT"
 Q DPTLRT
 ;
ICD(ICD) ;ICD Code
 ;Use ICD API (IA #3990) instead of direct global read.
 N X
 S ICD=$S(ICD'="":$$GET1^DIQ(80,ICD,.01),1:"0000")
 I ICD["." S ICD=$P(ICD,".")_$P(ICD,".",2)
 S:$L(ICD)=3 ICD=ICD_9
 S:$L(ICD)<4 ICD=$E("0000",1,4-$L(ICD))_ICD
 S:$L(ICD)>4 ICD=$E(ICD,1,4)
 I $E(ICD,4)="X"!($E(ICD,4)="-") S ICD=$E(ICD,1,3)_9
 Q ICD
 ;
ICDR(ICD) ;ICD Revision Number [1920] 1392-1392
 N ICDR
 S ICD=$$ICD(ICD)
 S ICDR=$S(ICD="    ":0,1:$$GET1^DIQ(160,ACD160,20,"I"))
 S:ICDR="" ICDR=0
 Q ICDR
 ;
PPAY(IEN) ;PRIMARY PAYER AT DX (165.5,18)
 N X
 S X=$$GET1^DIQ(165.5,IEN,18,"I")
 S X=$$GET1^DIQ(160.3,$S(X'="":X,1:99),.01,"I")
 S X=$S(X<42:X,X>47:X,1:X-1)
 Q X
 ;
DS(IEN) ;RX Date--Surgery [1200] 755-762
 N X
 S X=$$GET1^DIQ(165.5,IEN,50,"I") I X'="" S SURGDT(X)=""
 S X=$$GET1^DIQ(165.5,IEN,138.2,"I") I X'="" S SURGDT(X)=""
 S X=$$GET1^DIQ(165.5,IEN,139.2,"I") I X'="" S SURGDT(X)=""
 S SURGDT=$O(SURGDT(0))
 S X=$$DATE^ONCACDU1(SURGDT)
 K SURGDT
 Q X
STRIP ;Replace punctuation marks with spaces
 S ACDANS=$TR(ACDANS,"!""""@#$%&'()*+,-./:;<=>?[>]^_\{|}~`","                                    ")
 S ACDANS=$$TRIM^XLFSTR(ACDANS)
 Q
 ;
STRIP1 ;Strip out punctuation marks
 S ACDANS=$$STRIP^XLFSTR(ACDANS,"!""""#$%&'()*+,-./:;<=>?[>]^_\{|}~`")
 Q
 ;
STNUM ;get 3-digit state number for state extract. reporting facility must be the same w/ 160.1 entry.
 ;if no 3-digit number, use the initial from file #200
 N ONC3DIG,ONC1601,ONC3IEN,ONC16019
 S ONC3DIG=""
 S ONC16019=$$GET1^DIQ(165.5,IEN,.03,"I"),ONC1601=0
 F  S ONC1601=$O(^ONCO(160.1,"D",ACDANS,ONC1601)) Q:ONC1601'>0  D
 .I $D(^ONCO(160.1,ONC1601,1)),$P(^(1),U,4)'=ONC16019 Q
 .S ONC3IEN=$O(^ONCO(160.1,"D",ACDANS,ONC1601,0)) S:$G(ONC3IEN) ONC3DIG=$P(^ONCO(160.1,ONC1601,"REG",ONC3IEN,0),U,2)
 S:ONC3DIG="" ACDANS=$E($$GET1^DIQ(200,ACDANS,1,"I"),1,3)
 I ONC3DIG'="" S ACDANS=$S($L(ONC3DIG)=1:"00"_ONC3DIG,$L(ONC3DIG)=2:"0"_ONC3DIG,1:ONC3DIG)
 Q
 ;
CLEANUP ;Cleanup
 K EXTRACT