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

AMERSAV1.m

Go to the documentation of this file.
AMERSAV1 ; IHS/ANMC/GIS - PUT ENTRY IN ER VISIT FILE ;   
 ;;3.0;ER VISIT SYSTEM;**6**;MAR 03, 2009;Build 30
 ;
RUN() ; EP from AMERSAVE
 D COMP
 D TRANS ; HER TRANSFER FIELDS
 S AMERDA=$$DIC(AMERDR(.01)) I 'AMERDA Q 0
 F AMERX=1,1.1,2,2.1,12 S %=$G(AMERDR(AMERX)) I %]"" D DIE(AMERDA,%)
 ; Save identified "clinic" into ER VISIT
 F AMERX=2:1:7 S %=$G(AMERDRI(AMERX)) I %]"" D DIE(AMERDA,%) ; INJURY INFO
 ;IHS/OIT/SCR 12/15/08 - update ER VISIT FILE with DATE LAST UPDATED (NOW)
 D TIMESTMP(AMERDA)
 D MULT(AMERDA)
 D KILL
 D EXIT
 Q AMERDA
 ;
EXIT K ZTRTN,ZTIO,ZTDESC,ZTSAVE,AMERDR,ZTDTH,AMERX
 K AMERDRI
 Q
COMP ; COMPUTED FIELDS
C0 ; REVOLVING DOOR
 N X,Y,Z,%,%H,%T,%Y,AMERDFN S AMERDFN=+$P(AMERDR(1),".02////",2)
 S Z=AMERDR(.01)
 S %=0 F X=0:0 S X=$O(^AMERVSIT("AC",AMERDFN,X)) Q:'X  S Y=+^AMERVSIT(X,0) I Y>%,Y'>Z S %=Y
 I '% G C1
 S %=$$DT^AMERSAV1(Z,%,"D")
 I %<366 S AMERDR(2)=AMERDR(2)_";8.2////"_%
C1 ; INJURY TRANSPORT LAG
 S X=$$VAL^AMERSAV1("QD32",3) I 'X G C2
 S %=$$DT(Z,X,"M"),AMERDR(2)=AMERDR(2)_";8.1////"_%
C2 ; DOC WAIT
 S X=$$VAL("QD25",12) I 'X G C3
 S %=$$DT(X,Z,"M"),AMERDR(12)=AMERDR(12)_";12.3////"_%
C3 ; TRIAGE WAIT
 S X=$$VAL("QD24",12) I 'X G C4
 S %=$$DT(X,Z,"M"),AMERDR(12)=AMERDR(12)_";12.4////"_%
C4 ; VISIT DURATION
 S X=$$VAL("QD19",2) I 'X G CEXIT
 S %=$$DT(X,Z,"M"),AMERDR(12)=AMERDR(12)_";12.5////"_%
CEXIT K A,B,C,E,X,%,%H,Z
 Q
 ;
KILL I $D(ZTQUEUED) S ZTREQ="@"
 Q
 ;
DIC(X) ; GIVEN A ADMISSION TIMESTAMP, CREATE AN ENTRY IN THE ER VISIT FILE AND RETURN THE IEN
 I '$G(X) Q ""
 N Y,DIC
 S DIC="^AMERVSIT(",DIC(0)="L",DIADD=1
 K DD,DO
 D FILE^DICN
 I Y=-1 Q ""
 Q +Y
 ;
DIE(DA,DR) ; GIVEN AN ENTRY NUMBER AND A DR STRING, EDIT THE ER VISIT FILE
 N X,Y,%
 N D,D0,DI,DIC,DICR,DIE,DIG,DIH,DIV,DIU,DIW,DQ
 S DIE="^AMERVSIT("
DIE1 L +^AMERVSIT:3 E  Q
 D ^DIE
 L -^AMERVSIT
 Q
 ;
MULT(AMERDA) ; SUBENTRIES
 N DA,DIC,X,Y,AMERX,AMERI,AMERY,AMERY2,DR,DIE,D,D0,DICR,DIG,DIH,DIV,DIU,DIW,DQ
 S DA(1)=AMERDA,DIC="^AMERVSIT(DA(1),4,",DIC(0)="L",DIC("P")=$P(^DD(9009080,4,0),U,2) ; PROCEDURES
 F AMERI=1:1 S AMERX=$P($G(AMERDR(4)),U,AMERI) Q:AMERX=""  S X="`"_AMERX D ^DIC
 S DA(1)=AMERDA,DIC="^AMERVSIT(DA(1),5,",DIC(0)="L",DIC("P")=$P(^DD(9009080,5,0),U,2) ; DIAGNOSES
 F AMERI=1:1 S AMERX=$P($G(AMERDR(6)),U,AMERI) Q:AMERX=""  D
 .S X="`"_AMERX
 .D ^DIC
 .S %=$G(AMERDR(6,AMERI)) I %]""
 .S DIE=DIC,DA=+Y,DR="1////"_$E(%,1,80)
 .D ^DIE
 S DA(1)=AMERDA,DIC="^AMERVSIT(DA(1),9,",DIC(0)="L",DIC("P")=$P(^DD(9009080,9,0),U,2) ; PT ED TOPICS
 F AMERI=1:1 S AMERX=$P($G(AMERDR(5)),U,AMERI) Q:AMERX=""  S X="`"_AMERX D ^DIC
 S DA(1)=AMERDA,DIC="^AMERVSIT(DA(1),19,",DIC(0)="LN",DIC("P")=$P(^DD(9009080,19,0),U,2) ; ER CONSULTANTS
 F AMERI=1:1 S AMERX=$P($G(AMERDR(3)),U,AMERI)  Q:AMERX=""  D
 .S X="`"_AMERX
 .D ^DIC Q:Y=-1
 .S AMERY=$G(AMERDR(3,AMERI,.02)),AMERY2=$G(AMERDR(3,AMERI,.03))
 .S DIE=DIC,DA=+Y,DR=".02////"_AMERY_";.03////"_AMERY2
 .D DIE1
 S DA(1)=AMERDA,DIC="^AMERVSIT(DA(1),18,",DIC(0)="L",DIC("P")=$P(^DD(9009080,18,0),U,2) ; HER TRANSFER FACILITIES
 F AMERI=1:1 S AMERX=$P($G(AMERDR(18)),U,AMERI) Q:AMERX=""  D
 . S X=+AMERX,AMERY=$P(AMERX,";",2)
 . D ^DIC I Y=-1 Q
 . S DIE=DIC,DA=+Y,DR=".02////"_AMERY
 . D DIE1
 Q
 ;
DT(X,Y,T) ; EP - ENTRY POINT FROM AMERFIX ;TIME DIFFERENCE
 ; X=T2,Y=T1,T="D":DAYS,T="M":MINUTES
 I '$G(X)!('$G(Y)) Q ""
 I $G(T)="" S T="M"
 N %,A,B,C,E,%T,%H,%Y
 D H^%DTC S A=+%H,B=%T,X=Y
 D H^%DTC S C=+%H,E=%T
 I E>B S B=B+86400,A=A-1
 S %=((A-C)*86400)+(B-E)
 I T="M" S %=%\60
 E  S %=%\86400
 Q %
 ;
VAL(Q,N) ; EP - ENTRY POINT THIS ROUTINE
 ; GETS A NUMERIC/DATE VALUE FROM THE DR STRING
 N %,X
 S %=$O(^AMER(2.3,"B",Q,0)) I '% Q ""
 S %=$G(^AMER(2.3,%,0)),%=$P(%,U,5) I '% Q ""
 I $P(Q,"QD",2)>30 S X=+$P($G(AMERDRI(N)),(%_"////"),2) Q X
 S X=+$P(AMERDR(N),(%_"////"),2)
 Q X
 ;
INJ ; EP - ENTRY POINT CALLED BY AMERSAV ;INJURY ENTRIES
 N G,X,Y,Z,%,F,N,V
 S G="AMERDRI(N)",X=30
 F  S X=$O(^TMP("AMER",$J,2,X)) Q:'X  S V=^(X) I V]"" D
 . ;
 . ;AMER*3.0*6;No longer convert to ICD - Already done
 . ;I X="33" S V=$G(^AMER(3,+V,"ICD")) I V="" Q  ; CONVERT CAUSE OF INJURY OPTION TO ICD CODE
 . S Y="QD"_X,Z=$O(^AMER(2.3,"B",Y,0)) I Y="" Q
 . S N=X\10,F=$P($G(^AMER(2.3,Z,0)),U,5) I 'F Q
 . S %=$G(@G) I %]"" S %=%_";"
 . S %=%_F_"////"_V,@G=%
 . Q
 ;
 Q
 ;
TRANS ; HER TRANSFER FIELDS
 N %,STG S STG=""
 S %=+$P($G(AMERDR(1)),"17.2////",2)
 I % S STG=%_";"_"A"
 S %=+$P($G(AMERDR(2)),"6.6////",2)
 I %,STG'="" S STG=STG_U
 I % S STG=STG_%_";"_"D"
 S AMERDR(18)=STG
 Q
TIMESTMP(AMERIEN)  ;UPDATE 'DATE LAST MODIFIED' IN ER VISIT FILE WITH CURRENT TIME
 ;IHS/SCR/OIT 12/15/08 - ADDED FUNCTION TO STAMP A MODIFIED ER VISIT WITH CURRENT TIME
 N X,Y,%
 N D,D0,DI,DIC,DICR,DIE,DIG,DIH,DIV,DIU,DIW,DQ,DA
 S DA=AMERIEN
 D NOW^%DTC
 S DR="12.6///"_%
 S DIE="^AMERVSIT("
 L +^AMERVSIT(AMERIEN):3 E  Q
 D ^DIE
 L -^AMERVSIT(AMERIEN)
 K DIE,DA,DR
 Q