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

SDES2APPTUTIL.m

Go to the documentation of this file.
SDES2APPTUTIL ;ALB/BLB,TJB/ANU/BLB/LAB,BLB - SDES2 CREATE APPOINTMENT UTILITIES ;APR 30,2024
 ;;5.3;Scheduling;**866,871,875,877,878,880,881**;Aug 13, 1993;Build 10
 ;;Per VHA Directive 6402, this routine should not be modified
 ;---------------------------------------------------------------
 Q
 ;
APPTREQ(SDCONTEXT,APPOINTMENT,APPTIEN,APPTMSG) ; called only on create of appointment
 N STARTDATETIME,CLINICIEN,REQUESTIEN,REQUESTTYPE,SDUSER
 S REQUESTIEN=$P($G(APPOINTMENT("REQUEST TYPE")),"|",2)
 S REQUESTTYPE=$P($G(APPOINTMENT("REQUEST TYPE")),"|")
 ;
 S STARTDATETIME=$G(APPOINTMENT("START DATE TIME")),CLINICIEN=$G(APPOINTMENT("CLINIC IEN"))
 D ADDPIDHISTORY^SDESCREATEAPPREQ($P($G(APPOINTMENT("REQUEST TYPE")),"|",2),$G(APPOINTMENT("PATIENT INDICATED DATE")))
 ;
 S SDUSER=$S($G(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
 D BUILDAPPTDATA^SDESEDITAPPTREQ(REQUESTIEN,STARTDATETIME,CLINICIEN,$G(APPOINTMENT("SERVICE CONNECTED PERCENTAGE")),$G(APPOINTMENT("SERVICE CONNECTED")),$G(APPOINTMENT("APPOINTMENT TYPE")),$G(SDCONTEXT("ACHERON AUDIT ID")),SDUSER,.APPTMSG)
 I $G(APPOINTMENT("MRTC PARENT")),$G(APPOINTMENT("MRTC")) D
 .D MRTCCHILD($G(APPOINTMENT("PATIENT INDICATED DATE")),REQUESTIEN,APPTIEN,$G(APPOINTMENT("MRTC PARENT")))
 Q
 ;
RECALL(RECALLRETURN,SDCONTEXT,RECALL,REQUESTIEN) ;
 S RECALL("RECALL IEN")=REQUESTIEN
 S RECALL("DELETE REASON")=7
 D DISPRECALL^SDES2DISPRECALL(.RECALLRETURN,.SDCONTEXT,.RECALL)
 Q
 ;
CONSULT(APPOINTMENT,APPTIEN44,USERID) ;
 N FDA,REQUESTIEN,PROVIDERIEN,NOTE,STARTDATETIME,RESOURCEIEN,DFN,CLINICIEN,NETSTARTDT
 ;
 S REQUESTIEN=$P($G(APPOINTMENT("REQUEST TYPE")),"|",2)
 S PROVIDERIEN=$G(APPOINTMENT("PROVIDER IEN"))
 S NOTE=$G(APPOINTMENT("NOTE"))
 S STARTDATETIME=$G(APPOINTMENT("START DATE TIME"))
 S NETSTARTDT=$$FMTONET^SDECDATE(STARTDATETIME)
 S RESOURCEIEN=$G(APPOINTMENT("RESOURCE IEN"))
 S DFN=$G(APPOINTMENT("DFN"))
 S CLINICIEN=$G(APPOINTMENT("CLINIC IEN"))
 D REQSET(REQUESTIEN,USERID,"SCHEDULED","",$TR($E(NOTE,1,150),"^"," "),STARTDATETIME,CLINICIEN,DFN)
 ;
 S FDA(44.003,APPTIEN44_","_STARTDATETIME_","_CLINICIEN_",",688)=REQUESTIEN
 D UPDATE^DIE("","FDA") K FDA
 ;
 D UPDATECONSULTPID(REQUESTIEN,$G(APPOINTMENT("PATIENT INDICATED DATE")),DFN,.USERID)
 Q
 ;
REQSET(REQUESTIEN,USERID,ACTION,CANCELLEDBY,NOTE,STARTDATETIME,CLINICIEN,DFN) ;
 N %DT,X,SD,TMPYCLNC
 ;
 I $$GET1^DIQ(123,REQUESTIEN_",",8,"E")="DISCONTINUED"!($$GET1^DIQ(123,REQUESTIEN_",",8,"E")="COMPLETE") Q
 ;
 I ACTION="SCHEDULED" D
 .D EDITCS^SDCNSLT(STARTDATETIME,NOTE,CLINICIEN_U_$$GET1^DIQ(44,CLINICIEN,.01,"E"),REQUESTIEN)
 ;
 I ACTION="CANCELLED" D
 .D SDECCAN^SDCNSLT(REQUESTIEN,$$GET1^DIQ(123,REQUESTIEN,.02,"I"),STARTDATETIME,CLINICIEN,CANCELLEDBY,$$GET44APPTIEN^SDES2NOSHOW(CLINICIEN,STARTDATETIME,DFN),NOTE)
 Q
 ;
UPDATECONSULTPID(CONSULTIEN,PID,DFN,USERIEN) ;
 N CONSULTPIDIEN,CONSULTFDA,CONSULTSUBFDA,TOPLEVELIEN
 ;
 I '$D(^SDEC(409.87,"B",CONSULTIEN)) D
 .S CONSULTFDA(409.87,"+1,",.01)=CONSULTIEN
 .S CONSULTFDA(409.87,"+1,",.02)=DFN
 .D UPDATE^DIE("","CONSULTFDA","TOPLEVELIEN") K CONSULTFDA
 .;
 .S CONSULTSUBFDA(409.871,"+1,"_TOPLEVELIEN(1)_",",.01)=$$NOW^XLFDT
 .S CONSULTSUBFDA(409.871,"+1,"_TOPLEVELIEN(1)_",",1)=PID
 .S CONSULTSUBFDA(409.871,"+1,"_TOPLEVELIEN(1)_",",2)=$S($G(USERIEN):USERIEN,1:DUZ)
 .D UPDATE^DIE("","CONSULTSUBFDA") K CONSULTSUBFDA
 ;
 ; file consult pid history subfile only
 S CONSULTPIDIEN=$O(^SDEC(409.87,"B",CONSULTIEN,0))
 I $D(^SDEC(409.87,"B",CONSULTIEN)) D
 .I $$CONSPIDCHECK^SDEC07(CONSULTIEN,PID) D
 ..S CONSULTSUBFDA(409.871,"+1,"_CONSULTPIDIEN_",",.01)=$$NOW^XLFDT
 ..S CONSULTSUBFDA(409.871,"+1,"_CONSULTPIDIEN_",",1)=PID
 ..S CONSULTSUBFDA(409.871,"+1,"_CONSULTPIDIEN_",",2)=$S($G(USERIEN):USERIEN,1:DUZ)
 ..D UPDATE^DIE("","CONSULTSUBFDA") K CONSULTSUBFDA
 Q
 ;
CONSPIDCHECK(SDRIEN1,SDDDT) ;
 N CHIEN,CHSIEN,OLDPID
 S CHIEN=$O(^SDEC(409.87,"B",SDRIEN1,0))
 S CHSIEN=$O(^SDEC(409.87,CHIEN,1,9999999),-1)
 S OLDPID=$$GET1^DIQ(409.871,CHSIEN_","_CHIEN_",",1,"I")
 I OLDPID'=$G(SDDDT) Q 1
 Q 0
 ;
ENCOUNTERS(APPOINTMENT,ENCOUNTER) ;
 I $$NOW^XLFDT>$G(APPOINTMENT("START DATE TIME")),$$NEW^SDPCE($G(APPOINTMENT("START DATE TIME"))) D
 .S ENCOUNTER=$$GETAPT^SDVSIT2($G(APPOINTMENT("DFN")),$G(APPOINTMENT("START DATE TIME")),$G(APPOINTMENT("CLINIC IEN")))
 Q
 ;
MAKE(DFN,STARTDATETIME,CLINICIEN) ;
 D MAKE^SDAMEVT(DFN,STARTDATETIME,CLINICIEN,$$SCIEN^SDECU2(DFN,CLINICIEN,STARTDATETIME),2)
 Q
 ;
GETRESOURCE(ERRORS,APPOINTMENT,CLINICIEN) ;
 N RESOURCE,MATCH
 ;
 I '$G(APPOINTMENT("RESOURCE IEN")) D
 .S RESOURCE=0,MATCH=0
 .F  S RESOURCE=$O(^SDEC(409.831,"ALOC",CLINICIEN,RESOURCE)) Q:RESOURCE'>0!(MATCH>0)  D
 ..I $$GET1^DIQ(409.831,RESOURCE_",",.012,"E")'="CLINIC" Q
 ..S APPOINTMENT("RESOURCE IEN")=RESOURCE,MATCH=1
 ;
 I $$GET1^DIQ(409.831,$G(APPOINTMENT("RESOURCE IEN")),.04,"I")'=$G(CLINICIEN) D ERRLOG^SDESJSON(.ERRORS,366) Q
 Q
 ;
GETPROVIDER(APPOINTMENT,CLINICIEN,PROVIDER,REQUESTTYPE,REQUESTIEN) ;
 N DEFAULTPROVIEN,PROVIDERIEN
 ;
 I $L($G(PROVIDER)) Q
 ;
 I REQUESTTYPE="R" D  Q
 .S APPOINTMENT("PROVIDER IEN")=$$GET1^DIQ(403.54,$$GET1^DIQ(403.5,REQUESTIEN,4,"I"),.01,"I")
 ;
 S PROVIDERIEN=0,DEFAULTPROVIEN=""
 F  S PROVIDERIEN=$O(^SC(CLINICIEN,"PR",PROVIDERIEN)) Q:'PROVIDERIEN!($G(DEFAULTPROVIEN))  D
 .I $$GET1^DIQ(44.1,PROVIDERIEN_","_CLINICIEN_",",.02,"I") S DEFAULTPROVIEN=$$GET1^DIQ(44.1,PROVIDERIEN_","_CLINICIEN_",",.01,"I")
 S APPOINTMENT("PROVIDER IEN")=DEFAULTPROVIEN
 ;
 Q
 ;
MRTCCHILD(PID,REQUESTIEN,APPTIEN,PARENT) ;
 N REQUEST
 S REQUEST("MRTC","PATIENT INDICATED DATE")=$G(APPOINTMENT("PATIENT INDICATED DATE"))
 S REQUEST("MRTC","CHILD REQUEST")=REQUESTIEN
 S REQUEST("MRTC","MRTC APPOINTMENT")=$G(APPTIEN)
 D BUILDMRTCLINKS^SDESEDITAPPTREQ(.REQUEST,$G(APPOINTMENT("MRTC PARENT")))
 D BUILDMRTCPID^SDESEDITAPPTREQ(.REQUEST,$G(APPOINTMENT("MRTC PARENT")))
 Q
 ;
STOREREQUESTCOMM(REQUESTIEN) ;
 N SUBIEN,PATIENTCOMMENTS
 ;
 I $D(^SDEC(409.85,REQUESTIEN,"PATCOM",0)) D
 .S SUBIEN=0
 .F  S SUBIEN=$O(^SDEC(409.85,REQUESTIEN,"PATCOM",SUBIEN)) Q:'SUBIEN  D
 ..S PATIENTCOMMENTS(SUBIEN)=$$GET1^DIQ(409.855,SUBIEN_","_REQUESTIEN_",",.01,"E")
 D WP^DIE(409.84,APPTIEN_",",4,"","PATIENTCOMMENTS")
 Q
 ;
STORENOTE(APPTIEN,NOTE,APPTNOTES) ;
 I $L(NOTE) D
 .D WP^SDECUTL(.APPTNOTES,NOTE)
 .D WP^DIE(409.84,APPTIEN_",",1,"","APPTNOTES")
 Q
 ;
REQUESTTYPE(ERRORS,APPOINTMENTS,REQUESTTYPE,REQUESTIEN,DFN) ;
 I '$L($G(APPOINTMENT("REQUEST TYPE"))) D ERRLOG^SDESJSON(.ERRORS,60) Q
 ;
 I REQUESTTYPE'="A",REQUESTTYPE'="R",REQUESTTYPE'="C" D ERRLOG^SDESJSON(.ERRORS,61) Q
 ;
 I '$G(REQUESTIEN) D ERRLOG^SDESJSON(.ERRORS,61) Q
 ;
 I REQUESTTYPE="R",'$D(^SD(403.5,REQUESTIEN,0)) D ERRLOG^SDESJSON(.ERRORS,61) Q
 I REQUESTTYPE="C",'$D(^GMR(123,REQUESTIEN,0)) D ERRLOG^SDESJSON(.ERRORS,61) Q
 I REQUESTTYPE="A",'$D(^SDEC(409.85,REQUESTIEN,0)) D ERRLOG^SDESJSON(.ERRORS,61) Q
 ;
 I REQUESTTYPE="A",$$GET1^DIQ(409.85,$G(REQUESTIEN),23,"I")="C" D ERRLOG^SDESJSON(.ERRORS,433) Q
 ;
 I REQUESTTYPE="C" D
 .I $$GET1^DIQ(123,REQUESTIEN_",",8,"E")'="PENDING",$$GET1^DIQ(123,+REQUESTIEN_",",8,"E")'="ACTIVE" D ERRLOG^SDESJSON(.ERRORS,433) Q
 ;
 I REQUESTTYPE="A" D
 .I DFN'=$$GET1^DIQ(409.85,REQUESTIEN,.01,"I") D ERRLOG^SDESJSON(.ERRORS,447) Q
 I REQUESTTYPE="R" D
 .I DFN'=$$GET1^DIQ(403.5,REQUESTIEN,.01,"I") D ERRLOG^SDESJSON(.ERRORS,447) Q
 I REQUESTTYPE="C" D
 .I DFN'=$$GET1^DIQ(123,REQUESTIEN,.02,"I") D ERRLOG^SDESJSON(.ERRORS,447)
 Q
 ;
GETAPPTTYPE(ERRORS,APPOINTMENT,TYPE,TYPENAME) ;
 I '$G(TYPE),'$L($G(TYPENAME)) D ERRLOG^SDESJSON(.ERRORS,306) Q
 ;
 I $G(TYPE),$D(^SD(409.1,TYPE,0)) Q
 ;
 I $L($G(TYPENAME)),$D(^SD(409.1,"B",TYPENAME)) S APPOINTMENT("APPOINTMENT TYPE")=$$FIND1^DIC(409.1,"","X",TYPENAME,"B") Q
 ;
 D ERRLOG^SDESJSON(.ERRORS,180)
 Q
 ;
APPTIN44EXISTS(DFN,CLINIC,DATE) ;
 N SUBIEN,FOUND
 ;
 S SUBIEN=0,FOUND=0
 F  S SUBIEN=$O(^SC(CLINIC,"S",DATE,1,SUBIEN)) Q:'SUBIEN!($G(FOUND)=1)  D
 .I $$GET1^DIQ(44.003,SUBIEN_","_DATE_","_CLINIC_",",310)="CANCELLED" Q  ;cancelled
 .I $$GET1^DIQ(44.003,SUBIEN_","_DATE_","_CLINIC_",",.01,"I")=DFN S FOUND=1 Q  ; record exists
 I $G(FOUND) Q 1
 Q 0
 ;
APPTINDIFFTZ(DFN,DATETIME) ;
 N EXISTINGAPPTCLIN,EXISTINGDATETIME,APPTIEN,FOUND
 ;
 S FOUND=0,APPTIEN=0
 F  S APPTIEN=$O(^SDEC(409.84,"CPAT",DFN,APPTIEN)) Q:'APPTIEN!($G(FOUND)=1)  D
 .I $$GET1^DIQ(409.84,APPTIEN,.12,"I") Q
 .S EXISTINGAPPTCLIN=$$GET1^DIQ(409.831,$$GET1^DIQ(409.84,APPTIEN,.07,"I"),.04,"I")
 .S EXISTINGDATETIME=$$FMTISO^SDAMUTDT($$GET1^DIQ(409.84,APPTIEN,.01,"I"))
 .I $$ISOTFM^SDAMUTDT(EXISTINGDATETIME,EXISTINGAPPTCLIN)=DATETIME S FOUND=1
 Q FOUND
 ;
DELETECANRECORD(DFN,DATETIME,CLINICIEN) ;
 N SUBIEN,FOUND,FDA,FDAERR
 ;
 S SUBIEN=0,FOUND=0
 F  S SUBIEN=$O(^SC(CLINICIEN,"S",DATETIME,1,SUBIEN)) Q:'SUBIEN!(FOUND=1)  D
 .I $$GET1^DIQ(44.003,SUBIEN_","_DATETIME_","_CLINICIEN_",",.01,"I")=DFN D
 ..I $$GET1^DIQ(44.003,SUBIEN_","_DATETIME_","_CLINICIEN_",",310)'="CANCELLED" D
 ...S FOUND=1
 ...S FDA(2.98,DATETIME_","_DFN_",",.01)="@"
 ...D FILE^DIE(,"FDA","FDAERR") K FDA
 ;
DELETERECORD(ARRAYDELETE) ;
 N DELETEFDA,FILENUMBER,IENS,ERR
 ;
 S FILENUMBER=0
 F  S FILENUMBER=$O(ARRAYDELETE(FILENUMBER)) Q:'FILENUMBER  D
 .S IENS=ARRAYDELETE(FILENUMBER)
 .S DELETEFDA(FILENUMBER,IENS,.01)="@"
 .D FILE^DIE(,"DELETEFDA","ERR") K DELETEFDA
 Q
 ;
ORDERCHECKLOCK(ERRORS,REQTYPE,DFN) ;
 N FOUND,REQUESTIEN,ORDERID
 ;
 S FOUND=0
 S REQUESTIEN=$P($G(REQTYPE),"|",2)
 S REQTYPE=$$GET1^DIQ(409.85,REQUESTIEN,4,"I")
 I REQTYPE="RTC" D
 .S ORDERID=$$GET1^DIQ(409.85,REQUESTIEN,46,"I")
 .I '+$G(ORDERID) Q
 .I $D(^XTMP("ORLK-"_ORDERID)) D ERRLOG^SDESJSON(.ERRORS,188) S FOUND=1
 Q FOUND
 ;
GETPID(APPOINTMENT,PID,REQUESTTYPE,REQUESTIEN) ;
 I $L($G(PID)) Q
 ;
 I REQUESTTYPE="A" S PID=$$GET1^DIQ(409.85,REQUESTIEN,22,"I")
 I REQUESTTYPE="R" S PID=$$GET1^DIQ(403.5,REQUESTIEN,5,"I")
 ;
 I REQUESTTYPE="C",$$GET1^DIQ(123,REQUESTIEN,17,"I")'="" S PID=$$GET1^DIQ(123,REQUESTIEN,17,"I")
 I REQUESTTYPE="C",PID="" S PID=$$GET1^DIQ(123,REQUESTIEN,.01,"I")
 ;
 S APPOINTMENT("PATIENT INDICATED DATE")=$G(PID)
 Q
 ;
DECREMENTAVAIL1(CLINICIEN,APPTSTARTTIME,APPTLENGTH) ;
 N COUNT,CLINICAPPTLENGTH,NUMOFSLOTSINPLAY
 S CLINICAPPTLENGTH=+$E($$GET1^DIQ(44,CLINICIEN,1917,"E"),1,2)
 S NUMOFSLOTSINPLAY=APPTLENGTH/CLINICAPPTLENGTH
 F COUNT=1:1:NUMOFSLOTSINPLAY D
 .I COUNT>1 D
 ..S APPTSTARTTIME=$$FMADD^XLFDT(APPTSTARTTIME,,,CLINICAPPTLENGTH)
 .D DECREMENTAVAIL2(CLINICIEN,APPTSTARTTIME,APPTLENGTH)
 Q
 ;
DECREMENTAVAIL2(CLINICIEN,APPTSTARTTIME,APPTLENGTH) ;decrement availability by one when creating appointment
 N SLOTINCREMENT,SLOTSTATUSSTRING,CURRENTSCHEDULE,NEWSCHEDULE,TIMECLINICOPENS,SLOTLENGTH,NEWAVAILABILITY,SPECIALCHARACTER,AVAILABILITYFDA,CENTEROFSLOT,CHARMULTIPLIER,MAXDAYSINFUTURE
 ;
 S CURRENTSCHEDULE=$$GET1^DIQ(44.005,$P(APPTSTARTTIME,".")_","_CLINICIEN_",",1)
 S TIMECLINICOPENS=$S($L($$GET1^DIQ(44,CLINICIEN,1914,"I")):$$GET1^DIQ(44,CLINICIEN,1914,"I"),1:8)-1/100
 S SLOTLENGTH=$S($$GET1^DIQ(44,CLINICIEN,1917,"I"):$$GET1^DIQ(44,CLINICIEN,1917,"I"),1:4)
 S SLOTINCREMENT=$S('$$GET1^DIQ(44,CLINICIEN,1917,"I"):4,$$GET1^DIQ(44,CLINICIEN,1917,"I")<3:4,$$GET1^DIQ(44,CLINICIEN,1917,"I"):$$GET1^DIQ(44,CLINICIEN,1917,"I"),1:4)
 S CHARMULTIPLIER=$S(SLOTLENGTH<3:8/SLOTLENGTH,1:2)
 S NEWAVAILABILITY=APPTSTARTTIME#1-TIMECLINICOPENS*100
 S CENTEROFSLOT=NEWAVAILABILITY#1*SLOTINCREMENT\.6+(NEWAVAILABILITY\1*SLOTINCREMENT)*2
 S MAXDAYSINFUTURE=$$GET1^DIQ(44,CLINICIEN,2002,"I")
 S SLOTSTATUSSTRING="#@!$* XXWVUTSRQPONMLKJIHGFEDCBA0123456789jklmnopqrstuvwxyz"
 ;
 I $P(APPTSTARTTIME,".")>$$FMADD^XLFDT(DT,MAXDAYSINFUTURE) D ERRLOG^SDESJSON(.ERRORS,491) Q
 ;
 I '$D(^SC(CLINICIEN,"ST",$P(APPTSTARTTIME,"."),1)) D
 .D ASSEMBLE^SDESCLINDAILYSCH(.ERRORS,CLINICIEN,$P(APPTSTARTTIME,"."),$$GET1^DIQ(44,CLINICIEN,1917,"I"),TIMECLINICOPENS)
 ;
 I $D(^SC(CLINICIEN,"ST",$P(APPTSTARTTIME,"."),"CAN"))!(CURRENTSCHEDULE["CAN") D ERRLOG^SDESJSON(.ERRORS,492)
 ;
 F SPECIALCHARACTER=CENTEROFSLOT:CHARMULTIPLIER  Q:$L($G(NEWSCHEDULE))!($G(NEWAVAILABILITY)="")  D
 .S NEWAVAILABILITY=$E(SLOTSTATUSSTRING,$F(SLOTSTATUSSTRING,$E(CURRENTSCHEDULE,SPECIALCHARACTER+1))-2)
 .S NEWSCHEDULE=$E(CURRENTSCHEDULE,1,SPECIALCHARACTER)_NEWAVAILABILITY_$E(CURRENTSCHEDULE,SPECIALCHARACTER+2,999)
 ;
 S AVAILABILITYFDA(44.005,$P(APPTSTARTTIME,".")_","_CLINICIEN_",",1)=NEWSCHEDULE
 D FILE^DIE(,"AVAILABILITYFDA") K AVAILABILITYFDA
 Q
 ;