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

BQICAUTL.m

Go to the documentation of this file.
BQICAUTL ;VNGT/HS/ALA-Utility for CA ; 29 Mar 2011  4:49 PM
 ;;2.6;ICARE MANAGEMENT SYSTEM;;Jul 07, 2017;Build 72
 ;
TAX(TMFRAME,TAX,NIT,PTDFN,FREF,PRB,SAME,TREF) ;EP
 ; Find value for a taxonomy (TAX) or list of taxonomies (TREF)
 ; Input
 ;   TMFRAME - Timeframe to search for data
 ;   TAX     - Taxonomy
 ;   NIT     - Number of iterations
 ;   PTDFN   - Patient IEN
 ;   FREF    - File number reference
 ;   PRB     - If Active Problem okay
 ;   SAME    - If NIT is allowed for the same 30 days or not (1 same 30 days okay)
 ;   TREF    - Multiple same resulting taxonomies (e.g. MEDs) built
 ;             into reference (usually global)
 ;
 NEW RESULT,GREF,ENDT,IEN,TIEN,TEMP,QFL
 S TMFRAME=$G(TMFRAME,""),NIT=$G(NIT,1),PRB=$G(PRB,0),SAME=$G(SAME,1)
 S ENDT=$$DATE^BQIUL1(TMFRAME),RESULT=0,TREF=$G(TREF,""),TAX=$G(TAX,"")
 I TAX'="" D
 . S TREF=$NA(^TMP("BQITAX",UID))
 . K @TREF
 . D BLD^BQITUTL(TAX,TREF)
 S GREF=$$ROOT^DILFD(FREF,"",1)
 S TEMP=$NA(^TMP("BQITEMP",UID)) K @TEMP
 ;
 I PRB D
 . S IEN="",QFL=0,RESULT=0
 . F  S IEN=$O(^AUPNPROB("AC",PTDFN,IEN),-1) Q:IEN=""  D  Q:QFL
 .. S TIEN=$$GET1^DIQ(9000011,IEN,.01,"I") I TIEN="" Q
 .. I '$D(@TREF@(TIEN)) Q
 .. ;  Check class - if Family ignore
 .. I $$GET1^DIQ(9000011,IEN,.04,"I")="F" Q
 .. I $$GET1^DIQ(9000011,IEN,.12,"I")'="A" Q
 .. S VSDTM=$$PROB^BQIUL1(IEN)\1 Q:VSDTM=0
 .. I $G(TMFRAME)'="",VSDTM<ENDT Q
 .. S RESULT=1_U_VSDTM,$P(RESULT,U,4)=IEN,QFL=1
 ;
 I 'RESULT D
 . S IEN="",QFL=0,RESULT=0,CT=0
 . I $G(TMFRAME)'="" D
 .. S EDT=9999999-ENDT,BDT=""
 .. F  S BDT=$O(@GREF@("AA",PTDFN,BDT)) Q:BDT=""!(BDT>EDT)  D
 ... S IEN=""
 ... F  S IEN=$O(@GREF@("AA",PTDFN,BDT,IEN)) Q:IEN=""  D
 .... S TIEN=$$GET1^DIQ(FREF,IEN,.01,"I") I TIEN="" Q
 .... I '$D(@TREF@(TIEN)) Q
 .... S VISIT=$$GET1^DIQ(FREF,IEN,.03,"I") I VISIT="" Q
 .... I $$GET1^DIQ(9000010,VISIT,.11,"I")=1 Q
 .... S VSDTM=$$GET1^DIQ(9000010,VISIT,.01,"I")\1 Q:VSDTM=0
 .... ;I $G(TMFRAME)'="",VSDTM<ENDT Q
 .... ; Set temporary
 .... S @TEMP@(VSDTM,VISIT,IEN)=""
 . ;
 . I $G(TMFRAME)="" D
 .. F  S IEN=$O(@GREF@("AC",PTDFN,IEN),-1) Q:IEN=""  D
 ... S TIEN=$$GET1^DIQ(FREF,IEN,.01,"I") I TIEN="" Q
 ... I '$D(@TREF@(TIEN)) Q
 ... S VISIT=$$GET1^DIQ(FREF,IEN,.03,"I") I VISIT="" Q
 ... I $$GET1^DIQ(9000010,VISIT,.11,"I")=1 Q
 ... S VSDTM=$$GET1^DIQ(9000010,VISIT,.01,"I")\1 Q:VSDTM=0
 ... ;I $G(TMFRAME)'="",VSDTM<ENDT Q
 ... ; Set temporary
 ... S @TEMP@(VSDTM,VISIT,IEN)=""
 ;
 S VSDTM="",QFL=0
 F  S VSDTM=$O(@TEMP@(VSDTM),-1) Q:VSDTM=""!(QFL)  D
 . S VISIT=""
 . F  S VISIT=$O(@TEMP@(VSDTM,VISIT),-1) Q:VISIT=""  D  Q:QFL
 .. S IEN=""
 .. F  S IEN=$O(@TEMP@(VSDTM,VISIT,IEN),-1) Q:IEN=""  D  Q:QFL
 ... ; If result cannot be within 30 days, quit
 ... I 'SAME,$P(RESULT,U,2)=VSDTM Q
 ... S CT=CT+1
 ... I $P(RESULT,U,2)'="",(CT'>NIT) D
 .... I VSDTM'<STDT,'SAME S CT=CT-1 Q
 .... S $P(RESULT,U,2)=$P(RESULT,U,2)_";"_VSDTM
 .... S $P(RESULT,U,4)=$P(RESULT,U,4)_";"_VISIT
 .... S $P(RESULT,U,5)=$P(RESULT,U,5)_";"_IEN
 ... I $P(RESULT,U,2)="" S $P(RESULT,U,2)=VSDTM,$P(RESULT,U,4)=VISIT_U_IEN
 ... ;S $P(RESULT,U,4)=VISIT_U_IEN,CT=CT+1
 ... ;S RESULT=U_VSDTM_U_U_VISIT_U_IEN,CT=CT+1
 ... I CT=NIT S QFL=1,$P(RESULT,U,1)=1
 K @TREF
 Q RESULT
 ;
MEAS(BQDFN,MEAS,VISIT,RESVAL,OPER) ;EP - Get measurement
 I MEAS'?.N S MEAS=$$FIND1^DIC(9999999.07,,"MX",MEAS)
 S VALUE=0
 S VDATE=$P(^AUPNVSIT(VISIT,0),U,1)\1
 S RVDT=9999999-VDATE
 S IEN=""
 F  S IEN=$O(^AUPNVMSR("AA",BQDFN,MEAS,RVDT,IEN)) Q:IEN=""  D
 . S RESULT=$P($G(^AUPNVMSR(IEN,0)),"^",4) I RESULT="" Q
 . I $P($G(^AUPNVMSR(IEN,2)),"^",1)=1 Q
 . ; if the new ENTERED IN ERROR field exists, exclude the record if it is marked as an error
 . I $$VFIELD^DILFD(9000010.01,2) Q:$$GET1^DIQ(9000010.01,IEN_",",2,"I")=1
 . I @(RESULT_OPER_RESVAL) S VALUE="1^"_VDATE_U_RESULT_U_VISIT_U_IEN_U_"9000010.01"
 Q VALUE
 ;
LAB(TMFRAME,RECENT,BQDFN,TAX,SEARCH,TREF) ;EP
 ; Check for a lab test result
 ;
 ; Input
 ;   TMFRAME - Time frame to search data for
 ;   RECENT  - 1=Only check most recent lab,0=Check all within timeframe
 ;   BQDFN   - Patient internal entry number
 ;   TAX     - Lab taxonomy to search
 ;   RESULT  - Lab result to check for
 ;   OPER    - Operand to use for result check
 ;   RES2    - If range, the other result value
 ;   OPER2   - If range, the other result operand
 ;   TREF    - Multiple same resulting taxonomies built
 ;             into reference (usually global)
 ;
 NEW TEMP,EDATE,BDATE,LIEN,QFL,RES,CT,VALUE,VIEN,VSDTM
 S BDATE=$$DATE^BQIUL1(TMFRAME),EDATE=DT
 S TEMP=$NA(^TMP("BQITEMP",UID)) K @TEMP
 S TAX=$G(TAX,""),RECENT=$G(RECENT,0)
 I TAX'="" D
 . S TREF=$NA(^TMP("BQITAX",UID))
 . K @TREF
 . D BLD^BQITUTL(TAX,TREF)
 ;
 S LIEN="",QFL=0,RES=0_U_"No Test",CT=0
 I $G(TMFRAME)'="" D
 . S TIEN=""
 . F  S TIEN=$O(@TREF@(TIEN)) Q:TIEN=""  D
 .. S EDT=9999999-BDATE,BDT=(9999999-EDATE)-.001
 .. I $P($G(^LAB(60,TIEN,0)),U,4)="MI" D  Q
 ... D MIC(BQDFN,TIEN,EDT,BDT,.MICRO)
 ... M @TEMP=MICRO
 ... K MICRO
 .. F  S BDT=$O(^AUPNVLAB("AA",BQDFN,TIEN,BDT)) Q:BDT=""!(BDT>EDT)  D
 ... S LIEN=""
 ... F  S LIEN=$O(^AUPNVLAB("AA",BQDFN,TIEN,BDT,LIEN)) Q:LIEN=""  D
 .... S VALUE=$P(^AUPNVLAB(LIEN,0),U,4) I VALUE="" Q
 .... S VIEN=$P(^AUPNVLAB(LIEN,0),U,3) I VIEN="" Q
 .... S FLAG=$P($G(^AUPNVLAB(LIEN,11)),U,9) I FLAG="" Q
 .... I FLAG'="R"&(FLAG'="M") Q
 .... S VSDTM=$$GET1^DIQ(9000010,VIEN_",",.01,"I")\1 I VSDTM=0 Q
 .... ;I $G(TMFRAME)'="",VSDTM<BDATE Q
 .... ; quit if deleted flag
 .... I $P($G(^AUPNVSIT(VIEN,0)),U,11)=1 Q
 .... I $P($G(^AUPNVLAB(LIEN,11)),U,9)="D" Q
 .... S @TEMP@(VSDTM,VIEN,LIEN)=VALUE_U_"9000010.09"_U_TIEN
 ;
 I $G(TMFRAME)="" D
 . S LIEN=""
 . F  S LIEN=$O(^AUPNVLAB("AC",BQDFN,LIEN),-1) Q:LIEN=""  D
 .. S TIEN=$P($G(^AUPNVLAB(LIEN,0)),U,1) I TIEN="" Q
 .. I '$D(@TREF@(TIEN)) Q
 .. S VALUE=$P(^AUPNVLAB(LIEN,0),U,4) I VALUE="" Q
 .. S VIEN=$P(^AUPNVLAB(LIEN,0),U,3) I VIEN="" Q
 .. S VSDTM=$$GET1^DIQ(9000010,VIEN_",",.01,"I")\1 I VSDTM=0 Q
 .. ;I $G(TMFRAME)'="",VSDTM<BDATE Q
 .. ; quit if deleted flag
 .. I $P($G(^AUPNVSIT(VIEN,0)),U,11)=1 Q
 .. I $P($G(^AUPNVLAB(LIEN,11)),U,9)="D" Q
 .. S @TEMP@(VSDTM,VIEN,LIEN)=VALUE_U_"9000010.09"_U_TIEN
 . F  S LIEN=$O(^AUPNVMIC("AC",BQDFN,LIEN),-1) Q:LIEN=""  D
 .. S TIEN=$P($G(^AUPNVMIC(LIEN,0)),U,1) I TIEN="" Q
 .. I '$D(@TREF@(TIEN)) Q
 .. S VALUE=$P(^AUPNVMIC(LIEN,0),U,7) I VALUE="" Q
 .. S VIEN=$P(^AUPNVMIC(LIEN,0),U,3) I VIEN="" Q
 .. S VSDTM=$$GET1^DIQ(9000010,VIEN_",",.01,"I")\1 I VSDTM=0 Q
 .. ; quit if deleted flag
 .. I $P($G(^AUPNVSIT(VIEN,0)),U,11)=1 Q
 .. S FLAG=$P($G(^AUPNVMIC(LIEN,11)),U,9)
 .. I FLAG'="R"&(FLAG'="M") Q
 .. S @TEMP@(VSDTM,VIEN,LIEN)=VALUE_U_"9000010.25"_U_TIEN
 ;
 S VSDTM=""
 F  S VSDTM=$O(@TEMP@(VSDTM),-1) Q:VSDTM=""  D  Q:QFL
 . S VIEN=$O(@TEMP@(VSDTM,""),-1),LIEN=""
 . F  S LIEN=$O(@TEMP@(VSDTM,VIEN,LIEN),-1) Q:LIEN=""!(QFL)  D
 .. S VALUE=$P(@TEMP@(VSDTM,VIEN,LIEN),U,1),OVALUE=VALUE
 .. S FILE=$P(@TEMP@(VSDTM,VIEN,LIEN),U,2)
 .. S TIEN=$P(@TEMP@(VSDTM,VIEN,LIEN),U,3)
 .. K ROPER
 .. S RN=""
 .. F  S RN=$O(SEARCH(RN)) Q:RN=""  D  Q:QFL
 ... S OPER=$P(SEARCH(RN),U,2),RESULT=$P(SEARCH(RN),U,1),OPER2=$P(SEARCH(RN),U,4),RES2=$P(SEARCH(RN),U,3)
 ... D RCHK
 K @TEMP
 Q RES
 ;
RCHK ;
 I OPER="'=",RESULT="",VALUE'="" S RES=1_U_$$FMTE^BQIUL1(VSDTM)_U_VALUE_U_VIEN_U_LIEN_U_TIEN_U_FILE,QFL=1 Q
 ;
 I RESULT'?.N,VALUE?.N Q
 ;
 I RESULT="POS",$E(VALUE,1)'?.N,'$$POSITIVE^BQITRUTL(VALUE) Q
 I RESULT="POS",$E(VALUE,1)'?.N,$$POSITIVE^BQITRUTL(VALUE) D  Q
 . S RES=1_U_$$FMTE^BQIUL1(VSDTM)_U_VALUE_U_VIEN_U_LIEN_U_TIEN_U_FILE,QFL=1
 I RESULT="NEG",$E(VALUE,1)'?.N,'$$NEGATIVE^BQITRUTL(VALUE) Q
 I RESULT="NEG",$E(VALUE,1)'?.N,$$NEGATIVE^BQITRUTL(VALUE) D
 . S RES=1_U_$$FMTE^BQIUL1(VSDTM)_U_VALUE_U_VIEN_U_LIEN_U_TIEN_U_FILE,QFL=1
 I VALUE'?.PN,VALUE'?.N Q
 ;I $E(VALUE,$L(VALUE))?.P S VALUE=VALUE_"0"
 I $E(VALUE,$L(VALUE),$L(VALUE))?.P S VALUE=$E(VALUE,1,$L(VALUE)-1)
 ; if value starts with a punctuation e.g. < or >
 I $E(VALUE,1,1)?.P S ROPER=$E(VALUE,1,1),VALUE=$E(VALUE,2,$L(VALUE))
 I RES2="" D
 . I $G(ROPER)="",@("VALUE"_OPER_"RESULT") D  Q
 .. S RES=1_U_$$FMTE^BQIUL1(VSDTM)_U_OVALUE_U_VIEN_U_LIEN_U_TIEN_U_FILE,QFL=1
 . I $G(ROPER)'="",OPER=ROPER,@("VALUE"_OPER_"RESULT") D  Q
 .. S RES=1_U_$$FMTE^BQIUL1(VSDTM)_U_OVALUE_U_VIEN_U_LIEN_U_TIEN_U_FILE,QFL=1
 . I $G(ROPER)'="",OPER'=ROPER Q
 I RES2'="" D
 . I @("VALUE"_OPER_"RESULT"),@("VALUE"_OPER2_"RES2") D
 .. S RES=1_U_$$FMTE^BQIUL1(VSDTM)_U_OVALUE_U_VIEN_U_LIEN_U_TIEN_U_FILE,QFL=1
 Q
 ;
MIC(BQDFN,TIEN,EDT,BDT,MICRO) ;EP - Look through Microbiology file
 NEW FLAG,LIEN,VALUE,VIEN,VSDTM
 K MICRO
 F  S BDT=$O(^AUPNVMIC("AA",BQDFN,TIEN,BDT)) Q:BDT=""!(BDT>EDT)  D
 . S LIEN=""
 . F  S LIEN=$O(^AUPNVMIC("AA",BQDFN,TIEN,BDT,LIEN)) Q:LIEN=""  D
 .. S VALUE=$P(^AUPNVMIC(LIEN,0),U,7) I VALUE="" Q
 .. S VIEN=$P(^AUPNVMIC(LIEN,0),U,3) I VIEN="" Q
 .. S VSDTM=$$GET1^DIQ(9000010,VIEN_",",.01,"I")\1 I VSDTM=0 Q
 .. ; quit if deleted flag
 .. I $P($G(^AUPNVSIT(VIEN,0)),U,11)=1 Q
 .. S FLAG=$P($G(^AUPNVMIC(LIEN,11)),U,9)
 .. I FLAG'="R"&(FLAG'="M") Q
 .. S MICRO(VSDTM,VIEN,LIEN)=VALUE_U_"9000010.25"_U_TIEN
 Q
 ;
LBB(TMFRAME,RECENT,DATE,BQDFN,TAX,SEARCH,TREF) ;EP
 I $G(TMFRAME)'="" D
 . I TMFRAME'["-" Q
 . S TMFRAME=$P(TMFRAME,"-",2)
 S BDATE=$$FMADD^XLFDT(DATE,-TMFRAME),EDATE=$$FMADD^XLFDT(DATE,TMFRAME)
 S TEMP=$NA(^TMP("BQITEMP",UID)) K @TEMP
 S TAX=$G(TAX,""),RECENT=$G(RECENT,0)
 I TAX'="" D
 . S TREF=$NA(^TMP("BQITAX",UID))
 . K @TREF
 . D BLD^BQITUTL(TAX,TREF)
 ;
 S LIEN="",QFL=0,RES=0_U_"No Test",CT=0
 D
 . S TIEN=""
 . F  S TIEN=$O(@TREF@(TIEN)) Q:TIEN=""  D
 .. S EDT=9999999-BDATE,BDT=(9999999-EDATE)-.001
 .. I $P($G(^LAB(60,TIEN,0)),U,4)="MI" D  Q
 ... D MIC(BQDFN,TIEN,EDT,BDT,.MICRO)
 ... M @TEMP=MICRO
 ... K MICRO
 .. F  S BDT=$O(^AUPNVLAB("AA",BQDFN,TIEN,BDT)) Q:BDT=""!(BDT>EDT)  D
 ... S LIEN=""
 ... F  S LIEN=$O(^AUPNVLAB("AA",BQDFN,TIEN,BDT,LIEN)) Q:LIEN=""  D
 .... S VALUE=$P(^AUPNVLAB(LIEN,0),U,4) I VALUE="" Q
 .... S VIEN=$P(^AUPNVLAB(LIEN,0),U,3) I VIEN="" Q
 .... S FLAG=$P($G(^AUPNVLAB(LIEN,11)),U,9) I FLAG="" Q
 .... I FLAG'="R"&(FLAG'="M") Q
 .... S VSDTM=$$GET1^DIQ(9000010,VIEN_",",.01,"I")\1 I VSDTM=0 Q
 .... ;I $G(TMFRAME)'="",VSDTM<BDATE Q
 .... ; quit if deleted flag
 .... I $P($G(^AUPNVSIT(VIEN,0)),U,11)=1 Q
 .... I $P($G(^AUPNVLAB(LIEN,11)),U,9)="D" Q
 .... S @TEMP@(VSDTM,VIEN,LIEN)=VALUE_U_"9000010.09"_U_TIEN
 ;
 S VSDTM=""
 F  S VSDTM=$O(@TEMP@(VSDTM),-1) Q:VSDTM=""  D  Q:QFL
 . S VIEN=$O(@TEMP@(VSDTM,""),-1),LIEN=""
 . F  S LIEN=$O(@TEMP@(VSDTM,VIEN,LIEN),-1) Q:LIEN=""!(QFL)  D
 .. S VALUE=$P(@TEMP@(VSDTM,VIEN,LIEN),U,1),OVALUE=VALUE
 .. S FILE=$P(@TEMP@(VSDTM,VIEN,LIEN),U,2)
 .. S TIEN=$P(@TEMP@(VSDTM,VIEN,LIEN),U,3)
 .. K ROPER
 .. S RN=""
 .. F  S RN=$O(SEARCH(RN)) Q:RN=""  D  Q:QFL
 ... S OPER=$P(SEARCH(RN),U,2),RESULT=$P(SEARCH(RN),U,1),OPER2=$P(SEARCH(RN),U,4),RES2=$P(SEARCH(RN),U,3)
 ... D RCHK
 K @TEMP
 Q RES