-
Notifications
You must be signed in to change notification settings - Fork 12
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
1 parent
3bb87c1
commit 6359423
Showing
4 changed files
with
51 additions
and
3 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
39 changes: 39 additions & 0 deletions
39
fhirpath/src/main/java/au/csiro/pathling/sql/dates/time/NormalizeTimeFunction.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,39 @@ | ||
package au.csiro.pathling.sql.dates.time; | ||
|
||
import au.csiro.pathling.sql.udf.SqlFunction1; | ||
import java.time.LocalTime; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.Objects; | ||
import org.apache.spark.sql.types.DataType; | ||
import org.apache.spark.sql.types.DataTypes; | ||
|
||
/** | ||
* A function for normalizing a time string to a long (nanoseconds) for comparison purposes. | ||
* <p> | ||
* Truncates the precision of the time to milliseconds, as this is the highest precision supported | ||
* by FHIR. | ||
*/ | ||
public class NormalizeTimeFunction implements SqlFunction1<String, Long> { | ||
|
||
private static final long serialVersionUID = 4117774962772392910L; | ||
|
||
public static final String FUNCTION_NAME = "normalize_time"; | ||
|
||
@Override | ||
public String getName() { | ||
return FUNCTION_NAME; | ||
} | ||
|
||
@Override | ||
public DataType getReturnType() { | ||
return DataTypes.LongType; | ||
} | ||
|
||
@Override | ||
public Long call(final String timeString) throws Exception { | ||
final LocalTime time = Objects.requireNonNull( | ||
LocalTime.parse(timeString)); | ||
return time.truncatedTo(ChronoUnit.MILLIS).toNanoOfDay(); | ||
} | ||
|
||
} |
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