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

SDES2BLOCKMOVE.m

Go to the documentation of this file.
SDES2BLOCKMOVE ;ALB/TJB - SCHEDULING BLOCK AND MOVE RPC ;JAN 22, 2024
 ;;5.3;Scheduling;**871**;Aug 13, 1993;Build 13
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 Q
 ;
BLOCKANDMOVE(JSON,SDCONTEXT,SDPARAM) ;
 N RETURN,ERRORS,BLKPARAM,AVPARAM,DFN,SDDUZ,RESOURCEIEN,APPTARRAY,JSONCANCEL,CANCELCLINAVAIL,ORIGINALCLINIC,JSONAPPT,NEWAPPT
 ;
 D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
 ; populate vars
 S SDDUZ=$S($G(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
 D POPULATE(.BLKPARAM,.AVPARAM,.SDPARAM,SDDUZ)
 ;
 ; validate Block and Move
 D VALIDATE(.ERRORS,.BLKPARAM,SDDUZ)
 I $D(ERRORS) S RETURN("BlockAndMoveAppointment")="" M RETURN=ERRORS D BUILDJSON^SDES2JSON(.JSON,.RETURN) Q
 ; cancel original appointment
 D CANCEL(.JSONCANCEL,.BLKPARAM,.SDCONTEXT)
 ;
 ; block availability in original clinic slot
 D CANCELAVAIL(.CANCELCLINAVAIL,.SDCONTEXT,.AVPARAM)
 ;
 ; create new appointment in new slot
 D BUILDAPPTARRAY(.APPTARRAY,.BLKPARAM)
 D CREATE^SDES2CREATEAPPT(.JSONAPPT,.SDCONTEXT,.APPTARRAY)
 D DECODE^XLFJSON("JSONAPPT","NEWAPPT")
 ;
 S RETURN("BlockAndMoveAppointment","NewAppointmentIEN")=$G(NEWAPPT("Appointment","IEN"))
 D BUILDJSON^SDES2JSON(.JSON,.RETURN)
 Q
 ;
POPULATE(PARAMS,AVPARAMS,SDPARAM,SDDUZ) ;
 N APPTIEN,RESOURCEIEN
 S APPTIEN=$G(SDPARAM("APPOINTMENT IEN"))
 S RESOURCEIEN=$$GET1^DIQ(409.84,$G(APPTIEN),.07,"I")
 S PARAMS("APPT IEN")=APPTIEN
 S PARAMS("RESOURCE IEN")=RESOURCEIEN
 S PARAMS("CLINIC IEN")=$$GET1^DIQ(409.831,$G(RESOURCEIEN),.04,"I")
 S PARAMS("TARGET CLINIC IEN")=$G(SDPARAM("TARGET CLINIC"))
 S PARAMS("TARGET DATE TIME")=$G(SDPARAM("TARGET DATE TIME")) ; ISO Format
 S PARAMS("DFN")=$$GET1^DIQ(409.84,$G(APPTIEN),.05,"I")
 S PARAMS("CANCELLED BY")="C"
 S PARAMS("CANCEL REASON")="BLOCK AND MOVE"
 S PARAMS("CANCEL REASON IEN")=$O(^SD(409.2,"B",PARAMS("CANCEL REASON"),0))
 S PARAMS("ORIGINAL USER")=$S($G(SDDUZ)'="":SDDUZ,1:DUZ)
 S AVPARAM("CLINIC IEN")=PARAMS("CLINIC IEN")
 S AVPARAM("START DATE TIME")=$$FMTISO^SDAMUTDT($$GET1^DIQ(409.84,APPTIEN,.01,"I"),$G(PARAMS("CLINIC IEN")))
 S AVPARAM("END DATE TIME")=$$FMTISO^SDAMUTDT($$GET1^DIQ(409.84,APPTIEN,.02,"I"),$G(PARAMS("CLINIC IEN")))
 S AVPARAM("FULL PARTIAL FLAG")="P"
 S AVPARAM("REMARKS")="For BLOCK AND MOVE"
 Q
 ;
 ; CANCEL(RETURN,APPTIEN,ORIGINALCLINIC,DFN,CANCELBY,CANREASON,NOTE) ;
CANCEL(RETURN,PARAMS,SDCONTEXT) ;
 N SDRETURN,SDERRORS
 ; ** Required Parameters **
 ; PARAMS("APPT IEN") = IEN of SDEC APPOINTMENT (#409.84) file record to be Cancelled
 ; PARAMS("CLINIC IEN") = Pointer to the HOSPITAL LOCATION (#44) file
 ; PARAMS("DFN") = Pointer to the PATIENT (#2) file
 ; PARAMS("CANCELLED BY") - Appt Cancelled By: C=CANCELLED BY CLINIC ; PC=CANCELLED BY PATIENT
 ; PARAMS("CANCEL REASON") - Cancellation Reason NAME in the CANCELLATION REASON (#409.2) file
 ; PARAMS("NOTE") - Comments related to the cancellation (optional)
 ;
 D TRY2CANCEL^SDES2CANCELAPPT(.SDRETURN,.SDCONTEXT,.PARAMS,.SDERRORS)
 I $D(SDERRORS) M RETURN=SDERRORS
 I '$D(SDERRORS) M RETURN=SDRETURN
 Q
 ;
CANCELAVAIL(CANAVAIL,SDCONTEXT,AVPARAMS) ;
 N CANCAVJSON,DECDATA
 ;
 D CANCEL^SDES2CANCLNAVAIL(.CANCAVJSON,.SDCONTEXT,.AVPARAMS)
 M CANAVAIL=CANCAVJSON
 Q
 ;
VALIDATE(ERRORS,CONTEXT,SDDUZ) ;
 N ORIGINALSLOTS,TARGETDATE,TARGETSLOTS,SINC,STARTOFDAY,APPTARRAY,ARY84,ARY44,ARY2
 ;
 S APPTIEN=$G(CONTEXT("APPT IEN"))
 S TARGETDATE=$G(CONTEXT("TARGET DATE TIME"))
 S TARGETCLINIC=$G(CONTEXT("TARGET CLINIC IEN"))
 D VALIDATEDATE(.ERRORS,.TARGETDATE,TARGETCLINIC)
 D VALIDATEAPPTIEN(.ERRORS,APPTIEN,TARGETDATE)
 D VALIDATECLINIC(.ERRORS,TARGETCLINIC)
 I $D(ERRORS) Q
 ;
 D PRIVILEGEDUSER(.ERRORS,TARGETCLINIC,SDDUZ)
 D VALIDATECLINOPEN(.ERRORS,TARGETCLINIC,TARGETDATE)
 D VALIDATELENGTHS(.ERRORS,$G(CONTEXT("RESOURCE IEN")),TARGETCLINIC,APPTIEN)
 D VALIDATETARGSLOT(.ERRORS,.TARGETSLOTS,TARGETCLINIC,TARGETDATE,APPTIEN)
 D VALIDATEORIGSLOT(.ERRORS,.ORIGINALSLOTS,$$GET1^DIQ(409.831,$$GET1^DIQ(409.84,$G(APPTIEN),.07,"I"),.04,"I"),$P($$FMTISO^SDAMUTDT($$GET1^DIQ(409.84,$G(APPTIEN),.01,"I")),"T"),$P($$GET1^DIQ(409.84,$G(APPTIEN),.01,"I"),".",2))
 Q
 ;
VALIDATETARGSLOT(ERRORS,TARGETSLOTS,TARGETCLINIC,TARGETSTARTDATE,APPTIEN) ;
 N SLOTS,SLOTNUM,DONE
 D GETCLAVAILABLTY^SDESCLINICAVAIL(.SLOTS,TARGETCLINIC,$$FMTISO^SDAMUTDT(TARGETSTARTDATE),$$FMTISO^SDAMUTDT($P(TARGETSTARTDATE,".")))
 D DECODE^XLFJSON("SLOTS","TARGETSLOTS")
 ;
 S SLOTNUM=0,DONE=0
 S SLOTNUM=$O(TARGETSLOTS("ClinAvail",SLOTNUM)) Q:'SLOTNUM!(DONE=1)  D
 .I $G(TARGETSLOTS("ClinAvail",SLOTNUM,"BeginTime"))=$$FMTISO^SDAMUTDT(TARGETSTARTDATE) D
 ..I '$G(TARGETSLOTS("ClinAvail",SLOTNUM,"SlotsAvail")) D ERRLOG^SDES2JSON(.ERRORS,470) S DONE=1 Q
 Q
 ;
VALIDATEORIGSLOT(ERRORS,ORIGINALSLOTS,ORIGINALCLINIC,APPTDATE,APPTSTARTTIME) ;
 N SLOTS,COUNT,SLOTNUM,DONE
 D GETSCHEDULE^SDESCLINDAILYSCH(.ORIGINALSLOTS,ORIGINALCLINIC,APPTDATE)
 D DECODE^XLFJSON("ORIGINALSLOTS","SLOTS")
 S SLOTNUM=0,DONE=0,COUNT=1
 F  S SLOTNUM=$O(SLOTS("ClinicSlot",SLOTNUM)) Q:'SLOTNUM!(DONE=1)  D
 .I $G(SLOTS("ClinicSlot",SLOTNUM,"StartTime"))=$E(APPTSTARTTIME_"0000",1,4) D
 ..I $G(SLOTS("ClinicSlot",SLOTNUM,"OpenSlots"))>1 D ERRLOG^SDES2JSON(.ERRORS,468) S DONE=1 Q
 I $$GET1^DIQ(44.003,$$GET44RECORDIENS^SDESCANAPPT2(ORIGINALCLINIC,$$GET1^DIQ(409.84,APPTIEN,.01,"I"),$$GET1^DIQ(409.84,APPTIEN,.05,"I")),9,"E")="OVERBOOK" D ERRLOG^SDES2JSON(.ERRORS,469)
 Q
 ;
VALIDATEAPPTIEN(ERRORS,APPTIEN,TARGETDATE) ;
 I APPTIEN="" D ERRLOG^SDES2JSON(.ERRORS,14) Q
 I APPTIEN'="",'$D(^SDEC(409.84,APPTIEN,0)) D ERRLOG^SDES2JSON(.ERRORS,15) Q
 I $P($$GET1^DIQ(409.84,APPTIEN,.01,"I"),".")'=$P($$GET1^DIQ(409.84,APPTIEN,.02,"I"),".") D ERRLOG^SDES2JSON(.ERRORS,462) Q
 I $$GET1^DIQ(409.84,APPTIEN,.12,"I")!($$GET1^DIQ(409.84,APPTIEN,.03,"I"))!($$GET1^DIQ(409.84,APPTIEN,.14,"I"))!($$GET1^DIQ(409.84,APPTIEN,.101,"I")) D ERRLOG^SDES2JSON(.ERRORS,463)
 Q
 ;
VALIDATECLINIC(ERRORS,TARGETCLINIC) ;
 I TARGETCLINIC="" D ERRLOG^SDES2JSON(.ERRORS,18) Q
 I TARGETCLINIC'="",'$D(^SC(TARGETCLINIC,0)) D ERRLOG^SDES2JSON(.ERRORS,19) Q
 Q
 ;
VALIDATECLINOPEN(ERRORS,TARGETCLINIC,TARGETDATE) ;
 N TIMECLINICOPENS
 S TIMECLINICOPENS=$$GET1^DIQ(44,TARGETCLINIC,1914,"I")
 I TIMECLINICOPENS="" S TIMECLINICOPENS=8
 ;
 I +$E($P(TARGETDATE,".",2)_"0000",1,4)<TIMECLINICOPENS D ERRLOG^SDES2JSON(.ERRORS,344)
 I '$G(^SC(TARGETCLINIC,"ST",$P(TARGETDATE,"."),0)) D ERRLOG^SDES2JSON(.ERRORS,466)
 Q
 ;
VALIDATELENGTHS(ERRORS,RESOURCEIEN,TARGETCLINIC,APPTIEN) ;
 I $$GET1^DIQ(44,TARGETCLINIC,1912)'=$$GET1^DIQ(44,$$GET1^DIQ(409.831,RESOURCEIEN,.04,"I"),1912) D ERRLOG^SDES2JSON(.ERRORS,500)
 I $$GET1^DIQ(409.84,APPTIEN,.18,"I")'=$$GET1^DIQ(44,$$GET1^DIQ(409.831,RESOURCEIEN,.04,"I"),1912) D ERRLOG^SDES2JSON(.ERRORS,507)
 Q
 ;
PRIVILEGEDUSER(ERRORS,TARGETCLINIC,SDDUZ) ;
 I $$GET1^DIQ(44,TARGETCLINIC,2500,"I")="Y" D
 .I '$D(^SC(TARGETCLINIC,"SDPRIV",SDDUZ,0)) D ERRLOG^SDES2JSON(.ERRORS,343)
 Q
 ;
VALIDATEDATE(ERRORS,DATE,CLINICIEN) ;
 I DATE="" D ERRLOG^SDES2JSON(.ERRORS,9) Q
 S DATE=$$ISOTFM^SDAMUTDT(DATE)
 I DATE=-1 D ERRLOG^SDES2JSON(.ERRORS,11) Q
 I '$P(DATE,".",2) D ERRLOG^SDES2JSON(.ERRORS,511) Q
 ; cant schedule on holiday if clinic does not allow
 I $$GET1^DIQ(44,CLINICIEN,1918.5,"I")'="Y",$D(^HOLIDAY($P(DATE,"."),0)) D ERRLOG^SDES2JSON(.ERRORS,465)
 Q
 ;
BUILDAPPTARRAY(APPOINTMENT,PARAMS) ;
 N ORIGINALAPPT,TARGETDATE,TARGETCLINIC,APPTIEN,FMDATETIME
 S APPTIEN=PARAMS("APPT IEN")
 S TARGETDATE=PARAMS("TARGET DATE TIME")
 S FMDATETIME=$$ISOTFM^SDAMUTDT(TARGETDATE)
 S TARGETCLINIC=PARAMS("TARGET CLINIC IEN")
 D GETS^DIQ(409.84,APPTIEN,"*","ZI","ORIGINALAPPT")
 ;
 S APPOINTMENT("START DATE TIME")=TARGETDATE
 S APPOINTMENT("END DATE TIME")=$$FMTISO^SDAMUTDT($$FMADD^XLFDT(FMDATETIME,,,$$GET1^DIQ(409.84,APPTIEN,.18,"I")))
 S APPOINTMENT("DFN")=$G(ORIGINALAPPT(409.84,APPTIEN_",",.05,"I"))
 S APPOINTMENT("RESOURCE IEN")=$$GETRES^SDESINPUTVALUTL(TARGETCLINIC,1)
 S APPOINTMENT("WALKIN")="N"
 S APPOINTMENT("PATIENT INDICATED DATE")=$$FMTISO^SDAMUTDT($G(ORIGINALAPPT(409.84,APPTIEN_",",.2,"I")))
 S APPOINTMENT("EXTERNAL ID")=""
 S APPOINTMENT("REQUEST TYPE")=$E($$GET1^DIQ(409.84,APPTIEN,.22,"E"),1,1)_"|"_$P($G(ORIGINALAPPT(409.84,APPTIEN_",",.22,"I")),";",1)
 S APPOINTMENT("PROVIDER IEN")=$G(ORIGINALAPPT(409.84,APPTIEN_",",.16,"I"))
 S APPOINTMENT("CLINIC IEN")=TARGETCLINIC
 S APPOINTMENT("NOTE")=$G(ORIGINALAPPT(409.84,APPTIEN_",",.1,"I"))
 S APPOINTMENT("APPOINTMENT TYPE")=""
 S APPOINTMENT("APPOINTMENT TYPE NAME")=$$GET1^DIQ(409.1,$G(ORIGINALAPPT(409.84,APPTIEN_",",.06,"I")),.01,"E")
 S APPOINTMENT("PATIENT STATUS")=$G(ORIGINALAPPT(409.84,APPTIEN_",",.23,"I"))
 S APPOINTMENT("APPOINTMENT LENGTH")=$G(ORIGINALAPPT(409.84,APPTIEN_",",.18,"I"))
 S APPOINTMENT("SERVICE CONNECTED")=""
 S APPOINTMENT("SERVICE CONNECTED PERCENTAGE")=""
 I $$GET1^DIQ(409.85,$P($G(ORIGINALAPPT(409.84,APPTIEN_",",.22,"I")),";"),43.8) D
  . S APPOINTMENT("MRTC")="TRUE"
  . S APPOINTMENT("MRTC PARENT")=$$GET1^DIQ(409.85,$P($G(ORIGINALAPPT(409.84,APPTIEN_",",.22,"I")),";"),43.8)
 S APPOINTMENT("APPOINTMENT REASON")="TEST"
 S APPOINTMENT("PATIENT ELIGIBILITY")=2
 S APPOINTMENT("OVERBOOK")=""
 S APPOINTMENT("LAB DATE TIME")=""
 S APPOINTMENT("XRAY DATE TIME")=""
 S APPOINTMENT("EKG DATE TIME")=""
 S APPOINTMENT("PURPOSE")=3
 S APPOINTMENT("COLLATERAL")=""
 S APPOINTMENT("SCHEDULE REQUEST TYPE")="P"
 S APPOINTMENT("NEXT AVAILABLE APPOINTMENT")=0
 S APPOINTMENT("FOLLOWUP")="" Q
 ;