Changeset 1330 for ccr/branches/ohum/p/C0CUNIT.m
- Timestamp:
- Jan 3, 2012, 11:45:29 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ccr/branches/ohum/p/C0CUNIT.m
r1329 r1330 1 C0CUNIT 2 ;;1.0;C0C;;May 19, 2009;Build 38 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ZT(ZARY,BAT,TST) 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 ZLOAD(ZARY,ROUTINE) 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 ZTEST(ZARY,WHICH) 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 TEST 107 108 109 110 111 112 113 114 115 116 117 GTSTS(GTZARY,RTN) 118 119 120 121 122 123 124 TESTALL(RNM) 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 TLIST(ZARY) 144 145 146 147 148 149 150 151 152 153 154 155 156 157 MEDS 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 PAT 175 176 177 178 179 180 181 182 183 184 185 186 1 C0CUNIT ; CCDCCR/GPL - Unit Testing Library; 5/07/08 2 ;;1.0;C0C;;May 19, 2009;Build 1 3 ;Copyright 2008 George Lilly. Licensed under the terms of the GNU 4 ;General Public License See attached copy of the License. 5 ; 6 ;This program is free software; you can redistribute it and/or modify 7 ;it under the terms of the GNU General Public License as published by 8 ;the Free Software Foundation; either version 2 of the License, or 9 ;(at your option) any later version. 10 ; 11 ;This program is distributed in the hope that it will be useful, 12 ;but WITHOUT ANY WARRANTY; without even the implied warranty of 13 ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 ;GNU General Public License for more details. 15 ; 16 ;You should have received a copy of the GNU General Public License along 17 ;with this program; if not, write to the Free Software Foundation, Inc., 18 ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 ; 20 W "This is a unit testing library",! 21 W ! 22 Q 23 ; 24 ZT(ZARY,BAT,TST) ; private routine to add a test case to the ZARY array 25 ; ZARY IS PASSED BY REFERENCE 26 ; BAT is a string identifying the test battery 27 ; TST is a test which will evaluate to true or false 28 ; I '$G(ZARY) D 29 ; . S ZARY(0)=0 ; initially there are no elements 30 ; W "GOT HERE LOADING "_TST,! 31 N CNT ; count of array elements 32 S CNT=ZARY(0) ; contains array count 33 S CNT=CNT+1 ; increment count 34 S ZARY(CNT)=TST ; put the test in the array 35 I $D(ZARY(BAT)) D ; NOT THE FIRST TEST IN BATTERY 36 . N II,TN ; TEMP FOR ENDING TEST IN BATTERY 37 . S II=$P(ZARY(BAT),"^",2) 38 . S $P(ZARY(BAT),"^",2)=II+1 39 I '$D(ZARY(BAT)) D ; FIRST TEST IN THIS BATTERY 40 . S ZARY(BAT)=CNT_"^"_CNT ; FIRST AND LAST TESTS IN BATTERY 41 . S ZARY("TESTS",BAT)="" ; PUT THE BATTERY IN THE TESTS INDEX 42 . ; S TN=$NA(ZARY("TESTS")) 43 . ; D PUSH^C0CXPATH(TN,BAT) 44 S ZARY(0)=CNT ; update the array counter 45 Q 46 ; 47 ZLOAD(ZARY,ROUTINE) ; load tests into ZARY which is passed by reference 48 ; ZARY IS PASSED BY NAME 49 ; ZARY = name of the root, closed array format (e.g., "^TMP($J)") 50 ; ROUTINE = NAME OF THE ROUTINE - PASSED BY VALUE 51 K @ZARY 52 S @ZARY@(0)=0 ; initialize array count 53 N LINE,LABEL,BODY 54 N INTEST S INTEST=0 ; switch for in the test case section 55 N SECTION S SECTION="[anonymous]" ; test case section 56 ; 57 N NUM F NUM=1:1 S LINE=$T(+NUM^@ROUTINE) Q:LINE="" D 58 . I LINE?." "1";;><TEST>".E S INTEST=1 ; entering test section 59 . I LINE?." "1";;><TEMPLATE>".E S INTEST=1 ; entering TEMPLATE section 60 . I LINE?." "1";;></TEST>".E S INTEST=0 ; leaving test section 61 . I LINE?." "1";;></TEMPLATE>".E S INTEST=0 ; leaving TEMPLATE section 62 . I INTEST D ; within the testing section 63 . . I LINE?." "1";;><".E D ; section name found 64 . . . S SECTION=$P($P(LINE,";;><",2),">",1) ; pull out name 65 . . I LINE?." "1";;>>".E D ; test case found 66 . . . D ZT(.@ZARY,SECTION,$P(LINE,";;>>",2)) ; put the test in the array 67 S @ZARY@("ALL")="1"_"^"_@ZARY@(0) ; MAKE A BATTERY FOR ALL 68 Q 69 ; 70 ZTEST(ZARY,WHICH) ; try out the tests using a passed array ZTEST 71 N ZI,ZX,ZR,ZP 72 S DEBUG=0 73 ; I WHICH="ALL" D Q ; RUN ALL THE TESTS 74 ; . W "DOING ALL",! 75 ; . N J,NT 76 ; . S NT=$NA(ZARY("TESTS")) 77 ; . W NT,@NT@(0),! 78 ; . F J=1:1:@NT@(0) D ; 79 ; . . W @NT@(J),! 80 ; . . D ZTEST^C0CUNIT(@ZARY,@NT@(J)) 81 I '$D(ZARY(WHICH)) D Q ; TEST SECTION DOESN'T EXIST 82 . W "ERROR -- TEST SECTION DOESN'T EXIST -> ",WHICH,! 83 N FIRST,LAST 84 S FIRST=$P(ZARY(WHICH),"^",1) 85 S LAST=$P(ZARY(WHICH),"^",2) 86 F ZI=FIRST:1:LAST D 87 . I ZARY(ZI)?1">"1.E D ; NOT A TEST, JUST RUN THE STATEMENT 88 . . S ZP=$E(ZARY(ZI),2,$L(ZARY(ZI))) 89 . . ; W ZP,! 90 . . S ZX=ZP 91 . . W "RUNNING: "_ZP 92 . . X ZX 93 . . W "..SUCCESS: ",WHICH,! 94 . I ZARY(ZI)?1"?"1.E D ; THIS IS A TEST 95 . . S ZP=$E(ZARY(ZI),2,$L(ZARY(ZI))) 96 . . S ZX="S ZR="_ZP 97 . . W "TRYING: "_ZP 98 . . X ZX 99 . . W $S(ZR=1:"..PASSED ",1:"..FAILED "),! 100 . . I '$D(TPASSED) D ; NOT INITIALIZED YET 101 . . . S TPASSED=0 S TFAILED=0 102 . . I ZR S TPASSED=TPASSED+1 103 . . I 'ZR S TFAILED=TFAILED+1 104 Q 105 ; 106 TEST ; RUN ALL THE TEST CASES 107 N ZTMP 108 D ZLOAD(.ZTMP) 109 D ZTEST(.ZTMP,"ALL") 110 W "PASSED: ",TPASSED,! 111 W "FAILED: ",TFAILED,! 112 W ! 113 W "THE TESTS!",! 114 ; I DEBUG ZWR ZTMP 115 Q 116 ; 117 GTSTS(GTZARY,RTN) ; return an array of test names 118 N I,J S I="" S I=$O(GTZARY("TESTS",I)) 119 F J=0:0 Q:I="" D 120 . D PUSH^C0CXPATH(RTN,I) 121 . S I=$O(GTZARY("TESTS",I)) 122 Q 123 ; 124 TESTALL(RNM) ; RUN ALL THE TESTS 125 N ZI,J,TZTMP,TSTS,TOTP,TOTF 126 S TOTP=0 S TOTF=0 127 D ZLOAD^C0CUNIT("TZTMP",RNM) 128 D GTSTS(.TZTMP,"TSTS") 129 F ZI=1:1:TSTS(0) D ; 130 . S TPASSED=0 S TFAILED=0 131 . D ZTEST^C0CUNIT(.TZTMP,TSTS(ZI)) 132 . S TOTP=TOTP+TPASSED 133 . S TOTF=TOTF+TFAILED 134 . S $P(TSTS(ZI),"^",2)=TPASSED 135 . S $P(TSTS(ZI),"^",3)=TFAILED 136 F ZI=1:1:TSTS(0) D ; 137 . W "TEST=> ",$P(TSTS(ZI),"^",1) 138 . W " PASSED=>",$P(TSTS(ZI),"^",2) 139 . W " FAILED=>",$P(TSTS(ZI),"^",3),! 140 W "TOTAL=> PASSED:",TOTP," FAILED:",TOTF,! 141 Q 142 ; 143 TLIST(ZARY) ; LIST ALL THE TESTS 144 ; THEY ARE MARKED AS ;;><TESTNAME> IN THE TEST CASES 145 ; ZARY IS PASSED BY REFERENCE 146 N I,J,K S I="" S I=$O(ZARY("TESTS",I)) 147 S K=1 148 F J=0:0 Q:I="" D 149 . ; W "I IS NOW=",I,! 150 . W I," " 151 . S I=$O(ZARY("TESTS",I)) 152 . S K=K+1 I K=6 D 153 . . W ! 154 . . S K=1 155 Q 156 ; 157 MEDS 158 N DEBUG S DEBUG=0 159 N DFN S DFN=5685 160 K ^TMP($J) 161 W "Loading CCR Template into T using LOAD^GPLCCR0($NA(^TMP($J,""CCR"")))",!! 162 N T S T=$NA(^TMP($J,"CCR")) D LOAD^GPLCCR0(T) 163 N XPATH S XPATH="//ContinuityOfCareRecord/Body/Medications" 164 W "XPATH is: "_XPATH,! 165 W "Getting Med Template into INXML using",! 166 W "QUERY^GPLXPATH(T,XPATH,""INXML"")",!! 167 D QUERY^GPLXPATH(T,XPATH,"INXML") 168 W "Executing EXTRACT^C0CMED(INXML,DFN,OUTXML)",! 169 W "OUTXML will be ^TMP($J,""OUT"")",! 170 N OUTXML S OUTXML=$NA(^TMP($J,"OUT")) 171 D EXTRACT^C0CMED6("INXML",DFN,OUTXML) 172 D FILEOUT^C0CRNF(OUTXML,"TESTMEDS.xml") 173 Q 174 PAT 175 D ANALYZE^ARJTXRD("C0CDPT",.OUT) ; Analyze a routine in the directory 176 N X,Y 177 ; Select Patient 178 S DIC=2,DIC(0)="AEMQ" D ^DIC 179 ; 180 W "You have selected patient "_Y,!! 181 N I S I=89 F S I=$O(OUT(I)) Q:I="ALINE" D 182 . W "OUT("_I_",0)"_" is "_$P(OUT(I,0)," ")_" " 183 . W "valued at " 184 . W @("$$"_$P(OUT(I,0),"(DFN)")_"^"_"C0CDPT"_"("_$P(Y,"^")_")") 185 . W ! 186 Q
Note:
See TracChangeset
for help on using the changeset viewer.