Produced by Araxis Merge on 11/14/2017 6:57:21 AM Central Standard 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 | cbs.zip\cbs\cbs\src\main\java\gov\va\cpss\service | CbsService.java | Thu Nov 9 14:19:42 2017 UTC |
| 2 | cbs.zip\cbs\cbs\src\main\java\gov\va\cpss\service | CbsService.java | Tue Nov 14 12:27:08 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 1634 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| 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.cpss. service; | |
| 2 | ||
| 3 | import jav a.sql.Time stamp; | |
| 4 | import jav a.util.Arr ayList; | |
| 5 | import jav a.util.Cal endar; | |
| 6 | import jav a.util.Col lections; | |
| 7 | import jav a.util.Com parator; | |
| 8 | import jav a.util.Dat e; | |
| 9 | import jav a.util.Lis t; | |
| 10 | import jav a.util.Map ; | |
| 11 | import jav a.util.Map .Entry; | |
| 12 | import jav a.util.str eam.Collec tors; | |
| 13 | ||
| 14 | import org .apache.lo g4j.Logger ; | |
| 15 | import org .springfra mework.ste reotype.Se rvice; | |
| 16 | ||
| 17 | import gov .va.cpss.c obol.Money ; | |
| 18 | import gov .va.cpss.d ao.CBSAcco untDAO; | |
| 19 | import gov .va.cpss.d ao.CBSSite PatientDAO ; | |
| 20 | import gov .va.cpss.d ao.CBSSite StmtDAO; | |
| 21 | import gov .va.cpss.d ao.CBSSite TransDAO; | |
| 22 | import gov .va.cpss.d ao.CBSStmt DAO; | |
| 23 | import gov .va.cpss.d ao.Process StatusDAO; | |
| 24 | import gov .va.cpss.m odel.Boole anChar; | |
| 25 | import gov .va.cpss.m odel.cbs.C BSSitePati ent; | |
| 26 | import gov .va.cpss.m odel.cbs.C BSSiteStmt ; | |
| 27 | import gov .va.cpss.m odel.cbs.C BSSiteTran s; | |
| 28 | import gov .va.cpss.m odel.cbs.C BSStmt; | |
| 29 | import gov .va.cpss.m odel.Proce ssStatus; | |
| 30 | import gov .va.cpss.m odel.fps.P SDetails; | |
| 31 | import gov .va.cpss.m odel.fps.P SPatient; | |
| 32 | ||
| 33 | /** | |
| 34 | * Service class for handling activities relating to consoli dating a p atient | |
| 35 | * stateme nt. | |
| 36 | * | |
| 37 | * @author DN S BROWNL | |
| 38 | */ | |
| 39 | @Service | |
| 40 | public cla ss CbsServ ice { | |
| 41 | ||
| 42 | pr ivate stat ic final L ogger logg er = Logge r.getLogge r(CbsServi ce.class.g etCanonica lName()); | |
| 43 | ||
| 44 | pr ivate stat ic final i nt MAX_COB OL_FIELD_L ENGTH = 9; | |
| 45 | ||
| 46 | pr ivate bool ean lateSt atementMes sage; | |
| 47 | ||
| 48 | pr ivate Proc essStatusD AO process StatusDAO; | |
| 49 | ||
| 50 | pr ivate CBSA ccountDAO cbsAccount DAO; | |
| 51 | ||
| 52 | pr ivate CBSS tmtDAO cbs StmtDAO; | |
| 53 | ||
| 54 | pr ivate CBSS iteStmtDAO cbsSiteSt mtDAO; | |
| 55 | ||
| 56 | pr ivate CBSS itePatient DAO cbsSit ePatientDA O; | |
| 57 | ||
| 58 | pr ivate CBSS iteTransDA O cbsSiteT ransDAO; | |
| 59 | ||
| 60 | pu blic CbsSe rvice() { | |
| 61 | } | |
| 62 | ||
| 63 | pu blic boole an getLate StatementM essage() { | |
| 64 | retu rn lateSta tementMess age; | |
| 65 | } | |
| 66 | ||
| 67 | pu blic void setLateSta tementMess age(boolea n lateStat ementMessa ge) { | |
| 68 | this .lateState mentMessag e = lateSt atementMes sage; | |
| 69 | } | |
| 70 | ||
| 71 | pu blic Proce ssStatusDA O getProce ssStatusDA O() { | |
| 72 | retu rn process StatusDAO; | |
| 73 | } | |
| 74 | ||
| 75 | pu blic void setProcess StatusDAO( ProcessSta tusDAO pro cessStatus DAO) { | |
| 76 | this .processSt atusDAO = processSta tusDAO; | |
| 77 | } | |
| 78 | ||
| 79 | pu blic CBSAc countDAO g etCbsAccou ntDAO() { | |
| 80 | retu rn cbsAcco untDAO; | |
| 81 | } | |
| 82 | ||
| 83 | pu blic void setCbsAcco untDAO(CBS AccountDAO cbsAccoun tDAO) { | |
| 84 | this .cbsAccoun tDAO = cbs AccountDAO ; | |
| 85 | } | |
| 86 | ||
| 87 | pu blic CBSSt mtDAO getC bsStmtDAO( ) { | |
| 88 | retu rn cbsStmt DAO; | |
| 89 | } | |
| 90 | ||
| 91 | pu blic void setCbsStmt DAO(CBSStm tDAO cbsSt mtDAO) { | |
| 92 | this .cbsStmtDA O = cbsStm tDAO; | |
| 93 | } | |
| 94 | ||
| 95 | pu blic CBSSi tePatientD AO getCbsS itePatient DAO() { | |
| 96 | retu rn cbsSite PatientDAO ; | |
| 97 | } | |
| 98 | ||
| 99 | pu blic void setCbsSite PatientDAO (CBSSitePa tientDAO c bsSitePati entDAO) { | |
| 100 | this .cbsSitePa tientDAO = cbsSitePa tientDAO; | |
| 101 | } | |
| 102 | ||
| 103 | pu blic CBSSi teStmtDAO getCbsSite StmtDAO() { | |
| 104 | retu rn cbsSite StmtDAO; | |
| 105 | } | |
| 106 | ||
| 107 | pu blic void setCbsSite StmtDAO(CB SSiteStmtD AO cbsSite StmtDAO) { | |
| 108 | this .cbsSiteSt mtDAO = cb sSiteStmtD AO; | |
| 109 | } | |
| 110 | ||
| 111 | pu blic CBSSi teTransDAO getCbsSit eTransDAO( ) { | |
| 112 | retu rn cbsSite TransDAO; | |
| 113 | } | |
| 114 | ||
| 115 | pu blic void setCbsSite TransDAO(C BSSiteTran sDAO cbsSi teTransDAO ) { | |
| 116 | this .cbsSiteTr ansDAO = c bsSiteTran sDAO; | |
| 117 | } | |
| 118 | ||
| 119 | /* * | |
| 120 | * Build a c onsolidate d statemen t for the CBS Accoun t to list of PSPatie nt | |
| 121 | * records m ap. | |
| 122 | * | |
| 123 | * @param ba tchRunId | |
| 124 | * The batc h run ID. | |
| 125 | * @param pa tientMap | |
| 126 | * The map of records to consol idate. | |
| 127 | * @return A consolida ted statem ent. | |
| 128 | * / | |
| 129 | pu blic CBSSt mt buildSt atementFor PatientMap (final lon g batchRun Id, Entry< Long, List <PSPatient >> patient Map) | |
| 130 | throws RuntimeEx ception { | |
| 131 | ||
| 132 | // F irst, crea te an init ial statem ent for th e records in the map . | |
| 133 | CBSS tmt statem ent = crea teInitialS tatement(b atchRunId, patientMa p.getKey() ); | |
| 134 | ||
| 135 | // T hen proces s the list of PSPati ent record s. | |
| 136 | if ( processPat ientList(s tatement, patientMap .getValue( )) > 0) { | |
| 137 | ||
| 138 | // Now check if this shoul d be a lat e statemen t or if a new | |
| 139 | // sta tement alr eady exist s for this patient. | |
| 140 | // If an unrecov erable err or occurs false will be return ed. | |
| 141 | if (!c heckForExi stingState ment(state ment)) { | |
| 142 | ||
| 143 | // An un recoverabl e error ha s occurred indicatin g the data base | |
| 144 | // is co rrupted. | |
| 145 | throw ne w RuntimeE xception(" Unrecovera ble data e rror check ing for ex isting sta tement"); | |
| 146 | } | |
| 147 | ||
| 148 | } el se { | |
| 149 | ||
| 150 | // If unexpected data erro r occurs ( patient li st is empt y or no | |
| 151 | // pat ients proc essed) the n log an e rror messa ge and | |
| 152 | // ski p the stat ement. | |
| 153 | logger .error("No patients processed for CBS Ac count: " + patientMa p.getKey() ); | |
| 154 | ||
| 155 | // Ret urn null w hich will skip state ment. | |
| 156 | statem ent = null ; | |
| 157 | } | |
| 158 | ||
| 159 | // S et accntNu mDisp afte r site pat ients have been proc essed and | |
| 160 | // s tatement m erged with existing statement | |
| 161 | setA cntNumDisp (statement ); | |
| 162 | ||
| 163 | retu rn stateme nt; | |
| 164 | } | |
| 165 | ||
| 166 | /* * | |
| 167 | * Check and handle ex isting sta tement. | |
| 168 | * | |
| 169 | * @param st atement | |
| 170 | * The cons olidated s tatement. | |
| 171 | * @return F lag indica ting if su ccessfully checked o r if an un recoverabl e | |
| 172 | * e rror occur red. | |
| 173 | * / | |
| 174 | pu blic boole an checkFo rExistingS tatement(C BSStmt sta tement) { | |
| 175 | ||
| 176 | bool ean succes sful = fal se; | |
| 177 | ||
| 178 | // C heck if th is should be a late statement (a stateme nt for thi s month | |
| 179 | // a lready) or if a new statement | |
| 180 | // a lready exi sts that n eeds to be merged. | |
| 181 | fina l Date sta tementDate = stateme nt.getSite StmtL().ge t(0).getSt atementDat e(); | |
| 182 | ||
| 183 | // U nrecoverab le error i f statemen t date hap pens to be null. | |
| 184 | if ( statementD ate != nul l) { | |
| 185 | ||
| 186 | Intege r statusId = cbsStmt DAO.getSta tusIdForEx istingStat ementByAcc ountAndMon th(stateme nt.getAcco untId(), | |
| 187 | statementD ate); | |
| 188 | ||
| 189 | // If an existin g statemen t exists ( !null) the n process accordingl y. | |
| 190 | if (st atusId != null) { | |
| 191 | ||
| 192 | // Handl e existing statement different ly dependi ng on its | |
| 193 | // statu s. | |
| 194 | switch ( processSta tusDAO.get StatusType (statusId) .getStatus ()) { | |
| 195 | ||
| 196 | case NEW : | |
| 197 | // Query f or existin g statemen t. | |
| 198 | CBSStmt ex istingStat ement = ge tExistingS tatementFo rAccount(s tatement.g etAccountI d(), state mentDate); | |
| 199 | ||
| 200 | combineWit hExistingS tatement(s tatement, existingSt atement); | |
| 201 | successful = true; | |
| 202 | break; | |
| 203 | case ACK : | |
| 204 | case ERR OR: | |
| 205 | case SEN T: | |
| 206 | setAsLateS tatement(s tatement); | |
| 207 | successful = true; | |
| 208 | break; | |
| 209 | case INI TIAL: | |
| 210 | case REP LACED: | |
| 211 | case UND EFINED: | |
| 212 | default: | |
| 213 | logger.err or("Existi ng stateme nt detecte d of inval id status at time of query"); | |
| 214 | break; | |
| 215 | } | |
| 216 | } else { | |
| 217 | ||
| 218 | // There is no exi sting stat ement foun d. | |
| 219 | successf ul = true; | |
| 220 | } | |
| 221 | } el se { | |
| 222 | ||
| 223 | logger .error("Un able to ch eck for ex isting sta tement bec ause date check was unexpected ly null"); | |
| 224 | } | |
| 225 | ||
| 226 | retu rn success ful; | |
| 227 | } | |
| 228 | ||
| 229 | /* * | |
| 230 | * Create a consolidat ed stateme nt object for the sp ecified ac count numb er. | |
| 231 | * | |
| 232 | * @param ac countNumbe r | |
| 233 | * The acco unt number to associ ate with t he consoli dated | |
| 234 | * statemen t. | |
| 235 | * @return T he initial ized conso lidated st atement. | |
| 236 | * / | |
| 237 | pr ivate CBSS tmt create InitialSta tement(fin al long ba tchRunId, final long accountNu mber) { | |
| 238 | ||
| 239 | // C reate a st atement fo r the acco unt. | |
| 240 | CBSS tmt statem ent = new CBSStmt(ba tchRunId, accountNum ber, | |
| 241 | processS tatusDAO.g etStatusFr omEnum(Pro cessStatus .Status.IN ITIAL)); | |
| 242 | ||
| 243 | init ializeStat ement(stat ement); | |
| 244 | ||
| 245 | retu rn stateme nt; | |
| 246 | } | |
| 247 | ||
| 248 | /* * | |
| 249 | * Combine t he consoli dated stat ement with the speci fied exist ing statem ent. | |
| 250 | * | |
| 251 | * @param st atement | |
| 252 | * The cons olidated s tatement. | |
| 253 | * @param ex istingStat ement | |
| 254 | * The exis ting conso lidated st atement. | |
| 255 | * / | |
| 256 | pu blic void combineWit hExistingS tatement(C BSStmt sta tement, fi nal CBSStm t existing Statement) { | |
| 257 | ||
| 258 | // S ave the re places id. | |
| 259 | stat ement.setR eplacedStm tId(existi ngStatemen t.getId()) ; | |
| 260 | ||
| 261 | // I nitialize the runnin g totals w ith the va lues alrea dy in the | |
| 262 | // s tatement. | |
| 263 | doub le amountD ue = state ment.getAm ountDue(). getDouble( ); | |
| 264 | doub le previou sBalance = statement .getPrevBa lance().ge tDouble(); | |
| 265 | doub le totalCh arges = st atement.ge tTotalChar ges().getD ouble(); | |
| 266 | doub le totalCr edits = st atement.ge tTotalCred its().getD ouble(); | |
| 267 | doub le newBala nce = stat ement.getN ewBalance( ).getDoubl e(); | |
| 268 | ||
| 269 | // A dd the exi sting stat ement valu es. | |
| 270 | amou ntDue += e xistingSta tement.get AmountDue( ).getDoubl e(); | |
| 271 | prev iousBalanc e += exist ingStateme nt.getPrev Balance(). getDouble( ); | |
| 272 | tota lCharges + = existing Statement. getTotalCh arges().ge tDouble(); | |
| 273 | tota lCredits + = existing Statement. getTotalCr edits().ge tDouble(); | |
| 274 | newB alance += existingSt atement.ge tNewBalanc e().getDou ble(); | |
| 275 | ||
| 276 | // S ave the va lues. | |
| 277 | setA mountDue(s tatement, amountDue) ; | |
| 278 | setP revBalance (statement , previous Balance); | |
| 279 | setT otalCharge s(statemen t, totalCh arges); | |
| 280 | setT otalCredit s(statemen t, totalCr edits); | |
| 281 | setN ewBalance( statement, newBalanc e); | |
| 282 | ||
| 283 | // A ppend the existing l ist of sit e statemen ts to the new statem ent. | |
| 284 | List <CBSSiteSt mt> siteSt atementL = statement .getSiteSt mtL(); | |
| 285 | site StatementL .addAll(ex istingStat ement.getS iteStmtL() ); | |
| 286 | setP rimarySite Flags(stat ement, sit eStatement L); | |
| 287 | stat ement.setS iteStmtL(s iteStateme ntL); | |
| 288 | ||
| 289 | // T ake the va lue of the existing statement late state ment messa ge. | |
| 290 | stat ement.setL ateStmtMsg (existingS tatement.g etLateStmt Msg()); | |
| 291 | } | |
| 292 | ||
| 293 | /* * | |
| 294 | * Set the l ate messag e in the s tatement. | |
| 295 | * | |
| 296 | * @param st atement | |
| 297 | * The stat ement that is late. | |
| 298 | * / | |
| 299 | pr ivate void setAsLate Statement( CBSStmt st atement) { | |
| 300 | stat ement.setL ateStmtMsg (lateState mentMessag e); | |
| 301 | } | |
| 302 | ||
| 303 | /* * | |
| 304 | * Initializ e a consol idated sta tement val ues. | |
| 305 | * | |
| 306 | * @param st atement | |
| 307 | * / | |
| 308 | pr ivate void initializ eStatement (CBSStmt s tatement) { | |
| 309 | ||
| 310 | fina l Timestam p currentT ime = new Timestamp( Calendar.g etInstance ().getTime ().getTime ()); | |
| 311 | ||
| 312 | stat ement.setS iteStmtL(n ew ArrayLi st<>()); | |
| 313 | ||
| 314 | setA mountDue(s tatement, 0); | |
| 315 | setP revBalance (statement , 0); | |
| 316 | setT otalCharge s(statemen t, 0); | |
| 317 | setT otalCredit s(statemen t, 0); | |
| 318 | setN ewBalance( statement, 0); | |
| 319 | ||
| 320 | stat ement.setC reatedDate (currentTi me); | |
| 321 | stat ement.setM odifiedDat e(currentT ime); | |
| 322 | ||
| 323 | stat ement.setL ateStmtMsg (false); | |
| 324 | } | |
| 325 | ||
| 326 | pu blic void setAmountD ue(CBSStmt statement , final do uble value ) { | |
| 327 | stat ement.setA mountDue(n ew Money(v alue, MAX_ COBOL_FIEL D_LENGTH)) ; | |
| 328 | } | |
| 329 | ||
| 330 | pu blic void setPrevBal ance(CBSSt mt stateme nt, final double val ue) { | |
| 331 | stat ement.setP revBalance (new Money (value, MA X_COBOL_FI ELD_LENGTH )); | |
| 332 | } | |
| 333 | ||
| 334 | pu blic void setTotalCh arges(CBSS tmt statem ent, final double va lue) { | |
| 335 | stat ement.setT otalCharge s(new Mone y(value, M AX_COBOL_F IELD_LENGT H)); | |
| 336 | } | |
| 337 | ||
| 338 | pu blic void setTotalCr edits(CBSS tmt statem ent, final double va lue) { | |
| 339 | stat ement.setT otalCredit s(new Mone y(value, M AX_COBOL_F IELD_LENGT H)); | |
| 340 | } | |
| 341 | ||
| 342 | pu blic void setNewBala nce(CBSStm t statemen t, final d ouble valu e) { | |
| 343 | stat ement.setN ewBalance( new Money( value, MAX _COBOL_FIE LD_LENGTH) ); | |
| 344 | } | |
| 345 | ||
| 346 | pu blic void setAcntNum Disp(CBSSt mt stateme nt) { | |
| 347 | stat ement.setA cntNumDisp (CBSStmt.c reateAcntN umDisp(sta tement)); | |
| 348 | } | |
| 349 | ||
| 350 | /* * | |
| 351 | * Identify the approp riate site statement s for prim ary patien t data and | |
| 352 | * primary p atient add ress. | |
| 353 | * | |
| 354 | * @param si teStatemen tL | |
| 355 | * The list of site s tatements for which to calcula te primary | |
| 356 | * flags. | |
| 357 | * / | |
| 358 | pu blic void setPrimary SiteFlags( CBSStmt st atement, L ist<CBSSit eStmt> sit eStatement L) { | |
| 359 | ||
| 360 | // I f there is only one site state ment then this is ea sy. | |
| 361 | if ( siteStatem entL.size( ) == 1) { | |
| 362 | ||
| 363 | siteSt atementL.g et(0).setI sPrimary(B ooleanChar .Y); | |
| 364 | siteSt atementL.g et(0).setI sPrimaryAd dress(Bool eanChar.Y) ; | |
| 365 | ||
| 366 | // Set the state ment dates to the da tes of the primary s ite | |
| 367 | // sta tement. | |
| 368 | setSta tementDate s(statemen t, siteSta tementL.ge t(0)); | |
| 369 | ||
| 370 | } el se { | |
| 371 | ||
| 372 | // If there are multiple s ite statem ents then it is more | |
| 373 | // com plicated. | |
| 374 | ||
| 375 | // Fir st, initia lize all t he sites t o not prim ary. | |
| 376 | // Whi le doing s o, count t he number of AR flag s. | |
| 377 | int ar FlagCount = 0; | |
| 378 | for (C BSSiteStmt siteState ment : sit eStatement L) { | |
| 379 | ||
| 380 | siteStat ement.setI sPrimary(B ooleanChar .N); | |
| 381 | siteStat ement.setI sPrimaryAd dress(Bool eanChar.N) ; | |
| 382 | ||
| 383 | // Count how many sites have the AR fl ag set. | |
| 384 | if (site Statement. getArAddre ssFlag().i sTrue()) { | |
| 385 | arFlagCoun t++; | |
| 386 | } | |
| 387 | } | |
| 388 | ||
| 389 | // Sor t statemen ts by most recent la stBillPrep Date to id entify | |
| 390 | // isP rimary | |
| 391 | Collec tions.sort (siteState mentL, new Comparato r<CBSSiteS tmt>() { | |
| 392 | public i nt compare (CBSSiteSt mt o1, CBS SiteStmt o 2) { | |
| 393 | if (o1.get LastBillPr epDate() = = null) { | |
| 394 | // If o1 nul l, then as sume older . | |
| 395 | re turn 1; | |
| 396 | } else if (o2.getLas tBillPrepD ate() == n ull) { | |
| 397 | // If o2 is then assum e o1 is ne wer. | |
| 398 | re turn -1; | |
| 399 | } else { | |
| 400 | // Desire mo st recent date, so c ompare o2 to o1. | |
| 401 | re turn o2.ge tLastBillP repDate(). compareTo( o1.getLast BillPrepDa te()); | |
| 402 | } | |
| 403 | } | |
| 404 | }); | |
| 405 | ||
| 406 | // The most rece nt will be sorted fi rst. | |
| 407 | // It will be us ed for Pat ient Detai ls. | |
| 408 | // Set the first in the co llection t o isPrimar y for Pati ent Detail s. | |
| 409 | siteSt atementL.g et(0).setI sPrimary(B ooleanChar .Y); | |
| 410 | ||
| 411 | // Set the state ment dates to the da tes of the primary s ite | |
| 412 | // sta tement. | |
| 413 | setSta tementDate s(statemen t, siteSta tementL.ge t(0)); | |
| 414 | ||
| 415 | // Use different logic to identify t he primary site stat ement to u se | |
| 416 | // for the Patie nt | |
| 417 | // Add ress | |
| 418 | ||
| 419 | if (ar FlagCount == 1) { | |
| 420 | ||
| 421 | // If ex actly one AR flag fo und then u se that si te stateme nt as | |
| 422 | // the P rimary Add ress. | |
| 423 | for (CBS SiteStmt s iteStateme nt : siteS tatementL) { | |
| 424 | if (siteSt atement.ge tArAddress Flag().isT rue()) { | |
| 425 | si teStatemen t.setIsPri maryAddres s(BooleanC har.Y); | |
| 426 | br eak; | |
| 427 | } | |
| 428 | } | |
| 429 | ||
| 430 | } else { | |
| 431 | ||
| 432 | // If th ere is mor e than one AR flag o r if there are no AR flags | |
| 433 | // then use the fi rst in the sorted co llection j ust like h ow | |
| 434 | // Patie nt | |
| 435 | // Detai ls is dete rmined. | |
| 436 | siteStat ementL.get (0).setIsP rimaryAddr ess(Boolea nChar.Y); | |
| 437 | } | |
| 438 | } | |
| 439 | } | |
| 440 | ||
| 441 | /* * | |
| 442 | * Set the s tatement d ates using the prima ry site st atement da te values. | |
| 443 | * | |
| 444 | * @param st atement | |
| 445 | * The stat ement to u pdate. | |
| 446 | * @param si teStatemen t | |
| 447 | * The site statement as refere nce. | |
| 448 | * / | |
| 449 | pr ivate void setStatem entDates(C BSStmt sta tement, fi nal CBSSit eStmt site Statement) { | |
| 450 | // S et the sta tement val ues to poi nt to the primary da tes. | |
| 451 | stat ement.setS tatementDa te(siteSta tement.get StatementD ate()); | |
| 452 | stat ement.setP rocessDate (siteState ment.getPr ocessDate( )); | |
| 453 | } | |
| 454 | ||
| 455 | /* * | |
| 456 | * Process t he list of raw PSPat ient recor ds and rol l processe d data int o | |
| 457 | * the conso lidated st atement. | |
| 458 | * | |
| 459 | * @param st atement | |
| 460 | * The cons olidated s tatement t o update. | |
| 461 | * @param ps PatientL | |
| 462 | * The list of PSPati ent record s. | |
| 463 | * @return N umber of p atients pr ocessed. | |
| 464 | * / | |
| 465 | pu blic int p rocessPati entList(CB SStmt stat ement, fin al List<PS Patient> p sPatientL) { | |
| 466 | ||
| 467 | int processedC ount = 0; | |
| 468 | ||
| 469 | if ( (psPatient L == null) || psPati entL.isEmp ty()) { | |
| 470 | ||
| 471 | // Une xpected er ror that s hould neve r happen. | |
| 472 | logger .error("Pa tient list was unexp ectedly em pty!"); | |
| 473 | ||
| 474 | } el se { | |
| 475 | ||
| 476 | // Get the site statement list. | |
| 477 | List<C BSSiteStmt > siteStat ementL = s tatement.g etSiteStmt L(); | |
| 478 | ||
| 479 | // Ini tialize th e running totals wit h the valu es already in the | |
| 480 | // sta tement. | |
| 481 | double amountDue = stateme nt.getAmou ntDue().ge tDouble(); | |
| 482 | double previousB alance = s tatement.g etPrevBala nce().getD ouble(); | |
| 483 | double totalChar ges = stat ement.getT otalCharge s().getDou ble(); | |
| 484 | double totalCred its = stat ement.getT otalCredit s().getDou ble(); | |
| 485 | double newBalanc e = statem ent.getNew Balance(). getDouble( ); | |
| 486 | ||
| 487 | for (P SPatient p sPatient : psPatient L) { | |
| 488 | logger.d ebug("Proc essing Pat ient: " + psPatient. getIcnNumb er()); | |
| 489 | ||
| 490 | // Creat e CBSSiteS tmt associ ated with the PSPati ent record . | |
| 491 | CBSSiteS tmt siteSt atement = getSiteSta tementForP atient(psP atient); | |
| 492 | ||
| 493 | // Calcu late Total s for Cons olidated S tatement | |
| 494 | amountDu e += siteS tatement.g etAmountDu e().getDou ble(); | |
| 495 | previous Balance += siteState ment.getPr evBalance( ).getDoubl e(); | |
| 496 | totalCha rges += si teStatemen t.getTotal Charges(). getDouble( ); | |
| 497 | totalCre dits += si teStatemen t.getTotal Credits(). getDouble( ); | |
| 498 | newBalan ce += site Statement. getNewBala nce().getD ouble(); | |
| 499 | ||
| 500 | // Appen d the site statement to the li st. | |
| 501 | siteStat ementL.add (siteState ment); | |
| 502 | ||
| 503 | // Incre ment the n umber of p atients pr ocessed. | |
| 504 | processe dCount++; | |
| 505 | } | |
| 506 | ||
| 507 | if (!s iteStateme ntL.isEmpt y()) { | |
| 508 | // Ident ify Primar y Site (Pa tient Deta ils) and P rimary Sit e | |
| 509 | // (Addr ess) | |
| 510 | setPrima rySiteFlag s(statemen t, siteSta tementL); | |
| 511 | ||
| 512 | // Set t he site st atement li st in the Consolidat ed Stateme nt | |
| 513 | statemen t.setSiteS tmtL(siteS tatementL) ; | |
| 514 | ||
| 515 | // Set t he calcula ted totals . | |
| 516 | setAmoun tDue(state ment, amou ntDue); | |
| 517 | setPrevB alance(sta tement, pr eviousBala nce); | |
| 518 | setTotal Charges(st atement, t otalCharge s); | |
| 519 | setTotal Credits(st atement, t otalCredit s); | |
| 520 | setNewBa lance(stat ement, new Balance); | |
| 521 | } | |
| 522 | } | |
| 523 | ||
| 524 | retu rn process edCount; | |
| 525 | } | |
| 526 | ||
| 527 | /* * | |
| 528 | * Build a s ite statem ent associ ated with the patien t record. | |
| 529 | * | |
| 530 | * @param ps Patient | |
| 531 | * The pati ent record . | |
| 532 | * @return A site stat ement asso ciated wit h the spec ified pati ent record . | |
| 533 | * / | |
| 534 | pr ivate CBSS iteStmt ge tSiteState mentForPat ient(final PSPatient psPatient ) { | |
| 535 | ||
| 536 | fina l Timestam p currentT ime = new Timestamp( Calendar.g etInstance ().getTime ().getTime ()); | |
| 537 | ||
| 538 | CBSS iteStmt si teStatemen t = new CB SSiteStmt( ); | |
| 539 | site Statement. setStation Num(psPati ent.getPsS ite().getF acilityNum ()); | |
| 540 | site Statement. setStation PhoneNum(p sPatient.g etPsSite() .getFacili tyPhoneNum ()); | |
| 541 | site Statement. setProcess Date(psPat ient.getPs Site().get ProcessDat e()); | |
| 542 | site Statement. setStateme ntDate(psP atient.get PsSite().g etStatemen tDate()); | |
| 543 | site Statement. setAmountD ue(psPatie nt.getAmou ntDue()); | |
| 544 | site Statement. setPrevBal ance(psPat ient.getPr evBalance( )); | |
| 545 | site Statement. setTotalCh arges(psPa tient.getT otalCharge s()); | |
| 546 | site Statement. setTotalCr edits(psPa tient.getT otalCredit s()); | |
| 547 | site Statement. setNewBala nce(psPati ent.getNew Balance()) ; | |
| 548 | site Statement. setSpecial Notes(psPa tient.getS pecialNote s()); | |
| 549 | site Statement. setNoParaC des(psPati ent.getRig htsObligat ionParagra phCodes()) ; | |
| 550 | site Statement. setLargeFo ntInd(psPa tient.getL argeFontIn d()); | |
| 551 | site Statement. setArAddre ssFlag(psP atient.get AddressFla g()); | |
| 552 | site Statement. setLastBil lPrepDate( psPatient. getLastBil lPrepDate( )); | |
| 553 | site Statement. setIsPrima ry(Boolean Char.N); | |
| 554 | site Statement. setIsPrima ryAddress( BooleanCha r.N); | |
| 555 | site Statement. setCreated Date(curre ntTime); | |
| 556 | site Statement. setModifie dDate(curr entTime); | |
| 557 | ||
| 558 | CBSS itePatient sitePatie nt = new C BSSitePati ent(); | |
| 559 | site Patient.se tIcn(psPat ient.getIc nNumber()) ; | |
| 560 | site Patient.se tDfn(psPat ient.getDf nNumber()) ; | |
| 561 | site Patient.se tOldAcntNu m(psPatien t.getPatie ntAccount( )); | |
| 562 | site Patient.se tFirstName (psPatient .getPatien tFirstName ()); | |
| 563 | site Patient.se tLastName( psPatient. getPatient LastName() ); | |
| 564 | site Patient.se tMiddleNam e(psPatien t.getPatie ntMiddleNa me()); | |
| 565 | site Patient.se tAddress1( psPatient. getAddress 1()); | |
| 566 | site Patient.se tAddress2( psPatient. getAddress 2()); | |
| 567 | site Patient.se tAddress3( psPatient. getAddress 3()); | |
| 568 | site Patient.se tCity(psPa tient.getC ity()); | |
| 569 | site Patient.se tState(psP atient.get State()); | |
| 570 | site Patient.se tZipCode(p sPatient.g etZipCode( )); | |
| 571 | site Patient.se tCountry(p sPatient.g etCountryN ame()); | |
| 572 | site Patient.se tCreatedDa te(current Time); | |
| 573 | site Patient.se tModifiedD ate(curren tTime); | |
| 574 | site Statement. setSitePat ient(siteP atient); | |
| 575 | ||
| 576 | List <CBSSiteTr ans> siteT ransL = ne w ArrayLis t<>(); | |
| 577 | for (PSDetails details : psPatient .getPsDeta ilsL()) { | |
| 578 | ||
| 579 | CBSSit eTrans sit eTrans = n ew CBSSite Trans(); | |
| 580 | siteTr ans.setDat ePosted(de tails.getD atePosted( )); | |
| 581 | siteTr ans.setTra nsDesc(det ails.getTr ansDesc()) ; | |
| 582 | siteTr ans.setTra nsAmount(d etails.get TransAmoun t()); | |
| 583 | siteTr ans.setRef erenceNum( details.ge tReference Num()); | |
| 584 | siteTr ans.setOrd erNum(deta ils.getSeq Num()); | |
| 585 | siteTr ans.setCre atedDate(c urrentTime ); | |
| 586 | siteTr ans.setMod ifiedDate( currentTim e); | |
| 587 | siteTr ansL.add(s iteTrans); | |
| 588 | } | |
| 589 | site Statement. setSiteTra nsL(siteTr ansL); | |
| 590 | ||
| 591 | retu rn siteSta tement; | |
| 592 | } | |
| 593 | ||
| 594 | /* * | |
| 595 | * Save an s tatement a nd update the databa se auto ge nerated ID . | |
| 596 | * | |
| 597 | * @param st atement | |
| 598 | * The cons olidated s tatement. | |
| 599 | * @return T he updated statement populated with the auto gener ated ID. | |
| 600 | * / | |
| 601 | pu blic void saveStatem ent(CBSStm t statemen t) { | |
| 602 | ||
| 603 | stat ement.setI d(cbsStmtD AO.save(st atement)); | |
| 604 | } | |
| 605 | ||
| 606 | /* * | |
| 607 | * Save an s ite patien t and upda te the dat abase auto generated ID. | |
| 608 | * | |
| 609 | * @param si tePatient | |
| 610 | * The site patient. | |
| 611 | * @return T he updated site pati ent popula ted with t he auto ge nerated ID . | |
| 612 | * / | |
| 613 | pu blic void savePatien t(CBSSiteP atient sit ePatient) { | |
| 614 | ||
| 615 | site Patient.se tId(cbsSit ePatientDA O.save(sit ePatient)) ; | |
| 616 | } | |
| 617 | ||
| 618 | /* * | |
| 619 | * Save an s ite statem ent and up date the d atabase au to generat ed ID. | |
| 620 | * | |
| 621 | * @param si teStatemen t | |
| 622 | * The site statement . | |
| 623 | * @return T he updated site stat ement popu lated with the auto generated ID. | |
| 624 | * / | |
| 625 | pu blic void saveSiteSt atement(CB SSiteStmt siteStatem ent) { | |
| 626 | ||
| 627 | site Statement. setId(cbsS iteStmtDAO .save(site Statement, true)); | |
| 628 | } | |
| 629 | ||
| 630 | /* * | |
| 631 | * Save the List of CB SStmts. Th e nested C BSSiteStmt s CBSSiteP atients an d | |
| 632 | * CBSSiteTr ans object s will als o be saved (deep sav e). The au to generat ed | |
| 633 | * IDs will NOT be upd ated in th e objects. If the id s are requ ired, then use | |
| 634 | * the other individua l saveXXX( ) methods. | |
| 635 | * | |
| 636 | * @param st atementL | |
| 637 | * List of CBSStmts t o save | |
| 638 | * / | |
| 639 | pu blic void batchSaveS tatements( List<CBSSt mt> statem entL) { | |
| 640 | cbsS tmtDAO.sav eBatch(sta tementL); | |
| 641 | ||
| 642 | // c bsSiteStmt DAO.saveBa tch(statem entL); | |
| 643 | for (CBSStmt c bsStmt : s tatementL) { | |
| 644 | List<C BSSiteStmt > cbsSiteS tmtL = cbs Stmt.getSi teStmtL(); | |
| 645 | ||
| 646 | cbsStm t.setId(cb sStmtDAO.g etCBSStmtI d(cbsStmt. getBatchRu nId(), cbs Stmt.getAc countId()) );; | |
| 647 | ||
| 648 | if (cb sSiteStmtL != null) { | |
| 649 | for (CBS SiteStmt c bsSiteStmt : cbsSite StmtL) { | |
| 650 | cbsSiteStm t.setStmtI d(cbsStmt. getId()); | |
| 651 | cbsSiteStm tDAO.save( cbsSiteStm t, false); | |
| 652 | } | |
| 653 | } | |
| 654 | } | |
| 655 | ||
| 656 | cbsS itePatient DAO.saveBa tch(statem entL); | |
| 657 | cbsS iteTransDA O.saveBatc h(statemen tL); | |
| 658 | } | |
| 659 | ||
| 660 | /* * | |
| 661 | * Query the database for an exi sting stat ement for this accou nt for the | |
| 662 | * same mont h as the s pecified d ate. | |
| 663 | * | |
| 664 | * @param ac countNumbe r | |
| 665 | * The acco unt number for the s tatement. | |
| 666 | * @param st atementDat e | |
| 667 | * The date for this month. | |
| 668 | * @return T he existin g statemen t or null if does no t exist. | |
| 669 | * / | |
| 670 | pr ivate CBSS tmt getExi stingState mentForAcc ount(final long acco untNumber, final Dat e statemen tDate) { | |
| 671 | ||
| 672 | CBSS tmt statem ent = cbsS tmtDAO.get ExistingSt atementByA ccountAndM onth(accou ntNumber, statementD ate); | |
| 673 | ||
| 674 | if ( statement != null) { | |
| 675 | ||
| 676 | // The n get all CBSSiteStm t from dat abase. | |
| 677 | List<C BSSiteStmt > siteStat ementL = c bsSiteStmt DAO.getAll ByCBSStmtI D(statemen t.getId(), true); | |
| 678 | ||
| 679 | // The n get all CBSSiteTra ns from da tabase. | |
| 680 | if ((s iteStateme ntL != nul l) && !sit eStatement L.isEmpty( )) { | |
| 681 | ||
| 682 | List<CBS SiteTrans> siteTrans L = cbsSit eTransDAO. getAllByCB SSiteStmtI D(statemen t.getId()) ; | |
| 683 | ||
| 684 | // Sort into a map (CBSSiteS tmt.ID to List<CBSSi teTrans>) for | |
| 685 | // the | |
| 686 | // list of CBSSite Trans. | |
| 687 | Map<Long , List<CBS SiteTrans> > transQue ryM = site TransL.str eam() | |
| 688 | .c ollect(Col lectors.gr oupingBy(w -> w.getS iteStmtId( ))); | |
| 689 | ||
| 690 | // Set t he appropr iate trans list in t he CBSSite Stmt. | |
| 691 | for (CBS SiteStmt s iteStmt : siteStatem entL) { | |
| 692 | ||
| 693 | logger.deb ug("SITEST MT.ID: " + siteStmt. getId()); | |
| 694 | ||
| 695 | List<CBSSi teTrans> s iteTransMa pEntry = t ransQueryM .get(siteS tmt.getId( )); | |
| 696 | // If no l ist then a n unrecove rable data error. | |
| 697 | if (siteTr ansMapEntr y != null) { | |
| 698 | ||
| 699 | si teStmt.set SiteTransL (siteTrans MapEntry); | |
| 700 | } else { | |
| 701 | fi nal String error = " Unrecovera ble data e rror, site trans map is null f or site"; | |
| 702 | lo gger.error (error); | |
| 703 | th row new Ru ntimeExcep tion(error ); | |
| 704 | } | |
| 705 | } | |
| 706 | ||
| 707 | // Add t he site st atement li st to the statement. | |
| 708 | statemen t.setSiteS tmtL(siteS tatementL) ; | |
| 709 | } else { | |
| 710 | final St ring error = "Unreco verable da ta error, site state ment list is null or empty"; | |
| 711 | logger.e rror(error ); | |
| 712 | throw ne w RuntimeE xception(e rror); | |
| 713 | } | |
| 714 | } | |
| 715 | ||
| 716 | retu rn stateme nt; | |
| 717 | } | |
| 718 | ||
| 719 | /* * | |
| 720 | * Publish t he INITIAL statement s to NEW s tatus. | |
| 721 | * | |
| 722 | * @return T he number of stateme nts that w ere update d. | |
| 723 | * / | |
| 724 | pu blic int p ublishAllN ewStatemen ts() { | |
| 725 | ||
| 726 | Inte ger initia lStatus = processSta tusDAO.get StatusFrom Enum(Proce ssStatus.S tatus.INIT IAL); | |
| 727 | Inte ger newSta tus = proc essStatusD AO.getStat usFromEnum (ProcessSt atus.Statu s.NEW); | |
| 728 | ||
| 729 | if ( (initialSt atus != nu ll) && (ne wStatus != null)) { | |
| 730 | ||
| 731 | return cbsStmtDA O.updateAl lStatusFro mTo(initia lStatus, n ewStatus); | |
| 732 | } el se { | |
| 733 | ||
| 734 | logger .error("Un able to ob tain statu s mapping for: " + P rocessStat us.Status. INITIAL + " or " | |
| 735 | + ProcessS tatus.Stat us.NEW); | |
| 736 | } | |
| 737 | ||
| 738 | retu rn 0; | |
| 739 | } | |
| 740 | ||
| 741 | /* * | |
| 742 | * Revert th e REPLACED statement s to NEW s tatus that are assoc iated with | |
| 743 | * INITIAL s tatements. | |
| 744 | * | |
| 745 | * @return T he number of stateme nts that w ere update d. | |
| 746 | * / | |
| 747 | pu blic int r evertRepla cedStateme ntsAssocia tedWithIni tialStatem ents() { | |
| 748 | ||
| 749 | int revertedCo unt = -1; | |
| 750 | ||
| 751 | Inte ger initia lStatus = processSta tusDAO.get StatusFrom Enum(Proce ssStatus.S tatus.INIT IAL); | |
| 752 | Inte ger replac edStatus = processSt atusDAO.ge tStatusFro mEnum(Proc essStatus. Status.REP LACED); | |
| 753 | Inte ger newSta tus = proc essStatusD AO.getStat usFromEnum (ProcessSt atus.Statu s.NEW); | |
| 754 | ||
| 755 | if ( (initialSt atus != nu ll) && (re placedStat us != null ) && (newS tatus != n ull)) { | |
| 756 | ||
| 757 | revert edCount = cbsStmtDAO .updateSta tusFromToF orInitial( replacedSt atus, newS tatus, ini tialStatus ); | |
| 758 | } el se { | |
| 759 | ||
| 760 | logger .error("Un able to ob tain statu s mapping for: " + P rocessStat us.Status. INITIAL + " or " | |
| 761 | + ProcessS tatus.Stat us.REPLACE D + " or " + Process Status.Sta tus.NEW); | |
| 762 | } | |
| 763 | ||
| 764 | retu rn reverte dCount; | |
| 765 | } | |
| 766 | ||
| 767 | /* * | |
| 768 | * Remove st atements t hat have I NITIAL sta tus. | |
| 769 | * | |
| 770 | * @return T he number of stateme nts that w ere update d. | |
| 771 | * / | |
| 772 | pu blic int r emoveIniti alStatemen ts() { | |
| 773 | ||
| 774 | int removedCou nt = -1; | |
| 775 | ||
| 776 | Inte ger initia lStatus = processSta tusDAO.get StatusFrom Enum(Proce ssStatus.S tatus.INIT IAL); | |
| 777 | ||
| 778 | if ( initialSta tus != nul l) { | |
| 779 | ||
| 780 | remove dCount = c bsStmtDAO. deleteBySt atusId(ini tialStatus ); | |
| 781 | } el se { | |
| 782 | ||
| 783 | logger .error("Un able to ob tain statu s mapping for: " + P rocessStat us.Status. INITIAL); | |
| 784 | } | |
| 785 | ||
| 786 | retu rn removed Count; | |
| 787 | } | |
| 788 | ||
| 789 | /* * | |
| 790 | * Query the number of consolida ted statem ents in th e NEW stat e. | |
| 791 | * | |
| 792 | * @return T he number of consoli dated stat ements in the NEW st ate or nul l if | |
| 793 | * e rror. | |
| 794 | * / | |
| 795 | pu blic Long getCountOf Statements InState(fi nal Proces sStatus.St atus state ) { | |
| 796 | ||
| 797 | Long available Count = nu ll; | |
| 798 | ||
| 799 | Inte ger status = process StatusDAO. getStatusF romEnum(st ate); | |
| 800 | ||
| 801 | if ( status != null) { | |
| 802 | ||
| 803 | availa bleCount = cbsStmtDA O.getState mentCountW ithStatus( status); | |
| 804 | ||
| 805 | if (av ailableCou nt == null ) { | |
| 806 | ||
| 807 | logger.e rror("Inva lid count when check ing for co unt of sta tements"); | |
| 808 | } | |
| 809 | ||
| 810 | } el se { | |
| 811 | ||
| 812 | logger .error("Un able to ob tain statu s mapping for: " + s tate); | |
| 813 | } | |
| 814 | ||
| 815 | retu rn availab leCount; | |
| 816 | } | |
| 817 | ||
| 818 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.