BMXADOXY ; IHS/CIHA/GIS - RPC CALL: GENERATE AN ADO SCHEMA STRING AND DATA SET ;
;;2.0;BMX;;FEB 26, 2007
; EXMAPLES OF FILEMAN SCHEMA GENERATION
;
;
;
DISP(OUT) ; TEMP DISPLAY OF THE ANR
N I,X
S I=0 W !
F S I=$O(@OUT@(I)) Q:'I S X=@OUT@(I) S X=$TR(X,$C(30),"}") S X=$TR(X,$C(31),"{") W !,X
Q
;
SCHEMA(NAME) ; GIVEN SCHEMA NAME, RETURN THE IEN
N IEN
S IEN=$O(^BMXADO("B",NAME,0))
Q IEN
;
NUM ; ITERATE BY IEN
; IX="",START WITH IEN=1, STOP AFTER IEN=20, MAX # RECORDS RETURNED = 5
; TO VIEW INTERNAL VALUES SET VSTG="~1~20~5~I"
N OUT,%,SIEN
S SIEN=$$SCHEMA("IHS PATIENT")
D SS^BMXADO(.OUT,SIEN,"","~1~20~5")
D DISP(OUT) R %:$G(DTIME,60)
K ^TMP("BMX ADO",$J)
Q
;
IX ; ITERATE BY INDEX
; ITERATE USING THE "B" INDEX
; START WITH PT NAME "C", STOP AFTER PATIENT NAME = "D", MAX # RECORDS RETURNED = 5
N OUT,%,SIEN
S SIEN=$$SCHEMA("IHS PATIENT")
D SS^BMXADO(.OUT,SIEN,"","B~C~D~5")
D DISP(OUT) R %:$G(DTIME,60)
K ^TMP("BMX ADO",$J)
Q
;
RENT ; ITERATE IN CHUNKS
; RE-ITERATE USING THE "B" INDEX
; START WITH PT IEN 5 AS THE "SEED", STOP AFTER PATIENT NAME = "D", MAX # RECORDS RETURNED = 5
N OUT,%,SIEN,SEED,LSEED,X,Y
S SEED=0,LSEED=""
S SIEN=$$SCHEMA("IHS PATIENT")
RIT F D I '$G(SEED) Q
. D SS^BMXADO(.OUT,SIEN,SEED,"B~CA~CB~5")
. D DISP(OUT) R %:$G(DTIME,60) E S SEED="" Q
. I %?1"^" S SEED="" Q
. S X=$P(@OUT@(1),U,1)
. S SEED=$P(X,"|",3)
. I SEED=LSEED S SEED="" Q
. S LSEED=SEED
. K ^TMP("BMX ADO",$J)
. Q
Q
;
SUB ; SUBFILE ITERATION
; THE SCHEMA IS ATTACHED TO THE MEDICARE ELIGIBILITY FILE/ELIG DATE SUBFILE
; THE DA STRING HAS A VALUE OF '4,',: THE IEN IN THE PARENT FILE (PATIENT DFN).
; NOTE THE COMMA IN THE DA STRING. THIS INDICATES THAT THE FILE IEN IS 4 BUT THE SUBFILE IEN IS UNSPECIFIED
N OUT,%,SIEN
S SIEN=$$SCHEMA("UPDATE MEDICARE DATES")
;D SS^BMXADO(.OUT,SIEN,"1,","~~~")
D SS^BMXADO(.OUT,18,"1,","~~~")
D DISP(OUT) R %:$G(DTIME,60)
K ^TMP("BMX ADO",$J)
Q
;
DINUM ; DINUMED POINTER ITERATION
; THE SCHEMA IS ATTACHED TO THE PATIENT FILE (9000001)
; THE PATIENT FILE IS DINUM'D AND ITS .01 FIELD POINTS TO THE VA PATIENT FILE (2)
; BECAUSE OF THE SPECIAL RELATIONSHIP BETWEEN THE FILES, WE CAN USE THE B INDEX OF FILE 2 TO ITERATE FILE 9000001.
N OUT,%,SIEN
S SIEN=$$SCHEMA("IHS PATIENT")
D SS^BMXADO(.OUT,SIEN,"","B~A~B~5")
D DISP(OUT) R %:$G(DTIME,60)
K ^TMP("BMX ADO",$J)
Q
;
IXP ; INDEXED POINTER ITERATION
; THE SCHEMA IS ATTACHED TO THE V POV FILE
; THE AC CROSS REFERENCE INDEXES THE PATIENT FIELD
; BY STARTING AND STOPING WITH PATIENT 235 (MAX=5) WE COLLECT THE FIRST 5 POVS FOR PATIENT 235 IN THE FILE
N OUT,%,SIEN
S SIEN=$$SCHEMA("VIEW POVS")
D SS^BMXADO(.OUT,SIEN,"","AC~235~235~5")
D DISP(OUT) R %:$G(DTIME,60)
K ^TMP("BMX ADO",$J)
Q
;
AA ; ITERATE USING AA INDEX
; INDEX IS 'AA" THE START AND STOP DATES ARE SPECIFIED IN EXTERNAL FORMAT. MAX=10
; THE FOLLOWING FILTERS ARE SPECIFIED IN THE LAST PARAMETER ("235|WT|C"):
; 235=PATIENT DFN #235
; WT=RETURN ONLY WEIGHTS. MEASUREMENT TYPE MUST BE SPECIFIED WITH A VALID, UNAMBIGUOUS LOOKUP VALUE.
; C=RETRUN VALUES IN CHRONOLOGICAL ORDER USE 'R' INSTEAD OF 'C' FOR REVERSE CHRONOLOGICAL ORDER. DEFAULT=C
; THE SEED PARAMTER IS SET AND CAN BE USED TO RETURN DATA IN CHUNKS
N OUT,%,SIEN
S SIEN=$$SCHEMA("VIEW MEASUREMENTS")
D SS^BMXADO(.OUT,SIEN,"","AA~3/21/1965~6/4/2004~5~~~~235|WT|C")
D DISP(OUT) R %:$G(DTIME,60)
K ^TMP("BMX ADO",$J)
Q
;
AA2 ; ITERATE USING AA INDEX
; THIS SCHEMA IS ATTACHED TO THE VISIT FILE (9000010)
; IN THIS CASE THERE IS NO ATTRIBUTE TYPE SO THE FILTER PARAM HAS ONLY 2 PIECES "1|R"
; 235=PATIENT DFN
; R=RETURN DATA IN REVERSE CHRONOLOGICAL ORDER
N OUT,%,SIEN
S SIEN=$$SCHEMA("VISITS") ;12
D SS^BMXADO(.OUT,SIEN,"","AA~3/21/1965~6/4/2004~5~~~~235|R")
D DISP(OUT) R %:$G(DTIME,60)
K ^TMP("BMX ADO",$J)
Q
;
CIT ; CUSTOM ITERATOR
; IF COMPLEX OR UNUSUAL SORTING/FILTERING IS REQUITED, USE A CUSTOM ITERATOR
; THE CUSTOM ITERATOR IS DEFINED BY 6TH, 7TH AND 8TH PIECES IN THE VSTG
; PIECE 8=TAG, PIECE 9=ROUTINE, PIECE 8=A PARAMETER PASSED TO THE ENTRY POINT
; THE 9TH PIECE CONTAINS PT DFN, TIMESTAMP, VISIT TYPE, LOC IEN, AND SERVICE CATEGORY IN A "|" DELIMTED STRING
; THE ITERATOR CALL TAG^ROUTINE(PARAM) TO GENERATE IENS
; IN THIS CASE THE SCHEMA IS ATTACHED TO THE VISIT FILE.
; GIVEN THE INFORMATION IN THE PARAMETER, THE CUSTOM ITERATOR RETURNS POSSIBLE DUPLICATE VISITS
N OUT,%,SIEN
S SIEN=$$SCHEMA("VISITS")
D SS^BMXADO(.OUT,SIEN,"","~~~~~DUPV~BMXADOV2~9285|5/24/04@1PM|I|516|~")
D DISP(OUT) R %:$G(DTIME,60)
K ^TMP("BMX ADO",$J)
Q
;
ID ; IDENTIFIER FIELD
; THE SCHEMA IS ATTACHED TO THE VA PATIENT FILE (2)
; THE SCHEMA HAS A BUILT IN FIELD (.01ID) THAT RETURNS THE IDENTIFIERS
; THE ENTRY POINT THAT GENERATES THE IDETIFIERS IS STORED IN THE BMX ADO SCHEMA FILE
; PATIENT DFN=235
N OUT,%,SIEN
S SIEN=$$SCHEMA("UPDATE PATIENT DEMOGRAPHICS")
D SS^BMXADO(.OUT,SIEN,"","~235~235~")
D DISP(OUT) R %:$G(DTIME,60)
K ^TMP("BMX ADO",$J)
Q
;
JSTD ; STANDARD JOIN
; BY SPECIFYING A JOIN IN THE VSTG, MULTIPLE SCHEMAE AND DATA SETS ARE RETURNED IN ONE PASS
; THE SCHEMA IS ATTACHED TO THE V MEASUREMENT FILE
; THIS IS JOINED TO A SECOND FILE, THE VA PATIENT FILE VIA A JOIN
; THE JOIN IS BASTED ON THE FACT THAT THE PATIENT FIELD (.02) IN THE V MEASUREMENT FILE POINTS TO THE VA PATIENT FILE
; THE JOIN PARAMETER IS THE 9TH PIECE OF THE VSTG. IT CONSISTS OF 2 PIECES DELIMITED BY A ","
; PIECE 1 IS THE SCHEMA THAT YOU ARE JOINING TO
; PIECE 2 IS THE FIELD IN THE PRIMARY FILE THAT ENABLES THE JOIN
; THE DATA SET FROM THE SECOND (JOIN) FILE CONTAINS ONLY THOSE RECORDS NECESSARY TO COMPLETE THE JOIN
; PATIENT DFN=235, INDEX=AA, MAX=5, START=3/21/65, STOP=6/4/04
N OUT,%,SIEN1,SIEN2
S SIEN2=$$SCHEMA("VIEW MEASUREMENTS")
S SIEN1=$$SCHEMA("PATIENT DEMOGRAPHICS")
;SIEN1=23, SIEN2=11
;D SS^BMXADO(.OUT,SIEN1,"","AA~3/21/1965~6/4/2004~5~~~~234|WT|C~"_SIEN2_",.02")
D SS^BMXADO(.OUT,SIEN1,"","~234~236~~~~~~"_SIEN2_",.01")
D DISP(OUT) R %:$G(DTIME,60)
K ^TMP("BMX ADO",$J)
Q
;
HWSTD ;
; PATIENT DFN=235, INDEX=AA, MAX=5, START=3/21/65, STOP=6/4/04
N OUT,%,SIEN1,SIEN2
S SIEN1=$$SCHEMA("PATIENT DEMOGRAPHICS")
S SIEN2=$$SCHEMA("VIEW MEASUREMENTS")
;SIEN2=23, SIEN1=11
D SS^BMXADO(.OUT,SIEN1,"","~235~250~~~~~~"_SIEN2_",.01")
D DISP(OUT) R %:$G(DTIME,60)
K ^TMP("BMX ADO",$J)
Q
;
JMD ;JOIN MASTER TO DETAIL
N OUT,%,SIEN1,SIEN2,SIEN3,VSTG
S SIEN1=$$SCHEMA("PATIENT DEMOGRAPHICS")
S SIEN2=$$SCHEMA("VIEW MEASUREMENTS")
S SIEN3=$$SCHEMA("VIEW MEDS")
S VSTG="~1~5~~~~~~"
;S VSTG=VSTG_SIEN3_",.001,.02IEN,AA~1/1/1960~6/30/2004~~~~~|C"
S VSTG=VSTG_SIEN3_",.001,.02IEN,AA~1/1/1960~6/30/2004~~~~~|C"
;S VSTG="~1~5~~~~~~23,.001,.02IEN,AA~1/1/1960~6/30/2004~~~~~|WT|C"
;BMX ADO SS^11^^~1~5~~~~~~23,.001,.02IEN,AA~1/1/1960~6/30/2004~~~~~|WT|C
;BMX ADO SS^11^^~1~5~~~~~~25,.001,.02IEN,AA~1/1/1960~6/30/2004~~~~~|C
D SS^BMXADO(.OUT,SIEN1,"",VSTG)
D DISP(OUT) R %:$G(DTIME,60)
K ^TMP("BMX ADO",$J)
Q
;
JSUB ; SUBFILE JOIN
; IN THIS CASE THE RECORDS IN A PARENT FILE ARE "JOINED" TO THE RECORDS IN ONE OF ITS SUB FILES
; THE SCHEMA IS ATTACHED TO THE "MEDICARE ELIGIBLE" FILE
; IT IS JOINED TO ITS SUBFILE, "ELIG DATES", VIA THE UPDATE MEDICARE DATES SCHEMA
; THE SYNTAX FOR THE JOIN PIECE IS "sien2,SUB" WHERE sien2=IEN OF SECOND SCHEMA
; PATIENT DFN=4
N OUT,%,SIEN1,SIEN2
S SIEN1=$$SCHEMA("UPDATE MEDICARE INFO") ;17
S SIEN2=$$SCHEMA("UPDATE MEDICARE DATES") ;18
;BMX ADO SS^17^^~4~5~~~~~~18,SUB
D SS^BMXADO(.OUT,SIEN1,"","~4~5~~~~~~"_SIEN2_",SUB")
D DISP(OUT) R %:$G(DTIME,60)
K ^TMP("BMX ADO",$J)
Q
;
JPAR ; PARENT FILE JOIN
; SIMILAR TO A SUBFILE JOIN EXCEPT THE SUB-FILE IS TREATED AS THE PRIMARY FILE AND IT IS JOINED TO ITS PARENT
; BECAUSE WE ARE STARTING IN A SUBFILE, THE DA STRING CONTAINS THE IEN OF THE PARENT FILE ("4,"
; THE SYNTAX OF THE 9TH PIECE IS "sien2,PARENT" WHERE sien2 IS THE IEN OF THE SECONDARY SCHEMA
; PATIENT DFN=4
N OUT,%,SIEN1,SIEN2
S SIEN1=$$SCHEMA("UPDATE MEDICARE DATES")
S SIEN2=$$SCHEMA("UPDATE MEDICARE INFO")
D SS^BMXADO(.OUT,SIEN1,"4,","~~~5~~~~~"_SIEN2_",PARENT")
D DISP(OUT) R %:$G(DTIME,60)
K ^TMP("BMX ADO",$J)
Q
;
ADD ; ADD A NEW ENTRY
; THIS IS A 2 STEP PROCESS:
; FIRST GET THE SCHEMA FOR THE FILE YOU WISH TO UPDATE
; THIS SCHEMA'S NAME TYPICALLY BEGINS WITH THE WORD "UPDATE"
; IT CONTAINS NO ID OR IEN FIELDS
; SECOND ADD THE DATA NODE TO THE ARRAY
; IT HAS THE SAME FORMAT AS A DATA STRING ASSOCIATED WITH THE SCHEMA EXCEPT THE FIRST "^" PIECE IS NULL
; THIS PIECE CORRESPONDS TO THE IEN OF THE RECORD. SINCE THE RECORD HAS NOT BEEN ADDED YET, IT IS NULL.
; IN THE DATA STRING, ALL POINTER VALUES ARE PRECEDED BY THE '`' CHARACTER AND EA. STRING ENDS IN $C(30)
; MULTIPLE DATA STRINGS CAN BE APPENDED AS NEW NODES AT THE BOTTOM OF THE ARRAY
; IN THIS CASE WE ARE ADDING A RECORD TO THE V MEASUREMENT FILE
; DATA STRING="^MEASUREMENT TYPE IEN^PATIENT DFN^VISIT IEN^RESULT"_$C(30)
; THERE ARE 2 INPUT PARAMS:
; THE CLOSED REF WHERE THE INPUT ARRAY IS STORED
; SINCE IT IS PASSED BY REFERENCE "OUT" CAN BE NULL OR UNDEFIEND.
; OUT WILL BE DEFINED AT THE CONCLUSION OF THE TRANSACTION.
; THE OUTPUT IS IN THE OUT ARRAY
; OUT(1)="OK|ien" WHERE ien IS THE IEN OF THE RECORD THAT HAS BEE ADDED.
; IF THE TRANSACTION FAILED, AN ERROR MSG WILL BE IN THE OUT ARRAY
; MEASUREMENT TYPE=2, PATIENT DFN=2, VISIT IEN=7806, PATIENT'S WEIGHT=172.75
N OUT,%,SIEN,NODE,DFN
S DFN=2
S SIEN=$$SCHEMA("UPDATE MEASUREMENTS")
D SS^BMXADO(.OUT,SIEN,"","") ; GET SCHEMA
S NODE=$O(^TMP("BMX ADO",$J,999999),-1)+1
S ^TMP("BMX ADO",$J,NODE)="^`2^`"_DFN_"^`7806^172.75"_$C(30)
D DISP(OUT) R %:$G(DTIME,60) ; DISPLAY THE INPUT ARRAY BEFORE UPDATING THE RECORD
D BAFM^BMXADOF1(.OUT,$NA(^TMP("BMX ADO",$J))) ; EP FOR UPDAING THE RECORD
K ^TMP("BMX ADO",$J)
W !!,OUT S %=0 F S %=$O(OUT(%)) Q:'% W !,OUT(%) ; SEND BACK AN ACKNOWLEDGEMENT OR ERROR MSG
Q
;
DEL ; DELETE A RECORD
; THE SIPLEST WAY TO DELETE AN ENTRY IS TO PUT THE RECORD IEN IN THE DA STRING PRECEDED BY A MINUS SIGN
; YOU CAN ALSO SET THE VALUE OF THE .01 FIELD TO "@"
; IF THE VALUE OF THE .01 FIELD IS NULL AND THE DA STRING IS NOT PRECEDED BY A MINUS SIGN, THE TRANSACTION WILL BE CANCELLED
; IF THE DA STRING IS NULL, THE TRANSACTION WILL BE CANCELLED
; IN THIS EXAMPLE, WE DELETE A V MEASUREMENT RECORD THAT WAS JUST ADDED
N OUT,%,SIEN,NODE,DEL
S DEL=1621
S SIEN=$$SCHEMA("UPDATE MEASUREMENTS")
D SS^BMXADO(.OUT,SIEN,"","") ; GET SCHEMA
S NODE=$O(^TMP("BMX ADO",$J,999999),-1)+1
S ^TMP("BMX ADO",$J,NODE)="-"_DEL_$C(30)
D DISP(OUT) R %:$G(DTIME,60) ; DISPLAY THE INPUT ARRAY BEFORE UPDATING THE RECORD
D BAFM^BMXADOF1(.OUT,$NA(^TMP("BMX ADO",$J))) ; EP FOR UPDAING THE RECORD
K ^TMP("BMX ADO",$J)
W !!,OUT S %=0 F S %=$O(OUT(%)) Q:'% W !,OUT(%) ; SEND BACK AN ACKNOWLEDGEMENT OR ERROR MSG
Q
;
EDIT ; EDIT AN EXISTING ENTRY
; SIMILAR TO ABOVE EXCEPT THAT THE FIRST "^" PIECE OF THE DATA NODE IS THE IEN OF THE RECORD TO BE EDITIED
; NOTE THAT THERE IS NO '`' IN FRONT OF THE FIRST PIECE. IT IS A PURE INTEGER
; LAB TEST=175, PATIENT DFN=2, VISIT IEN=8040, PT'S GLUCOSE=276, ANORMAL="ABNORMAL"
N OUT,%,SIEN,NODE
S SIEN=$$SCHEMA("UPDATE LABS")
D SS^BMXADO(.OUT,SIEN,"","") ; GET SCHEMA
S NODE=$O(^TMP("BMX ADO",$J,999999),-1)+1
S ^TMP("BMX ADO",$J,NODE)="279^`175^`2^`8040^280^H"_$C(30)
D DISP(OUT) R %:$G(DTIME,60) ; DISPLAY THE INPUT ARRAY BEFORE UPDATING THE RECORD
D BAFM^BMXADOF1(.OUT,$NA(^TMP("BMX ADO",$J))) ; EP FOR UPDAING THE RECORD
K ^TMP("BMX ADO",$J)
W !!,OUT S %=0 F S %=$O(OUT(%)) Q:'% W !,OUT(%) ; SEND BACK AN ACKNOWLEDGEMENT OR ERROR MSG
Q
;
DELVAL ; DELETE A VALUE IN A FIELD
; SIMILAR TO EDIT EXCEPT THE VALUE IS "@"
; DELETE WILL BE ABORTED IF IF FILEMAN SAYS THIS IS A REQUIRED FIELD
N OUT,%,SIEN,NODE
S SIEN=$$SCHEMA("UPDATE LABS")
D SS^BMXADO(.OUT,SIEN,"","") ; GET SCHEMA
S NODE=$O(^TMP("BMX ADO",$J,999999),-1)+1
S ^TMP("BMX ADO",$J,NODE)="279^`175^`2^`8040^^@"_$C(30)
D DISP(OUT) R %:$G(DTIME,60) ; DISPLAY THE INPUT ARRAY BEFORE UPDATING THE RECORD
D BAFM^BMXADOF1(.OUT,$NA(^TMP("BMX ADO",$J))) ; EP FOR UPDAING THE RECORD
K ^TMP("BMX ADO",$J)
W !!,OUT S %=0 F S %=$O(OUT(%)) Q:'% W !,OUT(%) ; SEND BACK AN ACKNOWLEDGEMENT OR ERROR MSG
Q
;
BMXADOXY ; IHS/CIHA/GIS - RPC CALL: GENERATE AN ADO SCHEMA STRING AND DATA SET ;
+1 ;;2.0;BMX;;FEB 26, 2007
+2 ; EXMAPLES OF FILEMAN SCHEMA GENERATION
+3 ;
+4 ;
+5 ;
DISP(OUT) ; TEMP DISPLAY OF THE ANR
+1 NEW I,X
+2 SET I=0
WRITE !
+3 FOR
SET I=$ORDER(@OUT@(I))
IF 'I
QUIT
SET X=@OUT@(I)
SET X=$TRANSLATE(X,$CHAR(30),"}")
SET X=$TRANSLATE(X,$CHAR(31),"{")
WRITE !,X
+4 QUIT
+5 ;
SCHEMA(NAME) ; GIVEN SCHEMA NAME, RETURN THE IEN
+1 NEW IEN
+2 SET IEN=$ORDER(^BMXADO("B",NAME,0))
+3 QUIT IEN
+4 ;
NUM ; ITERATE BY IEN
+1 ; IX="",START WITH IEN=1, STOP AFTER IEN=20, MAX # RECORDS RETURNED = 5
+2 ; TO VIEW INTERNAL VALUES SET VSTG="~1~20~5~I"
+3 NEW OUT,%,SIEN
+4 SET SIEN=$$SCHEMA("IHS PATIENT")
+5 DO SS^BMXADO(.OUT,SIEN,"","~1~20~5")
+6 DO DISP(OUT)
READ %:$GET(DTIME,60)
+7 KILL ^TMP("BMX ADO",$JOB)
+8 QUIT
+9 ;
IX ; ITERATE BY INDEX
+1 ; ITERATE USING THE "B" INDEX
+2 ; START WITH PT NAME "C", STOP AFTER PATIENT NAME = "D", MAX # RECORDS RETURNED = 5
+3 NEW OUT,%,SIEN
+4 SET SIEN=$$SCHEMA("IHS PATIENT")
+5 DO SS^BMXADO(.OUT,SIEN,"","B~C~D~5")
+6 DO DISP(OUT)
READ %:$GET(DTIME,60)
+7 KILL ^TMP("BMX ADO",$JOB)
+8 QUIT
+9 ;
RENT ; ITERATE IN CHUNKS
+1 ; RE-ITERATE USING THE "B" INDEX
+2 ; START WITH PT IEN 5 AS THE "SEED", STOP AFTER PATIENT NAME = "D", MAX # RECORDS RETURNED = 5
+3 NEW OUT,%,SIEN,SEED,LSEED,X,Y
+4 SET SEED=0
SET LSEED=""
+5 SET SIEN=$$SCHEMA("IHS PATIENT")
RIT FOR
Begin DoDot:1
+1 DO SS^BMXADO(.OUT,SIEN,SEED,"B~CA~CB~5")
+2 DO DISP(OUT)
READ %:$GET(DTIME,60)
IF '$TEST
SET SEED=""
QUIT
+3 IF %?1"^"
SET SEED=""
QUIT
+4 SET X=$PIECE(@OUT@(1),U,1)
+5 SET SEED=$PIECE(X,"|",3)
+6 IF SEED=LSEED
SET SEED=""
QUIT
+7 SET LSEED=SEED
+8 KILL ^TMP("BMX ADO",$JOB)
+9 QUIT
End DoDot:1
IF '$GET(SEED)
QUIT
+10 QUIT
+11 ;
SUB ; SUBFILE ITERATION
+1 ; THE SCHEMA IS ATTACHED TO THE MEDICARE ELIGIBILITY FILE/ELIG DATE SUBFILE
+2 ; THE DA STRING HAS A VALUE OF '4,',: THE IEN IN THE PARENT FILE (PATIENT DFN).
+3 ; NOTE THE COMMA IN THE DA STRING. THIS INDICATES THAT THE FILE IEN IS 4 BUT THE SUBFILE IEN IS UNSPECIFIED
+4 NEW OUT,%,SIEN
+5 SET SIEN=$$SCHEMA("UPDATE MEDICARE DATES")
+6 ;D SS^BMXADO(.OUT,SIEN,"1,","~~~")
+7 DO SS^BMXADO(.OUT,18,"1,","~~~")
+8 DO DISP(OUT)
READ %:$GET(DTIME,60)
+9 KILL ^TMP("BMX ADO",$JOB)
+10 QUIT
+11 ;
DINUM ; DINUMED POINTER ITERATION
+1 ; THE SCHEMA IS ATTACHED TO THE PATIENT FILE (9000001)
+2 ; THE PATIENT FILE IS DINUM'D AND ITS .01 FIELD POINTS TO THE VA PATIENT FILE (2)
+3 ; BECAUSE OF THE SPECIAL RELATIONSHIP BETWEEN THE FILES, WE CAN USE THE B INDEX OF FILE 2 TO ITERATE FILE 9000001.
+4 NEW OUT,%,SIEN
+5 SET SIEN=$$SCHEMA("IHS PATIENT")
+6 DO SS^BMXADO(.OUT,SIEN,"","B~A~B~5")
+7 DO DISP(OUT)
READ %:$GET(DTIME,60)
+8 KILL ^TMP("BMX ADO",$JOB)
+9 QUIT
+10 ;
IXP ; INDEXED POINTER ITERATION
+1 ; THE SCHEMA IS ATTACHED TO THE V POV FILE
+2 ; THE AC CROSS REFERENCE INDEXES THE PATIENT FIELD
+3 ; BY STARTING AND STOPING WITH PATIENT 235 (MAX=5) WE COLLECT THE FIRST 5 POVS FOR PATIENT 235 IN THE FILE
+4 NEW OUT,%,SIEN
+5 SET SIEN=$$SCHEMA("VIEW POVS")
+6 DO SS^BMXADO(.OUT,SIEN,"","AC~235~235~5")
+7 DO DISP(OUT)
READ %:$GET(DTIME,60)
+8 KILL ^TMP("BMX ADO",$JOB)
+9 QUIT
+10 ;
AA ; ITERATE USING AA INDEX
+1 ; INDEX IS 'AA" THE START AND STOP DATES ARE SPECIFIED IN EXTERNAL FORMAT. MAX=10
+2 ; THE FOLLOWING FILTERS ARE SPECIFIED IN THE LAST PARAMETER ("235|WT|C"):
+3 ; 235=PATIENT DFN #235
+4 ; WT=RETURN ONLY WEIGHTS. MEASUREMENT TYPE MUST BE SPECIFIED WITH A VALID, UNAMBIGUOUS LOOKUP VALUE.
+5 ; C=RETRUN VALUES IN CHRONOLOGICAL ORDER USE 'R' INSTEAD OF 'C' FOR REVERSE CHRONOLOGICAL ORDER. DEFAULT=C
+6 ; THE SEED PARAMTER IS SET AND CAN BE USED TO RETURN DATA IN CHUNKS
+7 NEW OUT,%,SIEN
+8 SET SIEN=$$SCHEMA("VIEW MEASUREMENTS")
+9 DO SS^BMXADO(.OUT,SIEN,"","AA~3/21/1965~6/4/2004~5~~~~235|WT|C")
+10 DO DISP(OUT)
READ %:$GET(DTIME,60)
+11 KILL ^TMP("BMX ADO",$JOB)
+12 QUIT
+13 ;
AA2 ; ITERATE USING AA INDEX
+1 ; THIS SCHEMA IS ATTACHED TO THE VISIT FILE (9000010)
+2 ; IN THIS CASE THERE IS NO ATTRIBUTE TYPE SO THE FILTER PARAM HAS ONLY 2 PIECES "1|R"
+3 ; 235=PATIENT DFN
+4 ; R=RETURN DATA IN REVERSE CHRONOLOGICAL ORDER
+5 NEW OUT,%,SIEN
+6 ;12
SET SIEN=$$SCHEMA("VISITS")
+7 DO SS^BMXADO(.OUT,SIEN,"","AA~3/21/1965~6/4/2004~5~~~~235|R")
+8 DO DISP(OUT)
READ %:$GET(DTIME,60)
+9 KILL ^TMP("BMX ADO",$JOB)
+10 QUIT
+11 ;
CIT ; CUSTOM ITERATOR
+1 ; IF COMPLEX OR UNUSUAL SORTING/FILTERING IS REQUITED, USE A CUSTOM ITERATOR
+2 ; THE CUSTOM ITERATOR IS DEFINED BY 6TH, 7TH AND 8TH PIECES IN THE VSTG
+3 ; PIECE 8=TAG, PIECE 9=ROUTINE, PIECE 8=A PARAMETER PASSED TO THE ENTRY POINT
+4 ; THE 9TH PIECE CONTAINS PT DFN, TIMESTAMP, VISIT TYPE, LOC IEN, AND SERVICE CATEGORY IN A "|" DELIMTED STRING
+5 ; THE ITERATOR CALL TAG^ROUTINE(PARAM) TO GENERATE IENS
+6 ; IN THIS CASE THE SCHEMA IS ATTACHED TO THE VISIT FILE.
+7 ; GIVEN THE INFORMATION IN THE PARAMETER, THE CUSTOM ITERATOR RETURNS POSSIBLE DUPLICATE VISITS
+8 NEW OUT,%,SIEN
+9 SET SIEN=$$SCHEMA("VISITS")
+10 DO SS^BMXADO(.OUT,SIEN,"","~~~~~DUPV~BMXADOV2~9285|5/24/04@1PM|I|516|~")
+11 DO DISP(OUT)
READ %:$GET(DTIME,60)
+12 KILL ^TMP("BMX ADO",$JOB)
+13 QUIT
+14 ;
ID ; IDENTIFIER FIELD
+1 ; THE SCHEMA IS ATTACHED TO THE VA PATIENT FILE (2)
+2 ; THE SCHEMA HAS A BUILT IN FIELD (.01ID) THAT RETURNS THE IDENTIFIERS
+3 ; THE ENTRY POINT THAT GENERATES THE IDETIFIERS IS STORED IN THE BMX ADO SCHEMA FILE
+4 ; PATIENT DFN=235
+5 NEW OUT,%,SIEN
+6 SET SIEN=$$SCHEMA("UPDATE PATIENT DEMOGRAPHICS")
+7 DO SS^BMXADO(.OUT,SIEN,"","~235~235~")
+8 DO DISP(OUT)
READ %:$GET(DTIME,60)
+9 KILL ^TMP("BMX ADO",$JOB)
+10 QUIT
+11 ;
JSTD ; STANDARD JOIN
+1 ; BY SPECIFYING A JOIN IN THE VSTG, MULTIPLE SCHEMAE AND DATA SETS ARE RETURNED IN ONE PASS
+2 ; THE SCHEMA IS ATTACHED TO THE V MEASUREMENT FILE
+3 ; THIS IS JOINED TO A SECOND FILE, THE VA PATIENT FILE VIA A JOIN
+4 ; THE JOIN IS BASTED ON THE FACT THAT THE PATIENT FIELD (.02) IN THE V MEASUREMENT FILE POINTS TO THE VA PATIENT FILE
+5 ; THE JOIN PARAMETER IS THE 9TH PIECE OF THE VSTG. IT CONSISTS OF 2 PIECES DELIMITED BY A ","
+6 ; PIECE 1 IS THE SCHEMA THAT YOU ARE JOINING TO
+7 ; PIECE 2 IS THE FIELD IN THE PRIMARY FILE THAT ENABLES THE JOIN
+8 ; THE DATA SET FROM THE SECOND (JOIN) FILE CONTAINS ONLY THOSE RECORDS NECESSARY TO COMPLETE THE JOIN
+9 ; PATIENT DFN=235, INDEX=AA, MAX=5, START=3/21/65, STOP=6/4/04
+10 NEW OUT,%,SIEN1,SIEN2
+11 SET SIEN2=$$SCHEMA("VIEW MEASUREMENTS")
+12 SET SIEN1=$$SCHEMA("PATIENT DEMOGRAPHICS")
+13 ;SIEN1=23, SIEN2=11
+14 ;D SS^BMXADO(.OUT,SIEN1,"","AA~3/21/1965~6/4/2004~5~~~~234|WT|C~"_SIEN2_",.02")
+15 DO SS^BMXADO(.OUT,SIEN1,"","~234~236~~~~~~"_SIEN2_",.01")
+16 DO DISP(OUT)
READ %:$GET(DTIME,60)
+17 KILL ^TMP("BMX ADO",$JOB)
+18 QUIT
+19 ;
HWSTD ;
+1 ; PATIENT DFN=235, INDEX=AA, MAX=5, START=3/21/65, STOP=6/4/04
+2 NEW OUT,%,SIEN1,SIEN2
+3 SET SIEN1=$$SCHEMA("PATIENT DEMOGRAPHICS")
+4 SET SIEN2=$$SCHEMA("VIEW MEASUREMENTS")
+5 ;SIEN2=23, SIEN1=11
+6 DO SS^BMXADO(.OUT,SIEN1,"","~235~250~~~~~~"_SIEN2_",.01")
+7 DO DISP(OUT)
READ %:$GET(DTIME,60)
+8 KILL ^TMP("BMX ADO",$JOB)
+9 QUIT
+10 ;
JMD ;JOIN MASTER TO DETAIL
+1 NEW OUT,%,SIEN1,SIEN2,SIEN3,VSTG
+2 SET SIEN1=$$SCHEMA("PATIENT DEMOGRAPHICS")
+3 SET SIEN2=$$SCHEMA("VIEW MEASUREMENTS")
+4 SET SIEN3=$$SCHEMA("VIEW MEDS")
+5 SET VSTG="~1~5~~~~~~"
+6 ;S VSTG=VSTG_SIEN3_",.001,.02IEN,AA~1/1/1960~6/30/2004~~~~~|C"
+7 SET VSTG=VSTG_SIEN3_",.001,.02IEN,AA~1/1/1960~6/30/2004~~~~~|C"
+8 ;S VSTG="~1~5~~~~~~23,.001,.02IEN,AA~1/1/1960~6/30/2004~~~~~|WT|C"
+9 ;BMX ADO SS^11^^~1~5~~~~~~23,.001,.02IEN,AA~1/1/1960~6/30/2004~~~~~|WT|C
+10 ;BMX ADO SS^11^^~1~5~~~~~~25,.001,.02IEN,AA~1/1/1960~6/30/2004~~~~~|C
+11 DO SS^BMXADO(.OUT,SIEN1,"",VSTG)
+12 DO DISP(OUT)
READ %:$GET(DTIME,60)
+13 KILL ^TMP("BMX ADO",$JOB)
+14 QUIT
+15 ;
JSUB ; SUBFILE JOIN
+1 ; IN THIS CASE THE RECORDS IN A PARENT FILE ARE "JOINED" TO THE RECORDS IN ONE OF ITS SUB FILES
+2 ; THE SCHEMA IS ATTACHED TO THE "MEDICARE ELIGIBLE" FILE
+3 ; IT IS JOINED TO ITS SUBFILE, "ELIG DATES", VIA THE UPDATE MEDICARE DATES SCHEMA
+4 ; THE SYNTAX FOR THE JOIN PIECE IS "sien2,SUB" WHERE sien2=IEN OF SECOND SCHEMA
+5 ; PATIENT DFN=4
+6 NEW OUT,%,SIEN1,SIEN2
+7 ;17
SET SIEN1=$$SCHEMA("UPDATE MEDICARE INFO")
+8 ;18
SET SIEN2=$$SCHEMA("UPDATE MEDICARE DATES")
+9 ;BMX ADO SS^17^^~4~5~~~~~~18,SUB
+10 DO SS^BMXADO(.OUT,SIEN1,"","~4~5~~~~~~"_SIEN2_",SUB")
+11 DO DISP(OUT)
READ %:$GET(DTIME,60)
+12 KILL ^TMP("BMX ADO",$JOB)
+13 QUIT
+14 ;
JPAR ; PARENT FILE JOIN
+1 ; SIMILAR TO A SUBFILE JOIN EXCEPT THE SUB-FILE IS TREATED AS THE PRIMARY FILE AND IT IS JOINED TO ITS PARENT
+2 ; BECAUSE WE ARE STARTING IN A SUBFILE, THE DA STRING CONTAINS THE IEN OF THE PARENT FILE ("4,"
+3 ; THE SYNTAX OF THE 9TH PIECE IS "sien2,PARENT" WHERE sien2 IS THE IEN OF THE SECONDARY SCHEMA
+4 ; PATIENT DFN=4
+5 NEW OUT,%,SIEN1,SIEN2
+6 SET SIEN1=$$SCHEMA("UPDATE MEDICARE DATES")
+7 SET SIEN2=$$SCHEMA("UPDATE MEDICARE INFO")
+8 DO SS^BMXADO(.OUT,SIEN1,"4,","~~~5~~~~~"_SIEN2_",PARENT")
+9 DO DISP(OUT)
READ %:$GET(DTIME,60)
+10 KILL ^TMP("BMX ADO",$JOB)
+11 QUIT
+12 ;
ADD ; ADD A NEW ENTRY
+1 ; THIS IS A 2 STEP PROCESS:
+2 ; FIRST GET THE SCHEMA FOR THE FILE YOU WISH TO UPDATE
+3 ; THIS SCHEMA'S NAME TYPICALLY BEGINS WITH THE WORD "UPDATE"
+4 ; IT CONTAINS NO ID OR IEN FIELDS
+5 ; SECOND ADD THE DATA NODE TO THE ARRAY
+6 ; IT HAS THE SAME FORMAT AS A DATA STRING ASSOCIATED WITH THE SCHEMA EXCEPT THE FIRST "^" PIECE IS NULL
+7 ; THIS PIECE CORRESPONDS TO THE IEN OF THE RECORD. SINCE THE RECORD HAS NOT BEEN ADDED YET, IT IS NULL.
+8 ; IN THE DATA STRING, ALL POINTER VALUES ARE PRECEDED BY THE '`' CHARACTER AND EA. STRING ENDS IN $C(30)
+9 ; MULTIPLE DATA STRINGS CAN BE APPENDED AS NEW NODES AT THE BOTTOM OF THE ARRAY
+10 ; IN THIS CASE WE ARE ADDING A RECORD TO THE V MEASUREMENT FILE
+11 ; DATA STRING="^MEASUREMENT TYPE IEN^PATIENT DFN^VISIT IEN^RESULT"_$C(30)
+12 ; THERE ARE 2 INPUT PARAMS:
+13 ; THE CLOSED REF WHERE THE INPUT ARRAY IS STORED
+14 ; SINCE IT IS PASSED BY REFERENCE "OUT" CAN BE NULL OR UNDEFIEND.
+15 ; OUT WILL BE DEFINED AT THE CONCLUSION OF THE TRANSACTION.
+16 ; THE OUTPUT IS IN THE OUT ARRAY
+17 ; OUT(1)="OK|ien" WHERE ien IS THE IEN OF THE RECORD THAT HAS BEE ADDED.
+18 ; IF THE TRANSACTION FAILED, AN ERROR MSG WILL BE IN THE OUT ARRAY
+19 ; MEASUREMENT TYPE=2, PATIENT DFN=2, VISIT IEN=7806, PATIENT'S WEIGHT=172.75
+20 NEW OUT,%,SIEN,NODE,DFN
+21 SET DFN=2
+22 SET SIEN=$$SCHEMA("UPDATE MEASUREMENTS")
+23 ; GET SCHEMA
DO SS^BMXADO(.OUT,SIEN,"","")
+24 SET NODE=$ORDER(^TMP("BMX ADO",$JOB,999999),-1)+1
+25 SET ^TMP("BMX ADO",$JOB,NODE)="^`2^`"_DFN_"^`7806^172.75"_$CHAR(30)
+26 ; DISPLAY THE INPUT ARRAY BEFORE UPDATING THE RECORD
DO DISP(OUT)
READ %:$GET(DTIME,60)
+27 ; EP FOR UPDAING THE RECORD
DO BAFM^BMXADOF1(.OUT,$NAME(^TMP("BMX ADO",$JOB)))
+28 KILL ^TMP("BMX ADO",$JOB)
+29 ; SEND BACK AN ACKNOWLEDGEMENT OR ERROR MSG
WRITE !!,OUT
SET %=0
FOR
SET %=$ORDER(OUT(%))
IF '%
QUIT
WRITE !,OUT(%)
+30 QUIT
+31 ;
DEL ; DELETE A RECORD
+1 ; THE SIPLEST WAY TO DELETE AN ENTRY IS TO PUT THE RECORD IEN IN THE DA STRING PRECEDED BY A MINUS SIGN
+2 ; YOU CAN ALSO SET THE VALUE OF THE .01 FIELD TO "@"
+3 ; IF THE VALUE OF THE .01 FIELD IS NULL AND THE DA STRING IS NOT PRECEDED BY A MINUS SIGN, THE TRANSACTION WILL BE CANCELLED
+4 ; IF THE DA STRING IS NULL, THE TRANSACTION WILL BE CANCELLED
+5 ; IN THIS EXAMPLE, WE DELETE A V MEASUREMENT RECORD THAT WAS JUST ADDED
+6 NEW OUT,%,SIEN,NODE,DEL
+7 SET DEL=1621
+8 SET SIEN=$$SCHEMA("UPDATE MEASUREMENTS")
+9 ; GET SCHEMA
DO SS^BMXADO(.OUT,SIEN,"","")
+10 SET NODE=$ORDER(^TMP("BMX ADO",$JOB,999999),-1)+1
+11 SET ^TMP("BMX ADO",$JOB,NODE)="-"_DEL_$CHAR(30)
+12 ; DISPLAY THE INPUT ARRAY BEFORE UPDATING THE RECORD
DO DISP(OUT)
READ %:$GET(DTIME,60)
+13 ; EP FOR UPDAING THE RECORD
DO BAFM^BMXADOF1(.OUT,$NAME(^TMP("BMX ADO",$JOB)))
+14 KILL ^TMP("BMX ADO",$JOB)
+15 ; SEND BACK AN ACKNOWLEDGEMENT OR ERROR MSG
WRITE !!,OUT
SET %=0
FOR
SET %=$ORDER(OUT(%))
IF '%
QUIT
WRITE !,OUT(%)
+16 QUIT
+17 ;
EDIT ; EDIT AN EXISTING ENTRY
+1 ; SIMILAR TO ABOVE EXCEPT THAT THE FIRST "^" PIECE OF THE DATA NODE IS THE IEN OF THE RECORD TO BE EDITIED
+2 ; NOTE THAT THERE IS NO '`' IN FRONT OF THE FIRST PIECE. IT IS A PURE INTEGER
+3 ; LAB TEST=175, PATIENT DFN=2, VISIT IEN=8040, PT'S GLUCOSE=276, ANORMAL="ABNORMAL"
+4 NEW OUT,%,SIEN,NODE
+5 SET SIEN=$$SCHEMA("UPDATE LABS")
+6 ; GET SCHEMA
DO SS^BMXADO(.OUT,SIEN,"","")
+7 SET NODE=$ORDER(^TMP("BMX ADO",$JOB,999999),-1)+1
+8 SET ^TMP("BMX ADO",$JOB,NODE)="279^`175^`2^`8040^280^H"_$CHAR(30)
+9 ; DISPLAY THE INPUT ARRAY BEFORE UPDATING THE RECORD
DO DISP(OUT)
READ %:$GET(DTIME,60)
+10 ; EP FOR UPDAING THE RECORD
DO BAFM^BMXADOF1(.OUT,$NAME(^TMP("BMX ADO",$JOB)))
+11 KILL ^TMP("BMX ADO",$JOB)
+12 ; SEND BACK AN ACKNOWLEDGEMENT OR ERROR MSG
WRITE !!,OUT
SET %=0
FOR
SET %=$ORDER(OUT(%))
IF '%
QUIT
WRITE !,OUT(%)
+13 QUIT
+14 ;
DELVAL ; DELETE A VALUE IN A FIELD
+1 ; SIMILAR TO EDIT EXCEPT THE VALUE IS "@"
+2 ; DELETE WILL BE ABORTED IF IF FILEMAN SAYS THIS IS A REQUIRED FIELD
+3 NEW OUT,%,SIEN,NODE
+4 SET SIEN=$$SCHEMA("UPDATE LABS")
+5 ; GET SCHEMA
DO SS^BMXADO(.OUT,SIEN,"","")
+6 SET NODE=$ORDER(^TMP("BMX ADO",$JOB,999999),-1)+1
+7 SET ^TMP("BMX ADO",$JOB,NODE)="279^`175^`2^`8040^^@"_$CHAR(30)
+8 ; DISPLAY THE INPUT ARRAY BEFORE UPDATING THE RECORD
DO DISP(OUT)
READ %:$GET(DTIME,60)
+9 ; EP FOR UPDAING THE RECORD
DO BAFM^BMXADOF1(.OUT,$NAME(^TMP("BMX ADO",$JOB)))
+10 KILL ^TMP("BMX ADO",$JOB)
+11 ; SEND BACK AN ACKNOWLEDGEMENT OR ERROR MSG
WRITE !!,OUT
SET %=0
FOR
SET %=$ORDER(OUT(%))
IF '%
QUIT
WRITE !,OUT(%)
+12 QUIT
+13 ;