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

APCHS2I.m

Go to the documentation of this file.
APCHS2I ; IHS/CMI/LAB - PART 2 OF APCHS -- SUMMARY PRODUCTION COMPONENTS ; 03 Jul 2012  7:20 PM
 ;;2.0;IHS PCC SUITE;**9**;MAY 14, 2009;Build 3
 ;
INPMEAS ; ******************** MEASUREMENTS * 9000010.01 *******
 ; <SETUP>
 Q:'$D(^AUPNVMSR("AA",APCHSPAT))
 ;get last/latest Hospital Stay admission date
 NEW APCHINPB,APCHINPV,APCHINPD,APCHINPS,APCHVSIT,APCHM,APCHMEAS,APCHEVD,APCHM,APCHSX,APCHSMT,APCHSDFN ;adm date ivd, ien, dd ivd
 S APCHINPV=$$LASTHV(APCHSPAT)  ;get ien of latest H visit that is not contract health
 I 'APCHINPV Q  ;no hospital stays so don't bother
 S APCHINPB=$P($P(^AUPNVSIT(APCHINPV,0),U,1),".")  ;admission date of last H visit
 S APCHINPS=9999999-APCHINPB
 S APCHINPD=$$DSCHDATE^APCLV(APCHINPV)  ;get discharge date
 I APCHINPD="" S APCHINPD=DT  ;if no discharge date, set to DT as this means the patient is in-house
 X APCHSBRK
 ; <DISPLAY>
 X APCHSCKP Q:$D(APCHSQIT)
 ;loop through all visits from adm date to discharge date (or DT) and display measurements from
 ;H and I visits
 S APCHSIVD=(9999999-APCHINPD-1)_".9999"
 F  S APCHSIVD=$O(^AUPNVSIT("AA",APCHSPAT,APCHSIVD)) Q:$P(APCHSIVD,".")>APCHINPS!(APCHSIVD="")  D
 .S APCHVSIT=0 F  S APCHVSIT=$O(^AUPNVSIT("AA",APCHSPAT,APCHSIVD,APCHVSIT)) Q:APCHVSIT'=+APCHVSIT  D
 ..Q:'$D(^AUPNVSIT(APCHVSIT,0))
 ..Q:"HI"'[$P(^AUPNVSIT(APCHVSIT,0),U,7)  ;only H and I
 ..S APCHM=0 F  S APCHM=$O(^AUPNVMSR("AD",APCHVSIT,APCHM)) Q:APCHM=""  D
 ...;GET EVENT DATE/TIME OR VISIT DATE/TIME
 ...Q:'$D(^AUPNVMSR(APCHM,0))
 ...Q:$P(^AUPNVMSR(APCHM,0),U,1)=""
 ...Q:$P($G(^AUPNVMSR(APCHM,2)),U,1)  ;entered in error so skip it
 ...S APCHEVD=+$E($P($G(^AUPNVMSR(APCHM,12)),U,1),1,12)  ;STRIP OFF SECONDS IF ENTERED PER SUSAN AND MARY ANN EMAIL
 ...I APCHEVD=""!(APCHEVD=0) S APCHEVD=$P(^AUPNVSIT(APCHINPV,0),U,1)  ;visit date/time if no event date time
 ...I APCHMDSP="D" S APCHMEAS(APCHEVD,$$VAL^XBDIQ1(9000010.01,APCHM,.01),APCHM)=""
 ...I APCHMDSP="T" S APCHMEAS($$VAL^XBDIQ1(9000010.01,APCHM,.01),APCHEVD,APCHM)=""
 ;now display them
 D MEASDSP
 ; <CLEANUP>
MEASX K APCHSMT,APCHSMT2,APCHSMT3,APCHSDFN,APCHSND2,APCHSDAT,APCHMEAS
 Q
INPMEASD ;EP
 S APCHMDSP="D"
 G INPMEAS
INPMEAST ;EP
 S APCHMDSP="T"
 G INPMEAS
MEASDSP ;
 I APCHMDSP="T" G MEASDSPT  ;display by type
 S APCHSIVD="" F  S APCHSIVD=$O(APCHMEAS(APCHSIVD),-1) Q:APCHSIVD=""!($D(APCHSQIT))  D
 .X APCHSCKP Q:$D(APCHSQIT)  W !,?2,$$DT(APCHSIVD)
 .S APCHMT="" F  S APCHMT=$O(APCHMEAS(APCHSIVD,APCHMT)) Q:APCHMT=""!($D(APCHSQIT))  D
 ..S APCHSDFN=0 F  S APCHSDFN=$O(APCHMEAS(APCHSIVD,APCHMT,APCHSDFN)) Q:APCHSDFN=""!($D(APCHSQIT))  D MEASDSP1
 Q
MEASDSPT ;
 ;
 S APCHMT="" F  S APCHMT=$O(APCHMEAS(APCHMT)) Q:APCHMT=""  D
 .X APCHSCKP Q:$D(APCHSQIT)
 .W !?1,$S(APCHMT="O2":"O2 Sat",1:APCHMT)
 .S APCHSIVD="" F  S APCHSIVD=$O(APCHMEAS(APCHMT,APCHSIVD),-1) Q:APCHSIVD=""!($D(APCHSQIT))  D
 ..S APCHSDFN=0 F  S APCHSDFN=$O(APCHMEAS(APCHMT,APCHSIVD,APCHSDFN)) Q:APCHSDFN=""!($D(APCHSQIT))  D
 ...D MEASDSP2
 Q
DT(D) ;
 NEW A
 S A=$$FMTE^XLFDT(D,5)
 S A=$P(A,"@",2),A=$P(A,":",1,2)
 NEW B
 S B=$E(D,4,5)_"/"_$E(D,6,7)_"/"_(1700+$E(D,1,3))
 Q B_$S(A]"":"@",1:"")_A
 ;
MEASDSP1 ;
 X APCHSCKP Q:$D(APCHSQIT)
 W ?21,$S(APCHMT="O2":"O2 Sat",1:APCHMT) D REST
 Q
MEASDSP2 ;
 X APCHSCKP Q:$D(APCHSQIT)
 W:APCHSNPG ?1,$S(APCHMT="O2":"O2 Sat",1:APCHMT)
 W ?9,$$DT(APCHSIVD)
 D REST
 Q
REST ;
 W ?29,$P(^AUPNVMSR(APCHSDFN,0),U,4)
 I $$VAL^XBDIQ1(9000010.01,APCHSDFN,.01)="O2" D
 .Q:$P(^AUPNVMSR(APCHSDFN,0),U,10)=""
 .W ?41,"Supplemental O2: ",$P(^AUPNVMSR(APCHSDFN,0),U,10),!
 I '$O(^AUPNVMSR(APCHSDFN,5,0)) W ! Q   ;no qualifiers
 S C=0,X=0 F  S X=$O(^AUPNVMSR(APCHSDFN,5,X)) Q:X'=+X  S C=C+1
 W ?41,"Qualifier"_$S(C>1:"s",1:""),":"
 S APCHSX=0,X="" F  S APCHSX=$O(^AUPNVMSR(APCHSDFN,5,APCHSX)) Q:APCHSX'=+APCHSX  S Y=$P($G(^AUPNVMSR(APCHSDFN,5,APCHSX,0)),U) I Y S X=X_$S(X]"":", ",1:"")_$P($G(^GMRD(120.52,Y,0)),U,1)
 K APCHWP
 D WP^APCHS82(X,23)
 S APCHX=0,C=0 F  S APCHX=$O(APCHWP(APCHX)) Q:APCHX'=+APCHX!($D(APCHSQIT))  D
 .X APCHSCKP Q:$D(APCHSQIT)
 .S C=C+1
 .I C>1 W !
 .W ?53,APCHWP(APCHX)
 W !
 Q
LASTHV(P) ;get last H visit that is not contract
 NEW X,Y,V
 S V=""
 S X=0 F  S X=$O(^AUPNVSIT("AAH",P,X)) Q:X'=+X!(V)  D
 .S Y=0 F  S Y=$O(^AUPNVSIT("AAH",P,X,Y)) Q:Y'=+Y  D
 ..Q:'$D(^AUPNVSIT(Y,0))
 ..Q:$P(^AUPNVSIT(Y,0),U,3)="C"  ;don't count contract visits
 ..S V=Y
 ..Q
 Q V