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

BLRLUAC1.m

Go to the documentation of this file.
BLRLUAC1 ; IHS/OIT/MKK - IHS LRUPAC 1, main driver ; 22-Oct-2013 09:22 ; MKK
 ;;5.2;IHS LABORATORY;**1030,1033**;NOV 01, 1997
 ;;
 ;; Emulates the Lab accession and test counts Report.
 ;; Should be more Accurate.
 ;;
EP ; EP 
 NEW BLRDUZ,CNT,COMPDATE,DATANAME,DATETIME,DFN,DINVBEG
 NEW DINVEND,ERRORS,F44IEN,FILE4IEN,HEADER,LAB60IEN,L60DESC
 NEW LABTEST,LOCPIECE,LOGOFF,LOGON,LRAA,LRAD,LRAN,LRAS
 NEW LRDFN,LRDFNCNT,LRIDT,LRSSOCNT,PURGDATE,SELRAA
 NEW SELRAAAB,SELRAAAN,SELLRSS,SOMEDATA,SPECTYPE,SPECNAME
 NEW SPTKNDAT,SRCHDN,STR,STR0,TESTLOC,TODAY,VMICIEN,VBBIEN
 NEW VISITIEN,VLABCNT,VLABFND,VLABIEN,XTMPNODE
 ;
 S HEADER(1)="Count Accessioned Tests"
 ;
 Q:$$GETACCSA()="Q"
 ;
 Q:$$GETDATER()="Q"
 ;
 D TASKEDGD
 ;
 Q
 ;
GETACCSA() ; EP -- Get Accession Area
 D HEADERDT^BLRGMENU
 ;
 D ^XBFMK
 S DIR(0)="PO^68"
 S DIR("A")="Select ACCESSION AREA"
 D ^DIR
 I +$G(Y)<1!(+$G(DIRUT)) D PROGEND("Invalid/No Entry.")  Q "Q"
 ;
 S SELRAA=+$G(Y)
 ;
 ; Accession Area Abbreviation
 S SELRAAAB=$$GET1^DIQ(68,SELRAA,"ABBREVIATION",,,"ERRORS")
 I $D(ERRORS)>0 D PROGEND("Could not Find Accession Abbreviation.")  Q "Q"
 ;
 ; Accession Area Name
 S SELRAAAN=$$GET1^DIQ(68,SELRAA,"AREA",,,"ERRORS")
 I $D(ERRORS)>0 D PROGEND("Could not Find Accession Area.")  Q "Q"
 ;
 ; Accession Area LR Subscript
 S LRSS=$$GET1^DIQ(68,SELRAA,"LR SUBSCRIPT",,,"ERRORS")  ; LR Subscript
 I $D(ERRORS)>0 D PROGEND("Could not Find LR Subscript.")  Q "Q"
 ;
 S SELLRSS=$E(LRSS,1,2)   ; Lab Data File D1 node
 ;
 Q "OK"
 ;
GETDATER() ; EP - Get Date Range
 D HEADERDT^BLRGMENU
 D B^LRU             ; Get beginning (LRSDT) & ending (LRLDT) dates
 ;
 I $L(Y)<1!($G(Y)=-1) D PROGEND("Invalid/No Date Range Entered.")  Q "Q"
 ;
 Q "OK"
 ;
TASKEDGD ; EP - Setup routine for TaskMan
 NEW BLRDUZ,IOP,ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE,ZTSK
 ;
 W !!!,"Queuing Compilation",!
 ;
 S ZTRTN="TGETDATA^BLRLUAC1"
 S ZTDESC="BLRLUAC1 Compilation"
 ;
 M BLRDUZ=DUZ
 S ZTSAVE("*")=""
 S ZTDTH=$H
 S ZTIO=""
 S IOP="Q"
 D ^%ZTLOAD
 W !,?4,"Job ",ZTSK," Queued",!
 D PRESSKEY^BLRGMENU(9)
 Q
 ;
TGETDATA ; EP - Tasked GETDATA
 I $D(ZTQUEUED) S ZTREQ="@"
 D TASKDATI
 ;
 F  S LRDFN=$O(^LR(LRDFN))  Q:LRDFN<1  D
 . ; S DFN=$P($G(^LR(LRDFN,0)),"^",3)
 . S DFN=+$P($G(^LR(LRDFN,0)),"^",3)     ; IHS/OIT/MKK - LR*5.2*1033 - DFN Must be an integer
 . S LRIDT=DINVEND
 . F  S LRIDT=$O(^LR(LRDFN,LRSS,LRIDT))  Q:LRIDT<1!(LRIDT>DINVBEG)  D
 .. S STR0=$G(^LR(LRDFN,LRSS,LRIDT,0))
 .. Q:$L(STR0)<1                         ; Skip if no data
 .. ;
 .. S LRAS=$P(STR0,"^",6)                ; Accession Number
 .. Q:$P(LRAS," ")'=SELRAAAB             ; Skip if not Selected Acc
 .. ;
 .. S SPTKNDAT=+$P(STR0,"^")             ; Specimen Taken Date
 .. S COMPDATE=+$P(STR0,"^",3)           ; Completed Date
 .. ; S SPECTYPE=$P(STR0,"^",5)            ; Specimen Type
 .. S SPECTYPE=+$P(STR0,"^",5)           ; IHS/OIT/MKK - LR*5.2*1033 - Specimen Type Must be an integer
 .. ;
 .. S LRIDT($P(LRIDT,"."))=SPTKNDAT
 .. ;
 .. D @(LRSS_"DATA")                     ; Do Specific Breakout
 .. D LDORDSRT                           ; Hospital Location Sort
 .. S CNT=CNT+1
 ;
 S:SOMEDATA<1 ^BLRLUPAC(DATETIME,"GETDATA2 Compilation Failed.")=""
 S:SOMEDATA>0 ^BLRLUPAC(DATETIME,"COMPILED")=$$DT^XLFDT_"^"_$H
 ;
 D DONEGETD
 ;
 Q
 ;
TASKDATI ; EP - Tasked Initialization of variables
 S TODAY=$$DT^XLFDT
 S PURGDATE=$$FMADD^XLFDT(TODAY,30)
 ;
 S LRDFN=.9999999,LRSS=SELLRSS
 ;
 S DINVEND=9999999-$$FMADD^XLFDT(LRLDT,1)
 S DINVBEG=9999999-$$FMADD^XLFDT(LRSDT,-1)
 ;
 S (CNT,LRDFNCNT,ORDCNT,SOMEDATA)=0
 S LOGON=$$HTFM^XLFDT($H)              ; Set Login Date/Time
 S DATETIME=LOGON
 K ^BLRLUPAC(DATETIME)
 ;
 Q
 ;
DONEGETD ; EP - Compilation DONE; send E-mail
 NEW STR
 ;
 S STR(1)="Compilation of Lab Accession and Test counts Report Completed."
 S STR(2)=" "
 S STR(3)="Accession Area:"_SELRAAAN_" ("_SELRAAAB_")"
 S STR(4)=" "
 S STR(5)="Date Range: "_$$FMTE^XLFDT(LRSDT,"5MZ")_" thru "_$$FMTE^XLFDT(LRLDT,"5MZ")_"."
 S STR(6)=" "
 S LOGOFF=$$HTFM^XLFDT($H)
 S STR(7)="START="_$$LJ^XLFSTR($$FMTE^XLFDT(LOGON,"5MZ"),18)_"END="_$$FMTE^XLFDT(LOGOFF,"5MZ")
 S STR(8)="     Compilation took:"_$$FMDIFF^XLFDT(LOGOFF,LOGON,3)
 S STR(9)=" "
 S STR(10)="Date/Time of compilation:"_$$FMTE^XLFDT(DATETIME,"5MZ")
 ;
 I SOMEDATA<1 D
 . S STR(11)=" "
 . S STR(12)=" >>> NO DATA GATHERED.  REPORTS WILL BE EMPTY. <<<"
 . S STR(13)=" "
 ;
 D SENDMAIL(.STR)
 ;
 Q
 ;
SENDMAIL(STR) ; EP - SEND MAIL when tasked GETDATA complete
 NEW XMDUZ,XMMG,XMSUB,XMTEST,XMY,XMZ
 ;
 S XMY(BLRDUZ)=""
 ;
 S LRBLNOW=$E($$NOW^XLFDT,1,12)
 ;
 S XMSUB=$G(STR(1))
 S XMTEXT="STR("
 S XMDUZ="BLRLUAC1"
 S XMZ="NOT OKAY"
 D ^XMD
 ;
 I $G(XMMG)'=""!(XMZ="NOT OKAY") D
 . S NOW=$H
 . S ^XTMP("BLRLUPAC",DATETIME,0)=$$FMADD^XLFDT(TODAY,7)_"^"_TODAY_"^BLRLUPAC Message"
 . S ^XTMP("BLRLUPAC",DATETIME,NOW,"MAILMAN ERROR")=""
 . S ^XTMP("BLRLUPAC",DATETIME,NOW,"MAILMAN ERROR","XMZ")=XMZ
 . S ^XTMP("BLRLUPAC",DATETIME,NOW,"MAILMAN ERROR","XMMG")=XMMG
 ;
 Q
 ;
CHDATA ; EP - "CH" Data
 Q:(COMPDATE<LRSDT)!(COMPDATE>LRLDT)     ; Skip if not in Date Range
 ;
 S DATANAME=1.9999999
 F  S DATANAME=$O(^LR(LRDFN,LRSS,LRIDT,DATANAME))  Q:DATANAME<1  D
 . Q:DATANAME=9009027   ; Skip E-Sig Node
 . ;
 . ; Skip Pending tests
 . ; Q:$$UP^XLFSTR($G(^LR(LRDFN,LRSS,LRIDT,DATANAME)))["PENDING"
 . ;
 . S SRCHDN="CH;"_DATANAME_";1"
 . S LAB60IEN=+$O(^LAB(60,"C",SRCHDN,0))
 . I LAB60IEN<1 D STORERRS(LRDFN,LRSS,LRIDT,DATANAME,LAB60IEN,"No Test Associated with Dataname")  Q
 . ;
 . S SOMEDATA=SOMEDATA+1
 . D TOPOGSRT
 . D LATSTSRT
 . ; D CHORDSRT
 . D INSTFSRT
 . ;
 Q
 ;
TOPOGSRT ; EP - Topography File sort
 S:$D(^BLRLUPAC(DATETIME,"SPECSORT"))<1 ^BLRLUPAC(DATETIME,"SPECSORT")=SELRAAAB_"^"_LRSDT_"^"_LRLDT
 S ^BLRLUPAC(DATETIME,"SPECSORT",SPECTYPE)=1+$G(^BLRLUPAC(DATETIME,"SPECSORT",SPECTYPE))
 S ^BLRLUPAC(DATETIME,"SPECSORT",SPECTYPE,LAB60IEN)=1+$G(^BLRLUPAC(DATETIME,"SPECSORT",SPECTYPE,LAB60IEN))
 Q
 ;
LATSTSRT ; EP - V File - Laboratory Test File sort
 S:$D(^BLRLUPAC(DATETIME,"TESTSORT"))<1 ^BLRLUPAC(DATETIME,"TESTSORT")=SELRAAAB_"^"_LRSDT_"^"_LRLDT
 S ^BLRLUPAC(DATETIME,"TESTSORT",LAB60IEN)=1+$G(^BLRLUPAC(DATETIME,"TESTSORT",LAB60IEN))
 S ^BLRLUPAC(DATETIME,"TESTSORT",LAB60IEN,SPECTYPE)=1+$G(^BLRLUPAC(DATETIME,"TESTSORT",LAB60IEN,SPECTYPE))
 Q
 ;
CHORDSRT ; EP - CH Hospital Location sort
 NEW DNHOLDER
 ;
 S DNHOLDER=$S($L($G(DATANAME)):$G(DATANAME),1:"<NO DATANAME>")
 ;
 ;
 ; Use V LAB file to get information
 S (VLABCNT,VLABFND)=0,VLABIEN="A"
 F  S VLABIEN=$O(^AUPNVLAB("B",LAB60IEN,VLABIEN),-1)  Q:VLABIEN<1!(VLABFND)  D
 . S:$P($G(^AUPNVLAB(VLABIEN,0)),"^",6)=LRAS VLABFND=VLABIEN
 ;
 I VLABFND<1 D STORERRS(LRDFN,LRSS,LRIDT,DNHOLDER,LAB60IEN,"No V LAB Data")  Q
 ;
 S VISITIEN=+$P($G(^AUPNVLAB(VLABFND,0)),"^",3)
 D VFORDSRT
 Q
 ;
INSTFSRT ; EP - Institution File sort
 NEW NOW,DATASTR,DNHOLDER
 ;
 S DNHOLDER=$S($L($G(DATANAME)):$G(DATANAME),1:"<NO DATANAME>")
 ;
 S FILE4IEN=0
 S DATASTR=$G(^LR(LRDFN,LRSS,LRIDT,DNHOLDER))
 S:$L(DATASTR,"^")>1 FILE4IEN=+$RE($P($RE(DATASTR),"^"))
 S:FILE4IEN<1 FILE4IEN=$P($G(^SC(+$G(F44IEN),0)),"^",4)
 ;
 I FILE4IEN<1 D STORERRS(LRDFN,LRSS,LRIDT,DNHOLDER,LAB60IEN,"No Site in File 63 nor File 44")  Q
 ;
 S:$D(^BLRLUPAC(DATETIME,"SITESORT"))<1 ^BLRLUPAC(DATETIME,"SITESORT")=SELRAAAB_"^"_LRSDT_"^"_LRLDT
 S ^BLRLUPAC(DATETIME,"SITESORT",FILE4IEN)=1+$G(^BLRLUPAC(DATETIME,"SITESORT",FILE4IEN))
 S ^BLRLUPAC(DATETIME,"SITESORT",FILE4IEN,LAB60IEN)=1+$G(^BLRLUPAC(DATETIME,"SITESORT",FILE4IEN,LAB60IEN))
 Q
 ;
MIDATA ; EP - "MI" Data
 Q:(SPTKNDAT<LRSDT)!(SPTKNDAT>LRLDT)   ; Skip if not in Date Range
 ;
 S LRAS=$P($G(^LR(LRDFN,"MI",LRIDT,0)),"^",6)
 ;
 D GETVMIEN(.VMICIEN)
 I VMICIEN<1 D STORERRS(LRDFN,LRSS,LRIDT,"<Not App>","<UNK>","No MI Data in VISIT file")  Q
 ;
 S STR=$G(^AUPNVMIC(VMICIEN,0))
 S LAB60IEN=+$P(STR,"^",1)
 S VISITIEN=+$P(STR,"^",3)
 ;
 S SOMEDATA=SOMEDATA+1
 D TOPOGSRT
 D LATSTSRT
 D VFORDSRT   ; Be aware that MI Subscripts don't have DATANAME
 D INSTFSRT   ; Be aware that MI Subscripts don't have DATANAME
 Q
 ;
GETVMIEN(VMICIEN) ; EP - Get V MICRO IEN, if it exists
 S VMICIEN=0,FLAG="NO"
 F  S VMICIEN=$O(^AUPNVMIC("AC",DFN,VMICIEN))  Q:VMICIEN<1!(FLAG)  D
 . S COLLDTT=+$G(^AUPNVMIC(VMICIEN,12))
 . Q:$P(COLLDTT,".")'=$P(SPTKNDAT,".")
 . Q:LRAS'=$P($G(^AUPNVMIC(VMICIEN,0)),"^",6)
 . S FLAG=VMICIEN
 S VMICIEN=FLAG
 Q
 ;
LDORDSRT ; EP - Lab Data Hospital Location File Sort
 Q:+$G(LAB60IEN)<1
 ;
 NEW LOCPIECE
 ;
 ; S LOCPIECE=$S(LRSS="BB":8,LRSS="CH":11,LRSS="CY":8,LRSS="MI":8,LRSS="SP":8,1:0)
 S LOCPIECE=$S(LRSS="BB":8,LRSS="CH":11,LRSS="CY":8,LRSS="MI":13,LRSS="SP":8,1:0)   ; IHS/MSC/MKK - LR*5.2*1033 - Need to use Requesting LOC/DIV field for "MI" tests
 ;
 S F44IEN=$P($G(^LR(LRDFN,LRSS,LRIDT,0)),"^",LOCPIECE)
 S:$L(F44IEN)>0 F44IEN=+$O(^SC("C",F44IEN,0))
 ;
 ; I +$G(F44IEN)<1 D STORERRS(LRDFN,LRSS,LRIDT,DATANAME,LAB60IEN,"No File 44 Data in V FILE")  Q
 I +$G(F44IEN)<1 D STORERRS(LRDFN,LRSS,LRIDT,+$G(DATANAME),LAB60IEN,"No File 44 Data in V FILE")  Q     ; IHS/MSC/MKK - LR*5.2*1033 - DATANAME variable only exists for "CH" tests
 ;
 S:$D(^BLRLUPAC(DATETIME,"LOCSORT"))<1 ^BLRLUPAC(DATETIME,"LOCSORT")=SELRAAAB_"^"_LRSDT_"^"_LRLDT
 S ^BLRLUPAC(DATETIME,"LOCSORT",F44IEN)=1+$G(^BLRLUPAC(DATETIME,"LOCSORT",F44IEN))
 S ^BLRLUPAC(DATETIME,"LOCSORT",F44IEN,LAB60IEN)=1+$G(^BLRLUPAC(DATETIME,"LOCSORT",F44IEN,LAB60IEN))
 Q
 ;
VFORDSRT ; EP - V File - Hospital Location File sort
 NEW DNHOLDER
 S F44IEN=+$P($G(^AUPNVSIT(VISITIEN,0)),"^",22)
 ;
 S DNHOLDER=$S($L($G(DATANAME)):$G(DATANAME),1:"<NO DATANAME>")
 I F44IEN<1 D STORERRS(LRDFN,LRSS,LRIDT,DNHOLDER,LAB60IEN,"No File 44 Data in V FILE")  Q
 ;
 S:$D(^BLRLUPAC(DATETIME,"LOCSORT"))<1 ^BLRLUPAC(DATETIME,"LOCSORT")=SELRAAAB_"^"_LRSDT_"^"_LRLDT
 S ^BLRLUPAC(DATETIME,"LOCSORT",F44IEN)=1+$G(^BLRLUPAC(DATETIME,"LOCSORT",F44IEN))
 S ^BLRLUPAC(DATETIME,"LOCSORT",F44IEN,LAB60IEN)=1+$G(^BLRLUPAC(DATETIME,"LOCSORT",F44IEN,LAB60IEN))
 Q
 ;
BBDATA ; EP - "BB" Data
 Q:(SPTKNDAT<LRSDT)!(SPTKNDAT>LRLDT)   ; Skip if not in Date Range
 ;
 S LRAS=$P($G(^LR(LRDFN,"BB",LRIDT,0)),"^",6)
 ;
 D GETBBIEN(.VBBIEN)
 I VBBIEN<1 D STORERRS(LRDFN,LRSS,LRIDT,"<Not App>","<UNK>","No BB Data in V BLOOD BANK File")  Q
 ;
 S STR=$G(^AUPNVBB(VBBIEN,0))
 S LAB60IEN=$P(STR,"^",1)
 S VISITIEN=+$P(STR,"^",3)
 ;
 S SOMEDATA=SOMEDATA+1
 D TOPOGSRT
 D LATSTSRT
 ; D VFORDSRT
 D INSTFSRT
 ;
 Q
 ;
GETBBIEN(VBBIEN) ; EP -- Get V BLOOD BANK IEN, if it exists
 S VBBIEN=0,FLAG="NO"
 F  S VBBIEN=$O(^AUPNVBB("AC",DFN,VBBIEN))  Q:VBBIEN<1!(FLAG)  D
 . S COLLDTT=+$G(^AUPNVBB(VBBIEN,12))
 . Q:$P(COLLDTT,".")'=$P(SPTKNDAT,".")
 . Q:LRAS'=$P($G(^AUPNVBB(VBBIEN,0)),"^",6)
 . S FLAG=VBBIEN
 S VBBIEN=FLAG
 Q
 ;
STORERRS(LRDFN,LRSS,LRIDT,DATANAME,LAB60IEN,ERRMSG) ; EP -- Store DATANAME Errors
 NEW STR
 ; S STR=LAB60IEN
 ; S:$G(ERRMSG)'="" STR=STR_"^"_ERRMSG
 S:$D(^BLRLUPAC(DATETIME,"ERRORS"))<1 ^BLRLUPAC(DATETIME,"ERRORS")=SELRAAAB_"^"_LRSDT_"^"_LRLDT
 ; S ^BLRLUPAC(DATETIME,"ERRORS",LRDFN,LRSS,LRIDT,DATANAME)=STR
 S ^BLRLUPAC(DATETIME,"ERRORS",ERRMSG)=1+$G(^BLRLUPAC(DATETIME,"ERRORS",ERRMSG))
 S ^BLRLUPAC(DATETIME,"ERRORS",ERRMSG,LAB60IEN)=1+$G(^BLRLUPAC(DATETIME,"ERRORS",ERRMSG,LAB60IEN))
 S ^BLRLUPAC(DATETIME,"ERRORS",ERRMSG,LAB60IEN,LRDFN,LRSS,LRIDT,DATANAME)=""
 Q
 ;
SETXTMPN(XTMPNODE) ; EP -- Set the node for the ^BLRLUPAC global
 S XTMPNODE="BLRLUPAC"
 Q
 ;
PROGEND(MSG) ; EP -- Routine Ends 
 W !,?4,MSG,"  Routine Ends.",!
 D PRESSKEY^BLRGMENU(9)
 D V^LRU
 Q
 ;
NOTHING ; EP - No Data Found
 D HEADERDT^BLRGMENU
 D PROGEND("No Data Found.")
 K ^BLRLUPAC(DATETIME)
 Q