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

BWMDET1.m

Go to the documentation of this file.
BWMDET1 ;CMI/THL - NEW METHOD TO EXPORT CBE/MAM DATA - BWMDET CON'T;30-May-2003 15:26;DKM
 ;;2.0;WOMEN'S HEALTH;**5,6,7,8**;MAY 16, 1996
 ;;  CDC EXPORT, BUILDS ASCII FIXED LENGTH RECORDS FOR EXPORT.
 ;IHS/CMI/THL - patch 5 new routine for new cdc format
 ;;
 ;; BWTCBE(35) = CDC DX CODE
 ;; BWTCBE(36) = DX WORKUP PLANNED CODE
 ;; Each of the BWTCBE(n) variables corresponds to the 67 field of the
 ;; CDC exprt record per version 2.4
 ;EVALUATE EACH PROCEDURE FOR CDC EXPORT
LASTCBE ;EP;FIND LAST CBE
 D CBEARRAY:'$D(^TMP("CBEARRAY",$J,BWTPATDA))
 Q:'$D(^TMP("CBEARRAY",$J,BWTPATDA))
 K BWTQUIT
 N BWTX,BWTDATX
 S BWTZ=""
 ;CHECK FOR CBE ON SAME DAY UP IEN
 S BWTX=$O(^TMP("CBEARRAY",$J,BWTPATDA,"CBE",BWTDAT,BWTPCDDA))
 I BWTX,'$D(^TMP("BWTPCD",$J,BWTX)) S BWTZ=BWTX,BWTDATX=BWTDAT D  Q:'$D(BWTQUIT)
 .D INTV
 .I BWTINTV>60 D  Q
 ..S BWTQUIT=""
 ..;S ^TMP("BWTPCD",$J,BWTX)="" ;PATCH 8
 ..;K ^TMP("CBEARRAY",$J,BWTPATDA,"CBE",BWTDATX,BWTX) ;PATCH 8
 .S BWTZ=BWTX
 .D L1
 K XMINUS
 ;CHECK FOR CBE ON SAME DAY BACK IEN
 S BWTX=$O(^TMP("CBEARRAY",$J,BWTPATDA,"CBE",BWTDAT,BWTPCDDA),-1)
 I BWTX,'$D(^TMP("BWTPCD",$J,BWTX)) S BWTZ=BWTX,BWTDATX=BWTDAT D  Q:'$D(BWTQUIT)
 .D INTV
 .I BWTINTV>60 D  Q
 ..S BWTQUIT=""
 ..;S ^TMP("BWTPCD",$J,BWTX)="" ;PATCH 8
 ..;K ^TMP("CBEARRAY",$J,BWTPATDA,"CBE",BWTDATX,BWTX) ;PATCH 8
 .K XMINUS
 .S BWTZ=BWTX
 .D L1
 K XMINUS
 ;CHECK FOR CBE ON PREVIOUS VISIT DAY FOR UP TO 2 VISITS ON THAT DATE
 S BWTDATX=$O(^TMP("CBEARRAY",$J,BWTPATDA,"CBE",BWTDAT),-1)
 I 'BWTDATX D L0 Q
 S BWTX=$O(^TMP("CBEARRAY",$J,BWTPATDA,"CBE",BWTDATX,0))
 I BWTX,'$D(^TMP("BWTPCD",$J,BWTX)) D  Q:'$D(BWTQUIT)&'$D(XMINUS)  K BWTQUIT
 .D INTV
 .I BWTINTV>60 D  Q
 ..S:'$D(XMINUS) BWTQUIT=""
 ..;S ^TMP("BWTPCD",$J,BWTX)="" ;PATCH 8
 ..;K ^TMP("CBEARRAY",$J,BWTPATDA,"CBE",BWTDATX,BWTX) ;PATCH 8
 .K XMINUS
 .S BWTZ=BWTX
 .D L1
 K XMINUS
 S BWTX=$O(^TMP("CBEARRAY",$J,BWTPATDA,"CBE",BWTDATX,BWTX))
 I BWTX,'$D(^TMP("BWTPCD",$J,BWTX)) D  Q:'$D(BWTQUIT)  K BWTQUIT
 .D INTV
 .I BWTINTV>60 D  Q
 ..S BWTQUIT=""
 ..;S ^TMP("BWTPCD",$J,BWTX)="" ;PATCH 8
 ..;K ^TMP("CBEARRAY",$J,BWTPATDA,"CBE",BWTDATX,BWTX) ;PATCH 8
 .S BWTZ=BWTX
 .D L1
 K XMINUS
 ;CHECK FOR CBE ON NEXT VISIT DAY FOR UP TO 2 VISITS ON THAT DATE
 S BWTDATX=$O(^TMP("CBEARRAY",$J,BWTPATDA,"CBE",BWTDAT))
 I 'BWTDATX D L0 Q
 S BWTX=$O(^TMP("CBEARRAY",$J,BWTPATDA,"CBE",BWTDATX,0))
 I BWTX,'$D(^TMP("BWTPCD",$J,BWTX)) D  Q:'$D(BWTQUIT)  K BWTQUIT
 .D INTV
 .I BWTINTV>60 D  Q
 ..S BWTQUIT=""
 ..;S ^TMP("BWTPCD",$J,BWTX)="" ;PATCH 8
 ..;K ^TMP("CBEARRAY",$J,BWTPATDA,"CBE",BWTDATX,BWTX) ;PATCH 8
 .S BWTZ=BWTX
 .D L1
 K XMINUS
 S BWTX=$O(^TMP("CBEARRAY",$J,BWTPATDA,"CBE",BWTDATX,BWTX))
 I BWTX,'$D(^TMP("BWTPCD",$J,BWTX)) D  Q:'$D(BWTQUIT)  K BWTQUIT
 .D INTV
 .I BWTINTV>60 D  Q
 ..S BWTQUIT=""
 ..;S ^TMP("BWTPCD",$J,BWTX)="" ;PATCH 8
 ..;K ^TMP("CBEARRAY",$J,BWTPATDA,"CBE",BWTDATX,BWTX) ;PATCH 8
 .S BWTZ=BWTX
 .D L1
 K XMINUS
L0 I 'BWTZ S BWTZ=BWTPCDDA,BWTDATX=BWTDAT
L1 D ENDATE
 Q:$D(BWTQUIT)
 S ^TMP("BWTPCD",$J,BWTZ)=""
 K ^TMP("CBEARRAY",$J,BWTPATDA,"CBE",BWTDATX,BWTZ)
 S X=$G(^BWPCD(BWTZ,0))
 I $P(X,U,5)=8!($P(X,U,5)=63)!'$P(X,U,5) Q:$P(X,U,4)'=27  S BWTDAT=BWTDATX G LASTCBE
 S BWT("CBE RESULT POINTER")=$P($G(^BWDIAG(+$P(X,U,5),0)),U,27)
 S:$P($G(^BWCBE(+BWT("CBE RESULT POINTER"),0)),U,2) BWTCBE(21)=$P($G(^BWCBE(+BWT("CBE RESULT POINTER"),0)),U,2)
 K BWTCBE("CBE PAID")
 I BWTCBE(21),BWTCBE(21)<3 S BWTCBE("CBE PAID")=1
 S BWTDATX=$P(X,U,12)
 S BWTDAT=$P(BWTDAT,".")
 N XX,YY
 S XX=BWTDATX
 S YY=22
 D F1^BWMDET:BWTCBE(21)<3
 D INTV
 Q
INTV ;EP;CALCULATE INTERVAL BETWEEN EVENTS
 S X1=BWTDAT
 S X2=BWTDATX
 D ^%DTC
 S:X<0 XMINUS=X,X=X*-1
 S BWTINTV=X
 Q
CBEARRAY ;EP;CREATE ARRAY OF ALL VISITS FOR A PATIENT
 Q:$D(^TMP("CBEARRAY",$J,BWTPATDA))
 N X,Y,Z
 S X=0
 F  S X=$O(^BWPCD("C",BWTPATDA,X)) Q:'X  D
 .S Y=$G(^BWPCD(X,0))
 .Q:'$P(Y,U,12)
 .Q:"^27^28^29^25^26^30^31^32^33^34^38^"'[(U_$P(Y,U,4)_U)  ;PATCH 8
 .I $P(Y,U,5)=8!($P(Y,U,5)=63)!'$P(Y,U,5) Q
 .S Z=$P(Y,U,12)
 .Q:Z<2950101
 .S ^TMP("CBEARRAY",$J,BWTPATDA,Z,X)=$P(Y,U,1,12)
 .S:$P(Y,U,4)=27 ^TMP("CBEARRAY",$J,BWTPATDA,"CBE",Z,X)=$P(Y,U,1,12)
 Q
ENDATE ;EP;CHECK ENROLLMENT DATE
 N BWTDAT,BWTDATX
 S X1=$P($G(^BWP(BWTPATDA,0)),U,21)
 S X2=$P($G(^BWPCD(+$G(BWTPCDDA),0)),U,12)
 Q:'X1!'X2!(X1-1<X2)
 D ^%DTC
 I X>59 S BWTQUIT="" D USED^BWMDET
 Q
SEL ;EP;TO SELECT PATIENTS TO EXPORT ;PATCH 8
 F  D S1 Q:$D(BWQUIT)
 K BWQUIT
 Q:'$D(BWTSEL)
 D ^BWMDE
 Q
S1 S DIC="^BWP("
 S DIC(0)="AEMQZ"
 S DIC("A")="Name of Patient to Export: "
 W !
 D ^DIC
 K DIC
 I +Y<1 S BWQUIT="" Q
 S BWTSEL(+Y)=""
 Q
MCARE ;EP;EVALUATE MEDICARE ELIGIBILITY; PATCH 8
 Q:'$D(^AUPNMCR("B",BWDFN))
 K BWQUIT
 N D,X,Y,Z
 S X=0
 F  S X=$O(^AUPNMCR(BWDFN,11,X)) Q:'X!$D(BWQUIT)  D
 .S Y=$G(^AUPNMCR(BWDFN,11,X,0)),D=$P(Y,U,2)
 .I $P(Y,U,3)="B",BWDT>+Y,BWDT<D!'D S BWQUIT="" Q
 Q
 Q:"^1665^1860^1861^"'[(U_DUZ(2)_U)
 I DUZ(2)=1665,$P(BWTP0,U,3)<2990401 S BWTCBE(38)=1 Q
 I DUZ(2)=1860!(DUZ(2)=1861),$P(BWTP0,U,3)<2991001 S BWTCBE(38)=1 Q
 NEW AGE
 I $G(BWTCBE(35))>8 D  Q  ;IHS/CMI/THL PATCH 8
 .I BWTCBE(35)<12 S BWTCBE(38)=""
 .E  S BWTCBE(38)=2
 S AGE=$P($G(^DPT(+$P(BWTP0,U,2),0)),U,3)
 S AGE=$E(DT,1,3)-$E(AGE,1,3)
 I AGE<50!(AGE>65) S AGE=$R(100)
 E  S AGE=1
 I AGE<26 S BWTCBE(38)=1
 E  S BWTCBE(38)=2
 Q
RACE(DATE) ;EP;FIND RACE FOR SELECTED SITES AFTER SELECTED DATES
 ;IHS/CIM/THL PATCH 8
 K BWQUIT
 Q:$G(DATE)=""
 Q:DUZ(2)'=1665
 Q:$E(DATE,5,8)<1999
 Q:$E(DATE,1,2)<10
 S ZZ=""  ;$$RACE^BWMDE2
 Q:ZZ=4
 S BWQUIT=""
 Q
FILE ;FILE NEW EXPORT RECORD
 K BWQUIT
 D RACE(BWTCBE(37)):DUZ(2)=1665
 I $D(BWQUIT) K BWQUIT Q  ;IHS/CIM/THL PATCH 8
 D MCARE
 I $D(BWQUIT) K BWQUIT Q  ;IHS/CIM/THL PATCH 8
 ;S BWTTOT=BWTTOT+1
 D ^BWUTL5,PCDVARS^BWUTL3(BWIEN,0,1)
 I '$D(NEW) I BWTCBE(21)>2 S BWTCBE(22)="",BWTCBE(23)=3 ;IHS/CMI/THL PATCH 8
 I '$D(NEW) I BWTCBE(21)<3,'$G(BWTCBE(22)) I BWTCBE(37) S BWTCBE(22)=BWTCBE(37),BWTCBE(23)=1 ;IHS/CMI/THL PATCH 8
 S BWMAM=1
 S BWPAP=0
 S $E(BWCDC(BWIEN),1)=$$STSCR^BWMDE2
 S $E(BWCDC(BWIEN),3)=$$CNTYSCR^BWMDE2
 S $E(BWCDC(BWIEN),6)=$E($P($G(^AUTTLOC(DUZ(2),0)),U,13),1,15)
 S $E(BWCDC(BWIEN),21)=$J($P(BW0,U,10),5)
 S:BWPAP $E(BWCDC(BWIEN),26)=$J($P(BW0,U,10),5)
 S:BWMAM $E(BWCDC(BWIEN),31)=$J($P(BW0,U,10),5)
 S $E(BWCDC(BWIEN),40)=$$PATID^BWMDE2
 S $E(BWCDC(BWIEN),55)=$$RECID^BWMDE2
 S $E(BWCDC(BWIEN),61)=2
 S $E(BWCDC(BWIEN),62)=$$CNTYRES^BWMDE2
 S $E(BWCDC(BWIEN),65)=$$STRES^BWMDE2
 S $E(BWCDC(BWIEN),67)=$$ZIP^BWMDE2
 S $E(BWCDC(BWIEN),72)=$$DOB^BWMDE2
 S $E(BWCDC(BWIEN),80)=""  ;$$RACE^BWMDE2
 S $E(BWCDC(BWIEN),81)=2
 S $E(BWCDC(BWIEN),88)=$G(BWTCBE(20))
 S $E(BWCDC(BWIEN),89)=$G(BWTCBE(21))
 S $E(BWCDC(BWIEN),90)=$G(BWTCBE(22))
 I $G(BWTCBE(21)),BWTCBE(21)<3 S BWTCBE("CBE PAID")=1
 I $G(BWTCBE(21)),BWTCBE(21)>2 S BWTCBE("CBE PAID")=""
 S $E(BWCDC(BWIEN),98)=$G(BWTCBE("CBE PAID"))
 S $E(BWCDC(BWIEN),99)=3
 S $E(BWCDC(BWIEN),107)=" 9"
 S $E(BWCDC(BWIEN),129)=2
 S $E(BWCDC(BWIEN),139)=$G(BWTCBE(32))
 S $E(BWCDC(BWIEN),140)=$G(BWTCBE(33))
 S $E(BWCDC(BWIEN),146)=$S($L($G(BWTCBE(35)))=1:"0",1:"")_$G(BWTCBE(35))
 S $E(BWCDC(BWIEN),148)=$G(BWTCBE(36))
 S $E(BWCDC(BWIEN),149)=$G(BWTCBE(37))
 I BWTCBE(35)<9 S BWTCBE(38)=1 ;IHS/CMI/THL PATCH 8
 E  I BWTCBE(35)<12 S BWTCBE(38)=""
 E  S BWTCBE(38)=2
 D PAID
 S $E(BWCDC(BWIEN),157)=$G(BWTCBE(38))
 I BWTCBE(38)'=1 S ^TMP("BWTEST",$J,BWTPCDDA)=BWTCBE(38)
 S $E(BWCDC(BWIEN),158)=41
 I $E(BWCDC(BWIEN),148)=1 D
 .S $E(BWCDC(BWIEN),243)=$G(BWTCBE(52))
 .S $E(BWCDC(BWIEN),244)=$G(BWTCBE(53))
 .S $E(BWCDC(BWIEN),245)=$G(BWTCBE(54))
 .S $E(BWCDC(BWIEN),246)=$G(BWTCBE(55))
 .S $E(BWCDC(BWIEN),247)=$G(BWTCBE(56))
 .S $E(BWCDC(BWIEN),248)=$S($G(BWTCBE(57)):BWTCBE(57),BWTCBE(36)=1:2,1:"")
 .S BWTCBE(58)=$TR($G(BWTCBE(58)),",",";")
 .S $E(BWCDC(BWIEN),249)=$G(BWTCBE(58))
 .S BWTCBE(59)=$TR($G(BWTCBE(59)),",",";")
 .S $E(BWCDC(BWIEN),269)=$G(BWTCBE(59))
 .S X=$E(BWCDC(BWIEN),243,248)
 .F J=1:1:6 I $E(X,J)=1 S $E(BWCDC(BWIEN),288)=1 Q
 .I X=222222 S $E(BWCDC(BWIEN),288)=2
 .S $E(BWCDC(BWIEN),289)=$G(BWTCBE(60))
 .S $E(BWCDC(BWIEN),290)=$G(BWTCBE(61))
 .S $E(BWCDC(BWIEN),291)=$G(BWTCBE(62))
 .I $G(BWTCBE(63)) S $E(BWCDC(BWIEN),292)=$G(BWTCBE(63))
 .E  I X=222222 S $E(BWCDC(BWIEN),292)=2
 .S $E(BWCDC(BWIEN),293)=$G(BWTCBE(64))
 .S $E(BWCDC(BWIEN),301)=$G(BWTCBE(65))
 .S $E(BWCDC(BWIEN),302)=$G(BWTCBE(66))
 S $E(BWCDC(BWIEN),310)=$$EOR^BWMDE21
 S ^BWTMP($J,BWDFN,BWIEN)=BWCDC(BWIEN)
 ;S ^TMP("BWEXPORT",$J,BWDFN,BWIEN)=BWCDC(BWIEN)
 I '$D(BWSILENT) U IO(0) W "." ;IHS/CIM/THL PATCH 8
 K BWCDC(BWIEN),BWTCBE
 Q
SETUP ;EP;
 S BWTCBE(20)=2
 S BWTCBE(21)=1
 S BWTCBE(23)=3
 S BWTCBE(27)=" 9"
 S BWTCBE(29)=2
 S BWTCBE(32)=2
 S BWTCBE(35)="01"
 ;S BWTCBE(35)="1" ;IHS/CMI/THL PATCH 7
 S BWTCBE(36)=2
 Q