[1544] | 1 | C0CDIC ; CCDCCR/GPL - CCR Dictionary utilities; 6/1/08
|
---|
[1586] | 2 | ;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50
|
---|
| 3 | ;Copyright 2008 WorldVistA.
|
---|
[1544] | 4 | ;
|
---|
[1586] | 5 | ; This program is free software: you can redistribute it and/or modify
|
---|
| 6 | ; it under the terms of the GNU Affero General Public License as
|
---|
| 7 | ; published by the Free Software Foundation, either version 3 of the
|
---|
| 8 | ; License, or (at your option) any later version.
|
---|
[1544] | 9 | ;
|
---|
[1586] | 10 | ; This program is distributed in the hope that it will be useful,
|
---|
| 11 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 12 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 13 | ; GNU Affero General Public License for more details.
|
---|
[1544] | 14 | ;
|
---|
[1586] | 15 | ; You should have received a copy of the GNU Affero General Public License
|
---|
| 16 | ; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
[1544] | 17 | ;
|
---|
| 18 | W "This is the CCR Dictionary Utility Library ",!
|
---|
| 19 | W !
|
---|
| 20 | Q
|
---|
| 21 | ;
|
---|
| 22 | DIC2CSV ;OUTPUT THE CCR DICTIONARY TO A CSV FILE
|
---|
| 23 | ;
|
---|
| 24 | N ZI
|
---|
| 25 | S ZI=""
|
---|
| 26 | S G1=$NA(^TMP($J,"C0CCSV",1))
|
---|
| 27 | S G1A=$NA(@G1@("V"))
|
---|
| 28 | S G2=$NA(^TMP($J,"C0CCSV",2))
|
---|
| 29 | D GETN2^C0CRNF(G1,170) ; GET THE MATRIX
|
---|
| 30 | F S ZI=$O(@G1A@(ZI)) Q:ZI="" D ;FOR EACH ROW IN THE MATRIX
|
---|
| 31 | . I $G(@G1A@(ZI,"MAPPING METHOD",1))'="" D ;
|
---|
| 32 | . . W @G1A@(ZI,"MAPPING METHOD",1),!
|
---|
| 33 | . . ;K @G1A@(ZI,"MAPPING METHOD")
|
---|
| 34 | . ;W !,ZI,$G(@G1A@(ZI,"MAPPING METHOD",1))
|
---|
| 35 | D RNF2CSV^C0CRNF(G2,G1,"VN") ; PREPARE THE CVS FILE
|
---|
| 36 | K @G1
|
---|
| 37 | D FILEOUT^C0CRNF(G2,"FILE_"_170_".csv")
|
---|
| 38 | K @G2
|
---|
| 39 | Q
|
---|
| 40 | ;
|
---|
| 41 | GVARS(C0CVARS,C0CT) ; Get the CCR variables from the CCR template
|
---|
| 42 | ; and return them in C0CVARS, which is passed by name
|
---|
| 43 | ; FIRST PIECE OF C0CVARS(x) IS THE VARIABLE NAME, SECOND PIECE
|
---|
| 44 | ; IS THE LINE NUMBER OF THE VARIABLE IN THE TEMPLATE
|
---|
| 45 | ; C0CT IS RETURNED AS THE CCR TEMPLATE
|
---|
| 46 | N C0CTVARS ; ARRAY FOR THE TEMPLATE AND ARRAY FOR THE VARS
|
---|
| 47 | D LOAD^GPLCCR0(C0CT) ; LOAD THE CCR TEMPLATE
|
---|
| 48 | D XVARS^GPLXPATH("C0CTVARS",C0CT) ; PULL OUT THE VARS
|
---|
| 49 | N C0CI,C0CX
|
---|
| 50 | S @C0CVARS@(0)=C0CTVARS(0) ; SAME COUNT
|
---|
| 51 | F C0CI=1:1:C0CTVARS(0) D ; FOR EVERY LINE IN THE ARRAY
|
---|
| 52 | . S C0CX=C0CTVARS(C0CI) ; THE VARIABLE - 3 PIECES, FIRST ONE NULL
|
---|
| 53 | . S @C0CVARS@(C0CI)=$P(C0CX,"^",2)_"^"_$P(C0CX,"^",3) ; VAR NAME^LINE NUMBER
|
---|
| 54 | ;D PARY^GPLXPATH("C0CVARS")
|
---|
| 55 | Q
|
---|
| 56 | ;
|
---|
| 57 | GXPATH(C0CPVARS,C0CPT) ; LOAD THE CCR TEMPLATE INTO C0CPT, PULL OUT VARIABLES
|
---|
| 58 | ; AND THE XPATH TO THE VARIABLES INTO C0CPVARS
|
---|
| 59 | ; BY INDEXING THE TEMPLATE C0CT AND MATCHING THE XPATH TO THE VARIABLE
|
---|
| 60 | ; BOTH ARE PASSED BY NAME
|
---|
| 61 | ; C0CPVARS(x) IS VAR^LINENUM^XPATH SORTED BY LINENUM
|
---|
| 62 | ; C0CPVARS(0) IS NUMBER OF VARIABLES
|
---|
| 63 | ; C0CPT(0) IS NUMBER OF LINES IN THE TEMPLATE
|
---|
| 64 | D GVARS(C0CPVARS,C0CPT) ; GET THE VARIABLES AND LINE NUMBERS
|
---|
| 65 | ;N C0CTVARS ; HASH TABLE FOR VARIABLE BY LINE NUMBER
|
---|
| 66 | D HASHV ; PUT THE VARIABLES IN A LINE NUMBER HASH FOR MATCHING TO XPATHS
|
---|
| 67 | ; NOW GO GET THE XPATH INDEXES
|
---|
| 68 | D INDEX^GPLXPATH(C0CPT) ; ADD THE XPATH INDEXES TO THE TEMPLATE ARRAY
|
---|
| 69 | S C0CI="" ; GOING TO LOOP THROUGH THE WHOLE ARRAY LOOKING AT XPATHS
|
---|
| 70 | F S C0CI=$O(@C0CPT@(C0CI)) Q:C0CI="" D ; VISIT EVERY LINE
|
---|
| 71 | . I +C0CI'=0 Q ; SKIP EVERYTHING BUT THE XPATH INDEX
|
---|
| 72 | . I C0CI=0 Q ; SKIP THE ZERO NODE
|
---|
| 73 | . S C0CX=@C0CPT@(C0CI) ; PULL OUT THE LINE NUMBERS X^Y
|
---|
| 74 | . S C0CY=$P(C0CX,"^",1) ; STARTING LINE NUMBER
|
---|
| 75 | . S C0CZ=$P(C0CX,"^",2) ; ENDING LINE NUMBER
|
---|
| 76 | . I C0CY=C0CZ D ; THIS IS AN XPATH END NODE, HAS A VARIABLE (WE HOPE)
|
---|
| 77 | . . ; W "FOUND ",C0CI,!
|
---|
| 78 | . . I $D(C0CTVARS(C0CY)) D ; IF THERE IS A VARIABLE THERE
|
---|
| 79 | . . . S $P(C0CTVARS(C0CY),"^",3)=C0CI ; INSERT THE XPATH FOR THE VAR
|
---|
| 80 | D SORTV ; SORT THE ARRAY BY LINE NUMBER
|
---|
| 81 | Q
|
---|
| 82 | ;
|
---|
| 83 | HASHV ; INTERNAL ROUTINE TO PUT VARIABLE NAMES IN A LINE NUMBER HASH
|
---|
| 84 | ;N C0CI,C0CTVARS,C0CX,C0CY
|
---|
| 85 | F C0CI=1:1:@C0CPVARS@(0) D ; FOR THE ENTIRE ARRAY
|
---|
| 86 | . S C0CX=$P(@C0CPVARS@(C0CI),"^",2) ; LINE NUMBER
|
---|
| 87 | . S C0CY=$P(@C0CPVARS@(C0CI),"^",1) ; VARIABLE NAME
|
---|
| 88 | . S C0CTVARS(C0CX)=C0CY ; BUILD HASH OF VARIABLES BY LINE NUMBER
|
---|
| 89 | Q
|
---|
| 90 | ;
|
---|
| 91 | SORTV ; INTERNAL ROUTINE TO OUTPUT VARIABLES (AND XPATHS) IN LINE NUMBER ORDER
|
---|
| 92 | ;N C0CV2 ; SCRACTH SPACE FOR BUILDING SORTED ARRAY
|
---|
| 93 | S C0CI="" ;
|
---|
| 94 | F S C0CI=$O(C0CTVARS(C0CI)) Q:C0CI="" D ; BY LINE NUMBER
|
---|
| 95 | . S C0CX=C0CTVARS(C0CI) ;VARIABLE NAME
|
---|
| 96 | . S $P(C0CX,"^",2)=C0CI ; LINE NUMBER IS SECOND PIECE
|
---|
| 97 | . D PUSH^GPLXPATH("C0C2",C0CX) ; PUT ONTO ARRAY
|
---|
| 98 | K @C0CPVARS
|
---|
| 99 | M @C0CPVARS=C0C2
|
---|
| 100 | Q
|
---|
| 101 | ;
|
---|
| 102 | LOAD ; LOAD VARIABLE NAMES AND XPATH IN ^C0CDIC(170
|
---|
| 103 | ; INITIAL LOAD OF THE CCR DICTIONARY
|
---|
| 104 | ;
|
---|
| 105 | N C0CDIC,C0CARY,C0CXML,C0CFDA,C0CI
|
---|
| 106 | S C0CDIC="^C0CDIC(170," ; ROOT OF THE CCR DICTIONARY
|
---|
| 107 | D GXPATH("C0CARY","C0CXML") ; FETCH THE VARIABLES AND XPATH INTO C0CARY
|
---|
| 108 | ; C0CXML WILL CONTAIN THE TEMPLATE - NOT NEEDED FOR LOAD
|
---|
| 109 | D PARY^GPLXPATH("C0CARY") ;TEST
|
---|
| 110 | F C0CI=1:1:C0CARY(0) D ; LOAD EACH VARIABLE
|
---|
| 111 | . S C0CFDA(170,"+"_C0CI_",",.01)=$P(C0CARY(C0CI),"^",1) ; VAR NAME
|
---|
| 112 | . S C0CFDA(170,"+"_C0CI_",",2)=$P(C0CARY(C0CI),"^",3) ; XPATH
|
---|
| 113 | . D UPDATE^DIE("","C0CFDA")
|
---|
| 114 | . I $D(^TMP("DIERR",$J)) U $P BREAK
|
---|
| 115 | . W "LOADING:",C0CI," ",C0CARY(C0CI),!
|
---|
| 116 | Q
|
---|
| 117 | ;
|
---|
| 118 | INIT ; INITIALIZE CCR DICTIONARY BASED ON VARIABLE NAMES
|
---|
| 119 | ;
|
---|
| 120 | ; CHEAT SHEET FOR VARIABLE NAMES IN ^C0CDIC(170.xx,
|
---|
| 121 | ; THIS IS WHAT WILL BE IN C0CA FOR EACH DICTIONARY ENTRY
|
---|
| 122 | ;G1("CODING")="170^8"
|
---|
| 123 | ;G1("DATA ELEMENT")="170^7"
|
---|
| 124 | ;G1("DESCRIPTION")="170^3"
|
---|
| 125 | ;G1("ID")="170^1"
|
---|
| 126 | ;G1("M","170^8","CODING")="170.08^.01"
|
---|
| 127 | ;G1("MAPPING METHOD")="170.08^1"
|
---|
| 128 | ;G1("SECTION")="170^10"
|
---|
| 129 | ;G1("SOURCE")="170^4"
|
---|
| 130 | ;G1("STATUS")="170^9"
|
---|
| 131 | ;G1("TYPE")="170^6"
|
---|
| 132 | ;G1("VARIABLE")="170^.01"
|
---|
| 133 | ;G1("XPATH")="170^2"
|
---|
| 134 | ;
|
---|
| 135 | N C0CZA,C0CZX,C0CN,C0CSTAT
|
---|
| 136 | S C0CZX=0
|
---|
| 137 | S C0CSTAT=0 ; INIT STATUS SET FLAG
|
---|
| 138 | F S C0CZX=$O(^C0CDIC(170,C0CZX)) Q:+C0CZX=0 D ; FOR EACH DICT ENTRY
|
---|
| 139 | . ;W C0CZX,!
|
---|
| 140 | . K C0CA,C0CN ; CLEAR OUT THE LAST ONE
|
---|
| 141 | . D GETN1^C0CRNF("C0CA",170,C0CZX,"","ALL") ; GET VARIABLE HASH
|
---|
| 142 | . ;ZWR C0CA B ;
|
---|
| 143 | . S C0CN=$$ZVALUE("VARIABLE") ;NAME OF THE VARIABLE
|
---|
| 144 | . W "VARIABLE: ",C0CN,!
|
---|
| 145 | . I $E(C0CN,1,5)="ACTOR" D SETFDA("SECTION","ACTORS") ;
|
---|
| 146 | . I $E(C0CN,1,6)="SOCIAL" D ;
|
---|
| 147 | . . D SETFDA("SECTION","SOC") ;
|
---|
| 148 | . . D SETFDA("STATUS","X") ;SOCIAL HISTORY NOT IMPLEMENTED
|
---|
| 149 | . . S C0CSTAT=1
|
---|
| 150 | . I $E(C0CN,1,6)="FAMILY" D ;
|
---|
| 151 | . . D SETFDA("SECTION","FAM") ;
|
---|
| 152 | . . D SETFDA("STATUS","X") ;FAMILY HISTORY NOT IMPLEMENTED
|
---|
| 153 | . . S C0CSTAT=1
|
---|
| 154 | . ;D SETFDA("TYPE","") ;CORRECT FOR TYPE ERRORS
|
---|
| 155 | . I $E(C0CN,1,5)="ALERT" D SETFDA("SECTION","ALERTS")
|
---|
| 156 | . I $E(C0CN,1,5)="VITAL" D SETFDA("SECTION","VITALS")
|
---|
| 157 | . I $E(C0CN,1,7)="PROBLEM" D SETFDA("SECTION","PROBLEMS")
|
---|
| 158 | . I $E(C0CN,1,10)="RESULTTEST" D SETFDA("SECTION","TEST")
|
---|
| 159 | . E I $E(C0CN,1,6)="RESULT" D SETFDA("SECTION","LABS")
|
---|
| 160 | . I C0CN["CODEVALUE" D SETFDA("TYPE","CD") ;CODES
|
---|
| 161 | . I C0CN["CODEVERSION" D SETFDA("TYPE","CV") ; CODE VERSION
|
---|
| 162 | . I C0CN["CODINGSYSTEM" D SETFDA("TYPE","CS") ;CODING SYSTEM
|
---|
| 163 | . I $$ZVALUE("STATUS")=""!'C0CSTAT D SETFDA("STATUS","N") ;BLANK STATUS TO N
|
---|
| 164 | . I $$ZVALUE("XPATH")["/Medication/Directions/" D ; MEDS DIRECTIONS VAR
|
---|
| 165 | . . D SETFDA("SECTION","DIR") ; SPECIAL SECTION FOR DIRECTIONS
|
---|
| 166 | . E I $$ZVALUE("XPATH")["/Medications/Medication/" D ; ALL OTHER MEDS
|
---|
| 167 | . . D SETFDA("SECTION","MEDS") ; A MEDS VAR
|
---|
| 168 | . I $E(C0CN,($L(C0CN)-1),$L(C0CN))="ID" D SETFDA("TYPE","ID") ;CATCH THE IDS
|
---|
| 169 | . I C0CN["DATETIME" D SETFDA("TYPE","DT") ; DATE/TIME VARIABLE
|
---|
| 170 | . W "VARIABLE: ",C0CZX," ",C0CA("VARIABLE"),!
|
---|
| 171 | . ;ZWR C0CFDA
|
---|
| 172 | . I $D(C0CFDA) D ; WE HAVE CHANGES ON THIS VARIABLE
|
---|
| 173 | . . ;ZWR C0CFDA
|
---|
| 174 | . . D UPDATE^DIE("","C0CFDA(C0CZX)")
|
---|
| 175 | . . I $D(^TMP("DIERR",$J)) U $P BREAK
|
---|
| 176 | . . D CLEAN^DILF ; CLEAN UP
|
---|
| 177 | . ;ZWR C0CFDA
|
---|
| 178 | Q
|
---|
| 179 | ;
|
---|
| 180 | SETFDA(C0CSN,C0CSV) ; INTERNAL ROUTINE TO MAKE AN FDA ENTRY FOR FIELD C0CSN
|
---|
| 181 | ; TO SET TO VALUE C0CSV.
|
---|
| 182 | ; C0CFDA,C0CA,C0CZX ARE ASSUMED FROM THE CALLING ROUTINE
|
---|
| 183 | ; C0CSN,C0CSV ARE PASSED BY VALUE
|
---|
| 184 | ;
|
---|
| 185 | N C0CSI,C0CSJ
|
---|
| 186 | S C0CSI=$$ZFILE(C0CSN,"C0CA") ; FILE NUMBER
|
---|
| 187 | S C0CSJ=$$ZFIELD(C0CSN,"C0CA") ; FIELD NUMBER
|
---|
| 188 | S C0CFDA(C0CZX,C0CSI,C0CZX_",",C0CSJ)=C0CSV
|
---|
| 189 | Q
|
---|
| 190 | ZFILE(ZFN,ZTAB) ; EXTRINSIC TO RETURN FILE NUMBER FOR FIELD NAME PASSED
|
---|
| 191 | ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 1 OF C0CA(ZFN)
|
---|
| 192 | ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
|
---|
| 193 | I '$D(ZTAB) S ZTAB="C0CA"
|
---|
| 194 | Q $P(@ZTAB@(ZFN),"^",1)
|
---|
| 195 | ZFIELD(ZFN,ZTAB) ;EXTRINSIC TO RETURN FIELD NUMBER FOR FIELD NAME PASSED
|
---|
| 196 | ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 2 OF C0CA(ZFN)
|
---|
| 197 | ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
|
---|
| 198 | I '$D(ZTAB) S ZTAB="C0CA"
|
---|
| 199 | Q $P(@ZTAB@(ZFN),"^",2)
|
---|
| 200 | ZVALUE(ZFN,ZTAB) ;EXTRINSIC TO RETURN VALUE FOR FIELD NAME PASSED
|
---|
| 201 | ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 3 OF C0CA(ZFN)
|
---|
| 202 | ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
|
---|
| 203 | I '$D(ZTAB) S ZTAB="C0CA"
|
---|
| 204 | Q $P(@ZTAB@(ZFN),"^",3)
|
---|
| 205 | ;
|
---|