This topic contains 3 replies, has 2 voices, and was last updated by  Can 4 years, 5 months ago.

Convert HL7 DoB to a human-readable format. (PID:7)

  • Used the following code to convert PID:7 (Date of Birth) into a human-readable format.

    local dob = Orig.PID[7]:D():sub(1,10):D()
    dob = dob:sub(9,10)..”-“..dob:sub(6,7)..”-“..dob:sub(1,4)

    input:
    PID|1||122454^^^PAS^PI~1380066^^^PAS^MR^””~1234567890^^^NHS^NH||DYLAN^BOB^””^^MR||19780201|M

    Output:
    01-02-1978

    This works fine but I wonder if there are there are any date functions that I can use to convert the date into this format (dd-mm-yyyy).

    I guess the editor replaced D with the smiley faces.

    local dob = Orig.PID[7]:D():sub(1,10):D()
    dob = dob:sub(9,10)..”-“..dob:sub(6,7)..”-“..dob:sub(1,4)

    Add to custom String module extension (to custom shared module, let’s say its name is ‘strings’)

    string:D2(fmt)
    local t = dateparse.parse(self, fmt)
    return t and os.date(‘%Y-%m-%d’, t)
    end

    Add to custom Node module extension (to custom shared module, let’s say its name is node)

    function node:D2(fmt)
    return tostring(self): D2(fmt)
    end

    require (‘dateparse’)
    require(‘node’)
    require(‘strings’)

    local dob = Orig.PID[7]:D2()

    yields DOB value in format YYYY-mm-DD

    Great… Thanks Lev.

You must be logged in to reply to this topic.