DATEPARSE Library
Different systems and protocols may have different requirements for date/time formats.
The DATEPARSE library provides a date/time parser that translates a wide variety of common date/time formats. It also provides several node functions that can be used to easily apply the date/time parser to convert date/time nodes into common database or HL7 timestamps.
local Msg = hl7.parse{data=Data, vmd='demo.vmd'}
local T = db.tables{vmd='demo.vmd', name='ADT'}
local Dob = Msg.PID[7][1]
trace(Dob) --> node containing '19830711183045'
-- use dateparse directly to return the date as Unix Epoch time value and as a table
local t, d = dateparse.parse(Dob:nodeValue()) --> '404265600'
-- date compatible with database table node tree
trace(Dob:D()) --> '1983-07-11 00:00:00'
-- datetime compatible with database table node tree
trace(Dob:T()) --> '1983-07-11 18:30:45'
-- HL7 timestamp - not compatible with db table
trace(Dob:TS()) --> '19830711183045'
-- convert current date to an HL7 timestamp
local hl7Date = os.date():TS()
If a format doesn't exist in the library, you can pass a one-off custom format to any of the library functions:
local t, d = dateparse.parse('01/11/2024','dd/mm/yyyy') --> '1730419200'
Alternatively, if there are several custom formats that you use frequently, you can create your own version of the library and expand the list of recognized formats. This can be done by updating the list of known_fmts
in dateparse.lua:
You can import this library to accelerate your date parsing capabilities in your interfaces. See how to Import a Library.