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

SDES2GETSTATUS.m

Go to the documentation of this file.
SDES2GETSTATUS ;ALB/LAB,BWF - VISTA CALL TO GET STATUS; JUL 22, 2024
 ;;5.3;Scheduling;**871,886**;Aug 13, 1993;Build 13
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 Q
 ;
 ; This is a rewrite of SDEC50 code - rewritten by BWF and then pulled in by LAB
APPTSTATUS(APPTIEN,CLINIEN) ;Get current status for an entry in the SDEC APPOINTMENT file in the style of STATUS^SDAM1
 ;APPTIEN (R)- IEN of entry in the SDEC APPOINTMENT file (#409.84)
 ;CLINIEN (O)- IEN of entry in the HOSPITAL LOCATION file (#44); non-count will not be checked via clinic if not passed in (can check via OE)
 N STATUS,OUTENCIEN,DFN,APPTDTTM,VAINDT,VADMVT,CHKIO,RET,OESTS,CANCELREASON,CANCELREASONTYP,CANCELSTATUS,STATUSDATE
 N APPTIENS,ORIGSTATUSINT,NOSHOW,CANCELDTTM,CHECKOUTDT,NONCOUNT,CKOUTCOMP,APPTDATA,OESTATUS,CHECKINDT
 S APPTIENS=APPTIEN_","
 D GETS^DIQ(409.84,APPTIENS,".01;.03;.05;.1;.101;.12;.122;.14;.17","IE","APPTDATA","APPTERR")
 S APPTDTTM=$G(APPTDATA(409.84,APPTIENS,.01,"I"))
 S DFN=$G(APPTDATA(409.84,APPTIENS,.05,"I"))
 S OUTENCIEN=$$GET1^DIQ(2.98,APPTDTTM_","_DFN_",",21,"I")
 S CHKIO=""
 ;
 ;set initial status value ; non-count clinic?
 ;
 S ORIGSTATUSINT=$G(APPTDATA(409.84,APPTIENS,.17,"I"))
 S STATUS=$G(APPTDATA(409.84,APPTIENS,.17,"E"))
 ;
 ; initial status date is set to the cancelled date/time
 ;
 S (STATUSDATE,CANCELDTTM)=$G(APPTDATA(409.84,APPTIENS,.12,"I"))
 S NONCOUNT=$$GET1^DIQ(44,CLINIEN,2502,"I")
 I STATUS="",CLINIEN,NONCOUNT="Y" S STATUS="NON-COUNT" ;check for non-count clinic don't crash if resource/clinic not available
 I CLINIEN'="",STATUS="NO ACTION TAKEN",OUTENCIEN'="" S STATUS=""
 ;
 ;no show?
 ;
 S NOSHOW=$G(APPTDATA(409.84,APPTIENS,.1,"I"))
 I NOSHOW=1 D
 . I STATUSDATE]"" D  Q  ;handle cancel after no-show -- appt STATUS doesn't get updated with cxl but pt status does; 745 STATUSDATE
 . .S CANCELREASON=$G(APPTDATA(409.84,APPTIENS,.122,"I"))
 . .; Line below revised to use appointment status (field .17) to calculate status when reason is missing
 . . I CANCELREASON="" S STATUS=$S(ORIGSTATUSINT="C":"CANCELLED BY CLINIC",ORIGSTATUSINT="PC":"CANCELLED BY PATIENT",1:"CANCELLED") Q
 . . S CANCELREASONTYP=$$GET1^DIQ(409.2,CANCELREASON,2,"I")
 . . I CANCELREASONTYP="C" S STATUS="CANCELLED BY CLINIC" Q
 . . I CANCELREASONTYP="P" S STATUS="CANCELLED BY PATIENT" Q
 . . S CANCELSTATUS=$$GET1^DIQ(2.98,APPTDTTM_","_DFN_",",100)
 . . I CANCELSTATUS["CANCELLED" S STATUS=CANCELSTATUS Q
 . . S STATUS="CANCELLED BY CLINIC" ;default to clinic if information is lost
 . S STATUS="NO-SHOW",STATUSDATE=$G(APPTDATA(409.84,APPTIENS,.101,"I"))
 I STATUS=""!(ORIGSTATUSINT="I"),$$INP^SDAM2(DFN,APPTDTTM)="I" D
 . S STATUS=$S(CANCELDTTM="":"INPATIENT",$$GET1^DIQ(2.98,APPTDTTM_","_DFN_",",3,"I")="PC":"CANCELLED BY PATIENT",1:"CANCELLED BY CLINIC")
 N SDNEXTIEN
 S SDNEXTIEN=$O(^SDEC(409.84,"APTDT",DFN,APPTDTTM,APPTIEN))
 I +$G(SDNEXTIEN),(ORIGSTATUSINT="I"),(CANCELDTTM'="") S STATUS="INPATIENT/CANCELLED"
 Q:STATUS="INPATIENT/CANCELLED" STATUS
 S VAINDT=APPTDTTM D ADM^VADPT2 ;ADM^VADPT2 assumes VAINDT and returns in VADMVT
 ;
 ; Reference to DOMICILIARY WARDS IN MAS PARAMETERS IA #483
 ; Reference to SERIVCE in WARD LOCATION - IA #1377
 ; Reference to WARD LOCATION in PATIENT MOVEMENT - IA #358
 ;
 I STATUS["INPATIENT",$S('VADMVT:1,'$$GET1^DIQ(43,1,16,"I"):0,1:$$GET1^DIQ(42,+$$GET1^DIQ(405,VADMVT,.06,"I"),.03,"I")="D") S STATUS=""
 ; -- determine ci/co indicator
 S CHECKINDT=$G(APPTDATA(409.84,APPTIENS,.03,"I"))
 S CHECKOUTDT=$G(APPTDATA(409.84,APPTIENS,.14,"I"))
 S CHKIO=$S(CHECKOUTDT]"":"CHECKED OUT",CHECKINDT]"":"CHECKED IN",APPTDTTM>(DT+.2400):"FUTURE",1:"NO ACTION TAKEN")
 ;
 ; Look for check-in time in the Location file (#44) if check-in/out indicator is NO ACTION TAKEN.
 ;
 I CHKIO="NO ACTION TAKEN",CLINIEN'="" D
 . N SFIEN S SFIEN=$$FIND^SDAM2(DFN,APPTDTTM,CLINIEN) I SFIEN,$$GET1^DIQ(44.003,SFIEN_","_APPTDTTM_","_CLINIEN_",",309)'="" S CHKIO="CHECKED IN" ;
 S:STATUS="" STATUS=CHKIO
 ;If NO ACTION TAKEN, If cancelled in Patient(by SDCANCEL)
 I STATUS'["CANCELLED" D  ;
 . I $$GET1^DIQ(2.98,APPTDTTM_","_DFN_",",.01,"I")'=CLINIEN Q  ;If appointment does not match, leave status alone.
 . S STATUS=$S($$GET1^DIQ(2.98,APPTDTTM_","_DFN_",",3,"I")="PC":"CANCELLED BY PATIENT",$$GET1^DIQ(2.98,APPTDTTM_","_DFN_",",3,"I")="C":"CANCELLED BY CLINIC",1:STATUS)
 ;
 I (STATUS="NO ACTION TAKEN"),($P(APPTDTTM,".")=DT),(CHKIO'["CHECKED") S CHKIO="TODAY"
 ; -- determine print status
 I STATUS["CANCELLED" Q STATUS_"^"_STATUSDATE
 S RET=$S(STATUS=CHKIO!(CHKIO=""):STATUS,1:"")
 S CKOUTCOMP=$$GET1^DIQ(409.68,OUTENCIEN,.07,"I")
 I RET="" D
 . I STATUS["INPATIENT",$P(APPTDTTM,".",1)>DT S RET=$P(STATUS," ",1)_"/FUTURE" Q
 . I (STATUS["INPATIENT"),(CLINIEN]""),(NONCOUNT'="Y"),OUTENCIEN="" S RET=$P(STATUS," ",1)_"/ACT REQ" Q  ;no outpatient encounter for inpatient
 . I (STATUS["INPATIENT"),(CLINIEN]""),(NONCOUNT'="Y"),(CKOUTCOMP="") S RET=$P(STATUS," ",1)_"/ACT REQ" Q
 . I (STATUS="NO ACTION TAKEN"),((CHKIO="CHECKED OUT")!(CHKIO="CHECKED IN")) S RET="ACT REQ/"_CHKIO D  Q
 . . I (OUTENCIEN),(CKOUTCOMP) S RET="CHECKED OUT"
 . I ((STATUS="NO-SHOW")!(STATUS="NON-COUNT")) S RET=STATUS Q:CHKIO="NO ACTION TAKEN"
 . S RET=STATUS_"/"_CHKIO
 I STATUS["INPATIENT",((CHKIO="")!(CHKIO="NO ACTION TAKEN")) D
 . I APPTDTTM>(DT+.2359) S RET=$P(STATUS," ")_"/FUTURE" Q
 . S RET=$P(STATUS," ")_"/NO ACT TAKN"
 I STATUS["INPATIENT" Q RET
 I STATUS["NO-SHOW" Q RET_"^"_STATUSDATE ;745
 I ($G(OUTENCIEN)),($D(^SCE(OUTENCIEN,0))) D
 . S OESTATUS=$$GET1^DIQ(409.68,OUTENCIEN,.12,"E")
 . I $G(OESTATUS)="NON-COUNT" D  Q
 . . I CHECKOUTDT S RET="NON-COUNT/CHECKED OUT" Q
 . . I CHECKINDT S RET="NON-COUNT/CHECKED IN"
 . I $G(OESTATUS)="CHECKED OUT" S RET="CHECKED OUT" Q
 . I CHECKOUTDT S RET="ACT REQ/CHECKED OUT" D  Q
 . . I ($G(OESTATUS)=""),(CKOUTCOMP) S RET="CHECKED OUT"
 . I CHECKINDT S RET="ACT REQ/CHECKED IN"
 Q RET
 ;