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

IVMPLOG.m

Go to the documentation of this file.
  1. IVMPLOG ;ALB/CJM,RTK - API for IVM PATIENT file; ; 12/6/00 5:28pm [ 07/13/2001 6:33 AM ]
  1. ;;2.0;INCOME VERIFICATION MATCH;**9,19,12,21,17,28,36**; 21-OCT-94
  1. ;;Per VHA Directive 10-93-142, this routine should not be modified.
  1. ;IHS/ANMC/LJF 7/13/2001 added quit to EVENT subroutine
  1. ;
  1. ;
  1. FIND(DFN,YEAR) ;
  1. ;Description: Looks up an entry in the IVM PATIENT file (#301.5).
  1. ;Input:
  1. ; DFN - IEN in the PATIENT file.
  1. ; YEAR - value for the INCOME YEAR field, a year in FM format.
  1. ;Output:
  1. ; Function Value - returns IEN of record if found, NULL otherwise.
  1. ;
  1. Q:('$G(DFN)!'$G(YEAR)) ""
  1. ;
  1. N YR
  1. S YR=$E(YEAR,1,3)_"0000"
  1. Q $O(^IVM(301.5,"APT",DFN,YR,0))
  1. ;
  1. LOCK(IEN) ;
  1. ;Description: Locks a record in the IVM PATIENT file.
  1. ;Input:
  1. ; IEN - ien of record in IVM PATIENT file.
  1. ;Output:
  1. ; Function Value - 1 if successful, 0 otherwise.
  1. ;
  1. I $G(IEN) L +^IVM(301.5,IEN):3
  1. Q $T
  1. ;
  1. UNLOCK(IEN) ;
  1. ;Description: Unlocks a record in the IVM PATIENT file.
  1. ;Input:
  1. ; IEN - ien of record in the IVM PATIENT file.
  1. ;Output: None
  1. ;
  1. I $G(IEN) L -^IVM(301.5,IEN)
  1. Q
  1. ;
  1. STATUS(IEN,EVENTS) ;
  1. ;Description: Returns the value of the TRANSMISSION STATUS field of the
  1. ; IVM PATIENT file.
  1. ;
  1. ;Input:
  1. ; IEN - internal entry number of a record in the IVM PATIENT file
  1. ;Output:
  1. ; Function Value -returns the value of the TRANSMISSION STATUS field
  1. ; EVENTS - optional, pass by reference. Will return the types of events logged.
  1. ; EVENTS("IVM") - value of IVM EVENT field
  1. ; EVENTS("DCD") - value of DCD EVENT field
  1. ; EVENTS("ENROLL") - value of ENROLLMENT EVENT field
  1. ;
  1. ;
  1. S EVENTS("IVM")=""
  1. S EVENTS("DCD")=""
  1. S EVENTS("ENROLL")=""
  1. ;
  1. Q:'$G(IEN) ""
  1. ;
  1. N NODE
  1. S NODE=$G(^IVM(301.5,IEN,"E"))
  1. S EVENTS("IVM")=$P(NODE,"^")
  1. S EVENTS("DCD")=$P(NODE,"^",2)
  1. S EVENTS("ENROLL")=$P(NODE,"^",3)
  1. Q $P($G(^IVM(301.5,IEN,0)),"^",3)
  1. ;
  1. SETSTAT(IEN,EVENTS,ERRMSG) ;
  1. ;Description: Sets the value of the TRANSMISSION STATUS field of the
  1. ; IVM PATIENT file for a particular record to 0, meaning transmission
  1. ; is requested. If the case is closed, depending on the event types,
  1. ; the TRANSMISSION STATUS may not be set.
  1. ;Input:
  1. ; IEN - internal entry number of a record in the IVM PATIENT file.
  1. ; EVENTS () - an array of reasons for transmission, pass by reference.
  1. ; EVENTS("IVM") = 1 if transmission due to IVM criteria, 0 otherwise
  1. ; EVENTS("DCD")=1 if transmission due to DCD criteria, 0 otherwise
  1. ; EVENTS("ENROLL")=1 if transmission due to enrollment criteria, 0 otherwise
  1. ;Output:
  1. ; Function Value - 1 on success, 0 on failure.
  1. ; ERRMSG - optional, pass by reference if needed, returns message on failure
  1. ;
  1. N DATA,CLOSED,SUCCESS
  1. ;
  1. I ($G(DGENUPLD)="ENROLLMENT/ELIGIBILITY UPLOAD IN PROGRESS") S ERRMSG="ENROLLMENT UPLOAD IN PROGRESS" Q 0
  1. ;
  1. I '$$LOCK($G(IEN)) S ERRMSG="UNABLE TO OBTAIN LOCK ON IVM PATIENT, TRY AGAIN LATTER" Q 0
  1. S CLOSED=$$CLOSED(IEN)
  1. S SUCCESS=0
  1. I ('CLOSED)!(1=$G(EVENTS("ENROLL"))) D
  1. .S DATA(.03)=0
  1. .I 'CLOSED D
  1. ..I $G(EVENTS("IVM"))=1 S DATA(30.01)=1
  1. ..I $G(EVENTS("DCD"))=1 S DATA(30.02)=1
  1. .I $G(EVENTS("ENROLL"))=1 S DATA(30.03)=1
  1. .S SUCCESS=$$UPD^DGENDBS(301.5,IEN,.DATA,.ERRMSG)
  1. E S SUCCESS=0,ERRMSG="CASE IS CLOSED"
  1. D UNLOCK(IEN)
  1. Q SUCCESS
  1. ;
  1. CLEAR(IEN,WHEN) ;
  1. ; Description: Sets the value of the TRANSMISSION STATUS field of the
  1. ;IVM PATIENT file for a particular record to 1, meaning transmission
  1. ;already occurred.
  1. ;
  1. ;Input:
  1. ; IEN - internal entry number of record in IVM PATIENT file
  1. ; WHEN - optional, date/time in FM format that transmission occurred
  1. ;Output:
  1. ; Function Value - 1 on success, 0 on failure
  1. ;
  1. N SUCCESS,PLOG,DATA
  1. Q:'$$LOCK($G(IEN)) 0
  1. Q:'$$GET(IEN,.PLOG) 0
  1. S DATA(.03)=1
  1. I PLOG("EVENTS","IVM")=1 S DATA(30.01)=2
  1. I PLOG("EVENTS","DCD")=1 S DATA(30.02)=2
  1. I PLOG("EVENTS","ENROLL")=1 S DATA(30.03)=2
  1. I $G(WHEN),((PLOG("FIRST")'>0)!(WHEN<PLOG("FIRST"))) S DATA(.05)=WHEN
  1. S SUCCESS=$$UPD^DGENDBS(301.5,IEN,.DATA)
  1. D UNLOCK(IEN)
  1. Q SUCCESS
  1. ;
  1. GET(IEN,PLOG) ;
  1. ;Description: Used to obtain a record in the IVM PATIENT file. The
  1. ;values are returned in the PLOG() array.
  1. ;Input:
  1. ; IEN - internal entry number of a record in the IVM PATIENT file.
  1. ;Output:
  1. ; Function Value - 1 on success, 0 on failure.
  1. ; PLOG() array, pass by reference. Subscripts are
  1. ; "DFN" - value of the PATIENT field (#.01) which is the ien of record in the PATIENT file.
  1. ; "YEAR" - value of the INCOME YEAR field (#.02)
  1. ; "STATUS" - value from the TRANSMISSIONS STATUS field (#.03)
  1. ; "FIRST" - value from the QUERY TRANSMISSION DATE/TIME field (#.05)
  1. ; "CLOSE" - value from the STOP FLAG field (#.04)
  1. ; "CLOSE","REASON" - value from the CLOSURE REASON field (#301.93)
  1. ; "CLOSE","SOURCE" - value of the CLOSURE SOURCE field (#1.02)
  1. ; "CLOSE","TIME" - value of the CLOSURE DATE/TIME field (#1.03)
  1. ; "EVENTS","IVM" - value of the IVM EVENT field
  1. ; "EVENTS","DCD" - value of the DCD EVENT field
  1. ; "EVENTS","ENROLL" - value of the ENROLLMENT EVENT field
  1. ;
  1. N NODE
  1. Q:'$G(IEN) 0
  1. S NODE=$G(^IVM(301.5,IEN,0))
  1. Q:(NODE="") 0
  1. S PLOG("DFN")=$P(NODE,"^")
  1. S PLOG("YEAR")=$P(NODE,"^",2)
  1. S PLOG("STATUS")=$P(NODE,"^",3)
  1. S PLOG("FIRST")=$P(NODE,"^",5)
  1. S PLOG("CLOSE")=$P(NODE,"^",4)
  1. S NODE=$G(^IVM(301.5,IEN,1))
  1. S PLOG("CLOSE","REASON")=$P(NODE,"^")
  1. S PLOG("CLOSE","SOURCE")=$P(NODE,"^",2)
  1. S PLOG("CLOSE","TIME")=$P(NODE,"^",3)
  1. S NODE=$G(^IVM(301.5,IEN,"E"))
  1. S PLOG("EVENTS","IVM")=$P(NODE,"^")
  1. S PLOG("EVENTS","DCD")=$P(NODE,"^",2)
  1. S PLOG("EVENTS","ENROLL")=$P(NODE,"^",3)
  1. Q 1
  1. ;
  1. CLOSED(IEN) ;
  1. ;Description: Returns the value of the STOP FLAG field of the
  1. ;IVM PATIENT file for a particular record, which indicates whether
  1. ;transmissions for certain events (but not enrollment events) should
  1. ;take place.
  1. ;
  1. ;Input:
  1. ; IEN - internal entry number of a record in the IVM PATIENT file.
  1. ;Output:
  1. ; Function Value - The value of the STOP FLAG field.
  1. ;
  1. Q:'$G(IEN) ""
  1. Q $P($G(^IVM(301.5,IEN,0)),"^",4)
  1. ;
  1. LOG(DFN,YEAR,EVENTS) ;
  1. ;Description: Used to queue a patient for the nightly full transmission
  1. ;for a particular income year. If EVENTS is not passed, an entry in the
  1. ;IVM PATIENT file will be created if it does not already exist, but
  1. ;the flag for transmission will not be set.
  1. ;
  1. ;Input:
  1. ; DFN - ien of record in the PATIENT file.
  1. ; YEAR - income year in FM format. This is the year that is to be
  1. ; used when creating the full transmission message.
  1. ; EVENTS () - an array of reasons for transmission, pass by reference.
  1. ; EVENTS("IVM") = 1 if transmission due to IVM criteria, 0 otherwise
  1. ; EVENTS(" "DCD")=1 if transmission due to DCD criteria, 0 otherwise
  1. ; EVENTS("ENROLL")=1 if transmission due to enrollment criteria, 0 otherwise
  1. ;Output:
  1. ; Function Value - internal entry number of the IVM PATIENT file record, or NULL if record could not be found or created.
  1. ;
  1. N IEN
  1. ;
  1. ;if the eligibility/enrollment upload is in progess, do nothing
  1. Q:($G(DGENUPLD)="ENROLLMENT/ELIGIBILITY UPLOAD IN PROGRESS") ""
  1. ;
  1. ;to be compatable with current software - in some places,
  1. ;YEAR passed is just 3 digits
  1. S:YEAR YEAR=$E(YEAR,1,3)_"0000"
  1. ;
  1. Q:'$$TESTVAL^DGENDBS(301.5,.01,DFN) ""
  1. Q:'$$TESTVAL^DGENDBS(301.5,.02,YEAR) ""
  1. ;
  1. ; check for an existing record in 301.5 for this income year...
  1. S IEN=$$FIND(DFN,YEAR)
  1. I 'IEN D
  1. .;need to create a new record
  1. .N DATA
  1. .L +^IVM(301.5,0):3
  1. .Q:'$T
  1. .S IEN=$$FIND(DFN,YEAR)
  1. .I IEN L -^IVM(301.5,0) Q
  1. .S DATA(.01)=DFN,DATA(.02)=YEAR
  1. .S IEN=$$ADD^DGENDBS(301.5,,.DATA)
  1. .L -^IVM(301.5,0)
  1. I IEN,$D(EVENTS),$$SETSTAT(IEN,.EVENTS)
  1. Q IEN
  1. ;
  1. DELETE(DFN,TESTDATE,MT,RX,HARDSHIP) ;
  1. ;Description: Used to notify HEC that deletion of a MT,RX Copay test, or
  1. ;hardship has occurred
  1. ;
  1. ;Input:
  1. ; DFN - ien of record in the PATIENT file.
  1. ; TESTDATE - date of test
  1. ; MT - if $D(MT),MT then a MT was deleted
  1. ; RX - if $D(RX),RX then a RX copay test was deleted
  1. ; HARDSHIP - if $D(HARDSHIP),HARDSHIP then a hardship was deleted
  1. ;Output: none
  1. ;
  1. N YEAR,IEN,DATA
  1. ;
  1. S YEAR=($E(TESTDATE,1,3)-1)_"0000"
  1. ;
  1. ;
  1. S IEN=$$FIND(DFN,YEAR)
  1. Q:'IEN
  1. I $D(HARDSHIP),HARDSHIP S DATA(.1)=TESTDATE
  1. I $D(MT),MT S DATA(.08)=TESTDATE
  1. I $D(RX),RX S DATA(.09)=TESTDATE
  1. I $$UPD^DGENDBS(301.5,IEN,.DATA)
  1. Q
  1. ;
  1. EVENT(DFN) ;
  1. Q ;IHS/ANMC/LJF 7/13/2001
  1. ;Description: Called in response to enrollment events. Determines
  1. ;whether for this patient transmission is appropriate, and if so the
  1. ;patient is logged for transmission.
  1. ;
  1. ;Input: DFN
  1. ;Output: none
  1. ;
  1. Q:'$G(DFN)
  1. ;
  1. Q:'$$ON^IVMUPAR1 ;quit if enrollment events turned off
  1. ;
  1. ;don't want to log event if called due to file re-indexing
  1. I $D(DIU(0))!($D(DIK)&$D(DIKJ)&$D(DIKLK)&$D(DIKS)&$D(DIN)) Q
  1. ;
  1. ;if the eligibility/enrollment upload is in progess, or there is no enrollment, do nothing
  1. Q:($G(DGENUPLD)="ENROLLMENT/ELIGIBILITY UPLOAD IN PROGRESS")
  1. I ('$$FINDCUR^DGENA(DFN)),('$$VET^DGENPTA(DFN)) Q
  1. N STATUS
  1. S STATUS=$$STATUS^DGENA(DFN)
  1. ; Purple Heart added status 21
  1. I $$VET1^DGENPTA(DFN)!(STATUS=1)!(STATUS=2)!(STATUS=9)!(STATUS=15)!(STATUS=16)!(STATUS=17)!(STATUS=18)!(STATUS=21) D
  1. .N EVENTS
  1. .S EVENTS("ENROLL")=1
  1. .I $$LOG(DFN,$$YEAR(DFN),.EVENTS) ;no need to inform on success or failure
  1. Q
  1. ;
  1. YEAR(DFN) ;
  1. ;Determines the income year to be used in the transmission
  1. ;
  1. N YEAR
  1. S YEAR=$$LD^IVMUFNC4(DFN)
  1. S:YEAR YEAR=($E(YEAR,1,3)-1)_"0000"
  1. S:'YEAR YEAR=($E(DT,1,3)-1)_"0000"
  1. Q YEAR