Produced by Araxis Merge on 12/5/2017 12:06:50 PM 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 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\VistaDataSourceCommon\main\src\java\gov\va\med\imaging\protocol\vista | VistaCommonTranslator.java | Mon Dec 4 21:34:58 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\VistaDataSourceCommon\main\src\java\gov\va\med\imaging\protocol\vista | VistaCommonTranslator.java | Mon Dec 4 22:06:32 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 1736 |
| 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.med.i maging.pro tocol.vist a; | |
| 2 | ||
| 3 | import gov .va.med.im aging.exch ange.busin ess.Patien tMeansTest Result; | |
| 4 | import gov .va.med.im aging.exch ange.busin ess.Patien tSensitive Value; | |
| 5 | import gov .va.med.im aging.exch ange.enums .PatientSe nsitivityL evel; | |
| 6 | import gov .va.med.im aging.url. vista.Stri ngUtils; | |
| 7 | import gov .va.med.im aging.url. vista.exce ptions.Vis taMethodEx ception; | |
| 8 | ||
| 9 | import jav a.text.Dec imalFormat ; | |
| 10 | import jav a.text.Par seExceptio n; | |
| 11 | import jav a.text.Sim pleDateFor mat; | |
| 12 | import jav a.util.Arr ayList; | |
| 13 | import jav a.util.Cal endar; | |
| 14 | import jav a.util.Dat e; | |
| 15 | import jav a.util.Has hSet; | |
| 16 | import jav a.util.Ite rator; | |
| 17 | import jav a.util.Lin kedList; | |
| 18 | import jav a.util.Lis t; | |
| 19 | import jav a.util.Loc ale; | |
| 20 | ||
| 21 | import org .apache.lo gging.log4 j.LogManag er; | |
| 22 | import org .apache.lo gging.log4 j.Logger; | |
| 23 | ||
| 24 | ||
| 25 | public cla ss VistaCo mmonTransl ator | |
| 26 | { | |
| 27 | pr ivate stat ic Logger logger = L ogManager. getLogger( VistaCommo nTranslato r.class); | |
| 28 | ||
| 29 | pu blic stati c PatientS ensitiveVa lue conver tStringToP atientSens itiveValue (String rt n, String patientDfn ) | |
| 30 | th rows Vista MethodExce ption | |
| 31 | { | |
| 32 | if( (rtn == nu ll) || (rt n.equals(" -1")) ) | |
| 33 | { | |
| 34 | String msg = "Er ror respon se while c hecking pa tient sens itivity fo r patient; DFN=" + p atientDfn; | |
| 35 | logger .error(msg ); | |
| 36 | throw new VistaM ethodExcep tion(msg); | |
| 37 | } | |
| 38 | Stri ng [] line s = rtn.sp lit(String Utils.NEW_ LINE); | |
| 39 | if(l ines.lengt h <= 0) | |
| 40 | { | |
| 41 | String msg = "Er ror parsin g response from chec king patie nt sensiti ve; DFN=" + patientD fn; | |
| 42 | logger .error(msg ); | |
| 43 | logger .error("Vi stA Respon se [" + rt n + "]"); | |
| 44 | throw new VistaM ethodExcep tion(msg); | |
| 45 | } | |
| 46 | int code = Int eger.parse Int(lines[ 0].trim()) ; | |
| 47 | logg er.info("P atient Sen sitive lev el for pat ient (DFN) : '" + pat ientDfn + "' is '" + code + "' "); | |
| 48 | Pati entSensiti vityLevel sensitiveL evel = Pat ientSensit ivityLevel .getPatien tSensitivi tyLevel(co de); | |
| 49 | Stri ngBuilder sb = new S tringBuild er(); | |
| 50 | for( int i = 1; i < lines .length; i ++) | |
| 51 | { | |
| 52 | sb.app end(lines[ i]); | |
| 53 | if(i ! = (lines.l ength - 1) ) | |
| 54 | sb.appen d("\n"); | |
| 55 | } | |
| 56 | retu rn new Pat ientSensit iveValue(s ensitiveLe vel, sb.to String()); | |
| 57 | } | |
| 58 | ||
| 59 | pu blic stati c Date con vertVistaD atetoDate( String vis taDate) | |
| 60 | { | |
| 61 | if(( vistaDate == null) | | (vistaDa te.length( ) <= 0)) | |
| 62 | return null; | |
| 63 | try | |
| 64 | { | |
| 65 | // if the value includes t he time, i nclude tha t in the p arse | |
| 66 | if(vis taDate.len gth() > 10 ) | |
| 67 | { | |
| 68 | SimpleDa teFormat f ormat = ne w SimpleDa teFormat(" MM/dd/yyyy HH:mm", L ocale.US); | |
| 69 | return f ormat.pars e(vistaDat e); | |
| 70 | } | |
| 71 | else | |
| 72 | { | |
| 73 | SimpleDa teFormat f ormat = ne w SimpleDa teFormat(" MM/dd/yyyy ", Locale. US); | |
| 74 | return f ormat.pars e(vistaDat e); | |
| 75 | } | |
| 76 | } | |
| 77 | catc h(ParseExc eption pX) | |
| 78 | { | |
| 79 | logger .error("Er ror parsin g date [" + vistaDat e + "] fro m VistA", pX); | |
| 80 | } | |
| 81 | retu rn null; | |
| 82 | } | |
| 83 | ||
| 84 | ||
| 85 | /* * | |
| 86 | * | |
| 87 | * @param da te | |
| 88 | * @return - a String representa tion of th e date in the format needed to make | |
| 89 | * an RPC ca ll or a ze ro-length string if date is nu ll. | |
| 90 | * / | |
| 91 | pu blic stati c String c onvertDate ToRpcForma t(Date dat e) | |
| 92 | { | |
| 93 | if(d ate == nul l) | |
| 94 | return ""; | |
| 95 | ||
| 96 | Cale ndar calen dar = Cale ndar.getIn stance(); | |
| 97 | cale ndar.setTi me(date); | |
| 98 | ||
| 99 | int year = cal endar.get( Calendar.Y EAR); | |
| 100 | int month = ca lendar.get (Calendar. MONTH) + 1 ; | |
| 101 | int day = cale ndar.get(C alendar.DA Y_OF_MONTH ); | |
| 102 | // i nt hour = calendar.g et(Calenda r.HOUR_OF_ DAY); | |
| 103 | // i nt minute = calendar .get(Calen dar.MINUTE ); | |
| 104 | //in t second = calendar. get(Calend ar.SECOND) ; | |
| 105 | ||
| 106 | Stri ng mDateFo rmat = ""; | |
| 107 | /* | |
| 108 | int yearDiffer ence = ((y ear - 1700 ) / 100); | |
| 109 | mDat eFormat = yearDiffer ence + ""; | |
| 110 | year = (year % 100); | |
| 111 | */ | |
| 112 | ||
| 113 | Deci malFormat twoDigitFo rmat = new DecimalFo rmat("00") ; | |
| 114 | ||
| 115 | mDat eFormat = twoDigitFo rmat.forma t(month) + "/" + two DigitForma t.format(d ay) + "/" + year; | |
| 116 | ||
| 117 | /* | |
| 118 | mDat eFormat += twoDigitF ormat.form at(year) + twoDigitF ormat.form at(month) + twoDigit Format.for mat(day) + twoDigitF ormat.form at(hour) + | |
| 119 | twoD igitFormat .format(mi nute) + tw oDigitForm at.format( second); | |
| 120 | */ | |
| 121 | retu rn mDateFo rmat; | |
| 122 | } | |
| 123 | ||
| 124 | /* * | |
| 125 | * | |
| 126 | * @param di comDate | |
| 127 | * @return | |
| 128 | * / | |
| 129 | pu blic stati c String c onvertDICO MDateToRpc Format(Str ing dicomD ate) | |
| 130 | { | |
| 131 | if(( dicomDate == null) | | (dicomDa te.equals( ""))) { | |
| 132 | return ""; | |
| 133 | } | |
| 134 | if(d icomDate.l ength() < 8) { | |
| 135 | return ""; | |
| 136 | } | |
| 137 | ||
| 138 | //TO DO: update this func tion to ha ndle if on ly part of the date is given ( no month, etc) | |
| 139 | //TO DO: month and day ar e now requ ired, do a check for length an d parse on that | |
| 140 | //TO DO: if the date is i nvalid, sh ould this throw an e xception o r always g et full li st of stud ies? | |
| 141 | //St ring dicom Date = "20 0610181436 43.655321+ 0200"; | |
| 142 | //Si mpleDateFo rmat sdf = new Simpl eDateForma t("yyyyMMd dHHmmss", Locale.US) ; | |
| 143 | ||
| 144 | Stri ng format = getDateF ormat(dico mDate); | |
| 145 | if(" ".equals(f ormat)) | |
| 146 | return ""; | |
| 147 | //Si mpleDateFo rmat sdf = new Simpl eDateForma t("yyyyMMd d", Locale .US); | |
| 148 | Simp leDateForm at sdf = n ew SimpleD ateFormat( format, Lo cale.US); | |
| 149 | Date d = null; | |
| 150 | try | |
| 151 | { | |
| 152 | d = sd f.parse(di comDate); | |
| 153 | ||
| 154 | return convertDa teToRpcFor mat(d); | |
| 155 | } | |
| 156 | catc h(ParseExc eption pX) { | |
| 157 | logger .error(pX) ; | |
| 158 | return ""; | |
| 159 | } | |
| 160 | ||
| 161 | ||
| 162 | /* | |
| 163 | * Y YYYMMDDHHM MSS.FFFFFF +ZZZZ | |
| 164 | The co mponents o f this str ing, from left to ri ght, are | |
| 165 | YYYY = Year, | |
| 166 | MM = M onth, | |
| 167 | DD = D ay, | |
| 168 | HH = H our, | |
| 169 | MM = M inute, | |
| 170 | SS = S econd, | |
| 171 | FFFFFF = Fractio nal Second , | |
| 172 | “+” or “-” and Z ZZZ = Hour s and Minu tes of off set. | |
| 173 | &ZZZZ is an opti onal suffi x for plus /minus off set from C oordinated Universal Time. | |
| 174 | A comp onent that is omitte d from the string is termed a null compo nent. | |
| 175 | Traili ng null co mponents o f Date Tim e are igno red. | |
| 176 | Nontra iling null component s are proh ibited, gi ven that t he optiona l suffix i s not cons idered as a componen t. | |
| 177 | ||
| 178 | The pa ttern shou ld read as : | |
| 179 | 4 requ ired digit s (the yea r) | |
| 180 | 2 opti onal digit s for each of month, day, hour , minute a nd seconds | |
| 181 | option ally a dec imal point followed by 6 digit s (the mil liseconds) | |
| 182 | option ally an am persand fo llowed by '+' or '-' and 4 dig its, 2 for hours and 2 for min utes (the offset fro m UCT) | |
| 183 | Note t hat ranges are not c hecked by this patte rn, that i s there ma y be 63 mi nutes in a n hour. | |
| 184 | ||
| 185 | Ex: 2: 36:43PM on 18 Octobe r, 2006 in EST would be: 20061 018143643. 655321+050 0 | |
| 186 | * | |
| 187 | */ | |
| 188 | ||
| 189 | } | |
| 190 | ||
| 191 | /* | |
| 192 | * String di comDate = "200610181 43643.6553 21+0200"; | |
| 193 | //Si mpleDateFo rmat sdf = new Simpl eDateForma t("yyyyMMd dHHmmss", Locale.US) ; | |
| 194 | * / | |
| 195 | ||
| 196 | pr ivate stat ic String getDateFor mat(String date) { | |
| 197 | if(d ate == nul l) | |
| 198 | return ""; | |
| 199 | swit ch(date.le ngth()) { | |
| 200 | case 4 : | |
| 201 | return " yyyy"; | |
| 202 | case 6 : | |
| 203 | return " yyyyMM"; | |
| 204 | case 8 : | |
| 205 | return " yyyyMMdd"; | |
| 206 | case 1 0: | |
| 207 | return " yyyyMMddHH "; | |
| 208 | case 1 2: | |
| 209 | return " yyyyMMddHH mm"; | |
| 210 | case 1 4: | |
| 211 | return " yyyyMMddHH mmss"; | |
| 212 | defaul t: | |
| 213 | return " yyyyMMddHH mmss"; | |
| 214 | ||
| 215 | } | |
| 216 | ||
| 217 | } | |
| 218 | ||
| 219 | /* * | |
| 220 | * | |
| 221 | * @param rt n | |
| 222 | * @return | |
| 223 | * @throws E xception | |
| 224 | * / | |
| 225 | pu blic stati c String p arseOption Number(Str ing rtn) | |
| 226 | th rows Excep tion | |
| 227 | { | |
| 228 | Stri ng[] lines = StringU tils.Split (rtn, Stri ngUtils.CR LF); | |
| 229 | if ( !lines[0]. equals("[D ata]")) { | |
| 230 | throw new Except ion("Inval id return format (" + rtn + ") "); | |
| 231 | } | |
| 232 | if ( lines[1].s tartsWith( "[BEGIN_di ERRORS]")) { | |
| 233 | throw new Except ion(rtn.su bstring(8) ); | |
| 234 | } | |
| 235 | if ( lines.leng th == 1) { | |
| 236 | throw new Except ion("No op tion numbe r data"); | |
| 237 | } | |
| 238 | int p = lines[ 1].indexOf (",^"); | |
| 239 | Stri ng optNum = lines[1] .substring (p + 2); | |
| 240 | if ( !StringUti ls.isNumer ic(optNum) ) { | |
| 241 | throw new Except ion("Non-n umeric opt ion number "); | |
| 242 | } | |
| 243 | retu rn optNum; | |
| 244 | } | |
| 245 | ||
| 246 | /* * | |
| 247 | * | |
| 248 | * @param si teString | |
| 249 | * @return | |
| 250 | * | |
| 251 | * CTB - com mented out for now b ecause usi ng the Sit eImpl clas s for a si te number | |
| 252 | * and site name is no t safe. | |
| 253 | * / | |
| 254 | // pu blic stati c List<Sit e> convert SiteString ToSiteList (String si teString) | |
| 255 | // { | |
| 256 | // List <Site> sit es = new L inkedList< Site>(); | |
| 257 | // if(( siteString == null) || (siteSt ring.equal s(""))) | |
| 258 | // return sites; | |
| 259 | // Stri ng siteDat a[] = Stri ngUtils.Sp lit(siteSt ring, Stri ngUtils.CA RET); | |
| 260 | // | |
| 261 | // for( int i = 0 ; i < site Data.lengt h; i = i + 4 ) | |
| 262 | // { | |
| 263 | // if( (i + 4) < si teData.len gth ) | |
| 264 | // { | |
| 265 | // Site sit e = new Si teImpl(nul l, siteDat a[i], site Data[i + 1 ], null); | |
| 266 | // //site.s etSiteNumb er(siteDat a[i]); | |
| 267 | // //site.s etSiteName (siteData[ i + 1]); | |
| 268 | // } | |
| 269 | // else | |
| 270 | // break; | |
| 271 | // } | |
| 272 | // retu rn sites; | |
| 273 | // } | |
| 274 | ||
| 275 | pu blic stati c List<Str ing> conve rtSiteStri ngToSiteSt ringList(S tring site String) | |
| 276 | { | |
| 277 | List <String> s ites = new LinkedLis t<String>( ); | |
| 278 | if(( siteString == null) || (siteSt ring.equal s(""))) | |
| 279 | return sites; | |
| 280 | Stri ng siteDat a[] = Stri ngUtils.Sp lit(siteSt ring, Stri ngUtils.CA RET); | |
| 281 | Stri ngBuilder initialSit eList = ne w StringBu ilder(); | |
| 282 | Stri ngBuilder convertedS iteList = new String Builder(); | |
| 283 | Stri ng prefix = ""; | |
| 284 | ||
| 285 | for( int i = 0 ; i < site Data.lengt h; i = i + 4 ) | |
| 286 | { | |
| 287 | if( (i + 4) < si teData.len gth ) | |
| 288 | { | |
| 289 | String i nitialSite Number = s iteData[i] ; | |
| 290 | String c onvertedSi teNumber = extractUn necessaryS iteNumberC haracters( initialSit eNumber); | |
| 291 | initialS iteList.ap pend(prefi x); | |
| 292 | initialS iteList.ap pend(initi alSiteNumb er); | |
| 293 | converte dSiteList. append(pre fix); | |
| 294 | converte dSiteList. append(con vertedSite Number); | |
| 295 | sites.ad d(converte dSiteNumbe r); | |
| 296 | prefix = ", "; | |
| 297 | } | |
| 298 | else | |
| 299 | break; | |
| 300 | } | |
| 301 | ||
| 302 | logg er.info("C onverted s ite list ' " + initia lSiteList. toString() + "' to ' " + conver tedSiteLis t.toString () + "'.") ; | |
| 303 | // p ut into a hashset to exclude d uplicate e ntries | |
| 304 | retu rn new Arr ayList<Str ing>(new H ashSet<Str ing>(sites )); | |
| 305 | } | |
| 306 | ||
| 307 | /* * | |
| 308 | * This meth od looks a t the site number an d extracts unnecessa ry charact ers. If th e site | |
| 309 | * number st arts with letters, t hey are ex cluded. A ny letters after num bers are e xcluded an d | |
| 310 | * any numbe rs followi ng that ar e also exc luded. | |
| 311 | * | |
| 312 | * ex: ABC20 0T1 transl ates to 20 0 | |
| 313 | * @param ra wSiteNumbe r | |
| 314 | * @return | |
| 315 | * / | |
| 316 | pr ivate stat ic String extractUnn ecessarySi teNumberCh aracters(S tring rawS iteNumber) | |
| 317 | { | |
| 318 | Stri ngBuilder result = n ull; | |
| 319 | for( int i = 0; i < rawSi teNumber.l ength(); i ++) | |
| 320 | { | |
| 321 | char c h = rawSit eNumber.ch arAt(i); | |
| 322 | int c = (int)ch; | |
| 323 | if((c < 48) || ( c > 57)) | |
| 324 | { | |
| 325 | if(resul t != null) | |
| 326 | return res ult.toStri ng(); | |
| 327 | } | |
| 328 | else | |
| 329 | { | |
| 330 | if(resul t == null) | |
| 331 | { | |
| 332 | result = n ew StringB uilder(); | |
| 333 | } | |
| 334 | result.a ppend(ch); | |
| 335 | } | |
| 336 | } | |
| 337 | if(r esult == n ull) | |
| 338 | return ""; | |
| 339 | retu rn result. toString() ; | |
| 340 | ||
| 341 | /* | |
| 342 | Stri ng newSite Number = r awSiteNumb er.replace All("[A-Za -z]", ""); | |
| 343 | newS iteNumber = newSiteN umber.repl aceAll("&" , ""); | |
| 344 | retu rn newSite Number; | |
| 345 | */ | |
| 346 | } | |
| 347 | ||
| 348 | /* * | |
| 349 | * Parse the lines rea d from a V ista into a hierarch y as defin ed by the tag delimi ter keys. | |
| 350 | * The first line is s kipped. | |
| 351 | * Example: | |
| 352 | * lines = | |
| 353 | * 8 | |
| 354 | * NEXT_ST UDY||712 | |
| 355 | * STUDY_I EN|712 | |
| 356 | * STUDY_P AT|1011|92 17103663V7 10366|IMAG PATIENT101 1,1011 | |
| 357 | * NEXT_SE RIES | |
| 358 | * SERIES_ IEN|712 | |
| 359 | * NEXT_IM AGE | |
| 360 | * IMAGE_I EN|713 | |
| 361 | * IMAGE_I NFO|B2^713 ^\\isw-wer felj-lt\im age1$\DM\0 0\07\DM000 713.TGA^\\ isw-werfel j-lt\image 1$\DM\00\0 7\DM000713 .ABS^04060 0-28 CHES T SINGLE V IEW^300040 6.1349^3^C R^04/06/20 00^^M^A^^^ 1^1^SLC^^^ 1011^IMAGP ATIENT1011 ,1011^CLIN ^^^^ | |
| 362 | * and ontol ogyDelimit erKeys = | |
| 363 | * NEXT_ST UDY, NEXT_ SERIES, NE XT_IMAGE | |
| 364 | * | |
| 365 | * would ret urn a list : | |
| 366 | * ParsedV istaLine | |
| 367 | * with ke y="NEXT_ST UDY" and v alues="", "712" | |
| 368 | * and pro perties: | |
| 369 | * Parse dVistaLine with key= "STUDY_IEN " and valu es="712" | |
| 370 | * Parse dVistaLine with key= "STUDY_PAT " and valu es="1011", "92171036 63V710366" , IMAGPATI ENT1011,10 11 | |
| 371 | * and chi ldren: | |
| 372 | * Parse dVistaLine | |
| 373 | * with key="NEXT_ SERIES" an d values= | |
| 374 | * and p roperties: | |
| 375 | * Par sedVistaLi ne with ke y="SERIES_ IEN" and v alues="712 " | |
| 376 | * and c hildren: | |
| 377 | * Par sedVistaLi ne | |
| 378 | * wit h key="NEX T_IMAGE" a nd values= | |
| 379 | * and propertie s: | |
| 380 | * P arsedVista Line with key="IMAGE _IEN" and values="71 3" | |
| 381 | * P arsedVista Line with key="IMAGE _INFO" and values="B 2^713^\\is w-werfelj- lt\image1$ \DM\00\07\ DM000713.T GA^\\isw-w erfelj-lt\ image1$\DM \00\07\DM0 00713.ABS^ 040600-28 CHEST SIN GLE VIEW^3 000406.134 9^3^CR^04/ 06/2000^^M ^A^^^1^1^S LC^^^1011^ IMAGPATIEN T1011,1011 ^CLIN^^^^" | |
| 382 | * | |
| 383 | * | |
| 384 | * | |
| 385 | * @param li nes | |
| 386 | * @param de limiterKey s - A list of key va lues that define the start of each seria lized obje ct. | |
| 387 | * The or der of the delimiter keys IS S IGNIFICANT . Later, numericall y higher i ndex, | |
| 388 | * delimi ter keys a re conside red childr en of earl ier keys. The retur ned List | |
| 389 | * will c onsist ent irely of P arsedVista Line where the key i s the firs t delimite rKeys | |
| 390 | * member . Each of those Par sedVistaLi ne will ha ve childre n with a k ey value | |
| 391 | * of the second de limiterKey s member, etc ... | |
| 392 | * | |
| 393 | * @return | |
| 394 | * / | |
| 395 | pu blic stati c List<Par sedVistaLi ne> parseL ines( | |
| 396 | String [] lines, | |
| 397 | Ontolo gyDelimite rKey[] ont ologyDelim iterKeys, | |
| 398 | boolea n discardU nknownRoot Lines) | |
| 399 | { | |
| 400 | ||
| 401 | // p arameter c hecking, t he ontolog y delimite r keys mus t be provi ded | |
| 402 | if(o ntologyDel imiterKeys == null | | ontology DelimiterK eys.length <= 0) | |
| 403 | throw new Illega lArgumentE xception(" The delimi ter keys m ust not be null or a n empty ar ray."); | |
| 404 | ||
| 405 | for( OntologyDe limiterKey ontologyD elimiterKe y : ontolo gyDelimite rKeys) | |
| 406 | if(ont ologyDelim iterKey == null || o ntologyDel imiterKey. getKey() = = null || ontologyDe limiterKey .getKey(). length() < = 0) | |
| 407 | throw ne w IllegalA rgumentExc eption("Al l keys in the delimi ter keys m ust not be null or a n empty St ring."); | |
| 408 | ||
| 409 | List <ParsedVis taLine> pa rsedLines = new Arra yList<Pars edVistaLin e>(); | |
| 410 | // i f no lines given the n return a n empty li st | |
| 411 | if(l ines == nu ll || line s.length < = 1) | |
| 412 | return parsedLin es; | |
| 413 | ||
| 414 | logg er.info("P arsing " + lines.len gth + " li nes using " + ontolo gyDelimite rKeys.leng th + " key s."); | |
| 415 | ||
| 416 | // A n array of ParsedVis taLine ins tances tha t define t he current path | |
| 417 | // i n the resu lting hier archy. Ne w instance s of Parse dVistaLine , as they | |
| 418 | // a re parsed, are added to the cu rrent path , unless t hey are de limiter | |
| 419 | // k eys, in wh ich case t hey change the curre nt path. | |
| 420 | Pars edVistaLin e[] curren tHierarchy Path = new ParsedVis taLine[ont ologyDelim iterKeys.l ength]; | |
| 421 | for( int index= 0; index < currentHi erarchyPat h.length; ++index) | |
| 422 | curren tHierarchy Path[index ] = null; | |
| 423 | // t he depth i nto the hi erarchy th at we are currently adding to | |
| 424 | // t his is als o the inde x into cur rentHierar chyPath of the "acti ve" elemen t | |
| 425 | int currentHie rarchyDept h = 0; | |
| 426 | ||
| 427 | for( String lin e : lines) | |
| 428 | { | |
| 429 | if(lin e == null) // should ne ver happen , but ... | |
| 430 | continue ; | |
| 431 | line = line.trim (); // remove tr ailing whi tespace | |
| 432 | ||
| 433 | logger .debug("Pa rsing line '" + line + "'."); | |
| 434 | ||
| 435 | // giv en a line like "NEXT _STUDY||71 2" get the parts "NE XT_STUDY", "", "712" | |
| 436 | String parts[] = line.spli t("\\|", - 1); // Str ingUtils.S plit(line, StringUti ls.STICK); | |
| 437 | String key = par ts[0].trim (); | |
| 438 | String [] values = parts.le ngth > 1 ? new Strin g[parts.le ngth-1] : null; | |
| 439 | if(val ues != nul l) | |
| 440 | System.a rraycopy(p arts, 1, v alues, 0, parts.leng th-1); | |
| 441 | // at this point the examp le line sh ould end u p like: | |
| 442 | // key = "NEXT_S TUDY" | |
| 443 | // val ues = "", "712" | |
| 444 | ||
| 445 | int on tologyKeyI ndex; | |
| 446 | for(on tologyKeyI ndex=0; on tologyKeyI ndex < ont ologyDelim iterKeys.l ength; ++o ntologyKey Index) | |
| 447 | { | |
| 448 | if( onto logyDelimi terKeys[on tologyKeyI ndex].getK ey().equal s(key) ) | |
| 449 | { | |
| 450 | break; | |
| 451 | } | |
| 452 | } | |
| 453 | int pa rentKeyInd ex = -1; | |
| 454 | if(ont ologyKeyIn dex >= ont ologyDelim iterKeys.l ength) | |
| 455 | { | |
| 456 | ontology KeyIndex = -1; | |
| 457 | // if th e current key is not a ontolog y key, che ck to see if the cur rent key | |
| 458 | // is a exceptiona l key for an ontolog y. if so we will ad d this pro perty to t hat key | |
| 459 | for(pare ntKeyIndex = ontolog yDelimiter Keys.lengt h - 1; par entKeyInde x >= 0; -- parentKeyI ndex) | |
| 460 | { | |
| 461 | if(ontolog yDelimiter Keys[paren tKeyIndex] .containsE xceptional Key(key)) | |
| 462 | { | |
| 463 | br eak; | |
| 464 | } | |
| 465 | } | |
| 466 | } | |
| 467 | ||
| 468 | // if the new li ne is a ro ot line | |
| 469 | if(ont ologyKeyIn dex == 0) | |
| 470 | { | |
| 471 | logger.d ebug("Root line dete cted '" + line + "'. "); | |
| 472 | ||
| 473 | ParsedVi staLine ro ot = new P arsedVista Line(key, values); | |
| 474 | parsedLi nes.add(ro ot); | |
| 475 | currentH ierarchyDe pth = 0; | |
| 476 | currentH ierarchyPa th[current HierarchyD epth] = ro ot; | |
| 477 | } | |
| 478 | ||
| 479 | // if the new li ne is just a propert y | |
| 480 | else i f(ontology KeyIndex = = -1) | |
| 481 | { | |
| 482 | logger.d ebug("Prop erty line detected ' " + line + "'."); | |
| 483 | ParsedVi staLine pa rent = nul l; | |
| 484 | // if th e parent k ey index i s not -1, then there is a pare nt key ind ex to use, not the c urrent one | |
| 485 | if(paren tKeyIndex >= 0) | |
| 486 | { | |
| 487 | parent = c urrentHier archyPath[ parentKeyI ndex]; | |
| 488 | } | |
| 489 | else | |
| 490 | { | |
| 491 | parent = c urrentHier archyPath[ currentHie rarchyDept h]; | |
| 492 | } | |
| 493 | if(paren t != null) | |
| 494 | parent.add Property(k ey, values ); | |
| 495 | else | |
| 496 | { | |
| 497 | if(discard UnknownRoo tLines) | |
| 498 | lo gger.warn( "There is no current line to a dd unknown line '" + line + "' to, disca rding."); | |
| 499 | else | |
| 500 | pa rsedLines. add( new P arsedVista Line(key, values) ); | |
| 501 | } | |
| 502 | } | |
| 503 | ||
| 504 | // if the key is a delimit er at the current hi erarchy le vel | |
| 505 | // and it is not the root level (whi ch we addr essed in t he preceed ing 'if' b lock) | |
| 506 | // cre ate a new ParsedVist aLine as a sibling o f the curr ent | |
| 507 | // and make the new elemen t the curr ently acti ve element | |
| 508 | else i f(ontology KeyIndex = = currentH ierarchyDe pth) | |
| 509 | { | |
| 510 | logger.d ebug("Sibl ing delimi ter line d etected '" + line + "'."); | |
| 511 | ||
| 512 | ParsedVi staLine pa rent = cur rentHierar chyPath[on tologyKeyI ndex-1]; | |
| 513 | currentH ierarchyPa th[ontolog yKeyIndex] = parent. addChild(k ey, values ); | |
| 514 | } | |
| 515 | ||
| 516 | // if the key is a delimit er at the child hier erchy leve l | |
| 517 | // cre ate a new ParsedVist aLine as a child of the curren t | |
| 518 | // mak e the new element th e currentl y active e lement | |
| 519 | // set the curre nt depth t o the new deeper lev el | |
| 520 | else i f(ontology KeyIndex > currentHi erarchyDep th) | |
| 521 | { | |
| 522 | logger.d ebug("Desc endent del imiter lin e detected '" + line + "'."); | |
| 523 | ||
| 524 | ParsedVi staLine pa rent = cur rentHierar chyPath[cu rrentHiera rchyDepth] ; | |
| 525 | currentH ierarchyPa th[ontolog yKeyIndex] = parent. addChild(k ey, values ); | |
| 526 | currentH ierarchyDe pth = onto logyKeyInd ex; | |
| 527 | } | |
| 528 | ||
| 529 | // if the key is a delimit er at an a ncestor hi ererchy le vel | |
| 530 | // cre ate a new ParsedVist aLine | |
| 531 | // mak e the new element th e currentl y active e lement | |
| 532 | // set the curre nt depth t o the new shallower level | |
| 533 | else i f(ontology KeyIndex < currentHi erarchyDep th) | |
| 534 | { | |
| 535 | logger.d ebug("Ance stor delim iter line detected ' " + line + "'."); | |
| 536 | ||
| 537 | ParsedVi staLine pa rent = cur rentHierar chyPath[on tologyKeyI ndex-1]; | |
| 538 | currentH ierarchyPa th[ontolog yKeyIndex] = parent. addChild(k ey, values ); | |
| 539 | currentH ierarchyDe pth = onto logyKeyInd ex; | |
| 540 | } | |
| 541 | } | |
| 542 | ||
| 543 | retu rn parsedL ines; | |
| 544 | } | |
| 545 | ||
| 546 | /* * | |
| 547 | * A class t hat contai ns parsed lines from Vista wit h no seman tics appli ed, | |
| 548 | * other tha n recogniz ing "NEXT_ XXX" as a start deli miter. | |
| 549 | * | |
| 550 | * @author
|
|
| 551 | * | |
| 552 | * / | |
| 553 | st atic class ParsedVis taLine | |
| 554 | { | |
| 555 | priv ate final String key ; | |
| 556 | priv ate final List<Strin g> values; | |
| 557 | priv ate final List<Parse dVistaLine > properti es; | |
| 558 | priv ate final List<Parse dVistaLine > children ; | |
| 559 | ||
| 560 | Pars edVistaLin e(String k ey, String [] values) | |
| 561 | { | |
| 562 | this.k ey = key; | |
| 563 | this.v alues = ne w ArrayLis t<String>( ); | |
| 564 | if(val ues != nul l) | |
| 565 | for(Stri ng value : values) | |
| 566 | this.value s.add(valu e); | |
| 567 | this.p roperties = new Arra yList<Pars edVistaLin e>(); | |
| 568 | this.c hildren = new ArrayL ist<Parsed VistaLine> (); | |
| 569 | } | |
| 570 | ||
| 571 | /** | |
| 572 | * A Child is a line who se type in dicates an inferior position | |
| 573 | * i n the defi ned hierar chy. | |
| 574 | * | |
| 575 | * @ param key | |
| 576 | * @ param valu es | |
| 577 | * @ return | |
| 578 | */ | |
| 579 | Pars edVistaLin e addChild (String ke y, String[ ] values) | |
| 580 | { | |
| 581 | Parsed VistaLine child = ne w ParsedVi staLine(ke y, values) ; | |
| 582 | childr en.add( ch ild ); | |
| 583 | ||
| 584 | return child; | |
| 585 | } | |
| 586 | ||
| 587 | /** | |
| 588 | * A Property is a line whose type indicates an equiva lent posit ion | |
| 589 | * i n the defi ned hierar chy. | |
| 590 | * | |
| 591 | * @ param key | |
| 592 | * @ param valu es | |
| 593 | * @ return | |
| 594 | */ | |
| 595 | Pars edVistaLin e addPrope rty(String key, Stri ng[] value s) | |
| 596 | { | |
| 597 | Parsed VistaLine property = new Parse dVistaLine (key, valu es); | |
| 598 | proper ties.add( property ) ; | |
| 599 | ||
| 600 | return property; | |
| 601 | } | |
| 602 | ||
| 603 | Stri ng getKey( ) | |
| 604 | { | |
| 605 | retu rn key; | |
| 606 | } | |
| 607 | ||
| 608 | Iter ator<Strin g> valuesI terator() | |
| 609 | { | |
| 610 | retu rn values. iterator() ; | |
| 611 | } | |
| 612 | ||
| 613 | It erator<Par sedVistaLi ne> proper tyIterator () | |
| 614 | { | |
| 615 | retu rn propert ies.iterat or(); | |
| 616 | } | |
| 617 | ||
| 618 | It erator<Par sedVistaLi ne> childI terator() | |
| 619 | { | |
| 620 | retu rn childre n.iterator (); | |
| 621 | } | |
| 622 | ||
| 623 | St ring getVa lueAtIndex (int index ) | |
| 624 | { | |
| 625 | retu rn values. get(index) ; | |
| 626 | } | |
| 627 | ||
| 628 | bo olean isVa luteAtInde xExists(in t index) | |
| 629 | { | |
| 630 | if(i ndex < 0) | |
| 631 | return false; | |
| 632 | if(i ndex >= va lues.size( )) | |
| 633 | return false; | |
| 634 | retu rn true; | |
| 635 | } | |
| 636 | ||
| 637 | Pa rsedVistaL ine getPro pertyAtInd ex(int ind ex) | |
| 638 | { | |
| 639 | retu rn propert ies.get(in dex); | |
| 640 | } | |
| 641 | ||
| 642 | Pa rsedVistaL ine getChi ldAtIndex( int index) | |
| 643 | { | |
| 644 | retu rn childre n.get(inde x); | |
| 645 | } | |
| 646 | ||
| 647 | Pa rsedVistaL ine getPro perty(Stri ng key) | |
| 648 | { | |
| 649 | for( Iterator<P arsedVista Line> iter = propert yIterator( ); iter.ha sNext(); ) | |
| 650 | { | |
| 651 | Parsed VistaLine property = iter.next (); | |
| 652 | if( ke y.equals(p roperty.ge tKey()) ) | |
| 653 | return p roperty; | |
| 654 | } | |
| 655 | ||
| 656 | retu rn null; | |
| 657 | } | |
| 658 | ||
| 659 | /* * | |
| 660 | * The keys must match and the | |
| 661 | * propertie s and chil dren must also be eq uals and i n the same order. | |
| 662 | * | |
| 663 | * @see java .lang.Obje ct#equals( java.lang. Object) | |
| 664 | * / | |
| 665 | @O verride | |
| 666 | pu blic boole an equals( Object obj ) | |
| 667 | { | |
| 668 | if(o bj instanc eof Parsed VistaLine) | |
| 669 | { | |
| 670 | Parsed VistaLine that = (Pa rsedVistaL ine)obj; | |
| 671 | ||
| 672 | if( th is.getKey( ) == null && that.ge tKey() != null || | |
| 673 | this.get Key() != n ull && tha t.getKey() == null | | | |
| 674 | ! this.g etKey().eq uals(that. getKey()) ) | |
| 675 | { | |
| 676 | logger.i nfo("this. key '" + t his.getKey () + "' is not equal to that.k ey '" + th at.getKey( ) + "'."); | |
| 677 | return f alse; | |
| 678 | } | |
| 679 | ||
| 680 | if(thi s.values.s ize() != t hat.values .size()) | |
| 681 | { | |
| 682 | logger.i nfo("this. values.siz e '" + thi s.values.s ize() + "' is not eq ual to tha t.values.s ize '" + t hat.values .size() + "'."); | |
| 683 | return f alse; | |
| 684 | } | |
| 685 | ||
| 686 | Iterat or<String> thisValue Iterator = this.valu esIterator (); | |
| 687 | Iterat or<String> thatValue Iterator = that.valu esIterator (); | |
| 688 | for(; thisValueI terator.ha sNext() && thatValue Iterator.h asNext(); ) | |
| 689 | { | |
| 690 | String t hisValue = thisValue Iterator.n ext(); | |
| 691 | String t hatValue = thatValue Iterator.n ext(); | |
| 692 | if(! thi sValue.equ als(thatVa lue)) | |
| 693 | { | |
| 694 | logger.i nfo("this( " + this.g etKey() + ").value ' " + thisVa lue + | |
| 695 | "' is not eq ual to tha t(" + that .getKey() + ").value '" + that Value + "' ."); | |
| 696 | return fal se; | |
| 697 | } | |
| 698 | } | |
| 699 | ||
| 700 | if(thi s.properti es.size() != that.pr operties.s ize()) | |
| 701 | { | |
| 702 | logger.i nfo("this. properties .size '" + this.prop erties.siz e() + "' i s not equa l to that. properties .size '" + that.prop erties.siz e() + "'." ); | |
| 703 | return f alse; | |
| 704 | } | |
| 705 | ||
| 706 | Iterat or<ParsedV istaLine> thisProper tyIterator = this.pr opertyIter ator(); | |
| 707 | Iterat or<ParsedV istaLine> thatProper tyIterator = that.pr opertyIter ator(); | |
| 708 | for(; thisProper tyIterator .hasNext() && thatPr opertyIter ator.hasNe xt(); ) | |
| 709 | { | |
| 710 | ParsedVi staLine th isProperty = thisPro pertyItera tor.next() ; | |
| 711 | ParsedVi staLine th atProperty = thatPro pertyItera tor.next() ; | |
| 712 | if(! thi sProperty. equals(tha tProperty) ) | |
| 713 | return fal se; | |
| 714 | } | |
| 715 | ||
| 716 | if(thi s.children .size() != that.chil dren.size( )) | |
| 717 | { | |
| 718 | logger.i nfo("this. children.s ize '" + t his.childr en.size() + "' is no t equal to that.chil dren.size '" + that. children.s ize() + "' ."); | |
| 719 | return f alse; | |
| 720 | } | |
| 721 | ||
| 722 | Iterat or<ParsedV istaLine> thisChildI terator = this.child Iterator() ; | |
| 723 | Iterat or<ParsedV istaLine> thatChildI terator = that.child Iterator() ; | |
| 724 | for(; thisChildI terator.ha sNext() && thatChild Iterator.h asNext(); ) | |
| 725 | { | |
| 726 | ParsedVi staLine th isChild = thisChildI terator.ne xt(); | |
| 727 | ParsedVi staLine th atChild = thatChildI terator.ne xt(); | |
| 728 | if(! thi sChild.equ als(thatCh ild)) | |
| 729 | return fal se; | |
| 730 | } | |
| 731 | ||
| 732 | return true; | |
| 733 | } | |
| 734 | ||
| 735 | retu rn false; | |
| 736 | } | |
| 737 | ||
| 738 | @O verride | |
| 739 | pu blic Strin g toString () | |
| 740 | { | |
| 741 | Stri ngBuilder sb = new S tringBuild er(); | |
| 742 | ||
| 743 | sb.a ppend("Par sedVistaLi ne \r"); | |
| 744 | ||
| 745 | sb.a ppend("\tK ey :'"); | |
| 746 | sb.a ppend(key) ; | |
| 747 | sb.a ppend("'\r "); | |
| 748 | ||
| 749 | sb.a ppend("\tV alues :'") ; | |
| 750 | for( String val ue : value s) | |
| 751 | sb.app end(value + " "); | |
| 752 | sb.a ppend("'\r "); | |
| 753 | ||
| 754 | retu rn sb.toSt ring(); | |
| 755 | } | |
| 756 | } | |
| 757 | ||
| 758 | /* * | |
| 759 | * Represent s an ontol ogy key in the study , series, instance h ierearchy | |
| 760 | * | |
| 761 | * @author v haiswwerfe j | |
| 762 | * | |
| 763 | * / | |
| 764 | st atic class OntologyD elimiterKe y | |
| 765 | { | |
| 766 | priv ate final String key ; | |
| 767 | priv ate final String[] e xceptional Keys; | |
| 768 | ||
| 769 | /** | |
| 770 | * C reate an o ntology de limiter ke y with no exceptiona l keys | |
| 771 | * | |
| 772 | * @ param key | |
| 773 | */ | |
| 774 | Onto logyDelimi terKey(Str ing key) | |
| 775 | { | |
| 776 | this.k ey = key; | |
| 777 | except ionalKeys = null; | |
| 778 | } | |
| 779 | ||
| 780 | /** | |
| 781 | * C reate an o ntology de limiter ke y with exc eptional k eys | |
| 782 | * @ param key | |
| 783 | * @ param exce ptionalKey s | |
| 784 | */ | |
| 785 | Onto logyDelimi terKey(Str ing key, S tring [] e xceptional Keys) | |
| 786 | { | |
| 787 | this.k ey = key; | |
| 788 | this.e xceptional Keys = exc eptionalKe ys; | |
| 789 | } | |
| 790 | ||
| 791 | /** | |
| 792 | * @ return the key | |
| 793 | */ | |
| 794 | publ ic String getKey() { | |
| 795 | return key; | |
| 796 | } | |
| 797 | ||
| 798 | /** | |
| 799 | * @ return the exception alKeys | |
| 800 | */ | |
| 801 | publ ic String[ ] getExcep tionalKeys () { | |
| 802 | return exception alKeys; | |
| 803 | } | |
| 804 | ||
| 805 | publ ic boolean containsE xceptional Key(String searchExc eptionalKe y) | |
| 806 | { | |
| 807 | if(exc eptionalKe ys == null ) | |
| 808 | return f alse; | |
| 809 | if(sea rchExcepti onalKey == null) | |
| 810 | return f alse; | |
| 811 | for(St ring excep tionalKey : exceptio nalKeys) | |
| 812 | { | |
| 813 | if(excep tionalKey. equals(sea rchExcepti onalKey)) | |
| 814 | return tru e; | |
| 815 | } | |
| 816 | return false; | |
| 817 | } | |
| 818 | } | |
| 819 | ||
| 820 | pu blic stati c PatientM eansTestRe sult conve rtMeansTes tResult(St ring rtn, String pat ientDfn) | |
| 821 | th rows Vista MethodExce ption | |
| 822 | { | |
| 823 | if( (rtn == nu ll) || (rt n.equals(" -1")) ) | |
| 824 | { | |
| 825 | String msg = "Er ror respon se while c hecking pa tient mean s test; DF N=" + pati entDfn; | |
| 826 | logger .error(msg ); | |
| 827 | throw new VistaM ethodExcep tion(msg); | |
| 828 | } | |
| 829 | Stri ng [] line s = rtn.sp lit(String Utils.NEW_ LINE); | |
| 830 | if(l ines.lengt h <= 0) | |
| 831 | { | |
| 832 | String msg = "Er ror parsin g response from chec king patie nt means t est; DFN=" + patient Dfn; | |
| 833 | logger .error(msg ); | |
| 834 | logger .error("Vi stA Respon se [" + rt n + "]"); | |
| 835 | throw new VistaM ethodExcep tion(msg); | |
| 836 | } | |
| 837 | int code = Int eger.parse Int(lines[ 0].trim()) ; | |
| 838 | logg er.debug(" Means test for patie nt (DFN): '" + patie ntDfn + "' is '" + c ode + "'") ; | |
| 839 | Stri ngBuilder sb = new S tringBuild er(); | |
| 840 | for( int i = 1; i < lines .length; i ++) | |
| 841 | { | |
| 842 | sb.app end(lines[ i]); | |
| 843 | if(i ! = (lines.l ength - 1) ) | |
| 844 | sb.appen d("\n"); | |
| 845 | } | |
| 846 | retu rn new Pat ientMeansT estResult( code, sb.t oString()) ; | |
| 847 | } | |
| 848 | ||
| 849 | /* | |
| 850 | * | |
| 851 | 6 44^PHOENIX , AZ^30502 29^^1 | |
| 852 | 6 88^WASHING TON, DC^30 50229^^1 | |
| 853 | 7 56^EL PASO , TX^30502 29^^1 | |
| 854 | 2 00^DEPT. O F DEFENSE^ 3050229^^1 | |
| 855 | * / | |
| 856 | pu blic stati c List<Str ing> conve rtCprsSite List(Strin g rtn) | |
| 857 | { | |
| 858 | List <String> s ites = new LinkedLis t<String>( ); | |
| 859 | if(( rtn == nul l) || (rtn .equals("" ))) | |
| 860 | return sites; | |
| 861 | Stri ng [] line s = String Utils.Spli t(rtn, Str ingUtils.N EW_LINE); | |
| 862 | for( String lin e : lines) | |
| 863 | { | |
| 864 | String [] pieces = StringU tils.Split (line, Str ingUtils.C ARET); | |
| 865 | sites. add(pieces [0]); | |
| 866 | } | |
| 867 | retu rn sites; | |
| 868 | } | |
| 869 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.