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

BDMDM7.m

Go to the documentation of this file.
BDMDM7 ; IHS/CMI/LAB - BLOOD SUGAR TAKEN/LAST 3 ;
 ;;2.0;DIABETES MANAGEMENT SYSTEM;**2**;JUN 14, 2007
 ;
 ;
BSTAKEN ;EP
 K BDMLVST,BDMLGLU
 K ^TMP("BDMDM FETCH",$J) S BDMX=BDMPD_"^ALL LAB [DM AUDIT GLUCOSE TESTS TAX"_BDMDATE,BDMY="^TMP(""BDMDM FETCH"",$J," S BDMER=$$START1^APCLDF(BDMX,BDMY)
 I BDMER W !,"*** SCRIPT ERROR IN DMGLUCOSE^BDMDM7.  CONTACT SITE MANAGER" G BSTAKENX
 F BDML=1:1 Q:'$D(^TMP("BDMDM FETCH",$J,BDML))  S BDMLVST($P(^TMP("BDMDM FETCH",$J,BDML),U,5))=$P(^AUPNVLAB(+$P(^TMP("BDMDM FETCH",$J,BDML),U,4),0),U)_U_^TMP("BDMDM FETCH",$J,BDML)
 K BDM,^TMP("BDMDM FETCH",$J)
 K BDM S BDMY="BDM(",BDMX=BDMPD_"^LAST LAB [DM AUDIT HGB A1C TAX"_BDMDATE S BDMER=$$START1^APCLDF(BDMX,BDMY) S ^TMP("BDM",$J,32)=$S($D(BDM(1)):$P(BDM(1),U,2)_"%",1:"-")
 S (BDMYES,BDMNTOT)=0 F BDML=1:1:BDMTOT Q:'$D(^TMP("BDMDM DXVS",$J,BDML))  D
 .S BDMVDFN=^TMP("BDMDM DXVS",$J,BDML)
 .S BDMNTOT=BDMNTOT+1
 .I $D(BDMLVST(BDMVDFN)) S BDMYES=BDMYES+1 ;***
 .Q
 I 'BDMNTOT S ^TMP("BDM",$J,9)="No DM visits (01,06,28 clinics only)" G BSTAKENC
 NEW V S V=(BDMYES/BDMNTOT)*100,V=$J(V,2,0)
 S ^TMP("BDM",$J,9)=$S(V<75:"NO",1:"YES")_" - "_V_"%"
BSTAKENC I BDMCUML S BDMGOT1=$S(^TMP("BDM",$J,9)["YES":1,1:0),BDMSUB=15 D CUML^BDMDM1
BSTAKENX K BDMNTOT
LAST3BS ;GET LAST THREE
 K BDMLGLU,BDML3R
 S V=0 F  S V=$O(BDMLVST(V)) Q:V'=+V  D
 .I $P(^AUPNVSIT(V,0),U,8)]"",$P(^(0),U,8)=BDMERCO Q  ;don't count er visits in last 3
 .S BDMLGLU(9999999-$P(BDMLVST(V),U,2),$P($P(BDMLVST(V),U,5),";"))=$P(BDMLVST(V),U,4)_" - "_$S($P(^LAB(60,$P(BDMLVST(V),U),0),U)["FAST":"FASTING",1:"RANDOM")_" - "_$P(BDMLVST(V),U,3)
 S (BDMX,BDMY,BDMZ)=0 F  Q:BDMZ=3  S BDMX=$O(BDMLGLU(BDMX)) Q:BDMX=""  F  S BDMY=$O(BDMLGLU(BDMX,BDMY)) Q:'BDMY!(BDMZ=3)  D
 .S BDMZ=BDMZ+1,^TMP("BDM",$J,10_"."_BDMZ)=BDMLGLU(BDMX,BDMY),Y=(9999999-BDMX) D DD^%DT S ^TMP("BDM",$J,38_"."_BDMZ)=Y
 I BDMCUML D BSLEVEL
 K BDMLVST,BDMBEL,BDMLAB,BDMCOUN,BDMTYPE,BDMLGLU,BDMTEST,BDMYES,BDMX,BDMY,BDMZ
 Q
 ;
X7 K BDMLVST,BDMBEL,BDMLAB,BDMCOUN,BDMTYPE,BDMERCO,BDML3R,BDMLGLU
 Q
BSLEVEL ;calculate bs control
 ;get last Hemoglobin A1C in time frame, if there is one,
 ;use it to calculate :
 ;    ---> acceptable <=7.5
 ;    ---> fair       7.6-10.0
 ;    ---> high       10.1-12.0
 ;    ---> very high  >12.0
 ;quit
 ;if no hgla1c get last 3 bs's - if not three put in undocumented
 ;take mean of 3
 K BDM S BDMY="BDM(",BDMX=BDMPD_"^LAST LAB [DM AUDIT HGB A1C TAX"_BDMDATE
 S BDMER=$$START1^APCLDF(BDMX,BDMY) I $D(BDM(1)),$P(BDM(1),U,2)]"",$P(BDM(1),U,2)'="?" D  Q
 .S V=$P(BDM(1),U,2)
 .I V<7.6 S BDMGOT1=1,BDMSUB=16 D CUML^BDMDM1 D  Q
 ..S BDMGOT1=0 F BDMSUB=17,18,58,59 D CUML^BDMDM1
 .;
 .I V>7.5&(V<10.1) S BDMGOT1=1,BDMSUB=17 D CUML^BDMDM1 D  Q
 ..S BDMGOT1=0 F BDMSUB=16,18,58,59 D CUML^BDMDM1
 .;
 .I V>10.0&(V<12.1) S BDMGOT1=1,BDMSUB=18 D CUML^BDMDM1 D  Q
 ..S BDMGOT1=0 F BDMSUB=16,17,58,59 D CUML^BDMDM1
 .I V>12.0 S BDMGOT1=1,BDMSUB=58 D CUML^BDMDM1 D  Q
 ..S BDMGOT1=0 F BDMSUB=16,17,18,59 D CUML^BDMDM1
GLUCOSE ;check mean of last 3 glucose results
 I '$D(^TMP("BDM",$J,10.3)) S BDMGOT1=1,BDMSUB=59 D CUML^BDMDM1 D  Q
 .S BDMGOT1=0 F BDMSUB=16,17,18,58 D CUML^BDMDM1
 S BDMTOT=""
 S C=0 F X=10.1,10.2,10.3 S V=+(+$P(^TMP("BDM",$J,X),"- ",3)) I V S C=C+1,BDMTOT=BDMTOT+V
 I C'=3 S BDMGOT1=1,BDMSUB=59 D CUML^BDMDM1 D  Q
 .S BDMGOT1=0 F BDMSUB=16,17,18,58 D CUML^BDMDM1
 S X=BDMTOT/3
 I X<166 S BDMGOT1=1,BDMSUB=16 D CUML^BDMDM1 D  Q
 .S BDMGOT1=0 F BDMSUB=17,18,58,59 D CUML^BDMDM1
 I X>165,X<251 S BDMGOT1=1,BDMSUB=17 D CUML^BDMDM1 D  Q
 .S BDMGOT1=0 F BDMSUB=16,18,58,59 D CUML^BDMDM1
 I X>250,X<341 S BDMSUB=18,BDMGOT1=1 D CUML^BDMDM1 D  Q
 .S BDMGOT1=0 F BDMSUB=16,17,58,59 D CUML^BDMDM1
 I X>340 S BDMSUB=58,BDMGOT1=1 D CUML^BDMDM1 D  Q
 .S BDMGOT1=0 F BDMSUB=16,17,18,59 D CUML^BDMDM1
 Q