BIXRPC ;IHS/CMI/MWR - BI REMOTE PROCEDURE CALLS; MAY 10, 2010
;;8.5;IMMUNIZATION;;SEP 01,2011
;;* MICHAEL REMILLARD, DDS * CIMARRON MEDICAL INFORMATICS, FOR IHS *
;; GENERIC LOOKUP UTILITY FOR RETURNING MATCHING RECORDS
;; OR TABLES TO RPC'S.
;
; *** NOTE: I have discovered a number of cases where these calls
; produce errors (with error messages to IO) or simply
; do not work correctly. ANY CALL to this utility
; should be thoroughly tested in the M environment
; before being used as an RPC.
;
;----------
LOOKUP(BIGBL,BIFL,BIFLDS,BIFLG,BIIN,BIMX,BIIX,BISCR,BIMC) ;EP
;---> Places matching records from requested file into a
;---> result global, ^BITEMP($J). The exact global name
;---> is returned in the first parameter (BIGBL).
;---> Records are returned one per node in the result global.
;---> Each record is terminated with a $C(30), for parsing out
;---> on the VB side, since the Broker concatenates all nodes
;---> into a single string when passing the data out of M.
;---> Requested fields within records are delimited by "^".
;---> NOTE: The first "^"-piece of every node is the IEN of
;---> that entry in its file; the requested fields follow.
;---> The final record (node) contains Error Delimiter,
; $C(31)_$C(31), followed by error text, if any.
;
;---> Parameters:
; 1 - BIGBL (ret) Name of result global for Broker.
; 2 - BIFL (req) File for lookup.
; 3 - BIFLDS (opt) Fields to return w/each entry.
; 4 - BIFLG (opt) Flags in DIC(0); If null, "M" is sent.
; 5 - BIIN (opt) Input to match on (see Algorithm below).
; 6 - BIMX (opt) Maximum number of entries to return.
; 7 - BIIX (opt) Indexes to search.
; 8 - BISCR (opt) Screen/filter (M code).
; 9 - BIMC (opt) Mixed Case: 1=mixed case, 0=no change.
; (Converts data in uppercase to mixed case.)
;
;---> Set variables, kill temp globals.
N (BIGBL,BIFL,BIFLDS,BIFLG,BIIN,BIMX,BIIX,BISCR,BIMC)
S BI31=$C(31)_$C(31)
S BIGBL="^BITEMP("_$J_")",BIERR="",U="^"
K ^BITMP($J),^BITEMP($J)
;
;---> If file number not provided, return error.
I '$G(BIFL) D ERROUT("File number not provided.",1) Q
;
;---> If no fields provided, pass .01.
;---> IEN will always be the first piece of data returned.
;---> NOTE: If .01 is NOT included, but the Index to lookup on is
;---> NOT on the .01, then the .01 will be returned
;---> automatically as the second ^-piece of data in the
;---> Result Global.
;---> So it would be: IEN^.01^requested fields...
I $G(BIFLDS)="" S BIFLDS=".01"
;
;---> If no index or flag provided, set flag="M".
I $G(BIFLG)="" D
.I $G(BIIX)="" S BIFLG="M" Q
.S BIFLG=""
;
;---> If no Maximum Number provided, set it to 200.
I '$G(BIMX) S BIMX=200
;
;---> Define index and screen.
S:'$D(BIIX) BIIX=""
S:'$D(BISCR) BISCR=""
;
;---> Set Target Global for output and errors.
S BIG="^BITMP($J)"
;
;---> If Mixed Case not set, set to No Change.
I '$D(BIMC) S BIMC=0
;
;---> Silent Fileman call.
D
.I $G(BIIN)="" D Q
..D LIST^DIC(BIFL,,BIFLDS,,BIMX,0,,BIIX,BISCR,,BIG,BIG)
.D FIND^DIC(BIFL,,BIFLDS,BIFLG,BIIN,BIMX,BIIX,BISCR,,BIG,BIG)
;
D WRITE
Q
;
;
;----------
WRITE ;EP
;---> Collect data for matching records and write in result global.
;
;---> First, check for errors.
;---> If errors exist, write them and quit.
N I,N,X
I $D(^BITMP($J,"DIERR")) I $O(^("DIERR",0)) D Q
.S N=0,X=""
.F S N=$O(^BITMP($J,"DIERR",N)) Q:'N D
..N M S M=0
..F S M=$O(^BITMP($J,"DIERR",N,"TEXT",M)) Q:'M D
...S X=X_^BITMP($J,"DIERR",N,"TEXT",M)_" "
.D ERROUT(X,1)
;
;
;---> Write valid results.
;---> Loop through the IEN node (...2,N) of the temp global.
N I,N,X S N=0
F I=1:1 S N=$O(^BITMP($J,"DILIST",2,N)) Q:'N D
.;---> Always set first piece of X=IEN of entry.
.S X=^BITMP($J,"DILIST",2,N)
.;
.;---> Collect other fields and concatenate to X.
.N M S M=0
.F S M=$O(^BITMP($J,"DILIST","ID",N,M)) Q:'M D
..S X=X_U_^BITMP($J,"DILIST","ID",N,M)
.;
.;---> Convert data to mixed case if BIMC=1.
.S:BIMC X=$$T^BITRS(X)
.;
.;---> Set data in result global.
.S ^BITEMP($J,I)=X_$C(30)
;
;---> If no results, report it as an error.
D:'$O(^BITEMP($J,0))
.I BIIN]"" S BIERR="No entry matches """_BIIN_"""." Q
.S BIERR="Either the lookup file is empty"
.S BIERR=BIERR_" or all entries are screened (software error)."
;
;---> Tack on Error Delimiter and any error.
S ^BITEMP($J,I)=BI31_BIERR
Q
;
;
;----------
ERROUT(BIERR,I) ;EP
;---> Save next line for Error Code File if ever used.
;---> If necessary, use I>1 to avoid overwriting valid data.
;D ERRCD^BIUTL2(BIERR,.BIERR)
S:'$G(I) I=1
S ^BITEMP($J,I)=BI31_BIERR
Q
;
;
PASSERR(BIGBL,BIERR) ;EP
;---> If the RPC routine calling the BI Generic Lookup above
;---> detects a specific error prior to the call and wants to pass
;---> that error in the result global rather than a generic error,
;---> then a call to this function (PASSERR) can be made.
;---> This call will store the error text passed in the result global.
;---> The calling routine should then quit (abort its call to the
;---> BI Generic Lookup function above).
;
;---> Parameters:
; 1 - BIGBL (ret) Name of result global for Broker.
; 2 - BIERR (req) Text of error to be stored in result global.
;
S:$G(BIERR)="" BIERR="Error not passed (software error)."
;
N BI31 S BI31=$C(31)_$C(31)
K ^BITMP($J),^BITEMP($J)
S BIGBL="^BITEMP("_$J_")"
S ^BITEMP($J,1)=BI31_BIERR
Q
BIXRPC ;IHS/CMI/MWR - BI REMOTE PROCEDURE CALLS; MAY 10, 2010
+1 ;;8.5;IMMUNIZATION;;SEP 01,2011
+2 ;;* MICHAEL REMILLARD, DDS * CIMARRON MEDICAL INFORMATICS, FOR IHS *
+3 ;; GENERIC LOOKUP UTILITY FOR RETURNING MATCHING RECORDS
+4 ;; OR TABLES TO RPC'S.
+5 ;
+6 ; *** NOTE: I have discovered a number of cases where these calls
+7 ; produce errors (with error messages to IO) or simply
+8 ; do not work correctly. ANY CALL to this utility
+9 ; should be thoroughly tested in the M environment
+10 ; before being used as an RPC.
+11 ;
+12 ;----------
LOOKUP(BIGBL,BIFL,BIFLDS,BIFLG,BIIN,BIMX,BIIX,BISCR,BIMC) ;EP
+1 ;---> Places matching records from requested file into a
+2 ;---> result global, ^BITEMP($J). The exact global name
+3 ;---> is returned in the first parameter (BIGBL).
+4 ;---> Records are returned one per node in the result global.
+5 ;---> Each record is terminated with a $C(30), for parsing out
+6 ;---> on the VB side, since the Broker concatenates all nodes
+7 ;---> into a single string when passing the data out of M.
+8 ;---> Requested fields within records are delimited by "^".
+9 ;---> NOTE: The first "^"-piece of every node is the IEN of
+10 ;---> that entry in its file; the requested fields follow.
+11 ;---> The final record (node) contains Error Delimiter,
+12 ; $C(31)_$C(31), followed by error text, if any.
+13 ;
+14 ;---> Parameters:
+15 ; 1 - BIGBL (ret) Name of result global for Broker.
+16 ; 2 - BIFL (req) File for lookup.
+17 ; 3 - BIFLDS (opt) Fields to return w/each entry.
+18 ; 4 - BIFLG (opt) Flags in DIC(0); If null, "M" is sent.
+19 ; 5 - BIIN (opt) Input to match on (see Algorithm below).
+20 ; 6 - BIMX (opt) Maximum number of entries to return.
+21 ; 7 - BIIX (opt) Indexes to search.
+22 ; 8 - BISCR (opt) Screen/filter (M code).
+23 ; 9 - BIMC (opt) Mixed Case: 1=mixed case, 0=no change.
+24 ; (Converts data in uppercase to mixed case.)
+25 ;
+26 ;---> Set variables, kill temp globals.
+27 NEW (BIGBL,BIFL,BIFLDS,BIFLG,BIIN,BIMX,BIIX,BISCR,BIMC)
+28 SET BI31=$CHAR(31)_$CHAR(31)
+29 SET BIGBL="^BITEMP("_$JOB_")"
SET BIERR=""
SET U="^"
+30 KILL ^BITMP($JOB),^BITEMP($JOB)
+31 ;
+32 ;---> If file number not provided, return error.
+33 IF '$GET(BIFL)
DO ERROUT("File number not provided.",1)
QUIT
+34 ;
+35 ;---> If no fields provided, pass .01.
+36 ;---> IEN will always be the first piece of data returned.
+37 ;---> NOTE: If .01 is NOT included, but the Index to lookup on is
+38 ;---> NOT on the .01, then the .01 will be returned
+39 ;---> automatically as the second ^-piece of data in the
+40 ;---> Result Global.
+41 ;---> So it would be: IEN^.01^requested fields...
+42 IF $GET(BIFLDS)=""
SET BIFLDS=".01"
+43 ;
+44 ;---> If no index or flag provided, set flag="M".
+45 IF $GET(BIFLG)=""
Begin DoDot:1
+46 IF $GET(BIIX)=""
SET BIFLG="M"
QUIT
+47 SET BIFLG=""
End DoDot:1
+48 ;
+49 ;---> If no Maximum Number provided, set it to 200.
+50 IF '$GET(BIMX)
SET BIMX=200
+51 ;
+52 ;---> Define index and screen.
+53 IF '$DATA(BIIX)
SET BIIX=""
+54 IF '$DATA(BISCR)
SET BISCR=""
+55 ;
+56 ;---> Set Target Global for output and errors.
+57 SET BIG="^BITMP($J)"
+58 ;
+59 ;---> If Mixed Case not set, set to No Change.
+60 IF '$DATA(BIMC)
SET BIMC=0
+61 ;
+62 ;---> Silent Fileman call.
+63 Begin DoDot:1
+64 IF $GET(BIIN)=""
Begin DoDot:2
+65 DO LIST^DIC(BIFL,,BIFLDS,,BIMX,0,,BIIX,BISCR,,BIG,BIG)
End DoDot:2
QUIT
+66 DO FIND^DIC(BIFL,,BIFLDS,BIFLG,BIIN,BIMX,BIIX,BISCR,,BIG,BIG)
End DoDot:1
+67 ;
+68 DO WRITE
+69 QUIT
+70 ;
+71 ;
+72 ;----------
WRITE ;EP
+1 ;---> Collect data for matching records and write in result global.
+2 ;
+3 ;---> First, check for errors.
+4 ;---> If errors exist, write them and quit.
+5 NEW I,N,X
+6 IF $DATA(^BITMP($JOB,"DIERR"))
IF $ORDER(^("DIERR",0))
Begin DoDot:1
+7 SET N=0
SET X=""
+8 FOR
SET N=$ORDER(^BITMP($JOB,"DIERR",N))
IF 'N
QUIT
Begin DoDot:2
+9 NEW M
SET M=0
+10 FOR
SET M=$ORDER(^BITMP($JOB,"DIERR",N,"TEXT",M))
IF 'M
QUIT
Begin DoDot:3
+11 SET X=X_^BITMP($JOB,"DIERR",N,"TEXT",M)_" "
End DoDot:3
End DoDot:2
+12 DO ERROUT(X,1)
End DoDot:1
QUIT
+13 ;
+14 ;
+15 ;---> Write valid results.
+16 ;---> Loop through the IEN node (...2,N) of the temp global.
+17 NEW I,N,X
SET N=0
+18 FOR I=1:1
SET N=$ORDER(^BITMP($JOB,"DILIST",2,N))
IF 'N
QUIT
Begin DoDot:1
+19 ;---> Always set first piece of X=IEN of entry.
+20 SET X=^BITMP($JOB,"DILIST",2,N)
+21 ;
+22 ;---> Collect other fields and concatenate to X.
+23 NEW M
SET M=0
+24 FOR
SET M=$ORDER(^BITMP($JOB,"DILIST","ID",N,M))
IF 'M
QUIT
Begin DoDot:2
+25 SET X=X_U_^BITMP($JOB,"DILIST","ID",N,M)
End DoDot:2
+26 ;
+27 ;---> Convert data to mixed case if BIMC=1.
+28 IF BIMC
SET X=$$T^BITRS(X)
+29 ;
+30 ;---> Set data in result global.
+31 SET ^BITEMP($JOB,I)=X_$CHAR(30)
End DoDot:1
+32 ;
+33 ;---> If no results, report it as an error.
+34 IF '$ORDER(^BITEMP($JOB,0))
Begin DoDot:1
+35 IF BIIN]""
SET BIERR="No entry matches """_BIIN_"""."
QUIT
+36 SET BIERR="Either the lookup file is empty"
+37 SET BIERR=BIERR_" or all entries are screened (software error)."
End DoDot:1
+38 ;
+39 ;---> Tack on Error Delimiter and any error.
+40 SET ^BITEMP($JOB,I)=BI31_BIERR
+41 QUIT
+42 ;
+43 ;
+44 ;----------
ERROUT(BIERR,I) ;EP
+1 ;---> Save next line for Error Code File if ever used.
+2 ;---> If necessary, use I>1 to avoid overwriting valid data.
+3 ;D ERRCD^BIUTL2(BIERR,.BIERR)
+4 IF '$GET(I)
SET I=1
+5 SET ^BITEMP($JOB,I)=BI31_BIERR
+6 QUIT
+7 ;
+8 ;
PASSERR(BIGBL,BIERR) ;EP
+1 ;---> If the RPC routine calling the BI Generic Lookup above
+2 ;---> detects a specific error prior to the call and wants to pass
+3 ;---> that error in the result global rather than a generic error,
+4 ;---> then a call to this function (PASSERR) can be made.
+5 ;---> This call will store the error text passed in the result global.
+6 ;---> The calling routine should then quit (abort its call to the
+7 ;---> BI Generic Lookup function above).
+8 ;
+9 ;---> Parameters:
+10 ; 1 - BIGBL (ret) Name of result global for Broker.
+11 ; 2 - BIERR (req) Text of error to be stored in result global.
+12 ;
+13 IF $GET(BIERR)=""
SET BIERR="Error not passed (software error)."
+14 ;
+15 NEW BI31
SET BI31=$CHAR(31)_$CHAR(31)
+16 KILL ^BITMP($JOB),^BITEMP($JOB)
+17 SET BIGBL="^BITEMP("_$JOB_")"
+18 SET ^BITEMP($JOB,1)=BI31_BIERR
+19 QUIT