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

BQIPTMSR.m

Go to the documentation of this file.
BQIPTMSR ;PRXM/HC/ALA-Patient Measurements ; 23 Feb 2007  3:17 PM
 ;;2.4;ICARE MANAGEMENT SYSTEM;;Apr 01, 2015;Build 41
 ;
 Q
 ;
MSR(DATA,DFN,DRANGE) ; EP -- BQI PATIENT MEASUREMENTS
 ;
 ;Description - all the measurements that a patient has
 ;
 ;Input
 ;  DFN - Patient internal entry number
 ;  DRANGE - Date range as a relative date ie. T-6M
 ;
 NEW UID,II,IEN,TIEN,TNAME,VISIT,VSDTM,VALUE,OPROV,EPROV,PERCNT
 NEW BI,BMI,HDR,IENSMS,ORPHY,EVDTM,QN,N,QUAL
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BQIPTMSR",UID))
 K @DATA
 ;
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQIPTMSR D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ;
 S DRANGE=$$DATE^BQIUL1($G(DRANGE))
 S @DATA@(II)="I00010MEAS_IEN^I00010VISIT_IEN^D00030VISIT_DATETIME^T00030TYPE_DESC^T00100VALUE^D00030EVENT_DATETIME^N00005PERCENTILE^T01024QUALIF"_$C(30)
 S IEN=""
 F  S IEN=$O(^AUPNVMSR("AC",DFN,IEN),-1) Q:IEN=""  D
 . S TIEN=$$GET1^DIQ(9000010.01,IEN_",",.01,"I") I TIEN="" 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
 . S TNAME=$$GET1^DIQ(9999999.07,TIEN_",",.02,"E")
 . S VISIT=$$GET1^DIQ(9000010.01,IEN_",",.03,"I") I VISIT="" Q
 . S VSDTM=$$GET1^DIQ(9000010,VISIT_",",.01,"I") I VSDTM=0 Q
 . I DRANGE'="",(VSDTM\1<DRANGE) Q
 . S VALUE=$$GET1^DIQ(9000010.01,IEN_",",.04,"E")
 . S PERCNT=$$GET1^DIQ(9000010.01,IEN_",",.05,"E") S:PERCNT="" PERCNT=-1
 . ;S OPROV=$$GET1^DIQ(9000010.01,IEN_",",1202,"E")
 . ;S EPROV=$$GET1^DIQ(9000010.01,IEN_",",1204,"E")
 . S EVDTM=$$GET1^DIQ(9000010.01,IEN_",",1201,"I")
 . S QUAL="",N=0
 . F  S N=$O(^AUPNVMSR(IEN,5,N)) Q:'N  D
 .. S QN=$P(^AUPNVMSR(IEN,5,N,0),U,1)
 .. S QUAL=QUAL_$P($G(^GMRD(120.52,QN,0)),U,1)_"; "
 . S QUAL=$$TKO^BQIUL1(QUAL,"; ")
 . S II=II+1,@DATA@(II)=IEN_U_VISIT_U_$$FMTE^BQIUL1(VSDTM)_U_TNAME_U_VALUE_U_$$FMTE^BQIUL1(EVDTM)_U_PERCNT_U_QUAL_$C(30)
 ;
 ; Check for refusals
 D REF
 ;
DONE ;
 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
 ;
REF ; Check for refusals
 NEW MSRN,RVDT,REVDT,RFIEN,VISIT,PERCNT,TNAME,VALUE
 S MSRN=""
 F  S MSRN=$O(^AUPNPREF("AA",DFN,9999999.07,MSRN)) Q:MSRN=""  D
 . S RVDT=""
 . F  S RVDT=$O(^AUPNPREF("AA",DFN,9999999.07,MSRN,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,9999999.07,MSRN,RVDT,RFIEN)) Q:RFIEN=""  D
 ... S TNAME=$$GET1^DIQ(9999999.07,MSRN_",",.01,"E")
 ... S VALUE=$$GET1^DIQ(9000022,RFIEN_",",.07,"E")
 ... S ORPHY=$$GET1^DIQ(9000022,RFIEN_",",1204,"E")
 ... S PERCNT=-1,VISIT="",EVDTM=""
 ... S II=II+1,@DATA@(II)=U_VISIT_U_$$FMTE^BQIUL1(REVDT)_U_TNAME_U_VALUE_U_EVDTM_U_PERCNT_$C(30)
 Q
 ;
LST(DATA,DFN) ;EP -- BQI PATIENT LAST MEASURES
 ; Input
 ;   DFN - Patient IEN
 NEW UID,II,IEN,QUAL,HDR,VISIT,VSDTM,BMI,IENS,BI,TIEN,TNAME,VALUE,BQISORT,MEAS,N
 NEW BMID,MSN,QFL
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP("BQIPTMSR",UID))
 K @DATA
 ;
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQIPTMSR D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ;
 S HDR="I00010MEAS_IEN^I00010VISIT_IEN^D00030EVENT_VISIT_DATETIME^T00030TYPE_DESC^T00100VALUE^T01024QUALIF^T00010BMI"
 S @DATA@(II)=HDR_$C(30)
 ;
 K BQISORT
 S IEN=""
 F  S IEN=$O(^AUPNVMSR("AC",DFN,IEN),-1) Q:IEN=""  D
 . S VISIT=$$GET1^DIQ(9000010.01,IEN_",",.03,"I") I VISIT="" Q
 . S VSDTM=$$GET1^DIQ(9000010,VISIT_",",.01,"I")\1 I VSDTM=0 Q
 . S BQISORT(VSDTM)=VISIT
 ;
 K MEAS
 ;S BMI=$$OBMI^BQITBMI(DFN,""),QUAL=""
 S BMID=$$PBMI^APCLV(DFN,DT),QUAL=""
 S BMI=$P(BMID,"^",1)
 I BMI'="" D
 . F BI=4,7 S VISIT=$P(BMID,"^",BI) D
 .. S VSDTM=$P($G(^AUPNVSIT(VISIT,0)),"^",1)\1 I VSDTM=0 Q
 .. I BI=4 S TNAME="HEIGHT",VALUE=$P(BMID,"^",2)
 .. I BI=7 S TNAME="WEIGHT",VALUE=$P(BMID,"^",5)
 .. S MSN=$$FIND1^DIC(9999999.07,,"MX",TNAME)
 .. S IEN=$P(BMID,"^",10)
 .. I IEN="" D
 ... S MIEN="",QFL=0
 ... F  S MIEN=$O(^AUPNVMSR("AD",VISIT,MIEN)) Q:MIEN=""!(QFL)  D
 .... I $P(^AUPNVMSR(MIEN,0),U,1)=MSN S IEN=MIEN,QFL=1
 .. ; 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
 .. S QUAL="",N=0
 .. F  S N=$O(^AUPNVMSR(IEN,5,N)) Q:'N  D
 ... S QN=$P(^AUPNVMSR(IEN,5,N,0),U,1)
 ... S QUAL=QUAL_$P($G(^GMRD(120.52,QN,0)),U,1)_"; "
 .. S QUAL=$$TKO^BQIUL1(QUAL,"; ")
 .. S MEAS(TNAME)=VSDTM
 .. S II=II+1,@DATA@(II)=IEN_U_VISIT_U_$$FMTE^BQIUL1(VSDTM)_U_TNAME_U_VALUE_U_QUAL_U_$J(BMI,3,2)_$C(30)
 I BMI="" D
 . NEW HT,WT,VSDTM,VISIT,VALUE,IEN
 . S HT=$$MREC^BQIUTIL(DFN,9000010.01,"HT")
 . S VISIT=$P(HT,U,4),VALUE=$P(HT,U,3),IEN=$P(HT,U,5),VSDTM=$P(HT,U,2)
 . S QUAL="",N=0
 . I HT F  S N=$O(^AUPNVMSR(IEN,5,N)) Q:'N  D
 .. S QN=$P(^AUPNVMSR(IEN,5,N,0),U,1)
 .. S QUAL=QUAL_$P($G(^GMRD(120.52,QN,0)),U,1)_"; "
 . S QUAL=$$TKO^BQIUL1(QUAL,"; ")
 . I VALUE="" S VALUE="None found"
 . S MEAS("HEIGHT")=VSDTM
 . S II=II+1,@DATA@(II)=IEN_U_VISIT_U_$$FMTE^BQIUL1(VSDTM)_U_"HEIGHT"_U_VALUE_U_QUAL_U_"NC"_$C(30)
 . S WT=$$MREC^BQIUTIL(DFN,9000010.01,"WT")
 . S VISIT=$P(WT,U,4),VALUE=$P(WT,U,3),IEN=$P(WT,U,5),VSDTM=$P(WT,U,2)
 . S QUAL="",N=0
 . I WT F  S N=$O(^AUPNVMSR(IEN,5,N)) Q:'N  D
 .. S QN=$P(^AUPNVMSR(IEN,5,N,0),U,1)
 .. S QUAL=QUAL_$P($G(^GMRD(120.52,QN,0)),U,1)_"; "
 . S QUAL=$$TKO^BQIUL1(QUAL,"; ")
 . I VALUE="" S VALUE="None found"
 . S MEAS("WEIGHT")=VSDTM
 . S II=II+1,@DATA@(II)=IEN_U_VISIT_U_$$FMTE^BQIUL1(VSDTM)_U_"WEIGHT"_U_VALUE_U_QUAL_U_"NC"_$C(30)
 ;
 S VSDTM=$O(BQISORT(""),-1) I VSDTM="" G DONE
 S VISIT=BQISORT(VSDTM)
 ;
 S IEN="",BMI=""
 F  S IEN=$O(^AUPNVMSR("AD",VISIT,IEN)) Q:IEN=""  D
 . S TIEN=$$GET1^DIQ(9000010.01,IEN_",",.01,"I") I TIEN="" 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
 . S TNAME=$$GET1^DIQ(9999999.07,TIEN_",",.02,"E")
 . I $G(MEAS(TNAME))'="" Q
 . S VALUE=$$GET1^DIQ(9000010.01,IEN_",",.04,"E")
 . S QUAL="",N=0
 . F  S N=$O(^AUPNVMSR(IEN,5,N)) Q:'N  D
 .. S QN=$P(^AUPNVMSR(IEN,5,N,0),U,1)
 .. S QUAL=QUAL_$P($G(^GMRD(120.52,QN,0)),U,1)_"; "
 . S QUAL=$$TKO^BQIUL1(QUAL,"; ")
 . S BQIMEAS(TNAME)=IEN_U_VISIT_U_$$FMTE^BQIUL1(VSDTM)_U_TNAME_U_VALUE_U_QUAL_U_BMI
 ;
 NEW MS
 S MS=""
 F  S MS=$O(BQIMEAS(MS)) Q:MS=""  D
 . S II=II+1,@DATA@(II)=BQIMEAS(MS)_$C(30)
 K MEAS,BQIMEAS
 G DONE