We were discussing in HiGHmed / EHRBASE about the accepted formats for dates, times and specially datetimes in AQL.
The spec [Archetype Query Language (AQL)] says those datatypes should comply with ISO 8601 which allows to:
a. use dots or commas for the fraction seconds marker
b. avoid the time separator if “mutually agreed”, that is the ‘T’ in aaaammddThhmmssZ
Currently EHRBASE doesn’t support using commas for the fraction seconds marker or not having the ‘T’ time separator, so AQLs with those formats will fail.
I suggested to add in the EHRBASE documentation what is supported and what is not. @birger.haarbrandt mentioned that should be something better agreed at the SEC level because adding constraints just to one implementation could difficult migrating queries from one implementation o another.
I agree in looking for “mostly compatible” queries, we need to address this at the SEC. Another point is, the current spec by saying “this is ISO 8601” it is actually allowing commas in the fraction seconds marker and use or not the time separator, which is OK from the specification point of view.
It would be interesting to know what others think and get some input on what other implementations support or not in the datetime formats.
There is one extra case for the query API, when the datetime value is in the JSON as a parameter instead of hardcoded in the AQL, please consider:
Hardcoded datetime in the AQL expression:
{
“q”: “SELECT c/uid/value FROM EHR e[ehr_id/value=$ehr_id] CONTAINS COMPOSITION c[openEHR-EHR-COMPOSITION.review.v1] WHERE c/context/start_time/value = ‘20200607195544.339Z’”,
“query_parameters”: {
“ehr_id”: “{{ ehr_id }}”
}
}
Datetime as a parameter in the JSON:
{
“q”: “SELECT c/uid/value FROM EHR e[ehr_id/value=$ehr_id] CONTAINS COMPOSITION c[openEHR-EHR-COMPOSITION.review.v1] WHERE c/context/start_time/value = $dt”,
“query_parameters”: {
“ehr_id”: “{{ ehr_id }}”,
“dt”: ‘20200607195544.339Z’
}
}
While the format for the hardcoded AQL value should comply with the AQL rules, the dt parameter should comply with the “JSON rules” if the type is datetime, but it could be also a string so no specific format is needed.
Reading about datetimes in JSON, there are no specific rules, but some recommend to use the JS rules, which generates this format “2020-06-08T17:04:30.621Z” (ISO 8601 extended with dot as fraction seconds marker and the time separator), which comes from executing new Date().toJSON() in JS.
My question about this is: do we consider the $dt value to be a datetime or a string? and should we enforce any specific formatting when included in the JSON instead of in the AQL expression?