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

AMERPCC3.m

Go to the documentation of this file.
AMERPCC3 ; IHS/OIT/SCR - SUPPORTING ROUTINES FOR V POV SYNCHING ;
 ;;3.0;ER VISIT SYSTEM;**1,2**;FEB 23, 2009
 ;
VPOVUPDT(AMERPAT,AMERPCC,AMERTIME,AMERDOC)  ;
 ; For each ER DX, check to see if an entry has been made in V POV
 ; - If entry has been made:
 ;  -- Compare data and ask user to update if needed
 ; - If entry has not been made
 ;  --  ask user to add V POV entry or remove from ERS
 ; For each V POV entry that is not matched to an ER DX, either add to ERS or remove from PCC
 N AMERFND,AMERPOV,AMERVPOV,AMERVDR,AMERVIEN,AMERDX,AMERNAR,AMERVDXI,AMERVICD
 N AMEREDNM,AMERDUZ,AMERAIEN,AMEREDTS,AMERCODE,AMERCNT,AMEREPOV,AMERENAR,AMER9999,AMERSLNT
 N Y,X,DIC,DIE
 N AMERCLN ;IHS/OIT/SCR 072309 patch 2
 S AMERSLNT=0 ;IHS/OIT/SCR 060409 patch 1 
 S AMEREDNM=0
 S AMERVPOV=0
 S AMERDUZ=DUZ
 S AMEREDTS=""
 S AMER9999=$P($$ICDDX^ICDCODE(".9999",,,1),U,1) ;POINTER TO .9999 CODE IN ICD9 CODE - THIS CODE CAN BE ENTERED MORE THAN ONCE
  ; Now build array of the VALID ICD9 codes and narratives that exist in ER VISIT
 I $G(^AMERVSIT(AMERDA,5,0))'="" D
 .S AMERCNT=0
 .;S AMEREPOV(1)=$P($$ICDDX^ICDCODE(+AMERPDX,,,1),U,1)  ;pointer to the primary ICD9 code
 .;S AMERENAR(1)=AMERPNAR ; PRIMARY NARRATIVE
 .S AMERPOV=0
 .F  S AMERPOV=$O(^AMERVSIT(AMERDA,5,AMERPOV)) Q:AMERPOV="B"!(AMERPOV="")  D
 ..S AMERCNT=AMERCNT+1
 ..I $P($G(^AMERVSIT(AMERDA,5,AMERPOV,0)),U,1)=AMER9999 D
 ...S AMERE999=AMERE999+1
 ...;Q:((AMEREPOV(1)=AMER9999)&(AMERE999=1))
 ...S AMERDX=AMER9999
 ...S AMEREPOV(AMERCNT)=AMERDX_"^"_AMERPOV  ; THIS IS A ICD9 POINTER WITH ITS INDEX IN THE ER VISIT FILE
 ...S AMERENAR(AMERCNT)=$G(^AMERVSIT(AMERDA,5,AMERPOV,1))
 ...Q
 ..;E  I ($P($G(^AMERVSIT(AMERDA,5,AMERPOV,0)),U,1)'=AMERPDX) D
 ..I $P($G(^AMERVSIT(AMERDA,5,AMERPOV,0)),U,1)'=AMER9999 D
 ...S AMERCNT=AMERCNT+1
 ...S AMERDX=$P($G(^AMERVSIT(AMERDA,5,AMERPOV,0)),U,1)
 ...S AMEREPOV(AMERCNT)=AMERDX_"^"_AMERPOV  ; THIS IS A ICD9 POINTER WITH ITS INDEX IN THE ER VISIT FILE
 ...S AMERENAR(AMERCNT)=$G(^AMERVSIT(AMERDA,5,AMERPOV,1))  ; DX NARATIVE
 ...Q
 ..Q  ;IF THIS ISN'T THE PRIMARY, ADD IT TO THE LIST OF DX'S TO ADD
 .Q  ; FOR EACH ERS VISIT
 S (AMERVDR,AMERVIEN)=""
 ;IHS/OIT/SCR 072209 patch 2 - GET THE CLINIC THAT IS IN THE ER VISIT FILE
 S AMERCLN=$P(^AMERVSIT(AMERDA,0),U,4)  ;this is a pointer to the ER OPTION FILE
 ;S AMERCLN=$P($G(^AMER(3,AMERCLN,0)),U,4)  ; this is a clinic stop code
 S:AMERCLN>0 AMERCLN=$P($G(^AMER(3,AMERCLN,0)),U,4)  ; IHS/OIT/SCR 10/05/09 patch 2
 S AMERCODE=$S($G(AMERCLN)>0:$G(AMERCLN),1:80)
 ;IHS/OIT/SCR 072309 if this code is not what is in V POV, update V POV to match
 K APCLV
 S AMERVERR=$$PCCVF^APCLV(AMERPCC,"POV","5;7;11;12;14;17")   ;bring back current V POV info
 ; The V POV PRIMARY/SECODARY explainations in SAC Developers handbook state that the field is
 ; Required for Hospitalizations.
 ; For other visits, the first POV entered for a visit is considered the
 ; primary one.
 ; With this kind of business rule, we need to delete all V POV's and recreate
 ; them when the "primary DX" in ERS is changed, and be sure the first one adeded is always the primary
 S AMERPOV=0
 I $O(APCLV(0))="" S AMERSLNT=1   ;IF THERE ARE NO PCC DX, JUST ADD ANY ERS WITHOUT ASKING
 F  S AMERPOV=$O(AMEREPOV(AMERPOV)) Q:AMERPOV=""  D
 .S AMERDX=$P(AMEREPOV(AMERPOV),"^",1)
 .S AMERICD9=$P($$ICDDX^ICDCODE(AMERDX,,,1),U,2)
 .S AMERINDX=$P(AMEREPOV(AMERPOV),"^",2)  ;DX INDEX IN ER VISIT FILE
 .S AMERNAR=AMERENAR(AMERPOV)
 .;I $O(APCLV(0))="" S AMERSLNT=1   ;IF THERE ARE NO PCC DX, JUST ADD ANY ERS WITHOUT ASKING
 .S AMERFND=0,AMERVPOV=0  ; Flag set to 1 if DX CODE is later found in V POV file which should be looked at from the begining for each ER DX
 .Q:AMEREPOV(AMERPOV)=""  ; If there is no valid DX CODE, quit
 .F  S AMERVPOV=$O(APCLV(AMERVPOV)) Q:((AMERVPOV="")!AMERFND=1)  D
 ..;IHS/OIT/SCR 02/05/09 START LOCAL CODE CHANFES
 ..S AMERVICD=$P(APCLV(AMERVPOV),U,7)
 ..S AMERVDXI=$P($$ICDDX^ICDCODE(AMERVICD,,,1),U,1)
 ..I AMERVDXI<1 D
 ...S AMERVDXI=$P($$ICDDX^ICDCODE(".9999",,,1),U,1)   ;start by setting it to 'uncoded'
 ...I AMERVICD="VA LOCAL CODE SELECTED" D
 ....;LOOK IT UP THROUGH FILEMAN
 ....S DIC="^AUPNVPOV(",DIC(0)="NX",X="`"_$P(APCLV(AMERVPOV),"^",5)
 ....D ^DIC
 ....I (Y'=-1) D
 .....S AMERVDXI=$P(Y,"^",2)   ;brings back the ICD ien
 .....Q
 ....Q  ;IF THIS WAS A LOCAL CODE
 ...S AMERVICD=$P($$ICDDX^ICDCODE(AMERVDXI,,,1),U,2)  ;brings back the code
 ...Q
 ..;IHS/OIT/SCR 02/05/09 END LOCAL CODE CHANGES
 ..I (AMERVICD=AMERICD9) D
 ...S AMERFND=1
 ...;IHS/OIT/SCR 072309 - update CLINIC STOP to match what is in ERS
 ...D UPDTCLNC($P(APCLV(AMERVPOV),U,5),AMERCLN)
 ...K APCLV(AMERVPOV)   ;REMOVE THIS ENTRY SINCE WE JUST MATCHED IT UP WITH AN ERS ENTRY
 ...Q
 ..Q  ;FOR EACH V POV ENTRY
 .I AMERFND=0  D   ; Add this ER DIAGNOSIS TO THE PCC VISIT since it isn't there
 ..I AMERSLNT S AMERANS=1  ;ADD ALL ERS ENTRIES TO V POV WITHOUT ASKING if there are no DX in PCC yet
 ..E  D
 ...D EN^DDIOL("**AN ERS DX CODE WAS NOT FOUND IN A V POV ENTRY FOR THIS PCC VISIT**","","!!?3")
 ...;D EN^DDIOL("**A V POV ENTRY WAS FOUND THAT IS NOT CURRENTLY IN ERS FOR THIS VISIT**","","!!?3")
 ...D EN^DDIOL("ERS DX CODE: "_AMERICD9_" - "_AMERNAR,"","!?3")
 ...S DIR(0)="SO^1:ADD A NEW V POV ENTRY TO THIS PCC VISIT;2:REMOVE THE ERS DX CODE FROM THE ERS VISIT"
 ...S DIR("A")="Which would you like to do"
 ...D ^DIR K DIR
 ...I (Y="^"!Y="") S AMERANS=2  ;IF YOU CHOOSE NOT TO DECIDE,MAKE ERS MATCH PCC BY REMOVING THIS CODE
 ...E  S AMERANS=+Y
 ...Q
 ..I (AMERANS=1) D
 ...;ADD A V POV TO THIS PCC VISIT
 ...I $P($G(^AMER(2.5,DUZ(2),0)),U,5)="N" S:AMERICD9'=".9999" AMERVIEN=$$ADDPOV(AMERPCC,AMERICD9,AMERNAR,AMERPAT,AMERTIME,AMERDOC,AMERCODE) Q
 ...I $P($G(^AMER(2.5,DUZ(2),0)),U,5)'="N" S AMERVIEN=$$ADDPOV(AMERPCC,AMERICD9,AMERNAR,AMERPAT,AMERTIME,AMERDOC,AMERCODE)
 ...I +AMERVIEN<1 D  Q   ; WRITE INFO TO SCREEN AND QUIT
 ....D EN^DDIOL("UNABLE TO ADD PCC V POV "_AMERICD9,"","!!")
 ....D EN^DDIOL("ERROR RETURNED : "_$P(AMERVIEN,U,2))
 ....D:$P(AMERVIEN,U,2)="FAILED FM EDITS" EN^DDIOL("CONSIDER FINDING A MORE DETAILED CODE","","!!")
 ....Q  ;IF ADD VPOV WAS NOT SUCCESSFUL
 ...D EN^DDIOL("","","!")
 ...D EN^DDIOL("** V POV ADDED TO PCC VISIT **","","!?3")
 ...Q  ;I (AMERANS=1)
 ..I (AMERANS=2) D
 ...;REMOVE THE DX FROM THE ERS VISIT
 ...D NOW^%DTC
 ...;S:$G(AMERAIEN)="" AMERAIEN=$$CREATAUD^AMEREDAU(AMERDA,AMERDUZ) Q:AMERAIEN<0  ;CREATE AN AUDIT FILE RECORD
 ...;S AMEREDNM=AMEREDNM+1
 ...;S AMERSTRG="5-01"_"."_AMEREDNM_";"_X_";"_$$EDDISPL^AMEREDAU(AMERDX,"X")_";;Other;DIAGNOSIS;Silent PCC SYNCH"
 ...;S AMEREDTS=$S(AMEREDTS="":AMERSTRG,1:AMEREDTS_"^"_AMERSTRG)
 ...;S AMERSTRG="5-01"_"."_AMEREDNM_";"_X_";"_AMERONAR_";;Other;PROVIDER NARRATIVE;Silent PCC SYNCH"
 ...;S AMEREDTS=$S(AMEREDTS="":AMERSTRG,1:AMEREDTS_"^"_AMERSTRG)
 ...;D:AMEREDTS'="" MULTAUDT^AMEREDAU(AMEREDTS,AMERAIEN)
 ...S DA(1)=AMERDA,DA=AMERINDX
 ...S DIK="^AMERVSIT(DA(1),5,"
 ...D ^DIK,EN^DIK  ; Delete identified entry and re-index diagnosis field
 ...D EN^DDIOL("** DIAGNOSIS REMOVED FROM ERS VISIT **","","!?3")
 ...Q  ;IF AMERANS=2 DELETE THE V POV ENTRY TO MATCH WHAT IS IN ERS
 ..Q  ;IF ERS ENTRY WAS NOT FOUND IN V POV ARRAY
 .Q  ;FOR EACH ERS ENTRY
 ;IHS/OIT/SCR ...ANY V POV ENTRIES THAT ARE LEFT NEED TO BE REMOVED FROM PCC OR ADDED TO ERS
 ;IF 'SILENT' ONLY ADD TO ERS
 F  S AMERVPOV=$O(APCLV(AMERVPOV)) Q:AMERVPOV=""  D
 .; APCLV(x)=^^^^internal value of V POV^^ ICD9 code^^^^Cause of injury^place of injury^provider narrative^date of injury
 .S AMERVIEN=$P(APCLV(AMERVPOV),"^",1)
 .S AMERVICD=$P(APCLV(AMERVPOV),"^",7)
 .S AMERVNAR=$P(APCLV(AMERVPOV),"^",14)
 .S AMERVDXI=$P($$ICDDX^ICDCODE(AMERVICD,,,1),U,1)
 .I AMERVDXI<1 D
 ..S AMERVDXI=$P($$ICDDX^ICDCODE(".9999",,,1),U,1)   ;start by setting it to 'uncoded'
 ..I AMERVICD="VA LOCAL CODE SELECTED" D
 ...;LOOK IT UP THROUGH FILEMAN
 ...S DIC="^AUPNVPOV(",DIC(0)="NX",X="`"_$P(APCLV(AMERVPOV),"^",5)
 ...D ^DIC
 ...I Y'=-1 S AMERVDXI=$P(Y,"^",2)   ;brings back the ICD ien
 ...Q
 ..S AMERVICD=$P($$ICDDX^ICDCODE(AMERVDXI,,,1),U,2)  ;brings back the code
 ..Q
 .I AMERSLNT S AMERANS=2
 .E  D
 ..D EN^DDIOL("**A V POV ENTRY WAS FOUND THAT IS NOT CURRENTLY IN ERS FOR THIS VISIT**","","!!?3")
 ..D EN^DDIOL("V POV ENTRY: "_AMERVICD_" - "_AMERVNAR,"","!?3")
 ..;S DIR(0)="SO^1:ADD THIS DX INFORMATION TO THE ERS VISIT;2:REMOVE THE V POV ENTRY FROM THE PCC VISIT"
 ..S DIR(0)="SO^1:REMOVE THE V POV ENTRY FROM THE PCC VISIT;2:ADD THIS DX INFORMATION TO THE ERS VISIT"
 ..;S DIR("A")="Which would you like to do"
 ..D ^DIR K DIR
 ..I (Y="^"!Y="") S AMERANS=2  ;IF YOU CHOOSE NOT TO DECIDE,MAKE ERS MATCH PCC BY ADDING THIS CODE TO ERS
 ..E  S AMERANS=+Y
 ..Q
 .I AMERANS=2 D
 ..;ADD NEW DX TO ERS VISIT
 ..;S:$G(AMERAIEN)="" AMERAIEN=$$CREATAUD^AMEREDAU(AMERDA,AMERDUZ) Q:AMERAIEN<0
 ..S DA(1)=AMERDA,DIC="^AMERVSIT(DA(1),5,",DIC(0)="L" ; DIAGNOSES
 ..S X="`"_AMERVDXI
 ..D ^DIC
 ..I +Y>0 D
 ...;S AMEREDNM=AMEREDNM+1
 ...;S AMERSTRG="5-01"_"."_AMEREDNM_";"_X_";"_$$EDDISPL^AMEREDAU(AMERNDXI,"X")_";;Other;DIAGNOSIS; PCC SYNCH"
 ...;S AMEREDTS=$S(AMEREDTS="":AMERSTRG,1:AMEREDTS_"^"_AMERSTRG)
 ...;S AMERSTRG="5-01"_"."_AMEREDNM_";"_X_";"_AMERVNAR_";;Other;PROVIDER NARRATIVE; PCC SYNCH"
 ...;S AMEREDTS=$S(AMEREDTS="":AMERSTRG,1:AMEREDTS_"^"_AMERSTRG)
 ...;D:AMEREDTS'="" MULTAUDT^AMEREDAU(AMEREDTS,AMERAIEN)
 ...D EN^DDIOL("** DIAGNOSIS ADDED TO ERS VISIT **","","!?3")
 ...Q
 ..Q
 .I AMERANS=1 D
 ..I $$REMOVPOV^AMERVSIT(AMERVIEN)  D EN^DDIOL("** V POV REMOVED FROM PCC VISIT **","","!?3")
 ..E  D EN^DDIOL("** COULD NOT REMOVE V POV FROM PCC VISIT! **","","!?3")
 ..Q
 .Q
 K APCLV
 Q
ADDPOV(AMERPCC,AMERICD9,AMERNAR,AMERDFN,AMERTIME,AMERDOC,AMERCLN)  ; ADD AN ENTRY TO V POV
 ; AMERPCC - VISIT IEN
 ; AMERICD9 - ICD9 CODE
 ; AMERNAR -  PROVIDER NARRATIVE
 ; AMERDFN  - PATIENT IEN
 ; AMERTIME - VA FILE MAN FORMAT OF VISIT TIME
 ; AMERDOC - POIINTER TO NEW PERSON PROVIDER
 ; AMERCLN - IS NOT A POINTER TO ^DIC(40.2 - "CLINIC STOP" FILE - NO
 ;           if I send through a pointer "72" - ^DIC(40.7,72,0)=URGENT CARE^80
 ;           I see the clinic stop "MAMMOGRAPHY" ^DIC(40.7,67,0)=MAMMOGRAPHY^72
 ;           SO   
 ; AMERCLN - CLINC CODE:30 - EMERGENCY MEDICINE or 80 - URGENT CARE
 K APCDALVR,APCDAFLE,APCDTPAT,APCDTPOV,APCDTNQ,APCDTPRO
 I 'AMERPCC>0 Q 0  ; INVALID VISIT IEN
 I 'AMERDFN>0 Q 0 ; INVALID PATIENT IEN
 S APCDAFLE("APCDAFLE")="9000010.07"  ; THIS IS DOCUMENTED IN SAC Developer Handbook
 S APCDALVR("APCDTPOV")=AMERICD9  ; ICD9 CODE -  pre-screened during "finalization"
 S APCDALVR("APCDPAT")=AMERDFN  ; PATIENT IEN
 S APCDALVR("APCDVSIT")=AMERPCC  ; VISIT IEN
 S APCDALVR("APCDTNQ")=AMERNAR  ; NARRATIVE
 S APCDALVR("APCDTCDT")=AMERTIME ; EVENT DATE AND TIME - date diagnosis
 S APCDALVR("APCDTCLN")=AMERCLN   ; CLINIC - pointer to clinic stop file
 S APCDALVR("APCDTEPR")="`"_AMERDOC   ; PROVIDER who made DIAGNOSIS - but in DD definition this is the encounter provider who treated the Dx...
 S APCDALVR("APCDATMP")="[APCDALVR 9000010.07 (ADD)]"
 D EN^APCDALVR
 S AMERVIEN=$G(APCDALVR("APCDADFN"))
 I AMERVIEN="" D
  .S AMERVIEN=-1_"^"_$S($G(APCDALVR("APCDAFLG"))=1:"NO VISIT SELECTED",$G(APCDALVR("APCDAFLG"))=2:"FAILED FM EDITS",1:"UNSPECIFIFED ERROR")
  D:+AMERVIEN>0 MOD^AUPNVSIT
  K APCDALVR,APCDAFLE,APCDTPOV,APCDTPAT,APCDVSIT,APCDTNQ,APCDTCDT,APCDTCLN,APCDTEPR,APCDATMP
 Q AMERVIEN
UPDTCLNC(AMERVPOV,AMERCLN) ;update the CLINIC STOP field in V POV to match the value in ERS
 ;IHS/OIT/SCR 090309 patch 2
 N DIE,DA,DR
 S DIE="^AUPNVPOV("
 S DA=AMERVPOV
 S DR="1203///"_AMERCLN
 D ^DIE
 Q