Produced by Araxis Merge on 12/5/2017 12:06:39 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\DicomCodecImpl\main\src\java\gov\va\med\imaging\dicom | DicomDateFormat.java | Mon Dec 4 21:34:32 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\DicomCodecImpl\main\src\java\gov\va\med\imaging\dicom | DicomDateFormat.java | Tue Dec 5 12:43:36 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 532 |
| 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 | /** | |
| 2 | * | |
| 3 | */ | |
| 4 | package go v.va.med.i maging.dic om; | |
| 5 | ||
| 6 | import jav a.text.*; | |
| 7 | import jav a.util.*; | |
| 8 | import org .apache.lo gging.log4 j.LogManag er; | |
| 9 | import org .apache.lo gging.log4 j.Logger; | |
| 10 | import jav a.util.reg ex.Matcher ; | |
| 11 | import jav a.util.reg ex.Pattern ; | |
| 12 | ||
| 13 | /** | |
| 14 | * A date formatter for DICOM date-time data eleme nts (DT). | |
| 15 | * | |
| 16 | * ======= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ==== | |
| 17 | * From th e DICOM Sp ec (06.05 pg.26): | |
| 18 | * "The Da te Time co mmon data type. Indi cates a co ncatenated date-time ASCII str ing in the format: Y YYYMMDDHHM MSS.FFFFFF &ZZZZ | |
| 19 | * The com ponents of this stri ng, from l eft to rig ht, are | |
| 20 | * YYYY = Year, | |
| 21 | * MM = Mo nth, | |
| 22 | * DD = Da y, | |
| 23 | * HH = Ho ur, | |
| 24 | * MM = Mi nute, | |
| 25 | * SS = Se cond, | |
| 26 | * FFFFFF = Fraction al Second, | |
| 27 | * & = “+” or “-”, a nd | |
| 28 | * ZZZZ = Hours and Minutes of offset. | |
| 29 | * &ZZZZ i s an optio nal suffix for plus/ minus offs et from Co ordinated Universal Time. A co mponent th at is omit ted from t he string is | |
| 30 | * termed a null com ponent. Tr ailing nul l componen ts of Date Time are ignored. N ontrailing null comp onents are prohibite d, given | |
| 31 | * that th e optional suffix is not consi dered as a component . | |
| 32 | * Note: F or reasons of backwa rd compati bility wit h versions of this s tandard pr ior to V3. 0, many ex isting DIC OM Data | |
| 33 | * Element s use the separate D A and TM V Rs. Standa rd and Pri vate Data Elements d efined in the future should us e DT, when | |
| 34 | * appropr iate, to b e more com pliant wit h ANSI HIS PP MSDS." | |
| 35 | * ======= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ==== | |
| 36 | * | |
| 37 | * NOTES | |
| 38 | * 1.) Thi s class DO ES NOT sup port the b ackward co mpatibilit y mentione d above fo r versions before 3. 0. | |
| 39 | * 2.) The DICOM spe cification does not specify th e calendar used for date inter pretation. This cla ss | |
| 40 | * always uses a Gre gorian cal endar. | |
| 41 | * 3.) The timezone is default ed to the default ti mezone for the VM if it is not specified . | |
| 42 | * 4.) DIC OM uses 1- indexing f or months. | |
| 43 | * ======= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ==== | |
| 44 | * | |
| 45 | * @author
|
|
| 46 | */ | |
| 47 | public cla ss DicomDa teFormat | |
| 48 | extends Si mpleDateFo rmat | |
| 49 | { | |
| 50 | pr ivate stat ic final l ong serial VersionUID = -138146 1230116366 880L; | |
| 51 | ||
| 52 | // YYYYMMDDH HMMSS.FFFF FF+ZZZZ | |
| 53 | // The compo nents of t his string , from lef t to right , are | |
| 54 | // YYYY = Ye ar, | |
| 55 | // MM = Mont h, | |
| 56 | // DD = Day, | |
| 57 | // HH = Hour , | |
| 58 | // MM = Minu te, | |
| 59 | // SS = Seco nd, | |
| 60 | // FFFFFF = millisecon ds | |
| 61 | // ZZZZZ - t imezone of fset (firs t digit is + or - | |
| 62 | pr ivate fina l static S tring dico mDateForma t = "yyyyM MddHHmmss. SSSSSSZZZZ Z"; | |
| 63 | ||
| 64 | // The regul are expres sion patte rn should read as: | |
| 65 | // requ ired 4 d igits (the year) | |
| 66 | // opti onally 2 d igit (the month of t he year) | |
| 67 | // opti onally 2 d igit (the day of the month) | |
| 68 | // opti onally 2 d igits (for each of t he hour, m inute and seconds) | |
| 69 | // opti onally 1 d ecimal poi nt followe d by 4 or 6 digits ( for the mi lliseconds ) | |
| 70 | // opti onally 1 ' +' or '-' followed b y 4 digits , 2 for ho urs and 2 for minute s (for the offset fr om UCT) | |
| 71 | pr ivate fina l static S tring dico mDateRegex = "(\\d{4 })(\\d{2}) ?(\\d{2})? (\\d{2})?( \\d{2})?(\ \d{2})?(\\ .(\\d{4}|\ \d{6}))?(( [+|-]\\d{4 }))?"; | |
| 72 | ||
| 73 | pr ivate stat ic final i nt yearGro upIndex = 1; | |
| 74 | pr ivate stat ic final i nt monthGr oupIndex = 2; | |
| 75 | pr ivate stat ic final i nt dayGrou pIndex = 3 ; | |
| 76 | pr ivate stat ic final i nt hourGro upIndex = 4; | |
| 77 | pr ivate stat ic final i nt minuteG roupIndex = 5; | |
| 78 | pr ivate stat ic final i nt secondG roupIndex = 6; | |
| 79 | pr ivate stat ic final i nt millise condGroupI ndex = 8; | |
| 80 | pr ivate stat ic final i nt timezon eGroupInde x = 9; | |
| 81 | ||
| 82 | // during pr ocessing i t may be n ecessary t o calculat e a date t o use for timezone | |
| 83 | // determina tion, this is NOT th e DateForm at used to do our fo rmatting o r parsing | |
| 84 | pr ivate Date Format uti lityDateFo rmat = new SimpleDat eFormat("y yyyMMddhhm mss.SSSSSS "); | |
| 85 | ||
| 86 | // a NumberF ormat used to build timezone f ormatted s trings | |
| 87 | pr ivate Numb erFormat t imezoneNum berFormat = new Deci malFormat( "+0000;-00 00"); | |
| 88 | ||
| 89 | /* * | |
| 90 | * Construct a DicomDa teFormat i nstance us ing the de fault loca le. | |
| 91 | * | |
| 92 | * / | |
| 93 | pu blic Dicom DateFormat () | |
| 94 | { | |
| 95 | supe r(dicomDat eFormat); | |
| 96 | supe r.setCalen dar(new Gr egorianCal endar()); | |
| 97 | } | |
| 98 | ||
| 99 | /* * | |
| 100 | * Construct a DicomDa teFormat i nstance sp ecifying a locale. | |
| 101 | * | |
| 102 | * @param lo cale | |
| 103 | * / | |
| 104 | pu blic Dicom DateFormat (Locale lo cale) | |
| 105 | { | |
| 106 | supe r(dicomDat eFormat, l ocale); | |
| 107 | supe r.setCalen dar(new Gr egorianCal endar()); | |
| 108 | } | |
| 109 | ||
| 110 | /* * | |
| 111 | * Method do es nothing , the date format pa ttern is d efined by the class. | |
| 112 | * | |
| 113 | * @see java .text.Simp leDateForm at#applyLo calizedPat tern(java. lang.Strin g) | |
| 114 | * / | |
| 115 | @O verride | |
| 116 | pu blic void applyLocal izedPatter n(String p attern) {} | |
| 117 | ||
| 118 | /* * | |
| 119 | * Method do es nothing , the date format pa ttern is d efined by the class. | |
| 120 | * | |
| 121 | * @see java .text.Simp leDateForm at#applyPa ttern(java .lang.Stri ng) | |
| 122 | * / | |
| 123 | @O verride | |
| 124 | pu blic void applyPatte rn(String pattern){} | |
| 125 | ||
| 126 | /* * | |
| 127 | * Method do es nothing , the Cale ndar is de fined by t he class a s a Gregor ian calend ar instanc e. | |
| 128 | * | |
| 129 | * @see java .text.Date Format#set Calendar(j ava.util.C alendar) | |
| 130 | * / | |
| 131 | @O verride | |
| 132 | pu blic void setCalenda r(Calendar newCalend ar){} | |
| 133 | ||
| 134 | /* * | |
| 135 | * @throws P arseExcept ion | |
| 136 | * | |
| 137 | * / | |
| 138 | @O verride | |
| 139 | pu blic Date parse(Stri ng dicomFo rmattedDat e) | |
| 140 | th rows Parse Exception | |
| 141 | { | |
| 142 | Stri ng year = null; | |
| 143 | Stri ng month = null; | |
| 144 | Stri ng day = n ull; | |
| 145 | Stri ng hour = null; | |
| 146 | Stri ng minute = null; | |
| 147 | Stri ng second = null; | |
| 148 | Stri ng millise cond = nul l; | |
| 149 | Stri ng timezon eOffset = null; | |
| 150 | ||
| 151 | Patt ern dicomP attern = P attern.com pile(dicom DateRegex) ; | |
| 152 | ||
| 153 | Matc her matche r = dicomP attern.mat cher(dicom FormattedD ate); | |
| 154 | if( ! matcher. matches() ) | |
| 155 | throw new ParseE xception(" '" + dicom FormattedD ate + "' i s not a va lid DICOM date.", 0) ; | |
| 156 | ||
| 157 | year = matcher .group(yea rGroupInde x); | |
| 158 | ||
| 159 | mont h = match er.group(m onthGroupI ndex); | |
| 160 | mont h = (month == null ? "01" : mo nth); | |
| 161 | int monthInt = Integer.p arseInt(mo nth); | |
| 162 | if(m onthInt < 1 || month Int > 12) | |
| 163 | throw new ParseE xception(" Month must be betwee n 01 and 1 1", 3); | |
| 164 | ||
| 165 | day = matcher .group(day GroupIndex ); | |
| 166 | day = (day == null ? "01 " : day); | |
| 167 | ||
| 168 | hour = matche r.group(ho urGroupInd ex); | |
| 169 | hour = (hour = = null ? " 00" : hour ); | |
| 170 | ||
| 171 | minu te = match er.group(m inuteGroup Index); | |
| 172 | minu te = (minu te == null ? "00" : minute); | |
| 173 | ||
| 174 | seco nd = matc her.group( secondGrou pIndex); | |
| 175 | seco nd = (seco nd == null ? "00" : second); | |
| 176 | ||
| 177 | mill isecond = matcher.g roup(milli secondGrou pIndex); | |
| 178 | mill isecond = (milliseco nd == null ? "000000 " : millis econd); | |
| 179 | ||
| 180 | time zoneOffset = matche r.group(ti mezoneGrou pIndex); | |
| 181 | if(t imezoneOff set == nul l) | |
| 182 | { | |
| 183 | Date d ate = util ityDateFor mat.parse( year + mon th + day + hour + mi nute + sec ond + "." + millisec ond); | |
| 184 | ||
| 185 | // get Offset() r eturns the amount of time in m illisecond s to add t o UTC to g et local t ime. | |
| 186 | int of fset = Tim eZone.getD efault().g etOffset(d ate.getTim e()); | |
| 187 | ||
| 188 | int of fsetMinute s = offset / (1000 * 60); | |
| 189 | int of fsetHours = offsetMi nutes / 60 ; | |
| 190 | offset Minutes %= 60; | |
| 191 | ||
| 192 | timezo neOffset = timezoneN umberForma t.format(o ffsetHours * 100 + o ffsetMinut es); | |
| 193 | } | |
| 194 | ||
| 195 | //fo r(int grou pIndex=0; groupIndex < matcher .groupCoun t(); ++gro upIndex) | |
| 196 | //{ | |
| 197 | // String group = m atcher.gro up(groupIn dex); | |
| 198 | // System .out.print ln("\tGrou p [" + gro upIndex + "] = '" + group + "' "); | |
| 199 | //} | |
| 200 | Stri ng concate natedTime = year + m onth + day + hour + minute + s econd + ". " + millis econd + ti mezoneOffs et; | |
| 201 | ||
| 202 | LogM anager.get Logger(thi s.getClass ().getName ()).info(" Parsing co ncatenated time '" + concatena tedTime + "'."); | |
| 203 | retu rn super.p arse(conca tenatedTim e); | |
| 204 | } | |
| 205 | ||
| 206 | /* * | |
| 207 | * @see java .text.Simp leDateForm at#equals( java.lang. Object) | |
| 208 | * / | |
| 209 | @O verride | |
| 210 | pu blic boole an equals( Object obj ) | |
| 211 | { | |
| 212 | retu rn obj ins tanceof Di comDateFor mat && sup er.equals( obj); | |
| 213 | } | |
| 214 | ||
| 215 | /* * | |
| 216 | * This is s imply a te st driver for develo pment. | |
| 217 | * | |
| 218 | * @param ar gv | |
| 219 | * / | |
| 220 | pu blic stati c void mai n(String [ ] argv) | |
| 221 | { | |
| 222 | Date Format out putDf = ne w SimpleDa teFormat(" dd-MMM-yyy y @ hh:mm: ss.SSSS ZZ ZZZ"); | |
| 223 | try | |
| 224 | { | |
| 225 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 7")) ); // year | |
| 226 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 712")) ); // year, m onth | |
| 227 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 71230")) ) ; // year, month, da y | |
| 228 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 7123012")) ); // yea r, month, day, hour | |
| 229 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 712301234" )) ); // y ear, month , day, hou r, minute | |
| 230 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 7123012345 6")) ); // year, mon th, day, h our, minut e, second | |
| 231 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 7123012345 6.9999")) ); // year , month, d ay, hour, minute, se cond, mill isecond | |
| 232 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 7123012345 6.999999") ) ); // ye ar, month, day, hour , minute, second, mi llisecond | |
| 233 | ||
| 234 | // rep eat all of the above with posi tive timez one | |
| 235 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 7+0500")) ); // year | |
| 236 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 712+0500") ) ); // ye ar, month | |
| 237 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 71230+0500 ")) ); // year, mont h, day | |
| 238 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 7123012+05 00")) ); / / year, mo nth, day, hour | |
| 239 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 712301234+ 0500")) ); // year, month, day , hour, mi nute | |
| 240 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 7123012345 6+0500")) ); // year , month, d ay, hour, minute, se cond | |
| 241 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 7123012345 6.9999+050 0")) ); // year, mon th, day, h our, minut e, second, milliseco nd | |
| 242 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 7123012345 6.999999+0 500")) ); // year, m onth, day, hour, min ute, secon d, millise cond | |
| 243 | ||
| 244 | // rep eat all of the above with nega tive timez one | |
| 245 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 7-0500")) ); // year | |
| 246 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 712-0500") ) ); // ye ar, month | |
| 247 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 71230-0500 ")) ); // year, mont h, day | |
| 248 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 7123012-05 00")) ); / / year, mo nth, day, hour | |
| 249 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 712301234- 0500")) ); // year, month, day , hour, mi nute | |
| 250 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 7123012345 6-0500")) ); // year , month, d ay, hour, minute, se cond | |
| 251 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 7123012345 6.9999-050 0")) ); // year, mon th, day, h our, minut e, second, milliseco nd | |
| 252 | System .out.print ln( "Resul t is '" + outputDf.f ormat(pars eDate("200 7123012345 6.999999-0 500")) ); // year, m onth, day, hour, min ute, secon d, millise cond | |
| 253 | } | |
| 254 | catc h(Exceptio n x) | |
| 255 | { | |
| 256 | x.prin tStackTrac e(); | |
| 257 | } | |
| 258 | } | |
| 259 | pr ivate stat ic Date pa rseDate(St ring dateS tring) | |
| 260 | th rows Parse Exception | |
| 261 | { | |
| 262 | Dico mDateForma t df = new DicomDate Format(); | |
| 263 | ||
| 264 | Syst em.out.pri ntln("Pars ing '" + d ateString + "'."); | |
| 265 | retu rn df.pars e(dateStri ng); | |
| 266 | } | |
| 267 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.