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

SDECRRCLEANUP.m

Go to the documentation of this file.
SDECRRCLEANUP ;ALB/BLB/DMR SDEC RECALL REMINDERS CLEANUP ;June 9, 2021@11:35
 ;;5.3;Scheduling;**785**;;Build 14
 ;;
 N %DT,BDATE,EDATE,Y,%ZIS
 S %DT="AEX"
 S (DEFAULTDATE,DDATETXT)=""
 S DEFAULTDATE=$$GETDEFAULTDT(DEFAULTDATE)
 S DDATETXT=$$FMTONET^SDECDATE(DEFAULTDATE,"N")
 W !!,"Beginning date cannot be less than "_DDATETXT
 W !
 S %DT("A")="Enter the beginning date: "
 D ^%DT
 I $G(Y)=U Q
 S BDATE=$G(Y)
 I BDATE<DEFAULTDATE D
 .W !!,"Beginning date set to default: "_DDATETXT
 .S BDATE=DEFAULTDATE
 W !
 S %DT="AEX"
 S %DT("A")="Enter the ending date: "
 D ^%DT
 I $G(Y)=U Q
 S EDATE=$G(Y)
 W !
 I $G(Y)=U Q
 ;
PRINT ;
 S %ZIS="Q" D ^%ZIS G:POP END
 I $D(IO("Q")) S ZTRTN="RRRDATELOOP^SDECRRCLEANUP",ZTSAVE("*")="" D ^%ZTLOAD K ZTRTN,ZTSAVE G END
 ;I $D(IO("Q")) S ZTRTN="DRIVER^SDECRRCLEANUP",ZTSAVE("*")="" D ^%ZTLOAD K ZTRTN,ZTSAVE G END
 I '$D(IO("Q")) U IO
 D RRRDATELOOP
 D END
 Q
 ;
GETDEFAULTDT(DEFAULTDATE) ;
 S (FIRSTARIEN,DEFAULTBDATE)=0
 F  S FIRSTARIEN=$O(^SDEC(409.85,FIRSTARIEN)) Q:DEFAULTBDATE'=0  D
 .S DEFAULTBDATE=$P(^SDEC(409.85,FIRSTARIEN,0),"^",16)
 Q DEFAULTBDATE
 ;
WRITE ; 
 N REC,CC,CCC S CCC=""
 W !,"Recall Removed IEN ^ Patient Name^ Provider ^ Recall Date ^ Recall Clinic ^ Recall Type ^ Recall Appointment Date ^ Clinic ^ Comment"
 S REC="" F  S REC=$O(^TMP("CLEANUP",$J,REC)) Q:REC=""  D
 .S CC="" F  S CC=$O(^TMP("CLEANUP",$J,REC,CC)) Q:CC=""  D
 ..W !,^TMP("CLEANUP",$J,REC,CC)
 ..S CCC=CCC+1
 W !,"Counter: "_CCC
 G END
 Q
END ;
 D ^%ZISC
 K ^TMP("CLEANUP",$J)
 K APPTCLINIC,ARIEN,CANCELLED,COUNTER,DDATETXT,DEFAULTBDATE,FIRSTARIEN,IEN40984
 K OPENAR,OPENCOMPAPPT,POP,RRIEN,RRRSTOPCODEN,SAMECLINIC,SAMESTOPCODE,SAVED,SDECAPPTIEN
 K STATUS,WITHINRANGE,X1,X2,OPENRECALL
 Q
RRRDATELOOP ;
 N DELREAS,DFN,RRRCLINIC,RRRSTOPCODE,RRRCLINIC,ARRESOURCE,ARCLINIC,ARSTOPCODENUM
 N ARSTOPCODE,RRCLINIC,RRSTOPCODENUM,RRSTOPCODE,DAYSETTING,APPTDATE
 S FIRSTARIEN=0
 W "THIS CAN TAKE A LONG TIME, PLEASE WAIT...",!
 S COUNTER=1
 I EDATE=-1 S EDATE=$P($$NOW^XLFDT,".",1)
 F  S BDATE=$O(^SD(403.56,"C",BDATE)) Q:BDATE>$G(EDATE)  D
 .S RRREMOVEDIEN=0
 .F  S RRREMOVEDIEN=$O(^SD(403.56,"C",BDATE,RRREMOVEDIEN)) Q:'RRREMOVEDIEN  D
 ..Q:$$HASDELREASON(RRREMOVEDIEN)'=1
 ..S DFN=$$GET1^DIQ(403.56,RRREMOVEDIEN,.01,"I")
 ..S RRRCLINIC=$$GET1^DIQ(403.56,RRREMOVEDIEN,4.5,"I")
 ..S APPTCLINIC=$$GET1^DIQ(403.56,RRREMOVEDIEN,102,"I")
 ..S RRRSTOPCODEN=$$GET1^DIQ(44,RRRCLINIC,8,"I")
 ..S RRRSTOPCODE=$$GET1^DIQ(40.7,RRRSTOPCODEN,1,"I") ; amis stop code - 40.7, field 1
 ..Q:$$HASOPENAR(DFN)=1
 ..Q:$$HASOPENRECALL(DFN)=1
 ..Q:$$HASOPENCOMPAPT(DFN)=1
 ..Q:$$ALREADYSAVED(DFN)=1
 ..D SAVETOTMP
 D WRITE
 Q
 ;
HASDELREASON(RRREMOVEDIEN) ; CHECK RECALL REMINDER REMOVED DELETED REASON IS 6 (OTHER) OR 7 (SCHEDULED)
 S DELREAS=0
 S DELREAS=$$GET1^DIQ(403.56,RRREMOVEDIEN,203,"I")
 I DELREAS=6!(DELREAS=7) D
 .S DELREAS=1
 Q DELREAS
 ;
GETRRRFIELDS(RRREMOVEDIEN) ; GET 403.56 (RECALL REMINDER REMOVED) FIELDS NEEDED
 S DFN=$$GET1^DIQ(403.56,RRREMOVEDIEN,.01,"I")
 S RRRCLINIC=$$GET1^DIQ(403.56,RRREMOVEDIEN,4.5,"I")
 S RRRSTOPCODEN=$$GET1^DIQ(44,RRRCLINIC,8,"I")
 S RRRSTOPCODE=$$GET1^DIQ(40.7,RRRSTOPCODEN,1,"I") ; amis stop code - 40.7, field 1
 Q
 ;
 ;CHECK FOR AN OPEN 409.85 (SDEC APPT REQUEST) ENTRY AFTER RECALL DATE FROM 403.56 (RECALL REMINDER REMOVED) ENTRY
HASOPENAR(DFN) ;
 N ARRESOURCE,ARCLINICIEN,ARSTOPCODENUM,ARSTOPCODE
 S (OPENAR,ARIEN)=0
 F  S ARIEN=$O(^SDEC(409.85,"B",DFN,ARIEN)) Q:'ARIEN!(OPENAR=1)  D
 .I $$GET1^DIQ(409.85,ARIEN,23,"I")'="O" Q
 .S ARCLINICIEN=$$GET1^DIQ(409.85,ARIEN,8,"I") ;Appointment resource/clinic
 .I ARCLINICIEN'="" D
 ..S ARSTOPCODENUM=$$GET1^DIQ(44,ARCLINICIEN,8,"I")
 ..S ARSTOPCODE=$$GET1^DIQ(40.7,ARSTOPCODENUM,1,"I")
 ..I ARCLINICIEN=RRRCLINIC!(RRRSTOPCODE=ARSTOPCODE) D  ;CHECKING TO SEE IF CLINIC OR STOP CODE MATCH FOR CLINIC SPECIFIC REQUEST
 ...S OPENAR=1
 .I ARCLINICIEN="" D
 ..S ARSTOPCODENUM=$$GET1^DIQ(409.85,ARIEN,8.5,"I")
 ..S ARSTOPCODE=$$GET1^DIQ(40.7,ARSTOPCODENUM,1,"I")
 ..I ARSTOPCODE=RRRSTOPCODE D  ;CHECK TO SEE IF STOP CODE MATCH FOR SERVICE REQUEST
 ...S OPENAR=1
 Q OPENAR
 ;
HASOPENRECALL(DFN) ;
 N RRCLINIC,RRSTOPCODENUM,RRSTOPCODE
 S (OPENRECALL,RRIEN)=0
 F  S RRIEN=$O(^SD(403.5,"B",DFN,RRIEN)) Q:'RRIEN!(OPENRECALL=1)  D
 .S RRCLINIC=$$GET1^DIQ(403.5,RRIEN,4.5,"I")
 .I RRRCLINIC=RRCLINIC S OPENRECALL=1 ; CHECKING FOR OPEN RECALL REMINDER FOR SAME CLINIC
 .S RRSTOPCODENUM=$$GET1^DIQ(44,RRCLINIC,8,"I")
 .S RRSTOPCODE=$$GET1^DIQ(40.7,RRSTOPCODENUM,1,"I")
 .I RRRSTOPCODE=RRSTOPCODE S OPENRECALL=1 ; CHECKING FOR OPEN RECALL REMINDER FOR SAME STOPCODE
 Q OPENRECALL
 ;
HASOPENCOMPAPT(DFN) ;
 N STARTDATE
 S STARTDATE=$$GETSTARTDATE(DFN)
 S (OPENCOMPAPPT,SDECAPPTIEN)=0
 F  S SDECAPPTIEN=$O(^SDEC(409.84,"CPAT",DFN,SDECAPPTIEN)) Q:'SDECAPPTIEN  D
 .Q:$$ISCANCELLED(DFN)=1
 .Q:$$ISDATEINRANGE(DFN)'=1
 .Q:$$ISSAMESTOPCODE(DFN)'=1&($$ISSAMECLINIC(DFN)'=1)
 .S OPENCOMPAPPT=1
 Q OPENCOMPAPPT
 ;
GETSTARTDATE(DFN) ;
 S DAYSETTING=45
 S X1=BDATE,X2=-DAYSETTING D C^%DTC
 S STARTDATE=X K X
 S STARTDATE=STARTDATE-.5
 Q STARTDATE
 ;
ISCANCELLED(DFN) ;
 S CANCELLED=0
 S STATUS=$$GET1^DIQ(409.84,SDECAPPTIEN,.17,"I")
 I STATUS="C"!(STATUS="PC") S CANCELLED=1
 Q CANCELLED
 ;
ISDATEINRANGE(DFN) ;
 N APPTDATE
 S WITHINRANGE=0
 S APPTDATE=$$GET1^DIQ(409.84,SDECAPPTIEN,.01,"I")
 I APPTDATE>STARTDATE S WITHINRANGE=1
 Q WITHINRANGE
 ;
ISSAMESTOPCODE(DFN) ;
 N APPTRESOURCE,APPTCLINICIEN,APPTSTOPCODEN,APPTSTOPCODE
 S SAMESTOPCODE=0
 S APPTRESOURCE=$$GET1^DIQ(409.84,SDECAPPTIEN,.07,"I")
 S APPTCLINICIEN=$$GET1^DIQ(409.831,APPTRESOURCE,.04,"I")
 S APPTSTOPCODEN=$$GET1^DIQ(44,APPTCLINICIEN,8,"I")
 S APPTSTOPCODE=$$GET1^DIQ(40.7,APPTSTOPCODEN,1)
 I APPTSTOPCODE=RRRSTOPCODE S SAMESTOPCODE=1
 Q SAMESTOPCODE
 ;
ISSAMECLINIC(DFN) ;
 N APPTRESOURCE,APPTCLINICIEN
 S SAMECLINIC=0
 S APPTRESOURCE=$$GET1^DIQ(409.84,SDECAPPTIEN,.07,"I")
 S APPTCLINICIEN=$$GET1^DIQ(409.831,APPTRESOURCE,.04,"I")
 I RRRCLINIC=APPTCLINICIEN!(APPTCLINIC=APPTCLINICIEN) S SAMECLINIC=1
 Q SAMECLINIC
 ;
ALREADYSAVED(DFN) ;
 S SAVED=0
 I $D(^TMP("CLEANUP",$J,RRREMOVEDIEN)) S SAVED=1
 Q SAVED
 ;
SAVETOTMP  ;
 N PROVIDER,RECALLCLINIC,RECALLDATE,TYPE,RECALLAPPTDT,COMMENT,CLINIC
 S PROVIDER=$$GET1^DIQ(403.56,RRREMOVEDIEN,4,"E")
 S RECALLCLINIC=$$GET1^DIQ(403.56,RRREMOVEDIEN,4.5,"E")
 S RECALLDATE=$$GET1^DIQ(403.56,RRREMOVEDIEN,5,"E")
 S TYPE=$$GET1^DIQ(403.56,RRREMOVEDIEN,3,"E")
 S RECALLAPPTDT=$$GET1^DIQ(403.56,RRREMOVEDIEN,101,"E")
 S COMMENT=$$GET1^DIQ(403.56,RRREMOVEDIEN,2.5,"E")
 S APPTCLINIC=$$GET1^DIQ(403.56,RRREMOVEDIEN,102,"E")
 S ^TMP("CLEANUP",$J,RRREMOVEDIEN,COUNTER)=RRREMOVEDIEN_"^"_$$GET1^DIQ(2,DFN,.01,"E")_"^"_PROVIDER_"^"_RECALLDATE_"^"_RECALLCLINIC_"^"_TYPE_"^"_RECALLAPPTDT_"^"_APPTCLINIC_"^"_COMMENT
 S COUNTER=COUNTER+1
 Q
 ;
FINDMISMATCH ;
 K ^TMP("MISMATCH")
 N REC40984,RESOURCE,CLINIC1,DFN,APPTDATETIME,APPTDT44,REC44APPT0,IEN44PATIENT
 S STARTDATE=3170418
 S (IEN40984,CC)=0
 S CCC=1
 F  S IEN40984=$O(^SDEC(409.84,IEN40984)) Q:'IEN40984  D
 .Q:$$GET1^DIQ(409.84,IEN40984,.17,"I")'="C"
 .S REC40984=^SDEC(409.84,IEN40984,0)
 .S RESOURCE=$P(REC40984,"^",7)
 .S CLINIC1=""
 .S CLINIC1=$$GET1^DIQ(409.831,RESOURCE,.04,"I")
 .S DFN=$$GET1^DIQ(409.84,IEN40984,.05,"I")
 .S APPTDATETIME=$P(REC40984,"^",1)
 .S APPTDT44=APPTDATETIME
 .F  S CC=$O(^SC(CLINIC1,"S",APPTDT44,1,CC)) Q:'CC  D
 ..S REC44APPT0=^SC(CLINIC1,"S",APPTDT44,1,CC,0)
 ..S IEN44PATIENT=$P(REC44APPT0,"^",1)
 ..Q:IEN44PATIENT'=DFN
 ..Q:APPTDT44'=APPTDATETIME
 ..Q:$P(REC44APPT0,"^",9)="C"
 ..S ^TMP("MISMATCH",$J,CCC)=IEN40984_"^"_IEN44PATIENT_"^"_APPTDATETIME_"^"_CLINIC1
 ..S CCC=CCC+1
 Q