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

AMERERS.m

Go to the documentation of this file.
AMERERS ; IHS/OIT/SCR - ROUTINES TO SUPPORT MERGE OF PCC DATA TO ERS DATA ;
 ;;3.0;ER VISIT SYSTEM;**1,2,6,7**;MAR 03, 2009;Build 5
SYNCHERA(AMERDA,AMERPCC)   ;
 ;IHS/OIT/SCR 12/31/08 
 ;This routine is called when it is determined that PCC admission data needs to replace shared ERS Visit
 ;file admission information
  ; Compare ER "Presenting Complaint" to VISIT "Chief Complaint"
 ;N AMERVVAL,AMEREVAL,AMERDUZ,AMERSTRG,AMEREDTS
 N AMERVVAL,AMEREVAL,AMERDUZ,AMERSTRG,AMEREDTS,AMERDR  ;IHS/OIT/SCR 071509
 ;S AMERDUZ=DUZ
 S AMEREVAL=$G(^AMERVSIT(AMERDA,1))
 S AMERVVAL=$G(^AUPNVSIT(AMERPCC,14))
 S AMERVVAL=$TR(AMERVVAL,";","~")  ;IHS/OIT/SCR 05/07/09 patch 1 - don't try to save ";"
 ;S AMERAIEN=$$CREATAUD^AMEREDAU(AMERDA,AMERDUZ) Q:AMERAIEN<0  ;CREATE AN AUDIT FILE RECORD
 I (AMEREVAL'=AMERVVAL) D
 .Q:AMERVVAL=""
 .;KEEP THE PCC VISIT INFO - PUT IT INTO THE AMER VISIT
 .NEW AMUPD
 .S AMUPD(9009080,AMERDA_",",1)=AMERVVAL
 .D FILE^DIE("","AMUPD","ERROR")
 .;S AMERDR="1////"_AMERVVAL
 .;D DIE^AMEREDIT(AMERDA,AMERDR)
 .;D NOW^%DTC
 .;S AMERSTRG="1;"_X_";"_AMEREVAL_";"_AMERVVAL_";Other;CHIEF COMPLAINT;Silent PCC SYNCH"
 .;S AMEREDTS=AMERSTRG
 .;D:AMEREDTS'="" MULTAUDT^AMEREDAU(AMEREDTS,AMERAIEN)
 .Q
 ; GET THE DEPARTURE OUT TIME FROM VISIT AND COMPARE TO CHECK OUT TIME IN ER VISIT
 S AMEREVAL=$P($G(^AMERVSIT(AMERDA,6)),U,2)  ; AMERDEPT IS DEPARTURE TIME
 ;S AMERVVAL=$$CODT^APCLV(AMERPCC,"I")
 S AMERVVAL=$P(^AUPNVSIT(AMERPCC,0),"^",18)  ;CHECKOUT TIME
 I (AMEREVAL'=AMERVVAL) D
 .Q:AMERVVAL=""
 .;KEEP THE PCC VISIT INFO - PUT IT INTO THE AMER VISIT
 .S AMERDR="6.2////"_AMERVVAL
 .D DIE^AMEREDIT(AMERDA,AMERDR)
 .;D NOW^%DTC
 .;S AMERSTRG="1;"_X_";"_$$EDDISPL^AMEREDAU(AMEREVAL,"D")_";"_$$EDDISPL^AMEREDAU(AMERVVAL,"D")_";Other;CHECK OUT TIME;Silent PCC SYNCH"
 .;S AMEREDTS=AMERSTRG
 .;D:AMEREDTS'="" MULTAUDT^AMEREDAU(AMEREDTS,AMERAIEN)
 .Q
 Q
SYNCHERX(AMERDA,AMERPCC)  ;EP from AMEREDIT and AMERPCC2
 ;IHS/OIT/SCR 12/29/08
 ;This routine is called when it is determined that PCC DX need to replace the ER VISIT file DXs.
 ;0. REMOVE ALL DX FROM ERS SO DX GO BACK IN SAME INDEX AS PCC ARRA
 ;1. GET ALL DX FROM PCC
 ;2. REPLACE THE PRIMARY DX INFO WITH THE FIRST DX
 ;3. REPLACE EACH DX NODE IN ERS WITH THAT PCC DX NODE
 N AMERDXS,AMERINDX,AMERVERR,AMERDR,AMERONAR,AMERODX,AMEROLD,AMERNEW,AMERPDX,AMERNNAR,AMERSTRG,AMERAIEN,AMERDUZ
 N AMEREDNM,AMEREDTS,AMERDIE,AMERERR,DA,DIC,X,Y,DIK,AMEROFST
 N AMERPOV
 ;
 S AMEREDTS=""
 ;S AMEROFST=0
 S AMERERR=0
 ;S AMEREDNM=1
 ;S AMERDUZ=DUZ ;WHO EVER IS USING THIS APPLICATION WHEN THIS ROUTINE IS CALLED
 ;S AMERAIEN=$$CREATAUD^AMEREDAU(AMERDA,AMERDUZ) Q:AMERAIEN<0  ;CREATE AN AUDIT FILE RECORD
 ;
 ;Clear out exisiting AMER VISIT POV entries
 S AMERINDX=0
 F  S AMERINDX=$O(^AMERVSIT(AMERDA,5,AMERINDX)) Q:(AMERINDX="")  D
 .S DA(1)=AMERDA,DA=AMERINDX
 .S DIK="^AMERVSIT(DA(1),5,"
 .D ^DIK,EN^DIK  ; Delete identified entry and re-index diagnosis field
 .Q
 ;
 ;Clear out primary Dx and Narrative
 D
 . NEW DIE,DA,DR
 . S DIE="^AMERVSIT("
 . S DA=AMERDA
 . S DR="5.2////@;5.3////@"
 . L +^AMERVSIT(DA):0 I $T D ^DIE L -^AMERVSIT(DA)
 ;
 ;AMER*3*6;Pull POV information using new call
 ;$$POV^AMERUTIL Returns
 ;AMERPOV(CNT)=[1]^[2]^[3]^[4]^[5]
 ;[1] - ICD code
 ;[2] - P-Primary, S-Secondary
 ;[3] - Provider Narrative
 ;[4] - IEN Pointer to file 80
 ;[5] - ICD Description Value
 ;[6] - V POV IEN
 S AMERVERR=$$POV^AMERUTIL("",AMERPCC,.AMERPOV)
 ;
 ;Now update AMERVSIT
 S AMERINDX="" F  S AMERINDX=$O(AMERPOV(AMERINDX)) Q:AMERINDX=""  D
 . NEW DXNAR,DXIEN,DXPRM,DA,DIC,DIE,X,Y,DLAYGO,DR
 . ;
 . ;Retrieve values
 . S DXNAR=$P(AMERPOV(AMERINDX),U,3) ;Provider Narrative
 . S DXIEN=$P(AMERPOV(AMERINDX),U,4) ;POV IEN
 . S DXPRM=$P(AMERPOV(AMERINDX),U,2) ;P/S
 . ;
 . ;If primary save special fields
 . I DXPRM="P" D
 .. ;AMER*3.0*7;Changes to handle special characters in narrative
 .. NEW AMUPD
 .. S AMUPD(9009080,AMERDA_",",5.2)=DXIEN
 .. I DXNAR]"" S AMUPD(9009080,AMERDA_",",5.3)=DXNAR
 .. D FILE^DIE("","AMUPD","ERROR")
 .. ;S DIE="^AMERVSIT("
 .. ;S DA=AMERDA
 .. ;S DR="5.2////"_DXIEN
 .. ;I DXNAR]"" S DR=DR_";5.3////"_DXNAR
 .. ;L +^AMERVSIT(DA):0 I $T D ^DIE L -^AMERVSIT(DA)
 . ;
 . ;Save entry
 . S DA(1)=AMERDA,DIC="^AMERVSIT("_DA(1)_",5,",DIC(0)="L"
 . S DLAYGO=9009080.05
 . S X=DXIEN
 . K DO,DD D FILE^DICN
 . Q:DXNAR=""  ;Quit if no narrative
 . Q:+Y<0
 . ;AMER*3.0*7;Changes to handle special characters in narrative
 . ;S DIE=DIC,DA(1)=AMERDA,DA=+Y,DR="1////"_DXNAR
 . ;D ^DIE
 . NEW IENS,AMUPD
 . S DA(1)=AMERDA,DA=+Y,IENS=$$IENS^DILF(.DA)
 . S AMUPD(9009080.05,IENS,1)=DXNAR
 . D FILE^DIE("","AMUPD","ERROR")
 ;
 Q
 ;
SYNCHERD(AMERDA,AMERPCC)  ;EP from AMEREDIT and AMERPCC1
 ;IHS/OIT/SCR 12/30/08
 ;This routine is called when it is determined that PCC PROVIDERS need to replace the ER VISIT file PROVIDERS.
 ;1. GET ALL PROVIDERS FROM PCC
 ;2. REPLACE THE ERS DISCHARGE PROVIDER INFO WITH THE INFO IN THE PCC PRIMARY PROVIDER IF THEY ARE DIFFERENT
 N AMERVINT,AMEREINT,AMERVERR,AMERDR,AMERSTRG,AMERAIEN,AMERDUZ,AMEREDTS
 S AMEREDTS=""
 ;S AMERDUZ=DUZ ;WHO EVER IS USING THIS APPLICATION WHEN THIS ROUTINE IS CALLED
 ;S AMERAIEN=$$CREATAUD^AMEREDAU(AMERDA,AMERDUZ) Q:AMERAIEN<0  ;CREATE AN AUDIT FILE RECORD
 S AMERVINT=$$PRIMPROV^APCLV(AMERPCC,"I")  ;RETURNS ONE PCC PRIMARY PROVIDER
 S AMEREINT=$P($G(^AMERVSIT(AMERDA,6)),U,3) ; DISCHARGE PROVIDER
 I AMERVINT'=AMEREINT D
 .Q:AMERVINT=""
 .;UPDATE ERS DISCHARGE PROVIDER WITH THE PCC PRIMARY PROVIDER
 .S AMERDR=""
 .S AMERDR="6.3////"_AMERVINT
 .D:AMERDR'="" DIE^AMEREDIT(AMERDA,AMERDR)
 .;D NOW^%DTC
 .;S AMERSTRG="6.3;"_X_";"_$$EDDISPL^AMEREDAU(AMEREINT,"N")_";"_$$EDDISPL^AMEREDAU(AMERVINT,"N")_";Other;DISCHARGE PROVIDER;Silent PCC SYNCH"
 .;S AMEREDTS=AMERSTRG
 .;D:AMEREDTS'="" MULTAUDT^AMEREDAU(AMEREDTS,AMERAIEN)
 .Q
 Q
SYNCHERS(AMERSTRT,AMEREND)  ;EP from ERS reporting routines to synch a range of records
 ;IHS/OIT/SCR 12/29/08
 ;This routine is called to check all ER VISITS in a date range and update them with PCC DATA when
 ;the 'last edited' date on the PCC VISIT is more recent than the 'last edited' 'date in the ERS VISIT
 ; 1. CREATE AN ARRAY OF ERS IEN, PCC VISIT IEN AND ERS LAST UPDATE INFO FOR ERS VISITS IN THE DATE RANGE
 ; 2. FOR EACH ENTRY IN THAT ARRAY, GET THE PCC 'LAST UPDATE DATE'
 ;      COMPARE PCC 'LAST UPDATE' TO  ERS 'LAST UPDATE'
 ;      IF PCC LAST UPDATE IS MORE CURRENTCALL SYNCHER ROUTINES TO UPDATE ERS VISIT
 N AMEREMOD,AMERPMOD,AMERPCC,AMERDA,AMERFRST,AMERLST,X,Y,X1,X2,AMERPAT
 S %DT=""
 S X=AMERSTRT
 D ^%DT
 S AMERFRST=Y
 S X=AMEREND
 D ^%DT
 S AMERLST=Y
 ;S AMERIDX1=AMERFRST
 S AMERIDX1=AMERFRST-1  ;IHS/OIT/SCR 2/27/09 not synching all entries when reports are run
 F  S AMERIDX1=$O(^AMERVSIT("B",AMERIDX1)) Q:($P(AMERIDX1,".",1)>AMERLST)!(AMERIDX1="")  D
 .I AMERIDX1<AMERFRST Q  ;GET TO STARTING POINT
 .S AMERDA=$O(^AMERVSIT("B",AMERIDX1,""))
 .S AMEREMOD=$P($G(^AMERVSIT(AMERDA,12)),"^",6)  ;DATE  LAST MODIFIED IN ERS VISIT
 .S AMERPCC=$P($G(^AMERVSIT(AMERDA,0)),"^",3)   ;PCC IEN FOR THIS VISIT
 .I AMERPCC<1 D  Q  ;IHS/OIT/SCR 05/07/09
 ..D EN^DDIOL("No PCC VISIT found for ERS VISIT IEN "_AMERDA_"!!","","!?5")
 ..D EN^DDIOL("Skipping this record","","!?10")
 ..Q
 .S AMERPMOD=$$DLM^APCLV(AMERPCC,"I")
 .I AMERPMOD>=$P(AMEREMOD,".",1) D
 ..D SYNCHERA(AMERDA,AMERPCC)   ;SYNCH ADMISSION IFO
 ..D SYNCHERX(AMERDA,AMERPCC)   ;SYNCH DIAG INFO
 ..D SYNCHERD(AMERDA,AMERPCC)   ;SYNCH PRIMARY PROVIDER INFO
 ..;IHS/OIT/SCR 12/15/08 - update ER VISIT FILE with DATE LAST SYNCHED (NOW)
 ..D TIMESTMP^AMERSAV1(AMERDA)
 ..Q
 .S AMERPAT=$P($G(^AMERVSIT(AMERDA,0)),U,2)
 .D:AMERPAT>0 SYNCHERP(AMERPAT,AMERDA)
 .Q
 W !,"FINISHED SYNCHING ERS WITH CURRENT PCC DATA FROM "_AMERSTRT_" TO "_AMEREND
 Q
SYNCHERP(AMERPAT,AMERDA)  ; EP from AMER0, AMEREDIT AND AMERPCC
 ;SYNCHS MOST CURRENT PATIENT INFORMATION FOR DUPLICATED FIELDS HRN AND DOB
 N AMERDOB,AMERHRN,AMERDR ;IHS/OIT/SCR 071509 patch 2
 S AMERDOB=$$DOB^AUPNPAT(AMERPAT)
 S AMERHRN=$$HRN^AUPNPAT(AMERPAT,DUZ(2))
 I $P($G(^AMERVSIT(AMERDA,0)),U,12)'=AMERDOB D
 .S AMERDR=".12////"_AMERDOB
 .D DIE^AMEREDIT(AMERDA,AMERDR)
 .Q
 I $P($G(^AMERVSIT(AMERDA,0)),U,13)'=AMERHRN D
 .S AMERDR=".13////"_AMERHRN
 .D DIE^AMEREDIT(AMERDA,AMERDR)
 .Q
 Q