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

DGCOMPACTELIG.m

Go to the documentation of this file.
DGCOMPACTELIG ;ALB/BPA,CMC - Routine for COMPACT Act Eligibility;04/29/2024@11:30AM
 ;;5.3;Registration;**1104**;Aug 13, 1993;Build 59
 ; *1104* API for COMPACT Act Administrative Eligibility
 ; Reference to FILEMANERR^PXCOMPACT1 in ICR #7469
 ;
 Q
ELIG(DFN,RTN) ;
 ;DFN - Internal Patient ID *(required)
 ;RTN - original calling routine (required)
 N DA,DGXTMPDTTM,ELIG,NOW,VACOM,XTMPSUB
 I $G(RTN)="" S RTN="NO ROUTINE"
 S DGXTMPDTTM="",NOW=$$NOW^XLFDT,ELIG="UNDETERMINED",XTMPSUB="DGCOMPACTELIG"_DT
 ;Determine and return admin eligibility (ELIGIBLE, NOT ELIGIBLE or UNDETERMINED)
 D CAI^VADPT
 I VACOM("CAI")=1 S ELIG="ELIGIBLE" Q ELIG
 D CHECKCACHE(DFN,NOW,XTMPSUB)
 I '$D(^XTMP("DGELIG",XTMPSUB,DFN)) S ELIG=$$WEBSRVC(DFN,$G(RTN))
 E  D
 . S DGXTMPDTTM=$O(^XTMP("DGELIG",XTMPSUB,DFN,DGXTMPDTTM))
 . S ELIG=$$CHECKDFN(DFN,XTMPSUB,$G(RTN),NOW,DGXTMPDTTM)
 Q ELIG
 ;
CHECKCACHE(DFN,NOW,XTMPSUB) ;
 N DGELIGDTTM,PURGDT,XTMPDT
 ; Look for expired cache to clean it up, use $O and removed them
 S XTMPDT=""
 F  S XTMPDT=$O(^XTMP("DGELIG",XTMPDT)) Q:(XTMPDT="")  D
 . S PURGDT=$P(^XTMP("DGELIG",XTMPDT,0),"^",1)
 . I $P(NOW,".")>$P(PURGDT,".") K ^XTMP("DGELIG",XTMPDT)
 I '$D(^XTMP("DGELIG",XTMPSUB)) D 
 . S PURGDT=DT_".1159"
 . S ^XTMP("DGELIG",XTMPSUB,0)=PURGDT_U_DT_U_"COMPACT Act administrative eligibility"
 Q
 ;
CHECKDFN(DFN,XTMPSUB,RTN,NOW,DTTM) ;
 ;If the current time is more than two hours (7200 seconds) past the last stored eligibility, 
 ;kill the stored value and check for changes
 I $$FMDIFF^XLFDT(NOW,DTTM,2)>7200 D
 . K ^XTMP("DGELIG",XTMPSUB,DFN,DTTM)
 . S ELIG=$$WEBSRVC(DFN,RTN)
 E  S ELIG=$P(^XTMP("DGELIG",XTMPSUB,DFN,DTTM),U,1)
 Q ELIG
 ;
WEBSRVC(DFN,DGRTN) ;
 N DGCOMP,DGKEY,DGREQNAME,DGREQDTTM,DGRESP,DGRESPDTTM,ELIG,PURGDT,PURGSEQ,VAEL
 S (DGCOMP,DGKEY,DGREQNAME,DGREQDTTM,DGRESP,DGRESPDTTM,PURGDT,PURGSEQ)="",ELIG="UNDETERMINED"
 S DGKEY=$$GETICN^MPIF001(DFN),DGREQNAME="VistADataVTwo"
 I $P(DGKEY,"^",1)'=-1 D
 . S DGREQDTTM=$$NOW^XLFDT
 . S DGRESP=$$EN^DGREGEEWS(DGKEY,DGREQNAME,"","",.DGCOMP)
 . S DGRESPDTTM=$$NOW^XLFDT
 ;
 I $P(DGRESP,"^",1)=1 D
 . I DGCOMP="No" S ELIG="NOT ELIGIBLE"
 . I DGCOMP="Yes" S ELIG="ELIGIBLE"
 ;
 S ^XTMP("DGELIG",XTMPSUB,DFN,$$NOW^XLFDT)=ELIG_"^"_DFN_"^"_$G(DGRTN)
 ;Processing for Transaction Log here
 I $P(DGKEY,"^",1)'=-1 D
 . S DGRESP=$TR(DGRESP,"^","~")
 . N CMPMSG,DGIEN,TRDATA
 . S DGIEN="+1,"
 . S TRDATA(33.3,DGIEN,.01)=DGKEY
 . S TRDATA(33.3,DGIEN,2)=DGRTN
 . S TRDATA(33.3,DGIEN,3)=DGREQDTTM
 . S TRDATA(33.3,DGIEN,4)=DGRESP
 . S TRDATA(33.3,DGIEN,5)=DGRESPDTTM
 . D UPDATE^DIE("","TRDATA","","CMPMSG")
 . I $D(CMPMSG("DIERR")) D FILEMANERR^PXCOMPACT1(DFN,.TRDATA,.CMPMSG)
 ;
 S PURGDT=$O(^DGCOMP(33.3,"C","")) I $$FMDIFF^XLFDT(DT,PURGDT,1)>29 D
 . F  S PURGSEQ=$O(^DGCOMP(33.3,"C",PURGDT,PURGSEQ)) Q:PURGSEQ=""  D
 . . ;Loop through the "C" level to purge data
 . . S DIK="^DGCOMP(33.3,"
 . . S DA=PURGSEQ
 . . D ^DIK
 . . K DA,DIK
 ;
 Q ELIG