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

SDESAPTREQSET.m

Go to the documentation of this file.
SDESAPTREQSET   ;ALB/TAW,KML,RRM,MGD - APPOINTMENT REQUEST CREATE / UPDATE ;July 19, 2022
 ;;5.3;Scheduling;**794,799,805,809,815,818,819,820**;Aug 13, 1993;Build 10
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 Q
 ;
ARSET(RETURN,ARIEN,DFN,EDT,INST,TYPE,CLIN,USER,REQBY,PROV,DAPTDT,COMM,ENPRI,MAR,MAI,MAN,PATCONT,SVCCON,SVCCOP,MRTCPREFDT,STOP,APTYP,PATSTAT,MULTIAPTMADE,PARENT,NLT,PRER,ORDN,VAOSGUID,EAS,PCMT,INSTIEN,PATDATEPREFS,ARSTOPSEC,MODALITY) ;
 ;Refer SDESARSETDESC for the input param desc
 ;
 N POP,SDAPTREQ,X,Y,ARORIGDT,ARORIGDTI,FNUM,INSTI,ARTEAM,ARPOS,ARSRVSP,MI,STOPIEN,EDIT,EDITPATCOM,DATERANGE1,DATERANGE2,DATERANGE3
 N ARPRIO,AREESTAT,FDA,ARNEW,ARRET,ARMSG,ARDATA,ARERR,ARHOSN,AUDF,SDREC,ARPATTEL,DATE,RANGE,ARYIEN
 D VALIDATE
 I 'POP D
 .I +ARIEN D UPDATE
 .I +ARIEN=0 D CREATE
 .I 'POP D FILE
 D BUILDER
 Q
VALIDATE ;
 S (POP,AUDF)=0
 S FNUM=$$FNUM^SDECAR
 S ARIEN=$G(ARIEN,"")
 I ARIEN S EDIT=1
 ;If the Update RPC is called and no ARIEN is sent then it will show as -1
 I ARIEN'="" D
 .I ARIEN=-1 S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,3) Q
 .I '$D(^SDEC(409.85,ARIEN)) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,4)
 S DFN=$G(DFN,"")
 I ARIEN="" D
 .I DFN="" S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,1)
 .I DFN'="",'$D(^DPT(DFN,0)) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,2)
 ;Originating Dt/Tm
 S EDT=$G(EDT,"")
 I ARIEN="",EDT="" S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,48)
 I EDT'="" S EDT=$$CALLDT(EDT)  ; vse-2396
 I EDT=-1 S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,49)
 S ARORIGDT=$P(EDT,".",1)
 ;Institution IEN based on #99
 S INSTIEN=$G(INSTIEN,"")
 I INSTIEN'="" S INSTIEN=$$FIND1^DIC(4,"","X",INSTIEN,"D")
 ;Institution IEN based on #.01
 S INST=$G(INST,"")
 I INST'="" S INST=$$FIND1^DIC(4,"","X",INST,"B")
 I 'INSTIEN,'INST S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,185)
 ;Appt Request Type
 S TYPE=$G(TYPE,"")
 S:TYPE="APPOINTMENT" TYPE="APPT"
 I ARIEN="",TYPE="" S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,60)
 ;Clinic name/number
 S CLIN=$G(CLIN,"")
 I CLIN'="" D
 .I +CLIN=CLIN D
 ..I '$D(^SC(+CLIN,0)) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,19)
 .I +CLIN'=CLIN D
 ..S CLIN=$O(^SC("B",CLIN,0))
 ..I CLIN="" S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,51)
 ;User
 S USER=$G(USER,"")
 I USER'="",'+USER S USER=$O(^VA(200,"B",USER,0))
 I USER="" S USER=DUZ
 ;Requested by
 S REQBY=$G(REQBY,"")
 I REQBY'="" D
 .S REQBY=$S(REQBY="PATIENT":2,REQBY="PROVIDER":1,1:"")
 I ARIEN="",REQBY="" S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,62)
 ;Provider name
 S PROV=$G(PROV,"")
 I PROV'="" S PROV=$O(^VA(200,"B",PROV,0))
 ;Desired date of appt
 S DAPTDT=$G(DAPTDT,"")
 S ARPRIO=""
 I ARIEN="",DAPTDT="" S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,57)
 I DAPTDT'="" D
 .S DAPTDT=$$CALLDT(DAPTDT)  ;vse-2396
 .I DAPTDT=-1 S DAPTDT="",POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,58) Q
 .I ARIEN="",DAPTDT<DT S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,59) Q  ;Only validate on Create
 .S ARPRIO=$S(DAPTDT=$P($$NOW^XLFDT,".",1):"A",1:"F") ;Priority ASAP or Future
 ;comment
 S COMM=$TR($G(COMM),"^"," ")
 ;Enrollment Prio
 S ENPRI=$G(ENPRI,"")
 S:ENPRI'="" ENPRI=$S(ENPRI="GROUP 1":1,ENPRI="GROUP 2":2,ENPRI="GROUP3":3,ENPRI="GROUP4":4,ENPRI="GROUP 5":5,ENPRI="GROUP 6":6,ENPRI="GROUP 7":7,ENPRI="GROUP 8":8,1:ENPRI)
 ;MRTC Yes/No
 S MAR=$G(MAR,"")
 I MAR'="" S MAR=$S(MAR="YES":1,1:0)
 ;Multi Apt IEN
 S MAI=$G(MAI,"")
 ;Multi Apt numbers
 S MAN=$G(MAN,"")
 ;Serv Connect Prio
 S SVCCON=$G(SVCCON,"")
 S:SVCCON'="" SVCCON=$S(SVCCON="YES":1,1:0)
 ;Serv Connect %
 S SVCCOP=$G(SVCCOP,"")
 I SVCCOP'="" S:(+SVCCOP<0)!(+SVCCOP>100) SVCCOP=""
 ;Clinic Stop Code
 S STOP=$G(STOP,"") ;
 I $G(STOP) D
 .S STOPIEN=0
 .S STOPIEN=$O(^DIC(40.7,"C",STOP,STOPIEN))
 .S STOP=STOPIEN
 I ARIEN="",CLIN="",STOP="" S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,63)
 I STOP'="",CLIN'="" S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,52,"Cannot include both Clinic Name and Clinic Stop.")
 I CLIN="",STOP="",ARSTOPSEC="" S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,63)
 I $G(ARSTOPSEC)'="" S ARSTOPSEC=$$FIND1^DIC(40.7,"","X",ARSTOPSEC,"C") I '$G(ARSTOPSEC) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,214)
 I ARSTOPSEC'="",CLIN'="" S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,219)
 ;Appt Type#
 S APTYP=+$G(APTYP,"")
 I +APTYP,'$D(^SD(409.1,APTYP,0)) S APTYP=""
 ;Pat Status
 S PATSTAT=$G(PATSTAT,"")
 I PATSTAT'="" S PATSTAT=$S(PATSTAT="N":"N",PATSTAT="NEW":"N",PATSTAT="E":"E",PATSTAT="ESTABLISHED":"E",1:"")
 ;Parent Request
 S PARENT=+$G(PARENT,"")
 I +PARENT,'$D(^SDEC(409.85,+PARENT,0)) S PARENT=""
 ;No Later Than
 S NLT=+$G(NLT,"")
 I +PARENT>0&(+$G(NLT)=0) S NLT=$P($G(^SDEC(409.85,+PARENT,7)),"^",2)
 ;Prerequisite
 S PRER=$G(PRER,"")
 I +PARENT>0&(PRER="") D
 .N PRIEN,PR
 .S PRIEN=0 F  S PRIEN=$O(^SDEC(409.85,+PARENT,8,PRIEN)) Q:PRIEN'>0  D
 ..S PR=$P($G(^SDEC(409.85,+PARENT,8,PRIEN,0)),"^")
 ..S:PR'="" PRER=$S(PRER'="":PRER_";"_PR,1:PR)
 ;Order IEN
 S ORDN=+$G(ORDN)
 I +PARENT>0&(+$G(ORDN)=0) S ORDN=$P($G(^SDEC(409.85,+PARENT,7)),"^",1)
 ;VAOS ID
 S VAOSGUID=$G(VAOSGUID,"")
 ;EAS
 S EAS=$TR($G(EAS),"^"," ")
 I $L(EAS) S EAS=$$EASVALIDATE^SDESUTIL(EAS)
 I EAS=-1 S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,142)
 S PCMT=$TR($G(PCMT),"^"," ")
 ;preferred dates
 I $D(PATDATEPREFS) D
 .S ARYIEN=0
 .F  S ARYIEN=$O(PATDATEPREFS(ARYIEN)) Q:'ARYIEN  D
 ..S DATE=$G(PATDATEPREFS(ARYIEN))
 ..S DATE=$$ISOTFM^SDAMUTDT($G(DATE),CLIN)
 ..I $G(DATE)=-1!($L(DATE,".")=1) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,46) Q
 I $G(PATDATEPREFS(1)),'$G(PATDATEPREFS(2)) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,195)
 I $G(PATDATEPREFS(3)),'$G(PATDATEPREFS(4)) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,195)
 I $G(PATDATEPREFS(5)),'$G(PATDATEPREFS(6)) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,195)
 I $G(MODALITY)'="",$$VALIDATEMODALITY^SDESINPUTVALUTL(.SDAPTREQ,MODALITY) S POP=1
 Q
 ;
CREATE ;Build FDA array to add a new entry in 409.85
 S AUDF=1
 S FDA=$NA(FDA(FNUM,"+1,"))
 S @FDA@(.01)=+DFN
 S:$G(ARORIGDT)'="" @FDA@(1)=ARORIGDT
 S:$G(INSTIEN)'="" @FDA@(2)=INSTIEN
 S:$G(INSTIEN)=""&($G(INST)'="") @FDA@(2)=INST
 S:$G(TYPE)'="" @FDA@(4)=TYPE
 S:$G(VAOSGUID)'="" @FDA@(5)=VAOSGUID
 S:$G(MODALITY)'="" @FDA@(6)=MODALITY
 S:$G(CLIN)'="" @FDA@(8)=+CLIN
 S:$G(STOP)'="" @FDA@(8.5)=+STOP
 S:$G(ARSTOPSEC)'="" @FDA@(8.6)=+ARSTOPSEC
 S:+APTYP @FDA@(8.7)=+APTYP
 S:$G(USER)'="" @FDA@(9)=+USER
 S:$G(EDT)'="" @FDA@(9.5)=EDT
 S:$G(ARPRIO)'="" @FDA@(10)=ARPRIO
 S:$G(ENPRI)'="" @FDA@(10.5)=ENPRI
 S:$G(REQBY)'="" @FDA@(11)=REQBY
 S:$G(PROV)'="" @FDA@(12)=+PROV
 S:$G(DAPTDT)'="" @FDA@(13)=DAPTDT
 S:$G(SVCCOP)'="" @FDA@(14)=SVCCOP
 S:$G(SVCCON)'="" @FDA@(15)=+SVCCON
 S:$G(DAPTDT)'="" @FDA@(22)=DAPTDT
 S:$G(NLT)'="" @FDA@(47)=NLT
 S:EAS'="" @FDA@(100)=EAS
 D FDAPRER(.FDA,PRER,"+1")
 S:$G(ORDN)'="" @FDA@(46)=ORDN
 S @FDA@(23)="O"
 S:$G(COMM)'="" @FDA@(25)=COMM
 S:$G(MAR)'="" @FDA@(41)=MAR
 I +MAR,$G(MAI)'="" S @FDA@(42)=MAI
 I +MAR,$G(MAN)'="" S @FDA@(43)=MAN
 S:PATSTAT'="" @FDA@(.02)=PATSTAT
 S:+PARENT @FDA@(43.8)=+PARENT
 I $G(PARENT) D
 .S @FDA@(43.1)=$$MRTCHILDSEQUENCE^SDECAR2($G(PARENT),$G(DFN))
 Q
 ;
UPDATE ;
 S ARIEN=ARIEN_","
 K ARDATA,ARERR
 D GETS^DIQ(FNUM,ARIEN,"*","IE","ARDATA","ARERR")
 I $D(ARERR) D  Q
 .S POP=1
 .K FDA
 .F MI=1:1:$G(ARERR("DIERR")) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,48,$G(ARERR("DIERR",MI,"TEXT",1)))
 S FDA=$NA(FDA(FNUM,ARIEN))
 I ARORIGDT'="" D
 .S ARORIGDT=$P(ARORIGDT,"@",1) S ARORIGDTI=$$CALLDT(ARORIGDT)
 .I ARORIGDTI'=ARDATA(FNUM,ARIEN,1,"I") S @FDA@(1)=$S(ARORIGDT="":"@",1:ARORIGDT)
 I INSTIEN'="",INSTIEN'=ARDATA(FNUM,ARIEN,2,"I") S @FDA@(2)=INSTIEN
 I INSTIEN="",INST'="" S @FDA@(2)=INST
 I TYPE'="",TYPE'=ARDATA(FNUM,ARIEN,4,"I") S @FDA@(4)=TYPE
 I VAOSGUID'="",VAOSGUID'=ARDATA(FNUM,ARIEN,5,"I") S @FDA@(5)=VAOSGUID
 I MODALITY'="",MODALITY'=ARDATA(FNUM,ARIEN,6,"I") S @FDA@(6)=MODALITY
 I CLIN'="",CLIN'=ARDATA(FNUM,ARIEN,8,"I") S @FDA@(8)=+CLIN,AUDF=1 D
 .I ARDATA(FNUM,ARIEN,8.5,"I")'="" S @FDA@(8.5)="@",@FDA@(8.6)="@"
 I STOP'="",STOP'=ARDATA(FNUM,ARIEN,8.5,"I") S @FDA@(8.5)=+STOP,AUDF=1 S:ARDATA(FNUM,ARIEN,8,"I")'="" @FDA@(8)="@"
 I ARSTOPSEC'="",ARSTOPSEC'=ARDATA(FNUM,ARIEN,8.6,"I") S @FDA@(8.6)=+ARSTOPSEC,AUDF=1 S:ARDATA(FNUM,ARIEN,8,"I")'="" @FDA@(8)="@"
 S:+APTYP @FDA@(8.7)=+APTYP
 I USER'="",USER'=ARDATA(FNUM,ARIEN,9,"I") S @FDA@(9)=+USER
 I EDT'="",EDT'=$G(ARDATA(FNUM,ARIEN,9.5,"I")) S @FDA@(9.5)=EDT
 I ARPRIO'="",ARPRIO'=ARDATA(FNUM,ARIEN,10,"I") S @FDA@(10)=$S(ARPRIO="":"@",1:ARPRIO)
 I ENPRI'="",ENPRI'=ARDATA(FNUM,ARIEN,10.5,"I") S @FDA@(10.5)=ENPRI
 I REQBY'="",REQBY'=ARDATA(FNUM,ARIEN,11,"I") S @FDA@(11)=$S(REQBY="":"@",1:REQBY)
 I PROV'="",PROV'=ARDATA(FNUM,ARIEN,12,"I") S @FDA@(12)=+PROV
 I SVCCOP'="",SVCCOP'=$G(ARDATA(FNUM,ARIEN,14,"I")) S @FDA@(14)=SVCCOP
 I SVCCON'="",SVCCON'=ARDATA(FNUM,ARIEN,15,"I") S @FDA@(15)=+SVCCON
 I DAPTDT'="",DAPTDT'=ARDATA(FNUM,ARIEN,22,"I") S @FDA@(22)=$S(DAPTDT="":"@",1:DAPTDT)
 I COMM'="",COMM'=ARDATA(FNUM,ARIEN,25,"I") S @FDA@(25)=$S(COMM="":"@",1:COMM)
 S:MAR'="" @FDA@(41)=MAR
 S:MAI'="" @FDA@(42)=MAI
 S:MAN'="" @FDA@(43)=MAN
 S:NLT'="" @FDA@(47)=NLT
 S:EAS'="" @FDA@(100)=EAS
 D DELPRER(+ARIEN)
 D FDAPRER(.FDA,PRER,+ARIEN)
 S:ORDN'="" @FDA@(46)=ORDN
 S:PATSTAT'="" @FDA@(.02)=PATSTAT
 S:+PARENT @FDA@(43.8)=+PARENT
 Q
 ;
DELPRER(ARIEN) ;Delete all entries in the PREREQUISITE multiple (#48)
 N DIK,DA
 Q:$G(ARIEN)'=+$G(ARIEN)  Q:ARIEN'>0
 S DIK="^SDEC(409.85,"_ARIEN_",8,",DA(1)=ARIEN
 S DA=0 F  S DA=$O(^SDEC(409.85,ARIEN,8,DA)) Q:DA'>0  D ^DIK
 Q
 ;
FDAPRER(FDA,PRER,ARIEN) ;Setup the FDA array for the PREREQUISITE mult (#48)
 N ASEQ,DELIM,PC,PR
 Q:$G(PRER)=""
 S DELIM=";",ASEQ=80
 F PC=1:1:$L(PRER,DELIM) D
 .S PR=$P(PRER,DELIM,PC) Q:PR=""
 .S ASEQ=ASEQ+1,FDA(409.8548,"+"_ASEQ_","_ARIEN_",",.01)=PR
 Q
 ;
FILE ;Perform file update
 ;Only call UPDATE^DIE if there are entries in FDA
 D:$D(FDA)>9 UPDATE^DIE("","FDA","ARRET","ARMSG")
 I $D(ARMSG) D  Q
 . F MI=1:1:$G(ARMSG("DIERR")) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,48,$G(ARMSG("DIERR",MI,"TEXT",1)))
 N IEN
 S IEN=$S(+ARIEN:+ARIEN,1:ARRET(1))
 S INSTI=$P($G(^SDEC(409.85,IEN,0)),U,3)
 I $G(PATCONT)'="" D AR23(PATCONT,IEN)   ;Pat contacts
 I +MAR,$G(MRTCPREFDT)'="" D AR435(MRTCPREFDT,IEN)   ;MRTC CALC PREF DATES
 I +AUDF D ARAUD(IEN,CLIN,STOP)   ;VS AUDIT
 I $G(MULTIAPTMADE)'="" D
 .N SDI
 .F SDI=1:1:$L(MULTIAPTMADE,"|") S SDREC=$P(MULTIAPTMADE,"|",SDI) D AR433(IEN,SDREC)
 I +PARENT D AR433(+PARENT,"~"_IEN)
 ;file Pat entered comments if any sent
 I PCMT]"",PCMT'["Patient preferred date range" D ARPCMT(IEN,PCMT)
 ;file Pat date preferences in comments mult
 I $D(PATDATEPREFS(1)),$D(PATDATEPREFS(2)),'$G(EDIT) D
 .S PATDATEPREFS(1)=$$ISOTFM^SDAMUTDT(PATDATEPREFS(1),CLIN),PATDATEPREFS(1)=$$FMTE^XLFDT(PATDATEPREFS(1))
 .S PATDATEPREFS(2)=$$ISOTFM^SDAMUTDT(PATDATEPREFS(2),CLIN),PATDATEPREFS(2)=$$FMTE^XLFDT(PATDATEPREFS(2))
 .S RANGE(1)="Patient preferred date range #1: "_PATDATEPREFS(1)_" to "_PATDATEPREFS(2)
 .I $D(PATDATEPREFS(3)),$D(PATDATEPREFS(4)) D
 ..S PATDATEPREFS(3)=$$ISOTFM^SDAMUTDT(PATDATEPREFS(3),CLIN),PATDATEPREFS(3)=$$FMTE^XLFDT(PATDATEPREFS(3))
 ..S PATDATEPREFS(4)=$$ISOTFM^SDAMUTDT(PATDATEPREFS(4),CLIN),PATDATEPREFS(4)=$$FMTE^XLFDT(PATDATEPREFS(4))
 ..S RANGE(2)="Patient preferred date range #2: "_PATDATEPREFS(3)_" to "_PATDATEPREFS(4)
 .I $D(PATDATEPREFS(5)),$D(PATDATEPREFS(6)) D
 ..S PATDATEPREFS(5)=$$ISOTFM^SDAMUTDT(PATDATEPREFS(5),CLIN),PATDATEPREFS(5)=$$FMTE^XLFDT(PATDATEPREFS(5))
 ..S PATDATEPREFS(6)=$$ISOTFM^SDAMUTDT(PATDATEPREFS(6),CLIN),PATDATEPREFS(6)=$$FMTE^XLFDT(PATDATEPREFS(6))
 ..S RANGE(3)="Patient preferred date range #3: "_PATDATEPREFS(5)_" to "_PATDATEPREFS(6)
 .D WP^DIE(409.85,IEN_",",60,"A","RANGE")
 I $G(EDIT) D
 .I PCMT'["Patient preferred date range" S EDITPATCOM(1)=PCMT D WP^DIE(409.85,IEN_",",60,"","EDITPATCOM") Q
 .S EDITPATCOM(1)=$P($G(PCMT),"Patient preferred date range",1)
 .S DATERANGE1=$P($G(PCMT),"Patient preferred date range",2) I $L($G(DATERANGE1)) S EDITPATCOM(2)="Patient preferred date range"_$P($G(PCMT),"Patient preferred date range",2)
 .S DATERANGE2=$P($G(PCMT),"Patient preferred date range",3) I $L($G(DATERANGE2)) S EDITPATCOM(3)="Patient preferred date range"_$P($G(PCMT),"Patient preferred date range",3)
 .S DATERANGE3=$P($G(PCMT),"Patient preferred date range",4) I $L($G(DATERANGE3)) S EDITPATCOM(4)="Patient preferred date range"_$P($G(PCMT),"Patient preferred date range",4)
 .D WP^DIE(409.85,IEN_",",60,"","EDITPATCOM")
 I +$G(ARRET(1)) S SDAPTREQ("AptReqCreate","IEN")=IEN
 E  S SDAPTREQ("AptReqUpdate","IEN")=IEN
 Q
 ;
ARPCMT(ARIEN,COMMENTSFLD60) ;populate word processing PATIENT COMMENTS (409.855,60)
 ;ARIEN-(req)IEN to entry in 409.85
 ;COMMENTSFLD60-(opt)VAOS related patient-entered comments
 N SDFDA,PCMTSARRAY
 S COMMENTSFLD60=$G(COMMENTSFLD60)
 D WP^SDECUTL(.PCMTSARRAY,COMMENTSFLD60)
 D WP^DIE(409.85,ARIEN_",",60,"","PCMTSARRAY")
 Q
 ;
ARAUD(ARIEN,CLIN,STOP,DATE,USER) ;populate VS AUDIT mult field 45
 ;ARIEN-(req)pointer to SDEC APPT REQUEST file 409.85
 ;CLIN-(opt)pointer to HOSPITAL LOCATION file 44
 ;STOP-(opt)pointer to CLINIC STOP file
 ;DATE-(opt)dt/tm in FileMan format
 N SDFDA,SDP,SDPN,ERRARRY
 S ARIEN=$G(ARIEN) Q:ARIEN=""
 S CLIN=$G(CLIN)
 S STOP=$G(STOP)
 S SDP=$O(^SDEC(409.85,ARIEN,6,9999999),-1)
 I +SDP S SDPN=^SDEC(409.85,ARIEN,6,SDP,0) I $P(SDPN,U,3)=CLIN,$P(SDPN,U,4)=STOP Q
 S DATE=$G(DATE) S:DATE="" DATE=$E($$NOW^XLFDT,1,12)
 S USER=$G(USER) S:USER="" USER=DUZ
 S SDFDA(409.8545,"+1,"_ARIEN_",",.01)=DATE
 S SDFDA(409.8545,"+1,"_ARIEN_",",1)=USER
 S:CLIN'="" SDFDA(409.8545,"+1,"_ARIEN_",",2)=CLIN
 S:STOP'="" SDFDA(409.8545,"+1,"_ARIEN_",",3)=STOP
 D UPDATE^DIE("","SDFDA",,"ERRARRY")
 Q
 ;
AR433(ARIEN,SDEC) ;set MULT APPTS MADE
 ;INPUT:
 ; ARIEN=(req)pointer to SDEC APPT REQUEST file 409.85
 ;
 ;
 N SDAPP,SDFDA,SDI,SDIEN,ERRARRY
 S ARIEN=$G(ARIEN)
 Q:'$D(^SDEC(409.85,ARIEN,0))
 S SDEC=$G(SDEC)
 F SDI=1:1:$L(SDEC,"|") D
 .K SDFDA
 .S SDAPP=$P(SDEC,"|",SDI)
 .I $P(SDAPP,"~",2)="",$P(SDAPP,"~",1)'="" S $P(SDAPP,"~",2)=$P($$GET1^DIQ(409.84,+SDAPP_",",.22,"I"),";",1)
 .Q:$P(SDAPP,"~",2)=""
 .S SDIEN=$O(^SDEC(409.85,ARIEN,2,"B",$P(SDAPP,"~",2),0))
 .S SDIEN=$S(SDIEN'="":SDIEN,1:"+1")
 .I $D(^SDEC(409.85,+$P(SDAPP,"~",2),0)) S SDFDA(409.852,SDIEN_","_ARIEN_",",.01)=+$P(SDAPP,"~",2)
 .I $D(^SDEC(409.84,+$P(SDAPP,"~",1),0)) S SDFDA(409.852,SDIEN_","_ARIEN_",",.02)=+$P(SDAPP,"~",1)
 .D:$D(SDFDA) UPDATE^DIE("","SDFDA",,"ERRARRY")
 Q
 ;
AR435(SDDT,ARIEN) ;set dates into MRTC CALC PREF DATES mult field 43.5
 ;INPUT:
 ; ARIEN-Requested date ID pointer to SDEC REQUESTED APPT file 409.85
 ; SDDT -MRTC calculated preferred dates separated by pipe |. Each date can be in external format with no time.
 N SDI,SDJ,SDFDA,TMPDT,ERRARRY
 F SDI=1:1:$L(SDDT,"|") D
 .S TMPDT=$P($P(SDDT,"|",SDI),"@",1)
 .S SDJ=$$CALLDT(TMPDT)
 .Q:SDJ=-1
 .Q:$O(^SDEC(409.85,ARIEN,5,"B",SDJ,0))  ;don't add duplicates
 .S SDFDA(409.851,"+1,"_ARIEN_",",.01)=SDJ
 .D UPDATE^DIE("","SDFDA",,"ERRARRY")
 Q
 ;
AR23(INP17,ARI) ;Pat Contacts
 N STR17,ARASDH,ARDATA1,ARERR1,ARI1,ARIENS,ARIENS1,ARRET1,FDA,ARMSG1
 N ARDT,ARUSR
 S ARIENS=ARI_","
 F ARI1=1:1:$L(INP17,"::") D
 .S STR17=$P(INP17,"::",ARI1)
 .K FDA
 .;Change date conversion to deal with midnight. 5/29/18 wtc patch 694
 .S ARDT=$P($P(STR17,"~~",1),":",1,2)
 .S ARDT=$$CALLDT(ARDT)
 .I (ARDT=-1)!(ARDT="") Q
 .S ARASDH=""
 .S ARIENS1=$S(ARASDH'="":ARASDH,1:"+1")_","_ARIENS
 .S FDA=$NA(FDA(409.8544,ARIENS1))
 .I ARASDH'="" D
 ..D GETS^DIQ(409.8544,ARIENS1,"*","IE","ARDATA1","ARERR1")
 ..I $P(STR17,"~~",1)'="" S @FDA@(.01)=ARDT ;DATE ENTERED external dt/tm
 ..I $P(STR17,"~~",2)'="" S ARUSR=$P(STR17,"~~",2) S @FDA@(2)=$S(ARUSR="":"@",+ARUSR:$P($G(^VA(200,ARUSR,0)),U,1),1:USER) ;PC ENTERED BY USER
 ..I $P(STR17,"~~",4)'="" S @FDA@(3)=$P(STR17,"~~",4) ;ACTION  C=Called; M=Message Left; L=LETTER
 ..I $P(STR17,"~~",5)'="" S @FDA@(4)=$P(STR17,"~~",5) ;PATIENT PHONE
 .I ARASDH="" D
 ..I $P(STR17,"~~",1)'="" S @FDA@(.01)=ARDT ;DATE ENTERED external dt/tme
 ..I $P(STR17,"~~",2)'="" S ARUSR=$P(STR17,"~~",2) S @FDA@(2)=$S(ARUSR="":"@",+ARUSR:$P($G(^VA(200,ARUSR,0)),U,1),1:ARUSR) ;PC ENTERED BY USER
 ..I $P(STR17,"~~",4)'="" S @FDA@(3)=$P(STR17,"~~",4) ;ACTION  C=Called; M=Message Left; L=LETTER
 ..I $P(STR17,"~~",5)'="" S @FDA@(4)=$P(STR17,"~~",5) ;PATIENT PHONE
 .D:$D(@FDA) UPDATE^DIE("E","FDA",,"ARMSG1")
 Q
CALLDT(X) ;
 Q $$ISOTFM^SDAMUTDT(X)  ;VSE-2396
 ;
BUILDER ;Convert data to JSON
 N JSONERR
 S JSONERR=""
 D ENCODE^SDESJSON(.SDAPTREQ,.RETURN,.JSONERR)
 Q