AMQQSQL ; IHS/CMI/THL - SUBQUERY DESCRIPTIVE LIST ;
;;2.0;IHS PCC SUITE;;MAY 14, 2009
;-----
I $D(AMQQXX) Q
N AMQQSQLS
LIST S AMQQSQLS="W ?"_$S($D(AMQQGVF):6,1:(3*AMQQUSQL+6))_","""
EN1 ; ENTRY POINT FROM AMQQSQP
I '$D(AMQQSQCT),$D(AMQQSBCT) S AMQQSQCT=AMQQSBCT ; &&&
I $D(^UTILITY("AMQQ",$J,"SQ",AMQQSQNN,"NULL"))!($G(X)="NULL") S AMQQSQLS=AMQQSQLS_"'NULL' (None meet criteria)" G LS
I AMQQSQCT="B","EV"[AMQQSQST,AMQQSQST'="" D BP G LS
S %=AMQQSQCT
D @$S($D(AMQQSQLF):"MULT",%="D":"DT^AMQQSQL1",%="B":"VAL",%="C":"COMP",%="O":"ORD",%="T":"LEAST",%="R":"REL",%="L":"LINK",%="V":"VIS",%="M":"MULT",%="S":"SET",1:"NOSQL")
I $D(AMQQNOSQ)!($G(AMQQSQLS)[";*;") K AMQQNOSQ Q ; &&&
LS I '$D(AMQQNOSQ) S ^UTILITY("AMQQ",$J,"SQL",AMQQSQNN,AMQQSQFN)=AMQQSQLS_""""
EXIT K %,A,B,C,E,F,G,H,S,T,Z,AMQQNOSQ
Q
;
NOSQL S AMQQNOSQ=""
Q
;
VAL N X,Y,Z,A S X=AMQQSQCV
I AMQQSQCV["~",AMQQSQTP="E" D BP Q
I AMQQSQCV[";" S:$D(AMQQSQNT) AMQQSQLS=AMQQSQLS_"NOT " S AMQQSQLS=AMQQSQLS_"BETWEEN "_$P(AMQQSQCV,";")_" and "_$P(AMQQSQCV,";",2) Q
S A=$S($E(AMQQSQBS)="'":$E(AMQQSQBS,2,99),1:AMQQSQBS)
S Y=$F("[]=?$#><",A)-1
S Z=$P("CONTAINS^FOLLOWS^EQUALS^PATTERN MATCH^STARTS WITH^ENDS WITH^GREATER THAN^LESS THAN",U,Y)
I $D(AMQQSQNT) S Z=$S(Y<7:"DOES ",1:"")_"NOT "_$P("CONTAIN^FOLLOW^EQUAL^PATTERN MATCH^START WITH^END WITH^GREATER THAN^LESS THAN",U,Y)
S AMQQSQLS=AMQQSQLS_Z_" "
S:AMQQSQST="T" AMQQSQLS=AMQQSQLS_"1:"
S AMQQSQLS=AMQQSQLS_AMQQSQCV
Q
;
;
BP N A,B,C,E,X,F,G,H,T,Z
S Y=AMQQSQCV
I Y=">:0~>:0~!" S AMQQSQLS=AMQQSQLS_"all values""" Q
I AMQQSQSN=253 S F="S",G="D",T="" G BP1
S F="R"
S G="L"
S T="20/"
BP1 S Z=$P(Y,"~")
S A=$P(Z,":")
S B=$P(Z,":",2)
S C=$P(Z,":",3)
S E=$P(Z,":",4)
S AMQQSQLS=AMQQSQLS_F
S:C="" AMQQSQLS=AMQQSQLS_A_T_B
S:C'="" AMQQSQLS=AMQQSQLS_" "_T_B_"-"_E
S H=$S($P(Y,"~",3)="&":" and ",1:" or "),AMQQSQLS=AMQQSQLS_H_G
S Z=$P(Y,"~",2),A=$P(Z,":")
S B=$P(Z,":",2)
S C=$P(Z,":",3)
S E=$P(Z,":",4)
S:C="" AMQQSQLS=AMQQSQLS_A_T_B
S:C'="" AMQQSQLS=AMQQSQLS_" "_T_B_"-"_E
Q
;
LEAST I AMQQSQNM["_" S AMQQSQLS=AMQQSQLS_$P(AMQQSQNM,"_")_AMQQSQCV_$P(AMQQSQNM,"_",2) Q
ORD S AMQQSQLS=AMQQSQLS_AMQQSQNM_" "_AMQQSQCV
Q
;
COMP S AMQQSQLS=AMQQSQLS_AMQQSQNM
Q
;
REL S AMQQSQLS=AMQQSQLS_"DURING THE SPECIFIED AGE WINDOW"
Q
;
LINK N X
S X=AMQQQ,Y=$P(X,U,3)
I X[";;;NULL" S AMQQSQLS=AMQQSQLS_$P(X,U,2)_" IS 'NULL'" Q
I X[";;;EXIST" S AMQQSQLS=AMQQSQLS_$P(X,U,2)_" IS NOT 'NULL'" Q
D VIS1
Q
;
VIS N X,Y
S X=AMQQQ,Y=$P(X,U,3)
I AMQQQ["NULL" S AMQQSQLS=AMQQSQLS_$P(X,U,2)_" IS 'NULL'" Q
VIS1 I "GL"[Y D ZSET^AMQQATL1 S AMQQSQLS=AMQQSQLS_$P(X,U,2)_$G(Z) Q
I Y="D" D DATE^AMQQSQL1 Q
I Y="S" D SET^AMQQSQL1 Q
I Y="F" D FREE^AMQQSQL1 Q
I $P(X,U,8)="><" S AMQQSQLS=AMQQSQLS_$P(X,U,2)_" BETWEEN "_+$P(X,U,9)_" AND "_$P($P(X,U,9),";",2) Q
S AMQQSQLS=AMQQSQLS_$P(X,U,2)_" "_$P(X,U,8)_" "_$P(X,U,9)
; INSERT OTHER TYPES HERE
Q
;
MULT S AMQQZSQL=AMQQSQNN_U_AMQQSQFN_U_(AMQQUSQN+1)
K AMQQSQLF
S AMQQSQLS=AMQQSQLS_$P(AMQQSQSQ,U,6)_" ENTERED "
I $P(AMQQSQSQ,U,7),$G(AMQQSQN),$G(AMQQSQSN),$D(^AMQQ(5,AMQQSQN,5)),$D(^AMQQ(5,AMQQSQSN,5)),$P(^(5),U,2),$P(^(5),U,2)=$P(^AMQQ(5,AMQQSQN,5),U,2) S AMQQSQLS=AMQQSQLS_"DURING THIS "_$P(AMQQSQSQ,U,5) Q
I $P(AMQQSQSQ,U,7) S AMQQSQLS=AMQQSQLS_"ON THE SAME VISIT AS EA. "_$P(AMQQSQSQ,U,5) Q
N X,Y
S X=$P(AMQQSQSQ,U,3)
S Y=$P(AMQQSQSQ,U,4)
I X["0 DAY " S X="THE SAME DAY"
I Y["0 DAY " S Y="THE SAME DAY AS"
S AMQQSQLS=AMQQSQLS_"FROM "_X_" TO "_Y_" EA. "_$P(AMQQSQSQ,U,5)
Q
;
SET N %,S,A,B
I AMQQLINK>1000!((AMQQLINK>689.9999)&(AMQQLINK<706)) S S=$G(^AMQQ(1,AMQQLINK,4,1,1)),S=$P(S,"S Y=""",2),S=$P(S,""",X=$F") G SET1
S %=$P($G(^AMQQ(5,AMQQSQSN,0)),U,5)
I % S:%=9 %=AMQQSQSN+($J/100000) S %=$P($G(^AMQQ(1,%,0)),U,6) I % S %="^DD("_%_",0)" I $D(@%) S S=";"_$P(^(0),U,3)
SET1 S A=";"_AMQQSQCV_":"
S A=$F(S,A)
I A S B=$P($E(S,A,999),";")
S AMQQSQLS=AMQQSQLS_"Result is "_$S($G(AMQQSQBS)="'=":"not ",1:"")_$G(B)
Q
;
AMQQSQL ; IHS/CMI/THL - SUBQUERY DESCRIPTIVE LIST ;
+1 ;;2.0;IHS PCC SUITE;;MAY 14, 2009
+2 ;-----
+3 IF $DATA(AMQQXX)
QUIT
+4 NEW AMQQSQLS
LIST SET AMQQSQLS="W ?"_$SELECT($DATA(AMQQGVF):6,1:(3*AMQQUSQL+6))_","""
EN1 ; ENTRY POINT FROM AMQQSQP
+1 ; &&&
IF '$DATA(AMQQSQCT)
IF $DATA(AMQQSBCT)
SET AMQQSQCT=AMQQSBCT
+2 IF $DATA(^UTILITY("AMQQ",$JOB,"SQ",AMQQSQNN,"NULL"))!($GET(X)="NULL")
SET AMQQSQLS=AMQQSQLS_"'NULL' (None meet criteria)"
GOTO LS
+3 IF AMQQSQCT="B"
IF "EV"[AMQQSQST
IF AMQQSQST'=""
DO BP
GOTO LS
+4 SET %=AMQQSQCT
+5 DO @$SELECT($DATA(AMQQSQLF):"MULT",%="D":"DT^AMQQSQL1",%="B":"VAL",%="C":"COMP",%="O":"ORD",%="T":"LEAST",%="R":"REL",%="L":"LINK",%="V":"VIS",%="M":"MULT",%="S":"SET",1:"NOSQL")
+6 ; &&&
IF $DATA(AMQQNOSQ)!($GET(AMQQSQLS)[";*;")
KILL AMQQNOSQ
QUIT
LS IF '$DATA(AMQQNOSQ)
SET ^UTILITY("AMQQ",$JOB,"SQL",AMQQSQNN,AMQQSQFN)=AMQQSQLS_""""
EXIT KILL %,A,B,C,E,F,G,H,S,T,Z,AMQQNOSQ
+1 QUIT
+2 ;
NOSQL SET AMQQNOSQ=""
+1 QUIT
+2 ;
VAL NEW X,Y,Z,A
SET X=AMQQSQCV
+1 IF AMQQSQCV["~"
IF AMQQSQTP="E"
DO BP
QUIT
+2 IF AMQQSQCV[";"
IF $DATA(AMQQSQNT)
SET AMQQSQLS=AMQQSQLS_"NOT "
SET AMQQSQLS=AMQQSQLS_"BETWEEN "_$PIECE(AMQQSQCV,";")_" and "_$PIECE(AMQQSQCV,";",2)
QUIT
+3 SET A=$SELECT($EXTRACT(AMQQSQBS)="'":$EXTRACT(AMQQSQBS,2,99),1:AMQQSQBS)
+4 SET Y=$FIND("[]=?$#><",A)-1
+5 SET Z=$PIECE("CONTAINS^FOLLOWS^EQUALS^PATTERN MATCH^STARTS WITH^ENDS WITH^GREATER THAN^LESS THAN",U,Y)
+6 IF $DATA(AMQQSQNT)
SET Z=$SELECT(Y<7:"DOES ",1:"")_"NOT "_$PIECE("CONTAIN^FOLLOW^EQUAL^PATTERN MATCH^START WITH^END WITH^GREATER THAN^LESS THAN",U,Y)
+7 SET AMQQSQLS=AMQQSQLS_Z_" "
+8 IF AMQQSQST="T"
SET AMQQSQLS=AMQQSQLS_"1:"
+9 SET AMQQSQLS=AMQQSQLS_AMQQSQCV
+10 QUIT
+11 ;
+12 ;
BP NEW A,B,C,E,X,F,G,H,T,Z
+1 SET Y=AMQQSQCV
+2 IF Y=">:0~>:0~!"
SET AMQQSQLS=AMQQSQLS_"all values"""
QUIT
+3 IF AMQQSQSN=253
SET F="S"
SET G="D"
SET T=""
GOTO BP1
+4 SET F="R"
+5 SET G="L"
+6 SET T="20/"
BP1 SET Z=$PIECE(Y,"~")
+1 SET A=$PIECE(Z,":")
+2 SET B=$PIECE(Z,":",2)
+3 SET C=$PIECE(Z,":",3)
+4 SET E=$PIECE(Z,":",4)
+5 SET AMQQSQLS=AMQQSQLS_F
+6 IF C=""
SET AMQQSQLS=AMQQSQLS_A_T_B
+7 IF C'=""
SET AMQQSQLS=AMQQSQLS_" "_T_B_"-"_E
+8 SET H=$SELECT($PIECE(Y,"~",3)="&":" and ",1:" or ")
SET AMQQSQLS=AMQQSQLS_H_G
+9 SET Z=$PIECE(Y,"~",2)
SET A=$PIECE(Z,":")
+10 SET B=$PIECE(Z,":",2)
+11 SET C=$PIECE(Z,":",3)
+12 SET E=$PIECE(Z,":",4)
+13 IF C=""
SET AMQQSQLS=AMQQSQLS_A_T_B
+14 IF C'=""
SET AMQQSQLS=AMQQSQLS_" "_T_B_"-"_E
+15 QUIT
+16 ;
LEAST IF AMQQSQNM["_"
SET AMQQSQLS=AMQQSQLS_$PIECE(AMQQSQNM,"_")_AMQQSQCV_$PIECE(AMQQSQNM,"_",2)
QUIT
ORD SET AMQQSQLS=AMQQSQLS_AMQQSQNM_" "_AMQQSQCV
+1 QUIT
+2 ;
COMP SET AMQQSQLS=AMQQSQLS_AMQQSQNM
+1 QUIT
+2 ;
REL SET AMQQSQLS=AMQQSQLS_"DURING THE SPECIFIED AGE WINDOW"
+1 QUIT
+2 ;
LINK NEW X
+1 SET X=AMQQQ
SET Y=$PIECE(X,U,3)
+2 IF X[";;;NULL"
SET AMQQSQLS=AMQQSQLS_$PIECE(X,U,2)_" IS 'NULL'"
QUIT
+3 IF X[";;;EXIST"
SET AMQQSQLS=AMQQSQLS_$PIECE(X,U,2)_" IS NOT 'NULL'"
QUIT
+4 DO VIS1
+5 QUIT
+6 ;
VIS NEW X,Y
+1 SET X=AMQQQ
SET Y=$PIECE(X,U,3)
+2 IF AMQQQ["NULL"
SET AMQQSQLS=AMQQSQLS_$PIECE(X,U,2)_" IS 'NULL'"
QUIT
VIS1 IF "GL"[Y
DO ZSET^AMQQATL1
SET AMQQSQLS=AMQQSQLS_$PIECE(X,U,2)_$GET(Z)
QUIT
+1 IF Y="D"
DO DATE^AMQQSQL1
QUIT
+2 IF Y="S"
DO SET^AMQQSQL1
QUIT
+3 IF Y="F"
DO FREE^AMQQSQL1
QUIT
+4 IF $PIECE(X,U,8)="><"
SET AMQQSQLS=AMQQSQLS_$PIECE(X,U,2)_" BETWEEN "_+$PIECE(X,U,9)_" AND "_$PIECE($PIECE(X,U,9),";",2)
QUIT
+5 SET AMQQSQLS=AMQQSQLS_$PIECE(X,U,2)_" "_$PIECE(X,U,8)_" "_$PIECE(X,U,9)
+6 ; INSERT OTHER TYPES HERE
+7 QUIT
+8 ;
MULT SET AMQQZSQL=AMQQSQNN_U_AMQQSQFN_U_(AMQQUSQN+1)
+1 KILL AMQQSQLF
+2 SET AMQQSQLS=AMQQSQLS_$PIECE(AMQQSQSQ,U,6)_" ENTERED "
+3 IF $PIECE(AMQQSQSQ,U,7)
IF $GET(AMQQSQN)
IF $GET(AMQQSQSN)
IF $DATA(^AMQQ(5,AMQQSQN,5))
IF $DATA(^AMQQ(5,AMQQSQSN,5))
IF $PIECE(^(5),U,2)
IF $PIECE(^(5),U,2)=$PIECE(^AMQQ(5,AMQQSQN,5),U,2)
SET AMQQSQLS=AMQQSQLS_"DURING THIS "_$PIECE(AMQQSQSQ,U,5)
QUIT
+4 IF $PIECE(AMQQSQSQ,U,7)
SET AMQQSQLS=AMQQSQLS_"ON THE SAME VISIT AS EA. "_$PIECE(AMQQSQSQ,U,5)
QUIT
+5 NEW X,Y
+6 SET X=$PIECE(AMQQSQSQ,U,3)
+7 SET Y=$PIECE(AMQQSQSQ,U,4)
+8 IF X["0 DAY "
SET X="THE SAME DAY"
+9 IF Y["0 DAY "
SET Y="THE SAME DAY AS"
+10 SET AMQQSQLS=AMQQSQLS_"FROM "_X_" TO "_Y_" EA. "_$PIECE(AMQQSQSQ,U,5)
+11 QUIT
+12 ;
SET NEW %,S,A,B
+1 IF AMQQLINK>1000!((AMQQLINK>689.9999)&(AMQQLINK<706))
SET S=$GET(^AMQQ(1,AMQQLINK,4,1,1))
SET S=$PIECE(S,"S Y=""",2)
SET S=$PIECE(S,""",X=$F")
GOTO SET1
+2 SET %=$PIECE($GET(^AMQQ(5,AMQQSQSN,0)),U,5)
+3 IF %
IF %=9
SET %=AMQQSQSN+($JOB/100000)
SET %=$PIECE($GET(^AMQQ(1,%,0)),U,6)
IF %
SET %="^DD("_%_",0)"
IF $DATA(@%)
SET S=";"_$PIECE(^(0),U,3)
SET1 SET A=";"_AMQQSQCV_":"
+1 SET A=$FIND(S,A)
+2 IF A
SET B=$PIECE($EXTRACT(S,A,999),";")
+3 SET AMQQSQLS=AMQQSQLS_"Result is "_$SELECT($GET(AMQQSQBS)="'=":"not ",1:"")_$GET(B)
+4 QUIT
+5 ;