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

AMEREDPC.m

Go to the documentation of this file.
AMEREDPC ; IHS/OIT/SCR - SUB ROUTINE FOR PCC VISIT CREATION; 
 ;;3.0;ER VISIT SYSTEM;**1,6**;MAR 03, 2009;Build 30
 ;
CHKVSIT(AMERDA,AMERAIEN) ; EP FROM AMEREDIT to validate and save PCC information
 ; AMERDA - IEN OF ER VISIT
 ; AMERAIEN - IEN OF AUDIT RECORD - IF "", NOT IN EDIT MODE
 ; CHECK for required elements of a PCC Visit
 ;  1. Primary Provider is in Provider file
 ;  2. Primary DX and Narrative exist as valid codes/strings
 ;  3. Valid patient IEN 
 ;  4. Dates make sense and are not in the future
 ;
 N AMERQUIT,APCDTPRO,APCDTNQ,APCTPAT,AMERTIME,APCDTPOV,AMERNAR,AMERPRIM
 N AMERDX,AMERDATE,AMERTIME,AMERDSCH,AMERDEPT,AMERERR,AMERPAT,AMERPROV
 S AMERQUIT=0,(APCDTPRO,APCDTNQ,APCDTPAT,AMERTIME,APCDTPOV,AMERNAR,AMERDSCH)=""
 ;Primary provider must hold AK.PROVIDER keys
 S AMERPROV=""
 I $G(^AMERVSIT(AMERDA,6))'="" S AMERPROV=$P(^AMERVSIT(AMERDA,6),U,3)
 I AMERPROV'="" D
 .I $D(^VA(200,"AK.PROVIDER",$P($G(^VA(200,AMERPROV,0)),U),AMERPROV)) S APCDTPRO=AMERPROV
 .Q
 I AMERPROV="" S APCDTPRO=""
 ; Valid Primary DX  AND NARRATIVE
 I $P($G(^AMERVSIT(AMERDA,5.1)),U,2)'="" D
 .S AMERDX=$P(^AMERVSIT(AMERDA,5.1),U,2),AMERNAR=$P(^AMERVSIT(AMERDA,5.1),U,3)
 .;IHS/OIT/SCR 11/20/08 TEMP ALLOWING LOCAL CODES
 .;AMER*3*6;Get to work for ICD-10
 .NEW ICDINFO,VDATE
 .S VDATE=$P($$GET1^DIQ(9009080,AMERDA,.01,"I"),".")
 .I $$AICD^AMERUTIL() S ICDINFO=$$ICDDX^ICDEX(+AMERDX,VDATE)
 .E  S ICDINFO=$$ICDDX^ICDCODE(+AMERDX,VDATE)
 .I $P(ICDINFO,U)'=-1,$P(ICDINFO,U,2)'="ZZZ.999",$P(ICDINFO,U,2)'=".9999" S APCDTPOV="`"_AMERDX
 .E  S APCDTPOV=""
 .;valid narrative
 .I AMERNAR'="" S APCDTNQ=AMERNAR
 .Q
 I $P($G(^AMERVSIT(AMERDA,5.1)),U,2)="" S (APCDTNQ,APCDTPOV)=""
 ;valid patient identifier
 I $P($G(^AMERVSIT(AMERDA,0)),U,2)'="" D
 .S AMERPAT=$P(^AMERVSIT(AMERDA,0),U,2)
 .I $D(^DPT(AMERPAT)) S APCDTPAT=AMERPAT
 .Q
 ;valid date of visit (not in future)
 I $G(^AMERVSIT(AMERDA,0))'="" S AMERTIME=$P(^AMERVSIT(AMERDA,0),U,1)
 D NOW^%DTC
 S X1=%,X2=AMERTIME
 D ^%DTC
 I X>=0 S AMERDATE=AMERTIME
 ;valid discharge date (not before admission)
 ;IHS/OIT/SCR 061809 - avoid undefined if no discharge data is present
 ;I $G(^AMERVSIT(AMERDA,6))'="" S AMERDEPT=$P(^AMERVSIT(AMERDA,6),U,2)
 I $G(^AMERVSIT(AMERDA,6))'="" D
 .S AMERDEPT=$P(^AMERVSIT(AMERDA,6),U,2)
 .;if ARRIVE TIME compared to DEPART TIME is before
 .I $$TCOMP^AMERTIME(AMERTIME,AMERDEPT,0) S AMERDSCH=AMERDEPT
 .Q
 I $G(^AMERVSIT(AMERDA,6))="" D
 .D EN^DDIOL("No DISCHARGE information available for this ERS VISIT^","","!!") ;IHS/OIT/SCR 061809
 .S AMERDSCH=0
 .Q
 ;if there is missing information, print each
 S AMERERR=$$PCCERROR(APCDTPRO,APCDTNQ,APCDTPOV,APCDTPAT,AMERDATE,AMERDSCH)
 I AMERERR'="" D
 .S AMERQUIT=1
 .D EN^DDIOL("***INSUFFICIENT DATA AVAILABLE FOR COMPLETE PCC VISIT***","","!!")
 .D EN^DDIOL("","","!")
 .F AMERI=1:1 S AMERWRIT=$P(AMERERR,U,AMERI) Q:AMERWRIT=""  D EN^DDIOL($P(AMERERR,U,AMERI),"","!")
 .D EN^DDIOL("***PLEASE CORRECT THESE PROBLEMS ***","","!!?10")
 .D EN^DDIOL("","","!")
 .Q
 D SYNCHPCC^AMERPCC(AMERDA) ;even if problems, save what you can
 Q:AMERQUIT 0
 K AMERQUIT,APCDTPRO,APCDTNQ,APCTPAT,AMERTIME,APCDTPOV,AMERNAR,AMERPRIM
 K AMERDX,AMERDATE,AMERTIME,AMERDSCH,AMERDEPT,AMERPAT,AMERPROV
 Q 1
PCCERROR(PROVIDER,PRIMNAR,PRIMDIAG,PATIENT,AMERDATE,AMERDSCH)  ;
 S AMERERR=""
 I PROVIDER="" S AMERERR=AMERERR_"Valid discharge provider missing^"
 I PRIMNAR="" S AMERERR=AMERERR_"Primary provider narrative missing^"
 I PRIMDIAG="" S AMERERR=AMERERR_"primary diagnosis is not coded^"
 I PATIENT="" S AMERERR=AMERERR_"Valid patient identifier missing^"
 I AMERDATE="" S AMERERR=AMERERR_"Time of visit cannot be in future^"
 I AMERDSCH="" S AMERERR=AMERERR_"Discharge time must be after admission time^"
 Q AMERERR