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

BLRAG02.m

Go to the documentation of this file.
  1. BLRAG02 ; IHS/MSC/SAT - LABORATORY ACCESSION GUI RPCS ; MAY 23, 2013 1500; SAT
  1. ;;5.2;IHS LABORATORY;**1031,1032**;NOV 01, 1997;Build 185
  1. ;
  1. ;return all accessioned lab records - RPC
  1. ABD(BLRY,BLRBDT,BLREDT,BLRDFN,BLRDEV) ;return all accessioned records for given date range - RPC
  1. ; RPC Name is BLR ALL-ACCESSIONED
  1. ;INPUT
  1. ; BLRBDT = (optional) Begin Date in external date form
  1. ; defaults to 'today'
  1. ; BLREDT = (optional) End Date in external date form
  1. ; defaults to BLRBDT
  1. ; BLRDFN = (optional) return all accessioned lab records for this
  1. ; given patient only
  1. ; return for all patients of this parameters is not defined
  1. ; BLRDEV = Printer for Manifest reprinting - IEN pointer to the DEVICE file
  1. ; No printing will occur if null or undefined in the DEVICE file
  1. ;
  1. ;return all accessioned records for given date range - RPC
  1. ; DFN = patient IEN, pointer to VA PATIENT file 2
  1. ; PNAME = patient name as defined in the NAME field .01
  1. ; of the Va PATIENT file 2
  1. ; ACCESSION_# = as defined in the ACCESSION file 68
  1. ; UID = as defined in the LAB ORDER ENTRY file 69
  1. ; TEST_NAME = as defined in the NAME field .01 of the
  1. ; LABORATORY TEST file 60
  1. ; COLLECTION_STATUS = as defined under the SPECIMEN Multiple in the
  1. ; LAB ORDER ENTRY file 69
  1. ; REF_LAB_NAME = as defined in the REF LAB NAME FOR SHIP MANIFEST
  1. ; field in the BLR MASTER CONTROL file
  1. ; Client_# = all Client account numbers as defined in the
  1. ; BLR MASTER CONTROL file 9009029 separated by pipe |
  1. ; CHART_# = patient HCRN for area
  1. ; COLLECTION_DATE_TIME = date/time of specimen collection external format
  1. ; PROVIDER_NAM = name of person signing for the order
  1. ; LRO69_POINTERS = list of TEST POINTERS to LAB ORDER ENTRY file 69
  1. ; BLRDT:BLRSP:BLRTEST
  1. ; BLRDT = Date pointer to the LAB ORDER ENTRY file 69
  1. ; BLRSP = Specimen pointer to the LAB ORDER ENTRY FILE 69
  1. ; BLRTEST = Test pointer to the LAB ORDER ENTRY FILE 69
  1. ; ACCESSION_AREA_IEN = Accession Area pointer to file 68
  1. ; ACCESSION_AREA_NAM = Accession Area name from file 68
  1. ; ORDER_NUMBER = Unique order number to identify the specimen
  1. ;
  1. N BLR60NAM,BLR62NAM,BLRSPNS,BLRTOP
  1. N BLRCS
  1. N BLRACCNO,BLRDT,BLRHCRN,BLRI,BLRIFNL,BLRJ,BLRK,BLRLCNT,BLRLI,BLRLRDFN,BLRLST,BLRLSTI,BLROI
  1. N BLRLTMP,BLRNODS,BLRNODT,BLROERR,BLROLOC,BLRPADD
  1. N BLRPHRN,BLRPNAM,BLRSEX,BLRSP,BLRT,BLRTI,BLRTMP
  1. K ^TMP("BLRAG02",$J) ;used to keep records for same patient together
  1. S (BLRPAD1,BLRPAD2,BLRPAD3,BLRPADC,BLRPADS,BLRPADZ,BLRTMP)=""
  1. D ^XBKVAR S X="ERROR^BLRAGUT",@^%ZOSF("TRAP")
  1. K BLRIFNL,BLRLTMP
  1. S (BLRI,BLRLCNT,BLROI,BLRTI)=0
  1. K ^TMP("BLRAG",$J)
  1. S BLRY="^TMP(""BLRAG"","_$J_")"
  1. S ^TMP("BLRAG",$J,0)="ERROR_ID"
  1. S BLRTMP=""
  1. ;
  1. ;if begin date is null, default to today
  1. I $G(BLRBDT)="" S BLRBDT=$$HTFM^XLFDT($H,1)
  1. E D
  1. .;convert external date to FM format
  1. .S X=BLRBDT,%DT="XT" D ^%DT S BLRBDT=$P(Y,".")
  1. .;default to 'today' if invalid date passed in
  1. .S:$$FR^XLFDT($G(BLRBDT)) BLRBDT=$$HTFM^XLFDT($H,1)
  1. ;
  1. ;if end date is null, default to begin date
  1. I $G(BLREDT)="" S BLREDT=BLRBDT
  1. E D
  1. .;convert external date to FM format
  1. .S X=BLREDT,%DT="XT" D ^%DT S BLREDT=$P(Y,".")
  1. .;default to begin date if invalid date passed in
  1. .S:$$FR^XLFDT($G(BLREDT)) BLREDT=BLRBDT
  1. S BLRDFN=$G(BLRDFN)
  1. ;
  1. K BLRDTCK S BLRDTCK=""
  1. ;
  1. ;Only need to look at beginning based on BLRBDT for Yearly, Monthly, and Quarterly transforms.
  1. ; If the date range crosses years, months,or quarters, the Daily will catch them.
  1. ;look for accessions with yearly ACCESSION TRANSFORMS
  1. S BLRDATE=$E(BLRBDT,1,3)_"0000" S BLRDTCK(BLRDATE)=""
  1. S BLRAFMSC="" F S BLRAFMSC=$O(^LRO(69,"AFMSC",BLRDATE,BLRAFMSC)) Q:BLRAFMSC="" D ABDA
  1. ;
  1. ;look for accessions with monthly ACCESSION TRANSFORMS
  1. S BLRDATE=$E(BLRBDT,1,5)_"00"
  1. I '$D(BLRDTCK(BLRDATE)) D
  1. .S BLRDTCK(BLRDATE)=""
  1. .S BLRAFMSC="" F S BLRAFMSC=$O(^LRO(69,"AFMSC",BLRDATE,BLRAFMSC)) Q:BLRAFMSC="" D ABDA
  1. ;
  1. ;look for accessions with quarterly ACCESSION TRANSFORMS
  1. S BLRTN=+($E(BLRBDT,4,5)\3) S BLRTN=(BLRTN*3)+1 S BLRDATE=$E(BLRBDT,1,3)_$S(BLRTN<10:"0",1:"")_BLRTN_"00"
  1. I '$D(BLRDTCK(BLRDATE)) D
  1. .S BLRDTCK(BLRDATE)=""
  1. .S BLRAFMSC="" F S BLRAFMSC=$O(^LRO(69,"AFMSC",BLRDATE,BLRAFMSC)) Q:BLRAFMSC="" D ABDA
  1. ;
  1. ;look for accessions in given date range (daily ACCESSION TRANSFORMS)
  1. S BLRDATE=BLRBDT-1 F S BLRDATE=$O(^LRO(69,"AFMSC",BLRDATE)) Q:BLRDATE'>0 Q:BLRDATE>BLREDT D
  1. .I '$D(BLRDTCK(BLRDATE)) D
  1. ..S BLRAFMSC="" F S BLRAFMSC=$O(^LRO(69,"AFMSC",BLRDATE,BLRAFMSC)) Q:BLRAFMSC="" D ABDA
  1. ;
  1. D ABDHD
  1. S BLRJ="" F S BLRJ=$O(^TMP("BLRAG02",$J,BLRJ)) Q:BLRJ="" D
  1. .S BLRK="" F S BLRK=$O(^TMP("BLRAG02",$J,BLRJ,BLRK)) Q:BLRK="" D
  1. ..S BLRI=BLRI+1
  1. ..S ^TMP("BLRAG",$J,BLRI)=^TMP("BLRAG02",$J,BLRJ,BLRK)
  1. ;
  1. ;S BLRI=BLRI+1
  1. ;S ^TMP("BLRAG",$J,BLRI)=$C(31)
  1. Q
  1. ;
  1. ABDA ;
  1. S BLRDT=$P(BLRAFMSC,"|",1) ; Order Date
  1. S BLRSP=$P(BLRAFMSC,"|",2) ; Order Specimen
  1. S BLRT=$P(BLRAFMSC,"|",3) ; Order Test
  1. ;
  1. S BLRORD=$P($G(^LRO(69,BLRDT,1,BLRSP,.1)),U,1) ; Order #
  1. Q:$G(BLRORD)="" ; Quit if no Order #
  1. ;
  1. S BLRNODS1=$G(^LRO(69,BLRDT,1,BLRSP,1)) ; specimen mult collection node
  1. S BLRCTIM=$P(BLRNODS1,U,1) ; Collection Time
  1. Q:+BLRCTIM<1 ; Quit if Collection time is null
  1. ;
  1. Q:$P(BLRCTIM,".")<$P(BLRBDT,".")!($P(BLRCTIM,".")>$P(BLREDT,".")) ; IHS/MSC/MKK - BLR*5.2*1032 -- Quit if collection date not today, no matter the Accession Area.
  1. ;
  1. S BLRNODS=$G(^LRO(69,BLRDT,1,BLRSP,0)) ; specimen mult node
  1. S BLR62NAM=$P($G(^LAB(62,+$P(BLRNODS,U,3),0)),U,1) ; Collection Sample
  1. ;
  1. S LRDOC=""
  1. S (BLRDOC,X)=$P(BLRNODS,U,6) D DOC^LRX
  1. S BLRDOCN=$E(LRDOC,1,25) ; Provider
  1. S BLRCS=$P($G(^LRO(69,BLRDT,1,BLRSP,1)),U,4) ; Collection status
  1. S BLROLOC=$P(BLRNODS,U,9) ; Ordering Location
  1. ;
  1. S BLRNODT=$G(^LRO(69,BLRDT,1,BLRSP,2,BLRT,0)) ; test mult node
  1. I $P(BLRNODT,U,3)'="" D ; Accession Date
  1. .I $P(BLRNODT,U,9)'="CA" D ; Status
  1. ..I ($E($P(BLRNODT,U,3),6,7)="00")!(($P(BLRNODT,U,3)>=BLRBDT)&($P(BLRNODT,U,3)<=BLREDT)) D ;accession date is in range
  1. ...S BLRLRDFN=$P(BLRNODS,U,1) ; lab data IEN
  1. ...S BLRLRNOD=$G(^LR(BLRLRDFN,0)) ; Lab Data file Patient node
  1. ...I $P(BLRLRNOD,U,2)=2 D
  1. ....S BLRPDFN=$P(BLRLRNOD,U,3) ; patient IEN
  1. ....I BLRDFN'="" Q:BLRDFN'=BLRPDFN ; IFF passed in DFN, then only collect data for that patient
  1. ....;
  1. ....S BLRPNAM=$P(^DPT(BLRPDFN,0),U,1) ; patient name
  1. ....S BLRACCNI=$P(BLRNODT,U,5) ; accession number (internal pointer to file 68)
  1. ....S BLRAREA=$P(BLRNODT,U,4) ; accession area
  1. ....S BLRAREAN=$P($G(^LRO(68,BLRAREA,0)),U,1) ; accession area name
  1. ....S BLRDATE=$P(BLRNODT,U,3) ; accession date
  1. ....S BLRACCNO=$P($G(^LRO(68,BLRAREA,1,BLRDATE,1,BLRACCNI,.2)),U,1) ; Accession Number string
  1. ....S BLRUID=$P($G(^LRO(69,BLRDT,1,BLRSP,2,BLRT,.3)),U,1) ; UID
  1. ....; S BLR60NAM=$$GET1^DIQ(60,$P(BLRNODT,U,1)_",",.01) ; test name
  1. ....S BLR60NAM=$$TESTNAME^BLRAGUT(+$P(BLRNODT,U,1)) ;get test name
  1. ....S BLRHCRN=$$HRCN^BDGF2(BLRPDFN,DUZ(2)) ; chart number - HCRN
  1. ....S BLR68TST=$O(^LRO(68,BLRAREA,1,BLRDATE,1,BLRACCNI,4,"B",$P(BLRNODT,U,1),0))
  1. ....S BLRRLNAM=$P($G(^BLRSITE(DUZ(2),"RL")),U,20) ; lab name
  1. ....S BLRCLN=$P($G(^LRO(69,BLRDT,1,BLRSP,2,BLRT,"MSC")),U,1) ; client number
  1. ....;
  1. ....;S BLRMAN=$P($G(^LRO(68,BLRAREA,1,BLRDATE,1,BLRACCNI,4,BLR68TST,0)),U,10)
  1. ....;S BLRINV=$$GET1^DIQ(62.8,BLRMAN_",",.01) ; invoice number
  1. ....;S BLRCONF=$$GET1^DIQ(62.8,BLRMAN_",",.02) ; shipping configuration
  1. ....;S BLRSTAT=$$GET1^DIQ(62.8,BLRMAN_",",.03) ; shipping status
  1. ....;
  1. ....S BLRTI=BLRTI+1
  1. ....;
  1. ....; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
  1. ....S ^TMP("BLRAG02",$J,BLRPDFN,BLRTI)=BLRPDFN_U_BLRPNAM_U_BLRACCNO_U_BLRUID_U_BLR60NAM_U_BLRCS_U_BLRRLNAM_U_BLRCLN_U_BLRHCRN_U_$$FMTE^XLFDT(BLRCTIM,"5M")_U_BLRDOCN_U_BLRDT_":"_BLRSP_":"_BLRT_U_BLRAREA_U_BLRAREAN_U_BLRORD
  1. ;
  1. Q
  1. ;
  1. ABDHD ;
  1. S BLRTMP="T00020DFN^T00020PNAME^T00020ACCESSION_#^T00020UID^T00020TEST_NAME^T00020COLLECTION_STATUS^"
  1. S BLRTMP=BLRTMP_"T00020REF_LAB_NAME^T00020Client_#^T00020CHART_#^T00020COLLECTION_DATE_TIME^"
  1. S BLRTMP=BLRTMP_"T00020PROVIDER_NAM^T00020LRO69_POINTERS^T00020ACCESSION_AREA_IEN^T00020ACCESSION_AREA_NAM^"
  1. S BLRTMP=BLRTMP_"T00020ORDER_NUMBER"
  1. S ^TMP("BLRAG",$J,0)=BLRTMP
  1. Q
  1. ;
  1. CLIENT() ;
  1. N BLRCN,BLRRET
  1. S BLRRET=""
  1. S BLRCN=$O(^BLRSITE(DUZ(2),"RLCA",0))
  1. S:BLRCN'="" BLRRET=$G(^BLRSITE(DUZ(2),"RLCA",BLRCN,0))
  1. I BLRCN'="" F S BLRCN=$O(^BLRSITE(DUZ(2),"RLCA",BLRCN)) Q:BLRCN'>0 D
  1. .S BLRRET=BLRRET_"|"_$G(^BLRSITE(DUZ(2),"RLCA",BLRCN,0))
  1. Q BLRRET
  1. ;
  1. ABR(BLRY,BLRUID,BLRLMF,BLRDEV) ;reprint accession label or manifest - RPC
  1. ; RPC Name is BLR ACCESSION PRINT
  1. ; .BLRY = returned pointer to appointment data
  1. ;INPUT:
  1. ; BLRUID = UIDs of accession to reprint delimited by ^
  1. ; BLRLMF = label or manifest flag 0=label (default); 1=manifest
  1. ; BLRDEV = Printer for Manifest printing - IEN pointer to the DEVICE file
  1. ;RETURNS:
  1. ; ERROR_ID = 0=clean
  1. ;
  1. N BLRC1,BLRC2,BLRC3,BLRERR,BLRI,BLRJ,BLRUID1
  1. N LRAA,LRAD,LRAN,LRODT,LRSN
  1. S BLRERR=0
  1. D ^XBKVAR S X="ERROR^BLRAGUT",@^%ZOSF("TRAP")
  1. K BLRIFNL,BLRLTMP
  1. S BLRI=0
  1. K ^TMP("BLRAG",$J)
  1. S BLRY="^TMP(""BLRAG"","_$J_")"
  1. S ^TMP("BLRAG",$J,0)="ERRORID"
  1. I $G(BLRLMF)="" S BLRLMF=0 ;default to label
  1. I '+$G(BLRUID) D ERR^BLRAGUT("BLRAG02: Invalid UID") Q
  1. ;
  1. I BLRLMF S IOP="`"_+$G(BLRDEV) D ^%ZIS
  1. F BLRJ=1:1:$L(BLRUID,"^") D
  1. .S BLRUID1=$P(BLRUID,"^",BLRJ)
  1. .S:'$D(^LRO(68,"C",BLRUID1)) BLRUID1=$P($G(^LRO(69,+$P(BLRUID1,":",1),1,+$P(BLRUID1,":",2),2,+$P(BLRUID1,":",3),.3)),"^",1)
  1. .Q:BLRUID1=""
  1. .S LRAA=$O(^LRO(68,"C",BLRUID1,0)) Q:LRAA=""
  1. .S LRAD=$O(^LRO(68,"C",BLRUID1,LRAA,0)) Q:LRAD=""
  1. .S LRAN=$O(^LRO(68,"C",BLRUID1,LRAA,LRAD,0)) Q:LRAN=""
  1. .I 'BLRLMF D ;print labels
  1. ..S BLRDEVN=$P($G(^LAB(69.9,1,3.5,+DUZ(2),0)),U,3) ;do not use passed in printer for labels; only manifest printer is passed in
  1. ..S BLRDEV=$O(^%ZIS(1,"B",BLRDEVN,0))
  1. ..I BLRDEV>0 D
  1. ...D LBLTYP^BLRAG02A ;D LBLTYP^LRLABLD
  1. ...S IOP=$P($G(^%ZIS(1,BLRDEV,0)),U,1)
  1. ...D ^%ZIS
  1. ...Q:POP
  1. ...S LRLABLIO=ION_";"_IOST_";"_IOM_";"_IOSL
  1. ...U IO
  1. ...D PRINT^LRLABXT
  1. ...D ^%ZISC
  1. .I BLRLMF D ;print manifests
  1. .. D RPRT(+$O(^BLRSHPM("B",BLRUID1,0)),$G(BLRDEV))
  1. I BLRDEV>0 S ^TMP("BLRAG",$J,0)="CLEAN" S BLRI=BLRI+1 S ^TMP("BLRAG",$J,BLRI)=0
  1. I BLRDEV<1 S BLRI=BLRI+1 S ^TMP("BLRAG",$J,BLRI)=1
  1. Q
  1. ;
  1. RPRT(RIEN,BLRDEV) ;-- reprint
  1. U $$DEV($G(BLRDEV))
  1. N BLRDA
  1. S BLRDA=0 F S BLRDA=$O(^BLRSHPM(RIEN,11,BLRDA)) Q:'BLRDA D
  1. . W !,$G(^BLRSHPM(RIEN,11,BLRDA,0))
  1. D ^%ZISC
  1. Q
  1. ;
  1. DEV(BLRDEV) ;-- device handler
  1. ; Return updated IO
  1. ; Return -1 error if device not defined at ^BLRSITE(<site>,"RL")
  1. S DEV=""
  1. I $G(BLRDEV)'="" S DEV=BLRDEV
  1. ;I DEV'="" S DEV=$$GET1^DIQ(3.5,BLRDEV_",",.01)
  1. S:DEV="" DEV=$S($P($G(^BLRSITE(DUZ(2),"RL")),U,2)]"":$P($G(^BLRSITE(DUZ(2),"RL")),U,2),1:"") ;blr master control file
  1. I DEV="" Q -1
  1. S IOP="`"_DEV
  1. D ^%ZIS
  1. Q IO
  1. ;
  1. UL(BLRY) ; rpc to return the value of the 'REF LAB USING LEDI?' field in the BLR MASTER CONTROL file
  1. ; RPC: BLR REF LAB USING LEDI
  1. ;Returns:
  1. ; (0) REF LAB USING LEDI? = 0='no'=CACHE (default); 1='yes'=ENSEMBLE
  1. ; (1) REF LAB BILLING TYPE = C=client
  1. ; P=patient
  1. ; T=third party
  1. ; (2) CURRENT USER IEN = pointer to VA PATIENT file 2
  1. ; (3) CURRENT USER NAME = value of NAME field in VA PATIENT
  1. ; (4) PT CONFIRM = Patient Confirmation enabled
  1. ; 0='no' (default); 1='yes'
  1. ; (5) USE INS SEQ = value of REF LAB USE INSURANCE SEQ
  1. ; 0='no' (default); 1='yes'
  1. ; (6) CLIENT ACC LIST = list of values from the
  1. ; REF LAB CLIENT ACCOUNT NUMBER multiple
  1. ; in BLR MASTER CONTROL separated by pipe |
  1. ; (7) DEF DEV MANIFEST = REF LAB DEV FOR SHIP MANIFEST
  1. ; default printer for Shipping Manifest
  1. ; ien pointer to the DEVICE file
  1. ;
  1. ;N BLRDOM,BLRENT,BLRPAR
  1. K ^TMP("BLRAG",$J)
  1. D ^XBKVAR S X="ERROR^BLRAGUT",@^%ZOSF("TRAP")
  1. S BLRY="^TMP(""BLRAG"","_$J_")"
  1. S ^TMP("BLRAG",$J,0)="ERROR_ID"
  1. N BLRBILL,BLRCANI,BLRCANL,BLRISEQ,BLRLEDI,BLRPTCF,BLRRET,BLRSITE,BLRUSERN
  1. S BLRCANL=""
  1. I '+$G(DUZ) D ERR^BLRAGUT("BLRAG02: Invalid user defined.") Q
  1. S BLRSITE=$G(^BLRSITE(DUZ(2),"RL"))
  1. S BLRLEDI=+$P(BLRSITE,U,22) ; REF LAB USING LEDI?
  1. S BLRBILL=$P(BLRSITE,U,15) ; REF LAB BILLING TYPE
  1. S BLRRET=$P($G(^BLRSITE(DUZ(2),"RL")),U,22)
  1. S BLRDEVM=$P(BLRSITE,U,2) ;get default printer for Shipping Manifest
  1. S BLRUSERN=$$GET1^DIQ(200,DUZ_",",.01) ;get user name
  1. S BLRPTCF=$$PTC^BLRAGUT() ;get patient confirmation flag
  1. S BLRISEQ=+$P(BLRSITE,U,21) ;get REF LAB USE INSURANCE SEQ
  1. S BLRCANI=$O(^BLRSITE(DUZ(2),"RLCA",0)) S:BLRCANI>0 BLRCANL=$P($G(^BLRSITE(DUZ(2),"RLCA",BLRCANI,0)),U,1)
  1. I BLRCANI>0 F S BLRCANI=$O(^BLRSITE(DUZ(2),"RLCA",BLRCANI)) Q:BLRCANI'>0 S BLRCANL=BLRCANL_"|"_$P($G(^BLRSITE(DUZ(2),"RLCA",BLRCANI,0)),U,1)
  1. S ^TMP("BLRAG",$J,0)="T00020USING_LEDI?^T00020BILLING_TYPE^T00020CURRENT_USER_IEN^T00020CURRENT_USER_NAME^T00020PT_CONFIRM^T00020USE_INS_SEQ^T00100CLIENT_ACC_LIST^T00020DEF_DEV_MANIFEST"
  1. S ^TMP("BLRAG",$J,1)=+BLRLEDI_U_$G(BLRBILL)_U_DUZ_U_BLRUSERN_U_BLRPTCF_U_BLRISEQ_U_BLRCANL_U_BLRDEVM
  1. Q