-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
180 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...zation/src/main/java/org/smartregister/immunization/domain/conditions/GivenCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.smartregister.immunization.domain.conditions; | ||
|
||
import org.smartregister.immunization.db.VaccineRepo; | ||
import org.smartregister.immunization.domain.Vaccine; | ||
import org.smartregister.immunization.domain.VaccineCondition; | ||
import org.smartregister.immunization.domain.VaccineSchedule; | ||
|
||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
public class GivenCondition extends VaccineCondition { | ||
private final Comparison comparison; | ||
private final String value; | ||
|
||
public GivenCondition(VaccineRepo.Vaccine vaccine, String value, Comparison comparison) { | ||
super(vaccine); | ||
this.value = value; | ||
this.comparison = comparison; | ||
} | ||
|
||
public static Comparison getComparison(String name) { | ||
for (Comparison curComparison : Comparison.values()) { | ||
if (curComparison.name.equalsIgnoreCase(name)) { | ||
return curComparison; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean passes(Date anchorDate, List<Vaccine> issuedVaccines) { | ||
boolean result = false; | ||
|
||
// Check if vaccine was given at all | ||
Vaccine comparisonVaccine = null; | ||
for (Vaccine curVaccine : issuedVaccines) { | ||
if (curVaccine.getName().equalsIgnoreCase(vaccine.display())) { | ||
comparisonVaccine = curVaccine; | ||
break; | ||
} | ||
} | ||
|
||
if (comparisonVaccine != null) { | ||
Calendar comparisonDate = Calendar.getInstance(); | ||
VaccineSchedule.standardiseCalendarDate(comparisonDate); | ||
comparisonDate = VaccineSchedule.addOffsetToCalendar(comparisonDate, value); | ||
|
||
Calendar vaccinationDate = Calendar.getInstance(); | ||
vaccinationDate.setTime(comparisonVaccine.getDate()); | ||
VaccineSchedule.standardiseCalendarDate(vaccinationDate); | ||
|
||
switch (comparison) { | ||
case EXACTLY: | ||
result = comparisonDate.getTimeInMillis() == vaccinationDate.getTimeInMillis(); | ||
break; | ||
case AT_LEAST: | ||
result = comparisonDate.getTimeInMillis() >= vaccinationDate.getTimeInMillis(); | ||
break; | ||
case AT_MOST: | ||
result = comparisonDate.getTimeInMillis() <= vaccinationDate.getTimeInMillis(); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public enum Comparison { | ||
EXACTLY("exactly"), | ||
AT_LEAST("at_least"), | ||
AT_MOST("at_most"); | ||
|
||
private final String name; | ||
|
||
Comparison(String name) { | ||
this.name = name; | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ization/src/main/java/org/smartregister/immunization/domain/conditions/JoinCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.smartregister.immunization.domain.conditions; | ||
|
||
import org.smartregister.immunization.db.VaccineRepo; | ||
import org.smartregister.immunization.domain.Vaccine; | ||
import org.smartregister.immunization.domain.VaccineCondition; | ||
import org.smartregister.immunization.domain.jsonmapping.Condition; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
// TODO | ||
public class JoinCondition extends VaccineCondition { | ||
private Condition conditionData; | ||
|
||
public JoinCondition(VaccineRepo.Vaccine vaccine, Condition conditionData) { | ||
super(vaccine); | ||
this.conditionData = conditionData; | ||
} | ||
|
||
public JoinCondition() { | ||
super(null); | ||
} | ||
|
||
@Override | ||
public boolean passes(Date anchorDate, List<Vaccine> issuedVaccines) { | ||
if(conditionData.conditions != null && conditionData.conditions.size() > 0){ | ||
|
||
} | ||
|
||
return false; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ion/src/main/java/org/smartregister/immunization/domain/conditions/NotGivenCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.smartregister.immunization.domain.conditions; | ||
|
||
import org.smartregister.immunization.db.VaccineRepo; | ||
import org.smartregister.immunization.domain.Vaccine; | ||
import org.smartregister.immunization.domain.VaccineCondition; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
public class NotGivenCondition extends VaccineCondition { | ||
|
||
public NotGivenCondition(VaccineRepo.Vaccine vaccine) { | ||
super(vaccine); | ||
} | ||
|
||
@Override | ||
public boolean passes(Date anchorDate, List<Vaccine> issuedVaccines) { | ||
// Check if vaccine was not given | ||
boolean given = false; | ||
|
||
// TODO: Check if name used in VaccineRepo.Vaccine is the same as the one in Vaccine | ||
for (Vaccine curVaccine : issuedVaccines) { | ||
if (curVaccine.getName().equalsIgnoreCase(vaccine.display())) { | ||
given = true; | ||
break; | ||
} | ||
} | ||
|
||
return !given; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters