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

BQIPTDX.m

Go to the documentation of this file.
BQIPTDX ;PRXM/HC/ALA-Patient Diagnosis Categories ; 18 May 2006  10:14 AM
 ;;2.1;ICARE MANAGEMENT SYSTEM;;Feb 07, 2011
 ;
 Q
 ;
GET(DATA,DFN) ; EP -- BQI PAT DX CAT
 ;
 ;Description
 ;  Returns a list of all of the Diagnosis Categories for a patient
 ;Input
 ;   DFN  - Patient internal entry number
 ;
 NEW UID,II,DTMU,DXN,FN,NAME,FNAME,REC,CT,RECORD,RDATE,TAGDTU,WHO,COM
 NEW RTYP,X,DXC,BNAME,COMPIEN,COMPREF,COMPVAL,FTNAME,TSTAT,SIEN,SCOM
 NEW OCN,RIEN,BQVAL,OCOM,FREF,IEN
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BQIPTDX",UID))
 K @DATA
 ;
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQIPTDX D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ;
 D HDR
 ;
 S DXN=""
 F  S DXN=$O(^BQIREG("C",DFN,DXN)) Q:DXN=""  D
 . S NAME=$$GET1^DIQ(90506.2,DXN_",",.01,"E")
 . S SIEN=$O(^BQIREG("C",DFN,DXN,"")) I SIEN="" Q
 . S TAGDTU=$P(^BQIREG(SIEN,0),U,4)
 . S TAGDTU=$$FMTE^BQIUL1(TAGDTU)
 . S WHO=$P(^BQIREG(SIEN,0),U,5)
 . S TSTAT=$P(^BQIREG(SIEN,0),U,3)
 . S SCOM=$$GET1^DIQ(90509,SIEN_",",.06,"I")
 . S OCOM=""
 . S OCN=0
 . F  S OCN=$O(^BQIREG(SIEN,1,OCN)) Q:'OCN  D
 .. S OCOM=OCOM_^BQIREG(SIEN,1,OCN,0)_" "
 . ;
 . S RIEN=""
 . F  S RIEN=$O(^BQIREG("C",DFN,DXN,RIEN)) Q:RIEN=""  D
 .. ;D RDATA(.DXN,.RIEN)
 .. S BQVAL=$$RDATA(DXN,RIEN)
 .. ;I $O(^BQIPAT(DFN,20,DXN,0))'="" D GDATA(.DXN)
 .. I 'BQVAL S BQVAL=$$GDATA(DXN)
 .. I 'BQVAL D
 ... S II=II+1
 ... S @DATA@(II)=DXN_U_U_U_U_U_U_U_TSTAT_U
 ... S @DATA@(II)=@DATA@(II)_TAGDTU_U_WHO_U_SCOM_U_OCOM_$C(30)
 ;
 S II=II+1,@DATA@(II)=$C(31)
 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(II),$D(DATA) S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
GDATA(DXN) ;EP - Get patient's data by diagnosis category
 NEW BQRES,LII,STAT
 S FN=0,BQRES=0
 F  S FN=$O(^BQIPAT(DFN,20,DXN,1,FN)) Q:'FN  D
 . S DTMU=$P(^BQIPAT(DFN,20,DXN,0),U,2)
 . S FNAME=$P(^BQIPAT(DFN,20,DXN,1,FN,0),U,1)
 . S SIEN=$O(^BQIREG("C",DFN,DXN,"")) I SIEN="" Q
 . S STAT=$P(^BQIREG(SIEN,0),U,3)
 . I STAT'="A",STAT'="P" Q
 . ;
 . ; If the met criteria is a tag, get the original data to display
 . I FNAME[" Tag" S FTNAME=FNAME D TGG Q
 . ;
 . S REC="A",CT=0
 . I '$O(^BQIPAT(DFN,20,DXN,1,FN,1,REC),-1) D
 .. S II=II+1
 .. S @DATA@(II)=DXN_"^"_$$FMTE^BQIUL1(DTMU)_"^"_FNAME_"^^"_$C(30)
 . F  S REC=$O(^BQIPAT(DFN,20,DXN,1,FN,1,REC),-1) Q:'REC!(CT>3)  D
 .. S CT=CT+1 Q:CT>3
 .. ;
 .. S COMPVAL=""
 .. S RECORD=$P(^BQIPAT(DFN,20,DXN,1,FN,1,REC,0),U,1),RDATE=$P(^(0),U,2)
 .. S COMPIEN=$P(^BQIPAT(DFN,20,DXN,1,FN,1,REC,0),U,4)
 .. S FREF=$P(^BQIPAT(DFN,20,DXN,1,FN,1,REC,0),U,5)
 .. I FREF'="" D
 ... S COMPREF=$P(^DD(FREF,.01,0),U,1)
 ... S COMPVAL=COMPREF_": "_$$GET1^DIQ(FREF,COMPIEN_",",.01,"E")
 .. I $E(RECORD,1,1)="P" S COMPVAL="Problem: "_$$GET1^DIQ(9000011,$E(RECORD,2,$L(RECORD))_",",.01,"E")
 .. S RTYP=$S($E(RECORD,1,1)="P":"Problem",1:"Visit")
 .. I RDATE="" D
 ... NEW IEN
 ... S IEN=$E(RECORD,2,$L(RECORD))
 ... I $E(RTYP,1,1)="P" S RDATE=$$PROB^BQIUL1(IEN)
 ... I $E(RTYP,1,1)="V" S RDATE=$$GET1^DIQ(9000010,IEN_",",.01,"I")
 .. S II=II+1,BQRES=1
 .. S @DATA@(II)=DXN_U_$$FMTE^BQIUL1(DTMU)_U_FNAME_U_RTYP_U_COMPVAL_U_RECORD_U_$$FMTE^BQIUL1(RDATE)_U
 .. S @DATA@(II)=@DATA@(II)_STAT_U_TAGDTU_U_WHO_U_SCOM_U_OCOM_$C(30)
 Q BQRES
 ;
RDATA(DXN,BRIEN) ;EP
 NEW BQRES,STAT
 S BQRES=0
 S STAT=$P(^BQIREG(BRIEN,0),U,3)
 I STAT="P" D  Q BQRES
 . S FN=0
 . F  S FN=$O(^BQIREG(BRIEN,5,FN)) Q:'FN  D
 .. D FAC(FN,.BQRES)
 ;
 S IEN=""
 F  S IEN=$O(^BQIFACT("C",DFN,DXN,IEN)) Q:IEN=""  D FAC(IEN,.BQRES)
 Q BQRES
 ;
TGG ; If the met criteria is a tag, get the original data to display
 NEW FNAME,DXNN,RIEN
 I FTNAME["-" S FTNAME=$P(FTNAME,"-",2)
 S FTNAME=$P(FTNAME," Tag",1)
 S DXNN=$$GDXN^BQITUTL(FTNAME),LII=II,BNAME=NAME
 S RIEN=""
 F  S RIEN=$O(^BQIREG("C",DFN,DXNN,RIEN)) Q:RIEN=""  D
 . D RDATA(.DXNN,.RIEN)
 . I $O(^BQIPAT(DFN,20,DXNN,0))'="" D GDATA(.DXNN)
 ;I $D(^BQIPAT(DFN,20,DXNN)) D GDATA(DXNN)
 ;I $D(^BQIREG("C",DFN,DXNN)) D RDATA(DXNN)
 F  S LII=$O(@DATA@(LII)) Q:LII=""  S $P(@DATA@(LII),U,1)=DXN
 Q
 ;
HDR ; Set up header
 S @DATA@(II)="I00010DIAG_CAT_IEN^D00030CAT_LAST_UPDATED^T00060FACTOR^T00030PROBVISIT^T00030COMPLIANCE_VALUE^"
 S @DATA@(II)=@DATA@(II)_"T00020PROB_VISIT_IEN^D00030VISIT_DATETIME^T00015STATUS^D00030STATUS_LASTUPDATE^"
 S @DATA@(II)=@DATA@(II)_"T00035UPDATED_BY^T00050COMMENT^T01024OTHER_COMMENT"_$C(30)
 Q
 ;
FAC(FIEN,BQRES) ; EP - Get factor data
 NEW FDATA,FNAME,DTMU,COMPVAL,RDATE,COMPIEN,FREF,RECORD,COMPREF,COMPVAL
 NEW COMPIEN,RTYP,RECORD
 S FDATA=^BQIFACT(FIEN,0)
 S FNAME=$P(FDATA,U,1)
 ;I FNAME[" Tag" S FTNAME=FNAME D TGG Q
 I FNAME["Age:" S RTYP=""
 ;
 ;S DTMU=$P(FDATA,U,4)\1
 S DTMU=$P(FDATA,U,4)
 S COMPVAL=""
 S RDATE=$P(FDATA,U,6)
 S COMPIEN=$P(FDATA,U,5),FREF=$P(FDATA,U,8),RECORD=$P(FDATA,U,7)
 I FREF'="" D
 . S COMPREF=$P(^DD(FREF,.01,0),U,1)
 . S COMPVAL=COMPREF_": "_$$GET1^DIQ(FREF,RECORD_",",.01,"E")
 I $P(COMPIEN,";",2)="AUPNPROB(" S COMPVAL="Problem: "_$$GET1^DIQ(9000011,$P(COMPIEN,";",1)_",",.01,"E"),RTYP="Problem"
 I $P(COMPIEN,";",2)="AUPNVSIT(" S RTYP="Visit"
 ;
 I RDATE="" D
 . NEW IEN
 . S IEN=$P(COMPIEN,";",1)
 . I $E(RTYP,1,1)="P" S RDATE=$$PROB^BQIUL1(IEN)
 . I $E(RTYP,1,1)="V" S RDATE=$$GET1^DIQ(9000010,IEN_",",.01,"I")
 S RECORD=$E(RTYP,1,1)_$P(COMPIEN,";",1)
 S II=II+1
 S @DATA@(II)=DXN_U_$$FMTE^BQIUL1(DTMU)_U_FNAME_U_RTYP_U_COMPVAL_U_RECORD_U_$$FMTE^BQIUL1(RDATE)_U_STAT_U
 S @DATA@(II)=@DATA@(II)_TAGDTU_U_WHO_U_SCOM_U_OCOM_$C(30)
 S BQRES=1
 Q
 ;
FACD(FIEN,FPARMS) ;EP - Get factor data
 K FPARMS
 NEW FNAME,RTYP,FDATA,DTMU,COMPVAL,RDATE,COMPIEN,FREF,RECORD,COMPVAL
 NEW COMPREF
 S FDATA=^BQIFACT(FIEN,0)
 S FNAME=$P(FDATA,U,1)
 I FNAME["Age:" S RTYP=""
 ;
 ;S DTMU=$P(FDATA,U,4)\1
 S DTMU=$P(FDATA,U,4)
 S COMPVAL=""
 S RDATE=$P(FDATA,U,6)
 S COMPIEN=$P(FDATA,U,5),FREF=$P(FDATA,U,8),RECORD=$P(FDATA,U,7)
 I FREF'="" D
 . S COMPREF=$P(^DD(FREF,.01,0),U,1)
 . S COMPVAL=COMPREF_": "_$$GET1^DIQ(FREF,RECORD_",",.01,"E")
 I $P(COMPIEN,";",2)="AUPNPROB(" S COMPVAL="Problem: "_$$GET1^DIQ(9000011,$P(COMPIEN,";",1)_",",.01,"E"),RTYP="Problem"
 I $P(COMPIEN,";",2)="AUPNVSIT(" S RTYP="Visit"
 ;
 I RDATE="" D
 . NEW IEN
 . S IEN=$P(COMPIEN,";",1)
 . I $E(RTYP,1,1)="P" S RDATE=$$PROB^BQIUL1(IEN)
 . I $E(RTYP,1,1)="V" S RDATE=$$GET1^DIQ(9000010,IEN_",",.01,"I")
 S RECORD=$E(RTYP,1,1)_$P(COMPIEN,";",1)
 S FPARMS(1)=FNAME,FPARMS(2)=RTYP,FPARMS(3)=COMPVAL,FPARMS(4)=RECORD,FPARMS(5)=$$FMTE^BQIUL1(RDATE)
 Q
 ;
FPD(BQIDFN,BQITAG,FPARMS) ;EP - Get proposed factor data
 K FPARMS
 NEW BQIFN,BQIFAC,BQIRN,BQIREC,BQIRDT,BQIREX,BQIIEN,COMPVAL,RTYP,BQIFIL
 NEW COMPREF,BQIVPR
 S BQIFN=0
 F  S BQIFN=$O(^BQIPAT(BQIDFN,20,BQITAG,1,BQIFN)) Q:'BQIFN  D
 . S BQIFAC=$P(^BQIPAT(BQIDFN,20,BQITAG,1,BQIFN,0),U,1)
 . I BQIFAC["Age:" S BQIVPR=""
 . S BQIRN=0
 . F  S BQIRN=$O(^BQIPAT(BQIDFN,20,BQITAG,1,BQIFN,1,BQIRN)) Q:'BQIRN  D
 .. S BQIREC=$P(^BQIPAT(BQIDFN,20,BQITAG,1,BQIFN,1,BQIRN,0),U,1)
 .. S BQIRDT=$P(^BQIPAT(BQIDFN,20,BQITAG,1,BQIFN,1,BQIRN,0),U,2)
 .. S BQIREX=$P(^BQIPAT(BQIDFN,20,BQITAG,1,BQIFN,1,BQIRN,0),U,3)
 .. S BQIIEN=$P(^BQIPAT(BQIDFN,20,BQITAG,1,BQIFN,1,BQIRN,0),U,4)
 .. S BQIFIL=$P(^BQIPAT(BQIDFN,20,BQITAG,1,BQIFN,1,BQIRN,0),U,5)
 .. S COMPVAL=""
 .. S RTYP=$S($E(BQIREC,1,1)="V":"Visit",1:"Problem")
 .. S COMPVAL="Problem: "_$$GET1^DIQ(9000011,$E(BQIREC,2,$L(BQIREC))_",",.01,"E")
 .. I BQIFIL'="" D
 ... S COMPREF=$P(^DD(BQIFIL,.01,0),U,1)
 ... S COMPVAL=COMPREF_": "_$$GET1^DIQ(BQIFIL,BQIIEN_",",.01,"E")
 .. S FPARMS(BQIFN_BQIRN,1)=BQIFAC,FPARMS(BQIFN_BQIRN,2)=RTYP,FPARMS(BQIFN_BQIRN,3)=COMPVAL
 .. S FPARMS(BQIFN_BQIRN,4)=BQIREC,FPARMS(BQIFN_BQIRN,5)=$$FMTE^BQIUL1(BQIRDT)
 Q