[613] | 1 | ORRHCQ ; SLC/KCM/JLI - CPRS Query Tools - Utilities ;2/1/03 11:10
|
---|
| 2 | ;;3.0;ORDER ENTRY/RESULTS REPORTING;**153,174**;Dec 17, 1997
|
---|
| 3 | ;
|
---|
| 4 | SETUP(ITR,QRY) ; Setup the query
|
---|
| 5 | ; use ^TMP("ORRHCQ",$J,"QRY") for the query
|
---|
| 6 | ; use ^TMP("ORRHCQ",$J,"COL") for the columns
|
---|
| 7 | ; use ^TMP("ORRHCQD",$J) for the query data
|
---|
| 8 | D CLEAR(.OK)
|
---|
| 9 | N I,X,NAM,VAL,CID,ICOL,QROOT,DTRNG,CSLTGRP S ICOL=0,ITR=0,CSLTGRP=0
|
---|
| 10 | S I=0 F S I=$O(QRY(I)) Q:'I D
|
---|
| 11 | . S NAM=$P(QRY(I),"="),VAL=$P(QRY(I),"=",2,99)
|
---|
| 12 | . ; if time range, convert relative to actual fileman times
|
---|
| 13 | . S CID=+$O(^ORD(102.22,"B",NAM,0))
|
---|
| 14 | . I +CID S:$P(^ORD(102.22,CID,0),U,2)=2 VAL=$$RNG2FM^ORRHCU(VAL)
|
---|
| 15 | . I $L(VAL) S ^TMP("ORRHCQ",$J,"QRY",$P(NAM,"."),$P(NAM,".",2),VAL)=""
|
---|
| 16 | . I NAM="Report.Column" S ICOL=ICOL+1,^TMP("ORRHCQ",$J,"COL",ICOL)=VAL
|
---|
| 17 | ; when looking for combination of items, create full list to pass to query
|
---|
| 18 | S QROOT="^TMP(""ORRHCQ"",$J,""QRY"")"
|
---|
| 19 | I $D(@QROOT@("Order","ItemCombo1"))>1 D
|
---|
| 20 | . M @QROOT@("Order","Orderable")=@QROOT@("Order","ItemCombo1")
|
---|
| 21 | . M @QROOT@("Order","Orderable")=@QROOT@("Order","ItemCombo2")
|
---|
| 22 | I $D(@QROOT@("Consult","ItemCombo1"))>1 D
|
---|
| 23 | . M @QROOT@("Consult","Orderable")=@QROOT@("Consult","ItemCombo1")
|
---|
| 24 | . M @QROOT@("Consult","Orderable")=@QROOT@("Consult","ItemCombo2")
|
---|
| 25 | I $D(@QROOT@("Consult","DisplayGroup"))>1 D
|
---|
| 26 | . S CSLTGRP=$O(^ORD(100.98,"B","CSLT",0))
|
---|
| 27 | . I CSLTGRP=$O(@QROOT@("Consult","DisplayGroup",0)) Q
|
---|
| 28 | . M @QROOT@("Consult","Orderable")=@QROOT@("Consult","DisplayGroup")
|
---|
| 29 | . K @QROOT@("Consult","DisplayGroup")
|
---|
| 30 | ; set up actual dates for clinic list sources
|
---|
| 31 | S X=""
|
---|
| 32 | F S X=$O(@QROOT@("Patient","ListSource",X)) Q:X="" I $E(X)="c" D
|
---|
| 33 | . S DTRNG=$P(X,":",3,4),DTRNG=$$RNG2FM^ORRHCU(DTRNG)
|
---|
| 34 | . K @QROOT@("Patient","ListSource",X)
|
---|
| 35 | . S @QROOT@("Patient","ListSource",$P(X,":",1,2)_":"_DTRNG)=""
|
---|
| 36 | ; set up date ranges for search items based on general date range
|
---|
| 37 | S DTRNG=$O(@QROOT@("Search","DateRange",0))
|
---|
| 38 | I $D(@QROOT@("Document")) S @QROOT@("Document","Reference",DTRNG)=""
|
---|
| 39 | I $D(@QROOT@("Order")) S @QROOT@("Order","TimeFrame",DTRNG)=""
|
---|
| 40 | I $D(@QROOT@("Consult")) S @QROOT@("Consult","TimeFrame",DTRNG)=""
|
---|
| 41 | I $D(@QROOT@("Visit")) S @QROOT@("Visit","TimeFrame",DTRNG)=""
|
---|
| 42 | S ^TMP("ORRHCQ",$J,"TOT")=0
|
---|
| 43 | S ITR=$$NXTITER("")
|
---|
| 44 | Q
|
---|
| 45 | ADDTO(IEN,CLINDT) ;Add active location to lst
|
---|
| 46 | N IEN42
|
---|
| 47 | S IEN42=0
|
---|
| 48 | I ($P($G(^SC(IEN,0)),U,3)="C"),$$ACTLOC^ORWU(IEN) D
|
---|
| 49 | . S @QROOT@("Patient","ListSource","c:"_IEN_":"_CLINDT)=""
|
---|
| 50 | I ($P($G(^SC(IEN,0)),U,3)="W"),$$ACTLOC^ORWU(IEN) D
|
---|
| 51 | . S IEN42=$G(^SC(IEN,42))
|
---|
| 52 | . S:IEN42 @QROOT@("Patient","ListSource","w:"_IEN42_":")=""
|
---|
| 53 | Q
|
---|
| 54 | WCFDIV(DIVLST) ;Get wards/clinics for division
|
---|
| 55 | N XXI,XXJ,NNN,CDTR
|
---|
| 56 | S (XXI,NNN)=0,CDTR=""
|
---|
| 57 | F S XXI=$O(DIVLST(XXI)) Q:'XXI D
|
---|
| 58 | . S CDTR=$P(DIVLST(XXI),":",2,3)
|
---|
| 59 | . S XXJ=0
|
---|
| 60 | . F S XXJ=$O(^SC(XXJ)) Q:'XXJ D
|
---|
| 61 | . . I $P(^SC(XXJ,0),U,4)=+DIVLST(XXI) D ADDTO(XXJ,CDTR)
|
---|
| 62 | Q
|
---|
| 63 | DODIV ; find Wards/Clinics for divisions
|
---|
| 64 | N XI,XJ,NN,WCLST,DIVLST,DIVPTR
|
---|
| 65 | S (XI,XJ,DIVLST)="",(NN,DIVPTR)=0
|
---|
| 66 | F S XI=$O(@QROOT@("Patient","ListSource",XI)) Q:XI="" I $E(XI)="d" D
|
---|
| 67 | . S NN=NN+1,DIVLST(NN)=$P(XI,":",2,4)
|
---|
| 68 | . K @QROOT@("Patient","ListSource",XI)
|
---|
| 69 | Q:$D(DIVLST)=1
|
---|
| 70 | S XI=""
|
---|
| 71 | F S XJ=$O(@QROOT@("Patient","ListSource",XJ)) Q:XJ="" I "cw"[$E(XJ) D
|
---|
| 72 | . S DIVPTR=$P($G(^SC($P(XJ,":",2),0)),U,4) Q:'DIVPTR
|
---|
| 73 | . F S XI=$O(DIVLST(XI)) Q:'XI D
|
---|
| 74 | . . I DIVPTR=+DIVLST(XI) K @QROOT@("Patient","ListSource",XJ)
|
---|
| 75 | D WCFDIV(.DIVLST)
|
---|
| 76 | Q
|
---|
| 77 | CLEAR(OK) ; Clear/Cancel the query
|
---|
| 78 | K ^TMP("ORRHCQ",$J),^TMP("ORRHCQD",$J) ;LW UNCOMMENT
|
---|
| 79 | K ^TMP("ORRHCQB",$J),^TMP("ORRHCQS",$J) ;LW UNCOMMENT
|
---|
| 80 | S OK=1
|
---|
| 81 | Q
|
---|
| 82 | NXTITER(X) ; Return the iterator for the next patient
|
---|
| 83 | ; ITER=Subscript;DFN;Item#
|
---|
| 84 | N SUB,ITM,DFNITM
|
---|
| 85 | S SUB=$P(X,";",1),ITM=$P(X,";",3)
|
---|
| 86 | F D Q:+DFNITM Q:SUB="" ; loop until DFN or no subscripts
|
---|
| 87 | . S DFNITM=$$NXTDFN(SUB,ITM)
|
---|
| 88 | . Q:+DFNITM
|
---|
| 89 | . S SUB=$O(^TMP("ORRHCQ",$J,"QRY","Patient","ListSource",SUB))
|
---|
| 90 | . Q:SUB=""
|
---|
| 91 | . D SETPTS(SUB)
|
---|
| 92 | . S ITM=0
|
---|
| 93 | Q:+DFNITM=0 ""
|
---|
| 94 | Q SUB_";"_DFNITM
|
---|
| 95 | ;
|
---|
| 96 | NXTDFN(SUB,ITM) ; Return the next patient^item within a subscript
|
---|
| 97 | Q:SUB="" 0
|
---|
| 98 | N DFN S DFN=""
|
---|
| 99 | I $E(SUB)="r" D
|
---|
| 100 | . N RC,ITR
|
---|
| 101 | . M ITR=^TMP("ORRHCQ",$J,"PTLST",SUB,"ITR")
|
---|
| 102 | . S RC=$$NEXTPAT^RORAPI01(.ITR)
|
---|
| 103 | . M ^TMP("ORRHCQ",$J,"PTLST",SUB,"ITR")=ITR
|
---|
| 104 | . S DFN=$P(RC,U),ITM=0
|
---|
| 105 | E D
|
---|
| 106 | . S ITM=$O(^TMP("ORRHCQ",$J,"PTLST",SUB,+ITM))
|
---|
| 107 | . I ITM S DFN=+^TMP("ORRHCQ",$J,"PTLST",SUB,ITM)
|
---|
| 108 | Q DFN_";"_ITM
|
---|
| 109 | ;
|
---|
| 110 | SETPTS(SUB) ; Set up to iterate through a patient list
|
---|
| 111 | N LST
|
---|
| 112 | I $E(SUB)="c" D CLINPTS^ORQRY01(.LST,$P(SUB,":",2),$P(SUB,":",3),$P(SUB,":",4)) M:$D(@LST)>1 ^TMP("ORRHCQ",$J,"PTLST",SUB)=@LST Q
|
---|
| 113 | I $E(SUB)="w" D BYWARD^ORWPT(.LST,$P(SUB,":",2))
|
---|
| 114 | I $E(SUB)="t" D TEAMPTS^ORQPTQ1(.LST,$P(SUB,":",2))
|
---|
| 115 | I $E(SUB)="s" D SPECPTS^ORQPTQ2(.LST,$P(SUB,":",2))
|
---|
| 116 | I $E(SUB)="p" D PROVPTS^ORQPTQ2(.LST,$P(SUB,":",2))
|
---|
| 117 | I $D(LST)>1 M ^TMP("ORRHCQ",$J,"PTLST",SUB)=LST Q
|
---|
| 118 | ;
|
---|
| 119 | N ITR
|
---|
| 120 | I ($E(SUB)="r"),'($$PATITER^RORAPI01(.ITR,$P(SUB,":",2),$P(SUB,":",3))) D
|
---|
| 121 | . M ^TMP("ORRHCQ",$J,"PTLST",SUB,"ITR")=ITR
|
---|
| 122 | Q
|
---|
| 123 | QRYITR(VAL,ORRITR) ; Do query for the current iterator
|
---|
| 124 | ; VAL=PtSearched^RecordsFound^Iterator
|
---|
| 125 | S VAL=$$PTSCRN($P(ORRITR,";",2))
|
---|
| 126 | I VAL S $P(VAL,U,2)=$$QRYPT($P(ORRITR,";",2))
|
---|
| 127 | S $P(VAL,U,3)=$$NXTITER(ORRITR)
|
---|
| 128 | Q
|
---|
| 129 | ;
|
---|
| 130 | PTSCRN(PATID) ; Return 1 if should continue with this patient
|
---|
| 131 | Q:$D(^TMP("ORRHCQ",$J,"DFN",PATID)) 0
|
---|
| 132 | N PRILST,LOCLST,DATRNG,CONT
|
---|
| 133 | M PRILST=^TMP("ORRHCQ",$J,"QRY","Patient","Primary")
|
---|
| 134 | M LOCLST=^TMP("ORRHCQ",$J,"QRY","Patient","Location")
|
---|
| 135 | S DATRNG=$O(^TMP("ORRHCQ",$J,"QRY","Patient","DateRange",0)),CONT=1
|
---|
| 136 | ;
|
---|
| 137 | ; check if pt has primary provider in the list
|
---|
| 138 | I $D(PRILST)>1 D
|
---|
| 139 | . N FND,IPP S FND=0,IPP=0
|
---|
| 140 | . F S IPP=$O(PRILST(IPP)) Q:'IPP S FND=$$PP^ORQRY(PATID,IPP) Q:FND
|
---|
| 141 | . I 'FND S CONT=0
|
---|
| 142 | Q:CONT=0 0
|
---|
| 143 | ;
|
---|
| 144 | ; check if pt has visit at during date range at optional location
|
---|
| 145 | I $L(DATRNG) D
|
---|
| 146 | . S:$D(LOCLST) CONT=$$ACT^ORQRY(PATID,$P(DATRNG,":"),$P(DATRNG,":",2),.LOCLST)
|
---|
| 147 | . S:'$D(LOCLST) CONT=$$ACT^ORQRY(PATID,$P(DATRNG,":"),$P(DATRNG,":",2))
|
---|
| 148 | I CONT S ^TMP("ORRHCQ",$J,"DFN",PATID)=""
|
---|
| 149 | Q CONT
|
---|
| 150 | ;
|
---|
| 151 | QRYPT(PATID) ; Search for records and return the number found
|
---|
| 152 | N QRY,ROOT,CNT
|
---|
| 153 | K ^TMP("ORRHCQP",$J)
|
---|
| 154 | S ROOT="^TMP(""ORRHCQP"",$J)"
|
---|
| 155 | M QRY=^TMP("ORRHCQ",$J,"QRY")
|
---|
| 156 | D BYPT^ORQRY(ROOT,PATID,.QRY)
|
---|
| 157 | S CNT=$G(^TMP("ORRHCQP",$J,0,"Documents"))+$G(^("Orders"))+$G(^("Visits"))+$G(^("Consults"))
|
---|
| 158 | S ^TMP("ORRHCQ",$J,"TOT")=^TMP("ORRHCQ",$J,"TOT")+CNT
|
---|
| 159 | M ^TMP("ORRHCQD",$J)=^TMP("ORRHCQP",$J)
|
---|
| 160 | K ^TMP("ORRHCQP",$J)
|
---|
| 161 | Q CNT
|
---|
| 162 | SORTBY(SEQ,FNM,FWD) ; Sort by a particular field
|
---|
| 163 | N ID,KEY
|
---|
| 164 | K ^TMP("ORRHCQB",$J),^TMP("ORRHCQS",$J)
|
---|
| 165 | S SEQ=0 I 'FWD S SEQ=^TMP("ORRHCQ",$J,"TOT")+1
|
---|
| 166 | S ID=0 F S ID=$O(^TMP("ORRHCQD",$J,ID)) Q:ID="" D
|
---|
| 167 | . S KEY=$E($G(^TMP("ORRHCQD",$J,ID,FNM),"~~~~~~~~~~~~~~~~"),1,64)
|
---|
| 168 | . S KEY=$TR(KEY,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
---|
| 169 | . S:KEY="" KEY=" "
|
---|
| 170 | . S ^TMP("ORRHCQB",$J,KEY,ID)=""
|
---|
| 171 | S KEY="" F S KEY=$O(^TMP("ORRHCQB",$J,KEY)) Q:KEY="" D
|
---|
| 172 | . S ID="" F S ID=$O(^TMP("ORRHCQB",$J,KEY,ID)) Q:ID="" D
|
---|
| 173 | . . S:FWD SEQ=SEQ+1 S:'FWD SEQ=SEQ-1
|
---|
| 174 | . . S ^TMP("ORRHCQS",$J,SEQ)=ID
|
---|
| 175 | Q
|
---|
| 176 | SUBDTA(LST,FIRST,LAST) ; Return name-value pairs for subset of query data
|
---|
| 177 | N SEQ,COL,ID,ICOL,ILST S ILST=0
|
---|
| 178 | M COL=^TMP("ORRHCQ",$J,"COL")
|
---|
| 179 | F SEQ=FIRST:1:LAST D
|
---|
| 180 | . Q:'$D(^TMP("ORRHCQS",$J,SEQ))
|
---|
| 181 | . S ID=^TMP("ORRHCQS",$J,SEQ)
|
---|
| 182 | . S ILST=ILST+1,LST(ILST)="RowItemID="_ID
|
---|
| 183 | . S ICOL=0 F S ICOL=$O(COL(ICOL)) Q:'ICOL D
|
---|
| 184 | . . S ILST=ILST+1
|
---|
| 185 | . . S LST(ILST)=COL(ICOL)_"="_$G(^TMP("ORRHCQD",$J,ID,COL(ICOL)))
|
---|
| 186 | Q
|
---|
| 187 | DETAIL(REF,ID) ; Return results of order identified by ID
|
---|
| 188 | K ^TMP("ORXPND",$J)
|
---|
| 189 | N ORESULTS,ORVP,LCNT,ORID S ORESULTS=1,LCNT=0
|
---|
| 190 | I ID[":" S ID=$P(ID,":",2) ;strip off prefix
|
---|
| 191 | S ORVP=$P(^OR(100,+ID,0),U,2),ORID=ID
|
---|
| 192 | D ORDERS^ORCXPND1 S ID=ORID
|
---|
| 193 | D ORDERS^ORCXPND2
|
---|
| 194 | K ^TMP("ORXPND",$J,"VIDEO")
|
---|
| 195 | S REF=$NA(^TMP("ORXPND",$J))
|
---|
| 196 | Q
|
---|
| 197 | PTINFO(VAL,ID) ; Return patient info given an order, consult, or note
|
---|
| 198 | N DFN,X,X0,X1,X101
|
---|
| 199 | S VAL="",DFN=0,X=$P(ID,":")
|
---|
| 200 | I X="ORD"!(X="CST") S DFN=+$P(^OR(100,+$P(ID,":",2),0),U,2)
|
---|
| 201 | I X="DOC" S DFN=+$P(^TIU(8925,+$P(ID,":",2),0),U,2)
|
---|
| 202 | ;I X="VST" visits too?
|
---|
| 203 | Q:'DFN
|
---|
| 204 | S X0=^DPT(DFN,0),X1=$G(^(.1)),X101=$G(^(.101))
|
---|
| 205 | S VAL=$P(X0,U)_U_$P(X0,U,9)_U_X1_" "_X101
|
---|
| 206 | Q
|
---|
| 207 | RNGFM(ORY,RNG) ;Return FM date range string
|
---|
| 208 | Q:'$L(RNG)
|
---|
| 209 | S ORY=$$RNG2FM^ORRHCU(RNG)
|
---|
| 210 | Q
|
---|