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

BDGLOS1.m

Go to the documentation of this file.
  1. BDGLOS1 ; IHS/ANMC/LJF - LOS BY WARD BY MONTH ; [ 09/30/2004 11:32 AM ]
  1. ;;5.3;PIMS;**1001,1019**;APR 26, 2002;Build 3
  1. ;
  1. EN ; -- main entry point for BDG LOS BY WARD & MONTH
  1. NEW VALMCNT
  1. I $E(IOST,1,2)="P-" D INIT,PRINT Q ;if printing to paper
  1. D TERM^VALM0,CLEAR^VALM1
  1. D EN^VALM("BDG LOS BY WARD & MONTH")
  1. D CLEAR^VALM1
  1. Q
  1. ;
  1. HDR ; -- header code
  1. S VALMHDR(1)=$$SP(15)_$$CONF^BDGF
  1. NEW X S X=$$FMTE^XLFDT(BDGBD)_" to "_$$FMTE^XLFDT(BDGED)
  1. S VALMHDR(2)=$$SP(75-$L(X)\2)_X
  1. Q
  1. ;
  1. INIT ; -- init variables and list array
  1. NEW DFN,CA,DATE,IEN,WARD,ENDDT,BEGIN,MONTH,END,LOS,LINE,NAME,BDGEDT
  1. K ^TMP("BDGLOS1",$J),^TMP("BDGLOS1A",$J)
  1. S VALMCNT=0
  1. S BDGEDT=$$FMADD^XLFDT(BDGED,1)
  1. ;
  1. ; first find all inpatients during date range
  1. S DFN=0 F S DFN=$O(^DGPM("APCA",DFN)) Q:'DFN D
  1. . S CA=0 F S CA=$O(^DGPM("APCA",DFN,CA)) Q:'CA D
  1. .. ;
  1. .. Q:'$G(^DGPM(CA,0)) ;bad xref entry
  1. .. I $$DSCH(CA)<BDGBD Q ;if patient discharged before begin date
  1. .. I +^DGPM(CA,0)>BDGED Q ;if patient admitted after end date
  1. .. ;
  1. .. ; for each inpatient, find all wards & their los
  1. .. S DATE=0
  1. .. F S DATE=$O(^DGPM("APCA",DFN,CA,DATE)) Q:'DATE Q:(DATE>BDGED) D
  1. ... S IEN=0 F S IEN=$O(^DGPM("APCA",DFN,CA,DATE,IEN)) Q:'IEN D
  1. .... ;
  1. .... Q:'$G(^DGPM(IEN,0)) ;bad xref entry
  1. .... Q:$P(^DGPM(IEN,0),U,2)=3 ;discharge movement
  1. .... S WARD=$$GET1^DIQ(405,IEN,.06) ;find ward for this movement
  1. .... Q:WARD="" ;ihs/cmi/maw 01/29/2016 PATCH 1019
  1. .... S ENDDT=$$NEXTDT(DFN,CA,DATE) ;find date pat left ward
  1. .... S NAME=$$GET1^DIQ(2,DFN,.01) ;patient name
  1. .... ;
  1. .... ;IHS/ITSC/WAR 9/30/04 PATCH #1001 resolve incorrect display of
  1. .... ; a Pt's LOS. Was displaying each month instead of combining
  1. .... S BDGADT=$E(DATE,1,5)
  1. .... ;
  1. .... ; loop thru months for date pair
  1. .... S BEGIN=DATE F Q:BEGIN>ENDDT D
  1. ..... S MONTH=$E(BEGIN,1,5)
  1. ..... ;
  1. ..... ; if pat left ward in same month
  1. ..... I $E(BEGIN,1,5)=$E(ENDDT,1,5) D Q ;same month
  1. ...... S LOS=$$FMDIFF^XLFDT(ENDDT,BEGIN) ;difference
  1. ...... I DATE=ENDDT S LOS=1 ;if 1 day admit
  1. ...... I LOS S ^TMP("BDGLOS1A",$J,MONTH,WARD,NAME,CA)=$G(^TMP("BDGLOS1A",$J,MONTH,WARD,NAME,CA))+LOS
  1. ...... S BEGIN=9999999 ;end loop
  1. ..... ;
  1. ..... ; else find days for first month
  1. ..... ;IHS/ITSC/WAR 8/11/04 PATCH #1001 per /IHS/ANMC/DLG 05AUG2004
  1. ..... ; problem with leap-year required a change and in DAYS subrtn
  1. ..... ;S END=MONTH_$$DAYS(+$E(MONTH,4,5))
  1. ..... S END=MONTH_$$DAYS(MONTH) ; pass the year and month
  1. ..... S END=$$FMADD^XLFDT(END,1)
  1. ..... S LOS=$$FMDIFF^XLFDT(END,BEGIN)
  1. ..... ;IHS/ITSC/WAR 9/30/04 PATCH #1001 see above note, dated same
  1. ..... ;I LOS S ^TMP("BDGLOS1A",$J,MONTH,WARD,NAME,CA)=$G(^TMP("BDGLOS1A",$J,MONTH,WARD,NAME,CA))+LOS
  1. ..... I LOS S ^TMP("BDGLOS1A",$J,BDGADT,WARD,NAME,CA)=$G(^TMP("BDGLOS1A",$J,BDGADT,WARD,NAME,CA))+LOS
  1. ..... ;
  1. ..... ; then for all others until discharge or end of date range
  1. ..... S BEGIN=END ;beginning of next month
  1. ;
  1. S MONTH=0
  1. F S MONTH=$O(^TMP("BDGLOS1A",$J,MONTH)) Q:'MONTH D
  1. . S WARD=0
  1. . F S WARD=$O(^TMP("BDGLOS1A",$J,MONTH,WARD)) Q:WARD="" D
  1. .. S NAME=0
  1. .. F S NAME=$O(^TMP("BDGLOS1A",$J,MONTH,WARD,NAME)) Q:NAME="" D
  1. ... S CA=0
  1. ... F S CA=$O(^TMP("BDGLOS1A",$J,MONTH,WARD,NAME,CA)) Q:'CA D
  1. .... S LOS=^TMP("BDGLOS1A",$J,MONTH,WARD,NAME,CA) ;length of stay
  1. .... ;
  1. .... S LINE=$$FMTE^XLFDT(MONTH_"00") ;month - external format
  1. .... S LINE=$$PAD(LINE,12)_$E(WARD,1,6) ;then ward
  1. .... S LINE=$$PAD(LINE,20)_$E(NAME,1,18) ;then patient
  1. .... S DFN=$$GET1^DIQ(405,CA,.03,"I")
  1. .... S LINE=$$PAD(LINE,40)_$J($$HRCN^BDGF2(DFN,DUZ(2)),6) ;chart #
  1. .... S LINE=$$PAD(LINE,50)_$P($$GET1^DIQ(405,CA,.01),"@") ;admit date
  1. .... S LINE=$$PAD(LINE,65)_$J(LOS,4) ;# of days
  1. .... D SET(LINE,.VALMCNT)
  1. ;
  1. I '$D(^TMP("BDGLOS1",$J)) D SET("NO DATA FOUND",.VALMCNT)
  1. K ^TMP("BDGLOS1A",$J)
  1. Q
  1. ;
  1. DSCH(ADM) ; return discharge date for admission ADM
  1. NEW X
  1. S X=$P($G(^DGPM(ADM,0)),U,17) I X="" Q 9999999 ;still inpatient
  1. Q $S($G(^DGPM(X,0)):+^(0),1:9999999)
  1. ;
  1. NEXTDT(PAT,ADM,LAST) ; return date when patient left ward
  1. NEW DATE
  1. S DATE=$O(^DGPM("APCA",PAT,ADM,LAST))
  1. I 'DATE S DATE=$$DSCH(ADM) ;if last mvmt, return discharge date
  1. Q $S(DATE>BDGED:BDGEDT,1:DATE) ;only go as far as date range
  1. ;
  1. ;IHS/ITSC/WAR 8/11/04 PATCH #1001 per /IHS/ANMC/DLG 05AUG2004
  1. DAYS(YRMONTH) ; return # of days in particular year/month
  1. ; /IHS/ANMC/DLG 05AUG2004 Fix the leap year bug
  1. ; Original line-label and following line are below:
  1. ;DAYS(M) ; return # of days in particular month
  1. ; I M=2,$E($$FMADD^XLFDT(M_"28",1),6,7)=29 Q 29 ;leap year
  1. ;
  1. NEW M
  1. S M=+$E(YRMONTH,4,5)
  1. I M=2,$E($$FMADD^XLFDT(YRMONTH_"28",1),6,7)=29 Q 29 ;leap year
  1. ; /IHS/ANMC/DLG end of changes
  1. Q $P($T(DAY),";;",M+1)
  1. ;
  1. DAY ;;31;;28;;31;;30;;31;;30;;31;;31;;30;;31;;30;;31
  1. ;
  1. SET(DATA,NUM) ; puts display data into array
  1. S NUM=NUM+1
  1. S ^TMP("BDGLOS1",$J,NUM,0)=DATA
  1. Q
  1. ;
  1. HELP ; -- help code
  1. S X="?" D DISP^XQORM1 W !!
  1. Q
  1. ;
  1. EXIT ; -- exit code
  1. K ^TMP("BDGLOS1",$J)
  1. K BDGBD,BDGED
  1. Q
  1. ;
  1. EXPND ; -- expand code
  1. Q
  1. ;
  1. PRINT ; print to paper
  1. NEW BDGN
  1. U IO
  1. D HDG S BDGN=0
  1. F S BDGN=$O(^TMP("BDGLOS1",$J,BDGN)) Q:'BDGN D
  1. . I $Y>(IOSL-4) D HDG
  1. . W !,^TMP("BDGLOS1",$J,BDGN,0)
  1. D ^%ZISC,EXIT
  1. Q
  1. ;
  1. HDG ; heading if printing to paper
  1. W @IOF
  1. NEW X S X="LENGTH OF STAY BY MONTH AND WARD" W !?80-$L(X)\2,X
  1. D HDR S X=0 F S X=$O(VALMHDR(X)) Q:'X W !,VALMHDR(X)
  1. W !,$$REPEAT^XLFSTR("=",80)
  1. W !,"Month",?12,"Ward",?20,"Patient Name",?40,"Chart #"
  1. W ?50,"Admit Date",?65,"Length of Stay",!,$$REPEAT^XLFSTR("-",80),!
  1. Q
  1. ;
  1. PAD(D,L) ;EP -- SUBRTN to pad length of data
  1. ; -- D=data L=length
  1. Q $E(D_$$REPEAT^XLFSTR(" ",L),1,L)
  1. ;
  1. SP(N) ; -- SUBRTN to pad N number of spaces
  1. Q $$PAD(" ",N)