Changeset 3975
- Timestamp:
- 04/21/08 01:00:16 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs-modules/clinicalsummary/src/org/openmrs/module/clinicalsummary/SummaryExportFunctions.java
r3884 r3975 254 254 */ 255 255 public String getCD4CountReminder() throws Exception { 256 // days in milliseconds; 257 long ONE_DAY = 86400000; 258 long THREE_DAYS = ONE_DAY * 3; 259 // duplicate cd4 count flag. 256 260 boolean duplicateCD4Obs = false; 261 // output format for date 257 262 DateFormat reminderFormat = new SimpleDateFormat("MMMMM yyyy"); 258 263 DateFormat obsFormat = new SimpleDateFormat("dd-MMM-yyyy"); 264 // tomorrow 259 265 GregorianCalendar tomorrow = new GregorianCalendar(); 260 266 tomorrow.add(Calendar.DAY_OF_MONTH, 1); 261 GregorianCalendar sixMosAgo = new GregorianCalendar(); 262 sixMosAgo.add(Calendar.MONTH, -6); 263 GregorianCalendar conceptDatetime = new GregorianCalendar(); 267 // five months ago 268 GregorianCalendar fiveMosAgo = new GregorianCalendar(); 269 fiveMosAgo.add(Calendar.MONTH, -5); 270 // the time of this obs 271 GregorianCalendar obsDatetime = new GregorianCalendar(); 264 272 Concept cd4 = getConcept("5497"); // name='CD4, BY FACS' 265 273 Set<Obs> obs = Context.getObsService().getObservations(getPatient(), 266 274 cd4, false); 267 // No CD4 count. 275 /* 276 * No CD4 count. 277 */ 268 278 if (obs.isEmpty()) { 269 279 return "Please order CD4 count now (no prior CD4 count on record)."; 270 280 } 271 // More than one CD4 count 281 /* 282 * More than one CD4 count 283 */ 272 284 else if (obs.size() > 1) { 273 285 GregorianCalendar firstCD4 = new GregorianCalendar(); … … 285 297 } 286 298 if (Math 287 .abs(lastCD4.getTimeInMillis() - firstCD4.getTimeInMillis()) < 86400000) { 288 // All CD4's have been taken within the same 24 hour time span. 289 // Consider them the same day. 299 .abs(lastCD4.getTimeInMillis() - firstCD4.getTimeInMillis()) < THREE_DAYS) { 300 // All CD4's taken within this time frame can be considered just one CD4 count taken. 290 301 duplicateCD4Obs = true; 291 302 } else { … … 293 304 } 294 305 } 295 // Exactly one CD4 count 306 /* 307 * Exactly one CD4 count 308 */ 296 309 if (obs.size() == 1 || duplicateCD4Obs) { 297 310 for (Obs o : obs) { 298 conceptDatetime.setTime(o.getObsDatetime()); 299 if (conceptDatetime.before(sixMosAgo)) { 300 return "Please order CD4 count now (last CD4 count over 6 months ago)."; 301 } else if (conceptDatetime.after(sixMosAgo) 302 && conceptDatetime.before(tomorrow)) { 303 Calendar nextCD4 = (Calendar) conceptDatetime.clone(); 311 obsDatetime.setTime(o.getObsDatetime()); 312 if (obsDatetime.before(fiveMosAgo)) { 313 // Maybe sometime give a more intelligent message. 314 // int months = tomorrow.get(Calendar.MONTH) - obsDatetime.get(Calendar.MONTH); 315 // int years = tomorrow.get(Calendar.YEAR) - obsDatetime.get(Calendar.YEAR); 316 // String mosAgo = (months > 1) ? months + " months" : months + " month"; 317 // String yrsAgo = (years > 1) ? years + " years" : years + " year"; 318 // Right now this will suffice: 319 return "Please order CD4 count now (last CD4 count over 5 months ago)."; 320 } else if (obsDatetime.after(fiveMosAgo) 321 && obsDatetime.before(tomorrow)) { 322 Calendar nextCD4 = (Calendar) obsDatetime.clone(); 304 323 nextCD4.add(Calendar.MONTH, 6); 305 324 return new String("Next CD4 count due in " … … 307 326 + " (last CD4 count was " + o.getValueNumeric() 308 327 + " on " 309 + obsFormat.format( conceptDatetime.getTime())328 + obsFormat.format(obsDatetime.getTime()) 310 329 + ")."); 311 330 } else {