-
Notifications
You must be signed in to change notification settings - Fork 253
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
Fix FHIR Engine search sort for DateTime properties #1384
Fix FHIR Engine search sort for DateTime properties #1384
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1384 +/- ##
=============================================
+ Coverage 0 85.66% +85.66%
- Complexity 0 714 +714
=============================================
Files 0 150 +150
Lines 0 10749 +10749
Branches 0 856 +856
=============================================
+ Hits 0 9208 +9208
- Misses 0 1104 +1104
- Partials 0 437 +437
Help us with your feedback. Take ten seconds to tell us how you rate us. |
54c0366
to
cc725cd
Compare
@ekigamba , when can we expect this PR to get completed? |
@Tarun-Bhardwaj This PR is complete |
|
||
import ca.uhn.fhir.rest.gclient.DateClientParam | ||
|
||
class DateTimeClientParam(theParamName: String) : DateClientParam(theParamName) |
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 might not be intuitive to the app developers that they need to pass DateTimeClientParam for date & time in the search sort function . Also they will have to re-define the DateClientParam
define in hapi lib as a DateTimeClientParam
now.
fun sort(parameter: DateClientParam, order: Order) {
sort = parameter
this.order = order
}
One way to handle date-time could be to pass a boolean param in the sort
indicating the type of search i.e Date or DateTime.
Any thoughts @jingtang10 ?
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.
Thanks for bringing it up:
- We can have below function to make it more intuitive
fun sort(parameter: DateTimeClientParam, order: Order) {
sort = parameter
this.order = order
}
- Do we really need to define
DateTimeClientParam
in the hapi lib since this is only used for sorting on this lib? Having extendedDateClientParam
means it can be reused for other places whereDateClientParam
is supposed to be used without changing the code to accomodate the new class. It's only role will be better readability when passed as a param in otherDateClientParam
functions
Alternatively, we can use a boolean as you stated. This will require us to track the boolean and have it as a class property of Search
that will only be used whenever the sort param is a DateClientParam
discussed this on thursday (@f-odhiambo @ekigamba @aditya-07 @maimoonak). the root problem is the fact that there is only 1 type of search param for both date and datetime indices, but at run time we don't know which index table to join. we talked about 2 options:
@ekigamba can you investigate these 2 options a little bit and discuss the pros and cons so we can make a decision? thanks |
@ekigamba , did you get a chance to work on the comments provided by @jingtang10 ? |
Yea, in progress. Investigating both and how Hapi FHIR server handles this currently |
- Add tests for the double-join and double sort for FHIR engine queries Fixes google#1363
26f8e79
to
b24b4c9
Compare
368fe62
to
0bff104
Compare
- Update query tests
0bff104
to
f95cabf
Compare
@jingtang10 Kindly review this |
|
||
sortArgs += sort.paramName | ||
|
||
// Fixes issue https://github.com/google/android-fhir/issues/1363 | ||
if (sort is DateClientParam) { | ||
sortJoinStatement += | ||
""" | ||
LEFT JOIN ${SortTableInfo.DATE_TIME_SORT_TABLE_INFO.tableName} bDateTime | ||
ON a.resourceType = bDateTime.resourceType AND a.resourceUuid = bDateTime.resourceUuid AND bDateTime.index_name = ? | ||
""" | ||
|
||
sortArgs += sort.paramName | ||
} | ||
|
||
sortOrderStatement = | ||
""" | ||
ORDER BY b.${sortTableName.columnName} ${order.sqlString} | ||
""".trimIndent() | ||
sortArgs += sort.paramName | ||
|
||
// Fixes issue https://github.com/google/android-fhir/issues/1363 | ||
if (sort is DateClientParam) { | ||
sortOrderStatement += | ||
", bDateTime.${SortTableInfo.DATE_TIME_SORT_TABLE_INFO.columnName} ${order.sqlString}" | ||
} |
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 code is very procedural and difficult to read - i think what should happen is for the when
clause on line 65, you sould return a list of SortTableInfo
s. And for each of them, you add the join statement and the sort order statement. that way it's much clearer.
so in this case or the DateClientParam
, you just need to add both date and datetime tables.
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 have made the changes as requested. However, I think that the forEachIndexed
can be confusing since it makes it seem as if the engine allows multiple sort params. It is also not clear that the are implemented for an exception. The for loops feel like generic solutions while they help fix the issue for 1 exception.
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.
Remove the if for DateTimeClient when performing double-joins and use a generic for loop
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.
just one comment on test - otherwise good to go
engine/src/test/java/com/google/android/fhir/search/SearchTest.kt
Outdated
Show resolved
Hide resolved
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.
thanks @ekigamba
Fixes #1363
Description
Implements a double-join to the tables
DateTimeIndexEntity
andDateIndexEntity
whenever a DateClientParam sort is requestedAlternative(s) considered
Yes, a number of alternatives were considered and discussed here namely:
Type
Choose one: Bug fix
Screenshots (if applicable)
N/A
Checklist
./gradlew spotlessApply
and./gradlew spotlessCheck
to check my code follows the style guide of this project../gradlew check
and./gradlew connectedCheck
to test my changes locally.