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

BLRTN.m

Go to the documentation of this file.
BLRTN ; IHS/HQT/MJL - CREATE/EDIT TRANSACTIONS ; 17-Dec-2015 15:37 ; MKK
 ;;5.2;IHS LABORATORY;**1011,1012,1013,1014,1015,1018,1026,1028,1033,1038**;NOV 01, 1997;Build 6
 ;        
TSK ; EP - entry point for background job
 L +^BLRLOCK:5 Q:'$T
 S BLRQUIET=1
 D INIT^BLRPARAM    ;INITIALIZE VARS
 S (BLRTRY,BLRHCNT)=0
 S BLRQDH=$P($G(^BLRSITE(BLRQSITE,0)),U,7)
 ; S:BLRQDH="" BLRQDH=+$H,$P(^BLRSITE(BLRQSITE,0),U,7)=BLRQDH
 ; ----- BEGIN IHS/OIT/MKK - LR*5.2*1033
 I $L(BLRQDH)'=5 D MAKEITSO^BLRUTIL6   ; If BLRQDH an invalid number, reset it
 S $P(^BLRSITE(BLRQSITE,0),U,7)=BLRQDH
 ; ----- END IHS/OIT/MKK - LR*5.2*1033
 ;
 ;ERRCHK CHECKS FOR ERRORS > THAN THE PARAMETER 'ERROR OVERFLOW LIMIT'
 F  D CTL Q:BLRHCNT>600  H 1 S BLRHCNT=BLRHCNT+1 Q:BLRSTOP  Q:$$ERRCHK^BLRUTIL(+$H)  I 'BLRLOG,'BLRXPCC Q
 D KILL
 L -^BLRLOCK
 Q
 ;
CTL ; EP 
 ;----- BEGIN IHS/OIT/MKK MODIFICATIONS LR*5.2*1026 -- Line too long
 NEW BLRQFLAG
 S BLRQFLAG="N"
 F  Q:BLRQFLAG="Y"  D
 . S BLRLOG=$G(^BLRSITE(BLRQSITE,0))
 . S BLRXPCC=$P(BLRLOG,U,3)
 . S BLRSTOP=$P(BLRLOG,U,9)
 . S BLRLOG=$P(BLRLOG,U,2)
 . I 'BLRLOG!(BLRSTOP)!($$ERRCHK^BLRUTIL(+$H))!('BLRQDH) S BLRQFLAG="Y"  Q
 . ;
 . S BLRLTA=$G(^BLRSITE(BLRQSITE,20,BLRQDH,0))
 . S BLRLTP=$P(BLRLTA,U,3)
 . S BLRLTA=$P(BLRLTA,U,2)
 . I BLRLTA>BLRLTP!(BLRQDH=+$H) S BLRQFLAG="Y"  Q
 . ;
 . I $H-1=BLRQDH S BLRTRY=BLRTRY+1 I BLRTRY=1 H 1 Q
 . S BLRQDH=$O(^BLRSITE(BLRQSITE,20,BLRQDH)) S:'BLRQDH BLRQDH=+$H
 . I $L(BLRQDH)'=5 D MAKEITSO^BLRUTIL6      ; IHS/OIT/MKK - LR*5.2*1033
 . S $P(^BLRSITE(BLRQSITE,0),U,7)=BLRQDH
 ;----- END IHS/OIT/MKK MODIFICATIONS LR*5.2*1026
 ;
 Q:BLRSTOP
 Q:$$ERRCHK^BLRUTIL(+$H)    ;IHS/ITSC/TPF 09/24/01 CHECK FOR ERRORS OVER OVERFLOW LIMIT
 I BLRLOG F BLRLTP=BLRLTP+1:1:BLRLTA S BLRX=$G(^BLRSITE(BLRQSITE,20,BLRQDH,1,BLRLTP,0)),BLRHCNT=0 D:BLRX'="" CTL1
 K BLRMOD
 I BLRLOG,BLRQDH<+$H Q
 I BLRXPCC D ^BLRNLINK
 Q
 ;
CTL1 ; EP
 ; Wait 60 seconds to finish setting data, if not done (something's wrong!) proceed to next queue entry.
 F BLRI=1:1:60 Q:$G(^BLRSITE(BLRQSITE,20,BLRQDH,1,BLRLTP,"C"))  H 1
 ;
 I BLRI=60,'$G(^BLRSITE(BLRQSITE,20,BLRQDH,1,BLRLTP,"C")) S $P(^BLRSITE(BLRQSITE,20,BLRQDH,0),U,3)=BLRLTP K BLR Q
 S BLRDIR=1,BLROKCK="CKORD",BLRBADCK="",BLRRSTAG="",BLRERR=0
 ;
 S BLRCMF=$P(BLRX,U),BLRPHASE=$P(BLRX,U,2),BLROPT=$P(BLRX,U,3),BLRPARAM=$P(BLRX,U,4),BLRIDS=$P(BLRX,U,5),BLRDUZ2=$P(BLRX,U,6),BLRDUZ=$P(BLRX,U,7),BLR("DUZ(2)")=BLRDUZ2,BLR("STATUS FLAG")=BLRPHASE
 ;
 ; ----- BEGIN IHS/OIT/MKK - LR*5.2*1026
 D @$S(BLRPHASE="O":"ORDER",BLRPHASE="A":"ACCESSN",BLRPHASE="D":"DELETE^BLRTNDEL",BLRPHASE="R":"RESULT^BLRTNRES",1:"DEFAULT")
 ; ----- END IHS/OIT/MKK - LR*5.2*1026
 ;
 S $P(^BLRSITE(BLRQSITE,20,BLRQDH,0),U,3)=BLRLTP
 K BLR
 Q
 ;
ORDER ; EP
 ;----- BEGIN IHS MODIFICATIONS LR*5.2*1018 IHS -- DELACC needs to be filtered also
 Q:"^^MULTI^ACCWARD^BYPASS^DELACC^FASTORD^"[(U_BLROPT_U)
 ;----- END IHS MODIFICATIONS LR*5.2*1018 IHS -- DELACC needs to be filtered also
 S BLRODT=$P(BLRIDS,","),BLRSEQ=$P(BLRIDS,",",2)
 Q:'$P($G(^LRO(69,BLRODT,1,BLRSEQ,1)),U)
 ; S ^BLRENTRY("BLROPT",BLROPT)=""
 S BLRCRSBS="""AOT"",BLRODTM,BLRSEQ,BLRTEST1",BLRDIR=1,BLROKCK="CKORD",BLRBADCK=""
 I BLROPT="ADDCOL" D MODSET Q
 I BLROPT="ADDORD" M BLRTSTS=^BLRSITE(BLRQSITE,20,BLRQDH,1,BLRLTP,"BLRTSTS")
 ; D ORDVRS,UPDTNS
 D ORDVRS^BLRTNRES,UPDTNS    ; IHS/OIT/MKK - Patch 1026 Modification
 K BLRTSTS
 Q
 ;
ACCESSN ; EP
 Q:"^BYPASS^"[(U_BLROPT_U)
 S BLRODT=$P(BLRIDS,","),BLRSEQ=$P(BLRIDS,",",2),BLRAA=$P(BLRIDS,",",3),BLRAD=$P(BLRIDS,",",4),BLRAN=$P(BLRIDS,",",5)
 S BLRCRSBS="""AOT"",BLRODTM,BLRSEQ,BLRTEST1",BLRDIR=1,BLROKCK="CKORD",BLRBADCK=""
 ;
 ; D ORDVRS,ACCVRS Q:BLRACCN=""
 D ORDVRS^BLRTNRES,ACCVRS Q:BLRACCN=""      ; IHS/OIT/MKK - Patch 1026 Modification
 I BLROPT="ADDACC" S BLRTEST=$G(^BLRSITE(BLRQSITE,20,BLRQDH,1,BLRLTP,"BLRTEST")) D SET1 Q
 D UPDTNS
 Q
 ;
 ;IHS/ITSC/TPF 10/25/02 GET 'SIGN OR SYMPTOM' LAB POV **1015**
GETDIAG(TEST) ; EP
 N TSTIEN
 Q:$G(TEST)=""  ;
 S TSTIEN=$O(^LRO(69,BLRODT,1,BLRSEQ,2,"B",TEST,""))
 Q:TSTIEN=""
 S (BLRDIAG,BLR("SIGN OR SYMPTOM"))=$G(^LRO(69,BLRODT,1,BLRSEQ,2,TSTIEN,9999999))
 K:BLRDIAG="" BLR("SIGN OR SYMPTOM")
 K TSTIEN
 Q
 ;
DEFAULT ; EP
 I BLRPHASE="REFILE" D
 . S BLRX=$P($G(^BLRSITE(BLRQSITE,21,BLRQDH,0)),U,2)+1
 . S $P(^BLRSITE(BLRQSITE,21,BLRQDH,0),U,2)=BLRX
 . S ^BLRSITE(BLRQSITE,21,BLRQDH,BLRX)=BLRIDS
 Q
 ;
ACCVRS ; EP
 S BLRACCN=$G(^LRO(68,BLRAA,1,BLRAD,1,BLRAN,.2)),BLR("ACCESSION NUMBER")=BLRACCN
 S BLR("VERIFIER POINTER")=""
 Q
 ;
MODSET ; EP
 S BLRPSN=^BLRSITE(BLRQSITE,20,BLRQDH,1,BLRLTP,"LRPSN"),BLROAOT=$P($G(^LRO(69,BLRODT,1,BLRPSN,0)),U,5),BLRODTM=BLROAOT
 S BLRCTST=0 F  S BLRCTST=$O(^BLRTXLOG("AOT",BLRODTM,BLRSEQ,BLRCTST)) Q:'BLRCTST  D
 .I $D(^BLRTXLOG("AOT",BLROAOT,BLRPSN,BLRCTST)) S BLRPHASE="D"
 .S BLRTEST1=BLRCTST,BLR("SEQUENCE NUMBER")=$$GETIEN Q:BLRERR  S BLR("STATUS FLAG")=BLRPHASE
 .S BLR("ORDER DATE")=$P($G(^LRO(69,BLRODT,1,BLRPSN,0)),U,5),BLR("ORDER SEQUENCE NUMBER")=BLRPSN,BLR("ORDER NUMBER")=$G(^LRO(69,BLRODT,1,BLRPSN,.1))
 .D ^BLRNFLTL
 .S BLRPHASE="O"
 K BLRCTST,BLROAOT,BLRPSN
 Q
 ;
UPDTNS ; EP
 S BLRTST=0 F  S BLRTST=$O(^LRO(69,BLRODT,1,BLRSEQ,2,BLRTST)) Q:'BLRTST  D
 .S BLRX=$G(^LRO(69,BLRODT,1,BLRSEQ,2,BLRTST,0)),BLRTEST=+BLRX I BLRPHASE="O",BLROPT="ADDORD",'$D(BLRTSTS(BLRTEST)) Q
 .D GETDIAG(BLRTST)
 .I BLRPHASE="A" D  Q
 ..I BLRAD=$P(BLRX,U,3),BLRAA=$P(BLRX,U,4),BLRAN=$P(BLRX,U,5) D SET1 Q
 .D SET1
 Q
 ;
 ; This module will update the transaction for a given test, plus all
 ; of its descendents' transactions. ie (subpanels, atomic tests)
 ; Input - BLRTEST
SET1 ; EP
 S BLRLEV=1,BLRCPTL=10000,BLRTEST1=BLRTEST,BLRLEV(1)=BLRTEST,BLRLEV(1,1)="",BLRPAR="",BLRATOM=0 D SET3
 F  D SET2 Q:'BLRLEV
 K BLRLEV,BLRPAR
 Q
 ;
SET2 ; EP
 S BLRATOM=$O(^LAB(60,BLRLEV(BLRLEV),2,0))="" I BLRATOM,BLRLEV=1 S BLRLEV=0 Q
 S:'BLRATOM BLRLEV=BLRLEV+1 S BLRLEV(BLRLEV,0)=$O(^LAB(60,BLRLEV(BLRLEV-1),2,$G(BLRLEV(BLRLEV,0),0)))
 I BLRLEV(BLRLEV,0) S BLRTEST1=+^LAB(60,BLRLEV(BLRLEV-1),2,$G(BLRLEV(BLRLEV,0),0),0),BLRLEV(BLRLEV)=BLRTEST1 D SET3 Q
 S BLRLEV(BLRLEV,0)=0,BLRLEV=BLRLEV-2
 Q
 ;
SET3 ; EP
 S BLRATOM=$O(^LAB(60,BLRTEST1,2,0))="",BLRL60=$G(^LAB(60,BLRTEST1,0)),BLRCST=$P(BLRL60,U,11),BLRMOD=$P(BLRL60,U,4)
 S BLRCPTS="",BLRCPTP="" I BLRLEV=1,BLRCMF="C" D CPTCODE
 S BLRSTR1="",BLRSPEC=$G(^BLRSITE(BLRQSITE,20,BLRQDH,1,BLRLTP,"LRSPEC"))
 ; I BLRCMF="C",BLROPT="RECCOL"!(BLROPT="ITMCOL") S BLRSPEC=$P($G(^LRO(68,BLRAA,1,BLRAD,1,BLRAN,5,1,0)),U)
 ;
 ; ----- BEGIN IHS/MSC/MKK - LR*5.2*1038
 I BLRCMF="C",BLROPT="RECCOL"!(BLROPT="ITMCOL") D
 . ; Ensure the BLRAA, BLRAD, and BLRAN variables exist BEFORE they're used
 . I +$G(BLRAA)<1!(+$G(BLRAD)<1)!(+$G(BLRAN)<1) S BLRAD=$P(BLRX,U,3),BLRAA=$P(BLRX,U,4),BLRAN=$P(BLRX,U,5)
 . ;
 . S BLRSPEC=$P($G(^LRO(68,+BLRAA,1,+BLRAD,1,+BLRAN,5,1,0)),U)
 ; ----- END IHS/MSC/MKK - LR*5.2*1038
 ; 
 I BLRCMF="C",BLRSPEC'="" D SET4
 S BLR("CPT LAB CODE POINTER")=BLRCPTP,BLR("BILLING CPT STRING")=BLRCPTS,BLR("PANEL/TEST POINTER")=BLRTEST1,BLR("LAB TEST LIST COST")=BLRCST,BLR("LAB MODULE")=BLRMOD
 S BLR("SEQUENCE NUMBER")=$$GETIEN() Q:BLRERR
 I BLRCMF="C" S BLR("PARENT POINTER")=BLRLEV(BLRLEV,1) S:'BLRATOM BLRPAR=BLR("SEQUENCE NUMBER")
 ;
 D:BLRRSTAG'="" @BLRRSTAG
 D LOINC
 D ^BLRNFLTL           ;UPDATE TRANSACTION LOG
 D:BLRPHASE="R" CRSFLDS
 I 'BLRATOM,BLRCMF="C" S BLRLEV(BLRLEV+1,1)=BLRPAR
 Q
 ;
SET4 ; EP
 ;[LR*5.2*1028;08/20/10;IHS/OIT/MPW]I $D(^LAB(60,BLRTEST1,1,BLRSPEC)) S BLRZ=$G(^LAB(60,BLRTEST1,1,BLRSPEC,0)),BLRUNITS=$P($P(BLRZ,U,7)," ",1),BLR("SITE/SPECIMEN POINTER")=BLRSPEC,BLR("UNITS")=BLRUNITS Q
 I $D(^LAB(60,BLRTEST1,1,BLRSPEC)) D  Q
 .S BLRZ=$G(^LAB(60,BLRTEST1,1,BLRSPEC,0)),BLRUNITS=$P($P(BLRZ,U,7)," ",1)
 .I BLRUNITS=+BLRUNITS,$D(^BLRUCUM(BLRUNITS,0)) S BLRUNITS=$P($G(^BLRUCUM(BLRUNITS,0)),U,1)
 .S BLR("SITE/SPECIMEN POINTER")=BLRSPEC,BLR("UNITS")=BLRUNITS Q
 .Q
 S BLR("SITE/SPECIMEN POINTER")=BLRSPEC
 Q
 ;
CPTCODE ; EP - Entry point
 ; S BLRFOUND=0,(BLRXII,BLRCPTS,BLRCPTP)="" F  S BLRXII=$O(^BLRCPT("C",BLRTEST1,BLRXII)) Q:(BLRXII="")  I '$P($G(^BLRCPT(BLRXII,1)),U,2) D GETCPT Q:BLRFOUND
 S BLRFOUND=0,(BLRXII,BLRCPTS,BLRCPTP)="" F  S BLRXII=$O(^BLRCPT("C",BLRTEST1,BLRXII)) Q:(BLRXII="")  I '$P($G(^BLRCPT(BLRXII,1)),U,2) D GETCPT^BLRTNCON  Q:BLRFOUND  ; IHS/MSC/MKK - LR*5.2*1038
 Q
 ;
GETCPT ; EP
 Q:BLRODTM<$P($G(^BLRCPT(BLRXII,0)),U,3)
 S BLRFOUND=1,BLRCPTP=BLRXII
 S BLRCPTN=0 F BLRNN=1:1 S BLRCPTN=$O(^BLRCPT(BLRXII,11,BLRCPTN)) Q:'BLRCPTN  S BLRCPDAT=$G(^BLRCPT(BLRXII,11,BLRCPTN,0)),BLRCPCD=$P(BLRCPDAT,U),BLRCPCST=$P(BLRCPDAT,U,2),BLRCPRC=$P(BLRCPDAT,U,3),BLRCPACT=$P(BLRCPDAT,U,4) D
 .S (BLRCPTM,BLRCPTQ)=""
 .S BLRCPMN=0 F BLRNN1=1:1 S BLRCPMN=$O(^BLRCPT(BLRXII,11,BLRCPTN,1,BLRCPMN)) Q:'BLRCPMN  S:BLRNN1>1 BLRCPTM=BLRCPTM_"," S BLRCPTM=BLRCPTM_$G(^BLRCPT(BLRXII,11,BLRCPTN,1,BLRCPMN,0))
 .S BLRCPQN=0 F BLRNN1=1:1 S BLRCPQN=$O(^BLRCPT(BLRXII,11,BLRCPTN,2,BLRCPQN)) Q:'BLRCPQN  S:BLRNN1>1 BLRCPTQ=BLRCPTQ_"," S BLRCPTQ=BLRCPTQ_$G(^BLRCPT(BLRXII,11,BLRCPTN,2,BLRCPQN,0))
 .S:BLRNN>1 BLRCPTS=BLRCPTS_";" S BLRCPTS=BLRCPTS_BLRCPCD_"|"_BLRCPCST_"|"_BLRCPRC_"|"_BLRCPACT_"|"_BLRCPTM_"|"_BLRCPTQ
 ;
 K BLRCPCD,BLRCPCST,BLRCPRC,BLRCPACT,BLRCPTN,BLRCPDAT,BLRCPTM,BLRCPMN,BLRCPTQ,BLRCPQN,BLRNN,BLRNN1
 Q
 ;
RESVRS ; EP
 S BLRCREF=$P(BLRL60,U,5)
 I BLRSS=$P(BLRCREF,";"),$D(BLRRVS($P(BLRCREF,";",2))) S BLRRES=BLRRVS($P(BLRCREF,";",2)),BLRNAF=$P(BLRRES,U,2),BLRDUZ=$P(BLRRES,U,4),BLRRES=$P(BLRRES,U) D RES1
 Q
 ;
RES1 ; EP
 I BLRCMF'="C" S BLRDEL=$P($G(^BLRTXLOG(BLR("SEQUENCE NUMBER"),1)),U,2)="D" Q:BLRDEL
 ;IF ERRORS OCCUR HERE BECAUSE OF SEX OR AGE UNDEF. SEE REFERENCE RANGE
 I BLRSPEC'="" S BLRZ=$G(^LAB(60,BLRTEST1,1,BLRSPEC,0)) I BLRZ'="" D
 .S BLRRL=$P(BLRZ,U,2),BLRRH=$P(BLRZ,U,3),BLRUNITS=$P($P(BLRZ,U,7)," ")
 .;[LR*5.2*1028;08/20/10;IHS/OIT/MPW]Added next 1 line
 .I BLRUNITS=+BLRUNITS,$D(^BLRUCUM(BLRUNITS,0)) S BLRUNITS=$P($G(^BLRUCUM(BLRUNITS,0)),U,1)
 .S:$D(^BLRSITE(BLRQSITE,20,BLRQDH,1,BLRLTP,"AGE")) AGE=$G(^("AGE"))
 .S:$D(^BLRSITE(BLRQSITE,20,BLRQDH,1,BLRLTP,"SEX")) SEX=$G(^("SEX"))
 .X:BLRRH'?.N "S BLRRH="_BLRRH X:BLRRL'?.N "S BLRRL="_BLRRL
 .S BLR("UNITS")=BLRUNITS,BLR("REFERENCE HIGH")=BLRRH,BLR("REFERENCE LOW")=BLRRL
 .K AGE,SEX
 .D LOINC
 S BLR("RESULT")=BLRRES,BLR("RESULT N/A FLAG")=BLRNAF,BLR("STATUS FLAG")=$S(BLRRES'="":"R",1:"A")
 S:$G(BLRDUZ)="" BLRDUZ=DUZ
 S BLRDUZN=$S($D(^VA(200,BLRDUZ,0)):$P(^(0),U,1),1:"UNK"_BLRDUZ)
 S BLR("VERIFIER POINTER")=BLRDUZ
 Q
 ;
CRSFLDS ; EP
 K BLR("REFERENCE HIGH"),BLR("REFERENCE LOW"),BLR("RESULT"),BLR("RESULT N/A FLAG")
 S BLR("STATUS FLAG")="A"  ;IHS/ITSC/TPF 10/02/01 ALONG WITH CHNAGE IN LRVER3A+55 FIXES DUPLICATE ENTRIES IN LOG
 Q
 ;
GETIEN() ; EP
 S BLRERR=0 D
 .I BLRCMF="C" D GETNEW Q
 .S BLRCRGL="^BLRTXLOG("_BLRCRSBS_")",BLRENT=$O(@BLRCRGL@(""),BLRDIR)
 .;
 .S:'BLRENT BLRERR=1
 .I BLRENT,BLROKCK'="" D @BLROKCK
 .I 'BLRERR,BLRBADCK'="" D @BLRBADCK
 .I BLRERR D EMSG Q
 .S BLRIEN=BLRENT_"," Q
 Q BLRENT
 ;
CHKDT ; EP
 D:'BLRENT EMSG Q:BLRERR
 S BLRCDT=$P(^BLRTXLOG(BLRENT,12),U)
 I $E(BLRCDT,1,3)=$E(DT,1,3) S BLRIEN=BLRENT_"," Q
 I ($E(BLRCDT,1,3)+1)'=$E(DT,1,3) S BLRERR=1,BLRDTER=1 Q  ;MORE THAN 1 YEAR AHEAD
 I $E(BLRCDT,4,5)<11 S BLRERR=1,BLRDTER=1 Q
 S BLRIEN=BLRENT_"," Q
 Q
EMSG ; EP
 ; Log an error because the crossreference isn't set.
 I 'BLRENT D
 .S BLRERR=1,BLRERROR(1)="Something wrong -- problem with IHS Lab Transaction Log Cross Reference: "_BLRCRGL
 Q
 ;
CKORD ; EP
 S BLRERR=1
 F  D  Q:'BLRENT!'BLRERR
 .S BLRENT1=BLRENT F  Q:'$P(^BLRTXLOG(BLRENT1,1),U)  S BLRENT1=$P(^BLRTXLOG(BLRENT1,1),U)
 .D  Q:'BLRERR
 ..I $D(LRAN) D  Q
 ...I $D(^LRO(68,LRAA,1,LRAD,1,LRAN,4,$P(^BLRTXLOG(BLRENT1,0),U,6))) S BLRERR=0 Q
 ..I $D(^LRO(69,BLRODTM,1,BLRSEQ,2,"B",$P(^BLRTXLOG(BLRENT1,0),U,6))) S BLRERR=0 Q
 .S BLRENT=$O(@BLRCRGL@(BLRENT),BLRDIR)
 K BLRENT1
 Q
 ;
GETNEW ; EP
 S BLRENT=$G(^BLRTXLOG("SEQ"))
 I 'BLRENT S BLRENT=$O(^BLRTXLOG("@"),-1) I BLRENT,'$D(^BLRTXLOG(1)) S BLRENT=0
 F BLRENT=BLRENT+1:1 Q:'$D(^BLRTXLOG(BLRENT))
 S BLRENTS="BLRENTS",BLRENTS(1)=BLRENT,^BLRTXLOG("SEQ")=BLRENT,BLRIEN="+1,"
 Q
 ;
KILL ; EP
 K BLR,BLRARRAY,BLREMSG,BLRENTS,BLRERR,BLRERROR,BLRFDA,BLRI,BLRICNT,BLRIEN,BLRIENS,BLRIII,BLRLOGDA,BLRQUIET,BLRSFID,BLRSIEN,BLRSTOP,BLRT,BLRTCNT,BLRVL,BLRVR,BLRVRS
 K ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE,BLRESTR,BLRPT,BLRXQY0,BLRPC,BLRMI,BLRDTER
 Q
 ;THE FOLLOWING CODE SETS UP FIELDS ADDED FOR THE LOINC PROJECT
LOINC ; EP
 ;FOLLOWING LINES ADDED FOR LOINC PROJECT ;ITSC/TPF 2/26/02
 S:$G(BLRSS)="" BLRSS=$P($G(^LRO(68,$G(BLRAA,"UNDEF"),0)),U,2)
 Q:'$G(BLRTEST1)!'$G(BLRAA)!'$G(BLRAD)!'$G(BLRAN)!'$G(BLRLRDFN)!($G(BLRSS)="")
 S BLR("SITE/SPECIMEN POINTER")=$P($G(^LRO(68,BLRAA,1,BLRAD,1,BLRAN,5,1,0)),U)  ;SITE/SPECIMEN
 ;
 D GETDIAG($S($G(BLRTEST1)'="":BLRTEST1,1:BLRTEST))  ;IHS/ITSC/TPF 10/25/02 'SIGN OR SYMPTOM' LAB POV **1015** ADDED BLRTEST1 TO CHECK FOR BB TESTS
 S:$G(BLRDTC)="" BLRDTC=$P($G(^LRO(69,BLRODT,1,BLRSEQ,1)),U)
 ;
 S BLR("COMPLETE DATE")=$P($G(^LR(BLRLRDFN,BLRSS,9999999-BLRDTC,0)),U,3)
 I $G(BLR("COMPLETE DATE"))="" S BLR("COMPLETE DATE")=$$COMPDATE(BLRLRDFN,BLRSS,9999999-BLRDTC,BLRSS)
 S (SPEC,BLR("COLLECTION SAMPLE POINTER"))=$P($G(^LRO(68,BLRAA,1,BLRAD,1,BLRAN,5,1,0)),U,2)  ;COLLECTION SAMPLE  
 S:$G(BLR("SITE/SPECIMEN POINTER")) (LOINC,BLR("LOINC CODE"))=$P($G(^LAB(60,BLRTEST1,1,BLR("SITE/SPECIMEN POINTER"),95.3)),U)
 ;
 ; ----- BEGIN IHS/MSC/MKK - LR*5.2*1038
 NEW IHSLOINC
 S IHSLOINC=$$GET1^DIQ(60,BLRTEST1,"IHS LOINC","I")
 Q:$L(IHSLOINC)<1
 ;
 S:$L($G(LOINC))<1 LOINC=IHSLOINC
 S BLR("IHS LOINC")=IHSLOINC
 ; ----- END IHS/MSC/MKK - LR*5.2*1038
 ;
 ;END CODE FOR LOINC PROJECT
 Q
 ;complete date from lab order entry and entry in lab test file do not
 ;necessarily match
COMPDATE(BLRLRDFN,BLRSS,BLRDTC,BLRACCN) ; EP
 N SDATE,CDATE
 S SDATE=BLRDTC
 ;
 I $D(^LR(BLRLRDFN,BLRSS,BLRDTC,0)) S TARACC=$P($G(^LR(BLRLRDFN,BLRSS,BLRDTC,0)),U,6)=BLRACCN I TARACC S CDATE=$P($G(^LR(BLRLRDFN,BLRSS,BLRDTC,0)),U,3)
 ;GO FORWARD 
 I $G(CDATE)="" D
 .F  S SDATE=$O(^LR(BLRLRDFN,BLRSS,SDATE)) Q:+SDATE=0  I SDATE'="" S TARACC=$P($G(^LR(BLRLRDFN,BLRSS,SDATE,0)),U,6)=BLRACCN I TARACC S CDATE=$P($G(^LR(BLRLRDFN,BLRSS,SDATE,0)),U,3)
 ;GO BACKWARD 
 I $G(CDATE)="" D
 .F  S SDATE=$O(^LR(BLRLRDFN,BLRSS,SDATE),-1) Q:+SDATE=0  I SDATE'="" S TARACC=$P($G(^LR(BLRLRDFN,BLRSS,SDATE,0)),U,6)=BLRACCN I TARACC S CDATE=$P($G(^LR(BLRLRDFN,BLRSS,SDATE,0)),U,3)
 K SDATE
 Q $G(CDATE)
 ;