[645] | 1 | BMXADOV ; CIHA/CIHA/GIS - RPC CALL: GENERATE DATA FOR AN ADO DATASET
|
---|
[1087] | 2 | ;;2.3;BMX;;Jan 25, 2011
|
---|
[645] | 3 | ;
|
---|
| 4 | ;
|
---|
| 5 | ;
|
---|
| 6 | ; VSTG = VIEW STRING: SCHEMA NAME OR IEN~DAS~INDEX~START~STOP~MAX~FORMAT~TAG~ROUTINE~PARAM~JOIN
|
---|
| 7 | ; SCHEMA NAME/IEN: FROM THE BMX ADO SCHEMA FILE
|
---|
| 8 | ; DAS: THE DA STRING. HIGHEST LEVEL IS FIRST, FOLLOWED BY SUBFILE IENS. CAN BE CONVERTED TO AN 'IENS' STRING.
|
---|
| 9 | ; IF THE LAST ',' PIECE OF DAS IS DEFINED, THAT IS USED AS THE CURRENT STARTING SEED POINT FOR THE ITERATOR
|
---|
| 10 | ; THE NEXT INDEX VALUE AFTER THE SEED POINT WILL BE THE FIRST ENTRY SELECTED FOR THE CURRENT TRANSACTION
|
---|
| 11 | ; INDEX: THE INDEX THAT RUNS THE ITERATOR. IF NULL, THE ITERATOR WULL CYCLE BY IEN
|
---|
| 12 | ; START: STARTING LOOKUP VALUE IN THE OVERALL ITERATION (THE FIRST VALUE THAT CAN BE USED IN SPECIFIED INDEX)
|
---|
| 13 | ; STOP: THE LAST LOOKUP VALUE IN THE OVERALL ITERATION (THE LAST VALUE USED IN SPECIFIED INDEX)
|
---|
| 14 | ; START AND STOP MUST BE IN THE FORMAT (INTERNAL OR EXTERNAL) USED BY THE INDEX
|
---|
| 15 | ; IF THE INDEX IS ON A POINTER FIELD, AND POINTED TO FILED IS DINUMNED, THEN THE EXTERNAL VALUE CAN BE USED
|
---|
| 16 | ; MAX: MAXIMUM NUMBER OF ENTRIES REURNED IN THE TRANSACTION
|
---|
| 17 | ; FORMAT: RETURN INTERNAL OR EXTERNAL VALUES IN THE DATASET
|
---|
| 18 | ; TAG AND ROUTINE: ENTRY POINT FOR CUSTOM/COMPLEX ITERATION
|
---|
| 19 | ; PARAM: PARAMETER STRING PASSED TO THE ITERATOR ENTRY POINT.
|
---|
| 20 | ; ALSO USED WITH THE AA INDEX TO DEFINE PATIENT DFN, V FILE ATTRIBUTE TYPE AND SORT ORDER (C OR R)
|
---|
| 21 | ; E.G., 1|WT|R COULD BE PATIENT #1, MEASUREMENT TYPE="WEIGHT" AND REVERSE CHRONOLICAL PRESENTATION OF DATA
|
---|
| 22 | ; JOIN: JOIN INSTRUCTIONS; E.G., ...~2,4,.04|2,5,.07|4,9,SUB"
|
---|
| 23 | ;
|
---|
| 24 | ;
|
---|
| 25 | VIEW(OUT,VSTG,TOT) ; EP-VIEW A DATA SET ; GATEWAY TO ALL ITERATORS
|
---|
| 26 | ;
|
---|
| 27 | ; DON'T CALL THIS EP UNLESS YOU WANT DATA RETURNED WITH THE SCHEMA!
|
---|
| 28 | ; INPUT: VSTG AND THE TOTAL NUMBER OF NODES IN THE SCHEMA ARRAY
|
---|
| 29 | ; OUTPUT: THE DATA NODES AND THE SEED (SEED IS STUFFED INTO 3RD PIECE OF INTRODUCTORY NODE OF SCHEMA ARRAY)
|
---|
| 30 | ; RETURNS THE ADO DATASET IN THE ARRAY SPECIFIED BY 'OUT'
|
---|
| 31 | ; THE SEED IS ALWAYS RETURNED IN 'LDA' REGARDLESS OF WHAT ITERATOR IS USED
|
---|
| 32 | ; IF ITERATION IS COMPLETED THE SEED WILL HAVE A NULL VALUE
|
---|
| 33 | ;
|
---|
| 34 | ;
|
---|
| 35 | ;
|
---|
| 36 | N DAS,DA,IX,START,STOP,MAX,FMT,EP,IENS,OREF,CREF,FIEN,TAG,ROUTINE,X,Y,%,PARAM,NUM,FINFO,LIEN,LDA,LFILE,%DT,T
|
---|
| 37 | S SIEN=+$G(VSTG) I SIEN,'$D(^BMXADO(SIEN,0)) S ERR="Invalid schema IEN" D ERR^BMXADO(ERR) Q
|
---|
| 38 | I $G(TOT)<2 S ERR="Missing schema string" D ERR^BMXADO(ERR) Q ; MUST HAVE A VALID SCHEMA STRING FOR EACH TRANSACTION
|
---|
| 39 | INIT ; INITIALIZE VARIABLES
|
---|
| 40 | S T="~"
|
---|
| 41 | S FIEN=$P(^BMXADO(SIEN,0),U,2) I '$D(^DD(FIEN,0)) S ERR="Invalid file number in schema file" D ERR^BMXADO(ERR) Q
|
---|
| 42 | S DAS=$P(VSTG,T,2),IX=$P(VSTG,T,3)
|
---|
| 43 | S START=$P(VSTG,T,4),STOP=$P(VSTG,T,5),MAX=$P(VSTG,T,6)
|
---|
| 44 | I $L(START),$L(STOP),START,START=+START,STOP,STOP=+STOP
|
---|
| 45 | S %=$T ; NUMERIC START AND STOP
|
---|
| 46 | I %,START>STOP S ERR="Invalid start stop pair" D ERR^BMXADO(ERR) Q
|
---|
| 47 | I '%,$L(START),$L(STOP),START]STOP S ERR="Invalid start stop pair" D ERR^BMXADO(ERR) Q
|
---|
| 48 | I $L(MAX),(MAX'>0!(MAX'=MAX\1)) S ERR="Invalid MAX parameter" D ERR^BMXADO(ERR) Q
|
---|
| 49 | S FMT=$P(VSTG,T,7),TAG=$P(VSTG,T,8),ROUTINE=$P(VSTG,T,9),PARAM=$P(VSTG,T,10),NUM=0
|
---|
| 50 | I $L(TAG),'$L(ROUTINE) S ERR="Invalid EP info" D ERR^BMXADO(ERR) Q
|
---|
| 51 | S EP=TAG_U_ROUTINE I EP=U S EP=""
|
---|
| 52 | I $L(EP) X ("S %=$L($T("_EP_"))") I '% S ERR="Invalid EP info" D ERR^BMXADO(ERR) Q
|
---|
| 53 | I FMT='"I" S FMT=""
|
---|
| 54 | I MAX="" S MAX=100
|
---|
| 55 | I $G(JOIN) S MAX=999999999 ; MAX IS UNLIMITED FOR SECONDARY DATA SETS DURING JOINS
|
---|
| 56 | S IENS=$$IENS(DAS) ; CONVERT DA STRING TO IEN STRING ; DAS AND IENS MUST BE AVAILABLE TO ALL ITERATORS
|
---|
| 57 | S OREF=$$ROOT^DILFD(FIEN,IENS) I '$L(OREF) S ERR="Unable to generate a vaild open reference" D ERR^BMXADO(ERR) Q
|
---|
| 58 | S CREF=$$CREF^DILF(OREF) I '$L(CREF) S ERR="Unable to generate a vaild closed reference" D ERR^BMXADO(ERR) Q
|
---|
| 59 | DATA ; GET DATA
|
---|
| 60 | SPEC I $L(EP) D Q ; SPECIAL CASE: USE CUSTOM ITERATOR
|
---|
| 61 | . I '$G(LDA) S LDA=""
|
---|
| 62 | . X ("S LDA=$$"_EP_"(PARAM,IENS,MAX,.OUT,.TOT)")
|
---|
| 63 | . D SEED(LDA)
|
---|
| 64 | . Q
|
---|
| 65 | I IX="" S LDA=$$NUMIT^BMXADOV1(+$G(DA)) D SEED(LDA) Q ; NO INDEX USED: ITERATE IN IEN ORDER
|
---|
| 66 | I IX="AA",FIEN=9000013!(FIEN=9000019) S IX="AC" ; 'AA' ITERATION UNNECESSARY FOR SOME FILES. BETTER TO USE 'AC'
|
---|
| 67 | I '$L($O(@CREF@(IX,""))) Q ; NO INDEXED DATA AVAILABLE, SO QUIT NOW
|
---|
| 68 | I IX="AA" D Q ; SPECIAL CASE: AA INDEX
|
---|
| 69 | . I FIEN=9000011 S LDA=$$AAP^BMXADOV1 Q ; THE AA INDEX FOR 'PROBLEMS'; LDA ALWAYS NULL
|
---|
| 70 | . S LDA=$$AA^BMXADOV1 D SEED(LDA) ; THE VISIT/V-FILE AA INDEX
|
---|
| 71 | . Q
|
---|
| 72 | S FINFO=$$IXFLD(FIEN,IX) I FINFO="" Q ; FILE INFO: IX FIELD NUMBER, TYPE, AND DINUM SUBTYPE
|
---|
| 73 | I $P(FINFO,U,2)="D" D ; PREP FOR DATE INDEX LOOKUP
|
---|
| 74 | . I $L(START) S X=START D ^%DT S START=+Y
|
---|
| 75 | . I $L(STOP) S X=STOP D ^%DT S STOP=+Y
|
---|
| 76 | . Q
|
---|
| 77 | I $P(FINFO,U,2)="P",$E(START)="`" D Q ; SPECIAL CASE: SHORTCUT TO POINTER LOOKUP FOR A SINGLE, SPECIFIC IEN.
|
---|
| 78 | . S LIEN=+$E(START,2,99)
|
---|
| 79 | . S LDA=$$LOOK^BMXADOV1(LIEN)
|
---|
| 80 | . D SEED(LDA)
|
---|
| 81 | . Q
|
---|
| 82 | I $P(FINFO,U,4) S LFILE=$P(FINFO,U,3) I LFILE D Q ; SPECIAL CASE: DINUM -> TEXT LOOKUP.
|
---|
| 83 | . S LDA=$$LOOK2^BMXADOV1(LFILE)
|
---|
| 84 | . D SEED(LDA)
|
---|
| 85 | . Q
|
---|
| 86 | S LDA=$$LOOK1^BMXADOV1 ; STD INDEX LOOKUP: START FROM SCRATCH
|
---|
| 87 | D SEED(LDA) ; CAPTURE RE-ENTRY SEED
|
---|
| 88 | Q
|
---|
| 89 | ;
|
---|
| 90 | SEED(LDA) ; UPDATE THE SCHEMA STRING WITH THE SEED PARAMETER
|
---|
| 91 | N X,Y
|
---|
| 92 | S X=@OUT@(1)
|
---|
| 93 | S Y=$P(X,U)
|
---|
| 94 | S $P(Y,"|",3)=LDA
|
---|
| 95 | S $P(X,U,1)=Y
|
---|
| 96 | S @OUT@(1)=X
|
---|
| 97 | Q
|
---|
| 98 | ;
|
---|
| 99 | IENS(DAS) ;EP - CONVERT DAS STRING TO IENS STRING
|
---|
| 100 | N I,L,IENS
|
---|
| 101 | S DAS=$G(DAS)
|
---|
| 102 | S DAS=$TR(DAS,"+","")
|
---|
| 103 | S DAS=$TR(DAS,"-","")
|
---|
| 104 | I '$L(DAS) Q ","
|
---|
| 105 | I DAS="," S DAS=""
|
---|
| 106 | S L=$L(DAS,C)
|
---|
| 107 | S IENS=""
|
---|
| 108 | F I=L:-1:1 S IENS=IENS_$P(DAS,C,I)_C
|
---|
| 109 | Q IENS
|
---|
| 110 | ;
|
---|
| 111 | IXFLD(FIEN,IX) ;EP - GIVEN AN FILE NUMMER AND INDEX NAME, RETURIN THE FIELD NUMBER, TYPE, AND DINUM SUBTYPE
|
---|
| 112 | N FLD,TYPES,T,X,I
|
---|
| 113 | I '$G(FIEN) Q ""
|
---|
| 114 | I '$L($G(IX)) Q ""
|
---|
| 115 | S FLD=$O(^DD(FIEN,0,"IX",IX,FIEN,0))
|
---|
| 116 | I 'FLD Q FLD
|
---|
| 117 | S TYPES="DNSFWCPVM",T=$P($G(^DD(FIEN,FLD,0)),U,2)
|
---|
| 118 | F I=1:1 S X=$E(TYPES,I) Q:'$L(X) I T[X Q
|
---|
| 119 | I X="P" S X=X_U_+$P(T,"P",2) I $P(^DD(FIEN,FLD,0),U,5)["DINUM" S X=X_U_1
|
---|
| 120 | S FLD=FLD_U_X
|
---|
| 121 | Q FLD
|
---|
| 122 | ;
|
---|