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

APCLACG1.m

Go to the documentation of this file.
APCLACG1 ; IHS/CMI/LAB - IHS GPRA 09 SELECTED REPORT DRIVER 21 May 2008 12:10 PM ; 11 Dec 2009  6:32 AM
 ;;2.0;IHS PCC SUITE;**2**;MAY 14, 2009
 ;
PROC ;EP
 S APCLJOB=$J,APCLBTH=$H,(APCLUPOP,APCLUPWR,APCLUPAC,APCLRPOP,APCLRPWR,APCLRPAC,APCLRPWA,APCLRPIN,APCLRPI9,APCLRPVK,APCLRPMI,APCLRPMN,APCLRPNI,APCLRPNN,APCLRPMU,APCLRPNU)=0
 K ^TMP($J)
 K APCLEHRL
 I APCLGRP="E" D PLSTPTS^BEHOPTP2(.APCLEHRL,$P(APCLICP,U,2)) D
 .S X=0 F  S X=$O(APCLEHRL(X)) Q:X'=+X  S ^XTMP("APCLACG",APCLJOB,APCLBTH,"PATIENTS",$P(APCLEHRL(X),U,1))="",APCLRPOP=APCLRPOP+1
 K APCLEHRL
 I APCLGRP="I" D RET^BQIPLDFN(.APCLEHRL,DUZ,$P(APCLICP,U,2)) D
 .S X=0 F  S X=$O(^TMP("BQIPLDFN",$J,X)) Q:X'=+X  I ^TMP("BQIPLDFN",$J,X) S ^XTMP("APCLACG",APCLJOB,APCLBTH,^TMP("BQIPLDFN",$J,X))="",APCLRPOP=APCLRPOP+1
 D XTMP^APCLOSUT("APCLACG",DT)
 S APCL3YE=$$FMADD^XLFDT(APCLED,(3*-365))
 S DFN=0 F  S DFN=$O(^AUPNPAT(DFN)) Q:DFN'=+DFN  D
 .Q:'$D(^DPT(DFN,0))
 .S (APCLUP,APCLFAC,APCLPTWR,APCLPTAC,APCLWRAC,APCLPINR,APCLPTI9,APCLPTVK,APCLPTMI,APCLPTMN,APCLPTNI,APCLPTNN,APCLPTMU,APCLPTNU)=0
 .S APCLUP=0  ;PATIENT USER POP FLAG
 .S APCLPTWR=0 ;PATIENT WARFARIN FLAG
 .S APCLPTAC=0  ;PATIENT AC CLINIC FLAG
 .S APCLWRAC=0  ;patient on warfarin and ac clinic visit
 .S APCLUP=$$ACTUP(DFN,APCL3YE,APCLED,APCLTAXI)
 .I APCLUP S APCLUPOP=APCLUPOP+1  ;,^XTMP("APCLACG",APCLJ,APCLH,"LIST 1",DFN)=""  ;TOTAL USER POP COUNTER
 .I 'APCLUP G RPTPOP
 .K APCLV
 .K APCLMEDS
 .D GETMEDS^APCHSMU1(DFN,$$FMADD^XLFDT(APCLED,-45),APCLED,"BGP CMS WARFARIN MEDS",,,"WARFARIN",.APCLMEDS)
 .I $D(APCLMEDS) S APCLPTWR=1 I APCLUP S APCLUPWR=APCLUPWR+1
 .S APCLV="APCLV"
 .D ALLV^APCLAPIU(DFN,APCLBD,APCLED,.APCLV)
 .;now see if any visit is to one of the anticoag clinics
 .S X=0 F  S X=$O(APCLV(X)) Q:X'=+X!(APCLPTAC)  D
 ..S V=$P(APCLV(X),U,5)
 ..S C=$P(^AUPNVSIT(V,0),U,8)
 ..Q:C=""
 ..I $D(APCLACCL(C)) S APCLPTAC=1
 .I APCLPTAC,APCLPTWR S APCLWRAC=1 I APCLUP S APCLUPAC=APCLUPAC+1
 .;
RPTPOP .;
 .;GET all patients in the report pop into ^XTMP("APCLACG",APCLJOB,APCLBTH,"PATIENTS") and count in APCLRPOP
 .I APCLGRP="W",APCLPTWR S ^XTMP("APCLACG",APCLJOB,APCLBTH,"PATIENTS",DFN)="",APCLRPOP=APCLRPOP+1
 .I APCLGRP="A",APCLPTAC S ^XTMP("APCLACG",APCLJOB,APCLBTH,"PATIENTS",DFN)="",APCLRPOP=APCLRPOP+1
 .I APCLGRP="S",$D(^DIBT(APCLSTMP,1,DFN)) S ^XTMP("APCLACG",APCLJOB,APCLBTH,"PATIENTS",DFN)="",APCLRPOP=APCLRPOP+1
 .I $D(^XTMP("APCLACG",APCLJOB,APCLBTH,"PATIENTS",DFN)),APCLPTAC S APCLRPAC=APCLRPAC+1
 .I $D(^XTMP("APCLACG",APCLJOB,APCLBTH,"PATIENTS",DFN)),APCLPTWR S APCLRPWR=APCLRPWR+1
 .I $D(^XTMP("APCLACG",APCLJOB,APCLBTH,"PATIENTS",DFN)),APCLPTWR,APCLPTAC S APCLRPWA=APCLRPWA+1
 .Q:'$D(^XTMP("APCLACG",APCLJOB,APCLBTH,"PATIENTS",DFN))  ;rest is for report pop only
 .K APCLINR
 .S APCLV="APCLINR"
 .D ALLLAB^APCLAPIU(DFN,$$FMADD^XLFDT(APCLED,-45),APCLED,$O(^ATXLAB("B","BJPC INR LAB TESTS",0)),$O(^ATXAX("B","BJPC INR LAB LOINCS",0)),"INR",.APCLV)
 .S X=0 F  S X=$O(APCLINR(X)) Q:X'=+X  D
 ..S APCLPINR=1  ;had an INR
 ..I $P(APCLINR(X),U,3)>9 S APCLPTI9=1
 .;if had at least 1 >9 table all of them for display later
 .I APCLPTI9 S APCLRPI9=APCLRPI9+1 S X=0 F  S X=$O(APCLINR(X)) Q:X'=+X  S ^XTMP("APCLACG",APCLJOB,APCLBTH,"INR >9",DFN,$P(APCLINR(X),U,1),$P(APCLINR(X),U,4))=$P(APCLINR(X),U,3)
 .I APCLPINR S APCLRPIN=APCLRPIN+1
 .;VITAMIN K
 .K APCLMEDS
 .D GETMEDS^APCHSMU1(DFN,APCLBD,APCLED,,,,"PHYTONADIONE",.APCLMEDS)
 .I $D(APCLMEDS) S APCLPTVK=1 S APCLRPVK=APCLRPVK+1
 .S X=0,D="" F  S X=$O(APCLMEDS(X)) Q:X'=+X  S D=$P(APCLMEDS(X),U,1)
 .I APCLPTVK S ^XTMP("APCLACG",APCLJOB,APCLBTH,"VITK",DFN)=D
MONT .;THOSE on warfarin and monitored were they within range
 .I APCLWRAC D  Q
 ..;get last INR value in date range
 ..S APCLLINR=$P($$LASTINR^APCLACGM(DFN,APCLBD,APCLED),U,3)
 ..;get last goal in date range
 ..S APCLGINR=$$INRGOAL^APCLACGM(DFN,APCLED)
 ..I APCLLINR=""!(APCLGINR="")!(+APCLLINR=0) S APCLPTMU=1,APCLRPMU=APCLRPMU+1,^XTMP("APCLACG",APCLJOB,APCLBTH,"MONT UNABLE TO ASSESS",DFN)=APCLLINR_U_APCLGINR Q
 ..S L=$P(APCLGINR," - ",1)
 ..S H=$P(APCLGINR," - ",2)
 ..I APCLLINR'<L,APCLLINR'>H S APCLPTMI=1,APCLRPMI=APCLRPMI+1,^XTMP("APCLACG",APCLJOB,APCLBTH,"MONT IN RANGE",DFN)=APCLLINR_U_APCLGINR Q
 ..S APCLPTMN=1,APCLRPMN=APCLRPMN+1,^XTMP("APCLACG",APCLJOB,APCLBTH,"MONT NOT IN RANGE",DFN)=APCLLINR_U_APCLGINR
NOTMONT .;NOT MONITORED
 .I APCLPTWR,'APCLPTAC D
 ..;get last INR value in date range
 ..S APCLLINR=$P($$LASTINR^APCLACGM(DFN,APCLBD,APCLED),U,3)
 ..;get last goal in date range
 ..S APCLGINR=$$INRGOAL^APCLACGM(DFN,APCLED)
 ..I APCLLINR=""!(APCLGINR="")!(+APCLLINR=0) S APCLPTNU=1,APCLRPNU=APCLRPNU+1,^XTMP("APCLACG",APCLJOB,APCLBTH,"NOT MONT UNABLE TO ASSESS",DFN)=APCLLINR_U_APCLGINR Q
 ..S L=$P(APCLGINR," - ",1)
 ..S H=$P(APCLGINR," - ",2)
 ..I APCLLINR'<L,APCLLINR'>H S APCLPTNI=1,APCLRPNI=APCLRPNI+1,^XTMP("APCLACG",APCLJOB,APCLBTH,"NOT MONT IN RANGE",DFN)=APCLLINR_U_APCLGINR Q
 ..S APCLPTNN=1,APCLRPNN=APCLRPNN+1,^XTMP("APCLACG",APCLJOB,APCLBTH,"NOT MONT NOT IN RANGE",DFN)=APCLLINR_U_APCLGINR
 Q
ACTUP(P,BDATE,EDATE,T) ;EP - is this patient in user pop?
 ;I B=1,$$BEN^AUPNPAT(P,"C")'="01" Q 0  ;must be Indian/Alaskan Native
 ;I B=2,$$BEN^AUPNPAT(P,"C")="01" Q 0  ;must not be I/A
 NEW DOD
 S DOD=$$DOD^AUPNPAT(P) I DOD]"",DOD<EDATE Q 0
 S X=$P($G(^AUPNPAT(P,11)),U,18) I X="" Q 0
 I '$D(^ATXAX(T,21,"B",($P(^AUPNPAT(P,11),U,18)))),'$D(^ATXAX(T,21,"AA",$P(^AUPNPAT(P,11),U,18),$P(^AUPNPAT(P,11),U,18))) Q 0
 S X=$$LASTVD(P,BDATE,EDATE)
 Q $S(X:1,1:0)
 ;
LASTVD(P,BDATE,EDATE) ;
 I '$D(^AUPNVSIT("AC",P)) Q ""
 NEW APCHV,A,B,G,X
 S APCLV="APCLV"
 D ALLV^APCLAPIU(P,BDATE,EDATE,.APCLV)
 S (X,G)=0 F  S X=$O(APCLV(X)) Q:X'=+X!(G)  S V=$P(APCLV(X),U,5) D
 .Q:'$D(^AUPNVSIT(V,0))
 .Q:'$P(^AUPNVSIT(V,0),U,9)
 .Q:$P(^AUPNVSIT(V,0),U,11)
 .Q:'$D(^AUPNVPRV("AD",V))
 .Q:"SAHOM"'[$P(^AUPNVSIT(V,0),U,7)
 .Q:"V"[$P(^AUPNVSIT(V,0),U,3)
 .Q:$P(^AUPNVSIT(V,0),U,6)=""
 .S G=1
 .Q
 Q G