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

AMHCDBL1.m

Go to the documentation of this file.
AMHCDBL1 ; IHS/CMI/LAB - backload pcc visits ;
 ;;4.0;IHS BEHAVIORAL HEALTH;;MAY 14, 2010
 ;
 ;backfill BH with CDMIS Data
IN ;EP
 ;create MHSS record first
 S AMHCDST=$O(^ACDIIF("C",AMHIEN,0))
 I 'AMHCDST W !!,"INITIAL entry not complete, skipping ",AMHIEN Q
 I $E(AMHDATE,6,7)="00" S AMHDATE=$E(AMHDATE,1,5)_"01"
 K DIC S DIC(0)="EL",DIC="^AMHREC(",DLAYGO=9002011,DIADD=1,X=AMHDATE,DIC("DR")=".02///C;.03///^S X=DT;.19////"_DUZ_";.33////R;.28////"_DUZ_";.22///A;.21///^S X=DT"
 K DD,DO,D0 D FILE^DICN K DIC,DR,DIE,DIADD,DLAYGO,X,D0
 I Y=-1 W !!,$C(7),$C(7),"Error creating Behavioral Health Record!!  Deleting Record.",! Q
 S AMHR=+Y,DIE="^AMHREC(",DA=AMHR,DR="5100///NOW",DR(2,9002011.5101)=".02////^S X=DUZ" D ^DIE K DIE,DA,DR
 S AMHTIME=$P($G(^ACDIIF(AMHCDST,0)),U,6) S AMHTIME=AMHTIME*60 I 'AMHTIME S AMHTIME=1
 S DIE="^AMHREC(",DA=AMHR
 S DR=".04////"_AMHLOC_";.05////"_AMHDCOM_";.06///"_AMHACT_";.07///"_$S(AMHCOMP="PRIMARY RESID":11,1:2)_";.08////"_AMHPAT_";.09///1;1101///"_AMHCOMP_";.12///"_AMHTIME_";.25///43;.32///"_AMHTC_";1105///"_AMHCOMT,DIE="^AMHREC(" D ^DIE
 I $D(Y) W !!,"error editing MHSS Record entry ",AMHIEN," ",AMHMIEN
 ;get initial entry and file activity time and mhss staging tool entry, get problem for later use
 S AMHSTR0=^ACDIIF(AMHCDST,0)
 K AMHPROB
 S AMHPROB(1)=$P(AMHSTR0,U)_U_$P(^ACDPROB($P(AMHSTR0,U),0),U)_U_$P(^ACDPROB($P(AMHSTR0,U),0),U,2)
 ;S ^TMP($J,"ACDCONV",AMHPAT,9999999-AMHDATE)=AMHPROB(1)
 S AMHC=1
 S X=0 F  S X=$O(^ACDIIF(AMHCDST,3,X)) Q:X'=+X  D
 .S AMHC=AMHC+1
 .S P=$P(^ACDIIF(AMHCDST,3,X,0),U)
 .S N="" I $P(^ACDIIF(AMHCDST,3,X,0),U,2)]"" S N=$P(^ACDIIF(AMHCDST,3,X,0),U,2)]""
 .I N="" S N=$P(^ACDPROB(P,0),U)
 .S AMHPROB(AMHC)=P_U_N_U_$P(^ACDPROB(P,0),U,2)
 .Q
 D PROBCONV
 D ^XBFMK
 I AMHTC="IR"!(AMHTC="OT") G PROVPOV
 S X=AMHR,DIC("DR")=".02////"_AMHPAT_";.03////"_$P(AMHPROB(1),U,5)_";.04////"_DT_";.05////"_DUZ_";.19///"_AMHTC,DIC="^AMHRCDST(",DIC(0)="MLQ",DIADD=1,DLAYGO=9002011.06
 K DD,DO D FILE^DICN K DIC,DA,DO,DD,D0,DG,DH,DI,DIW,DIU,DIADD,DIE,DQ,DLAYGO
 I Y=-1 W !!,"Creating STAGING TOOL entry failed!!!",$C(7),$C(7) H 2
 S AMHSTIEN=+Y
 S $P(^AMHRCDST(AMHSTIEN,0),U,6)=$P(AMHSTR0,U,4)
 S $P(^AMHRCDST(AMHSTIEN,0),U,7)=$P(AMHSTR0,U,5)
 S $P(^AMHRCDST(AMHSTIEN,0),U,8)=$P(AMHSTR0,U,7)
 S $P(^AMHRCDST(AMHSTIEN,0),U,9)=$P(AMHSTR0,U,8)
 S $P(^AMHRCDST(AMHSTIEN,0),U,12)=$P(AMHSTR0,U,10)
 S $P(^AMHRCDST(AMHSTIEN,0),U,13)=$P(AMHSTR0,U,11)
 S $P(^AMHRCDST(AMHSTIEN,0),U,14)=$P(AMHSTR0,U,12)
 S $P(^AMHRCDST(AMHSTIEN,0),U,15)=$P(AMHSTR0,U,13)
 S $P(^AMHRCDST(AMHSTIEN,0),U,16)=$P(AMHSTR0,U,14)
 S $P(^AMHRCDST(AMHSTIEN,0),U,17)=$P(AMHSTR0,U,15)
 S $P(^AMHRCDST(AMHSTIEN,0),U,18)=$P(AMHSTR0,U,22)
 S (AMHRCOMP,AMHACOMP,AMHDIFF)=""
 S X=$$VAL^XBDIQ1(9002170,AMHCDST,15)
 I X]"" S AMHRCOMP=$O(^AMHTCOMP("B",X,0))
 S X=$$VAL^XBDIQ1(9002170,AMHCDST,17)
 I X]"" S AMHACOMP=$O(^AMHTCOMP("B",X,0))
 S X=$$VAL^XBDIQ1(9002170,AMHCDST,19)
 I X]"" S AMHDIFF=$O(^AMHTCDDR("B",X,0))
 S $P(^AMHRCDST(AMHSTIEN,0),U,21)=AMHRCOMP
 S $P(^AMHRCDST(AMHSTIEN,0),U,22)=AMHACOMP
 S $P(^AMHRCDST(AMHSTIEN,0),U,23)=AMHDIFF
 S DA=AMHSTIEN,DIK="^AMHRCDST(" D IX1^DIK K DA,DIK
 D ^XBFMK
PROVPOV ;now create pov/provider
 S X=AMHPROV,DIC("DR")=".02////"_AMHPAT_";.03////"_AMHR_";.04///P",DIC="^AMHRPROV(",DIC(0)="MLQ",DIADD=1,DLAYGO=9002011.02
 K DD,DO D FILE^DICN K DIC,DA,DO,DD,D0,DG,DH,DI,DIW,DIU,DIADD,DIE,DQ,DLAYGO
 I Y=-1 W !!,"Creating Primary Provider entry failed!!!",$C(7),$C(7) H 2
 D ^XBFMK
 ;now create POV
 S AMHX=0 F  S AMHX=$O(AMHPROB(AMHX)) Q:AMHX'=+AMHX  D
 .S X=$P(AMHPROB(AMHX),U,5),DIC("DR")=".02////"_AMHPAT_";.03////"_AMHR_";.04///"_$P(AMHPROB(AMHX),U,2),DIC="^AMHRPRO(",DIC(0)="MLQ",DIADD=1,DLAYGO=9002011.01 K DD,DO D FILE^DICN K DIC,DA,DO,DD,D0,DG,DH,DI,DIW,DIU,DIADD,DIE,DQ,DLAYGO
 .I Y=-1 W !!,"Creating POV entry failed!!!",$C(7),$C(7) H 2
 .D ^XBFMK
 D PCCLINK^AMHCDBL
 S AMHCDVS=AMHCDVS+1
 Q
TD ;EP
 ;create MHSS record first
 S AMHCDST=$O(^ACDTDC("C",AMHIEN,0))
 I 'AMHCDST W !!,"TDC entry not complete, skipping ",AMHIEN Q
 I $E(AMHDATE,6,7)="00" S AMHDATE=$E(AMHDATE,1,5)_"01"
 K DIC S DIC(0)="EL",DIC="^AMHREC(",DLAYGO=9002011,DIADD=1,X=AMHDATE,DIC("DR")=".02///C;.03///^S X=DT;.19////"_DUZ_";.33////R;.28////"_DUZ_";.22///A;.21///^S X=DT"
 K DD,DO,D0 D FILE^DICN K DIC,DR,DIE,DIADD,DLAYGO,X,D0
 I Y=-1 W !!,$C(7),$C(7),"Error creating Behavioral Health Record!!  Deleting Record.",! Q
 S AMHR=+Y,DIE="^AMHREC(",DA=AMHR,DR="5100///NOW",DR(2,9002011.5101)=".02////^S X=DUZ" D ^DIE K DIE,DA,DR
 S AMHTIME=$P($G(^ACDTDC(AMHCDST,0)),U,29) S AMHTIME=AMHTIME*60 I 'AMHTIME S AMHTIME=1
 S DIE="^AMHREC(",DA=AMHR,DR=".04////"_AMHLOC_";.05////"_AMHDCOM_";.06///"_AMHACT_";.07///2;.08////"_AMHPAT_";.09///1;1101///"_AMHCOMP_";.12///"_AMHTIME_";.25///43;.32///"_AMHTC_";1105///"_AMHCOMT,DIE="^AMHREC(" D ^DIE
 I $D(Y) W !!,"error editing MHSS Record entry ",AMHIEN," ",AMHMIEN
 ;get initial entry and file activity time and mhss staging tool entry, get problem for later use
 S AMHSTR0=^ACDTDC(AMHCDST,0)
 K AMHPROB
 I '$P(AMHSTR0,U,27) W !,"no primary problem on discharge ",AMHIEN,"  ",AMHCDST S AMHC=0 G N
 S AMHPROB(1)=$P(AMHSTR0,U,27)_U_$P(^ACDPROB($P(AMHSTR0,U,27),0),U)_U_$P(^ACDPROB($P(AMHSTR0,U,27),0),U,2)
  S AMHC=1
N ;
 S X=0 F  S X=$O(^ACDTDC(AMHCDST,3,X)) Q:X'=+X  D
 .S AMHC=AMHC+1
 .S P=$P(^ACDTDC(AMHCDST,3,X,0),U)
 .S N="" I $P(^ACDTDC(AMHCDST,3,X,0),U,2)]"" S N=$P(^ACDTDC(AMHCDST,3,X,0),U,2)]""
 .I N="" S N=$P(^ACDPROB(P,0),U)
 .S AMHPROB(AMHC)=P_U_N_U_$P(^ACDPROB(P,0),U,2)
 .Q
 D PROBCONV
 D ^XBFMK
 S X=AMHR,DIC("DR")=".02////"_AMHPAT_";.03////"_$P($G(AMHPROB(1)),U,5)_";.04////"_DT_";.05////"_DUZ_";.19///"_AMHTC,DIC="^AMHRCDST(",DIC(0)="MLQ",DIADD=1,DLAYGO=9002011.06
 K DD,DO D FILE^DICN K DIC,DA,DO,DD,D0,DG,DH,DI,DIW,DIU,DIADD,DIE,DQ,DLAYGO
 I Y=-1 W !!,"Creating STAGING TOOL entry failed!!!",$C(7),$C(7) H 2
 S AMHSTIEN=+Y
 S $P(^AMHRCDST(AMHSTIEN,0),U,6)=$P(AMHSTR0,U,4)
 S $P(^AMHRCDST(AMHSTIEN,0),U,7)=$P(AMHSTR0,U,5)
 S $P(^AMHRCDST(AMHSTIEN,0),U,8)=$P(AMHSTR0,U,7)
 S $P(^AMHRCDST(AMHSTIEN,0),U,9)=$P(AMHSTR0,U,8)
 S $P(^AMHRCDST(AMHSTIEN,0),U,12)=$P(AMHSTR0,U,10)
 S $P(^AMHRCDST(AMHSTIEN,0),U,13)=$P(AMHSTR0,U,11)
 S $P(^AMHRCDST(AMHSTIEN,0),U,14)=$P(AMHSTR0,U,12)
 S $P(^AMHRCDST(AMHSTIEN,0),U,15)=$P(AMHSTR0,U,13)
 S $P(^AMHRCDST(AMHSTIEN,0),U,16)=$P(AMHSTR0,U,14)
 S $P(^AMHRCDST(AMHSTIEN,0),U,17)=$P(AMHSTR0,U,15)
 S $P(^AMHRCDST(AMHSTIEN,0),U,18)=$P(AMHSTR0,U,22)
 S (AMHRCOMP,AMHACOMP,AMHDIFF)=""
 S X=$$VAL^XBDIQ1(9002171,AMHCDST,15)
 I X]"" S AMHRCOMP=$O(^AMHTCOMP("B",X,0))
 S X=$$VAL^XBDIQ1(9002171,AMHCDST,17)
 I X]"" S AMHACOMP=$O(^AMHTCOMP("B",X,0))
 S X=$$VAL^XBDIQ1(9002171,AMHCDST,19)
 I X]"" S AMHDIFF=$O(^AMHTCDDR("B",X,0))
 S $P(^AMHRCDST(AMHSTIEN,0),U,21)=AMHRCOMP
 S $P(^AMHRCDST(AMHSTIEN,0),U,22)=AMHACOMP
 S $P(^AMHRCDST(AMHSTIEN,0),U,23)=AMHDIFF
 S DA=AMHSTIEN,DIK="^AMHRCDST(" D IX1^DIK K DA,DIK
 D ^XBFMK
 ;now create pov/provider
 S X=AMHPROV,DIC("DR")=".02////"_AMHPAT_";.03////"_AMHR_";.04///P",DIC="^AMHRPROV(",DIC(0)="MLQ",DIADD=1,DLAYGO=9002011.02
 K DD,DO D FILE^DICN K DIC,DA,DO,DD,D0,DG,DH,DI,DIW,DIU,DIADD,DIE,DQ,DLAYGO
 I Y=-1 W !!,"Creating Primary Provider entry failed!!!",$C(7),$C(7) H 2
 D ^XBFMK
 ;now create POV
 Q:'$D(AMHPROB)
 S AMHX=0 F  S AMHX=$O(AMHPROB(AMHX)) Q:AMHX'=+AMHX  D
 .S X=$P(AMHPROB(AMHX),U,5),DIC("DR")=".02////"_AMHPAT_";.03////"_AMHR_";.04///"_$P(AMHPROB(AMHX),U,2),DIC="^AMHRPRO(",DIC(0)="MLQ",DIADD=1,DLAYGO=9002011.01 K DD,DO D FILE^DICN K DIC,DA,DO,DD,D0,DG,DH,DI,DIW,DIU,DIADD,DIE,DQ,DLAYGO
 .I Y=-1 W !!,"Creating POV entry failed!!!",$C(7),$C(7) H 2
 .D ^XBFMK
 D PCCLINK^AMHCDBL S AMHCDVS=AMHCDVS+1
 Q
PROBCONV ;
 S X=0 F  S X=$O(AMHPROB(X)) Q:X'=+X  S %=$$PCONV($P(AMHPROB(X),U,3)),$P(AMHPROB(X),U,4)=%,$P(AMHPROB(X),U,5)=$O(^AMHPROB("B",%,0))
 Q
PCONV(P) ;
 I P=17 Q 89
 I P=1 Q 29
 I P=18 Q 94
 I P=30 Q 43
 I P=2 Q 30
 I P=42 Q 23
 I P=16 Q 3
 I P=36 Q 42.2
 I P=40 Q 44.2
 I P=32 Q 43.2
 I P=12 Q 59
 I P=14 Q 79
 I P=60 Q 312.31
 I P=61 Q 26
 I P=44 Q 302.6
 I P=53 Q 80
 I P=3 Q "305.90"
 I P=13 Q 88
 I P=11 Q 56
 I P=15 Q 5
 I P=55 Q 3
 I P="MIA" Q 8
 I P=37 Q 47
 I P=41 Q 48
 I P=33 Q 49
 I P=19 Q 82
 I P=20 Q 26
 I P=34 Q 42.1
 I P=38 Q 44.1
 I P=49 Q 66
 I P=35 Q 42.3
 I P=39 Q 44.3
 I P=31 Q 43.3
 I P=43 Q 302.9
 I P=50 Q 62
 I P=10 Q 304.83
 I P=9 Q 62
 I P=47 Q "40"
 I P=48 Q 41
 I P=46 Q 41
 I P=45 Q 39
 I P=29 Q "305.10"
 Q ""