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

SDES2CANCELAPPT.m

Go to the documentation of this file.
SDES2CANCELAPPT ;ALB/JAS,MCB,JAS,BLB,LAB,BLB,MGD,BWF - SDES2 CANCEL APPOINTMENT ; AUG 05 2024
 ;;5.3;Scheduling;**869,871,873,875,877,878,880,886**;Aug 13, 1993;Build 13
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 Q
 ;
CANCELAPPT(JSONRETURN,SDCONTEXT,PARAMS) ;
 ;
 N APPTIEN,APPTIENS,GOODPARAMS,ORIGUSER,SDERRORS,SDRETURN
 ;
 D VALCONTEXT^SDES2VALCONTEXT(.SDERRORS,.SDCONTEXT)
 I $D(SDERRORS) M SDRETURN=SDERRORS S SDRETURN("Appointment",1)="" D BUILDJSON^SDES2JSON(.JSONRETURN,.SDRETURN) Q
 S ORIGUSER=$S($G(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
 ;
 S GOODPARAMS=$$VALPARAMS(.PARAMS,.SDERRORS)
 I 'GOODPARAMS,$D(SDERRORS) M SDRETURN=SDERRORS S SDRETURN("Appointment",1)="" D BUILDJSON^SDES2JSON(.JSONRETURN,.SDRETURN) Q
 ;
 S PARAMS("NOTE")=$$VALNOTE($G(PARAMS("NOTE")),$G(PARAMS("CANCEL HASH")))
 S PARAMS("CANCEL REASON IEN")=$O(^SD(409.2,"B",PARAMS("CANCEL REASON"),0))
 S PARAMS("ORIGINAL USER")=ORIGUSER
 D TRY2CANCEL(.SDRETURN,.SDCONTEXT,.PARAMS,.SDERRORS)
 ;
 I '$D(SDRETURN) S SDRETURN("Appointment",1)=""
 I $D(SDERRORS) M SDRETURN=SDERRORS
 D BUILDJSON^SDES2JSON(.JSONRETURN,.SDRETURN)
 Q
 ;
VALPARAMS(PARAMS,SDERRORS) ;
 N LINKEDCLINIC,PID,RESOURCEIEN,VALRET
 ;
 ; Validate APPT IEN
 D VALFILEIEN^SDES2VALUTIL(.VALRET,.SDERRORS,409.84,$G(PARAMS("APPT IEN")),1,0,14,15)
 Q:'VALRET 0
 I $$GET1^DIQ(409.84,PARAMS("APPT IEN"),.12,"I") D ERRLOG^SDES2JSON(.SDERRORS,449) Q 0
 ;
 ; Validate Clinic IEN
 D VALFILEIEN^SDES2VALUTIL(.VALRET,.SDERRORS,44,$G(PARAMS("CLINIC IEN")),1,0,18,19)
 Q:'VALRET 0
 S RESOURCEIEN=$$GET1^DIQ(409.84,PARAMS("APPT IEN"),.07,"I")
 S LINKEDCLINIC=$$GET1^DIQ(409.831,RESOURCEIEN,.04,"I")
 I PARAMS("CLINIC IEN")'=LINKEDCLINIC D ERRLOG^SDES2JSON(.SDERRORS,193) Q 0
 ;
 ; Validate DFN
 D VALFILEIEN^SDES2VALUTIL(.VALRET,.SDERRORS,2,$G(PARAMS("DFN")),1,0,1,2)
 Q:'VALRET 0
 I $$GET1^DIQ(409.84,PARAMS("APPT IEN"),.05,"I")'=PARAMS("DFN") D ERRLOG^SDES2JSON(.SDERRORS,194) Q 0
 ;
 ; Order Lock Check
 N APPTREQTYPE,REQTYPE,REQUESTIEN,APPOINTMENT
 S APPTREQTYPE=$$GET1^DIQ(409.84,PARAMS("APPT IEN"),.22,"I")
 S REQUESTIEN=$P($G(APPTREQTYPE),";")
 S REQTYPE=$$GET1^DIQ(409.85,REQUESTIEN,4,"I")
 ;
 ; Validate Cancelled By
 D VALFIELD^SDES2VALUTIL(.VALRET,.SDERRORS,409.84,.17,$G(PARAMS("CANCELLED BY")),1,0,190,189)
 Q:'VALRET 0
 I PARAMS("CANCELLED BY")'="C",PARAMS("CANCELLED BY")'="PC" D ERRLOG^SDES2JSON(.SDERRORS,189) Q 0
 I $$GET1^DIQ(409.84,PARAMS("APPT IEN"),.12,"I") D ERRLOG^SDES2JSON(.SDERRORS,449) Q 0
 ;
 ; Validate Cancel Reason
 D VALFIELD^SDES2VALUTIL(.VALRET,.SDERRORS,409.84,.122,$G(PARAMS("CANCEL REASON")),1,0,128,129)
 Q:'VALRET 0
 ;
 I $G(PARAMS("NEW PID"))'="" D  Q:$D(SDERRORS) 0
 . S PID=$$ISOTFM^SDAMUTDT(PARAMS("NEW PID"))
 . I PID=-1!($P(PID,".",2)) D ERRLOG^SDES2JSON(.SDERRORS,160) Q
 . I PARAMS("CANCELLED BY")="C" D ERRLOG^SDES2JSON(.SDERRORS,448) Q
 . I $$DUPPIDCHK(REQUESTIEN,PID) D ERRLOG^SDES2JSON(.SDERRORS,545) Q
 . S PARAMS("NEW PID")=PID
 Q 1
 ;
VALNOTE(NOTE,CANCELHASH) ;
 N SDECJ
 S NOTE=$TR($G(NOTE),"^"," ") ;
 I $G(CANCELHASH)'="" F SDECJ=$L(CANCELHASH,U):-1:1 S NOTE=$P(CANCELHASH,U,SDECJ)_"_"_NOTE
 I $E(NOTE,$L(NOTE))="_" S NOTE=$E(NOTE,1,$L(NOTE)-1)
 Q NOTE
 ;
DUPPIDCHK(REQUESTIEN,NEWPID) ;
 N CHILDIEN,DUPPID,PARENTIEN S (CHILDIEN,DUPPID)=0
 S PARENTIEN=$$GET1^DIQ(409.85,REQUESTIEN_",",43.8,"I")
 I 'PARENTIEN Q DUPPID
 F  S CHILDIEN=$O(^SDEC(409.85,PARENTIEN,2,"B",CHILDIEN)) Q:'CHILDIEN  D
 . Q:CHILDIEN=REQUESTIEN
 . I NEWPID>0,$$GET1^DIQ(409.85,CHILDIEN,22,"I")=NEWPID S DUPPID=1
 Q DUPPID
 ;
TRY2CANCEL(SDRETURN,SDCONTEXT,PARAMS,SDERRORS) ; Cancel Patient's Appt
 N APPTIEN,CLINICIEN,DFN,CANBYCLINORPAT,CANCELREASON,CANCELREASONIEN,NOTE,CANCELHASH,EAS,NEWPID,ORIGUSER
 S APPTIEN=PARAMS("APPT IEN"),CLINICIEN=PARAMS("CLINIC IEN"),DFN=PARAMS("DFN")
 S CANBYCLINORPAT=PARAMS("CANCELLED BY"),CANCELREASON=PARAMS("CANCEL REASON"),CANCELREASONIEN=PARAMS("CANCEL REASON IEN")
 S NOTE=$G(PARAMS("NOTE")),EAS=$G(SDCONTEXT("ACHERON AUDIT ID")),NEWPID=$G(PARAMS("NEW PID")),ORIGUSER=PARAMS("ORIGINAL USER")
 ;
 N SDATA,APPTENDTIME,APPTLENGTH,APPTSTARTTIME,APPTTYPE,CLINICSUBIEN,EDITED,MRTC,OLDRECALLPTR,PROVIEN
 N PARENTREQUEST,PARENTSTATUS,RECALLREQIEN,RECALLREQLINK,RECALLRET,REQUESTIEN,REQUESTTYPE,RESOURCE,IENS44
 ;
 D POPULATE(APPTIEN,.APPTSTARTTIME,.REQUESTTYPE,.REQUESTIEN,.APPTENDTIME,.APPTLENGTH,.APPTTYPE,.RESOURCE,.WALKIN,.MRTC,.PARENTREQUEST,.PARENTSTATUS,.SLOTSTATUSSTRING)
 S IENS44=$$GET44RECORDIENS(CLINICIEN,APPTSTARTTIME,DFN)
 ; first event handler
 S CLINICSUBIEN=$$BEFOREEVENT^SDES2CANCELAPPT1(DFN,APPTSTARTTIME,CLINICIEN,.SDATA)
 ;
 ; cancel appointments
 D CANCEL40984(.SDERRORS,APPTIEN,CANCELREASON,CANBYCLINORPAT,WALKIN,$G(EAS))
 D CANCEL44(.SDERRORS,CLINICIEN,APPTSTARTTIME,DFN,APPTIEN,WALKIN,IENS44)
 D CANCEL2(.SDERRORS,DFN,APPTSTARTTIME,CANBYCLINORPAT,CANCELREASON,$G(NOTE),APPTIEN,CLINICIEN,IENS44)
 Q:$D(SDERRORS)
 ;
 ; update linked appointment request records
 D UPDATEREQUEST(REQUESTIEN,APPTIEN,CLINICIEN,DFN,CANBYCLINORPAT,$G(NOTE),APPTSTARTTIME,RESOURCE,MRTC,PARENTREQUEST,PARENTSTATUS,$G(NEWPID),$G(SDCONTEXT("USER DUZ")))
 ;
 ; update compensation and pension records
 I APPTTYPE="COMPENSATION & PENSION" D AMIECAN^SDESCOMPPEN(.SDRETURN,DFN,APPTSTARTTIME)
 ;
 ; remove outpatient encounter
 D REMOVEENCOUNTER(APPTIEN,$$GET1^DIQ(2.98,APPTSTARTTIME_","_DFN_",",21,"I"),APPTSTARTTIME,DFN,IENS44)
 ;
 ; update clinic availability
 D INCREMENTAVAIL1^SDESUTIL(CLINICIEN,APPTSTARTTIME,APPTLENGTH) ;
 ;
 ; second event handler
 D AFTEREVENT^SDES2CANCELAPPT1($G(DFN),$G(APPTSTARTTIME),$G(CLINICIEN),$G(CLINICSUBIEN),.SDATA)
 ;
 S SDRETURN("Appointment","Cancelled")=$G(APPTIEN)
 Q
 ;
CANCEL40984(SDERRORS,APPTIEN,CANCELREASON,CANBYCLINORPAT,WALKIN,EAS) ;
 N IENS,FDA,ERR84
 ;
 S IENS=APPTIEN_","
 ;
 I WALKIN="YES" D
 .S FDA(409.84,IENS,.03)=""
 .S FDA(409.84,IENS,.04)=""
 S FDA(409.84,IENS,.12)=$$NOW^XLFDT
 S FDA(409.84,IENS,.121)=ORIGUSER
 S FDA(409.84,IENS,.122)=CANCELREASONIEN
 S FDA(409.84,IENS,.17)=CANBYCLINORPAT
 S FDA(409.84,IENS,100)=EAS
 ;
 L +^SDEC(APPTIEN):3 I '$T D ERRLOG^SDES2JSON(.SDERRORS,192) Q
 D FILE^DIE("","FDA","ERR84") K FDA
 L -^SDEC(APPTIEN)
 I $D(ERR84) D ERRLOG^SDES2JSON(.SDERRORS,191) Q
 Q
 ;
CANCEL44(SDERRORS,CLINICIEN,APPTSTARTTIME,DFN,APPTIEN,WALKIN,IENS44) ;
 N IENS,FDA44003,ERR44003
 ;
 I WALKIN="YES" D
 .S FDA44003(44.003,IENS44,309)=""
 S FDA44003(44.003,IENS44,310)="C"
 ;
 L +^SC(CLINICIEN):3 I '$T D ERRLOG^SDES2JSON(.SDERRORS,186),CLEAN40984(APPTIEN) Q
 D FILE^DIE("","FDA44003","ERR44003") K FDA44003
 L -^SC(CLINICIEN)
 I $D(ERR44003) D ERRLOG^SDES2JSON(.SDERRORS,191) D CLEAN40984(APPTIEN) Q
 Q
 ;
CANCEL2(SDERRORS,DFN,APPTSTARTTIME,CANBYCLINORPAT,CANCELREASON,NOTE,APPTIEN,CLINICIEN,IENS44) ;
 N IENS,FDA298,ERR298
 S IENS=APPTSTARTTIME_","_DFN_","
 S FDA298(2.98,IENS,3)=CANBYCLINORPAT
 S FDA298(2.98,IENS,14)=ORIGUSER
 S FDA298(2.98,IENS,15)=$$NOW^XLFDT
 S FDA298(2.98,IENS,16)=CANCELREASONIEN
 S FDA298(2.98,IENS,17)=NOTE
 L +^DPT(DFN):3 I '$T D ERRLOG^SDES2JSON(.SDERRORS,187),CLEAN40984(APPTIEN),CLEAN44003(DFN,CLINICIEN,APPTSTARTTIME,IENS44) Q
 D FILE^DIE("","FDA298","ERR298") K FDA298
 L -^DPT(DFN)
 I $D(ERR298) D ERRLOG^SDES2JSON(.SDERRORS,191),CLEAN40984(APPTIEN),CLEAN44003(DFN,CLINICIEN,APPTSTARTTIME,IENS44) Q
 Q
 ;
UPDATEREQUEST(REQUESTIEN,APPTIEN,CLINICIEN,DFN,CANBYCLINORPAT,NOTE,APPTSTARTTIME,RESOURCE,MRTC,PARENTREQUEST,PARENTSTATUS,NEWPID,USERID) ;
 N RECALLREQIEN,RECALLREQLINK,OLDRECALLPTR,PROVIDERIEN
 ;
 I REQUESTTYPE="APPTREQ"!(REQUESTTYPE="RTC")!(REQUESTTYPE="VETERAN")!(REQUESTTYPE="MOBILE") D
 .D DELETEAPPTDATA(REQUESTIEN)
 .D OPENAPPTREQUEST(REQUESTIEN,APPTIEN,MRTC,PARENTREQUEST,PARENTSTATUS,DFN,CANBYCLINORPAT)
 .D UPDCONTSEQ^SDESCONTACTS(DFN,REQUESTIEN)
 .I $G(NEWPID),CANBYCLINORPAT="PC" D
 ..D ADDPIDHISTORY^SDES2CRTAPREQ(REQUESTIEN,NEWPID,ORIGUSER)
 ;
 I REQUESTTYPE="RECALL" D
 .D REOPEN^SDESRECALLREQ(.RECALLRET,APPTIEN,,NEWPID,CANBYCLINORPAT,,USERID)
 .I '$D(RECALLRET) Q
 .S RECALLREQIEN=$P($G(RECALLRET),U)
 .S RECALLREQLINK=$P($G(RECALLRET),U,2)
 .S OLDRECALLPTR=$P($G(RECALLRET),U,3)
 .D UPDCONTSEQ^SDESCONTACTS($G(DFN),$G(RECALLREQIEN),$G(RECALLREQLINK),$G(OLDRECALLPTR))
 ;
 I REQUESTTYPE="CONSULT" D
 .S PROVIDERIEN=$$GETPROVIDER^SDESCREATEAPPT(CLINICIEN,"C")
 .D REQSET^SDESCONSULTUPD(REQUESTIEN,PROVIDERIEN,"",2,CANBYCLINORPAT,NOTE,APPTSTARTTIME,RESOURCE)
 .D UPDCONTSEQ^SDESCONTACTS(DFN,REQUESTIEN)
 .;
 .I $G(NEWPID) D
 ..D UPDATECONSULTPID^SDES2APPTUTIL(REQUESTIEN,NEWPID,DFN,USERID)
 ;
 Q
 ;
OPENAPPTREQUEST(REQUESTIEN,APPTIEN,MRTC,PARENTREQUEST,PARENTSTATUS,DFN,CANBYCLINORPAT) ;
 N REQFDA,REQUESTERR,FDA,PARENTERR,REASONALLOWSOPEN,CANEDITPID
 ;
 S REASONALLOWSOPEN=$$GET1^DIQ(409.2,$$GET1^DIQ(409.84,APPTIEN,.122,"I"),5,"I")
 S CANEDITPID=$S(CANBYCLINORPAT="C":0,CANBYCLINORPAT="PC":1,1:"")
 ;
 I REASONALLOWSOPEN D
 .S REQFDA(409.85,REQUESTIEN_",",19)=""
 .S REQFDA(409.85,REQUESTIEN_",",20)=""
 .S REQFDA(409.85,REQUESTIEN_",",21)=""
 .S REQFDA(409.85,REQUESTIEN_",",23)="O"
 .S REQFDA(409.85,REQUESTIEN_",",49)=CANEDITPID
 .D FILE^DIE("","REQFDA","REQUESTERR") K REQFDA,REQUESTERR
 ;
 ; do not re-open
 I 'REASONALLOWSOPEN D
 .S REQFDA(409.85,REQUESTIEN_",",19)=$P($$GET1^DIQ(409.84,APPTIEN,.12,"I"),".",1)
 .S REQFDA(409.85,REQUESTIEN_",",20)=$$GET1^DIQ(409.84,APPTIEN,.121,"I")
 .S REQFDA(409.85,REQUESTIEN_",",21)=$O(^SDEC(409.853,"B","CANCELLED NOT RE-OPENED",""))
 .S REQFDA(409.85,REQUESTIEN_",",49)=CANEDITPID
 .D FILE^DIE("","REQFDA","REQUESTERR") K REQFDA,REQUESTERR
 ;
 I MRTC D
 .D REMOVEMRTCAPTIEN(REQUESTIEN,APPTIEN,PARENTREQUEST)
 .I PARENTSTATUS="C",REASONALLOWSOPEN D
 ..S FDA(409.85,PARENTREQUEST_",",19)=""
 ..S FDA(409.85,PARENTREQUEST_",",20)=""
 ..S FDA(409.85,PARENTREQUEST_",",21)=""
 ..S FDA(409.85,PARENTREQUEST_",",23)="O"
 ..D FILE^DIE("","FDA","PARENTERR") K FDA
 Q
 ;
UPDATEMRTCSEQNUM(PARENTREQUEST,DFN) ;
 N COUNT,REQUESTIEN,IENS,NEXTSEQUENCENUM,CHILD,LASTCHILD,MRTCFDA,ERR
 ;
 S REQUESTIEN=0,COUNT=0,LASTCHILD=""
 F  S REQUESTIEN=$O(^SDEC(409.85,"B",DFN,REQUESTIEN)) Q:'REQUESTIEN  D
 .I $$GET1^DIQ(409.85,REQUESTIEN,43.8,"I")=PARENTREQUEST D
 ..I $$GET1^DIQ(409.85,REQUESTIEN,21,"I") Q
 ..S COUNT=COUNT+1
 ..S CHILD(REQUESTIEN)=COUNT
 ;
 S REQUESTIEN=0
 F  S REQUESTIEN=$O(CHILD(REQUESTIEN)) Q:'REQUESTIEN  D
 .S MRTCFDA(409.85,REQUESTIEN_",",43.1)=$G(CHILD(REQUESTIEN))
 .D FILE^DIE(,"MRTCFDA","ERR")  K MRTCFDA
 Q
 ;
REMOVEENCOUNTER(APPTIEN,ENCOUNTERIEN,APPTSTARTTIME,DFN,IENS44) ;
 N SECENCOUNTERIEN,VAR,PROCESSTYPE,APPTFDA,ENCOUNTERFDA,CHILDIEN,CHILDFDA,CHILDPROCESSTYPE,VISITUPDATE,PATIENTFDA,CLINICFDA,CLINICIENS,DISPOSITIONFDA,DISPOSITIONIEN,CLASSIEN,CLASSFDA
 ;
 I '$G(ENCOUNTERIEN)!('$$EDITOK^SDCO3($G(ENCOUNTERIEN),2)) Q
 ;
 S VAR=$$DELVFILE^PXAPI("ALL",$P($G(^SCE(ENCOUNTERIEN,0)),U,5),"","","",0)
 ;
 S PROCESSTYPE=$$GET1^DIQ(409.68,ENCOUNTERIEN,.08,"E")
 ;
 ; child encounters
 I $L($G(PROCESSTYPE)),$G(PROCESSTYPE)'="CREDIT STOP CODE" D
 .S CHILDIEN=0
 .F  S CHILDIEN=$O(^SCE("APAR",ENCOUNTERIEN,CHILDIEN)) Q:'CHILDIEN  D
 ..S CHILDFDA(409.68,CHILDIEN_",",.01)="@"
 ..D FILE^DIE(,"CHILDFDA") K CHILDFDA
 ..S VISITUPDATE=$$KILL^VSITKIL($$GET1^DIQ(409.68,CHILDIEN,.05,"I"))
 ;
 ; patient file and check-in from clinic file
 I PROCESSTYPE="APPOINTMENT" D
 .S PATIENTFDA(2.98,APPTSTARTTIME_","_DFN_",",21)="@"
 .D FILE^DIE(,"PATIENTFDA") K PATIENTFDA
 .S CLINICFDA(44.003,IENS44,303)="@"
 .D FILE^DIE(,"CLINICFDA") K CLINICFDA
 ;
 ; disposition subfile in patient file
 I PROCESSTYPE="DISPOSITION" D
 .S DISPOSITIONIEN=$$GET1^DIQ(409.68,ENCOUNTERIEN,.09,"I")
 .S DISPOSITIONFDA(2.101,DISPOSITIONIEN_","_DFN_",",18)="@"
 .D FILE^DIE(,"DISPOSITIONFDA") K DISPOSITIONFDA
 ;
 ; outpatient classification file
 I '$$GET1^DIQ(409.68,ENCOUNTERIEN,.06,"I"),$O(^SDD(409.42,"AO",ENCOUNTERIEN,0))>0 D
 .S CLASSIEN=0
 .F  S CLASSIEN=$O(^SDD(409.42,"AO",ENCOUNTERIEN,CLASSIEN)) Q:'CLASSIEN  D
 ..S CLASSFDA(409.42,CLASSIEN_",",.01)="@"
 ..D FILE^DIE(,"CLASSFDA") K CLASSFDA
 ;
 ; outpatient encounter file
 S ENCOUNTERFDA(409.68,ENCOUNTERIEN_",",.01)="@"
 D FILE^DIE(,"ENCOUNTERFDA") K ENCOUNTERFDA
 S VISITUPDATE=$$KILL^VSITKIL($$GET1^DIQ(409.68,ENCOUNTERIEN,.05,"I"))
 ;
 ; delete checkout in appointment file
 I $$GET1^DIQ(409.84,APPTIEN,.14,"I") D
 .S APPTFDA(409.84,APPTIEN_",",.14)="@"
 .S APPTFDA(409.84,APPTIEN_",",.08)=$G(ORIGUSER)
 .D FILE^DIE(,"APPTFDA") K APPTFDA
 Q
 ;
DELETEAPPTDATA(REQUESTIEN) ;
 N FDA
 S REQUESTIEN=$G(REQUESTIEN)_","
 S FDA(409.85,REQUESTIEN,13)="@"
 S FDA(409.85,REQUESTIEN,13.1)="@"
 S FDA(409.85,REQUESTIEN,13.2)="@"
 S FDA(409.85,REQUESTIEN,13.3)="@"
 S FDA(409.85,REQUESTIEN,13.4)="@"
 S FDA(409.85,REQUESTIEN,13.6)="@"
 S FDA(409.85,REQUESTIEN,13.7)="@"
 S FDA(409.85,REQUESTIEN,13.8)="@"
 S FDA(409.85,REQUESTIEN,100)=$G(EAS)
 D FILE^DIE(,"FDA") K FDA
 Q
 ;
REMOVEMRTCAPTIEN(REQUESTIEN,APPTIEN,PARENTIEN) ;
 N SUBIEN,FDA
 S SUBIEN=0
 S SUBIEN=$O(^SDEC(409.85,PARENTIEN,2,"B",REQUESTIEN,SUBIEN)) Q:'SUBIEN
 S FDA(409.852,SUBIEN_","_PARENTIEN_",",.02)="@"
 D FILE^DIE(,"FDA","FDAERR") K FDA
 Q
 ;
GET44RECORDIENS(CLINICIEN,APPTSTARTTIME,DFN) ;
 N FOUND,IENS44003
 S FOUND=0
 S SUBIEN=0 F  S SUBIEN=$O(^SC(CLINICIEN,"S",APPTSTARTTIME,1,SUBIEN)) Q:'SUBIEN!($G(FOUND)=1)  D
 .I $$GET1^DIQ(44.003,SUBIEN_","_APPTSTARTTIME_","_CLINICIEN_",",310,"E")="CANCELLED" Q
 .I $$GET1^DIQ(44.003,SUBIEN_","_APPTSTARTTIME_","_CLINICIEN_",",.01,"I")=DFN D
 ..S IENS44003=SUBIEN_","_APPTSTARTTIME_","_CLINICIEN_",",FOUND=1 Q
 Q $G(IENS44003)
 ;
CLEAN40984(APPTIEN) ;
 N FDA,IENS
 S IENS=APPTIEN_","
 S FDA(409.84,IENS,.12)=""
 S FDA(409.84,IENS,.121)=""
 S FDA(409.84,IENS,.122)=""
 S FDA(409.84,IENS,.17)=""
 S FDA(409.84,IENS,100)=""
 D FILE^DIE("","FDA") K FDA
 Q
 ;
CLEAN44003(DFN,CLINICIEN,APPTSTARTTIME,IENS44) ;
 N FDA44003,IENS,ERR44003
 S FDA44003(44.003,IENS44,310)=""
 D FILE^DIE("","FDA44003","ERR44003") K FDA44003
 Q
 ;
POPULATE(APPTIEN,APPTSTARTTIME,REQUESTTYPE,REQUESTIEN,APPTENDTIME,APPTLENGTH,APPTTYPE,RESOURCE,WALKIN,MRTC,PARENTREQUEST,PARENTSTATUS,SLOTSTATUSSTRING) ;
 S APPTSTARTTIME=$$GET1^DIQ(409.84,$G(APPTIEN),.01,"I")
 S REQUESTTYPE=$P($$GET1^DIQ(409.84,$G(APPTIEN),.22,"I"),";",2),REQUESTTYPE=$S(REQUESTTYPE="GMR(123,":"CONSULT",REQUESTTYPE="SD(403.5,":"RECALL",REQUESTTYPE="SDEC(409.85,":"APPTREQ",1:"")
 S REQUESTIEN=$P($$GET1^DIQ(409.84,$G(APPTIEN),.22,"I"),";")
 S APPTENDTIME=$$GET1^DIQ(409.84,$G(APPTIEN),.02,"I")
 S APPTLENGTH=$$GET1^DIQ(409.84,APPTIEN,.18,"I")
 S APPTTYPE=$$GET1^DIQ(409.84,APPTIEN,.06,"E")
 S RESOURCE=$$GET1^DIQ(409.84,$G(APPTIEN),.07,"I")
 S WALKIN=$$GET1^DIQ(409.84,APPTIEN,.13,"E")
 S MRTC=$$GET1^DIQ(409.85,REQUESTIEN,41,"I")
 S PARENTREQUEST=$$GET1^DIQ(409.85,REQUESTIEN,43.8,"I")
 S PARENTSTATUS=$$GET1^DIQ(409.85,PARENTREQUEST,23,"I")
 S SLOTSTATUSSTRING="#@!$* XXWVUTSRQPONMLKJIHGFEDCBA0123456789jklmnopqrstuvwxyz"
 Q