SDESGETPRFGAPS ;ALB/ANU - VISTA SCHEDULING RPCS ;NOV 22, 2022
;;5.3;Scheduling;**831**;Aug 13, 1993;Build 4
;;Per VHA Directive 6402, this routine should not be modified
;
;External References
;-------------------
; Reference to $$GETS^DIQ,$$GETS1^DIQ in ICR #2056
;
Q
;
PREFGET(JSONRETURN,DFN,INAC) ; Get values from SDEC PREFERENCES AND SPECIAL NEEDS file
;INPUT:
; DFN = (integer) Patient ID - Pointer to the PATIENT file 2
; INAC = (optional) include inactive entries (1-Include; 0-Don't Include)
;RETURN:
; Successful Return:
; 1. (integer) Patient ID - pointer to PATIENT file
; 2. (text) Preference text
; 3. (date/time) Date/Time preference added in external format - defaults to NOW
; 4. (integer) Added by User - Pointer to NEW PERSON file - defaults to Current User
; 5. (text) Added by User Name
; 6. (date/time) Date/Time Inactivated in external format
; 7. (integer) Inactivated by user - Pointer to NEW PERSON file
; 8. (text) Inactivated by user Name
; 9. (text) Remarks
;
N ISDFNVALID,ISINACVALID,RETURN,ERRORS,REQUESTIEN,REQUEST
;
S ISDFNVALID=$$VALIDATEDFN(.ERRORS,$G(DFN))
S ISINACVALID=$$VALIDATEINAC(.ERRORS,$G(INAC))
I $D(ERRORS) M RETURN=ERRORS D BUILDJSON^SDESBUILDJSON(.JSONRETURN,.RETURN) Q
;
I '$D(ERRORS) S HASFIELDS=$$PREFG(.ELGFIELDSARRAY,DFN,INAC)
I HASFIELDS M RETURN=ELGFIELDSARRAY
;
I '$D(RETURN("PatientPref")) S RETURN("PatientPref",1)=""
D BUILDJSON^SDESBUILDJSON(.JSONRETURN,.RETURN)
D CLEANUP
Q
;
PATWARDGET(JSONRETURN,DFN) ; Get values
;INPUT:
; DFN = (integer) Patient ID - Pointer to the PATIENT file 2
;RETURN:
; Successful Return:
; 1. (integer) Patient ID - pointer to PATIENT file
; 2. (text) Patient Name
; 3. (text) Patient Ward
;
N ISDFNVALID,RETURN,ERRORS,REQUESTIEN,REQUEST
;
S ISDFNVALID=$$VALIDATEDFN(.ERRORS,$G(DFN))
I $D(ERRORS) M RETURN=ERRORS D BUILDJSON^SDESBUILDJSON(.JSONRETURN,.RETURN) Q
;
I '$D(ERRORS) S HASFIELDS=$$PATWARD(.ELGFIELDSARRAY,DFN)
I HASFIELDS M RETURN=ELGFIELDSARRAY
;
I '$D(RETURN("InPatient")) S RETURN("InPatient",1)=""
D BUILDJSON^SDESBUILDJSON(.JSONRETURN,.RETURN)
D CLEANUP
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
;
VALIDATEINAC(ERRORS,INAC) ;
I +$G(INAC)'=0,+$G(INAC)'=1 D ERRLOG^SDESJSON(.ERRORS,372) Q 0
Q 1
;
PREFG(ELGARRAY,DFN,INAC) ; Get values from SDEC PREFERENCES AND SPECIAL NEEDS file
;
N PIEN,PIEN1,PIEN1NOD,SDESI,SDI,SDWP,SDMSG,PREFARY,ERR,SDESERR,IENS,HASDATA,X
S SDESI=1
;check for existing patient entry in SDEC PREFERENCES AND SPECIAL NEEDS file
S PIEN=$O(^SDEC(409.845,"B",DFN,0))
I PIEN="" Q 1
S PIEN1=0 F S PIEN1=$O(^SDEC(409.845,PIEN,1,PIEN1)) Q:PIEN1'>0 D
.S PIEN1NOD=^SDEC(409.845,PIEN,1,PIEN1,0)
.I '+$G(INAC) Q:$P(PIEN1NOD,U,4)'=""
.S SDESI=SDESI+1
.S IENS=PIEN1_","_PIEN_","
.D GETS^DIQ(409.8451,IENS,"**","IE","PREFARY","ERR")
.S ELGARRAY("PatientPref",1,"PatientDFN")=DFN
.S ELGARRAY("PatientPref",1,"PatientName")=$$GET1^DIQ(2,DFN_",",.01,"E")
.S ELGARRAY("PatientPref",SDESI,"Preference")=$G(PREFARY(409.8451,IENS,.01,"E"))
.S ELGARRAY("PatientPref",SDESI,"AddedDateTime")=$$FMTISO^SDAMUTDT($G(PREFARY(409.8451,IENS,2,"I")))
.S ELGARRAY("PatientPref",SDESI,"AddedByUserIEN")=$G(PREFARY(409.8451,IENS,3,"I"))
.S ELGARRAY("PatientPref",SDESI,"AddedByUserName")=$G(PREFARY(409.8451,IENS,3,"E"))
.S ELGARRAY("PatientPref",SDESI,"InactiveDate")=$$FMTISO^SDAMUTDT($G(PREFARY(409.8451,IENS,4,"I")))
.S ELGARRAY("PatientPref",SDESI,"InactivatedByUserIEN")=$G(PREFARY(409.8451,IENS,5,"I"))
.S ELGARRAY("PatientPref",SDESI,"InactivatedByUserName")=$G(PREFARY(409.8451,IENS,5,"E"))
.;get remark
.K SDWP S X=$$GET1^DIQ(409.8451,PIEN1_","_PIEN_",",6,"","SDWP","SDMSG")
.S SDWP=""
.S SDI=0 F S SDI=$O(SDWP(SDI)) Q:SDI="" D
..S ELGARRAY("PatientPref",SDESI,"Remarks",SDI)=$G(SDWP(SDI))
S HASDATA=($D(ELGARRAY)>1)
Q HASDATA
;
PATWARD(ELGARRAY,DFN) ; Get values
;
N HASDATA
S ELGARRAY("InPatient","PatientDFN")=DFN
S ELGARRAY("InPatient","PatientName")=$$GET1^DIQ(2,DFN_",",.01,"E")
;S ELGARRAY("PatientHealthInfo","MentalHealthProvider")=$$START^SCMCMHTC(DFN) ;Return Mental Health Provider
;S ELGARRAY("PatientHealthInfo","PrimaryCareProvider")=$$OUTPTPR^SDUTL3(DFN) ;Return Primary Care Provider
S ELGARRAY("InPatient","PatientWard")=$$GET1^DIQ(2,DFN_",",.1,"E")
S HASDATA=($D(ELGARRAY)>1)
Q HASDATA
;
CLEANUP ;
K RETURNERROR,ERRORFLAG,ERRORS,ISRGIENVALID,ISRGNAMEVALID
K RETURN,HASFIELDS,ELGFIELDSARRAY,ELGRETURN
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDESGETPRFGAPS 4857 printed Nov 22, 2024@18:06:53 Page 2
SDESGETPRFGAPS ;ALB/ANU - VISTA SCHEDULING RPCS ;NOV 22, 2022
+1 ;;5.3;Scheduling;**831**;Aug 13, 1993;Build 4
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 ;External References
+5 ;-------------------
+6 ; Reference to $$GETS^DIQ,$$GETS1^DIQ in ICR #2056
+7 ;
+8 QUIT
+9 ;
PREFGET(JSONRETURN,DFN,INAC) ; Get values from SDEC PREFERENCES AND SPECIAL NEEDS file
+1 ;INPUT:
+2 ; DFN = (integer) Patient ID - Pointer to the PATIENT file 2
+3 ; INAC = (optional) include inactive entries (1-Include; 0-Don't Include)
+4 ;RETURN:
+5 ; Successful Return:
+6 ; 1. (integer) Patient ID - pointer to PATIENT file
+7 ; 2. (text) Preference text
+8 ; 3. (date/time) Date/Time preference added in external format - defaults to NOW
+9 ; 4. (integer) Added by User - Pointer to NEW PERSON file - defaults to Current User
+10 ; 5. (text) Added by User Name
+11 ; 6. (date/time) Date/Time Inactivated in external format
+12 ; 7. (integer) Inactivated by user - Pointer to NEW PERSON file
+13 ; 8. (text) Inactivated by user Name
+14 ; 9. (text) Remarks
+15 ;
+16 NEW ISDFNVALID,ISINACVALID,RETURN,ERRORS,REQUESTIEN,REQUEST
+17 ;
+18 SET ISDFNVALID=$$VALIDATEDFN(.ERRORS,$GET(DFN))
+19 SET ISINACVALID=$$VALIDATEINAC(.ERRORS,$GET(INAC))
+20 IF $DATA(ERRORS)
MERGE RETURN=ERRORS
DO BUILDJSON^SDESBUILDJSON(.JSONRETURN,.RETURN)
QUIT
+21 ;
+22 IF '$DATA(ERRORS)
SET HASFIELDS=$$PREFG(.ELGFIELDSARRAY,DFN,INAC)
+23 IF HASFIELDS
MERGE RETURN=ELGFIELDSARRAY
+24 ;
+25 IF '$DATA(RETURN("PatientPref"))
SET RETURN("PatientPref",1)=""
+26 DO BUILDJSON^SDESBUILDJSON(.JSONRETURN,.RETURN)
+27 DO CLEANUP
+28 QUIT
+29 ;
PATWARDGET(JSONRETURN,DFN) ; Get values
+1 ;INPUT:
+2 ; DFN = (integer) Patient ID - Pointer to the PATIENT file 2
+3 ;RETURN:
+4 ; Successful Return:
+5 ; 1. (integer) Patient ID - pointer to PATIENT file
+6 ; 2. (text) Patient Name
+7 ; 3. (text) Patient Ward
+8 ;
+9 NEW ISDFNVALID,RETURN,ERRORS,REQUESTIEN,REQUEST
+10 ;
+11 SET ISDFNVALID=$$VALIDATEDFN(.ERRORS,$GET(DFN))
+12 IF $DATA(ERRORS)
MERGE RETURN=ERRORS
DO BUILDJSON^SDESBUILDJSON(.JSONRETURN,.RETURN)
QUIT
+13 ;
+14 IF '$DATA(ERRORS)
SET HASFIELDS=$$PATWARD(.ELGFIELDSARRAY,DFN)
+15 IF HASFIELDS
MERGE RETURN=ELGFIELDSARRAY
+16 ;
+17 IF '$DATA(RETURN("InPatient"))
SET RETURN("InPatient",1)=""
+18 DO BUILDJSON^SDESBUILDJSON(.JSONRETURN,.RETURN)
+19 DO CLEANUP
+20 QUIT
+21 ;
VALIDATEDFN(ERRORS,DFN) ;
+1 IF DFN=""
DO ERRLOG^SDESJSON(.ERRORS,1)
QUIT 0
+2 IF DFN'=""
IF '$DATA(^DPT(DFN,0))
DO ERRLOG^SDESJSON(.ERRORS,2)
QUIT 0
+3 QUIT 1
+4 ;
VALIDATEINAC(ERRORS,INAC) ;
+1 IF +$GET(INAC)'=0
IF +$GET(INAC)'=1
DO ERRLOG^SDESJSON(.ERRORS,372)
QUIT 0
+2 QUIT 1
+3 ;
PREFG(ELGARRAY,DFN,INAC) ; Get values from SDEC PREFERENCES AND SPECIAL NEEDS file
+1 ;
+2 NEW PIEN,PIEN1,PIEN1NOD,SDESI,SDI,SDWP,SDMSG,PREFARY,ERR,SDESERR,IENS,HASDATA,X
+3 SET SDESI=1
+4 ;check for existing patient entry in SDEC PREFERENCES AND SPECIAL NEEDS file
+5 SET PIEN=$ORDER(^SDEC(409.845,"B",DFN,0))
+6 IF PIEN=""
QUIT 1
+7 SET PIEN1=0
FOR
SET PIEN1=$ORDER(^SDEC(409.845,PIEN,1,PIEN1))
if PIEN1'>0
QUIT
Begin DoDot:1
+8 SET PIEN1NOD=^SDEC(409.845,PIEN,1,PIEN1,0)
+9 IF '+$GET(INAC)
if $PIECE(PIEN1NOD,U,4)'=""
QUIT
+10 SET SDESI=SDESI+1
+11 SET IENS=PIEN1_","_PIEN_","
+12 DO GETS^DIQ(409.8451,IENS,"**","IE","PREFARY","ERR")
+13 SET ELGARRAY("PatientPref",1,"PatientDFN")=DFN
+14 SET ELGARRAY("PatientPref",1,"PatientName")=$$GET1^DIQ(2,DFN_",",.01,"E")
+15 SET ELGARRAY("PatientPref",SDESI,"Preference")=$GET(PREFARY(409.8451,IENS,.01,"E"))
+16 SET ELGARRAY("PatientPref",SDESI,"AddedDateTime")=$$FMTISO^SDAMUTDT($GET(PREFARY(409.8451,IENS,2,"I")))
+17 SET ELGARRAY("PatientPref",SDESI,"AddedByUserIEN")=$GET(PREFARY(409.8451,IENS,3,"I"))
+18 SET ELGARRAY("PatientPref",SDESI,"AddedByUserName")=$GET(PREFARY(409.8451,IENS,3,"E"))
+19 SET ELGARRAY("PatientPref",SDESI,"InactiveDate")=$$FMTISO^SDAMUTDT($GET(PREFARY(409.8451,IENS,4,"I")))
+20 SET ELGARRAY("PatientPref",SDESI,"InactivatedByUserIEN")=$GET(PREFARY(409.8451,IENS,5,"I"))
+21 SET ELGARRAY("PatientPref",SDESI,"InactivatedByUserName")=$GET(PREFARY(409.8451,IENS,5,"E"))
+22 ;get remark
+23 KILL SDWP
SET X=$$GET1^DIQ(409.8451,PIEN1_","_PIEN_",",6,"","SDWP","SDMSG")
+24 SET SDWP=""
+25 SET SDI=0
FOR
SET SDI=$ORDER(SDWP(SDI))
if SDI=""
QUIT
Begin DoDot:2
+26 SET ELGARRAY("PatientPref",SDESI,"Remarks",SDI)=$GET(SDWP(SDI))
End DoDot:2
End DoDot:1
+27 SET HASDATA=($DATA(ELGARRAY)>1)
+28 QUIT HASDATA
+29 ;
PATWARD(ELGARRAY,DFN) ; Get values
+1 ;
+2 NEW HASDATA
+3 SET ELGARRAY("InPatient","PatientDFN")=DFN
+4 SET ELGARRAY("InPatient","PatientName")=$$GET1^DIQ(2,DFN_",",.01,"E")
+5 ;S ELGARRAY("PatientHealthInfo","MentalHealthProvider")=$$START^SCMCMHTC(DFN) ;Return Mental Health Provider
+6 ;S ELGARRAY("PatientHealthInfo","PrimaryCareProvider")=$$OUTPTPR^SDUTL3(DFN) ;Return Primary Care Provider
+7 SET ELGARRAY("InPatient","PatientWard")=$$GET1^DIQ(2,DFN_",",.1,"E")
+8 SET HASDATA=($DATA(ELGARRAY)>1)
+9 QUIT HASDATA
+10 ;
CLEANUP ;
+1 KILL RETURNERROR,ERRORFLAG,ERRORS,ISRGIENVALID,ISRGNAMEVALID
+2 KILL RETURN,HASFIELDS,ELGFIELDSARRAY,ELGRETURN
+3 QUIT
+4 ;