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

APCDK.m

Go to the documentation of this file.
APCDK ; IHS/CMI/LAB - NIGHTLY AMBULATORY VISIT V FILE RELINKER ; 15 Nov 2010  12:10 PM
 ;;2.0;IHS PCC SUITE;**1,5,10**;MAY 14, 2009;Build 88
 ;
 ;
EN ;
 D ^APCDCHKJ ;run in hospital re-linker to link I's to H's
 D ^APCDKDTC ;dtc re-linker
 S X1=DT,X2=-91 D C^%DTC S APCDK("DATE")=X_.999999
 S U="^",(APCDK("VISITS"),APCDK("RELINK"))=0,APCDRUND=DT
 ;go through B index and get all visits since 61 days ago
 S APCDKVD=APCDK("DATE") F  S APCDKVD=$O(^AUPNVSIT("B",APCDKVD)) Q:APCDKVD'=+APCDKVD  D
 .S APCDKV=0 F  S APCDKV=$O(^AUPNVSIT("B",APCDKVD,APCDKV)) Q:APCDKV'=+APCDKV  D PROCESS
 K APCDKVD
 D EOJ
 Q
EOJ ;
 S DA=1,DIE="^AUTTSITE(",DR=".24////^S X=DT" D ^DIE K DA,DIE,DR
 ;update rpms site file, no error checking
 S:$D(ZTQUEUED) ZTREQ="@"
 K APCDKV,APCDKNV,APCDKMM,APCDKVFL,APCDKVDG,APCDKIGR,APCDVDFN,APCDK12N,APCDK,APCDKX,APCDKDSP,APCDKHI,APCDKPAT,APCDKAVD,APCDKAVC,APCDKVCT,APCDKDVR,APCDRUND
 K DIE,DA,DR,DIU,DIV,DIC
 Q
 ;
PROCESS ;Get vars and process visit
 Q:'$D(^AUPNVSIT(APCDKV))
 Q:$P(^AUPNVSIT(APCDKV,0),U,11)
 S DFN=$P(^AUPNVSIT(APCDKV,0),U,5) I DFN="",$P(^AUPNVSIT(APCDKV,0),U,2)]"",$P(^AUPNVSIT(APCDKV,0),U,2)'=DT,$$NOVFILES(APCDKV) S DA=APCDKV,DIK="^AUPNVSIT(" D ^DIK Q  ;delete visits with no patient
 Q:'$P(^AUPNVSIT(APCDKV,0),U,9)
 I $$GET1^DIQ(9009080,DFN,"1.1","I")=APCDKV Q  ;Quit if current ER patient
 I "AORSX"'[$P(^AUPNVSIT(APCDKV,0),U,7) Q  ;only review ambulatory visits
 Q:$D(^AUPNVPOV("AD",APCDKV))  ;leave complete visit alone
 Q:$D(^AUPNVPRV("AD",APCDKV))  ;leave complete visit alone
 S DFN=$P(^AUPNVSIT(APCDKV,0),U,5)
GVISITS ;go through all A and X visits on this date for this patient
 S APCDKXVS=0,(APCDKAVD,APCDKAVC)=9999999-$P($P(^AUPNVSIT(APCDKV,0),U),"."),APCDKAVD=(APCDKAVD-1)_".9999999"
 F  S APCDKAVD=$O(^AUPNVSIT("AA",DFN,APCDKAVD)) Q:APCDKAVD=""  Q:$P(APCDKAVD,".")'=APCDKAVC  D
 .F APCDKXVS=0:0 S APCDKXVS=$O(^AUPNVSIT("AA",DFN,APCDKAVD,APCDKXVS)) Q:APCDKXVS=""   D  D CHECKV
 ..Q:APCDKV=APCDKXVS  ;don't compare to self
 ..Q:$P(^AUPNVSIT(APCDKXVS,0),U,11)
 ..Q:'$D(^AUPNVPOV("AD",APCDKXVS))  ;do not use incomplete visits to link to
 ..Q:'$D(^AUPNVPRV("AD",APCDKXVS))  ;quit if not a complete visit
 ..Q:$P(^AUPNVSIT(APCDKXVS,0),U,6)'=$P(^AUPNVSIT(APCDKV,0),U,6)  ;don't use visits with differing facilities
 ..Q:"AORSX"'[$P(^AUPNVSIT(APCDKXVS,0),U,7)  ;link to ambulatory only
 ..NEW X,P,S S (S,X)=0,APCDKDSP="" F  S X=$O(^AUPNVPRV("AD",APCDKXVS,X)) Q:X'=+X  S:$P(^AUPNVPRV(X,0),U,4)="P" APCDKDPP=+^(0) I $P(^(0),U,4)="S"!($P(^(0),U,4)="") S S=S+1,$P(APCDKDSP,U,S)=+^(0)
 ..S APCDKVFL=9000010 F  S APCDKVFL=$O(^DIC(APCDKVFL)) Q:APCDKVFL>9000010.99!(APCDKVFL'=+APCDKVFL)  D VENTRIES
 ..;go through all V file entries
 .Q
 Q
VENTRIES ;
 S APCDKVDG=^DIC(APCDKVFL,0,"GL"),APCDKIGR=APCDKVDG_"""AD"",APCDKV,APCDVDFN)"
 S APCDVDFN="" F APCDVI=1:1 S APCDVDFN=$O(@APCDKIGR) Q:APCDVDFN=""  D CHECK
 Q
 ;
CHECK ;
 S APCDK12N=APCDKVDG_APCDVDFN_",12)"
 Q:'$D(@(APCDK12N))
 S APCDK12N=@(APCDK12N)
 Q:APCDK12N=""
ENCPROV ;
 ;if both v record encounter provider and any provider in V Provider for this visit match, re-link and quit (both must have a value)
 ;G ORDPROV ;IHS/ANMC/LAB - 9/23/98 per Chris Saddler ;IHS/CMI/LAB
 I APCDKVFL'=9000010.28,APCDKVFL'=9000010.11 G ORDPROV ;IHS/CMI/LAB for V NOTE
 S APCDKVFP=""
 G:$P(APCDK12N,U,4)="" ORDPROV
 I $P(^DD(9000010.06,.01,0),U,2)[6,$P(^DD(APCDKVFL,1204,0),U,2)[200 S APCDKVFP=$P(^VA(200,$P(APCDK12N,U,4),0),U,16)
 I $P(^DD(9000010.06,.01,0),U,2)[200,$P(^DD(APCDKVFL,1204,0),U,2)[200 S APCDKVFP=$P(APCDK12N,U,4)
 I $P(^DD(9000010.06,.01,0),U,2)[6,$P(^DD(APCDKVFL,1204,0),U,2)[6 S APCDKVFP=$P(APCDK12N,U,4)
 I APCDKVFP="" G ORDPROV
 I $G(APCDKDPP)=APCDKVFP D RELINK Q
 S X=0 F I=1:1 S X=$P(APCDKDSP,U,I) Q:X=""  I APCDKVFP=X D RELINK Q
 ;I $G(APCDKDPP)=$P(APCDK12N,U,4) D RELINK Q
 ;S X=0 F I=1:1 S X=$P(APCDKDSP,U,I) Q:X=""  I $P(APCDK12N,U,4)=X D RELINK Q
ORDPROV ;
 S APCDKVFP=""
 G:$P(APCDK12N,U,2)="" CLIN
 I $P(^DD(9000010.06,.01,0),U,2)[6,$P(^DD(APCDKVFL,1202,0),U,2)[200 S APCDKVFP=$P(^VA(200,$P(APCDK12N,U,2),0),U,16)
 I $P(^DD(9000010.06,.01,0),U,2)[200,$P(^DD(APCDKVFL,1202,0),U,2)[200 S APCDKVFP=$P(APCDK12N,U,2)
 I $P(^DD(9000010.06,.01,0),U,2)[6,$P(^DD(APCDKVFL,1202,0),U,2)[6 S APCDKVFP=$P(APCDK12N,U,2)
 I APCDKVFP="" G CLIN
 I $G(APCDKDPP)=APCDKVFP D RELINK Q
 S X=0 F I=1:1 S X=$P(APCDKDSP,U,I) Q:X=""  I APCDKVFP=X D RELINK Q
 ;G:$P(APCDK12N,U,2)="" CLIN
 ;I $G(APCDKDPP)=$P(APCDK12N,U,2) D RELINK Q
 ;S X=0 F I=1:1 S X=$P(APCDKDSP,U,I) Q:X=""  I $P(APCDK12N,U,2)=X D RELINK Q
CLIN ;check clinic
 ;Q  ;per discussion with Linda ;IHS/CMI/LAB - check site parameter after discussion w/Chris 1/6/04
 ;I '$P($G(^APCDSITE(DUZ(2),0)),U,27) Q  ; NO LINKING BY CLINIC PER LINDA FELS
 ;if both v record clinic and visit record clinic are not null, and they match, re-link v record and quit
 ;I $P(APCDK12N,U,3)]"",$P(^AUPNVSIT(APCDKXVS,0),U,8)]"",$P(APCDK12N,U,3)=$P(^AUPNVSIT(APCDKXVS,0),U,8) D RELINK Q
ORDERLOC ;check ordering location
 I $P(APCDK12N,U,15)]"",$P(^AUPNVSIT(APCDKXVS,0),U,22)]"",$P(APCDK12N,U,15)=$P(^AUPNVSIT(APCDKXVS,0),U,22) D RELINK Q
 Q
 ;W !,"Would have re-linked ",APCDKVFL," ",APCDVDFN," to visit ",APCDKXVS Q
 K DIE,DR,DA,DIU,DIV S DITC="",DA=APCDVDFN,DIE=APCDKVDG,DR=".03////"_APCDKXVS D ^DIE K DIE,DA,DR,DIU,DIV,DITC
 ;I APCDKVFL=9000010.09 D LABLRO
 I (APCDKVFL=9000010.09)!(APCDKVFL=9000010.25)!(APCDKVFL=9000010.31) D LABLRO    ;NEW LINE
 NEW AUPNVSIT S AUPNVSIT=APCDKXVS D MOD^AUPNVSIT
 ;update new log with from visit, to visit, multiple of v file
 D UPDLOG(APCDKVFL,APCDVDFN,APCDKXVS,APCDKV,APCDRUND,"N")
 Q
 ;
UPDLOG(VF,VFI,TV,FV,RD,TYPE) ;EP - CALLED FROM APCDKDE
 D EN^XBNEW("UPDLOG1^APCDK","VF;VFI;TV;FV;RD;TYPE")
 Q
UPDLOG1 ;EP
 NEW APCDLOGX
 NEW DIC,DIADD,DLAYGO,DIE,DR,DA,X
 S APCDLOGX=$O(^APCDKLOG("AA",RD,FV,0))
 I APCDLOGX D UPDMULT K APCDLOGX Q
 S X=RD,DIADD=1,DLAYGO=9001003.91,DIC(0)="L",DIC="^APCDKLOG(",DIC("DR")=".02////"_$P(^AUPNVSIT(TV,0),U,5)_";.03////"_$P(^AUPNVSIT(TV,0),U,1)_";.04////"_FV_";.05////"_TV_";.06////"_TYPE K DD,D0,DO D FILE^DICN K DIC,DIADD,DLAYGO,X
 S APCDLOGX=+Y
 ;
UPDMULT ;
 S X="`"_VF,DIC="^APCDKLOG("_APCDLOGX_",11,",DIC(0)="L",DIC("P")=$P(^DD(9001003.91,1101,0),U,2),DA(1)=APCDLOGX
 D ^DIC
 ;NO ERROR
 S DIE=DIC K DIC
 S DA=+Y
 S DR=".02////"_VFI
 D ^DIE
 K DIC,X,DA,DIE,DR
 Q
LABLRO ;
 ;if this is a v lab go fix LR(68.999999901 for backwards compatibility with ALR and LAB
 ;S APCDKORD=$P($G(^AUPNVLAB(APCDVDFN,11)),U,2)
 NEW APCDFILE S APCDFILE=APCDKVDG_"APCDVDFN,11)"     ;IHS/ITSC/LJF 
 S APCDKORD=$P($G(@APCDFILE),U,2)                   ;IHS/ITSC/LJF 4/21/2004
 I APCDKORD]"" D
 .K APCDKIEN S I=0  F  S I=$O(^LRO(68.999999901,"AC",APCDKV,I)) Q:I'=+I  I $P($G(^LRO(68.999999901,I,0)),U,3)=APCDKORD S APCDKIEN=I
 .I $G(APCDKIEN),$P(^LRO(68.999999901,APCDKIEN,0),U,2)'=APCDKXVS S DA=APCDKIEN,DIE="^LRO(68.999999901,",DR=".02////"_APCDKXVS D ^DIE K DA,DR,DIE
 K APCDKIEN,APCDKORD,I
 Q
CHECKV ;check visit to see if should be deleted
 S X=$$EN1^APCDKFDE(APCDKV)
 Q
 ;
NOVFILES(V) ;check to see if any vfiles, if so return a 1
 I $D(^AUPNVMSR("AD",V)) Q 0
 I $D(^AUPNVINP("AD",V)) Q 0
 I $D(^AUPNVCHS("AD",V)) Q 0
 I $D(^AUPNVEYE("AD",V)) Q 0
 I $D(^AUPNVDEN("AD",V)) Q 0
 I $D(^AUPNVPRV("AD",V)) Q 0
 I $D(^AUPNVPOV("AD",V)) Q 0
 I $D(^AUPNVPRC("AD",V)) Q 0
 I $D(^AUPNVLAB("AD",V)) Q 0
 I $D(^AUPNVIMM("AD",V)) Q 0
 I $D(^AUPNVSK("AD",V)) Q 0
 I $D(^AUPNVXAM("AD",V)) Q 0
 I $D(^AUPNVMED("AD",V)) Q 0
 I $D(^AUPNVTRT("AD",V)) Q 0
 I $D(^AUPNVCPT("AD",V)) Q 0
 I $D(^AUPNVTM("AD",V)) Q 0
 I $D(^AUPNVDXP("AD",V)) Q 0
 I $D(^AUPNVRAD("AD",V)) Q 0
 I $D(^AUPNVHF("AD",V)) Q 0
 I $D(^AUPNVPTH("AD",V)) Q 0
 I $D(^AUPNVMIC("AD",V)) Q 0
 I $D(^AUPNVNOT("AD",V)) Q 0
 I $D(^AUPNVER("AD",V)) Q 0
 I $D(^AUPNVBB("AD",V)) Q 0
 I $D(^AUPNVPHN("AD",V)) Q 0
 I $D(^AUPNVTC("AD",V)) Q 0
 I $D(^AUPNVNT("AD",V)) Q 0
 I $D(^AUPNVELD("AD",V)) Q 0
 I $D(^AUPNVTRC("AD",V)) Q 0
 I $D(^AUPNVUNH("AD",V)) Q 0
 I $D(^AUPNVTXC("AD",V)) Q 0
 I $D(^AUPNVAST("AD",V)) Q 0
 I $D(^AUPNVPOD("AD",V)) Q 0
 Q 1