source: ccr/trunk/p/C0CUNIT.m@ 1724

Last change on this file since 1724 was 1586, checked in by Sam Habiel, 12 years ago

Changed license to AGPL. Some clean-up for XINDEX

  • Property svn:mergeinfo set to (toggle deleted branches)
    /ccr/branches/ohum/o-old/p/C0CUNIT.m1290
    /ccr/branches/ohum/p/C0CUNIT.m1291-1543
    /ccr/branches/ohum/p/p/C0CUNIT.m1287-1289
File size: 5.8 KB
Line 
1C0CUNIT ; CCDCCR/GPL - Unit Testing Library; 5/07/08
2 ;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50
3 ;Copyright 2008 George Lilly.
4 ;
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.
9 ;
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.
14 ;
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/>.
17 ;
18 W "This is a unit testing library",!
19 W !
20 Q
21 ;
22ZT(ZARY,BAT,TST) ; private routine to add a test case to the ZARY array
23 ; ZARY IS PASSED BY REFERENCE
24 ; BAT is a string identifying the test battery
25 ; TST is a test which will evaluate to true or false
26 ; I '$G(ZARY) D
27 ; . S ZARY(0)=0 ; initially there are no elements
28 ; W "GOT HERE LOADING "_TST,!
29 N CNT ; count of array elements
30 S CNT=ZARY(0) ; contains array count
31 S CNT=CNT+1 ; increment count
32 S ZARY(CNT)=TST ; put the test in the array
33 I $D(ZARY(BAT)) D ; NOT THE FIRST TEST IN BATTERY
34 . N II,TN ; TEMP FOR ENDING TEST IN BATTERY
35 . S II=$P(ZARY(BAT),"^",2)
36 . S $P(ZARY(BAT),"^",2)=II+1
37 I '$D(ZARY(BAT)) D ; FIRST TEST IN THIS BATTERY
38 . S ZARY(BAT)=CNT_"^"_CNT ; FIRST AND LAST TESTS IN BATTERY
39 . S ZARY("TESTS",BAT)="" ; PUT THE BATTERY IN THE TESTS INDEX
40 . ; S TN=$NA(ZARY("TESTS"))
41 . ; D PUSH^C0CXPATH(TN,BAT)
42 S ZARY(0)=CNT ; update the array counter
43 Q
44 ;
45ZLOAD(ZARY,ROUTINE) ; load tests into ZARY which is passed by reference
46 ; ZARY IS PASSED BY NAME
47 ; ZARY = name of the root, closed array format (e.g., "^TMP($J)")
48 ; ROUTINE = NAME OF THE ROUTINE - PASSED BY VALUE
49 K @ZARY
50 S @ZARY@(0)=0 ; initialize array count
51 N LINE,LABEL,BODY
52 N INTEST S INTEST=0 ; switch for in the test case section
53 N SECTION S SECTION="[anonymous]" ; test case section
54 ;
55 N NUM F NUM=1:1 S LINE=$T(+NUM^@ROUTINE) Q:LINE="" D
56 . I LINE?." "1";;><TEST>".E S INTEST=1 ; entering test section
57 . I LINE?." "1";;><TEMPLATE>".E S INTEST=1 ; entering TEMPLATE section
58 . I LINE?." "1";;></TEST>".E S INTEST=0 ; leaving test section
59 . I LINE?." "1";;></TEMPLATE>".E S INTEST=0 ; leaving TEMPLATE section
60 . I INTEST D ; within the testing section
61 . . I LINE?." "1";;><".E D ; section name found
62 . . . S SECTION=$P($P(LINE,";;><",2),">",1) ; pull out name
63 . . I LINE?." "1";;>>".E D ; test case found
64 . . . D ZT(.@ZARY,SECTION,$P(LINE,";;>>",2)) ; put the test in the array
65 S @ZARY@("ALL")="1"_"^"_@ZARY@(0) ; MAKE A BATTERY FOR ALL
66 Q
67 ;
68ZTEST(ZARY,WHICH) ; try out the tests using a passed array ZTEST
69 N ZI,ZX,ZR,ZP
70 S DEBUG=0
71 ; I WHICH="ALL" D Q ; RUN ALL THE TESTS
72 ; . W "DOING ALL",!
73 ; . N J,NT
74 ; . S NT=$NA(ZARY("TESTS"))
75 ; . W NT,@NT@(0),!
76 ; . F J=1:1:@NT@(0) D ;
77 ; . . W @NT@(J),!
78 ; . . D ZTEST^C0CUNIT(@ZARY,@NT@(J))
79 I '$D(ZARY(WHICH)) D Q ; TEST SECTION DOESN'T EXIST
80 . W "ERROR -- TEST SECTION DOESN'T EXIST -> ",WHICH,!
81 N FIRST,LAST
82 S FIRST=$P(ZARY(WHICH),"^",1)
83 S LAST=$P(ZARY(WHICH),"^",2)
84 F ZI=FIRST:1:LAST D
85 . I ZARY(ZI)?1">"1.E D ; NOT A TEST, JUST RUN THE STATEMENT
86 . . S ZP=$E(ZARY(ZI),2,$L(ZARY(ZI)))
87 . . ; W ZP,!
88 . . S ZX=ZP
89 . . W "RUNNING: "_ZP
90 . . X ZX
91 . . W "..SUCCESS: ",WHICH,!
92 . I ZARY(ZI)?1"?"1.E D ; THIS IS A TEST
93 . . S ZP=$E(ZARY(ZI),2,$L(ZARY(ZI)))
94 . . S ZX="S ZR="_ZP
95 . . W "TRYING: "_ZP
96 . . X ZX
97 . . W $S(ZR=1:"..PASSED ",1:"..FAILED "),!
98 . . I '$D(TPASSED) D ; NOT INITIALIZED YET
99 . . . S TPASSED=0 S TFAILED=0
100 . . I ZR S TPASSED=TPASSED+1
101 . . I 'ZR S TFAILED=TFAILED+1
102 Q
103 ;
104TEST ; RUN ALL THE TEST CASES
105 N ZTMP
106 D ZLOAD(.ZTMP)
107 D ZTEST(.ZTMP,"ALL")
108 W "PASSED: ",TPASSED,!
109 W "FAILED: ",TFAILED,!
110 W !
111 W "THE TESTS!",!
112 ; I DEBUG ZWR ZTMP
113 Q
114 ;
115GTSTS(GTZARY,RTN) ; return an array of test names
116 N I,J S I="" S I=$O(GTZARY("TESTS",I))
117 F J=0:0 Q:I="" D
118 . D PUSH^C0CXPATH(RTN,I)
119 . S I=$O(GTZARY("TESTS",I))
120 Q
121 ;
122TESTALL(RNM) ; RUN ALL THE TESTS
123 N ZI,J,TZTMP,TSTS,TOTP,TOTF
124 S TOTP=0 S TOTF=0
125 D ZLOAD^C0CUNIT("TZTMP",RNM)
126 D GTSTS(.TZTMP,"TSTS")
127 F ZI=1:1:TSTS(0) D ;
128 . S TPASSED=0 S TFAILED=0
129 . D ZTEST^C0CUNIT(.TZTMP,TSTS(ZI))
130 . S TOTP=TOTP+TPASSED
131 . S TOTF=TOTF+TFAILED
132 . S $P(TSTS(ZI),"^",2)=TPASSED
133 . S $P(TSTS(ZI),"^",3)=TFAILED
134 F ZI=1:1:TSTS(0) D ;
135 . W "TEST=> ",$P(TSTS(ZI),"^",1)
136 . W " PASSED=>",$P(TSTS(ZI),"^",2)
137 . W " FAILED=>",$P(TSTS(ZI),"^",3),!
138 W "TOTAL=> PASSED:",TOTP," FAILED:",TOTF,!
139 Q
140 ;
141TLIST(ZARY) ; LIST ALL THE TESTS
142 ; THEY ARE MARKED AS ;;><TESTNAME> IN THE TEST CASES
143 ; ZARY IS PASSED BY REFERENCE
144 N I,J,K S I="" S I=$O(ZARY("TESTS",I))
145 S K=1
146 F J=0:0 Q:I="" D
147 . ; W "I IS NOW=",I,!
148 . W I," "
149 . S I=$O(ZARY("TESTS",I))
150 . S K=K+1 I K=6 D
151 . . W !
152 . . S K=1
153 Q
154 ;
155MEDS ;
156 N DEBUG S DEBUG=0
157 N DFN S DFN=5685
158 K ^TMP($J)
159 W "Loading CCR Template into T using LOAD^GPLCCR0($NA(^TMP($J,""CCR"")))",!!
160 N T S T=$NA(^TMP($J,"CCR")) D LOAD^GPLCCR0(T)
161 N XPATH S XPATH="//ContinuityOfCareRecord/Body/Medications"
162 W "XPATH is: "_XPATH,!
163 W "Getting Med Template into INXML using",!
164 W "QUERY^GPLXPATH(T,XPATH,""INXML"")",!!
165 D QUERY^GPLXPATH(T,XPATH,"INXML")
166 W "Executing EXTRACT^C0CMED(INXML,DFN,OUTXML)",!
167 W "OUTXML will be ^TMP($J,""OUT"")",!
168 N OUTXML S OUTXML=$NA(^TMP($J,"OUT"))
169 D EXTRACT^C0CMED6("INXML",DFN,OUTXML)
170 D FILEOUT^C0CRNF(OUTXML,"TESTMEDS.xml")
171 Q
172PAT ;
173 D ANALYZE^ARJTXRD("C0CDPT",.OUT) ; Analyze a routine in the directory
174 N X,Y
175 ; Select Patient
176 S DIC=2,DIC(0)="AEMQ" D ^DIC
177 ;
178 W "You have selected patient "_Y,!!
179 N I S I=89 F S I=$O(OUT(I)) Q:I="ALINE" D
180 . W "OUT("_I_",0)"_" is "_$P(OUT(I,0)," ")_" "
181 . W "valued at "
182 . W @("$$"_$P(OUT(I,0),"(DFN)")_"^"_"C0CDPT"_"("_$P(Y,"^")_")")
183 . W !
184 Q
Note: See TracBrowser for help on using the repository browser.