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

BWMDEX2.m

Go to the documentation of this file.
  1. BWMDEX2 ;IHS/CIA/DKM - Data transforms for extract;21-Mar-2011 14:15;PLS
  1. ;;2.0;WOMEN'S HEALTH;**9,11,12**;MAY 16, 1996
  1. ; Returns CDC export version
  1. CDCVER(BWSITE) ; EP
  1. N X
  1. S:'$G(BWSITE) BWSITE=DUZ(2)
  1. S X=$P($G(^BWSITE(BWSITE,0)),U,18)
  1. Q $S(X:X,1:41)
  1. ; Convert FM date to CDC format
  1. ; BWLN = Format type
  1. ; 6: 6-bytes (MMYYYY)
  1. ; 8: 8-bytes (MMDDYYYY) (default)
  1. CDCDT(BWDT,BWLN) ;
  1. S:BWDT BWDT=BWDT+17000000
  1. Q $S(BWDT:$E(BWDT,5,$G(BWLN,8))_$E(BWDT,1,4),1:"")
  1. ; Return data from specified node and piece
  1. PC(BWN,BWP,BWT) ;
  1. Q $$PC^BWMDEX(.BWN,.BWP,.BWT)
  1. ; ===========================
  1. ; Patient Demographics
  1. ; ===========================
  1. ; Return unique patient id
  1. ; Assigns one if this has not already been done.
  1. PATID() N X
  1. S X=$$CDCID^BWUTL1(BWDFN)
  1. I '$L(X) D
  1. .D CDCID^BWPATE(BWDFN)
  1. .S X=$$CDCID^BWUTL1(BWDFN)
  1. Q X
  1. ; Returns DOB
  1. DOB() Q $$CDCDT($$DOB^BWUTL1(BWDFN))
  1. ; Return record identifier for this procedure.
  1. ; First digit is 1 for pap, 2 for mam.
  1. ; Second digit is one's digit of the year.
  1. ; Last 4 digits are the 1-10000 digits of the accession.
  1. RECID() N X,Y
  1. S Y=$$PC(0,1),X=$P(Y,"-",2)
  1. Q $S($E(Y)="P":1,1:2)_$E(Y,4)_$E(X,$L(X)-3,$L(X))
  1. ; Return state of residence (FIPS)
  1. STRES() N X
  1. S X=$P($G(^DPT(BWDFN,.11)),U,5)
  1. Q $S(X:$P(^DIC(5,X,0),U,3),1:"")
  1. ; Return 5 digit zipcode
  1. ZIP() N X
  1. S X=$E($$ZIP^BWUTL1(BWDFN),1,5)
  1. Q $S(X:X,1:"")
  1. ; Return FIPS code for screening state
  1. STSCR(BWSITE) ;
  1. Q $P($G(^BWSITE($G(BWSITE,DUZ(2)),0)),U,11)
  1. ; Return FIPS code for screening county
  1. CNTYSCR(BWSITE) ;
  1. N X
  1. S X=$P($G(^BWSITE($G(BWSITE,DUZ(2)),0)),U,16)
  1. Q $S(X>0:X,1:999)
  1. ; Return screening city
  1. CITY(BWSITE) ;
  1. Q $P($G(^AUTTLOC($G(BWSITE,DUZ(2)),0)),U,13)
  1. ; Return race as a string of CDC race codes
  1. ; BWVER = CDC version # (defaults to current)
  1. RACE(BWVER) ;
  1. N BWRACE,BWRSLT,I
  1. D RACEGET(.BWRACE)
  1. S BWRSLT="",I=0
  1. S:'$G(BWVER) BWVER=$$CDCVER
  1. F S I=$O(BWRACE(I)) Q:'I D
  1. .S BWRACE=$O(^BWRACE(I,1,"AC",BWVER,0))
  1. .I BWRACE,BWRSLT'[BWRACE S BWRSLT=BWRSLT_BWRACE
  1. Q BWRSLT
  1. ; Check for specific racial origin
  1. ; BWRC = IEN of race file entry
  1. ; Returns: 1 = yes, 2 = no, 3 = unknown
  1. RACECHK(BWRC) ;
  1. N BWRACE
  1. D RACEGET(.BWRACE)
  1. Q $S('$D(BWRACE):3,$D(BWRACE(BWRC)):1,1:2)
  1. ; Load race IENs into array
  1. RACEGET(BWRACE) ;
  1. N I
  1. K BWRACE
  1. S I=0
  1. F S I=$O(^BWP(BWDFN,2,I)) Q:'I S BWRACE(+^(I,0))=""
  1. ; If no race designated then infer from tribal affiliation
  1. I '$D(BWRACE) D
  1. .S I=+$P($G(^AUPNPAT(BWDFN,11)),U,8)
  1. .S I=$S(I:+$O(^BWRACE("C",I,0)),1:7)
  1. .; bw patch 10 - remove default race value of '5'/if unknown blank fill
  1. .I 'I Q
  1. .S BWRACE(I)=""
  1. Q
  1. ; Returns ethnicity code
  1. ; Assumes the IENs of file 10.2 are constant.
  1. HISPANIC() ; EP
  1. N X
  1. S X=$P(^BWP(BWDFN,0),U,9)
  1. Q $S('X:2,X=1:1,X=2:2,1:3)
  1. ; Determine Bethesda System used
  1. ; BWPDT = Date of Procedure (defaults to BWDT)
  1. ; BWSITE = Site to check (defaults to DUZ(2))
  1. ; Returns 1: 1991 system; 2: 2001 system
  1. BSU(BWPDT,BWSITE) ;
  1. N X
  1. I $G(BWMAM)!$G(BWCBE) Q ""
  1. I $$PC("all.5.03")=4!($$PC("all.5.03")=5),'$G(BWPDT) Q ""
  1. S X=$P($G(^BWSITE($G(BWSITE,DUZ(2)),.51)),U,2)
  1. S BWDT=$G(BWPDT,$G(BWDT))
  1. Q $S('X:1,BWDT<X:1,1:2)
  1. ; Return the dx workup (PAP and MAM)
  1. ; BWFLG = If zero, forces result to 2
  1. ; 1 = planned; 2 = unplanned; 3 = undetermined
  1. WKUP(BWFLG) ;
  1. N X
  1. S BWFLG=+$G(BWFLG,1),X=$S('BWFLG:2,1:$$PC(2,20))
  1. I BWFLG,$G(BWPAP),$$PRESLT=11 S X=3
  1. I BWFLG,$G(BWMAM),$$MRESLT=10 S X=3
  1. Q $S(X:X,1:2)
  1. ; Find the last procedure within time window
  1. ; BWPT = Procedure type(s) to find (separate by ^)
  1. ; BWDT1 = Ending date for search
  1. ; BWDT2 = Beginning date for search (defaults to BWDT1 - 1 year)
  1. ; Return IEN of last procedure, or 0 if none found.
  1. FINDLAST(BWPT,BWDT1,BWDT2) ; EP
  1. N X,Y,Z
  1. S:'$D(BWDT2) BWDT2=$$FMADD^XLFDT(BWDT1,-366)
  1. F X=1:1:$L(BWPT,U) S BWPT(+$P(BWPT,U,X))=""
  1. S X=0
  1. F S X=$O(^BWPCD("C",BWDFN,X)) Q:'X D
  1. .S Y=^BWPCD(X,0),Z=$P(Y,U,12)
  1. .I $D(BWPT(+$P(Y,U,4))),Z<BWDT1,Z>BWDT2 S Z(Z)=X
  1. S Z=$O(Z(""),-1)
  1. Q $S(Z:Z(Z),1:0)
  1. ; ===========================
  1. ; Breast exam
  1. ; ===========================
  1. ; Breast symptoms
  1. BRSYMP() Q $S('BWMAM&'BWCBE:3,$$PC(2,35):$$PC(2,35),1:3)
  1. ; Clinical breast exam results
  1. ; Also sets:
  1. ; CBEAB = abnormal flag
  1. ; CBEDT = abnormal date
  1. CBE() ; EP
  1. Q:'$G(BWMAM)&'$G(BWCBE) 3
  1. N BWCBEDX,BWCBEDT
  1. I $G(BWMAM) S BWCBEDX=$$PC(2,32),BWCBEDT=$$PC(2,33)
  1. E S BWCBEDX=$P($G(^BWDIAG(+$$PC(0,5),0)),U,27),BWCBEDT=BWDT
  1. S:BWCBEDX BWCBEDX=+$P($G(^BWCBE(BWCBEDX,0)),U,2)
  1. I $G(BWMAM) D
  1. .S BWDATA("CBEAB")=$$PC(16,7)
  1. .I BWDATA("CBEAB")="",BWCBEDX D
  1. ..Q:BWCBEDX=3
  1. ..Q:BWCBEDX=4
  1. ..S BWDATA("CBEAB")=1
  1. E D
  1. .I $L($$PC(16,7)) S BWDATA("CBEAB")=$$PC(16,7)
  1. .E I $L($$PC(2,38)) S BWDATA("CBEAB")=$$PC(2,38)
  1. .E S BWDATA("CBEAB")=$S(BWCBEDX<1:"",BWCBEDX<3:1,1:"")
  1. ; if a value is set in 2.38, use as OVERRIDE for default
  1. ;I 'BWDATA("CBEAB"),$$PC(2,38) S BWDATA("CBEAB")=$$PC(2,38)
  1. S BWDATA("CBEDT")=$S(BWDATA("CBEAB"):$$CDCDT(BWCBEDT),1:"")
  1. Q BWCBEDX
  1. ; ===========================
  1. ; PAP
  1. ; ===========================
  1. ; PAP specimen adequacy (CDC 5.0 and above)
  1. ; Need to code for Bethesda 2001 and collected after 10/01/02.
  1. SAPT() N BWSAPT
  1. I $G(BWMAM)!$G(BWCBE) Q ""
  1. S BWSAPT=$$PC(.3)
  1. I BWSAPT=2,$$BSU=2 S BWSAPT=1 ; code 2 only for Bethesda 1991
  1. I BWDT>3020930,'$L(BWSAPT) S BWSAPT=4 ; default to 4
  1. Q BWSAPT
  1. ; Find previous PAP
  1. ; Returns 1 if found, 2 if not, 3 if not PAP.
  1. ; Sets PAPDT
  1. PPREV() Q:'BWPAP 3
  1. N X
  1. S X=$G(^BWPCD(+$$FINDLAST(1,BWDT,0),0))
  1. S BWDATA("PAPDT")=$$CDCDT($P(X,U,12),6)
  1. Q $S($L(X):1,1:2)
  1. ; PAP result code
  1. ; Sets the following:
  1. ; POTHR = PAP result text
  1. ; PDT = Date of screening pap
  1. ; PPAY = Paid
  1. ; PABN = Abnormal PAP
  1. ; PRES = PAP result code
  1. PRESLT() N BWRESN,BWBSU,BWCODE,BWTEXT
  1. I 'BWPAP Q ""
  1. I $G(BWMAM)!$$PC(2,33)!BWCBE Q ""
  1. Q:$D(BWDATA("PRES")) BWDATA("PRES")
  1. S BWRESN=+$$PC(0,5)
  1. I 'BWRESN S BWCODE=11,BWDATA("PWKUP")=3,BWBSU=0
  1. E S BWCODE="",BWTEXT=$P($G(^BWDIAG(BWRESN,0)),U),BWBSU=$$BSU
  1. I BWBSU=1 D
  1. .S BWCODE=$P($G(^BWDIAG(BWRESN,0)),U,24)
  1. .S:BWCODE=7 BWDATA("POTHR")=BWTEXT
  1. .S BWDATA("PABN")=$S(BWCODE=14:1,1:3456[BWCODE)
  1. I BWBSU=2 D
  1. .S BWCODE=$P($G(^BWDIAG(BWRESN,1)),U)
  1. .S:BWCODE=8 BWDATA("POTHR")=BWTEXT
  1. .S BWDATA("PABN")=4567[BWCODE
  1. S:(BWCODE<9)!(BWCODE>10) BWDATA("PDT")=$$CDCDT(BWDT)
  1. I $L($$PC(2,38)) S BWDATA("PPAY")=$$PC(2,38)
  1. E S BWDATA("PPAY")=$S(BWCODE<9:1,BWCODE>13:1,BWCODE>11:2,1:"")
  1. ; IF a value is present in 2.38, OVERRIDE accordingly (NBCCEDP PAID)
  1. ;I 'BWDATA("PPAY") S BWDATA("PPAY")=$$PC(2,38)
  1. S BWDATA("PRES")=BWCODE
  1. Q BWCODE
  1. ; ===========================
  1. ; Colposcopy
  1. ; ===========================
  1. ; Return piece from 0-node of colposcopy
  1. COLPPC(BWP) ;
  1. S:'$D(BWDATA("COLP")) BWDATA("COLP")=$$COLP0^BWUTL4(BWIEN)
  1. Q $P(BWDATA("COLP"),U,BWP)
  1. ; Colposcopy Impression (No Biopsy)
  1. ; Return: 1 = Yes, 2 = No
  1. CONOBX() Q $S($$WKUP'=1:"",$$COLPPC(4)=37:1,1:2)
  1. ; Colposcopy w/Biopsy
  1. ; Return: 1 = Yes, 2 = No
  1. COLPBX() Q $S($$WKUP'=1:"",$$COLPPC(4)=2:1,1:2)
  1. ; Colposcopy final dx
  1. ; Sets the following:
  1. ; CPSTG = final stage
  1. ; CPDX = diagnosis text
  1. COLPDX() Q:$$WKUP'=1 ""
  1. N BWDX,X
  1. S BWDX=$$PC(0,33)
  1. S:'BWDX BWDX=$$COLPPC(5)
  1. S X=$G(^BWDIAG(+BWDX,0))
  1. S BWDX=$P(X,U,26)
  1. S:BWDX=6 BWDATA("CPSTG")=$$COLPPC(31)
  1. S:BWDX=7 BWDATA("CPDX")=$P(X,U)
  1. Q BWDX
  1. ; ===========================
  1. ; Mammography
  1. ; ===========================
  1. ; Find previous MAM
  1. ; Returns 1 if found, 2 if not, 3 if not MAM.
  1. ; Sets MAMDT
  1. MPREV() Q:'BWMAM&'BWCBE 3
  1. N X
  1. S X=$G(^BWPCD(+$$FINDLAST("25^26^28",BWDT,0),0))
  1. S BWDATA("MAMDT")=$$CDCDT($P(X,U,12),6)
  1. Q $S($L(X):1,1:2)
  1. ; MAM Result Code
  1. ; Sets the following:
  1. ; MABN = Abnormal mammogram
  1. ; MDT = Date of MAM
  1. ; MPAY = MAM paid
  1. ; MRES = MAM result code
  1. MRESLT() N BWCODE,BWRESN,BWMPAY
  1. Q:'$G(BWMAM) $S(BWFMT=2:8,BWFMT=3:8,1:"")
  1. Q:$D(BWDATA("MRES")) BWDATA("MRES")
  1. S BWDATA("MABN")=0,BWRESN=+$$PC(0,5)
  1. S BWCODE=$S(BWRESN:$P(^BWDIAG(BWRESN,0),U,25),1:10),BWMPAY=$S(BWCODE=12:2,1:"")
  1. S BWDATA("MABN")=$S(654[BWCODE:1,1:0)
  1. S:(BWCODE<8)!(BWCODE>9) BWDATA("MDT")=$$CDCDT(BWDT)
  1. S:$$PC(0,3)<$P($G(^BWSITE(DUZ(2),0)),U,17) BWMPAY=1
  1. ;I BWMPAY>1 D
  1. ;.N BWAGE
  1. ;.S BWAGE=$$AGE^AUPNPAT(BWDFN)
  1. ;.I (BWAGE<50)!(BWAGE>65) S BWAGE=$R(100)
  1. ;.E S BWAGE=1
  1. ;.S BWMPAY=$S(BWAGE<26:1,1:2)
  1. ; If BWCODE IS 8 (Not needed) or 12 (Done recently elsewhewre), blank fill the MDE
  1. I BWCODE=8!(BWCODE=12)!(BWCODE=9) S BWCODE=""
  1. I $L($$PC(2,38)) S BWDATA("MPAY")=$$PC(2,38)
  1. E S BWDATA("MPAY")=1 ;$S(BWMPAY:BWMPAY,1:1)
  1. ; CHECK FIELD 2.38 - IF DEFINED USE VALUE DEFINED IN 2.38 AS OVERRIDE
  1. ;I '$G(BWDATA("MPAY")) S BWDATA("MPAY")=$$PC(2,38)
  1. S BWDATA("MRES")=BWCODE
  1. Q BWCODE
  1. ; Returns true if diagnostic procedure was paid
  1. DXPAID() Q $S($L($$PC(16,6)):$$PC(16,6),$L($$PC(15,9)):$$PC(15,9),$$PC(2,22)=1:1,1:2)
  1. ; Conversion for Indication for Mammogram
  1. MIND() ;
  1. N BWRESN
  1. ; If this is a pap smear, return '5 (Cervical record only, breast services not done.)
  1. I $G(BWPAP) Q 5
  1. I $G(BWCBE),'$G(BWMAM) Q 4
  1. S BWRESN=+$$PC(0,5)
  1. S BWCODE=$S(BWRESN:$P(^BWDIAG(BWRESN,0),U,25),1:10)
  1. ; If the result code is '8' (Not needed), and there is a CBE, set the BWCODE to 4 (Initial mammogram not done...) and return the value
  1. ; set "Indication for Initial mammogram) to 4 (Initial mammogram not done..)
  1. I BWCODE=8,$$PC(2,32) S BWCODE=4 Q BWCODE
  1. ; If the result code is '9' (Needed but not performed at this visit), set Indication for initial mammogram to '4'
  1. I BWCODE=9 S BWCODE=4 Q BWCODE
  1. ; If the result code is '8' and there was no CBE, set BWCODE to 5 (Cervical Record only, breast services not done.)
  1. S BWCODE=$S(BWRESN=8:5,BWRESN=12:3,1:"")
  1. I 'BWCODE S BWCODE=$$PC(16,1)
  1. ; If there is still no code defined, and this is a 'Mammogram Screening', return 1 - for 'Routine Screening Mammogram'.
  1. I 'BWCODE,BWMAM S BWCODE=1
  1. I 'BWCODE S BWCODE=9
  1. Q BWCODE
  1. ;
  1. ; Conversion for Indication for Pap Smear
  1. PIND() ;
  1. ; If this is a mammogram, return '5 (Breast Record only, cervical services not done)
  1. I $G(BWMAM) Q 5
  1. I $G(BWCBE),'$G(BWMAM) Q 5
  1. I BWPAP,$$PC(15,1) Q $$PC(15,1)
  1. I BWPAP Q 1
  1. Q 9
  1. ;
  1. ; HPV dx
  1. ; Sets the following:
  1. ; HPVD = HPV Date
  1. ; HPVP = HPV Paid by NBCCEDP funds
  1. HPVDX() ;
  1. N HPVIDT,HPVIEN,HPVDT,HPVIEN,HPVCDT,X,HPV15,HPVRIEN,HPVDX,DTXT,HPVCHK,X1,HPVSTAT
  1. S HPVIDT=$O(^BWPCD("AHPV",BWIEN,0)) Q:'HPVIDT 3
  1. S HPVFMDT=9999999-HPVIDT
  1. S HPVCDT=$$CDCDT(HPVFMDT,8) S BWDATA("HPVD")=HPVCDT
  1. S HPVIEN=$O(^BWPCD("AHPV",BWIEN,HPVIDT,0)) ;S BWDATA("HPVP")=$S($$PC(2,38):$$PC(2,38),1:1) Q 9
  1. I '$D(^BWPCD(HPVIEN)) S BWDATA("HPVP")=$S($$PC(2,38):$$PC(2,38),1:2) Q 9
  1. S HPV15=$G(^BWPCD(HPVIEN,2))
  1. ; IF HPV test present, default to 1
  1. ; if HPV test not present, default to 2
  1. ; override with what is in NBCCEDP PAID
  1. S BWDATA("HPVP")=$P(HPV15,U,38) I 'BWDATA("HPVP") S BWDATA("HPVP")=$S($$PC(2,38):$$PC(2,38),1:1)
  1. S HPVRIEN=$P(^BWPCD(HPVIEN,0),U,5)
  1. S X=$G(^BWDIAG(+HPVRIEN,0)),X1=$G(^BWDIAG(+HPVRIEN,1))
  1. ; Convert 'Detected' into POSITIVE (cdc value = 1)
  1. ; Convert 'Not Detected' into NEGATIVE (cdc value = 2)
  1. ; If the value is error/disregard, convert value to 'UNKNOWN' (cdc value = 9)
  1. S DTXT=$P(X,U)
  1. S HPVCHK=$S(DTXT="Detected":1,DTXT="Not Detected":2,DTXT="Error/Disregard":9,1:"")
  1. I HPVCHK'="" S HPVDX=HPVCHK Q HPVDX
  1. S HPVDX=$P(X1,U,2)
  1. S:HPVDX="" HPVDX=9
  1. Q HPVDX
  1. ;
  1. ; Screen logic for field mam.10.04 (Final Imaging outcome)
  1. MAM1004() ;
  1. N MAM1001,MAM1002,MAM1003
  1. I $$PC("all.6.08")'=1 Q ""
  1. I BWDT<3090101 Q 0
  1. S MAM1001=$$PC("mam.10.01"),MAM1002=$$PC("mam.10.02"),MAM1003=$$PC("mam.10.03")
  1. ;I ((MAM1001="")!(MAM1001=2)),((MAM1002="")!(MAM1002=2)),((MAM1003="")!(MAM1003=2)) Q 0
  1. I MAM1001=1!(MAM1002=1)!(MAM1003=1) Q 1
  1. Q 0
  1. ; Specimen Type
  1. SPECTYP() ;
  1. N DEFSTYP
  1. I $G(BWCBE)!$G(BWMAM) Q ""
  1. ; if Bethesda system used is 'Bethesda 1991' specimen type should be blank.
  1. I $$PC("all.5.05")=1 Q ""
  1. I $$PC(.3,2)'="" Q $$PC(.3,2)
  1. S DEFSTYP=$$GET1^DIQ(9002086.02,$G(DUZ(2)),.24,"I") I DEFSTYP Q DEFSTYP
  1. ; If there was not a value in the specimen type field, and there is no default defined, return 1 - Conventional
  1. Q 1
  1. MAM1005() ;
  1. Q 1
  1. N RES
  1. S RES=0
  1. I $$MAM1004(),$$PC("mam.10.04"),$$PC("mam.10.04")'=8 S RES=1
  1. ;Q:$$PC("mam.10.01")=1!($$PC("mam.10.02")=1)!($$PC("mam.10.03")=1) 1
  1. Q RES