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

BQIRLB.m

Go to the documentation of this file.
BQIRLB ;PRXM/HC/DLS - Patient Labs ; 18 Jan 2006  11:46 AM
 ;;2.6;ICARE MANAGEMENT SYSTEM;;Jul 07, 2017;Build 72
 ;
 Q
 ;
EN(DATA,DFN,DRANGE,PARMS) ; EP -- BQI PATIENT LABS
 ;Description
 ;  Generates a Lab Review Report for a Given DFN and Relative Date.
 ;
 ;Input
 ;  DFN    - Patient Internal ID
 ;  DRANGE - 'From' for pulling Patient Labs (to the present).
 ;  PARMS  - Parameters for special filtering
 ;
 ;Output
 ;  DATA - Name of global in which data is stored(^TMP("BQIRLB"))
 ;
 NEW UID,X,BQII,LABDT,LABTYP,RLABDT,LABIEN,ORPHY,VISIT,PAR,PNL,SPNLNM
 NEW DATE,TEST,RSLT,UNIT,REFLOW,REFHIGH,RANGE,RDRANGE,NRMABN,TST,PNLNM
 NEW ASDATA,ASN,ASNAME,ASSOC,ASV,ASVAL,BN,BQ,CGFL,FILTER,II,PDATA,REGIEN
 NEW RGFL,RGRP,TAX,TN,TREF,VAL,FDATA
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BQIRLB",UID))
 K @DATA
 ;
 S BQII=0
 ;
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQIRLB D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ;
 S PARMS=$G(PARMS,"")
 I PARMS="" D
 . S LIST="",BN=""
 . F  S BN=$O(PARMS(BN)) Q:BN=""  S LIST=LIST_PARMS(BN)
 . K PARMS
 . S PARMS=LIST
 . K LIST
 ;
 F BQ=1:1:$L(PARMS,$C(28)) S FILTER(BQ)=$P(PARMS,$C(28),BQ)
 F BQQ=1:1:BQ D
 . S PDATA=$G(FILTER(BQQ)) Q:PDATA=""
 . S NAME=$P(PDATA,"=",1),VALUE=$P(PDATA,"=",2,99)
 . S FDATA(BQQ)=NAME
 . F II=1:1:$L(VALUE,$C(29)) D
 .. S VAL=$P(VALUE,$C(29),II),ASSOC=$P(VAL,$C(25),2,99)
 .. S FILTER(BQQ,II)=$P(VAL,$C(25),1)
 .. I ASSOC'="" D
 ... F ASN=1:1:$L(ASSOC,$C(25)) D
 .... S ASDATA=$P(ASSOC,$C(25),ASN)
 .... S ASVAL=$P(ASDATA,"=",2),ASNAME=$P(ASDATA,"=",1)
 .... S FILTER(BQQ,II,ASN)=ASNAME
 .... I ASVAL'[$C(24) S FILTER(BQQ,II,ASN,1)=ASVAL Q
 .... F ASV=1:1:$L(ASVAL,$C(24)) S FILTER(BQQ,II,ASN,ASV)=$P(ASVAL,$C(24),ASV)
 .. I ASSOC="" S FILTER(BQQ,II)=VAL
 I $D(FDATA) F BQQ=1:1:BQ S FILTER(BQQ)=FDATA(BQQ)
 K FDATA,PARMS
 ;
 NEW BQQ,MBQ,NAME,VALUE,SBQ,MSBQ
 K REG,CGRP
 S BQQ="",CGFL=0,RGFL=0
 F  S BQQ=$O(FILTER(BQQ)) Q:BQQ=""  D
 . ;S NAME=FILTER(BQQ)
 . S MBQ=""
 . F  S MBQ=$O(FILTER(BQQ,MBQ)) Q:MBQ=""  D
 .. S VALUE=FILTER(BQQ,MBQ),NAME=FILTER(BQQ)
 .. ;I NAME="REG" S REG(VALUE)="",RGFL=1
 .. I NAME="REG" S RGFL=1
 .. S @NAME@(VALUE)=""
 .. ;I NAME="CGRP" S CGRP(VALUE)=""
 .. S SBQ=""
 .. F  S SBQ=$O(FILTER(BQQ,MBQ,SBQ)) Q:SBQ=""  D
 ... ;S NAME=FILTER(BQQ,MBQ,SBQ)
 ... S MSBQ=""
 ... F  S MSBQ=$O(FILTER(BQQ,MBQ,SBQ,MSBQ)) Q:MSBQ=""  D
 .... S VALUE=FILTER(BQQ,MBQ,SBQ,MSBQ),NAME=FILTER(BQQ,MBQ,SBQ)
 .... ;I NAME="CGRP" S CGRP(VALUE)="",CGFL=1
 .... I NAME="CGRP" S CGFL=1
 .... S @NAME@(VALUE)=""
 ;
 ; Get lab taxonomies
 S TREF=$NA(^TMP("BQITAX",UID))
 K @TREF
 S REG=""
 F  S REG=$O(REG(REG)) Q:REG=""  D
 . S REGIEN=$$FIND1^DIC(90507,,"MX",REG)
 . S TN=0
 . F  S TN=$O(^BQI(90507,REGIEN,10,TN)) Q:'TN  D
 .. I $P(^BQI(90507,REGIEN,10,TN,0),U,5)'="T" Q
 .. S RGRP=$P(^BQI(90507,REGIEN,10,TN,0),U,7)
 .. I CGFL,RGRP'="",'$D(CGRP(RGRP)) Q
 .. S TAX=$P(^BQI(90507,REGIEN,10,TN,0),U,1)
 .. I $P(^BQI(90507,REGIEN,10,TN,0),U,2)["ATXLAB" D BLD^BQITUTL(TAX,TREF,"L")
 .. I $P(^BQI(90507,REGIEN,10,TN,0),U,2)["ATXAX" D BLD^BQITUTL(TAX,TREF)
 ;
 D HDR
 S DRANGE=$$DATE^BQIUL1($G(DRANGE))
 S LABIEN=""
 F  S LABIEN=$O(^AUPNVLAB("AC",DFN,LABIEN),-1) Q:LABIEN=""  D
 . D LAB(LABIEN)
 . I $G(VISIT)="" Q
 . S RLABDT=$$GET1^DIQ(9000010,VISIT,.01,"I") I RLABDT=0 Q
 . S DATE=$$FMTE^BQIUL1(RLABDT)
 . I DRANGE'="",(RLABDT\1)<DRANGE Q
 . S BQII=BQII+1,@DATA@(BQII)=VISIT_"^"_LABIEN_"^"_DATE_"^"_TEST_"^"_RSLT_"^"_UNIT_"^"_RANGE_"^"_NRMABN_"^"
 . S @DATA@(BQII)=@DATA@(BQII)_ORPHY_"^"_PAR_"^"_$S(PNL=1:"Y",1:"N")_"^"_SPNLNM_"^"_PNLNM_$C(30)
 ;
 ; Check for refusals
 D REF
 ;
DONE ;
 S BQII=BQII+1,@DATA@(BQII)=$C(31)
 Q
 ;
HDR ;
 S @DATA@(BQII)="I00010VISIT_IEN^I00010LAB_IEN^D00030LAB_DATE^T00050LAB_TEST^T00030LAB_RSLT^T00015LAB_UNIT^T00020LAB_RANGE^T00010LAB_NRMABN^"
 S @DATA@(BQII)=@DATA@(BQII)_"T00035LAB_ORD_PHYS^I00010PARENT_IEN^T00001PANEL_FLAG^T00050SUB_PANEL_NAME^T00050PAR_PANEL_NAME"_$C(30)
 Q
 ;
ERR ;
 D ^%ZTER
 NEW Y,ERRDTM
 S Y=$$NOW^XLFDT() X ^DD("DD") S ERRDTM=Y
 S BMXSEC="Recording that an error occurred at "_ERRDTM
 I $D(BQII),$D(DATA) S BQII=BQII+1,@DATA@(BQII)=$C(31)
 Q
 ;
LAB(LABIEN) ;EP - Get data for a specific lab
 S TEST=$$GET1^DIQ(9000010.09,LABIEN,".01","E") I TEST="" Q
 S TST=$$GET1^DIQ(9000010.09,LABIEN,".01","I")
 ;
 I $G(RGFL),'$D(@TREF@(TST)) S VISIT="" Q
 ;I TST="" Q
 S RSLT=$$GET1^DIQ(9000010.09,LABIEN,".04","E")
 S ORPHY=$$GET1^DIQ(9000010.09,LABIEN,1202,"E")
 S UNIT=$$GET1^DIQ(9000010.09,LABIEN,"1101","E")
 S REFLOW=$$GET1^DIQ(9000010.09,LABIEN,"1104","E")
 S REFHIGH=$$GET1^DIQ(9000010.09,LABIEN,"1105","E")
 S RANGE=REFLOW_"-"_REFHIGH
 I RANGE="-" S RANGE=""
 S NRMABN=$$GET1^DIQ(9000010.09,LABIEN,".05","I")
 S VISIT=$$GET1^DIQ(9000010.09,LABIEN,".03","I")
 S PNL=0,SPNLNM="",PNLNM=""
 I LABIEN=VISIT Q
 I $O(^LAB(60,TST,2,0))'="" S PNL=1,SPNLNM=$P($G(^LAB(60,TST,0)),U,1)
 S PAR=$$GET1^DIQ(9000010.09,LABIEN,1208,"I")
 ;
 I PAR'="" D
 . NEW TST,NPAR
 . S TST=$$GET1^DIQ(9000010.09,PAR,".01","I")
 . I TST="" Q
 . I TST'="" S PNLNM=$P($G(^LAB(60,TST,0)),U,1)
 . I $O(^LAB(60,TST,2,0))="" Q
 . S NPAR=$$GET1^DIQ(9000010.09,PAR,1208,"I")
 . I NPAR'="" D
 .. NEW TST
 .. S TST=$$GET1^DIQ(9000010.09,NPAR,".01","I")
 .. S SPNLNM=PNLNM
 .. I TST="" Q
 .. I TST'="" S PNLNM=$P($G(^LAB(60,TST,0)),U,1)
 I 'PNL,PAR'="",SPNLNM="" S SPNLNM=PNLNM,PNLNM=""
 I PNL S TEST=""
 I PNL,PAR="" D
 . NEW PTS,LTS,SBFL
 . S PTS=0,SBFL=0
 . F  S PTS=$O(^LAB(60,TST,2,PTS)) Q:'PTS  D
 .. S LTS=$P(^LAB(60,TST,2,PTS,0),U,1)
 .. I $O(^LAB(60,LTS,2,0))'="" D
 ... NEW N
 ... S N=""
 ... F  S N=$O(^AUPNVLAB("AD",VISIT,N)) Q:N=""  D
 .... I $P(^AUPNVLAB(N,0),U,1)=LTS S SBFL=1
 . I SBFL S PNLNM=SPNLNM,SPNLNM=""
 Q
 ;
REF ; Find refusals
 NEW TST,RVDT,REVDT,RFIEN
 S TST=""
 F  S TST=$O(^AUPNPREF("AA",DFN,60,TST)) Q:TST=""  D
 . S RVDT=""
 . F  S RVDT=$O(^AUPNPREF("AA",DFN,60,TST,RVDT)) Q:RVDT=""  D
 .. ; Reverse the reverse date
 .. S REVDT=9999999-RVDT
 .. I DRANGE'="",(REVDT\1)<DRANGE Q
 .. S RFIEN=""
 .. F  S RFIEN=$O(^AUPNPREF("AA",DFN,60,TST,RVDT,RFIEN)) Q:RFIEN=""  D
 ... S RSLT=$$GET1^DIQ(9000022,RFIEN_",",.07,"E")
 ... S ORPHY=$$GET1^DIQ(9000022,RFIEN_",",1204,"E")
 ... S LABIEN=TST
 ... S DATE=$$FMTE^BQIUL1(REVDT)
 ... S VISIT="",PAR="",PNL="",UNIT="",RANGE="",NRMABN="",SPNLNM="",PNLNM=""
 ... S BQII=BQII+1,@DATA@(BQII)=VISIT_"^"_LABIEN_"^"_DATE_"^"_TEST_"^"_RSLT_"^"_UNIT_"^"_RANGE_"^"_NRMABN_"^"
 ... S @DATA@(BQII)=@DATA@(BQII)_ORPHY_"^"_PAR_"^"_$S(PNL=1:"Y",1:"N")_"^"_SPNLNM_"^"_PNLNM_$C(30)
 Q