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

APCDVCH.m

Go to the documentation of this file.
APCDVCH ; IHS/CMI/LAB - EDIT HOSPITALIZATIONS ; 02 Nov 2015  11:43 AM
 ;;2.0;IHS PCC SUITE;**2,11,13**;MAY 14, 2009;Build 9
CHKHOSP ;
 Q:'$O(^AUPNVINP("AD",APCDVSIT,""))
 W !
 D GETTS
 Q:APCDTS=""
 Q:APCDDS=""
 D GETPOVS
 I '$D(APCDVCPV("P")) W !,$C(7),"WARNING: No PRINCIPLE DX entered for this Hospitalization!",! D XIT Q
 I APCD3>1 W !,$C(7),"WARNING: Multiple PRINCIPLE DXs entered for this Hospitalization!",! D XIT Q
 D GETACC
 S X2=AUPNDOB,X1=APCDDATE D ^%DTC S AUPNDAYS=X
 D ^APCDVCH2
 D CHECKPVS
 D ^APCDVCH1
 K APCDAGEE
 S X=0 F  S X=$O(^AUPNVPOV("AD",APCDVSIT,X)) Q:X'=+X  S APCDICDP=$P(^AUPNVPOV(X,0),U),APCDICD=$$CODEC^ICDEX(80,APCDICDP) D
 .K APCDAGEE
 .I $$CHKE1^AUPNSICD(APCDICDP) W !,"External Cause code used for POV" Q
 .I APCDICD=.9999!(APCDICD="ZZZ.999") W !,APCDICD_" Diagnosis used" Q
 .S %=$$ICDDX^ICDEX(APCDICDP,$$VD^APCLV(APCDVSIT)) I $P(%,U,11)]"",AUPNSEX'=$P(%,U,11) W !,"Gender of Patient invalid for this ICD code "_APCDICD Q
 .S (A,B)=""  ;CSV
 .I $$VERSION^XPDUTL("BCSV")]"" D  I 1  ;CSV
 ..S A=$P(%,U,15),B=$P(%,U,16)
 .E  S A=$P($G(^ICD9(APCDICDP,9999999)),U),B=$P($G(^ICD9(APCDICDP,9999999)),U,2)
 .I A,A>$$AGE^AUPNPAT($P($G(^AUPNVSIT(APCDVSIT,0)),U,5),$$VD^APCLV(APCDVSIT)) S APCDAGEE=""
 .I B,B<$$AGE^AUPNPAT($P($G(^AUPNVSIT(APCDVSIT,0)),U,5),$$VD^APCLV(APCDVSIT)) S APCDAGEE=""
 .I $P(APCDVREC,U,7)="H",'$D(^APCDINPT(9,11,"AC",APCDICD)),$D(APCDAGEE) W !,"WARNING: ICD code invalid for age, please review "_APCDICD Q
 .I $D(APCDAGEE) W !,"Age invalid for this ICD code.  PLEASE REVIEW: "_APCDICD Q
XIT ;
 K APCDTS,APCDVINR,APCDDS,APCDIACC,APCD1,APCD2,APCD3,APCDPREC,APCDSC,APCDICD9,APCDVCPV,APCDACC,APCDDUPE,APCDDXP,APCDACCO,APCDDUPO,APCDOPP,APCDDX,APCDPX,APCDFOUN,APCDOPP,APCDOPC,APCDDXP,APCDDXC,APCDDXOP,APCDOPDX,APCDVCPS
 K APCDE,APCDVCPV,APCDVPRC,APCDOP,APCDADM,APCDDIS,APCD3,APCDAGEE,A,B,%
 Q
GETTS ;
 S APCDVINR=$O(^AUPNVINP("AD",APCDVSIT,"")),APCDVINR=^AUPNVINP(APCDVINR,0),APCDTS=$P(APCDVINR,U,4),APCDDS=$P(APCDVINR,U,5)
 I APCDTS="" W !,$C(7),"WARNING: Admitting Service Missing",! Q
 I APCDDS="" W !,$C(7),"WARNING: Discharge Service Missing",! Q
 S APCDTS=$P(^DIC(45.7,APCDTS,9999999),U),APCDDS=$P(^DIC(45.7,APCDDS,9999999),U)
 I APCDTS="" W !,$C(7),"WARNING: Admitting Service Code Missing",!
 I APCDDS="" W !,$C(7),"WARNING: Discharge Service Code Missing",!
 Q
GETACC ;
 S APCDACC=""  ;ACCEPT COMMAND NO LONGER NECESSARY FOR EXPORT
 Q
GETPOVS ;
 S (APCD1,APCD2,APCD3)=0 F  S APCD2=$O(^AUPNVPOV("AD",APCDVSIT,APCD2)) Q:APCD2=""  S APCD1=APCD1+1 D SETPOV
 Q
SETPOV ;
 S APCDPREC=^AUPNVPOV(APCD2,0),APCDSC=$P(APCDPREC,U,12) S:APCDSC="" APCDSC="S"
 I APCDSC="P" S APCD3=APCD3+1,APCDVCPV("P")=$$CODEC^ICDEX(80,$P(APCDPREC,U))_"^"_$P(APCDPREC,U)_"^"_APCD2 Q
 S APCDVCPV(APCDSC,APCD1)=$$CODEC^ICDEX(80,$P(APCDPREC,U))_"^"_$P(APCDPREC,U)_"^"_APCD2
 Q
CHECKPVS ;
C2 ;CERTAIN "V" CODES CANNOT BE PRIM DXS
 I $D(^APCDINPT(2,11,"AC",$P(APCDVCPV("P"),U))) W !,$C(7),"WARNING: Diagnosis Code ",$P(APCDVCPV("P"),U)," cannot be used as a PRIMARY DX!  Please review.",!
C1 ;IF PRIM DX IS A "V" CODE SEC MUST BE "V" CODE ALSO
 ;WITH EXCEPTIONS
 ;I $E($P(APCDVCPV("P"),U))="V",'$D(^APCDINPT(1,11,"AC",$P(APCDVCPV("P"),U))) D C11
E1 ;CERTAIN CODES REQUIRE AN ACCEPT COMMAND
 I $D(^APCDINPT(8,11,"AC",$P(APCDVCPV("P"),U))),'$D(APCDACC) S APCDICD9=$P(APCDVCPV("P"),U) D E1W
 S APCD1=0 F  S APCD1=$O(APCDVCPV("S",APCD1)) Q:APCD1'=+APCD1  D E11
 ;
E2 ;IF CODE V30-V39 (.0) ADM SRV MUST BE NEWBORN
 I $D(^APCDINPT(4,"AC",$P(APCDVCPV("P"),U))),APCDTS'="07" W !,$C(7),"WARNING: Primary DX is ",$P(APCDVCPV("P"),U)," therefore Admitting Service must",!,"be NEWBORN (07)!",! Q
E3 ;IF PRIM DX IS V30-V39(.1) ADM SRV MUST BE ,11
 ;I $D(^APCDINPT(3,11,"AC",$P(APCDVCPV("P"),U))),APCDTS'=11 W !,$C(7),"WARNING: Primary DX is ",$P(APCDVCPV("P"),U)," therefore Admitting Service must",!,"be PEDIATRICS (11)!",! Q
E4 ;IF PRIM DX (V30-V39 (.0 OR ,.1)) AGE CANNOT BE > 3 DAYS
 I (($D(^APCDINPT(4,11,"AC",$P(APCDVCPV("P"),U))))!($D(^APCDINPT(3,11,"AC",$P(APCDVCPV("P"),U))))),AUPNDAYS>3 W !,$C(7),"WARNING: Primary DX is ",$P(APCDVCPV("P"),U)," therefore Age of Patient cannot be",!,"greater than 3 days!",! Q
 Q
E11 ;
 I $D(^APCDINPT(8,11,"AC",$P(APCDVCPV("S",APCD1),U))),'$D(APCDACC) S APCDICD9=$P(APCDVCPV("S",APCD1),U) D E1W
 Q
E1W ;
 W !,$C(7),"WARNING: You have used ICD code ",APCDICD9,", please review with Your Supervisor.",! Q
 Q
C11 ;
 ;S APCD1=0 F  S APCD1=$O(APCDVCPV("S",APCD1)) Q:APCD1'=+APCD1  D C12
 Q
C12 ;
 ;I $E($P(APCDVCPV("S",APCD1),U))'="V" W !,$C(7),"WARNING: The primary POV for this Hospitalization is a V Code, therefore",!,"the Secondary POVs must be V codes.  Please correct this Visit.",!
 Q