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

SDES2GETDISPCONS.m

Go to the documentation of this file.
SDES2GETDISPCONS ;ALB/JAS - VISTA SCHEDULING - SDES2 GET DISP CONT ATTEMPTS ;Aug 23,2024
 ;;5.3;Scheduling;**885,886,887**;Aug 13, 1993;Build 7
 ;;Per VHA Directive 6402, this routine should not be modified
 Q
 ;
GETCONTACTS(RESULT,SDCONTEXT,REQARRAY) ; RPC: SDES2 GET DISP CONT ATTEMPTS
 N ERRORS,PATDFN,CNATDATE,CHKDATE,CHKMTCH,CONTACTS,CONTACTIEN,CONCNT
 D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
 I $D(ERRORS) S ERRORS("Contact",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
 ;
 S PATDFN=$G(REQARRAY("PATIENT DFN"))
 D VALFILEIEN^SDES2VALUTIL(,.ERRORS,2,PATDFN,1,0,1,2)
 I $D(ERRORS) S ERRORS("Contact",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
 ;
 S CONTACTIEN="",CONCNT=0
 S CHKDATE=$$FMADD^XLFDT(DT,-365)
 F  S CONTACTIEN=$O(^SDEC(409.86,"B",PATDFN,CONTACTIEN)) Q:'CONTACTIEN  I $D(^SDEC(409.86,CONTACTIEN,1,"B")) D
 . S CNATDATE="",CHKMTCH=0
 . F  S CNATDATE=$O(^SDEC(409.86,CONTACTIEN,1,"B",CNATDATE),-1) Q:CNATDATE=""!(CHKMTCH)  D
 . . Q:+CNATDATE<CHKDATE
 . . S CHKMTCH=1
 . I CHKMTCH D BLDRETNINFO(.CONTACTS,CONTACTIEN,PATDFN,.CONCNT)
 I '$D(CONTACTS) S CONTACTS("Contact",1)="" D BUILDJSON^SDES2JSON(.RESULT,.CONTACTS) Q
 ;
 D BUILDJSON^SDESBUILDJSON(.RESULT,.CONTACTS)
 Q
 ;
BLDRETNINFO(RESULT,IEN,PATDFN,CONCNT) ;build return result of contact attempts
 N FILE,IENS,ERR,PREFDATE,CLINIC,CONTDATA,DISPDATE,REQDAT,REQIEN,REQTYPE,REQTYPECD,SERVICE
 S FILE=409.86,IENS=IEN_","
 D GETS^DIQ(409.86,IENS,"1;2;2.1;2.3","IE","CONTDATA","ERR")
 Q:$D(ERR)
 ;
 S REQIEN=$P($G(CONTDATA(FILE,IENS,2.3,"I")),";"),REQTYPECD=$G(CONTDATA(FILE,IENS,2.1,"I"))
 S CLINIC=$G(CONTDATA(FILE,IENS,1,"I")),PREFDATE=$G(CONTDATA(FILE,IENS,2,"I"))
 ;
 D REQUESTINFO(.REQDAT,REQIEN,REQTYPECD,PATDFN,CLINIC,PREFDATE)
 Q:$G(REQDAT("DISPDATE"))=""
 S:CLINIC="" CLINIC=$G(REQDAT("CLINIC"))
 S SERVICE=$G(REQDAT("SERVICE"))
 S:PREFDATE="" PREFDATE=$G(REQDAT("PREFDATE"))
 S REQTYPE=$S($D(REQDAT("REQTYPE")):REQDAT("REQTYPE"),1:$G(CONTDATA(FILE,IENS,2.1,"E")))
 S PREFDATE=$$FMTISO^SDAMUTDT(PREFDATE,$G(CLINIC))
 I PREFDATE<0 S PREFDATE=""
 ;
 S CONCNT=CONCNT+1
 S RESULT("Contact",CONCNT,"ContactID")=$P(IENS,",")
 S RESULT("Contact",CONCNT,"Patient")=PATDFN
 S RESULT("Contact",CONCNT,"Clinic")=CLINIC
 S RESULT("Contact",CONCNT,"ClinicName")=$G(CONTDATA(FILE,IENS,1,"E"))
 S RESULT("Contact",CONCNT,"Service")=SERVICE
 S RESULT("Contact",CONCNT,"PreferredDate")=PREFDATE
 S RESULT("Contact",CONCNT,"RequestType")=REQTYPE
 S RESULT("Contact",CONCNT,"RequestIEN")=$P($G(CONTDATA(FILE,IENS,2.3,"I")),";")
 S DISPDATE=$$FMTISO^SDAMUTDT($G(REQDAT("DISPDATE")),$G(CLINIC))
 S RESULT("Contact",CONCNT,"DispositionDate")=DISPDATE
 S RESULT("Contact",CONCNT,"DispositionedBy")=$G(REQDAT("DISPBY"))
 S RESULT("Contact",CONCNT,"RecallReqRemovedIEN")=$G(REQDAT("RRRIEN"))
 K CONTDATA
 ;
 D DISPCONTACT(.RESULT,IEN,CONCNT)
 Q
 ;
REQUESTINFO(REQDAT,REQUESTIEN,REQTYPECD,PATDFN,CLINIC,PREFDATE) ;
 ; Given the request ien and request type, return back information needed for return
 I (REQTYPECD="A")!(REQTYPECD="RTC")!(REQTYPECD="V") D  Q
 . I CLINIC="" S REQDAT("CLINIC")=$$GET1^DIQ(409.85,REQUESTIEN,8,"I")
 . S REQDAT("SERVICE")=$$GET1^DIQ(409.85,REQUESTIEN,8.5,"E")
 . I PREFDATE="" S REQDAT("PREFDATE")=$$GET1^DIQ(409.85,REQUESTIEN,22,"I")
 . S REQDAT("REQTYPE")=$$GET1^DIQ(409.85,REQUESTIEN,4,"I")
 . S REQDAT("DISPDATE")=$$GET1^DIQ(409.85,REQUESTIEN,19,"I")
 . S REQDAT("DISPBY")=$$GET1^DIQ(409.85,REQUESTIEN,20,"E")
 ;
 I (REQTYPECD="C")!(REQTYPECD="P") D  Q
 . N LASTACT S LASTACT=$$GET1^DIQ(123,REQUESTIEN,9,"E")
 . Q:(LASTACT'="DISCONTINUED")&(LASTACT'="CANCELLED")
 . S REQDAT("SERVICE")=$$GET1^DIQ(123,REQUESTIEN,1,"E")
 . I 'PREFDATE D
 . . S REQDAT("PREFDATE")=$$GET1^DIQ(123,REQUESTIEN,17,"I")
 . . S:$G(REQDAT("PREFDATE"))="" REQDAT("PREFDATE")=$$GET1^DIQ(123,REQUESTIEN,.01,"I")
 . N ACTDATE,ACTIEN
 . S ACTDATE=$O(^GMR(123,REQUESTIEN,40,"B",""),-1) Q:'ACTDATE  D
 . . S ACTIEN=$O(^GMR(123,REQUESTIEN,40,"B",ACTDATE,""),-1) Q:'ACTIEN  D
 . . . S REQDAT("DISPDATE")=$$GET1^DIQ(123.02,ACTIEN_","_REQUESTIEN_",",2,"I")
 . . . S REQDAT("DISPBY")=$$GET1^DIQ(123.02,ACTIEN_","_REQUESTIEN_",",4,"E")
 ;
 I REQTYPECD="R" D
 . I $D(^SD(403.5,REQUESTIEN)) S REQDAT("DISPDATE")="" Q
 . I $D(^SD(403.56,"B",PATDFN)) D
 . . N RRRIEN S RRRIEN=0
 . . F  S RRRIEN=$O(^SD(403.56,"B",PATDFN,RRRIEN)) Q:'RRRIEN  D
 . . . Q:CLINIC'=$$GET1^DIQ(403.56,RRRIEN,4.5,"I")
 . . . Q:PREFDATE'=$$GET1^DIQ(403.56,RRRIEN,5,"I")
 . . . Q:$$GET1^DIQ(403.56,RRRIEN,203,"E")="APPT SCHEDULED"
 . . . S REQDAT("DISPDATE")=$$GET1^DIQ(403.56,RRRIEN,201,"I")
 . . . S REQDAT("DISPBY")=$$GET1^DIQ(403.56,RRRIEN,202,"E")
 . . . S REQDAT("RRRIEN")=RRRIEN
 . . . S REQDAT("SERVICE")=""
 Q
 ;
DISPCONTACT(RESULT,CONTACTIEN,CONCNT) ;get contact attempt information given contact ien
 N CONTMULT,CIENS,CONTDATA,CCNT,CONTACTS,CONTDATE
 S CONTACTIEN=$G(CONTACTIEN),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,".01;1;2;4;5","IE","CONTDATA")
 .I '$G(CLINIC) S CLINIC=$$GET1^DIQ(409.86,CONTACTIEN,1,"I")
 .S CONTDATE=$G(CONTDATA(409.863,CIENS,.01,"I"))
 .S CONTDATE=$$FMTISO^SDAMUTDT(CONTDATE,$G(CLINIC))
 .;
 .S CCNT=CCNT+1
 .S CONTACTS("Contact",CONCNT,"ContactAttempts",CCNT,"DateTimeOfContact")=CONTDATE
 .S CONTACTS("Contact",CONCNT,"ContactAttempts",CCNT,"ContactType")=$G(CONTDATA(409.863,CIENS,1,"E"))
 .S CONTACTS("Contact",CONCNT,"ContactAttempts",CCNT,"Comments")=$G(CONTDATA(409.863,CIENS,2,"E"))
 .S CONTACTS("Contact",CONCNT,"ContactAttempts",CCNT,"SequenceOfAttempt")=$G(CONTDATA(409.863,CIENS,4,"E"))
 .S CONTACTS("Contact",CONCNT,"ContactAttempts",CCNT,"ContactEnteredBy")=$G(CONTDATA(409.863,CIENS,5,"E"))
 .K CONTDATA
 S CONTACTS("Contact",CONCNT,"TotalAttemptsMade")=$G(CCNT)
 M RESULT=CONTACTS
 Q
 ;