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

AMERPCC2.m

Go to the documentation of this file.
AMERPCC2 ; IHS/OIT/SCR - SUPPORTING ROUTINES FOR V POV SYNCHING ;
 ;;3.0;ER VISIT SYSTEM;**1,3,6**;MAR 03, 2009;Build 30
 ;
SYNCHPOV(AMERDA,AMERPCC,AMERPAT,AMERTIME,AMERDOC,AMERCLN)  ; EP from SYNCHPCC^AMERPCC
 ;AMER*3.0*6;AMER no longer storing DX information directly to AMER
 ;          ;Information now gets updated using SYNC^AMERPOV
 Q
 ; Q  ; DX SYNCHRONIZATION VALIDATION BETWEEN ER VISIT FILE AND V POV NOW MANAGED ELSEWHERE
 ; This routine LOOKS AT EACH V POV entry and tries to find it in ERS for comparison
 ;  IF differences exist will prompt user to identify which data to save 
 ;  When each V POV entry has been looked at, each ERS entry is examined in VPOVUPDT
 ;  IF DX codes exist in the ERS entry that aren't in V POV user is prompted to identify which data to save
 ; INPUT:
 ;  AMERDA - IEN OF ER VISIT FILE
 ;  AMERPCC - IEN OF VISIT FILE
 ;  AMERPAT -IEN OF PATIENT FILE
 ;  AMERTIME - DATE TIME OF VISIT
 ;  AMERDOC - PROVIDER IEN
 ;  AMERCLN - NAME OF CLINIC STOP (EMERGENCY OR URGENT CARE)
 N AMERVERR,AMEREPOV,AMERENAR,AMERVNAR,AMERVPOV,AMER9999,AMERPDX,AMERDX,AMERPNAR,AMERICD9,AMERPOV,AMERNXT,AMERANS,AMERDONE,AMERFND
 ;N AMERSLNT,AMER9999,AMERV999,AMERE999,AMERVICD,AMERNDXI
 N AMER9999,AMERV999,AMERE999,AMERVICD,AMERNDXI
 ; This routine updates V POV entires with DX information in ER VISIT file
 ; First get any CODES that are in V POV
 ;S AMERDONE=0,AMERSLNT=0
 S AMERDONE=0
 S AMERV999=0 ;COUNTS HOW MANY 999 CODES ARE IN V POV ENTRIES
 S AMERE999=0 ; COUNTS HOW MANY 9999 CODES WERE MATCHED IN ERS
 S AMER9999=$P($$ICDDX^ICDCODE(".9999",,,1),U,1) ;POINTER TO .9999 CODE IN ICD9 CODE - THIS CODE CAN BE ENTERED MORE THAN ONCE
 S AMERPDX=$P($G(^AMERVSIT(AMERDA,5.1)),U,2)  ; PRIMARY DX POINTER
 S AMERPNAR=$P($G(^AMERVSIT(AMERDA,5.1)),U,3) ; PRIMARY NARRATIVE
 K APCLV
 S AMERVERR=$$PCCVF^APCLV(AMERPCC,"POV","5;7;11;12;14;17")
 ; This will return:
 ; APCLV(x)=^^^^internal value of V POV^^ ICD9 code^^^^Cause of injury^place of injury^provider narrative^date of injury
 ; for each V POV x in the file for this visit
 S AMERVPOV=0,AMERVIEN=""
 F  S AMERVPOV=$O(APCLV(AMERVPOV)) Q:AMERVPOV=""  D
 .S AMERVIEN=$P(APCLV(AMERVPOV),U,5)
 .S AMERVICD=$P(APCLV(AMERVPOV),U,7)
 .;IHS/OIT/SCR 2/4/09 try to deal with VA LOCAL CODE PROBLEM start changes
 .;I AMER9999=$P($$ICDDX^ICDCODE(AMERVICD,,,1),U,1) S AMERV999=AMERV999+1 ;THIS IS THE NUMBER OF .9999 CODES SO FAR
 .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
 ...S AMERVICD=$P($$ICDDX^ICDCODE(AMERVDXI,,,1),U,2)  ;brings back the code
 ..Q
 ..;I AMER9999=AMERVDXI S AMERV999=AMERV999+1 ;THIS IS THE NUMBER OF PCC .9999 CODES SO FAR
 .;IHS/OIT/SCR 2/4/09 try to deal with VA LOCAL CODE PROBLEM end changes
 .I AMERVPOV=1 D   ; IF THIS IS THE FIRST V POV RETURNED
 ..;I $P($$ICDDX^ICDCODE(+AMERPDX,,,1),U,2)'=$P(APCLV(AMERVPOV),U,7) D
 ..I $P($$ICDDX^ICDCODE(+AMERPDX,,,1),U,2)'=AMERVICD D
 ...;IHS/OIT/SCR 12/19 - if the values are different, user needs to choose
 ...D EN^DDIOL("**The PRIMARY DX in the PCC VISIT file is different from ERS PRIMARY DX**","","!!?3")
 ...D EN^DDIOL("PCC VISIT VALUE: "_AMERVICD_" - "_$P(APCLV(AMERVPOV),U,14),"","!?3")
 ...D EN^DDIOL("ERS ENTERED VALUE: "_$P($$ICDDX^ICDCODE(+AMERPDX,,,1),U,2)_" - "_AMERPNAR,"","!?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
 ...S AMERANS=+Y
 ...I Y=""!(Y="^")!(AMERANS=2) D  ;if user selects to or up-hats out, keep PCC info
 ....D SYNCHERX^AMERERS(AMERDA,AMERPCC)   ;REPLACE ANY ER VISIT DX INFO WITH INFO THAT IS IN PCC AND STOP
 ....S AMERDONE=1
 ....Q
 ...I AMERANS=1 D
 ....; UPDATE THE PCC VISIT WITH THE PRIMARY DX THE USER JUST ENTERED - START BY DELETING WHAT IS THERE
 ....I $$DELETPOV^AMERVSIT(AMERPCC)=0 D EN^DDIOL("THERE WAS A PROBLEM DELETING V POV ENTRIES","","!!")
 ....K APCLV   ; ALL V POVS WERE DELETED, SO GET RID OF THIS ARRAY, AND BUILD IT AGAIN
 ....S AMERVPOV=0  ; RESET LOOP VARIABLE to get out of loop
 ....S AMERVERR=$$PCCVF^APCLV(AMERPCC,"POV","5;7;11;12;14;17")
 ....;S AMERSLNT=1
 ....Q
 ...Q
 ..Q:((AMERVPOV<1)!AMERDONE)
 ..S AMERVNAR=$P(APCLV(AMERVPOV),U,14)  ;IHS/OIT/SCR patch 1
 ..S AMERVNAR=$$STRIPNAR(AMERVNAR) ;IHS/OIT/SCR - remove ";" from narrative
 ..;I (AMERPNAR'=$P(APCLV(AMERVPOV),U,14)) D  
 ..I (AMERPNAR'=AMERVNAR) D  ;IHS/OIT/SCR patch 1
 ...D EN^DDIOL("**The value for PRIMARY NARRATIVE in the PCC visit file is different from ERS NARRATIVE**","","!!?3")
 ...;D EN^DDIOL("PCC VISIT VALUE: "_AMERVICD_" - "_$P(APCLV(AMERVPOV),U,14),"","!?3")
 ...D EN^DDIOL("PCC VISIT VALUE: "_AMERVICD_" - "_AMERVNAR,"","!?3")
 ...D EN^DDIOL("ERS ENTERED VALUE: "_$P($$ICDDX^ICDCODE(+AMERPDX,,,1),U,2)_" - "_AMERPNAR,"","!?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
 ...S AMERANS=+Y
 ...;I Y=""!(Y="^")!(AMERANS=2) D
 ...I (AMERANS=0)!(AMERANS=2) D  Q  ;IHS/OIT/GIS 8/23/11 patch 3
 ....;UPDATE ERS PRIMARY NARRATIVE WITH THE NARRATIVE FOR THIS PCC DX
 ....;IHS/OIT/SCR 05/14/09 ...But this means updating in PRIMARY and in DX MULTIPLE...
 ....;S DR=$S(DR'="":DR_";",1:""),DR=DR_"5.3////"_AMERVNAR
 ....;S DIE="^AMERVSIT(DA(1),5,",DA(1)=AMERDA,DA=AMERINDX,DR=""
 ....;S DR="1////"_$P(APCLV(AMERVPOV),U,14)
 ....;S DR="1////"_AMERVNAR ;IHS/OIT/SCR 05/05/09
 ....;D MULTDIE^AMEREDIT(DIE,DA,DA(1),DR)
 ....S DR="5.3////"_AMERVNAR
 ....D DIE^AMEREDIT(AMERDA,DR)
 ....;K DIE
 ....;now you have to find the old narrative in the multiple DX file; check code and replace
 ....S AMERINDX=0
 ....S AMERINDX=0,AMERFND=0
 ....I AMER9999=AMERVDXI S AMERV999=AMERV999+1 ;THIS IS THE NUMBER OF PCC .9999 CODES THAT AREN'T PRIMARY SO FAR
 ....F  S AMERINDX=$O(^AMERVSIT(AMERDA,5,AMERINDX)) Q:AMERINDX="B"!AMERFND  D
 .....I AMERINDX="" S AMERINDX="B"  ;if we have no DX info for some reason, get out of loop
 .....I (AMERPNAR=$G(^AMERVSIT(AMERDA,5,AMERINDX,1)))&(AMERPDX=$G(^AMERVSIT(AMERDA,5,AMERINDX,0))) D  Q
 ......S DIE="^AMERVSIT(DA(1),5,",DA(1)=AMERDA,DA=AMERINDX,DR=""
 ......D MULTDIE^AMEREDIT(DIE,DA,DA(1),DR)
 ......S AMERFND=1
 ......Q
 .....Q
 ....Q
 ....I AMERFND=0 D   ;This primary DX was not found in the ERS record...synch with PCC now
 .....D EN^DDIOL("Corrupted ERS DX record found","","!!")
 .....D EN^DDIOL("Replacing with PCC V POV entries","","!!")
 .....D SYNCHERX^AMERERS(AMERDA,AMERPCC)   ;REPLACE ANY ER VISIT DX INFO WITH INFO THAT IS IN PCC AND STOP
 .....S AMERDONE=1
 .....Q
 ....Q
 ...I AMERANS=1 D UPDTNAR^AMERVSIT(AMERVIEN,AMERPNAR) ;IHS/OIT/GIS 8/23/11 patch 3
 ...Q  ;IF AMERENAR'=$P(APCLV(AMERVPOV),U,14)
 ..Q
 .I AMERVPOV>1 D
 ..;THIS IS  NOT THE PRIMARY DX IN PCC, LOOK FOR IT IN THE ER VISIT FILE DIAGNOSIS SUB-ENTRIES
 ..;IF IT IS THERE COMPARE THE TWO NARRATIVES AND GIVE USER A CHANCE TO UPDATE WITH CHOOSEN  VERSION
 ..;IF IT IS NOT THERE ASK THE USER IF THEY WANT TO ADD THE CODE TO ERS, OR REMOVE IT FROM PCC
 ..S AMERINDX=0,AMERFND=0,AMERNXT=0,AMERE999=0
 ..I AMER9999=AMERVDXI S AMERV999=AMERV999+1 ;THIS IS THE NUMBER OF PCC .9999 CODES THAT AREN'T PRIMARY SO FAR
 ..F  S AMERINDX=$O(^AMERVSIT(AMERDA,5,AMERINDX)) Q:AMERINDX="B"!AMERFND  D
 ...S AMERDX=^AMERVSIT(AMERDA,5,AMERINDX,0)
 ...;S AMERNAR=$G(^AMERVSIT(AMERDA,5,AMERINDX,1))
 ...S AMERENAR=$G(^AMERVSIT(AMERDA,5,AMERINDX,1))
 ...;Q:(AMERDX=AMERPDX)&(AMERNAR=AMERPNAR)  ;IHS/OIT/SCR 01/13/08 - if this is the primary DX, don't mess with it
 ...Q:(AMERDX=AMERPDX)&(AMERENAR=AMERPNAR)  ;IHS/OIT/SCR 01/13/08 - if this is the primary DX, don't mess with it
 ...I AMERDX=AMER9999 S AMERE999=AMERE999+1
 ...Q:(AMERDX=AMER9999)&(AMERE999<AMERV999)  ;if this is a .9999 code and we've already considered it, move on
 ...I $P($$ICDDX^ICDCODE(+AMERDX,,,1),U,2)=AMERVICD D
 ....S AMERFND=1
 ....;I AMERNAR'=$P(APCLV(AMERVPOV),U,14) D
 ....I AMERENAR'=$P(APCLV(AMERVPOV),U,14) D
 .....S AMERVNAR=$$STRIPNAR(AMERVNAR) ;IHS/OIT/SCR 5/5/09 patch 1
 .....D EN^DDIOL("**The value for NARRATIVE in the PCC visit file is different from ERS NARRATIVE**","","!!?3")
 .....D EN^DDIOL("PCC VISIT VALUE: "_AMERVICD_" - "_$P(APCLV(AMERVPOV),U,14),"","!?3")
 .....;D EN^DDIOL("PCC VISIT VALUE: "_AMERVICD_" - "_AMERVNAR,"","!?3") ;IHS/OIT/SCR 5/5/09 patch 1
 .....;D EN^DDIOL("ERS ENTERED VALUE: "_$P($$ICDDX^ICDCODE(+AMERDX,,,1),U,2)_" - "_AMERNAR,"","!?3")
 .....D EN^DDIOL("ERS ENTERED VALUE: "_$P($$ICDDX^ICDCODE(+AMERDX,,,1),U,2)_" - "_AMERENAR,"","!?3") ;IHS/OIT/SCR 5/5/09 patch 1
 .....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 ;IHS/OIT/SCR 5/5/09 patch 1
 .....I (AMERANS=0)!(AMERANS=2) D  ;IHS/OIT/GIS 8/23/11 patch 3
 ......;UPDATE ERS NARRATIVE WITH THE NARRATIVE FOR THIS PCC DX
 ......S DIE="^AMERVSIT(DA(1),5,",DA(1)=AMERDA,DA=AMERINDX,DR=""
 ......;IHS/OIT/SCR 5/5/09 first strip ";"
 ......;S DR="1////"_$P(APCLV(AMERVPOV),U,14)
 ......S DR="1////"_AMERVNAR ;IHS/OIT/SCR 05/05/09
 ......D MULTDIE^AMEREDIT(DIE,DA,DA(1),DR)
 ......K DIE
 ......Q
 .....I Y=1 D UPDTNAR^AMERVSIT(AMERVIEN,AMERENAR)
 .....Q
 ....Q  ;IF AMERENAR'=$P(APCLV(AMERVPOV),U,14)
 ...Q
 ..I 'AMERFND D
 ...D EN^DDIOL("**There is no ERS DIAGNOSIS CODE CORRESPONDING TO V POV ENTRY**","","!!?3")
 ...D EN^DDIOL("PCC VISIT VALUE: "_AMERVICD_" - "_$P(APCLV(AMERVPOV),U,14),"","!?3")
 ...S DIR(0)="SO^1:Correct ERS data by adding this diagnosis;2:Correct PCC data by removing this V POV entry"
 ...S DIR("A")="Which would you like to do"
 ...D ^DIR K DIR
 ...S AMERANS=+Y
 ...;I Y=""!(Y="^")!(AMERANS=1) D
 ...I (AMERANS=0)!(AMERANS=1) D
 ....;ADD THIS V POV DX TO ERS VISIT
 ....;S AMERNDXI=$P($$ICDDX^ICDCODE(AMERVICD,,,1),U,1)
 ....S AMERVNAR=$P(APCLV(AMERVPOV),U,14)
 ....S AMERVNAR=$$STRIPNAR(AMERVNAR) ;IHS/OIT/SCR 05/05/09 - remove ";" from narrative
 ....;CAN'T USE DIE TO ADD A SUBENTRY...WE WANT TO USE DIC
 ....;S DIE="^AMERVSIT(DA(1),5,",DA(1)=AMERDA,DA=AMERNXT,DR=""
 ....;S DR=".01////"_AMERVDXI
 ....;S DR=DR_";1////"_AMERNNAR
 ....;D MULTDIE^AMEREDIT(DIE,DA,DA(1),DR)
 ....;K DIE
 ....S DA(1)=AMERDA,DIC="^AMERVSIT("_DA(1)_",5,",DIC(0)="" ; DIAGNOSES
 ....S X=AMERVDXI
 ....D FILE^DICN
 ....Q:+Y<0
 ....S DIE=DIC,DA(1)=AMERDA,DA=+Y,DR="1////"_AMERVNAR
 ....D ^DIE
 ....K DIC,DIE,DA,Y,DR
 ....Q
 ...I AMERANS=2 D
 ....;REMOVE THE V POV ENTRY
 ....L +^AUPNVPOV:3 E  Q
 ....S DA=AMERVIEN,DIK="^AUPNVPOV(" D ^DIK,EN^DIK
 ....L -^AUPNVPOV
 ....Q
 ....;K APCLV(AMERVPOV)  ;
 ..Q
 .Q
 Q:AMERPDX=""  ; Don't try to update AUPNVPOV if no primary DX has been identified in ERS
 Q:AMERDONE    ;If the routine has just updated ERS to match PCC its done
 D VPOVUPDT^AMERPCC3(AMERPAT,AMERPCC,AMERTIME,AMERDOC)
 Q
STRIPNAR(AMERSTG)  ;IHS/OIT/SCR 050709
 S AMERSTG=$TR(AMERSTG,";","~")
 Q AMERSTG