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

VENPCC1C.m

Go to the documentation of this file.
VENPCC1C ; IHS/OIT/GIS - MORE DATA MINING FOR ENCOUNTER FORMS 09 Mar 2004 8:15 AM ;
 ;;2.6;PCC+;;NOV 12, 2007
 ;
 ; ONLY THE x FIELDS ARE POPULTED HERE UNDER VER 2.5.  NEW CODE IS IN VENPCCC
 ; ART PKG FOR ALLERGIES IS SUPPORTED HERE
 ; 
XSET(SS,DFN,MIEN,MMF,CLASS,DEFEF) ; EP-SET MAIL MERGE FIELDS INTO TMP ARRAY
 N PTYPE,X,VAL,TAG,TMP
 S PTYPE=$P($G(^VEN(SS,MIEN,0)),U,9)
 S TMP=$NA(^TMP("VEN PRNT",$J,1))
 I '$$OK(SS,DFN,MIEN,PTYPE,CLASS,DEFEF) Q 0 ; FIELD FAILED TO MATCH PATIENT TYPE
 S X=^VEN(SS,MIEN,0)
 S VAL=$P(X,U)
 S TAG=$G(^VEN(SS,MIEN,1))
 I TAG'="",TAG?1.8UN1"^VENPCC"1.2UN X "I $L($T("_TAG_"))" I  X ("N X S VAL=$$"_TAG_"(DFN)") ; COMPUTED VALUE ;  TO PREVENT PROBLEMS CAUSED BY INVALID DATABASE ENTRY
 I SS=7.94 S ^TMP("VEN PRNT",$J,1,MMF)=$P(X,U,4)_VAL_$P(X,U,5) Q 1
 S ^TMP("VEN PRNT",$J,1,MMF)=VAL
C1 S %=$P(X,U,6) I %'="" S @TMP@(MMF_"a")=% ; CODE #1
C2 S %=$P(X,U,7) I %'="" S @TMP@(MMF_"b")=% ; CODE #2
 Q 1
 ; 
OK(SS,DFN,MIEN,PTYPE,CLASS,DEFEF) ; EP-CHECK FOR PATIENT TYPE MATCH
 N TAG,X,FORM
 I PTYPE'=CLASS Q 0
 S TAG=$G(^VEN(SS,MIEN,2)) I TAG="" Q 1
 X ("S X=$$"_TAG_"(DFN)")
 Q X
 ; 
ALLERG(APCHSPAT) ; EP-ALLERGIES
 N APCHSDFN,IIEN,ICD,TOT,OK,MAX,APCHSP,APCHSNKA
 I $P($G(^VEN(7.5,$$CFG^VENPCCU,0)),U,23) D ART^VENPCC1L(APCHSPAT) Q  ; USE THE ADVERSE RXN TRACKING PKG, VER 2.5
 S APCHSDFN="",TOT=0,MAX=$P($G(^VEN(7.41,+$G(DEFEF),2)),U,5) I 'MAX S MAX=5
 F  Q:TOT=(MAX+1)  S APCHSDFN=$O(^AUPNPROB("AC",+$G(APCHSPAT),APCHSDFN)) Q:'APCHSDFN  D
 . S IIEN=+$P($G(^AUPNPROB(APCHSDFN,0)),U)
 . S APCHSP=$P($G(^ICD9(IIEN,0)),U)
 . I $L(APCHSP) S APCHSNKA=0 D PROBACHK^APCHS40 I $T,'APCHSNKA D SETA(APCHSDFN)
 . Q
 Q
 ; 
SETA(PIEN) ;
 N NARR,NIEN,MAXNARR
 S MAXNARR=$P($G(^VEN(7.41,$G(DEFEF),14)),U,6) I 'MAXNARR S MAXNARR=32 ; MAX STG LENGTH
 S NIEN=+$P($G(^AUPNPROB(PIEN,0)),U,5)
 S NARR=$P($G(^AUTNPOV(NIEN,0)),U)
 I '$L(NARR) Q
 S TOT=TOT+1
 I TOT=(MAX+1) S @TMP@(1,("a"_MAX))="More allergies on Hlth Summary!" Q
 S @TMP@(1,("a"_TOT))=$E(NARR,1,MAXNARR)
 Q
 ; 
INS(DFN)          ;  EP-- send the patient dfn and get back 3p elig
 Q $$TPC(DFN)
 ; 
CLASS(DFN) ; EP-GIVEN THE DFN RETURN THE PATIENT CLASS FOR SITE PREFERENCES
 ; 1=INFANT,2=CHILD,3=ADULT MALE,4=ADULT FEMALE
 N AGE,SEX,DOB,X
 S X=$P($G(^DPT(DFN,0)),U,2,3),DOB=$P(X,U,2),SEX=$P(X,U)
 I DOB,$L(SEX)
 E  Q ""
 S AGE=(DT-DOB)\10000
 S X=$S(AGE<2:1,AGE<13:2,SEX="M":3,1:4)
 Q X
 ; 
IF ; EP-ENABLE IMMUNIZATION FORECASTING AT SITES THAT SUPPORT IMMUNIZATION FORECASTING
 I $L($T(VER^BILOGO)),$$VER^BILOGO>7.99,$L($T(IMMBI^BIAPCHS)) N TMP,% S TMP="IMM",%=$$NEWIMM^VENPCCS2(DFN) K @TMP,% Q  ; FOR IMM PKG 8.0 ; PATCHED BY GIS/ITSC
 N I,TOT,X,Y,Z,%,N,LINE,BIDE,IMM,GRP,DATE,PRE,POST,TMP
 S TMP=$NA(^TMP("VEN PRNT",$J,1))
 S (LINE,PRE,POST)="",TOT=7
 S %=$O(^VEN(7.94,"B","IMMUNIZATIONS",0)) I % S PRE=$P($G(^VEN(7.94,%,0)),U,4),POST=$P($G(^VEN(7.94,%,0)),U,5)
 F I=8,26,27,60,33,44,57 S BIDE(I)=""
 D IMMHX^BIRPC(.LINE,DFN,.BIDE)
 F I=9:1:25 S @TMP@("h"_I)="" ; CLEAR OUT OLD VALUES FOR IMMUNIZATIONS
 S Z=$L(LINE,U)-1
 F N=1:1:Z S X=$P(LINE,U,N) I $L(X) D
 . S IMM=$P(X,"|",2),DATE=$P(X,"|",8),GRP=$P(X,"|",4)
 . I $L(IMM),$L(DATE),$L(GRP)
 . E  Q
 . S GRP(GRP)=PRE_IMM_"   "_DATE_POST
 . Q
 S GRP="" F TOT=9:1 S GRP=$O(GRP(GRP)) Q:GRP=""  S @TMP@("h"_TOT)=GRP(GRP)
 Q
 ;
IX(X,CMD,IEN) ; EP-1=SET, 2=MMF, 3=DELETE
 I $G(X)="" Q
 I '$D(^VEN(7.93,+$G(IEN),0)) Q
 I +$G(CMD)<1,+$G(CMD)>4 Q
 N STG,MMF,SET,%
 S STG=^VEN(7.93,IEN,0)
 I CMD#2 S SET=X,MMF=$P($G(^VEN(7.42,+$P(STG,U,3),0)),U)
 E  S MMF=$P($G(^VEN(7.42,X,0)),U),SET=$P(STG,U,2)
 I 'SET!(MMF="") Q
 I CMD<3 S ^VEN(7.93,"AS",SET,MMF,IEN)="" Q
 K ^VEN(7.93,"AS",SET,MMF,IEN)
 Q
 ; 
AX(X,CMD,IEN) ; EP-1=SET, 2=OGRP, 3=PGRP, 4=DELETE
 I $G(X)="" Q
 I '$D(^VEN(7.93,+$G(IEN),0)) Q
 I +$G(CMD)<1,+$G(CMD)>4 Q
 N STG,PGRP,SET,%,GRP,FLD
 S STG=^VEN(7.93,IEN,0)
 I CMD=1 S SET=X,PGRP=$P(STG,U,9),FLD=$P(STG,U,8)
 I CMD=2 S FLD=X,SET=$P(STG,U,2),PGRP=$P(STG,U,9)
 I CMD=3 S PGRP=X,SET=$P(STG,U,2),FLD=$P(STG,U,8)
 I CMD=4 S PGRP=$P(STG,U,9),SET=$P(STG,U,2),FLD=$P(STG,U,8)
 I SET,$L(FLD),PGRP
 E  Q
 S GRP=PGRP_$E(FLD)
 I CMD<4 S ^VEN(7.93,"AX",SET,GRP,IEN)="" Q
 K ^VEN(7.93,"AX",SET,GRP,IEN)
 Q
 ; 
OSET(DEFEF) ; EP - RETURN SET IEN IF THE TEMPLATE IS ASSOCIATED WITH A SET
 I '$G(DEFEF) Q 0
 I '$O(^VEN(7.92,0)) Q 0
 I '$O(^VEN(7.93,"AS",0)) Q 0
 N OSET
 S OSET=+$P($G(^VEN(7.41,+$G(DEFEF),0)),U,9)
 Q OSET
 ; 
TPC(DFN) ; EP-THIRD PARTY COVERAGE
 I '$D(^DPT(DFN)) Q ""
 N A,B,C,STG
 S A=$$PVT(DFN),B=$$MCR(DFN),C=$$MCD(DFN),STG=""
 I $L(A) S STG=A
 I $L(STG),$L(B) S STG=A_", "_B
 I '$L(A),$L(B) S STG=B
 I $L(STG),$L(C) S STG=STG_", "_C
 I '$L(STG),$L(C) S STG=C
 S STG=$TR(STG,U,",")
 Q STG
 ; 
PVT(DFN) ; EP-PRIVATE INSURANCE
 N TPIEN,IIEN,NAME,INO,D1,D2,%,STG,STATUS
 S TPIEN=0,STG=""
 F  S TPIEN=$O(^AUPNPRVT(DFN,11,TPIEN)) Q:'TPIEN  S %=$G(^AUPNPRVT(DFN,11,TPIEN,0)) I $L(%) D
 . S IIEN=+%,INO=$P(%,U,2),D1=$P(%,U,6),D2=$P(%,U,7)
 . S NAME=$P($G(^AUTNINS(IIEN,0)),U) I '$L(NAME) Q
 . I D1,D1>DT Q
 . I D2,D2<DT Q
 . I $L(STG) S STG=STG_U
 . S STG=STG_NAME_" ("_INO_")"
 . S STATUS=$P($G(^AUTNINS(IIEN,1)),U,7)
 . I STATUS>2 S STG=STG_$S(STATUS=3:" [UNVERIFIED]",STATUS=4:" [UNBILLABLE]",1:"")
 . Q
 Q STG
 ; 
MCD(DFN) ; EP-MEDICAID ; SHOW EXPIRATION DATE IF MCD IS CURRENT
 N %,Y,MIEN,DIEN,D1,D2,STG,MAXDT
 S MIEN=999999999999,STG="",MAXDT=0
 F  S MIEN=$O(^AUPNMCD("B",DFN,MIEN),-1) Q:'MIEN  S DIEN=9999999 F  S DIEN=$O(^AUPNMCD(MIEN,11,DIEN),-1) Q:'DIEN  D  ; ALSO MANAGES DUPLICATE RECORDS PROPERLY
 . S %=$G(^AUPNMCD(MIEN,11,DIEN,0)) I '$L(%) Q
 . S D1=+%,D2=$P(%,U,2)
 . I D1'>MAXDT Q  ; ONLY CHECK THE LATEST RECORD
 . S MAXDT=D1
 . I D2 S Y=D2 X ^DD("DD")
 . I D2,DT>D2 S STG="Medicaid expired "_Y Q
 . I D2 S STG="Medicaid (expires "_Y_")" Q
 . S STG="Medicaid (expires ??)"
 . Q
 Q STG ; STG WILL ALWAYS CONTAIN THE MCD STATUS FOR THE LATEST RECORD
 ; 
MCR(DFN) ; EP-MEDICARE
 N %,MIEN,DIEN,D1,D2
 S MIEN=$O(^AUPNMCR("B",DFN,999999999),-1) I 'MIEN Q "" ; MANAGES DUPLICATE RECORDS PROPERLY
 S DIEN=$O(^AUPNMCR(MIEN,11,999999999),-1) I 'DIEN Q ""
 S %=$G(^AUPNMCR(MIEN,11,DIEN,0)) I '$L(%) Q ""
 S D1=+%,D2=$P(%,U,2)
 I D1,D1>DT Q ""
 I D2,D2<DT Q ""
 Q "Medicare"
 ; 
SPEC(DFN,DEFEF) ; EP-GET DATA FOR OCXS
 N CIEN,EIEN,MM,PCE,HIEN,HDR,TAG,VAL,X
 S CIEN=0 F  S CIEN=$O(^VEN(7.62,"AB",+$G(DEFEF),CIEN)) Q:'CIEN  D
 . S EIEN=0 F  S EIEN=$O(^VEN(7.62,CIEN,3,"B",EIEN)) Q:'EIEN  D
 .. S TAG=$G(^VEN(7.61,EIEN,1)) I '$L(TAG) Q
 .. S X=$G(^VEN(7.61,EIEN,0)) I X="" Q
 .. S HIEN=$P(X,U,2) I 'HIEN Q
 .. S PCE=$P(X,U,3) I 'PCE Q
 .. S HDR=$P($G(^VEN(7.42,HIEN,0)),U) I HDR="" Q
 .. X ("S VAL=$$"_TAG_"(DFN)")
 .. S X=$G(SPECHOLD(HDR))
 .. S $P(X,"\",PCE)=VAL
 .. S SPECHOLD(HDR)=X
 .. Q
 . Q
 Q
 ;