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

BQICMUTL.m

Go to the documentation of this file.
BQICMUTL ;VNGT/HS/ALA-Care Mgmt Utility ; 25 Jul 2011  7:25 AM
 ;;2.6;ICARE MANAGEMENT SYSTEM;;Jul 07, 2017;Build 72
 ;
 ;
ITM(TMFRAME,BQDFN,FREF,RREF,TIEN,TAX,TREF) ;EP - Find the value
 ; Find visits for a request item
 ; Input
 ;   TMFRAME - Time frame to search data for
 ;   BQDFN   - Patient internal entry number
 ;   FREF    - File to search in
 ;   RREF    - Search file table file
 ;   TIEN    - Item to search on
 ;   TAX     - Taxonomy
 ;   TREF    - Reference array
 ;
 NEW GREF,ENDT,IEN,QFL,RESULT,VISIT,VSDTM,RES,DTM,ITIEN,EDT,BDT,VFL
 NEW SRCTYP
 S TMFRAME=$G(TMFRAME,"")
 I $G(TAX)'="" D
 . S TREF=$NA(^TMP($J,"BQITAX")) K @TREF
 . I $G(RREF)=60 D BLD^BQITUTL(TAX,TREF,"L") Q
 . D BLD^BQITUTL(TAX,TREF)
 I $G(TAX)="" D
 . I $G(TIEN)="" Q
 . S TREF="BQITAX" K @TREF
 . S @TREF@(TIEN)=""
 S GREF=$$ROOT^DILFD(FREF,"",1)
 S VFL=$O(^BQI(90508.6,"B",FREF,""))
 I VFL'="" S SRCTYP=$P(^BQI(90508.6,VFL,0),U,3)
 S ENDT=$$DATE^BQIUL1(TMFRAME)
 S IEN="",QFL=0,RESULT=0
 I $G(TMFRAME)'="" D
 . S EDT=9999999-ENDT,BDT=""
 . I SRCTYP'=2 D  Q
 .. F  S BDT=$O(@GREF@("AA",BQDFN,BDT)) Q:BDT=""!(BDT>EDT)  D  Q:QFL
 ... S IEN=""
 ... F  S IEN=$O(@GREF@("AA",BQDFN,BDT,IEN)) Q:IEN=""  D  Q:QFL
 .... S ITIEN=$$GET1^DIQ(FREF,IEN,.01,"I") I ITIEN="" Q
 .... S RES=$$GET1^DIQ(FREF,IEN,.04,"I")
 .... I $G(TIEN)'="",ITIEN'=TIEN Q
 .... I $G(TIEN)="",'$D(@TREF@(ITIEN)) Q
 .... S VISIT=$$GET1^DIQ(FREF,IEN,.03,"I") I VISIT="" Q
 .... ;I $$GET1^DIQ(9000010,VISIT,.11,"I")=1 Q
 .... I $P($G(^AUPNVSIT(VISIT,0)),"^",11)=1 Q
 .... ;S VSDTM=$$GET1^DIQ(9000010,VISIT,.01,"I")\1 Q:VSDTM=0
 .... S VSDTM=$P($G(^AUPNVSIT(VISIT,0)),"^",1)\1 I VSDTM=0 Q
 .... S RESULT=1_U_VSDTM_U_U_VISIT_U_IEN_U_RES,QFL=1
 . ;
 . F  S BDT=$O(@GREF@("AA",PTDFN,TIEN,BDT)) Q:BDT=""!(BDT>EDT)  D
 .. S IEN=""
 .. F  S IEN=$O(@GREF@("AA",PTDFN,TIEN,BDT,IEN)) Q:IEN=""  D
 ... S ITIEN=$$GET1^DIQ(FREF,IEN,.01,"I") I ITIEN="" Q
 ... S RES=$$GET1^DIQ(FREF,IEN,.04,"I")
 ... I $G(TIEN)'="",ITIEN'=TIEN Q
 ... I $G(TIEN)="",'$D(@TREF@(ITIEN)) Q
 ... S VISIT=$$GET1^DIQ(FREF,IEN,.03,"I") I VISIT="" Q
 ... ;I $$GET1^DIQ(9000010,VISIT,.11,"I")=1 Q
 ... I $P($G(^AUPNVSIT(VISIT,0)),"^",11)=1 Q
 ... ;S VSDTM=$$GET1^DIQ(9000010,VISIT,.01,"I")\1 Q:VSDTM=0
 ... S VSDTM=$P($G(^AUPNVSIT(VISIT,0)),"^",1)\1 I VSDTM=0 Q
 ... S RESULT=1_U_VSDTM_U_U_VISIT_U_IEN_U_RES,QFL=1
 . ; check for refusal
 . I $O(^AUPNPREF("AA",BQDFN,RREF,""))'="" D
 .. I $D(TREF) S TIEN="" F  S TIEN=$O(@TREF@(TIEN)) Q:TIEN=""  D
 ... S EDT=9999999-ENDT,BDT=""
 ... F  S BDT=$O(^AUPNPREF("AA",BQDFN,RREF,TIEN,BDT)) Q:BDT=""!(BDT>EDT)  D
 .... S IEN="" F  S IEN=$O(^AUPNPREF("AA",BQDFN,RREF,TIEN,BDT,IEN)) Q:IEN=""  D
 ..... S DTM=$P(^AUPNPREF(IEN,0),U,3)
 ..... I $P(RESULT,U,2)'="",DTM<$P(RESULT,U,2) Q
 ..... S RESULT=1_U_DTM_U_U_U_U_U_"refusal"
 ;
 I $G(TMFRAME)="" D
 . S IEN=""
 . F  S IEN=$O(@GREF@("AC",BQDFN,IEN),-1) Q:IEN=""  D  Q:QFL
 .. S ITIEN=$$GET1^DIQ(FREF,IEN,.01,"I") I ITIEN="" Q
 .. I $G(TIEN)'="",ITIEN'=TIEN Q
 .. I $G(TIEN)="",'$D(@TREF@(ITIEN)) Q
 .. S RES=$$GET1^DIQ(FREF,IEN,.04,"I")
 .. S VISIT=$$GET1^DIQ(FREF,IEN,.03,"I") I VISIT="" Q
 .. ;I $$GET1^DIQ(9000010,VISIT,.11,"I")=1 Q
 .. I $P($G(^AUPNVSIT(VISIT,0)),"^",11)=1 Q
 .. ;S VSDTM=$$GET1^DIQ(9000010,VISIT,.01,"I")\1 Q:VSDTM=0
 .. S VSDTM=$P($G(^AUPNVSIT(VISIT,0)),"^",1)\1 I VSDTM=0 Q
 .. S RESULT=1_U_VSDTM_U_U_VISIT_U_IEN_U_RES,QFL=1
 . ; check for refusal
 . I $O(^AUPNPREF("AA",BQDFN,RREF,""))'="" D
 .. I $D(TREF) S TIEN="" F  S TIEN=$O(@TREF@(TIEN)) Q:TIEN=""  D
 ... ;S EDT=(9999999-DT)+.001,BDT=""
 ... S BDT="",STOP=0
 ... F  S BDT=$O(^AUPNPREF("AA",BQDFN,RREF,TIEN,BDT)) Q:BDT=""  D  Q:STOP
 .... S IEN="" F  S IEN=$O(^AUPNPREF("AA",BQDFN,RREF,TIEN,BDT,IEN)) Q:IEN=""  D  Q:STOP
 ..... S DTM=$P(^AUPNPREF(IEN,0),U,3)
 ..... I $P(RESULT,U,2)'="",DTM<$P(RESULT,U,2) Q
 ..... S RESULT=1_U_DTM_U_U_U_U_U_"refusal",STOP=1
 Q RESULT
 ;
FTAG(TGN,COLN,BQDFN) ; EP - Find the last entry for a value in Tag
 ; Input Parameters
 ;   TGN   - Tag IEN
 ;   COLN  - Column IEN
 ;   BQDFN - Patient IEN
 ;
 NEW DA,IENS,FRN,FREF,RREF,ITM,NAM,TAX
 S DA(1)=TGN,DA=COLN,IENS=$$IENS^DILF(.DA)
 S FRN=$$GET1^DIQ(90506.26,IENS,.02,"I")
 S FREF=$$PTR^BQIUL2(90506.26,.02,FRN,.02)
 S RREF=$$PTR^BQIUL2(90506.26,.02,FRN,.08)
 S ITM=$$GET1^DIQ(90506.26,IENS,.04,"E")
 ;S DIS=$$GET1^DIQ(90506.26,IENS,.05,"I")
 S NAM=$$GET1^DIQ(90506.26,IENS,.03,"E")
 S TAX=$$GET1^DIQ(90506.26,IENS,.07,"E")
 Q $$ITM^BQICMUTL("",BQDFN,FREF,RREF,ITM,TAX,"")
 ;
FND(CRN,COLN,BQDFN) ;EP - Find the last entry for a value in Source
 ; Input Parameters
 ;   CRN   - Care Mgmt Source IEN
 ;   COLN  - Column IEN
 ;   BQDFN - Patient IEN
 ;
 NEW DA,IENS,FRN,FREF,RREF,ITM,NAM,TAX,EXEC,NONT,APCHSDFN,APCHSPAT
 S (APCHSDFN,APCHSPAT)=BQDFN
 S DA(1)=CRN,DA=COLN,IENS=$$IENS^DILF(.DA)
 S FRN=$$GET1^DIQ(90506.51,IENS,.02,"I")
 S FREF=$$PTR^BQIUL2(90506.51,.02,FRN,.02)
 S RREF=$$PTR^BQIUL2(90506.51,.02,FRN,.08)
 S ITM=$$GET1^DIQ(90506.51,IENS,.04,"E")
 ;S DIS=$$GET1^DIQ(90506.51,IENS,.05,"I")
 S NAM=$$GET1^DIQ(90506.51,IENS,.03,"E")
 S TAX=$$GET1^DIQ(90506.51,IENS,.07,"E")
 S EXEC=$$GET1^DIQ(90506.51,IENS,1,"E")
 S NONT=$$GET1^DIQ(90506.51,IENS,2,"E")
 I EXEC'="" X EXEC
 I EXEC'="",EXEC["VAL" Q VAL
 I EXEC'="",EXEC["RESULT" Q RESULT
 I NONT'="" X NONT
 Q $$ITM^BQICMUTL("",BQDFN,FREF,RREF,ITM,TAX,.TREF)
 ;
SKN ;EP - Skin Test
 S TIEN=$O(^AUTTSK("B","PPD","")) I TIEN="" Q
 S BTREF(TIEN)="PPD",TREF=$NA(BTREF)
 Q
 ;
TB ;EP - Quantiferon lab
 NEW TAX
 S TREF=$NA(BTREF) K @TREF
 S TAX="BQI TB QUANTIFERON LOINC" D BLD^BQITUTL(TAX,.TREF)
 S TAX="BQI TB QUANTIFERON TEST" D BLD^BQITUTL(TAX,.TREF,"L")
 Q
 ;
SER(TAX,RESULT) ;EP - Find a series
 NEW TREF,TIEN
 S TREF=$NA(^TMP($J,"BQITAX")) K @TREF
 D BLD^BQITUTL(TAX,TREF)
 S GREF=$$ROOT^DILFD(FREF,"",1),RREF=FREF
 S IEN="",QFL=0,CT=0,RESULT=CT
 F  S IEN=$O(@GREF@("AC",BQDFN,IEN),-1) Q:'IEN  D
 . S ITIEN=$$GET1^DIQ(FREF,IEN,.01,"I") I ITIEN="" Q
 . I $G(TIEN)'="",ITIEN'=TIEN Q
 . I $G(TIEN)="",'$D(@TREF@(ITIEN)) Q
 . S RES=$$GET1^DIQ(FREF,IEN,.04,"I")
 . S VISIT=$$GET1^DIQ(FREF,IEN,.03,"I") I VISIT="" Q
 . ;I $$GET1^DIQ(9000010,VISIT,.11,"I")=1 Q
 . I $P($G(^AUPNVSIT(VISIT,0)),"^",11)=1 Q
 . ;S VSDTM=$$GET1^DIQ(9000010,VISIT,.01,"I")\1 Q:VSDTM=0
 . S VSDTM=$P($G(^AUPNVSIT(VISIT,0)),"^",1)\1 I VSDTM=0 Q
 . S CT=CT+1,RESULT=CT
 . S RESULT(CT)=1_U_VSDTM_U_U_VISIT_U_IEN_U_RES
 ; check for refusal
 I $O(^AUPNPREF("AA",BQDFN,RREF,""))'="" D
 . I $D(TREF) S TIEN="" F  S TIEN=$O(@TREF@(TIEN)) Q:TIEN=""  D
 .. S BDT="",STOP=0
 .. F  S BDT=$O(^AUPNPREF("AA",BQDFN,RREF,TIEN,BDT)) Q:BDT=""  D
 ... S IEN="" F  S IEN=$O(^AUPNPREF("AA",BQDFN,RREF,TIEN,BDT,IEN)) Q:IEN=""  D
 .... S DTM=$P(^AUPNPREF(IEN,0),U,3)
 .... I $P(RESULT,U,2)'="",DTM<$P(RESULT,U,2) Q
 .... S CT=CT+1,RESULT=CT
 .... S RESULT(CT)=1_U_DTM_U_U_U_U_U_"refusal"
 I RESULT="" Q
 NEW NRES,BQDTFRM,NCT
 S NRES=""
 S BQDTFRM=$$GET1^DIQ(90506.51,IENS,.08,"I") S:BQDTFRM="" BQDTFRM="S"
 S NCT=""
 F  S NCT=$O(RESULT(NCT),-1) Q:NCT=""  D
 . S NRES=NRES_$S(BQDTFRM="S":$$FMTE^BQIUL1($P(RESULT(NCT),U,2)),1:$$FMTMDY^BQIUL1($P(RESULT(NCT),U,2)))_$C(13)_$C(10)
 . I $P(RESULT(NCT),U,8)="refusal" S NRES=NRES_"(refusal)"_$C(13)_$C(10)
 K RESULT S RESULT=NRES
 Q
 ;
EX(TYPE,RIEN,FIELD,RESULT) ;EP
 NEW MDATA
 I TYPE="PR" D
 . S RESULT=""
 . I FIELD=.01 D  Q
 .. S DN=$$GET1^DIQ(9000011,RIEN_",",FIELD,"I")
 .. I $$VERSION^XPDUTL("AICD")>3.51 S RESULT=1_U_$$VST^ICDCODE(DN,"",80)_" ["_$$CODEC^ICDCODE(DN,80)_"]" Q
 .. S RESULT=1_U_$P(^ICD9(DN,0),U,3)_" ["_$P(^ICD9(DN,0),U,1)_"]"
 . I FIELD="ONSET" D  Q
 .. S MDATA=$$PROB^BQIUL1(RIEN) I MDATA="" S RESULT=0
 .. S RESULT=1_U_MDATA
 . I DIS="D" S RESULT=1_U_$$GET1^DIQ(9000011,RIEN_",",FIELD,"I") Q
 . S RESULT=1_U_$$GET1^DIQ(9000011,RIEN_",",FIELD,"E")
 . I RESULT="" S RESULT=0
 I TYPE="AL" D
 . NEW ARIEN
 . S RESULT=""
 . I FIELD=4 S RESULT=1_U_$$GET1^DIQ(120.8,RIEN_",",FIELD,"I") Q
 . I FIELD=14.5 S ARIEN=$O(^GMR(120.85,"C",RIEN,"")) I ARIEN'="" S RESULT=1_U_$$GET1^DIQ(120.85,ARIEN_",",FIELD,"E") Q
 . S RESULT=1_U_$$GET1^DIQ(120.8,RIEN_",",FIELD,"E")
 . I RESULT="" S RESULT=0
 I TYPE="ME" D  Q
 . NEW FILE
 . S FILE=9000010.14,RESULT=""
 . I FIELD="DATE" D
 .. S RES=$$VISD(FILE,RIEN)
 .. I RES'="" S RESULT=1_U_(RES\1)
 . I FIELD?.N!(FIELD?1".".N) D  Q
 .. S RESULT=1_U_$$GET1^DIQ(FILE,RIEN_",",FIELD,"E")
 . S RXN=$$GET1^DIQ(9000010.14,RIEN_",",1102,"E") I RXN="" Q
 . S RXIEN=$O(^PSRX("B",RXN,"")) I RXIEN="" Q
 . I FIELD="STAT" S RESULT=1_U_$$GET1^DIQ(52,RXIEN_",",100,"E")
 . I FIELD="NREF" S RESULT=1_U_$$GET1^DIQ(52,RXIEN_",",9,"E")
 . I FIELD="LDDT" S RESULT=1_U_$$GET1^DIQ(52,RXIEN_",",101,"I")
 . I RESULT="" S RESULT=0
 I TYPE="CP" D  Q
 . NEW FILE
 . S FILE=9000010.18,RESULT=""
 . I FIELD?.N!(FIELD?1".".N) D  Q
 .. S RESULT=1_U_$$GET1^DIQ(FILE,RIEN_",",FIELD,"E")
 . I FIELD="DATE" D
 .. S RES=$$VISD(FILE,RIEN)
 .. I RES'="" S RESULT=1_U_(RES\1)
 . I FIELD="CPT" D
 .. S DN=$P($G(^AUPNVCPT(RIEN,0)),U,1) I DN="" Q
 .. S RESULT=1_U_$P(^ICPT(DN,0),U,1)_" - "_$P(^ICPT(DN,0),U,2)
 . I RESULT="" S RESULT=0
 I TYPE="ER" D  Q
 . NEW FILE
 . S FILE=9009080,RESULT=""
 . I FIELD?.N!(FIELD?1".".N)!(FIELD?.N1".".N) D  Q
 .. I DFN=RIEN,FIELD'=.05 Q
 .. I DFN=RIEN,FIELD=.05 S RESULT=1_U_$$GET1^DIQ(9009081,RIEN_",",3,"E") Q
 .. S RESULT=1_U_$$GET1^DIQ(FILE,RIEN_",",FIELD,"E")
 . I FIELD="ADATE" D
 .. I DFN=RIEN S RESULT=1_U_$P($G(^AMERADM(RIEN,0)),U,2)\1 Q
 .. S RESULT=1_U_$P($G(^AMERVSIT(RIEN,0)),U,1)
 . I FIELD="DDATE" D
 .. I DFN=RIEN Q
 .. S RESULT=1_U_$P($G(^AMERVSIT(RIEN,6)),U,2)
 . I FIELD="MODE" D
 .. I DFN=RIEN S RESULT=1_U_$$GET1^DIQ(9009081,RIEN_",",6,"E") Q
 .. NEW MODE
 .. S MODE=$$GET1^DIQ(FILE,RIEN_",",.25,"E")
 .. I MODE="" S MODE=$$GET1^DIQ(FILE,RIEN_",",17.3,"E")
 .. I MODE'="" S RESULT=1_U_MODE
 . I RESULT="" S RESULT=0
 I TYPE="LA" D  Q
 . NEW FILE,TEXT,LN,RES
 . S FILE=9000010.09,RESULT=""
 . I FIELD?.N!(FIELD?1".".N)!(FIELD?.N1".".N) D  Q
 .. S RESULT=1_U_$$GET1^DIQ(FILE,RIEN_",",FIELD,"E")
 . I FIELD="COM" D  Q
 .. S TEXT="",LN=0
 .. F  S LN=$O(^AUPNVLAB(RIEN,21,LN)) Q:'LN  D
 ... S TEXT=TEXT_^AUPNVLAB(RIEN,21,LN,0)_$C(10)_$C(13)
 .. S RESULT=1_U_$$TKO^BQIUL1(TEXT,$C(10)_$C(13))
 . I FIELD="DATE" D
 .. ;S VISIT=$P($G(^AUPNVLAB(RIEN,0)),U,3) I VISIT="" Q
 .. S RES=$$VISD(FILE,RIEN)
 .. I RES'="" S RESULT=1_U_(RES\1)
 . I RESULT="" S RESULT=0
 I TYPE="ED" D  Q
 . NEW FILE,RES
 . S FILE=9000010.16,RESULT=""
 . I FIELD?.N!(FIELD?1".".N)!(FIELD?.N1".".N) D  Q
 .. S RESULT=1_U_$$GET1^DIQ(FILE,RIEN_",",FIELD,"E")
 . I FIELD="DATE" D
 .. S RES=$$VISD(FILE,RIEN)
 .. I RES'="" S RESULT=1_U_(RES\1)
 . I RESULT="" S RESULT=0
 Q
 ;
VISD(FILE,RIEN) ; EP - Get visit date
 NEW VFILE
 S VFILE=$$ROOT^DILFD(FILE,"",1)
 S VISIT=$P($G(@VFILE@(RIEN,0)),U,3) I VISIT="" Q ""
 Q $P($G(^AUPNVSIT(VISIT,0)),U,1)
 ;
ORD ;EP - Display Order
 NEW BQSRC
 S BQSRC=$$GET1^DIQ(90506.1,D0_",",3.01,"I")
 S BQSRC=$$PTR^BQIUL2(90506.1,3.01,BQSRC,.02)
 W "Previous Order:  ",$O(^BQI(90506.1,"AD",BQSRC,""),-1)
 Q