DIPSAS/openehpy

Date and Datetime handling

Opened this issue · 0 comments

Time is important in healthcare. It would be great if the library where able to handle DV_DATE and DV_DATE_TIME into the similar Python datatype.

I am working on a project now where I had to add the following

import datetime
import dateutil.parser
from dateutil.parser import parse
ds = '2020-10-15T22:41:21.9666195+02:00'
# See https://stackoverflow.com/questions/59121002/translating-a-messy-date-string-in-a-dataframe-to-datetime-in-python-and-panda 

def parse_date(date):
    if date is np.nan:
        return np.nan
    else:
          return dateutil.parser.isoparse(date)

And then use it in the handling of data frames like.

dfa = openehr_server.query(aql)
dfa['Time'] = dfa['Last_updated'].apply(parse_date)
dfa['Time'] = pd.to_datetime(dfa['Time'], utc=True)

I suggest adding support for DV_DATE and DV_DATE_TIME as objects to be parsed into python objects like above