AUPNMBIU ; IHS/OIT/FBD&NKD - MBI API UTILITIES ; 11/02/2017 ;
;;99.1;IHS DICTIONARIES (PATIENT);**26**;MAR 9, 1999;Build 11
;
Q ;NO TOP-LEVEL CALL ALLOWED
;
RAND() ;PEP - RANDOM MBI VALUE GENERATOR
;Function: Return randomly generated MBI value (for testing use)
;Call: $$RAND^AUPNMBIU
;Returned value: Randomly generated text string complying with CMS-defined MBI format
;
;Acceptable MBI Format is:
; 1 1
;Position: 1 2 3 4 5 6 7 8 9 0 1
; ---------------------
; Type: C A X N A X N A A N N
;
;Types are:
; A = Alphabetic characters A-Z
; C = Natural numbers 1-9
; N = Whole numbers 0-9
; X = Alphanumeric characters 0-9 and A-Z
;Letters excluded from use in alphabetics and alphanumerics: S, L, O, B, I, Z
;
N RES
S RES=$$C_$$A_$$X_$$N_$$A_$$X_$$N_$$A_$$A_$$N_$$N
Q RES
;
C() Q $C((49+$R(9))) ;RANDOM GENERATOR FOR NATURAL NUMBERS 1-9
;
N() Q $C((48+$R(10))) ;RANDOM GENERATOR FOR WHOLE NUMBERS 0-9
;
A() ;RANDOM GENERATOR FOR ALPHABETIC CHARACTERS A-Z
N X,EXCLUDE
S EXCLUDE="SLOBIZ" ;EXCLUSIONS FROM ACCEPTABLE CHARACTER LIST
F S X=65+$R(26) Q:EXCLUDE'[$C(X)
Q $C(X)
;
X() ;RANDOM GENERATOR FOR ALPHANUMERIC CHARACTERS 0-9 AND A-Z
N X,EXCLUDE
S EXCLUDE="SLOBIZ" ;EXCLUSIONS FROM ACCEPTABLE CHARACTER LIST
F D Q:$G(X) ;REPEAT LOOP UNTIL AN ACCEPTABLE VALUE PERSISTS THROUGH ALL CHECKS
. S X=48+$R(43) ;RANDOM GENERATOR
. Q:X<58 ;EXIT IF GENERATED RANDOM VALUE FALLS INTO NUMERIC RANGE (ASCII 48-57 = CHARS "0"-"9")
. I X>64 D ;CHECK FURTHER IF GENERATED RANDOM VALUE FALLS INTO ALPHABETIC RANGE (ASCII 65-90 = CHARS "A"-"Z")
. . K:EXCLUDE[$C(X) X ;ELIMINATE IF GENERATED RANDOM VALUE CORRESPONDS TO EXCLUDED ASCII CHAR
. E K X
Q $C(X)
;
AUPNMBIU ; IHS/OIT/FBD&NKD - MBI API UTILITIES ; 11/02/2017 ;
+1 ;;99.1;IHS DICTIONARIES (PATIENT);**26**;MAR 9, 1999;Build 11
+2 ;
+3 ;NO TOP-LEVEL CALL ALLOWED
QUIT
+4 ;
RAND() ;PEP - RANDOM MBI VALUE GENERATOR
+1 ;Function: Return randomly generated MBI value (for testing use)
+2 ;Call: $$RAND^AUPNMBIU
+3 ;Returned value: Randomly generated text string complying with CMS-defined MBI format
+4 ;
+5 ;Acceptable MBI Format is:
+6 ; 1 1
+7 ;Position: 1 2 3 4 5 6 7 8 9 0 1
+8 ; ---------------------
+9 ; Type: C A X N A X N A A N N
+10 ;
+11 ;Types are:
+12 ; A = Alphabetic characters A-Z
+13 ; C = Natural numbers 1-9
+14 ; N = Whole numbers 0-9
+15 ; X = Alphanumeric characters 0-9 and A-Z
+16 ;Letters excluded from use in alphabetics and alphanumerics: S, L, O, B, I, Z
+17 ;
+18 NEW RES
+19 SET RES=$$C_$$A_$$X_$$N_$$A_$$X_$$N_$$A_$$A_$$N_$$N
+20 QUIT RES
+21 ;
C() ;RANDOM GENERATOR FOR NATURAL NUMBERS 1-9
QUIT $CHAR((49+$RANDOM(9)))
+1 ;
N() ;RANDOM GENERATOR FOR WHOLE NUMBERS 0-9
QUIT $CHAR((48+$RANDOM(10)))
+1 ;
A() ;RANDOM GENERATOR FOR ALPHABETIC CHARACTERS A-Z
+1 NEW X,EXCLUDE
+2 ;EXCLUSIONS FROM ACCEPTABLE CHARACTER LIST
SET EXCLUDE="SLOBIZ"
+3 FOR
SET X=65+$RANDOM(26)
IF EXCLUDE'[$CHAR(X)
QUIT
+4 QUIT $CHAR(X)
+5 ;
X() ;RANDOM GENERATOR FOR ALPHANUMERIC CHARACTERS 0-9 AND A-Z
+1 NEW X,EXCLUDE
+2 ;EXCLUSIONS FROM ACCEPTABLE CHARACTER LIST
SET EXCLUDE="SLOBIZ"
+3 ;REPEAT LOOP UNTIL AN ACCEPTABLE VALUE PERSISTS THROUGH ALL CHECKS
FOR
Begin DoDot:1
+4 ;RANDOM GENERATOR
SET X=48+$RANDOM(43)
+5 ;EXIT IF GENERATED RANDOM VALUE FALLS INTO NUMERIC RANGE (ASCII 48-57 = CHARS "0"-"9")
IF X<58
QUIT
+6 ;CHECK FURTHER IF GENERATED RANDOM VALUE FALLS INTO ALPHABETIC RANGE (ASCII 65-90 = CHARS "A"-"Z")
IF X>64
Begin DoDot:2
+7 ;ELIMINATE IF GENERATED RANDOM VALUE CORRESPONDS TO EXCLUDED ASCII CHAR
IF EXCLUDE[$CHAR(X)
KILL X
End DoDot:2
+8 IF '$TEST
KILL X
End DoDot:1
IF $GET(X)
QUIT
+9 QUIT $CHAR(X)
+10 ;