Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
package edu.ncsu.csc.itrust.action;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.Calendar;
import edu.ncsu.csc.itrust.beans.forms.VisitReminderReturnForm;
import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.dao.mysql.VisitRemindersDAO;
import edu.ncsu.csc.itrust.dao.mysql.PatientDAO;
import edu.ncsu.csc.itrust.beans.ProcedureBean;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.exception.ITrustException;
import edu.ncsu.csc.itrust.beans.VisitFlag;
import edu.ncsu.csc.itrust.beans.PatientBean;
import edu.ncsu.csc.itrust.enums.Gender;
/**
* Gets the VisitReminders for a given patient Used by visitReminders.jsp
*
*
*/
public class GetVisitRemindersAction {
private static final int WEEK_IN_MILLIS = 1000 * 60 * 60 * 24 * 7;
/**
* Reminder Type enumeration.
*/
public static enum ReminderType {
DIAGNOSED_CARE_NEEDERS("Diagnosed Care Needers"),
FLU_SHOT_NEEDERS("Flu Shot Needers"),
IMMUNIZATION_NEEDERS("Immunization Needers");
private String typeName;
private ReminderType(String typeName) {
this.typeName = typeName;
}
private static final Map<String, ReminderType> map = new HashMap<String, ReminderType>();
static {
for (ReminderType rt : ReminderType.values()) {
map.put(rt.getTypeName(), rt);
}
}
/**
* Gets the ReminderType for the name passed as a param
*
* @param name
* @return the ReminderType associated with the name
*/
public static ReminderType getReminderType(String name) {
return map.get(name);
}
/**
* Returns the type name as a string
*
* @return
*/
public String getTypeName() {
return typeName;
}
}
/**
*
* Begin GetVisitRemindersAction code
*
*/
private VisitRemindersDAO visitReminderDAO;
private PatientDAO patientDAO;
private long loggedInMID;
/**
* Set up defaults
*
* @param factory The DAOFactory used to create the DAOs used in this action.
* @param loggedInMID MID of the person who is logged in
* @throws ITrustException
*/
public GetVisitRemindersAction(DAOFactory factory, long loggedInMID) throws ITrustException {
this.loggedInMID = loggedInMID;
visitReminderDAO = factory.getVisitRemindersDAO();
patientDAO = factory.getPatientDAO();
}
/**
* Returns a list of VisitReminderReturnForms for the type passed in as a param
*
* @param type
* the ReminderType
* @return the list of VisitReminderReturnForms
* @throws ITrustException
* @throws FormValidationException
*/
public List<VisitReminderReturnForm> getVisitReminders(ReminderType type) throws ITrustException, FormValidationException {
if (null == type)
throw new ITrustException("Reminder Type DNE");
switch (type) {
case DIAGNOSED_CARE_NEEDERS:
return visitReminderDAO.getDiagnosedVisitNeeders(loggedInMID);
//return stripDupes(visitReminderDAO.getDiagnosedVisitNeeders(loggedInMID));
case FLU_SHOT_NEEDERS:
return visitReminderDAO.getFluShotDelinquents(loggedInMID);
case IMMUNIZATION_NEEDERS:
return getImmunizationNeeders(loggedInMID);
default:
throw new ITrustException("Reminder Type DNE");
}
}
/**
* Gets a list of anyone who need immunizations
*
* @param mid the HCP whose patients are being checked
* @return a list of all the people who need immunizations--done in a visit reminder
* @throws ITrustException
*/
private List<VisitReminderReturnForm> getImmunizationNeeders(long mid) throws ITrustException {
List<VisitReminderReturnForm> formList;
List<VisitReminderReturnForm> needList = new ArrayList<VisitReminderReturnForm>();
String reason = "";
// Get list of patients that designate this HCP
formList = visitReminderDAO.getPatients(mid);
for (VisitReminderReturnForm r : formList) {
reason = checkImmunizations(r.getPatientID());
if (0 < reason.length()) {
needList.add(r);
r.addVisitFlag(new VisitFlag(VisitFlag.IMMUNIZATION, reason));
}
}
return needList;
}
/**
* Checks a patient to see what immunizations they need
*
* @param pid patient to be checked
* @return patient list of those lacking immunizations according to the schedule
*/
private String checkImmunizations(long pid) throws ITrustException {
String reason = "";
List<ProcedureBean> procs = patientDAO.getProcedures(pid);
PatientBean patient = patientDAO.getPatient(pid);
Date patientDOB = patient.getDateOfBirth();
Gender gen = patient.getGender();
int hepB = 0;
long hepBTime = 0;
int rota = 0;
long rotaTime = 0;
int diptet = 0;
long deptetTime = 0;
int haemoflu = 0;
long haemofluTime = 0;
long haemofluTimeFirst = 0;
int pneumo = 0;
long pneumoTime = 0;
long pneumofluTimeFirst = 0;
int polio = 0;
long polioTime = 0;
int measles = 0;
long measlesTime = 0;
int varicella = 0;
long varicellaTime = 0;
int hepA = 0;
long hepATime = 0;
int hpv = 0;
long hpvTime = 0;
for (ProcedureBean proc: procs) {
String cpt = proc.getCPTCode();
// Hep B (90371)
if (cpt.equals("90371")) {
hepB++;
hepBTime = proc.getDate().getTime();
}
// Rotavirus (90681)
else if (cpt.equals("90681")) {
rota++;
rotaTime = proc.getDate().getTime();
}
// Diptheria, Tetanus, Pertussis (90696)
else if (cpt.equals("90696")) {
diptet++;
deptetTime = proc.getDate().getTime();
}
// Haemophilus influenza (90645)
else if (cpt.equals("90645")) {
if (0 == haemoflu)
haemofluTimeFirst = proc.getDate().getTime();
haemoflu++;
haemofluTime = proc.getDate().getTime();
}
// Pneumococcal (90669)
else if (cpt.equals("90669")) {
if (0 == pneumo)
pneumofluTimeFirst = proc.getDate().getTime();
pneumo++;
pneumoTime = proc.getDate().getTime();
}
// Poliovirus (90712)
else if (cpt.equals("90712")) {
polio++;
polioTime = proc.getDate().getTime();
}
// Measles, Mumps, Rubella (90707)
else if (cpt.equals("90707")) {
measles++;
measlesTime = proc.getDate().getTime();
}
// Varicella (90396)
else if (cpt.equals("90396")) {
varicella++;
varicellaTime = proc.getDate().getTime();
}
// Hep A (90633)
else if (cpt.equals("90633")) {
hepA++;
hepATime = proc.getDate().getTime();
}
// Human Papillomaavirus (90649)
else if (cpt.equals("90649")) {
hpv++;
hpvTime = proc.getDate().getTime();
}
}
if (3 > hepB) {
reason += testHepB(hepB, patientDOB, hepBTime);
}
if (3 > rota) {
reason += testRotaVirus(rota, patientDOB, rotaTime);
}
if (6 > diptet) {
reason += testDipTet(diptet, patientDOB, deptetTime);
}
if (3 > haemoflu) {
reason += testHaemoFlu(haemoflu, patientDOB, haemofluTime, haemofluTimeFirst);
}
if (4 > pneumo) {
reason += testPneumo(pneumo, patientDOB, pneumoTime, pneumofluTimeFirst);
}
if (3 > polio) {
reason += testPolio(polio, patientDOB, polioTime);
}
if (2 > measles) {
reason += testMeasles(measles, patientDOB, measlesTime);
}
if (2 > varicella) {
reason += testVaricella(varicella, patientDOB, varicellaTime);
}
if (2 > hepA) {
reason += testHepA(hepA, patientDOB, hepATime);
}
if (3 > hpv && gen.getName().equals("Female")) {
reason += testHPV(hpv, patientDOB, hpvTime);
}
if(reason.length() > 2)
return reason.substring(0, reason.length() - 2);
return reason;
}
/**
* Checks to see if a patient needs the HPV immunization
*
* @param count how many HPV immunizations she has already had
* @param patientAge how old the patient is, in weeks
* @param time date of the last procedure
* @return the reason the immunization should be given, including required immunization age
*/
public static String testHPV(int count, Date patientDOB, long time) {
String reason = "";
long weeks = (Calendar.getInstance().getTimeInMillis() - time) / WEEK_IN_MILLIS;
new Date();
if (0 == count) {
if (olderThan(patientDOB, 9, 0, 0))
reason += "90649 Human Papillomavirus (9 years), ";
}
else if (1 == count) {
if (olderThan(patientDOB, 9, 2, 0) && 8 <= weeks)
reason += "90649 Human Papillomavirus (9 years, 2 months), ";
}
else if (2 == count) {
if (olderThan(patientDOB, 9, 6, 0) && 16 <= weeks)
reason += "90649 Human Papillomavirus (9 years, 6 months), ";
}
return reason;
}
/**
* Checks to see if a patient needs the Hepatits A immunization
*
* @param count which immunization they are on
* @param patientAge how old the patient is
* @param time what the current date is
* @return when the immunization should be given
*/
public static String testHepA(int count, Date patientDOB, long time) {
String reason = "";
long weeks = (Calendar.getInstance().getTimeInMillis() - time) / WEEK_IN_MILLIS;
if (0 == count) {
if (olderThan(patientDOB, 1, 0, 0))
reason += "90633 Hepatits A (12 months), ";
}
else if (1 == count) {
if (olderThan(patientDOB, 1, 6, 0) && 26 <= weeks)
reason += "90633 Hepatits A (18 months), ";
}
return reason;
}
/**
* Checks to see if a patient needs the Varicella immunization
*
* @param count which immunization they are on
* @param patientAge how old the patient is
* @param time what the current date is
* @return when the immunization should be given
*/
public static String testVaricella(int count, Date patientDOB, long time) {
String reason = "";
long weeks = (Calendar.getInstance().getTimeInMillis() - time) / WEEK_IN_MILLIS;
if (0 == count) {
if (olderThan(patientDOB, 1, 0, 0))
reason += "90396 Varicella (12 months), ";
}
else if (1 == count) {
if (olderThan(patientDOB, 4, 0, 0) && 12 <= weeks)
reason += "90396 Varicella (4 years), ";
}
return reason;
}
/**
* Checks to see if a patient needs the Measles, Mumps, and Rubekka immunization
*
* @param count which immunization they are on
* @param patientAge how old the patient is
* @param time what the current date is
* @return when the immunization should be given
*/
public static String testMeasles(int count, Date patientDOB, long time) {
String reason = "";
long weeks = (Calendar.getInstance().getTimeInMillis() - time) / WEEK_IN_MILLIS;
if (0 == count) {
if (olderThan(patientDOB, 1, 0, 0))
reason += "90707 Measles, Mumps, Rubekka (12 months), ";
}
else if (1 == count) {
if (olderThan(patientDOB, 4, 0, 0) && 12 <= weeks)
reason += "90707 Measles, Mumps, Rubekka (4 years), ";
}
return reason;
}
/**
* Checks to see if a patient needs the Polio immunization
*
* @param count which immunization they are on
* @param patientAge how old the patient is
* @param time what the current date is
* @return when the immunization should be given
*/
public static String testPolio(int count, Date patientDOB, long time) {
String reason = "";
long weeks = (Calendar.getInstance().getTimeInMillis() - time) / WEEK_IN_MILLIS;
if (0 == count) {
if (olderThan(patientDOB, 0, 0, 6))
reason += "90712 Poliovirus (6 weeks), ";
}
else if (1 == count) {
if (olderThan(patientDOB, 0, 4, 0) && 4 <= weeks)
reason += "90712 Poliovirus (4 months), ";
}
else if (2 == count) {
if (olderThan(patientDOB, 0, 6, 0))
reason += "90712 Poliovirus (6 months), ";
}
return reason;
}
/**
* Checks to see if a patient needs the Pneumococcal immunization
*
* @param count which immunization they are on
* @param time what the current date is
* @return when the immunization should be given
*/
public static String testPneumo(int count, Date patientDOB, long time, long firstDoseTime) {
String reason = "";
Date firstDose = new Date(firstDoseTime);
long weeks = (Calendar.getInstance().getTimeInMillis() - time) / WEEK_IN_MILLIS;
if (0 == count) {
if (olderThan(patientDOB, 0, 0, 6))
reason += "90669 Pneumococcal (6 weeks), ";
}
else if (1 == count) {
if (olderThan(patientDOB, 0, 4, 0) && !(firstDoseAfter(patientDOB, firstDose, 1, 0, 0)) && 4 <= weeks)
reason += "90669 Pneumococcal (4 months), ";
else if (olderThan(patientDOB, 0, 4, 0) && (firstDoseAfter(patientDOB, firstDose, 1, 0, 0)) && !(firstDoseAfter(patientDOB, firstDose, 1, 2, 0)) && 8 <= weeks)
reason += "90669 Pneumococcal (4 months), ";
}
else if (2 == count) {
if (olderThan(patientDOB, 0, 6, 0) && 4 <= weeks && !(firstDoseAfter(patientDOB, firstDose, 1, 0, 0)))
reason += "90669 Pneumococcal (6 months), ";
}
else if (3 == count) {
if (olderThan(patientDOB, 1, 0, 0) && 8 <= weeks && !(firstDoseAfter(patientDOB, firstDose, 1, 0, 0)))
reason += "90669 Pneumococcal (12 months), ";
}
return reason;
}
/**
* Checks to see if a patient needs the Haemophilus Infulenzae immunization
*
* @param count which immunization they are on
* @param time what the current date is
* @return when the immunization should be given
*/
public static String testHaemoFlu(int count, Date patientDOB, long time, long firstDoseTime) {
String reason = "";
long weeks = (Calendar.getInstance().getTimeInMillis() - time) / WEEK_IN_MILLIS;
Date firstDose = new Date(firstDoseTime);
if (0 == count) {
if (olderThan(patientDOB, 0, 0, 6))
reason += "90645 Haemophilus influenzae (6 weeks), ";
}
else if (1 == count) {
if (olderThan(patientDOB, 0, 4, 0) && !(firstDoseAfter(patientDOB, firstDose, 1, 0, 0)) && 4 <= weeks)
reason += "90645 Haemophilus influenzae (4 months), ";
else if (olderThan(patientDOB, 0, 4, 0) && firstDoseAfter(patientDOB, firstDose, 1, 0, 0) && !(firstDoseAfter(patientDOB, firstDose, 1, 2, 0)) && 8 <= weeks)
reason += "90645 Haemophilus influenzae (4 months), ";
}
else if (2 == count) {
if (olderThan(patientDOB, 0, 6, 0) && 4 <= weeks && !(firstDoseAfter(patientDOB, firstDose, 1, 0, 0)))
reason += "90645 Haemophilus influenzae (6 months), ";
}
return reason;
}
/**
* Checks to see if a patient needs the Diphtheria, Tetanus, Pertussis immunization
*
* @param count which immunization they are on
* @param time what the current date is
* @return when the immunization should be given
*/
public static String testDipTet(int count, Date patientDOB, long time) {
String reason = "";
long weeks = (Calendar.getInstance().getTimeInMillis() - time) / WEEK_IN_MILLIS;
if (0 == count) {
if (olderThan(patientDOB, 0, 0, 6))
reason += "90696 Diphtheria, Tetanus, Pertussis (6 weeks), ";
}
else if (1 == count) {
if (olderThan(patientDOB, 0, 4, 0) && 4 <= weeks )
reason += "90696 Diphtheria, Tetanus, Pertussis (4 months), ";
}
else if (2 == count) {
if (olderThan(patientDOB, 0, 6, 0) && 4 <= weeks)
reason += "90696 Diphtheria, Tetanus, Pertussis (6 months), ";
}
else if (3 == count) {
if (olderThan(patientDOB, 0, 0, 15) && 26 <= weeks)
reason += "90696 Diphtheria, Tetanus, Pertussis (15 weeks), ";
}
else if (4 == count) {
if (olderThan(patientDOB, 4, 0, 0) && 26 <= weeks)
reason += "90696 Diphtheria, Tetanus, Pertussis (4 years), ";
}
else if (5 == count) {
if (olderThan(patientDOB, 11, 0, 0) && 260 <= weeks)
reason += "90696 Diphtheria, Tetanus, Pertussis (11 years), ";
}
return reason;
}
/**
* Checks to see if a patient needs the Rotavirus immunization
*
* @param count which immunization they are on
* @param time what the current date is
* @return when the immunization should be given
*/
public static String testRotaVirus(int count, Date patientDOB, long time) {
String reason = "";
long weeks = (Calendar.getInstance().getTimeInMillis() - time) / WEEK_IN_MILLIS;
if (0 == count) {
if (olderThan(patientDOB, 0, 0, 6))
reason += "90681 Rotavirus (6 weeks), ";
}
else if (1 == count) {
if (olderThan(patientDOB, 0, 4, 0) && 4 <= weeks)
reason += "90681 Rotavirus (4 months), ";
}
else if (2 == count) {
if (olderThan(patientDOB, 0, 6, 0) && 4 <= weeks )
reason += "90681 Rotavirus (6 months), ";
}
return reason;
}
/**
* Checks to see if a patient needs the Hepatitis B immunization
*
* @param count which immunization they are on
* @param time what the current date is
* @return when the immunization should be given
*/
public static String testHepB(int count, Date patientDOB, long time) {
String reason = "";
long weeks = (Calendar.getInstance().getTimeInMillis() - time) / WEEK_IN_MILLIS;
if (0 == count) {
if (olderThan(patientDOB, 0, 0, 0))
reason += "90371 Hepatitis B (birth), ";
}
else if (1 == count) {
if (olderThan(patientDOB, 0, 1, 0) && 4 <= weeks)
reason += "90371 Hepatitis B (1 month), ";
}
else if (2 == count) {
if (olderThan(patientDOB, 0, 6, 0) && 8 <= weeks)
reason += "90371 Hepatitis B (6 months), ";
}
return reason;
}
private static boolean olderThan(Date patientDOB, int years, int months, int weeks) {
return endBefore(patientDOB, new Date(), years, months, weeks);
}
private static boolean firstDoseAfter(Date patientDOB, Date ageFirst, int years, int months, int weeks) {
return endBefore(patientDOB, ageFirst, years, months, weeks);
}
private static boolean endBefore(Date startTime, Date endTime, int years, int months, int weeks) {
Calendar cal = Calendar.getInstance();
cal.setTime(startTime);
cal.add(Calendar.YEAR, years);
cal.add(Calendar.MONTH, months);
cal.add(Calendar.HOUR, weeks*7*24);
return (cal.getTime().compareTo(endTime) <= 0);
}
}