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

APCHS12.m

Go to the documentation of this file.
APCHS12 ; IHS/CMI/LAB - PART 12 OF APCHS -- SUMMARY PRODUCTION COMPONENTS ;
 ;;2.0;IHS PCC SUITE;**11**;MAY 14, 2009;Build 58
 ;
 ;cmi/anch/maw 8/28/2007 code set versioning in PVCH and FLOWCP
 ;
FLOW ; ********** FLOWSHEET PRODUCTION **********
 ; <SETUP>
 Q:'$D(^AUPNVSIT("AA",APCHSPAT))
 S APCHSFNM=0
 S APCHSND2=APCHSNDM
 F APCHSFOR=0:0 S APCHSFOR=$O(^APCHSCTL(APCHSTYP,6,APCHSFOR)) Q:'APCHSFOR  S APCHSNDM=APCHSND2 D FLOWOUT Q:$D(APCHSQIT)
FLOWX K APCHSFOR,APCHSND2,APCHSDUS,APCHSFCN,APCHSIVD,APCHSTB,APCHSDB,APCHSI,APCHST,APCHSW,APCHSFDF,APCHSAS,APCHSVDF,APCHSN,APCHSIT,APCHSCLN
 K APCHSDAT,APCHSIDF,APCHSITP,APCHSJ,APCHSL,APCHSMXL,APCHSTTL,APCHSVGL,APCHSX,APCHSXT,APCHSII,APCHSNGL,APCHSXS,APCHSFXF
 K APCHSFOK,APCHSPI,APCHSCI,APCHSC1,APCHSC2,APCHSCM,APCHSFNM
 Q
FLOWOUT ; <DISPLAY>
 S APCHSFDF=$P(^APCHSCTL(APCHSTYP,6,APCHSFOR,0),U,2)
 D FLOWCHK Q:'APCHSFOK
 Q:'$$GENDER(APCHSFDF,APCHSPAT)  ;not correct gender
 Q:'$$AGE(APCHSFDF,APCHSPAT)  ;not correct age
 S APCHSFNM=APCHSFNM+1 I APCHSFNM=1 X APCHSCKP Q:$D(APCHSQIT)  X:'APCHSNPG APCHSBRK
 S APCHSFCN=$P(^APCHSFLC(APCHSFDF,0),U,1)
 D FLOWTB
 X APCHSCKP Q:$D(APCHSQIT)  D FLOWHD
 S APCHSIVD="" F APCHSQ=0:0 S APCHSIVD=$O(^AUPNVSIT("AA",APCHSPAT,APCHSIVD)) Q:APCHSIVD=""!(APCHSIVD>APCHSDLM)  D FLOWBD Q:$D(APCHSQIT)  I APCHSDUS S APCHSNDM=APCHSNDM-1 Q:APCHSNDM=0
 X APCHSCKP Q:$D(APCHSQIT)  I 'APCHSNPG S APCHSP="",$P(APCHSP,"-",APCHSMXL+9)="" W ?2,APCHSP,!
 X APCHSCKP Q:$D(APCHSQIT)  I 'APCHSNPG W !
 Q
FLOWCHK ; <SCREEN>
 I '$O(^APCHSFLC(APCHSFDF,2,0)) S APCHSFOK=1 Q
 S APCHSFOK=0
 ;Q:'$O(^AUPNPROB("AC",APCHSPAT,0))
 F APCHSPI=0:0 S APCHSPI=$O(^AUPNPROB("AC",APCHSPAT,APCHSPI)) Q:'APCHSPI  D FLOWCP Q:APCHSFOK
 Q:APCHSFOK  ;found on Problem list
PVCH ;IHS/CMI/LAB - now check for dx in past year per Bill and Charlton by pcp
 K APCHY,APCHV,^TMP($J,"ALL VISITS")
 S APCHSNVN=$S($P($G(^APCHSITE(DUZ(2),12,APCHSFDF,0)),U,2):$P($G(^APCHSITE(DUZ(2),12,APCHSFDF,0)),U,2),1:1)
 S APCHSNYR=$S($P($G(^APCHSITE(DUZ(2),12,APCHSFDF,0)),U,3):$P($G(^APCHSITE(DUZ(2),12,APCHSFDF,0)),U,3),1:1)
 S APCHSNYR=APCHSNYR*365
 S APCHSBD=$$FMADD^XLFDT(DT,-(APCHSNYR))
 S APCHY="^TMP($J,""ALL VISITS"",",%=APCHSPAT_"^ALL VISITS;DURING "_$$FMTE^XLFDT(APCHSBD)_"-"_$$FMTE^XLFDT(DT),E=$$START1^APCLDF(%,APCHY)
 I '$D(^TMP($J,"ALL VISITS",1)) Q
 S (X,APCHSCNT,APCHSFOK)=0 F  S X=$O(^TMP($J,"ALL VISITS",X)) Q:X'=+X!(APCHSFOK)  S V=$P(^TMP($J,"ALL VISITS",X),U,5) D
 .Q:'$P(^AUPNVSIT(V,0),U,9)
 .Q:$P(^AUPNVSIT(V,0),U,11)
 .Q:"DAHO"'[$P(^AUPNVSIT(V,0),U,7)
 .Q:'$D(^AUPNVPRV("AD",V))
 .Q:'$D(^AUPNVPOV("AD",V))
 .;cmi/anch/maw 8/27/2007 mods for code set versioning
 .;S (D,Y)=0 F  S Y=$O(^AUPNVPOV("AD",V,Y)) Q:Y'=+Y!(D)  S APCHSCM=$P($G(^AUPNVPOV(Y,0)),U) I APCHSCM S APCHSCM=$P($G(^ICD9(APCHSCM,0)),U) I APCHSCM]"" D CHKCODE
 .N APCHSVDT
 .S APCHSVDT=$P(+V,".")
 .S (D,Y)=0 F  S Y=$O(^AUPNVPOV("AD",V,Y)) Q:Y'=+Y!(D)  S APCHSCM=$P($G(^AUPNVPOV(Y,0)),U) I APCHSCM S APCHSCM=$P($$ICDDX^ICDEX(APCHSCM,APCHSVDT),U,2) I APCHSCM]"" D CHKCODE
 .;cmi/anch/maw 8/27/2007 end of mods
 .Q:'D
 .S Y=$$PRIMPROV^APCLV(V,"F")
 .Q:'Y
 .Q:$P($G(^DIC(7,Y,9999999)),U,3)'="Y"
 .S APCHSCNT=APCHSCNT+1
 .I APCHSCNT'<APCHSNVN S APCHSFOK=1
 .Q
 K ^TMP($J,"ALL VISITS"),APCHV,APCHY,APCHC
 Q
FLOWCP ;
 S APCHSP=^AUPNPROB(APCHSPI,0) Q:"ID"[$P(APCHSP,U,12)   ;'="A"
 ;S APCHSCM=$P(^ICD9(+$P(APCHSP,U,1),0),U,1)  cmi/anch/maw 8/27/2007 orig line
 S APCHSCM=$$VAL^XBDIQ1(9000011,APCHSPI,.01) D CHKCODE I D S APCHSFOK=1
 Q  ;cmi/anch/maw 8/27/2007 code set versioning
 F APCHSCI=0:0 S APCHSCI=$O(^APCHSFLC(APCHSFDF,2,APCHSCI)) Q:'APCHSCI  D FLOWCR Q:APCHSFOK
 Q
FLOWCR ;
 S APCHSC1=$P(^APCHSFLC(APCHSFDF,2,APCHSCI,0),U,1)
 I APCHSC1["-" S APCHSC2=$P(APCHSC1,"-",2),APCHSC1=$P(APCHSC1,"-",1)
 E  S APCHSC2=APCHSC1
 S APCHSC1=APCHSC1_" ",APCHSC2=APCHSC2_" "
 I APCHSC1'](APCHSCM_" "),(APCHSCM_" ")']APCHSC2 S APCHSFOK=1
 ;I APCHSC1']APCHSCM,APCHSCM']APCHSC2 S APCHSFOK=1
 Q
CHKCODE ;
 F APCHSCI=0:0 S APCHSCI=$O(^APCHSFLC(APCHSFDF,2,APCHSCI)) Q:'APCHSCI  D CHKCODE1 Q:D
 Q
CHKCODE1 ;
 S D=0
 S APCHSC1=$P(^APCHSFLC(APCHSFDF,2,APCHSCI,0),U,1)
 I APCHSC1["-" S APCHSC2=$P(APCHSC1,"-",2),APCHSC1=$P(APCHSC1,"-",1)
 E  S APCHSC2=APCHSC1
 ;S APCHSC1=APCHSC1_" ",APCHSC2=APCHSC2_" "
 ;I APCHSC1'](APCHSCM_" "),(APCHSCM_" ")']APCHSC2 S D=1
 S APCHCS=$P(^APCHSFLC(APCHSFDF,2,APCHSCI,0),U,2)
 I APCHCS="" S APCHCS=1  ;if no coding system, assume icd-9
 K APCHC
 D LST^ATXAPI(APCHCS,80,APCHSC1_"-"_APCHSC2,"CODE","APCHC")
 I $D(APCHC(APCHSCM_" ")) S D=1
 K APCHC
 Q
FLOWCKP ;ENTRY POINT
 X APCHSCKP Q:$D(APCHSQIT)  Q:'APCHSNPG
FLOWHD ;ENTRY POINT
 ; DISPLAY HEADER
 X APCHSCKP Q:$D(APCHSQIT)
 W APCHSFCN,!
 I $O(^APCHSFLC(APCHSFDF,3,0)) W ?2,"Clinics limited to:" S X=0 F  S X=$O(^APCHSFLC(APCHSFDF,3,X)) Q:'X  X APCHSCKP Q:$D(APCHSQIT)  G:APCHSNPG FLOWHD W ?22,$P(^DIC(40.7,X,0),U),!
 X APCHSCKP Q:$D(APCHSQIT)  G:APCHSNPG FLOWHD
 F APCHSII=0:0 S APCHSII=$O(APCHSTB(APCHSII)) Q:'APCHSII  W ?12+APCHSTB(APCHSII),APCHSTB(APCHSII,"L")
 W !
 Q
FLOWTB ; BUILD TAB TABLE
 K APCHSTB
 S APCHST=1,APCHSMXL=0
 F APCHSI=0:0 S APCHSI=$O(^APCHSFLC(APCHSFDF,1,APCHSI)) Q:'APCHSI  D FLOWTB2
 Q
FLOWTB2 S APCHSW=0
 Q:'($D(^APCHSFLC(APCHSFDF,1,APCHSI,0))#2)  S APCHSN=^(0)
 S APCHSTTL=$P(APCHSN,U,3) S APCHSP=$L(APCHSTTL) S:APCHSP>APCHSW APCHSW=APCHSP
 S APCHSP=$P(APCHSN,U,4) S:+APCHSP>APCHSW APCHSW=APCHSP
 S:APCHSW=0 APCHSW=10
 S APCHSTB(APCHSI)=APCHST_"^"_APCHSW,APCHSTB(APCHSI,"L")=APCHSTTL
 S APCHSMXL=APCHSMXL+APCHSW+2
 S APCHST=APCHST+APCHSW+2
 Q
FLOWBD ; BUILD AND DISPLAY DATA TABLE (FOR ONE DATE)
 K APCHSDB
 S APCHSDUS=0
 F APCHSVDF=0:0 S APCHSVDF=$O(^AUPNVSIT("AA",APCHSPAT,APCHSIVD,APCHSVDF)) Q:'APCHSVDF  D FLOWB
 D:$D(APCHSDB) FLOWD^APCHS12A
 Q
FLOWB S APCHSCLN=$P(^AUPNVSIT(APCHSVDF,0),U,8)
 I APCHSCLN,$O(^APCHSFLC(APCHSFDF,3,0)),'$D(^(APCHSCLN)) Q
 S APCHSDUS=1
 F APCHSIDF=0:0 S APCHSIDF=$O(^APCHSFLC(APCHSFDF,1,APCHSIDF)) Q:'APCHSIDF  S APCHSJ=0 D FLOWB2 Q:$D(APCHSQIT)
 Q
FLOWB2 S APCHSN=^APCHSFLC(APCHSFDF,1,APCHSIDF,0)
 S APCHSIT=$P(APCHSN,U,2)
 S APCHSFXF=$G(^APCHSFLC(APCHSFDF,1,APCHSIDF,1))
 S APCHSX=^APCHSFLI(APCHSIT,1)
 S APCHSXT=^APCHSFLI(APCHSIT,2)
 S APCHSP=$P(^APCHSFLI(APCHSIT,0),U,3),APCHSVGL=^DIC(APCHSP,0,"GL")_"""AD"",APCHSVDF)"
 S APCHSAS=$O(^APCHSFLC(APCHSFDF,1,APCHSIDF,2,0)),APCHSNGL=APCHSAS&'$O(^(APCHSAS)) D FLOWBA:'APCHSAS,FLOWBS:APCHSAS
 Q
FLOWBS ; ADD SPECIFIED ITEMS
 F DA=0:0 S DA=$O(@APCHSVGL@(DA)) Q:'DA  D FLOWBS2
 Q
FLOWBS2 ;
 X APCHSXT
 S APCHSITP=X
 F I=0:0 S I=$O(^APCHSFLC(APCHSFDF,1,APCHSIDF,2,I)) Q:'I  I +$P(^APCHSFLC(APCHSFDF,1,APCHSIDF,2,I,0),U,1)=APCHSITP D FLOWADD Q
 Q
FLOWBA ; ADD ALL (NO ITEMS SPECIFIED)
 F DA=0:0 S DA=$O(@APCHSVGL@(DA)) Q:'DA  D FLOWADD
 Q
FLOWADD ; ADD VALUE FROM SELECTED FILE/DFN
 ;QUIT IF MEASUREMENT IS DELETED
 I APCHSVGL["AUPNVMSR" Q:$P($G(^AUPNVMSR(DA,2)),U,1)
 S APCHSL=$P(APCHSTB(APCHSIDF),U,2)
 X APCHSX
FLOWS I $L(X),$E(X,$L(X))=" " S X=$E(X,1,$L(X)-1) G FLOWS
 I APCHSFXF]"",$P(X,"=",2)]"" S APCHSXS=$P(X,"="),X=$P(X,"=",2) X APCHSFXF S X=APCHSXS_"="_X
 ;S:$E(X,$L(X))="=" X=$P(X,"=")_"n/r"
 S:$E(X,$L(X))="=" X="n/r" ;per Gary Lawless do not display name of test 12/26/01
 I $G(^APCHSFLC(APCHSFDF,1,APCHSIDF,3))]"" X ^APCHSFLC(APCHSFDF,1,APCHSIDF,3)
 ;I $G(^APCHSFLC(APCHSFDF,1,APCHSIDF,1))]"" X ^APCHSFLC(APCHSFDF,1,APCHSIDF,1) ;IHS/CMI/GRL execute flowsheet order transform code
 I APCHSNGL,X["=" S X=$P(X,"=",2)
 I $$VAL^XBDIQ1(9001019,APCHSIT,.01)="LAB RESULT",X["=",$P(X,"=",2)[" " S X=$P($P(X,"=",2)," ") ;CMI/GRL remove alpha comment after lab result
 F APCHSI=1:APCHSL S APCHSP=$E(X,APCHSI,APCHSL+APCHSI-1) Q:APCHSP=""  S APCHSJ=APCHSJ+1,APCHSDB(APCHSJ,APCHSIDF)=APCHSP
 Q
GENDER(I,P) ;
 I $P(^APCHSFLC(I,0),U,2)="" Q 1
 I $P(^DPT(P,0),U,2)'=$P(^APCHSFLC(I,0),U,2) Q 0
 Q 1
AGE(I,P) ;
 NEW A,B,C
 S A=$P(^APCHSFLC(I,0),U,3)   ;lower age
 S B=$P(^APCHSFLC(I,0),U,4)  ;upper age
 I A="",B="" Q 1
 S C=$$AGE^AUPNPAT(P,DT)
 I A]"",C<A Q 0
 I B]"",C>B Q 0
 Q 1