2009-05-21 13:12:11 -04:00
|
|
|
C0CUNIT ; CCDCCR/GPL - Unit Testing Library; 5/07/08
|
|
|
|
;;1.0;C0C;;May 19, 2009;
|
2009-03-14 18:23:22 -04:00
|
|
|
;Copyright 2008 George Lilly. Licensed under the terms of the GNU
|
2008-07-14 10:53:09 -04:00
|
|
|
;General Public License See attached copy of the License.
|
|
|
|
;
|
|
|
|
;This program is free software; you can redistribute it and/or modify
|
|
|
|
;it under the terms of the GNU General Public License as published by
|
|
|
|
;the Free Software Foundation; either version 2 of the License, or
|
|
|
|
;(at your option) any later version.
|
|
|
|
;
|
|
|
|
;This program is distributed in the hope that it will be useful,
|
|
|
|
;but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;GNU General Public License for more details.
|
|
|
|
;
|
|
|
|
;You should have received a copy of the GNU General Public License along
|
|
|
|
;with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
;
|
2008-07-03 21:02:47 -04:00
|
|
|
W "This is a unit testing library",!
|
|
|
|
W !
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
ZT(ZARY,BAT,TST) ; private routine to add a test case to the ZARY array
|
2008-07-03 21:02:47 -04:00
|
|
|
; ZARY IS PASSED BY REFERENCE
|
|
|
|
; BAT is a string identifying the test battery
|
|
|
|
; TST is a test which will evaluate to true or false
|
|
|
|
; I '$G(ZARY) D
|
|
|
|
; . S ZARY(0)=0 ; initially there are no elements
|
|
|
|
; W "GOT HERE LOADING "_TST,!
|
|
|
|
N CNT ; count of array elements
|
|
|
|
S CNT=ZARY(0) ; contains array count
|
|
|
|
S CNT=CNT+1 ; increment count
|
|
|
|
S ZARY(CNT)=TST ; put the test in the array
|
|
|
|
I $D(ZARY(BAT)) D ; NOT THE FIRST TEST IN BATTERY
|
|
|
|
. N II,TN ; TEMP FOR ENDING TEST IN BATTERY
|
|
|
|
. S II=$P(ZARY(BAT),"^",2)
|
|
|
|
. S $P(ZARY(BAT),"^",2)=II+1
|
|
|
|
I '$D(ZARY(BAT)) D ; FIRST TEST IN THIS BATTERY
|
|
|
|
. S ZARY(BAT)=CNT_"^"_CNT ; FIRST AND LAST TESTS IN BATTERY
|
|
|
|
. S ZARY("TESTS",BAT)="" ; PUT THE BATTERY IN THE TESTS INDEX
|
|
|
|
. ; S TN=$NA(ZARY("TESTS"))
|
2009-03-14 18:23:22 -04:00
|
|
|
. ; D PUSH^C0CXPATH(TN,BAT)
|
2008-07-03 21:02:47 -04:00
|
|
|
S ZARY(0)=CNT ; update the array counter
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
ZLOAD(ZARY,ROUTINE) ; load tests into ZARY which is passed by reference
|
2008-07-03 21:02:47 -04:00
|
|
|
; ZARY IS PASSED BY NAME
|
|
|
|
; ZARY = name of the root, closed array format (e.g., "^TMP($J)")
|
|
|
|
; ROUTINE = NAME OF THE ROUTINE - PASSED BY VALUE
|
|
|
|
K @ZARY
|
|
|
|
S @ZARY@(0)=0 ; initialize array count
|
|
|
|
N LINE,LABEL,BODY
|
|
|
|
N INTEST S INTEST=0 ; switch for in the test case section
|
|
|
|
N SECTION S SECTION="[anonymous]" ; test case section
|
|
|
|
;
|
|
|
|
N NUM F NUM=1:1 S LINE=$T(+NUM^@ROUTINE) Q:LINE="" D
|
|
|
|
. I LINE?." "1";;><TEST>".E S INTEST=1 ; entering test section
|
|
|
|
. I LINE?." "1";;><TEMPLATE>".E S INTEST=1 ; entering TEMPLATE section
|
|
|
|
. I LINE?." "1";;></TEST>".E S INTEST=0 ; leaving test section
|
|
|
|
. I LINE?." "1";;></TEMPLATE>".E S INTEST=0 ; leaving TEMPLATE section
|
|
|
|
. I INTEST D ; within the testing section
|
|
|
|
. . I LINE?." "1";;><".E D ; section name found
|
|
|
|
. . . S SECTION=$P($P(LINE,";;><",2),">",1) ; pull out name
|
|
|
|
. . I LINE?." "1";;>>".E D ; test case found
|
|
|
|
. . . D ZT(.@ZARY,SECTION,$P(LINE,";;>>",2)) ; put the test in the array
|
|
|
|
S @ZARY@("ALL")="1"_"^"_@ZARY@(0) ; MAKE A BATTERY FOR ALL
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
ZTEST(ZARY,WHICH) ; try out the tests using a passed array ZTEST
|
2008-08-06 13:29:59 -04:00
|
|
|
N ZI,ZX,ZR,ZP
|
2008-07-03 21:02:47 -04:00
|
|
|
S DEBUG=0
|
|
|
|
; I WHICH="ALL" D Q ; RUN ALL THE TESTS
|
|
|
|
; . W "DOING ALL",!
|
|
|
|
; . N J,NT
|
|
|
|
; . S NT=$NA(ZARY("TESTS"))
|
|
|
|
; . W NT,@NT@(0),!
|
|
|
|
; . F J=1:1:@NT@(0) D ;
|
|
|
|
; . . W @NT@(J),!
|
2009-03-14 18:23:22 -04:00
|
|
|
; . . D ZTEST^C0CUNIT(@ZARY,@NT@(J))
|
2008-09-12 22:45:03 -04:00
|
|
|
I '$D(ZARY(WHICH)) D Q ; TEST SECTION DOESN'T EXIST
|
2008-07-03 21:02:47 -04:00
|
|
|
. W "ERROR -- TEST SECTION DOESN'T EXIST -> ",WHICH,!
|
|
|
|
N FIRST,LAST
|
|
|
|
S FIRST=$P(ZARY(WHICH),"^",1)
|
|
|
|
S LAST=$P(ZARY(WHICH),"^",2)
|
2008-08-06 13:29:59 -04:00
|
|
|
F ZI=FIRST:1:LAST D
|
|
|
|
. I ZARY(ZI)?1">"1.E D ; NOT A TEST, JUST RUN THE STATEMENT
|
|
|
|
. . S ZP=$E(ZARY(ZI),2,$L(ZARY(ZI)))
|
2008-07-03 21:02:47 -04:00
|
|
|
. . ; W ZP,!
|
|
|
|
. . S ZX=ZP
|
|
|
|
. . W "RUNNING: "_ZP
|
|
|
|
. . X ZX
|
|
|
|
. . W "..SUCCESS: ",WHICH,!
|
2008-08-06 13:29:59 -04:00
|
|
|
. I ZARY(ZI)?1"?"1.E D ; THIS IS A TEST
|
|
|
|
. . S ZP=$E(ZARY(ZI),2,$L(ZARY(ZI)))
|
2008-07-03 21:02:47 -04:00
|
|
|
. . S ZX="S ZR="_ZP
|
|
|
|
. . W "TRYING: "_ZP
|
|
|
|
. . X ZX
|
|
|
|
. . W $S(ZR=1:"..PASSED ",1:"..FAILED "),!
|
|
|
|
. . I '$D(TPASSED) D ; NOT INITIALIZED YET
|
|
|
|
. . . S TPASSED=0 S TFAILED=0
|
|
|
|
. . I ZR S TPASSED=TPASSED+1
|
|
|
|
. . I 'ZR S TFAILED=TFAILED+1
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
TEST ; RUN ALL THE TEST CASES
|
2008-07-03 21:02:47 -04:00
|
|
|
N ZTMP
|
|
|
|
D ZLOAD(.ZTMP)
|
|
|
|
D ZTEST(.ZTMP,"ALL")
|
|
|
|
W "PASSED: ",TPASSED,!
|
|
|
|
W "FAILED: ",TFAILED,!
|
|
|
|
W !
|
|
|
|
W "THE TESTS!",!
|
2008-08-30 15:13:15 -04:00
|
|
|
; I DEBUG ZWR ZTMP
|
2008-07-03 21:02:47 -04:00
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
GTSTS(GTZARY,RTN) ; return an array of test names
|
2008-07-03 21:02:47 -04:00
|
|
|
N I,J S I="" S I=$O(GTZARY("TESTS",I))
|
|
|
|
F J=0:0 Q:I="" D
|
2009-03-14 18:23:22 -04:00
|
|
|
. D PUSH^C0CXPATH(RTN,I)
|
2008-07-03 21:02:47 -04:00
|
|
|
. S I=$O(GTZARY("TESTS",I))
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
TESTALL(RNM) ; RUN ALL THE TESTS
|
2008-08-06 19:18:51 -04:00
|
|
|
N ZI,J,TZTMP,TSTS,TOTP,TOTF
|
2008-07-03 21:02:47 -04:00
|
|
|
S TOTP=0 S TOTF=0
|
2009-03-14 18:23:22 -04:00
|
|
|
D ZLOAD^C0CUNIT("TZTMP",RNM)
|
2008-07-03 21:02:47 -04:00
|
|
|
D GTSTS(.TZTMP,"TSTS")
|
2008-08-06 19:18:51 -04:00
|
|
|
F ZI=1:1:TSTS(0) D ;
|
2008-07-03 21:02:47 -04:00
|
|
|
. S TPASSED=0 S TFAILED=0
|
2009-03-14 18:23:22 -04:00
|
|
|
. D ZTEST^C0CUNIT(.TZTMP,TSTS(ZI))
|
2008-07-03 21:02:47 -04:00
|
|
|
. S TOTP=TOTP+TPASSED
|
|
|
|
. S TOTF=TOTF+TFAILED
|
2008-08-06 19:18:51 -04:00
|
|
|
. S $P(TSTS(ZI),"^",2)=TPASSED
|
|
|
|
. S $P(TSTS(ZI),"^",3)=TFAILED
|
2008-11-08 13:41:28 -05:00
|
|
|
F ZI=1:1:TSTS(0) D ;
|
2008-08-06 19:18:51 -04:00
|
|
|
. W "TEST=> ",$P(TSTS(ZI),"^",1)
|
|
|
|
. W " PASSED=>",$P(TSTS(ZI),"^",2)
|
|
|
|
. W " FAILED=>",$P(TSTS(ZI),"^",3),!
|
2008-07-03 21:02:47 -04:00
|
|
|
W "TOTAL=> PASSED:",TOTP," FAILED:",TOTF,!
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
TLIST(ZARY) ; LIST ALL THE TESTS
|
2008-07-03 21:02:47 -04:00
|
|
|
; THEY ARE MARKED AS ;;><TESTNAME> IN THE TEST CASES
|
|
|
|
; ZARY IS PASSED BY REFERENCE
|
|
|
|
N I,J,K S I="" S I=$O(ZARY("TESTS",I))
|
|
|
|
S K=1
|
|
|
|
F J=0:0 Q:I="" D
|
|
|
|
. ; W "I IS NOW=",I,!
|
|
|
|
. W I," "
|
|
|
|
. S I=$O(ZARY("TESTS",I))
|
|
|
|
. S K=K+1 I K=6 D
|
|
|
|
. . W !
|
|
|
|
. . S K=1
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
MEDS
|
2009-03-15 20:27:26 -04:00
|
|
|
N DEBUG S DEBUG=0
|
|
|
|
N DFN S DFN=5685
|
|
|
|
K ^TMP($J)
|
|
|
|
W "Loading CCR Template into T using LOAD^GPLCCR0($NA(^TMP($J,""CCR"")))",!!
|
|
|
|
N T S T=$NA(^TMP($J,"CCR")) D LOAD^GPLCCR0(T)
|
|
|
|
N XPATH S XPATH="//ContinuityOfCareRecord/Body/Medications"
|
|
|
|
W "XPATH is: "_XPATH,!
|
|
|
|
W "Getting Med Template into INXML using",!
|
|
|
|
W "QUERY^GPLXPATH(T,XPATH,""INXML"")",!!
|
|
|
|
D QUERY^GPLXPATH(T,XPATH,"INXML")
|
2009-03-22 15:26:00 -04:00
|
|
|
W "Executing EXTRACT^C0CMED(INXML,DFN,OUTXML)",!
|
2009-03-15 20:27:26 -04:00
|
|
|
W "OUTXML will be ^TMP($J,""OUT"")",!
|
|
|
|
N OUTXML S OUTXML=$NA(^TMP($J,"OUT"))
|
2009-03-22 15:26:00 -04:00
|
|
|
D EXTRACT^C0CMED6("INXML",DFN,OUTXML)
|
2009-03-15 20:27:26 -04:00
|
|
|
D FILEOUT^C0CRNF(OUTXML,"TESTMEDS.xml")
|
|
|
|
Q
|
2009-05-21 13:12:11 -04:00
|
|
|
PAT
|
2009-03-22 15:06:25 -04:00
|
|
|
D ANALYZE^ARJTXRD("C0CDPT",.OUT) ; Analyze a routine in the directory
|
2009-03-15 20:39:55 -04:00
|
|
|
N X,Y
|
|
|
|
; Select Patient
|
|
|
|
S DIC=2,DIC(0)="AEMQ" D ^DIC
|
|
|
|
;
|
|
|
|
W "You have selected patient "_Y,!!
|
|
|
|
N I S I=89 F S I=$O(OUT(I)) Q:I="ALINE" D
|
|
|
|
. W "OUT("_I_",0)"_" is "_$P(OUT(I,0)," ")_" "
|
|
|
|
. W "valued at "
|
2009-03-22 15:06:25 -04:00
|
|
|
. W @("$$"_$P(OUT(I,0),"(DFN)")_"^"_"C0CDPT"_"("_$P(Y,"^")_")")
|
2009-03-15 20:39:55 -04:00
|
|
|
. W !
|
|
|
|
Q
|