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

APCDKDE.m

Go to the documentation of this file.
APCDKDE ; IHS/CMI/LAB - POST DATA ENTRY RELINKER ;
 ;;2.0;IHS PCC SUITE;;MAY 14, 2009
 ;
 ;
EP ;EP find v file entries to re-link to this visit
 I '$D(APCDVSIT) Q  ;quit if visit not passed
 I '$D(^AUPNVSIT(APCDVSIT)) Q  ;quit if not valid visit
 I "AORSX"'[$P(^AUPNVSIT(APCDVSIT,0),U,7) Q
 ;
 NEW APCDKDEY
 D PROCESS
 D EOJ
 Q
EOJ ;
 L -^AUPNVSIT(APCDVSIT,0)
 K APCDK,APCDKXVS,APCDVDFN,APCDVI,APCDFDEC,APCDK12N,APCDKAVC,APCDKAVD,APCDKDPP,APCDKDSP,V,APCDKDVS,APCDKFDE,APCDKIGR,APCDKOPP,APCDKOSP,APCDKOVS,DFN,APCDKV,APCDKVDG,APCDKVFL,APCDKVFP
 K I,P,X,S,ZTSK
 Q
PROCESS ;
 W:'$D(ZTQUEUED) !,"Looking for ancillary data to merge into this visit..."
 NEW V
 L +^AUPNVSIT(APCDVSIT,0):60
 S V=^AUPNVSIT(APCDVSIT,0)
 Q:$P(V,U,11)  ;quit if visit has been deleted
 Q:'$P(V,U,9)  ;quit if no dependent entries
 Q:'$D(^AUPNVPRV("AD",APCDVSIT))  ;quit if not a provider yet
 S DFN=$P(V,U,5)
 ;store v providers in an array
 NEW X,P,S S (S,X)=0,APCDKDSP="" F  S X=$O(^AUPNVPRV("AD",APCDVSIT,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)
GVISITS ;go through all A and X visits on this date for this patient
 S APCDKXVS=0,(APCDKAVD,APCDKAVC)=9999999-$P($P(V,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
 ..Q:APCDVSIT=APCDKXVS  ;don't compare to self
 ..Q:$P(^AUPNVSIT(APCDKXVS,0),U,11)
 ..Q:'$P(^AUPNVSIT(APCDKXVS,0),U,9)
 ..Q:$D(^AUPNVPOV("AD",APCDKXVS))  ;quit if visit already has pov
 ..Q:$D(^AUPNVPRV("AD",APCDKXVS))  ;quit if this is a complete visit already
 ..Q:$P(^AUPNVSIT(APCDKXVS,0),U,6)'=$P(^AUPNVSIT(APCDVSIT,0),U,6)  ;don't use visits with differing facilities
 ..Q:"AORSX"'[$P(^AUPNVSIT(APCDKXVS,0),U,7)  ;don't link to non Ambulatory
 ..S APCDKVFL=9000010 F  S APCDKVFL=$O(^DIC(APCDKVFL)) Q:APCDKVFL>9000010.99!(APCDKVFL'=+APCDKVFL)  D VENTRIES
 ..D CHECKV
 .Q
 Q
 ;
VENTRIES ;
 S APCDKVDG=^DIC(APCDKVFL,0,"GL"),APCDKIGR=APCDKVDG_"""AD"",APCDKXVS,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 ;
 S APCDKVFP=""
 ;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:$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)[6,$P(^DD(APCDKVFL,1204,0),U,2)[6 S APCDKVFP=$P(APCDK12N,U,4)
 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 APCDKVFP="" G ORDPROV
 ;I $G(APCDKDPP)=$P(APCDK12N,U,4) D RELINK Q
 I $G(APCDKDPP)=APCDKVFP 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
 S X=0 F I=1:1 S X=$P(APCDKDSP,U,I) Q:X=""  I APCDKVFP=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)[6,$P(^DD(APCDKVFL,1202,0),U,2)[6 S APCDKVFP=$P(APCDK12N,U,2)
 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 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
 ;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
 ;if both v record clinic and visit record clinic are not null, and they match, re-link v record and quit
 ;Q  ;quit per Linda - 1/6/04 - don't quit per Linda's document of 9/28/03 Check site parameter per Chris
 ;I '$P($G(^APCDSITE(DUZ(2),0)),U,27) Q
 ;I $P(APCDK12N,U,3)]"",$P(V,U,8)]"",$P(APCDK12N,U,3)=$P(V,U,8) D RELINK Q
ORDERLOC ;check ordering location
 I $P(APCDK12N,U,15)]"",$P(V,U,22)]"",$P(APCDK12N,U,15)=$P(V,U,22) D RELINK Q
CHECKXIT ;
 Q
 W:'$D(ZTQUEUED) "  ",$P(^DIC(APCDKVFL,0),U)
 K DIE,DR,DA,DIU,DIV S DITC="",DA=APCDVDFN,DIE=APCDKVDG,DR=".03////"_APCDVSIT D ^DIE K DIE,DA,DR,DIU,DIV,DITC
 I (APCDKVFL=9000010.09)!(APCDKVFL=9000010.25)!(APCDKVFL=9000010.31) D LABLRO
 D UPDLOG^APCDK(APCDKVFL,APCDVDFN,APCDVSIT,APCDKXVS,DT,"D")
 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",APCDKXVS,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)'=APCDVSIT S DA=APCDKIEN,DIE="^LRO(68.999999901,",DR=".02////"_APCDVSIT D ^DIE K DA,DR,DIE
 K APCDKIEN,APCDKORD,I
 Q
CHECKV ;check visit to see if should be deleted
 S X=$$EN1^APCDKFDE(APCDKXVS)
 Q