BMXADOVJ ; IHS/CIHA/GIS - RPC CALL: GENERATE DATA FOR AN ADO DATASET ;
;;4.0;BMX;;JUN 28, 2010
; THIS ROUTINE MANAGES THE JOINS
;
;
;
; THE FIFTH PARAMETER OF SS^BMXADO CONTAINS THE JOIN INSTRUCTIONS
; SYNTAX: DESCENDANT SCHEMA IEN (DETAILS FILE), JOIN FIELD FROM MASTER FILE
; THE FIRST "," PIECE STATES THAT THE MASTER FILE IS JOINED BY ITS .02 FIELD TO THE DETAILS FILE
; THE SECOND "," PIECE STARTES THAT THE DETAILS FILE IS DEFINED BY SCHEMA #6
; AN OPTIONAL 3RD "," PIECE MAY CONTAIN A SECONDARY VSTG TO MORE PRECISELY DEFINE JOIN ITERATION
; E.G., "...~6.,.02,AA~1/1/2004~2/1/2004~~~~~|WT|R"
; IN THIS CASE, THE SECONDARY VSTG SPECIFIES THAT THE AA INDEX BE USED TO CONTROL THE ITERATOR
; THE START AND STOP DATES ARE IN EFFECT BUT MAX IS IGNORED/IRRELEVANT
; THE 1ST "|" PIECE OF THE PARAM SECTION WILL BE AUTOMATICALLY STUFFED WITH PATEINT DFN(S) DURING ITERATION
; IF MULTIPLE JOINS ARE REQUESTED, THEY ARE SPARATED BY THE '@JOIN@' DELIMTER
; "E.G., 6,.02@JOIN@1,.03@JOIN@2,.02@JOIN@9,SUB"
; IN THIS EXAPLE THE MASTER FILE IS JOIND TO THE DETAILS FILES ASSOCIATED WITH SCHEMAS 6, 1, AND 9
; NOTE THAT THE 3RD JOIN DEINED IN THE STRING SPECIFIES A SUBFILE REALTION RATHER THAN A "POINTER" RELATION
; IF A SECOND RECORD SET IS CREATED TO FULFILL A JOIN REQUEST, IT WILL ONLY CONTAIN THE ROWS NECESSARY TO COMPLETE THE JOIN
;
JOIN(SMASTER,JSTG) ;EP - APPEND ADDITIONAL ANRS TO FULFILL JOIN REQUESTS
N TMP,JOIN,JINST,FMASTER
I '$L($G(JSTG)) Q ; JOIN STRING MUST NOT BE NULL
S FMASTER=$P($G(^BMXADO(+$G(SMASTER),0)),U,2) I 'FMASTER Q ; MASTER SCHEMA & FILE MUST EXIST
S TMP=$NA(^TMP("BMX JOIN",$J)) K @TMP ; JOIN INFO TEMP STORAGE ARRAY
S @TMP@(0,SMASTER)=$$RANGE ; GET DATA NODE RANGE FOR THE MASTER ANR
I '$D(@TMP@(0)) Q ; DATA MUST EXIST IN THE MASTER FILE OR QUIT
F JOIN=1:1 S JINST=$P(JSTG,"@JOIN@",JOIN) Q:JINST="" D J(SMASTER,JINST) ; MAIN LOOP FOR DOING JOINS
K @TMP
Q
;
RANGE() ; GET DATA NODE RANGE FOR LAST SCHEMA ENTERED
N X,FIRST,LAST,Y
S (X,LAST)=$O(@OUT@(999999999),-1)
F S X=$O(@OUT@(X),-1) Q:'X S Y=@OUT@(X) Q:Y'[$C(30) S FIRST=X
I '$G(FIRST) Q ""
S FIRST=FIRST+1
Q (FIRST_U_LAST)
;
J(SMASTER,JSTG) ; JOIN DETAILS FILE TO MASTER FILE
; SMASTER=MASTER SCHMA IEN, SDETAIL=DETAILS SCHEMA IEN
N JARR,SEC,ERR,JIEN,SUB,IX,PARENT,JFLD,DFLD,NODE,X,STOP,VSTG2,SDETAIL,JFLD
S SDETAIL=$P(JSTG,C),JFLD=$P(JSTG,C,2),DFLD=$P(JSTG,C,3),VSTG2=$P(JSTG,C,4,999)
I JFLD="SUB" S JFLD=.001,DFLD=.0001
I JFLD=.001,DFLD=.0001 S SUB=1,VSTG2="~~~~~SIT~BMXADOVJ~" ; MAKE SUBFILE ITERATOR VSTG
D IEN(SMASTER,SDETAIL,JFLD) ; GET A LIST OF JOIN IENS FROM THE MASTER FILE
I '$D(@TMP@(1)) Q ; NO MASTER FILE IENS FOR JOINS, SO QUIT
N FIEN,DAS,SIEN,VSTG,JSTG
S DAS="",SIEN=SDETAIL,VSTG=VSTG2
S FIEN=$P($G(^BMXADO(SIEN,0)),U,2) I 'FIEN Q
D JEP^BMXADO ; BUILD THE JOIN ANR
Q
;
IEN(SMASTER,SDETAIL,JFLD) ; GET THE MASTER FILE IENS FOR BUILDING THE JOIN DATA SET
N FIEN,%,FIRST,LAST,NODE,DA,IEN
I JFLD["IEN" S JFLD=+JFLD
S FIEN=$P($G(^BMXADO(SMASTER,0)),U,2) I 'FIEN Q
S %=$G(@TMP@(0,SMASTER)) I '$L(%) Q
S FIRST=+%,LAST=$P(%,U,2),NODE=FIRST-.1
F S NODE=$O(@OUT@(NODE)) Q:'NODE Q:NODE>LAST D
. S DA=+@OUT@(NODE)
. I 'DA Q
. I JFLD=.001 S @TMP@(1,SDETAIL,DA)="" Q
. S IEN=$$GET1^DIQ(FIEN,(DA_C),JFLD,"I") I 'IEN Q
. S @TMP@(1,SDETAIL,IEN)=""
. Q
Q
;
JFLD ; EP-STUFF JOIN FIELD IDS INTO THE INTRO SEGMENT OF THE SCHEMA
N NODE,%
S NODE=999999999999
F S NODE=$O(@OUT@(NODE),-1) Q:'NODE I @OUT@(NODE)["@@@meta@@@" Q
I 'NODE Q
S %=$P(@OUT@(NODE),U),$P(%,"|",4)=$G(JFLD),$P(%,"|",5)=$G(DFLD)
S @OUT@(NODE)=%_U
Q
;
BMXADOVJ ; IHS/CIHA/GIS - RPC CALL: GENERATE DATA FOR AN ADO DATASET ;
+1 ;;4.0;BMX;;JUN 28, 2010
+2 ; THIS ROUTINE MANAGES THE JOINS
+3 ;
+4 ;
+5 ;
+6 ; THE FIFTH PARAMETER OF SS^BMXADO CONTAINS THE JOIN INSTRUCTIONS
+7 ; SYNTAX: DESCENDANT SCHEMA IEN (DETAILS FILE), JOIN FIELD FROM MASTER FILE
+8 ; THE FIRST "," PIECE STATES THAT THE MASTER FILE IS JOINED BY ITS .02 FIELD TO THE DETAILS FILE
+9 ; THE SECOND "," PIECE STARTES THAT THE DETAILS FILE IS DEFINED BY SCHEMA #6
+10 ; AN OPTIONAL 3RD "," PIECE MAY CONTAIN A SECONDARY VSTG TO MORE PRECISELY DEFINE JOIN ITERATION
+11 ; E.G., "...~6.,.02,AA~1/1/2004~2/1/2004~~~~~|WT|R"
+12 ; IN THIS CASE, THE SECONDARY VSTG SPECIFIES THAT THE AA INDEX BE USED TO CONTROL THE ITERATOR
+13 ; THE START AND STOP DATES ARE IN EFFECT BUT MAX IS IGNORED/IRRELEVANT
+14 ; THE 1ST "|" PIECE OF THE PARAM SECTION WILL BE AUTOMATICALLY STUFFED WITH PATEINT DFN(S) DURING ITERATION
+15 ; IF MULTIPLE JOINS ARE REQUESTED, THEY ARE SPARATED BY THE '@JOIN@' DELIMTER
+16 ; "E.G., 6,.02@JOIN@1,.03@JOIN@2,.02@JOIN@9,SUB"
+17 ; IN THIS EXAPLE THE MASTER FILE IS JOIND TO THE DETAILS FILES ASSOCIATED WITH SCHEMAS 6, 1, AND 9
+18 ; NOTE THAT THE 3RD JOIN DEINED IN THE STRING SPECIFIES A SUBFILE REALTION RATHER THAN A "POINTER" RELATION
+19 ; IF A SECOND RECORD SET IS CREATED TO FULFILL A JOIN REQUEST, IT WILL ONLY CONTAIN THE ROWS NECESSARY TO COMPLETE THE JOIN
+20 ;
JOIN(SMASTER,JSTG) ;EP - APPEND ADDITIONAL ANRS TO FULFILL JOIN REQUESTS
+1 NEW TMP,JOIN,JINST,FMASTER
+2 ; JOIN STRING MUST NOT BE NULL
IF '$LENGTH($GET(JSTG))
QUIT
+3 ; MASTER SCHEMA & FILE MUST EXIST
SET FMASTER=$PIECE($GET(^BMXADO(+$GET(SMASTER),0)),U,2)
IF 'FMASTER
QUIT
+4 ; JOIN INFO TEMP STORAGE ARRAY
SET TMP=$NAME(^TMP("BMX JOIN",$JOB))
KILL @TMP
+5 ; GET DATA NODE RANGE FOR THE MASTER ANR
SET @TMP@(0,SMASTER)=$$RANGE
+6 ; DATA MUST EXIST IN THE MASTER FILE OR QUIT
IF '$DATA(@TMP@(0))
QUIT
+7 ; MAIN LOOP FOR DOING JOINS
FOR JOIN=1:1
SET JINST=$PIECE(JSTG,"@JOIN@",JOIN)
IF JINST=""
QUIT
DO J(SMASTER,JINST)
+8 KILL @TMP
+9 QUIT
+10 ;
RANGE() ; GET DATA NODE RANGE FOR LAST SCHEMA ENTERED
+1 NEW X,FIRST,LAST,Y
+2 SET (X,LAST)=$ORDER(@OUT@(999999999),-1)
+3 FOR
SET X=$ORDER(@OUT@(X),-1)
IF 'X
QUIT
SET Y=@OUT@(X)
IF Y'[$CHAR(30)
QUIT
SET FIRST=X
+4 IF '$GET(FIRST)
QUIT ""
+5 SET FIRST=FIRST+1
+6 QUIT (FIRST_U_LAST)
+7 ;
J(SMASTER,JSTG) ; JOIN DETAILS FILE TO MASTER FILE
+1 ; SMASTER=MASTER SCHMA IEN, SDETAIL=DETAILS SCHEMA IEN
+2 NEW JARR,SEC,ERR,JIEN,SUB,IX,PARENT,JFLD,DFLD,NODE,X,STOP,VSTG2,SDETAIL,JFLD
+3 SET SDETAIL=$PIECE(JSTG,C)
SET JFLD=$PIECE(JSTG,C,2)
SET DFLD=$PIECE(JSTG,C,3)
SET VSTG2=$PIECE(JSTG,C,4,999)
+4 IF JFLD="SUB"
SET JFLD=.001
SET DFLD=.0001
+5 ; MAKE SUBFILE ITERATOR VSTG
IF JFLD=.001
IF DFLD=.0001
SET SUB=1
SET VSTG2="~~~~~SIT~BMXADOVJ~"
+6 ; GET A LIST OF JOIN IENS FROM THE MASTER FILE
DO IEN(SMASTER,SDETAIL,JFLD)
+7 ; NO MASTER FILE IENS FOR JOINS, SO QUIT
IF '$DATA(@TMP@(1))
QUIT
+8 NEW FIEN,DAS,SIEN,VSTG,JSTG
+9 SET DAS=""
SET SIEN=SDETAIL
SET VSTG=VSTG2
+10 SET FIEN=$PIECE($GET(^BMXADO(SIEN,0)),U,2)
IF 'FIEN
QUIT
+11 ; BUILD THE JOIN ANR
DO JEP^BMXADO
+12 QUIT
+13 ;
IEN(SMASTER,SDETAIL,JFLD) ; GET THE MASTER FILE IENS FOR BUILDING THE JOIN DATA SET
+1 NEW FIEN,%,FIRST,LAST,NODE,DA,IEN
+2 IF JFLD["IEN"
SET JFLD=+JFLD
+3 SET FIEN=$PIECE($GET(^BMXADO(SMASTER,0)),U,2)
IF 'FIEN
QUIT
+4 SET %=$GET(@TMP@(0,SMASTER))
IF '$LENGTH(%)
QUIT
+5 SET FIRST=+%
SET LAST=$PIECE(%,U,2)
SET NODE=FIRST-.1
+6 FOR
SET NODE=$ORDER(@OUT@(NODE))
IF 'NODE
QUIT
IF NODE>LAST
QUIT
Begin DoDot:1
+7 SET DA=+@OUT@(NODE)
+8 IF 'DA
QUIT
+9 IF JFLD=.001
SET @TMP@(1,SDETAIL,DA)=""
QUIT
+10 SET IEN=$$GET1^DIQ(FIEN,(DA_C),JFLD,"I")
IF 'IEN
QUIT
+11 SET @TMP@(1,SDETAIL,IEN)=""
+12 QUIT
End DoDot:1
+13 QUIT
+14 ;
JFLD ; EP-STUFF JOIN FIELD IDS INTO THE INTRO SEGMENT OF THE SCHEMA
+1 NEW NODE,%
+2 SET NODE=999999999999
+3 FOR
SET NODE=$ORDER(@OUT@(NODE),-1)
IF 'NODE
QUIT
IF @OUT@(NODE)["@@@meta@@@"
QUIT
+4 IF 'NODE
QUIT
+5 SET %=$PIECE(@OUT@(NODE),U)
SET $PIECE(%,"|",4)=$GET(JFLD)
SET $PIECE(%,"|",5)=$GET(DFLD)
+6 SET @OUT@(NODE)=%_U
+7 QUIT
+8 ;