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

LRCAPDAR.m

Go to the documentation of this file.
  1. LRCAPDAR ;DALOI/FHS/RBN - LAB DSS RESULTS EXTRACT (LAR) ;6/5/18 15:59
  1. ;;5.2;LAB SERVICE;**143,169,258,307,326,386,385,394,399,420,455,510**;Sep 27, 1994;Build 2
  1. ;
  1. ; Call with Start Date (LRSDT) End Date (LREDT) FileMan format
  1. ; Calling routine should have already purged ^LAR(64.036)
  1. EN S:$D(ZTQUEUED) ZTREQ="@"
  1. I $S($G(LRSDT)'?7N:1,$G(LREDT)'?7N:1,1:0) Q
  1. L +^LAR(64.036):2 G:'$T END
  1. N DIR,DIC,DIE,X,I,LR3,LRAA,LRAD,LRAN,LRC,LRSPDT,LRSPTM,UID,Y,DLAYGO,NEXTMO,RERUN ;420
  1. N LRDFN,LRDN,LRY,LRNLT,LRLOINC,ARRAY,LRP8
  1. S DLAYGO=64
  1. I LRSDT>LREDT S X=LRSDT,LRSDT=LREDT,LREDT=X
  1. S LRX1=9999999-(LRSDT_.0001),LRX2=9999999-(LREDT_.235959)
  1. S:'$D(^LAR(64.036,0))#2 ^LAR(64.036,0)="LAB DSS LAR EXTRACT^64.036^2"
  1. LR ;
  1. K ARRAY S ARRAY("ALL")="" D LOINC^ECXUTL6(.ARRAY) ;Build ^TMP($J,"ECXUTL6")
  1. S NEXTMO=$E($$FMADD^XLFDT(LREDT,1),1,5) ;420 Get next month, year and month
  1. S RERUN=$D(^XTMP("LRECX",NEXTMO)) ;420 Need to know if we're re-running an extract.
  1. D MISSED ;420 Look at skipped entries from previous month's extract
  1. S LRDFN=0 F S LRDFN=$O(^LR(LRDFN)) Q:LRDFN<1 I $P($G(^LR(LRDFN,0)),U,2)=2 S LRN=^(0) D
  1. . S DFN=$P(LRN,U,3),LRDPF=$P(LRN,U,2)
  1. . S LRIDT=LRX2
  1. . F S LRIDT=$O(^LR(LRDFN,"CH",LRIDT)) Q:LRIDT<1!(LRIDT>LRX1) I $D(^(LRIDT,0)) S LRVSPEC=$P(^(0),U,5),LRN0=^(0) D
  1. . . I '$P(^LR(LRDFN,"CH",LRIDT,0),U,3) D SAVE Q ;420 If accessioned and no result, put on list for next month.
  1. . . I RERUN I +$G(^XTMP("LRECX",NEXTMO,LRDFN,LRIDT))=1 Q ;420 Don't consider this record as it's already been counted in the following month's extract.
  1. . . I RERUN I $G(ECXTL)'="LAR" K ^XTMP("LRECX",NEXTMO,LRDFN,LRIDT) ;420 If re-running the extract and it's not the untranslatable report then remove entry from next month's list as we now have a result
  1. . . S LRDN=0 F S LRDN=$O(^LR(LRDFN,"CH",LRIDT,LRDN)) Q:LRDN<1 D
  1. . . . S LRY=$$TSTRES^LRRPU(LRDFN,"CH",LRIDT,LRDN,"",1)
  1. . . . S LRP8=$P(LRY,U,8)
  1. . . . S LRNLT=$P($P(LRP8,"!",2),";"),LRLOINC=$P($P(LRP8,"!",3),";")
  1. . . . Q:'(+LRLOINC)
  1. . . . I +$G(^TMP($J,"ECXUTL6",LRLOINC))>0 D SET
  1. . . I $O(LRVV(0)) D FILE
  1. WRAP K DA,DR,DIC,DIE,DD,DO
  1. S (X,DINUM)=1
  1. S DIC="^LAR(64.036,",DIC(0)="LNM" D FILE^DICN S DA=+Y
  1. G:Y<1 END
  1. S DR="9///"_DT,DR(2,64.369)=".01///"_DT_";1///"_LRSDT_";2///"_LREDT_";3///"_$$NOW^LRAFUNC1_";4////"_$G(DUZ)
  1. S DIE=DIC D ^DIE G END
  1. Q
  1. SET S LRVV(+$P(^TMP($J,"ECXUTL6",LRLOINC),U,2),LRDN)=$TR($E($P(LRY,U),1,35),";","-")_U_$P(LRY,U,2)_U_LRNLT_U_LRLOINC ;455,510 Allow up to 35 characters in the result
  1. Q
  1. END L -^LAR(64.036)
  1. K D,D0,D1,DA,DFN,DI,DIC,DIE,DR,I,II,LRDA,LRDPF,LRIDT,LRN,LRN0
  1. K LRNOW,LRSB,LRSP,LRTS,LRVR,LRVSPEC,LRVV,LRX1,LRX2,X,DLAYGO
  1. K LRDFN,D2,LRSP,LRTS,DINUM,^TMP($J,"ECXUTL6") Q
  1. FILE K DR,DA,DIC,DIR,LRPROV
  1. D UID
  1. S LRN0T1=$P(LRN0,U),LRN0T2=$P(LRN0,U,3),LRPROV=$P(LRN0,U,10)
  1. S $P(LRN0,U)=$S(LRN0T2<LRN0T1:LRN0T2,1:LRN0T1)
  1. S X=$P(^LAR(64.036,0),U,3) S:X<2 X=2 F X=X:1 Q:'$D(^LAR(64.036,X))
  1. S DA=X,DIC="^LAR(64.036,",DINUM=X,DIC(0)="LNMF"
  1. S LRN0T1=$E($P($P(LRN0,U),".",2),1,4) S:'LRN0T1 LRN0T1=0 I LRN0T1,$E(LRN0T1,3,4)>59 S LRN0T1=$E(LRN0T1,1,2)_"59"
  1. S LRN0T2=$E($P($P(LRN0,U,3),".",2),1,4) S:'LRN0T2 LRN0T2=0
  1. S DIC("DR")="1///"_LRDPF_";2///"_DFN_";3///"_$P($P(LRN0,U),".")_";4///"_LRN0T1_";5///"_$P($P(LRN0,U,3),".")_";6///"_LRN0T2_";7///`"_LRVSPEC_";12///`"_LRPROV
  1. K DD,DO D FILE^DICN K DA S LRDA=Y Q:LRDA<1
  1. S $P(^LAR(64.036,+LRDA,0),U,9)=LRSPDT,$P(^(0),U,10)=LRSPTM
  1. F2 S DA(1)=+LRDA
  1. S DIC=DIC_DA(1)_",1,"
  1. S DIC(0)="L",DIC("P")=$P(^DD(64.036,8,0),"^",2)
  1. F LRTS=0:0 S LRTS=$O(LRVV(LRTS)) Q:LRTS<1 D
  1. .S LRDN=0 F S LRDN=$O(LRVV(LRTS,LRDN)) Q:LRDN<1 D DR1
  1. K LRVV,LRN0T1,LRN0T2
  1. Q
  1. DR1 K DR,DIR,DIE S DA=+LRDA
  1. S DIC("DR")=".01///"_LRTS_";1///"_$P(LRVV(LRTS,LRDN),U)_";2///"_$P(LRVV(LRTS,LRDN),U,2)_";3///"_$P(LRVV(LRTS,LRDN),U,3)_";4///"_$P(LRVV(LRTS,LRDN),U,4)
  1. S X=LRTS
  1. K D0 D FILE^DICN
  1. Q
  1. FIX S X=$P(^LAR(64.036,0),U,1,2) K ^LAR(64.036) S ^LAR(64.036,0)=X Q
  1. UID ;
  1. S LRN0T2=$P(LRN0,U,3)
  1. S LRSPDT=$P($P(LRN0,U),"."),LRSPTM=$E($P($P(LRN0,U),".",2),1,4)
  1. D
  1. . I 'LRSPTM S LRSPTM=1 Q
  1. . I LRSPTM,$E(LRSPTM,3,4)>59 S LRSPTM=$E(LRSPTM,1,2)_"59"
  1. S LRN0T1=LRSPDT_"."_LRSPTM,$P(LRN0,U)=LRN0T1
  1. S UID=$P($G(^LR(LRDFN,"CH",LRIDT,"ORU")),U) Q:'$L(UID)
  1. S LRC=$Q(^LRO(68,"C",UID)) Q:$QS(LRC,3)'=UID
  1. S LRAA=$QS(LRC,4),LRAD=$QS(LRC,5),LRAN=$QS(LRC,6)
  1. D
  1. . N LR3,LRODT,LROODT,LRSN
  1. . Q:'$G(^LRO(68,LRAA,1,LRAD,1,LRAN,0)) S LR3=^(0)
  1. . S LRODT=$P(LR3,U,4),LRSN=$P(LR3,U,5)
  1. . S LROODT=$P($G(^LRO(69,LRODT,1,LRSN,0)),U,5)
  1. . I $G(LROODT) S $P(LRN0,U)=LROODT
  1. Q
  1. ;
  1. SAVE ;added in patch 420, save records for next month's review if no result
  1. ;In this section we're saving any records that don't have a value in
  1. ;the date report completed field in the CHEM multiple of the LAB DATA
  1. ;file. We don't save records if the user is running the lab
  1. ;untranslatable report. If we're re-running the extract for the month
  1. ;then we don't count the record if it's been counted in a subsequent
  1. ;month's extract. Finally, we set the record into the XTMP global for
  1. ;later retrieval. It will be deleted one year from being stored.
  1. I $G(ECXTL)="LAR" Q ;Don't add to the list if running untranslatable report.
  1. I RERUN I +$G(^XTMP("LRECX",NEXTMO,LRDFN,LRIDT)) Q ;Don't update an entry on the list if we've already counted it.
  1. I '$D(^XTMP("LRECX",NEXTMO,0)) S ^XTMP("LRECX",NEXTMO,0)=$$FMADD^XLFDT($$DT^XLFDT,365)_"^"_$$DT^XLFDT_"^"_"Accessioned tests without results"
  1. S ^XTMP("LRECX",NEXTMO,LRDFN,LRIDT)="" ;save specific record
  1. Q
  1. ;
  1. MISSED ;added in patch 420, process any records missed in previous month's extract
  1. ;In this section we will look at the lab tests from the previous month
  1. ;that didn't have a result when the extract was run. If they now have
  1. ;a result, they'll be counted if they match the LOINC criteria. We
  1. ;only check records in the month after they were identified as no lab
  1. ;test that we report on should take more than 30 days to result. When
  1. ;we count a test that we previously skipped, the entry in the XTMP
  1. ;global is set equal to 1 to denote that we've processed this record
  1. ;and it shouldn't be counted in future extracts or in reruns of
  1. ;an extract month.
  1. N CURMO,LRDFN,LRN,LRDN,LRIDT,LRVSPEC,LRN0,LRY,LRP8,LRNLT,LRLOINC,LRVV
  1. S CURMO=$E(LRSDT,1,5) ;Year and month we're extracting
  1. I '$D(^XTMP("LRECX",CURMO,0)) Q ;No records to review
  1. S LRDFN=0 F S LRDFN=$O(^XTMP("LRECX",CURMO,LRDFN)) Q:LRDFN<1 I $P($G(^LR(LRDFN,0)),U,2)=2 S LRN=^(0) D
  1. . S DFN=$P(LRN,U,3),LRDPF=$P(LRN,U,2)
  1. . S LRIDT=0
  1. . F S LRIDT=$O(^XTMP("LRECX",CURMO,LRDFN,LRIDT)) Q:LRIDT<1 I $D(^LR(LRDFN,"CH",LRIDT,0)),$P(^(0),U,3) S LRVSPEC=$P(^(0),U,5),LRN0=^(0) D
  1. . . S LRDN=0 F S LRDN=$O(^LR(LRDFN,"CH",LRIDT,LRDN)) Q:LRDN<1 D
  1. . . . S LRY=$$TSTRES^LRRPU(LRDFN,"CH",LRIDT,LRDN,"",1)
  1. . . . S LRP8=$P(LRY,U,8)
  1. . . . S LRNLT=$P($P(LRP8,"!",2),";"),LRLOINC=$P($P(LRP8,"!",3),";")
  1. . . . Q:'(+LRLOINC)
  1. . . . I +$G(^TMP($J,"ECXUTL6",LRLOINC))>0 D SET
  1. . . I $O(LRVV(0)) D FILE I $G(ECXTL)'="LAR" S ^XTMP("LRECX",CURMO,LRDFN,LRIDT)=1 ;Mark it as counted in this month's extract
  1. Q