SDES2CONTACTS ;ALB/LAB,MCB/TJB,JAS - VISTA SCHEDULING CONTACT SDES2 CONTACT ATTEMPTS ;Aug 28,2024
;;5.3;Scheduling;**860,873,878,887**;Aug 13, 1993;Build 7
;;Per VHA Directive 6402, this routine should not be modified
Q
;
ADDCONTACT(RESULT,SDCONTEXT,CONTACT) ; RPC: SDEC2 ADD CONTACT ATTEMPT
N ERRORS,DFN,CLINIC,PREFDATE,REQTYPE,DTTMOFCONTACT,CONTACTTYPE,COMMENTS,DTTMENTERED,REQUESTIEN,NEWCONTACT
N NEWIEN,APPTREQTYPE,FDA,NEWCONTIEN,SUBIENS,CONTACTIEN,SEQUENCE,LEFTMSG,NEWCONTATTMTIEN,VALID
;
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
I $D(ERRORS) S ERRORS("Contact",1)="",ERRORS("ContactAttempts")="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
;
D REQUESTINFO(.ERRORS,.CONTACT,.APPTREQTYPE,.REQUESTIEN,.REQTYP,.DFN,.CLINIC,.PREFDATE)
I $D(ERRORS) S ERRORS("Contact",1)="",ERRORS("ContactAttempts")="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
;
D ASSIGNVARS(.CONTACT,.REQTYPE,.DTTMOFCONTACT,.COMMENTS,.DTMENTERED,.LEFTMSG,.SDDUZ)
D VALIDATE(.ERRORS,REQTYPE,.DTTMOFCONTACT,COMMENTS,.DTTMENTERED,LEFTMSG,CONTACTTYPE,CLINIC)
I $D(ERRORS) S ERRORS("Contact",1)="",ERRORS("ContactAttempts")="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
;
D GETCONTACTIEN(.CONTACTIEN,APPTREQTYPE)
;
D:(CONTACTIEN'="") UPDATECONTACT(.RESULT,.FDA,CONTACTIEN,DTTMOFCONTACT,CONTACTTYPE,COMMENTS,SDDUZ,DTTMENTERED,LEFTMSG)
D:(CONTACTIEN="") CREATECONTACT(.RESULT,.FDA,DFN,CONTACTIEN,CLINIC,PREFDATE,REQTYPE,APPTREQTYPE,DTTMOFCONTACT,CONTACTTYPE,COMMENTS,SDDUZ,DTTMENTERED,LEFTMSG)
D SAVECONTACT(.ERRORS,.RESULT,.FDA,.NEWIEN)
D ASSIGNNEWIEN(.NEWCONTACTIEN,.CONTACTIEN,.NEWIEN)
D BLDRETNINFO(.NEWCONTACT,CONTACTIEN,CLINIC)
I '$D(NEWCONTACT) S NEWCONTACT("Contact",1)="",ERRORS("ContactAttempts")="" D BUILDJSON^SDES2JSON(.RESULT,.CONTACTS) Q
D DISPCONTACT(.NEWCONTACT,CONTACTIEN,CLINIC)
D BUILDJSON^SDES2JSON(.RESULT,.NEWCONTACT)
Q
;
ASSIGNNEWIEN(NEWCONTACTIEN,CONTACTIEN,NEWIEN) ;get the iens that were created during create/update
S:CONTACTIEN'="" NEWCONTATTMTIEN=$G(NEWIEN(1))
I CONTACTIEN="" D
.S CONTACTIEN=$G(NEWIEN(1))
.S NEWCONTATTMTIEN=$G(NEWIEN(2))
Q
;
GETCONTACTIEN(CONTACTIEN,APPTREQTYPE) ;if a contact attempt already exists, get it's ien
S CONTACTIEN=""
S:$D(^SDEC(409.86,"REQPTR",APPTREQTYPE)) CONTACTIEN=$O(^SDEC(409.86,"REQPTR",APPTREQTYPE,"A"),-1)
Q
;
BLDNEWCONT(FDA,IENS,DFN,CLINIC,PREFDATE,REQTYPE,APPTREQTYPE) ; build the new contact attempt record.
S FDA(409.86,IENS,.01)=DFN
S FDA(409.86,IENS,1)=CLINIC
S FDA(409.86,IENS,2)=PREFDATE
S FDA(409.86,IENS,2.1)=REQTYPE
; Main Sequence (2.2) is always set to 1 initially
S FDA(409.86,IENS,2.2)=1
S FDA(409.86,IENS,2.3)=APPTREQTYPE
Q
;
BLDNEWATTMPT(FDA,IENS,DTTMOFCONTACT,CONTACTTYPE,COMMENTS,SDDUZ,DTTMENTERED,LEFTMSG,SEQUENCE) ;add a new entry to existing contact attempt record.
S FDA(409.863,IENS,.01)=DTTMOFCONTACT
S FDA(409.863,IENS,1)=CONTACTTYPE
S FDA(409.863,IENS,2)=COMMENTS
S FDA(409.863,IENS,3)=$G(LEFTMSG)
; The first entry in this subfile will always be 1
S FDA(409.863,IENS,4)=SEQUENCE
S FDA(409.863,IENS,5)=$G(SDDUZ)
S FDA(409.863,IENS,6)=DTTMENTERED
Q
;
BLDRETNINFO(RESULT,IEN,CLINIC) ;build return result of contact attempts
N F,IENS,ERR,PREFDATE,STOPIEN,CONTDATA
S F=409.86,IENS=IEN_","
D GETS^DIQ(409.86,IENS,"**","IE","CONTDATA","ERR")
Q:$D(ERR)
I '$G(CLINIC) S CLINIC=$G(CONTDATA(F,IENS,1,"I"))
S PREFDATE=$$FMTISO^SDAMUTDT($G(CONTDATA(F,IENS,2,"I")),$G(CLINIC))
I PREFDATE<0 S PREFDATE=""
S RESULT("Contact","ID")=$P(IENS,",")
S RESULT("Contact","Patient")=$G(CONTDATA(F,IENS,.01,"I"))
S RESULT("Contact","Clinic")=$G(CONTDATA(F,IENS,1,"I"))
S STOPIEN=$$GET1^DIQ(44,CLINIC,8,"I")
S RESULT("Contact","ClinicStopCodeAMIS")=$$STOPCODETOAMIS^SDESUTIL(STOPIEN)
S RESULT("Contact","PreferredDate")=PREFDATE
S RESULT("Contact","RequestType")=$G(CONTDATA(F,IENS,2.1,"I"))
S RESULT("Contact","MainSequence")=$G(CONTDATA(F,IENS,2.2,"I"))
N SRVSTRING
S SRVSTRING=$$GETSRV($G(CONTDATA(F,IENS,2.1,"I")),+$G(CONTDATA(F,IENS,2.3,"I")))
S RESULT("Contact","Service")=$P($G(SRVSTRING),"^")
S RESULT("Contact","ServiceName")=$P($G(SRVSTRING),"^",2)
S RESULT("Contact","RequestPointer")=$G(CONTDATA(F,IENS,2.3,"I"))
K CONTDATA
Q
;
ASSIGNVARS(CONTACT,REQTYPE,DTTMOFCONTACT,COMMENTS,DTMENTERED,LEFTMSG,SDDUZ) ;assign variables used sent in from CONTACT array
S DTTMOFCONTACT=$G(CONTACT("DTTMOFCONTACT"))
S CONTACTTYPE=$G(CONTACT("CONTACTTYPE"))
S COMMENTS=$G(CONTACT("COMMENTS"))
S DTTMENTERED=$G(CONTACT("DTTMENTERED"))
S LEFTMSG=$G(CONTACT("LEFTMESSAGE"))
S:LEFTMSG="" LEFTMSG=0
S:$G(SDCONTEXT("USER DUZ"))'="" SDDUZ=$G(SDCONTEXT("USER DUZ"))
S:$G(SDCONTEXT("USER DUZ"))="" SDDUZ=DUZ
Q
;
VALIDATE(ERRORS,REQTYPE,DTTMOFCONTACT,COMMENTS,DTTMENTERED,LEFTMSG,CONTACTTYPE,CLINIC) ;validate input array values
D VALFIELD^SDES2VALUTIL(,.ERRORS,409.86,2.1,REQTYPE,,0,395,396)
D VALFIELD^SDES2VALUTIL(,.ERRORS,409.863,3,LEFTMSG,0,0,,402)
D VALFIELD^SDES2VALUTIL(,.ERRORS,409.863,2,COMMENTS,0,0)
D VALFIELD^SDES2VALUTIL(,.ERRORS,409.863,1,CONTACTTYPE,1,0)
S DTTMOFCONTACT=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,DTTMOFCONTACT,CLINIC,1,389,390) ;
S DTTMENTERED=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,DTTMENTERED,,1,387,388) ;
Q
;
REQUESTINFO(ERRORS,CONTACT,APPTREQTYPE,REQUESTIEN,REQTYP,DFN,CLINIC,PREFDATE,CONTACTIEN) ;
; Given the request ien and request type, return back information needed from request
N REQTYPEFOUND,VALID
S REQTYPEFOUND=0
S REQUESTIEN=$G(CONTACT("REQUESTIEN"))
S REQTYPE=$G(CONTACT("REQTYPE"))
I (REQTYPE="A")!(REQTYPE="RTC")!(REQTYPE="V") D
. D VALFILEIEN^SDES2VALUTIL(.VALID,.ERRORS,409.85,REQUESTIEN,1,0,3,4)
. Q:'VALID
. S DFN=$$GET1^DIQ(409.85,REQUESTIEN,.01,"I")
. S CLINIC=$$GET1^DIQ(409.85,REQUESTIEN,8,"I")
. S PREFDATE=$$GET1^DIQ(409.85,REQUESTIEN,22,"I")
. S APPTREQTYPE=REQUESTIEN_";"_"SDEC(409.85,"
. S REQTYPEFOUND=1
I (REQTYPE="C")!(REQTYPE="P") D
. D VALFILEIEN^SDES2VALUTIL(.VALID,.ERRORS,123,REQUESTIEN,1,0,3,4)
. Q:'VALID
. S DFN=$$GET1^DIQ(123,REQUESTIEN,.02,"I")
. S CLINIC=""
. S:$$GET1^DIQ(123,REQUESTIEN,17,"I")'="" PREFDATE=$$GET1^DIQ(123,REQUESTIEN,17,"I")
. S:$G(PREFDATE)="" PREFDATE=$$GET1^DIQ(123,REQUESTIEN,.01,"I")
. S APPTREQTYPE=REQUESTIEN_";"_"GMR(123,"
. S REQTYPEFOUND=1
I REQTYPE="R" D
. D VALFILEIEN^SDES2VALUTIL(.VALID,.ERRORS,403.5,REQUESTIEN,1,0,3,4)
. Q:'VALID
. S DFN=$$GET1^DIQ(403.5,REQUESTIEN,.01,"I")
. S CLINIC=$$GET1^DIQ(403.5,REQUESTIEN,4.5,"I")
. S PREFDATE=$$GET1^DIQ(403.5,REQUESTIEN,5,"I")
. S APPTREQTYPE=REQUESTIEN_";"_"SD(403.5,"
. S REQTYPEFOUND=1
I '$D(ERRORS)&('REQTYPEFOUND) D ERRLOG^SDES2JSON(.ERRORS,52,"Passed in Request Type invalid or not supported.")
Q
;
CREATECONTACT(RESULT,FDA,DFN,CONTACTIEN,CLINIC,PREFDATE,REQTYPE,APPTREQTYPE,DTTMOFCONTACT,CONTACTTYPE,COMMENTS,SDDUZ,DTTMENTERED,LEFTMSG) ;
;create a new contact attempt record
D BLDNEWCONT(.FDA,"+1,",DFN,CLINIC,PREFDATE,REQTYPE,APPTREQTYPE)
S SUBIENS="+2,+1,"
D BLDNEWATTMPT(.FDA,SUBIENS,DTTMOFCONTACT,CONTACTTYPE,COMMENTS,SDDUZ,DTTMENTERED,LEFTMSG,1)
Q
;
UPDATECONTACT(RESULT,FDA,CONTACTIEN,DTTMOFCONTACT,CONTACTTYPE,COMMENTS,SDDUZ,DTTMENTERED,LEFTMSG) ;
;update the contact attempt multiple with the new contact data
S SUBIENS="+1,"_CONTACTIEN_","
S SEQUENCE=$O(^SDEC(409.86,CONTACTIEN,1,9999),-1)+1
D BLDNEWATTMPT(.FDA,SUBIENS,DTTMOFCONTACT,CONTACTTYPE,COMMENTS,SDDUZ,DTTMENTERED,LEFTMSG,SEQUENCE)
Q
;
SAVECONTACT(ERRORS,RESULT,FDA,NEWIEN) ;file contact attempt in 409.86 file
NEW DIERR,FILERR
D UPDATE^DIE(,"FDA","NEWIEN","FILERR") K FDA
I $D(FILERR) D Q
.D ERRLOG^SDESJSON(.ERRORS,52,$G(FILERR("DIERR",1,"TEXT",1)))
.S ERRORS("Contact",1)=""
.D BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
Q
;
GETCONTACTS(RESULT,SDCONTEXT,REQARRAY) ; RPC: SDES2 GET CONTACT ATTEMPT
N REQTYPE,REQIEN,ERRORS,APPTREQTYPE,REQIEN,REQTYPE,DFN,CLINIC,PREFDATE,CONTACTS,CONTACTIEN
D ASSIGNREQVAR(.REQARRAY,.REQTYPE,.REQIEN)
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
I $D(ERRORS) S ERRORS("Contact",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
;
D VALFIELD^SDES2VALUTIL(,.ERRORS,409.86,2.1,REQTYPE,,0,395,396)
D REQUESTINFO(.ERRORS,.REQARRAY,.APPTREQTYPE)
I $D(ERRORS) S ERRORS("Contact",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
;
D GETCONTACTIEN(.CONTACTIEN,APPTREQTYPE)
I $G(CONTACTIEN)="" S CONTACTS("Contact",1)="",CONTACTS("ContactAttempts")="" D BUILDJSON^SDES2JSON(.RESULT,.CONTACTS) Q
D BLDRETNINFO(.CONTACTS,CONTACTIEN)
D DISPCONTACT(.CONTACTS,CONTACTIEN)
D BUILDJSON^SDESBUILDJSON(.RESULT,.CONTACTS)
Q
;
ASSIGNREQVAR(REQARRAY,REQTYPE,REQIEN) ;
S REQTYPE=$G(REQARRAY("REQTYPE"))
S REQIEN=$G(REQARRAY("REQUESTIEN"))
Q
;
DISPCONTACT(RESULT,CONTACTIEN,CLINIC) ;get contact attempt information given contact ien
N ERRORS,CONTMULT,CIENS,CONTDATA,CCNT,CONTACTS,CONTDATE,DTTMENTERED
;
S CONTACTIEN=$G(CONTACTIEN)
S CCNT=0
S CONTMULT=0 F S CONTMULT=$O(^SDEC(409.86,CONTACTIEN,1,CONTMULT)) Q:'CONTMULT D
.S CIENS=CONTMULT_","_CONTACTIEN_","
.D GETS^DIQ(409.863,CIENS,"**","IE","CONTDATA")
.I '$G(CLINIC) S CLINIC=$$GET1^DIQ(409.86,CONTACTIEN,1,"I")
.S CCNT=CCNT+1
.S CONTDATE=$G(CONTDATA(409.863,CIENS,.01,"I"))
.S CONTDATE=$$FMTISO^SDAMUTDT(CONTDATE,$G(CLINIC))
.S CONTACTS("ContactAttempts",CCNT,"DateTimeOfContact")=CONTDATE
.S CONTACTS("ContactAttempts",CCNT,"Type")=$G(CONTDATA(409.863,CIENS,1,"E"))
.S CONTACTS("ContactAttempts",CCNT,"Comments")=$G(CONTDATA(409.863,CIENS,2,"E"))
.S CONTACTS("ContactAttempts",CCNT,"LeftMessage")=$G(CONTDATA(409.863,CIENS,3,"E"))
.S CONTACTS("ContactAttempts",CCNT,"Sequence")=$G(CONTDATA(409.863,CIENS,4,"E"))
.S CONTACTS("ContactAttempts",CCNT,"EnteredByName")=$G(CONTDATA(409.863,CIENS,5,"E"))
.S CONTACTS("ContactAttempts",CCNT,"EnteredByIEN")=$G(CONTDATA(409.863,CIENS,5,"I"))
.S CONTACTS("ContactAttempts",CCNT,"EnteredBySecID")=$$GET1^DIQ(200,$G(CONTDATA(409.863,CIENS,5,"I")),205.1,"E")
.S DTTMENTERED=$$FMTISO^SDAMUTDT($G(CONTDATA(409.863,CIENS,6,"I")))
.S CONTACTS("ContactAttempts",CCNT,"DateTimeEntered")=DTTMENTERED
.K CONTDATA
I '$D(CONTACTS) S CONTACTS("ContactAttempts",1)=""
M RESULT=CONTACTS
Q
;
GETSRV(REQTYP,REQIEN) ; Function to get SERVICE based on Request type and ien
N SERVICE S SERVICE=""
I 'REQIEN!(REQTYP="") Q SERVICE
I (REQTYP="A")!(REQTYP="RTC")!(REQTYP="V") D Q SERVICE
. S SERVICE=$$GET1^DIQ(409.85,REQIEN,8.5,"I")
. S SERVICE=SERVICE_"^"_$$GET1^DIQ(409.85,REQIEN,8.5,"E")
I (REQTYP="C")!(REQTYP="P") D Q SERVICE
. S SERVICE=$$GET1^DIQ(123,REQIEN,1,"I")
. S SERVICE=SERVICE_"^"_$$GET1^DIQ(123,REQIEN,1,"E")
Q SERVICE
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDES2CONTACTS 10693 printed Dec 13, 2024@02:53:34 Page 2
SDES2CONTACTS ;ALB/LAB,MCB/TJB,JAS - VISTA SCHEDULING CONTACT SDES2 CONTACT ATTEMPTS ;Aug 28,2024
+1 ;;5.3;Scheduling;**860,873,878,887**;Aug 13, 1993;Build 7
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 QUIT
+4 ;
ADDCONTACT(RESULT,SDCONTEXT,CONTACT) ; RPC: SDEC2 ADD CONTACT ATTEMPT
+1 NEW ERRORS,DFN,CLINIC,PREFDATE,REQTYPE,DTTMOFCONTACT,CONTACTTYPE,COMMENTS,DTTMENTERED,REQUESTIEN,NEWCONTACT
+2 NEW NEWIEN,APPTREQTYPE,FDA,NEWCONTIEN,SUBIENS,CONTACTIEN,SEQUENCE,LEFTMSG,NEWCONTATTMTIEN,VALID
+3 ;
+4 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
+5 IF $DATA(ERRORS)
SET ERRORS("Contact",1)=""
SET ERRORS("ContactAttempts")=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+6 ;
+7 DO REQUESTINFO(.ERRORS,.CONTACT,.APPTREQTYPE,.REQUESTIEN,.REQTYP,.DFN,.CLINIC,.PREFDATE)
+8 IF $DATA(ERRORS)
SET ERRORS("Contact",1)=""
SET ERRORS("ContactAttempts")=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+9 ;
+10 DO ASSIGNVARS(.CONTACT,.REQTYPE,.DTTMOFCONTACT,.COMMENTS,.DTMENTERED,.LEFTMSG,.SDDUZ)
+11 DO VALIDATE(.ERRORS,REQTYPE,.DTTMOFCONTACT,COMMENTS,.DTTMENTERED,LEFTMSG,CONTACTTYPE,CLINIC)
+12 IF $DATA(ERRORS)
SET ERRORS("Contact",1)=""
SET ERRORS("ContactAttempts")=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+13 ;
+14 DO GETCONTACTIEN(.CONTACTIEN,APPTREQTYPE)
+15 ;
+16 if (CONTACTIEN'="")
DO UPDATECONTACT(.RESULT,.FDA,CONTACTIEN,DTTMOFCONTACT,CONTACTTYPE,COMMENTS,SDDUZ,DTTMENTERED,LEFTMSG)
+17 if (CONTACTIEN="")
DO CREATECONTACT(.RESULT,.FDA,DFN,CONTACTIEN,CLINIC,PREFDATE,REQTYPE,APPTREQTYPE,DTTMOFCONTACT,CONTACTTYPE,COMMENTS,SDDUZ,DTTMENTERED,LEFTMSG)
+18 DO SAVECONTACT(.ERRORS,.RESULT,.FDA,.NEWIEN)
+19 DO ASSIGNNEWIEN(.NEWCONTACTIEN,.CONTACTIEN,.NEWIEN)
+20 DO BLDRETNINFO(.NEWCONTACT,CONTACTIEN,CLINIC)
+21 IF '$DATA(NEWCONTACT)
SET NEWCONTACT("Contact",1)=""
SET ERRORS("ContactAttempts")=""
DO BUILDJSON^SDES2JSON(.RESULT,.CONTACTS)
QUIT
+22 DO DISPCONTACT(.NEWCONTACT,CONTACTIEN,CLINIC)
+23 DO BUILDJSON^SDES2JSON(.RESULT,.NEWCONTACT)
+24 QUIT
+25 ;
ASSIGNNEWIEN(NEWCONTACTIEN,CONTACTIEN,NEWIEN) ;get the iens that were created during create/update
+1 if CONTACTIEN'=""
SET NEWCONTATTMTIEN=$GET(NEWIEN(1))
+2 IF CONTACTIEN=""
Begin DoDot:1
+3 SET CONTACTIEN=$GET(NEWIEN(1))
+4 SET NEWCONTATTMTIEN=$GET(NEWIEN(2))
End DoDot:1
+5 QUIT
+6 ;
GETCONTACTIEN(CONTACTIEN,APPTREQTYPE) ;if a contact attempt already exists, get it's ien
+1 SET CONTACTIEN=""
+2 if $DATA(^SDEC(409.86,"REQPTR",APPTREQTYPE))
SET CONTACTIEN=$ORDER(^SDEC(409.86,"REQPTR",APPTREQTYPE,"A"),-1)
+3 QUIT
+4 ;
BLDNEWCONT(FDA,IENS,DFN,CLINIC,PREFDATE,REQTYPE,APPTREQTYPE) ; build the new contact attempt record.
+1 SET FDA(409.86,IENS,.01)=DFN
+2 SET FDA(409.86,IENS,1)=CLINIC
+3 SET FDA(409.86,IENS,2)=PREFDATE
+4 SET FDA(409.86,IENS,2.1)=REQTYPE
+5 ; Main Sequence (2.2) is always set to 1 initially
+6 SET FDA(409.86,IENS,2.2)=1
+7 SET FDA(409.86,IENS,2.3)=APPTREQTYPE
+8 QUIT
+9 ;
BLDNEWATTMPT(FDA,IENS,DTTMOFCONTACT,CONTACTTYPE,COMMENTS,SDDUZ,DTTMENTERED,LEFTMSG,SEQUENCE) ;add a new entry to existing contact attempt record.
+1 SET FDA(409.863,IENS,.01)=DTTMOFCONTACT
+2 SET FDA(409.863,IENS,1)=CONTACTTYPE
+3 SET FDA(409.863,IENS,2)=COMMENTS
+4 SET FDA(409.863,IENS,3)=$GET(LEFTMSG)
+5 ; The first entry in this subfile will always be 1
+6 SET FDA(409.863,IENS,4)=SEQUENCE
+7 SET FDA(409.863,IENS,5)=$GET(SDDUZ)
+8 SET FDA(409.863,IENS,6)=DTTMENTERED
+9 QUIT
+10 ;
BLDRETNINFO(RESULT,IEN,CLINIC) ;build return result of contact attempts
+1 NEW F,IENS,ERR,PREFDATE,STOPIEN,CONTDATA
+2 SET F=409.86
SET IENS=IEN_","
+3 DO GETS^DIQ(409.86,IENS,"**","IE","CONTDATA","ERR")
+4 if $DATA(ERR)
QUIT
+5 IF '$GET(CLINIC)
SET CLINIC=$GET(CONTDATA(F,IENS,1,"I"))
+6 SET PREFDATE=$$FMTISO^SDAMUTDT($GET(CONTDATA(F,IENS,2,"I")),$GET(CLINIC))
+7 IF PREFDATE<0
SET PREFDATE=""
+8 SET RESULT("Contact","ID")=$PIECE(IENS,",")
+9 SET RESULT("Contact","Patient")=$GET(CONTDATA(F,IENS,.01,"I"))
+10 SET RESULT("Contact","Clinic")=$GET(CONTDATA(F,IENS,1,"I"))
+11 SET STOPIEN=$$GET1^DIQ(44,CLINIC,8,"I")
+12 SET RESULT("Contact","ClinicStopCodeAMIS")=$$STOPCODETOAMIS^SDESUTIL(STOPIEN)
+13 SET RESULT("Contact","PreferredDate")=PREFDATE
+14 SET RESULT("Contact","RequestType")=$GET(CONTDATA(F,IENS,2.1,"I"))
+15 SET RESULT("Contact","MainSequence")=$GET(CONTDATA(F,IENS,2.2,"I"))
+16 NEW SRVSTRING
+17 SET SRVSTRING=$$GETSRV($GET(CONTDATA(F,IENS,2.1,"I")),+$GET(CONTDATA(F,IENS,2.3,"I")))
+18 SET RESULT("Contact","Service")=$PIECE($GET(SRVSTRING),"^")
+19 SET RESULT("Contact","ServiceName")=$PIECE($GET(SRVSTRING),"^",2)
+20 SET RESULT("Contact","RequestPointer")=$GET(CONTDATA(F,IENS,2.3,"I"))
+21 KILL CONTDATA
+22 QUIT
+23 ;
ASSIGNVARS(CONTACT,REQTYPE,DTTMOFCONTACT,COMMENTS,DTMENTERED,LEFTMSG,SDDUZ) ;assign variables used sent in from CONTACT array
+1 SET DTTMOFCONTACT=$GET(CONTACT("DTTMOFCONTACT"))
+2 SET CONTACTTYPE=$GET(CONTACT("CONTACTTYPE"))
+3 SET COMMENTS=$GET(CONTACT("COMMENTS"))
+4 SET DTTMENTERED=$GET(CONTACT("DTTMENTERED"))
+5 SET LEFTMSG=$GET(CONTACT("LEFTMESSAGE"))
+6 if LEFTMSG=""
SET LEFTMSG=0
+7 if $GET(SDCONTEXT("USER DUZ"))'=""
SET SDDUZ=$GET(SDCONTEXT("USER DUZ"))
+8 if $GET(SDCONTEXT("USER DUZ"))=""
SET SDDUZ=DUZ
+9 QUIT
+10 ;
VALIDATE(ERRORS,REQTYPE,DTTMOFCONTACT,COMMENTS,DTTMENTERED,LEFTMSG,CONTACTTYPE,CLINIC) ;validate input array values
+1 DO VALFIELD^SDES2VALUTIL(,.ERRORS,409.86,2.1,REQTYPE,,0,395,396)
+2 DO VALFIELD^SDES2VALUTIL(,.ERRORS,409.863,3,LEFTMSG,0,0,,402)
+3 DO VALFIELD^SDES2VALUTIL(,.ERRORS,409.863,2,COMMENTS,0,0)
+4 DO VALFIELD^SDES2VALUTIL(,.ERRORS,409.863,1,CONTACTTYPE,1,0)
+5 ;
SET DTTMOFCONTACT=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,DTTMOFCONTACT,CLINIC,1,389,390)
+6 ;
SET DTTMENTERED=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,DTTMENTERED,,1,387,388)
+7 QUIT
+8 ;
REQUESTINFO(ERRORS,CONTACT,APPTREQTYPE,REQUESTIEN,REQTYP,DFN,CLINIC,PREFDATE,CONTACTIEN) ;
+1 ; Given the request ien and request type, return back information needed from request
+2 NEW REQTYPEFOUND,VALID
+3 SET REQTYPEFOUND=0
+4 SET REQUESTIEN=$GET(CONTACT("REQUESTIEN"))
+5 SET REQTYPE=$GET(CONTACT("REQTYPE"))
+6 IF (REQTYPE="A")!(REQTYPE="RTC")!(REQTYPE="V")
Begin DoDot:1
+7 DO VALFILEIEN^SDES2VALUTIL(.VALID,.ERRORS,409.85,REQUESTIEN,1,0,3,4)
+8 if 'VALID
QUIT
+9 SET DFN=$$GET1^DIQ(409.85,REQUESTIEN,.01,"I")
+10 SET CLINIC=$$GET1^DIQ(409.85,REQUESTIEN,8,"I")
+11 SET PREFDATE=$$GET1^DIQ(409.85,REQUESTIEN,22,"I")
+12 SET APPTREQTYPE=REQUESTIEN_";"_"SDEC(409.85,"
+13 SET REQTYPEFOUND=1
End DoDot:1
+14 IF (REQTYPE="C")!(REQTYPE="P")
Begin DoDot:1
+15 DO VALFILEIEN^SDES2VALUTIL(.VALID,.ERRORS,123,REQUESTIEN,1,0,3,4)
+16 if 'VALID
QUIT
+17 SET DFN=$$GET1^DIQ(123,REQUESTIEN,.02,"I")
+18 SET CLINIC=""
+19 if $$GET1^DIQ(123,REQUESTIEN,17,"I")'=""
SET PREFDATE=$$GET1^DIQ(123,REQUESTIEN,17,"I")
+20 if $GET(PREFDATE)=""
SET PREFDATE=$$GET1^DIQ(123,REQUESTIEN,.01,"I")
+21 SET APPTREQTYPE=REQUESTIEN_";"_"GMR(123,"
+22 SET REQTYPEFOUND=1
End DoDot:1
+23 IF REQTYPE="R"
Begin DoDot:1
+24 DO VALFILEIEN^SDES2VALUTIL(.VALID,.ERRORS,403.5,REQUESTIEN,1,0,3,4)
+25 if 'VALID
QUIT
+26 SET DFN=$$GET1^DIQ(403.5,REQUESTIEN,.01,"I")
+27 SET CLINIC=$$GET1^DIQ(403.5,REQUESTIEN,4.5,"I")
+28 SET PREFDATE=$$GET1^DIQ(403.5,REQUESTIEN,5,"I")
+29 SET APPTREQTYPE=REQUESTIEN_";"_"SD(403.5,"
+30 SET REQTYPEFOUND=1
End DoDot:1
+31 IF '$DATA(ERRORS)&('REQTYPEFOUND)
DO ERRLOG^SDES2JSON(.ERRORS,52,"Passed in Request Type invalid or not supported.")
+32 QUIT
+33 ;
CREATECONTACT(RESULT,FDA,DFN,CONTACTIEN,CLINIC,PREFDATE,REQTYPE,APPTREQTYPE,DTTMOFCONTACT,CONTACTTYPE,COMMENTS,SDDUZ,DTTMENTERED,LEFTMSG) ;
+1 ;create a new contact attempt record
+2 DO BLDNEWCONT(.FDA,"+1,",DFN,CLINIC,PREFDATE,REQTYPE,APPTREQTYPE)
+3 SET SUBIENS="+2,+1,"
+4 DO BLDNEWATTMPT(.FDA,SUBIENS,DTTMOFCONTACT,CONTACTTYPE,COMMENTS,SDDUZ,DTTMENTERED,LEFTMSG,1)
+5 QUIT
+6 ;
UPDATECONTACT(RESULT,FDA,CONTACTIEN,DTTMOFCONTACT,CONTACTTYPE,COMMENTS,SDDUZ,DTTMENTERED,LEFTMSG) ;
+1 ;update the contact attempt multiple with the new contact data
+2 SET SUBIENS="+1,"_CONTACTIEN_","
+3 SET SEQUENCE=$ORDER(^SDEC(409.86,CONTACTIEN,1,9999),-1)+1
+4 DO BLDNEWATTMPT(.FDA,SUBIENS,DTTMOFCONTACT,CONTACTTYPE,COMMENTS,SDDUZ,DTTMENTERED,LEFTMSG,SEQUENCE)
+5 QUIT
+6 ;
SAVECONTACT(ERRORS,RESULT,FDA,NEWIEN) ;file contact attempt in 409.86 file
+1 NEW DIERR,FILERR
+2 DO UPDATE^DIE(,"FDA","NEWIEN","FILERR")
KILL FDA
+3 IF $DATA(FILERR)
Begin DoDot:1
+4 DO ERRLOG^SDESJSON(.ERRORS,52,$GET(FILERR("DIERR",1,"TEXT",1)))
+5 SET ERRORS("Contact",1)=""
+6 DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
End DoDot:1
QUIT
+7 QUIT
+8 ;
GETCONTACTS(RESULT,SDCONTEXT,REQARRAY) ; RPC: SDES2 GET CONTACT ATTEMPT
+1 NEW REQTYPE,REQIEN,ERRORS,APPTREQTYPE,REQIEN,REQTYPE,DFN,CLINIC,PREFDATE,CONTACTS,CONTACTIEN
+2 DO ASSIGNREQVAR(.REQARRAY,.REQTYPE,.REQIEN)
+3 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
+4 IF $DATA(ERRORS)
SET ERRORS("Contact",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+5 ;
+6 DO VALFIELD^SDES2VALUTIL(,.ERRORS,409.86,2.1,REQTYPE,,0,395,396)
+7 DO REQUESTINFO(.ERRORS,.REQARRAY,.APPTREQTYPE)
+8 IF $DATA(ERRORS)
SET ERRORS("Contact",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+9 ;
+10 DO GETCONTACTIEN(.CONTACTIEN,APPTREQTYPE)
+11 IF $GET(CONTACTIEN)=""
SET CONTACTS("Contact",1)=""
SET CONTACTS("ContactAttempts")=""
DO BUILDJSON^SDES2JSON(.RESULT,.CONTACTS)
QUIT
+12 DO BLDRETNINFO(.CONTACTS,CONTACTIEN)
+13 DO DISPCONTACT(.CONTACTS,CONTACTIEN)
+14 DO BUILDJSON^SDESBUILDJSON(.RESULT,.CONTACTS)
+15 QUIT
+16 ;
ASSIGNREQVAR(REQARRAY,REQTYPE,REQIEN) ;
+1 SET REQTYPE=$GET(REQARRAY("REQTYPE"))
+2 SET REQIEN=$GET(REQARRAY("REQUESTIEN"))
+3 QUIT
+4 ;
DISPCONTACT(RESULT,CONTACTIEN,CLINIC) ;get contact attempt information given contact ien
+1 NEW ERRORS,CONTMULT,CIENS,CONTDATA,CCNT,CONTACTS,CONTDATE,DTTMENTERED
+2 ;
+3 SET CONTACTIEN=$GET(CONTACTIEN)
+4 SET CCNT=0
+5 SET CONTMULT=0
FOR
SET CONTMULT=$ORDER(^SDEC(409.86,CONTACTIEN,1,CONTMULT))
if 'CONTMULT
QUIT
Begin DoDot:1
+6 SET CIENS=CONTMULT_","_CONTACTIEN_","
+7 DO GETS^DIQ(409.863,CIENS,"**","IE","CONTDATA")
+8 IF '$GET(CLINIC)
SET CLINIC=$$GET1^DIQ(409.86,CONTACTIEN,1,"I")
+9 SET CCNT=CCNT+1
+10 SET CONTDATE=$GET(CONTDATA(409.863,CIENS,.01,"I"))
+11 SET CONTDATE=$$FMTISO^SDAMUTDT(CONTDATE,$GET(CLINIC))
+12 SET CONTACTS("ContactAttempts",CCNT,"DateTimeOfContact")=CONTDATE
+13 SET CONTACTS("ContactAttempts",CCNT,"Type")=$GET(CONTDATA(409.863,CIENS,1,"E"))
+14 SET CONTACTS("ContactAttempts",CCNT,"Comments")=$GET(CONTDATA(409.863,CIENS,2,"E"))
+15 SET CONTACTS("ContactAttempts",CCNT,"LeftMessage")=$GET(CONTDATA(409.863,CIENS,3,"E"))
+16 SET CONTACTS("ContactAttempts",CCNT,"Sequence")=$GET(CONTDATA(409.863,CIENS,4,"E"))
+17 SET CONTACTS("ContactAttempts",CCNT,"EnteredByName")=$GET(CONTDATA(409.863,CIENS,5,"E"))
+18 SET CONTACTS("ContactAttempts",CCNT,"EnteredByIEN")=$GET(CONTDATA(409.863,CIENS,5,"I"))
+19 SET CONTACTS("ContactAttempts",CCNT,"EnteredBySecID")=$$GET1^DIQ(200,$GET(CONTDATA(409.863,CIENS,5,"I")),205.1,"E")
+20 SET DTTMENTERED=$$FMTISO^SDAMUTDT($GET(CONTDATA(409.863,CIENS,6,"I")))
+21 SET CONTACTS("ContactAttempts",CCNT,"DateTimeEntered")=DTTMENTERED
+22 KILL CONTDATA
End DoDot:1
+23 IF '$DATA(CONTACTS)
SET CONTACTS("ContactAttempts",1)=""
+24 MERGE RESULT=CONTACTS
+25 QUIT
+26 ;
GETSRV(REQTYP,REQIEN) ; Function to get SERVICE based on Request type and ien
+1 NEW SERVICE
SET SERVICE=""
+2 IF 'REQIEN!(REQTYP="")
QUIT SERVICE
+3 IF (REQTYP="A")!(REQTYP="RTC")!(REQTYP="V")
Begin DoDot:1
+4 SET SERVICE=$$GET1^DIQ(409.85,REQIEN,8.5,"I")
+5 SET SERVICE=SERVICE_"^"_$$GET1^DIQ(409.85,REQIEN,8.5,"E")
End DoDot:1
QUIT SERVICE
+6 IF (REQTYP="C")!(REQTYP="P")
Begin DoDot:1
+7 SET SERVICE=$$GET1^DIQ(123,REQIEN,1,"I")
+8 SET SERVICE=SERVICE_"^"_$$GET1^DIQ(123,REQIEN,1,"E")
End DoDot:1
QUIT SERVICE
+9 QUIT SERVICE
+10 ;