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

SDESADDRG.m

Go to the documentation of this file.
SDESADDRG ;ALB/ANU - VISTA SCHEDULING RPCS - ROUTINE ADD RESOURCE GROUP ;Sept 20, 2022@14:21
 ;;5.3;Scheduling;**825,826**;Aug 13, 1993;Build 18
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 ;External References
 ;-------------------
 ; Reference to $$GETS^DIQ,$$GETS1^DIQ in ICR #2056
 ;
 Q
 ;
 ;
RGADDEDIT(RETURNJSON,SDRGIEN,SDRGNAME) ;ADD/EDIT RESOURCE GROUP
 ;
 ; Input:
 ;    SDRGIEN        [Optional] = Resoruce Group IEN
 ;    SDRGNAME       [Required] = Resource Group Name
 ;
 ; Output:
 ;    RETURNJSON = Returns IEN of added/edited entry or 0 if error.
 ;
 N RETURN,HASFIELDS,ELGFIELDSARRAY,ELGRETURN
 N ISRGIENVALID,ISRGNAMEVALID
 S (RETURN,ELGFIELDSARRAY,HASFIELDS)=""
 ;
 S ISRGIENVALID=$$VALIDATERGIEN(.ERRORS,$G(SDRGIEN))
 S ISRGNAMEVALID=$$VALIDATERGNAME(.ERRORS,$G(SDRGNAME))
 ;
 I $D(ERRORS) M RETURN=ERRORS
 I '$D(ERRORS) S HASFIELDS=$$RGMOD(.ELGFIELDSARRAY,$G(SDRGIEN),SDRGNAME)
 I HASFIELDS M RETURN=ELGFIELDSARRAY
 ;
 D BUILDJSON^SDESBUILDJSON(.RETURNJSON,.RETURN)
 D CLEANUP
 Q
 ;
DELRESGP(RETURNJSON,SDRGNAME) ;Deletes entry name SDRGNAME from SDEC RESOURCE GROUP file
 ; Input:
 ; SDRGNAME     [Required] = Resource Group Name
 ;
 ; Output:
 ;    RETURNJSON - Returns Status (Success or Failure)
 ;
 ; Called by SDES DELETE RESGRP
 ;
 N RETURN,HASFIELDS,ELGFIELDSARRAY,ELGRETURN
 N ISRGNAMEVALID
 S (RETURN,ELGFIELDSARRAY,HASFIELDS)=""
 ;
 S ISRGNAMEVALID=$$VALIDATERGNAME1(.ERRORS,$G(SDRGNAME))
 ;
 I $D(ERRORS) M RETURN=ERRORS
 I '$D(ERRORS) S HASFIELDS=$$RGMOD1(.ELGFIELDSARRAY,SDRGNAME)
 I HASFIELDS M RETURN=ELGFIELDSARRAY
 ;
 D BUILDJSON^SDESBUILDJSON(.RETURNJSON,.RETURN)
 D CLEANUP
 Q
 ;
VALIDATERGIEN(ERRORS,SDRGIEN) ; Validate Resource Group IEN
 N ERRORFLAG
 I SDRGIEN'="" I '$D(^SDEC(409.832,SDRGIEN,0)) S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,276) Q $D(ERRORFLAG)
 Q $D(ERRORFLAG)
 ;
VALIDATERGNAME(ERRORS,SDRGNAME) ; Validate Resource Group Name
 N ERRORFLAG
 I SDRGNAME="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,275) Q $D(ERRORFLAG) ;Name required
 I ($L($$TRIM^XLFSTR(SDRGNAME))<3)!($L($$TRIM^XLFSTR(SDRGNAME))>30) S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,310) Q $D(ERRORFLAG) ;Length is wrong
 ;I SDRGNAME'="" I '$D(^SDEC(409.832,SDRGNAME,0)) S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,276) Q $D(ERRORFLAG) ; Invalid Resource Group/Resource Grp not found
 ;Prevent adding entry with duplicate name
 I SDRGNAME'="",$D(^SDEC(409.832,"B",SDRGNAME)),$O(^SDEC(409.832,"B",SDRGNAME,0))'=$G(SDRGIEN) D  Q $D(ERRORFLAG)
 . S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,274) ;Cannot have two Resource Groups with the same name.
 . Q
 Q $D(ERRORFLAG)
 ;
VALIDATERGNAME1(ERRORS,SDRGNAME) ; Validate Resource Group Name
 N ERRORFLAG
 I SDRGNAME="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,275) Q $D(ERRORFLAG) ;Name required
 I SDRGNAME'="" I '$D(^SDEC(409.832,"B",SDRGNAME)) S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,315) Q $D(ERRORFLAG) ; RESOURCE GROUP NAME NOT FOUND
 Q $D(ERRORFLAG)
 ;
RGMOD(ELGARRAY,SDRGIEN,SDRGNAME) ; Add or Edit Resource Group Name
 N SDRGIENS,SDRGFDA,SDRGMSG,HASDATA,SDRGM1
 S ELGARRAY("Status","IEN")=0
 S ELGARRAY("Status","Message")=""
 S SDRGM1=""
 I +SDRGIEN D
 . S SDRGIENS=SDRGIEN_","
 . S SDRGFDA(409.832,SDRGIENS,.01)=SDRGNAME ;NAME
 . D FILE^DIE("","SDRGFDA","SDRGMSG")
 . S SDRGM1="Successfully updated."
 I '+SDRGIEN D
 . S SDRGIENS="+1,"
 . K SDRGIEN
 . S SDRGFDA(409.832,SDRGIENS,.01)=SDRGNAME ;NAME
 . D UPDATE^DIE("","SDRGFDA","SDRGIENS","SDRGMSG")
 . S SDRGIEN=+$G(SDRGIENS(1))
 . S SDRGM1="Successfully added."
 S ELGARRAY("Status","IEN")=$G(SDRGIEN)
 S ELGARRAY("Status","Message")=$G(SDRGM1)
 S HASDATA=($D(ELGARRAY)>1)
 Q HASDATA
 ;
RGMOD1(ELGARRAY,SDRGNAME) ; Delete Resource Group Name
 N HASDATA,SDFDA,SDMSG,SDESIEN,DA,DIK
 S SDESIEN=$O(^SDEC(409.832,"B",SDRGNAME,0))
 ;Delete entry SDECIEN
 S DIK="^SDEC(409.832,"
 S DA=SDESIEN
 D ^DIK
 ;
 K SDESIEN
 S SDESIEN=$O(^SDEC(409.832,"B",SDRGNAME,0))
 I $G(SDESIEN)'="" S ELGARRAY("Status")="0^Error in deleting Resource Group."
 I $G(SDESIEN)="" S ELGARRAY("Status")="1^Resource Group is successfully deleted."
 S HASDATA=($D(ELGARRAY)>1)
 Q HASDATA
 ;
CLEANUP ;
 K RETURNERROR,ERRORFLAG,ERRORS,ISRGNAMEVALID,ISRGIENVALID
 K SDRGIENS,SDRGFDA,SDRGMSG
 Q
 ;