| 26 | | |
|---|
| 27 | | /** |
|---|
| 28 | | * Returns a list of file names within a specific directory |
|---|
| 29 | | * |
|---|
| 30 | | * @param xmlDirectory specific directory |
|---|
| 31 | | * @return String[] list of file names |
|---|
| 32 | | */ |
|---|
| 33 | | public static String[] getFilesInDirectory(String xmlDirectory) |
|---|
| 34 | | { |
|---|
| 35 | | File dir = new File(xmlDirectory); |
|---|
| 36 | | |
|---|
| 37 | | return dir.list(); |
|---|
| 38 | | } |
|---|
| 39 | | |
|---|
| 40 | | /** |
|---|
| 41 | | * Returns the file name without an extension or directory path |
|---|
| 42 | | * @param filepath path to the file |
|---|
| 43 | | * @return String file name without an extension or directory path |
|---|
| 44 | | */ |
|---|
| 45 | | public static String getFilenameWithoutExtension(String filepath) |
|---|
| 46 | | { |
|---|
| 47 | | String filename = filepath; |
|---|
| 48 | | int index = filename.lastIndexOf("/"); |
|---|
| 49 | | int index2 = filename.lastIndexOf("\\"); |
|---|
| 50 | | |
|---|
| 51 | | if(index2 > index) |
|---|
| 52 | | { |
|---|
| 53 | | index = index2; |
|---|
| 54 | | } |
|---|
| 55 | | |
|---|
| 56 | | if(index>-1) |
|---|
| 57 | | { |
|---|
| 58 | | filename = filename.substring(index+1); |
|---|
| 59 | | } |
|---|
| 60 | | |
|---|
| 61 | | index = filename.lastIndexOf("."); |
|---|
| 62 | | |
|---|
| 63 | | if(index > -1) |
|---|
| 64 | | { |
|---|
| 65 | | filename = filename.substring(0,index); |
|---|
| 66 | | } |
|---|
| 67 | | |
|---|
| 68 | | return filename; |
|---|
| 69 | | } |
|---|
| 100 | | * Calculates age to a precision of days, weeks, months, or years based on a |
|---|
| 101 | | * set of rules |
|---|
| 102 | | * |
|---|
| 103 | | * @param birthdate patient's birth date |
|---|
| 104 | | * @param cutoff date to calculate age from |
|---|
| 105 | | * @return String age with units |
|---|
| 106 | | */ |
|---|
| 107 | | public static String adjustAgeUnits(Date birthdate, Date cutoff) |
|---|
| 108 | | { |
|---|
| 109 | | int years = getAgeInUnits(birthdate, cutoff, YEAR_ABBR); |
|---|
| 110 | | int months = getAgeInUnits(birthdate, cutoff, MONTH_ABBR); |
|---|
| 111 | | int weeks = getAgeInUnits(birthdate, cutoff, WEEK_ABBR); |
|---|
| 112 | | int days = getAgeInUnits(birthdate, cutoff, DAY_ABBR); |
|---|
| 113 | | |
|---|
| 114 | | if (years >= 2) |
|---|
| 115 | | { |
|---|
| 116 | | return years + " " + YEAR_ABBR; |
|---|
| 117 | | } |
|---|
| 118 | | |
|---|
| 119 | | if (months >= 2) |
|---|
| 120 | | { |
|---|
| 121 | | return months + " " + MONTH_ABBR; |
|---|
| 122 | | } |
|---|
| 123 | | |
|---|
| 124 | | if (days > 30) |
|---|
| 125 | | { |
|---|
| 126 | | return weeks + " " + WEEK_ABBR; |
|---|
| 127 | | } |
|---|
| 128 | | |
|---|
| 129 | | return days + " " + DAY_ABBR; |
|---|
| 130 | | } |
|---|
| 131 | | |
|---|
| 132 | | /** |
|---|
| 133 | | * Returns a person's age in the specified units (days, weeks, months, years) |
|---|
| 134 | | * |
|---|
| 135 | | * @param birthdate person's date of birth |
|---|
| 136 | | * @param today date to calculate age from |
|---|
| 137 | | * @param unit unit to calculate age in (days, weeks, months, years) |
|---|
| 138 | | * @return int age in the given units |
|---|
| 139 | | */ |
|---|
| 140 | | public static int getAgeInUnits(Date birthdate, Date today, String unit) |
|---|
| 141 | | { |
|---|
| 142 | | if (birthdate == null) |
|---|
| 143 | | { |
|---|
| 144 | | return 0; |
|---|
| 145 | | } |
|---|
| 146 | | |
|---|
| 147 | | if (today == null) |
|---|
| 148 | | { |
|---|
| 149 | | today = new Date(); |
|---|
| 150 | | } |
|---|
| 151 | | |
|---|
| 152 | | int diffMonths = 0; |
|---|
| 153 | | int diffWeeks = 0; |
|---|
| 154 | | int diffDays = 0; |
|---|
| 155 | | int years = 0; |
|---|
| 156 | | int months = 0; |
|---|
| 157 | | int weeks = 0; |
|---|
| 158 | | int days = 0; |
|---|
| 159 | | |
|---|
| 160 | | Calendar birthdateCalendar = Calendar.getInstance(); |
|---|
| 161 | | birthdateCalendar.setTime(birthdate); |
|---|
| 162 | | Calendar todayCalendar = Calendar.getInstance(); |
|---|
| 163 | | todayCalendar.setTime(today); |
|---|
| 164 | | |
|---|
| 165 | | // return 0 if the birthdate is after today |
|---|
| 166 | | if (birthdate.compareTo(today) > 0) |
|---|
| 167 | | { |
|---|
| 168 | | return 0; |
|---|
| 169 | | } |
|---|
| 170 | | |
|---|
| 171 | | years = todayCalendar.get(Calendar.YEAR) |
|---|
| 172 | | - birthdateCalendar.get(Calendar.YEAR); |
|---|
| 173 | | diffMonths = todayCalendar.get(Calendar.MONTH) |
|---|
| 174 | | - birthdateCalendar.get(Calendar.MONTH); |
|---|
| 175 | | diffWeeks = todayCalendar.get(Calendar.WEEK_OF_YEAR) |
|---|
| 176 | | - birthdateCalendar.get(Calendar.WEEK_OF_YEAR); |
|---|
| 177 | | diffDays = todayCalendar.get(Calendar.DAY_OF_YEAR) |
|---|
| 178 | | - birthdateCalendar.get(Calendar.DAY_OF_YEAR); |
|---|
| 179 | | |
|---|
| 180 | | months = years * 12; |
|---|
| 181 | | months += diffMonths; |
|---|
| 182 | | |
|---|
| 183 | | weeks = years * 52; |
|---|
| 184 | | weeks += diffWeeks; |
|---|
| 185 | | |
|---|
| 186 | | days = years * 365; |
|---|
| 187 | | days += diffDays; |
|---|
| 188 | | |
|---|
| 189 | | if (unit.equalsIgnoreCase(YEAR_ABBR)) |
|---|
| 190 | | { |
|---|
| 191 | | if (diffMonths < 0) |
|---|
| 192 | | { |
|---|
| 193 | | years--; |
|---|
| 194 | | } |
|---|
| 195 | | return years; |
|---|
| 196 | | } |
|---|
| 197 | | |
|---|
| 198 | | if (unit.equalsIgnoreCase(MONTH_ABBR)) |
|---|
| 199 | | { |
|---|
| 200 | | if (diffWeeks < 0) |
|---|
| 201 | | { |
|---|
| 202 | | months--; |
|---|
| 203 | | } |
|---|
| 204 | | return months; |
|---|
| 205 | | } |
|---|
| 206 | | |
|---|
| 207 | | if (unit.equalsIgnoreCase(WEEK_ABBR)) |
|---|
| 208 | | { |
|---|
| 209 | | if (diffDays < 0) |
|---|
| 210 | | { |
|---|
| 211 | | weeks--; |
|---|
| 212 | | } |
|---|
| 213 | | return weeks; |
|---|
| 214 | | } |
|---|
| 215 | | |
|---|
| 216 | | if (days < 0) |
|---|
| 217 | | { |
|---|
| 218 | | days = 0; |
|---|
| 219 | | } |
|---|
| 220 | | return days; |
|---|
| 221 | | } |
|---|
| 222 | | |
|---|
| 223 | | /** |
|---|