-
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
base: master
Are you sure you want to change the base?
Conversation
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); | ||
} | ||
|
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?
Chris, please don't go deep into this pull request as it is a draft and incomplete @chrisknoll |
Will be easier to point out issues earlier instead of sifting through potentially thousands of lines of changes. |
5098a3a
to
dfa05f5
Compare
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 comment
The 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.
### ${conceptSet.name} | ||
<#list conceptSet.expression.items> | ||
|Concept ID|Concept Name|Code|Vocabulary|Excluded|Descendants|Mapped | ||
|:---|:---------------------------------------|:--|:-----|:--:|:--:|:--:| | ||
<#items as conceptSetItem> | ||
|${conceptSetItem.concept.conceptId?c}|<#-- |
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.
You want to be extremly careful with changing the formatting of the Freemarker templates (ftl files) that are building the markdown format, since these are very sensitive to whitespacing. Unless you need to change this, I would not touch any of these.
dfa05f5
to
6fd8ecd
Compare
# Conflicts: # src/main/java/org/ohdsi/circe/check/checkers/Comparisons.java # src/main/java/org/ohdsi/circe/check/checkers/ExitCriteriaDaysOffsetCheck.java # src/main/java/org/ohdsi/circe/check/checkers/FirstTimeInHistoryCheck.java # src/main/java/org/ohdsi/circe/check/checkers/RangeCheck.java # src/main/java/org/ohdsi/circe/cohortdefinition/CohortExpressionQueryBuilder.java # src/main/java/org/ohdsi/circe/cohortdefinition/CollapseSettings.java # src/main/java/org/ohdsi/circe/cohortdefinition/CustomEraStrategy.java # src/main/java/org/ohdsi/circe/cohortdefinition/DateOffsetStrategy.java # src/main/java/org/ohdsi/circe/cohortdefinition/IntervalUnit.java # src/main/java/org/ohdsi/circe/cohortdefinition/Window.java # src/main/resources/resources/cohortdefinition/printfriendly/cohortExpression.ftl # src/main/resources/resources/cohortdefinition/printfriendly/criteriaTypes.ftl # src/main/resources/resources/cohortdefinition/printfriendly/inputTypes.ftl # src/main/resources/resources/cohortdefinition/sql/customEraStrategy.sql # src/main/resources/resources/cohortdefinition/sql/dateOffsetStrategy.sql # src/main/resources/resources/cohortdefinition/sql/generateCohort.sql # src/test/java/org/ohdsi/circe/check/checkers/CriteriaCheckValueTest.java # src/test/java/org/ohdsi/circe/check/checkers/DeathTimeWindowCheckTest.java # src/test/java/org/ohdsi/circe/cohortdefinition/builders/CriteriaUtils.java # src/test/java/org/ohdsi/circe/cohortdefinition/printfriendly/PrintFriendlyTest.java
Added dateAdjust to print friendly and other corrections.
# Conflicts: # src/main/resources/resources/cohortdefinition/printfriendly/cohortExpression.ftl
0036dc0
to
cebb8c5
Compare
# Conflicts: # src/main/java/org/ohdsi/circe/check/checkers/Comparisons.java # src/main/java/org/ohdsi/circe/check/checkers/ExitCriteriaDaysOffsetCheck.java # src/main/java/org/ohdsi/circe/check/checkers/FirstTimeInHistoryCheck.java # src/main/java/org/ohdsi/circe/check/checkers/RangeCheck.java # src/main/java/org/ohdsi/circe/cohortdefinition/CohortExpressionQueryBuilder.java # src/main/java/org/ohdsi/circe/cohortdefinition/CollapseSettings.java # src/main/java/org/ohdsi/circe/cohortdefinition/CustomEraStrategy.java # src/main/java/org/ohdsi/circe/cohortdefinition/DateOffsetStrategy.java # src/main/java/org/ohdsi/circe/cohortdefinition/IntervalUnit.java # src/main/java/org/ohdsi/circe/cohortdefinition/Window.java # src/main/resources/resources/cohortdefinition/printfriendly/cohortExpression.ftl # src/main/resources/resources/cohortdefinition/printfriendly/criteriaTypes.ftl # src/main/resources/resources/cohortdefinition/printfriendly/inputTypes.ftl # src/main/resources/resources/cohortdefinition/sql/customEraStrategy.sql # src/main/resources/resources/cohortdefinition/sql/dateOffsetStrategy.sql # src/main/resources/resources/cohortdefinition/sql/generateCohort.sql # src/test/java/org/ohdsi/circe/check/checkers/CriteriaCheckValueTest.java # src/test/java/org/ohdsi/circe/check/checkers/DeathTimeWindowCheckTest.java # src/test/java/org/ohdsi/circe/cohortdefinition/builders/CriteriaUtils.java # src/test/java/org/ohdsi/circe/cohortdefinition/printfriendly/PrintFriendlyTest.java
…le resolving the SELECT clause in SQL builders
ece0b7a
to
690b273
Compare
return range1 - (range2End - range2Start); | ||
public static int compareTo(ObservationFilter filter, Window window) { | ||
int range1, range2Start, range2End; | ||
if (Objects.nonNull(window.start) && (Objects.nonNull(window.start.days) || IntervalUnit.DAY.getName().equals(window.start.timeUnit))) { |
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.
This produces an NPE when window.start is not set and timeUnit is a DAY.
d7cdc0d
to
3ca769e
Compare
…ntation of the datediff() function. - Modify the cdm_v5.0.sql file to incorporate additional datetime fields. - Include timeIntervalUnit parameters to handle various scenarios such as hours/minutes/seconds. - Write tests to validate the functionality under different time interval units, including hours/minutes/seconds.
3ca769e
to
4209ca0
Compare
@chrisknoll , if this pull request is related to OHDSI/Atlas#2886, I'm looking for advice on getting past a hurdle. the GUI looks good, and when one explicitly specifies hour or minute for a widget, the generated code looks correct for that widget. However, if there is a single reference to datetime in the JSON, then all dates that can be converted to datetime must be. There are two areas of challenge in the current efforts to implement this:
I think this can be handled by post-processing the SQL generated by circe-be: The following python function addresses both steps:
If we find that the generated SQL doesn't always have a datetime reference, another option is to use regular expressions to search the JSON definition for "TimeUnit" of "hour|minute|second". Can the circe-be function that does the SQL template generation be amended (or intercepted) to call this additional function (or its Java equivalent) before the final String is returned to the requestor? From there, SqlRender should work fine on the syntax-specific translation. |
Hi, @TomWhite-MedStar , I haven't dug deeply into this, as there's missing information in the PR description about what the changes are (in moderate detail), but currently has nothing yet. Second issue is the entire notion of minute/second granularity in the cohort result, it is not clear what the impact on the external tools will be if there is a unit of time other than day. Also, looks like this has some conflicts based on recent PRs that have been merged into master. As far as using this for your own purposes, a branch or fork approach would work for you to use this in your own environment if there is that need. As you might imagine that this cohort definition work is central to a lot of the OHDSI tool stack, we must be extremely careful what gets put into a formal release. On the forums, I've observed support that it's a good idea (hour/minute granularity), but beyond that there are technical considerations (such as: sometimes the result query will put So for starters, I think the PR author should include details on what the intended changes are that are being introduced in this PR (so that we have something to cross-check between the 'intended change' vs. the actual change in the 'lines of code changed'). This is important because we don't want to be left to reverse-engineer the lines of code that were changed to infer the intent of the author...it should be declared, and then we can judge the code changes based on that declared intent. On small changes, it's pretty straight forward to declare what the intended changes of a PR is. On something larger like this, we have new test cases, enums, date calculations (I think I saw in some cases that we intended to resolve the time diffs to seconds, but in certain places I see we're accounting for sometimes hours, sometimes minutes, sometimes seconds), so I just would like to know what I should be expecting when looking through the code changes before digesting all the lines of code changes. Re: your approach to fix sql to date or date_time via string replace |
@chrisknoll , thanks for the lengthy reply. I am presuming, but not sure, that this PR might be for work that Odysseus is doing for me at MedStar. If so, I'm trying to get past a hurdle in that work. They have working for months, and finding that the source code is very complex - so I'm wanting to brainstorm whether there might be post-processing approach that is easier to implement and maintain. |
Thanks for your understanding, @TomWhite-MedStar . Although the codebase may be complicated, at the core it's a string-builder plus logic validator (through the checkers). This means that, at the core, it's assembling the string through the various builder functions. Introducing a notion of building the final string through a process of find/replaces might seem straightforward from an implementation perspective, but out of place from a functional perspective. So, lets get the description of what's in the PR in the description of this PR, resolve the conflicts, evaluate if the code is doing what it intended, and then we can make implementation recommendations based on findings. |
No description provided.