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

BHSDEM.m

Go to the documentation of this file.
BHSDEM ;IHS/MSC/MGH - Health Summary Demographics  ;14-Jan-2014 14:59;DU
 ;;1.0;HEALTH SUMMARY COMPONENTS;**1,2,3,4,6,9**;March 17,2006;Build 16
 ;==================================================================
 ;VA health summary comopnents for patient demographics
 ;Taken from APCHS1
 ;;2.0;IHS RPMS/PCC Health Summary;**2,8,9,10,11,12**;JUN 24, 1997
 ;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
 ;
 ;Patch 2 added phone number as in patch 16
 ;Patch 3 SSN is Nremoved
 ;Patch 4 updated for BJPC patch 2
 ;Patch 6 added preferred language and cause of death
DEMOG ; ******************** DEMOGRAPHICS ********************
 N BHSPAT,BHSN,BHSNAM,BHSSEX,BHSDOB,BHSMNM,BHSFNM
 N Y,BHSX,BHOTPH,A,BHSFLD,BHSNL,C,BHTCNT,BHPLNG
 S BHSPAT=DFN
 ; <SETUP>
 S BHSN=^DPT(BHSPAT,0)
 S BHSNAM=$P(BHSN,U,1)
 S BHSEX=$P(BHSN,U,2),BHSEX=$S(BHSEX="M":"MALE",BHSEX="F":"FEMALE",1:"<no sex>")
 S Y=$P(BHSN,U,3)
 I 'Y S BHSDOB="<NO DATE OF BIRTH>"
 E  X ^DD("DD") S BHSDOB=Y
 S BHSSN=$$SSN(BHSPAT)
 ;S BHSSN=$P(BHSN,U,9) S:BHSSN]"" BHSSN=$E(BHSSN,1,3)_"-"_$E(BHSSN,4,5)_"-"_$E(BHSSN,6,9)
 S BHSN=$G(^DPT(BHSPAT,.24))
 S BHSMNM=$P(BHSN,U,3)
 S BHSFNM=$P(BHSN,U)
 S BHSN=^AUPNPAT(BHSPAT,0)
 S Y=$P(BHSN,U,3)
 I 'Y S BHSLUD=""
 E  X ^DD("DD") S BHSLUD=Y
 D
 .  Q:'$D(^DPT(BHSPAT,"LR"))
 .  S BHSX("LRDFN")=^DPT(BHSPAT,"LR")   ; get pt's LRDFN
 .  D                        ; get Blood Bank blood type
 .. Q:'$D(BHSX("LRDFN"))
 .. Q:BHSX("LRDFN")=""
 .. Q:'$D(^LR(BHSX("LRDFN"),0))
 ..  S BHSX("LR")=^LR(BHSX("LRDFN"),0)
 ..  S BHSX("ABO")=$P($G(BHSX("LR")),U,5)
 ..  Q:BHSX("ABO")=""
 ..  S BHSX("Rh")=$P($G(BHSX("LR")),U,6)
 ..  Q:BHSX("Rh")=""
 ..  S BHSX("ABO/Rh")=BHSX("ABO")_"/"_BHSX("Rh")
 ..  S:$D(BHSX("ABO/Rh")) BHSBT="ABO/Rh:  "_BHSX("ABO/Rh")
 ..  Q
 .  Q
 I '$D(BHSX("ABO/Rh")) D   ; no BB data - data from ^DPT BType
 .  S BHSBT=$P(BHSN,U,13)
 .  S:BHSBT="" BHSBT="no blood type"
 .  Q
 K BHSX                     ; kill BHSX vars
 ; end - vjm 9/20/01
 S BHSPP=$P(BHSN,U,14)
 S:BHSPP=-1 BHSPP=""  ;IHS/ANMC/LJF 8/5/99 prevent UNDEF
 S:BHSPP="" BHSPP="<none identified>"
 I +BHSPP,$P(^DD(9000001,.14,0),U,2)[200 S BHSPP=$P(^VA(200,BHSPP,0),U) ;*** file 200 conversion ***
V ;
 S BHSVST="" I $D(^DPT(BHSPAT,"VET"))#2,$P(^("VET"),U)="Y" D VSTAT
 S BHSN=$G(^AUPNPAT(BHSPAT,11))
 S BHSTR=$P(BHSN,U,8)
 I 'BHSTR S BHSTR=",<no tribe>"
 E  S BHSTR=^AUTTTRI(BHSTR,0) S BHSTR=$P(BHSTR,U,1)_$S($P(BHSTR,U,4)="Y":" <old code>",1:"")
 S BHSEL=$P(BHSN,U,12)
 S X=$P(^DD(9000001,1112,0),U,3) F BHSI=1:1 S BHSP=$P(X,";",BHSI) Q:BHSP=""  I $P(BHSP,":",1)=BHSEL S BHSEL=$P(BHSP,":",2) Q
 S BHSCMR=$P(BHSN,U,18) S:BHSCMR="" BHSCMR="<NO COMMUNITY OF RESIDENCE>"
 S BHSNL=$P($G(^APCHSITE(DUZ(2),0)),U,4)
 S BHSFLD=$P($G(^APCHSITE(DUZ(2),0)),U,5)
 I 'BHSNL S BHSNL=2
 I BHSFLD="" S BHSFLD="F"
 K BHSRE1
 S C=0,BHTCNT=0
 S X=0 F  S X=$O(^AUPNPAT(BHSPAT,13,X)) Q:X'=+X  S BHTCNT=BHTCNT+1
 I BHSFLD="F" S X=0 F  S X=$O(^AUPNPAT(BHSPAT,13,X)) Q:X'=+X!(C=BHSNL)  S C=C+1,BHSRE1(C)=^AUPNPAT(BHSPAT,13,X,0)
 I BHSFLD="L" S X=9999999 F  S X=$O(^AUPNPAT(BHSPAT,13,X),-1) Q:X<1!(C=BHSNL)  S C=C+1,BHSRE1(99999-C)=^AUPNPAT(BHSPAT,13,X,0)
 ;S BHSI=$O(^AUPNPAT(BHSPAT,13,0)) S BHSRE1=$S(BHSI:^(BHSI,0),1:"") S BHSI=$O(^AUPNPAT(BHSPAT,13,BHSI)) S BHSRE2=$S(BHSI:^(BHSI,0),1:"") S:$O(^AUPNPAT(BHSPAT,13,BHSI)) BHSRE2=BHSRE2_" [more]"
 S BHSADR=""
 I $D(^DPT(BHSPAT,.11)) S BHSN=^(.11) F E=1:1:6 S BHSP=$P(BHSN,U,E) I BHSP]"" S:E=5 BHSP=$P(^DIC(5,BHSP,0),U,2) S BHSADR=BHSADR_","_BHSP
 S BHSADR=$E(BHSADR,2,255)
 S:BHSADR]"" BHSCMR=BHSCMR_" ("_BHSADR_")  "
 S BHSN=$G(^DPT(BHSPAT,.13))
 S BHSHPH=$P(BHSN,U,1),BHSOPH=$P(BHSN,U,2)
 I BHSHPH="",BHSOPH="" S BHSHPH="<no phone numbers recorded>"
 S:+BHSHPH BHSHPH="(H) "_BHSHPH
 S:BHSOPH]"" BHSOPH="(W) "_BHSOPH S:BHSHPH]"" BHSOPH=" "_BHSOPH
 S BHOTPH=$P($G(^AUPNPAT(BHSPAT,18)),U,1)
 G DEMDSP
VSTAT S BHSVST="VETERAN"
 I $D(^DPT(BHSPAT,.3))#2,$P(^(.3),U)="Y" S BHSVST="SERVICE-CONNECTED "_BHSVST
 S BHSN=$G(^DPT(BHSPAT,.32))
 I $P(BHSN,U,5) S BHSVST=BHSVST_"  "_$P(^DIC(23,$P(BHSN,U,5),0),U,2)
 S Y=$P(BHSN,U,6) I Y D VSDT S BHSVST=BHSVST_" ("_Y_"-" S Y=$P(BHSN,U,7) S:'Y BHSVST=BHSVST_"?)" I Y D VSDT S BHSVST=BHSVST_Y_")"
 I $D(^DPT(BHSPAT,.31))#2 S BHSN=^(.31) S Y=$P(BHSN,U,3) I Y S BHSVST=BHSVST_"  CLAIM# "_Y
 Q
VSDT S Y=$E(Y,4,5)_"/"_$E(Y,6,7)_"/"_(1700+$E(Y,1,3))
 Q
DEMDSP ; <DISPLAY>
 D CKP^GMTSUP Q:$D(GMTSQIT)
 ;I $$DOD^AUPNPAT(BHSPAT)]"" W "*** DOD: ",$$FMTE^XLFDT($$DOD^AUPNPAT(BHSPAT),"2D")," ***",!
 I $$DOD^AUPNPAT(BHSPAT)]""!($$VAL^XBDIQ1(9000001,BHSPAT,1114)]"") D
 .W "*** DOD: ",$$VAL^XBDIQ1(2,BHSPAT,.351),!
 .W "*** CAUSE OF DEATH: " I $$VAL^XBDIQ1(9000001,BHSPAT,1114)]"" D  I 1
 ..W $$VAL^XBDIQ1(9000001,BHSPAT,1114)
 ..K BHSDSC
 ..;Patch 9 new apis for ICD-10
 ..I $$AICD^BHSUTL D
 ...S BHSDSC=$$ICDD^ICDEX($$VAL^XBDIQ1(9000001,BHSPAT,1114),"BHSDSC",$$DOD^AUPNPAT(BHSPAT)) I $P(BHSDSC,U)=-1 S BHSDSC(1)=$P($$ICDDX^ICDEX($P(^AUPNPAT(BHSPAT,11),U,14),$$DOD^AUPNPAT(BHSPAT)),U,4)
 ..E  S BHSDSC=$$ICDD^ICDCODE($$VAL^XBDIQ1(9000001,BHSPAT,1114),"BHSDSC",$$DOD^AUPNPAT(BHSPAT)) I $P(BHSDSC,U)=-1 S BHSDSC(1)=$P($$ICDDX^ICDCODE($P(^AUPNPAT(BHSPAT,11),U,14),$$DOD^AUPNPAT(BHSPAT)),U,4)
 ..K ^UTILITY($J,"W")
 ..S BHSX=0
 ..S DIWL=0,DIWR=45 F  S BHSX=$O(BHSDSC(BHSX)) Q:BHSX'=+BHSX!($D(GMTSQIT))  D
 ...S X=BHSDSC(BHSX)
 ...Q:X="CODE TEXT MAY BE INACCURATE"
 ...Q:X=" "
 ...D ^DIWP
 ..S BHSZ=0 F  S BHSZ=$O(^UTILITY($J,"W",DIWL,BHSZ)) Q:BHSZ'=+BHSZ  D
 ...Q:$D(GMTSQIT)
 ...W ?28,^UTILITY($J,"W",DIWL,BHSZ,0),!
 .E  W !!
 .;W !
 K ^UTILITY($J,"W"),BHSDSC,DIWL,DIWR,BHSX,BHSZ,DIWL,DIW
 W BHSNAM
 W:BHSDOB]"" ?34,"DOB: ",BHSDOB,?51,$$AGE(BHSPAT,DT,"R")
 W:BHSEX]"" ?59,BHSEX
 D
 .  I BHSBT["/" W !,?34,BHSBT,! Q
 .  W:BHSBT]"" ?67,BHSBT,!
 .  Q
 I BHSTR]""!(BHSMNM]"") W:BHSTR]"" $E(BHSTR,1,33) W:BHSSN]"" ?34,"SSN: ",BHSSN W !
 W:BHSMNM]"" ?34,"MOTHER'S MAIDEN NAME: ",BHSMNM W !
 W BHSHPH,BHSOPH W:BHSFNM]"" ?34,"FATHER'S NAME: ",BHSFNM W !
 S BHPLNG=$$PREFLANG^APCLAPI7(BHSPAT,DT,"E")
 D
 .I BHOTPH]"" W "OTHER PHONE: ",BHOTPH
 .I BHPLNG]"" W ?34,"PREFERRED LANGUAGE: ",BHPLNG
 .I BHOTPH]""!(BHPLNG)]"" W !
 I BHSCMR]"" W BHSCMR,!!
 I BHSLUD]""!(BHSEL]"") W:BHSLUD]"" "LAST UPDATED: ",BHSLUD,"   " W:BHSEL]"" ?34,"ELIGIBILITY: ",BHSEL W !
 W:BHSVST]"" BHSVST,!
 ;IHS/CMI/LAB - patch 11 added Notice of Privacy act display
 S BHSNPP=$G(^AUPNNPP(BHSPAT,0))
 W !,"NOTICE OF PRIVACY PRACTICES REC'D BY PATIENT?  ",$$VAL^XBDIQ1(9000038,BHSPAT,.02)
 W !,"                    DATE RECEIVED BY PATIENT:  ",$$FMTE^XLFDT($P(BHSNPP,U,3))
 W !,"                  WAS ACKNOWLEDGEMENT SIGNED?  ",$$VAL^XBDIQ1(9000038,BHSPAT,.04)
 I $P(BHSNPP,U,5)]"" D
 .W !,"                                      REASON:  ",$P(BHSNPP,U,5)
 W !
 K BHSNPP
 W !
 I $D(^AUPNPAT(BHSPAT,41)) W "HEALTH RECORD NUMBERS:" F BHSFP=0:0 S BHSFP=$O(^AUPNPAT(BHSPAT,41,BHSFP)) Q:'BHSFP  S BHSHRN=$P(^(BHSFP,0),U,2),BHSFAC=$P(^DIC(4,BHSFP,0),U,1) W ?24,BHSHRN,"  ",BHSFAC,!
 D CKP^GMTSUP Q:$D(GMTSQIT)
 I $O(^BDPRECN("C",BHSPAT,0)) D BDPDISP G REM
 W "DESIGNATED PROVIDER: ",BHSPP,!
REM ;
 ;IHS/ANMC/LAB - added next 3 lines per Mosley 2/12/01
 N A
 I $P($G(^BWP(BHSPAT,0)),U,25) S A="WOMEN'S HEALTH DESIGNATED PROVIDER" W ?(38-$L(A)),A,":  "_$$VAL^XBDIQ1(9002086,BHSPAT,.25),!
 I $P($G(^AUPNPAT(BHSPAT,17)),U,1) S A="PRIMARY MENTAL HEALTH PROVIDER" W ?(38-$L(A)),A,":  ",$E($$VAL^XBDIQ1(9000001,BHSPAT,1701),1,22),!
 I $P($G(^AUPNPAT(BHSPAT,17)),U,4) S A="SECONDARY MENTAL HEALTH PROVIDER" W ?(38-$L(A)),A,":  ",$$VAL^XBDIQ1(9000001,BHSPAT,1704),!
 ;I BHSRE1]"" W "REMARKS:",?9,BHSRE1,! W:BHSRE2]"" ?9,BHSRE2,!
 I $D(BHSRE1) W "REMARKS:",! D
 .S BHSX=0 F  S BHSX=$O(BHSRE1(BHSX)) Q:BHSX=""!($D(GMTSQIT))  D
 ..D CKP^GMTSUP Q:$D(GMTSQIT)
 ..W ?1,BHSRE1(BHSX),!
 I BHSNL<BHTCNT W ?1,"[more]",!
 I $D(^BCPP(BHSPAT)) D  ;IHS/ANMC/LAB
 .S X="BCPAPI" X ^%ZOSF("TEST") I '$T Q
 .W !,"CHRONIC PAIN REGISTRY STATUS: ",$$VAL^XBDIQ1(90246,BHSPAT,.02) ;IHS/ANMC/LAB - added for chronic pain registry
 .D ACTAGR^BCPAPI(.APCHAG,BHSPAT,1) W ?45,$S(APCHAG:"Opioid Agreement",1:"No Opioid Agreement"),! ;IHS/ANMC/LAB
 D DSPCMSRG
DEMOGX K BHSNAM,BHSTR,BHSEX,BHSDOB,BHSSN,BHSMNM,BHSCMR,BHSEL,BHSFP,BHSFAC,BHSHRN,BHSBT,BHSPP,BHSADR,BHSN,BHSP,BHSI,BHSJ,BHSHPH,BHSOPH,BHSVST,BHSLUD,BHSRE1,BHSRE2,E,X,Y,APCHAG
 Q
DSPCMSRG ; DISPLAY MEMBERSHIP IN CMS REGISTER
 N BHSJ,BHSI,BHSK
 Q:'$D(^ACM(41,"D",BHSPAT))
 S BHSJ=1
 F BHSI=0:0 S BHSI=$O(^ACM(41,"AC",BHSPAT,BHSI)) Q:'BHSI  I $P(^ACM(41.1,BHSI,0),U,7) W:BHSJ "ON CMS REGISTER(S): " D
 .S BHSJ=0 W ?21,$P(^ACM(41.1,BHSI,0),U)
 .S BHSK=^ACM(41,"AC",BHSPAT,BHSI) W "  Status: ",$$VAL^XBDIQ1(9002241,BHSK,1),! ;IHS/CMI/LAB - display was not consisten with CMS
 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 DAY,YEAR
 S DAY=$$FMDIFF^XLFDT(D,$$DOB^AUPNPAT(DFN,""))
 S YEAR=DAY\365.25
 I F="Y" Q YEAR
 ;beginning Y2K fix
 ;Q $S(%1>2:%1_" YRS",%<31:%1_" DYS",1:%\30_" MOS") ;Y2000
 Q $S(YEAR>2:YEAR_" YRS",DAY<31:DAY_" DYS",1:DAY\30_" MOS") ;Y2000
 ;end Y2K
 ;
BDPDISP ;display providers from desg prov package
 W ?30,"DESIGNATED PROVIDERS",!
 S BHSX=0 F  S BHSX=$O(^BDPRECN("C",BHSPAT,BHSX)) Q:BHSX'=+BHSX  D
 .D CKP^GMTSUP Q:$D(GMTSQIT)
 .;get category and check health summary status
 .S A=$P($G(^BDPRECN(BHSX,0)),U)
 .Q:A=""
 .Q:'$D(^BDPTCAT(A,0))
 .Q:$P(^BDPTCAT(A,0),U,8)="N"
 .S A=$$VAL^XBDIQ1(90360.1,BHSX,.01) W ?(38-$L(A)),A,":  "_$$VAL^XBDIQ1(90360.1,BHSX,.03),!
 .Q
 Q
WWDSPL(DFN) ;
 N AGE,STAT,SDATE,WW
 Q:$E(BHSEX,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))