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

IVMUFNC1.m

Go to the documentation of this file.
  1. IVMUFNC1 ;ALB/SEK - INPATIENT/OUTPATIENT CALCULATIONS ; 06/19/2003
  1. ;;2.0;INCOME VERIFICATION MATCH ;**3,11,80**; 21-OCT-94
  1. ;;Per VHA Directive 10-93-142, this routine should not be modified.
  1. ;
  1. EN(DFN,IVMMTDT,IVMQUERY) ; number of inpatient and outpatient days since IVMMTDT date to
  1. ; IVMENDT (earliest of day before next means test and day before current date).
  1. ; Input: DFN -- pointer to patient in file #2
  1. ; IVMMTDT -- Means Test date/time for the patient
  1. ; IVMQUERY("OVIS") -- # of the QUERY that is currently open or
  1. ; undefined, zero, or null if no QUERY opened for
  1. ; finding outpatient visits
  1. ; Output: 1^2 where piece 1 = # of inpatient days
  1. ; piece 2 = # of outpatient days
  1. ;
  1. N IVMAD,IVMADMDT,IVMD,IVMDCN,IVMDT,IVMDGPM,IVMDISDT,IVMENDT,IVMF,IVMI,IVMIN,IVMOUT
  1. N IVMASIH,IVMADPTR,IVMDATE,VAINDT,VADMVT,VAIP,VAERR
  1. ;
  1. S (IVMIN,IVMOUT)=0
  1. I '$G(IVMMTDT) G EPQ
  1. S IVMMTDT=$P($$LST^DGMTU(DFN,IVMMTDT),"^",2)
  1. I '$G(IVMMTDT) G EPQ
  1. S IVMMTDT=$P(IVMMTDT,".")
  1. K ^TMP($J,"IVMUFNC1")
  1. ;
  1. ; - quit if the effective date of the test is today
  1. I IVMMTDT=DT G EPQ
  1. ;
  1. ; Calculate number of inpatient days
  1. ;
  1. ; get end date
  1. S IVMENDT=$$END^IVMUFNC2(DFN,IVMMTDT)
  1. ;
  1. ; - find if patient was an inpatient on IVMMTDT
  1. S VAINDT=IVMMTDT D ADM^VADPT2
  1. I VADMVT S IVMASIH=$P($G(^DGPM(VADMVT,0)),"^",21) D
  1. .I IVMASIH D Q
  1. ..S IVMIN=IVMIN+$$LOS(VADMVT,IVMMTDT)
  1. ..S IVMADPTR=$P($G(^DGPM(IVMASIH,0)),"^",14)
  1. ..S IVMDATE=$$CHK(IVMADPTR,IVMMTDT)
  1. ..S IVMIN=IVMIN+$$LOS(IVMADPTR,IVMDATE)
  1. .S VAIP("D")=IVMMTDT D IN5^VADPT
  1. .I 'VAIP(10) S IVMDATE=$$CHK(VADMVT,IVMMTDT)
  1. .S IVMIN=IVMIN+$$LOS(VADMVT,$S('VAIP(10):IVMDATE,1:IVMMTDT))
  1. ;
  1. ; - find admissions after IVMMTDT to end date
  1. S IVMD="" F S IVMD=$O(^DGPM("ATID1",DFN,IVMD)) Q:'IVMD!(9999999.9999999-IVMD<IVMMTDT) I 9999999.9999999-IVMD'>IVMENDT S IVMIN=IVMIN+$$LOS(+$O(^(IVMD,0)))
  1. ;
  1. ; Calculate number of outpatient days
  1. ;
  1. D EN^IVMUFNC2(.IVMQUERY)
  1. ;
  1. EPQ K ^TMP($J,"IVMUFNC1")
  1. Q IVMIN_"^"_IVMOUT
  1. ;
  1. ;
  1. LOS(IVMDG,IVMST) ; Calculate the length of stay for an admission.
  1. ; Input: IVMDG -- Pointer to the admission in file #405
  1. ; IVMST -- [Optional] Date after the admission on
  1. ; which to begin calculation of the LOS.
  1. ; Output: X -- Length of stay (in days)
  1. ;
  1. N A,D,DFN,DGE,DGS,I,X,X1,X2,LOP,LOA,LOAS,LOS
  1. S (LOP,LOA,LOAS)=0
  1. I $S('$D(IVMDG):1,'$D(^DGPM(+IVMDG,0)):1,$P(^(0),"^",2)'=1:1,1:0) S X=0 G Q
  1. S X=^DGPM(+IVMDG,0),DFN=$P(^(0),"^",3),(X2,A)=+X,D=$S($D(^DGPM(+$P(X,"^",17),0)):+^(0),1:""),(X1,D)=$S('D:IVMENDT,D>IVMENDT:IVMENDT,1:D)
  1. I $G(IVMST)'<$P(D,".") S X=0 G Q
  1. S:$G(IVMST) (X2,A)=IVMST
  1. D ^%DTC S LOS=$S(X:X,1:1) ; LOS = elapsed time between admission and discharge (or end date)
  1. F I=A:0 S I=$O(^DGPM("APCA",DFN,IVMDG,I)) Q:'I S DGS=$O(^(I,0)) I $D(^DGPM(+DGS,0)) S DGS=^(0) Q:+DGS>IVMENDT I "^1^2^3^13^43^44^45^"[("^"_$P(DGS,"^",18)_"^") S X2=+DGS,DGS=$P(DGS,"^",18) D ABS Q:'I
  1. S X=LOS-LOA-LOAS
  1. Q Q X
  1. ;
  1. ABS ; If patient was out on absence, find return
  1. S X1=0 F I=I:0 S I=$O(^DGPM("APCA",DFN,IVMDG,I)) Q:'I S DGE=$O(^(I,0)) I $D(^DGPM(+DGE,0)) S DGE=^(0) I "^14^22^23^24^"[("^"_$P(DGE,"^",18)_"^") S X1=+DGE,DGE=$P(DGE,"^",18) Q
  1. ; if no return from absence, use discharge or end date
  1. ; if return from absence greater then end date use end date
  1. I 'X1!(X1>D) S X1=D
  1. D ^%DTC S X=$S(X:X,1:1) I DGS=1,$S('$D(DGE):1,DGE'=25:1,1:0) S LOP=LOP+X Q ;if TO AA <96, but not FROM AA<96, count as absence, not pass
  1. I "^1^2^3^25^26^"[("^"_DGS_"^") S LOA=LOA+X Q
  1. S LOAS=LOAS+X Q
  1. ;
  1. CHK(ADPTR,DATE) ; Determine date that patient returned from leave
  1. ; Input: ADPTR -- Pointer to admission in file #405
  1. ; DATE -- Date the patient was on leave or ASIH
  1. ; Output: X1 -- Date the patient returned from leave
  1. N X,Y,I,%,X1,X2,DIS,DGE
  1. S X=^DGPM(+ADPTR,0),DIS=$S($D(^DGPM(+$P(X,"^",17),0)):+^(0),1:""),DIS=$S('DIS:IVMENDT,DIS>IVMENDT:IVMENDT,1:DIS)
  1. S X1=0 F I=DATE:0 S I=$O(^DGPM("APCA",DFN,ADPTR,I)) Q:'I S DGE=$O(^(I,0)) I $D(^DGPM(+DGE,0)) S DGE=^(0) I "^14^22^23^24^"[("^"_$P(DGE,"^",18)_"^") S X1=+DGE Q
  1. Q $P($S(X1:X1,1:DIS),".")