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

APCHS1.m

Go to the documentation of this file.
APCHS1 ; IHS/CMI/LAB - PART 1 OF APCHS -- SUMMARY PRODUCTION COMPONENTS ;
 ;;2.0;IHS PCC SUITE;**2,5,10,11**;MAY 14, 2009;Build 58
 ;CMI/TUCSON/LAB - patch 2 fix age display
 ;IHS/CMI/LAB - patch 11, added check for LR nodes to prevent undef
 ;              patch 11, added Notice of Privacy Act data per Shirley Lujan email
 ;IHS/CMI/LAB - patch 12 added chronic pain registry data per ANMC
 ;
DEMOG ; ******************** DEMOGRAPHICS ********************
 ; <SETUP>
 S APCHSN=^DPT(APCHSPAT,0)
 S APCHSNAM=$P(APCHSN,U,1)
 S APCHSEX=$P(APCHSN,U,2),APCHSEX=$S(APCHSEX="M":"MALE",APCHSEX="F":"FEMALE",APCHSEX="U":"UNKNOWN",1:"<no sex>")
 S Y=$P(APCHSN,U,3)
 I 'Y S APCHSDOB="<NO DATE OF BIRTH>"
 E  X ^DD("DD") S APCHSDOB=Y
 S APCHSSN=$$SSN(APCHSPAT)
 ;S APCHSSN=$P(APCHSN,U,9) S:APCHSSN]"" APCHSSN=$E(APCHSSN,1,3)_"-"_$E(APCHSSN,4,5)_"-"_$E(APCHSSN,6,9)
 S APCHSN=$G(^DPT(APCHSPAT,.24))
 S APCHSMNM=$P(APCHSN,U,3)
 S APCHSFNM=$P(APCHSN,U)
 S APCHSN=^AUPNPAT(APCHSPAT,0)
 S Y=$P(APCHSN,U,3)
 I 'Y S APCHSLUD=""
 E  X ^DD("DD") S APCHSLUD=Y
 ;S APCHSBT=$P(APCHSN,U,13) S:APCHSBT="" APCHSBT="no blood type"
 ; start - vjm 9/20/01   logic for Blood Bank blood type
 ;                       1) use BB's ABO/Rh - if it exists
 ;                       2) use PCC blood type - if it exists
 ;                       3) otherwise, say 'no blood type'
 ;S APCHSBT=$P(APCHSN,U,13) S:APCHSBT="" APCHSBT="no blood type"
 D
 .  Q:'$D(^DPT(APCHSPAT,"LR"))
 .  S APCHX("LRDFN")=^DPT(APCHSPAT,"LR")   ; get pt's LRDFN
 .  D                        ; get Blood Bank blood type 
 .. Q:'$D(APCHX("LRDFN"))
 .. Q:APCHX("LRDFN")=""
 .. Q:'$D(^LR(APCHX("LRDFN"),0))
 ..  S APCHX("LR")=^LR(APCHX("LRDFN"),0)
 ..  S APCHX("ABO")=$P($G(APCHX("LR")),U,5)
 ..  Q:APCHX("ABO")=""
 ..  S APCHX("Rh")=$P($G(APCHX("LR")),U,6)
 ..  Q:APCHX("Rh")=""
 ..  S APCHX("ABO/Rh")=APCHX("ABO")_"/"_APCHX("Rh")
 ..  S:$D(APCHX("ABO/Rh")) APCHSBT="ABO/Rh:  "_APCHX("ABO/Rh")
 ..  Q
 .  Q
 I '$D(APCHX("ABO/Rh")) D   ; no BB data - data from ^DPT BType
 .  S APCHSBT=$P(APCHSN,U,13)
 .  S:APCHSBT="" APCHSBT="no blood type"
 .  Q
 K APCHX                     ; kill APCHX vars
 ; end - vjm 9/20/01
 ;S APCHSPP=$P(APCHSN,U,14) S:APCHSPP="" APCHSPP="<none identified>" I +APCHSPP S APCHSPP=$P(^DIC(6,+APCHSPP,0),U,1) I +APCHSPP S APCHSPP=$P(^DIC(16,+APCHSPP,0),U,1) ;*** file 200 conversion ***
 S APCHSPP=$P(APCHSN,U,14)
 S:APCHSPP=-1 APCHSPP=""  ;IHS/ANMC/LJF 8/5/99 prevent UNDEF
 S:APCHSPP="" APCHSPP="<none identified>"
 I +APCHSPP,$P(^DD(9000001,.14,0),U,2)[200 S APCHSPP=$P(^VA(200,APCHSPP,0),U) ;*** file 200 conversion ***
 I +APCHSPP,$P(^DD(9000001,.14,0),U,2)[6 S APCHSPP=$P(^DIC(6,+APCHSPP,0),U,1) I +APCHSPP S APCHSPP=$P(^DIC(16,+APCHSPP,0),U,1)
V ;
 S APCHSVST="" I $D(^DPT(APCHSPAT,"VET"))#2,$P(^("VET"),U)="Y" D VSTAT
 S APCHSN=$G(^AUPNPAT(APCHSPAT,11))
 S APCHSTR=$P(APCHSN,U,8)
 I 'APCHSTR S APCHSTR="<no tribe>"
 E  S APCHSTR=^AUTTTRI(APCHSTR,0) S APCHSTR=$P(APCHSTR,U,1)_$S($P(APCHSTR,U,4)="Y":" <old code>",1:"")
 S APCHSEL=$P(APCHSN,U,12)
 S X=$P(^DD(9000001,1112,0),U,3) F APCHSI=1:1 S APCHSP=$P(X,";",APCHSI) Q:APCHSP=""  I $P(APCHSP,":",1)=APCHSEL S APCHSEL=$P(APCHSP,":",2) Q
 S APCHSCMR=$P(APCHSN,U,18) S:APCHSCMR="" APCHSCMR="<NO COMMUNITY OF RESIDENCE>"
 S APCHSNL=$P($G(^APCHSITE(DUZ(2),0)),U,4)
 S APCHSFLD=$P($G(^APCHSITE(DUZ(2),0)),U,5)
 I 'APCHSNL S APCHSNL=2
 I APCHSFLD="" S APCHSFLD="F"
 K APCHSRE1
 S C=0,APCHTCNT=0
 S X=0 F  S X=$O(^AUPNPAT(APCHSPAT,13,X)) Q:X'=+X  S APCHTCNT=APCHTCNT+1
 I APCHSFLD="F" S X=0 F  S X=$O(^AUPNPAT(APCHSPAT,13,X)) Q:X'=+X!(C=APCHSNL)  S C=C+1,APCHSRE1(C)=^AUPNPAT(APCHSPAT,13,X,0)
 I APCHSFLD="L" S X=9999999 F  S X=$O(^AUPNPAT(APCHSPAT,13,X),-1) Q:X<1!(C=APCHSNL)  S C=C+1,APCHSRE1(99999-C)=^AUPNPAT(APCHSPAT,13,X,0)
 ;S APCHSI=$O(^AUPNPAT(APCHSPAT,13,0)) S APCHSRE1=$S(APCHSI:^(APCHSI,0),1:"") S APCHSI=$O(^AUPNPAT(APCHSPAT,13,APCHSI)) S APCHSRE2=$S(APCHSI:^(APCHSI,0),1:"") S:$O(^AUPNPAT(APCHSPAT,13,APCHSI)) APCHSRE2=APCHSRE2_" [more]"
 S APCHSADR=""
 I $D(^DPT(APCHSPAT,.11)) S APCHSN=^(.11) F E=1:1:6 S APCHSP=$P(APCHSN,U,E) I APCHSP]"" S:E=5 APCHSP=$P($G(^DIC(5,APCHSP,0)),U,2) S APCHSADR=APCHSADR_","_APCHSP
 S APCHSADR=$E(APCHSADR,2,255)
 S:APCHSADR]"" APCHSCMR=APCHSCMR_" ("_APCHSADR_")  "
 S APCHSN=$G(^DPT(APCHSPAT,.13))
 S APCHSHPH=$P(APCHSN,U,1),APCHSOPH=$P(APCHSN,U,2)
 I APCHSHPH="",APCHSOPH="" S APCHSHPH="<no phone numbers recorded>"
 S:+APCHSHPH APCHSHPH="(H) "_APCHSHPH
 S:APCHSOPH]"" APCHSOPH="(W) "_APCHSOPH S:APCHSHPH]"" APCHSOPH=" "_APCHSOPH
 S APCHOTPH=$P($G(^AUPNPAT(APCHSPAT,18)),U,1)
 G DEMDSP
VSTAT S APCHSVST="VETERAN"
 I $D(^DPT(APCHSPAT,.3))#2,$P(^(.3),U)="Y" S APCHSVST="SERVICE-CONNECTED "_APCHSVST
 S APCHSN=$G(^DPT(APCHSPAT,.32))
 I $P(APCHSN,U,5) S APCHSVST=APCHSVST_"  "_$P(^DIC(23,$P(APCHSN,U,5),0),U,2)
 S Y=$P(APCHSN,U,6) I Y D VSDT S APCHSVST=APCHSVST_" ("_Y_"-" S Y=$P(APCHSN,U,7) S:'Y APCHSVST=APCHSVST_"?)" I Y D VSDT S APCHSVST=APCHSVST_Y_")"
 I $D(^DPT(APCHSPAT,.31))#2 S APCHSN=^(.31) S Y=$P(APCHSN,U,3) I Y S APCHSVST=APCHSVST_"  CLAIM# "_Y
 Q
VSDT S Y=$E(Y,4,5)_"/"_$E(Y,6,7)_"/"_(1700+$E(Y,1,3))
 Q
DEMDSP ; <DISPLAY>
 X APCHSBRK
 I $$DOD^AUPNPAT(APCHSPAT)]""!($$VAL^XBDIQ1(9000001,APCHSPAT,1114)]"") D
 .W "*** DOD: ",$$VAL^XBDIQ1(2,APCHSPAT,.351),!
 .W "*** CAUSE OF DEATH: " I $$VAL^XBDIQ1(9000001,APCHSPAT,1114)]"" D  I 1
 ..W $$VAL^XBDIQ1(9000001,APCHSPAT,1114)
 ..K APCHSDSC
 ..S APCHSDSC=$$ICDD^AUPNVUTL($$VAL^XBDIQ1(9000001,APCHSPAT,1114),"APCHSDSC",$$DOD^AUPNPAT(APCHSPAT)) I $P(APCHSDSC,U)=-1 S APCHSDSC(1)=$P($$ICDDX^ICDEX($P(^AUPNPAT(APCHSPAT,11),U,14),$$DOD^AUPNPAT(APCHSPAT)),U,4)
 ..K ^UTILITY($J,"W")
 ..S APCHSX=0
 ..S DIWL=0,DIWR=45 F  S APCHSX=$O(APCHSDSC(APCHSX)) Q:APCHSX'=+APCHSX!($D(APCHSQIT))  D
 ...S X=APCHSDSC(APCHSX)
 ...Q:X="CODE TEXT MAY BE INACCURATE"
 ...Q:X=" "
 ...D ^DIWP
 ..S APCHSZ=0 F  S APCHSZ=$O(^UTILITY($J,"W",DIWL,APCHSZ)) Q:APCHSZ'=+APCHSZ  D
 ...X APCHSCKP Q:$D(APCHSQIT)
 ...W ?28,^UTILITY($J,"W",DIWL,APCHSZ,0),!
 .E  W !!
 .;W !
 K ^UTILITY($J,"W"),APCHSDSC,DIWL,APCHSX,APCHSZ,DIWL,DIWR
 Q:$D(APCHSQIT)
 W APCHSNAM
 W:APCHSDOB]"" ?34,"DOB: ",APCHSDOB,?51,$$AGE(APCHSPAT,DT,"R")
 W:APCHSEX]"" ?59,APCHSEX
 ; start - vjm 9/20/2001 - to accomodate the display of ABO/Rh
 ;W:APCHSBT]"" ?67,APCHSBT
 ;W !
 D
 .  I APCHSBT["/" W !,?34,APCHSBT,! Q
 .  W:APCHSBT]"" ?67,APCHSBT,!
 .  Q
 ; end - vjm 9/20/2001
 I APCHSTR]""!(APCHSMNM]"") W:APCHSTR]"" $E(APCHSTR,1,33) W:APCHSSN]"" ?34,"SSN: ",APCHSSN W !
 W:APCHSMNM]"" ?34,"MOTHER'S MAIDEN NAME: ",APCHSMNM W !
 W APCHSHPH,APCHSOPH W:APCHSFNM]"" ?34,"FATHER'S NAME: ",APCHSFNM W !
 S APCHPLNG=$$PREFLANG^APCLAPI7(APCHSPAT,DT,"E")
 D
 .I APCHOTPH]"" W "OTHER PHONE: ",APCHOTPH
 .I APCHPLNG]"" W ?34,"PREFERRED LANGUAGE: ",APCHPLNG
 .I APCHOTPH]""!(APCHPLNG)]"" W !
 I APCHSCMR]"" W APCHSCMR,!!
 I APCHSLUD]""!(APCHSEL]"") W:APCHSLUD]"" "LAST UPDATED: ",APCHSLUD,"   " W:APCHSEL]"" ?34,"ELIGIBILITY: ",APCHSEL W !
 W:APCHSVST]"" APCHSVST,!
 ;IHS/CMI/LAB - patch 11 added Notice of Privacy act display
 S APCHSNPP=$G(^AUPNNPP(APCHSPAT,0))
 W !,"NOTICE OF PRIVACY PRACTICES REC'D BY PATIENT?  ",$$VAL^XBDIQ1(9000038,APCHSPAT,.02)
 W !,"                    DATE RECEIVED BY PATIENT:  ",$$FMTE^XLFDT($P(APCHSNPP,U,3))
 W !,"                  WAS ACKNOWLEDGEMENT SIGNED?  ",$$VAL^XBDIQ1(9000038,APCHSPAT,.04)
 I $P(APCHSNPP,U,5)]"" D
 .W !,"                                      REASON:  ",$P(APCHSNPP,U,5)
 W !
 K APCHSNPP
 W !
 I $D(^AUPNPAT(APCHSPAT,41)) W "HEALTH RECORD NUMBERS:" F APCHSFP=0:0 S APCHSFP=$O(^AUPNPAT(APCHSPAT,41,APCHSFP)) Q:'APCHSFP  S APCHSHRN=$P(^(APCHSFP,0),U,2),APCHSFAC=$P(^DIC(4,APCHSFP,0),U,1) W ?24,$E(1000000+APCHSHRN,2,7),"  ",APCHSFAC,!
 X APCHSCKP Q:$D(APCHSQIT)
 I $O(^BDPRECN("C",APCHSPAT,0)) D BDPDISP G REM
 W "DESIGNATED PRIMARY CARE PROVIDER: ",APCHSPP,!
REM ;
 ;IHS/ANMC/LAB - added next 3 lines per Mosley 2/12/01
 I $P($G(^BWP(APCHSPAT,0)),U,25) S A="WOMEN'S HEALTH DESIGNATED PROVIDER" W ?(38-$L(A)),A,":  "_$$VAL^XBDIQ1(9002086,APCHSPAT,.25),!
 I $P($G(^AUPNPAT(APCHSPAT,17)),U,1) S A="PRIMARY MENTAL HEALTH PROVIDER" W ?(38-$L(A)),A,":  ",$E($$VAL^XBDIQ1(9000001,APCHSPAT,1701),1,22),!
 I $P($G(^AUPNPAT(APCHSPAT,17)),U,4) S A="SECONDARY MENTAL HEALTH PROVIDER" W ?(38-$L(A)),A,":  ",$$VAL^XBDIQ1(9000001,APCHSPAT,1704),!
 ;I APCHSRE1]"" W "REMARKS:",?9,APCHSRE1,! W:APCHSRE2]"" ?9,APCHSRE2,!
 I $D(APCHSRE1) W "REMARKS:",! D
 .S APCHSX=0 F  S APCHSX=$O(APCHSRE1(APCHSX)) Q:APCHSX=""!($D(APCHSQIT))  D
 ..X APCHSCKP Q:$D(APCHSQIT)
 ..W ?1,APCHSRE1(APCHSX),!
 I APCHSNL<APCHTCNT W ?1,"[more]",!
 I $D(^BCPP(APCHSPAT)) D  ;IHS/ANMC/LAB
 .S X="BCPAPI" X ^%ZOSF("TEST") I '$T Q
 .W !,"CHRONIC PAIN REGISTRY STATUS: ",$$VAL^XBDIQ1(90246,APCHSPAT,.02) ;IHS/ANMC/LAB - added for chronic pain registry
 .D ACTAGR^BCPAPI(.APCHAG,APCHSPAT,1) W ?45,$S(APCHAG:"Opioid Agreement",1:"No Opioid Agreement"),! ;IHS/ANMC/LAB
 I $P($G(^AUPNPAT(APCHSPAT,40)),U,2)]"" W !,"Preferred Method of Receiving Reminders: ",$$VAL^XBDIQ1(9000001,APCHSPAT,4002),!
 D DSPCMSRG
 ; CIA/PLS - 11/24/04 - WiseWoman Modification per Mike Mosley
 ;D WWDSPL(APCHSPAT)  ; WW modification per Mike Mosley
 ; <CLEANUP>
DEMOGX K APCHSNAM,APCHSTR,APCHSEX,APCHSDOB,APCHSSN,APCHSMNM,APCHSCMR,APCHSEL,APCHSFP,APCHSFAC,APCHSHRN,APCHSBT,APCHSPP,APCHSADR,APCHSN,APCHSP,APCHSI,APCHSJ,APCHSHPH,APCHSOPH,APCHSVST,APCHSLUD,APCHSRE1,APCHSRE2,E,X,Y
 K APCHSX,APCHSRE1,APCHSNL,APCHSFLD
 Q
DSPCMSRG ; DISPLAY MEMBERSHIP IN CMS REGISTER
 D DSPCMSRG^APCHS
 Q
AGE(DFN,D,F) ;EP - Given DFN, return Age.
 I '$G(DFN) Q -1
 I '$D(^DPT(DFN,0)) Q -1
 I $$DOB^AUPNPAT(DFN,"")<0 Q -1
 S:$G(D)="" D=DT
 S:$G(F)="" F="Y"
 NEW %
 S %=$$FMDIFF^XLFDT(D,$$DOB^AUPNPAT(DFN,""))
 S %1=%\365.25
 I F="Y" Q %1
 ;beginning Y2K fix
 ;Q $S(%1>2:%1_" YRS",%<31:%1_" DYS",1:%\30_" MOS") ;Y2000
 Q $S(%1>2:%1_" YRS",%<31:%_" DYS",1:%\30_" MOS") ;Y2000
 ;end Y2K
 ;
BDPDISP ;EP - display providers from desg prov package
 W ?30,"DESIGNATED PROVIDERS",!
 S APCHSX=0 F  S APCHSX=$O(^BDPRECN("C",APCHSPAT,APCHSX)) Q:APCHSX'=+APCHSX  D
 .X APCHSCKP Q:$D(APCHSQIT)
 .;get category and check health summary status
 .S A=$P($G(^BDPRECN(APCHSX,0)),U)
 .Q:A=""
 .Q:'$D(^BDPTCAT(A,0))
 .Q:$P(^BDPTCAT(A,0),U,8)="N"
 .S A=$$VAL^XBDIQ1(90360.1,APCHSX,.01) S:A="DESIGNATED PRIMARY PROVIDER" A="DESIGNATED PRIMARY CARE PROVIDER" W ?(38-$L(A)),A,":  "_$$VAL^XBDIQ1(90360.1,APCHSX,.03),!
 .Q
 Q
WWDSPL(DFN) ;
 N AGE,STAT,SDATE,WW
 Q:$E(APCHSEX,1)'="F" ""  ; Must be a female patient
 S STAT="",SDATE=0
 S WW=$$WWENPROC(DFN)
 I WW D
 .S STAT="ENROLLED",SDATE=WW
 E  D
 .S STAT=$$GET1^DIQ(9000001,DFN,1709)
 .I $L(STAT) D
 ..S SDATE=$$GET1^DIQ(9000001,DFN,1710,"I")
 .E  D
 ..S AGE=$$AGE^AUPNPAT(DFN)
 ..S:AGE>29&(AGE<65) STAT="UNKNOWN"
 I $L(STAT) D
 .W !,"WW Status: ",STAT W:SDATE ?30,"WW Update Date: ",$$FMTE^XLFDT(SDATE)
 .W !!
 Q
 ; Return date of WW Enrollment Procedure or Zero
WWENPROC(DFN) ;
 N IEN,PDT
 S PDT=0
 Q:'$G(DFN) PDT
 S (IEN,PDT)=0 F  S IEN=$O(^BWPCD("C",DFN,IEN)) Q:'IEN  D
 .I $$GET1^DIQ(9002086.1,IEN,4.01,"I")=1 D
 ..S PDT=+$$GET1^DIQ(9002086.1,IEN,4.02,"I")
 Q PDT
SSN(P) ;EP
 I '$G(P) Q ""
 I '$D(^DPT(P,0)) Q ""
 Q $S($L($P(^DPT(P,0),U,9))=9:$J("XXX-XX-"_$E($P(^DPT(P,0),U,9),6,9),11),1:$J($P(^DPT(P,0),U,9),11))