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

AMERPCC1.m

Go to the documentation of this file.
AMERPCC1 ; IHS/OIT/SCR - SUPPORTING ROUTINES FOR PCC VISIT CREATION AND V PROVIDER EDITING ;
 ;;3.0;ER VISIT SYSTEM;**1,2**;FEB 23, 2009
 ;
SYNCHPRV(AMERDA,AMERPCC,AMERPAT) ; EP from AMERPCC
 ; INPUT
 ;   AMERDA : IEN OF ER VISIT FILE
 ;  AMERPCC : IEN OF VISIT FILE being broght in synch
 ;  AMERPAT : IEN OF PATIENT FILE for selected ER VISIT
 N AMERVERR,AMERFND,AMEREVAL,AMERETIM,AMERVPRV
 N AMERPROV,AMERTIME,AMERCNT,AMERLIST,AMERCNUM,AMERVIEN
 ; This routine updates V PROVIDER entires with provider information in ER VISIT file
 ; First get any providers that are in V PROVIDER
 K APCLV
 S AMERLIST=""
 S AMERVERR=$$PCCVF^APCLV(AMERPCC,"PROVIDER","5;13;16")
 ; This will return:
 ; APCLV(x)=internal value of provider entry^PROVIDER NAME^primary or secondary
 ; for each V PROVIDER x in the file for this visit
 ; now set the FOURTH piece to the "provider time" and
 ; set the FIFTH piece to "status" code for each of these providers
 S AMERVPRV=0,AMERVIEN=""
 F  S AMERVPRV=$O(APCLV(AMERVPRV)) Q:AMERVPRV=""  D
 .;IHS/OIT/SCR 05.29/09 added "^" to global reference - patch 1 t2 build
 .S $P(APCLV(AMERVPRV),U,4)=$P($G(^AUPNVSIT(AMERPCC,12)),U,1) ;The fourth piece is the Provider time
 .S $P(APCLV(AMERVPRV),U,5)=$P($G(^AUPNVSIT(AMERPCC,0)),U,5) ;The fifth piece is the provider status - will be null unless this is a consultant for this visit
 .; Now add the V PROVIDER ien to the array using a custom lookup
 .S AMERVIEN=$$VPRVIEN^AMERVSIT(AMERPCC,$P(APCLV(AMERVPRV),U,1))
 .S $P(APCLV(AMERVPRV),U,6)=AMERVIEN ; The sixth piece is the ien of the V PROVIDER file
 .Q
 ; Now build an array of the providers that exist in ER VISIT
 ; time can be imprecise, so send "day" of discharge for discharge provider and discharge nurse
 ; and collected times for admitting provider and triage nurse
 S X=$P($G(^AMERVSIT(AMERDA,0)),U,1)  ; X is the admission date in FM format
 D H^%DTC
 I $G(%H)'="" D YMD^%DTC
 S AMERTIME=$G(X)
 ; This is the DATE of admission in FM format
 S AMEREVAL(1)=$P($G(^AMERVSIT(AMERDA,6)),U,3) ; DISCHARGE PROVIDER
 S AMERETIM(1)=$G(AMERTIME)  ; DAY OF ADMIT
 I AMEREVAL(1)'="" S AMERLIST=AMEREVAL(1)_"^"
 S AMEREVAL(2)=$P($G(^AMERVSIT(AMERDA,6)),U,4) ; DISCHARGE NURSE
 S AMERETIM(2)=$G(AMERTIME)  ; DAY OF ADMIT
 ; IF DISCHARGE PROVIDER AND DISCHARGE NURSE ARE THE SAME, ONLY ADD ONE ENTRY
 I AMEREVAL(1)=AMEREVAL(2) S AMEREVAL(2)="",AMERETIM(2)=""
 I AMEREVAL(2)'="" S AMERLIST=AMERLIST_AMEREVAL(2)_"^"
 S AMEREVAL(3)=$P($G(^AMERVSIT(AMERDA,0)),U,6) ; ADMITTING PROVIDER
 S AMERETIM(3)=$P($G(^AMERVSIT(AMERDA,12)),U,1) ; ADMITTING PROVIDER TIME
 ; IF discharge provider is same as admitting provider, only add one entry
 I AMEREVAL(1)=AMEREVAL(3) S AMEREVAL(3)=""
 I AMEREVAL(3)'="" S AMERLIST=AMERLIST_AMEREVAL(3)_"^"
 ; If triage nurse is same as discharge provider , only add one entry
 I AMEREVAL(2)=AMEREVAL(3) S AMEREVAL(3)=""
 S AMEREVAL(4)=$P($G(^AMERVSIT(AMERDA,0)),U,7) ; TRIAGE NURSE
 S AMERETIM(4)=$P($G(^AMERVSIT(AMERDA,12)),U,2) ; TRIAGE NURSE TIME
 ; If discharge provider is same as traige nurse, only add once
 I AMEREVAL(1)=AMEREVAL(4) S AMEREVAL(4)=""
 ; If discharge nurse is same as triage nurse, only add once
 I AMEREVAL(2)=AMEREVAL(4) S AMEREVAL(4)=""
 ; If admitting provider is same as triage nurse, only add once
 I AMEREVAL(3)=AMEREVAL(4) S AMEREVAL(4)=""
 I AMEREVAL(4)'="" S AMERLIST=AMERLIST_AMEREVAL(4)_"^"
 ; If there are ER CONSULTANTS add them to the ER PROVIDER array
 I ($G(^AMERVSIT(AMERDA,19,0))'="") D
 .S AMERCNUM=0
 .F AMERCNT=5:1 S AMERCNUM=$O(^AMERVSIT(AMERDA,19,AMERCNUM)) Q:(AMERCNUM="B"!(AMERCNUM=""))  D
 ..; If provider already exists in provider list, don't add it again
 ..S AMERFND=0
 ..F AMERI=1:1 S AMERPROV=$P(AMERLIST,U,AMERI) Q:(AMERPROV=""!(AMERFND=1))  D
 ...I AMERPROV=$P($G(^AMERVSIT(AMERDA,19,AMERCNUM,0)),U,3) S AMERFND=1
 ...Q
 ..Q:AMERFND
 ..S AMEREVAL(AMERCNT)=$P($G(^AMERVSIT(AMERDA,19,AMERCNUM,0)),U,3) ; ER CONSULTANT NEW PERSON
 ..S AMERETIM(AMERCNT)=$P($G(^AMERVSIT(AMERDA,19,AMERCNUM,0)),U,2)
 ..S AMERLIST=AMERLIST_AMEREVAL(AMERCNT)_"^"
 ..Q
 .Q
 D VPRVUPDT
 K APCLV
 Q
VPRVUPDT ;
 ; For each ER Provider, check to see if an entry has been made in V PROVIDER
 ; - If entry has been made:
 ;  -- Compare data and update if needed
 ;  -- Remove this provider from local array of V providers
 ; - If entry has not been made
 ;  -- add V PROVIDER entry
 ; For each remaining V PROVIDER in local array ASK if user wants remove entry from V PROVIDER
 N AMERFND,AMERPROV,AMERVPRV,AMERVDR,AMERVIEN,AMERDR,AMERVINT,AMERVNAM,AMEREINT,AMERENAM
 S (AMERFND,AMERPROV,AMERVPRV)=0
 S (AMERVDR,AMERVIEN)=""
 F  S AMERPROV=$O(AMEREVAL(AMERPROV)) Q:AMERPROV=""  D
 .;I $G(AMEREVAL(AMERPROV))="" S AMERFND=1 Q  ;IHS/OIT/SCR 10/14/09 patch 2 beta1
 .S AMERFND=0  ; Flag set to 1 if provider is later found in V PROVIDER file
 .Q:AMEREVAL(AMERPROV)=""  ; If there is no unique information for this provider type, quit
 .F  S AMERVPRV=$O(APCLV(AMERVPRV)) Q:AMERVPRV=""  D
 ..I $P(AMEREVAL(AMERPROV),U,1)=$P(APCLV(AMERVPRV),U,1) D  ; If we have found a match, update if needed
 ...S AMERFND=1
 ...; First ask user if they want update PCC discharge provider as "primary" if it isn't already
 ...I (AMERPROV=1&($P(APCLV(AMERVPRV),U,2)="P")) D
 ....;IHS/OIT/SCR 12/29/08 ask before overwriting PCC
 ....D EN^DDIOL("**The value for PRIMARY PROVIDER in the PCC visit file is different from ERS DISCHARGE PROVIDER**","","!!?3")
 ....D EN^DDIOL("PCC VISIT PRIMARY PROVIDER: "_$P($G(APCLV(AMERVPRV)),U,1))
 ....D EN^DDIOL("ERS DISCHARGE PROVIDER: "_AMEREVAL(2))
 ....S DIR(0)="SO^1:Correct PCC data using ERS data;2:Correct ERS data using PCC data"
 ....S DIR("A")="Which would you like to do"
 ....D ^DIR K DIR
 ....S AMERANS=+Y
 ....I Y=""!(Y="^")!(AMERANS=2) D
 .....;UPDATE ERS DISCHARGE PROVIDER WITH THE PCC PRIMARY PROVIDER
 .....S AMERNEW=$P($G(APCLV(AMERVPRV)),U,1)
 .....S:AMERNEW'="" AMERDR="6.3////"_AMERNEW
 .....D:AMERDR'="" DIE^AMEREDIT(AMERDA,AMERDR)
 .....S AMEREVAL(1)=AMERNEW
 .....Q
 ....I AMERANS=1 D
 .....S AMERVDR=$S(AMERVDR'="":AMERVDR_";",1:"")
 .....S AMERVDR=AMERVDR_".04///"_"P"
 .....S AMERVIEN=$P(APCLV(AMERVPRV),U,6)
 .....Q
 ....Q  ; IF THIS IS THE PCC PRIMARY PROVIDER
 ...;If V PROVIDER is NOT marked secondary and is not the ER DISCHARGE provider, mark this provider "secondary"
 ...I $P(APCLV(AMERVPRV),U,3)'="S" D
 ....Q:AMERPROV=1
 ....S AMERVDR=$S(AMERVDR'="":AMERVDR_";",1:"")
 ....S AMERVDR=AMERVDR_".04///"_"S"
 ....S AMERVIEN=$P(APCLV(AMERVPRV),U,6)
 ....Q
 ...;Update V PROVIDER time, if different from day of admit
 ...I $P(APCLV(AMERVPRV),U,4)'=AMERTIME D
 ....S AMERVDR=$S(AMERVDR'="":AMERVDR_";",1:"")
 ....S AMERVDR=AMERVDR_"1201///"_AMERTIME
 ....S AMERVIEN=$P(APCLV(AMERVPRV),U,6)
 ....Q
 ...D:AMERVIEN'="" VPRVDIE^AMERVSIT(AMERVIEN,AMERVDR)
 ...K:$G(AMERVPRV)'="" APCLV(AMERVPRV) ; Remove this provider from local array
 ...S (AMERVDR,AMERVIEN)=""
 ...Q
 ..Q
 .I AMERFND=0 D   ; Add this provider if it isn't there already
 ..I AMERPROV=1 D
 ...S AMERVINT=$$PRIMPROV^APCLV(AMERPCC,"I")  ;RETURNS ONE PCC PRIMARY PROVIDER
 ...S AMERANS=1 ;DEFAULTING TO ADD ERS PROVIDER IF THERE ARE NO PCC PROVIDERS THERE
 ...S AMERVNAM=""
 ...S:AMERVINT'="" AMERVNAM=$P($G(^VA(200,AMERVINT,0)),"^",1)
 ...S AMEREINT=AMEREVAL(AMERPROV)
 ...S AMERENAM=$P($G(^VA(200,AMEREINT,0)),"^",1)
 ...I AMERVINT'="" D
 ....D EN^DDIOL("**The value for PRIMARY PROVIDER in the PCC visit file is different from ERS DISCHARGE PROVIDER**","","!!?3")
 ....D EN^DDIOL("PCC VISIT PRIMARY PROVIDER: "_AMERVNAM,"","!!?3")
 ....D EN^DDIOL("ERS DISCHARGE PROVIDER: "_AMERENAM,"","!!?3")
 ....S DIR(0)="SO^1:Correct PCC data using ERS data;2:Correct ERS data using PCC data"
 ....S DIR("A")="Which would you like to do"
 ....D ^DIR K DIR
 ....I Y=""!(Y="^") S AMERANS=2
 ....E  S AMERANS=+Y
 ....Q
 ...I AMERANS=2 D
 ....;UPDATE ERS DISCHARGE PROVIDER WITH THE PCC PRIMARY PROVIDER
 ....D SYNCHERD^AMERERS(AMERDA,AMERPCC)
 ....S AMEREVAL(1)=AMERVINT
 ....S AMERVPRV=""
 ....F  S AMERVPRV=$O(APCLV(AMERVPRV)) Q:AMERVPRV=""  K:$P(APCLV(AMERVPRV),"^",1)=AMERVINT APCLV(AMERVPRV)
 ....Q
 ...I AMERANS=1 D
 ....;DELETE THE OLD PRIMARY PROVIDER IF IT IS THERE AND REPLACE IT WITH THE ERS PRIMARY PROVIDER
 ....F  S AMERVPRV=$O(APCLV(AMERVPRV)) Q:AMERVPRV=""!(AMERVINT="")  D
 .....I ($P(APCLV(AMERVPRV),U,1)=AMERVINT) D
 ......S AMERVIEN=$P(APCLV(AMERVPRV),U,6)
 ......D DELVPRV^AMERVSIT(AMERVIEN)
 ......Q
 .....Q
 ....I $$ADDPRV(AMERPCC,AMEREVAL(AMERPROV),AMERETIM(AMERPROV),AMERPAT,"P","")<1 D EN^DDIOL("UNABLE TO ADD PRIMARY V PROVIDER","","!!")
 ....E  D EN^DDIOL("** PRIMARY V PROVIDER ADDED TO PCC VISIT **","","!!?3")
 ....Q  ;IF AMER ANS=1
 ...Q  ;IF THIS IS ERS PRIMARY PROVIDER
 ..I 2<=AMERPROV&(AMERPROV<=4) D   ;IF THIS IS NOT THE ERS PRIMARY PROVIDER
 ...;IHS/OIT/SCR 10/14/09 patch 2 beta1 QUIT IF THIS PROVIDER ALREADY EXISTS IN THE PCC V PROV FILE
 ...S AMERFND=0
 ...F  S AMERVPRV=$O(APCLV(AMERVPRV)) Q:AMERVPRV=""  D
 ....I ($P(APCLV(AMERVPRV),"^",1)=AMEREVAL(AMERPROV)) S AMERFND=1
 ....Q
 ...Q:AMERFND  ;ADD PROVIDER ONLY IF IT WASN'T FOUND IN THE PCC V PROVIDER ARRAY
 ...I $$ADDPRV(AMERPCC,AMEREVAL(AMERPROV),AMERETIM(AMERPROV),AMERPAT,"S","")<1 D EN^DDIOL("UNABLE TO ADD SECONDARY V PROVIDER","","!!")
 ...E  D EN^DDIOL("** SECONDARY V PROVIDER ADDED TO PCC VISIT **","","!!?3")
 ..I AMERPROV>4 D  ; Add Consultants with status of "C"
 ...I $$ADDPRV(AMERPCC,AMEREVAL(AMERPROV),AMERETIM(AMERPROV),AMERPAT,"S","C")<1 D EN^DDIOL("UNABLE TO ADD CONSULTANT V PROVIDER","","!!")
 ...E  D EN^DDIOL("** SECONDARY CONSULTANT V PROVIDER ADDED TO PCC VISIT **","","!!?3")
 ..;K:$G(AMERVPRV)'="" APCLV(AMERVPRV)
 ..Q  ;IF THE PROVIDER WASN'T FOUND
 .Q
 ; All ER PROVIDERS should now be in V PROVIDER file
 ; Now remove all V PROVIDER entries for providers still exiting in local V PROVIDER array
 S AMERVINT=$$PRIMPROV^APCLV(AMERPCC,"I")  ;RETURNS ONE PCC PRIMARY PROVIDER
 F  S AMERVPRV=$O(APCLV(AMERVPRV)) Q:AMERVPRV=""  D
 .;Q:APCLV(AMERVPRV)=AMERVINT  ;DONT ASK TO REMOVE THE ENTRY WE JUST ADDED TO ERS
 .;IHS/OIT/SCR 10/14/09 patch 2 beta1 - don't ask to remove a provider that is part of this visit
 .Q:($P(APCLV(AMERVPRV),"^",1)=AMEREVAL(1))!($P(APCLV(AMERVPRV),"^",1)=AMEREVAL(2))!($P(APCLV(AMERVPRV),"^",1)=AMEREVAL(3))!($P(APCLV(AMERVPRV),"^",1)=AMEREVAL(4))
 .D EN^DDIOL("**The following V PROVIDER entry is not represented in the ERS Visit**","","!!?3")
 .D EN^DDIOL("PCC VISIT PROVIDER: "_$P(APCLV(AMERVPRV),U,2))
 .S DIR(0)="SO^1:REMOVE THIS PCC V PROVIDER ENTRY;2:KEEP THIS PCC VISIT V PROVIDER ENTRY"
 .S DIR("A")="Which would you like to do"
 .D ^DIR K DIR
 .S AMERANS=+Y
 .I Y=1 D
 ..S AMERVIEN=$P(APCLV(AMERVPRV),U,6)
 ..D DELVPRV^AMERVSIT(AMERVIEN)
 ..D EN^DDIOL("** V PROVIDER ENTRY DELETED **","","!!?3")
 ..Q
 .Q
 Q
ADDPRV(AMERPCC,AMERPIEN,AMERTIME,AMERDFN,AMERTYPE,AMERSTAT) ; EP FROM AMERPCC  
 ; ADD AN ENTRY TO V PROVIDER
 ; INPUT: 
 ;   AMERPCC - VISIT IEN
 ;   AMERPIEN - PROVIDIER IEN
 ;   AMERTIME - TIME OF PROVIDER 
 ;   AMERDFN  - PATIENT IEN
 K APCDALVR,APCDAFLE
 I 'AMERPCC>0 Q 0  ; INVALID VISIT IEN
 I 'AMERPIEN>0 Q 0 ; INVALID PROVIDER IEN
 I 'AMERDFN>0 Q 0 ; INVALID PATIENT IEN
 I $G(AMERTYPE)'="P" S AMERTYPE="S"
 S APCDALVR("APCDTPRO")="`"_AMERPIEN  ; PROVIDER IEN
 S APCDAFLE("APCDAFLE")="9000010.06"
 S APCDALVR("APCDPAT")=AMERDFN  ; PATIENT IEN
 S APCDALVR("APCDVSIT")=AMERPCC  ; VISIT IEN
 S APCDALVR("APCDTCDT")=AMERTIME ; PROVIDER TIME
 I AMERSTAT="C" S APCDALVR("APCDTOA")="C"
 E  S APCDALVR("APCDTOA")=""
 S APCDALVR("APCDTPS")=AMERTYPE
 S APCDALVR("APCDATMP")="[APCDALVR 9000010.06 (ADD)]"
 D EN^APCDALVR
 D MOD^AUPNVSIT  ; Update VISIT file with last edit when a provider is added
 K APCDLVR,APCDTPRO,APCDAFLE,APCDPAT,APCDVSIT,APCDTCDT,APCDTOA,APCDTPS,APCDATMP
 Q 1
PRVTHERE(AMERPRVD,AMERPCC)  ;EP FROM AMERPCC1
 ;IHS/OIT/SCR 12/16/08 - check to see if the provider you are about to add is already in the PCC visit 
 ;INPUT: AMERPRVD - PROVIDER IEN
 ;    AMERPCC = VISIT FILE ien for this visit
 N AMERCHCK,AMERDONE,AMERERR,AMERINDX
 K APCLV
 Q:$G(AMERPCC)=""
 S AMERERR=$$PCCVF^APCLV(AMERPCC,"PROVIDER",5)  ;SPECIFYING THE INTERNAL PROVIDER ID
 I 'AMERERR D
 .S AMERINDX=0,AMERDONE=0,AMERCHCK=0
 .F  S AMERINDX=$O(APCLV(AMERINDX)) Q:AMERDONE  D
 ..I AMERINDX="" S AMERDONE=1 Q
 ..S AMERIEN=$G(APCLV(AMERINDX))
 ..S AMERCHCK=(AMERIEN=AMERPRVD)
 ..I AMERCHCK S AMERDONE=1
 ..Q
 K APCLV
 Q AMERCHCK
GETPCCPV(AMERPCC)  ; EP FROM AMERD AND OTHER ROUTINES
 ;IHS/OIT/SCR 12/18/08
 ;RETURNS AN ARRAY OF PCC V PROVIDER FILE INFORMATION THAT ERS SHARES
 ;S AMERPCCV=$$VDTM^APCLV(AMERPCC,"I") ; PIECE 1 IS THE TIMESTAMP IN THE VISIT
 ;S AMERPCCV=AMERPCCV_"^"_$$PATIENT^APCLV(AMERPCC,"I") ; PIECE 2 IS THE PATIENT IEN
 N AMERPRVS,AMERINDX
 S AMERPRVS=""
 K APCLV
 S AMERERR=$$PCCVF^APCLV(AMERPCC,"PROVIDER","5;13;16") ;PROVIDER IEN;PROVIDER NAME;PRIMARY/SECONDARY
 S AMERINDX=""
 F  S AMERINDX=$O(APCLV(AMERINDX)) Q:AMERINDX=""  D
 .S AMERPRVS=AMERPRVS_APCLV(AMERINDX)_"~"
 .Q
 K APCLV
 Q AMERPRVS