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

SDESGETCONSULTS.m

Go to the documentation of this file.
SDESGETCONSULTS ;ALB/BLB,MGD,RRM,BWF,CGP,BLB,ANU,LAB,BLB - VISTA SCHEDULING RPCS GET CONSULTS ;DEC 01,2023
 ;;5.3;Scheduling;**815,820,824,837,842,847,857,867,875,877,886**;Aug 13, 1993;Build 13
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 ;External References
 ;-------------------
 ; Reference to ^VA(200 in ICR #10060 ;
 ; Reference to $$GETS^DIQ,$$GET1^DIQ in ICR #2056
 ;
 ;
 ; ----------------- ----------------- ----------
 ;
 ;
 ; for an example of the return object, see SDESGETREQWRAPPR due to its length.
 ;
 Q
 ;
GETCONSULTSBYDFN(JSONRETURN,DFN,EAS) ; SDES GET CONSULTS BY DFN
 N ISDFNVALID,RETURN,REQUEST,CPRSSTATUS,IFCROLE,CONSULTIEN,ERRORS
 ;
 S ISDFNVALID=$$VALIDATEDFN(.ERRORS,$G(DFN))
 S ISEASVALID=$$VALIDATEEAS(.ERRORS,$G(EAS))
 I $D(ERRORS) S ERRORS("Request",1)="" M RETURN=ERRORS D BUILDJSON(.JSONRETURN,.RETURN) Q
 ;
 S CONSULTIEN=0
 F  S CONSULTIEN=$O(^GMR(123,"F",DFN,CONSULTIEN)) Q:'CONSULTIEN  D
 .S CPRSSTATUS=$$GET1^DIQ(123,CONSULTIEN,8,"E"),IFCROLE=$$GET1^DIQ(123,CONSULTIEN,.125,"E")
 .I CPRSSTATUS'="PENDING",CPRSSTATUS'="ACTIVE" Q
 .I IFCROLE="PLACER" Q
 .D GETCONSULT(.REQUEST,CONSULTIEN)
 I '$D(REQUEST) S REQUEST("Request",1)=""
 M RETURN=REQUEST
 ;
 D BUILDJSON(.JSONRETURN,.RETURN)
 Q
 ;
GETCONSULTBYIEN(JSONRETURN,CONSULTIEN,EAS) ; SDES GET CONSULTS BY IEN
 N ISCONSIENVALID,ISEASVALID,RETURN,ERRORS,REQUEST
 ;
 S ISCONSIENVALID=$$VALIDATECONIEN(.ERRORS,$G(CONSULTIEN))
 S ISEASVALID=$$VALIDATEEAS(.ERRORS,$G(EAS))
 I $D(ERRORS) S ERRORS("Request",1)="" M RETURN=ERRORS
 ;
 I '$D(ERRORS) D
 .D GETCONSULT(.REQUEST,CONSULTIEN)
 I '$D(REQUEST) S REQUEST("Request",1)=""
 M RETURN=REQUEST
 ;
 D BUILDJSON(.JSONRETURN,.RETURN)
 Q
 ;
VALIDATEDFN(ERRORS,DFN) ;
 I DFN="" D ERRLOG^SDESJSON(.ERRORS,1) Q 0
 I DFN'="",'$D(^DPT(DFN,0)) D ERRLOG^SDESJSON(.ERRORS,2) Q 0
 Q 1
 ;
VALIDATECONIEN(ERRORS,CONSULTIEN) ;
 I CONSULTIEN="" D ERRLOG^SDESJSON(.ERRORS,5) Q 0
 I CONSULTIEN'="",('$D(^GMR(123,CONSULTIEN)))!(CONSULTIEN=0) D ERRLOG^SDESJSON(.ERRORS,6) Q 0
 Q 1
 ;
VALIDATEEAS(ERRORS,EAS) ;
 I $L(EAS) S EAS=$$EASVALIDATE^SDESUTIL($G(EAS))
 I $P($G(EAS),U)=-1 D ERRLOG^SDESJSON(.ERRORS,142) Q 0
 Q 1
 ;
COVIDPRIORITYCHK(CONSULTIEN) ; pass back the latest entry in the comment multiple containging "covid-19 priority"
 N SUBIEN,SUBIEN2,FOUND,COVIDCOMMENT
 S SUBIEN=999999999,FOUND=0,COVIDCOMMENT=""
 F  S SUBIEN=$O(^GMR(123,CONSULTIEN,40,SUBIEN),-1) Q:'SUBIEN!(FOUND=1)  D
 .S SUBIEN2=0
 .F  S SUBIEN2=$O(^GMR(123,CONSULTIEN,40,SUBIEN,1,SUBIEN2)) Q:'SUBIEN2  D
 ..S COVIDCOMMENT=$$GET1^DIQ(123.25,SUBIEN2_","_SUBIEN_","_CONSULTIEN_",",.01)
 ..I COVIDCOMMENT["COVID-19 Priority" D
 ...S COVIDCOMMENT=$P(COVIDCOMMENT,"-COVID-19 Priority",1)
 ...S FOUND=1 Q
 Q COVIDCOMMENT
 ;857
GETSTOPCODES(REQUEST,SERVICEIEN,NUM) ;
 N SUBIEN,COUNT,STOPCODE
 S COUNT=0,SUBIEN=0
 F  S SUBIEN=$O(^GMR(123.5,SERVICEIEN,688,SUBIEN)) Q:'SUBIEN  D
 .S COUNT=COUNT+1
 .S STOPCODE=$$GET1^DIQ(123.5688,SUBIEN_","_SERVICEIEN_",",.01,"I")
 .S REQUEST("Request",NUM,"ConsultAssociatedStopCodes",COUNT,"StopCode")=STOPCODE
 .S REQUEST("Request",NUM,"ConsultAssociatedStopCodes",COUNT,"StopCodeName")=$$GET1^DIQ(40.7,STOPCODE,.01,"E")
 .S REQUEST("Request",NUM,"ConsultAssociatedStopCodes",COUNT,"AmisStopCode")=$$GET1^DIQ(40.7,STOPCODE,1,"I")
 .S REQUEST("Request",NUM,"ConsultAssociatedStopCodes",COUNT,"RestrictionType")=$$GET1^DIQ(40.7,STOPCODE,5,"I")
 Q
 ;
GETPID(CONSULTIEN) ;
 N CHIEN,CHSIEN,OLDESTPID
 S CHIEN=$O(^SDEC(409.87,"B",CONSULTIEN,0))
 S CHSIEN=$O(^SDEC(409.87,CHIEN,1,9999999),-1)
 S OLDESTPID=$$GET1^DIQ(409.871,CHSIEN_","_CHIEN_",",1,"I")
 Q OLDESTPID
 ;
CONSCANCELCHECK(CONSULTIEN,DFN) ;looking for most recent appt linked to this consult and checking if cancelled by patient or clinic
 N FOUND,APPTIEN,CANCHANGE
 S APPTIEN="",FOUND=0,CANCHANGE=0
 F  S APPTIEN=$O(^SDEC(409.84,"CPAT",DFN,APPTIEN),-1) Q:'APPTIEN!(FOUND=1)  D
 .I $P($$GET1^DIQ(409.84,APPTIEN,.22,"I"),";")=CONSULTIEN S FOUND=1 D
 ..I $$GET1^DIQ(409.84,APPTIEN,.17,"I")="PC" S CANCHANGE=1
 ..I $$GET1^DIQ(409.84,APPTIEN,.1,"I")=1 S CANCHANGE=1
 Q CANCHANGE
 ;857
GETCONSULT(REQUEST,CONSULTIEN) ;Build a consult record for every consult
 N CLINICIEN,CLINICNAME,SERVICEIEN,CONDATA,CONSERR,CANCHANGEPID,PID,NUM,ERRORS,PROVIDERIEN
 D GETS^DIQ(123,CONSULTIEN,"**","IE","CONDATA","CONSERR")
 S NUM="",NUM=$O(REQUEST("Request",NUM),-1)+1
 S REQUEST("Request",NUM,"Type")="Consult"
 ;
 ;I $D(^SDEC(409.86,"SRP",CONSULTIEN)) D
 ;I $$GETCONTIEN^SDESCONTACTS(.ERRORS,CONSULTIEN,"C") D
 D BUILDSDECONTACT^SDESGETAPPTREQ(.REQUEST,CONSULTIEN,NUM,"C")
 ;
 S SERVICEIEN=$G(CONDATA(123,CONSULTIEN_",",1,"I"))
 I $G(SERVICEIEN) D
 .D GETSTOPCODES(.REQUEST,SERVICEIEN,NUM)
 I '$G(SERVICEIEN) D
 .S REQUEST("Request",NUM,"ConsultAssociatedStopCodes",1)=""
 ;
 S CLINICIEN=$G(CONDATA(123,CONSULTIEN_",",2,"I"))
 S CLINICNAME=$G(CONDATA(123,CONSULTIEN_",",2,"E"))
 I '$G(CLINICIEN) D
 .S CLINICIEN=$G(CONDATA(123,CONSULTIEN_",",.05,"I"))
 .S CLINICNAME=$G(CONDATA(123,CONSULTIEN_",",.05,"E"))
 ;
 I $D(^SDEC(409.87,"B",CONSULTIEN)) D
 .S PID=$$GETPID(CONSULTIEN)
 .S REQUEST("Request",NUM,"ConsultClinicIndicatedDate")=$$FMTISO^SDAMUTDT(PID)
 I '$D(^SDEC(409.87,"B",CONSULTIEN)) D
 .S REQUEST("Request",NUM,"ConsultClinicIndicatedDate")=$$FMTISO^SDAMUTDT($G(CONDATA(123,CONSULTIEN_",",17,"I")))
 ;
 S PROVIDERIEN=$G(CONDATA(123,CONSULTIEN_",",10,"I"))
 ;
 S DFN=$G(CONDATA(123,CONSULTIEN_",",.02,"I"))
 S REQUEST("Request",NUM,"Type")="Consult"
 S REQUEST("Request",NUM,"PatientIEN")=DFN
 S REQUEST("Request",NUM,"PatientICN")=$$GETPATICN^SDESINPUTVALUTL(DFN)
 S REQUEST("Request",NUM,"PatientName")=$G(CONDATA(123,CONSULTIEN_",",.02,"E"))
 S REQUEST("Request",NUM,"RequestIEN")=CONSULTIEN
 S REQUEST("Request",NUM,"ConsultRequestType")=$G(CONDATA(123,CONSULTIEN_",",13,"E"))
 S REQUEST("Request",NUM,"CreateDate")=$$FMTISO^SDAMUTDT($G(CONDATA(123,CONSULTIEN_",",.01,"I")))
 S REQUEST("Request",NUM,"ConsultToService")=$G(CONDATA(123,CONSULTIEN_",",1,"E"))
 S REQUEST("Request",NUM,"ClinicIEN")=CLINICIEN
 S REQUEST("Request",NUM,"ClinicName")=CLINICNAME
 S REQUEST("Request",NUM,"EnteredByIEN")=$G(CONDATA(123,CONSULTIEN_",",10,"I"))
 S REQUEST("Request",NUM,"EnteredByName")=$G(CONDATA(123,CONSULTIEN_",",10,"E"))
 S REQUEST("Request",NUM,"ConsultCovidPriority")=$$COVIDPRIORITYCHK(CONSULTIEN)
 S REQUEST("Request",NUM,"ConsultDateReleasedFromCPRS")=$$FMTISO^SDAMUTDT($G(CONDATA(123,CONSULTIEN_",",3,"I")))
 S REQUEST("Request",NUM,"ConsultUrgencyOrEarliestDate")=$$FMTISO^SDAMUTDT($$PRIO^SDEC51A(CONSULTIEN))
 S REQUEST("Request",NUM,"ProviderIEN")=$G(CONDATA(123,CONSULTIEN_",",10,"I"))
 S REQUEST("Request",NUM,"ProviderName")=$G(CONDATA(123,CONSULTIEN_",",10,"E"))
 S REQUEST("Request",NUM,"ProviderSecID")=$$GET1^DIQ(200,PROVIDERIEN_",",205.1,"E")
 S REQUEST("Request",NUM,"ConsultServiceRenderedAs")=$G(CONDATA(123,CONSULTIEN_",",14,"E"))
 S REQUEST("Request",NUM,"ConsultProhibitedClinicFlag")=$S($$GET1^DIQ(44,+CLINICIEN_",",2500,"I")="Y":1,1:0)
 S REQUEST("Request",NUM,"CPRSStatus")=$$GET1^DIQ(123,CONSULTIEN,8,"E")
 S REQUEST("Request",NUM,"ConsultCanEditPid")=$$CONSCANCELCHECK^SDES2GETCONSULTS(CONSULTIEN,DFN)
 S REQUEST("Request",NUM,"PatientLast4")=$$LAST4SSN^SDESINPUTVALUTL(DFN)
 ; build appointment request and recall
 I '$$GETCONTIEN^SDESCONTACTS(.ERRORS,CONSULTIEN,"C") D
 .D SDECONTACT^SDESGETREQWRAPPR(.REQUEST,NUM)
 D APPTREQUEST^SDESGETREQWRAPPR(.REQUEST,NUM)
 D RECALL^SDESGETREQWRAPPR(.REQUEST,NUM)
 ;
 Q
 ;
BUILDJSON(JSONRETURN,RETURN) ;
 D ENCODE^XLFJSON("RETURN","JSONRETURN","JSONERROR")
 Q
 ;