Produced by Araxis Merge on 6/9/2017 3:51:25 PM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | Fri Jun 9 19:51:25 2017 UTC | ||
| 2 | eHealth_Exch (eHealth Exchange Enhancements) Build 3 docs & code_May_2017.zip\VAP_CIF_CODE0502.zip\VAP_CIF_CODE0502\VAP_CIF_CODE0502\nvap-web\src\main\java\gov\va\nvap\web\consent\audit\dao | AuditedConsentDAO.java | Fri Apr 21 20:03:30 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 1 | 606 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | package go v.va.nvap. web.consen t.audit.da o; | |||||
| 2 | ||||||
| 3 | import gov .va.nvap.c ommon.vali dation.Ass ert; | |||||
| 4 | import gov .va.nvap.c ommon.vali dation.Nul lChecker; | |||||
| 5 | import gov .va.nvap.w eb.consent .audit.Aud itedConsen tSummary; | |||||
| 6 | import jav a.io.IOExc eption; | |||||
| 7 | import jav a.io.Strin gReader; | |||||
| 8 | import jav a.security .InvalidPa rameterExc eption; | |||||
| 9 | import jav a.util.Arr ays; | |||||
| 10 | import jav a.util.Dat e; | |||||
| 11 | import jav a.util.Has hMap; | |||||
| 12 | import jav a.util.Lis t; | |||||
| 13 | import jav a.util.Loc ale; | |||||
| 14 | import jav a.util.Map ; | |||||
| 15 | import jav ax.persist ence.Entit yManager; | |||||
| 16 | import jav ax.persist ence.Persi stenceCont ext; | |||||
| 17 | import jav ax.persist ence.Query ; | |||||
| 18 | import jav ax.persist ence.Tempo ralType; | |||||
| 19 | import org .hibernate .CacheMode ; | |||||
| 20 | import org .hibernate .FlushMode ; | |||||
| 21 | ||||||
| 22 | /** | |||||
| 23 | * DAO for getting t he events from the C ONSENT_AUD IT table. | |||||
| 24 | * | |||||
| 25 | * @author Asha Amri traj | |||||
| 26 | * edited by Stephen Miller | |||||
| 27 | * edited by Irakli Kakushadze | |||||
| 28 | */ | |||||
| 29 | public cla ss Audited ConsentDAO { | |||||
| 30 | ||||||
| 31 | /* * | |||||
| 32 | * Read buff er size. | |||||
| 33 | * / | |||||
| 34 | pr ivate stat ic final i nt READ_BU FFER_SIZE = 4096; | |||||
| 35 | ||||||
| 36 | /* * | |||||
| 37 | * Entity Ma nager inst ance. | |||||
| 38 | * / | |||||
| 39 | @P ersistence Context | |||||
| 40 | pr ivate Enti tyManager em; | |||||
| 41 | ||||||
| 42 | pr ivate void appendGro upByClause (final Str ingBuffer buffer, fi nal String str) { | |||||
| 43 | this .appendGro upByClause (buffer, s tr, " Grou p By ", " , "); | |||||
| 44 | } | |||||
| 45 | ||||||
| 46 | pr ivate void appendGro upByClause (final Str ingBuffer buffer, | |||||
| 47 | final String str , final St ring empty , final St ring notEm pty) { | |||||
| 48 | if ( buffer.len gth() > 0) { | |||||
| 49 | buffer .append(no tEmpty); | |||||
| 50 | } el se { | |||||
| 51 | buffer .append(em pty); | |||||
| 52 | } | |||||
| 53 | buff er.append( str); | |||||
| 54 | } | |||||
| 55 | ||||||
| 56 | pr ivate void appendWhe reClause(f inal Strin gBuffer bu ffer, fina l String s tr) { | |||||
| 57 | this .appendWhe reClause(b uffer, str , " WHERE ", " AND " ); | |||||
| 58 | } | |||||
| 59 | ||||||
| 60 | pr ivate void appendWhe reClause(f inal Strin gBuffer bu ffer, fina l String s tr, | |||||
| 61 | final String emp ty, final String not Empty) { | |||||
| 62 | if ( buffer.len gth() > 0) { | |||||
| 63 | buffer .append(no tEmpty); | |||||
| 64 | } el se { | |||||
| 65 | buffer .append(em pty); | |||||
| 66 | } | |||||
| 67 | buff er.append( str); | |||||
| 68 | } | |||||
| 69 | ||||||
| 70 | privat e void han dleCommonF ilters(fin al Date st artDate, f inal Date endDate, | |||||
| 71 | fi nal String consentTy pe, final int patien tTypes, | |||||
| 72 | fi nal String Buffer whe reClause, final Hash Map<String , Object> setParams) { | |||||
| 73 | // Start dat e | |||||
| 74 | if (startDat e != null) { | |||||
| 75 | this.app endWhereCl ause(where Clause, "a .timeOfEve nt >= :sta rtDate"); | |||||
| 76 | setParam s.put("sta rtDate", s tartDate); | |||||
| 77 | } | |||||
| 78 | ||||||
| 79 | // End date | |||||
| 80 | if (endDate != null) { | |||||
| 81 | this.app endWhereCl ause(where Clause, "a .timeOfEve nt <= :end Date"); | |||||
| 82 | setParam s.put("end Date", end Date); | |||||
| 83 | } | |||||
| 84 | ||||||
| 85 | // Consent t ype | |||||
| 86 | if (!NullChe cker.isNul lOrEmpty(c onsentType )) { | |||||
| 87 | if (cons entType.eq ualsIgnore Case("allA uthorizati ons")) { | |||||
| 88 | this .appendWhe reClause(w hereClause , "a.actio nType = :a ctionType" ); | |||||
| 89 | setP arams.put( "actionTyp e", "OPT-I N"); | |||||
| 90 | } else i f (consent Type.equal sIgnoreCas e("allRevo cations")) { | |||||
| 91 | this .appendWhe reClause(w hereClause , "a.actio nType = :a ctionType" ); | |||||
| 92 | setP arams.put( "actionTyp e", "OPT-O UT"); | |||||
| 93 | } else i f (consent Type.equal sIgnoreCas e("NwHINAu thorizatio ns")) { | |||||
| 94 | this .appendWhe reClause(w hereClause , "a.conse ntType = : consentTyp e"); | |||||
| 95 | setP arams.put( "consentTy pe", "NwHI N Authoriz ation"); | |||||
| 96 | } else i f (consent Type.equal sIgnoreCas e("SSAAuth orizations ")) { | |||||
| 97 | this .appendWhe reClause(w hereClause , "a.conse ntType = : consentTyp e"); | |||||
| 98 | setP arams.put( "consentTy pe", "SSA Authorizat ion"); | |||||
| 99 | } else i f (consent Type.equal sIgnoreCas e("NwHINRe vocations" )) { | |||||
| 100 | this .appendWhe reClause(w hereClause , "a.conse ntType = : consentTyp e"); | |||||
| 101 | setP arams.put( "consentTy pe", "NwHI N Revocati on"); | |||||
| 102 | } else i f (consent Type.equal sIgnoreCas e("SSARevo cations")) { | |||||
| 103 | this .appendWhe reClause(w hereClause , "a.conse ntType = : consentTyp e"); | |||||
| 104 | setP arams.put( "consentTy pe", "SSA Revocation "); | |||||
| 105 | } else i f (consent Type.equal sIgnoreCas e("NwHINRe strictions ")) { | |||||
| 106 | this .appendWhe reClause(w hereClause , "a.conse ntType = : consentTyp e"); | |||||
| 107 | setP arams.put( "consentTy pe", "NwHI N Organiza tion Restr iction Aut horization "); | |||||
| 108 | } else i f (consent Type.equal sIgnoreCas e("NwHINRe strictionR evocations ")) { | |||||
| 109 | this .appendWhe reClause(w hereClause , "a.conse ntType = : consentTyp e"); | |||||
| 110 | setP arams.put( "consentTy pe", "NwHI N Organiza tion Restr iction Rev ocation"); | |||||
| 111 | } else { | |||||
| 112 | //TODO t hrow an er ror | |||||
| 113 | //pr ogram did not receiv e expected value | |||||
| 114 | } | |||||
| 115 | } | |||||
| 116 | ||||||
| 117 | // Patient t ypes | |||||
| 118 | if (patientT ypes == 1) { | |||||
| 119 | this.app endWhereCl ause(where Clause, "a .isTestPat ient = 0") ; | |||||
| 120 | } | |||||
| 121 | if (patientT ypes == 2) { | |||||
| 122 | this.app endWhereCl ause(where Clause, "a .isTestPat ient = 1") ; | |||||
| 123 | } | |||||
| 124 | } | |||||
| 125 | ||||||
| 126 | /** | |||||
| 127 | * Get the event s from the database table by b uilding an d calling a query. U se this me thod for c omplex que ries of de tails. It accepts | |||||
| 128 | * all parameter s and buil ds the whe re clause based on v alues supp lied. | |||||
| 129 | * | |||||
| 130 | * @pa ram req Re quest obje ct contain ing search field val ues | |||||
| 131 | * @re turn List of objects | |||||
| 132 | */ | |||||
| 133 | public final Lis t<Object> getEvents( DetailRequ est req) { | |||||
| 134 | ||||||
| 135 | fi nal String Buffer whe reClause = new Strin gBuffer(); | |||||
| 136 | fi nal String Buffer sor tClause = new String Buffer(); | |||||
| 137 | fi nal HashMa p<String, Object> se tParams = new HashMa p<String, Object>(); | |||||
| 138 | ||||||
| 139 | ha ndleCommon Filters(re q.startDat e, req.end Date, req. consentTyp e, req.pat ientTypes, whereClau se, setPar ams); | |||||
| 140 | ||||||
| 141 | if (!NullChe cker.isNul lOrEmpty(r eq.patient Ssn)) { | |||||
| 142 | this.app endWhereCl ause(where Clause, "a .patientSs n = :patie ntSsn"); | |||||
| 143 | setParam s.put("pat ientSsn", req.patien tSsn); | |||||
| 144 | } | |||||
| 145 | ||||||
| 146 | if (!NullChe cker.isNul lOrEmpty(r eq.patient FirstName) ) { | |||||
| 147 | this.app endWhereCl ause(where Clause, "u pper(a.pat ientGivenN ame) = :fi rstName"); | |||||
| 148 | setParam s.put("fir stName", r eq.patient FirstName. toUpperCas e()); | |||||
| 149 | } | |||||
| 150 | ||||||
| 151 | if (!NullChe cker.isNul lOrEmpty(r eq.patient LastName)) { | |||||
| 152 | this.app endWhereCl ause(where Clause, "u pper(a.pat ientLastNa me) = :las tName"); | |||||
| 153 | setParam s.put("las tName", re q.patientL astName.to UpperCase( )); | |||||
| 154 | } | |||||
| 155 | ||||||
| 156 | if ("ALL".eq uals(req.s tationNumb ers)) { | |||||
| 157 | if (req. includeUnk nownVisn) { | |||||
| 158 | // U ser chose to include everythin g, so ther e's no nee d for the WHERE clau se | |||||
| 159 | } else { | |||||
| 160 | // U ser chose to see eve rything BU T unknown VISN | |||||
| 161 | this .appendWhe reClause(w hereClause , "a.visnN umber IS N OT NULL"); | |||||
| 162 | } | |||||
| 163 | } else if (N ullChecker .isNullOrE mpty(req.s tationNumb ers)) { | |||||
| 164 | if (req. includeUnk nownVisn) { | |||||
| 165 | // U ser chose to see unk nown VISN only | |||||
| 166 | this .appendWhe reClause(w hereClause , "a.visnN umber IS N ULL"); | |||||
| 167 | } else { | |||||
| 168 | // T his should never be the case | |||||
| 169 | } | |||||
| 170 | } else { | |||||
| 171 | if (req. includeUnk nownVisn) { | |||||
| 172 | // U ser chose to see sel ected stat ion number s AND unkn own VISNs | |||||
| 173 | this .appendWhe reClause(w hereClause , "(a.faci lity IN (: stationNum bers) OR a .visnNumbe r IS NULL) "); | |||||
| 174 | } else { | |||||
| 175 | // U ser chose to see sel ected stat ions only | |||||
| 176 | this .appendWhe reClause(w hereClause , "a.facil ity IN (:s tationNumb ers)"); | |||||
| 177 | } | |||||
| 178 | List<Str ing> items = Arrays. asList(req .stationNu mbers.spli t(",")); | |||||
| 179 | setParam s.put("sta tionNumber s", items) ; | |||||
| 180 | } | |||||
| 181 | ||||||
| 182 | if (!NullChe cker.isNul lOrEmpty(r eq.inactiv ationReaso n)) { | |||||
| 183 | this.app endWhereCl ause(where Clause, "a .optoutRea son = :opt outReason" ); | |||||
| 184 | setParam s.put("opt outReason" , req.inac tivationRe ason); | |||||
| 185 | } | |||||
| 186 | ||||||
| 187 | if (!NullChe cker.isNul lOrEmpty(r eq.userId) ) { | |||||
| 188 | if (req. userId.toU pperCase(L ocale.ENGL ISH).equal s("EMPLOYE E")) { | |||||
| 189 | this .appendWhe reClause(w hereClause , "lower(a .userId) n ot like 'e benefits'" ); | |||||
| 190 | this .appendWhe reClause(w hereClause , "lower(a .userId) n ot like 'a utomatic s ervice'"); | |||||
| 191 | this .appendWhe reClause(w hereClause , "lower(a .userId) n ot like 's ystem'"); | |||||
| 192 | } else { | |||||
| 193 | this .appendWhe reClause(w hereClause , "lower(a .userId) l ike lower( :userId)") ; | |||||
| 194 | setP arams.put( "userId", "%" + req. userId + " %"); | |||||
| 195 | } | |||||
| 196 | } | |||||
| 197 | ||||||
| 198 | St ring valid atedSortFi eld = vali dateSortFi eld(req.so rtField); | |||||
| 199 | St ring valid atedSortDi rection = validateSo rtDirectio n(req.sort Direction) ; | |||||
| 200 | if (!NullChe cker.isNul lOrEmpty(v alidatedSo rtField) & & !NullChe cker.isNul lOrEmpty(v alidatedSo rtDirectio n)) { | |||||
| 201 | if ("tim eOfEvent". equals(val idatedSort Field)) { | |||||
| 202 | sort Clause.app end("a.tim eOfEvent " ); | |||||
| 203 | sort Clause.app end(valida tedSortDir ection); | |||||
| 204 | } else i f ("create dDate".equ als(valida tedSortFie ld)) { | |||||
| 205 | sort Clause.app end("a.cre atedDate " ); | |||||
| 206 | sort Clause.app end(valida tedSortDir ection); | |||||
| 207 | } else i f ("visnNa me".equals (validated SortField) ) { | |||||
| 208 | sort Clause.app end("a.vis nNumber ") ; | |||||
| 209 | sort Clause.app end(valida tedSortDir ection); | |||||
| 210 | sort Clause.app end(", a.t imeOfEvent DESC"); | |||||
| 211 | } else { | |||||
| 212 | sort Clause.app end("upper (a."); | |||||
| 213 | sort Clause.app end(valida tedSortFie ld); | |||||
| 214 | sort Clause.app end(") "); | |||||
| 215 | sort Clause.app end(valida tedSortDir ection); | |||||
| 216 | sort Clause.app end(", a.t imeOfEvent DESC"); | |||||
| 217 | } | |||||
| 218 | } else { | |||||
| 219 | sortClau se.append( "a.timeOfE vent DESC" ); //defau lt sort | |||||
| 220 | } | |||||
| 221 | ||||||
| 222 | fi nal Query query = th is.makeAud itedConsen tQuery(whe reClause, sortClause ); | |||||
| 223 | ||||||
| 224 | fo r (final M ap.Entry<S tring, Obj ect> entry : setPara ms.entrySe t()) { | |||||
| 225 | String p Key = entr y.getKey() ; | |||||
| 226 | Object p Value = en try.getVal ue(); | |||||
| 227 | if (pKey .equalsIgn oreCase("s tartDate") || pKey.e qualsIgnor eCase("end Date")) { | |||||
| 228 | quer y.setParam eter(pKey, (Date) pV alue, Temp oralType.T IMESTAMP); | |||||
| 229 | } else { | |||||
| 230 | quer y.setParam eter(pKey, pValue); | |||||
| 231 | } | |||||
| 232 | } | |||||
| 233 | ||||||
| 234 | fi nal Query updatedQue ry = this. setAdditio nalQueryPa ramaters(q uery); | |||||
| 235 | re turn this. getResults (updatedQu ery, req.c urrentPage , req.page Size); | |||||
| 236 | } | |||||
| 237 | ||||||
| 238 | public final lon g getEvent sCount(Det ailRequest req) { | |||||
| 239 | ||||||
| 240 | fi nal String Buffer whe reClause = new Strin gBuffer(); | |||||
| 241 | fi nal HashMa p<String, Object> se tParams = new HashMa p<>(); | |||||
| 242 | ||||||
| 243 | ha ndleCommon Filters(re q.startDat e, req.end Date, req. consentTyp e, req.pat ientTypes, whereClau se, setPar ams); | |||||
| 244 | ||||||
| 245 | if (!NullChe cker.isNul lOrEmpty(r eq.patient Ssn)) { | |||||
| 246 | this.app endWhereCl ause(where Clause, "a .patientSs n = :patie ntSsn"); | |||||
| 247 | setParam s.put("pat ientSsn", req.patien tSsn); | |||||
| 248 | } | |||||
| 249 | ||||||
| 250 | if (!NullChe cker.isNul lOrEmpty(r eq.patient FirstName) ) { | |||||
| 251 | this.app endWhereCl ause(where Clause, "u pper(a.pat ientGivenN ame) = :fi rstName"); | |||||
| 252 | setParam s.put("fir stName", r eq.patient FirstName. toUpperCas e()); | |||||
| 253 | } | |||||
| 254 | ||||||
| 255 | if (!NullChe cker.isNul lOrEmpty(r eq.patient LastName)) { | |||||
| 256 | this.app endWhereCl ause(where Clause, "u pper(a.pat ientLastNa me) = :las tName"); | |||||
| 257 | setParam s.put("las tName", re q.patientL astName.to UpperCase( )); | |||||
| 258 | } | |||||
| 259 | ||||||
| 260 | if ("ALL".eq uals(req.s tationNumb ers)) { | |||||
| 261 | if (req. includeUnk nownVisn) { | |||||
| 262 | // U ser chose to include everythin g, so ther e's no nee d for the WHERE clau se | |||||
| 263 | } else { | |||||
| 264 | // U ser chose to see eve rything BU T unknown VISN | |||||
| 265 | this .appendWhe reClause(w hereClause , "a.visnN umber IS N OT NULL"); | |||||
| 266 | } | |||||
| 267 | } else if (N ullChecker .isNullOrE mpty(req.s tationNumb ers)) { | |||||
| 268 | if (req. includeUnk nownVisn) { | |||||
| 269 | // U ser chose to see unk nown VISN only | |||||
| 270 | this .appendWhe reClause(w hereClause , "a.visnN umber IS N ULL"); | |||||
| 271 | } else { | |||||
| 272 | // T his should never be the case | |||||
| 273 | } | |||||
| 274 | } else { | |||||
| 275 | if (req. includeUnk nownVisn) { | |||||
| 276 | // U ser chose to see sel ected stat ion number s AND unkn own VISNs | |||||
| 277 | this .appendWhe reClause(w hereClause , "(a.faci lity IN (: stationNum bers) OR a .visnNumbe r IS NULL) "); | |||||
| 278 | } else { | |||||
| 279 | // U ser chose to see sel ected stat ions only | |||||
| 280 | this .appendWhe reClause(w hereClause , "a.facil ity IN (:s tationNumb ers)"); | |||||
| 281 | } | |||||
| 282 | List<Str ing> items = Arrays. asList(req .stationNu mbers.spli t(",")); | |||||
| 283 | setParam s.put("sta tionNumber s", items) ; | |||||
| 284 | } | |||||
| 285 | ||||||
| 286 | if (!NullChe cker.isNul lOrEmpty(r eq.inactiv ationReaso n)) { | |||||
| 287 | this.app endWhereCl ause(where Clause, "a .optoutRea son = :opt outReason" ); | |||||
| 288 | setParam s.put("opt outReason" , req.inac tivationRe ason); | |||||
| 289 | } | |||||
| 290 | ||||||
| 291 | if (!NullChe cker.isNul lOrEmpty(r eq.userId) ) { | |||||
| 292 | if (req. userId.toL owerCase() .equals("e mployee")) { | |||||
| 293 | this .appendWhe reClause(w hereClause , "lower(a .userId) n ot like 'e benefits'" ); | |||||
| 294 | this .appendWhe reClause(w hereClause , "lower(a .userId) n ot like 'a utomatic s ervice'"); | |||||
| 295 | this .appendWhe reClause(w hereClause , "lower(a .userId) n ot like 's ystem'"); | |||||
| 296 | } else i f (req.con sentType.e qualsIgnor eCase("SSA Authorizat ions") && req.userId .toLowerCa se().equal s("automat ed")) { | |||||
| 297 | this .appendWhe reClause(w hereClause , "lower(a .userId) l ike '%ssa. gov%'"); | |||||
| 298 | } else { | |||||
| 299 | this .appendWhe reClause(w hereClause , "lower(a .userId) l ike lower( :userId)") ; | |||||
| 300 | setP arams.put( "userId", "%" + req. userId + " %"); | |||||
| 301 | } | |||||
| 302 | } | |||||
| 303 | ||||||
| 304 | fi nal Query query = th is.makeAud itedConsen tCountQuer y(whereCla use); | |||||
| 305 | ||||||
| 306 | fo r (final M ap.Entry<S tring, Obj ect> entry : setPara ms.entrySe t()) { | |||||
| 307 | String p Key = entr y.getKey() ; | |||||
| 308 | Object p Value = en try.getVal ue(); | |||||
| 309 | if (pKey .equalsIgn oreCase("s tartDate") || pKey.e qualsIgnor eCase("end Date")) { | |||||
| 310 | quer y.setParam eter(pKey, (Date) pV alue, Temp oralType.T IMESTAMP); | |||||
| 311 | } else { | |||||
| 312 | quer y.setParam eter(pKey, pValue); | |||||
| 313 | } | |||||
| 314 | } | |||||
| 315 | ||||||
| 316 | fi nal Query updatedQue ry = this. setAdditio nalQueryPa ramaters(q uery); | |||||
| 317 | ||||||
| 318 | re turn (long ) updatedQ uery.getSi ngleResult (); | |||||
| 319 | } | |||||
| 320 | ||||||
| 321 | /* * | |||||
| 322 | * Get the e vent summa ries from the databa se table b y building and calli ng a | |||||
| 323 | * query. Us e this met hod for co mplex quer ies result ing in a s ummary. It | |||||
| 324 | * accepts a ll paramet ers and bu ilds the w here and o rder by cl auses by t he | |||||
| 325 | * values su pplied. | |||||
| 326 | * / | |||||
| 327 | pu blic final List<Audi tedConsent Summary> g etEventsSu mmary(fina l SummaryR equest req ) { | |||||
| 328 | ||||||
| 329 | fi nal String Buffer whe reClause = new Strin gBuffer(); | |||||
| 330 | fi nal String Buffer gro upByClause = new Str ingBuffer( ); | |||||
| 331 | fi nal HashMa p<String, Object> se tParams = new HashMa p<String, Object>(); | |||||
| 332 | fi nal String facilityN ameColumn = req.aggr egateAtFac ilityLevel ? "parent FacilityNa me" : "fac ilityName" ; | |||||
| 333 | fi nal String stationNu mberColumn = req.agg regateAtFa cilityLeve l ? "paren tStationNu mber" : "f acility"; | |||||
| 334 | ||||||
| 335 | // Construct WHERE cla use | |||||
| 336 | ha ndleCommon Filters(re q.startDat e, req.end Date, req. consentTyp e, req.pat ientTypes, whereClau se, setPar ams); | |||||
| 337 | ||||||
| 338 | if ("ALL".eq uals(req.s tationNumb ers)) { | |||||
| 339 | if (req. includeUnk nownVisn) { | |||||
| 340 | // U ser chose to include everythin g, so ther e's no nee d for the WHERE clau se | |||||
| 341 | } else { | |||||
| 342 | // U ser chose to see eve rything BU T unknown VISN | |||||
| 343 | this .appendWhe reClause(w hereClause , "a.visnN umber IS N OT NULL"); | |||||
| 344 | } | |||||
| 345 | } else if (N ullChecker .isNullOrE mpty(req.s tationNumb ers)) { | |||||
| 346 | if (req. includeUnk nownVisn) { | |||||
| 347 | // U ser chose to see unk nown VISN only | |||||
| 348 | this .appendWhe reClause(w hereClause , "a.visnN umber IS N ULL"); | |||||
| 349 | } else { | |||||
| 350 | // T his should never be the case | |||||
| 351 | } | |||||
| 352 | } else { | |||||
| 353 | if (req. includeUnk nownVisn) { | |||||
| 354 | // U ser chose to see sel ected stat ion number s AND unkn own VISNs | |||||
| 355 | this .appendWhe reClause(w hereClause , "(a." + stationNum berColumn + " IN (:s tationNumb ers) OR a. visnNumber IS NULL)" ); | |||||
| 356 | } else { | |||||
| 357 | // U ser chose to see sel ected stat ions only | |||||
| 358 | this .appendWhe reClause(w hereClause , "a." + s tationNumb erColumn + " IN (:st ationNumbe rs)"); | |||||
| 359 | } | |||||
| 360 | List<Str ing> items = Arrays. asList(req .stationNu mbers.spli t(",")); | |||||
| 361 | setParam s.put("sta tionNumber s", items) ; | |||||
| 362 | } | |||||
| 363 | ||||||
| 364 | if (!NullChe cker.isNul lOrEmpty(r eq.userId) ) { | |||||
| 365 | if (req. userId.toU pperCase(L ocale.ENGL ISH).equal s("EMPLOYE E")) { | |||||
| 366 | this .appendWhe reClause(w hereClause , "lower(a .userId) n ot like 'e benefits'" ); | |||||
| 367 | this .appendWhe reClause(w hereClause , "lower(a .userId) n ot like 'a utomatic s ervice'"); | |||||
| 368 | this .appendWhe reClause(w hereClause , "lower(a .userId) n ot like 's ystem'"); | |||||
| 369 | } else { | |||||
| 370 | this .appendWhe reClause(w hereClause , "lower(a .userId) l ike lower( :userId)") ; | |||||
| 371 | setP arams.put( "userId", "%" + req. userId + " %"); | |||||
| 372 | } | |||||
| 373 | } | |||||
| 374 | ||||||
| 375 | // Construct GROUP BY clause | |||||
| 376 | th is.appendG roupByClau se(groupBy Clause, "a ." + facil ityNameCol umn + ", a .consentTy pe"); | |||||
| 377 | ||||||
| 378 | // Construct ORDER BY clause | |||||
| 379 | St ring order By = null; | |||||
| 380 | fi nal Query query; | |||||
| 381 | St ring valid atedSortFi eld = vali dateSortFi eldForSumm ary(req.so rtField); | |||||
| 382 | St ring valid atedSortDi rection = validateSo rtDirectio n(req.sort Direction) ; | |||||
| 383 | if (!NullChe cker.isNul lOrEmpty(v alidatedSo rtField) & & !NullChe cker.isNul lOrEmpty(v alidatedSo rtDirectio n)) { | |||||
| 384 | if (vali datedSortF ield.equal sIgnoreCas e("facilit yName")) { | |||||
| 385 | orde rBy = "LOW ER(a." + f acilityNam eColumn + ") " + val idatedSort Direction + ", a.con sentType A SC"; | |||||
| 386 | } else i f (validat edSortFiel d.equalsIg noreCase(" consentTyp e")) { | |||||
| 387 | orde rBy = "a.c onsentType " + valid atedSortDi rection + ", LOWER(a ." + facil ityNameCol umn + ") A SC"; | |||||
| 388 | } else { | |||||
| 389 | orde rBy = "COU NT(*) " + validatedS ortDirecti on + ", LO WER(a." + facilityNa meColumn + ") ASC"; | |||||
| 390 | } | |||||
| 391 | } else { | |||||
| 392 | orderBy = "LOWER(a ." + facil ityNameCol umn + ") A SC, a.cons entType AS C"; | |||||
| 393 | } | |||||
| 394 | ||||||
| 395 | // Create th e query | |||||
| 396 | fi nal String queryStri ng = | |||||
| 397 | new Stri ng(" SELEC T NEW gov. va.nvap.we b.consent. audit.Audi tedConsent Summary " + | |||||
| 398 | " (a.con sentType, a." + faci lityNameCo lumn + ", COUNT(a.co nsentType) ) " + | |||||
| 399 | " FROM A uditedCons entEx a " + | |||||
| 400 | whereCla use.toStri ng() + | |||||
| 401 | groupByC lause.toSt ring() + | |||||
| 402 | " ORDER BY " + ord erBy.toStr ing()); | |||||
| 403 | ||||||
| 404 | qu ery = this .em.create Query(quer yString); | |||||
| 405 | ||||||
| 406 | // Set query parameter s | |||||
| 407 | fo r (final M ap.Entry<S tring, Obj ect> entry : setPara ms.entrySe t()) { | |||||
| 408 | Stri ng pKey = entry.getK ey(); | |||||
| 409 | Obje ct pValue = entry.ge tValue(); | |||||
| 410 | if ( pKey.equal sIgnoreCas e("startDa te") || pK ey.equalsI gnoreCase( "endDate") ) { | |||||
| 411 | query. setParamet er(pKey, ( Date)pValu e, Tempora lType.TIME STAMP); | |||||
| 412 | } el se { | |||||
| 413 | query. setParamet er(pKey, p Value); | |||||
| 414 | } | |||||
| 415 | } | |||||
| 416 | ||||||
| 417 | // Set addit ional Hibe rnate para meters | |||||
| 418 | fi nal Query updatedQue ry = this. setAdditio nalQueryPa ramaters(q uery); | |||||
| 419 | As sert.asser tNotEmpty( updatedQue ry, "Query cannot be empty"); | |||||
| 420 | ||||||
| 421 | // R eturn the result set | |||||
| 422 | retu rn updated Query.getR esultList( ); | |||||
| 423 | } | |||||
| 424 | ||||||
| 425 | /* * | |||||
| 426 | * Get the m essage con tent from the table. We do not want hibe rnate to p ull | |||||
| 427 | * all the r ecords wit h the clob content. So have an independe nt query t o | |||||
| 428 | * just pull messages from the c lob. | |||||
| 429 | * / | |||||
| 430 | pu blic final String ge tMessageCo ntent(fina l Long con sentAuditI d) { | |||||
| 431 | Asse rt.assertN otEmpty(co nsentAudit Id, | |||||
| 432 | "Audited event id cannot be empty"); | |||||
| 433 | // Q uery to ge t the indi vidual clo b content | |||||
| 434 | fina l Query qu ery = this .em | |||||
| 435 | .createQ uery("SELE CT ca.deta il from Co nsentAudit ca where ca.consent AuditId = :consentAu ditId"); | |||||
| 436 | quer y.setParam eter("cons entAuditId ", consent AuditId); | |||||
| 437 | ||||||
| 438 | fina l Query up datedQuery = this.se tAdditiona lQueryPara maters(que ry); | |||||
| 439 | //if (Clob.clas s.isInstan ce(Clob.cl ass)) { | |||||
| 440 | //fina l Clob clo b = (Clob) updatedQu ery.getSin gleResult( ); | |||||
| 441 | try { | |||||
| 442 | final String myd etail = (S tring) upd atedQuery. getSingleR esult(); | |||||
| 443 | if (Nu llChecker. isNotEmpty (consentAu ditId) && !NullCheck er.isNullO rEmpty(myd etail)) { | |||||
| 444 | final St ringReader reader = new String Reader(myd etail); | |||||
| 445 | if (Null Checker.is Empty(read er)) { | |||||
| 446 | return nul l; | |||||
| 447 | } | |||||
| 448 | final St ringBuffer sb = new StringBuff er(); | |||||
| 449 | final ch ar[] charb uf = new c har[Audite dConsentDA O.READ_BUF FER_SIZE]; | |||||
| 450 | for (int i = reade r.read(cha rbuf); i > 0; i = re ader | |||||
| 451 | .r ead(charbu f)) { | |||||
| 452 | sb.append( charbuf, 0 , i); | |||||
| 453 | } | |||||
| 454 | // Retur n the CDA R2 XML | |||||
| 455 | return s b.toString (); | |||||
| 456 | } | |||||
| 457 | } ca tch (final IOExcepti on e) { | |||||
| 458 | throw new Runtim eException (e); | |||||
| 459 | } | |||||
| 460 | //} | |||||
| 461 | retu rn null; | |||||
| 462 | } | |||||
| 463 | ||||||
| 464 | /* * | |||||
| 465 | * Get the r esults fro m the data base table based on the patien t id. | |||||
| 466 | * / | |||||
| 467 | pu blic List< Object> ge tResultsBy PatientId( String pat ientId) { | |||||
| 468 | Query qu ery = this .em.create Query("SEL ECT a FROM AuditedCo nsentEx a WHERE a.pa tientId = :patientId ORDER BY a.createdD ate DESC") ; | |||||
| 469 | query.se tParameter ("patientI d", patien tId); | |||||
| 470 | ||||||
| 471 | return q uery.getRe sultList() ; | |||||
| 472 | } | |||||
| 473 | ||||||
| 474 | /* * | |||||
| 475 | * Get the r esults fro m the data base table . | |||||
| 476 | * / | |||||
| 477 | pu blic final List<Obje ct> getRes ults(final Query que ry, | |||||
| 478 | final int curren tPage, fin al int pag eSize) { | |||||
| 479 | Asse rt.assertN otEmpty(qu ery, "Quer y cannot b e empty"); | |||||
| 480 | List <Object> a uditedEven tEntityLis t; | |||||
| 481 | if ( pageSize > 0) { | |||||
| 482 | audite dEventEnti tyList = q uery | |||||
| 483 | .setFirstR esult(curr entPage * pageSize) | |||||
| 484 | .setMaxRes ults(pageS ize).getRe sultList() ; | |||||
| 485 | } el se { | |||||
| 486 | audite dEventEnti tyList = q uery.getRe sultList() ; | |||||
| 487 | } | |||||
| 488 | retu rn audited EventEntit yList; | |||||
| 489 | } | |||||
| 490 | ||||||
| 491 | pr ivate Quer y makeAudi tedConsent Query(fina l StringBu ffer where Clause, | |||||
| 492 | final StringBuff er sortCla use) { | |||||
| 493 | if ( NullChecke r.isNullOr Empty(sort Clause)) { | |||||
| 494 | return this.em.c reateQuery ("SELECT a FROM Audi tedConsent Ex a " | |||||
| 495 | + whereCla use.toStri ng()); | |||||
| 496 | } el se { | |||||
| 497 | return this.em.c reateQuery ("SELECT a FROM Audi tedConsent Ex a " | |||||
| 498 | + whereCla use.toStri ng() + " O RDER BY " + sortClau se.toStrin g()); | |||||
| 499 | } | |||||
| 500 | } | |||||
| 501 | ||||||
| 502 | /** | |||||
| 503 | * Cou nts the en tries for the where clause par ameters | |||||
| 504 | * @pa ram whereC lause | |||||
| 505 | * @re turn | |||||
| 506 | */ | |||||
| 507 | privat e Query ma keAuditedC onsentCoun tQuery(fin al StringB uffer wher eClause){ | |||||
| 508 | re turn this. em.createQ uery("SELE CT COUNT(* ) FROM Aud itedConsen tEx a " + whereClaus e.toString ()); | |||||
| 509 | } | |||||
| 510 | ||||||
| 511 | /* * | |||||
| 512 | * Optimize the query parameters for fetch ing the re sult. | |||||
| 513 | * / | |||||
| 514 | pr ivate Quer y setAddit ionalQuery Paramaters (final Que ry theQuer y) { | |||||
| 515 | theQ uery.setHi nt("org.hi bernate.ca cheable", Boolean.TR UE) | |||||
| 516 | .setHint ("org.hibe rnate.fetc hSize", In teger.valu eOf(50)) | |||||
| 517 | .setHint ("org.hibe rnate.cach eMode", Ca cheMode.GE T) | |||||
| 518 | .setHint ("org.hibe rnate.read Only", Boo lean.TRUE) | |||||
| 519 | .setHint ("org.hibe rnate.flus hMode", Fl ushMode.MA NUAL); | |||||
| 520 | retu rn theQuer y; | |||||
| 521 | } | |||||
| 522 | ||||||
| 523 | /* * | |||||
| 524 | * Set the e ntity mana ger (Injec ted by Spr ing). | |||||
| 525 | * / | |||||
| 526 | pu blic void setEntityM anager(fin al EntityM anager em) { | |||||
| 527 | this .em = em; | |||||
| 528 | } | |||||
| 529 | ||||||
| 530 | pr ivate Stri ng validat eSortField (final Str ing sortFi eld) { | |||||
| 531 | if (NullChec ker.isNull OrEmpty(so rtField)) return ""; | |||||
| 532 | if (sortFiel d.equalsIg noreCase(" actionType ")) return "actionTy pe"; // No t used in UI? | |||||
| 533 | if (sortFiel d.equalsIg noreCase(" consentAud itId")) re turn "cons entAuditId "; // Not used in UI ? | |||||
| 534 | if (sortFiel d.equalsIg noreCase(" consentTyp e")) retur n "consent Type"; | |||||
| 535 | if (sortFiel d.equalsIg noreCase(" createdDat e")) retur n "created Date"; | |||||
| 536 | if (sortFiel d.equalsIg noreCase(" facility") ) return " facility"; | |||||
| 537 | if (sortFiel d.equalsIg noreCase(" facilityNa me")) retu rn "facili tyName"; | |||||
| 538 | if (sortFiel d.equalsIg noreCase(" optoutReas on")) retu rn "optout Reason"; | |||||
| 539 | if (sortFiel d.equalsIg noreCase(" patientGiv enName")) return "pa tientGiven Name"; | |||||
| 540 | if (sortFiel d.equalsIg noreCase(" patientId" )) return "patientId "; // Not used in UI ? | |||||
| 541 | if (sortFiel d.equalsIg noreCase(" patientLas tName")) r eturn "pat ientLastNa me"; | |||||
| 542 | if (sortFiel d.equalsIg noreCase(" patientMid dleName")) return "p atientMidd leName"; / / Not used in UI? | |||||
| 543 | if (sortFiel d.equalsIg noreCase(" patientSsn ")) return "patientS sn"; | |||||
| 544 | if (sortFiel d.equalsIg noreCase(" pouValue") ) return " pouValue"; | |||||
| 545 | if (sortFiel d.equalsIg noreCase(" timeOfEven t")) retur n "timeOfE vent"; | |||||
| 546 | if (sortFiel d.equalsIg noreCase(" userId")) return "us erId"; | |||||
| 547 | if (sortFiel d.equalsIg noreCase(" visnName") ) return " visnName"; | |||||
| 548 | ||||||
| 549 | thro w new Inva lidParamet erExceptio n("Wrong c olumn head er to sort on: " + s ortField); | |||||
| 550 | } | |||||
| 551 | ||||||
| 552 | /* * | |||||
| 553 | * Checks va lidity of columns to sort on f or Summary report | |||||
| 554 | * / | |||||
| 555 | privat e String v alidateSor tFieldForS ummary(fin al String sortField) { | |||||
| 556 | if (NullChec ker.isNull OrEmpty(so rtField)) return ""; | |||||
| 557 | if (sortFiel d.equalsIg noreCase(" consentTyp e")) retur n "consent Type"; | |||||
| 558 | if (sortFiel d.equalsIg noreCase(" facilityNa me")) retu rn "facili tyName"; | |||||
| 559 | if (sortFiel d.equalsIg noreCase(" total")) r eturn "tot al"; | |||||
| 560 | ||||||
| 561 | th row new In validParam eterExcept ion("Wrong column he ader to so rt on in s ummary rep ort: " + s ortField); | |||||
| 562 | } | |||||
| 563 | ||||||
| 564 | pr ivate Stri ng validat eSortDirec tion(final String so rtDirectio n) { | |||||
| 565 | if ("ASC".eq ualsIgnore Case(sortD irection)) return "A SC"; | |||||
| 566 | if ("DESC".e qualsIgnor eCase(sort Direction) ) return " DESC"; | |||||
| 567 | retu rn ""; | |||||
| 568 | } | |||||
| 569 | ||||||
| 570 | // Inn er classes | |||||
| 571 | ||||||
| 572 | public class Det ailRequest { | |||||
| 573 | ||||||
| 574 | pu blic Strin g consentT ype; | |||||
| 575 | pu blic int c urrentPage ; | |||||
| 576 | pu blic Date endDate; | |||||
| 577 | pu blic Strin g inactiva tionReason ; | |||||
| 578 | pu blic boole an include UnknownVis n; | |||||
| 579 | pu blic int p ageSize; | |||||
| 580 | pu blic Strin g patientF irstName; | |||||
| 581 | pu blic Strin g patientL astName; | |||||
| 582 | pu blic Strin g patientS sn; | |||||
| 583 | pu blic int p atientType s; | |||||
| 584 | pu blic Strin g sortFiel d; | |||||
| 585 | pu blic Strin g sortDire ction; | |||||
| 586 | pu blic Date startDate; | |||||
| 587 | pu blic Strin g stationN umbers; | |||||
| 588 | pu blic Strin g userId; | |||||
| 589 | ||||||
| 590 | } | |||||
| 591 | ||||||
| 592 | public class Sum maryReques t { | |||||
| 593 | ||||||
| 594 | pu blic boole an aggrega teAtFacili tyLevel; | |||||
| 595 | pu blic Strin g consentT ype; | |||||
| 596 | pu blic Date endDate; | |||||
| 597 | pu blic boole an include UnknownVis n; | |||||
| 598 | pu blic int p atientType s; | |||||
| 599 | pu blic Strin g sortFiel d; | |||||
| 600 | pu blic Strin g sortDire ction; | |||||
| 601 | pu blic Date startDate; | |||||
| 602 | pu blic Strin g stationN umbers; | |||||
| 603 | pu blic Strin g userId; | |||||
| 604 | ||||||
| 605 | } | |||||
| 606 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.