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

AMEROUT.m

Go to the documentation of this file.
AMEROUT ; IHS/ANMC/GIS - REPORT GENERATOR ; 
 ;;3.0;ER VISIT SYSTEM;;FEB 23, 2009
 ;
 D HOME^%ZIS W @IOF
 K ^TMP("AMER",$J),AMERQUIT
RUN D TEMP I $D(AMERQUIT) G EXIT
 D FIN I $D(AMERQUIT) G EXIT
 D TIME I $D(AMERQUIT) G EXIT
 ;IHS/OIT/SCR 12/29/08 - synch ERS data with PCC data for the time frame selected
 D SYNCHERS^AMERERS($P(AMERD1,".",1),$P(AMERD2,".",1))
 I $G(AMERRTYP)="H" D ^AMEROUT4 G EXIT
 D PSET,SORT,^AMEROUT1 I $D(AMERQUIT) G EXIT
EXIT D EXIT^AMER
 K AMERQUIT,AMERRTYP,AMERD1,AMERD2,AMERDISP,AMERQUIT,X,Y,AMERBRK,AMERCON,AMERINC,AMERTOT,AMERSTRT,AMERX,AMERZ,%DT,%X,AMERSTAT,%Y
 K AMERVTOT,B,DIJ,DIRUT,DISYS,DP,DIC,DIE,P,AMERPTOT,AMERBY,AMERFR,AMERTO,AMERATNM,AMERSCR,AMERGBL,AMERCAT,FR,TO,BY,L,FLDS,AMERA1,AMERA2,AMERSFL
 Q
 ;
OUT ;ENTRY POINT FROM AMERBSET
 ; QUIT
 I '$D(POP) S POP=0
 I ($D(DTOUT))!($D(DUOUT))!(POP)!($D(DIROUT)) K DIRUT,DTOUT,DUOUT,POP,DIROUT S AMERQUIT="" W !!,"Session terminated...." H 2 W @IOF
 Q
 ;
TEMP ; SELECT TEMPLATE TYPE
 W !!,?20,"*****  REPORT OPTIONS  *****"
 S DIR(0)="SO^1:STANDARD ER LOG REPORT;2:BRIEF ER LOG REPORT;3:STATISTICAL REPORTS;4:HOURLY WORKLOAD REPORT",DIR("A")="Report type",DIR("?")="",DIR("B")=1 D ^DIR K DIR
 D OUT I $D(AMERQUIT) Q
 S AMERRTYP=$S(Y<3:"V",Y=3:"S",Y=4:"H",1:"")
 I Y=1 S AMERHDR="STANDARD ER LOG REPORT"
 I Y=2 S AMERHDR="BRIEF ER LOG REPORT"
 I Y=3 S AMERHDR="ER STATISTICAL REPORT"
 S FLDS=$S(Y=1:"[AMER DETAIL",2:"[AMER BRIEF",3:"[AMER AGE ",4:".01",1:"")
 I FLDS="" S AMERQUIT="" Q
 Q
 ;
FIN ; FINISHING TOUCHES
 I AMERRTYP="H" Q
 K AMERSTAT I AMERRTYP="S" S AMERSTAT="",AMERRTYP="V",AMERDISP=3 Q
 I AMERRTYP="A" D ^AMERBSET
 I AMERRTYP'="V" S AMERDISP=3 Q
 W !!!!,?20,"*****  DISPLAY OPTIONS  *****"
 S DIR(0)="SO^1:VISITS IN INVERSE ORDER OF DATES;2:PATIENTS IN ALPHABETICAL ORDER;3:VISITS IN CHRONOLOGICAL ORDER",DIR("A")="Your choice",DIR("B")="3",DIR("?")="" D ^DIR K DIR
 D OUT I $D(AMERQUIT) Q
 S AMERDISP=Y
 Q
 ;
TIME ; TIME FRAME
 W !!!!,?20,"*****  TIME FRAME  *****"
T1 S DIR(0)="D"_$S(AMERRTYP="H":"",1:"O"),DIR("A")="Enter starting date",DIR("?")="" D ^DIR K DIR
 D OUT I $D(AMERQUIT) Q
 I X="" W "  (start at first ER visit)" S AMERD1=2950101.0001 G T2
 S AMERD1=Y X ^DD("DD") W "  (",Y,")"
T2 S DIR(0)="D"_$S(AMERRTYP="H":"",1:"O"),DIR("A")="Enter ending date",DIR("?")="" D ^DIR K DIR
 D OUT I $D(AMERQUIT) Q
 I X="" W "  (end at last ER visit)" S AMERD2=DT+.2359 Q
 I Y=Y\1 S Y=Y+.2359
 I Y<AMERD1 W "  ??",*7,"  Ending date must follow starting date" G T2
 S AMERD2=Y X ^DD("DD") W "  (",Y,")"
 I AMERRTYP="H" N X1,X2,X S X2=AMERD1,X1=AMERD2 D ^%DTC I X>30 W *7,!,"  The maximum time span for this report is 30 days.  Try again...",! K AMERD1,AMERD2 G T1
 S:$G(AMERHDR)'="" AMERDHD=$$AMERDHD^AMERREPT(AMERHDR,AMERD1,AMERD2)
 Q
 ;
SORT ; SORT OPTIONS
 K ^TMP("AMER",$J)
 W !!!!,?20,"*****  SORT OPTIONS  *****",!!
S1 ; ENTRY POINT FROM AMEROUT1
 S X="",AMERVTOT=0,AMERPTOT=0
 F L=0:0 S X=$O(^AMER(2.2,"B",X)) Q:X=""  F Y=0:0 S Y=$O(^AMER(2.2,"B",X,Y)) Q:'Y  S Z=^AMER(2.2,Y,0) I $P(Z,U,2)=AMERRTYP S ^TMP("AMER",$J,5,$P(Z,U,5),X)=Y
 S I=0 F Z="P","V" S X="" F L=0:0 S X=$O(^TMP("AMER",$J,5,Z,X)) Q:X=""  S Y=^(X),I=I+1,^TMP("AMER",$J,6,Z,I)=X,^TMP("AMER",$J,7,I)=Y S:Z="P" AMERPTOT=AMERPTOT+1 S:Z="V" AMERVTOT=AMERVTOT+1
EN1 S AMERCON="P",AMERSTRT=0,(AMERBRK,AMERINC)=(+$G(AMERPTOT)+1)\2 W "Patient attributes =>" D OPT ; ENTRY POINT TO LIST SORT OPTIONS
 S AMERCON="V",AMERSTRT=AMERPTOT,AMERINC=((AMERVTOT+1)\2),AMERBRK=AMERINC+AMERPTOT W !!,"Visit attributes =>" D OPT
 Q
 ;
OPT ; LIST SORT OPTIONS
 S I=AMERSTRT
INCI S I=I+1 I I>AMERBRK Q
 W !?3,I,")",?8,^TMP("AMER",$J,6,AMERCON,I)
 I $D(^TMP("AMER",$J,6,AMERCON,I+AMERINC)) W ?43,(I+AMERINC),")",?48,^(I+AMERINC)
 G INCI
 ;
EN2 ; RECENT ER VISITS
 W !! S DIR(0)="DO^::ET",DIR("A")="Starting date (time optional)" D ^DIR K DIR
 D OUT I $D(AMERQUIT) K AMERQUIT Q
 I X="" S X=2000101 W " (Start with first visit)"
 S FR=Y
 S DIR(0)="DO^::ET",DIR("A")="Ending date (time optional)",DIR("B")="NOW" D ^DIR K DIR
 D OUT I $D(AMERQUIT) K AMERQUIT Q
 S TO=Y
 I FR>TO W "  ??",*7,!!! G EN2
 S DIR(0)="SO^B:BRIEF REPORT;S:STANDARD REPORT",DIR("A")="Report type",DIR("B")="BRIEF" D ^DIR K DIR
 D OUT I $D(AMERQUIT) K AMERQUIT Q
 S FLDS=$S(Y="B":"[AMER BRIEF",1:"[AMER DETAIL")
 S DIC="^AMERVSIT(",BY="@.01"
 I $G(AMERHDR)'="" S DHD=AMERHDR
 E  S DHD="ER VISIT REPORT"
 D EN1^DIP,EXIT1^AMER
 I $G(IOST)["C-" S DIR(0)="E" D ^DIR
 Q
 ;
EN3 ; Recent ER Visits with Insurance Information for Business Office people
 W !! S DIR(0)="DO^::ET",DIR("A")="Starting date (time optional)" D ^DIR K DIR
 D OUT I $D(AMERQUIT) K AMERQUIT Q
 I X="" S X=2000101 W " (Start with first visit)"
 S FR=Y
 S DIR(0)="DO^::ET",DIR("A")="Ending date (time optional)",DIR("B")="NOW" D ^DIR K DIR
 D OUT I $D(AMERQUIT) K AMERQUIT Q
 S TO=Y
 I FR>TO W "  ??",*7,!!! G EN3
 D OUT I $D(AMERQUIT) K AMERQUIT Q
 S FLDS="[AMER WITH INSINFO"
 S DIC="^AMERVSIT(",BY="@.01",DHD="ER VISIT REPORT WITH INSURANCE INFORMATION"
 D EN1^DIP,EXIT1^AMER
 I $G(IOST)["C-" S DIR(0)="E" D ^DIR
 Q
 ;
PSET ; PRLIMINARY SET
 I AMERRTYP="A" Q
 S (BY,FR,TO)=""
 Q
 ; 
 I AMERDISP>1 S BY="@.01",FR=AMERD1,TO=AMERD2 S:$D(AMERSTAT) BY="'.01" Q
 S BY="@.16",FR=9999999.9999-AMERD2,TO=9999999.9999-AMERD1
 Q