-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for datetime calculations in cohort definitions #200
Open
jcnamendiOdysseus
wants to merge
27
commits into
OHDSI:master
Choose a base branch
from
odysseusinc:issues-2886
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
1fa1d69
Support for datetime calculations in cohort definitions
jcnamendiOdysseus b9b5820
update
jcnamendiOdysseus 6fd8ecd
update/412023
jcnamendiOdysseus 07a7160
add sql test
jcnamendiOdysseus eaf44d5
fix
jcnamendiOdysseus 6dc3918
Merge remote-tracking branch 'origin/is/2886' into issues-2886
jcnamendiOdysseus 603c800
update test
jcnamendiOdysseus fe4f7e5
fix indent on editor
jcnamendiOdysseus 75a2906
Merge pull request #6 from OHDSI/master
alex-odysseus 3210fae
Merge remote-tracking branch 'remotes/origin/master' into issues-2886
alex-odysseus e7f90a6
remove jar
jcnamendiOdysseus 0036dc0
Merge remote-tracking branch 'origin/issues-2886' into issues-2886
jcnamendiOdysseus 4d0cb33
Support for datetime calculations in cohort definitions
jcnamendiOdysseus 55b2eef
update
jcnamendiOdysseus 806c85b
update/412023
jcnamendiOdysseus 8a4eb23
add sql test
jcnamendiOdysseus f819d5e
fix
jcnamendiOdysseus 5e03963
update test
jcnamendiOdysseus de9527c
fix indent on editor
jcnamendiOdysseus ca6bbfd
remove jar
jcnamendiOdysseus cebb8c5
Revert "fix"
jcnamendiOdysseus 2ada34d
Merge remote-tracking branch 'origin/issues-2886' into issues-2886
jcnamendiOdysseus 6fb7fd2
add tests
jcnamendiOdysseus da13f6e
Adding IntervalUnit to Criteria to specify datetime table columns whi…
alex-odysseus 690b273
Replace wildcard import with specific imports
jcnamendiOdysseus 2f97201
Enhance time unit handling in compareTo() method
jcnamendiOdysseus 4209ca0
Introduce time interval testing functionality and enhance the impleme…
jcnamendiOdysseus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,7 @@ | |
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeParseException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.*; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
import org.apache.commons.lang3.builder.EqualsBuilder; | ||
|
@@ -31,6 +29,12 @@ | |
|
||
public class Comparisons { | ||
|
||
private static final Map<String, Integer> TIME_UNIT_CONVERSION = new HashMap<>(); | ||
static { | ||
TIME_UNIT_CONVERSION.put(IntervalUnit.HOUR.getName(), 60 * 60); | ||
TIME_UNIT_CONVERSION.put(IntervalUnit.MINUTE.getName(), 60); | ||
} | ||
|
||
public static Boolean startIsGreaterThanEnd(NumericRange r) { | ||
|
||
return Objects.nonNull(r.value) && Objects.nonNull(r.extent) && r.value.intValue() > r.extent.intValue(); | ||
|
@@ -101,19 +105,26 @@ public static Predicate<Concept> compare(Concept source) { | |
.append(concept.vocabularyId, source.vocabularyId) | ||
.build(); | ||
} | ||
|
||
public static int compareTo(ObservationFilter filter, Window window) { | ||
|
||
int range1 = filter.postDays + filter.priorDays; | ||
int range2Start = 0, range2End = 0; | ||
if (Objects.nonNull(window.start) && Objects.nonNull(window.start.days)) { | ||
range2Start = window.start.coeff * window.start.days; | ||
} | ||
if (Objects.nonNull(window.end) && Objects.nonNull(window.end.days)) { | ||
range2End = window.end.coeff * window.end.days; | ||
int range1 , range2Start , range2End; | ||
if(Objects.nonNull(window.start) && Objects.nonNull(window.start.days)){ | ||
range1 = filter.postDays + filter.priorDays; | ||
range2Start = window.start.coeff * window.start.days; | ||
range2End = Objects.nonNull(window.end) && Objects.nonNull(window.end.days) ? window.end.coeff * window.end.days : 0; | ||
}else { | ||
range1 = (filter.postDays + filter.priorDays) * 24 * 60 * 60; | ||
range2Start = getTimeInSeconds(window.start); | ||
range2End = getTimeInSeconds(window.end); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where the 4sp indent is glaring, so before you have to go back and change all of it back to 2sp, i'd adjust your formatting. |
||
} | ||
return range1 - (range2End - range2Start); | ||
} | ||
private static int getTimeInSeconds(Window.Endpoint endpoint) { | ||
return Optional.ofNullable(endpoint) | ||
.map(ep -> { | ||
int convertRate = TIME_UNIT_CONVERSION.getOrDefault(ep.timeUnit, 1); | ||
return Objects.nonNull(ep.timeUnitValue) ? ep.coeff * ep.timeUnitValue * convertRate : 0; | ||
}).orElse(0); | ||
} | ||
|
||
public static boolean compare(Criteria c1, Criteria c2) { | ||
|
||
|
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
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
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
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
19 changes: 19 additions & 0 deletions
19
src/main/java/org/ohdsi/circe/cohortdefinition/IntervalUnit.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,19 @@ | ||
package org.ohdsi.circe.cohortdefinition; | ||
|
||
import jdk.nashorn.internal.objects.annotations.Getter; | ||
|
||
public enum IntervalUnit { | ||
HOUR("hour"), | ||
MINUTE("minute"), | ||
SECOND("second"); | ||
|
||
private final String name; | ||
|
||
IntervalUnit(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't do it this way, it makes it seem like it's dynamic (ie: can change at runtime). Can't this function of conversion be associated to the enum itself?